@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.
Files changed (74) hide show
  1. package/README.md +1 -0
  2. package/command-line.json +140 -0
  3. package/lib/action/change/action.d.ts +2 -0
  4. package/lib/action/change/action.js +40 -0
  5. package/lib/action/change/amend-commit.d.ts +1 -0
  6. package/lib/action/change/amend-commit.js +23 -0
  7. package/lib/action/change/helper.d.ts +33 -0
  8. package/lib/action/change/helper.js +126 -0
  9. package/lib/action/change/index.d.ts +2 -0
  10. package/lib/action/change/index.js +17 -0
  11. package/lib/action/change/types.d.ts +5 -0
  12. package/lib/action/change/types.js +3 -0
  13. package/lib/action/publish/action.d.ts +2 -0
  14. package/lib/action/publish/action.js +68 -0
  15. package/lib/action/publish/apply-new-version.d.ts +2 -0
  16. package/lib/action/publish/apply-new-version.js +27 -0
  17. package/lib/action/publish/changelog.d.ts +2 -0
  18. package/lib/action/publish/changelog.js +79 -0
  19. package/lib/action/publish/confirm.d.ts +2 -0
  20. package/lib/action/publish/confirm.js +31 -0
  21. package/lib/action/publish/const.d.ts +1 -0
  22. package/lib/action/publish/const.js +5 -0
  23. package/lib/action/publish/git.d.ts +20 -0
  24. package/lib/action/publish/git.js +33 -0
  25. package/lib/action/publish/index.d.ts +2 -0
  26. package/lib/action/publish/index.js +43 -0
  27. package/lib/action/publish/packages.d.ts +3 -0
  28. package/lib/action/publish/packages.js +67 -0
  29. package/lib/action/publish/push-to-remote.d.ts +13 -0
  30. package/lib/action/publish/push-to-remote.js +105 -0
  31. package/lib/action/publish/request-bump-type.d.ts +5 -0
  32. package/lib/action/publish/request-bump-type.js +56 -0
  33. package/lib/action/publish/types.d.ts +25 -0
  34. package/lib/action/publish/types.js +12 -0
  35. package/lib/action/publish/version.d.ts +16 -0
  36. package/lib/action/publish/version.js +111 -0
  37. package/lib/action/release/action.d.ts +2 -0
  38. package/lib/action/release/action.js +34 -0
  39. package/lib/action/release/git.d.ts +5 -0
  40. package/lib/action/release/git.js +28 -0
  41. package/lib/action/release/index.d.ts +2 -0
  42. package/lib/action/release/index.js +31 -0
  43. package/lib/action/release/manifest.d.ts +5 -0
  44. package/lib/action/release/manifest.js +18 -0
  45. package/lib/action/release/package.d.ts +2 -0
  46. package/lib/action/release/package.js +49 -0
  47. package/lib/action/release/plan.d.ts +8 -0
  48. package/lib/action/release/plan.js +37 -0
  49. package/lib/action/release/release.d.ts +2 -0
  50. package/lib/action/release/release.js +50 -0
  51. package/lib/action/release/types.d.ts +14 -0
  52. package/lib/action/release/types.js +3 -0
  53. package/lib/generate-changelog/generate-changelog.d.ts +49 -0
  54. package/lib/generate-changelog/generate-changelog.js +127 -0
  55. package/lib/index.d.ts +1 -0
  56. package/lib/index.js +28 -0
  57. package/lib/types.d.ts +2 -0
  58. package/lib/types.js +3 -0
  59. package/lib/utils/exec.d.ts +7 -0
  60. package/lib/utils/exec.js +24 -0
  61. package/lib/utils/fs.d.ts +4 -0
  62. package/lib/utils/fs.js +27 -0
  63. package/lib/utils/get-rush-config.d.ts +2 -0
  64. package/lib/utils/get-rush-config.js +16 -0
  65. package/lib/utils/git.d.ts +19 -0
  66. package/lib/utils/git.js +70 -0
  67. package/lib/utils/logger.d.ts +58 -0
  68. package/lib/utils/logger.js +136 -0
  69. package/lib/utils/random.d.ts +6 -0
  70. package/lib/utils/random.js +19 -0
  71. package/lib/utils/whoami.d.ts +4 -0
  72. package/lib/utils/whoami.js +16 -0
  73. package/package.json +69 -0
  74. 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 get_rush_config_1 = require("../../utils/get-rush-config");
9
+ const fs_1 = require("../../utils/fs");
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_1.readJsonFile)(packageJsonPath);
43
+ for (const job of jobs) {
44
+ packageJson = await job(packageJson);
45
+ }
46
+ await (0, fs_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,37 @@
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 && branchName !== 'main') {
32
+ throw new Error('For LATEST release, should be on main branch only.');
33
+ }
34
+ return true;
35
+ };
36
+ exports.checkReleasePlan = checkReleasePlan;
37
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1,2 @@
1
+ import { type ReleaseOptions, type ReleaseManifest } from './types';
2
+ export declare const releasePackages: (releaseManifests: ReleaseManifest[], releaseOptions: ReleaseOptions) => Promise<void>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.releasePackages = void 0;
4
+ const logger_1 = require("../../utils/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
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -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
@@ -0,0 +1,2 @@
1
+ import { type Command } from 'commander';
2
+ export type InstallAction = (program: Command) => void;
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ import { type ExecOptions } from 'shelljs';
2
+ export interface ExecResult {
3
+ code: number;
4
+ stdout: string;
5
+ stderr: string;
6
+ }
7
+ export declare const exec: (cmd: string, options?: ExecOptions) => Promise<ExecResult>;
@@ -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,4 @@
1
+ export declare const readJsonFile: <T>(path: string) => Promise<T>;
2
+ export declare const writeJsonFile: (path: string, data: unknown) => Promise<void>;
3
+ export declare const isFileExists: (path: string) => Promise<boolean>;
4
+ export declare const isDirExists: (path: string) => Promise<boolean>;
@@ -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.isDirExists = exports.isFileExists = exports.writeJsonFile = exports.readJsonFile = void 0;
7
+ const promises_1 = __importDefault(require("fs/promises"));
8
+ const readJsonFile = async (path) => {
9
+ const content = await promises_1.default.readFile(path, 'utf8');
10
+ return JSON.parse(content);
11
+ };
12
+ exports.readJsonFile = readJsonFile;
13
+ const writeJsonFile = async (path, data) => {
14
+ await promises_1.default.writeFile(path, JSON.stringify(data, null, 2), 'utf8');
15
+ };
16
+ exports.writeJsonFile = writeJsonFile;
17
+ const isFileExists = async (path) => promises_1.default
18
+ .access(path)
19
+ .then(() => true)
20
+ .catch(() => false);
21
+ exports.isFileExists = isFileExists;
22
+ const isDirExists = async (path) => promises_1.default
23
+ .access(path)
24
+ .then(() => true)
25
+ .catch(() => false);
26
+ exports.isDirExists = isDirExists;
27
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1,2 @@
1
+ import { RushConfiguration } from '@rushstack/rush-sdk';
2
+ export declare const getRushConfiguration: (useCache?: boolean) => RushConfiguration;
@@ -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;
@@ -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,58 @@
1
+ /**
2
+ * 日志工具
3
+ *
4
+ * 提供统一的日志输出接口,支持不同级别的日志,包括彩色输出
5
+ */
6
+ export declare enum LogLevel {
7
+ DEBUG = 0,
8
+ INFO = 1,
9
+ WARN = 2,
10
+ ERROR = 3,
11
+ SUCCESS = 4,
12
+ NONE = 5
13
+ }
14
+ /**
15
+ * 设置全局日志级别
16
+ * @param level 日志级别
17
+ */
18
+ export declare function setLogLevel(level: LogLevel): void;
19
+ /**
20
+ * 获取当前日志级别
21
+ * @returns 当前日志级别
22
+ */
23
+ export declare function getLogLevel(): LogLevel;
24
+ /**
25
+ * 导出的日志工具
26
+ */
27
+ export declare const logger: {
28
+ /**
29
+ * 调试日志
30
+ * @param message 日志消息
31
+ * @param showPrefix 是否显示前缀,默认为 true
32
+ */
33
+ debug(message: string, showPrefix?: boolean): void;
34
+ /**
35
+ * 信息日志
36
+ * @param message 日志消息
37
+ * @param showPrefix 是否显示前缀,默认为 true
38
+ */
39
+ info(message: string, showPrefix?: boolean): void;
40
+ /**
41
+ * 警告日志
42
+ * @param message 日志消息
43
+ * @param showPrefix 是否显示前缀,默认为 true
44
+ */
45
+ warn(message: string, showPrefix?: boolean): void;
46
+ /**
47
+ * 错误日志
48
+ * @param message 日志消息
49
+ * @param showPrefix 是否显示前缀,默认为 true
50
+ */
51
+ error(message: string, showPrefix?: boolean): void;
52
+ /**
53
+ * 成功日志
54
+ * @param message 日志消息
55
+ * @param showPrefix 是否显示前缀,默认为 true
56
+ */
57
+ success(message: string, showPrefix?: boolean): void;
58
+ };