@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
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
|
+
};
|
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const getOverride = require('../utils/getOverride');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {Object} Opts
|
|
7
|
-
* @property {string} [modules]
|
|
8
|
-
*
|
|
9
|
-
* @param {Opts} [opts]
|
|
10
|
-
* @return {*}
|
|
11
|
-
*/
|
|
1
|
+
// src/config/babel.dependencies.js
|
|
2
|
+
var getOverride = require("../utils/getOverride");
|
|
12
3
|
module.exports = function getBabelConfig(opts = {}) {
|
|
13
|
-
const isDev = process.env.NODE_ENV ===
|
|
4
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
14
5
|
let config = {
|
|
15
6
|
cacheDirectory: true,
|
|
16
7
|
cacheCompression: false,
|
|
17
8
|
babelrc: false,
|
|
18
9
|
configFile: false,
|
|
19
|
-
sourceType:
|
|
10
|
+
sourceType: "unambiguous",
|
|
20
11
|
compact: false,
|
|
21
12
|
sourceMaps: isDev,
|
|
22
13
|
inputSourceMap: isDev,
|
|
23
|
-
presets: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
14
|
+
presets: [
|
|
15
|
+
[
|
|
16
|
+
"@babel/preset-env",
|
|
17
|
+
{
|
|
18
|
+
modules: opts.modules,
|
|
19
|
+
useBuiltIns: "entry",
|
|
20
|
+
corejs: 3,
|
|
21
|
+
// Exclude transforms that make all code slower
|
|
22
|
+
exclude: ["transform-typeof-symbol"]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
].filter(Boolean),
|
|
26
|
+
plugins: [
|
|
27
|
+
[
|
|
28
|
+
"@babel/plugin-transform-runtime",
|
|
29
|
+
{
|
|
30
|
+
corejs: false,
|
|
31
|
+
helpers: true,
|
|
32
|
+
// By default, babel assumes babel/runtime version 7.0.0-beta.0,
|
|
33
|
+
// explicitly resolving to match the provided helper functions.
|
|
34
|
+
// https://github.com/babel/babel/issues/10261
|
|
35
|
+
version: require("@babel/runtime/package.json").version,
|
|
36
|
+
regenerator: true
|
|
37
|
+
// // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
|
|
38
|
+
// // We should turn this on once the lowest version of Node LTS
|
|
39
|
+
// // supports ES Modules.
|
|
40
|
+
// useESModules: true,
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"import",
|
|
45
|
+
{ libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
|
|
46
|
+
"lodash"
|
|
47
|
+
]
|
|
48
|
+
].filter(Boolean)
|
|
47
49
|
};
|
|
48
50
|
const override = getOverride();
|
|
49
51
|
if (override.babel) {
|
|
50
|
-
config = override.babel(config,
|
|
52
|
+
config = override.babel(config, "node_modules") || config;
|
|
51
53
|
}
|
|
52
54
|
return config;
|
|
53
|
-
};
|
|
55
|
+
};
|
package/lib/config/babel.js
CHANGED
|
@@ -1,74 +1,101 @@
|
|
|
1
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
2
23
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
24
|
+
// src/config/babel.js
|
|
25
|
+
var fs = require("fs");
|
|
26
|
+
var paths = require("./paths");
|
|
27
|
+
var appConfig = require("../utils/appConfig");
|
|
28
|
+
var getOverride = require("../utils/getOverride");
|
|
29
|
+
var hasJsxRuntime = (() => {
|
|
8
30
|
try {
|
|
9
|
-
require.resolve(
|
|
10
|
-
return
|
|
31
|
+
require.resolve("react/jsx-runtime");
|
|
32
|
+
return appConfig.single;
|
|
11
33
|
} catch (error) {
|
|
12
34
|
return false;
|
|
13
35
|
}
|
|
14
36
|
})();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {Object} Opts
|
|
18
|
-
* @property {string} [modules]
|
|
19
|
-
*
|
|
20
|
-
* @param {Opts} [opts]
|
|
21
|
-
* @return {*}
|
|
22
|
-
*/
|
|
23
37
|
module.exports = function getBabelConfig(opts = {}) {
|
|
24
38
|
const isTypeScriptEnabled = fs.existsSync(paths.tsconfig);
|
|
25
|
-
const isDev = process.env.NODE_ENV ===
|
|
39
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
26
40
|
let config = {
|
|
27
41
|
cacheDirectory: true,
|
|
28
42
|
cacheCompression: false,
|
|
29
43
|
compact: !isDev,
|
|
30
44
|
babelrc: false,
|
|
31
45
|
configFile: false,
|
|
32
|
-
presets: [
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
presets: [
|
|
47
|
+
[
|
|
48
|
+
"@babel/preset-env",
|
|
49
|
+
{
|
|
50
|
+
modules: opts.modules,
|
|
51
|
+
useBuiltIns: "entry",
|
|
52
|
+
corejs: 3,
|
|
53
|
+
// Exclude transforms that make all code slower
|
|
54
|
+
exclude: ["transform-typeof-symbol"]
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"@babel/preset-react",
|
|
59
|
+
{
|
|
60
|
+
development: isDev,
|
|
61
|
+
runtime: hasJsxRuntime ? "automatic" : "classic",
|
|
62
|
+
useBuiltIns: !hasJsxRuntime
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
isTypeScriptEnabled && "@babel/preset-typescript"
|
|
66
|
+
].filter(Boolean),
|
|
67
|
+
plugins: [
|
|
68
|
+
[
|
|
69
|
+
"@babel/plugin-transform-runtime",
|
|
70
|
+
{
|
|
71
|
+
corejs: false,
|
|
72
|
+
helpers: true,
|
|
73
|
+
// By default, babel assumes babel/runtime version 7.0.0-beta.0,
|
|
74
|
+
// explicitly resolving to match the provided helper functions.
|
|
75
|
+
// https://github.com/babel/babel/issues/10261
|
|
76
|
+
version: require("@babel/runtime/package.json").version,
|
|
77
|
+
regenerator: true
|
|
78
|
+
// // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
|
|
79
|
+
// // We should turn this on once the lowest version of Node LTS
|
|
80
|
+
// // supports ES Modules.
|
|
81
|
+
// useESModules: true,
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
["@babel/plugin-proposal-decorators", { legacy: true }],
|
|
85
|
+
["@babel/plugin-proposal-class-properties", { loose: true }],
|
|
86
|
+
["@babel/plugin-proposal-private-methods", { loose: true }],
|
|
87
|
+
["@babel/plugin-proposal-private-property-in-object", { loose: true }],
|
|
88
|
+
[
|
|
89
|
+
"import",
|
|
90
|
+
{ libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
|
|
91
|
+
"lodash"
|
|
92
|
+
],
|
|
93
|
+
isDev && "react-refresh/babel"
|
|
94
|
+
].filter(Boolean)
|
|
68
95
|
};
|
|
69
96
|
const override = getOverride();
|
|
70
97
|
if (override.babel) {
|
|
71
|
-
config = override.babel(config,
|
|
98
|
+
config = override.babel(config, "src") || config;
|
|
72
99
|
}
|
|
73
100
|
return config;
|
|
74
|
-
};
|
|
101
|
+
};
|
package/lib/config/paths.js
CHANGED
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const glob = require('globby');
|
|
1
|
+
// src/config/paths.js
|
|
2
|
+
var path = require("path");
|
|
3
|
+
var fs = require("fs");
|
|
4
|
+
var glob = require("globby");
|
|
6
5
|
function resolveApp(...filePath) {
|
|
7
6
|
return path.resolve(process.cwd(), ...filePath);
|
|
8
7
|
}
|
|
9
|
-
function getExistPath(...
|
|
10
|
-
for (const
|
|
11
|
-
if (fs.existsSync(
|
|
12
|
-
return
|
|
8
|
+
function getExistPath(...paths2) {
|
|
9
|
+
for (const path2 of paths2) {
|
|
10
|
+
if (fs.existsSync(path2)) {
|
|
11
|
+
return path2;
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
|
-
return
|
|
14
|
+
return paths2[0];
|
|
16
15
|
}
|
|
17
|
-
|
|
16
|
+
var paths = {
|
|
18
17
|
resolveApp,
|
|
19
|
-
eduAppEnv: resolveApp(
|
|
20
|
-
dist: resolveApp(
|
|
21
|
-
sshSftp: resolveApp(
|
|
22
|
-
nodeModules: resolveApp(
|
|
23
|
-
tsconfig: resolveApp(
|
|
24
|
-
jsconfig: resolveApp(
|
|
25
|
-
package: resolveApp(
|
|
26
|
-
tailwind: resolveApp(
|
|
27
|
-
indexJS: resolveApp(
|
|
28
|
-
pages: resolveApp(
|
|
29
|
-
override: resolveApp(
|
|
30
|
-
indexHTML: glob.sync(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
theme: getExistPath(resolveApp('theme.json'), resolveApp('theme.js'))
|
|
18
|
+
eduAppEnv: resolveApp("src", "edu-app-env.d.ts"),
|
|
19
|
+
dist: resolveApp("dist"),
|
|
20
|
+
sshSftp: resolveApp(".sftprc.json"),
|
|
21
|
+
nodeModules: resolveApp("node_modules"),
|
|
22
|
+
tsconfig: resolveApp("tsconfig.json"),
|
|
23
|
+
jsconfig: resolveApp("jsconfig.json"),
|
|
24
|
+
package: resolveApp("package.json"),
|
|
25
|
+
tailwind: resolveApp("tailwind.config.js"),
|
|
26
|
+
indexJS: resolveApp("src", "index.js"),
|
|
27
|
+
pages: resolveApp("src", "pages"),
|
|
28
|
+
override: resolveApp("edu-scripts.override.js"),
|
|
29
|
+
indexHTML: glob.sync("./public/*.html", { absolute: true }),
|
|
30
|
+
src: resolveApp("src"),
|
|
31
|
+
public: resolveApp("public"),
|
|
32
|
+
static: resolveApp("public", "static"),
|
|
33
|
+
theme: getExistPath(resolveApp("theme.json"), resolveApp("theme.js")),
|
|
34
|
+
mock: resolveApp("mock")
|
|
37
35
|
};
|
|
38
|
-
module.exports = paths;
|
|
36
|
+
module.exports = paths;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
3
|
+
type API = string;
|
|
4
|
+
export type MockConfig = Record<`${Method} ${API}`, string | number | null | undefined | boolean | Record<string, any> | RequestHandler>;
|
|
5
|
+
export declare function defineMock(config: MockConfig): MockConfig;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
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);
|
|
18
|
+
|
|
19
|
+
// src/config/plugins/mock-server/defineMock.ts
|
|
20
|
+
var defineMock_exports = {};
|
|
21
|
+
__export(defineMock_exports, {
|
|
22
|
+
defineMock: () => defineMock
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(defineMock_exports);
|
|
25
|
+
function defineMock(config) {
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
defineMock
|
|
31
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/config/plugins/mock-server/index.js
|
|
2
|
+
var paths = require("../../paths");
|
|
3
|
+
var globby = require("globby");
|
|
4
|
+
var chokidar = require("chokidar");
|
|
5
|
+
var debounce = require("lodash/debounce");
|
|
6
|
+
var chalk = require("chalk");
|
|
7
|
+
var fs = require("fs-extra");
|
|
8
|
+
var express = require("express");
|
|
9
|
+
var cookieParser = require("cookie-parser");
|
|
10
|
+
var mockCache = {};
|
|
11
|
+
var isSetup = false;
|
|
12
|
+
var setupMock = debounce(function setupMock2() {
|
|
13
|
+
mockCache = {};
|
|
14
|
+
const files = globby.sync(paths.mock);
|
|
15
|
+
if (isSetup) {
|
|
16
|
+
console.log(chalk.green("Mock files changed, reloaded"));
|
|
17
|
+
} else {
|
|
18
|
+
isSetup = true;
|
|
19
|
+
}
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
delete require.cache[require.resolve(file)];
|
|
22
|
+
try {
|
|
23
|
+
let mock = require(file);
|
|
24
|
+
mock = mock.default || mock;
|
|
25
|
+
mockCache = { ...mockCache, ...mock };
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error(chalk.red(`Mock file ${file} error: ${e.message}`));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
console.log("🚀 ~ file: index.js:47 ~ setupMock ~ mockCache:", mockCache);
|
|
31
|
+
}, 100);
|
|
32
|
+
function mockMiddlewave(req, res, next) {
|
|
33
|
+
const { method, path } = req;
|
|
34
|
+
const key = `${method.toUpperCase()} ${path}`;
|
|
35
|
+
const mock = mockCache[key];
|
|
36
|
+
console.log(chalk.green(`Mock: ${key}`));
|
|
37
|
+
if (mock) {
|
|
38
|
+
if (typeof mock === "function") {
|
|
39
|
+
mock(req, res, next);
|
|
40
|
+
} else {
|
|
41
|
+
res.json(mock);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
next();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function setupMockServer(middelwaves, devServer) {
|
|
48
|
+
if (!fs.existsSync(paths.mock))
|
|
49
|
+
return;
|
|
50
|
+
require("@babel/register")({
|
|
51
|
+
presets: [["@babel/preset-env", { modules: "cjs" }], "@babel/preset-typescript"],
|
|
52
|
+
babelrc: false,
|
|
53
|
+
only: [/\/mock\//, /\/src\//],
|
|
54
|
+
extensions: [".js", ".ts"]
|
|
55
|
+
});
|
|
56
|
+
devServer.app.use(express.urlencoded({ extended: false }));
|
|
57
|
+
devServer.app.use(express.json());
|
|
58
|
+
devServer.app.use(cookieParser());
|
|
59
|
+
middelwaves.unshift({
|
|
60
|
+
name: "edu-scripts-mock-middelwave",
|
|
61
|
+
middleware: mockMiddlewave
|
|
62
|
+
});
|
|
63
|
+
console.log(
|
|
64
|
+
`<i> ${chalk.green.bold("[edu-scripts] Mock server created:")} ${chalk.cyan.bold(paths.mock)}`
|
|
65
|
+
);
|
|
66
|
+
chokidar.watch(paths.mock).on("all", setupMock);
|
|
67
|
+
return middelwaves;
|
|
68
|
+
}
|
|
69
|
+
module.exports = setupMockServer;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// src/config/plugins/postcss-safe-area.js
|
|
2
|
+
var vars = [
|
|
3
|
+
"safe-area-inset-top",
|
|
4
|
+
"safe-area-inset-bottom",
|
|
5
|
+
"safe-area-inset-left",
|
|
6
|
+
"safe-area-inset-right"
|
|
7
|
+
];
|
|
8
|
+
var expr = new RegExp(`env\\(\\s*(${vars.join("|")})\\s*,?\\s*([^)]+)?\\s*\\)`, "g");
|
|
7
9
|
module.exports = () => {
|
|
8
10
|
return {
|
|
9
|
-
postcssPlugin:
|
|
11
|
+
postcssPlugin: "postcss-safe-area",
|
|
10
12
|
Declaration(decl) {
|
|
11
|
-
const fallback = decl.value.replace(expr, (match, param, defaultValue) => defaultValue ||
|
|
13
|
+
const fallback = decl.value.replace(expr, (match, param, defaultValue) => defaultValue || "0");
|
|
12
14
|
if (fallback !== decl.value) {
|
|
13
|
-
decl.cloneBefore({
|
|
14
|
-
value: fallback
|
|
15
|
-
});
|
|
15
|
+
decl.cloneBefore({ value: fallback });
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
};
|
|
19
|
+
};
|