@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.
- package/CHANGELOG.md +14 -1
- package/app.d.ts +10 -0
- package/docs/feat.md +84 -0
- package/docs/override.md +7 -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 +28 -30
- package/lib/config/plugins/mock-server/defineMock.d.ts +6 -0
- package/lib/config/plugins/mock-server/defineMock.js +31 -0
- package/lib/config/plugins/mock-server/index.js +69 -0
- package/lib/config/plugins/postcss-safe-area.js +12 -12
- package/lib/config/webpackConfig.js +360 -325
- package/lib/config/webpackDevServerConfig.js +27 -29
- package/lib/deploy.js +58 -100
- package/lib/generator.js +49 -81
- package/lib/index.d.ts +1 -0
- package/lib/index.js +29 -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.d.ts +7 -0
- 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 +32 -29
- package/src/config/paths.js +1 -0
- package/src/config/plugins/mock-server/defineMock.ts +12 -0
- package/src/config/plugins/mock-server/index.js +92 -0
- package/src/config/webpackConfig.js +9 -2
- package/src/config/webpackDevServerConfig.js +8 -0
- package/src/index.ts +1 -0
- package/src/utils/defineConfig.ts +8 -1
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {*} args
|
|
7
|
-
* @param {import('../utils/defineConfig').Config} override
|
|
8
|
-
*/
|
|
1
|
+
// src/config/webpackDevServerConfig.js
|
|
2
|
+
var WebpackDevServer = require("webpack-dev-server");
|
|
3
|
+
var setupMockServer = require("./plugins/mock-server");
|
|
9
4
|
module.exports = function getWebpackDevServerConfig(args, override) {
|
|
10
|
-
const host = process.env.HOST ||
|
|
5
|
+
const host = process.env.HOST || "0.0.0.0";
|
|
11
6
|
const sockHost = process.env.WDS_SOCKET_HOST;
|
|
12
7
|
const sockPort = process.env.WDS_SOCKET_PORT;
|
|
13
|
-
|
|
14
|
-
/** @type {WebpackDevServer.Configuration} */
|
|
15
8
|
const devServer = {
|
|
16
9
|
hot: true,
|
|
17
|
-
allowedHosts:
|
|
10
|
+
allowedHosts: "all",
|
|
18
11
|
historyApiFallback: true,
|
|
19
12
|
port: args.port,
|
|
20
13
|
open: args.open,
|
|
21
14
|
host,
|
|
22
15
|
client: {
|
|
23
|
-
webSocketURL: {
|
|
24
|
-
protocol: 'auto:',
|
|
25
|
-
hostname: sockHost,
|
|
26
|
-
port: sockPort
|
|
27
|
-
},
|
|
16
|
+
webSocketURL: { protocol: "auto:", hostname: sockHost, port: sockPort },
|
|
28
17
|
overlay: {
|
|
29
18
|
runtimeErrors: false,
|
|
30
19
|
errors: true,
|
|
@@ -32,20 +21,29 @@ module.exports = function getWebpackDevServerConfig(args, override) {
|
|
|
32
21
|
}
|
|
33
22
|
},
|
|
34
23
|
headers: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
"Access-Control-Allow-Origin": "*",
|
|
25
|
+
"Access-Control-Allow-Methods": "*",
|
|
26
|
+
"Access-Control-Allow-Headers": "*"
|
|
38
27
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
changeOrigin: true,
|
|
43
|
-
headers: {
|
|
44
|
-
host: 'www.zhidianbao.cn',
|
|
45
|
-
origin: 'http://www.zhidianbao.cn'
|
|
28
|
+
setupMiddlewares: (middlewares, devServer2) => {
|
|
29
|
+
if (override.mock !== false) {
|
|
30
|
+
setupMockServer(middlewares, devServer2);
|
|
46
31
|
}
|
|
47
|
-
|
|
32
|
+
return middlewares;
|
|
33
|
+
},
|
|
34
|
+
proxy: [
|
|
35
|
+
...override.proxy,
|
|
36
|
+
{
|
|
37
|
+
context: ["/api"],
|
|
38
|
+
target: "http://192.168.10.19:3339/qsxxwapdev",
|
|
39
|
+
changeOrigin: true,
|
|
40
|
+
headers: {
|
|
41
|
+
host: "www.zhidianbao.cn",
|
|
42
|
+
origin: "http://www.zhidianbao.cn"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
],
|
|
48
46
|
compress: true
|
|
49
47
|
};
|
|
50
48
|
return devServer;
|
|
51
|
-
};
|
|
49
|
+
};
|
package/lib/deploy.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const appConfig = require('./utils/appConfig');
|
|
14
|
-
const baseConfig = {
|
|
15
|
-
localPath: 'dist',
|
|
1
|
+
// src/deploy.js
|
|
2
|
+
var { sshSftp } = require("@qse/ssh-sftp");
|
|
3
|
+
var path = require("path");
|
|
4
|
+
var paths = require("./config/paths");
|
|
5
|
+
var pkg = require(paths.package);
|
|
6
|
+
var chalk = require("chalk");
|
|
7
|
+
var fs = require("fs-extra");
|
|
8
|
+
var changeDeployVersion = require("./utils/changeDeployVersion");
|
|
9
|
+
var ora = require("ora");
|
|
10
|
+
var appConfig = require("./utils/appConfig");
|
|
11
|
+
var baseConfig = {
|
|
12
|
+
localPath: "dist",
|
|
16
13
|
ignore: [],
|
|
17
14
|
cleanRemoteFiles: false,
|
|
18
15
|
securityLock: false,
|
|
@@ -22,111 +19,78 @@ const baseConfig = {
|
|
|
22
19
|
async function normalDeploy(args) {
|
|
23
20
|
const presetConfig = {
|
|
24
21
|
s: {
|
|
25
|
-
context:
|
|
26
|
-
folder:
|
|
22
|
+
context: "eduwebngv1",
|
|
23
|
+
folder: "userportal"
|
|
27
24
|
},
|
|
28
25
|
b: {
|
|
29
|
-
context:
|
|
30
|
-
folder:
|
|
26
|
+
context: "eduwebngv1",
|
|
27
|
+
folder: "bureaupc"
|
|
31
28
|
},
|
|
32
29
|
d: {
|
|
33
|
-
context:
|
|
34
|
-
folder:
|
|
30
|
+
context: "eduwebngv1",
|
|
31
|
+
folder: "documentshelves"
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
34
|
const resolve = (...pathSegments) => path.resolve(process.cwd(), ...pathSegments);
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 生成路径
|
|
41
|
-
* @name remoteFile 远程文件
|
|
42
|
-
* @name tmpFile 本地文件
|
|
43
|
-
* @name tmpDir 本地临时文件夹 `tmpFile`存在的文件夹
|
|
44
|
-
* @name tmpBase 本地临时文件夹 到`__tmp__`层
|
|
45
|
-
* @param {string} remoteFilePath 远程文件相对`opts.remotePath`地址
|
|
46
|
-
*/
|
|
47
35
|
function getLocalAndRemoteFilePath(remoteFilePath, opts) {
|
|
48
|
-
const splited = remoteFilePath.split(
|
|
36
|
+
const splited = remoteFilePath.split("/");
|
|
49
37
|
const fileName = splited[splited.length - 1];
|
|
50
|
-
const tmpBase = resolve(opts.localPath,
|
|
51
|
-
const tmpDir = resolve(opts.localPath,
|
|
38
|
+
const tmpBase = resolve(opts.localPath, "__tmp__");
|
|
39
|
+
const tmpDir = resolve(opts.localPath, "__tmp__", ...splited.slice(0, -1));
|
|
52
40
|
const tmpFile = resolve(tmpDir, fileName);
|
|
53
|
-
const remoteFile = [opts.remotePath, remoteFilePath].join(
|
|
54
|
-
return {
|
|
55
|
-
tmpDir,
|
|
56
|
-
tmpFile,
|
|
57
|
-
remoteFile,
|
|
58
|
-
tmpBase
|
|
59
|
-
};
|
|
41
|
+
const remoteFile = [opts.remotePath, remoteFilePath].join("/");
|
|
42
|
+
return { tmpDir, tmpFile, remoteFile, tmpBase };
|
|
60
43
|
}
|
|
61
44
|
function dateTime() {
|
|
62
|
-
let date = new Date();
|
|
63
|
-
date = new Date(date.getTime() - date.getTimezoneOffset() *
|
|
64
|
-
return date.toISOString().replace(/T/,
|
|
45
|
+
let date = /* @__PURE__ */ new Date();
|
|
46
|
+
date = new Date(date.getTime() - date.getTimezoneOffset() * 6e4);
|
|
47
|
+
return date.toISOString().replace(/T/, " ").replace(/\..+/, "");
|
|
65
48
|
}
|
|
66
49
|
function updateLogContent(content, info) {
|
|
67
|
-
const lines = content.trim().split(
|
|
68
|
-
lines.push(`[${dateTime()}] ${JSON.stringify(info)}
|
|
69
|
-
|
|
50
|
+
const lines = content.trim().split("\n");
|
|
51
|
+
lines.push(`[${dateTime()}] ${JSON.stringify(info)}
|
|
52
|
+
`);
|
|
53
|
+
return lines.slice(-50).join("\n");
|
|
70
54
|
}
|
|
71
55
|
async function upload(opts) {
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} = await sshSftp(opts);
|
|
77
|
-
const spinner = ora('自动更新 ver.js 版本配置').start();
|
|
78
|
-
// 指定远程需要修改的文件
|
|
79
|
-
const fileName = 'js/ver.js';
|
|
80
|
-
// 生成各种路径
|
|
81
|
-
const {
|
|
82
|
-
remoteFile,
|
|
83
|
-
tmpDir,
|
|
84
|
-
tmpFile,
|
|
85
|
-
tmpBase
|
|
86
|
-
} = getLocalAndRemoteFilePath(fileName, fullOpts);
|
|
56
|
+
const { sftp, opts: fullOpts } = await sshSftp(opts);
|
|
57
|
+
const spinner = ora("自动更新 ver.js 版本配置").start();
|
|
58
|
+
const fileName = "js/ver.js";
|
|
59
|
+
const { remoteFile, tmpDir, tmpFile, tmpBase } = getLocalAndRemoteFilePath(fileName, fullOpts);
|
|
87
60
|
try {
|
|
88
|
-
|
|
89
|
-
fs.mkdirSync(tmpDir, {
|
|
90
|
-
recursive: true
|
|
91
|
-
});
|
|
61
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
92
62
|
const info = {
|
|
93
63
|
name: pkg.name,
|
|
94
64
|
version: pkg.version,
|
|
95
65
|
grayscale: appConfig.grayscale
|
|
96
66
|
};
|
|
97
67
|
{
|
|
98
|
-
// 拉取远程文件到本地
|
|
99
68
|
await sftp.fastGet(remoteFile, tmpFile);
|
|
100
|
-
|
|
101
|
-
// 读取本地文件内容
|
|
102
|
-
let code = await fs.readFile(tmpFile, {
|
|
103
|
-
encoding: 'utf-8'
|
|
104
|
-
});
|
|
69
|
+
let code = await fs.readFile(tmpFile, { encoding: "utf-8" });
|
|
105
70
|
code = changeDeployVersion(code, info);
|
|
106
|
-
await sftp.fastPut(tmpFile, remoteFile +
|
|
71
|
+
await sftp.fastPut(tmpFile, remoteFile + ".bak");
|
|
107
72
|
await fs.writeFile(tmpFile, code);
|
|
108
|
-
// 将修改完的内容传回服务器
|
|
109
73
|
await sftp.fastPut(tmpFile, remoteFile);
|
|
110
74
|
}
|
|
111
75
|
{
|
|
112
|
-
const remoteLogFile = remoteFile +
|
|
113
|
-
const tmpLogFile = tmpFile +
|
|
114
|
-
let content =
|
|
76
|
+
const remoteLogFile = remoteFile + ".log";
|
|
77
|
+
const tmpLogFile = tmpFile + ".log";
|
|
78
|
+
let content = "";
|
|
115
79
|
try {
|
|
116
80
|
await sftp.fastGet(remoteLogFile, tmpLogFile);
|
|
117
|
-
content = await fs.readFile(tmpLogFile,
|
|
118
|
-
} catch (error) {
|
|
81
|
+
content = await fs.readFile(tmpLogFile, "utf-8");
|
|
82
|
+
} catch (error) {
|
|
83
|
+
}
|
|
119
84
|
content = updateLogContent(content, info);
|
|
120
85
|
await fs.writeFile(tmpLogFile, content);
|
|
121
86
|
await sftp.fastPut(tmpLogFile, remoteLogFile);
|
|
122
87
|
}
|
|
123
|
-
spinner.succeed(
|
|
88
|
+
spinner.succeed("已更新 ver.js 版本配置");
|
|
124
89
|
} catch (e) {
|
|
125
90
|
spinner.fail(`自动修改 ver.js 失败,请手动修改`);
|
|
126
91
|
console.log(chalk.bgRed(e.message));
|
|
127
92
|
} finally {
|
|
128
93
|
await sftp.end();
|
|
129
|
-
// 清除临时文件夹
|
|
130
94
|
fs.removeSync(tmpBase);
|
|
131
95
|
}
|
|
132
96
|
}
|
|
@@ -141,40 +105,34 @@ async function normalDeploy(args) {
|
|
|
141
105
|
presets.push(presetConfig.d);
|
|
142
106
|
}
|
|
143
107
|
if (presets.length === 0) {
|
|
144
|
-
console.log(
|
|
145
|
-
|
|
108
|
+
console.log(
|
|
109
|
+
`
|
|
110
|
+
${chalk.red("指定 deploy 部署范围")}
|
|
146
111
|
|
|
147
112
|
# 部署代码 校端
|
|
148
|
-
${chalk.green(
|
|
113
|
+
${chalk.green("edu-scripts deploy -s")}
|
|
149
114
|
# 部署代码 局端
|
|
150
|
-
${chalk.green(
|
|
115
|
+
${chalk.green("edu-scripts deploy -b")}
|
|
151
116
|
# 部署代码 公文
|
|
152
|
-
${chalk.green(
|
|
117
|
+
${chalk.green("edu-scripts deploy -d")}
|
|
153
118
|
# 部署代码 校端 + 局端
|
|
154
|
-
${chalk.green(
|
|
155
|
-
`
|
|
119
|
+
${chalk.green("edu-scripts deploy -s -b")}
|
|
120
|
+
`
|
|
121
|
+
);
|
|
156
122
|
process.exit();
|
|
157
123
|
}
|
|
158
|
-
const uploadConfig = {
|
|
159
|
-
...baseConfig,
|
|
160
|
-
ignore: [...baseConfig.ignore, 'js/ver.js']
|
|
161
|
-
};
|
|
124
|
+
const uploadConfig = { ...baseConfig, ignore: [...baseConfig.ignore, "js/ver.js"] };
|
|
162
125
|
if (!appConfig.mainProject) {
|
|
163
|
-
uploadConfig.ignore = [...uploadConfig.ignore,
|
|
126
|
+
uploadConfig.ignore = [...uploadConfig.ignore, "!(js|images)"];
|
|
164
127
|
}
|
|
165
128
|
for (const preset of presets) {
|
|
166
|
-
await upload({
|
|
167
|
-
...uploadConfig,
|
|
168
|
-
preset
|
|
169
|
-
});
|
|
129
|
+
await upload({ ...uploadConfig, preset });
|
|
170
130
|
}
|
|
171
131
|
}
|
|
172
132
|
async function singleDeploy() {
|
|
173
133
|
const config = fs.existsSync(paths.sshSftp) ? fs.readJsonSync(paths.sshSftp) : {
|
|
174
134
|
...baseConfig,
|
|
175
|
-
preset: {
|
|
176
|
-
context: 'qsxxwapdev'
|
|
177
|
-
},
|
|
135
|
+
preset: { context: "qsxxwapdev" },
|
|
178
136
|
cleanRemoteFiles: true,
|
|
179
137
|
securityLock: true,
|
|
180
138
|
keepAlive: false,
|
|
@@ -188,4 +146,4 @@ module.exports = function deploy(args) {
|
|
|
188
146
|
} else {
|
|
189
147
|
normalDeploy(args);
|
|
190
148
|
}
|
|
191
|
-
};
|
|
149
|
+
};
|
package/lib/generator.js
CHANGED
|
@@ -1,77 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const chalk = require('chalk');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {string[]} args
|
|
15
|
-
* @returns {string}
|
|
16
|
-
*/
|
|
17
|
-
const getTmpPath = (...args) => path.resolve(__dirname, 'asset', 'template', ...args);
|
|
18
|
-
function genFile({
|
|
19
|
-
source,
|
|
20
|
-
target,
|
|
21
|
-
modulePath,
|
|
22
|
-
replace
|
|
23
|
-
}) {
|
|
24
|
-
let content = fs.readFileSync(source, 'utf-8');
|
|
25
|
-
if (typeof replace === 'object') {
|
|
1
|
+
// src/generator.js
|
|
2
|
+
var path = require("path");
|
|
3
|
+
var fs = require("fs-extra");
|
|
4
|
+
var { upperFirst, camelCase, has } = require("lodash");
|
|
5
|
+
var paths = require("./config/paths");
|
|
6
|
+
var chalk = require("chalk");
|
|
7
|
+
var getTmpPath = (...args) => path.resolve(__dirname, "asset", "template", ...args);
|
|
8
|
+
function genFile({ source, target, modulePath, replace }) {
|
|
9
|
+
let content = fs.readFileSync(source, "utf-8");
|
|
10
|
+
if (typeof replace === "object") {
|
|
26
11
|
Object.entries(replace).forEach(([searchValue, replaceValue]) => {
|
|
27
12
|
content = content.replaceAll(searchValue, replaceValue);
|
|
28
13
|
});
|
|
29
14
|
}
|
|
30
15
|
fs.writeFileSync(path.resolve(modulePath, target), content);
|
|
31
16
|
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {Object} PageArgs
|
|
35
|
-
* @property {string} name
|
|
36
|
-
* @property {boolean} [fc=false]
|
|
37
|
-
* @property {boolean} [ts=true]
|
|
38
|
-
* @property {boolean} [route=true]
|
|
39
|
-
*
|
|
40
|
-
* @param {PageArgs} args
|
|
41
|
-
*/
|
|
42
17
|
async function generatorPage(args) {
|
|
43
|
-
const tmpPath = getTmpPath(
|
|
44
|
-
const lessPath = tmpPath.replace(
|
|
18
|
+
const tmpPath = getTmpPath("page", "index.[type].[ext].tpl");
|
|
19
|
+
const lessPath = tmpPath.replace("[type].[ext]", "less");
|
|
45
20
|
const moduleName = camelCase(args.name);
|
|
46
21
|
const ModuleName = upperFirst(moduleName);
|
|
47
|
-
const type = args.fc ?
|
|
48
|
-
const ext = fs.existsSync(paths.tsconfig) ? args.ts ?
|
|
49
|
-
const jsPath = tmpPath.replace(
|
|
50
|
-
const routePath = tmpPath.replace(
|
|
51
|
-
const logicPath = tmpPath.replace(
|
|
22
|
+
const type = args.fc ? "fc" : "class";
|
|
23
|
+
const ext = fs.existsSync(paths.tsconfig) ? args.ts ? "tsx" : "js" : "js";
|
|
24
|
+
const jsPath = tmpPath.replace("[type]", type).replace("[ext]", ext);
|
|
25
|
+
const routePath = tmpPath.replace("index.[type].[ext]", "route.js");
|
|
26
|
+
const logicPath = tmpPath.replace("index.[type].[ext]", "logic.js");
|
|
52
27
|
const modulePath = path.resolve(paths.pages, moduleName);
|
|
53
|
-
const ModuleFileName = args.route ? ModuleName :
|
|
54
|
-
const ModuleLogicName = args.route ? ModuleName +
|
|
55
|
-
const replace = {
|
|
56
|
-
ModuleName,
|
|
57
|
-
moduleName,
|
|
58
|
-
ModuleFileName,
|
|
59
|
-
ModuleLogicName
|
|
60
|
-
};
|
|
28
|
+
const ModuleFileName = args.route ? ModuleName : "index";
|
|
29
|
+
const ModuleLogicName = args.route ? ModuleName + "Logic" : "logic";
|
|
30
|
+
const replace = { ModuleName, moduleName, ModuleFileName, ModuleLogicName };
|
|
61
31
|
fs.ensureDirSync(modulePath);
|
|
62
|
-
genFile({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
modulePath,
|
|
66
|
-
replace
|
|
67
|
-
});
|
|
68
|
-
genFile({
|
|
69
|
-
source: lessPath,
|
|
70
|
-
target: `${ModuleFileName}.less`,
|
|
71
|
-
modulePath,
|
|
72
|
-
replace
|
|
73
|
-
});
|
|
74
|
-
if (type === 'class' && ext === 'js') {
|
|
32
|
+
genFile({ source: jsPath, target: `${ModuleFileName}.${ext}`, modulePath, replace });
|
|
33
|
+
genFile({ source: lessPath, target: `${ModuleFileName}.less`, modulePath, replace });
|
|
34
|
+
if (type === "class" && ext === "js") {
|
|
75
35
|
genFile({
|
|
76
36
|
source: logicPath,
|
|
77
37
|
target: `${ModuleLogicName}.${ext.slice(0, 2)}`,
|
|
@@ -80,21 +40,25 @@ async function generatorPage(args) {
|
|
|
80
40
|
});
|
|
81
41
|
}
|
|
82
42
|
if (args.route) {
|
|
83
|
-
genFile({
|
|
84
|
-
source: routePath,
|
|
85
|
-
target: `index.${ext.slice(0, 2)}`,
|
|
86
|
-
modulePath,
|
|
87
|
-
replace
|
|
88
|
-
});
|
|
43
|
+
genFile({ source: routePath, target: `index.${ext.slice(0, 2)}`, modulePath, replace });
|
|
89
44
|
}
|
|
90
|
-
console.log(
|
|
45
|
+
console.log(
|
|
46
|
+
chalk.green(
|
|
47
|
+
[
|
|
48
|
+
`生成完毕:`,
|
|
49
|
+
`import ${ModuleName} from '@/pages/${moduleName}'`,
|
|
50
|
+
`const ${ModuleName} = lazy(() => import(/* webpackChunkName: '${moduleName}' */ '@/pages/${moduleName}'))`,
|
|
51
|
+
`{ path: '/${moduleName}', element: <${ModuleName} /> },`
|
|
52
|
+
].join("\n")
|
|
53
|
+
)
|
|
54
|
+
);
|
|
91
55
|
}
|
|
92
56
|
async function generatorOverride() {
|
|
93
57
|
if (fs.existsSync(paths.override)) {
|
|
94
58
|
console.log(chalk.red(`文件已存在 ${paths.override}`));
|
|
95
59
|
process.exit(0);
|
|
96
60
|
}
|
|
97
|
-
fs.copySync(getTmpPath(
|
|
61
|
+
fs.copySync(getTmpPath("edu-scripts.override.js.tpl"), paths.override);
|
|
98
62
|
console.log(chalk.green(`成功生成 ${paths.override}`));
|
|
99
63
|
}
|
|
100
64
|
async function generatorTsconfig() {
|
|
@@ -102,8 +66,8 @@ async function generatorTsconfig() {
|
|
|
102
66
|
console.log(chalk.red(`文件已存在 ${paths.tsconfig}`));
|
|
103
67
|
process.exit(0);
|
|
104
68
|
}
|
|
105
|
-
fs.copySync(getTmpPath(
|
|
106
|
-
fs.copySync(getTmpPath(
|
|
69
|
+
fs.copySync(getTmpPath("tsconfig.json.tpl"), paths.tsconfig);
|
|
70
|
+
fs.copySync(getTmpPath("edu-app-env.d.ts.tpl"), paths.eduAppEnv);
|
|
107
71
|
console.log(chalk.green(`成功生成 ${paths.tsconfig}`));
|
|
108
72
|
}
|
|
109
73
|
async function generatorTailwind() {
|
|
@@ -111,22 +75,26 @@ async function generatorTailwind() {
|
|
|
111
75
|
console.log(chalk.red(`文件已存在 ${paths.tailwind}`));
|
|
112
76
|
process.exit(0);
|
|
113
77
|
}
|
|
114
|
-
fs.copySync(getTmpPath(
|
|
115
|
-
const code = [
|
|
116
|
-
const globalLessFile = paths.resolveApp(
|
|
78
|
+
fs.copySync(getTmpPath("tailwind.config.js.tpl"), paths.tailwind);
|
|
79
|
+
const code = ["@tailwind base;", "@tailwind components;", "@tailwind utilities;"].join("\n");
|
|
80
|
+
const globalLessFile = paths.resolveApp("src", "index.less");
|
|
117
81
|
if (fs.existsSync(globalLessFile)) {
|
|
118
|
-
const content = fs.readFileSync(globalLessFile,
|
|
119
|
-
if (!content.includes(
|
|
120
|
-
fs.writeFileSync(globalLessFile, [code, content].join(
|
|
82
|
+
const content = fs.readFileSync(globalLessFile, "utf-8");
|
|
83
|
+
if (!content.includes("@tailwind base")) {
|
|
84
|
+
fs.writeFileSync(globalLessFile, [code, content].join("\n"));
|
|
121
85
|
}
|
|
122
86
|
console.log(chalk.green(`成功生成 ${paths.tailwind}`));
|
|
123
87
|
return;
|
|
124
88
|
}
|
|
125
|
-
console.log(
|
|
89
|
+
console.log(
|
|
90
|
+
chalk.green(
|
|
91
|
+
[`成功生成 ${paths.tailwind}`, "", "添加以下代码到入口处的 index.less 中", code].join("\n")
|
|
92
|
+
)
|
|
93
|
+
);
|
|
126
94
|
}
|
|
127
95
|
module.exports = {
|
|
128
96
|
page: generatorPage,
|
|
129
97
|
override: generatorOverride,
|
|
130
98
|
ts: generatorTsconfig,
|
|
131
99
|
tailwind: generatorTailwind
|
|
132
|
-
};
|
|
100
|
+
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
18
|
|
|
3
|
-
|
|
4
|
-
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
defineConfig: () => import_defineConfig.defineConfig,
|
|
23
|
+
defineMock: () => import_defineMock.defineMock
|
|
5
24
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
var import_defineConfig = require("./utils/defineConfig");
|
|
27
|
+
var import_defineMock = require("./config/plugins/mock-server/defineMock");
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
defineConfig,
|
|
31
|
+
defineMock
|
|
11
32
|
});
|
|
12
|
-
var _defineConfig = require("./utils/defineConfig");
|
package/lib/start.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
process.env.
|
|
4
|
-
process.env.
|
|
5
|
-
process.env.
|
|
6
|
-
process.
|
|
7
|
-
|
|
8
|
-
// Makes the script crash on unhandled rejections instead of silently
|
|
9
|
-
// ignoring them. In the future, promise rejections that are not handled will
|
|
10
|
-
// terminate the Node.js process with a non-zero exit code.
|
|
11
|
-
process.on('unhandledRejection', err => {
|
|
1
|
+
// src/start.js
|
|
2
|
+
process.env.NODE_ENV = "development";
|
|
3
|
+
process.env.BABEL_ENV = "development";
|
|
4
|
+
process.env.BROWSERSLIST = "chrome >= 70";
|
|
5
|
+
process.env.WEBPACK_DEV_SERVER_BASE_PORT = "3000";
|
|
6
|
+
process.on("unhandledRejection", (err) => {
|
|
12
7
|
throw err;
|
|
13
8
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
process.env.WDS_SOCKET_HOST = WebpackDevServer.internalIPSync(
|
|
9
|
+
var WebpackDevServer = require("webpack-dev-server");
|
|
10
|
+
var webpack = require("webpack");
|
|
11
|
+
var getConfig = require("./utils/getConfig");
|
|
12
|
+
var chalk = require("chalk");
|
|
13
|
+
process.env.WDS_SOCKET_HOST = WebpackDevServer.internalIPSync("v4") || "127.0.0.1";
|
|
19
14
|
module.exports = async function start(args) {
|
|
20
15
|
const basePort = process.env.WEBPACK_DEV_SERVER_BASE_PORT;
|
|
21
16
|
const port = await WebpackDevServer.getFreePort(args.port || process.env.PORT);
|
|
@@ -27,17 +22,16 @@ module.exports = async function start(args) {
|
|
|
27
22
|
const compiler = webpack(getConfig(args));
|
|
28
23
|
const devServer = new WebpackDevServer(compiler.options.devServer, compiler);
|
|
29
24
|
devServer.start();
|
|
30
|
-
[(
|
|
31
|
-
process.on(sig, function
|
|
25
|
+
[("SIGINT", "SIGTERM")].forEach(function(sig) {
|
|
26
|
+
process.on(sig, function() {
|
|
32
27
|
devServer.stop();
|
|
33
28
|
process.exit();
|
|
34
29
|
});
|
|
35
30
|
});
|
|
36
|
-
if (process.env.CI !==
|
|
37
|
-
|
|
38
|
-
process.stdin.on('end', function () {
|
|
31
|
+
if (process.env.CI !== "true") {
|
|
32
|
+
process.stdin.on("end", function() {
|
|
39
33
|
devServer.stop();
|
|
40
34
|
process.exit();
|
|
41
35
|
});
|
|
42
36
|
}
|
|
43
|
-
};
|
|
37
|
+
};
|