mirror of
https://github.com/youzan/vant.git
synced 2025-10-16 16:04:04 +00:00
feat(cli): using rslog (#12334)
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user