@qse/edu-scripts 1.14.17 → 2.0.0
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 +2 -483
- package/asset/rspack-dev-server-client.js +534 -0
- package/{src/asset → asset}/template/edu-scripts.override.js.tpl +2 -2
- package/{lib/asset → asset}/template/tailwind.config.js.tpl +1 -1
- package/babel.config.json +6 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1426 -0
- package/dist/index.d.mts +83 -0
- package/dist/index.mjs +13 -0
- package/eslint.config.mjs +3 -0
- package/{jest.config.js → jest.config.mjs} +8 -4
- package/package.json +52 -57
- package/src/{auto-refactor.js → auto-refactor.ts} +51 -59
- package/src/{build.js → build.ts} +22 -16
- package/src/{cli.js → cli.ts} +25 -21
- package/src/{commit-dist.js → commit-dist.ts} +28 -21
- package/src/config/paths.ts +52 -0
- package/src/config/plugins/mock-server/{index.js → index.ts} +30 -41
- package/src/config/plugins/{postcss-safe-area.js → postcss-safe-area.ts} +4 -2
- package/src/config/{webpackConfig.js → webpackConfig.ts} +152 -126
- package/src/config/{webpackDevServerConfig.js → webpackDevServerConfig.ts} +18 -18
- package/src/{deploy.js → deploy.ts} +36 -25
- package/src/{generator.js → generator.ts} +5 -14
- package/src/start.ts +52 -0
- package/src/utils/FileSizeReporter.ts +166 -0
- package/src/utils/{appConfig.js → appConfig.ts} +5 -4
- package/src/utils/{beforeStart.js → beforeStart.ts} +18 -29
- package/src/utils/{changeDeployVersion.js → changeDeployVersion.ts} +43 -48
- package/src/utils/defineConfig.ts +19 -36
- package/src/utils/{exec.js → exec.ts} +3 -3
- package/src/utils/{getConfig.js → getConfig.ts} +7 -5
- package/src/utils/getOverride.ts +32 -0
- package/src/utils/resolveModule.ts +3 -0
- package/tsconfig.json +3 -15
- package/tsdown.config.ts +5 -0
- package/docs/changelog.md +0 -5
- package/docs/debug.md +0 -17
- package/docs/deploy.md +0 -54
- package/docs/faq.md +0 -144
- package/docs/feat.md +0 -167
- package/docs/grayscale.md +0 -31
- package/docs/index.md +0 -5
- package/docs/mode.md +0 -42
- package/docs/override.md +0 -193
- package/docs/refactor-react-16.md +0 -37
- package/docs/refactor.md +0 -67
- package/docs/static.md +0 -24
- package/lib/asset/template/edu-scripts.override.js.tpl +0 -7
- package/lib/auto-refactor.js +0 -151
- package/lib/build.js +0 -59
- package/lib/cli.js +0 -66
- package/lib/commit-dist.js +0 -79
- package/lib/config/babel.dependencies.js +0 -79
- package/lib/config/babel.js +0 -107
- package/lib/config/paths.js +0 -36
- package/lib/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -31
- package/lib/config/plugins/mock-server/defineMock.d.ts +0 -6
- package/lib/config/plugins/mock-server/defineMock.js +0 -31
- package/lib/config/plugins/mock-server/index.js +0 -122
- package/lib/config/plugins/postcss-safe-area.js +0 -19
- package/lib/config/plugins/ws-utils-createSocketURL.js +0 -118
- package/lib/config/webpackConfig.js +0 -462
- package/lib/config/webpackDevServerConfig.js +0 -72
- package/lib/deploy.js +0 -143
- package/lib/generator.js +0 -50
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -32
- package/lib/start.js +0 -36
- package/lib/utils/FileSizeReporter.js +0 -107
- package/lib/utils/appConfig.js +0 -32
- package/lib/utils/beforeStart.js +0 -62
- package/lib/utils/changeDeployVersion.js +0 -89
- package/lib/utils/defineConfig.d.ts +0 -93
- package/lib/utils/defineConfig.js +0 -31
- package/lib/utils/exec.js +0 -7
- package/lib/utils/getConfig.js +0 -20
- package/lib/utils/getOverride.js +0 -61
- package/src/asset/dll/libcommon3-manifest.json +0 -181
- package/src/asset/template/edu-app-env.d.ts.tpl +0 -20
- package/src/asset/template/tailwind.config.js.tpl +0 -11
- package/src/asset/template/tsconfig.json.tpl +0 -24
- package/src/config/babel.dependencies.js +0 -66
- package/src/config/babel.js +0 -94
- package/src/config/paths.js +0 -38
- package/src/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -55
- package/src/config/plugins/ws-utils-createSocketURL.js +0 -140
- package/src/start.js +0 -44
- package/src/utils/FileSizeReporter.js +0 -151
- package/src/utils/getOverride.js +0 -48
- /package/{lib/asset → asset}/dll/libcommon3-manifest.json +0 -0
- /package/{lib/asset → asset}/template/edu-app-env.d.ts.tpl +0 -0
- /package/{lib/asset → asset}/template/tsconfig.json.tpl +0 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Chalk } from "chalk";
|
|
2
|
+
import { Compiler, Configuration, SwcLoaderOptions } from "@rspack/core";
|
|
3
|
+
import { Configuration as Configuration$1 } from "@rspack/dev-server";
|
|
4
|
+
import { RequestHandler } from "express";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/defineConfig.d.ts
|
|
7
|
+
type ProxyConfigArray = NonNullable<Configuration$1['proxy']>;
|
|
8
|
+
type Configuration$2 = {
|
|
9
|
+
webpack?: (config: Configuration) => Configuration | undefined;
|
|
10
|
+
devServer?: (config: Configuration$1) => Configuration$1 | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* webpack alias 配置,会与内置 alias 合并
|
|
13
|
+
*
|
|
14
|
+
* 会自动读取 tsconfig 里 baseUrl + paths 的配置
|
|
15
|
+
*
|
|
16
|
+
* @default
|
|
17
|
+
* { '@': './src' }
|
|
18
|
+
*/
|
|
19
|
+
alias?: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* webpack externals 配置,会与内置 externals 合并
|
|
22
|
+
*/
|
|
23
|
+
externals?: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* terser pure_funcs,esbuild pure 配置,传 [] 可以不清空 console.log
|
|
26
|
+
* @default ['console.log']
|
|
27
|
+
*/
|
|
28
|
+
pure_funcs?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* 是否压缩代码
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
minify?: boolean; /** 自定义全局参数 */
|
|
34
|
+
define?: Record<string, any>;
|
|
35
|
+
/**
|
|
36
|
+
* context 填写的顺序很重要,前面的会优先匹配。可以重复定义 /api 来覆盖默认的配置
|
|
37
|
+
*
|
|
38
|
+
* proxy 会自动删除请求头 referer,避免某些后端校验失败的问题
|
|
39
|
+
* @see https://webpack.js.org/configuration/dev-server/#devserverproxy
|
|
40
|
+
* @default /api -> /qsxxwapdev/api
|
|
41
|
+
* @example { '/api': 'http://localhost:3000' }
|
|
42
|
+
* @example [{ context: ['/api'], target: 'http://localhost:3000' }]
|
|
43
|
+
*/
|
|
44
|
+
proxy?: ProxyConfigArray | Record<string, string>;
|
|
45
|
+
extraPostCSSPlugins?: any[];
|
|
46
|
+
/**
|
|
47
|
+
* 开启 mock 功能,会自动加载 mock 文件夹下的文件
|
|
48
|
+
*
|
|
49
|
+
* 默认情况下自动判断根目录是否存在 mock 文件夹,如果存在则开启 mock 功能。
|
|
50
|
+
* 如果设置 false,会关闭 mock 功能
|
|
51
|
+
*/
|
|
52
|
+
mock?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 开发模式启动后用来展示启动后的提示信息,或者自定义的逻辑
|
|
55
|
+
*/
|
|
56
|
+
startup?: (params: {
|
|
57
|
+
/** 控制台输出内容 */logger: ReturnType<Compiler['getInfrastructureLogger']>; /** 字体颜色相关工具 */
|
|
58
|
+
chalk: Chalk; /** webpack compiler 自定义的时候会用到 */
|
|
59
|
+
compiler: Compiler;
|
|
60
|
+
}) => void;
|
|
61
|
+
/**
|
|
62
|
+
* 是否开启装饰器语法支持 只支持 legacy 版本
|
|
63
|
+
* @see https://babeljs.io/docs/en/babel-plugin-proposal-decorators
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
decorators?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 与 babel-plugin-import 类似,但是内部是 rspack 重构,libraryDirectory 默认值是 lib
|
|
69
|
+
*
|
|
70
|
+
* @see https://rspack.rs/zh/guide/features/builtin-swc-loader#rspackexperimentsimport
|
|
71
|
+
* @default [{libraryName: 'lodash',libraryDirectory: '',camelToDashComponentName: false}]
|
|
72
|
+
*/
|
|
73
|
+
import?: NonNullable<SwcLoaderOptions['rspackExperiments']>['import'];
|
|
74
|
+
};
|
|
75
|
+
declare function defineConfig(config: Configuration$2): Configuration$2;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/config/plugins/mock-server/defineMock.d.ts
|
|
78
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
79
|
+
type API = string;
|
|
80
|
+
type MockConfig = Record<`${Method} ${API}`, string | number | null | undefined | boolean | Record<string, any> | RequestHandler>;
|
|
81
|
+
declare function defineMock(config: MockConfig): MockConfig;
|
|
82
|
+
//#endregion
|
|
83
|
+
export { defineConfig, defineMock };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/utils/defineConfig.ts
|
|
2
|
+
function defineConfig(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/config/plugins/mock-server/defineMock.ts
|
|
8
|
+
function defineMock(config) {
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { defineConfig, defineMock };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* https://jestjs.io/docs/configuration
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export default {
|
|
7
7
|
// All imported modules in your tests should be mocked automatically
|
|
8
8
|
// automock: false,
|
|
9
9
|
|
|
@@ -11,11 +11,15 @@ module.exports = {
|
|
|
11
11
|
// bail: 0,
|
|
12
12
|
|
|
13
13
|
// The directory where Jest should store its cached dependency information
|
|
14
|
-
// cacheDirectory: "/private/var/folders/
|
|
14
|
+
// cacheDirectory: "/private/var/folders/71/g8xbd8f97pzcxd6csv8wxw6h0000gn/T/jest_dx",
|
|
15
15
|
|
|
16
16
|
// Automatically clear mock calls, instances, contexts and results before every test
|
|
17
17
|
clearMocks: true,
|
|
18
18
|
|
|
19
|
+
// Enable ESM support for Node.js test environment
|
|
20
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
21
|
+
testEnvironment: 'node',
|
|
22
|
+
|
|
19
23
|
// Indicates whether the coverage information should be collected while executing the test
|
|
20
24
|
// collectCoverage: false,
|
|
21
25
|
|
|
@@ -173,7 +177,7 @@ module.exports = {
|
|
|
173
177
|
// testRunner: "jest-circus/runner",
|
|
174
178
|
|
|
175
179
|
// A map from regular expressions to paths to transformers
|
|
176
|
-
// transform: undefined
|
|
180
|
+
// transform: undefined
|
|
177
181
|
|
|
178
182
|
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
179
183
|
// transformIgnorePatterns: [
|
|
@@ -192,4 +196,4 @@ module.exports = {
|
|
|
192
196
|
|
|
193
197
|
// Whether to use watchman for file crawling
|
|
194
198
|
// watchman: true,
|
|
195
|
-
}
|
|
199
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qse/edu-scripts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "Kinoko",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"description": "教育工程化基础框架",
|
|
7
8
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
9
|
+
"node": ">=18"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"docs:
|
|
12
|
+
"dev": "tsdown --watch",
|
|
13
|
+
"docs:dev": "vitepress dev docs",
|
|
14
|
+
"docs:build": "vitepress build docs",
|
|
13
15
|
"docs:deploy": "ssh-sftp",
|
|
14
|
-
"build": "
|
|
15
|
-
"deploy": "node scripts/deploy
|
|
16
|
-
"release": "npm run test && npm run build && npm publish && rimraf
|
|
16
|
+
"build": "tsdown",
|
|
17
|
+
"deploy": "node scripts/deploy.js",
|
|
18
|
+
"release": "npm run test && npm run build && npm publish && rimraf dist",
|
|
17
19
|
"prettier": "prettier -c -w \"src/**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
|
18
20
|
"lint": "eslint --fix src",
|
|
19
21
|
"postversion": "npm run release",
|
|
@@ -22,52 +24,43 @@
|
|
|
22
24
|
"homepage": "http://192.168.10.19:3339/qsxxwapdev/edu-scripts/",
|
|
23
25
|
"publishConfig": {
|
|
24
26
|
"registry": "https://registry.npmjs.org/",
|
|
25
|
-
"access": "public"
|
|
27
|
+
"access": "public",
|
|
28
|
+
"tag": "beta"
|
|
26
29
|
},
|
|
27
30
|
"bin": {
|
|
28
|
-
"edu-scripts": "
|
|
29
|
-
"edu": "
|
|
30
|
-
},
|
|
31
|
-
"main": "lib/index.js",
|
|
32
|
-
"typings": "lib/index.d.ts",
|
|
33
|
-
"eslintConfig": {
|
|
34
|
-
"extends": "qsb-react"
|
|
31
|
+
"edu-scripts": "dist/cli.mjs",
|
|
32
|
+
"edu": "dist/cli.mjs"
|
|
35
33
|
},
|
|
34
|
+
"main": "dist/index.mjs",
|
|
35
|
+
"typings": "dist/index.d.mts",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@babel/core": "~7.
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@babel/register": "~7.25.9",
|
|
44
|
-
"@babel/runtime": "~7.27.0",
|
|
45
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.16",
|
|
46
|
-
"@qse/ssh-sftp": "^1.1.0",
|
|
37
|
+
"@babel/core": "~7.29.0",
|
|
38
|
+
"@qse/ssh-sftp": "^1.3.1",
|
|
39
|
+
"@rsdoctor/rspack-plugin": "^1.5.2",
|
|
40
|
+
"@rspack/core": "^1.7.6",
|
|
41
|
+
"@rspack/dev-server": "^1.2.1",
|
|
42
|
+
"@rspack/plugin-react-refresh": "^1.6.1",
|
|
47
43
|
"@svgr/webpack": "^8.1.0",
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
44
|
+
"@swc-node/register": "^1.11.1",
|
|
45
|
+
"@swc/helpers": "^0.5.19",
|
|
46
|
+
"@types/express": "^4.17.25",
|
|
52
47
|
"chalk": "^4.1.2",
|
|
53
48
|
"chokidar": "^3.6.0",
|
|
54
49
|
"cookie-parser": "^1.4.7",
|
|
55
50
|
"css-loader": "^6.11.0",
|
|
56
51
|
"cssnano": "^6.1.2",
|
|
57
|
-
"debug": "^4.4.0",
|
|
58
|
-
"esbuild-loader": "^2.21.0",
|
|
59
52
|
"express": "^4.21.2",
|
|
60
53
|
"filesize": "^8.0.7",
|
|
61
|
-
"fs-extra": "^
|
|
62
|
-
"globby": "^
|
|
63
|
-
"gzip-size": "^
|
|
64
|
-
"html-webpack-plugin": "^5.6.
|
|
65
|
-
"inquirer": "^8.
|
|
54
|
+
"fs-extra": "^11.3.3",
|
|
55
|
+
"globby": "^16.1.1",
|
|
56
|
+
"gzip-size": "^7.0.0",
|
|
57
|
+
"html-webpack-plugin": "^5.6.6",
|
|
58
|
+
"@inquirer/prompts": "^8.3.0",
|
|
66
59
|
"less": "^3.13.1",
|
|
67
60
|
"less-loader": "^10.2.0",
|
|
68
|
-
"lodash": "^4.17.
|
|
69
|
-
"multer": "^1.
|
|
70
|
-
"
|
|
61
|
+
"lodash-es": "^4.17.23",
|
|
62
|
+
"multer": "^2.1.0",
|
|
63
|
+
"ora": "^9.3.0",
|
|
71
64
|
"path-to-regexp": "^6.3.0",
|
|
72
65
|
"postcss": "^8.5.3",
|
|
73
66
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
@@ -75,33 +68,35 @@
|
|
|
75
68
|
"postcss-momentum-scrolling": "^3.14.22",
|
|
76
69
|
"postcss-normalize": "^8.0.1",
|
|
77
70
|
"postcss-preset-env": "^9.6.0",
|
|
78
|
-
"prettier": "^
|
|
79
|
-
"prettier-plugin-tailwindcss": "^0.
|
|
71
|
+
"prettier": "^3.8.1",
|
|
72
|
+
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
80
73
|
"react-refresh": "^0.14.2",
|
|
81
74
|
"recursive-readdir": "^2.2.3",
|
|
82
|
-
"rimraf": "^3.0.2",
|
|
83
75
|
"semver": "^7.7.1",
|
|
84
76
|
"strip-ansi": "^6.0.1",
|
|
85
77
|
"style-loader": "^3.3.4",
|
|
86
|
-
"tailwindcss": "^3.4.
|
|
87
|
-
"terser-webpack-plugin": "~5.3.14",
|
|
78
|
+
"tailwindcss": "^3.4.19",
|
|
88
79
|
"tmp": "^0.2.3",
|
|
89
|
-
"typescript": "^5.
|
|
90
|
-
"update-notifier": "^5.1.0",
|
|
80
|
+
"typescript": "^5.9.3",
|
|
91
81
|
"url-loader": "^4.1.1",
|
|
92
|
-
"webpack": "^5.99.6",
|
|
93
|
-
"webpack-bundle-analyzer": "^4.10.2",
|
|
94
|
-
"webpack-dev-server": "^4.15.2",
|
|
95
|
-
"webpack-retry-chunk-load-plugin": "^3.1.1",
|
|
96
82
|
"yargs": "^17.7.2"
|
|
97
83
|
},
|
|
98
84
|
"devDependencies": {
|
|
99
|
-
"@
|
|
100
|
-
"@
|
|
101
|
-
"@
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
85
|
+
"@babel/preset-env": "~7.29.0",
|
|
86
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
87
|
+
"@qse/eslint-config": "^1.0.0",
|
|
88
|
+
"@types/cookie-parser": "^1.4.10",
|
|
89
|
+
"@types/fs-extra": "^11.0.4",
|
|
90
|
+
"@types/jest": "^30.0.0",
|
|
91
|
+
"@types/lodash-es": "^4.17.12",
|
|
92
|
+
"@types/multer": "^2.0.0",
|
|
93
|
+
"@types/semver": "^7.7.1",
|
|
94
|
+
"@types/tmp": "^0.2.6",
|
|
95
|
+
"@types/yargs": "^17.0.35",
|
|
96
|
+
"eslint": "^9.39.3",
|
|
97
|
+
"jest": "^30.2.0",
|
|
98
|
+
"rimraf": "^6.1.3",
|
|
99
|
+
"tsdown": "^0.20.3",
|
|
100
|
+
"vitepress": "^1.6.4"
|
|
106
101
|
}
|
|
107
102
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @param {string} msg
|
|
13
|
-
* @param {(spinner:ora.Ora) => void | Promise<void>} callback
|
|
14
|
-
*/
|
|
15
|
-
async function step(msg, callback) {
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import paths from './config/paths'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import { globby } from 'globby'
|
|
6
|
+
import ora from 'ora'
|
|
7
|
+
import { input, select, checkbox } from '@inquirer/prompts'
|
|
8
|
+
|
|
9
|
+
const pkg = fs.readJsonSync(paths.resolveOwn('package.json'))
|
|
10
|
+
|
|
11
|
+
async function step(msg: string, callback: (spinner: import('ora').Ora) => void | Promise<void>) {
|
|
16
12
|
const spinner = ora(msg).start()
|
|
17
13
|
try {
|
|
18
14
|
await callback(spinner)
|
|
@@ -23,55 +19,53 @@ async function step(msg, callback) {
|
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
export default async function autoRefactor() {
|
|
27
23
|
if (await fs.pathExists(paths.public)) {
|
|
28
24
|
console.log(chalk.green('已完成改造,不需要重复执行,如果运行报错请查看文档'))
|
|
29
25
|
console.log(`文档: ${chalk.underline(pkg.homepage)}`)
|
|
30
26
|
process.exit(0)
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
const appPkg =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
name: '
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
type: 'checkbox',
|
|
64
|
-
name: 'deploy',
|
|
29
|
+
const appPkg = fs.readJsonSync(paths.package)
|
|
30
|
+
|
|
31
|
+
const name = await input({
|
|
32
|
+
message: '请输入模块名称,要求唯一,不能与其他工程相同',
|
|
33
|
+
default: appPkg.name,
|
|
34
|
+
validate: (v) =>
|
|
35
|
+
/^[a-z][a-z0-9_-]+$/.test(v) ||
|
|
36
|
+
'请按格式输入 /^[a-z][a-z0-9_-]+$/ 只能使用小写字母、连字符、下划线',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const version = await input({
|
|
40
|
+
message: '版本号',
|
|
41
|
+
default: '1.0.0',
|
|
42
|
+
validate: (v) =>
|
|
43
|
+
/^\d+\.\d+\.\d+$/.test(v) || '请按格式输入 /^\\d+\\.\\d+\\.\\d+$/ 例如: 1.0.0',
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const mode = await select({
|
|
47
|
+
message: '项目使用的哪种模式',
|
|
48
|
+
choices: [
|
|
49
|
+
{ name: '教育子工程模式', value: '' },
|
|
50
|
+
{ name: '教育主工程模式', value: 'main' },
|
|
51
|
+
{ name: '独立模式', value: 'single' },
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
let deploy: string[] = []
|
|
56
|
+
if (mode !== 'single') {
|
|
57
|
+
deploy = await checkbox({
|
|
65
58
|
message: '项目需要部署到哪里',
|
|
66
|
-
when: (ans) => ans.mode !== 'single',
|
|
67
59
|
choices: [
|
|
68
60
|
{ name: '校端', value: '-s' },
|
|
69
61
|
{ name: '局端', value: '-b' },
|
|
70
62
|
{ name: '公文端', value: '-d' },
|
|
71
63
|
],
|
|
72
64
|
validate: (v) => (!!v && v.length > 0) || '必须选一个',
|
|
73
|
-
}
|
|
74
|
-
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const answers = { name, version, mode, deploy }
|
|
75
69
|
appPkg.name = answers.name
|
|
76
70
|
appPkg.version = answers.version
|
|
77
71
|
|
|
@@ -86,7 +80,7 @@ module.exports = async function autoRefactor() {
|
|
|
86
80
|
})
|
|
87
81
|
|
|
88
82
|
await step('移动 html 文件', async () => {
|
|
89
|
-
const HTMLFiles = await
|
|
83
|
+
const HTMLFiles = await globby('*.html', { cwd: paths.src })
|
|
90
84
|
for (const file of HTMLFiles) {
|
|
91
85
|
await fs.move(path.resolve(paths.src, file), path.resolve(paths.public, file))
|
|
92
86
|
}
|
|
@@ -100,9 +94,9 @@ module.exports = async function autoRefactor() {
|
|
|
100
94
|
|
|
101
95
|
await step('删除没用的 babel 和 webpack 配置', async () => {
|
|
102
96
|
const deleteFiles = [
|
|
103
|
-
...(await
|
|
104
|
-
...(await
|
|
105
|
-
...(await
|
|
97
|
+
...(await globby('{.,*}babel*')),
|
|
98
|
+
...(await globby('*webpack*')),
|
|
99
|
+
...(await globby('package-lock.json')),
|
|
106
100
|
paths.nodeModules,
|
|
107
101
|
paths.sshSftp,
|
|
108
102
|
]
|
|
@@ -137,8 +131,8 @@ module.exports = async function autoRefactor() {
|
|
|
137
131
|
/(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa|prettier)/i
|
|
138
132
|
|
|
139
133
|
const deletePkgs = {
|
|
140
|
-
dependencies: [],
|
|
141
|
-
devDependencies: [],
|
|
134
|
+
dependencies: [] as string[],
|
|
135
|
+
devDependencies: [] as string[],
|
|
142
136
|
}
|
|
143
137
|
Object.entries(deletePkgs).forEach(([scope, pkgs]) => {
|
|
144
138
|
for (const key in appPkg[scope]) {
|
|
@@ -158,8 +152,6 @@ module.exports = async function autoRefactor() {
|
|
|
158
152
|
|
|
159
153
|
await fs.writeFile(paths.package, JSON.stringify(appPkg, null, 2), 'utf-8')
|
|
160
154
|
|
|
161
|
-
open(`${pkg.homepage}#/refactor`)
|
|
162
|
-
|
|
163
155
|
console.log(
|
|
164
156
|
chalk.green(`
|
|
165
157
|
改造还未完成,剩余步骤请查看文档
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { rspack, type Stats } from '@rspack/core'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import getConfig from './utils/getConfig'
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { measureFileSizesBeforeBuild, printFileSizesAfterBuild } from './utils/FileSizeReporter'
|
|
6
|
+
import paths from './config/paths'
|
|
7
|
+
import fs from 'fs-extra'
|
|
8
|
+
import appConfig from './utils/appConfig'
|
|
4
9
|
|
|
5
|
-
const webpack = require('webpack')
|
|
6
|
-
const chalk = require('chalk')
|
|
7
|
-
const getConfig = require('./utils/getConfig')
|
|
8
|
-
const {
|
|
9
|
-
measureFileSizesBeforeBuild,
|
|
10
|
-
printFileSizesAfterBuild,
|
|
11
|
-
} = require('./utils/FileSizeReporter')
|
|
12
|
-
const paths = require('./config/paths')
|
|
13
|
-
const fs = require('fs-extra')
|
|
14
|
-
const appConfig = require('./utils/appConfig')
|
|
15
10
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = appConfig.single ? 1024 * 1024 : 30 * 1024
|
|
16
11
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
interface BuildArgs {
|
|
14
|
+
analyze?: boolean
|
|
15
|
+
outputHtml?: boolean
|
|
16
|
+
}
|
|
17
|
+
export default async function build(args: BuildArgs) {
|
|
18
|
+
process.env.NODE_ENV = 'production'
|
|
19
|
+
process.env.BABEL_ENV = 'production'
|
|
20
|
+
process.env.BROWSERSLIST = '>0.2%, iOS>=9, ie 11, chrome>=49, not op_mini all'
|
|
21
|
+
process.env.BROWSERSLIST_IGNORE_OLD_DATA = 'true'
|
|
22
|
+
|
|
19
23
|
if (args.analyze) {
|
|
20
24
|
process.env.ANALYZE = '1'
|
|
21
25
|
}
|
|
@@ -33,14 +37,16 @@ module.exports = async function build(args) {
|
|
|
33
37
|
fs.copySync(paths.static, paths.resolveApp('dist', 'static'))
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
const config = getConfig(args)
|
|
41
|
+
rspack(config, (error, stats: Stats | undefined) => {
|
|
37
42
|
if (error) {
|
|
38
43
|
console.log(chalk.red('编译失败'))
|
|
39
44
|
console.log(chalk.red(error.message || error))
|
|
40
|
-
console.log()
|
|
41
45
|
process.exit(1)
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
if (!stats) return
|
|
49
|
+
|
|
44
50
|
if (stats.compilation.errors.length) {
|
|
45
51
|
console.log(chalk.red('编译失败'))
|
|
46
52
|
console.log(stats.toString({ all: false, errors: true, colors: true }))
|
package/src/{cli.js → cli.ts}
RENAMED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import '@swc-node/register/esm-register'
|
|
3
|
+
import './utils/beforeStart'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import fs from 'fs-extra'
|
|
6
|
+
import yargs from 'yargs'
|
|
7
|
+
import paths from './config/paths'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
import start from './start'
|
|
10
|
+
import build from './build'
|
|
11
|
+
import deploy from './deploy'
|
|
12
|
+
import autoRefactor from './auto-refactor'
|
|
13
|
+
import commitDist from './commit-dist'
|
|
14
|
+
import * as generator from './generator'
|
|
15
|
+
|
|
16
|
+
const pkg = fs.readJsonSync(paths.resolveOwn('package.json'))
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
19
|
+
yargs(process.argv.slice(2))
|
|
9
20
|
.usage(`教育工程化 webpack5 基础框架\n文档: ${pkg.homepage}`)
|
|
10
21
|
.command(
|
|
11
22
|
'start',
|
|
12
23
|
'开发',
|
|
13
|
-
(yargs) =>
|
|
14
|
-
|
|
15
|
-
.option('port', { alias: 'p', desc: '指定端口' })
|
|
16
|
-
.option('open', { desc: '启动后打开页面' }),
|
|
17
|
-
(args) => require('./start')(args)
|
|
24
|
+
(yargs) => yargs.option('port', { alias: 'p', desc: '指定端口', string: true }),
|
|
25
|
+
(args) => start(args)
|
|
18
26
|
)
|
|
19
27
|
.command(
|
|
20
28
|
'build',
|
|
@@ -33,7 +41,7 @@ require('yargs')
|
|
|
33
41
|
default: false,
|
|
34
42
|
boolean: true,
|
|
35
43
|
}),
|
|
36
|
-
(args) =>
|
|
44
|
+
(args) => build(args)
|
|
37
45
|
)
|
|
38
46
|
.command(
|
|
39
47
|
'deploy',
|
|
@@ -60,26 +68,22 @@ require('yargs')
|
|
|
60
68
|
default: false,
|
|
61
69
|
boolean: true,
|
|
62
70
|
}),
|
|
63
|
-
(args) =>
|
|
71
|
+
(args) => deploy(args)
|
|
64
72
|
)
|
|
65
73
|
.command(['generator', 'g'], '自动生成代码', (yargs) =>
|
|
66
74
|
yargs
|
|
67
|
-
.command('override', '创建 override 文件', {}, (
|
|
68
|
-
|
|
69
|
-
)
|
|
70
|
-
.command('tailwind', '创建 tailwind 文件', {}, (args) =>
|
|
71
|
-
require('./generator').tailwind(args)
|
|
72
|
-
)
|
|
73
|
-
.command('ts', '创建 tsconfig 文件', {}, (args) => require('./generator').ts(args))
|
|
75
|
+
.command('override', '创建 override 文件', {}, () => generator.override())
|
|
76
|
+
.command('tailwind', '创建 tailwind 文件', {}, () => generator.tailwind())
|
|
77
|
+
.command('ts', '创建 tsconfig 文件', {}, () => generator.ts())
|
|
74
78
|
.showHelpOnFail(true)
|
|
75
79
|
.demandCommand(1, '')
|
|
76
80
|
)
|
|
77
|
-
.command('auto-refactor', '自动改造项目', {}, () =>
|
|
81
|
+
.command('auto-refactor', '自动改造项目', {}, () => autoRefactor())
|
|
78
82
|
.command(
|
|
79
83
|
'commit-dist',
|
|
80
84
|
'提交 dist 目录到 dist 分支',
|
|
81
85
|
(yargs) => yargs.option('rm-local', { desc: '提交完后删除本地 dist', type: 'boolean' }),
|
|
82
|
-
(args) =>
|
|
86
|
+
(args) => commitDist(args)
|
|
83
87
|
)
|
|
84
88
|
.showHelpOnFail(true)
|
|
85
89
|
.demandCommand(1, '')
|