@qse/edu-scripts 1.14.18 → 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 -487
  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 -58
  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,16 +1,27 @@
1
- const chalk = require('chalk')
2
- const paths = require('./config/paths')
3
- const fs = require('fs-extra')
4
- const exec = (cmd, opts) =>
5
- require('child_process').execSync(cmd, { encoding: 'utf-8', stdio: 'pipe', ...opts })
6
- const tmp = require('tmp')
7
-
8
- function validateSVNRoot(root) {
1
+ import chalk from 'chalk'
2
+ import paths from './config/paths'
3
+ import fs from 'fs-extra'
4
+ import cp from 'child_process'
5
+ import tmp from 'tmp'
6
+
7
+ const exec = (cmd: string, opts?: cp.ExecSyncOptions) =>
8
+ cp.execSync(cmd, { encoding: 'utf-8', stdio: 'pipe', ...opts }) as string
9
+
10
+ function validateSVNRoot(root: string) {
9
11
  const ls = exec(`svn ls ${root}`)
10
12
  return ['trunk', 'branches'].every((s) => ls.includes(s))
11
13
  }
12
14
 
13
- function getWorkingCopyInfo() {
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 {
14
25
  exec(`svn up`)
15
26
  const url = exec(`svn info --show-item url`).trim()
16
27
  const revision = exec(`svn info --show-item last-changed-revision`).trim()
@@ -19,7 +30,7 @@ function getWorkingCopyInfo() {
19
30
  let branch = 'trunk'
20
31
  let root = url.replace(/\/trunk$/, '')
21
32
  if (url.includes('/branches/')) {
22
- branch = url.split('/').pop()
33
+ branch = url.split('/').pop()!
23
34
  root = url.replace(/\/branches\/[^/]+$/, '')
24
35
  }
25
36
  let distBranchURL = root + '/branches/dist'
@@ -32,12 +43,12 @@ function getWorkingCopyInfo() {
32
43
  return { url, branch, revision, author, distBranchURL, distBranchDirURL, root }
33
44
  }
34
45
 
35
- function copyDistToRepo(info) {
46
+ function copyDistToRepo(info: WorkingCopyInfo) {
36
47
  const tmpdir = tmp.dirSync().name
37
48
 
38
49
  try {
39
50
  exec(`svn ls ${info.distBranchDirURL} --depth empty`)
40
- } catch (error) {
51
+ } catch (error: any) {
41
52
  if (error.message.includes('non-existent')) {
42
53
  exec(
43
54
  `svn mkdir ${info.distBranchDirURL} --parents -m "[edu-scripts] create ${info.branch} dist"`
@@ -50,8 +61,7 @@ function copyDistToRepo(info) {
50
61
 
51
62
  try {
52
63
  exec(`svn rm * --force -q`, { cwd: tmpdir })
53
- } catch (error) {}
54
-
64
+ } catch {}
55
65
  fs.copySync(paths.dist, tmpdir)
56
66
 
57
67
  exec(`svn add * --force --auto-props --parents --depth infinity -q`, { cwd: tmpdir })
@@ -62,13 +72,10 @@ function copyDistToRepo(info) {
62
72
  fs.removeSync(tmpdir)
63
73
  }
64
74
 
65
- /**
66
- * svn commit dist folder to dish branches
67
- *
68
- * @param {Object} args
69
- * @param {boolean} args.rmLocal
70
- */
71
- module.exports = async function commitDist(args) {
75
+ interface CommitDistArgs {
76
+ rmLocal?: boolean
77
+ }
78
+ export default async function commitDist(args: CommitDistArgs) {
72
79
  if (!fs.existsSync(paths.dist)) {
73
80
  console.log(chalk.red('未找到 dist 文件夹,请先 edu-scpirts build'))
74
81
  process.exit(1)
@@ -0,0 +1,52 @@
1
+ import path from 'path'
2
+ import fs from 'fs-extra'
3
+ import { globbySync } from 'globby'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ function resolveApp(...filePath: string[]) {
7
+ return path.resolve(process.cwd(), ...filePath)
8
+ }
9
+
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[]) {
24
+ for (const path of paths) {
25
+ if (fs.existsSync(path)) {
26
+ return path
27
+ }
28
+ }
29
+ return paths[0]
30
+ }
31
+
32
+ const paths = {
33
+ resolveApp,
34
+ resolveOwn,
35
+ eduAppEnv: resolveApp('src', 'edu-app-env.d.ts'),
36
+ dist: resolveApp('dist'),
37
+ sshSftp: resolveApp('.sftprc.json'),
38
+ nodeModules: resolveApp('node_modules'),
39
+ tsconfig: resolveApp('tsconfig.json'),
40
+ jsconfig: resolveApp('jsconfig.json'),
41
+ package: resolveApp('package.json'),
42
+ tailwind: resolveApp('tailwind.config.js'),
43
+ pages: resolveApp('src', 'pages'),
44
+ override: getExistPath(resolveApp('edu-scripts.override.js'), resolveApp('edu-scripts.override.ts')),
45
+ indexHTML: globbySync('./public/*.html', { absolute: true }),
46
+ src: resolveApp('src'),
47
+ public: resolveApp('public'),
48
+ static: resolveApp('public', 'static'),
49
+ theme: getExistPath(resolveApp('theme.json'), resolveApp('theme.js')),
50
+ mock: resolveApp('mock'),
51
+ }
52
+ export default paths
@@ -1,29 +1,25 @@
1
- const paths = require('../../paths')
2
- const globby = require('globby')
3
- const chokidar = require('chokidar')
4
- const debounce = require('lodash/debounce')
5
- const memoize = require('lodash/memoize')
6
- const chalk = require('chalk')
7
- const fs = require('fs-extra')
8
- const express = require('express')
9
- const cookieParser = require('cookie-parser')
10
- const multer = require('multer')
11
- const { pathToRegexp } = require('path-to-regexp')
12
-
13
- /**
14
- * @type {Record<string,{handler:any;method:string;path:string}>}
15
- */
16
- let mockCache = {}
1
+ import paths from '../../paths'
2
+ import { globbySync } from 'globby'
3
+ import chokidar from 'chokidar'
4
+ import { debounce, memoize } from 'lodash-es'
5
+ import chalk from 'chalk'
6
+ import fs from 'fs-extra'
7
+ import express from 'express'
8
+ import cookieParser from 'cookie-parser'
9
+ import multer from 'multer'
10
+ import { pathToRegexp, type Key } from 'path-to-regexp'
11
+ import { createRequire } from 'node:module'
12
+ import { resolveModule } from '@/utils/resolveModule'
13
+ const require = createRequire(import.meta.url)
14
+
15
+ let mockCache: Record<string, { handler: any; method: string; path: string }> = {}
17
16
  let isSetup = false
18
17
 
19
- /**
20
- * @param {import('webpack-dev-server').Middleware[]} middelwaves
21
- */
22
18
  const setupMock = debounce(function setupMock() {
23
19
  // clean
24
20
  mockCache = {}
25
21
 
26
- const files = globby.sync(paths.mock, { expandDirectories: { extensions: ['js', 'ts'] } })
22
+ const files = globbySync(paths.mock, { expandDirectories: { extensions: ['js', 'ts'] } })
27
23
 
28
24
  if (isSetup) {
29
25
  console.log(chalk.green('Mock files changed, reloaded'))
@@ -35,26 +31,25 @@ const setupMock = debounce(function setupMock() {
35
31
  for (const file of files) {
36
32
  delete require.cache[require.resolve(file)]
37
33
  try {
38
- let mock = require(file)
39
- mock = mock.default || mock
34
+ const mock = resolveModule(require(file))
40
35
 
41
36
  for (const key in mock) {
42
37
  const [method, path] = key.split(' ')
43
38
  mockCache[key] = { method, path, handler: mock[key] }
44
39
  }
45
- } catch (e) {
40
+ } catch (e: any) {
46
41
  console.error(chalk.red(`Mock file ${file} error: ${e.message}`))
47
42
  }
48
43
  }
49
44
  }, 100)
50
45
 
51
- const getPathReAndKeys = memoize((path) => {
52
- const keys = []
46
+ const getPathReAndKeys = memoize((path: string) => {
47
+ const keys: Key[] = []
53
48
  const re = pathToRegexp(path, keys)
54
49
  return { re, keys }
55
50
  })
56
51
 
57
- function decodeParam(val) {
52
+ function decodeParam(val: string) {
58
53
  if (typeof val !== 'string' || val.length === 0) {
59
54
  return val
60
55
  }
@@ -75,7 +70,7 @@ function decodeParam(val) {
75
70
  /**
76
71
  * @type {import('express').RequestHandler}
77
72
  */
78
- function mockMiddlewave(req, res, next) {
73
+ const mockMiddlewave: express.RequestHandler = function mockMiddlewave(req, res, next) {
79
74
  const { method, path } = req
80
75
  for (const key in mockCache) {
81
76
  const mock = mockCache[key]
@@ -93,6 +88,7 @@ function mockMiddlewave(req, res, next) {
93
88
  const prop = key.name
94
89
  const val = decodeParam(m[i])
95
90
  if (val !== undefined) {
91
+ // @ts-ignore
96
92
  params[prop] = val
97
93
  }
98
94
  }
@@ -125,23 +121,16 @@ function mockMiddlewave(req, res, next) {
125
121
  next()
126
122
  }
127
123
 
128
- /**
129
- * @param {import('webpack-dev-server').Middleware[]} middelwaves
130
- * @param {import('webpack-dev-server')} devServer
131
- */
132
- function setupMockServer(middelwaves, devServer) {
133
- if (!fs.existsSync(paths.mock)) return
124
+ type Middlewares = Parameters<
125
+ NonNullable<import('@rspack/dev-server').Configuration['setupMiddlewares']>
126
+ >[0]
134
127
 
135
- require('@babel/register')({
136
- presets: [['@babel/preset-env', { modules: 'cjs' }], '@babel/preset-typescript'],
137
- babelrc: false,
138
- only: [/\/mock\//, /\/src\//],
139
- extensions: ['.js', '.ts'],
140
- })
128
+ function setupMockServer(middelwaves: Middlewares, _devServer: any) {
129
+ if (!fs.existsSync(paths.mock)) return
141
130
 
142
131
  middelwaves.unshift({
143
132
  name: 'edu-scripts-mock-middelwave',
144
- middleware: mockMiddlewave,
133
+ middleware: mockMiddlewave as any,
145
134
  })
146
135
 
147
136
  console.log(
@@ -153,4 +142,4 @@ function setupMockServer(middelwaves, devServer) {
153
142
  return middelwaves
154
143
  }
155
144
 
156
- module.exports = setupMockServer
145
+ export default setupMockServer
@@ -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
- /** @type {import('postcss').PluginCreator} */
11
- module.exports = () => {
11
+ const PostcssSafeAreaPlugin = (): Plugin => {
12
12
  return {
13
13
  postcssPlugin: 'postcss-safe-area',
14
14
  Declaration(decl) {
@@ -19,3 +19,5 @@ module.exports = () => {
19
19
  },
20
20
  }
21
21
  }
22
+
23
+ export default PostcssSafeAreaPlugin