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