浏览代码

chore: update npm script

vben 4 年之前
父节点
当前提交
2be166d6a1
共有 9 个文件被更改,包括 268 次插入449 次删除
  1. 3 0
      .browserslistrc
  2. 0 52
      build/jsc.ts
  3. 2 0
      build/script/changelog.ts
  4. 0 40
      build/script/cli.ts
  5. 2 1
      build/script/postBuild.ts
  6. 10 13
      build/script/preserve.ts
  7. 26 26
      build/script/preview.ts
  8. 10 10
      package.json
  9. 215 307
      yarn.lock

+ 3 - 0
.browserslistrc

@@ -0,0 +1,3 @@
+> 1%
+last 2 versions
+not ie <= 10

+ 0 - 52
build/jsc.ts

@@ -1,52 +0,0 @@
-// 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,
-    }
-  );
-}

+ 2 - 0
build/script/changelog.ts

@@ -22,3 +22,5 @@ export const runChangeLog = async () => {
     process.exit(1);
   }
 };
+
+runChangeLog();

+ 0 - 40
build/script/cli.ts

@@ -1,40 +0,0 @@
-#!/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 {};

+ 2 - 1
build/script/build.ts → build/script/postBuild.ts

@@ -12,7 +12,7 @@ export const runBuild = async (preview = false) => {
   try {
     const argvList = argv._;
     if (preview) {
-      let cmd = `cross-env NODE_ENV=production vite build`;
+      let cmd = `npm run build`;
       await sh(cmd, {
         async: true,
         nopipe: true,
@@ -33,3 +33,4 @@ export const runBuild = async (preview = false) => {
     process.exit(1);
   }
 };
+runBuild();

+ 10 - 13
build/script/preserve.ts

@@ -4,29 +4,26 @@ import path from 'path';
 import fs from 'fs-extra';
 import { isEqual } from 'lodash';
 import { sh } from 'tasksfile';
-import {
-  successConsole,
-  //  errorConsole
-} from '../utils';
+import { successConsole, errorConsole } from '../utils';
 
 const resolve = (dir: string) => {
   return path.resolve(process.cwd(), dir);
 };
 
-// const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/;
+const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/;
 
 let NEED_INSTALL = false;
 
 export async function runPreserve() {
   // rc.6 fixed
-  // const cwdPath = process.cwd();
-  // if (reg.test(cwdPath)) {
-  //   errorConsole(
-  //     'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!'
-  //   );
-  //   errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!');
-  //   process.exit(1);
-  // }
+  const cwdPath = process.cwd();
+  if (reg.test(cwdPath)) {
+    errorConsole(
+      'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!'
+    );
+    errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!');
+    process.exit(1);
+  }
 
   fs.mkdirp(resolve('build/.cache'));
   function checkPkgUpdate() {

+ 26 - 26
build/script/preview.ts

@@ -1,15 +1,15 @@
 import chalk from 'chalk';
 import Koa from 'koa';
-import inquirer from 'inquirer';
+// import inquirer from 'inquirer';
 import staticServer from 'koa-static';
 import portfinder from 'portfinder';
 import { resolve } from 'path';
 import viteConfig from '../../vite.config';
 import { getIPAddress } from '../utils';
-import { runBuild } from './build';
+// import { runBuild } from './postBuild';
 
-const BUILD = 1;
-const NO_BUILD = 2;
+// const BUILD = 1;
+// const NO_BUILD = 2;
 
 // start server
 const startApp = () => {
@@ -35,25 +35,25 @@ const startApp = () => {
   });
 };
 
-export const runPreview = async () => {
-  const prompt = inquirer.prompt({
-    type: 'list',
-    message: 'Please select a preview method',
-    name: 'type',
-    choices: [
-      {
-        name: 'Preview after packaging',
-        value: BUILD,
-      },
-      {
-        name: `No packaging, preview directly (need to have dist file after packaging)`,
-        value: NO_BUILD,
-      },
-    ],
-  });
-  const { type } = await prompt;
-  if (type === BUILD) {
-    await runBuild(true);
-  }
-  startApp();
-};
+// export const runPreview = async () => {
+//   // const prompt = inquirer.prompt({
+//   //   type: 'list',
+//   //   message: 'Please select a preview method',
+//   //   name: 'type',
+//   //   choices: [
+//   //     {
+//   //       name: 'Preview after packaging',
+//   //       value: BUILD,
+//   //     },
+//   //     {
+//   //       name: `No packaging, preview directly (need to have dist file after packaging)`,
+//   //       value: NO_BUILD,
+//   //     },
+//   //   ],
+//   // });
+//   const { type } = await prompt;
+//   if (type === BUILD) {
+//     await runBuild(true);
+//   }
+// };
+startApp();

+ 10 - 10
package.json

@@ -2,21 +2,22 @@
   "name": "vben-admin-2.0",
   "version": "2.0.0-rc.5",
   "scripts": {
-    "bootstrap": "yarn install || npm install",
-    "serve": "cross-env ts-node --files -P  ./build/tsconfig.json ./build/script/preserve && cross-env NODE_ENV=development vite",
-    "build": "cross-env NODE_ENV=production vite build && node ./build/jsc.ts build",
+    "bootstrap": "yarn install",
+    "serve": "esno ./build/script/preserve.ts && cross-env NODE_ENV=development vite",
+    "build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
     "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 ",
-    "preview": "node ./build/jsc.ts preview",
-    "log": "node ./build/jsc.ts log",
+    "preview": "npm run build && esno ./build/script/preview.ts",
+    "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:lib": "npx rimraf node_modules",
     "ls-lint": "npx ls-lint",
     "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: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": {
     "@iconify/iconify": "^2.0.0-rc.1",
@@ -42,13 +43,12 @@
   "devDependencies": {
     "@commitlint/cli": "^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",
     "@purge-icons/generated": "^0.4.1",
     "@types/echarts": "^4.8.3",
     "@types/fs-extra": "^9.0.2",
     "@types/html-minifier": "^4.0.0",
-    "@types/inquirer": "^7.3.1",
     "@types/koa-static": "^4.0.1",
     "@types/lodash-es": "^4.17.3",
     "@types/mockjs": "^1.0.3",
@@ -70,10 +70,10 @@
     "eslint-config-prettier": "^6.14.0",
     "eslint-plugin-prettier": "^3.1.4",
     "eslint-plugin-vue": "^7.1.0",
+    "esno": "^0.2.4",
     "fs-extra": "^9.0.1",
     "html-minifier": "^4.0.0",
     "husky": "^4.3.0",
-    "inquirer": "^7.3.3",
     "koa-static": "^5.0.0",
     "less": "^3.12.2",
     "lint-staged": "^10.4.2",

文件差异内容过多而无法显示
+ 215 - 307
yarn.lock


部分文件因为文件数量过多而无法显示