@qse/edu-scripts 1.15.0 → 2.0.1

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 (94) hide show
  1. package/CHANGELOG.md +4 -489
  2. package/asset/rspack-dev-server-client.js +534 -0
  3. package/{src/asset → asset}/template/edu-scripts.override.js.tpl +2 -2
  4. package/{lib/asset → asset}/template/tailwind.config.js.tpl +1 -1
  5. package/babel.config.json +6 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +1432 -0
  8. package/dist/index.d.mts +83 -0
  9. package/dist/index.mjs +13 -0
  10. package/eslint.config.mjs +3 -0
  11. package/{jest.config.js → jest.config.mjs} +8 -4
  12. package/package.json +67 -67
  13. package/pnpm-workspace.yaml +2 -0
  14. package/src/{auto-refactor.js → auto-refactor.ts} +51 -59
  15. package/src/{build.js → build.ts} +22 -16
  16. package/src/{cli.js → cli.ts} +26 -21
  17. package/src/{commit-dist.js → commit-dist.ts} +28 -21
  18. package/src/config/paths.ts +52 -0
  19. package/src/config/plugins/mock-server/{index.js → index.ts} +30 -41
  20. package/src/config/plugins/{postcss-safe-area.js → postcss-safe-area.ts} +4 -2
  21. package/src/config/{webpackConfig.js → webpackConfig.ts} +157 -126
  22. package/src/config/{webpackDevServerConfig.js → webpackDevServerConfig.ts} +18 -18
  23. package/src/{deploy.js → deploy.ts} +36 -25
  24. package/src/{generator.js → generator.ts} +5 -14
  25. package/src/start.ts +52 -0
  26. package/src/utils/FileSizeReporter.ts +166 -0
  27. package/src/utils/{appConfig.js → appConfig.ts} +5 -4
  28. package/src/utils/{beforeStart.js → beforeStart.ts} +19 -7
  29. package/src/utils/{changeDeployVersion.js → changeDeployVersion.ts} +43 -48
  30. package/src/utils/defineConfig.ts +19 -36
  31. package/src/utils/esm-register.ts +6 -0
  32. package/src/utils/{exec.js → exec.ts} +3 -3
  33. package/src/utils/{getConfig.js → getConfig.ts} +7 -5
  34. package/src/utils/getOverride.ts +32 -0
  35. package/src/utils/resolveModule.ts +3 -0
  36. package/tsconfig.json +3 -15
  37. package/tsdown.config.ts +5 -0
  38. package/docs/changelog.md +0 -5
  39. package/docs/debug.md +0 -17
  40. package/docs/deploy.md +0 -54
  41. package/docs/faq.md +0 -144
  42. package/docs/feat.md +0 -167
  43. package/docs/grayscale.md +0 -31
  44. package/docs/index.md +0 -5
  45. package/docs/mode.md +0 -42
  46. package/docs/override.md +0 -193
  47. package/docs/refactor-react-16.md +0 -37
  48. package/docs/refactor.md +0 -67
  49. package/docs/static.md +0 -24
  50. package/lib/asset/template/edu-scripts.override.js.tpl +0 -7
  51. package/lib/auto-refactor.js +0 -151
  52. package/lib/build.js +0 -59
  53. package/lib/cli.js +0 -66
  54. package/lib/commit-dist.js +0 -79
  55. package/lib/config/babel.dependencies.js +0 -79
  56. package/lib/config/babel.js +0 -107
  57. package/lib/config/paths.js +0 -36
  58. package/lib/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -31
  59. package/lib/config/plugins/mock-server/defineMock.d.ts +0 -6
  60. package/lib/config/plugins/mock-server/defineMock.js +0 -31
  61. package/lib/config/plugins/mock-server/index.js +0 -122
  62. package/lib/config/plugins/postcss-safe-area.js +0 -19
  63. package/lib/config/plugins/ws-utils-createSocketURL.js +0 -118
  64. package/lib/config/webpackConfig.js +0 -462
  65. package/lib/config/webpackDevServerConfig.js +0 -72
  66. package/lib/deploy.js +0 -143
  67. package/lib/generator.js +0 -50
  68. package/lib/index.d.ts +0 -2
  69. package/lib/index.js +0 -32
  70. package/lib/start.js +0 -36
  71. package/lib/utils/FileSizeReporter.js +0 -107
  72. package/lib/utils/appConfig.js +0 -32
  73. package/lib/utils/beforeStart.js +0 -50
  74. package/lib/utils/changeDeployVersion.js +0 -89
  75. package/lib/utils/defineConfig.d.ts +0 -93
  76. package/lib/utils/defineConfig.js +0 -31
  77. package/lib/utils/exec.js +0 -7
  78. package/lib/utils/getConfig.js +0 -20
  79. package/lib/utils/getOverride.js +0 -61
  80. package/src/asset/dll/libcommon3-manifest.json +0 -181
  81. package/src/asset/template/edu-app-env.d.ts.tpl +0 -20
  82. package/src/asset/template/tailwind.config.js.tpl +0 -11
  83. package/src/asset/template/tsconfig.json.tpl +0 -24
  84. package/src/config/babel.dependencies.js +0 -66
  85. package/src/config/babel.js +0 -94
  86. package/src/config/paths.js +0 -38
  87. package/src/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -55
  88. package/src/config/plugins/ws-utils-createSocketURL.js +0 -140
  89. package/src/start.js +0 -44
  90. package/src/utils/FileSizeReporter.js +0 -151
  91. package/src/utils/getOverride.js +0 -48
  92. /package/{lib/asset → asset}/dll/libcommon3-manifest.json +0 -0
  93. /package/{lib/asset → asset}/template/edu-app-env.d.ts.tpl +0 -0
  94. /package/{lib/asset → asset}/template/tsconfig.json.tpl +0 -0
@@ -1,31 +0,0 @@
1
- // src/config/plugins/babel-plugin-add-webpack-chunk-name.js
2
- function removeTrailingIndex(string) {
3
- return string.split("_").length - 1 > 1 ? string.replace(/_index$/, "") : string;
4
- }
5
- function convertToKebabCase(string) {
6
- return string.replace(/\s+/g, "_");
7
- }
8
- function getChunkName(filename) {
9
- filename = filename.split("/").map((part) => part.replace(/\..*$/, "").replace(/[^a-zA-Z0-9-_/]/g, "")).filter(Boolean).map(convertToKebabCase).join("_");
10
- return removeTrailingIndex(filename);
11
- }
12
- function hasComment(comment) {
13
- return comment && comment.value.replace(/\*+/g, "").trim().startsWith("webpackChunkName");
14
- }
15
- function addWebpackChunkName({ types: t }) {
16
- return {
17
- name: "webpack-chunk-name-comments",
18
- visitor: {
19
- Import(path) {
20
- const [arg] = path.parent.arguments;
21
- if (!t.isStringLiteral(arg))
22
- return;
23
- const [comment] = arg.leadingComments || [];
24
- if (!hasComment(comment)) {
25
- t.addComment(arg, "leading", `webpackChunkName: "${getChunkName(arg.value)}"`);
26
- }
27
- }
28
- }
29
- };
30
- }
31
- module.exports = addWebpackChunkName;
@@ -1,6 +0,0 @@
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 {};
@@ -1,31 +0,0 @@
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
- });
@@ -1,122 +0,0 @@
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 memoize = require("lodash/memoize");
7
- var chalk = require("chalk");
8
- var fs = require("fs-extra");
9
- var express = require("express");
10
- var cookieParser = require("cookie-parser");
11
- var multer = require("multer");
12
- var { pathToRegexp } = require("path-to-regexp");
13
- var mockCache = {};
14
- var isSetup = false;
15
- var setupMock = debounce(function setupMock2() {
16
- mockCache = {};
17
- const files = globby.sync(paths.mock, { expandDirectories: { extensions: ["js", "ts"] } });
18
- if (isSetup) {
19
- console.log(chalk.green("Mock files changed, reloaded"));
20
- } else {
21
- isSetup = true;
22
- }
23
- for (const file of files) {
24
- delete require.cache[require.resolve(file)];
25
- try {
26
- let mock = require(file);
27
- mock = mock.default || mock;
28
- for (const key in mock) {
29
- const [method, path] = key.split(" ");
30
- mockCache[key] = { method, path, handler: mock[key] };
31
- }
32
- } catch (e) {
33
- console.error(chalk.red(`Mock file ${file} error: ${e.message}`));
34
- }
35
- }
36
- }, 100);
37
- var getPathReAndKeys = memoize((path) => {
38
- const keys = [];
39
- const re = pathToRegexp(path, keys);
40
- return { re, keys };
41
- });
42
- function decodeParam(val) {
43
- if (typeof val !== "string" || val.length === 0) {
44
- return val;
45
- }
46
- try {
47
- return decodeURIComponent(val);
48
- } catch (err) {
49
- if (err instanceof URIError) {
50
- err.message = `Failed to decode param ' ${val} '`;
51
- err.status = 400;
52
- err.statusCode = 400;
53
- }
54
- throw err;
55
- }
56
- }
57
- function mockMiddlewave(req, res, next) {
58
- const { method, path } = req;
59
- for (const key in mockCache) {
60
- const mock = mockCache[key];
61
- if (mock.method !== method)
62
- continue;
63
- const { keys, re } = getPathReAndKeys(mock.path);
64
- const m = re.exec(path);
65
- if (m) {
66
- console.log(chalk.green(`Mock: ${key}`));
67
- res.setHeader("X-Mock", key);
68
- if (typeof mock.handler === "function") {
69
- const params = {};
70
- for (let i = 1; i < m.length; i += 1) {
71
- const key2 = keys[i - 1];
72
- const prop = key2.name;
73
- const val = decodeParam(m[i]);
74
- if (val !== void 0) {
75
- params[prop] = val;
76
- }
77
- }
78
- req.params = params;
79
- const middelwaves = [
80
- express.urlencoded({ limit: "5mb", extended: true }),
81
- express.json({ limit: "5mb", strict: false }),
82
- multer().any(),
83
- cookieParser(),
84
- mock.handler
85
- ];
86
- const throwNext = () => {
87
- console.log(chalk.red(`Mock: ${key} don't use next()`));
88
- res.sendStatus(500);
89
- };
90
- const mwNext = () => {
91
- const middelwave = middelwaves.shift();
92
- middelwave(req, res, middelwaves.length ? mwNext : throwNext);
93
- };
94
- mwNext();
95
- } else {
96
- res.json(mock.handler);
97
- }
98
- return;
99
- }
100
- }
101
- next();
102
- }
103
- function setupMockServer(middelwaves, devServer) {
104
- if (!fs.existsSync(paths.mock))
105
- return;
106
- require("@babel/register")({
107
- presets: [["@babel/preset-env", { modules: "cjs" }], "@babel/preset-typescript"],
108
- babelrc: false,
109
- only: [/\/mock\//, /\/src\//],
110
- extensions: [".js", ".ts"]
111
- });
112
- middelwaves.unshift({
113
- name: "edu-scripts-mock-middelwave",
114
- middleware: mockMiddlewave
115
- });
116
- console.log(
117
- `<i> ${chalk.green.bold("[edu-scripts] Mock server created:")} ${chalk.cyan.bold(paths.mock)}`
118
- );
119
- chokidar.watch(paths.mock).on("all", setupMock);
120
- return middelwaves;
121
- }
122
- module.exports = setupMockServer;
@@ -1,19 +0,0 @@
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");
9
- module.exports = () => {
10
- return {
11
- postcssPlugin: "postcss-safe-area",
12
- Declaration(decl) {
13
- const fallback = decl.value.replace(expr, (match, param, defaultValue) => defaultValue || "0");
14
- if (fallback !== decl.value) {
15
- decl.cloneBefore({ value: fallback });
16
- }
17
- }
18
- };
19
- };
@@ -1,118 +0,0 @@
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/ws-utils-createSocketURL.js
20
- var ws_utils_createSocketURL_exports = {};
21
- __export(ws_utils_createSocketURL_exports, {
22
- default: () => ws_utils_createSocketURL_default
23
- });
24
- module.exports = __toCommonJS(ws_utils_createSocketURL_exports);
25
- function format(objURL) {
26
- var protocol = objURL.protocol || "";
27
- if (protocol && protocol.substr(-1) !== ":") {
28
- protocol += ":";
29
- }
30
- var auth = objURL.auth || "";
31
- if (auth) {
32
- auth = encodeURIComponent(auth);
33
- auth = auth.replace(/%3A/i, ":");
34
- auth += "@";
35
- }
36
- var host = "";
37
- if (objURL.hostname) {
38
- host = auth + (objURL.hostname.indexOf(":") === -1 ? objURL.hostname : "[".concat(objURL.hostname, "]"));
39
- if (objURL.port) {
40
- host += ":".concat(objURL.port);
41
- }
42
- }
43
- var pathname = objURL.pathname || "";
44
- if (objURL.slashes) {
45
- host = "//".concat(host || "");
46
- if (pathname && pathname.charAt(0) !== "/") {
47
- pathname = "/".concat(pathname);
48
- }
49
- } else if (!host) {
50
- host = "";
51
- }
52
- var search = objURL.search || "";
53
- if (search && search.charAt(0) !== "?") {
54
- search = "?".concat(search);
55
- }
56
- var hash = objURL.hash || "";
57
- if (hash && hash.charAt(0) !== "#") {
58
- hash = "#".concat(hash);
59
- }
60
- pathname = pathname.replace(
61
- /[?#]/g,
62
- /**
63
- * @param {string} match
64
- * @returns {string}
65
- */
66
- function(match) {
67
- return encodeURIComponent(match);
68
- }
69
- );
70
- search = search.replace("#", "%23");
71
- return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
72
- }
73
- function createSocketURL(parsedURL) {
74
- var hostname = parsedURL.hostname;
75
- var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]";
76
- if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf("http") === 0) {
77
- hostname = self.location.hostname;
78
- }
79
- var socketURLProtocol = parsedURL.protocol || self.location.protocol;
80
- if (socketURLProtocol === "auto:" || hostname && isInAddrAny && self.location.protocol === "https:") {
81
- socketURLProtocol = self.location.protocol;
82
- }
83
- socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, "ws");
84
- var socketURLAuth = "";
85
- if (parsedURL.username) {
86
- socketURLAuth = parsedURL.username;
87
- if (parsedURL.password) {
88
- socketURLAuth = socketURLAuth.concat(":", parsedURL.password);
89
- }
90
- }
91
- var socketURLHostname = (hostname || self.location.hostname || "localhost").replace(
92
- /^\[(.*)\]$/,
93
- "$1"
94
- );
95
- var socketURLPort = parsedURL.port;
96
- if (!socketURLPort || socketURLPort === "0") {
97
- socketURLPort = self.location.port;
98
- }
99
- var socketURLPathname = "/ws";
100
- if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
101
- socketURLPathname = parsedURL.pathname;
102
- if (hostname.indexOf("zhidianbao.cn") > -1 || hostname.indexOf("qsban.cn") > -1) {
103
- var ctx = self.location.pathname.split("/")[1];
104
- if (ctx) {
105
- socketURLPathname = "/" + ctx + socketURLPathname;
106
- }
107
- }
108
- }
109
- return format({
110
- protocol: socketURLProtocol,
111
- auth: socketURLAuth,
112
- hostname: socketURLHostname,
113
- port: socketURLPort,
114
- pathname: socketURLPathname,
115
- slashes: true
116
- });
117
- }
118
- var ws_utils_createSocketURL_default = createSocketURL;