feat: add devDeps, add nypm for installing deps

This commit is contained in:
sadeghbarati 2024-01-27 09:12:49 +03:30
parent 42f0086586
commit fb70bb3c89
7 changed files with 35 additions and 76 deletions

View File

@ -132,10 +132,8 @@
}, },
{ {
"name": "carousel", "name": "carousel",
"dependencies": [ "dependencies": ["embla-carousel"],
"embla-carousel-vue", "devDependencies": ["embla-carousel-vue"],
"embla-carousel"
],
"registryDependencies": [ "registryDependencies": [
"utils", "utils",
"button" "button"

View File

@ -45,7 +45,6 @@
"test:ui": "vitest --ui" "test:ui": "vitest --ui"
}, },
"dependencies": { "dependencies": {
"@antfu/ni": "^0.21.8",
"@babel/core": "^7.22.17", "@babel/core": "^7.22.17",
"@babel/parser": "^7.22.16", "@babel/parser": "^7.22.16",
"@babel/plugin-transform-typescript": "^7.22.15", "@babel/plugin-transform-typescript": "^7.22.15",
@ -55,12 +54,12 @@
"cosmiconfig": "^8.3.6", "cosmiconfig": "^8.3.6",
"detype": "npm:detypes@^0.7.6", "detype": "npm:detypes@^0.7.6",
"diff": "^5.1.0", "diff": "^5.1.0",
"execa": "^8.0.1",
"fs-extra": "^11.1.1", "fs-extra": "^11.1.1",
"https-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.2",
"lodash.template": "^4.5.0", "lodash.template": "^4.5.0",
"magic-string": "^0.30.3", "magic-string": "^0.30.3",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.2",
"nypm": "^0.3.6",
"ora": "^7.0.1", "ora": "^7.0.1",
"prompts": "^2.4.2", "prompts": "^2.4.2",
"radix-vue": "^1.3.0", "radix-vue": "^1.3.0",

View File

@ -3,13 +3,12 @@ import path from 'node:path'
import process from 'node:process' import process from 'node:process'
import chalk from 'chalk' import chalk from 'chalk'
import { Command } from 'commander' import { Command } from 'commander'
import { execa } from 'execa'
import ora from 'ora' import ora from 'ora'
import prompts from 'prompts' import prompts from 'prompts'
import * as z from 'zod' import * as z from 'zod'
import { addDependency, addDevDependency } from 'nypm'
import { transform } from '@/src/utils/transformers' import { transform } from '@/src/utils/transformers'
import { getConfig } from '@/src/utils/get-config' import { getConfig } from '@/src/utils/get-config'
import { getPackageManager } from '@/src/utils/get-package-manager'
import { handleError } from '@/src/utils/handle-error' import { handleError } from '@/src/utils/handle-error'
import { logger } from '@/src/utils/logger' import { logger } from '@/src/utils/logger'
import { import {
@ -190,17 +189,15 @@ export const add = new Command()
skippedDeps.add(dep), skippedDeps.add(dep),
) )
const packageManager = await getPackageManager(cwd) await addDependency(item.dependencies, {
await execa( cwd,
packageManager, })
[ }
packageManager === 'npm' ? 'install' : 'add',
...item.dependencies, if (item.devDependencies?.length) {
], await addDevDependency(item.devDependencies, {
{ cwd,
cwd, })
},
)
} }
} }
spinner.succeed('Done.') spinner.succeed('Done.')

View File

@ -3,11 +3,11 @@ import path from 'node:path'
import process from 'node:process' import process from 'node:process'
import chalk from 'chalk' import chalk from 'chalk'
import { Command } from 'commander' import { Command } from 'commander'
import { execa } from 'execa'
import template from 'lodash.template' import template from 'lodash.template'
import ora from 'ora' import ora from 'ora'
import prompts from 'prompts' import prompts from 'prompts'
import * as z from 'zod' import * as z from 'zod'
import { addDependency, addDevDependency } from 'nypm'
import * as templates from '../utils/templates' import * as templates from '../utils/templates'
import { import {
getRegistryBaseColor, getRegistryBaseColor,
@ -16,7 +16,6 @@ import {
} from '../utils/registry' } from '../utils/registry'
import { logger } from '../utils/logger' import { logger } from '../utils/logger'
import { handleError } from '../utils/handle-error' import { handleError } from '../utils/handle-error'
import { getPackageManager } from '../utils/get-package-manager'
import { transformByDetype } from '../utils/transformers/transform-sfc' import { transformByDetype } from '../utils/transformers/transform-sfc'
import { import {
type Config, type Config,
@ -276,20 +275,20 @@ export async function runInit(cwd: string, config: Config) {
// Install dependencies. // Install dependencies.
const dependenciesSpinner = ora('Installing dependencies...')?.start() const dependenciesSpinner = ora('Installing dependencies...')?.start()
const packageManager = await getPackageManager(cwd)
const deps = PROJECT_DEPENDENCIES.base.concat( const deps = PROJECT_DEPENDENCIES.base.concat(
config.framework === 'nuxt' ? PROJECT_DEPENDENCIES.nuxt : [],
).concat(
config.style === 'new-york' ? ['@radix-icons/vue'] : ['lucide-vue-next'], config.style === 'new-york' ? ['@radix-icons/vue'] : ['lucide-vue-next'],
).filter(Boolean) ).filter(Boolean)
await execa( if (config.framework === 'nuxt') {
packageManager, await addDevDependency(PROJECT_DEPENDENCIES.nuxt, {
[packageManager === 'npm' ? 'install' : 'add', ...deps],
{
cwd, cwd,
}, })
) }
await addDependency(deps, {
cwd,
})
dependenciesSpinner?.succeed() dependenciesSpinner?.succeed()
} }

View File

@ -1,16 +0,0 @@
import { detect } from '@antfu/ni'
export async function getPackageManager(
targetDir: string,
): Promise<'yarn' | 'pnpm' | 'bun' | 'npm'> {
const packageManager = await detect({ programmatic: true, cwd: targetDir })
if (packageManager === 'yarn@berry')
return 'yarn'
if (packageManager === 'pnpm@6')
return 'pnpm'
if (packageManager === 'bun')
return 'bun'
return packageManager ?? 'npm'
}

View File

@ -4,6 +4,7 @@ import * as z from 'zod'
export const registryItemSchema = z.object({ export const registryItemSchema = z.object({
name: z.string(), name: z.string(),
dependencies: z.array(z.string()).optional(), dependencies: z.array(z.string()).optional(),
devDependencies: z.array(z.string()).optional(),
registryDependencies: z.array(z.string()).optional(), registryDependencies: z.array(z.string()).optional(),
files: z.array(z.string()), files: z.array(z.string()),
type: z.enum(['components:ui', 'components:component', 'components:example']), type: z.enum(['components:ui', 'components:component', 'components:example']),

View File

@ -198,9 +198,6 @@ importers:
packages/cli: packages/cli:
dependencies: dependencies:
'@antfu/ni':
specifier: ^0.21.8
version: 0.21.8
'@babel/core': '@babel/core':
specifier: ^7.22.17 specifier: ^7.22.17
version: 7.23.0 version: 7.23.0
@ -228,9 +225,6 @@ importers:
diff: diff:
specifier: ^5.1.0 specifier: ^5.1.0
version: 5.1.0 version: 5.1.0
execa:
specifier: ^8.0.1
version: 8.0.1
fs-extra: fs-extra:
specifier: ^11.1.1 specifier: ^11.1.1
version: 11.1.1 version: 11.1.1
@ -246,6 +240,9 @@ importers:
node-fetch: node-fetch:
specifier: ^3.3.2 specifier: ^3.3.2
version: 3.3.2 version: 3.3.2
nypm:
specifier: ^0.3.6
version: 0.3.6
ora: ora:
specifier: ^7.0.1 specifier: ^7.0.1
version: 7.0.1 version: 7.0.1
@ -632,6 +629,7 @@ packages:
/@antfu/ni@0.21.8: /@antfu/ni@0.21.8:
resolution: {integrity: sha512-90X8pU2szlvw0AJo9EZMbYc2eQKkmO7mAdC4tD4r5co2Mm56MT37MIG8EyB7p4WRheuzGxuLDxJ63mF6+Zajiw==} resolution: {integrity: sha512-90X8pU2szlvw0AJo9EZMbYc2eQKkmO7mAdC4tD4r5co2Mm56MT37MIG8EyB7p4WRheuzGxuLDxJ63mF6+Zajiw==}
hasBin: true hasBin: true
dev: true
/@antfu/utils@0.7.6: /@antfu/utils@0.7.6:
resolution: {integrity: sha512-pvFiLP2BeOKA/ZOS6jxx4XhKzdVLHDhGlFEaZ2flWWYf2xOqVniqpk38I04DFRyz+L0ASggl7SkItTc+ZLju4w==} resolution: {integrity: sha512-pvFiLP2BeOKA/ZOS6jxx4XhKzdVLHDhGlFEaZ2flWWYf2xOqVniqpk38I04DFRyz+L0ASggl7SkItTc+ZLju4w==}
@ -2852,7 +2850,7 @@ packages:
magicast: 0.3.2 magicast: 0.3.2
nitropack: 2.8.1 nitropack: 2.8.1
nuxt: 3.8.2(@types/node@20.10.1)(eslint@8.56.0)(rollup@3.29.4)(typescript@5.3.3)(vite@4.5.1) nuxt: 3.8.2(@types/node@20.10.1)(eslint@8.56.0)(rollup@3.29.4)(typescript@5.3.3)(vite@4.5.1)
nypm: 0.3.3 nypm: 0.3.6
ofetch: 1.3.3 ofetch: 1.3.3
ohash: 1.1.3 ohash: 1.1.3
pacote: 17.0.4 pacote: 17.0.4
@ -2925,7 +2923,7 @@ packages:
pkg-types: 1.0.3 pkg-types: 1.0.3
scule: 1.0.0 scule: 1.0.0
semver: 7.5.4 semver: 7.5.4
ufo: 1.3.0 ufo: 1.3.2
unctx: 2.3.1 unctx: 2.3.1
unimport: 3.4.0(rollup@3.29.4) unimport: 3.4.0(rollup@3.29.4)
untyped: 1.4.0 untyped: 1.4.0
@ -3019,7 +3017,7 @@ packages:
pkg-types: 1.0.3 pkg-types: 1.0.3
postcss-import-resolver: 2.0.0 postcss-import-resolver: 2.0.0
std-env: 3.4.3 std-env: 3.4.3
ufo: 1.3.0 ufo: 1.3.2
unimport: 3.4.0(rollup@3.29.4) unimport: 3.4.0(rollup@3.29.4)
untyped: 1.4.0 untyped: 1.4.0
transitivePeerDependencies: transitivePeerDependencies:
@ -6155,7 +6153,6 @@ packages:
resolution: {integrity: sha512-AS7n5NSc0OQVMV9v6wt3ByujNIrne0/cTjiC2MYqhvao57VNfiuVksTSr2p17nVOhEr2KtqiAkGwHcgMC/qUuQ==} resolution: {integrity: sha512-AS7n5NSc0OQVMV9v6wt3ByujNIrne0/cTjiC2MYqhvao57VNfiuVksTSr2p17nVOhEr2KtqiAkGwHcgMC/qUuQ==}
dependencies: dependencies:
consola: 3.2.3 consola: 3.2.3
dev: true
/class-variance-authority@0.7.0: /class-variance-authority@0.7.0:
resolution: {integrity: sha512-jFI8IQw4hczaL4ALINxqLEXQbWcNjoSkloa4IaufXCJr6QawJyw7tuRysRsrE8w2p/4gGaxKIt/hX3qz/IbD1A==} resolution: {integrity: sha512-jFI8IQw4hczaL4ALINxqLEXQbWcNjoSkloa4IaufXCJr6QawJyw7tuRysRsrE8w2p/4gGaxKIt/hX3qz/IbD1A==}
@ -8564,7 +8561,7 @@ packages:
consola: 3.2.3 consola: 3.2.3
defu: 6.1.4 defu: 6.1.4
node-fetch-native: 1.6.1 node-fetch-native: 1.6.1
nypm: 0.3.4 nypm: 0.3.6
ohash: 1.1.3 ohash: 1.1.3
pathe: 1.1.2 pathe: 1.1.2
tar: 6.2.0 tar: 6.2.0
@ -10890,7 +10887,7 @@ packages:
mlly: 1.4.2 mlly: 1.4.2
nitropack: 2.8.1 nitropack: 2.8.1
nuxi: 3.10.0 nuxi: 3.10.0
nypm: 0.3.3 nypm: 0.3.6
ofetch: 1.3.3 ofetch: 1.3.3
ohash: 1.1.3 ohash: 1.1.3
pathe: 1.1.2 pathe: 1.1.2
@ -10950,8 +10947,8 @@ packages:
- xml2js - xml2js
dev: true dev: true
/nypm@0.3.3: /nypm@0.3.6:
resolution: {integrity: sha512-FHoxtTscAE723e80d2M9cJRb4YVjL82Ra+ZV+YqC6rfNZUWahi+ZhPF+krnR+bdMvibsfHCtgKXnZf5R6kmEPA==} resolution: {integrity: sha512-2CATJh3pd6CyNfU5VZM7qSwFu0ieyabkEdnogE30Obn1czrmOYiZ8DOZLe1yBdLKWoyD3Mcy2maUs+0MR3yVjQ==}
engines: {node: ^14.16.0 || >=16.10.0} engines: {node: ^14.16.0 || >=16.10.0}
hasBin: true hasBin: true
dependencies: dependencies:
@ -10959,18 +10956,6 @@ packages:
execa: 8.0.1 execa: 8.0.1
pathe: 1.1.2 pathe: 1.1.2
ufo: 1.3.2 ufo: 1.3.2
dev: true
/nypm@0.3.4:
resolution: {integrity: sha512-1JLkp/zHBrkS3pZ692IqOaIKSYHmQXgqfELk6YTOfVBnwealAmPA1q2kKK7PHJAHSMBozerThEFZXP3G6o7Ukg==}
engines: {node: ^14.16.0 || >=16.10.0}
hasBin: true
dependencies:
citty: 0.1.5
execa: 8.0.1
pathe: 1.1.2
ufo: 1.3.2
dev: true
/object-assign@4.1.1: /object-assign@4.1.1:
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
@ -13527,10 +13512,6 @@ packages:
engines: {node: '>=14.17'} engines: {node: '>=14.17'}
hasBin: true hasBin: true
/ufo@1.3.0:
resolution: {integrity: sha512-bRn3CsoojyNStCZe0BG0Mt4Nr/4KF+rhFlnNXybgqt5pXHNFRlqinSoQaTrGyzE4X8aHplSb+TorH+COin9Yxw==}
dev: false
/ufo@1.3.2: /ufo@1.3.2:
resolution: {integrity: sha512-o+ORpgGwaYQXgqGDwd+hkS4PuZ3QnmqMMxRuajK/a38L6fTpcE5GPIfrf+L/KemFzfUpeUQc1rRS1iDBozvnFA==} resolution: {integrity: sha512-o+ORpgGwaYQXgqGDwd+hkS4PuZ3QnmqMMxRuajK/a38L6fTpcE5GPIfrf+L/KemFzfUpeUQc1rRS1iDBozvnFA==}