@coze-arch/rush-publish-plugin 0.0.1-alpha.4a0c61
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 +38 -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/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/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 +71 -0
- package/rush-plugin-manifest.json +10 -0
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ReleaseManifest } from './types';
|
|
2
|
+
export declare enum ReleaseType {
|
|
3
|
+
ALPHA = "alpha",
|
|
4
|
+
BETA = "beta",
|
|
5
|
+
LATEST = "latest"
|
|
6
|
+
}
|
|
7
|
+
export declare const calReleaseType: (version: string) => ReleaseType;
|
|
8
|
+
export declare const checkReleasePlan: (releaseManifests: ReleaseManifest[], branchName: string) => boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
|
@@ -0,0 +1,50 @@
|
|
|
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.NPM_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 = [`NPM_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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RushConfigurationProject } from '@rushstack/rush-sdk';
|
|
2
|
+
export interface ReleaseOptions {
|
|
3
|
+
commit: string;
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
registry: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PackageToPublish {
|
|
8
|
+
packageName: string;
|
|
9
|
+
version: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ReleaseManifest {
|
|
12
|
+
project: RushConfigurationProject;
|
|
13
|
+
version: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
interface ChangeLogComment {
|
|
2
|
+
comment: string;
|
|
3
|
+
author?: string;
|
|
4
|
+
commit?: string;
|
|
5
|
+
customFields?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
interface ChangeLogEntry {
|
|
8
|
+
version: string;
|
|
9
|
+
tag: string;
|
|
10
|
+
date: string;
|
|
11
|
+
comments: {
|
|
12
|
+
major?: ChangeLogComment[];
|
|
13
|
+
minor?: ChangeLogComment[];
|
|
14
|
+
patch?: ChangeLogComment[];
|
|
15
|
+
dependency?: ChangeLogComment[];
|
|
16
|
+
none?: ChangeLogComment[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface ChangeLog {
|
|
20
|
+
name: string;
|
|
21
|
+
entries: ChangeLogEntry[];
|
|
22
|
+
}
|
|
23
|
+
interface Change {
|
|
24
|
+
packageName: string;
|
|
25
|
+
comment: string;
|
|
26
|
+
type: 'none' | 'dependency' | 'patch' | 'minor' | 'major';
|
|
27
|
+
customFields?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
export interface ChangeFile {
|
|
30
|
+
changes: Change[];
|
|
31
|
+
packageName: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
}
|
|
34
|
+
interface GenerateChangelogOptions {
|
|
35
|
+
packageName: string;
|
|
36
|
+
version: string;
|
|
37
|
+
commingChanges: ChangeFile[];
|
|
38
|
+
previousChangelog?: ChangeLog;
|
|
39
|
+
defaultChangelog?: string;
|
|
40
|
+
tag?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Merge and generate changelog
|
|
44
|
+
*/
|
|
45
|
+
export declare const generateChangelog: ({ commingChanges, previousChangelog, version, packageName, tag, defaultChangelog, }: GenerateChangelogOptions) => {
|
|
46
|
+
changelog: ChangeLog;
|
|
47
|
+
report: string;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const release_1 = require("./action/release");
|
|
10
|
+
const publish_1 = require("./action/publish");
|
|
11
|
+
const change_1 = require("./action/change");
|
|
12
|
+
const main = () => {
|
|
13
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../package.json'), 'utf8'));
|
|
14
|
+
const program = new commander_1.Command();
|
|
15
|
+
program
|
|
16
|
+
.name(packageJson.name)
|
|
17
|
+
.description(packageJson.description)
|
|
18
|
+
.version(packageJson.version)
|
|
19
|
+
.showSuggestionAfterError(true)
|
|
20
|
+
.showHelpAfterError(true);
|
|
21
|
+
const actions = [change_1.installAction, release_1.installAction, publish_1.installAction];
|
|
22
|
+
actions.forEach(a => {
|
|
23
|
+
a(program);
|
|
24
|
+
});
|
|
25
|
+
program.parse();
|
|
26
|
+
};
|
|
27
|
+
main();
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
package/lib/types.d.ts
ADDED
package/lib/types.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exec = void 0;
|
|
4
|
+
const shelljs_1 = require("shelljs");
|
|
5
|
+
class ExecError extends Error {
|
|
6
|
+
constructor(result) {
|
|
7
|
+
super(result.stderr || result.stdout);
|
|
8
|
+
this.code = result.code;
|
|
9
|
+
this.stderr = result.stderr;
|
|
10
|
+
this.stdout = result.stdout;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const exec = (cmd, options = { silent: true }) => new Promise((r, j) => {
|
|
14
|
+
(0, shelljs_1.exec)(cmd, options, (code, stdout, stderr) => {
|
|
15
|
+
if (code === 0) {
|
|
16
|
+
r({ code, stdout, stderr });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
j(new ExecError({ code, stderr, stdout }));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
exports.exec = exec;
|
|
24
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRushConfiguration = void 0;
|
|
4
|
+
const rush_sdk_1 = require("@rushstack/rush-sdk");
|
|
5
|
+
exports.getRushConfiguration = (() => {
|
|
6
|
+
let rushConfiguration = null;
|
|
7
|
+
return (useCache = true) => {
|
|
8
|
+
if (!useCache) {
|
|
9
|
+
rushConfiguration = null;
|
|
10
|
+
}
|
|
11
|
+
return (rushConfiguration || (rushConfiguration = rush_sdk_1.RushConfiguration.loadFromDefaultLocation({
|
|
12
|
+
startingFolder: process.cwd(),
|
|
13
|
+
})));
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
//# sourceMappingURL=get-rush-config.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const getChangedFilesFromCached: () => Promise<string[]>;
|
|
2
|
+
/**
|
|
3
|
+
* 获取当前分支名称
|
|
4
|
+
* @returns string
|
|
5
|
+
*/
|
|
6
|
+
export declare const getCurrentBranchName: () => Promise<string>;
|
|
7
|
+
export declare const isMainBranch: () => Promise<boolean>;
|
|
8
|
+
export declare const getChangedFiles: () => Promise<string[]>;
|
|
9
|
+
/**
|
|
10
|
+
* 确保没有未提交的变更
|
|
11
|
+
*/
|
|
12
|
+
export declare const ensureNotUncommittedChanges: () => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* 获取当前 Git 仓库设置的 origin 远程源地址
|
|
15
|
+
* @param cwd 当前工作目录
|
|
16
|
+
* @returns origin 远程源地址
|
|
17
|
+
*/
|
|
18
|
+
export declare const getCurrentOrigin: (cwd?: string) => Promise<string | undefined>;
|
|
19
|
+
export declare const convertGitSchemaToHttp: (gitUrl: string) => string;
|
package/lib/utils/git.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertGitSchemaToHttp = exports.getCurrentOrigin = exports.ensureNotUncommittedChanges = exports.getChangedFiles = exports.isMainBranch = exports.getCurrentBranchName = exports.getChangedFilesFromCached = void 0;
|
|
4
|
+
const exec_1 = require("./exec");
|
|
5
|
+
const serializeFilesName = (output) => output
|
|
6
|
+
.split('\n')
|
|
7
|
+
.map(line => {
|
|
8
|
+
if (line) {
|
|
9
|
+
const trimmedLine = line.trim();
|
|
10
|
+
return trimmedLine;
|
|
11
|
+
}
|
|
12
|
+
return '';
|
|
13
|
+
})
|
|
14
|
+
.filter(line => line && line.length > 0);
|
|
15
|
+
const getChangedFilesFromCached = async () => {
|
|
16
|
+
const output = await (0, exec_1.exec)('git diff --name-only --diff-filter=ACMR --cached');
|
|
17
|
+
if (!output) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
return serializeFilesName(output.stdout);
|
|
21
|
+
};
|
|
22
|
+
exports.getChangedFilesFromCached = getChangedFilesFromCached;
|
|
23
|
+
/**
|
|
24
|
+
* 获取当前分支名称
|
|
25
|
+
* @returns string
|
|
26
|
+
*/
|
|
27
|
+
const getCurrentBranchName = async () => {
|
|
28
|
+
const { stdout } = await (0, exec_1.exec)('git rev-parse --abbrev-ref HEAD');
|
|
29
|
+
return stdout.trim();
|
|
30
|
+
};
|
|
31
|
+
exports.getCurrentBranchName = getCurrentBranchName;
|
|
32
|
+
const isMainBranch = async () => {
|
|
33
|
+
const currentBranchName = await (0, exports.getCurrentBranchName)();
|
|
34
|
+
return currentBranchName === 'main';
|
|
35
|
+
};
|
|
36
|
+
exports.isMainBranch = isMainBranch;
|
|
37
|
+
const getChangedFiles = async () => {
|
|
38
|
+
const output = await (0, exec_1.exec)('git diff --name-only --diff-filter=ACMR');
|
|
39
|
+
return serializeFilesName(output.stdout);
|
|
40
|
+
};
|
|
41
|
+
exports.getChangedFiles = getChangedFiles;
|
|
42
|
+
/**
|
|
43
|
+
* 确保没有未提交的变更
|
|
44
|
+
*/
|
|
45
|
+
const ensureNotUncommittedChanges = async () => {
|
|
46
|
+
const changedFiles = (await Promise.all([(0, exports.getChangedFilesFromCached)(), (0, exports.getChangedFiles)()])).flat();
|
|
47
|
+
if (changedFiles.length > 0) {
|
|
48
|
+
throw new Error('There are uncommitted changes in the working tree, please commit them first.');
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
exports.ensureNotUncommittedChanges = ensureNotUncommittedChanges;
|
|
53
|
+
/**
|
|
54
|
+
* 获取当前 Git 仓库设置的 origin 远程源地址
|
|
55
|
+
* @param cwd 当前工作目录
|
|
56
|
+
* @returns origin 远程源地址
|
|
57
|
+
*/
|
|
58
|
+
const getCurrentOrigin = async (cwd = process.cwd()) => {
|
|
59
|
+
try {
|
|
60
|
+
const { stdout } = await (0, exec_1.exec)('git remote get-url origin', { cwd });
|
|
61
|
+
return stdout.trim();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.getCurrentOrigin = getCurrentOrigin;
|
|
68
|
+
const convertGitSchemaToHttp = (gitUrl) => gitUrl.replace('git@', 'https://').replace(':', '/').replace('.git', '');
|
|
69
|
+
exports.convertGitSchemaToHttp = convertGitSchemaToHttp;
|
|
70
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
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.randomHash = randomHash;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
/**
|
|
9
|
+
* 生成指定长度的随机字符串(使用 crypto 模块)
|
|
10
|
+
* @param digit 字符串长度
|
|
11
|
+
* @returns 随机字符串
|
|
12
|
+
*/
|
|
13
|
+
function randomHash(digit) {
|
|
14
|
+
return crypto_1.default
|
|
15
|
+
.randomBytes(Math.ceil(digit / 2))
|
|
16
|
+
.toString('hex')
|
|
17
|
+
.slice(0, digit);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whoAmI = void 0;
|
|
4
|
+
const exec_1 = require("./exec");
|
|
5
|
+
const whoAmI = async () => {
|
|
6
|
+
const [name, email] = await Promise.all([
|
|
7
|
+
(0, exec_1.exec)('git config user.name', { cwd: __dirname, silent: true }),
|
|
8
|
+
(0, exec_1.exec)('git config user.email', { cwd: __dirname, silent: true }),
|
|
9
|
+
]);
|
|
10
|
+
return {
|
|
11
|
+
name: name.stdout.toString().replace('\n', ''),
|
|
12
|
+
email: email.stdout.toString().replace('\n', ''),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.whoAmI = whoAmI;
|
|
16
|
+
//# sourceMappingURL=whoami.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coze-arch/rush-publish-plugin",
|
|
3
|
+
"version": "0.0.1-alpha.4a0c61",
|
|
4
|
+
"description": "rush plugin to generate change log and publish packages",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rush",
|
|
7
|
+
"plugin",
|
|
8
|
+
"command",
|
|
9
|
+
"release",
|
|
10
|
+
"publish"
|
|
11
|
+
],
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"author": "tecvan.fe@gmail.com",
|
|
14
|
+
"maintainers": [],
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"bin": {
|
|
17
|
+
"rush-publish": "./lib/index.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib",
|
|
21
|
+
"!**/*.tsbuildinfo",
|
|
22
|
+
"!**/*.map",
|
|
23
|
+
"command-line.json",
|
|
24
|
+
"rush-plugin-manifest.json"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -b tsconfig.build.json",
|
|
28
|
+
"lint": "eslint ./ --cache",
|
|
29
|
+
"test": "vitest --run --passWithNoTests",
|
|
30
|
+
"test:cov": "npm run test -- --coverage"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@coze-arch/fs-enhance": "0.0.1",
|
|
34
|
+
"@coze-arch/logger": "0.0.1",
|
|
35
|
+
"@inquirer/prompts": "^3.2.0",
|
|
36
|
+
"@rushstack/rush-sdk": "^5.150.0",
|
|
37
|
+
"chalk": "^4.1.2",
|
|
38
|
+
"conventional-changelog-angular": "^5.0.13",
|
|
39
|
+
"conventional-commits-parser": "^3.2.4",
|
|
40
|
+
"dayjs": "^1.11.13",
|
|
41
|
+
"open": "~10.1.0",
|
|
42
|
+
"semver": "^7.7.1",
|
|
43
|
+
"shelljs": "^0.9.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@commitlint/types": "^17.4.0",
|
|
47
|
+
"@coze-arch/eslint-config": "workspace:*",
|
|
48
|
+
"@coze-arch/ts-config": "workspace:*",
|
|
49
|
+
"@coze-arch/vitest-config": "workspace:*",
|
|
50
|
+
"@types/node": "^22.13.13",
|
|
51
|
+
"@types/semver": "^7.5.8",
|
|
52
|
+
"@types/shelljs": "^0.8.15",
|
|
53
|
+
"@vitest/coverage-v8": "^3.0.9",
|
|
54
|
+
"commander": "^13.1.0",
|
|
55
|
+
"sucrase": "^3.32.0",
|
|
56
|
+
"tsx": "^4.19.3",
|
|
57
|
+
"vitest": "^3.0.9"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"commander": "^13.1.0"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"cozePublishConfig": {
|
|
66
|
+
"bin": {
|
|
67
|
+
"rush-publish": "./lib/index.js"
|
|
68
|
+
},
|
|
69
|
+
"main": "./lib/index.js"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json",
|
|
3
|
+
"plugins": [
|
|
4
|
+
{
|
|
5
|
+
"pluginName": "@coze-arch/rush-publish-plugin",
|
|
6
|
+
"description": "rush plugin to generate change log and publish packages",
|
|
7
|
+
"commandLineJsonFilePath": "./command-line.json"
|
|
8
|
+
}
|
|
9
|
+
]
|
|
10
|
+
}
|