@qse/edu-scripts 0.0.0-beta.2 → 0.0.0-beta.4
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/babel.config.json +4 -1
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1440 -0
- package/dist/index.d.mts +89 -0
- package/dist/index.mjs +13 -0
- package/eslint.config.mjs +1 -1
- package/package.json +16 -10
- package/src/{auto-refactor.js → auto-refactor.ts} +6 -10
- package/src/{build.js → build.ts} +15 -7
- package/src/{cli.js → cli.ts} +14 -13
- package/src/{commit-dist.js → commit-dist.ts} +24 -15
- package/src/config/{paths.js → paths.ts} +17 -2
- package/src/config/plugins/mock-server/{index.js → index.ts} +15 -17
- package/src/config/plugins/{postcss-safe-area.js → postcss-safe-area.ts} +4 -2
- package/src/config/webpackConfig.js +37 -14
- package/src/config/webpackDevServerConfig.js +2 -3
- package/src/{deploy.js → deploy.ts} +23 -15
- package/src/{generator.js → generator.ts} +2 -10
- package/src/index.ts +2 -2
- package/src/{start.js → start.ts} +11 -6
- package/src/utils/FileSizeReporter.js +2 -2
- package/src/utils/{appConfig.js → appConfig.ts} +1 -1
- package/src/utils/{beforeStart.js → beforeStart.ts} +14 -5
- package/src/utils/changeDeployVersion.js +3 -3
- package/src/utils/defineConfig.ts +4 -4
- package/src/utils/{exec.js → exec.ts} +1 -1
- package/src/utils/{getConfig.js → getConfig.ts} +6 -4
- package/src/utils/{getOverride.js → getOverride.ts} +6 -8
- package/tsconfig.json +2 -3
- package/tsdown.config.ts +5 -0
- package/docs/.vitepress/config.ts +0 -35
- package/docs/changelog.md +0 -1
- 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 -15
- package/docs/install.md +0 -1
- 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/es/auto-refactor.js +0 -153
- package/es/build.js +0 -58
- package/es/cli.js +0 -65
- package/es/commit-dist.js +0 -83
- package/es/config/paths.js +0 -39
- package/es/config/plugins/mock-server/defineMock.d.ts +0 -6
- package/es/config/plugins/mock-server/defineMock.js +0 -7
- package/es/config/plugins/mock-server/index.js +0 -122
- package/es/config/plugins/postcss-safe-area.js +0 -22
- package/es/config/plugins/ws-utils-createSocketURL.js +0 -98
- package/es/config/webpackConfig.js +0 -421
- package/es/config/webpackDevServerConfig.js +0 -73
- package/es/deploy.js +0 -148
- package/es/generator.js +0 -52
- package/es/index.d.ts +0 -2
- package/es/index.js +0 -7
- package/es/start.js +0 -45
- package/es/utils/FileSizeReporter.js +0 -107
- package/es/utils/appConfig.js +0 -35
- package/es/utils/beforeStart.js +0 -51
- package/es/utils/changeDeployVersion.js +0 -85
- package/es/utils/defineConfig.d.ts +0 -83
- package/es/utils/defineConfig.js +0 -7
- package/es/utils/exec.js +0 -10
- package/es/utils/getConfig.js +0 -23
- package/es/utils/getOverride.js +0 -28
- 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/edu-scripts.override.js.tpl +0 -7
- package/src/asset/template/tailwind.config.js.tpl +0 -11
- package/src/asset/template/tsconfig.json.tpl +0 -24
- /package/{es/asset → asset}/dll/libcommon3-manifest.json +0 -0
- /package/{es/asset → asset}/template/edu-app-env.d.ts.tpl +0 -0
- /package/{es/asset → asset}/template/edu-scripts.override.js.tpl +0 -0
- /package/{es/asset → asset}/template/tailwind.config.js.tpl +0 -0
- /package/{es/asset → asset}/template/tsconfig.json.tpl +0 -0
- /package/{src/config/plugins → asset}/ws-utils-createSocketURL.js +0 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Chalk } from "chalk";
|
|
2
|
+
import { Compiler, Configuration } 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 BabelImportPlugin = {
|
|
9
|
+
libraryName: string;
|
|
10
|
+
libraryDirectory?: string;
|
|
11
|
+
customName?: string;
|
|
12
|
+
style?: boolean | 'css' | string;
|
|
13
|
+
};
|
|
14
|
+
type Configuration$2 = {
|
|
15
|
+
webpack?: (config: Configuration) => Configuration | undefined;
|
|
16
|
+
devServer?: (config: Configuration$1) => Configuration$1 | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* webpack alias 配置,会与内置 alias 合并
|
|
19
|
+
*
|
|
20
|
+
* @default
|
|
21
|
+
* { '@': './src' }
|
|
22
|
+
*/
|
|
23
|
+
alias?: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* webpack externals 配置,会与内置 externals 合并
|
|
26
|
+
*/
|
|
27
|
+
externals?: Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* terser pure_funcs,esbuild pure 配置,传 [] 可以不清空 console.log
|
|
30
|
+
* @default ['console.log']
|
|
31
|
+
*/
|
|
32
|
+
pure_funcs?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* 是否压缩代码
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
minify?: boolean; /** 自定义全局参数 */
|
|
38
|
+
define?: Record<string, any>;
|
|
39
|
+
/**
|
|
40
|
+
* context 填写的顺序很重要,前面的会优先匹配。可以重复定义 /api 来覆盖默认的配置
|
|
41
|
+
*
|
|
42
|
+
* proxy 会自动删除请求头 referer,避免某些后端校验失败的问题
|
|
43
|
+
* @see https://webpack.js.org/configuration/dev-server/#devserverproxy
|
|
44
|
+
* @default /api -> /qsxxwapdev/api
|
|
45
|
+
* @example { '/api': 'http://localhost:3000' }
|
|
46
|
+
* @example [{ context: ['/api'], target: 'http://localhost:3000' }]
|
|
47
|
+
*/
|
|
48
|
+
proxy?: ProxyConfigArray | Record<string, string>;
|
|
49
|
+
extraPostCSSPlugins?: any[];
|
|
50
|
+
/**
|
|
51
|
+
* 开启 mock 功能,会自动加载 mock 文件夹下的文件
|
|
52
|
+
*
|
|
53
|
+
* 默认情况下自动判断根目录是否存在 mock 文件夹,如果存在则开启 mock 功能。
|
|
54
|
+
* 如果设置 false,会关闭 mock 功能
|
|
55
|
+
*/
|
|
56
|
+
mock?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 开发模式启动后用来展示启动后的提示信息,或者自定义的逻辑
|
|
59
|
+
*/
|
|
60
|
+
startup?: (params: {
|
|
61
|
+
/** 控制台输出内容 */logger: ReturnType<Compiler['getInfrastructureLogger']>; /** 字体颜色相关工具 */
|
|
62
|
+
chalk: Chalk; /** webpack compiler 自定义的时候会用到 */
|
|
63
|
+
compiler: Compiler;
|
|
64
|
+
}) => void;
|
|
65
|
+
/**
|
|
66
|
+
* 是否开启装饰器语法支持 只支持 legacy 版本
|
|
67
|
+
* @see https://babeljs.io/docs/en/babel-plugin-proposal-decorators
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
decorators?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 与 babel-plugin-import 类似,但是内部是 rspack 重构,libraryDirectory 默认值是 lib
|
|
73
|
+
*
|
|
74
|
+
* 如果 libraryDirectory 传 ’‘ 则必须使用 customName 来写
|
|
75
|
+
*
|
|
76
|
+
* @see https://rspack.rs/zh/guide/features/builtin-swc-loader#rspackexperimentsimport
|
|
77
|
+
* @default [{libraryName: 'lodash', customName: 'lodash/{{member}}'}]
|
|
78
|
+
*/
|
|
79
|
+
import?: BabelImportPlugin[];
|
|
80
|
+
};
|
|
81
|
+
declare function defineConfig(config: Configuration$2): Configuration$2;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/config/plugins/mock-server/defineMock.d.ts
|
|
84
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
85
|
+
type API = string;
|
|
86
|
+
type MockConfig = Record<`${Method} ${API}`, string | number | null | undefined | boolean | Record<string, any> | RequestHandler>;
|
|
87
|
+
declare function defineMock(config: MockConfig): MockConfig;
|
|
88
|
+
//#endregion
|
|
89
|
+
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 };
|
package/eslint.config.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qse/edu-scripts",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.4",
|
|
4
4
|
"author": "Kinoko",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
"node": ">=18"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
+
"dev": "tsdown --watch",
|
|
12
13
|
"docs:dev": "vitepress dev docs",
|
|
13
14
|
"docs:build": "vitepress build docs",
|
|
14
15
|
"docs:deploy": "ssh-sftp",
|
|
15
|
-
"build": "
|
|
16
|
+
"build": "tsdown",
|
|
16
17
|
"deploy": "node scripts/deploy.js",
|
|
17
18
|
"release": "npm run test && npm run build && npm publish && rimraf es",
|
|
18
19
|
"prettier": "prettier -c -w \"src/**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
|
@@ -27,19 +28,21 @@
|
|
|
27
28
|
"tag": "beta"
|
|
28
29
|
},
|
|
29
30
|
"bin": {
|
|
30
|
-
"edu-scripts": "
|
|
31
|
-
"edu": "
|
|
31
|
+
"edu-scripts": "dist/cli.mjs",
|
|
32
|
+
"edu": "dist/cli.mjs"
|
|
32
33
|
},
|
|
33
|
-
"main": "
|
|
34
|
-
"typings": "
|
|
34
|
+
"main": "dist/index.mjs",
|
|
35
|
+
"typings": "dist/index.d.mts",
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@babel/core": "~7.29.0",
|
|
37
38
|
"@qse/ssh-sftp": "^1.2.0",
|
|
39
|
+
"@rsdoctor/rspack-plugin": "^1.5.2",
|
|
38
40
|
"@rspack/core": "^1.7.6",
|
|
39
41
|
"@rspack/dev-server": "^1.2.1",
|
|
40
42
|
"@rspack/plugin-react-refresh": "^1.6.1",
|
|
41
43
|
"@svgr/webpack": "^8.1.0",
|
|
42
44
|
"@swc-node/register": "^1.11.1",
|
|
45
|
+
"@swc/helpers": "^0.5.19",
|
|
43
46
|
"@types/express": "^4.17.25",
|
|
44
47
|
"chalk": "^4.1.2",
|
|
45
48
|
"chokidar": "^3.6.0",
|
|
@@ -75,22 +78,25 @@
|
|
|
75
78
|
"tailwindcss": "^3.4.19",
|
|
76
79
|
"tmp": "^0.2.3",
|
|
77
80
|
"typescript": "^5.9.3",
|
|
78
|
-
"update-notifier": "^7.3.1",
|
|
79
81
|
"url-loader": "^4.1.1",
|
|
80
|
-
"webpack-bundle-analyzer": "^5.2.0",
|
|
81
82
|
"yargs": "^17.7.2"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
84
85
|
"@babel/preset-env": "~7.29.0",
|
|
85
86
|
"@babel/preset-typescript": "^7.28.5",
|
|
87
|
+
"@qse/eslint-config": "^1.0.0",
|
|
88
|
+
"@types/cookie-parser": "^1.4.10",
|
|
86
89
|
"@types/fs-extra": "^11.0.4",
|
|
87
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",
|
|
88
95
|
"@types/yargs": "^17.0.35",
|
|
89
96
|
"eslint": "^9.39.3",
|
|
90
|
-
"eslint-config-qsb-react": "^2.0.4",
|
|
91
|
-
"father": "^4.5.2",
|
|
92
97
|
"jest": "^30.2.0",
|
|
93
98
|
"rimraf": "^6.1.3",
|
|
99
|
+
"tsdown": "^0.20.3",
|
|
94
100
|
"vitepress": "^1.6.4"
|
|
95
101
|
}
|
|
96
102
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import fs from 'fs-extra'
|
|
2
|
-
import paths from './config/paths
|
|
2
|
+
import paths from './config/paths'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
import { globby } from 'globby'
|
|
6
6
|
import ora from 'ora'
|
|
7
|
-
import { fileURLToPath } from 'node:url'
|
|
8
7
|
import inquirer from 'inquirer'
|
|
9
8
|
|
|
10
|
-
const pkg = fs.readJsonSync(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @param {(spinner:import("ora").Ora) => void | Promise<void>} callback
|
|
14
|
-
*/
|
|
15
|
-
async function step(msg, callback) {
|
|
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)
|
|
@@ -137,8 +133,8 @@ export default async function autoRefactor() {
|
|
|
137
133
|
/(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa|prettier)/i
|
|
138
134
|
|
|
139
135
|
const deletePkgs = {
|
|
140
|
-
dependencies: [],
|
|
141
|
-
devDependencies: [],
|
|
136
|
+
dependencies: [] as string[],
|
|
137
|
+
devDependencies: [] as string[],
|
|
142
138
|
}
|
|
143
139
|
Object.entries(deletePkgs).forEach(([scope, pkgs]) => {
|
|
144
140
|
for (const key in appPkg[scope]) {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { rspack } from '@rspack/core'
|
|
1
|
+
import { rspack, type Stats } from '@rspack/core'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
|
-
import getConfig from './utils/getConfig
|
|
4
|
-
|
|
5
|
-
import
|
|
3
|
+
import getConfig from './utils/getConfig'
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { measureFileSizesBeforeBuild, printFileSizesAfterBuild } from './utils/FileSizeReporter'
|
|
6
|
+
import paths from './config/paths'
|
|
6
7
|
import fs from 'fs-extra'
|
|
7
|
-
import appConfig from './utils/appConfig
|
|
8
|
+
import appConfig from './utils/appConfig'
|
|
8
9
|
|
|
9
10
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = appConfig.single ? 1024 * 1024 : 30 * 1024
|
|
10
11
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
interface BuildArgs {
|
|
14
|
+
analyze?: boolean
|
|
15
|
+
outputHtml?: boolean
|
|
16
|
+
}
|
|
17
|
+
export default async function build(args: BuildArgs) {
|
|
13
18
|
process.env.NODE_ENV = 'production'
|
|
14
19
|
process.env.BABEL_ENV = 'production'
|
|
15
20
|
process.env.BROWSERSLIST = '>0.2%, iOS>=9, ie 11, chrome>=49, not op_mini all'
|
|
@@ -31,13 +36,16 @@ export default async function build(args) {
|
|
|
31
36
|
fs.copySync(paths.static, paths.resolveApp('dist', 'static'))
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
const config = getConfig(args)
|
|
40
|
+
rspack(config, (error, stats: Stats | undefined) => {
|
|
35
41
|
if (error) {
|
|
36
42
|
console.log(chalk.red('编译失败'))
|
|
37
43
|
console.log(chalk.red(error.message || error))
|
|
38
44
|
process.exit(1)
|
|
39
45
|
}
|
|
40
46
|
|
|
47
|
+
if (!stats) return
|
|
48
|
+
|
|
41
49
|
if (stats.compilation.errors.length) {
|
|
42
50
|
console.log(chalk.red('编译失败'))
|
|
43
51
|
console.log(stats.toString({ all: false, errors: true, colors: true }))
|
package/src/{cli.js → cli.ts}
RENAMED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import './utils/beforeStart
|
|
2
|
+
import './utils/beforeStart'
|
|
3
3
|
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
import yargs from 'yargs'
|
|
6
|
-
import
|
|
6
|
+
import paths from './config/paths'
|
|
7
7
|
|
|
8
|
-
import start from './start
|
|
9
|
-
import build from './build
|
|
10
|
-
import deploy from './deploy
|
|
11
|
-
import autoRefactor from './auto-refactor
|
|
12
|
-
import commitDist from './commit-dist
|
|
13
|
-
import * as generator from './generator
|
|
8
|
+
import start from './start'
|
|
9
|
+
import build from './build'
|
|
10
|
+
import deploy from './deploy'
|
|
11
|
+
import autoRefactor from './auto-refactor'
|
|
12
|
+
import commitDist from './commit-dist'
|
|
13
|
+
import * as generator from './generator'
|
|
14
14
|
|
|
15
|
-
const pkg = fs.readJsonSync(
|
|
15
|
+
const pkg = fs.readJsonSync(paths.resolveOwn('package.json'))
|
|
16
16
|
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
17
18
|
yargs(process.argv.slice(2))
|
|
18
19
|
.usage(`教育工程化 webpack5 基础框架\n文档: ${pkg.homepage}`)
|
|
19
20
|
.command(
|
|
20
21
|
'start',
|
|
21
22
|
'开发',
|
|
22
|
-
(yargs) => yargs.option('port', { alias: 'p', desc: '指定端口' }),
|
|
23
|
+
(yargs) => yargs.option('port', { alias: 'p', desc: '指定端口', string: true }),
|
|
23
24
|
(args) => start(args)
|
|
24
25
|
)
|
|
25
26
|
.command(
|
|
@@ -70,9 +71,9 @@ yargs(process.argv.slice(2))
|
|
|
70
71
|
)
|
|
71
72
|
.command(['generator', 'g'], '自动生成代码', (yargs) =>
|
|
72
73
|
yargs
|
|
73
|
-
.command('override', '创建 override 文件', {}, (
|
|
74
|
-
.command('tailwind', '创建 tailwind 文件', {}, (
|
|
75
|
-
.command('ts', '创建 tsconfig 文件', {}, (
|
|
74
|
+
.command('override', '创建 override 文件', {}, () => generator.override())
|
|
75
|
+
.command('tailwind', '创建 tailwind 文件', {}, () => generator.tailwind())
|
|
76
|
+
.command('ts', '创建 tsconfig 文件', {}, () => generator.ts())
|
|
76
77
|
.showHelpOnFail(true)
|
|
77
78
|
.demandCommand(1, '')
|
|
78
79
|
)
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
|
-
import paths from './config/paths
|
|
2
|
+
import paths from './config/paths'
|
|
3
3
|
import fs from 'fs-extra'
|
|
4
4
|
import cp from 'child_process'
|
|
5
5
|
import tmp from 'tmp'
|
|
6
6
|
|
|
7
|
-
const exec = (cmd, opts
|
|
7
|
+
const exec = (cmd: string, opts?: cp.ExecSyncOptions) =>
|
|
8
|
+
cp.execSync(cmd, { encoding: 'utf-8', stdio: 'pipe', ...opts }) as string
|
|
8
9
|
|
|
9
|
-
function validateSVNRoot(root) {
|
|
10
|
+
function validateSVNRoot(root: string) {
|
|
10
11
|
const ls = exec(`svn ls ${root}`)
|
|
11
12
|
return ['trunk', 'branches'].every((s) => ls.includes(s))
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
interface WorkingCopyInfo {
|
|
16
|
+
url: string
|
|
17
|
+
branch: string
|
|
18
|
+
revision: string
|
|
19
|
+
author: string
|
|
20
|
+
distBranchURL: string
|
|
21
|
+
distBranchDirURL: string
|
|
22
|
+
root: string
|
|
23
|
+
}
|
|
24
|
+
function getWorkingCopyInfo(): WorkingCopyInfo {
|
|
15
25
|
exec(`svn up`)
|
|
16
26
|
const url = exec(`svn info --show-item url`).trim()
|
|
17
27
|
const revision = exec(`svn info --show-item last-changed-revision`).trim()
|
|
@@ -20,7 +30,7 @@ function getWorkingCopyInfo() {
|
|
|
20
30
|
let branch = 'trunk'
|
|
21
31
|
let root = url.replace(/\/trunk$/, '')
|
|
22
32
|
if (url.includes('/branches/')) {
|
|
23
|
-
branch = url.split('/').pop()
|
|
33
|
+
branch = url.split('/').pop()!
|
|
24
34
|
root = url.replace(/\/branches\/[^/]+$/, '')
|
|
25
35
|
}
|
|
26
36
|
let distBranchURL = root + '/branches/dist'
|
|
@@ -33,12 +43,12 @@ function getWorkingCopyInfo() {
|
|
|
33
43
|
return { url, branch, revision, author, distBranchURL, distBranchDirURL, root }
|
|
34
44
|
}
|
|
35
45
|
|
|
36
|
-
function copyDistToRepo(info) {
|
|
46
|
+
function copyDistToRepo(info: WorkingCopyInfo) {
|
|
37
47
|
const tmpdir = tmp.dirSync().name
|
|
38
48
|
|
|
39
49
|
try {
|
|
40
50
|
exec(`svn ls ${info.distBranchDirURL} --depth empty`)
|
|
41
|
-
} catch (error) {
|
|
51
|
+
} catch (error: any) {
|
|
42
52
|
if (error.message.includes('non-existent')) {
|
|
43
53
|
exec(
|
|
44
54
|
`svn mkdir ${info.distBranchDirURL} --parents -m "[edu-scripts] create ${info.branch} dist"`
|
|
@@ -51,7 +61,9 @@ function copyDistToRepo(info) {
|
|
|
51
61
|
|
|
52
62
|
try {
|
|
53
63
|
exec(`svn rm * --force -q`, { cwd: tmpdir })
|
|
54
|
-
} catch (
|
|
64
|
+
} catch (_e:any) {
|
|
65
|
+
// 如果目录为空,svn rm 会报错,忽略即可
|
|
66
|
+
}
|
|
55
67
|
|
|
56
68
|
fs.copySync(paths.dist, tmpdir)
|
|
57
69
|
|
|
@@ -63,13 +75,10 @@ function copyDistToRepo(info) {
|
|
|
63
75
|
fs.removeSync(tmpdir)
|
|
64
76
|
}
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @param {boolean} args.rmLocal
|
|
71
|
-
*/
|
|
72
|
-
export default async function commitDist(args) {
|
|
78
|
+
interface CommitDistArgs {
|
|
79
|
+
rmLocal?: boolean
|
|
80
|
+
}
|
|
81
|
+
export default async function commitDist(args: CommitDistArgs) {
|
|
73
82
|
if (!fs.existsSync(paths.dist)) {
|
|
74
83
|
console.log(chalk.red('未找到 dist 文件夹,请先 edu-scpirts build'))
|
|
75
84
|
process.exit(1)
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import { globbySync } from 'globby'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
4
5
|
|
|
5
|
-
function resolveApp(...filePath) {
|
|
6
|
+
function resolveApp(...filePath: string[]) {
|
|
6
7
|
return path.resolve(process.cwd(), ...filePath)
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
function
|
|
10
|
+
function resolveOwn(...filePath: string[]) {
|
|
11
|
+
let current = path.dirname(fileURLToPath(import.meta.url))
|
|
12
|
+
while (!fs.existsSync(path.join(current, 'package.json'))) {
|
|
13
|
+
const parent = path.dirname(current)
|
|
14
|
+
if (parent === current) {
|
|
15
|
+
throw new Error('package.json not found')
|
|
16
|
+
}
|
|
17
|
+
current = parent
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return path.resolve(current, ...filePath)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getExistPath(...paths: string[]) {
|
|
10
24
|
for (const path of paths) {
|
|
11
25
|
if (fs.existsSync(path)) {
|
|
12
26
|
return path
|
|
@@ -17,6 +31,7 @@ function getExistPath(...paths) {
|
|
|
17
31
|
|
|
18
32
|
const paths = {
|
|
19
33
|
resolveApp,
|
|
34
|
+
resolveOwn,
|
|
20
35
|
eduAppEnv: resolveApp('src', 'edu-app-env.d.ts'),
|
|
21
36
|
dist: resolveApp('dist'),
|
|
22
37
|
sshSftp: resolveApp('.sftprc.json'),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import paths from '../../paths
|
|
1
|
+
import paths from '../../paths'
|
|
2
2
|
import { globbySync } from 'globby'
|
|
3
3
|
import chokidar from 'chokidar'
|
|
4
4
|
import { debounce, memoize } from 'lodash-es'
|
|
@@ -7,15 +7,12 @@ import fs from 'fs-extra'
|
|
|
7
7
|
import express from 'express'
|
|
8
8
|
import cookieParser from 'cookie-parser'
|
|
9
9
|
import multer from 'multer'
|
|
10
|
-
import { pathToRegexp } from 'path-to-regexp'
|
|
10
|
+
import { pathToRegexp, type Key } from 'path-to-regexp'
|
|
11
11
|
import { createRequire } from 'node:module'
|
|
12
12
|
const require = createRequire(import.meta.url)
|
|
13
13
|
const { register } = require('@swc-node/register/register')
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
* @type {Record<string,{handler:any;method:string;path:string}>}
|
|
17
|
-
*/
|
|
18
|
-
let mockCache = {}
|
|
15
|
+
let mockCache: Record<string, { handler: any; method: string; path: string }> = {}
|
|
19
16
|
let isSetup = false
|
|
20
17
|
|
|
21
18
|
const setupMock = debounce(function setupMock() {
|
|
@@ -41,19 +38,19 @@ const setupMock = debounce(function setupMock() {
|
|
|
41
38
|
const [method, path] = key.split(' ')
|
|
42
39
|
mockCache[key] = { method, path, handler: mock[key] }
|
|
43
40
|
}
|
|
44
|
-
} catch (e) {
|
|
41
|
+
} catch (e: any) {
|
|
45
42
|
console.error(chalk.red(`Mock file ${file} error: ${e.message}`))
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
}, 100)
|
|
49
46
|
|
|
50
|
-
const getPathReAndKeys = memoize((path) => {
|
|
51
|
-
const keys = []
|
|
47
|
+
const getPathReAndKeys = memoize((path: string) => {
|
|
48
|
+
const keys: Key[] = []
|
|
52
49
|
const re = pathToRegexp(path, keys)
|
|
53
50
|
return { re, keys }
|
|
54
51
|
})
|
|
55
52
|
|
|
56
|
-
function decodeParam(val) {
|
|
53
|
+
function decodeParam(val: string) {
|
|
57
54
|
if (typeof val !== 'string' || val.length === 0) {
|
|
58
55
|
return val
|
|
59
56
|
}
|
|
@@ -74,7 +71,7 @@ function decodeParam(val) {
|
|
|
74
71
|
/**
|
|
75
72
|
* @type {import('express').RequestHandler}
|
|
76
73
|
*/
|
|
77
|
-
function mockMiddlewave(req, res, next) {
|
|
74
|
+
const mockMiddlewave: express.RequestHandler = function mockMiddlewave(req, res, next) {
|
|
78
75
|
const { method, path } = req
|
|
79
76
|
for (const key in mockCache) {
|
|
80
77
|
const mock = mockCache[key]
|
|
@@ -92,6 +89,7 @@ function mockMiddlewave(req, res, next) {
|
|
|
92
89
|
const prop = key.name
|
|
93
90
|
const val = decodeParam(m[i])
|
|
94
91
|
if (val !== undefined) {
|
|
92
|
+
// @ts-ignore
|
|
95
93
|
params[prop] = val
|
|
96
94
|
}
|
|
97
95
|
}
|
|
@@ -124,18 +122,18 @@ function mockMiddlewave(req, res, next) {
|
|
|
124
122
|
next()
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
function setupMockServer(middelwaves,
|
|
125
|
+
type Middlewares = Parameters<
|
|
126
|
+
NonNullable<import('@rspack/dev-server').Configuration['setupMiddlewares']>
|
|
127
|
+
>[0]
|
|
128
|
+
|
|
129
|
+
function setupMockServer(middelwaves: Middlewares, _devServer: any) {
|
|
132
130
|
if (!fs.existsSync(paths.mock)) return
|
|
133
131
|
|
|
134
132
|
register()
|
|
135
133
|
|
|
136
134
|
middelwaves.unshift({
|
|
137
135
|
name: 'edu-scripts-mock-middelwave',
|
|
138
|
-
middleware: mockMiddlewave,
|
|
136
|
+
middleware: mockMiddlewave as any,
|
|
139
137
|
})
|
|
140
138
|
|
|
141
139
|
console.log(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Plugin } from 'postcss'
|
|
1
2
|
const vars = [
|
|
2
3
|
'safe-area-inset-top',
|
|
3
4
|
'safe-area-inset-bottom',
|
|
@@ -7,8 +8,7 @@ const vars = [
|
|
|
7
8
|
|
|
8
9
|
const expr = new RegExp(`env\\(\\s*(${vars.join('|')})\\s*,?\\s*([^)]+)?\\s*\\)`, 'g')
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
export default () => {
|
|
11
|
+
const PostcssSafeAreaPlugin = (): Plugin => {
|
|
12
12
|
return {
|
|
13
13
|
postcssPlugin: 'postcss-safe-area',
|
|
14
14
|
Declaration(decl) {
|
|
@@ -19,3 +19,5 @@ export default () => {
|
|
|
19
19
|
},
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
export default PostcssSafeAreaPlugin
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
|
|
2
2
|
import { rspack } from '@rspack/core'
|
|
3
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
4
|
-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
5
3
|
import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
|
|
6
|
-
import paths from './paths.js'
|
|
7
|
-
import appConfig from '../utils/appConfig.js'
|
|
8
|
-
import { createRequire } from 'node:module'
|
|
9
4
|
import chalk from 'chalk'
|
|
10
|
-
|
|
5
|
+
import fs from 'fs-extra'
|
|
6
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
7
|
+
import { createRequire } from 'node:module'
|
|
8
|
+
import appConfig from '../utils/appConfig.js'
|
|
9
|
+
import paths from './paths.js'
|
|
10
|
+
import PostcssSafeAreaPlugin from './plugins/postcss-safe-area.js'
|
|
11
11
|
const require = createRequire(import.meta.url)
|
|
12
12
|
const appPkg = fs.readJsonSync(paths.package)
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ const qseCDN = (() => {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* @param {*} args
|
|
48
|
-
* @param {import('../utils/defineConfig').
|
|
48
|
+
* @param {import('../utils/defineConfig.js').Configuration} override
|
|
49
49
|
*/
|
|
50
50
|
export default function getWebpackConfig(args, override) {
|
|
51
51
|
const isDev = process.env.NODE_ENV === 'development'
|
|
@@ -86,7 +86,7 @@ export default function getWebpackConfig(args, override) {
|
|
|
86
86
|
// https://preset-env.cssdb.org/features/#stage-2
|
|
87
87
|
},
|
|
88
88
|
],
|
|
89
|
-
isProd &&
|
|
89
|
+
isProd && PostcssSafeAreaPlugin(),
|
|
90
90
|
isProd && [require.resolve('postcss-momentum-scrolling'), ['scroll', 'auto']],
|
|
91
91
|
require.resolve('postcss-normalize'),
|
|
92
92
|
...override.extraPostCSSPlugins,
|
|
@@ -196,11 +196,13 @@ export default function getWebpackConfig(args, override) {
|
|
|
196
196
|
type: 'asset/source',
|
|
197
197
|
},
|
|
198
198
|
{
|
|
199
|
-
test: /\.[jt]sx?$/,
|
|
199
|
+
test: /\.[cm]?[jt]sx?$/,
|
|
200
|
+
exclude: /node_modules/,
|
|
200
201
|
use: [
|
|
201
202
|
{
|
|
202
203
|
loader: 'builtin:swc-loader',
|
|
203
204
|
options: {
|
|
205
|
+
env: { targets: process.env.BROWSERSLIST },
|
|
204
206
|
rspackExperiments: {
|
|
205
207
|
import: [
|
|
206
208
|
{
|
|
@@ -210,14 +212,16 @@ export default function getWebpackConfig(args, override) {
|
|
|
210
212
|
...override.import,
|
|
211
213
|
],
|
|
212
214
|
},
|
|
215
|
+
isModule: 'unknown',
|
|
213
216
|
jsc: {
|
|
214
217
|
parser: {
|
|
215
218
|
syntax: 'typescript',
|
|
216
219
|
tsx: true,
|
|
217
220
|
decorators: override.decorators,
|
|
218
221
|
},
|
|
219
|
-
|
|
222
|
+
externalHelpers: true,
|
|
220
223
|
transform: {
|
|
224
|
+
legacyDecorator: override.decorators,
|
|
221
225
|
react: {
|
|
222
226
|
runtime: 'automatic',
|
|
223
227
|
development: isDev,
|
|
@@ -229,6 +233,25 @@ export default function getWebpackConfig(args, override) {
|
|
|
229
233
|
},
|
|
230
234
|
],
|
|
231
235
|
},
|
|
236
|
+
{
|
|
237
|
+
test: /\.[cm]?jsx?$/,
|
|
238
|
+
exclude: /node_modules[\\/](core-js|@swc[\\/]helpers)([\\/]|$)/,
|
|
239
|
+
use: [
|
|
240
|
+
{
|
|
241
|
+
loader: 'builtin:swc-loader',
|
|
242
|
+
options: {
|
|
243
|
+
env: { targets: process.env.BROWSERSLIST },
|
|
244
|
+
isModule: 'unknown',
|
|
245
|
+
jsc: {
|
|
246
|
+
parser: {
|
|
247
|
+
syntax: 'ecmascript',
|
|
248
|
+
},
|
|
249
|
+
externalHelpers: true,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
},
|
|
232
255
|
{
|
|
233
256
|
test: cssRegex,
|
|
234
257
|
exclude: cssModuleRegex,
|
|
@@ -349,11 +372,11 @@ export default function getWebpackConfig(args, override) {
|
|
|
349
372
|
plugins: [
|
|
350
373
|
qseCDN.isUseCommon &&
|
|
351
374
|
new rspack.DllReferencePlugin({
|
|
352
|
-
manifest:
|
|
375
|
+
manifest: fs.readJsonSync(paths.resolveOwn('asset', 'dll', 'libcommon3-manifest.json')),
|
|
353
376
|
}),
|
|
354
377
|
new rspack.NormalModuleReplacementPlugin(/createSocketURL\.js$/, (resource) => {
|
|
355
378
|
if (resource.context.includes('webpack-dev-server')) {
|
|
356
|
-
resource.request =
|
|
379
|
+
resource.request = paths.resolveOwn('asset', 'ws-utils-createSocketURL.js')
|
|
357
380
|
}
|
|
358
381
|
}),
|
|
359
382
|
new rspack.IgnorePlugin({
|
|
@@ -392,7 +415,7 @@ export default function getWebpackConfig(args, override) {
|
|
|
392
415
|
})
|
|
393
416
|
)
|
|
394
417
|
: []),
|
|
395
|
-
process.env.ANALYZE && isProd && new
|
|
418
|
+
process.env.ANALYZE && isProd && new RsdoctorRspackPlugin(),
|
|
396
419
|
isDev &&
|
|
397
420
|
((compiler) => {
|
|
398
421
|
let isFirst = true
|