@qse/edu-scripts 1.13.7 → 1.13.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/app.d.ts +10 -0
  3. package/docs/feat.md +84 -0
  4. package/docs/override.md +7 -0
  5. package/lib/auto-refactor.js +88 -95
  6. package/lib/build.js +33 -36
  7. package/lib/cli.js +64 -61
  8. package/lib/commit-dist.js +40 -54
  9. package/lib/config/babel.dependencies.js +41 -39
  10. package/lib/config/babel.js +82 -55
  11. package/lib/config/paths.js +28 -30
  12. package/lib/config/plugins/mock-server/defineMock.d.ts +6 -0
  13. package/lib/config/plugins/mock-server/defineMock.js +31 -0
  14. package/lib/config/plugins/mock-server/index.js +69 -0
  15. package/lib/config/plugins/postcss-safe-area.js +12 -12
  16. package/lib/config/webpackConfig.js +360 -325
  17. package/lib/config/webpackDevServerConfig.js +27 -29
  18. package/lib/deploy.js +58 -100
  19. package/lib/generator.js +49 -81
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +29 -9
  22. package/lib/start.js +16 -22
  23. package/lib/utils/FileSizeReporter.js +45 -56
  24. package/lib/utils/appConfig.js +12 -13
  25. package/lib/utils/beforeStart.js +35 -35
  26. package/lib/utils/changeDeployVersion.js +36 -65
  27. package/lib/utils/defineConfig.d.ts +7 -0
  28. package/lib/utils/defineConfig.js +27 -5
  29. package/lib/utils/exec.js +5 -9
  30. package/lib/utils/getConfig.js +6 -7
  31. package/lib/utils/getOverride.js +13 -17
  32. package/package.json +32 -29
  33. package/src/config/paths.js +1 -0
  34. package/src/config/plugins/mock-server/defineMock.ts +12 -0
  35. package/src/config/plugins/mock-server/index.js +92 -0
  36. package/src/config/webpackConfig.js +9 -2
  37. package/src/config/webpackDevServerConfig.js +8 -0
  38. package/src/index.ts +1 -0
  39. package/src/utils/defineConfig.ts +8 -1
package/CHANGELOG.md CHANGED
@@ -1,8 +1,21 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.13.9 (2023-08-10)
4
+
5
+ - feat: 增加 mock 功能
6
+
7
+ ## 1.13.8 (2023-07-25)
8
+
9
+ - feat: 支持 markdown 导入
10
+ - feat: 支持 `import content from '*?raw'` 导入规则
11
+ - feat: babel-loader include 修改成 exclude: /node_modules/
12
+ - chore: 升级打包工具
13
+ - chore: 升级依赖版本,尝试移除 stable 依赖警告
14
+ - chore: 最低 nodejs 版本要求 14
15
+
3
16
  ## 1.13.7 (2023-07-20)
4
17
 
5
- - feat: 关闭 derServer.client.overlay.runtimeError
18
+ - feat: 关闭 derServer.client.overlay.runtimeError
6
19
 
7
20
  ## 1.13.6 (2023-06-13)
8
21
 
package/app.d.ts CHANGED
@@ -46,6 +46,16 @@ declare module '*.webp' {
46
46
  export default src
47
47
  }
48
48
 
49
+ declare module '*.md' {
50
+ const content: string
51
+ export default content
52
+ }
53
+
54
+ declare module '*?raw' {
55
+ const content: string
56
+ export default content
57
+ }
58
+
49
59
  declare module '*.svg' {
50
60
  import * as React from 'react'
51
61
 
package/docs/feat.md CHANGED
@@ -81,3 +81,87 @@ export default () => (
81
81
  为所有 `overflow: auto/scroll` 自动增加 `-webkit-overflow-scrolling: touch`
82
82
 
83
83
  为所有 `env(safe-area-inset-*)` 增加 fallback
84
+
85
+ ## Mock
86
+
87
+ 项目内建 mock 服务器,支持热更新,可以在 development 环境下使用
88
+
89
+ mock 功能会根据 mock 文件夹自动判断是否开启
90
+
91
+ 可以通过 override.config.js 文件配置 mock 参数关闭该功能
92
+
93
+ ### 使用步骤
94
+
95
+ 根目录创建 mock 文件夹,在该文件夹下创建的所有 js、ts 文件都会被自动加载,可以创建多层级文件夹
96
+
97
+ ```js
98
+ // path: /mock/index.js
99
+ // path: /mock/depth/folder/index.js 支持深层文件
100
+
101
+ import { defineMock } from '@qse/edu-scripts'
102
+
103
+ export default defineMock({
104
+ 'GET /api/test/test': { hello: 'world' },
105
+ 'GET /api/test/test2': [1, 2, 3],
106
+ 'POST /api/test2/test': (req, res) => {
107
+ console.log(req.body, req.cookies)
108
+ res.json({ foo: 'bar' })
109
+ },
110
+ })
111
+ ```
112
+
113
+ ### mock 规则
114
+
115
+ ```ts
116
+ import type { RequestHandler } from 'express'
117
+ type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'
118
+ type API = string
119
+
120
+ export type MockConfig = Record<
121
+ `${Method} ${API}`,
122
+ string | number | null | undefined | boolean | Record<string, any> | RequestHandler
123
+ >
124
+
125
+ export function defineMock(config: MockConfig) {
126
+ return config
127
+ }
128
+ ```
129
+
130
+ mock 名称是由 method 和 apiUrl 组成的,按这种规则去匹配
131
+
132
+ 所有 mock 文件最终会被合并到一起,形成一个大的对象。**所以当出现同名的 mock,前面的会被后面的覆盖**
133
+
134
+ 可以通过下面的方式去获取参数
135
+
136
+ - `req.body` 获取 body 参数
137
+ - `req.query` 获取链接上的参数
138
+ - `req.cookies` 获取 cookies
139
+
140
+ <Alert>mock 规则比 proxy 具有更高的优先级,如果匹配中了 mock,就会不再去 proxy 了</Alert>
141
+
142
+ ```ts
143
+ // path: /mock/index.ts
144
+ import Mock from 'mockjs'
145
+
146
+ export default {
147
+ // method 必须是大写。可以直接返回数据
148
+ 'GET /api/test': { hello: 'world' },
149
+
150
+ // 可以通过 express.requestHandler 处理请求。能实现自定义内容,发送文件等
151
+ 'POST /api/test2': (req, res) => {
152
+ // 例如:将 body 内容返回
153
+ res.json(req.body)
154
+ },
155
+
156
+ // 可以通过第三方库生成 mock 数据
157
+ 'POST /api/test3': Mock.mock({
158
+ // 属性 list 的值是一个数组,其中含有 1 到 10 个元素
159
+ 'list|1-10': [
160
+ {
161
+ // 属性 id 是一个自增数,起始值为 1,每次增 1
162
+ 'id|+1': 1,
163
+ },
164
+ ],
165
+ }),
166
+ }
167
+ ```
package/docs/override.md CHANGED
@@ -46,6 +46,13 @@ export type Config = {
46
46
  */
47
47
  proxy?: ProxyConfigArray
48
48
  extraPostCSSPlugins?: any[]
49
+ /**
50
+ * 开启 mock 功能,会自动加载 mock 文件夹下的文件
51
+ *
52
+ * 默认情况下自动判断根目录是否存在 mock 文件夹,如果存在则开启 mock 功能。
53
+ * 如果设置 false,会关闭 mock 功能
54
+ */
55
+ mock?: boolean
49
56
  }
50
57
  ```
51
58
 
@@ -1,21 +1,13 @@
1
- "use strict";
2
-
3
- const fs = require('fs-extra');
4
- const paths = require('./config/paths');
5
- const path = require('path');
6
- const chalk = require('chalk');
7
- const pkg = require('../package.json');
8
- const glob = require('globby');
9
- const ora = require('ora');
10
- const {
11
- prompt
12
- } = require('inquirer');
13
- const open = require('open');
14
-
15
- /**
16
- * @param {string} msg
17
- * @param {(spinner:ora.Ora) => void | Promise<void>} callback
18
- */
1
+ // src/auto-refactor.js
2
+ var fs = require("fs-extra");
3
+ var paths = require("./config/paths");
4
+ var path = require("path");
5
+ var chalk = require("chalk");
6
+ var pkg = require("../package.json");
7
+ var glob = require("globby");
8
+ var ora = require("ora");
9
+ var { prompt } = require("inquirer");
10
+ var open = require("open");
19
11
  async function step(msg, callback) {
20
12
  const spinner = ora(msg).start();
21
13
  try {
@@ -28,105 +20,102 @@ async function step(msg, callback) {
28
20
  }
29
21
  module.exports = async function autoRefactor() {
30
22
  if (await fs.pathExists(paths.public)) {
31
- console.log(chalk.green('已完成改造,不需要重复执行,如果运行报错请查看文档'));
23
+ console.log(chalk.green("已完成改造,不需要重复执行,如果运行报错请查看文档"));
32
24
  console.log(`文档: ${chalk.underline(pkg.homepage)}`);
33
25
  process.exit(0);
34
26
  }
35
27
  const appPkg = require(paths.package);
36
- const answers = await prompt([{
37
- type: 'input',
38
- name: 'name',
39
- message: '请输入模块名称,要求唯一,不能与其他工程相同',
40
- default: appPkg.name,
41
- validate: v => /^[a-z][a-z0-9_-]+$/.test(v) || '请按格式输入 /^[a-z][a-z0-9_-]+$/ 只能使用小写字母、连字符、下划线'
42
- }, {
43
- type: 'input',
44
- name: 'version',
45
- message: '版本号',
46
- default: '1.0.0',
47
- validate: v => /^\d+\.\d+\.\d+$/.test(v) || '请按格式输入 /^\\d+\\.\\d+\\.\\d+$/ 例如: 1.0.0'
48
- }, {
49
- type: 'list',
50
- name: 'mode',
51
- message: '项目使用的哪种模式',
52
- choices: [{
53
- name: '教育子工程模式',
54
- value: ''
55
- }, {
56
- name: '教育主工程模式',
57
- value: 'main'
58
- }, {
59
- name: '独立模式',
60
- value: 'single'
61
- }]
62
- }, {
63
- type: 'checkbox',
64
- name: 'deploy',
65
- message: '项目需要部署到哪里',
66
- when: ans => ans.mode !== 'single',
67
- choices: [{
68
- name: '校端',
69
- value: '-s'
70
- }, {
71
- name: '局端',
72
- value: '-b'
73
- }, {
74
- name: '公文端',
75
- value: '-d'
76
- }],
77
- validate: v => !!v && v.length > 0 || '必须选一个'
78
- }]);
28
+ const answers = await prompt([
29
+ {
30
+ type: "input",
31
+ name: "name",
32
+ message: "请输入模块名称,要求唯一,不能与其他工程相同",
33
+ default: appPkg.name,
34
+ validate: (v) => /^[a-z][a-z0-9_-]+$/.test(v) || "请按格式输入 /^[a-z][a-z0-9_-]+$/ 只能使用小写字母、连字符、下划线"
35
+ },
36
+ {
37
+ type: "input",
38
+ name: "version",
39
+ message: "版本号",
40
+ default: "1.0.0",
41
+ validate: (v) => /^\d+\.\d+\.\d+$/.test(v) || "请按格式输入 /^\\d+\\.\\d+\\.\\d+$/ 例如: 1.0.0"
42
+ },
43
+ {
44
+ type: "list",
45
+ name: "mode",
46
+ message: "项目使用的哪种模式",
47
+ choices: [
48
+ { name: "教育子工程模式", value: "" },
49
+ { name: "教育主工程模式", value: "main" },
50
+ { name: "独立模式", value: "single" }
51
+ ]
52
+ },
53
+ {
54
+ type: "checkbox",
55
+ name: "deploy",
56
+ message: "项目需要部署到哪里",
57
+ when: (ans) => ans.mode !== "single",
58
+ choices: [
59
+ { name: "校端", value: "-s" },
60
+ { name: "局端", value: "-b" },
61
+ { name: "公文端", value: "-d" }
62
+ ],
63
+ validate: (v) => !!v && v.length > 0 || "必须选一个"
64
+ }
65
+ ]);
79
66
  appPkg.name = answers.name;
80
67
  appPkg.version = answers.version;
81
- await step('创建 public 文件夹', async () => {
68
+ await step("创建 public 文件夹", async () => {
82
69
  await fs.mkdir(paths.public);
83
70
  });
84
- await step('移动 js 文件夹', async () => {
85
- if (await fs.pathExists(path.resolve(paths.src, 'js'))) {
86
- await fs.move(path.resolve(paths.src, 'js'), path.resolve(paths.public, 'js'));
71
+ await step("移动 js 文件夹", async () => {
72
+ if (await fs.pathExists(path.resolve(paths.src, "js"))) {
73
+ await fs.move(path.resolve(paths.src, "js"), path.resolve(paths.public, "js"));
87
74
  }
88
75
  });
89
- await step('移动 html 文件', async () => {
90
- const HTMLFiles = await glob('*.html', {
91
- cwd: paths.src
92
- });
76
+ await step("移动 html 文件", async () => {
77
+ const HTMLFiles = await glob("*.html", { cwd: paths.src });
93
78
  for (const file of HTMLFiles) {
94
79
  await fs.move(path.resolve(paths.src, file), path.resolve(paths.public, file));
95
80
  }
96
81
  });
97
- await step('删除 dll 文件夹', async () => {
98
- if (await fs.pathExists(path.resolve(paths.src, 'dll'))) {
99
- await fs.remove(path.resolve(paths.src, 'dll'));
82
+ await step("删除 dll 文件夹", async () => {
83
+ if (await fs.pathExists(path.resolve(paths.src, "dll"))) {
84
+ await fs.remove(path.resolve(paths.src, "dll"));
100
85
  }
101
86
  });
102
- await step('删除没用的 babel 和 webpack 配置', async () => {
103
- const deleteFiles = [...(await glob('{.,*}babel*')), ...(await glob('*webpack*')), ...(await glob('package-lock.json')), paths.nodeModules, paths.sshSftp];
87
+ await step("删除没用的 babel 和 webpack 配置", async () => {
88
+ const deleteFiles = [
89
+ ...await glob("{.,*}babel*"),
90
+ ...await glob("*webpack*"),
91
+ ...await glob("package-lock.json"),
92
+ paths.nodeModules,
93
+ paths.sshSftp
94
+ ];
104
95
  for (const filePath of deleteFiles) {
105
96
  await fs.remove(filePath);
106
97
  }
107
98
  });
108
- await step('设置项目模式', () => {
99
+ await step("设置项目模式", () => {
109
100
  if (answers.mode) {
110
- appPkg.edu = {
111
- mode: answers.mode
112
- };
101
+ appPkg.edu = { mode: answers.mode };
113
102
  }
114
103
  });
115
- await step('修改 package.json 的 scripts', () => {
104
+ await step("修改 package.json 的 scripts", () => {
116
105
  const scripts = appPkg.scripts;
117
- scripts.start = 'edu-scripts start';
118
- scripts.build = 'edu-scripts build';
119
- scripts.analyze = 'edu-scripts build --analyze';
120
- if (answers.mode !== 'single') {
121
- scripts.deploy = `edu-scripts deploy ${answers.deploy.join(' ')}`;
106
+ scripts.start = "edu-scripts start";
107
+ scripts.build = "edu-scripts build";
108
+ scripts.analyze = "edu-scripts build --analyze";
109
+ if (answers.mode !== "single") {
110
+ scripts.deploy = `edu-scripts deploy ${answers.deploy.join(" ")}`;
122
111
  } else {
123
112
  scripts.deploy = `edu-scripts deploy`;
124
- scripts['commit-dist'] = 'edu-scripts commit-dist --rm-local';
113
+ scripts["commit-dist"] = "edu-scripts commit-dist --rm-local";
125
114
  }
126
- scripts['one-key-deploy'] = 'npm version patch';
127
- scripts.postversion = 'npm run build && npm run deploy';
115
+ scripts["one-key-deploy"] = "npm version patch";
116
+ scripts.postversion = "npm run build && npm run deploy";
128
117
  });
129
- await step('删除 babel/webpack 相关依赖', spinner => {
118
+ await step("删除 babel/webpack 相关依赖", (spinner) => {
130
119
  const deleteRe = /(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa|prettier)/i;
131
120
  const deletePkgs = {
132
121
  dependencies: [],
@@ -143,16 +132,20 @@ module.exports = async function autoRefactor() {
143
132
  }
144
133
  });
145
134
  spinner.clear();
146
- console.log(`删除的pkgs\n${chalk.green(JSON.stringify(deletePkgs, null, 2))}\n`);
147
- appPkg.devDependencies['@qse/edu-scripts'] = '^' + pkg.version;
135
+ console.log(`删除的pkgs
136
+ ${chalk.green(JSON.stringify(deletePkgs, null, 2))}
137
+ `);
138
+ appPkg.devDependencies["@qse/edu-scripts"] = "^" + pkg.version;
148
139
  });
149
- await fs.writeFile(paths.package, JSON.stringify(appPkg, null, 2), 'utf-8');
140
+ await fs.writeFile(paths.package, JSON.stringify(appPkg, null, 2), "utf-8");
150
141
  open(`${pkg.homepage}#/refactor`);
151
- console.log(chalk.green(`
142
+ console.log(
143
+ chalk.green(`
152
144
  改造还未完成,剩余步骤请查看文档
153
145
  ${pkg.homepage}#/refactor
154
146
 
155
147
  运行 npm i 安装依赖
156
148
  运行 edu-scripts start 启动服务
157
- `));
158
- };
149
+ `)
150
+ );
151
+ };
package/lib/build.js CHANGED
@@ -1,65 +1,62 @@
1
- "use strict";
2
-
3
- process.env.NODE_ENV = 'production';
4
- process.env.BABEL_ENV = 'production';
5
- process.env.BROWSERSLIST = '>0.2%, not dead, not op_mini all';
6
- const webpack = require('webpack');
7
- const chalk = require('chalk');
8
- const getConfig = require('./utils/getConfig');
9
- const {
1
+ // src/build.js
2
+ process.env.NODE_ENV = "production";
3
+ process.env.BABEL_ENV = "production";
4
+ process.env.BROWSERSLIST = ">0.2%, not dead, not op_mini all";
5
+ var webpack = require("webpack");
6
+ var chalk = require("chalk");
7
+ var getConfig = require("./utils/getConfig");
8
+ var {
10
9
  measureFileSizesBeforeBuild,
11
10
  printFileSizesAfterBuild
12
- } = require('./utils/FileSizeReporter');
13
- const paths = require('./config/paths');
14
- const fs = require('fs-extra');
15
- const appConfig = require('./utils/appConfig');
16
- const WARN_AFTER_BUNDLE_GZIP_SIZE = appConfig.single ? 1024 * 1024 : 30 * 1024;
17
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
11
+ } = require("./utils/FileSizeReporter");
12
+ var paths = require("./config/paths");
13
+ var fs = require("fs-extra");
14
+ var appConfig = require("./utils/appConfig");
15
+ var WARN_AFTER_BUNDLE_GZIP_SIZE = appConfig.single ? 1024 * 1024 : 30 * 1024;
16
+ var WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
18
17
  module.exports = async function build(args) {
19
18
  if (args.analyze) {
20
- process.env.ANALYZE = '1';
19
+ process.env.ANALYZE = "1";
21
20
  }
22
21
  if (args.outputHtml) {
23
- process.env.OUTPUT_HTML = '1';
22
+ process.env.OUTPUT_HTML = "1";
24
23
  }
25
24
  const previousSizeMap = await measureFileSizesBeforeBuild(paths.dist);
26
25
  fs.emptyDirSync(paths.dist);
27
26
  if (appConfig.single) {
28
- fs.copySync(paths.public, paths.resolveApp('dist'));
27
+ fs.copySync(paths.public, paths.resolveApp("dist"));
29
28
  }
30
29
  if (appConfig.mainProject && fs.existsSync(paths.static)) {
31
- fs.copySync(paths.static, paths.resolveApp('dist', 'static'));
30
+ fs.copySync(paths.static, paths.resolveApp("dist", "static"));
32
31
  }
33
32
  webpack(getConfig(args), (error, stats) => {
34
33
  if (error) {
35
- console.log(chalk.red('编译失败'));
34
+ console.log(chalk.red("编译失败"));
36
35
  console.log(chalk.red(error.message || error));
37
36
  console.log();
38
37
  process.exit(1);
39
38
  }
40
39
  if (stats.compilation.errors.length) {
41
- console.log(chalk.red('编译失败'));
42
- console.log(stats.toString({
43
- all: false,
44
- errors: true,
45
- colors: true
46
- }));
40
+ console.log(chalk.red("编译失败"));
41
+ console.log(stats.toString({ all: false, errors: true, colors: true }));
47
42
  process.exit(1);
48
43
  }
49
- console.log(stats.toString({
50
- colors: true,
51
- preset: 'errors-warnings',
52
- timings: true
53
- }));
44
+ console.log(stats.toString({ colors: true, preset: "errors-warnings", timings: true }));
54
45
  console.log();
55
- console.log('gzip 后文件大小:\n');
56
- printFileSizesAfterBuild(stats, previousSizeMap, paths.dist, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
46
+ console.log("gzip 后文件大小:\n");
47
+ printFileSizesAfterBuild(
48
+ stats,
49
+ previousSizeMap,
50
+ paths.dist,
51
+ WARN_AFTER_BUNDLE_GZIP_SIZE,
52
+ WARN_AFTER_CHUNK_GZIP_SIZE
53
+ );
57
54
  console.log();
58
55
  if (appConfig.single) {
59
- console.log(`打包完成,可以使用 ${chalk.green('@qse/ssh-sftp')} 自动部署代码到 v1`);
56
+ console.log(`打包完成,可以使用 ${chalk.green("@qse/ssh-sftp")} 自动部署代码到 v1`);
60
57
  } else {
61
- console.log(`打包完成,可以运行 ${chalk.green('npx edu-scripts deploy')} 部署代码到 v1`);
58
+ console.log(`打包完成,可以运行 ${chalk.green("npx edu-scripts deploy")} 部署代码到 v1`);
62
59
  }
63
60
  console.log();
64
61
  });
65
- };
62
+ };
package/lib/cli.js CHANGED
@@ -1,63 +1,66 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
2
 
4
- const pkg = require('../package.json');
5
-
6
- // 检查运行条件
7
- require('./utils/beforeStart');
8
-
9
- // eslint-disable-next-line no-unused-expressions
10
- require('yargs').usage(`教育工程化 webpack5 基础框架\n文档: ${pkg.homepage}`).command('start', '开发', yargs => yargs.option('port', {
11
- alias: 'p',
12
- desc: '指定端口'
13
- }).option('open', {
14
- desc: '启动后打开页面'
15
- }), args => require('./start')(args)).command('build', '打包', yargs => yargs.option('analyze', {
16
- alias: 'a',
17
- desc: '分析代码',
18
- default: false,
19
- boolean: true
20
- }).option('output-html', {
21
- alias: 'o',
22
- desc: '输出 html 文件',
23
- default: false,
24
- boolean: true
25
- }), args => require('./build')(args)).command('deploy', '自动部署 dist 到 v1 服务器', yargs => yargs.option('school', {
26
- alias: 's',
27
- desc: '上传到校端',
28
- default: false,
29
- boolean: true
30
- }).option('bureau', {
31
- alias: 'b',
32
- desc: '上传到局端',
33
- default: false,
34
- boolean: true
35
- }).option('documentshelves', {
36
- alias: 'd',
37
- desc: '上传到公文',
38
- default: false,
39
- boolean: true
40
- }), args => require('./deploy')(args)).command(['generator', 'g'], '自动生成代码', yargs => yargs.command('page', '生成 page 模版, 默认根据环境生成 js/ts 与 less 文件', yargs => yargs.option('name', {
41
- desc: '模块名称',
42
- string: true
43
- }).demandOption('name', '必须输入模块名称').option('ts', {
44
- alias: 't',
45
- desc: '生成 ts 文件',
46
- boolean: true,
47
- default: true
48
- }).option('route', {
49
- alias: 'r',
50
- desc: '生成 index.js 路由文件',
51
- boolean: true,
52
- default: true
53
- }).option('fc', {
54
- alias: 'f',
55
- desc: '生成 Function Component 文件',
56
- boolean: true
57
- }), args => require('./generator').page(args)).command('override', '创建 override 文件', {}, args => require('./generator').override(args)).command('tailwind', '创建 tailwind 文件', {}, args => require('./generator').tailwind(args)).command('ts', '创建 tsconfig 文件', {}, args => require('./generator').ts(args)).showHelpOnFail(true).demandCommand(1, '')).command('auto-refactor', '自动改造项目', {}, () => require('./auto-refactor')()).command('commit-dist', '提交 dist 目录到 dist 分支', yargs => yargs.option('rm-local', {
58
- desc: '提交完后删除本地 dist',
59
- type: 'boolean'
60
- }), args => require('./commit-dist')(args)).showHelpOnFail(true).demandCommand(1, '').alias({
61
- v: 'version',
62
- h: 'help'
63
- }).argv;
3
+ // src/cli.js
4
+ var pkg = require("../package.json");
5
+ require("./utils/beforeStart");
6
+ require("yargs").usage(`教育工程化 webpack5 基础框架
7
+ 文档: ${pkg.homepage}`).command(
8
+ "start",
9
+ "开发",
10
+ (yargs) => yargs.option("port", { alias: "p", desc: "指定端口" }).option("open", { desc: "启动后打开页面" }),
11
+ (args) => require("./start")(args)
12
+ ).command(
13
+ "build",
14
+ "打包",
15
+ (yargs) => yargs.option("analyze", {
16
+ alias: "a",
17
+ desc: "分析代码",
18
+ default: false,
19
+ boolean: true
20
+ }).option("output-html", {
21
+ alias: "o",
22
+ desc: "输出 html 文件",
23
+ default: false,
24
+ boolean: true
25
+ }),
26
+ (args) => require("./build")(args)
27
+ ).command(
28
+ "deploy",
29
+ "自动部署 dist 到 v1 服务器",
30
+ (yargs) => yargs.option("school", { alias: "s", desc: "上传到校端", default: false, boolean: true }).option("bureau", { alias: "b", desc: "上传到局端", default: false, boolean: true }).option("documentshelves", {
31
+ alias: "d",
32
+ desc: "上传到公文",
33
+ default: false,
34
+ boolean: true
35
+ }),
36
+ (args) => require("./deploy")(args)
37
+ ).command(
38
+ ["generator", "g"],
39
+ "自动生成代码",
40
+ (yargs) => yargs.command(
41
+ "page",
42
+ "生成 page 模版, 默认根据环境生成 js/ts 与 less 文件",
43
+ (yargs2) => yargs2.option("name", { desc: "模块名称", string: true }).demandOption("name", "必须输入模块名称").option("ts", { alias: "t", desc: "生成 ts 文件", boolean: true, default: true }).option("route", {
44
+ alias: "r",
45
+ desc: "生成 index.js 路由文件",
46
+ boolean: true,
47
+ default: true
48
+ }).option("fc", { alias: "f", desc: "生成 Function Component 文件", boolean: true }),
49
+ (args) => require("./generator").page(args)
50
+ ).command(
51
+ "override",
52
+ "创建 override 文件",
53
+ {},
54
+ (args) => require("./generator").override(args)
55
+ ).command(
56
+ "tailwind",
57
+ "创建 tailwind 文件",
58
+ {},
59
+ (args) => require("./generator").tailwind(args)
60
+ ).command("ts", "创建 tsconfig 文件", {}, (args) => require("./generator").ts(args)).showHelpOnFail(true).demandCommand(1, "")
61
+ ).command("auto-refactor", "自动改造项目", {}, () => require("./auto-refactor")()).command(
62
+ "commit-dist",
63
+ "提交 dist 目录到 dist 分支",
64
+ (yargs) => yargs.option("rm-local", { desc: "提交完后删除本地 dist", type: "boolean" }),
65
+ (args) => require("./commit-dist")(args)
66
+ ).showHelpOnFail(true).demandCommand(1, "").alias({ v: "version", h: "help" }).argv;