@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.
Files changed (92) hide show
  1. package/CHANGELOG.md +2 -483
  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 +1426 -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 +52 -57
  13. package/src/{auto-refactor.js → auto-refactor.ts} +51 -59
  14. package/src/{build.js → build.ts} +22 -16
  15. package/src/{cli.js → cli.ts} +25 -21
  16. package/src/{commit-dist.js → commit-dist.ts} +28 -21
  17. package/src/config/paths.ts +52 -0
  18. package/src/config/plugins/mock-server/{index.js → index.ts} +30 -41
  19. package/src/config/plugins/{postcss-safe-area.js → postcss-safe-area.ts} +4 -2
  20. package/src/config/{webpackConfig.js → webpackConfig.ts} +152 -126
  21. package/src/config/{webpackDevServerConfig.js → webpackDevServerConfig.ts} +18 -18
  22. package/src/{deploy.js → deploy.ts} +36 -25
  23. package/src/{generator.js → generator.ts} +5 -14
  24. package/src/start.ts +52 -0
  25. package/src/utils/FileSizeReporter.ts +166 -0
  26. package/src/utils/{appConfig.js → appConfig.ts} +5 -4
  27. package/src/utils/{beforeStart.js → beforeStart.ts} +18 -29
  28. package/src/utils/{changeDeployVersion.js → changeDeployVersion.ts} +43 -48
  29. package/src/utils/defineConfig.ts +19 -36
  30. package/src/utils/{exec.js → exec.ts} +3 -3
  31. package/src/utils/{getConfig.js → getConfig.ts} +7 -5
  32. package/src/utils/getOverride.ts +32 -0
  33. package/src/utils/resolveModule.ts +3 -0
  34. package/tsconfig.json +3 -15
  35. package/tsdown.config.ts +5 -0
  36. package/docs/changelog.md +0 -5
  37. package/docs/debug.md +0 -17
  38. package/docs/deploy.md +0 -54
  39. package/docs/faq.md +0 -144
  40. package/docs/feat.md +0 -167
  41. package/docs/grayscale.md +0 -31
  42. package/docs/index.md +0 -5
  43. package/docs/mode.md +0 -42
  44. package/docs/override.md +0 -193
  45. package/docs/refactor-react-16.md +0 -37
  46. package/docs/refactor.md +0 -67
  47. package/docs/static.md +0 -24
  48. package/lib/asset/template/edu-scripts.override.js.tpl +0 -7
  49. package/lib/auto-refactor.js +0 -151
  50. package/lib/build.js +0 -59
  51. package/lib/cli.js +0 -66
  52. package/lib/commit-dist.js +0 -79
  53. package/lib/config/babel.dependencies.js +0 -79
  54. package/lib/config/babel.js +0 -107
  55. package/lib/config/paths.js +0 -36
  56. package/lib/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -31
  57. package/lib/config/plugins/mock-server/defineMock.d.ts +0 -6
  58. package/lib/config/plugins/mock-server/defineMock.js +0 -31
  59. package/lib/config/plugins/mock-server/index.js +0 -122
  60. package/lib/config/plugins/postcss-safe-area.js +0 -19
  61. package/lib/config/plugins/ws-utils-createSocketURL.js +0 -118
  62. package/lib/config/webpackConfig.js +0 -462
  63. package/lib/config/webpackDevServerConfig.js +0 -72
  64. package/lib/deploy.js +0 -143
  65. package/lib/generator.js +0 -50
  66. package/lib/index.d.ts +0 -2
  67. package/lib/index.js +0 -32
  68. package/lib/start.js +0 -36
  69. package/lib/utils/FileSizeReporter.js +0 -107
  70. package/lib/utils/appConfig.js +0 -32
  71. package/lib/utils/beforeStart.js +0 -62
  72. package/lib/utils/changeDeployVersion.js +0 -89
  73. package/lib/utils/defineConfig.d.ts +0 -93
  74. package/lib/utils/defineConfig.js +0 -31
  75. package/lib/utils/exec.js +0 -7
  76. package/lib/utils/getConfig.js +0 -20
  77. package/lib/utils/getOverride.js +0 -61
  78. package/src/asset/dll/libcommon3-manifest.json +0 -181
  79. package/src/asset/template/edu-app-env.d.ts.tpl +0 -20
  80. package/src/asset/template/tailwind.config.js.tpl +0 -11
  81. package/src/asset/template/tsconfig.json.tpl +0 -24
  82. package/src/config/babel.dependencies.js +0 -66
  83. package/src/config/babel.js +0 -94
  84. package/src/config/paths.js +0 -38
  85. package/src/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -55
  86. package/src/config/plugins/ws-utils-createSocketURL.js +0 -140
  87. package/src/start.js +0 -44
  88. package/src/utils/FileSizeReporter.js +0 -151
  89. package/src/utils/getOverride.js +0 -48
  90. /package/{lib/asset → asset}/dll/libcommon3-manifest.json +0 -0
  91. /package/{lib/asset → asset}/template/edu-app-env.d.ts.tpl +0 -0
  92. /package/{lib/asset → asset}/template/tsconfig.json.tpl +0 -0
@@ -1,462 +0,0 @@
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
- ));
23
-
24
- // src/config/webpackConfig.js
25
- var fs = require("fs");
26
- var webpack = require("webpack");
27
- var HtmlWebpackPlugin = require("html-webpack-plugin");
28
- var { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
29
- var ReactRefreshPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
30
- var paths = require("./paths");
31
- var TerserPlugin = require("terser-webpack-plugin");
32
- var CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
33
- var appPkg = require(paths.package);
34
- var appConfig = require("../utils/appConfig");
35
- var { ESBuildMinifyPlugin } = require("esbuild-loader");
36
- var { RetryChunkLoadPlugin } = require("webpack-retry-chunk-load-plugin");
37
- var once = require("lodash/once");
38
- var jsMainPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.name}` : `${appPkg.name}/${appPkg.name}`;
39
- var assetPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.version}` : `${appPkg.name}/${appPkg.version}`;
40
- var cssRegex = /\.css$/;
41
- var cssModuleRegex = /\.module\.css$/;
42
- var lessRegex = /\.less$/;
43
- var lessModuleRegex = /\.module\.less$/;
44
- var imageInlineSizeLimit = 10 * 1024;
45
- var qseCDN = (() => {
46
- const contents = paths.indexHTML.map((url) => fs.readFileSync(url, "utf-8"));
47
- function include(pattern) {
48
- const regexp = new RegExp(pattern);
49
- return contents.some((content) => regexp.test(content));
50
- }
51
- return {
52
- isUseCommon: include(/react16.14.*_common31?.js|react-dev-preset.js/),
53
- isUseAxios: include(/react16.14.*_axios0.21.1|react-dev-preset.js/),
54
- isUseMoment: include("moment2.29.1.js"),
55
- isUseAntd: include("antd3.26.20.js"),
56
- isUseQsbAntd: include("qsb-antd.min.js"),
57
- isUseQsbSchemeRender: include("qsb-scheme-render.min.js")
58
- };
59
- })();
60
- module.exports = function getWebpackConfig(args, override) {
61
- const isDev = process.env.NODE_ENV === "development";
62
- const isProd = process.env.NODE_ENV === "production";
63
- const getStyleLoaders = (cssOptions, preProcessor) => {
64
- const loaders = [
65
- {
66
- loader: require.resolve("style-loader"),
67
- options: { attributes: { "data-module": appPkg.name, "data-version": appPkg.version } }
68
- },
69
- {
70
- loader: require.resolve("css-loader"),
71
- options: cssOptions
72
- },
73
- {
74
- // Options for PostCSS as we reference these options twice
75
- // Adds vendor prefixing based on your specified browser support in
76
- // package.json
77
- loader: require.resolve("postcss-loader"),
78
- options: {
79
- postcssOptions: {
80
- // Necessary for external CSS imports to work
81
- // https://github.com/facebook/create-react-app/issues/2677
82
- ident: "postcss",
83
- config: false,
84
- plugins: [
85
- isProd && require("cssnano")({ preset: "default" }),
86
- fs.existsSync(paths.tailwind) && require.resolve("tailwindcss"),
87
- require.resolve("postcss-flexbugs-fixes"),
88
- [
89
- require.resolve("postcss-preset-env"),
90
- {
91
- autoprefixer: {
92
- flexbox: "no-2009"
93
- }
94
- // https://preset-env.cssdb.org/features/#stage-2
95
- }
96
- ],
97
- isProd && require("./plugins/postcss-safe-area")(),
98
- isProd && [require.resolve("postcss-momentum-scrolling"), ["scroll", "auto"]],
99
- require.resolve("postcss-normalize"),
100
- ...override.extraPostCSSPlugins
101
- ].filter(Boolean)
102
- },
103
- sourceMap: isDev
104
- }
105
- }
106
- ];
107
- if (preProcessor === "less-loader") {
108
- loaders.push({
109
- loader: require.resolve("less-loader"),
110
- options: {
111
- lessOptions: {
112
- javascriptEnabled: true,
113
- modifyVars: fs.existsSync(paths.theme) ? require(paths.theme) : void 0
114
- },
115
- sourceMap: true
116
- }
117
- });
118
- }
119
- return loaders;
120
- };
121
- const config = {
122
- context: process.cwd(),
123
- mode: process.env.NODE_ENV,
124
- entry: "./src/index",
125
- target: "browserslist",
126
- output: {
127
- filename: appConfig.single ? `js/${jsMainPath}_${appPkg.version}.[contenthash:6].js` : `js/${jsMainPath}_${appPkg.version}.js`,
128
- chunkFilename: `js/${assetPath}/[name].[chunkhash:8].js`,
129
- assetModuleFilename: `images/${assetPath}/[name].[hash:6][ext]`,
130
- uniqueName: appPkg.name,
131
- publicPath: ""
132
- },
133
- externals: Object.assign(
134
- {},
135
- qseCDN.isUseCommon && {
136
- react: "React",
137
- "react-dom": "ReactDOM",
138
- "natty-fetch": "nattyFetch",
139
- "natty-storage": "nattyStorage",
140
- "common-utils": "CommonUtils",
141
- "@qse/common-utils": "CommonUtils"
142
- },
143
- qseCDN.isUseAxios && { axios: "axios" },
144
- qseCDN.isUseMoment && { moment: "moment" },
145
- qseCDN.isUseAntd && Object.assign(
146
- {
147
- react: "React",
148
- "react-dom": "ReactDOM",
149
- moment: "moment",
150
- antd: "antd"
151
- },
152
- qseCDN.isUseQsbAntd && {
153
- "@qse/antd": "qsbAntd",
154
- "@qsb/antd": "qsbAntd"
155
- },
156
- qseCDN.isUseQsbSchemeRender && {
157
- "@qse/scheme-render": "qsbSchemeRender",
158
- "@qsb/scheme-render": "qsbSchemeRender"
159
- }
160
- ),
161
- // 教育工程这些一定都需要 external
162
- !appConfig.single && Object.assign(
163
- {
164
- react: "React",
165
- "react-dom": "ReactDOM",
166
- "natty-fetch": "nattyFetch",
167
- "natty-storage": "nattyStorage",
168
- "common-utils": "CommonUtils",
169
- "@qse/common-utils": "CommonUtils",
170
- moment: "moment",
171
- antd: "antd"
172
- },
173
- isProd && {
174
- "@qse/antd": "qsbAntd",
175
- "@qsb/antd": "qsbAntd",
176
- "@qse/scheme-render": "qsbSchemeRender",
177
- "@qsb/scheme-render": "qsbSchemeRender"
178
- }
179
- ),
180
- override.externals
181
- ),
182
- resolve: {
183
- alias: {
184
- "@": paths.src,
185
- ...override.alias
186
- },
187
- extensions: [".web.js", ".web.mjs", ".js", ".mjs", ".jsx", ".ts", ".tsx", ".json", ".wasm"]
188
- },
189
- stats: isDev ? { preset: "errors-warnings", timings: true } : void 0,
190
- devtool: isDev ? "cheap-module-source-map" : false,
191
- cache: {
192
- type: "filesystem",
193
- version: require("../../package.json").version,
194
- buildDependencies: {
195
- config: [__filename],
196
- override: [paths.override, paths.theme].filter((f) => fs.existsSync(f)),
197
- tsconfig: [paths.tsconfig, paths.jsconfig].filter((f) => fs.existsSync(f))
198
- }
199
- },
200
- module: {
201
- parser: { javascript: { exportsPresence: "error" } },
202
- rules: [
203
- {
204
- oneOf: [
205
- {
206
- resourceQuery: /raw/,
207
- type: "asset/source"
208
- },
209
- {
210
- test: /\.(j|t)sx?$/,
211
- loader: require.resolve("babel-loader"),
212
- exclude: /node_modules/,
213
- options: require("./babel")()
214
- },
215
- override.transformNodeModules && {
216
- test: /\.m?js$/,
217
- loader: require.resolve("babel-loader"),
218
- exclude: /@babel(?:\/|\\{1,2})runtime/,
219
- options: require("./babel.dependencies")()
220
- },
221
- {
222
- test: cssRegex,
223
- exclude: cssModuleRegex,
224
- use: getStyleLoaders({
225
- importLoaders: 1,
226
- sourceMap: isDev,
227
- modules: {
228
- mode: "global",
229
- localIdentName: "[local]--[hash:base64:6]"
230
- }
231
- }),
232
- sideEffects: true
233
- },
234
- {
235
- test: cssModuleRegex,
236
- use: getStyleLoaders({
237
- importLoaders: 1,
238
- sourceMap: isDev,
239
- modules: {
240
- mode: "local",
241
- localIdentName: "[local]--[hash:base64:6]"
242
- }
243
- })
244
- },
245
- {
246
- test: lessRegex,
247
- exclude: lessModuleRegex,
248
- use: getStyleLoaders(
249
- {
250
- importLoaders: 2,
251
- sourceMap: isDev,
252
- modules: {
253
- mode: "global",
254
- localIdentName: "[local]--[hash:base64:6]"
255
- }
256
- },
257
- "less-loader"
258
- ),
259
- sideEffects: true
260
- },
261
- {
262
- test: lessModuleRegex,
263
- use: getStyleLoaders(
264
- {
265
- importLoaders: 2,
266
- sourceMap: isDev,
267
- modules: {
268
- mode: "local",
269
- localIdentName: "[local]--[hash:base64:6]"
270
- }
271
- },
272
- "less-loader"
273
- )
274
- },
275
- {
276
- test: /\.(bmp|png|jpe?g|gif|webp)$/,
277
- type: "asset",
278
- parser: {
279
- dataUrlCondition: {
280
- maxSize: imageInlineSizeLimit
281
- // 10kb
282
- }
283
- }
284
- },
285
- {
286
- test: /\.svg$/,
287
- type: "asset",
288
- parser: {
289
- dataUrlCondition: {
290
- maxSize: imageInlineSizeLimit
291
- // 10kb
292
- }
293
- },
294
- issuer: {
295
- and: [/\.(css|less)$/]
296
- }
297
- },
298
- {
299
- test: /\.svg$/,
300
- use: [
301
- {
302
- loader: require.resolve("@svgr/webpack"),
303
- options: {
304
- prettier: false,
305
- svgo: false,
306
- svgoConfig: {
307
- plugins: [{ removeViewBox: false }]
308
- },
309
- titleProp: true,
310
- ref: false
311
- }
312
- },
313
- {
314
- loader: require.resolve("url-loader"),
315
- options: {
316
- limit: imageInlineSizeLimit
317
- }
318
- }
319
- ],
320
- issuer: {
321
- and: [/\.(ts|tsx|js|jsx|md|mdx)$/]
322
- }
323
- },
324
- {
325
- test: /\.md$/,
326
- type: "asset/source"
327
- },
328
- {
329
- // Exclude `js` files to keep "css" loader working as it injects
330
- // its runtime that would otherwise be processed through "file" loader.
331
- // Also exclude `html` and `json` extensions so they get processed
332
- // by webpacks internal loaders.
333
- exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
334
- type: "asset/resource"
335
- }
336
- ].filter(Boolean)
337
- }
338
- ]
339
- },
340
- plugins: [
341
- qseCDN.isUseCommon && new webpack.DllReferencePlugin({
342
- manifest: require("../asset/dll/libcommon3-manifest.json")
343
- }),
344
- new webpack.NormalModuleReplacementPlugin(/createSocketURL\.js$/, (resource) => {
345
- if (resource.context.includes("webpack-dev-server")) {
346
- resource.request = require.resolve("./plugins/ws-utils-createSocketURL");
347
- }
348
- }),
349
- new webpack.IgnorePlugin({
350
- resourceRegExp: /^\.\/locale$/,
351
- contextRegExp: /moment$/
352
- }),
353
- new RetryChunkLoadPlugin({
354
- maxRetries: 3,
355
- retryDelay: 300,
356
- lastResortScript: `setTimeout(function() { window.location.reload(); }, 2000)`
357
- }),
358
- new webpack.DefinePlugin({
359
- "process.env.APP_NAME": JSON.stringify(appPkg.name),
360
- "process.env.APP_VERSION": JSON.stringify(appPkg.version),
361
- "process.env.BABEL_ENV": JSON.stringify(process.env.BABEL_ENV),
362
- "process.env.BROWSERSLIST": JSON.stringify(process.env.BROWSERSLIST),
363
- ...override.define
364
- }),
365
- new webpack.ProgressPlugin(),
366
- isDev && new CaseSensitivePathsPlugin(),
367
- isDev && new ReactRefreshPlugin({ overlay: false }),
368
- ...isDev || process.env.OUTPUT_HTML || appConfig.single || appConfig.mainProject ? paths.indexHTML.map(
369
- (template) => new HtmlWebpackPlugin({
370
- template,
371
- filename: template.split("/").pop(),
372
- inject: false,
373
- minify: {
374
- removeComments: true,
375
- collapseWhitespace: true,
376
- removeRedundantAttributes: true,
377
- useShortDoctype: true,
378
- removeEmptyAttributes: true,
379
- removeStyleLinkTypeAttributes: true,
380
- keepClosingSlash: true,
381
- minifyJS: true,
382
- minifyCSS: true,
383
- minifyURLs: true
384
- }
385
- })
386
- ) : [],
387
- process.env.ANALYZE && isProd && new BundleAnalyzerPlugin(),
388
- isDev && !!override.startup && ((compiler) => {
389
- compiler.hooks.afterDone.tap(
390
- "edu-scripts-startup",
391
- once(() => {
392
- const logger = compiler.getInfrastructureLogger("edu-scripts");
393
- override.startup({ logger, chalk: require("chalk"), compiler });
394
- })
395
- );
396
- })
397
- ].filter(Boolean),
398
- optimization: {
399
- minimize: isProd && override.minify !== false,
400
- minimizer: [
401
- override.minify === "esbuild" && new ESBuildMinifyPlugin({
402
- pure: override.pure_funcs ?? ["console.log"],
403
- drop: ["debugger"],
404
- keepNames: false,
405
- legalComments: "none",
406
- target: "es5"
407
- }),
408
- // This is only used in production mode
409
- override.minify === "terser" && new TerserPlugin({
410
- extractComments: false,
411
- terserOptions: {
412
- parse: {
413
- // We want terser to parse ecma 8 code. However, we don't want it
414
- // to apply any minification steps that turns valid ecma 5 code
415
- // into invalid ecma 5 code. This is why the 'compress' and 'output'
416
- // sections only apply transformations that are ecma 5 safe
417
- // https://github.com/facebook/create-react-app/pull/4234
418
- ecma: 8
419
- },
420
- compress: {
421
- pure_funcs: override.pure_funcs ?? ["console.log"],
422
- drop_debugger: true,
423
- ecma: 5,
424
- warnings: false,
425
- // Disabled because of an issue with Uglify breaking seemingly valid code:
426
- // https://github.com/facebook/create-react-app/issues/2376
427
- // Pending further investigation:
428
- // https://github.com/mishoo/UglifyJS2/issues/2011
429
- comparisons: false,
430
- // Disabled because of an issue with Terser breaking valid code:
431
- // https://github.com/facebook/create-react-app/issues/5250
432
- // Pending further investigation:
433
- // https://github.com/terser-js/terser/issues/120
434
- inline: 2
435
- },
436
- mangle: {
437
- safari10: true
438
- },
439
- // Added for profiling in devtools
440
- keep_classnames: false,
441
- keep_fnames: false,
442
- output: {
443
- ecma: 5,
444
- comments: false,
445
- // Turned on because emoji and regex is not minified properly using default
446
- // https://github.com/facebook/create-react-app/issues/2488
447
- ascii_only: true
448
- }
449
- }
450
- })
451
- ].filter(Boolean),
452
- splitChunks: {
453
- minChunks: 2
454
- }
455
- },
456
- performance: {
457
- maxEntrypointSize: appConfig.single ? 1024 * 1024 : 30 * 1024,
458
- maxAssetSize: 1024 * 1024
459
- }
460
- };
461
- return config;
462
- };
@@ -1,72 +0,0 @@
1
- // src/config/webpackDevServerConfig.js
2
- var WebpackDevServer = require("webpack-dev-server");
3
- var setupMockServer = require("./plugins/mock-server");
4
- function createProxy(context, target, origin) {
5
- const url = new URL(origin || target);
6
- return {
7
- context: [context],
8
- target,
9
- changeOrigin: true,
10
- onProxyReq: (proxyReq) => {
11
- proxyReq.setHeader("host", url.host);
12
- proxyReq.setHeader("origin", url.origin);
13
- proxyReq.removeHeader("referer");
14
- }
15
- };
16
- }
17
- module.exports = function getWebpackDevServerConfig(args, override) {
18
- const host = process.env.HOST || "0.0.0.0";
19
- const devServer = {
20
- hot: true,
21
- allowedHosts: "all",
22
- historyApiFallback: true,
23
- port: args.port,
24
- open: args.open,
25
- host,
26
- client: {
27
- webSocketURL: "auto://0.0.0.0:0/ws",
28
- overlay: {
29
- runtimeErrors: false,
30
- errors: true,
31
- warnings: false
32
- }
33
- },
34
- headers: {
35
- "Access-Control-Allow-Origin": "*",
36
- "Access-Control-Allow-Methods": "*",
37
- "Access-Control-Allow-Headers": "*"
38
- },
39
- setupMiddlewares: (middlewares, devServer2) => {
40
- if (override.mock !== false) {
41
- setupMockServer(middlewares, devServer2);
42
- }
43
- return middlewares;
44
- },
45
- proxy: [
46
- createProxy("/api", "http://192.168.10.19:3339/qsxxwapdev", "http://www.zhidianbao.cn")
47
- ],
48
- compress: true
49
- };
50
- if (override.proxy) {
51
- if (Array.isArray(override.proxy)) {
52
- devServer.proxy = [...override.proxy, ...devServer.proxy];
53
- } else if (typeof override.proxy === "object") {
54
- const proxies = Object.entries(override.proxy).map(([context, target]) => {
55
- return createProxy(context, target);
56
- });
57
- devServer.proxy = [...proxies, ...devServer.proxy];
58
- } else {
59
- throw new Error("proxy 必须是数组或对象");
60
- }
61
- const proxyMap = /* @__PURE__ */ new Map();
62
- devServer.proxy = devServer.proxy.filter((item) => {
63
- const key = JSON.stringify([...item.context].sort());
64
- if (!proxyMap.has(key)) {
65
- proxyMap.set(key, true);
66
- return true;
67
- }
68
- return false;
69
- });
70
- }
71
- return devServer;
72
- };
package/lib/deploy.js DELETED
@@ -1,143 +0,0 @@
1
- // src/deploy.js
2
- var { sshSftp } = require("@qse/ssh-sftp");
3
- var path = require("path");
4
- var paths = require("./config/paths");
5
- var pkg = require(paths.package);
6
- var chalk = require("chalk");
7
- var fs = require("fs-extra");
8
- var changeDeployVersion = require("./utils/changeDeployVersion");
9
- var ora = require("ora");
10
- var appConfig = require("./utils/appConfig");
11
- var baseConfig = {
12
- localPath: "dist",
13
- ignore: [],
14
- cleanRemoteFiles: false,
15
- securityLock: false,
16
- keepAlive: true,
17
- noWarn: true
18
- };
19
- async function normalDeploy(args) {
20
- const resolve = (...pathSegments) => path.resolve(process.cwd(), ...pathSegments);
21
- function getLocalAndRemoteFilePath(remoteFilePath, opts) {
22
- const splited = remoteFilePath.split("/");
23
- const fileName = splited[splited.length - 1];
24
- const tmpBase = resolve(opts.localPath, "__tmp__");
25
- const tmpDir = resolve(opts.localPath, "__tmp__", ...splited.slice(0, -1));
26
- const tmpFile = resolve(tmpDir, fileName);
27
- const remoteFile = [opts.remotePath, remoteFilePath].join("/");
28
- return { tmpDir, tmpFile, remoteFile, tmpBase };
29
- }
30
- function dateTime() {
31
- let date = /* @__PURE__ */ new Date();
32
- date = new Date(date.getTime() - date.getTimezoneOffset() * 6e4);
33
- return date.toISOString().replace(/T/, " ").replace(/\..+/, "");
34
- }
35
- function updateLogContent(content, info) {
36
- const lines = content.trim().split("\n");
37
- lines.push(`[${dateTime()}] ${JSON.stringify(info)}
38
- `);
39
- return lines.slice(-50).join("\n");
40
- }
41
- async function upload(opts) {
42
- const { sftp, opts: fullOpts } = await sshSftp(opts);
43
- const spinner = ora("自动更新 ver.js 版本配置").start();
44
- const fileName = "js/ver.js";
45
- const { remoteFile, tmpDir, tmpFile, tmpBase } = getLocalAndRemoteFilePath(fileName, fullOpts);
46
- try {
47
- fs.mkdirSync(tmpDir, { recursive: true });
48
- const info = {
49
- name: pkg.name,
50
- version: pkg.version,
51
- grayscale: appConfig.grayscale
52
- };
53
- {
54
- await sftp.fastGet(remoteFile, tmpFile);
55
- let code = await fs.readFile(tmpFile, { encoding: "utf-8" });
56
- code = changeDeployVersion(code, info);
57
- await sftp.fastPut(tmpFile, remoteFile + ".bak");
58
- await fs.writeFile(tmpFile, code);
59
- await sftp.fastPut(tmpFile, remoteFile);
60
- }
61
- {
62
- const remoteLogFile = remoteFile + ".log";
63
- const tmpLogFile = tmpFile + ".log";
64
- let content = "";
65
- try {
66
- await sftp.fastGet(remoteLogFile, tmpLogFile);
67
- content = await fs.readFile(tmpLogFile, "utf-8");
68
- } catch (error) {
69
- }
70
- content = updateLogContent(content, info);
71
- await fs.writeFile(tmpLogFile, content);
72
- await sftp.fastPut(tmpLogFile, remoteLogFile);
73
- }
74
- spinner.succeed("已更新 ver.js 版本配置");
75
- } catch (e) {
76
- spinner.fail(`自动修改 ver.js 失败,请手动修改`);
77
- console.log(chalk.bgRed(e.message));
78
- } finally {
79
- await sftp.end();
80
- fs.removeSync(tmpBase);
81
- }
82
- }
83
- const presetConfig = {
84
- s: { preset: { context: "eduwebngv1", folder: "userportal" } },
85
- b: { preset: { context: "eduwebngv1", folder: "bureaupc" } },
86
- d: { preset: { context: "eduwebngv1", folder: "documentshelves" } },
87
- c: { preset: { context: "eduwebngv1", folder: "compositionshelves" } },
88
- cd: {
89
- preset: { server: "19" },
90
- remotePath: "/erp/edumaven/dingcorrection-page-dev/compositionshelves"
91
- }
92
- };
93
- const uploadSftpConfigs = [];
94
- if (args.b) {
95
- uploadSftpConfigs.push(presetConfig.b);
96
- }
97
- if (args.s) {
98
- uploadSftpConfigs.push(presetConfig.s);
99
- }
100
- if (args.d) {
101
- uploadSftpConfigs.push(presetConfig.d);
102
- }
103
- if (args.c) {
104
- uploadSftpConfigs.push(presetConfig.c);
105
- }
106
- if (args.cd) {
107
- uploadSftpConfigs.push(presetConfig.cd);
108
- }
109
- if (uploadSftpConfigs.length === 0) {
110
- console.log(
111
- `
112
- ${chalk.red("指定 deploy 部署范围")}
113
- 执行 ${chalk.green("npx edu-scripts deploy -h")} 查看具体用法
114
- `
115
- );
116
- process.exit();
117
- }
118
- const uploadConfig = { ...baseConfig, ignore: [...baseConfig.ignore, "js/ver.js"] };
119
- if (!appConfig.mainProject) {
120
- uploadConfig.ignore = [...uploadConfig.ignore, "!(js|images)"];
121
- }
122
- for (const config of uploadSftpConfigs) {
123
- await upload({ ...uploadConfig, ...config });
124
- }
125
- }
126
- async function singleDeploy() {
127
- const config = fs.existsSync(paths.sshSftp) ? fs.readJsonSync(paths.sshSftp) : {
128
- ...baseConfig,
129
- preset: { context: "qsxxwapdev" },
130
- cleanRemoteFiles: true,
131
- securityLock: true,
132
- keepAlive: false,
133
- noWarn: false
134
- };
135
- sshSftp(config);
136
- }
137
- module.exports = function deploy(args) {
138
- if (appConfig.single) {
139
- singleDeploy();
140
- } else {
141
- normalDeploy(args);
142
- }
143
- };