@infly/libs 2.0.43 → 2.0.44

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 (56) hide show
  1. package/README.md +92 -67
  2. package/adapters/vue2/build/webpack5/inline-runtime-plugin.js +35 -0
  3. package/adapters/vue2/build/webpack5/remove-legacy-assets-plugin.js +84 -0
  4. package/adapters/vue2/build/webpack5/webpack.base.js +437 -0
  5. package/adapters/vue2/module/Permission.js +204 -0
  6. package/adapters/vue2/postinstall.js +46 -0
  7. package/adapters/vue2/project-preview.js +148 -0
  8. package/adapters/vue2/script-config.js +26 -0
  9. package/adapters/vue2/store/index.js +1 -0
  10. package/adapters/vue2/store/modules/user.js +268 -0
  11. package/bin/cli.js +71 -71
  12. package/build/build-dist/index.js +863 -863
  13. package/build/build-dist/script-management.js +5 -5
  14. package/build/docker/compose-command.js +74 -74
  15. package/build/docker/compose-release.js +91 -91
  16. package/build/webpack5/inline-runtime-plugin.js +1 -35
  17. package/build/webpack5/remove-legacy-assets-plugin.js +1 -84
  18. package/build/webpack5/webpack.base.js +1 -435
  19. package/compat/init.js +9 -0
  20. package/index.js +8 -20
  21. package/module/Permission.js +1 -204
  22. package/module/REST.js +31 -19
  23. package/module/TokenService.js +9 -0
  24. package/module/Uts.js +460 -7252
  25. package/module/cjs/request-url-rules.cjs +6 -0
  26. package/module/cjs/rest-error-rules.cjs +33 -0
  27. package/package.json +121 -92
  28. package/script/build/deps.js +1 -1
  29. package/script/build/webhook.js +3 -2
  30. package/script/git-automation/git-clone.js +3 -4
  31. package/script/git-automation/index.js +2 -2
  32. package/script/index.js +1 -26
  33. package/script/webhook/webhook.js +7 -2
  34. package/store/index.js +1 -0
  35. package/store/modules/user.js +1 -268
  36. package/tools/auto-export.js +1 -2
  37. package/tools/file-export.js +6 -4
  38. package/tools/project-command.js +194 -194
  39. package/tools/project-preview.js +1 -148
  40. package/tools/select-option.js +60 -60
  41. package/.prettierrc +0 -5
  42. package/build/build-dist/script-management.test.js +0 -16
  43. package/build/docker/compose-command.test.js +0 -148
  44. package/build/docker/compose-release.test.js +0 -101
  45. package/build/docker/docker-build-push.test.js +0 -124
  46. package/build/webpack5/webpack.base.test.js +0 -59
  47. package/lib/index.js +0 -6
  48. package/lib/server/connect.js +0 -3011
  49. package/lib/server/serve-static.js +0 -4848
  50. package/script/pts/cloud-scenes.mjs +0 -65
  51. package/script/pts/cloud.js +0 -151
  52. package/script/pts/generate-cloud-params.mjs +0 -210
  53. package/script/pts/generate-cloud-params.test.mjs +0 -67
  54. package/tools/project-command.test.js +0 -267
  55. package/tools/select-option.test.js +0 -52
  56. package/webpack.config.js +0 -38
package/README.md CHANGED
@@ -1,35 +1,48 @@
1
- # npm-package
1
+ # @infly/libs
2
2
 
3
3
  ## 介绍
4
4
 
5
- 基础库
5
+ `@infly/libs` 是不受 Vue、React 等前端框架限制的独立 JavaScript 工具库。包根入口无副作用;HTTP、Token、文件处理、Docker/Compose、通用项目命令等能力可被不同技术栈使用。
6
+
7
+ Vue 2 专属的 Permission、Vuex store、Vue CLI 预览和 webpack 配置集中在 `adapters/vue2/`,避免核心入口依赖 Vue 项目约定。
6
8
 
7
9
  ## 注意事项
8
10
 
9
- 如需使用第三方库,推荐使用 webpack 进行打包,放入 lib/中使用
11
+ 新代码应显式导入 Vue 2 适配路径。原有 `module/Permission.js`、`store/`、`tools/project-preview.js`、`script/index.js` 和 `build/webpack5/` 路径继续作为兼容转发保留。
10
12
 
11
13
  ## 软件架构
12
14
 
13
- @infly/libs
14
- ├── bin - 脚本文件暴露为可直接调用的命令
15
- └── cli.js - 命令入口调用方法判断
16
- ├── build - 构建相关工具库
17
- └── build-dist - 项目构建
18
- └───── zip.js - 压缩构建文件
19
- └───── index.js - 构建入口
20
- └── webpack5 - 构建配置封装
21
- ├── dataInit - 公共枚举
22
- ├── lib - 第三方库
23
- ├── module - 模块
24
- ├── script - 脚本模块
25
- └── git-automation - git自动化
26
- └── webhook - 机器人推送
27
- ├── store - 公共 vuex 模块
28
- ├── tools - 小工具类型方法
29
- ├── types - ts 类型说明
30
- ├── index.js - npm 包初始文件
31
- ├── package.json - npm 包管理配置, 正常无需 npm install 当前项目的依赖
32
- ├── webpack.config.js - webpack 配置实现打包第三方库减小体积
15
+ ```text
16
+ @infly/libs
17
+ ├── index.js # 框架无关、无副作用的包根入口
18
+ ├── module/ # HTTP、Token、格式化等通用模块
19
+ ├── tools/ # 文件与项目命令等通用工具
20
+ ├── build/
21
+ ├── docker/ # Docker/Compose 工具
22
+ ├── build-dist/ # 构建产物处理
23
+ ├── build/webpack5/ # Vue 2 webpack 真实实现
24
+ │ └── webpack5/ # 原路径兼容转发
25
+ ├── adapters/vue2/
26
+ ├── module/Permission.js # Vue Router/Vuex 权限适配
27
+ ├── store/ # Vuex 模块
28
+ ├── project-preview.js # Vue CLI 预览
29
+ ├── script-config.js # Vue CLI 脚本模板
30
+ │ └── postinstall.js # Vue 2 项目执行初始化
31
+ ├── bin/cli.js # 命令行入口
32
+ └── dataInit/ # 公共枚举
33
+ ```
34
+
35
+ 根入口加载示例:
36
+
37
+ ```javascript
38
+ const inflyLibs = require('@infly/libs');
39
+ ```
40
+
41
+ 根入口继续保留历史 `init()` API,但只在显式调用时懒加载 Vue 2 适配器,不会在 `require('@infly/libs')` 时自动执行:
42
+
43
+ ```javascript
44
+ inflyLibs.init();
45
+ ```
33
46
 
34
47
  ## 安装教程
35
48
 
@@ -49,57 +62,69 @@ infly-libs build:docker --local --env prod
49
62
  可通过可选参数 `--cicd-url` 在构建和镜像推送全部成功后输出蓝色发布系统链接。支持等号和空格两种传参形式:
50
63
 
51
64
  ```bash
52
- infly-libs build:docker --local --cicd-url="https://cicd.sutpay.com/view/积分商城/"
65
+ infly-libs build:docker --local --cicd-url="https://deploy.example.com/projects/admin/"
53
66
  ```
54
67
 
55
68
  ```bash
56
- infly-libs build:docker --local --cicd-url "https://cicd.sutpay.com/view/积分商城/"
69
+ infly-libs build:docker --local --cicd-url "https://deploy.example.com/projects/admin/"
57
70
  ```
58
71
 
59
72
  未传 `--cicd-url` 时保持原有输出。参数值必须是合法的 HTTP/HTTPS URL,且不能包含用户名、密码或控制字符。
60
73
 
61
- ## 配置驱动的项目命令
62
-
63
- `project` 命令将多平台项目的开发和构建目标从 package scripts 移到项目配置:
64
-
65
- ```bash
66
- infly-libs project
67
- infly-libs project dev
68
- infly-libs project build
69
- ```
70
-
71
- 命令从当前目录 `package.json` 的 `infly.targets`、`infly.dev` 和 `infly.build` 读取配置。交互选择会追加“退出”选项;选择退出或按取消键时会正常结束,不执行后续命令。项目命令不支持 `--config` 文件入口。
72
-
73
- 未指定 action、target 或构建环境时,会在 TTY 中显示单选菜单。CI/CD 必须显式传参:
74
-
75
- ```bash
76
- infly-libs project dev --target QDXY
77
- infly-libs project build --env stage --target SQ223
78
- ```
79
-
80
- `--dry-run` 只打印带 `VUE_APP_PLATFORM` 的命令计划。`infly.targets` 推荐使用平台代码数组,例如 `["DEFAULT", "MER", "JXEE"]`;同时兼容对象形式,对象值中的 `label` 只用于交互显示。普通 target 就是注入 `VUE_APP_PLATFORM` 的平台代码,批量构建通过 `build.presets` 组合多个 target。
81
-
82
- `dev.command` 以及 `build.before/command/after` 同时支持字符串和参数数组。字符串按空白拆分为可执行文件和参数,不经过 shell;参数本身包含空格时应继续使用数组形式。
83
-
74
+ ## HTTP 环境保护配置
75
+
76
+ `module/REST.js` 不内置任何项目域名。应用如需在测试环境误连正式接口时告警,应由应用显式注入完整的正式 API 基地址:
77
+
78
+ ```javascript
79
+ const service = createService({
80
+ productionBaseURLs: ["https://api.example.com"]
81
+ });
82
+ ```
83
+
84
+ 未传 `productionBaseURLs` 时不启用该项目级域名判断。
85
+
86
+ ## 配置驱动的项目命令
87
+
88
+ `project` 命令将多平台项目的开发和构建目标从 package scripts 移到项目配置:
89
+
90
+ ```bash
91
+ infly-libs project
92
+ infly-libs project dev
93
+ infly-libs project build
94
+ ```
95
+
96
+ 命令从当前目录 `package.json` 的 `infly.targets`、`infly.dev` 和 `infly.build` 读取配置。交互选择会追加“退出”选项;选择退出或按取消键时会正常结束,不执行后续命令。项目命令不支持 `--config` 文件入口。
97
+
98
+ 未指定 action、target 或构建环境时,会在 TTY 中显示单选菜单。CI/CD 必须显式传参:
99
+
100
+ ```bash
101
+ infly-libs project dev --target QDXY
102
+ infly-libs project build --env stage --target SQ223
103
+ ```
104
+
105
+ `--dry-run` 只打印带 `VUE_APP_PLATFORM` 的命令计划。`infly.targets` 推荐使用平台代码数组,例如 `["DEFAULT", "MER", "JXEE"]`;同时兼容对象形式,对象值中的 `label` 只用于交互显示。普通 target 就是注入 `VUE_APP_PLATFORM` 的平台代码,批量构建通过 `build.presets` 组合多个 target。
106
+
107
+ `dev.command` 以及 `build.before/command/after` 同时支持字符串和参数数组。字符串按空白拆分为可执行文件和参数,不经过 shell;参数本身包含空格时应继续使用数组形式。
108
+
84
109
  `build.environments` 推荐使用 `选择键:实际 mode` 数组,例如 `["prod:production", "stage:staging"]`;CLI 使用冒号前的值进行选择,并把冒号后的值作为 `--mode` 参数。没有冒号时选择键和 mode 同名。对象形式继续兼容,用于自定义 `label`、`mode` 或 `args`。项目如果自行管理构建入口,应设置 `infly.buildConfigs.manageScripts=false`,避免安装阶段重新写入传统 `build:prod/build:stage`。
85
110
 
86
- ### Docker Compose 版本发布
87
-
88
- `docker:compose` 面向已有 Compose 文件的镜像版本递增、配置校验和构建,与上面的 Dockerfile/commit-tag `build:docker` 流程互不替代:
89
-
90
- ```bash
91
- infly-libs docker:compose --target yhqy --bump patch
92
- ```
93
-
94
- 默认从当前目录 `package.json` 的 `infly.docker.targets` 读取目标,并以该 package 所在目录解析 Compose 相对路径;省略 `--target` 时在 TTY 中交互选择。`--config` 外部 JS 配置和原有 `--project-dir` + `--file` 直传方式继续兼容。
95
-
96
- 参数约束:
97
-
98
- - `--target`:选择 `infly.docker.targets` 或外部配置中的目标;非交互环境必须显式传入。
99
- - `--config`:可选的外部 JS 配置文件,使用 `targets.<name>.file` 结构。
100
- - `--project-dir` + `--file`:不使用 target 配置时的兼容直传方式,Compose 文件不能越出 `project-dir`。
101
- - `--bump patch`:目前只支持 patch 递增,且 Compose 中必须恰好有一个 `x.y.z` 镜像 tag。
102
- - `--push`:显式推送;未传时只执行 `docker compose config` 和 `build`。
103
- - `--dry-run`:只打印版本变化和计划命令,不写文件、不调用 Docker。
104
-
111
+ ### Docker Compose 版本发布
112
+
113
+ `docker:compose` 面向已有 Compose 文件的镜像版本递增、配置校验和构建,与上面的 Dockerfile/commit-tag `build:docker` 流程互不替代:
114
+
115
+ ```bash
116
+ infly-libs docker:compose --target yhqy --bump patch
117
+ ```
118
+
119
+ 默认从当前目录 `package.json` 的 `infly.docker.targets` 读取目标,并以该 package 所在目录解析 Compose 相对路径;省略 `--target` 时在 TTY 中交互选择。`--config` 外部 JS 配置和原有 `--project-dir` + `--file` 直传方式继续兼容。
120
+
121
+ 参数约束:
122
+
123
+ - `--target`:选择 `infly.docker.targets` 或外部配置中的目标;非交互环境必须显式传入。
124
+ - `--config`:可选的外部 JS 配置文件,使用 `targets.<name>.file` 结构。
125
+ - `--project-dir` + `--file`:不使用 target 配置时的兼容直传方式,Compose 文件不能越出 `project-dir`。
126
+ - `--bump patch`:目前只支持 patch 递增,且 Compose 中必须恰好有一个 `x.y.z` 镜像 tag。
127
+ - `--push`:显式推送;未传时只执行 `docker compose config` 和 `build`。
128
+ - `--dry-run`:只打印版本变化和计划命令,不写文件、不调用 Docker。
129
+
105
130
  构建、校验或推送失败时,命令会恢复原 Compose 内容。公共包不内置 yhqy、qdxy 等业务目标映射;目标配置和单一发布 script 应归 Compose 所在项目所有。
@@ -0,0 +1,35 @@
1
+ // build/InlineRuntimePlugin.js
2
+ class InlineRuntimePlugin {
3
+ apply(compiler) {
4
+ compiler.hooks.compilation.tap("InlineRuntimePlugin", (compilation) => {
5
+ const HtmlWebpackPlugin = compiler.options.plugins.find(
6
+ (plugin) => plugin.constructor && plugin.constructor.name === "HtmlWebpackPlugin"
7
+ )?.constructor;
8
+
9
+ if (!HtmlWebpackPlugin) return;
10
+
11
+ HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tap("InlineRuntimePlugin", (assets) => {
12
+ assets.headTags = this.inlineRuntime(assets.headTags, compilation.assets);
13
+ assets.bodyTags = this.inlineRuntime(assets.bodyTags, compilation.assets);
14
+ });
15
+ });
16
+ }
17
+
18
+ inlineRuntime(tags, assets) {
19
+ return tags.map((tag) => {
20
+ if (tag.tagName === "script" && tag.attributes?.src && /runtime\..*\.js$/.test(tag.attributes.src)) {
21
+ const filename = tag.attributes.src.replace(/^\//, "");
22
+ if (assets[filename]) {
23
+ return {
24
+ tagName: "script",
25
+ innerHTML: assets[filename].source(),
26
+ closeTag: true
27
+ };
28
+ }
29
+ }
30
+ return tag;
31
+ });
32
+ }
33
+ }
34
+
35
+ module.exports = InlineRuntimePlugin;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * RemoveLegacyAssetsPlugin
3
+ * 用于处理 Vue CLI Modern Mode 的 legacy 文件问题
4
+ *
5
+ * 功能:
6
+ * 1. 在构建前创建占位文件,防止 ModernModePlugin 读取时报错
7
+ * 2. 在构建时删除 legacy 相关的资源
8
+ * 3. 在构建完成后清理占位文件
9
+ */
10
+
11
+ "use strict";
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+
16
+ class RemoveLegacyAssetsPlugin {
17
+ constructor(options = {}) {
18
+ this.options = {
19
+ legacyFiles: [
20
+ 'legacy-assets-index.html.json',
21
+ 'modern-assets-index.html.json'
22
+ ],
23
+ ...options
24
+ };
25
+ }
26
+
27
+ apply(compiler) {
28
+ const outputPath = compiler.options.output.path;
29
+ const { legacyFiles } = this.options;
30
+
31
+ // 🔥 Hook 1: 构建开始前创建占位文件
32
+ compiler.hooks.beforeRun.tapAsync('RemoveLegacyAssetsPlugin', (compiler, callback) => {
33
+ // 确保输出目录存在
34
+ if (!fs.existsSync(outputPath)) {
35
+ fs.mkdirSync(outputPath, { recursive: true });
36
+ }
37
+
38
+ // 创建空数组的 JSON 文件(Vue CLI 期望数组格式)
39
+ legacyFiles.forEach(file => {
40
+ const filePath = path.join(outputPath, file);
41
+ try {
42
+ fs.writeFileSync(filePath, '[]');
43
+ } catch (err) {
44
+ // 忽略创建失败的错误
45
+ console.warn(`⚠ Failed to create placeholder: ${file}`, err.message);
46
+ }
47
+ });
48
+
49
+ callback();
50
+ });
51
+
52
+ // 🔥 Hook 2: 构建时删除编译产物中的 legacy 资源
53
+ compiler.hooks.emit.tapAsync('RemoveLegacyAssetsPlugin', (compilation, callback) => {
54
+ Object.keys(compilation.assets).forEach(filename => {
55
+ if (filename.includes('-legacy') || filename.includes('legacy-assets')) {
56
+ delete compilation.assets[filename];
57
+ }
58
+ });
59
+ callback();
60
+ });
61
+
62
+ // 🔥 Hook 3: 构建完成后清理占位文件
63
+ compiler.hooks.done.tapAsync('RemoveLegacyAssetsPlugin', (stats, callback) => {
64
+ // 延迟执行,确保所有读取操作完成
65
+ setTimeout(() => {
66
+ legacyFiles.forEach(file => {
67
+ const filePath = path.join(outputPath, file);
68
+ try {
69
+ if (fs.existsSync(filePath)) {
70
+ fs.unlinkSync(filePath);
71
+ console.log(`\x1b[32m✓ Cleaned up: ${file}\x1b[0m`);
72
+ }
73
+ } catch (err) {
74
+ // 忽略删除失败的错误
75
+ console.warn(`⚠ Failed to cleanup: ${file}`, err.message);
76
+ }
77
+ });
78
+ callback();
79
+ }, 100);
80
+ });
81
+ }
82
+ }
83
+
84
+ module.exports = RemoveLegacyAssetsPlugin;