@coze-arch/rush-publish-plugin 0.0.1-alpha.7aa19e
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/dist/action/change/action.d.ts +2 -0
- package/dist/action/change/action.js +40 -0
- package/dist/action/change/amend-commit.d.ts +1 -0
- package/dist/action/change/amend-commit.js +23 -0
- package/dist/action/change/helper.d.ts +33 -0
- package/dist/action/change/helper.js +126 -0
- package/dist/action/change/index.d.ts +2 -0
- package/dist/action/change/index.js +17 -0
- package/dist/action/change/types.d.ts +5 -0
- package/dist/action/change/types.js +3 -0
- package/dist/action/publish/action.d.ts +2 -0
- package/dist/action/publish/action.js +68 -0
- package/dist/action/publish/apply-new-version.d.ts +2 -0
- package/dist/action/publish/apply-new-version.js +27 -0
- package/dist/action/publish/changelog.d.ts +2 -0
- package/dist/action/publish/changelog.js +79 -0
- package/dist/action/publish/confirm.d.ts +2 -0
- package/dist/action/publish/confirm.js +31 -0
- package/dist/action/publish/const.d.ts +1 -0
- package/dist/action/publish/const.js +5 -0
- package/dist/action/publish/git.d.ts +20 -0
- package/dist/action/publish/git.js +33 -0
- package/dist/action/publish/index.d.ts +2 -0
- package/dist/action/publish/index.js +43 -0
- package/dist/action/publish/packages.d.ts +3 -0
- package/dist/action/publish/packages.js +67 -0
- package/dist/action/publish/push-to-remote.d.ts +13 -0
- package/dist/action/publish/push-to-remote.js +105 -0
- package/dist/action/publish/request-bump-type.d.ts +5 -0
- package/dist/action/publish/request-bump-type.js +56 -0
- package/dist/action/publish/types.d.ts +25 -0
- package/dist/action/publish/types.js +12 -0
- package/dist/action/publish/version.d.ts +16 -0
- package/dist/action/publish/version.js +111 -0
- package/dist/action/release/action.d.ts +2 -0
- package/dist/action/release/action.js +34 -0
- package/dist/action/release/git.d.ts +5 -0
- package/dist/action/release/git.js +28 -0
- package/dist/action/release/index.d.ts +2 -0
- package/dist/action/release/index.js +31 -0
- package/dist/action/release/manifest.d.ts +5 -0
- package/dist/action/release/manifest.js +18 -0
- package/dist/action/release/package.d.ts +2 -0
- package/dist/action/release/package.js +49 -0
- package/dist/action/release/plan.d.ts +8 -0
- package/dist/action/release/plan.js +37 -0
- package/dist/action/release/release.d.ts +2 -0
- package/dist/action/release/release.js +50 -0
- package/dist/action/release/types.d.ts +14 -0
- package/dist/action/release/types.js +3 -0
- package/dist/generate-changelog/generate-changelog.d.ts +49 -0
- package/dist/generate-changelog/generate-changelog.js +127 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +28 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +3 -0
- package/dist/utils/exec.d.ts +7 -0
- package/dist/utils/exec.js +24 -0
- package/dist/utils/fs.d.ts +4 -0
- package/dist/utils/fs.js +27 -0
- package/dist/utils/get-rush-config.d.ts +2 -0
- package/dist/utils/get-rush-config.js +16 -0
- package/dist/utils/git.d.ts +19 -0
- package/dist/utils/git.js +70 -0
- package/dist/utils/logger.d.ts +58 -0
- package/dist/utils/logger.js +136 -0
- package/dist/utils/random.d.ts +6 -0
- package/dist/utils/random.js +19 -0
- package/dist/utils/whoami.d.ts +4 -0
- package/dist/utils/whoami.js +16 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @coze-arch/rush-change-plugin
|
|
@@ -0,0 +1,40 @@
|
|
|
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.generateChangeFiles = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const logger_1 = require("../../utils/logger");
|
|
10
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
11
|
+
const helper_1 = require("./helper");
|
|
12
|
+
const amend_commit_1 = require("./amend-commit");
|
|
13
|
+
const generateChangeFiles = async (options) => {
|
|
14
|
+
// CI 环境的提交不做处理
|
|
15
|
+
if (options.ci || process.env.CI === 'true') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (options.amendCommit) {
|
|
19
|
+
(0, amend_commit_1.amendCommit)();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
let { commitMsg } = options;
|
|
24
|
+
if (!commitMsg) {
|
|
25
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
26
|
+
commitMsg = await promises_1.default.readFile(path_1.default.resolve(rushConfiguration.rushJsonFolder, '.git/COMMIT_EDITMSG'), 'utf-8');
|
|
27
|
+
}
|
|
28
|
+
const { content, type } = await (0, helper_1.analysisCommitMsg)(commitMsg);
|
|
29
|
+
if (!content) {
|
|
30
|
+
logger_1.logger.warn('Invalid subject');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
(0, helper_1.generateAllChangesFile)(content, type);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
logger_1.logger.error(`Generate changes file fail \n ${e}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.generateChangeFiles = generateChangeFiles;
|
|
40
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const amendCommit: () => Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.amendCommit = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const git_1 = require("../../utils/git");
|
|
9
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
10
|
+
const exec_1 = require("../../utils/exec");
|
|
11
|
+
const amendCommit = async () => {
|
|
12
|
+
const changedFiles = await (0, git_1.getChangedFilesFromCached)();
|
|
13
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
14
|
+
const relativeChangesFolder = path_1.default.relative(rushConfiguration.rushJsonFolder, rushConfiguration.changesFolder);
|
|
15
|
+
for (const file of changedFiles) {
|
|
16
|
+
if (file.startsWith(relativeChangesFolder)) {
|
|
17
|
+
await (0, exec_1.exec)('git commit --amend --no-edit -n');
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.amendCommit = amendCommit;
|
|
23
|
+
//# sourceMappingURL=amend-commit.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type RushConfigurationProject } from '@rushstack/rush-sdk';
|
|
2
|
+
import type { Commit, Parser, ParserOptions } from '@commitlint/types';
|
|
3
|
+
/**
|
|
4
|
+
* 收集需要更新 changes 的包
|
|
5
|
+
* @returns RushConfigurationProject[]
|
|
6
|
+
*/
|
|
7
|
+
export declare const collectShouldUpdateChangesProjects: () => Promise<RushConfigurationProject[]>;
|
|
8
|
+
/**
|
|
9
|
+
* 解析 commit-mag
|
|
10
|
+
* @param message
|
|
11
|
+
* @param parser
|
|
12
|
+
* @param parserOpts
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseCommit(message: string, parser?: Parser, parserOpts?: ParserOptions): Promise<Commit>;
|
|
16
|
+
/**
|
|
17
|
+
* 生成可能更新的版本类型
|
|
18
|
+
* @param commits
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function whatBump(commits: Commit[]): {
|
|
22
|
+
level: number;
|
|
23
|
+
releaseType: string;
|
|
24
|
+
reason: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function analysisCommitMsg(msg: string): Promise<{
|
|
27
|
+
type: string;
|
|
28
|
+
content: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* 生成 changes
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateAllChangesFile(comment: string, patchType: string): Promise<void>;
|
|
@@ -0,0 +1,126 @@
|
|
|
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.collectShouldUpdateChangesProjects = void 0;
|
|
7
|
+
exports.parseCommit = parseCommit;
|
|
8
|
+
exports.whatBump = whatBump;
|
|
9
|
+
exports.analysisCommitMsg = analysisCommitMsg;
|
|
10
|
+
exports.generateAllChangesFile = generateAllChangesFile;
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const ChangeFile_1 = require("@rushstack/rush-sdk/lib/api/ChangeFile");
|
|
13
|
+
const whoami_1 = require("../../utils/whoami");
|
|
14
|
+
const logger_1 = require("../../utils/logger");
|
|
15
|
+
const git_1 = require("../../utils/git");
|
|
16
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
17
|
+
const exec_1 = require("../../utils/exec");
|
|
18
|
+
// 这两个包没有 module 导出
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
20
|
+
const { sync } = require('conventional-commits-parser');
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
22
|
+
const defaultChangelogOpts = require('conventional-changelog-angular');
|
|
23
|
+
const VERSIONS = ['major', 'minor', 'patch'];
|
|
24
|
+
/**
|
|
25
|
+
* 收集需要更新 changes 的包
|
|
26
|
+
* @returns RushConfigurationProject[]
|
|
27
|
+
*/
|
|
28
|
+
const collectShouldUpdateChangesProjects = async () => {
|
|
29
|
+
const changedFiles = await (0, git_1.getChangedFilesFromCached)();
|
|
30
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
31
|
+
const lookup = rushConfiguration.getProjectLookupForRoot(rushConfiguration.rushJsonFolder);
|
|
32
|
+
const relativeChangesFolder = path_1.default.relative(rushConfiguration.rushJsonFolder, rushConfiguration.changesFolder);
|
|
33
|
+
const ignorePackage = [];
|
|
34
|
+
const shouldUpdateChangesProjects = new Set();
|
|
35
|
+
for (const file of changedFiles) {
|
|
36
|
+
// 收集有 common/changes 下变更的包
|
|
37
|
+
if (file.startsWith(relativeChangesFolder)) {
|
|
38
|
+
const packageName = path_1.default.relative(relativeChangesFolder, path_1.default.dirname(file));
|
|
39
|
+
ignorePackage.push(packageName);
|
|
40
|
+
}
|
|
41
|
+
const project = lookup.findChildPath(file);
|
|
42
|
+
// 按是否发布提取相关包信息,同时过滤掉changes包含在本次变更内的文件(该策略是手动更改优先级大于自动生成)
|
|
43
|
+
if (project && !ignorePackage.includes(project.packageName)) {
|
|
44
|
+
if (!shouldUpdateChangesProjects.has(project) && project.shouldPublish) {
|
|
45
|
+
shouldUpdateChangesProjects.add(project);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [...shouldUpdateChangesProjects];
|
|
50
|
+
};
|
|
51
|
+
exports.collectShouldUpdateChangesProjects = collectShouldUpdateChangesProjects;
|
|
52
|
+
/**
|
|
53
|
+
* 解析 commit-mag
|
|
54
|
+
* @param message
|
|
55
|
+
* @param parser
|
|
56
|
+
* @param parserOpts
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
// https://github.com/conventional-changelog/commitlint/blob/8b8a6e62f57511c0be05346d14959247851cdfeb/%40commitlint/parse/src/index.ts#L6
|
|
60
|
+
async function parseCommit(message, parser = sync, parserOpts) {
|
|
61
|
+
const defaultOpts = (await defaultChangelogOpts).parserOpts;
|
|
62
|
+
const opts = {
|
|
63
|
+
...defaultOpts,
|
|
64
|
+
...(parserOpts || {}),
|
|
65
|
+
fieldPattern: null,
|
|
66
|
+
};
|
|
67
|
+
const parsed = parser(message, opts);
|
|
68
|
+
parsed.raw = message;
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 生成可能更新的版本类型
|
|
73
|
+
* @param commits
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
// https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-recommended-bump/index.js
|
|
77
|
+
function whatBump(commits) {
|
|
78
|
+
const DEFAULT_LEVEL = 2;
|
|
79
|
+
let level = DEFAULT_LEVEL;
|
|
80
|
+
let breakings = 0;
|
|
81
|
+
let features = 0;
|
|
82
|
+
commits.forEach(commit => {
|
|
83
|
+
if (commit.notes.length > 0) {
|
|
84
|
+
breakings += commit.notes.length;
|
|
85
|
+
level = 0;
|
|
86
|
+
}
|
|
87
|
+
else if (commit.type === 'feat') {
|
|
88
|
+
features += 1;
|
|
89
|
+
if (level === DEFAULT_LEVEL) {
|
|
90
|
+
level = 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
level,
|
|
96
|
+
releaseType: VERSIONS[level],
|
|
97
|
+
reason: breakings === 1
|
|
98
|
+
? `There is ${breakings} BREAKING CHANGE and ${features} features`
|
|
99
|
+
: `There are ${breakings} BREAKING CHANGES and ${features} features`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function analysisCommitMsg(msg) {
|
|
103
|
+
const parsedCommit = await parseCommit(msg);
|
|
104
|
+
const bumpInfo = whatBump([parsedCommit]);
|
|
105
|
+
return { type: bumpInfo.releaseType, content: parsedCommit.subject || '' };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 生成 changes
|
|
109
|
+
*/
|
|
110
|
+
async function generateAllChangesFile(comment, patchType) {
|
|
111
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
112
|
+
const needUpdateProjects = await (0, exports.collectShouldUpdateChangesProjects)();
|
|
113
|
+
const { email } = await (0, whoami_1.whoAmI)();
|
|
114
|
+
// 重新组织已有 change 文件和待新增的 change
|
|
115
|
+
for (const project of needUpdateProjects) {
|
|
116
|
+
const { packageName } = project;
|
|
117
|
+
// TODO: ChangeFile 需要的 IChangeInfo 类型和当前规范存在属性差异,暂时先忽略 email
|
|
118
|
+
const changeFile = new ChangeFile_1.ChangeFile({ changes: [], packageName, email }, rushConfiguration);
|
|
119
|
+
changeFile.addChange({ packageName, comment, type: patchType });
|
|
120
|
+
changeFile.writeSync();
|
|
121
|
+
const updateChangesPath = path_1.default.resolve(rushConfiguration.changesFolder, packageName);
|
|
122
|
+
await (0, exec_1.exec)(`git add ${updateChangesPath}`);
|
|
123
|
+
logger_1.logger.success(`Success update ${packageName} changes file`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installAction = void 0;
|
|
4
|
+
const action_1 = require("./action");
|
|
5
|
+
const installAction = (program) => {
|
|
6
|
+
program
|
|
7
|
+
.command('change')
|
|
8
|
+
.description('Generate changes in a simple way.')
|
|
9
|
+
.option('-c, --commit-msg <string>', '本次提交信息,默认读取 .git/COMMIT_EDITMSG')
|
|
10
|
+
.option('-a, --amend-commit', '是否 amend commit 阶段')
|
|
11
|
+
.option('-i, --ci', '是否在 CI 环境')
|
|
12
|
+
.action(async (options) => {
|
|
13
|
+
await (0, action_1.generateChangeFiles)({ ...options });
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.installAction = installAction;
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publish = void 0;
|
|
4
|
+
const random_1 = require("../../utils/random");
|
|
5
|
+
const logger_1 = require("../../utils/logger");
|
|
6
|
+
const git_1 = require("../../utils/git");
|
|
7
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
8
|
+
const version_1 = require("./version");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const push_to_remote_1 = require("./push-to-remote");
|
|
11
|
+
const packages_1 = require("./packages");
|
|
12
|
+
const confirm_1 = require("./confirm");
|
|
13
|
+
const changelog_1 = require("./changelog");
|
|
14
|
+
const apply_new_version_1 = require("./apply-new-version");
|
|
15
|
+
// 针对不同类型的发布,对应不同 sideEffects:
|
|
16
|
+
// 1. alpha: 直接创建并push 分支,触发 CI,执行发布;
|
|
17
|
+
// 2. beta: 本分支直接切换版本号,并发布
|
|
18
|
+
// 3. 正式版本:发起MR,MR 合入 main 后,触发发布
|
|
19
|
+
const publish = async (options) => {
|
|
20
|
+
const sessionId = (0, random_1.randomHash)(6);
|
|
21
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
22
|
+
const rushFolder = rushConfiguration.rushJsonFolder;
|
|
23
|
+
if (process.env.SKIP_UNCOMMITTED_CHECK !== 'true') {
|
|
24
|
+
await (0, git_1.ensureNotUncommittedChanges)();
|
|
25
|
+
}
|
|
26
|
+
// 1. 验证并获取需要发布的包列表
|
|
27
|
+
const packagesToPublish = (0, packages_1.validateAndGetPackages)(options);
|
|
28
|
+
if (packagesToPublish.size === 0) {
|
|
29
|
+
logger_1.logger.error('No packages to publish, should specify some package by `--to` or `--from` or `--only`');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
logger_1.logger.debug(`Will publish the following packages:\n ${[...packagesToPublish].map(pkg => pkg.packageName).join('\n')}`);
|
|
33
|
+
// 2. 生成发布清单
|
|
34
|
+
const { manifests: publishManifests, bumpPolicy } = await (0, version_1.generatePublishManifest)(packagesToPublish, {
|
|
35
|
+
...options,
|
|
36
|
+
sessionId,
|
|
37
|
+
});
|
|
38
|
+
const isBetaPublish = [types_1.BumpType.BETA, types_1.BumpType.ALPHA].includes(bumpPolicy);
|
|
39
|
+
if (isBetaPublish === false && (await (0, git_1.isMainBranch)()) === false) {
|
|
40
|
+
// 只允许在主分支发布
|
|
41
|
+
logger_1.logger.error('You are not in main branch, please switch to main branch and try again.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const continuePublish = await (0, confirm_1.confirmForPublish)(publishManifests, !!options.dryRun);
|
|
45
|
+
if (!continuePublish) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// 3. 应用更新,注意这里会修改文件,产生 sideEffect
|
|
49
|
+
const postHandles = [apply_new_version_1.applyPublishManifest];
|
|
50
|
+
if (isBetaPublish === false) {
|
|
51
|
+
postHandles.push(changelog_1.generateChangelog);
|
|
52
|
+
}
|
|
53
|
+
const changedFiles = (await Promise.all(postHandles.map(handle => handle(publishManifests)))).flat();
|
|
54
|
+
// 4. 创建并推送发布分支
|
|
55
|
+
await (0, push_to_remote_1.pushToRemote)({
|
|
56
|
+
publishManifests,
|
|
57
|
+
bumpPolicy: bumpPolicy,
|
|
58
|
+
sessionId,
|
|
59
|
+
changedFiles,
|
|
60
|
+
cwd: rushFolder,
|
|
61
|
+
skipCommit: !!options.skipCommit,
|
|
62
|
+
skipPush: !!options.skipPush,
|
|
63
|
+
repoUrl: options.repoUrl,
|
|
64
|
+
});
|
|
65
|
+
logger_1.logger.success('Publish success.');
|
|
66
|
+
};
|
|
67
|
+
exports.publish = publish;
|
|
68
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
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.applyPublishManifest = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const logger_1 = require("../../utils/logger");
|
|
9
|
+
const fs_1 = require("../../utils/fs");
|
|
10
|
+
const updatePackageVersion = async (project, newVersion) => {
|
|
11
|
+
const packageJsonPath = path_1.default.resolve(project.projectFolder, 'package.json');
|
|
12
|
+
const packageJson = await (0, fs_1.readJsonFile)(packageJsonPath);
|
|
13
|
+
packageJson.version = newVersion;
|
|
14
|
+
await (0, fs_1.writeJsonFile)(packageJsonPath, packageJson);
|
|
15
|
+
return packageJsonPath;
|
|
16
|
+
};
|
|
17
|
+
const applyPublishManifest = async (manifests) => {
|
|
18
|
+
const modifiedFiles = await Promise.all(manifests.map(async (manifest) => {
|
|
19
|
+
const { project, newVersion } = manifest;
|
|
20
|
+
const modifiedFile = await updatePackageVersion(project, newVersion);
|
|
21
|
+
return modifiedFile;
|
|
22
|
+
}));
|
|
23
|
+
logger_1.logger.info(`Updated version for packages: ${manifests.map(m => m.project.packageName).join(', ')}`);
|
|
24
|
+
return modifiedFiles;
|
|
25
|
+
};
|
|
26
|
+
exports.applyPublishManifest = applyPublishManifest;
|
|
27
|
+
//# sourceMappingURL=apply-new-version.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
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 path_1 = __importDefault(require("path"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const get_rush_config_1 = require("../../utils/get-rush-config");
|
|
10
|
+
const fs_1 = require("../../utils/fs");
|
|
11
|
+
const generate_changelog_1 = require("../../generate-changelog/generate-changelog");
|
|
12
|
+
const deleteFiles = async (files) => {
|
|
13
|
+
await Promise.all(files.map(async (file) => {
|
|
14
|
+
await promises_1.default.unlink(file);
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
const readChangeFiles = async (changedFolderOfPkg) => {
|
|
18
|
+
if (!(await (0, fs_1.isDirExists)(changedFolderOfPkg))) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const changeFiles = (await promises_1.default.readdir(changedFolderOfPkg)).filter(r => r.endsWith('.json'));
|
|
22
|
+
return changeFiles.map(r => path_1.default.resolve(changedFolderOfPkg, r));
|
|
23
|
+
};
|
|
24
|
+
const readChanges = async (changeFiles) => {
|
|
25
|
+
const changes = (await Promise.all(changeFiles.map(async (r) => {
|
|
26
|
+
try {
|
|
27
|
+
const res = await (0, fs_1.readJsonFile)(r);
|
|
28
|
+
return res;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}))).filter(r => r !== null);
|
|
34
|
+
return changes;
|
|
35
|
+
};
|
|
36
|
+
const readPreviousChangelog = async (changelogJsonPath, packageName) => {
|
|
37
|
+
const defaultValue = {
|
|
38
|
+
name: packageName,
|
|
39
|
+
entries: [],
|
|
40
|
+
};
|
|
41
|
+
if (!(await (0, fs_1.isFileExists)(changelogJsonPath))) {
|
|
42
|
+
return defaultValue;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const changelog = await (0, fs_1.readJsonFile)(changelogJsonPath);
|
|
46
|
+
return changelog;
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
return defaultValue;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const generateChangelogForProject = async (manifest) => {
|
|
53
|
+
const { project, newVersion } = manifest;
|
|
54
|
+
const rushConfiguration = (0, get_rush_config_1.getRushConfiguration)();
|
|
55
|
+
const { changesFolder } = rushConfiguration;
|
|
56
|
+
const changedFolderOfPkg = path_1.default.resolve(changesFolder, project.packageName);
|
|
57
|
+
const changelogJsonPath = path_1.default.resolve(project.projectFolder, 'CHANGELOG.json');
|
|
58
|
+
const changelogMarkdownPath = path_1.default.resolve(project.projectFolder, 'CHANGELOG.md');
|
|
59
|
+
const changeFiles = await readChangeFiles(changedFolderOfPkg);
|
|
60
|
+
const changes = await readChanges(changeFiles);
|
|
61
|
+
const previousChangelog = await readPreviousChangelog(changelogJsonPath, project.packageName);
|
|
62
|
+
const { changelog, report: changelogMarkdown } = await (0, generate_changelog_1.generateChangelog)({
|
|
63
|
+
packageName: project.packageName,
|
|
64
|
+
version: newVersion,
|
|
65
|
+
commingChanges: changes,
|
|
66
|
+
previousChangelog,
|
|
67
|
+
});
|
|
68
|
+
// side effects
|
|
69
|
+
await (0, fs_1.writeJsonFile)(changelogJsonPath, changelog);
|
|
70
|
+
await promises_1.default.writeFile(changelogMarkdownPath, changelogMarkdown);
|
|
71
|
+
await deleteFiles(changeFiles);
|
|
72
|
+
return [changelogJsonPath, changelogMarkdownPath, ...changeFiles];
|
|
73
|
+
};
|
|
74
|
+
const generateChangelog = async (manifests) => {
|
|
75
|
+
const modifiedFiles = await Promise.all(manifests.map(manifest => generateChangelogForProject(manifest)));
|
|
76
|
+
return modifiedFiles.flat();
|
|
77
|
+
};
|
|
78
|
+
exports.generateChangelog = generateChangelog;
|
|
79
|
+
//# sourceMappingURL=changelog.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
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.confirmForPublish = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
9
|
+
const confirmForPublish = async (publishManifest, dryRun) => {
|
|
10
|
+
console.log(chalk_1.default.gray('Will publish the following packages:'));
|
|
11
|
+
publishManifest.forEach(manifest => {
|
|
12
|
+
const msg = `${manifest.project.packageName}: ${chalk_1.default.bgGreen(`${manifest.currentVersion} -> ${chalk_1.default.bold(manifest.newVersion)}`)}`;
|
|
13
|
+
console.log(`- ${msg}`);
|
|
14
|
+
});
|
|
15
|
+
if (dryRun) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
console.log('\n');
|
|
19
|
+
try {
|
|
20
|
+
const result = await (0, prompts_1.confirm)({
|
|
21
|
+
message: 'Are you sure to publish?',
|
|
22
|
+
default: true,
|
|
23
|
+
});
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.confirmForPublish = confirmForPublish;
|
|
31
|
+
//# sourceMappingURL=confirm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GIT_REPO_URL_REGEX: RegExp;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type PublishManifest } from './types';
|
|
2
|
+
export declare function createAndPushBranch(branchName: string, cwd: string): Promise<void>;
|
|
3
|
+
interface CommitChangesOptions {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
files: string[];
|
|
6
|
+
cwd: string;
|
|
7
|
+
publishManifests: PublishManifest[];
|
|
8
|
+
branchName: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function commitChanges({ sessionId, files, cwd, publishManifests, branchName, }: CommitChangesOptions): Promise<{
|
|
11
|
+
effects: string[];
|
|
12
|
+
branchName: string;
|
|
13
|
+
}>;
|
|
14
|
+
export interface PushOptions {
|
|
15
|
+
refs: string[];
|
|
16
|
+
cwd: string;
|
|
17
|
+
repoUrl: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function push({ refs, cwd, repoUrl }: PushOptions): Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -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
|