diff --git a/package.json b/package.json index ab2d70812..02bd9c538 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devb": "lerna run dev-build", "i-all": "lerna link && lerna exec npm install ", "publish": "pnpm run prepublishOnly2 && lerna publish --force-publish=pro/plus-core --conventional-commits && pnpm run afterpublishOnly ", + "publish2":" npm run pub_all && pnpm run afterpublishOnly", "afterpublishOnly": "pnpm run copylogs && time /t >trigger/build.trigger && git add ./trigger/build.trigger && git commit -m \"build: trigger build image\" && TIMEOUT /T 10 && pnpm run commitAll", "transform-sql": "cd ./packages/ui/certd-server/db/ && node --experimental-json-modules transform.js", "plugin-doc-gen": "cd ./packages/ui/certd-server/ && pnpm run export-metadata", @@ -39,7 +40,7 @@ "test:unit": "cross-env NODE_ENV=unittest pnpm -r --workspace-concurrency=1 run test:unit", "pub": "echo 1", "dev": "pnpm run -r --parallel compile ", - "pub_all":"pnpm run -r --parallel pub ", + "pub_all": "node ./scripts/pub-all.js", "release": "time /t >trigger/release.trigger && git add trigger/release.trigger && git commit -m \"build: release\" && git push", "publish_to_atomgit": "node --experimental-json-modules ./scripts/publish-atomgit.js", "publish_to_gitee": "node --experimental-json-modules ./scripts/publish-gitee.js", diff --git a/packages/core/acme-client/package.json b/packages/core/acme-client/package.json index 271c9caae..74d5ba2b9 100644 --- a/packages/core/acme-client/package.json +++ b/packages/core/acme-client/package.json @@ -76,5 +76,5 @@ "bugs": { "url": "https://github.com/publishlab/node-acme-client/issues" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/core/basic/package.json b/packages/core/basic/package.json index 081029e17..e135c7d44 100644 --- a/packages/core/basic/package.json +++ b/packages/core/basic/package.json @@ -52,5 +52,5 @@ "tslib": "^2.8.1", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/core/pipeline/package.json b/packages/core/pipeline/package.json index 8a49f04cb..2752b8788 100644 --- a/packages/core/pipeline/package.json +++ b/packages/core/pipeline/package.json @@ -49,5 +49,5 @@ "tslib": "^2.8.1", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/libs/lib-huawei/package.json b/packages/libs/lib-huawei/package.json index 437172b18..cb069666a 100644 --- a/packages/libs/lib-huawei/package.json +++ b/packages/libs/lib-huawei/package.json @@ -27,5 +27,5 @@ "prettier": "^2.8.8", "tslib": "^2.8.1" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/libs/lib-iframe/package.json b/packages/libs/lib-iframe/package.json index 578ecfa8c..5f86bf35b 100644 --- a/packages/libs/lib-iframe/package.json +++ b/packages/libs/lib-iframe/package.json @@ -34,5 +34,5 @@ "tslib": "^2.8.1", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/libs/lib-jdcloud/package.json b/packages/libs/lib-jdcloud/package.json index 17177fe1a..02ae7edce 100644 --- a/packages/libs/lib-jdcloud/package.json +++ b/packages/libs/lib-jdcloud/package.json @@ -59,5 +59,5 @@ "fetch" ] }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/libs/lib-k8s/package.json b/packages/libs/lib-k8s/package.json index 521354d66..b9a2fccfa 100644 --- a/packages/libs/lib-k8s/package.json +++ b/packages/libs/lib-k8s/package.json @@ -36,5 +36,5 @@ "tslib": "^2.8.1", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/libs/lib-server/package.json b/packages/libs/lib-server/package.json index 1a2433380..ffa97ed86 100644 --- a/packages/libs/lib-server/package.json +++ b/packages/libs/lib-server/package.json @@ -69,5 +69,5 @@ "typeorm": "^0.3.11", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/libs/midway-flyway-js/package.json b/packages/libs/midway-flyway-js/package.json index a8d35a489..ec5f2ffe8 100644 --- a/packages/libs/midway-flyway-js/package.json +++ b/packages/libs/midway-flyway-js/package.json @@ -49,5 +49,5 @@ "typeorm": "^0.3.11", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/plugins/plugin-cert/package.json b/packages/plugins/plugin-cert/package.json index 83638335f..efebd1e5c 100644 --- a/packages/plugins/plugin-cert/package.json +++ b/packages/plugins/plugin-cert/package.json @@ -41,5 +41,5 @@ "tslib": "^2.8.1", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/packages/plugins/plugin-lib/package.json b/packages/plugins/plugin-lib/package.json index 3b08d5225..b3255cef6 100644 --- a/packages/plugins/plugin-lib/package.json +++ b/packages/plugins/plugin-lib/package.json @@ -61,5 +61,5 @@ "tslib": "^2.8.1", "typescript": "^5.4.2" }, - "gitHead": "678b70cee8510a2b5217788c5db9469f49cbd439" + "gitHead": "01c91ba294f88bd07fddf9358c4301bbb4027916" } diff --git a/scripts/pub-all.js b/scripts/pub-all.js new file mode 100644 index 000000000..dca924473 --- /dev/null +++ b/scripts/pub-all.js @@ -0,0 +1,81 @@ +import childProcess from "child_process"; +import fs from "fs"; +import path from "path"; + +function run(command, args, options = {}) { + const result = childProcess.spawnSync(command, args, { + stdio: options.stdio ?? "pipe", + shell: process.platform === "win32", + encoding: "utf-8", + ...options, + }); + + if (result.error) { + throw result.error; + } + + return result; +} + +function printOutput(result) { + if (result.stdout) { + process.stdout.write(result.stdout); + } + if (result.stderr) { + process.stderr.write(result.stderr); + } +} + +function isAlreadyPublishedError(result) { + const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`; + return output.includes("You cannot publish over the previously published versions"); +} + +function getWorkspacePackages() { + const result = run("pnpm", ["list", "-r", "--depth", "-1", "--json"], { + stdio: "pipe", + }); + + if (result.status !== 0) { + console.error(result.stderr); + throw new Error("获取 workspace 包列表失败"); + } + + return JSON.parse(result.stdout); +} + +function hasPubScript(packagePath) { + const packageJsonPath = path.join(packagePath, "package.json"); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); + return Boolean(packageJson.scripts?.pub); +} + +const packages = getWorkspacePackages().filter(item => item.name !== "root"); +let skippedCount = 0; +let alreadyPublishedCount = 0; + +for (const item of packages) { + const packagePath = item.path; + + if (!hasPubScript(packagePath)) { + skippedCount++; + console.log(`[pub_all] 跳过 ${item.name},未定义 pub 脚本`); + continue; + } + + console.log(`\n[pub_all] 开始发布 ${item.name}`); + const result = run("pnpm", ["--dir", packagePath, "run", "pub"]); + printOutput(result); + + if (result.status === 0) { + console.log(`[pub_all] ${item.name} 发布完成`); + } else if (isAlreadyPublishedError(result)) { + alreadyPublishedCount++; + console.warn(`[pub_all] ${item.name} 当前版本已发布,继续发布其他包`); + } else { + console.error(`[pub_all] ${item.name} 发布失败,停止发布`); + process.exit(result.status ?? 1); + } +} + +console.log(`\n[pub_all] 发布任务完成,跳过 ${skippedCount} 个未定义 pub 脚本的包,${alreadyPublishedCount} 个包版本已存在`);