@qse/edu-scripts 1.13.6 → 1.13.8
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.
- package/CHANGELOG.md +13 -0
- package/app.d.ts +10 -0
- package/lib/auto-refactor.js +88 -95
- package/lib/build.js +33 -36
- package/lib/cli.js +64 -61
- package/lib/commit-dist.js +40 -54
- package/lib/config/babel.dependencies.js +41 -39
- package/lib/config/babel.js +82 -55
- package/lib/config/paths.js +27 -30
- package/lib/config/plugins/postcss-safe-area.js +12 -12
- package/lib/config/webpackConfig.js +360 -325
- package/lib/config/webpackDevServerConfig.js +24 -28
- package/lib/deploy.js +58 -100
- package/lib/generator.js +49 -81
- package/lib/index.js +26 -9
- package/lib/start.js +16 -22
- package/lib/utils/FileSizeReporter.js +45 -56
- package/lib/utils/appConfig.js +12 -13
- package/lib/utils/beforeStart.js +35 -35
- package/lib/utils/changeDeployVersion.js +36 -65
- package/lib/utils/defineConfig.js +27 -5
- package/lib/utils/exec.js +5 -9
- package/lib/utils/getConfig.js +6 -7
- package/lib/utils/getOverride.js +13 -17
- package/package.json +28 -29
- package/src/config/webpackConfig.js +9 -2
- package/src/config/webpackDevServerConfig.js +5 -0
- package/src/utils/defineConfig.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## 1.13.8 (2023-07-25)
|
|
4
|
+
|
|
5
|
+
- feat: 支持 markdown 导入
|
|
6
|
+
- feat: 支持 `import content from '*?raw'` 导入规则
|
|
7
|
+
- feat: babel-loader include 修改成 exclude: /node_modules/
|
|
8
|
+
- chore: 升级打包工具
|
|
9
|
+
- chore: 升级依赖版本,尝试移除 stable 依赖警告
|
|
10
|
+
- chore: 最低 nodejs 版本要求 14
|
|
11
|
+
|
|
12
|
+
## 1.13.7 (2023-07-20)
|
|
13
|
+
|
|
14
|
+
- feat: 关闭 derServer.client.overlay.runtimeError
|
|
15
|
+
|
|
3
16
|
## 1.13.6 (2023-06-13)
|
|
4
17
|
|
|
5
18
|
- fix: 修复 @babel 相关依赖缺失
|
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/lib/auto-refactor.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
name:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
68
|
+
await step("创建 public 文件夹", async () => {
|
|
82
69
|
await fs.mkdir(paths.public);
|
|
83
70
|
});
|
|
84
|
-
await step(
|
|
85
|
-
if (await fs.pathExists(path.resolve(paths.src,
|
|
86
|
-
await fs.move(path.resolve(paths.src,
|
|
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(
|
|
90
|
-
const HTMLFiles = await glob(
|
|
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(
|
|
98
|
-
if (await fs.pathExists(path.resolve(paths.src,
|
|
99
|
-
await fs.remove(path.resolve(paths.src,
|
|
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(
|
|
103
|
-
const deleteFiles = [
|
|
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(
|
|
104
|
+
await step("修改 package.json 的 scripts", () => {
|
|
116
105
|
const scripts = appPkg.scripts;
|
|
117
|
-
scripts.start =
|
|
118
|
-
scripts.build =
|
|
119
|
-
scripts.analyze =
|
|
120
|
-
if (answers.mode !==
|
|
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[
|
|
113
|
+
scripts["commit-dist"] = "edu-scripts commit-dist --rm-local";
|
|
125
114
|
}
|
|
126
|
-
scripts[
|
|
127
|
-
scripts.postversion =
|
|
115
|
+
scripts["one-key-deploy"] = "npm version patch";
|
|
116
|
+
scripts.postversion = "npm run build && npm run deploy";
|
|
128
117
|
});
|
|
129
|
-
await step(
|
|
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
|
|
147
|
-
|
|
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),
|
|
140
|
+
await fs.writeFile(paths.package, JSON.stringify(appPkg, null, 2), "utf-8");
|
|
150
141
|
open(`${pkg.homepage}#/refactor`);
|
|
151
|
-
console.log(
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
process.env.
|
|
4
|
-
process.env.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 =
|
|
19
|
+
process.env.ANALYZE = "1";
|
|
21
20
|
}
|
|
22
21
|
if (args.outputHtml) {
|
|
23
|
-
process.env.OUTPUT_HTML =
|
|
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(
|
|
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(
|
|
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(
|
|
56
|
-
printFileSizesAfterBuild(
|
|
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(
|
|
56
|
+
console.log(`打包完成,可以使用 ${chalk.green("@qse/ssh-sftp")} 自动部署代码到 v1`);
|
|
60
57
|
} else {
|
|
61
|
-
console.log(`打包完成,可以运行 ${chalk.green(
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
alias:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
alias:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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;
|
package/lib/commit-dist.js
CHANGED
|
@@ -1,93 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
encoding: 'utf-8',
|
|
8
|
-
stdio: 'pipe',
|
|
9
|
-
...opts
|
|
10
|
-
});
|
|
11
|
-
const tmp = require('tmp');
|
|
1
|
+
// src/commit-dist.js
|
|
2
|
+
var chalk = require("chalk");
|
|
3
|
+
var paths = require("./config/paths");
|
|
4
|
+
var fs = require("fs-extra");
|
|
5
|
+
var exec = (cmd, opts) => require("child_process").execSync(cmd, { encoding: "utf-8", stdio: "pipe", ...opts });
|
|
6
|
+
var tmp = require("tmp");
|
|
12
7
|
function validateSVNRoot(root) {
|
|
13
8
|
const ls = exec(`svn ls ${root}`);
|
|
14
|
-
return [
|
|
9
|
+
return ["trunk", "branches"].every((s) => ls.includes(s));
|
|
15
10
|
}
|
|
16
11
|
function getWorkingCopyInfo() {
|
|
17
12
|
exec(`svn up`);
|
|
18
13
|
const url = exec(`svn info --show-item url`).trim();
|
|
19
14
|
const revision = exec(`svn info --show-item last-changed-revision`).trim();
|
|
20
15
|
const author = exec(`svn info --show-item last-changed-author`).trim();
|
|
21
|
-
let branch =
|
|
22
|
-
let root = url.replace(/\/trunk$/,
|
|
23
|
-
if (url.includes(
|
|
24
|
-
branch = url.split(
|
|
25
|
-
root = url.replace(/\/branches\/[^/]+$/,
|
|
16
|
+
let branch = "trunk";
|
|
17
|
+
let root = url.replace(/\/trunk$/, "");
|
|
18
|
+
if (url.includes("/branches/")) {
|
|
19
|
+
branch = url.split("/").pop();
|
|
20
|
+
root = url.replace(/\/branches\/[^/]+$/, "");
|
|
26
21
|
}
|
|
27
|
-
let distBranchURL = root +
|
|
28
|
-
let distBranchDirURL = distBranchURL +
|
|
22
|
+
let distBranchURL = root + "/branches/dist";
|
|
23
|
+
let distBranchDirURL = distBranchURL + "/" + branch;
|
|
29
24
|
if (!validateSVNRoot(root)) {
|
|
30
|
-
console.log(chalk.red(
|
|
25
|
+
console.log(chalk.red("SVN目录不符合规则,必须包含 trunk branches"));
|
|
31
26
|
process.exit(1);
|
|
32
27
|
}
|
|
33
|
-
return {
|
|
34
|
-
url,
|
|
35
|
-
branch,
|
|
36
|
-
revision,
|
|
37
|
-
author,
|
|
38
|
-
distBranchURL,
|
|
39
|
-
distBranchDirURL,
|
|
40
|
-
root
|
|
41
|
-
};
|
|
28
|
+
return { url, branch, revision, author, distBranchURL, distBranchDirURL, root };
|
|
42
29
|
}
|
|
43
30
|
function copyDistToRepo(info) {
|
|
44
31
|
const tmpdir = tmp.dirSync().name;
|
|
45
32
|
try {
|
|
46
33
|
exec(`svn ls ${info.distBranchDirURL} --depth empty`);
|
|
47
34
|
} catch (error) {
|
|
48
|
-
if (error.message.includes(
|
|
49
|
-
exec(
|
|
35
|
+
if (error.message.includes("non-existent")) {
|
|
36
|
+
exec(
|
|
37
|
+
`svn mkdir ${info.distBranchDirURL} --parents -m "[edu-scripts] create ${info.branch} dist"`
|
|
38
|
+
);
|
|
50
39
|
} else {
|
|
51
40
|
throw error;
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
43
|
exec(`svn co ${info.distBranchDirURL} ${tmpdir}`);
|
|
55
44
|
try {
|
|
56
|
-
exec(`svn rm * --force -q`, {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} catch (error) {}
|
|
45
|
+
exec(`svn rm * --force -q`, { cwd: tmpdir });
|
|
46
|
+
} catch (error) {
|
|
47
|
+
}
|
|
60
48
|
fs.copySync(paths.dist, tmpdir);
|
|
61
|
-
exec(`svn add * --force --auto-props --parents --depth infinity -q`, {
|
|
62
|
-
cwd: tmpdir
|
|
63
|
-
});
|
|
49
|
+
exec(`svn add * --force --auto-props --parents --depth infinity -q`, { cwd: tmpdir });
|
|
64
50
|
const msg = `[edu-scripts] commit ${info.branch} dist #${info.revision} @${info.author}`;
|
|
65
|
-
exec(`svn ci -m "${msg}"`, {
|
|
66
|
-
cwd: tmpdir
|
|
67
|
-
});
|
|
51
|
+
exec(`svn ci -m "${msg}"`, { cwd: tmpdir });
|
|
68
52
|
fs.removeSync(tmpdir);
|
|
69
53
|
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* svn commit dist folder to dish branches
|
|
73
|
-
*
|
|
74
|
-
* @param {Object} args
|
|
75
|
-
* @param {boolean} args.rmLocal
|
|
76
|
-
*/
|
|
77
54
|
module.exports = async function commitDist(args) {
|
|
78
55
|
if (!fs.existsSync(paths.dist)) {
|
|
79
|
-
console.log(chalk.red(
|
|
56
|
+
console.log(chalk.red("未找到 dist 文件夹,请先 edu-scpirts build"));
|
|
80
57
|
process.exit(1);
|
|
81
58
|
}
|
|
82
|
-
if (exec(
|
|
83
|
-
console.log(chalk.red(
|
|
59
|
+
if (exec("svn st").trim().length) {
|
|
60
|
+
console.log(chalk.red("似乎存在未提交的代码,请提交后重试。运行 svn st 查看具体信息"));
|
|
84
61
|
process.exit(1);
|
|
85
62
|
}
|
|
86
63
|
const info = getWorkingCopyInfo();
|
|
87
|
-
console.log(
|
|
64
|
+
console.log(
|
|
65
|
+
chalk.green(
|
|
66
|
+
[
|
|
67
|
+
`分支: ${info.branch}`,
|
|
68
|
+
`版本: ${info.revision}`,
|
|
69
|
+
`作者: ${info.author}`,
|
|
70
|
+
`地址: ${info.distBranchDirURL}`
|
|
71
|
+
].join("\n")
|
|
72
|
+
)
|
|
73
|
+
);
|
|
88
74
|
copyDistToRepo(info);
|
|
89
75
|
if (args.rmLocal) {
|
|
90
76
|
fs.removeSync(paths.dist);
|
|
91
77
|
}
|
|
92
|
-
console.log(chalk.green(
|
|
93
|
-
};
|
|
78
|
+
console.log(chalk.green("提交完成"));
|
|
79
|
+
};
|