@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
@@ -1,5 +1,5 @@
1
- function shouldManageBuildScripts(inflyConfig) {
2
- return inflyConfig?.buildConfigs?.manageScripts !== false;
3
- }
4
-
5
- module.exports = { shouldManageBuildScripts };
1
+ function shouldManageBuildScripts(inflyConfig) {
2
+ return inflyConfig?.buildConfigs?.manageScripts !== false;
3
+ }
4
+
5
+ module.exports = { shouldManageBuildScripts };
@@ -1,74 +1,74 @@
1
- const fs = require("node:fs");
2
- const path = require("node:path");
3
-
4
- const {
5
- EXIT_SELECTION,
6
- selectOption: defaultSelectOption,
7
- } = require("../../tools/select-option");
8
- const { composeRelease: defaultComposeRelease } = require("./compose-release");
9
-
10
- function loadTargetConfig(configPath) {
11
- const resolvedPath = path.resolve(configPath);
12
- delete require.cache[require.resolve(resolvedPath)];
13
- return {
14
- config: require(resolvedPath),
15
- configDir: path.dirname(resolvedPath),
16
- };
17
- }
18
-
19
- function loadPackageTargetConfig(cwd = process.cwd()) {
20
- const packagePath = path.resolve(cwd, "package.json");
21
- if (!fs.existsSync(packagePath)) {
22
- throw new Error(`Package config not found: ${packagePath}`);
23
- }
24
- delete require.cache[require.resolve(packagePath)];
25
- const packageJson = require(packagePath);
26
- return {
27
- config: packageJson.infly?.docker,
28
- configDir: path.dirname(packagePath),
29
- };
30
- }
31
-
32
- async function runComposeCommand(options = {}, dependencies = {}) {
33
- const composeRelease = dependencies.composeRelease || defaultComposeRelease;
34
- const usesDirectConfig = !options.config
35
- && !options.configObject
36
- && (options.projectDir || options.file);
37
- if (usesDirectConfig) return composeRelease(options);
38
-
39
- const loaded = options.config
40
- ? loadTargetConfig(options.config)
41
- : options.configObject
42
- ? { config: options.configObject, configDir: options.configDir || process.cwd() }
43
- : loadPackageTargetConfig(options.cwd || process.cwd());
44
- const targets = loaded.config?.targets;
45
- if (!targets || Object.keys(targets).length === 0) {
46
- throw new Error("Docker target config must define at least one target.");
47
- }
48
-
49
- const selectOption = dependencies.selectOption || defaultSelectOption;
50
- const log = dependencies.log || console.log;
51
- const targetName = options.target || await selectOption(
52
- "请选择 Docker 发布目标",
53
- Object.entries(targets).map(([value, target]) => ({
54
- value,
55
- label: target.label || value,
56
- })),
57
- );
58
- if (targetName === EXIT_SELECTION) {
59
- log("已退出,未执行任何操作。");
60
- return { cancelled: true };
61
- }
62
- const target = targets[targetName];
63
- if (!target) throw new Error(`Unknown Docker target: ${targetName}`);
64
-
65
- return composeRelease({
66
- projectDir: loaded.configDir,
67
- file: target.file,
68
- bump: options.bump || "patch",
69
- push: Boolean(options.push),
70
- dryRun: Boolean(options.dryRun),
71
- });
72
- }
73
-
74
- module.exports = { loadPackageTargetConfig, loadTargetConfig, runComposeCommand };
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+
4
+ const {
5
+ EXIT_SELECTION,
6
+ selectOption: defaultSelectOption,
7
+ } = require("../../tools/select-option");
8
+ const { composeRelease: defaultComposeRelease } = require("./compose-release");
9
+
10
+ function loadTargetConfig(configPath) {
11
+ const resolvedPath = path.resolve(configPath);
12
+ delete require.cache[require.resolve(resolvedPath)];
13
+ return {
14
+ config: require(resolvedPath),
15
+ configDir: path.dirname(resolvedPath),
16
+ };
17
+ }
18
+
19
+ function loadPackageTargetConfig(cwd = process.cwd()) {
20
+ const packagePath = path.resolve(cwd, "package.json");
21
+ if (!fs.existsSync(packagePath)) {
22
+ throw new Error(`Package config not found: ${packagePath}`);
23
+ }
24
+ delete require.cache[require.resolve(packagePath)];
25
+ const packageJson = require(packagePath);
26
+ return {
27
+ config: packageJson.infly?.docker,
28
+ configDir: path.dirname(packagePath),
29
+ };
30
+ }
31
+
32
+ async function runComposeCommand(options = {}, dependencies = {}) {
33
+ const composeRelease = dependencies.composeRelease || defaultComposeRelease;
34
+ const usesDirectConfig = !options.config
35
+ && !options.configObject
36
+ && (options.projectDir || options.file);
37
+ if (usesDirectConfig) return composeRelease(options);
38
+
39
+ const loaded = options.config
40
+ ? loadTargetConfig(options.config)
41
+ : options.configObject
42
+ ? { config: options.configObject, configDir: options.configDir || process.cwd() }
43
+ : loadPackageTargetConfig(options.cwd || process.cwd());
44
+ const targets = loaded.config?.targets;
45
+ if (!targets || Object.keys(targets).length === 0) {
46
+ throw new Error("Docker target config must define at least one target.");
47
+ }
48
+
49
+ const selectOption = dependencies.selectOption || defaultSelectOption;
50
+ const log = dependencies.log || console.log;
51
+ const targetName = options.target || await selectOption(
52
+ "请选择 Docker 发布目标",
53
+ Object.entries(targets).map(([value, target]) => ({
54
+ value,
55
+ label: target.label || value,
56
+ })),
57
+ );
58
+ if (targetName === EXIT_SELECTION) {
59
+ log("已退出,未执行任何操作。");
60
+ return { cancelled: true };
61
+ }
62
+ const target = targets[targetName];
63
+ if (!target) throw new Error(`Unknown Docker target: ${targetName}`);
64
+
65
+ return composeRelease({
66
+ projectDir: loaded.configDir,
67
+ file: target.file,
68
+ bump: options.bump || "patch",
69
+ push: Boolean(options.push),
70
+ dryRun: Boolean(options.dryRun),
71
+ });
72
+ }
73
+
74
+ module.exports = { loadPackageTargetConfig, loadTargetConfig, runComposeCommand };
@@ -1,91 +1,91 @@
1
- const { execFileSync } = require("node:child_process");
2
- const fs = require("node:fs");
3
- const path = require("node:path");
4
-
5
- function bumpComposeImageVersion(content, bump = "patch") {
6
- if (bump !== "patch") {
7
- throw new Error(`Unsupported version bump: ${bump}. Only patch is supported.`);
8
- }
9
-
10
- const imageRegex = /^(\s*image:\s*)([^\s#]+):(\d+)\.(\d+)\.(\d+)(\s*(?:#.*)?)$/gm;
11
- const matches = [...content.matchAll(imageRegex)];
12
-
13
- if (matches.length !== 1) {
14
- throw new Error(`Compose file must contain exactly one versioned image; found ${matches.length}.`);
15
- }
16
-
17
- const [, prefix, image, major, minor, patchVersion, suffix] = matches[0];
18
- const from = `${image}:${major}.${minor}.${patchVersion}`;
19
- const to = `${image}:${major}.${minor}.${Number(patchVersion) + 1}`;
20
- const replacement = `${prefix}${to}${suffix}`;
21
-
22
- return {
23
- content: content.replace(imageRegex, replacement),
24
- from,
25
- to,
26
- };
27
- }
28
-
29
- function resolveComposePath(projectDir, file) {
30
- if (!projectDir) throw new Error("--project-dir is required.");
31
- if (!file) throw new Error("--file is required.");
32
-
33
- const resolvedProjectDir = path.resolve(projectDir);
34
- const composePath = path.resolve(resolvedProjectDir, file);
35
- const relative = path.relative(resolvedProjectDir, composePath);
36
-
37
- if (relative.startsWith("..") || path.isAbsolute(relative)) {
38
- throw new Error("Compose file must be inside project-dir.");
39
- }
40
- if (!fs.existsSync(composePath)) {
41
- throw new Error(`Compose file not found: ${composePath}`);
42
- }
43
-
44
- return { projectDir: resolvedProjectDir, composePath };
45
- }
46
-
47
- function defaultRunDocker(args, options) {
48
- execFileSync("docker", args, { cwd: options.cwd, stdio: "inherit" });
49
- }
50
-
51
- function composeRelease(options = {}, dependencies = {}) {
52
- const {
53
- projectDir,
54
- file,
55
- bump = "patch",
56
- push = false,
57
- dryRun = false,
58
- } = options;
59
- const runDocker = dependencies.runDocker || defaultRunDocker;
60
- const resolved = resolveComposePath(projectDir, file);
61
- const original = fs.readFileSync(resolved.composePath, "utf8");
62
- const updated = bumpComposeImageVersion(original, bump);
63
- const baseArgs = ["compose", "-f", resolved.composePath];
64
-
65
- console.log(`Version update: ${updated.from} -> ${updated.to}`);
66
-
67
- if (dryRun) {
68
- console.log(`[dry-run] docker ${[...baseArgs, "config"].join(" ")}`);
69
- console.log(`[dry-run] docker ${[...baseArgs, "build"].join(" ")}`);
70
- if (push) console.log(`[dry-run] docker ${[...baseArgs, "push"].join(" ")}`);
71
- return { ...updated, projectDir: resolved.projectDir, composePath: resolved.composePath };
72
- }
73
-
74
- fs.writeFileSync(resolved.composePath, updated.content, "utf8");
75
- try {
76
- runDocker([...baseArgs, "config"], { cwd: resolved.projectDir });
77
- runDocker([...baseArgs, "build"], { cwd: resolved.projectDir });
78
- if (push) runDocker([...baseArgs, "push"], { cwd: resolved.projectDir });
79
- } catch (error) {
80
- fs.writeFileSync(resolved.composePath, original, "utf8");
81
- throw error;
82
- }
83
-
84
- return { ...updated, projectDir: resolved.projectDir, composePath: resolved.composePath };
85
- }
86
-
87
- module.exports = {
88
- bumpComposeImageVersion,
89
- composeRelease,
90
- resolveComposePath,
91
- };
1
+ const { execFileSync } = require("node:child_process");
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+
5
+ function bumpComposeImageVersion(content, bump = "patch") {
6
+ if (bump !== "patch") {
7
+ throw new Error(`Unsupported version bump: ${bump}. Only patch is supported.`);
8
+ }
9
+
10
+ const imageRegex = /^(\s*image:\s*)([^\s#]+):(\d+)\.(\d+)\.(\d+)(\s*(?:#.*)?)$/gm;
11
+ const matches = [...content.matchAll(imageRegex)];
12
+
13
+ if (matches.length !== 1) {
14
+ throw new Error(`Compose file must contain exactly one versioned image; found ${matches.length}.`);
15
+ }
16
+
17
+ const [, prefix, image, major, minor, patchVersion, suffix] = matches[0];
18
+ const from = `${image}:${major}.${minor}.${patchVersion}`;
19
+ const to = `${image}:${major}.${minor}.${Number(patchVersion) + 1}`;
20
+ const replacement = `${prefix}${to}${suffix}`;
21
+
22
+ return {
23
+ content: content.replace(imageRegex, replacement),
24
+ from,
25
+ to,
26
+ };
27
+ }
28
+
29
+ function resolveComposePath(projectDir, file) {
30
+ if (!projectDir) throw new Error("--project-dir is required.");
31
+ if (!file) throw new Error("--file is required.");
32
+
33
+ const resolvedProjectDir = path.resolve(projectDir);
34
+ const composePath = path.resolve(resolvedProjectDir, file);
35
+ const relative = path.relative(resolvedProjectDir, composePath);
36
+
37
+ if (relative.startsWith("..") || path.isAbsolute(relative)) {
38
+ throw new Error("Compose file must be inside project-dir.");
39
+ }
40
+ if (!fs.existsSync(composePath)) {
41
+ throw new Error(`Compose file not found: ${composePath}`);
42
+ }
43
+
44
+ return { projectDir: resolvedProjectDir, composePath };
45
+ }
46
+
47
+ function defaultRunDocker(args, options) {
48
+ execFileSync("docker", args, { cwd: options.cwd, stdio: "inherit" });
49
+ }
50
+
51
+ function composeRelease(options = {}, dependencies = {}) {
52
+ const {
53
+ projectDir,
54
+ file,
55
+ bump = "patch",
56
+ push = false,
57
+ dryRun = false,
58
+ } = options;
59
+ const runDocker = dependencies.runDocker || defaultRunDocker;
60
+ const resolved = resolveComposePath(projectDir, file);
61
+ const original = fs.readFileSync(resolved.composePath, "utf8");
62
+ const updated = bumpComposeImageVersion(original, bump);
63
+ const baseArgs = ["compose", "-f", resolved.composePath];
64
+
65
+ console.log(`Version update: ${updated.from} -> ${updated.to}`);
66
+
67
+ if (dryRun) {
68
+ console.log(`[dry-run] docker ${[...baseArgs, "config"].join(" ")}`);
69
+ console.log(`[dry-run] docker ${[...baseArgs, "build"].join(" ")}`);
70
+ if (push) console.log(`[dry-run] docker ${[...baseArgs, "push"].join(" ")}`);
71
+ return { ...updated, projectDir: resolved.projectDir, composePath: resolved.composePath };
72
+ }
73
+
74
+ fs.writeFileSync(resolved.composePath, updated.content, "utf8");
75
+ try {
76
+ runDocker([...baseArgs, "config"], { cwd: resolved.projectDir });
77
+ runDocker([...baseArgs, "build"], { cwd: resolved.projectDir });
78
+ if (push) runDocker([...baseArgs, "push"], { cwd: resolved.projectDir });
79
+ } catch (error) {
80
+ fs.writeFileSync(resolved.composePath, original, "utf8");
81
+ throw error;
82
+ }
83
+
84
+ return { ...updated, projectDir: resolved.projectDir, composePath: resolved.composePath };
85
+ }
86
+
87
+ module.exports = {
88
+ bumpComposeImageVersion,
89
+ composeRelease,
90
+ resolveComposePath,
91
+ };
@@ -1,35 +1 @@
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;
1
+ module.exports = require("../../adapters/vue2/build/webpack5/inline-runtime-plugin.js");
@@ -1,84 +1 @@
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;
1
+ module.exports = require("../../adapters/vue2/build/webpack5/remove-legacy-assets-plugin.js");