提交 2be166d6 作者: vben

chore: update npm script

上级 adffefd7
> 1%
last 2 versions
not ie <= 10
// js调用cli 兼容调用ts
const { sh } = require('tasksfile');
const { argv } = require('yargs');
// const execa = require('execa');
let command = ``;
Object.keys(argv).forEach((key) => {
if (!/^\$/.test(key) && key !== '_') {
// @ts-ignore
if (argv[key]) {
command += `--${key} `;
}
}
});
// 执行任务名称
let taskList = argv._;
let NODE_ENV = process.env.NODE_ENV || 'development';
if (taskList.includes('build') || taskList.includes('report') || taskList.includes('preview')) {
NODE_ENV = 'production';
}
if (taskList && Array.isArray(taskList) && taskList.length) {
// execa(
// 'cross-env',
// [
// `NODE_ENV=${NODE_ENV}`,
// 'ts-node',
// '--project',
// './build/tsconfig.json',
// './build/script/cli.ts',
// taskList.join(' '),
// command,
// ],
// {
// stdio: 'inherit',
// }
// );
sh(
`cross-env NODE_ENV=${NODE_ENV} ts-node --files -P ./build/tsconfig.json ./build/script/cli.ts ${taskList.join(
' '
)} ${command}`,
{
async: true,
nopipe: true,
}
);
}
...@@ -22,3 +22,5 @@ export const runChangeLog = async () => { ...@@ -22,3 +22,5 @@ export const runChangeLog = async () => {
process.exit(1); process.exit(1);
} }
}; };
runChangeLog();
#!/usr/bin/env node
import chalk from 'chalk';
import { argv } from 'yargs';
import { runChangeLog } from './changelog';
import { runPreview } from './preview';
// import { runPreserve } from './preserve';
import { runBuild } from './build';
const task = (argv._ || [])[0];
console.log('Run Task: ' + chalk.cyan(task));
switch (task) {
// change log
case 'log':
runChangeLog();
break;
case 'build':
runBuild();
break;
// case 'preserve':
// runPreserve();
// break;
case 'preview':
runPreview();
break;
// TODO
case 'gzip':
break;
default:
break;
}
export default {};
...@@ -12,7 +12,7 @@ export const runBuild = async (preview = false) => { ...@@ -12,7 +12,7 @@ export const runBuild = async (preview = false) => {
try { try {
const argvList = argv._; const argvList = argv._;
if (preview) { if (preview) {
let cmd = `cross-env NODE_ENV=production vite build`; let cmd = `npm run build`;
await sh(cmd, { await sh(cmd, {
async: true, async: true,
nopipe: true, nopipe: true,
...@@ -33,3 +33,4 @@ export const runBuild = async (preview = false) => { ...@@ -33,3 +33,4 @@ export const runBuild = async (preview = false) => {
process.exit(1); process.exit(1);
} }
}; };
runBuild();
...@@ -4,29 +4,26 @@ import path from 'path'; ...@@ -4,29 +4,26 @@ import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import { sh } from 'tasksfile'; import { sh } from 'tasksfile';
import { import { successConsole, errorConsole } from '../utils';
successConsole,
// errorConsole
} from '../utils';
const resolve = (dir: string) => { const resolve = (dir: string) => {
return path.resolve(process.cwd(), dir); return path.resolve(process.cwd(), dir);
}; };
// const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/; const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/;
let NEED_INSTALL = false; let NEED_INSTALL = false;
export async function runPreserve() { export async function runPreserve() {
// rc.6 fixed // rc.6 fixed
// const cwdPath = process.cwd(); const cwdPath = process.cwd();
// if (reg.test(cwdPath)) { if (reg.test(cwdPath)) {
// errorConsole( errorConsole(
// 'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!' 'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!'
// ); );
// errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!'); errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!');
// process.exit(1); process.exit(1);
// } }
fs.mkdirp(resolve('build/.cache')); fs.mkdirp(resolve('build/.cache'));
function checkPkgUpdate() { function checkPkgUpdate() {
......
import chalk from 'chalk'; import chalk from 'chalk';
import Koa from 'koa'; import Koa from 'koa';
import inquirer from 'inquirer'; // import inquirer from 'inquirer';
import staticServer from 'koa-static'; import staticServer from 'koa-static';
import portfinder from 'portfinder'; import portfinder from 'portfinder';
import { resolve } from 'path'; import { resolve } from 'path';
import viteConfig from '../../vite.config'; import viteConfig from '../../vite.config';
import { getIPAddress } from '../utils'; import { getIPAddress } from '../utils';
import { runBuild } from './build'; // import { runBuild } from './postBuild';
const BUILD = 1; // const BUILD = 1;
const NO_BUILD = 2; // const NO_BUILD = 2;
// start server // start server
const startApp = () => { const startApp = () => {
...@@ -35,25 +35,25 @@ const startApp = () => { ...@@ -35,25 +35,25 @@ const startApp = () => {
}); });
}; };
export const runPreview = async () => { // export const runPreview = async () => {
const prompt = inquirer.prompt({ // // const prompt = inquirer.prompt({
type: 'list', // // type: 'list',
message: 'Please select a preview method', // // message: 'Please select a preview method',
name: 'type', // // name: 'type',
choices: [ // // choices: [
{ // // {
name: 'Preview after packaging', // // name: 'Preview after packaging',
value: BUILD, // // value: BUILD,
}, // // },
{ // // {
name: `No packaging, preview directly (need to have dist file after packaging)`, // // name: `No packaging, preview directly (need to have dist file after packaging)`,
value: NO_BUILD, // // value: NO_BUILD,
}, // // },
], // // ],
}); // // });
const { type } = await prompt; // const { type } = await prompt;
if (type === BUILD) { // if (type === BUILD) {
await runBuild(true); // await runBuild(true);
} // }
startApp(); // };
}; startApp();
...@@ -2,21 +2,22 @@ ...@@ -2,21 +2,22 @@
"name": "vben-admin-2.0", "name": "vben-admin-2.0",
"version": "2.0.0-rc.5", "version": "2.0.0-rc.5",
"scripts": { "scripts": {
"bootstrap": "yarn install || npm install", "bootstrap": "yarn install",
"serve": "cross-env ts-node --files -P ./build/tsconfig.json ./build/script/preserve && cross-env NODE_ENV=development vite", "serve": "esno ./build/script/preserve.ts && cross-env NODE_ENV=development vite",
"build": "cross-env NODE_ENV=production vite build && node ./build/jsc.ts build", "build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
"build:site": "cross-env SITE=true npm run build ", "build:site": "cross-env SITE=true npm run build ",
"build:no-cache": "yarn clean:cache && node ./build/jsc.ts build", "build:no-cache": "yarn clean:cache && npm run build",
"report": "cross-env REPORT=true npm run build ", "report": "cross-env REPORT=true npm run build ",
"preview": "node ./build/jsc.ts preview", "preview": "npm run build && esno ./build/script/preview.ts",
"log": "node ./build/jsc.ts log", "preview:dist": "esno ./build/script/preview.ts",
"log": "esno ./build/script/changelog.ts",
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite_opt_cache", "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite_opt_cache",
"clean:lib": "npx rimraf node_modules", "clean:lib": "npx rimraf node_modules",
"ls-lint": "npx ls-lint", "ls-lint": "npx ls-lint",
"lint:eslint": "eslint --fix --ext \"src/**/*.{vue,less,css,scss}\"", "lint:eslint": "eslint --fix --ext \"src/**/*.{vue,less,css,scss}\"",
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"", "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
"lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
"reinstall": "rimraf node_modules && rimraf yarn.lock && rimraf package.lock.json && npm run bootstrap" "reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap"
}, },
"dependencies": { "dependencies": {
"@iconify/iconify": "^2.0.0-rc.1", "@iconify/iconify": "^2.0.0-rc.1",
...@@ -42,13 +43,12 @@ ...@@ -42,13 +43,12 @@
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^11.0.0", "@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0", "@commitlint/config-conventional": "^11.0.0",
"@iconify/json": "^1.1.246", "@iconify/json": "^1.1.247",
"@ls-lint/ls-lint": "^1.9.2", "@ls-lint/ls-lint": "^1.9.2",
"@purge-icons/generated": "^0.4.1", "@purge-icons/generated": "^0.4.1",
"@types/echarts": "^4.8.3", "@types/echarts": "^4.8.3",
"@types/fs-extra": "^9.0.2", "@types/fs-extra": "^9.0.2",
"@types/html-minifier": "^4.0.0", "@types/html-minifier": "^4.0.0",
"@types/inquirer": "^7.3.1",
"@types/koa-static": "^4.0.1", "@types/koa-static": "^4.0.1",
"@types/lodash-es": "^4.17.3", "@types/lodash-es": "^4.17.3",
"@types/mockjs": "^1.0.3", "@types/mockjs": "^1.0.3",
...@@ -70,10 +70,10 @@ ...@@ -70,10 +70,10 @@
"eslint-config-prettier": "^6.14.0", "eslint-config-prettier": "^6.14.0",
"eslint-plugin-prettier": "^3.1.4", "eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-vue": "^7.1.0", "eslint-plugin-vue": "^7.1.0",
"esno": "^0.2.4",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"html-minifier": "^4.0.0", "html-minifier": "^4.0.0",
"husky": "^4.3.0", "husky": "^4.3.0",
"inquirer": "^7.3.3",
"koa-static": "^5.0.0", "koa-static": "^5.0.0",
"less": "^3.12.2", "less": "^3.12.2",
"lint-staged": "^10.4.2", "lint-staged": "^10.4.2",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论