mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): using rslog (#12334)
This commit is contained in:
parent
53188a7093
commit
087ecda7b2
2
.npmrc
2
.npmrc
@ -1,4 +1,4 @@
|
||||
registry=https://registry.npmmirror.com/
|
||||
registry=https://registry.npmjs.org/
|
||||
|
||||
strict-peer-dependencies=false
|
||||
auto-install-peers=false
|
||||
|
@ -36,7 +36,7 @@
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"consola": "^3.0.2",
|
||||
"rslog": "^1.0.0",
|
||||
"fast-glob": "^3.2.11",
|
||||
"fs-extra": "^11.1.0",
|
||||
"enquirer": "2.3.6",
|
||||
|
@ -1,7 +1,7 @@
|
||||
import fs from 'fs-extra';
|
||||
import glob from 'fast-glob';
|
||||
import color from 'picocolors';
|
||||
import { consola } from 'consola';
|
||||
import { logger } from 'rslog';
|
||||
import { prompt } from 'enquirer';
|
||||
import { sep, join } from 'node:path';
|
||||
import { CWD, GENERATOR_DIR } from './constant';
|
||||
@ -64,7 +64,7 @@ export class VanGenerator {
|
||||
|
||||
writing() {
|
||||
console.log();
|
||||
consola.info(`Creating project in ${color.green(this.outputDir)}\n`);
|
||||
logger.info(`Creating project in ${color.green(this.outputDir)}\n`);
|
||||
|
||||
// see https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
|
||||
const templatePath = join(GENERATOR_DIR, this.inputs.vueVersion).replace(
|
||||
@ -99,15 +99,15 @@ export class VanGenerator {
|
||||
fs.writeFileSync(to, content);
|
||||
|
||||
const name = to.replace(this.outputDir + sep, '');
|
||||
consola.success(`${color.green('create')} ${name}`);
|
||||
logger.success(`${color.green('create')} ${name}`);
|
||||
}
|
||||
|
||||
end() {
|
||||
const { name } = this.inputs;
|
||||
|
||||
console.log();
|
||||
consola.success(`Successfully created ${color.yellow(name)}.`);
|
||||
consola.success(
|
||||
logger.success(`Successfully created ${color.yellow(name)}.`);
|
||||
logger.success(
|
||||
`Run ${color.yellow(
|
||||
`cd ${name} && git init && yarn && yarn dev`,
|
||||
)} to start development!`,
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { consola } from 'consola';
|
||||
import { logger } from 'rslog';
|
||||
import { prompt } from 'enquirer';
|
||||
import { ensureDir } from 'fs-extra';
|
||||
import { VanGenerator } from './generator';
|
||||
@ -17,7 +17,7 @@ async function run() {
|
||||
const generator = new VanGenerator(name);
|
||||
await generator.run();
|
||||
} catch (e) {
|
||||
consola.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@
|
||||
"@vue/babel-plugin-jsx": "^1.1.1",
|
||||
"autoprefixer": "^10.4.8",
|
||||
"commander": "^11.0.0",
|
||||
"consola": "^3.0.2",
|
||||
"rslog": "^1.0.0",
|
||||
"esbuild": "^0.18.11",
|
||||
"eslint": "^8.46.0",
|
||||
"enquirer": "2.3.6",
|
||||
@ -69,7 +69,6 @@
|
||||
"markdown-it": "^13.0.1",
|
||||
"markdown-it-anchor": "^8.6.4",
|
||||
"nano-staged": "^0.8.0",
|
||||
"nanospinner": "^1.1.0",
|
||||
"picocolors": "^1.0.0",
|
||||
"postcss": "^8.4.23",
|
||||
"postcss-load-config": "^4.0.1",
|
||||
|
@ -1,9 +1,9 @@
|
||||
import fse from 'fs-extra';
|
||||
import { logger } from 'rslog';
|
||||
import { execSync } from 'child_process';
|
||||
import { join, relative } from 'node:path';
|
||||
import { clean } from './clean.js';
|
||||
import { CSS_LANG } from '../common/css.js';
|
||||
import { createSpinner, consola } from '../common/logger.js';
|
||||
import { installDependencies } from '../common/manager.js';
|
||||
import { compileSfc } from '../compiler/compile-sfc.js';
|
||||
import { compileStyle } from '../compiler/compile-style.js';
|
||||
@ -181,20 +181,19 @@ const tasks = [
|
||||
async function runBuildTasks() {
|
||||
for (let i = 0; i < tasks.length; i++) {
|
||||
const { task, text } = tasks[i];
|
||||
const spinner = createSpinner(text).start();
|
||||
|
||||
try {
|
||||
/* eslint-disable no-await-in-loop */
|
||||
await task();
|
||||
spinner.success({ text });
|
||||
logger.ready(text);
|
||||
} catch (err) {
|
||||
spinner.error({ text });
|
||||
console.log(err);
|
||||
logger.error(text);
|
||||
logger.error(err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
consola.success('Compile successfully');
|
||||
logger.success('Build all files');
|
||||
}
|
||||
|
||||
export async function build() {
|
||||
@ -205,7 +204,7 @@ export async function build() {
|
||||
await installDependencies();
|
||||
await runBuildTasks();
|
||||
} catch (err) {
|
||||
consola.error('Build failed');
|
||||
logger.error('Build failed');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { logger } from 'rslog';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { consola } from '../common/logger.js';
|
||||
|
||||
const commitRE =
|
||||
/^(revert: )?(fix|feat|docs|perf|test|types|style|build|chore|release|refactor|breaking change)(\(.+\))?: .{1,50}/;
|
||||
@ -9,7 +9,7 @@ export function commitLint(gitParams: string) {
|
||||
const commitMsg = readFileSync(gitParams, 'utf-8').trim();
|
||||
|
||||
if (!commitRE.test(commitMsg) && !mergeRE.test(commitMsg)) {
|
||||
consola.error(`invalid commit message: "${commitMsg}".
|
||||
logger.error(`invalid commit message: "${commitMsg}".
|
||||
|
||||
Proper commit message format is required for automated changelog generation.
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { exec } from 'child_process';
|
||||
import { consola, createSpinner } from '../common/logger.js';
|
||||
import { logger } from 'rslog';
|
||||
import { SCRIPT_EXTS } from '../common/constant.js';
|
||||
|
||||
type RunCommandMessages = {
|
||||
@ -9,7 +9,7 @@ type RunCommandMessages = {
|
||||
};
|
||||
|
||||
function runCommand(cmd: string, messages: RunCommandMessages) {
|
||||
const spinner = createSpinner(messages.start).start();
|
||||
logger.start(messages.start);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const options = {
|
||||
@ -18,11 +18,11 @@ function runCommand(cmd: string, messages: RunCommandMessages) {
|
||||
|
||||
exec(cmd, options, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
consola.error(stderr || stdout);
|
||||
spinner.error({ text: messages.failed });
|
||||
logger.error(stderr || stdout);
|
||||
logger.error(messages.failed);
|
||||
resolve(false);
|
||||
} else {
|
||||
spinner.success({ text: messages.succeed });
|
||||
logger.success(messages.succeed);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
|
@ -2,15 +2,15 @@ import fse from 'fs-extra';
|
||||
import { join } from 'node:path';
|
||||
import color from 'picocolors';
|
||||
import enquirer from 'enquirer';
|
||||
import { consola } from '../common/logger.js';
|
||||
import { logger } from 'rslog';
|
||||
import { getPackageManager } from '../common/manager.js';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
function logCurrentVersion(cwd: string) {
|
||||
const pkgJson = join(cwd, 'package.json');
|
||||
const pkg = fse.readJSONSync(pkgJson);
|
||||
consola.success(`${color.bold('Current package:')} ${color.green(pkg.name)}`);
|
||||
consola.success(
|
||||
logger.success(`${color.bold('Current package:')} ${color.green(pkg.name)}`);
|
||||
logger.success(
|
||||
`${color.bold('Current version:')} ${color.green(pkg.version)}`,
|
||||
);
|
||||
return {
|
||||
@ -43,7 +43,7 @@ function getNpmTag(version: string, forceTag?: string) {
|
||||
tag = 'latest';
|
||||
}
|
||||
|
||||
consola.success(`${color.bold('Npm tag:')} ${color.green(tag)}`);
|
||||
logger.success(`${color.bold('Npm tag:')} ${color.green(tag)}`);
|
||||
|
||||
return tag;
|
||||
}
|
||||
@ -60,7 +60,7 @@ function setPkgVersion(
|
||||
function buildPackage(pkgJson: Record<string, any>, packageManager: string) {
|
||||
if (pkgJson.scripts?.build) {
|
||||
const command = `${packageManager} run build`;
|
||||
consola.success(`${color.bold('Build package:')} ${color.green(command)}`);
|
||||
logger.success(`${color.bold('Build package:')} ${color.green(command)}`);
|
||||
execSync(command, { stdio: 'inherit' });
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ export async function release(command: { tag?: string; gitTag?: boolean }) {
|
||||
try {
|
||||
buildPackage(pkgJson, packageManager);
|
||||
} catch (err) {
|
||||
consola.error('Failed to build package, rollback to the previous version.');
|
||||
logger.error('Failed to build package, rollback to the previous version.');
|
||||
setPkgVersion(pkgJson, pkgJsonPath, currentVersion);
|
||||
throw err;
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
import { createSpinner } from 'nanospinner';
|
||||
import color from 'picocolors';
|
||||
import { consola } from 'consola';
|
||||
import { ROOT } from '../common/constant.js';
|
||||
|
||||
export function slimPath(path: string) {
|
||||
return color.yellow(path.replace(ROOT, ''));
|
||||
}
|
||||
|
||||
export { createSpinner, consola };
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { consola } from './logger.js';
|
||||
import { logger } from 'rslog';
|
||||
import { execSync } from 'child_process';
|
||||
import { getVantConfig } from './constant.js';
|
||||
|
||||
@ -28,7 +28,7 @@ export function getPackageManager() {
|
||||
}
|
||||
|
||||
export async function installDependencies() {
|
||||
consola.info('Install Dependencies\n');
|
||||
logger.info('Install Dependencies\n');
|
||||
|
||||
try {
|
||||
const manager = getPackageManager();
|
||||
|
@ -45,7 +45,7 @@ export async function compileSite(production = false) {
|
||||
const require = createRequire(import.meta.url);
|
||||
const { version } = require('vite/package.json');
|
||||
const viteInfo = color.cyan(`vite v${version}`);
|
||||
console.log(`\n ${viteInfo}` + color.green(` dev server running at:\n`));
|
||||
console.log(` ${viteInfo}` + color.green(` dev server running at:\n`));
|
||||
server.printUrls();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { parse } from 'node:path';
|
||||
import fse from 'fs-extra';
|
||||
import { logger } from 'rslog';
|
||||
import { getVantConfig, replaceExt } from '../common/index.js';
|
||||
import { compileCss } from './compile-css.js';
|
||||
import { compileLess } from './compile-less.js';
|
||||
import { compileSass } from './compile-sass.js';
|
||||
import { consola } from '../common/logger.js';
|
||||
|
||||
const { readFileSync, writeFileSync, removeSync } = fse;
|
||||
|
||||
@ -25,7 +25,7 @@ async function compileFile(filePath: string) {
|
||||
const source = readFileSync(filePath, 'utf-8');
|
||||
return await compileCss(source);
|
||||
} catch (err) {
|
||||
consola.error('Compile style failed: ' + filePath);
|
||||
logger.error('Compile style failed: ' + filePath);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
// @ts-ignore
|
||||
import fs from 'node:fs';
|
||||
import { URL, fileURLToPath } from 'node:url';
|
||||
import { logger } from 'rslog';
|
||||
|
||||
const packagePath = fileURLToPath(new URL('../package.json', import.meta.url));
|
||||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
|
||||
export const cliVersion: string = packageJson.version;
|
||||
|
||||
logger.greet(` Vant CLI v${cliVersion}\n`);
|
||||
|
||||
process.env.VANT_CLI_VERSION = cliVersion;
|
||||
|
31
pnpm-lock.yaml
generated
31
pnpm-lock.yaml
generated
@ -29,9 +29,6 @@ importers:
|
||||
|
||||
packages/create-vant-cli-app:
|
||||
dependencies:
|
||||
consola:
|
||||
specifier: ^3.0.2
|
||||
version: 3.2.3
|
||||
enquirer:
|
||||
specifier: 2.3.6
|
||||
version: 2.3.6
|
||||
@ -44,6 +41,9 @@ importers:
|
||||
picocolors:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
rslog:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
devDependencies:
|
||||
'@types/fs-extra':
|
||||
specifier: ^11.0.1
|
||||
@ -172,9 +172,6 @@ importers:
|
||||
commander:
|
||||
specifier: ^11.0.0
|
||||
version: 11.0.0
|
||||
consola:
|
||||
specifier: ^3.0.2
|
||||
version: 3.2.3
|
||||
enquirer:
|
||||
specifier: 2.3.6
|
||||
version: 2.3.6
|
||||
@ -214,9 +211,6 @@ importers:
|
||||
nano-staged:
|
||||
specifier: ^0.8.0
|
||||
version: 0.8.0
|
||||
nanospinner:
|
||||
specifier: ^1.1.0
|
||||
version: 1.1.0
|
||||
picocolors:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
@ -229,6 +223,9 @@ importers:
|
||||
prettier:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.1
|
||||
rslog:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
terser:
|
||||
specifier: ^5.19.2
|
||||
version: 5.19.2
|
||||
@ -1591,11 +1588,6 @@ packages:
|
||||
proto-list: 1.2.4
|
||||
dev: true
|
||||
|
||||
/consola@3.2.3:
|
||||
resolution: {integrity: sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==}
|
||||
engines: {node: ^14.18.0 || >=16.10.0}
|
||||
dev: false
|
||||
|
||||
/convert-source-map@1.9.0:
|
||||
resolution: {integrity: sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==}
|
||||
|
||||
@ -2660,12 +2652,6 @@ packages:
|
||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||
hasBin: true
|
||||
|
||||
/nanospinner@1.1.0:
|
||||
resolution: {integrity: sha512-yFvNYMig4AthKYfHFl1sLj7B2nkHL4lzdig4osvl9/LdGbXwrdFRoqBS98gsEsOakr0yH+r5NZ/1Y9gdVB8trA==}
|
||||
dependencies:
|
||||
picocolors: 1.0.0
|
||||
dev: false
|
||||
|
||||
/natural-compare-lite@1.4.0:
|
||||
resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==}
|
||||
dev: false
|
||||
@ -2956,6 +2942,11 @@ packages:
|
||||
resolution: {integrity: sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==}
|
||||
dev: true
|
||||
|
||||
/rslog@1.0.0:
|
||||
resolution: {integrity: sha512-yTulfJJIYHBftErlZZXHdZuFA8275spDcTrCs8JIXIh+wRIRgi6RGoT8MAnB8H6NIEvJbMUP14Mo1t7hCw4k1g==}
|
||||
engines: {node: '>=14.17.6'}
|
||||
dev: false
|
||||
|
||||
/run-parallel@1.2.0:
|
||||
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
|
||||
dependencies:
|
||||
|
Loading…
x
Reference in New Issue
Block a user