@coze-arch/rush-publish-plugin 0.0.1-alpha.bcd068 → 0.0.3-alpha.f72758
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/lib/action/publish/git.d.ts +2 -1
- package/lib/index.js +1628 -25
- package/package.json +14 -6
- package/lib/action/change/action.js +0 -40
- package/lib/action/change/amend-commit.js +0 -23
- package/lib/action/change/helper.js +0 -126
- package/lib/action/change/index.js +0 -17
- package/lib/action/change/types.js +0 -3
- package/lib/action/publish/action.js +0 -68
- package/lib/action/publish/apply-new-version.js +0 -27
- package/lib/action/publish/changelog.js +0 -79
- package/lib/action/publish/confirm.js +0 -31
- package/lib/action/publish/const.js +0 -5
- package/lib/action/publish/git.js +0 -33
- package/lib/action/publish/index.js +0 -43
- package/lib/action/publish/packages.js +0 -67
- package/lib/action/publish/push-to-remote.js +0 -105
- package/lib/action/publish/request-bump-type.js +0 -56
- package/lib/action/publish/types.js +0 -12
- package/lib/action/publish/version.js +0 -111
- package/lib/action/release/action.js +0 -34
- package/lib/action/release/git.js +0 -28
- package/lib/action/release/index.js +0 -31
- package/lib/action/release/manifest.js +0 -18
- package/lib/action/release/package.js +0 -49
- package/lib/action/release/plan.js +0 -38
- package/lib/action/release/release.js +0 -50
- package/lib/action/release/types.js +0 -3
- package/lib/generate-changelog/generate-changelog.js +0 -127
- package/lib/types.js +0 -3
- package/lib/utils/exec.js +0 -24
- package/lib/utils/get-rush-config.js +0 -16
- package/lib/utils/git.js +0 -70
- package/lib/utils/random.js +0 -19
- package/lib/utils/whoami.js +0 -16
|
@@ -1,105 +0,0 @@
|
|
|
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("@coze-arch/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
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1,111 +0,0 @@
|
|
|
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
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.release = release;
|
|
4
|
-
const logger_1 = require("@coze-arch/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
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installAction = void 0;
|
|
4
|
-
const logger_1 = require("@coze-arch/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
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1,49 +0,0 @@
|
|
|
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.applyPublishConfig = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_enhance_1 = require("@coze-arch/fs-enhance");
|
|
9
|
-
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
10
|
-
/**
|
|
11
|
-
* 更新依赖版本
|
|
12
|
-
*/
|
|
13
|
-
const updateDependencyVersions = async (packageJson) => {
|
|
14
|
-
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
15
|
-
const { dependencies } = packageJson;
|
|
16
|
-
if (dependencies) {
|
|
17
|
-
for (const [dep, ver] of Object.entries(dependencies)) {
|
|
18
|
-
const project = rushConfiguration.getProjectByName(dep);
|
|
19
|
-
if (/^workspace:/.test(ver) && project) {
|
|
20
|
-
dependencies[dep] = project.packageJson.version;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return Promise.resolve(packageJson);
|
|
25
|
-
};
|
|
26
|
-
const applyCozePublishConfig = async (packageJson) => {
|
|
27
|
-
const { cozePublishConfig } = packageJson;
|
|
28
|
-
if (cozePublishConfig) {
|
|
29
|
-
const keys = Object.keys(cozePublishConfig);
|
|
30
|
-
for (const key of keys) {
|
|
31
|
-
packageJson[key] = cozePublishConfig[key];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return Promise.resolve(packageJson);
|
|
35
|
-
};
|
|
36
|
-
const applyPublishConfig = async (project) => {
|
|
37
|
-
const jobs = [
|
|
38
|
-
updateDependencyVersions,
|
|
39
|
-
applyCozePublishConfig,
|
|
40
|
-
];
|
|
41
|
-
const packageJsonPath = path_1.default.join(project.projectFolder, 'package.json');
|
|
42
|
-
let packageJson = await (0, fs_enhance_1.readJsonFile)(packageJsonPath);
|
|
43
|
-
for (const job of jobs) {
|
|
44
|
-
packageJson = await job(packageJson);
|
|
45
|
-
}
|
|
46
|
-
await (0, fs_enhance_1.writeJsonFile)(packageJsonPath, packageJson);
|
|
47
|
-
};
|
|
48
|
-
exports.applyPublishConfig = applyPublishConfig;
|
|
49
|
-
//# sourceMappingURL=package.js.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkReleasePlan = exports.calReleaseType = exports.ReleaseType = void 0;
|
|
4
|
-
var ReleaseType;
|
|
5
|
-
(function (ReleaseType) {
|
|
6
|
-
ReleaseType["ALPHA"] = "alpha";
|
|
7
|
-
ReleaseType["BETA"] = "beta";
|
|
8
|
-
ReleaseType["LATEST"] = "latest";
|
|
9
|
-
})(ReleaseType || (exports.ReleaseType = ReleaseType = {}));
|
|
10
|
-
const calReleaseType = (version) => {
|
|
11
|
-
const tag = version.includes('alpha')
|
|
12
|
-
? ReleaseType.ALPHA
|
|
13
|
-
: version.includes('beta')
|
|
14
|
-
? ReleaseType.BETA
|
|
15
|
-
: ReleaseType.LATEST;
|
|
16
|
-
return tag;
|
|
17
|
-
};
|
|
18
|
-
exports.calReleaseType = calReleaseType;
|
|
19
|
-
const calReleasePlan = (releaseManifests) => {
|
|
20
|
-
const plan = releaseManifests.map(r => (0, exports.calReleaseType)(r.version));
|
|
21
|
-
if (plan.some(p => p === ReleaseType.LATEST)) {
|
|
22
|
-
return ReleaseType.LATEST;
|
|
23
|
-
}
|
|
24
|
-
if (plan.some(p => p === ReleaseType.BETA)) {
|
|
25
|
-
return ReleaseType.BETA;
|
|
26
|
-
}
|
|
27
|
-
return ReleaseType.ALPHA;
|
|
28
|
-
};
|
|
29
|
-
const checkReleasePlan = (releaseManifests, branchName) => {
|
|
30
|
-
const releasePlan = calReleasePlan(releaseManifests);
|
|
31
|
-
if (releasePlan === ReleaseType.LATEST &&
|
|
32
|
-
!['main', 'feat/auto-publish'].includes(branchName)) {
|
|
33
|
-
throw new Error('For LATEST release, should be on main branch only.');
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
exports.checkReleasePlan = checkReleasePlan;
|
|
38
|
-
//# sourceMappingURL=plan.js.map
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.releasePackages = void 0;
|
|
4
|
-
const logger_1 = require("@coze-arch/logger");
|
|
5
|
-
const exec_1 = require("../../utils/exec");
|
|
6
|
-
const package_1 = require("./package");
|
|
7
|
-
/**
|
|
8
|
-
* 发布包
|
|
9
|
-
*/
|
|
10
|
-
const publishPackage = async (project, releaseOptions) => {
|
|
11
|
-
const { dryRun, registry } = releaseOptions;
|
|
12
|
-
const token = process.env.NODE_AUTH_TOKEN;
|
|
13
|
-
const { version } = project.packageJson;
|
|
14
|
-
const tag = version.includes('alpha')
|
|
15
|
-
? 'alpha'
|
|
16
|
-
: version.includes('beta')
|
|
17
|
-
? 'beta'
|
|
18
|
-
: 'latest';
|
|
19
|
-
const args = [`NODE_AUTH_TOKEN=${token}`, 'npm', 'publish', `--tag ${tag}`];
|
|
20
|
-
if (dryRun) {
|
|
21
|
-
args.push('--dry-run');
|
|
22
|
-
}
|
|
23
|
-
if (registry) {
|
|
24
|
-
args.push(`--registry=${registry}`);
|
|
25
|
-
}
|
|
26
|
-
await (0, exec_1.exec)(args.join(' '), {
|
|
27
|
-
cwd: project.projectFolder,
|
|
28
|
-
});
|
|
29
|
-
logger_1.logger.success(`- Published ${project.packageName}@${version}`);
|
|
30
|
-
};
|
|
31
|
-
const releasePackage = async (releaseManifest, releaseOptions) => {
|
|
32
|
-
const { project } = releaseManifest;
|
|
33
|
-
const { packageName } = project;
|
|
34
|
-
logger_1.logger.info(`Preparing release for package: ${packageName}`);
|
|
35
|
-
await (0, package_1.applyPublishConfig)(project);
|
|
36
|
-
await publishPackage(project, releaseOptions);
|
|
37
|
-
};
|
|
38
|
-
const buildProjects = async (releaseManifests) => {
|
|
39
|
-
const packageNames = releaseManifests.map(manifest => manifest.project.packageName);
|
|
40
|
-
const buildCommands = `rush build ${packageNames.map(name => `--to ${name}`).join(' ')}`;
|
|
41
|
-
await (0, exec_1.exec)(buildCommands);
|
|
42
|
-
};
|
|
43
|
-
const releasePackages = async (releaseManifests, releaseOptions) => {
|
|
44
|
-
await buildProjects(releaseManifests);
|
|
45
|
-
await Promise.all(releaseManifests.map(async (manifest) => {
|
|
46
|
-
await releasePackage(manifest, releaseOptions);
|
|
47
|
-
}));
|
|
48
|
-
};
|
|
49
|
-
exports.releasePackages = releasePackages;
|
|
50
|
-
//# sourceMappingURL=release.js.map
|
|
@@ -1,127 +0,0 @@
|
|
|
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.generateChangelog = void 0;
|
|
7
|
-
const semver_1 = __importDefault(require("semver"));
|
|
8
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
|
-
/**
|
|
10
|
-
* Convert change type to corresponding title
|
|
11
|
-
*/
|
|
12
|
-
const getChangeTypeTitle = (type) => {
|
|
13
|
-
switch (type) {
|
|
14
|
-
case 'major':
|
|
15
|
-
return '### Breaking Changes';
|
|
16
|
-
case 'minor':
|
|
17
|
-
return '### New Features';
|
|
18
|
-
case 'patch':
|
|
19
|
-
return '### Bug Fixes';
|
|
20
|
-
case 'dependency':
|
|
21
|
-
return '### Dependencies';
|
|
22
|
-
case 'none':
|
|
23
|
-
return '### Other Changes';
|
|
24
|
-
default:
|
|
25
|
-
return '';
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Generate changelog for a single version
|
|
30
|
-
*/
|
|
31
|
-
const generateVersionChangelog = ({ version, changes, tag, defaultChangelog, }) => {
|
|
32
|
-
// Group changes by type
|
|
33
|
-
const groupedChanges = changes.length > 0
|
|
34
|
-
? changes.reduce((acc, change) => {
|
|
35
|
-
const { type, comment, customFields } = change;
|
|
36
|
-
if (!acc[type]) {
|
|
37
|
-
acc[type] = [];
|
|
38
|
-
}
|
|
39
|
-
const node = acc[type];
|
|
40
|
-
if (node.some(existing => existing.comment === comment) === false) {
|
|
41
|
-
node.push({
|
|
42
|
-
comment,
|
|
43
|
-
customFields,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return acc;
|
|
47
|
-
}, {})
|
|
48
|
-
: { none: [{ comment: defaultChangelog }] };
|
|
49
|
-
return {
|
|
50
|
-
version,
|
|
51
|
-
tag,
|
|
52
|
-
date: (0, dayjs_1.default)().toISOString(),
|
|
53
|
-
comments: groupedChanges,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Convert changelog to Markdown format
|
|
58
|
-
*/
|
|
59
|
-
const changelogToMarkdown = (changelog) => {
|
|
60
|
-
const lines = [];
|
|
61
|
-
lines.push(`# ${changelog.name}`);
|
|
62
|
-
lines.push('');
|
|
63
|
-
changelog.entries.forEach(entry => {
|
|
64
|
-
lines.push(`## ${entry.version} - ${(0, dayjs_1.default)(entry.date).format('YYYY-MM-DD')}`);
|
|
65
|
-
lines.push('');
|
|
66
|
-
// Output different types of changes in fixed order
|
|
67
|
-
const typeOrder = [
|
|
68
|
-
'major',
|
|
69
|
-
'minor',
|
|
70
|
-
'patch',
|
|
71
|
-
'dependency',
|
|
72
|
-
'none',
|
|
73
|
-
];
|
|
74
|
-
typeOrder.forEach(type => {
|
|
75
|
-
const changes = entry.comments[type];
|
|
76
|
-
if (changes?.length) {
|
|
77
|
-
lines.push(getChangeTypeTitle(type));
|
|
78
|
-
lines.push('');
|
|
79
|
-
changes.forEach(change => {
|
|
80
|
-
lines.push(`- ${change.comment}`);
|
|
81
|
-
// Add custom fields to changelog if they exist
|
|
82
|
-
if (change.customFields) {
|
|
83
|
-
Object.entries(change.customFields).forEach(([key, value]) => {
|
|
84
|
-
lines.push(` - ${key}: ${value}`);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
lines.push('');
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
lines.push('');
|
|
92
|
-
});
|
|
93
|
-
return lines.join('\n');
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Merge and generate changelog
|
|
97
|
-
*/
|
|
98
|
-
const generateChangelog = ({ commingChanges, previousChangelog, version, packageName, tag, defaultChangelog = 'Publish for noop', }) => {
|
|
99
|
-
// Create new changelog entry
|
|
100
|
-
const newEntry = generateVersionChangelog({
|
|
101
|
-
version,
|
|
102
|
-
changes: commingChanges.flatMap(r => r.changes),
|
|
103
|
-
tag: tag || 'HEAD',
|
|
104
|
-
defaultChangelog,
|
|
105
|
-
});
|
|
106
|
-
const allEntries = (previousChangelog ? [newEntry, ...previousChangelog.entries] : [newEntry]).sort((a, b) => {
|
|
107
|
-
// Handle invalid version numbers
|
|
108
|
-
if (!semver_1.default.valid(a.version) || !semver_1.default.valid(b.version)) {
|
|
109
|
-
return 0;
|
|
110
|
-
}
|
|
111
|
-
// Use semver.rcompare for descending sort (newer versions first)
|
|
112
|
-
return semver_1.default.rcompare(a.version, b.version);
|
|
113
|
-
});
|
|
114
|
-
// Merge with existing changelog
|
|
115
|
-
const changelog = {
|
|
116
|
-
name: packageName,
|
|
117
|
-
entries: allEntries,
|
|
118
|
-
};
|
|
119
|
-
// Convert to markdown
|
|
120
|
-
const markdown = changelogToMarkdown(changelog);
|
|
121
|
-
return {
|
|
122
|
-
changelog,
|
|
123
|
-
report: markdown,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
exports.generateChangelog = generateChangelog;
|
|
127
|
-
//# sourceMappingURL=generate-changelog.js.map
|
package/lib/types.js
DELETED