@qse/edu-scripts 1.13.7 → 1.13.9

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 (39) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/app.d.ts +10 -0
  3. package/docs/feat.md +84 -0
  4. package/docs/override.md +7 -0
  5. package/lib/auto-refactor.js +88 -95
  6. package/lib/build.js +33 -36
  7. package/lib/cli.js +64 -61
  8. package/lib/commit-dist.js +40 -54
  9. package/lib/config/babel.dependencies.js +41 -39
  10. package/lib/config/babel.js +82 -55
  11. package/lib/config/paths.js +28 -30
  12. package/lib/config/plugins/mock-server/defineMock.d.ts +6 -0
  13. package/lib/config/plugins/mock-server/defineMock.js +31 -0
  14. package/lib/config/plugins/mock-server/index.js +69 -0
  15. package/lib/config/plugins/postcss-safe-area.js +12 -12
  16. package/lib/config/webpackConfig.js +360 -325
  17. package/lib/config/webpackDevServerConfig.js +27 -29
  18. package/lib/deploy.js +58 -100
  19. package/lib/generator.js +49 -81
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +29 -9
  22. package/lib/start.js +16 -22
  23. package/lib/utils/FileSizeReporter.js +45 -56
  24. package/lib/utils/appConfig.js +12 -13
  25. package/lib/utils/beforeStart.js +35 -35
  26. package/lib/utils/changeDeployVersion.js +36 -65
  27. package/lib/utils/defineConfig.d.ts +7 -0
  28. package/lib/utils/defineConfig.js +27 -5
  29. package/lib/utils/exec.js +5 -9
  30. package/lib/utils/getConfig.js +6 -7
  31. package/lib/utils/getOverride.js +13 -17
  32. package/package.json +32 -29
  33. package/src/config/paths.js +1 -0
  34. package/src/config/plugins/mock-server/defineMock.ts +12 -0
  35. package/src/config/plugins/mock-server/index.js +92 -0
  36. package/src/config/webpackConfig.js +9 -2
  37. package/src/config/webpackDevServerConfig.js +8 -0
  38. package/src/index.ts +1 -0
  39. package/src/utils/defineConfig.ts +8 -1
@@ -1,93 +1,79 @@
1
- "use strict";
2
-
3
- const chalk = require('chalk');
4
- const paths = require('./config/paths');
5
- const fs = require('fs-extra');
6
- const exec = (cmd, opts) => require('child_process').execSync(cmd, {
7
- encoding: 'utf-8',
8
- stdio: 'pipe',
9
- ...opts
10
- });
11
- const tmp = require('tmp');
1
+ // src/commit-dist.js
2
+ var chalk = require("chalk");
3
+ var paths = require("./config/paths");
4
+ var fs = require("fs-extra");
5
+ var exec = (cmd, opts) => require("child_process").execSync(cmd, { encoding: "utf-8", stdio: "pipe", ...opts });
6
+ var tmp = require("tmp");
12
7
  function validateSVNRoot(root) {
13
8
  const ls = exec(`svn ls ${root}`);
14
- return ['trunk', 'branches'].every(s => ls.includes(s));
9
+ return ["trunk", "branches"].every((s) => ls.includes(s));
15
10
  }
16
11
  function getWorkingCopyInfo() {
17
12
  exec(`svn up`);
18
13
  const url = exec(`svn info --show-item url`).trim();
19
14
  const revision = exec(`svn info --show-item last-changed-revision`).trim();
20
15
  const author = exec(`svn info --show-item last-changed-author`).trim();
21
- let branch = 'trunk';
22
- let root = url.replace(/\/trunk$/, '');
23
- if (url.includes('/branches/')) {
24
- branch = url.split('/').pop();
25
- root = url.replace(/\/branches\/[^/]+$/, '');
16
+ let branch = "trunk";
17
+ let root = url.replace(/\/trunk$/, "");
18
+ if (url.includes("/branches/")) {
19
+ branch = url.split("/").pop();
20
+ root = url.replace(/\/branches\/[^/]+$/, "");
26
21
  }
27
- let distBranchURL = root + '/branches/dist';
28
- let distBranchDirURL = distBranchURL + '/' + branch;
22
+ let distBranchURL = root + "/branches/dist";
23
+ let distBranchDirURL = distBranchURL + "/" + branch;
29
24
  if (!validateSVNRoot(root)) {
30
- console.log(chalk.red('SVN目录不符合规则,必须包含 trunk branches'));
25
+ console.log(chalk.red("SVN目录不符合规则,必须包含 trunk branches"));
31
26
  process.exit(1);
32
27
  }
33
- return {
34
- url,
35
- branch,
36
- revision,
37
- author,
38
- distBranchURL,
39
- distBranchDirURL,
40
- root
41
- };
28
+ return { url, branch, revision, author, distBranchURL, distBranchDirURL, root };
42
29
  }
43
30
  function copyDistToRepo(info) {
44
31
  const tmpdir = tmp.dirSync().name;
45
32
  try {
46
33
  exec(`svn ls ${info.distBranchDirURL} --depth empty`);
47
34
  } catch (error) {
48
- if (error.message.includes('non-existent')) {
49
- exec(`svn mkdir ${info.distBranchDirURL} --parents -m "[edu-scripts] create ${info.branch} dist"`);
35
+ if (error.message.includes("non-existent")) {
36
+ exec(
37
+ `svn mkdir ${info.distBranchDirURL} --parents -m "[edu-scripts] create ${info.branch} dist"`
38
+ );
50
39
  } else {
51
40
  throw error;
52
41
  }
53
42
  }
54
43
  exec(`svn co ${info.distBranchDirURL} ${tmpdir}`);
55
44
  try {
56
- exec(`svn rm * --force -q`, {
57
- cwd: tmpdir
58
- });
59
- } catch (error) {}
45
+ exec(`svn rm * --force -q`, { cwd: tmpdir });
46
+ } catch (error) {
47
+ }
60
48
  fs.copySync(paths.dist, tmpdir);
61
- exec(`svn add * --force --auto-props --parents --depth infinity -q`, {
62
- cwd: tmpdir
63
- });
49
+ exec(`svn add * --force --auto-props --parents --depth infinity -q`, { cwd: tmpdir });
64
50
  const msg = `[edu-scripts] commit ${info.branch} dist #${info.revision} @${info.author}`;
65
- exec(`svn ci -m "${msg}"`, {
66
- cwd: tmpdir
67
- });
51
+ exec(`svn ci -m "${msg}"`, { cwd: tmpdir });
68
52
  fs.removeSync(tmpdir);
69
53
  }
70
-
71
- /**
72
- * svn commit dist folder to dish branches
73
- *
74
- * @param {Object} args
75
- * @param {boolean} args.rmLocal
76
- */
77
54
  module.exports = async function commitDist(args) {
78
55
  if (!fs.existsSync(paths.dist)) {
79
- console.log(chalk.red('未找到 dist 文件夹,请先 edu-scpirts build'));
56
+ console.log(chalk.red("未找到 dist 文件夹,请先 edu-scpirts build"));
80
57
  process.exit(1);
81
58
  }
82
- if (exec('svn st').trim().length) {
83
- console.log(chalk.red('似乎存在未提交的代码,请提交后重试。运行 svn st 查看具体信息'));
59
+ if (exec("svn st").trim().length) {
60
+ console.log(chalk.red("似乎存在未提交的代码,请提交后重试。运行 svn st 查看具体信息"));
84
61
  process.exit(1);
85
62
  }
86
63
  const info = getWorkingCopyInfo();
87
- console.log(chalk.green([`分支: ${info.branch}`, `版本: ${info.revision}`, `作者: ${info.author}`, `地址: ${info.distBranchDirURL}`].join('\n')));
64
+ console.log(
65
+ chalk.green(
66
+ [
67
+ `分支: ${info.branch}`,
68
+ `版本: ${info.revision}`,
69
+ `作者: ${info.author}`,
70
+ `地址: ${info.distBranchDirURL}`
71
+ ].join("\n")
72
+ )
73
+ );
88
74
  copyDistToRepo(info);
89
75
  if (args.rmLocal) {
90
76
  fs.removeSync(paths.dist);
91
77
  }
92
- console.log(chalk.green('提交完成'));
93
- };
78
+ console.log(chalk.green("提交完成"));
79
+ };
@@ -1,53 +1,55 @@
1
- "use strict";
2
-
3
- const getOverride = require('../utils/getOverride');
4
-
5
- /**
6
- * @typedef {Object} Opts
7
- * @property {string} [modules]
8
- *
9
- * @param {Opts} [opts]
10
- * @return {*}
11
- */
1
+ // src/config/babel.dependencies.js
2
+ var getOverride = require("../utils/getOverride");
12
3
  module.exports = function getBabelConfig(opts = {}) {
13
- const isDev = process.env.NODE_ENV === 'development';
4
+ const isDev = process.env.NODE_ENV === "development";
14
5
  let config = {
15
6
  cacheDirectory: true,
16
7
  cacheCompression: false,
17
8
  babelrc: false,
18
9
  configFile: false,
19
- sourceType: 'unambiguous',
10
+ sourceType: "unambiguous",
20
11
  compact: false,
21
12
  sourceMaps: isDev,
22
13
  inputSourceMap: isDev,
23
- presets: [['@babel/preset-env', {
24
- modules: opts.modules,
25
- useBuiltIns: 'entry',
26
- corejs: 3,
27
- // Exclude transforms that make all code slower
28
- exclude: ['transform-typeof-symbol']
29
- }]].filter(Boolean),
30
- plugins: [['@babel/plugin-transform-runtime', {
31
- corejs: false,
32
- helpers: true,
33
- // By default, babel assumes babel/runtime version 7.0.0-beta.0,
34
- // explicitly resolving to match the provided helper functions.
35
- // https://github.com/babel/babel/issues/10261
36
- version: require('@babel/runtime/package.json').version,
37
- regenerator: true
38
- // // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
39
- // // We should turn this on once the lowest version of Node LTS
40
- // // supports ES Modules.
41
- // useESModules: true,
42
- }], ['import', {
43
- libraryName: 'lodash',
44
- libraryDirectory: '',
45
- camel2DashComponentName: false
46
- }, 'lodash']].filter(Boolean)
14
+ presets: [
15
+ [
16
+ "@babel/preset-env",
17
+ {
18
+ modules: opts.modules,
19
+ useBuiltIns: "entry",
20
+ corejs: 3,
21
+ // Exclude transforms that make all code slower
22
+ exclude: ["transform-typeof-symbol"]
23
+ }
24
+ ]
25
+ ].filter(Boolean),
26
+ plugins: [
27
+ [
28
+ "@babel/plugin-transform-runtime",
29
+ {
30
+ corejs: false,
31
+ helpers: true,
32
+ // By default, babel assumes babel/runtime version 7.0.0-beta.0,
33
+ // explicitly resolving to match the provided helper functions.
34
+ // https://github.com/babel/babel/issues/10261
35
+ version: require("@babel/runtime/package.json").version,
36
+ regenerator: true
37
+ // // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
38
+ // // We should turn this on once the lowest version of Node LTS
39
+ // // supports ES Modules.
40
+ // useESModules: true,
41
+ }
42
+ ],
43
+ [
44
+ "import",
45
+ { libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
46
+ "lodash"
47
+ ]
48
+ ].filter(Boolean)
47
49
  };
48
50
  const override = getOverride();
49
51
  if (override.babel) {
50
- config = override.babel(config, 'node_modules') || config;
52
+ config = override.babel(config, "node_modules") || config;
51
53
  }
52
54
  return config;
53
- };
55
+ };
@@ -1,74 +1,101 @@
1
- "use strict";
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
+ ));
2
23
 
3
- const fs = require('fs');
4
- const paths = require('./paths');
5
- const appConfig = require('../utils/appConfig');
6
- const getOverride = require('../utils/getOverride');
7
- const hasJsxRuntime = (() => {
24
+ // src/config/babel.js
25
+ var fs = require("fs");
26
+ var paths = require("./paths");
27
+ var appConfig = require("../utils/appConfig");
28
+ var getOverride = require("../utils/getOverride");
29
+ var hasJsxRuntime = (() => {
8
30
  try {
9
- require.resolve('react/jsx-runtime');
10
- return true && appConfig.single;
31
+ require.resolve("react/jsx-runtime");
32
+ return appConfig.single;
11
33
  } catch (error) {
12
34
  return false;
13
35
  }
14
36
  })();
15
-
16
- /**
17
- * @typedef {Object} Opts
18
- * @property {string} [modules]
19
- *
20
- * @param {Opts} [opts]
21
- * @return {*}
22
- */
23
37
  module.exports = function getBabelConfig(opts = {}) {
24
38
  const isTypeScriptEnabled = fs.existsSync(paths.tsconfig);
25
- const isDev = process.env.NODE_ENV === 'development';
39
+ const isDev = process.env.NODE_ENV === "development";
26
40
  let config = {
27
41
  cacheDirectory: true,
28
42
  cacheCompression: false,
29
43
  compact: !isDev,
30
44
  babelrc: false,
31
45
  configFile: false,
32
- presets: [['@babel/preset-env', {
33
- modules: opts.modules,
34
- useBuiltIns: 'entry',
35
- corejs: 3,
36
- // Exclude transforms that make all code slower
37
- exclude: ['transform-typeof-symbol']
38
- }], ['@babel/preset-react', {
39
- development: isDev,
40
- runtime: hasJsxRuntime ? 'automatic' : 'classic',
41
- useBuiltIns: !hasJsxRuntime
42
- }], isTypeScriptEnabled && '@babel/preset-typescript'].filter(Boolean),
43
- plugins: [['@babel/plugin-transform-runtime', {
44
- corejs: false,
45
- helpers: true,
46
- // By default, babel assumes babel/runtime version 7.0.0-beta.0,
47
- // explicitly resolving to match the provided helper functions.
48
- // https://github.com/babel/babel/issues/10261
49
- version: require('@babel/runtime/package.json').version,
50
- regenerator: true
51
- // // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
52
- // // We should turn this on once the lowest version of Node LTS
53
- // // supports ES Modules.
54
- // useESModules: true,
55
- }], ['@babel/plugin-proposal-decorators', {
56
- legacy: true
57
- }], ['@babel/plugin-proposal-class-properties', {
58
- loose: true
59
- }], ['@babel/plugin-proposal-private-methods', {
60
- loose: true
61
- }], ['@babel/plugin-proposal-private-property-in-object', {
62
- loose: true
63
- }], ['import', {
64
- libraryName: 'lodash',
65
- libraryDirectory: '',
66
- camel2DashComponentName: false
67
- }, 'lodash'], isDev && 'react-refresh/babel'].filter(Boolean)
46
+ presets: [
47
+ [
48
+ "@babel/preset-env",
49
+ {
50
+ modules: opts.modules,
51
+ useBuiltIns: "entry",
52
+ corejs: 3,
53
+ // Exclude transforms that make all code slower
54
+ exclude: ["transform-typeof-symbol"]
55
+ }
56
+ ],
57
+ [
58
+ "@babel/preset-react",
59
+ {
60
+ development: isDev,
61
+ runtime: hasJsxRuntime ? "automatic" : "classic",
62
+ useBuiltIns: !hasJsxRuntime
63
+ }
64
+ ],
65
+ isTypeScriptEnabled && "@babel/preset-typescript"
66
+ ].filter(Boolean),
67
+ plugins: [
68
+ [
69
+ "@babel/plugin-transform-runtime",
70
+ {
71
+ corejs: false,
72
+ helpers: true,
73
+ // By default, babel assumes babel/runtime version 7.0.0-beta.0,
74
+ // explicitly resolving to match the provided helper functions.
75
+ // https://github.com/babel/babel/issues/10261
76
+ version: require("@babel/runtime/package.json").version,
77
+ regenerator: true
78
+ // // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
79
+ // // We should turn this on once the lowest version of Node LTS
80
+ // // supports ES Modules.
81
+ // useESModules: true,
82
+ }
83
+ ],
84
+ ["@babel/plugin-proposal-decorators", { legacy: true }],
85
+ ["@babel/plugin-proposal-class-properties", { loose: true }],
86
+ ["@babel/plugin-proposal-private-methods", { loose: true }],
87
+ ["@babel/plugin-proposal-private-property-in-object", { loose: true }],
88
+ [
89
+ "import",
90
+ { libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
91
+ "lodash"
92
+ ],
93
+ isDev && "react-refresh/babel"
94
+ ].filter(Boolean)
68
95
  };
69
96
  const override = getOverride();
70
97
  if (override.babel) {
71
- config = override.babel(config, 'src') || config;
98
+ config = override.babel(config, "src") || config;
72
99
  }
73
100
  return config;
74
- };
101
+ };
@@ -1,38 +1,36 @@
1
- "use strict";
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const glob = require('globby');
1
+ // src/config/paths.js
2
+ var path = require("path");
3
+ var fs = require("fs");
4
+ var glob = require("globby");
6
5
  function resolveApp(...filePath) {
7
6
  return path.resolve(process.cwd(), ...filePath);
8
7
  }
9
- function getExistPath(...paths) {
10
- for (const path of paths) {
11
- if (fs.existsSync(path)) {
12
- return path;
8
+ function getExistPath(...paths2) {
9
+ for (const path2 of paths2) {
10
+ if (fs.existsSync(path2)) {
11
+ return path2;
13
12
  }
14
13
  }
15
- return paths[0];
14
+ return paths2[0];
16
15
  }
17
- const paths = {
16
+ var paths = {
18
17
  resolveApp,
19
- eduAppEnv: resolveApp('src', 'edu-app-env.d.ts'),
20
- dist: resolveApp('dist'),
21
- sshSftp: resolveApp('.sftprc.json'),
22
- nodeModules: resolveApp('node_modules'),
23
- tsconfig: resolveApp('tsconfig.json'),
24
- jsconfig: resolveApp('jsconfig.json'),
25
- package: resolveApp('package.json'),
26
- tailwind: resolveApp('tailwind.config.js'),
27
- indexJS: resolveApp('src', 'index.js'),
28
- pages: resolveApp('src', 'pages'),
29
- override: resolveApp('edu-scripts.override.js'),
30
- indexHTML: glob.sync('./public/*.html', {
31
- absolute: true
32
- }),
33
- src: resolveApp('src'),
34
- public: resolveApp('public'),
35
- static: resolveApp('public', 'static'),
36
- theme: getExistPath(resolveApp('theme.json'), resolveApp('theme.js'))
18
+ eduAppEnv: resolveApp("src", "edu-app-env.d.ts"),
19
+ dist: resolveApp("dist"),
20
+ sshSftp: resolveApp(".sftprc.json"),
21
+ nodeModules: resolveApp("node_modules"),
22
+ tsconfig: resolveApp("tsconfig.json"),
23
+ jsconfig: resolveApp("jsconfig.json"),
24
+ package: resolveApp("package.json"),
25
+ tailwind: resolveApp("tailwind.config.js"),
26
+ indexJS: resolveApp("src", "index.js"),
27
+ pages: resolveApp("src", "pages"),
28
+ override: resolveApp("edu-scripts.override.js"),
29
+ indexHTML: glob.sync("./public/*.html", { absolute: true }),
30
+ src: resolveApp("src"),
31
+ public: resolveApp("public"),
32
+ static: resolveApp("public", "static"),
33
+ theme: getExistPath(resolveApp("theme.json"), resolveApp("theme.js")),
34
+ mock: resolveApp("mock")
37
35
  };
38
- module.exports = paths;
36
+ module.exports = paths;
@@ -0,0 +1,6 @@
1
+ import type { RequestHandler } from 'express';
2
+ type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
3
+ type API = string;
4
+ export type MockConfig = Record<`${Method} ${API}`, string | number | null | undefined | boolean | Record<string, any> | RequestHandler>;
5
+ export declare function defineMock(config: MockConfig): MockConfig;
6
+ export {};
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/config/plugins/mock-server/defineMock.ts
20
+ var defineMock_exports = {};
21
+ __export(defineMock_exports, {
22
+ defineMock: () => defineMock
23
+ });
24
+ module.exports = __toCommonJS(defineMock_exports);
25
+ function defineMock(config) {
26
+ return config;
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ defineMock
31
+ });
@@ -0,0 +1,69 @@
1
+ // src/config/plugins/mock-server/index.js
2
+ var paths = require("../../paths");
3
+ var globby = require("globby");
4
+ var chokidar = require("chokidar");
5
+ var debounce = require("lodash/debounce");
6
+ var chalk = require("chalk");
7
+ var fs = require("fs-extra");
8
+ var express = require("express");
9
+ var cookieParser = require("cookie-parser");
10
+ var mockCache = {};
11
+ var isSetup = false;
12
+ var setupMock = debounce(function setupMock2() {
13
+ mockCache = {};
14
+ const files = globby.sync(paths.mock);
15
+ if (isSetup) {
16
+ console.log(chalk.green("Mock files changed, reloaded"));
17
+ } else {
18
+ isSetup = true;
19
+ }
20
+ for (const file of files) {
21
+ delete require.cache[require.resolve(file)];
22
+ try {
23
+ let mock = require(file);
24
+ mock = mock.default || mock;
25
+ mockCache = { ...mockCache, ...mock };
26
+ } catch (e) {
27
+ console.error(chalk.red(`Mock file ${file} error: ${e.message}`));
28
+ }
29
+ }
30
+ console.log("🚀 ~ file: index.js:47 ~ setupMock ~ mockCache:", mockCache);
31
+ }, 100);
32
+ function mockMiddlewave(req, res, next) {
33
+ const { method, path } = req;
34
+ const key = `${method.toUpperCase()} ${path}`;
35
+ const mock = mockCache[key];
36
+ console.log(chalk.green(`Mock: ${key}`));
37
+ if (mock) {
38
+ if (typeof mock === "function") {
39
+ mock(req, res, next);
40
+ } else {
41
+ res.json(mock);
42
+ }
43
+ } else {
44
+ next();
45
+ }
46
+ }
47
+ function setupMockServer(middelwaves, devServer) {
48
+ if (!fs.existsSync(paths.mock))
49
+ return;
50
+ require("@babel/register")({
51
+ presets: [["@babel/preset-env", { modules: "cjs" }], "@babel/preset-typescript"],
52
+ babelrc: false,
53
+ only: [/\/mock\//, /\/src\//],
54
+ extensions: [".js", ".ts"]
55
+ });
56
+ devServer.app.use(express.urlencoded({ extended: false }));
57
+ devServer.app.use(express.json());
58
+ devServer.app.use(cookieParser());
59
+ middelwaves.unshift({
60
+ name: "edu-scripts-mock-middelwave",
61
+ middleware: mockMiddlewave
62
+ });
63
+ console.log(
64
+ `<i> ${chalk.green.bold("[edu-scripts] Mock server created:")} ${chalk.cyan.bold(paths.mock)}`
65
+ );
66
+ chokidar.watch(paths.mock).on("all", setupMock);
67
+ return middelwaves;
68
+ }
69
+ module.exports = setupMockServer;
@@ -1,19 +1,19 @@
1
- "use strict";
2
-
3
- const vars = ['safe-area-inset-top', 'safe-area-inset-bottom', 'safe-area-inset-left', 'safe-area-inset-right'];
4
- const expr = new RegExp(`env\\(\\s*(${vars.join('|')})\\s*,?\\s*([^)]+)?\\s*\\)`, 'g');
5
-
6
- /** @type {import('postcss').PluginCreator} */
1
+ // src/config/plugins/postcss-safe-area.js
2
+ var vars = [
3
+ "safe-area-inset-top",
4
+ "safe-area-inset-bottom",
5
+ "safe-area-inset-left",
6
+ "safe-area-inset-right"
7
+ ];
8
+ var expr = new RegExp(`env\\(\\s*(${vars.join("|")})\\s*,?\\s*([^)]+)?\\s*\\)`, "g");
7
9
  module.exports = () => {
8
10
  return {
9
- postcssPlugin: 'postcss-safe-area',
11
+ postcssPlugin: "postcss-safe-area",
10
12
  Declaration(decl) {
11
- const fallback = decl.value.replace(expr, (match, param, defaultValue) => defaultValue || '0');
13
+ const fallback = decl.value.replace(expr, (match, param, defaultValue) => defaultValue || "0");
12
14
  if (fallback !== decl.value) {
13
- decl.cloneBefore({
14
- value: fallback
15
- });
15
+ decl.cloneBefore({ value: fallback });
16
16
  }
17
17
  }
18
18
  };
19
- };
19
+ };