@coze-arch/rush-publish-plugin 0.0.1-alpha.6255b0
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 +1 -0
- package/command-line.json +140 -0
- package/lib/action/change/action.d.ts +2 -0
- package/lib/action/change/action.js +40 -0
- package/lib/action/change/amend-commit.d.ts +1 -0
- package/lib/action/change/amend-commit.js +23 -0
- package/lib/action/change/helper.d.ts +33 -0
- package/lib/action/change/helper.js +126 -0
- package/lib/action/change/index.d.ts +2 -0
- package/lib/action/change/index.js +17 -0
- package/lib/action/change/types.d.ts +5 -0
- package/lib/action/change/types.js +3 -0
- package/lib/action/publish/action.d.ts +2 -0
- package/lib/action/publish/action.js +68 -0
- package/lib/action/publish/apply-new-version.d.ts +2 -0
- package/lib/action/publish/apply-new-version.js +27 -0
- package/lib/action/publish/changelog.d.ts +2 -0
- package/lib/action/publish/changelog.js +79 -0
- package/lib/action/publish/confirm.d.ts +2 -0
- package/lib/action/publish/confirm.js +31 -0
- package/lib/action/publish/const.d.ts +1 -0
- package/lib/action/publish/const.js +5 -0
- package/lib/action/publish/git.d.ts +20 -0
- package/lib/action/publish/git.js +33 -0
- package/lib/action/publish/index.d.ts +2 -0
- package/lib/action/publish/index.js +43 -0
- package/lib/action/publish/packages.d.ts +3 -0
- package/lib/action/publish/packages.js +67 -0
- package/lib/action/publish/push-to-remote.d.ts +13 -0
- package/lib/action/publish/push-to-remote.js +105 -0
- package/lib/action/publish/request-bump-type.d.ts +5 -0
- package/lib/action/publish/request-bump-type.js +56 -0
- package/lib/action/publish/types.d.ts +25 -0
- package/lib/action/publish/types.js +12 -0
- package/lib/action/publish/version.d.ts +16 -0
- package/lib/action/publish/version.js +111 -0
- package/lib/action/release/action.d.ts +2 -0
- package/lib/action/release/action.js +34 -0
- package/lib/action/release/git.d.ts +5 -0
- package/lib/action/release/git.js +28 -0
- package/lib/action/release/index.d.ts +2 -0
- package/lib/action/release/index.js +31 -0
- package/lib/action/release/manifest.d.ts +5 -0
- package/lib/action/release/manifest.js +18 -0
- package/lib/action/release/package.d.ts +2 -0
- package/lib/action/release/package.js +49 -0
- package/lib/action/release/plan.d.ts +8 -0
- package/lib/action/release/plan.js +37 -0
- package/lib/action/release/release.d.ts +2 -0
- package/lib/action/release/release.js +50 -0
- package/lib/action/release/types.d.ts +14 -0
- package/lib/action/release/types.js +3 -0
- package/lib/generate-changelog/generate-changelog.d.ts +49 -0
- package/lib/generate-changelog/generate-changelog.js +127 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +28 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +3 -0
- package/lib/utils/exec.d.ts +7 -0
- package/lib/utils/exec.js +24 -0
- package/lib/utils/fs.d.ts +4 -0
- package/lib/utils/fs.js +27 -0
- package/lib/utils/get-rush-config.d.ts +2 -0
- package/lib/utils/get-rush-config.js +16 -0
- package/lib/utils/git.d.ts +19 -0
- package/lib/utils/git.js +70 -0
- package/lib/utils/logger.d.ts +58 -0
- package/lib/utils/logger.js +136 -0
- package/lib/utils/random.d.ts +6 -0
- package/lib/utils/random.js +19 -0
- package/lib/utils/whoami.d.ts +4 -0
- package/lib/utils/whoami.js +16 -0
- package/package.json +69 -0
- package/rush-plugin-manifest.json +10 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAndPushBranch = createAndPushBranch;
|
|
4
|
+
exports.commitChanges = commitChanges;
|
|
5
|
+
exports.push = push;
|
|
6
|
+
const logger_1 = require("../../utils/logger");
|
|
7
|
+
const exec_1 = require("../../utils/exec");
|
|
8
|
+
async function createAndPushBranch(branchName, cwd) {
|
|
9
|
+
try {
|
|
10
|
+
// 创建新分支
|
|
11
|
+
await (0, exec_1.exec)(`git checkout -b ${branchName}`, { cwd });
|
|
12
|
+
logger_1.logger.info(`Created new branch: ${branchName}`);
|
|
13
|
+
// 推送到远程
|
|
14
|
+
await (0, exec_1.exec)(`git push -u origin ${branchName}`, { cwd });
|
|
15
|
+
logger_1.logger.info(`Pushed branch to remote: ${branchName}`);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(`Failed to create/push branch: ${error}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function commitChanges({ sessionId, files, cwd, publishManifests, branchName, }) {
|
|
22
|
+
await (0, exec_1.exec)(`git add ${files.join(' ')}`, { cwd });
|
|
23
|
+
await (0, exec_1.exec)(`git commit -m "chore: Publish ${branchName}" -n`, { cwd });
|
|
24
|
+
const tags = publishManifests.map(m => `v/${m.project.packageName}@${m.newVersion}`);
|
|
25
|
+
await (0, exec_1.exec)(tags.map(tag => `git tag -a ${tag} -m "Bump type ${tag}"`).join(' && '), { cwd });
|
|
26
|
+
return { effects: [...tags, branchName], branchName };
|
|
27
|
+
}
|
|
28
|
+
async function push({ refs, cwd, repoUrl }) {
|
|
29
|
+
await (0, exec_1.exec)(`git push ${repoUrl} ${refs.join(' ')} --no-verify`, {
|
|
30
|
+
cwd,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installAction = void 0;
|
|
4
|
+
const logger_1 = require("../../utils/logger");
|
|
5
|
+
const git_1 = require("../../utils/git");
|
|
6
|
+
const const_1 = require("./const");
|
|
7
|
+
const action_1 = require("./action");
|
|
8
|
+
const installAction = (program) => {
|
|
9
|
+
program
|
|
10
|
+
.command('pub')
|
|
11
|
+
.description('Generate new version and create release branch.')
|
|
12
|
+
.option('-v, --version <string>', 'Specify publish version')
|
|
13
|
+
.option('-d, --dry-run', 'Enable dry run mode', false)
|
|
14
|
+
.option('-t, --to <packages...>', 'Publish specified packages and their downstream dependencies')
|
|
15
|
+
.option('-f, --from <packages...>', 'Publish specified packages and their upstream/downstream dependencies')
|
|
16
|
+
.option('-o, --only <packages...>', 'Only publish specified packages')
|
|
17
|
+
.option('-s, --skip-commit', 'Skip git commit', false)
|
|
18
|
+
.option('-p, --skip-push', 'Skip git push', false)
|
|
19
|
+
.option('-b, --bump-type <type>', 'Version bump type (alpha/beta/patch/minor/major)', /^(alpha|beta|patch|minor|major)$/)
|
|
20
|
+
.option('--repo-url <url>', 'Git repository URL (e.g. git@github.com:coze-dev/coze-js.git)', undefined)
|
|
21
|
+
.action(async (options) => {
|
|
22
|
+
try {
|
|
23
|
+
const repoUrl = options.repoUrl || (await (0, git_1.getCurrentOrigin)());
|
|
24
|
+
if (!repoUrl) {
|
|
25
|
+
throw new Error('Git repository URL is required');
|
|
26
|
+
}
|
|
27
|
+
if (!const_1.GIT_REPO_URL_REGEX.test(repoUrl)) {
|
|
28
|
+
throw new Error(`Invalid git repository URL: ${repoUrl}, it should be follow the format: git@github.com:\${org}/\${repo}.git`);
|
|
29
|
+
}
|
|
30
|
+
const normalizeOptions = {
|
|
31
|
+
...options,
|
|
32
|
+
repoUrl,
|
|
33
|
+
};
|
|
34
|
+
await (0, action_1.publish)(normalizeOptions);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger_1.logger.error('Publish failed!');
|
|
38
|
+
logger_1.logger.error(error.message);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.installAction = installAction;
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAndGetPackages = void 0;
|
|
4
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
5
|
+
var RetrievePattern;
|
|
6
|
+
(function (RetrievePattern) {
|
|
7
|
+
RetrievePattern["TO"] = "to";
|
|
8
|
+
RetrievePattern["FROM"] = "from";
|
|
9
|
+
RetrievePattern["ONLY"] = "only";
|
|
10
|
+
})(RetrievePattern || (RetrievePattern = {}));
|
|
11
|
+
const retrievePackages = (pattern, packages) => {
|
|
12
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
13
|
+
const matchedPackages = new Set();
|
|
14
|
+
packages.forEach(pkg => {
|
|
15
|
+
const project = rushConfiguration.getProjectByName(pkg);
|
|
16
|
+
if (!project) {
|
|
17
|
+
throw new Error(`Package "${pkg}" not found in rush configuration`);
|
|
18
|
+
}
|
|
19
|
+
if (!project.shouldPublish) {
|
|
20
|
+
throw new Error(`Package "${pkg}" is not set to publish. if you want to publish it, please set the "shouldPublish" property to true in the \`rush.json\` file.`);
|
|
21
|
+
}
|
|
22
|
+
const matched = [];
|
|
23
|
+
switch (pattern) {
|
|
24
|
+
case 'to': {
|
|
25
|
+
matched.push(project.dependencyProjects);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'from': {
|
|
29
|
+
matched.push(project.consumingProjects);
|
|
30
|
+
matched.push(project.dependencyProjects);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'only': {
|
|
34
|
+
// do nothing
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
default: {
|
|
38
|
+
throw new Error('Unexpected package selection state');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const matchedSet of matched) {
|
|
42
|
+
for (const p of matchedSet) {
|
|
43
|
+
if (p.shouldPublish) {
|
|
44
|
+
matchedPackages.add(p);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
matchedPackages.add(project);
|
|
49
|
+
});
|
|
50
|
+
return matchedPackages;
|
|
51
|
+
};
|
|
52
|
+
const validateAndGetPackages = (options) => {
|
|
53
|
+
const retrievePatterns = Object.values(RetrievePattern);
|
|
54
|
+
if (retrievePatterns.every(pattern => (options[pattern]?.length || 0) <= 0)) {
|
|
55
|
+
throw new Error('No packages to publish');
|
|
56
|
+
}
|
|
57
|
+
return retrievePatterns.reduce((acc, pattern) => {
|
|
58
|
+
const packages = options[pattern];
|
|
59
|
+
if (!packages || packages.length <= 0) {
|
|
60
|
+
return acc;
|
|
61
|
+
}
|
|
62
|
+
const placeholders = retrievePackages(pattern, packages);
|
|
63
|
+
return new Set([...acc, ...placeholders]);
|
|
64
|
+
}, new Set());
|
|
65
|
+
};
|
|
66
|
+
exports.validateAndGetPackages = validateAndGetPackages;
|
|
67
|
+
//# sourceMappingURL=packages.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PublishManifest, BumpType } from './types';
|
|
2
|
+
interface PushToRemoteOptions {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
changedFiles: string[];
|
|
5
|
+
cwd: string;
|
|
6
|
+
publishManifests: PublishManifest[];
|
|
7
|
+
bumpPolicy: BumpType | string;
|
|
8
|
+
skipCommit: boolean;
|
|
9
|
+
skipPush: boolean;
|
|
10
|
+
repoUrl: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const pushToRemote: (options: PushToRemoteOptions) => Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pushToRemote = void 0;
|
|
40
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
41
|
+
const logger_1 = require("../../utils/logger");
|
|
42
|
+
const git_1 = require("../../utils/git");
|
|
43
|
+
const exec_1 = require("../../utils/exec");
|
|
44
|
+
const types_1 = require("./types");
|
|
45
|
+
const git_2 = require("./git");
|
|
46
|
+
const const_1 = require("./const");
|
|
47
|
+
const pushToRemote = async (options) => {
|
|
48
|
+
const { sessionId, changedFiles, cwd, publishManifests, bumpPolicy, skipCommit, skipPush, repoUrl, } = options;
|
|
49
|
+
if (skipCommit) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// 获取仓库 URL
|
|
53
|
+
const actualRepoUrl = repoUrl;
|
|
54
|
+
let branchName;
|
|
55
|
+
if (bumpPolicy === types_1.BumpType.BETA) {
|
|
56
|
+
branchName = await (0, git_1.getCurrentBranchName)();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const date = (0, dayjs_1.default)().format('YYYYMMDD');
|
|
60
|
+
branchName = `release/${date}-${sessionId}`;
|
|
61
|
+
await (0, exec_1.exec)(`git checkout -b ${branchName}`, { cwd });
|
|
62
|
+
}
|
|
63
|
+
// 4. 创建并推送发布分支
|
|
64
|
+
const { effects } = await (0, git_2.commitChanges)({
|
|
65
|
+
sessionId,
|
|
66
|
+
files: changedFiles,
|
|
67
|
+
cwd,
|
|
68
|
+
publishManifests,
|
|
69
|
+
branchName,
|
|
70
|
+
});
|
|
71
|
+
if (skipPush) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await (0, git_2.push)({
|
|
75
|
+
refs: effects,
|
|
76
|
+
cwd,
|
|
77
|
+
repoUrl: actualRepoUrl,
|
|
78
|
+
});
|
|
79
|
+
const isTestPublish = [types_1.BumpType.ALPHA, types_1.BumpType.BETA].includes(bumpPolicy);
|
|
80
|
+
// 从 git URL 提取组织和仓库名称,用于构建 GitHub 链接
|
|
81
|
+
const repoInfoMatch = actualRepoUrl.match(const_1.GIT_REPO_URL_REGEX);
|
|
82
|
+
if (!repoInfoMatch) {
|
|
83
|
+
throw new Error('Invalid git repository URL');
|
|
84
|
+
}
|
|
85
|
+
const repoOwner = repoInfoMatch[1];
|
|
86
|
+
const repoName = repoInfoMatch[2];
|
|
87
|
+
if (isTestPublish) {
|
|
88
|
+
logger_1.logger.success(`Please refer to https://github.com/${repoOwner}/${repoName}/actions/workflows/release.yml for the release progress.`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const prUrl = `https://github.com/${repoOwner}/${repoName}/compare/${branchName}?expand=1`;
|
|
92
|
+
const log = [
|
|
93
|
+
'************************************************',
|
|
94
|
+
'*',
|
|
95
|
+
`* Please create PR: ${prUrl}`,
|
|
96
|
+
'*',
|
|
97
|
+
'************************************************',
|
|
98
|
+
];
|
|
99
|
+
logger_1.logger.success(log.join('\n'), false);
|
|
100
|
+
const open = await Promise.resolve().then(() => __importStar(require('open')));
|
|
101
|
+
await open.default(prUrl);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
exports.pushToRemote = pushToRemote;
|
|
105
|
+
//# sourceMappingURL=push-to-remote.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.requestBumpType = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
/**
|
|
11
|
+
* 获取更新类型的描述
|
|
12
|
+
*/
|
|
13
|
+
const getTypeDescription = (type) => {
|
|
14
|
+
switch (type) {
|
|
15
|
+
case types_1.BumpType.MAJOR:
|
|
16
|
+
return `Major update, incompatible API changes, for example: ${chalk_1.default.green('1.1.1 -> 2.0.0')}`;
|
|
17
|
+
case types_1.BumpType.MINOR:
|
|
18
|
+
return `Minor update, backwards-compatible features, for example: ${chalk_1.default.green('1.1.1 -> 1.2.0')}`;
|
|
19
|
+
case types_1.BumpType.PATCH:
|
|
20
|
+
return `Patch update, backwards-compatible bug fixes, for example: ${chalk_1.default.green('1.1.1 -> 1.1.2')}`;
|
|
21
|
+
case types_1.BumpType.BETA:
|
|
22
|
+
return `Beta pre-release version, for example: ${chalk_1.default.green('1.1.1-beta.1')}`;
|
|
23
|
+
case types_1.BumpType.ALPHA:
|
|
24
|
+
return `Alpha pre-release version, for example: ${chalk_1.default.green('1.1.1-alpha.2597f3')}`;
|
|
25
|
+
default:
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 让用户选择版本更新类型
|
|
31
|
+
*/
|
|
32
|
+
const requestBumpType = async () => {
|
|
33
|
+
const bumpTypesChoices = [
|
|
34
|
+
types_1.BumpType.ALPHA,
|
|
35
|
+
types_1.BumpType.BETA,
|
|
36
|
+
types_1.BumpType.PATCH,
|
|
37
|
+
types_1.BumpType.MINOR,
|
|
38
|
+
types_1.BumpType.MAJOR,
|
|
39
|
+
];
|
|
40
|
+
const choices = bumpTypesChoices.map(type => ({
|
|
41
|
+
name: `${chalk_1.default.bold(type.toUpperCase())}: ${getTypeDescription(type)}`,
|
|
42
|
+
value: type,
|
|
43
|
+
}));
|
|
44
|
+
try {
|
|
45
|
+
const selected = await (0, prompts_1.select)({
|
|
46
|
+
message: 'Select version bump type:',
|
|
47
|
+
choices,
|
|
48
|
+
});
|
|
49
|
+
return selected;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.requestBumpType = requestBumpType;
|
|
56
|
+
//# sourceMappingURL=request-bump-type.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RushConfigurationProject } from '@rushstack/rush-sdk';
|
|
2
|
+
export declare enum BumpType {
|
|
3
|
+
ALPHA = "alpha",
|
|
4
|
+
BETA = "beta",
|
|
5
|
+
PATCH = "patch",
|
|
6
|
+
MINOR = "minor",
|
|
7
|
+
MAJOR = "major"
|
|
8
|
+
}
|
|
9
|
+
export interface PublishOptions {
|
|
10
|
+
version?: string;
|
|
11
|
+
dryRun?: boolean;
|
|
12
|
+
to?: string[];
|
|
13
|
+
from?: string[];
|
|
14
|
+
only?: string[];
|
|
15
|
+
bumpType?: BumpType;
|
|
16
|
+
skipCommit?: boolean;
|
|
17
|
+
skipPush?: boolean;
|
|
18
|
+
repoUrl: string;
|
|
19
|
+
}
|
|
20
|
+
export interface PublishManifest {
|
|
21
|
+
project: RushConfigurationProject;
|
|
22
|
+
currentVersion: string;
|
|
23
|
+
newVersion: string;
|
|
24
|
+
}
|
|
25
|
+
export type ApplyPublishManifest = (manifests: PublishManifest[]) => Promise<string[]>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BumpType = void 0;
|
|
4
|
+
var BumpType;
|
|
5
|
+
(function (BumpType) {
|
|
6
|
+
BumpType["ALPHA"] = "alpha";
|
|
7
|
+
BumpType["BETA"] = "beta";
|
|
8
|
+
BumpType["PATCH"] = "patch";
|
|
9
|
+
BumpType["MINOR"] = "minor";
|
|
10
|
+
BumpType["MAJOR"] = "major";
|
|
11
|
+
})(BumpType || (exports.BumpType = BumpType = {}));
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RushConfigurationProject } from '@rushstack/rush-sdk';
|
|
2
|
+
import { BumpType } from './types';
|
|
3
|
+
import { type PublishManifest } from './types';
|
|
4
|
+
interface VersionOptions {
|
|
5
|
+
version?: string;
|
|
6
|
+
bumpType?: BumpType;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 生成发布清单
|
|
11
|
+
*/
|
|
12
|
+
export declare const generatePublishManifest: (packages: Set<RushConfigurationProject>, options: VersionOptions) => Promise<{
|
|
13
|
+
manifests: PublishManifest[];
|
|
14
|
+
bumpPolicy: BumpType | string | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generatePublishManifest = void 0;
|
|
7
|
+
const semver_1 = __importDefault(require("semver"));
|
|
8
|
+
const random_1 = require("../../utils/random");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const request_bump_type_1 = require("./request-bump-type");
|
|
11
|
+
/**
|
|
12
|
+
* 根据当前版本和发布类型计算新版本号
|
|
13
|
+
*/
|
|
14
|
+
const calculateNewVersion = (currentVersion, bumpType, sessionId) => {
|
|
15
|
+
// 解析当前版本
|
|
16
|
+
const parsed = semver_1.default.parse(currentVersion);
|
|
17
|
+
if (!parsed) {
|
|
18
|
+
throw new Error(`Invalid current version: ${currentVersion}`);
|
|
19
|
+
}
|
|
20
|
+
const { major, minor, patch, prerelease } = parsed;
|
|
21
|
+
switch (bumpType) {
|
|
22
|
+
case types_1.BumpType.PATCH:
|
|
23
|
+
case types_1.BumpType.MINOR:
|
|
24
|
+
case types_1.BumpType.MAJOR: {
|
|
25
|
+
// 如果当前是预发布版本,去掉预发布标识
|
|
26
|
+
const cc = prerelease.length > 0 ? `${major}.${minor}.${patch}` : currentVersion;
|
|
27
|
+
// 否则增加 patch 版本
|
|
28
|
+
return semver_1.default.inc(cc, bumpType) || currentVersion;
|
|
29
|
+
}
|
|
30
|
+
case types_1.BumpType.BETA: {
|
|
31
|
+
// 如果当前已经是 beta 版本,增加 beta 版本号
|
|
32
|
+
if (prerelease[0] === 'beta') {
|
|
33
|
+
const nextVersion = semver_1.default.inc(currentVersion, 'prerelease', 'beta');
|
|
34
|
+
return nextVersion || currentVersion;
|
|
35
|
+
}
|
|
36
|
+
// 否则基于当前版本创建新的 beta 版本
|
|
37
|
+
const baseVersion = `${major}.${minor}.${patch}`;
|
|
38
|
+
return `${baseVersion}-beta.1`;
|
|
39
|
+
}
|
|
40
|
+
case types_1.BumpType.ALPHA: {
|
|
41
|
+
// 否则基于当前版本创建新的 alpha 版本
|
|
42
|
+
const baseVersion = `${major}.${minor}.${patch}`;
|
|
43
|
+
// 生成随机哈希值
|
|
44
|
+
return `${baseVersion}-alpha.${sessionId || (0, random_1.randomHash)(6)}`;
|
|
45
|
+
}
|
|
46
|
+
default: {
|
|
47
|
+
throw new Error(`Invalid bump type: ${bumpType}, should be one of ${Object.values(types_1.BumpType).join(', ')}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 生成新版本号
|
|
53
|
+
* 策略优先级:
|
|
54
|
+
* 1. 指定版本号
|
|
55
|
+
* 2. 指定发布类型
|
|
56
|
+
* 3. 交互式选择
|
|
57
|
+
*/
|
|
58
|
+
const generateNewVersionForPackage = (project, options) => {
|
|
59
|
+
const currentVersion = project.packageJson.version;
|
|
60
|
+
// 1. 如果指定了版本号,直接使用
|
|
61
|
+
if (options.version) {
|
|
62
|
+
return options.version;
|
|
63
|
+
}
|
|
64
|
+
// 1. 如果指定了发布类型,计算新版本号
|
|
65
|
+
const { bumpType } = options;
|
|
66
|
+
if (!bumpType) {
|
|
67
|
+
throw new Error('Version selection was cancelled');
|
|
68
|
+
}
|
|
69
|
+
const newVersion = calculateNewVersion(currentVersion, bumpType, options.sessionId);
|
|
70
|
+
return newVersion;
|
|
71
|
+
};
|
|
72
|
+
const calBumpPolicy = (options) => {
|
|
73
|
+
const { version, bumpType } = options;
|
|
74
|
+
if (version) {
|
|
75
|
+
return version;
|
|
76
|
+
}
|
|
77
|
+
return bumpType;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* 生成发布清单
|
|
81
|
+
*/
|
|
82
|
+
const generatePublishManifest = async (packages, options) => {
|
|
83
|
+
const manifests = [];
|
|
84
|
+
const { version, bumpType } = options;
|
|
85
|
+
if (version && !semver_1.default.valid(version)) {
|
|
86
|
+
throw new Error(`Invalid version specified: ${version}`);
|
|
87
|
+
}
|
|
88
|
+
else if (!bumpType) {
|
|
89
|
+
const newBumpType = await (0, request_bump_type_1.requestBumpType)();
|
|
90
|
+
if (!newBumpType) {
|
|
91
|
+
throw new Error('Version selection was cancelled!');
|
|
92
|
+
}
|
|
93
|
+
options.bumpType = newBumpType;
|
|
94
|
+
}
|
|
95
|
+
for (const pkg of packages) {
|
|
96
|
+
const currentVersion = pkg.packageJson.version;
|
|
97
|
+
const newVersion = await generateNewVersionForPackage(pkg, options);
|
|
98
|
+
manifests.push({
|
|
99
|
+
project: pkg,
|
|
100
|
+
newVersion,
|
|
101
|
+
currentVersion,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const bumpPolicy = calBumpPolicy(options);
|
|
105
|
+
return {
|
|
106
|
+
manifests,
|
|
107
|
+
bumpPolicy,
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
exports.generatePublishManifest = generatePublishManifest;
|
|
111
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.release = release;
|
|
4
|
+
const logger_1 = require("../../utils/logger");
|
|
5
|
+
const git_1 = require("../../utils/git");
|
|
6
|
+
const exec_1 = require("../../utils/exec");
|
|
7
|
+
const release_1 = require("./release");
|
|
8
|
+
const plan_1 = require("./plan");
|
|
9
|
+
const manifest_1 = require("./manifest");
|
|
10
|
+
const git_2 = require("./git");
|
|
11
|
+
async function release(options) {
|
|
12
|
+
const { commit, dryRun = false, registry } = options;
|
|
13
|
+
// 1. 获取需要发布的包列表
|
|
14
|
+
const packagesToPublish = await (0, git_2.getPackagesToPublish)(commit);
|
|
15
|
+
if (packagesToPublish.length === 0) {
|
|
16
|
+
logger_1.logger.warn('No packages to publish');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// 2. 构建发布依赖树
|
|
20
|
+
const releaseManifests = (0, manifest_1.buildReleaseManifest)(packagesToPublish);
|
|
21
|
+
logger_1.logger.info('Release manifests:');
|
|
22
|
+
logger_1.logger.info(releaseManifests
|
|
23
|
+
.map(manifest => `${manifest.project.packageName}@${manifest.version}`)
|
|
24
|
+
.join(', '), false);
|
|
25
|
+
const branchName = await (0, git_1.getCurrentBranchName)();
|
|
26
|
+
(0, plan_1.checkReleasePlan)(releaseManifests, branchName);
|
|
27
|
+
await (0, exec_1.exec)(`git checkout ${commit}`);
|
|
28
|
+
await (0, release_1.releasePackages)(releaseManifests, { commit, dryRun, registry });
|
|
29
|
+
logger_1.logger.success('All packages published successfully!');
|
|
30
|
+
logger_1.logger.success(releaseManifests
|
|
31
|
+
.map(manifest => `- ${manifest.project.packageName}@${manifest.version}`)
|
|
32
|
+
.join('\n'), false);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPackagesToPublish = void 0;
|
|
4
|
+
const exec_1 = require("../../utils/exec");
|
|
5
|
+
/**
|
|
6
|
+
* 从 git tag 中解析需要发布的包信息
|
|
7
|
+
*/
|
|
8
|
+
const getPackagesToPublish = async (commit) => {
|
|
9
|
+
// 获取指定 commit 的所有 tag
|
|
10
|
+
const { stdout } = await (0, exec_1.exec)(`git tag --points-at ${commit}`);
|
|
11
|
+
const tags = stdout.split('\n').filter(Boolean);
|
|
12
|
+
// 解析符合 v/{packagename}@{version} 格式的 tag
|
|
13
|
+
const packagePattern = /^v\/(.+)@(.+)$/;
|
|
14
|
+
const packages = [];
|
|
15
|
+
for (const tag of tags) {
|
|
16
|
+
const match = tag.match(packagePattern);
|
|
17
|
+
if (match) {
|
|
18
|
+
const [, packageName, version] = match;
|
|
19
|
+
packages.push({
|
|
20
|
+
packageName,
|
|
21
|
+
version,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return packages;
|
|
26
|
+
};
|
|
27
|
+
exports.getPackagesToPublish = getPackagesToPublish;
|
|
28
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installAction = void 0;
|
|
4
|
+
const logger_1 = require("../../utils/logger");
|
|
5
|
+
const action_1 = require("./action");
|
|
6
|
+
const installAction = (program) => {
|
|
7
|
+
program
|
|
8
|
+
.command('release')
|
|
9
|
+
.description('Release packages based on git tags.')
|
|
10
|
+
.requiredOption('--commit <string>', '需要执行发布的 commit id')
|
|
11
|
+
.option('--dry-run', '是否只执行不真实发布', false)
|
|
12
|
+
.option('-r, --registry <string>', '发布到的 registry', 'https://registry.npmjs.org')
|
|
13
|
+
.action(async (options) => {
|
|
14
|
+
try {
|
|
15
|
+
if (!options.commit) {
|
|
16
|
+
throw new Error('请提供需要发布的 commit id');
|
|
17
|
+
}
|
|
18
|
+
if (!process.env.NODE_AUTH_TOKEN) {
|
|
19
|
+
throw new Error('请设置 NODE_AUTH_TOKEN 环境变量');
|
|
20
|
+
}
|
|
21
|
+
await (0, action_1.release)(options);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
logger_1.logger.error('Release failed!');
|
|
25
|
+
logger_1.logger.error(error.message);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
exports.installAction = installAction;
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildReleaseManifest = buildReleaseManifest;
|
|
4
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
5
|
+
/**
|
|
6
|
+
* 构建发布依赖树
|
|
7
|
+
*/
|
|
8
|
+
function buildReleaseManifest(packages) {
|
|
9
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
10
|
+
return packages.map(pkg => {
|
|
11
|
+
const project = rushConfiguration.getProjectByName(pkg.packageName);
|
|
12
|
+
if (!project) {
|
|
13
|
+
throw new Error(`Cannot find project: ${pkg.packageName}`);
|
|
14
|
+
}
|
|
15
|
+
return { project, version: project.packageJson.version };
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=manifest.js.map
|