@infly/libs 2.0.43 → 2.0.45
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/README.md +104 -67
- package/{module → adapters/vue2/module}/Permission.js +2 -2
- package/{module → adapters/vue2/module}/REST.js +32 -20
- package/{module → adapters/vue2/module}/TokenService.js +10 -1
- package/adapters/vue2/module/file-export.js +18 -0
- package/adapters/vue2/postinstall.js +46 -0
- package/adapters/vue2/project-preview.js +152 -0
- package/adapters/vue2/script-config.js +26 -0
- package/adapters/vue2/store/index.js +1 -0
- package/{store → adapters/vue2/store}/modules/user.js +1 -1
- package/adapters/vue2/vite/index.js +95 -0
- package/adapters/vue2/vite/jest.config.js +11 -0
- package/{build → adapters/vue2}/webpack5/webpack.base.js +26 -79
- package/bin/cli.js +71 -71
- package/build/build-dist/index.js +863 -863
- package/build/build-dist/script-management.js +5 -5
- package/{script/build → build/build-utils}/command.js +13 -4
- package/{script/build → build/build-utils}/deps.js +1 -1
- package/{script/build → build/build-utils}/git.js +6 -4
- package/{script/build → build/build-utils}/preview.js +4 -1
- package/{script/webhook/webhook.js → build/build-utils/webhook-single.js} +7 -2
- package/{script/build → build/build-utils}/webhook.js +3 -2
- package/build/docker/compose-command.js +74 -74
- package/build/docker/compose-release.js +91 -91
- package/compat/init.js +9 -0
- package/index.js +8 -20
- package/module/Uts.js +77 -7265
- package/module/cjs/{request-url-rules.cjs → request-url-rules.js} +6 -0
- package/module/cjs/rest-error-rules.js +33 -0
- package/package.json +124 -92
- package/script/git-automation/git-clone.js +3 -4
- package/script/git-automation/git-configure.js +29 -0
- package/script/git-automation/index.js +0 -14
- package/script/git-automation/submodule-status.js +113 -0
- package/script/git-automation/submodule-utils.js +18 -0
- package/script/index.js +1 -26
- package/tools/auto-export.js +1 -2
- package/tools/concurrency.js +30 -0
- package/tools/progress.js +63 -0
- package/tools/project-command.js +198 -194
- package/tools/project-preview.js +1 -148
- package/tools/select-option.js +60 -60
- package/tools/workspace-config.js +145 -0
- package/.prettierrc +0 -5
- package/build/build-dist/script-management.test.js +0 -16
- package/build/docker/compose-command.test.js +0 -148
- package/build/docker/compose-release.test.js +0 -101
- package/build/docker/docker-build-push.test.js +0 -124
- package/build/webpack5/remove-legacy-assets-plugin.js +0 -84
- package/build/webpack5/webpack.base.test.js +0 -59
- package/lib/index.js +0 -6
- package/lib/server/connect.js +0 -3011
- package/lib/server/serve-static.js +0 -4848
- package/module/cjs/deep-merge.cjs +0 -38
- package/script/pts/cloud-scenes.mjs +0 -65
- package/script/pts/cloud.js +0 -151
- package/script/pts/generate-cloud-params.mjs +0 -210
- package/script/pts/generate-cloud-params.test.mjs +0 -67
- package/store/index.js +0 -0
- package/tools/file-export.js +0 -165
- package/tools/project-command.test.js +0 -267
- package/tools/select-option.test.js +0 -52
- package/webpack.config.js +0 -38
- /package/{module → adapters/vue2/module}/Router.js +0 -0
- /package/{build → adapters/vue2}/webpack5/inline-runtime-plugin.js +0 -0
- /package/{script/build → build/build-utils}/env.js +0 -0
- /package/module/cjs/{page-config.cjs → page-config.js} +0 -0
|
@@ -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 };
|
|
@@ -2,14 +2,19 @@ const { spawn } = require("child_process");
|
|
|
2
2
|
|
|
3
3
|
function run(command, args, options = {}) {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
|
-
const
|
|
5
|
+
const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
|
|
6
|
+
// Avoid DEP0190: when shell=true, pass command+args as single string
|
|
7
|
+
const [cmd, cmdArgs] = useShell
|
|
8
|
+
? [[command, ...args].join(" "), []]
|
|
9
|
+
: [command, args];
|
|
10
|
+
const child = spawn(cmd, cmdArgs, {
|
|
6
11
|
cwd: options.cwd || process.cwd(),
|
|
7
12
|
env: {
|
|
8
13
|
...process.env,
|
|
9
14
|
...(options.env || {})
|
|
10
15
|
},
|
|
11
16
|
stdio: options.stdio || "inherit",
|
|
12
|
-
shell:
|
|
17
|
+
shell: useShell
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
child.on("close", (code) => {
|
|
@@ -25,14 +30,18 @@ function run(command, args, options = {}) {
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
function spawnBackground(command, args, options = {}) {
|
|
28
|
-
const
|
|
33
|
+
const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
|
|
34
|
+
const [cmd, cmdArgs] = useShell
|
|
35
|
+
? [[command, ...args].join(" "), []]
|
|
36
|
+
: [command, args];
|
|
37
|
+
const child = spawn(cmd, cmdArgs, {
|
|
29
38
|
cwd: options.cwd || process.cwd(),
|
|
30
39
|
env: {
|
|
31
40
|
...process.env,
|
|
32
41
|
...(options.env || {})
|
|
33
42
|
},
|
|
34
43
|
stdio: options.stdio || "inherit",
|
|
35
|
-
shell:
|
|
44
|
+
shell: useShell
|
|
36
45
|
});
|
|
37
46
|
|
|
38
47
|
child.on("error", (error) => {
|
|
@@ -9,7 +9,7 @@ const path = require("path");
|
|
|
9
9
|
*
|
|
10
10
|
* 示例(vue.config.js):
|
|
11
11
|
* alias: {
|
|
12
|
-
* "@
|
|
12
|
+
* "@example-admin": projectResolve("../example-admin/src")
|
|
13
13
|
* }
|
|
14
14
|
*
|
|
15
15
|
* @param {string} appDir - 当前 app 目录的绝对路径
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const { checkAndUpdatePackages } = require("
|
|
4
|
-
const { gitOutput, findGitRepo, getGitCommonDir } = require("
|
|
3
|
+
const { checkAndUpdatePackages } = require("../../script/git-automation");
|
|
4
|
+
const { gitOutput, findGitRepo, getGitCommonDir } = require("../../script/git-automation/git-utils");
|
|
5
5
|
const { run } = require("./command");
|
|
6
6
|
|
|
7
7
|
function getTargetBranch(rootPackageJson, mode) {
|
|
@@ -77,9 +77,11 @@ function getDistRepoInfo(rootDir, pkg, targetBranch, options = {}) {
|
|
|
77
77
|
fs.existsSync(nextConfigTs)
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
-
let outputDir;
|
|
80
|
+
let outputDir = pkg.viteOutputDir;
|
|
81
81
|
|
|
82
|
-
if (
|
|
82
|
+
if (outputDir) {
|
|
83
|
+
// Vite 注册表已经提供经过校验的 dist 根,禁止再执行历史 vue.config.js。
|
|
84
|
+
} else if (hasVueConfig) {
|
|
83
85
|
outputDir = require(vueConfigPath).outputDir;
|
|
84
86
|
} else if (hasNextConfig) {
|
|
85
87
|
outputDir = pkg.packageJson.infly?.buildConfigs?.outputPath;
|
|
@@ -34,7 +34,10 @@ function startBatchPreviews(rootDir, packages) {
|
|
|
34
34
|
const child = spawnBackground("infly-libs", ["preview", "--no-build"], {
|
|
35
35
|
cwd: path.join(rootDir, pkg.dir),
|
|
36
36
|
env: createBuildContext({
|
|
37
|
-
batchPreview: true
|
|
37
|
+
batchPreview: true,
|
|
38
|
+
outputDir: pkg.targetOutputDir || undefined,
|
|
39
|
+
target: pkg.targetKey || undefined,
|
|
40
|
+
targetLabel: pkg.targetLabel || undefined,
|
|
38
41
|
})
|
|
39
42
|
});
|
|
40
43
|
|
|
@@ -63,7 +63,7 @@ function postVersionFileAndMsg(publishText, extraParams = {}) {
|
|
|
63
63
|
gitAutoPushRepos,
|
|
64
64
|
gitAutoPushReposBranchMap,
|
|
65
65
|
repos,
|
|
66
|
-
deployUrl = "
|
|
66
|
+
deployUrl = ""
|
|
67
67
|
} = extraParams || {};
|
|
68
68
|
const { branch, commitMsg, author } = gitInfo || {};
|
|
69
69
|
const webhookMessage = getWebhookMessage();
|
|
@@ -82,7 +82,12 @@ function postVersionFileAndMsg(publishText, extraParams = {}) {
|
|
|
82
82
|
} */
|
|
83
83
|
let content = publishText;
|
|
84
84
|
if (gitAutoPushReposBranchMap) {
|
|
85
|
-
content =
|
|
85
|
+
content = [
|
|
86
|
+
publishText,
|
|
87
|
+
`构建文件:已推送对应仓库【${repos}】- 分支【${gitAutoPushReposBranchMap[branch]}】`,
|
|
88
|
+
`构建人:${author}`,
|
|
89
|
+
deployUrl ? `部署系统:${deployUrl}` : ""
|
|
90
|
+
].filter(Boolean).join("\n");
|
|
86
91
|
} else {
|
|
87
92
|
content = `${publishText}\n构建文件下载地址:${GITPATH}\n${webhookExtraText}\n`;
|
|
88
93
|
}
|
|
@@ -36,7 +36,7 @@ function getRecordContent(record, deployUrl) {
|
|
|
36
36
|
publishText,
|
|
37
37
|
`构建文件:已推送对应仓库【${repos || ""}】- 分支【${targetBranch}】`,
|
|
38
38
|
`构建人:${author || ""}`,
|
|
39
|
-
`部署系统:${deployUrl}`
|
|
39
|
+
deployUrl ? `部署系统:${deployUrl}` : ""
|
|
40
40
|
]
|
|
41
41
|
.filter(Boolean)
|
|
42
42
|
.join("\n");
|
|
@@ -77,7 +77,7 @@ async function postBatchWebhook(batchWebhookFile, extraArgs, mode) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const [firstRecord] = records;
|
|
80
|
-
const { webhookUrl, webhookAtUser = [], gitInfo = {}, deployUrl = "
|
|
80
|
+
const { webhookUrl, webhookAtUser = [], gitInfo = {}, deployUrl = "" } =
|
|
81
81
|
firstRecord.extraParams || {};
|
|
82
82
|
|
|
83
83
|
if (!webhookUrl) {
|
|
@@ -114,5 +114,6 @@ async function postBatchWebhook(batchWebhookFile, extraArgs, mode) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
module.exports = {
|
|
117
|
+
getRecordContent,
|
|
117
118
|
postBatchWebhook
|
|
118
119
|
};
|
|
@@ -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
|
+
};
|
package/compat/init.js
ADDED
package/index.js
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
const projectPreview = require("./tools/project-preview");
|
|
3
|
-
const path = require("path");
|
|
1
|
+
"use strict";
|
|
4
2
|
|
|
5
|
-
function init() {
|
|
6
|
-
|
|
7
|
-
const currentDir = process.cwd();
|
|
8
|
-
const packageDir = __dirname;
|
|
9
|
-
|
|
10
|
-
// 如果当前目录就是 infly-libs 包目录,跳过执行
|
|
11
|
-
if (currentDir === packageDir) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
projectPreview.scriptInit();
|
|
16
|
-
buildDist.scriptInit();
|
|
3
|
+
function init(projectRoot) {
|
|
4
|
+
return require("./compat/init").init(projectRoot);
|
|
17
5
|
}
|
|
18
6
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
init
|
|
23
|
-
};
|
|
7
|
+
module.exports = Object.freeze({
|
|
8
|
+
name: "@infly/libs",
|
|
9
|
+
framework: "agnostic",
|
|
10
|
+
init,
|
|
11
|
+
});
|