@qse/edu-scripts 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,14 @@
1
1
  import { Chalk } from "chalk";
2
2
  import { Compiler, Configuration, SwcLoaderOptions } from "@rspack/core";
3
- import { Configuration as Configuration$1 } from "@rspack/dev-server";
4
3
  import { RequestHandler } from "express";
4
+ import { Configuration as Configuration$1 } from "@rspack/dev-server";
5
5
 
6
+ //#region src/config/plugins/mock-server/defineMock.d.ts
7
+ type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
8
+ type API = string;
9
+ type MockConfig = Record<`${Method} ${API}`, string | number | null | undefined | boolean | Record<string, any> | RequestHandler>;
10
+ declare function defineMock(config: MockConfig): MockConfig;
11
+ //#endregion
6
12
  //#region src/utils/defineConfig.d.ts
7
13
  type ProxyConfigArray = NonNullable<Configuration$1['proxy']>;
8
14
  type Configuration$2 = {
@@ -81,10 +87,4 @@ type Configuration$2 = {
81
87
  };
82
88
  declare function defineConfig(config: Configuration$2): Configuration$2;
83
89
  //#endregion
84
- //#region src/config/plugins/mock-server/defineMock.d.ts
85
- type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
86
- type API = string;
87
- type MockConfig = Record<`${Method} ${API}`, string | number | null | undefined | boolean | Record<string, any> | RequestHandler>;
88
- declare function defineMock(config: MockConfig): MockConfig;
89
- //#endregion
90
90
  export { defineConfig, defineMock };
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- //#region src/utils/defineConfig.ts
2
- function defineConfig(config) {
1
+ //#region src/config/plugins/mock-server/defineMock.ts
2
+ function defineMock(config) {
3
3
  return config;
4
4
  }
5
5
 
6
6
  //#endregion
7
- //#region src/config/plugins/mock-server/defineMock.ts
8
- function defineMock(config) {
7
+ //#region src/utils/defineConfig.ts
8
+ function defineConfig(config) {
9
9
  return config;
10
10
  }
11
11
 
package/package.json CHANGED
@@ -1,10 +1,21 @@
1
1
  {
2
2
  "name": "@qse/edu-scripts",
3
- "version": "2.0.3",
4
- "author": "Kinoko",
5
- "license": "MIT",
6
3
  "type": "module",
4
+ "version": "2.1.0",
7
5
  "description": "教育工程化基础框架",
6
+ "author": "Kinoko",
7
+ "license": "MIT",
8
+ "homepage": "http://192.168.10.19:3339/qsxxwapdev/edu-scripts/",
9
+ "publishConfig": {
10
+ "registry": "https://registry.npmjs.org/",
11
+ "access": "public"
12
+ },
13
+ "main": "dist/index.mjs",
14
+ "types": "dist/index.d.mts",
15
+ "bin": {
16
+ "edu-scripts": "dist/cli.mjs",
17
+ "edu": "dist/cli.mjs"
18
+ },
8
19
  "engines": {
9
20
  "node": ">=18"
10
21
  },
@@ -21,21 +32,10 @@
21
32
  "postversion": "npm run release",
22
33
  "test": "jest"
23
34
  },
24
- "homepage": "http://192.168.10.19:3339/qsxxwapdev/edu-scripts/",
25
- "publishConfig": {
26
- "registry": "https://registry.npmjs.org/",
27
- "access": "public"
28
- },
29
- "bin": {
30
- "edu-scripts": "dist/cli.mjs",
31
- "edu": "dist/cli.mjs"
32
- },
33
- "main": "dist/index.mjs",
34
- "typings": "dist/index.d.mts",
35
35
  "dependencies": {
36
36
  "@babel/core": "~7.29.0",
37
37
  "@inquirer/prompts": "^8.3.0",
38
- "@qse/ssh-sftp": "^1.3.1",
38
+ "@qse/ssh-sftp": "^1.4.0",
39
39
  "@rsdoctor/rspack-plugin": "^1.5.2",
40
40
  "@rspack/core": "^1.7.6",
41
41
  "@rspack/dev-server": "^1.2.1",
@@ -44,6 +44,7 @@
44
44
  "@swc-node/register": "^1.11.1",
45
45
  "@swc/helpers": "^0.5.19",
46
46
  "@types/express": "^4.17.25",
47
+ "@types/node": "^24.12.0",
47
48
  "chalk": "^4.1.2",
48
49
  "chokidar": "^3.6.0",
49
50
  "cookie-parser": "^1.4.7",
@@ -83,7 +84,7 @@
83
84
  "devDependencies": {
84
85
  "@babel/preset-env": "~7.29.0",
85
86
  "@babel/preset-typescript": "^7.28.5",
86
- "@qse/eslint-config": "^1.0.0",
87
+ "@qse/eslint-config": "^1.1.2",
87
88
  "@types/cookie-parser": "^1.4.10",
88
89
  "@types/fs-extra": "^11.0.4",
89
90
  "@types/jest": "^30.0.0",
@@ -96,13 +97,5 @@
96
97
  "rimraf": "^6.1.3",
97
98
  "tsdown": "^0.20.3",
98
99
  "vitepress": "^1.6.4"
99
- },
100
- "peerDependencies": {
101
- "tailwindcss": "^3.0.0"
102
- },
103
- "peerDependenciesMeta": {
104
- "tailwindcss": {
105
- "optional": true
106
- }
107
100
  }
108
101
  }
@@ -1,10 +1,11 @@
1
- import fs from 'fs-extra'
2
- import paths from './config/paths'
3
- import path from 'path'
1
+ import { checkbox, input, select } from '@inquirer/prompts'
4
2
  import chalk from 'chalk'
3
+ import fs from 'fs-extra'
5
4
  import { globby } from 'globby'
6
5
  import ora from 'ora'
7
- import { input, select, checkbox } from '@inquirer/prompts'
6
+ import path from 'path'
7
+
8
+ import paths from './config/paths'
8
9
 
9
10
  const pkg = fs.readJsonSync(paths.resolveOwn('package.json'))
10
11
 
@@ -39,8 +40,7 @@ export default async function autoRefactor() {
39
40
  const version = await input({
40
41
  message: '版本号',
41
42
  default: '1.0.0',
42
- validate: (v) =>
43
- /^\d+\.\d+\.\d+$/.test(v) || '请按格式输入 /^\\d+\\.\\d+\\.\\d+$/ 例如: 1.0.0',
43
+ validate: (v) => /^\d+\.\d+\.\d+$/.test(v) || '请按格式输入 /^\\d+\\.\\d+\\.\\d+$/ 例如: 1.0.0',
44
44
  })
45
45
 
46
46
  const mode = await select({
package/src/build.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { rspack, type Stats } from '@rspack/core'
1
+ import type { Stats } from '@rspack/core'
2
+
3
+ import { rspack } from '@rspack/core'
2
4
  import chalk from 'chalk'
3
- import getConfig from './utils/getConfig'
4
- // @ts-ignore
5
- import { measureFileSizesBeforeBuild, printFileSizesAfterBuild } from './utils/FileSizeReporter'
6
- import paths from './config/paths'
7
5
  import fs from 'fs-extra'
6
+
7
+ import paths from './config/paths'
8
8
  import appConfig from './utils/appConfig'
9
+ import { measureFileSizesBeforeBuild, printFileSizesAfterBuild } from './utils/FileSizeReporter'
10
+ import getConfig from './utils/getConfig'
9
11
 
10
12
  const WARN_AFTER_BUNDLE_GZIP_SIZE = appConfig.single ? 1024 * 1024 : 30 * 1024
11
13
  const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024
package/src/cli.ts CHANGED
@@ -1,18 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import './utils/esm-register'
3
-
4
3
  import './utils/beforeStart'
5
4
 
6
5
  import fs from 'fs-extra'
7
6
  import yargs from 'yargs'
8
- import paths from './config/paths'
9
7
 
10
- import start from './start'
11
- import build from './build'
12
- import deploy from './deploy'
13
8
  import autoRefactor from './auto-refactor'
9
+ import build from './build'
14
10
  import commitDist from './commit-dist'
11
+ import paths from './config/paths'
12
+ import deploy from './deploy'
15
13
  import * as generator from './generator'
14
+ import start from './start'
16
15
 
17
16
  const pkg = fs.readJsonSync(paths.resolveOwn('package.json'))
18
17
 
@@ -46,7 +45,7 @@ yargs(process.argv.slice(2))
46
45
  )
47
46
  .command(
48
47
  'deploy',
49
- '自动部署 dist 到 v1 服务器',
48
+ '自动部署 dist 到 v1 服务器,可以使用 @qse/ssh-sftp 工具生成.sftprc.json文件,或者直接使用命令行参数指定上传目标',
50
49
  (yargs) =>
51
50
  yargs
52
51
  .option('school', { alias: 's', desc: '上传到校端', default: false, boolean: true })
@@ -1,9 +1,10 @@
1
1
  import chalk from 'chalk'
2
- import paths from './config/paths'
3
- import fs from 'fs-extra'
4
2
  import cp from 'child_process'
3
+ import fs from 'fs-extra'
5
4
  import tmp from 'tmp'
6
5
 
6
+ import paths from './config/paths'
7
+
7
8
  const exec = (cmd: string, opts?: cp.ExecSyncOptions) =>
8
9
  cp.execSync(cmd, { encoding: 'utf-8', stdio: 'pipe', ...opts }) as string
9
10
 
@@ -1,7 +1,7 @@
1
- import path from 'path'
2
1
  import fs from 'fs-extra'
3
2
  import { globbySync } from 'globby'
4
3
  import { fileURLToPath } from 'node:url'
4
+ import path from 'path'
5
5
 
6
6
  function resolveApp(...filePath: string[]) {
7
7
  return path.resolve(process.cwd(), ...filePath)
@@ -1,4 +1,5 @@
1
1
  import type { RequestHandler } from 'express'
2
+
2
3
  type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'
3
4
  type API = string
4
5
 
@@ -1,15 +1,18 @@
1
- import paths from '../../paths'
2
- import { globbySync } from 'globby'
1
+ import chalk from 'chalk'
3
2
  import chokidar from 'chokidar'
3
+ import cookieParser from 'cookie-parser'
4
4
  import { debounce, memoize } from 'es-toolkit'
5
- import chalk from 'chalk'
6
- import fs from 'fs-extra'
7
5
  import express from 'express'
8
- import cookieParser from 'cookie-parser'
6
+ import fs from 'fs-extra'
7
+ import { globbySync } from 'globby'
9
8
  import multer from 'multer'
10
- import { pathToRegexp } from 'path-to-regexp'
11
9
  import { createRequire } from 'node:module'
10
+ import { pathToRegexp } from 'path-to-regexp'
11
+
12
12
  import { resolveModule } from '@/utils/resolveModule'
13
+
14
+ import paths from '../../paths'
15
+
13
16
  const require = createRequire(import.meta.url)
14
17
 
15
18
  let mockCache: Record<string, { handler: any; method: string; path: string }> = {}
@@ -1,4 +1,5 @@
1
1
  import type { Plugin } from 'postcss'
2
+
2
3
  const vars = [
3
4
  'safe-area-inset-top',
4
5
  'safe-area-inset-bottom',
@@ -1,6 +1,6 @@
1
- import { resolveModule } from '@/utils/resolveModule'
2
- import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
3
1
  import type { Compiler, Configuration, RuleSetRule, SwcLoaderOptions } from '@rspack/core'
2
+
3
+ import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
4
4
  import { rspack } from '@rspack/core'
5
5
  import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
6
6
  import chalk from 'chalk'
@@ -8,11 +8,15 @@ import fs from 'fs-extra'
8
8
  import HtmlWebpackPlugin from 'html-webpack-plugin'
9
9
  import { createRequire } from 'node:module'
10
10
  import path from 'node:path'
11
- import appConfig from '../utils/appConfig'
11
+ import { fileURLToPath } from 'node:url'
12
+
13
+ import { resolveModule } from '@/utils/resolveModule'
14
+
12
15
  import type { Configuration as CustomConfiguration } from '../utils/defineConfig'
16
+
17
+ import appConfig from '../utils/appConfig'
13
18
  import paths from './paths'
14
19
  import PostcssSafeAreaPlugin from './plugins/postcss-safe-area'
15
- import { fileURLToPath } from 'node:url'
16
20
 
17
21
  const require = createRequire(import.meta.url)
18
22
  const appPkg = fs.readJsonSync(paths.package) as { name: string; version: string }
@@ -1,5 +1,7 @@
1
1
  import type { Configuration } from '@rspack/dev-server'
2
+
2
3
  import type { Configuration as CustomConfiguration } from '../utils/defineConfig'
4
+
3
5
  import setupMockServer from './plugins/mock-server'
4
6
 
5
7
  interface ProxyConfig {
@@ -24,7 +26,10 @@ function createProxy(context: string, target: string, origin?: string): ProxyCon
24
26
  }
25
27
  }
26
28
 
27
- export default function getWebpackDevServerConfig(args: any, override: CustomConfiguration): Configuration {
29
+ export default function getWebpackDevServerConfig(
30
+ args: any,
31
+ override: CustomConfiguration
32
+ ): Configuration {
28
33
  const host = process.env.HOST || '0.0.0.0'
29
34
 
30
35
  const devServer: Configuration = {
package/src/deploy.ts CHANGED
@@ -1,14 +1,15 @@
1
- // @ts-ignore
1
+ import type { Options as SshSftpOptions } from '@qse/ssh-sftp'
2
+
2
3
  import { sshSftp } from '@qse/ssh-sftp'
3
- import paths from './config/paths.js'
4
4
  import chalk from 'chalk'
5
5
  import fs from 'fs-extra'
6
- // @ts-ignore
7
- import changeDeployVersion from './utils/changeDeployVersion'
8
6
  import ora from 'ora'
9
- import appConfig from './utils/appConfig.js'
10
7
  import { format } from 'prettier'
11
8
 
9
+ import paths from './config/paths.js'
10
+ import appConfig from './utils/appConfig.js'
11
+ import changeDeployVersion from './utils/changeDeployVersion'
12
+
12
13
  const appPkg = fs.readJsonSync(paths.package)
13
14
 
14
15
  const baseConfig = {
@@ -54,9 +55,9 @@ async function normalDeploy(args: DeployArgs) {
54
55
  return lines.slice(-50).join('\n')
55
56
  }
56
57
 
57
- async function upload(opts: any) {
58
+ async function upload(opts: SshSftpOptions) {
58
59
  // 上传dist文件
59
- const { sftp, opts: fullOpts } = await sshSftp(opts)
60
+ const { sftp, opts: fullOpts } = (await sshSftp(opts))!
60
61
 
61
62
  const spinner = ora('自动更新 ver.js 版本配置').start()
62
63
  // 指定远程需要修改的文件
@@ -113,7 +114,7 @@ async function normalDeploy(args: DeployArgs) {
113
114
  }
114
115
  }
115
116
 
116
- const presetConfig = {
117
+ const presetConfig: Record<string, SshSftpOptions> = {
117
118
  s: { preset: { context: 'eduwebngv1', folder: 'userportal' } },
118
119
  b: { preset: { context: 'eduwebngv1', folder: 'bureaupc' } },
119
120
  d: { preset: { context: 'eduwebngv1', folder: 'documentshelves' } },
@@ -123,7 +124,7 @@ async function normalDeploy(args: DeployArgs) {
123
124
  remotePath: '/erp/edumaven/dingcorrection-page-dev/compositionshelves',
124
125
  },
125
126
  }
126
- const uploadSftpConfigs = []
127
+ const uploadSftpConfigs: SshSftpOptions[] = []
127
128
  if (args.bureau) {
128
129
  uploadSftpConfigs.push(presetConfig.b)
129
130
  }
@@ -139,6 +140,11 @@ async function normalDeploy(args: DeployArgs) {
139
140
  if (args.compositionshelvesDingtalk) {
140
141
  uploadSftpConfigs.push(presetConfig.cd)
141
142
  }
143
+ if (uploadSftpConfigs.length === 0 && fs.existsSync(paths.sshSftp)) {
144
+ const config = fs.readJsonSync(paths.sshSftp)
145
+ uploadSftpConfigs.push(config)
146
+ }
147
+
142
148
  if (uploadSftpConfigs.length === 0) {
143
149
  console.log(
144
150
  `
@@ -146,7 +152,7 @@ async function normalDeploy(args: DeployArgs) {
146
152
  执行 ${chalk.green('npx edu-scripts deploy -h')} 查看具体用法
147
153
  `
148
154
  )
149
- process.exit()
155
+ process.exit(1)
150
156
  }
151
157
 
152
158
  const uploadConfig = { ...baseConfig, ignore: [...baseConfig.ignore, 'js/ver.js'] }
package/src/generator.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import chalk from 'chalk'
1
2
  import fs from 'fs-extra'
3
+
2
4
  import paths from './config/paths'
3
- import chalk from 'chalk'
4
5
 
5
6
  const getTmpPath = (...args: string[]) => paths.resolveOwn('asset', 'template', ...args)
6
7
 
@@ -56,4 +57,4 @@ async function generatorTailwind() {
56
57
  )
57
58
  }
58
59
 
59
- export { generatorOverride as override, generatorTsconfig as ts, generatorTailwind as tailwind }
60
+ export { generatorOverride as override, generatorTailwind as tailwind, generatorTsconfig as ts }
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { defineConfig } from './utils/defineConfig'
2
1
  export { defineMock } from './config/plugins/mock-server/defineMock'
2
+ export { defineConfig } from './utils/defineConfig'
package/src/start.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { rspack } from '@rspack/core'
2
2
  import { RspackDevServer } from '@rspack/dev-server'
3
- import getConfig from './utils/getConfig.js'
4
3
  import chalk from 'chalk'
5
4
 
5
+ import getConfig from './utils/getConfig.js'
6
+
6
7
  interface StartArgs {
7
8
  port?: string
8
9
  }
@@ -5,15 +5,16 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import fs from 'fs-extra'
9
- import path from 'path'
8
+ import type { Stats } from '@rspack/core'
9
+
10
10
  import chalk from 'chalk'
11
11
  import filesize from 'filesize'
12
+ import fs from 'fs-extra'
13
+ import { gzipSizeSync } from 'gzip-size'
14
+ import path from 'path'
12
15
  // @ts-ignore
13
16
  import recursive from 'recursive-readdir'
14
17
  import stripAnsi from 'strip-ansi'
15
- import { gzipSizeSync } from 'gzip-size'
16
- import type { Stats } from '@rspack/core'
17
18
 
18
19
  interface SizeMap {
19
20
  root: string
@@ -1,6 +1,7 @@
1
- import paths from '../config/paths'
2
1
  import fs from 'fs-extra'
3
2
 
3
+ import paths from '../config/paths'
4
+
4
5
  const appPkg = fs.readJsonSync(paths.package)
5
6
 
6
7
  const edu = appPkg.edu || {}
@@ -1,7 +1,8 @@
1
- import fs from 'fs-extra'
2
- import paths from '../config/paths'
3
1
  import chalk from 'chalk'
2
+ import fs from 'fs-extra'
4
3
  import semver from 'semver'
4
+
5
+ import paths from '../config/paths'
5
6
  import appConfig from './appConfig'
6
7
 
7
8
  const pkg = fs.readJsonSync(paths.resolveOwn('package.json'))
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- import { parse, traverse, types as t, transformFromAstSync } from '@babel/core'
2
+ import { parse, types as t, transformFromAstSync, traverse } from '@babel/core'
3
3
 
4
4
  // ver.js 中定义模块的数组
5
5
  const TARGET_IDENTIFIER_NAME = 'project_apiArr'
@@ -1,6 +1,6 @@
1
- import type { Chalk } from 'chalk'
2
1
  import type { Compiler, Configuration as RspackConfiguration, SwcLoaderOptions } from '@rspack/core'
3
2
  import type { Configuration as DevServerConfiguration } from '@rspack/dev-server'
3
+ import type { Chalk } from 'chalk'
4
4
 
5
5
  type ProxyConfigArray = NonNullable<DevServerConfiguration['proxy']>
6
6
 
@@ -3,4 +3,5 @@ import { createRequire } from 'node:module'
3
3
  // 兼容 CommonJS 模块
4
4
  const require = createRequire(import.meta.url)
5
5
  const { register } = require('@swc-node/register/register')
6
+
6
7
  register()
package/src/utils/exec.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import cp from 'child_process'
2
+
2
3
  const exec = (cmd: string) => {
3
4
  console.log(`> ${cmd}`)
4
5
  return cp.execSync(cmd, { stdio: 'inherit', encoding: 'utf-8' })
@@ -1,6 +1,4 @@
1
- // @ts-ignore
2
1
  import getWebpackConfig from '../config/webpackConfig'
3
- // @ts-ignore
4
2
  import getWebpackDevServerConfig from '../config/webpackDevServerConfig'
5
3
  import getOverride from './getOverride'
6
4
 
@@ -1,7 +1,9 @@
1
1
  import fs from 'fs-extra'
2
- import paths from '../config/paths'
3
2
  import { createRequire } from 'node:module'
4
- import { type Configuration } from './defineConfig'
3
+
4
+ import type { Configuration } from './defineConfig'
5
+
6
+ import paths from '../config/paths'
5
7
  import { resolveModule } from './resolveModule'
6
8
 
7
9
  const require = createRequire(import.meta.url)
package/tsdown.config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from 'tsdown'
2
2
 
3
3
  export default defineConfig({
4
- entry: ['src/index.ts', 'src/cli.js'],
4
+ entry: ['src/index.ts', 'src/cli.ts'],
5
5
  })