diff --git a/package.json b/package.json index c27646f28..259279af9 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "test": "vant-cli test", "build": "vant-cli build", "release": "vant-cli release", - "changelog": "vant-cli changelog", "test:watch": "vant-cli test --watch", "release:site": "sh docs/site/release.sh", "test:coverage": "open test/coverage/index.html" diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index 919f43c7e..e277ea91e 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -36,7 +36,6 @@ "@types/postcss-load-config": "^2.0.1", "@types/sass": "^1.16.0", "@types/shelljs": "^0.8.6", - "@types/signale": "^1.2.1", "@types/source-map": "^0.5.7", "@types/webpack": "^4.41.2", "@types/webpack-dev-server": "^3.9.0", @@ -71,6 +70,7 @@ "clean-css": "^4.2.1", "codecov": "^3.6.1", "commander": "^4.1.0", + "consola": "^2.11.3", "conventional-changelog": "^3.1.18", "cross-env": "^6.0.3", "css-loader": "^3.4.1", @@ -93,7 +93,6 @@ "sass": "^1.24.4", "sass-loader": "^8.0.0", "shelljs": "^0.8.3", - "signale": "^1.4.0", "style-loader": "^1.1.2", "stylelint": "^12.0.1", "typescript": "^3.7.4", diff --git a/packages/vant-cli/src/commands/build.ts b/packages/vant-cli/src/commands/build.ts index b7ee70ca2..de5e18275 100644 --- a/packages/vant-cli/src/commands/build.ts +++ b/packages/vant-cli/src/commands/build.ts @@ -5,7 +5,7 @@ import { join, relative } from 'path'; import { remove, copy, readdirSync } from 'fs-extra'; import { clean } from './clean'; import { CSS_LANG } from '../common/css'; -import { getStepper, getInteractiveLogger, logger } from '../common/logger'; +import { ora, consola, slimPath } from '../common/logger'; import { compileJs } from '../compiler/compile-js'; import { compileSfc } from '../compiler/compile-sfc'; import { compileStyle } from '../compiler/compile-style'; @@ -28,8 +28,6 @@ import { setModuleEnv } from '../common'; -const stepper = getStepper(12); - async function compileFile(filePath: string) { if (isSfc(filePath)) { return compileSfc(filePath); @@ -67,7 +65,8 @@ async function compileDir(dir: string) { } async function installDependencies() { - stepper.start('Install Dependencies'); + consola.info('Install Dependencies'); + console.log(''); try { const manager = hasYarn() ? 'yarn' : 'npm'; @@ -76,71 +75,75 @@ async function installDependencies() { stdio: 'inherit' }); - stepper.success('Install Dependencies'); + console.log(''); } catch (err) { - stepper.error('Install Dependencies', err); + console.log(err); throw err; } } async function buildESModuleOutputs() { - stepper.start('Build ESModule Outputs'); + const spinner = ora('Build ESModule Outputs').start(); try { setModuleEnv('esmodule'); await copy(SRC_DIR, ES_DIR); await compileDir(ES_DIR); - stepper.success('Build ESModule Outputs'); + spinner.succeed('Build ESModule Outputs'); } catch (err) { - stepper.error('Build ESModule Outputs', err); + spinner.fail('Build ESModule Outputs'); + console.log(err); throw err; } } async function buildCommonjsOutputs() { - stepper.start('Build Commonjs Outputs'); + const spinner = ora('Build Commonjs Outputs').start(); try { setModuleEnv('commonjs'); await copy(SRC_DIR, LIB_DIR); await compileDir(LIB_DIR); - stepper.success('Build Commonjs Outputs'); + spinner.succeed('Build Commonjs Outputs'); } catch (err) { - stepper.error('Build Commonjs Outputs', err); + spinner.fail('Build Commonjs Outputs'); + console.log(err); throw err; } } async function buildStyleEntry() { - stepper.start('Build Style Entry'); + const spinner = ora('Build Style Entry').start(); try { await genStyleDepsMap(); genComponentStyle(); - stepper.success('Build Style Entry'); + spinner.succeed('Build Style Entry'); } catch (err) { - stepper.error('Build Style Entry', err); + spinner.fail('Build Style Entry'); + console.log(err); throw err; } } async function buildPackedOutputs() { - stepper.start('Build Packed Outputs'); + const spinner = ora('Build Packed Outputs').start(); try { setModuleEnv('esmodule'); await compilePackage(false); await compilePackage(true); genVeturConfig(); - stepper.success('Build Packed Outputs'); + spinner.succeed('Build Packed Outputs'); } catch (err) { - stepper.error('Build Packed Outputs', err); + spinner.fail('Build Packed Outputs'); + console.log(err); throw err; } } async function buildPackageEntry() { - stepper.start('Build Package Entry'); + const spinner = ora('Build Package Entry').start(); try { const esEntryFile = join(ES_DIR, 'index.js'); @@ -165,27 +168,26 @@ async function buildPackageEntry() { await compileJs(libEntryFile); await compileStyle(styleEntryFile); - stepper.success('Build Package Entry'); + spinner.succeed('Build Package Entry'); } catch (err) { - stepper.error('Build Package Entry', err); + spinner.fail('Build Package Entry'); + console.log(err); throw err; } } function watchFileChange() { - logger.watch('Compiled successfully, watching file changes...'); + consola.info('\nWatching file changes...'); chokidar.watch(SRC_DIR).on('change', async path => { if (isDemoDir(path) || isTestDir(path)) { return; } - const logger = getInteractiveLogger(); + const spinner = ora('File changed, start compilation...').start(); const esPath = path.replace(SRC_DIR, ES_DIR); const libPath = path.replace(SRC_DIR, LIB_DIR); - logger.pending('File change detected, start compilation...'); - try { await copy(path, esPath); await copy(path, libPath); @@ -193,9 +195,9 @@ function watchFileChange() { await compileFile(libPath); await genStyleDepsMap(); genComponentStyle({ cache: false }); - logger.success('Compiled: ' + path); + spinner.succeed('Compiled: ' + slimPath(path)); } catch (err) { - logger.error('Compile failed: ' + path); + spinner.fail('Compile failed: ' + path); console.log(err); } }); @@ -213,11 +215,13 @@ export async function build(cmd: { watch?: boolean } = {}) { await buildPackageEntry(); await buildPackedOutputs(); + consola.success('Compile successfully'); + if (cmd.watch) { watchFileChange(); } } catch (err) { - logger.error('Build failed'); + consola.error('Build failed'); process.exit(1); } } diff --git a/packages/vant-cli/src/commands/commit-lint.ts b/packages/vant-cli/src/commands/commit-lint.ts index f77d4d9af..d2297d733 100644 --- a/packages/vant-cli/src/commands/commit-lint.ts +++ b/packages/vant-cli/src/commands/commit-lint.ts @@ -1,5 +1,5 @@ import { readFileSync } from 'fs-extra'; -import { logger } from '../common/logger'; +import { consola } from '../common/logger'; const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)(\(.+\))?: .{1,50}/; const mergeRE = /Merge branch /; @@ -9,7 +9,7 @@ export function commitLint() { const commitMsg = readFileSync(gitParams, 'utf-8').trim(); if (!commitRE.test(commitMsg) && !mergeRE.test(commitMsg)) { - logger.error(`Error: invalid commit message: "${commitMsg}". + consola.error(`invalid commit message: "${commitMsg}". Proper commit message format is required for automated changelog generation. diff --git a/packages/vant-cli/src/common/logger.ts b/packages/vant-cli/src/common/logger.ts index 2b702ff80..8f7f992e9 100644 --- a/packages/vant-cli/src/common/logger.ts +++ b/packages/vant-cli/src/common/logger.ts @@ -1,43 +1,10 @@ import ora from 'ora'; import chalk from 'chalk'; -import logger from 'signale'; +import consola from 'consola'; import { ROOT } from '../common/constant'; -logger.config({ - displayTimestamp: true -}); - -const methods = ['success', 'start', 'error'] as const; - -type Stepper = Pick; - -export function getStepper(totalStep: number) { - const stepper = {} as Stepper; - let currentStep = 0; - - methods.forEach(key => { - stepper[key] = (message, ...args) => { - const prefix = `[${++currentStep}/${totalStep}] `; - return logger[key](prefix + message, ...args); - }; - }); - - return stepper; -} - -export function getInteractiveLogger() { - const interactive = new logger.Signale({ - interactive: true, - config: { - displayTimestamp: true - } - }); - - return interactive; -} - export function slimPath(path: string) { - return chalk.yellow(path.replace(ROOT, '.')); + return chalk.yellow(path.replace(ROOT, '')); } -export { ora, logger }; +export { ora, consola }; diff --git a/packages/vant-cli/src/compiler/compile-style.ts b/packages/vant-cli/src/compiler/compile-style.ts index d66e9e923..ab9335fb3 100644 --- a/packages/vant-cli/src/compiler/compile-style.ts +++ b/packages/vant-cli/src/compiler/compile-style.ts @@ -4,7 +4,7 @@ import { replaceExt } from '../common'; import { compileCss } from './compile-css'; import { compileLess } from './compile-less'; import { compileSass } from './compile-sass'; -import { logger } from '../common/logger'; +import { consola } from '../common/logger'; async function compileFile(filePath: string) { const parsedPath = parse(filePath); @@ -23,7 +23,7 @@ async function compileFile(filePath: string) { const source = readFileSync(filePath, 'utf-8'); return await compileCss(source); } catch (err) { - logger.error('Compile style failed: ' + filePath); + consola.error('Compile style failed: ' + filePath); throw err; } } diff --git a/packages/vant-cli/yarn.lock b/packages/vant-cli/yarn.lock index 4d34b126a..1dae0c2e5 100644 --- a/packages/vant-cli/yarn.lock +++ b/packages/vant-cli/yarn.lock @@ -1461,13 +1461,6 @@ "@types/glob" "*" "@types/node" "*" -"@types/signale@^1.2.1": - version "1.2.1" - resolved "https://registry.npm.taobao.org/@types/signale/download/@types/signale-1.2.1.tgz#7ff3d477e8d5983b7ecef544f5830c3cb271d1a8" - integrity sha1-f/PUd+jVmDt+zvVE9YMMPLJx0ag= - dependencies: - "@types/node" "*" - "@types/source-list-map@*": version "0.1.2" resolved "https://registry.npm.taobao.org/@types/source-list-map/download/@types/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9" @@ -3325,6 +3318,11 @@ consola@^2.10.0: resolved "https://registry.yarnpkg.com/consola/-/consola-2.11.1.tgz#1df259c0a7aef44c9eb4f448e3a20ba0850a65e7" integrity sha512-zFH/xFAE/KHJiWqwyTEDmdFe34Swc0pqMKJeowTvR3irepx8kKPu8bjaKzRd+RLjLH+0TvFxFBnohbSUQ+hOsw== +consola@^2.11.3: + version "2.11.3" + resolved "http://registry.npm.qima-inc.com/consola/download/consola-2.11.3.tgz#f7315836224c143ac5094b47fd4c816c2cd1560e" + integrity sha1-9zFYNiJMFDrFCUtH/UyBbCzRVg4= + consola@^2.6.0: version "2.11.0" resolved "https://registry.yarnpkg.com/consola/-/consola-2.11.0.tgz#9bb35d850d8cecde894ce2eb4d792fa6b90d9013" @@ -8693,14 +8691,6 @@ pirates@^4.0.1: dependencies: node-modules-regexp "^1.0.0" -pkg-conf@^2.1.0: - version "2.1.0" - resolved "https://registry.npm.taobao.org/pkg-conf/download/pkg-conf-2.1.0.tgz#2126514ca6f2abfebd168596df18ba57867f0058" - integrity sha1-ISZRTKbyq/69FoWW3xi6V4Z/AFg= - dependencies: - find-up "^2.0.0" - load-json-file "^4.0.0" - pkg-dir@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/pkg-dir/download/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b" @@ -10045,15 +10035,6 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: resolved "https://registry.npm.taobao.org/signal-exit/download/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= -signale@^1.4.0: - version "1.4.0" - resolved "https://registry.npm.taobao.org/signale/download/signale-1.4.0.tgz#c4be58302fb0262ac00fc3d886a7c113759042f1" - integrity sha1-xL5YMC+wJirAD8PYhqfBE3WQQvE= - dependencies: - chalk "^2.3.2" - figures "^2.0.0" - pkg-conf "^2.1.0" - sisteransi@^1.0.3: version "1.0.4" resolved "https://registry.npm.taobao.org/sisteransi/download/sisteransi-1.0.4.tgz?cache=0&sync_timestamp=1573410719947&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsisteransi%2Fdownload%2Fsisteransi-1.0.4.tgz#386713f1ef688c7c0304dc4c0632898941cad2e3" diff --git a/yarn.lock b/yarn.lock index e85c21c57..66377ae04 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11665,8 +11665,8 @@ vue-style-loader@^4.1.0: vue-template-compiler@^2.6.11: version "2.6.11" - resolved "https://registry.npm.taobao.org/vue-template-compiler/download/vue-template-compiler-2.6.11.tgz#c04704ef8f498b153130018993e56309d4698080" - integrity sha1-wEcE749JixUxMAGJk+VjCdRpgIA= + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.6.11.tgz#c04704ef8f498b153130018993e56309d4698080" + integrity sha512-KIq15bvQDrcCjpGjrAhx4mUlyyHfdmTaoNfeoATHLAiWB+MU3cx4lOzMwrnUh9cCxy0Lt1T11hAFY6TQgroUAA== dependencies: de-indent "^1.0.2" he "^1.1.0" @@ -11678,8 +11678,8 @@ vue-template-es2015-compiler@^1.9.0: vue@^2.6.11: version "2.6.11" - resolved "https://registry.npm.taobao.org/vue/download/vue-2.6.11.tgz?cache=0&sync_timestamp=1576274787429&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue%2Fdownload%2Fvue-2.6.11.tgz#76594d877d4b12234406e84e35275c6d514125c5" - integrity sha1-dllNh31LEiNEBuhONSdcbVFBJcU= + resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.11.tgz#76594d877d4b12234406e84e35275c6d514125c5" + integrity sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ== w3c-hr-time@^1.0.1: version "1.0.1"