diff --git a/package.json b/package.json index c4de1712a0..f6672f7e9e 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "eslint-plugin-vue": "^7.11.1", "husky": "^7.0.4", "lint-staged": "^11.0.0", + "npm-run-all": "^4.1.5", "stylelint": "^13.13.1", "stylelint-config-recommended-scss": "^4.3.0", "stylelint-config-standard": "^22.0.0", diff --git a/packages/devui-cli/package.json b/packages/devui-cli/package.json index eacbb2d868..60ce4304f5 100644 --- a/packages/devui-cli/package.json +++ b/packages/devui-cli/package.json @@ -11,7 +11,7 @@ "homepage": "https://github.com/DevCloudFE/vue-devui", "license": "MIT", "main": "lib/bin.js", - "types": "types/bin.d.ts", + "types": "types/config.d.ts", "bin": { "devui": "lib/bin.js" }, @@ -25,9 +25,8 @@ }, "scripts": { "dev": "esbuild --bundle ./src/bin.ts --format=cjs --platform=node --outfile=./lib/bin.js --external:esbuild --minify-whitespace --watch", - "build": "npm run build:lib & npm run build:dts", + "build": "run-p build:lib", "build:lib": "rimraf ./lib && esbuild --bundle ./src/bin.ts --format=cjs --platform=node --outfile=./lib/bin.js --external:esbuild --minify-whitespace", - "build:dts": "rimraf ./types && tsc -p ./tsconfig.json", "cli": "node ./lib/bin.js" }, "devDependencies": { diff --git a/packages/devui-cli/src/bin.ts b/packages/devui-cli/src/bin.ts index bf19b38a6e..b802d9943f 100644 --- a/packages/devui-cli/src/bin.ts +++ b/packages/devui-cli/src/bin.ts @@ -1,8 +1,9 @@ #!/usr/bin/env node import { Command } from 'commander' +import type { CliConfig } from '../types/config' import baseAction from './commands/base' import createAction, { validateCreateType } from './commands/create' -import { CliConfig, detectCliConfig } from './shared/config' +import { detectCliConfig } from './shared/config' import { VERSION } from './shared/constant' import { DEFAULT_CLI_CONFIG_FILE_NAME diff --git a/packages/devui-cli/src/commands/base.ts b/packages/devui-cli/src/commands/base.ts index 877dc955ad..78122a6910 100644 --- a/packages/devui-cli/src/commands/base.ts +++ b/packages/devui-cli/src/commands/base.ts @@ -1,68 +1,68 @@ -import { existsSync, statSync } from 'fs-extra' -import { dirname, extname, isAbsolute, resolve } from 'path' -import prompts from 'prompts' -import { mergeCliConfig } from '../shared/config' -import { CWD } from '../shared/constant' -import generateConfig from '../shared/generate-config' -import logger from '../shared/logger' -import { dynamicImport, onPromptsCancel } from '../shared/utils' -import buildAction from './build' -import createAction from './create' +import { existsSync, statSync } from 'fs-extra'; +import { dirname, extname, isAbsolute, resolve } from 'path'; +import prompts from 'prompts'; +import { mergeCliConfig } from '../shared/config'; +import { CWD } from '../shared/constant'; +import generateConfig from '../shared/generate-config'; +import logger from '../shared/logger'; +import { dynamicImport, onPromptsCancel } from '../shared/utils'; +import buildAction from './build'; +import createAction from './create'; function getActions() { - const actionMap = new Map() + const actionMap = new Map(); actionMap.set('create', { title: 'create', value: 'create', selected: true, action: createAction - }) - actionMap.set('build', { title: 'build', value: 'build', action: buildAction }) + }); + actionMap.set('build', { title: 'build', value: 'build', action: buildAction }); - return actionMap + return actionMap; } export type BaseCmd = { init?: boolean config?: string -} +}; export default async function baseAction(cmd: BaseCmd) { if (cmd.init) { - return generateConfig() + return generateConfig(); } - loadCliConfig(cmd) + loadCliConfig(cmd); - selectCommand() + selectCommand(); } export function loadCliConfig(cmd: Pick) { - if (!cmd.config) return + if (!cmd.config) return; - let configPath = resolve(CWD, cmd.config) + const configPath = resolve(CWD, cmd.config); if (!existsSync(configPath)) { - logger.error(`The path "${configPath}" not exist.`) - process.exit(1) + logger.error(`The path "${configPath}" not exist.`); + process.exit(1); } if (statSync(configPath).isDirectory() || !['.js', '.ts'].includes(extname(configPath))) { - logger.error(`The path "${configPath}" is not a ".js" or ".ts" file.`) - process.exit(1) + logger.error(`The path "${configPath}" is not a ".js" or ".ts" file.`); + process.exit(1); } - const config = dynamicImport(configPath) - if (!isAbsolute(config.cwd)) { - config.cwd = resolve(dirname(configPath), config.cwd) + const config = dynamicImport(configPath); + if (config.cwd && !isAbsolute(config.cwd)) { + config.cwd = resolve(dirname(configPath), config.cwd); } - mergeCliConfig(config) + mergeCliConfig(config); } async function selectCommand() { - const actions = getActions() - let result: any = {} + const actions = getActions(); + let result: any = {}; try { result = await prompts( @@ -77,11 +77,11 @@ async function selectCommand() { { onCancel: onPromptsCancel } - ) + ); } catch (e: any) { - logger.error(e.message) - process.exit(1) + logger.error(e.message); + process.exit(1); } - actions.get(result.command)!.action() + actions.get(result.command)!.action(); } diff --git a/packages/devui-cli/src/shared/config.ts b/packages/devui-cli/src/shared/config.ts index e4818a33ec..c52a78cc7a 100644 --- a/packages/devui-cli/src/shared/config.ts +++ b/packages/devui-cli/src/shared/config.ts @@ -1,71 +1,11 @@ import { readdirSync, statSync } from 'fs-extra' import { merge } from 'lodash-es' import { resolve } from 'path' +import type { CliConfig } from '../../types/config' import { loadCliConfig } from '../commands/base' import { CWD } from './constant' import { DEFAULT_CLI_CONFIG_NAME } from './generate-config' -export type CliConfig = { - /** - * current workspace directory - * - * ***Should be the root directory of the component library.*** - * - * @default process.cwd() - */ - cwd: string - /** - * Generate the root directory of component. - * - * ***Note that the path should be based on the `cwd` of configuration item.*** - * - * @default . - */ - componentRootDir: string - /** - * category of component - * - * @default ['通用', '导航', '反馈', '数据录入', '数据展示', '布局'] - */ - componentCategories: string[] - /** - * prefix of the component library - * - * @default '' - */ - libPrefix: string - /** - * component style file suffix of the component library - * - * @default .css - */ - libStyleFileSuffix: string - /** - * component class prefix of the component library - */ - libClassPrefix: string - /** - * component library entry file name - * - * @default index - */ - libEntryFileName: string - /** - * Generate the root directory of the lib entry file. - * - * ***Note that the path should be based on the `cwd` of configuration item.*** - * - * @default . - */ - libEntryRootDir: string - /** - * version of component library - * - * @default 0.0.0 - */ - version: string -} - export const cliConfig: CliConfig = { cwd: CWD, componentRootDir: '.', diff --git a/packages/devui-cli/src/shared/utils.ts b/packages/devui-cli/src/shared/utils.ts index 882bed6bfd..3ff20f8142 100644 --- a/packages/devui-cli/src/shared/utils.ts +++ b/packages/devui-cli/src/shared/utils.ts @@ -4,6 +4,7 @@ import { camelCase, upperFirst } from 'lodash-es' import { extname, relative, resolve } from 'path' import { coreFileName } from '../templates/component/utils' import { cliConfig } from './config' +import { PKG_NAME } from './constant' export function bigCamelCase(str: string) { return upperFirst(camelCase(str)) @@ -35,7 +36,7 @@ export function dynamicImport(path: string) { outfile: tempPath, platform: 'node', format: 'cjs', - external: ['esbuild', 'dev-cli'] + external: ['esbuild', PKG_NAME] }) const config = require(relativePath).default ?? {} diff --git a/packages/devui-cli/src/templates/base/config.ts b/packages/devui-cli/src/templates/base/config.ts index 5e2798cfaf..14b00105b5 100644 --- a/packages/devui-cli/src/templates/base/config.ts +++ b/packages/devui-cli/src/templates/base/config.ts @@ -1,5 +1,5 @@ -import { CliConfig } from "../../shared/config"; -import { PKG_NAME } from "../../shared/constant"; +import type { CliConfig } from '../../../types/config'; +import { PKG_NAME } from '../../shared/constant'; export default function genConfigTemplate(config: Partial = {}) { return `\ diff --git a/packages/devui-cli/src/templates/component/utils.ts b/packages/devui-cli/src/templates/component/utils.ts index a36a4f5a20..7e87005af8 100644 --- a/packages/devui-cli/src/templates/component/utils.ts +++ b/packages/devui-cli/src/templates/component/utils.ts @@ -24,9 +24,8 @@ export const directiveName = (name: string) => bigCamelCase(name + 'Directive') export async function getComponentMetaFiles() { return glob('./**/meta.json', { - cwd: cliConfig.cwd, - absolute: true, - deep: 2 + cwd: cliConfig.componentRootDir, + absolute: true }) } diff --git a/packages/devui-cli/src/templates/lib-entry/lib-entry.ts b/packages/devui-cli/src/templates/lib-entry/lib-entry.ts index 9450fe0bd2..7ad6221b62 100644 --- a/packages/devui-cli/src/templates/lib-entry/lib-entry.ts +++ b/packages/devui-cli/src/templates/lib-entry/lib-entry.ts @@ -58,7 +58,7 @@ export default function genLibEntryTemplate(componentsMeta: ComponentMeta[]) { return `\ import type { App } from 'vue' -${imports.join('\n')} +${imports.join('\n') || '// Not find components.'} const installs = [ \t${installs.join(',\n\t')} diff --git a/packages/devui-cli/tsconfig.json b/packages/devui-cli/tsconfig.json index e799e8ac90..5a626cfed3 100644 --- a/packages/devui-cli/tsconfig.json +++ b/packages/devui-cli/tsconfig.json @@ -8,10 +8,8 @@ "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, - "declaration": true, - "emitDeclarationOnly": true, "downlevelIteration": true, - "declarationDir": "./types", + "typeRoots": ["./node_modules/@types", "./types"], "allowSyntheticDefaultImports": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, @@ -20,6 +18,7 @@ }, "include": [ "./src/**/*.ts", - "./src/**/*.d.ts" + "./src/**/*.d.ts", + "./types/**/*.d.ts" ] } \ No newline at end of file diff --git a/packages/devui-vue/dc.config.ts b/packages/devui-vue/dc.config.ts new file mode 100644 index 0000000000..686925d139 --- /dev/null +++ b/packages/devui-vue/dc.config.ts @@ -0,0 +1,10 @@ +import { defineCliConfig } from 'devui-cli'; + +export default defineCliConfig({ + componentRootDir: './devui', + libClassPrefix: 'd', + libEntryFileName: 'vue-devui', + libEntryRootDir: './devui', + libPrefix: 'D', + libStyleFileSuffix: '.scss' +}) diff --git a/packages/devui-vue/package.json b/packages/devui-vue/package.json index a32723b334..411d4b075c 100644 --- a/packages/devui-vue/package.json +++ b/packages/devui-vue/package.json @@ -33,7 +33,6 @@ "generate:theme": "node ./devui-cli/index.js generate:theme", "generate:dts": "node ./devui-cli/index.js generate:dts", "copy": "cp package.json build && cp ../../README.md build && cp devui/theme/theme.scss build/theme", - "clean:cli": "npm uninstall -g devui-cli & npm uninstall -g vue-devui", "cli:create": "node ./devui-cli/index.js create -t component", "predev": "node ./devui-cli/index.js create -t vue-devui --ignore-parse-error", "prebuild": "node ./devui-cli/index.js create -t vue-devui --ignore-parse-error" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24671e160b..35f8e2c346 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,6 +13,7 @@ importers: eslint-plugin-vue: ^7.11.1 husky: ^7.0.4 lint-staged: ^11.0.0 + npm-run-all: ^4.1.5 stylelint: ^13.13.1 stylelint-config-recommended-scss: ^4.3.0 stylelint-config-standard: ^22.0.0 @@ -27,6 +28,7 @@ importers: eslint-plugin-vue: 7.20.0_eslint@7.32.0 husky: 7.0.4 lint-staged: 11.2.6 + npm-run-all: 4.1.5 stylelint: 13.13.1 stylelint-config-recommended-scss: 4.3.0_d55469ff7b1b68c43b61270d19a60ab6 stylelint-config-standard: 22.0.0_stylelint@13.13.1 @@ -3689,6 +3691,17 @@ packages: yaml: 1.10.2 dev: true + /cross-spawn/6.0.5: + resolution: {integrity: sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==} + engines: {node: '>=4.8'} + dependencies: + nice-try: 1.0.5 + path-key: 2.0.1 + semver: 5.7.1 + shebang-command: 1.2.0 + which: 1.3.1 + dev: true + /cross-spawn/7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -6067,6 +6080,10 @@ packages: pegjs: 0.10.0 dev: true + /json-parse-better-errors/1.0.2: + resolution: {integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==} + dev: true + /json-parse-even-better-errors/2.3.1: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==} dev: true @@ -6214,6 +6231,16 @@ packages: wrap-ansi: 7.0.0 dev: true + /load-json-file/4.0.0: + resolution: {integrity: sha1-L19Fq5HjMhYjT9U62rZo607AmTs=} + engines: {node: '>=4'} + dependencies: + graceful-fs: 4.2.9 + parse-json: 4.0.0 + pify: 3.0.0 + strip-bom: 3.0.0 + dev: true + /locate-path/2.0.0: resolution: {integrity: sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=} engines: {node: '>=4'} @@ -6389,6 +6416,11 @@ packages: resolution: {integrity: sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=} dev: true + /memorystream/0.3.1: + resolution: {integrity: sha1-htcJCzDORV1j+64S3aUaR93K+bI=} + engines: {node: '>= 0.10.0'} + dev: true + /meow/8.1.2: resolution: {integrity: sha512-r85E3NdZ+mpYk1C6RjPFEMSE+s1iZMuHtsHAqY0DT3jZczl0diWUZ8g6oU7h0M9cD2EL+PzaYghhCLzR0ZNn5Q==} engines: {node: '>=10'} @@ -6538,6 +6570,10 @@ packages: engines: {node: '>= 0.6'} dev: true + /nice-try/1.0.5: + resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==} + dev: true + /node-fetch/2.6.7: resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==} engines: {node: 4.x || >=6.0.0} @@ -6591,6 +6627,22 @@ packages: resolution: {integrity: sha1-0LFF62kRicY6eNIB3E/bEpPvDAM=} dev: true + /npm-run-all/4.1.5: + resolution: {integrity: sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==} + engines: {node: '>= 4'} + hasBin: true + dependencies: + ansi-styles: 3.2.1 + chalk: 2.4.2 + cross-spawn: 6.0.5 + memorystream: 0.3.1 + minimatch: 3.1.2 + pidtree: 0.3.1 + read-pkg: 3.0.0 + shell-quote: 1.7.3 + string.prototype.padend: 3.1.3 + dev: true + /npm-run-path/4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -6784,6 +6836,14 @@ packages: is-hexadecimal: 1.0.4 dev: true + /parse-json/4.0.0: + resolution: {integrity: sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=} + engines: {node: '>=4'} + dependencies: + error-ex: 1.3.2 + json-parse-better-errors: 1.0.2 + dev: true + /parse-json/5.2.0: resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==} engines: {node: '>=8'} @@ -6828,6 +6888,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /path-key/2.0.1: + resolution: {integrity: sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=} + engines: {node: '>=4'} + dev: true + /path-key/3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} @@ -6837,6 +6902,13 @@ packages: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} dev: true + /path-type/3.0.0: + resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==} + engines: {node: '>=4'} + dependencies: + pify: 3.0.0 + dev: true + /path-type/4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} @@ -6860,6 +6932,17 @@ packages: engines: {node: '>=8.6'} dev: true + /pidtree/0.3.1: + resolution: {integrity: sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA==} + engines: {node: '>=0.10'} + hasBin: true + dev: true + + /pify/3.0.0: + resolution: {integrity: sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=} + engines: {node: '>=4'} + dev: true + /pify/5.0.0: resolution: {integrity: sha512-eW/gHNMlxdSP6dmG6uJip6FXN0EQBwm2clYYd8Wul42Cwu/DK8HEftzsapcNdYe2MfLiIwZqsDk2RDEsTE79hA==} engines: {node: '>=10'} @@ -7168,6 +7251,15 @@ packages: type-fest: 0.8.1 dev: true + /read-pkg/3.0.0: + resolution: {integrity: sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k=} + engines: {node: '>=4'} + dependencies: + load-json-file: 4.0.0 + normalize-package-data: 2.5.0 + path-type: 3.0.0 + dev: true + /read-pkg/5.2.0: resolution: {integrity: sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==} engines: {node: '>=8'} @@ -7473,6 +7565,13 @@ packages: resolution: {integrity: sha1-BF+XgtARrppoA93TgrJDkrPYkPc=} dev: true + /shebang-command/1.2.0: + resolution: {integrity: sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=} + engines: {node: '>=0.10.0'} + dependencies: + shebang-regex: 1.0.0 + dev: true + /shebang-command/2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} @@ -7480,11 +7579,20 @@ packages: shebang-regex: 3.0.0 dev: true + /shebang-regex/1.0.0: + resolution: {integrity: sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=} + engines: {node: '>=0.10.0'} + dev: true + /shebang-regex/3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} dev: true + /shell-quote/1.7.3: + resolution: {integrity: sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==} + dev: true + /shelljs/0.8.5: resolution: {integrity: sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==} engines: {node: '>=4'} @@ -7641,6 +7749,15 @@ packages: strip-ansi: 6.0.1 dev: true + /string.prototype.padend/3.1.3: + resolution: {integrity: sha512-jNIIeokznm8SD/TZISQsZKYu7RJyheFNt84DUPrh482GC8RVp2MKqm2O5oBRdGxbDQoXrhhWtPIWQOiy20svUg==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.2 + define-properties: 1.1.3 + es-abstract: 1.19.1 + dev: true + /string.prototype.trimend/1.0.4: resolution: {integrity: sha512-y9xCjw1P23Awk8EvTpcyL2NIr1j7wJ39f+k6lvRnSMz+mz9CGz9NYPelDk42kOz6+ql8xjfK8oYzy3jAP5QU5A==} dependencies: