@spaceflow/publish 0.21.2 → 0.22.0
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/CHANGELOG.md +26 -0
- package/dist/index.js +548 -696
- package/package.json +3 -6
- package/src/index.ts +59 -21
- package/src/monorepo.service.ts +0 -2
- package/src/publish.service.ts +14 -10
- package/tsconfig.json +1 -1
- package/src/publish.command.ts +0 -71
- package/src/publish.module.ts +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spaceflow/publish",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Spaceflow CI 发布插件,用于在发布流程中锁定/解锁分支",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lydanne",
|
|
@@ -21,13 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^22.15.0",
|
|
24
|
-
"@spaceflow/cli": "0.
|
|
24
|
+
"@spaceflow/cli": "0.20.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@nestjs/config": "^4.0.2",
|
|
29
|
-
"nest-commander": "^3.20.1",
|
|
30
|
-
"@spaceflow/core": "0.1.3"
|
|
27
|
+
"@spaceflow/core": "0.2.0"
|
|
31
28
|
},
|
|
32
29
|
"spaceflow": {
|
|
33
30
|
"type": "flow",
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,68 @@
|
|
|
1
1
|
import "./locales";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { defineExtension, t } from "@spaceflow/core";
|
|
3
|
+
import type { GitProviderService, ConfigReaderService } from "@spaceflow/core";
|
|
4
4
|
import { publishSchema } from "./publish.config";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { PublishService } from "./publish.service";
|
|
6
|
+
import { MonorepoService } from "./monorepo.service";
|
|
7
|
+
|
|
8
|
+
export const extension = defineExtension({
|
|
7
9
|
name: "publish",
|
|
8
|
-
commands: ["publish"],
|
|
9
|
-
configKey: "publish",
|
|
10
|
-
configSchema: () => publishSchema,
|
|
11
10
|
version: "1.0.0",
|
|
12
11
|
description: t("publish:extensionDescription"),
|
|
13
|
-
|
|
12
|
+
configKey: "publish",
|
|
13
|
+
configSchema: () => publishSchema,
|
|
14
|
+
commands: [
|
|
15
|
+
{
|
|
16
|
+
name: "publish",
|
|
17
|
+
description: t("publish:description"),
|
|
18
|
+
options: [
|
|
19
|
+
{ flags: "-d, --dry-run", description: t("common.options.dryRun") },
|
|
20
|
+
{ flags: "-c, --ci", description: t("common.options.ci") },
|
|
21
|
+
{ flags: "-p, --prerelease <tag>", description: t("publish:options.prerelease") },
|
|
22
|
+
{ flags: "-r, --rehearsal", description: t("publish:options.rehearsal") },
|
|
23
|
+
],
|
|
24
|
+
run: async (_args, options, ctx) => {
|
|
25
|
+
const gitProvider = ctx.getService<GitProviderService>("gitProvider");
|
|
26
|
+
const configReader = ctx.getService<ConfigReaderService>("config");
|
|
27
|
+
|
|
28
|
+
if (!gitProvider) {
|
|
29
|
+
ctx.output.error("publish 命令需要配置 Git Provider");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const monorepoService = new MonorepoService();
|
|
34
|
+
const publishService = new PublishService(
|
|
35
|
+
gitProvider,
|
|
36
|
+
ctx.config,
|
|
37
|
+
configReader,
|
|
38
|
+
monorepoService,
|
|
39
|
+
);
|
|
14
40
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
41
|
+
const publishOptions = {
|
|
42
|
+
dryRun: !!options?.dryRun,
|
|
43
|
+
ci: !!options?.ci,
|
|
44
|
+
prerelease: options?.prerelease as string,
|
|
45
|
+
rehearsal: !!options?.rehearsal,
|
|
46
|
+
};
|
|
19
47
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
48
|
+
if (publishOptions.rehearsal) {
|
|
49
|
+
console.log(t("publish:rehearsalMode"));
|
|
50
|
+
} else if (publishOptions.dryRun) {
|
|
51
|
+
console.log(t("publish:dryRunMode"));
|
|
52
|
+
}
|
|
24
53
|
|
|
25
|
-
|
|
54
|
+
try {
|
|
55
|
+
const context = publishService.getContextFromEnv(publishOptions);
|
|
56
|
+
await publishService.execute(context);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
ctx.output.error(
|
|
59
|
+
t("common.executionFailed", { error: error instanceof Error ? error.message : error }),
|
|
60
|
+
);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
26
67
|
|
|
27
|
-
export
|
|
28
|
-
export * from "./publish.service";
|
|
29
|
-
export * from "./publish.module";
|
|
30
|
-
export * from "./monorepo.service";
|
|
68
|
+
export default extension;
|
package/src/monorepo.service.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Injectable } from "@nestjs/common";
|
|
2
1
|
import { execSync } from "child_process";
|
|
3
2
|
import { existsSync, readFileSync } from "fs";
|
|
4
3
|
import { join } from "path";
|
|
@@ -21,7 +20,6 @@ export interface MonorepoAnalysisResult {
|
|
|
21
20
|
packagesToPublish: PackageInfo[];
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
@Injectable()
|
|
25
23
|
export class MonorepoService {
|
|
26
24
|
private readonly cwd: string;
|
|
27
25
|
|
package/src/publish.service.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Injectable } from "@nestjs/common";
|
|
2
|
-
import { ConfigService } from "@nestjs/config";
|
|
3
1
|
import {
|
|
4
2
|
GitProviderService,
|
|
5
|
-
ConfigReaderService,
|
|
3
|
+
type ConfigReaderService,
|
|
4
|
+
type IConfigReader,
|
|
6
5
|
type BranchProtection,
|
|
7
|
-
|
|
6
|
+
ciConfig,
|
|
8
7
|
} from "@spaceflow/core";
|
|
9
8
|
import { type PublishConfig } from "./publish.config";
|
|
10
9
|
import { MonorepoService, type PackageInfo } from "./monorepo.service";
|
|
@@ -19,7 +18,13 @@ const releaseItModule = require("release-it") as
|
|
|
19
18
|
|
|
20
19
|
const releaseIt = typeof releaseItModule === "function" ? releaseItModule : releaseItModule.default;
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
export interface PublishOptions {
|
|
22
|
+
dryRun: boolean;
|
|
23
|
+
ci: boolean;
|
|
24
|
+
prerelease?: string;
|
|
25
|
+
/** 预演模式:执行 hooks 但不修改文件/git */
|
|
26
|
+
rehearsal: boolean;
|
|
27
|
+
}
|
|
23
28
|
|
|
24
29
|
export interface PublishContext extends PublishOptions {
|
|
25
30
|
owner: string;
|
|
@@ -48,7 +53,6 @@ interface ReleaseItConfigOptions {
|
|
|
48
53
|
publishConf: PublishConfig;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
@Injectable()
|
|
52
56
|
export class PublishService {
|
|
53
57
|
private cleanupOnExit: (() => void) | null = null;
|
|
54
58
|
private uncaughtExceptionHandler: ((err: Error) => void) | null = null;
|
|
@@ -56,7 +60,7 @@ export class PublishService {
|
|
|
56
60
|
|
|
57
61
|
constructor(
|
|
58
62
|
protected readonly gitProvider: GitProviderService,
|
|
59
|
-
protected readonly
|
|
63
|
+
protected readonly config: IConfigReader,
|
|
60
64
|
protected readonly configReader: ConfigReaderService,
|
|
61
65
|
protected readonly monorepoService: MonorepoService,
|
|
62
66
|
) {}
|
|
@@ -64,9 +68,9 @@ export class PublishService {
|
|
|
64
68
|
getContextFromEnv(options: PublishOptions): PublishContext {
|
|
65
69
|
this.gitProvider.validateConfig();
|
|
66
70
|
|
|
67
|
-
const ciConf =
|
|
68
|
-
const repository = ciConf
|
|
69
|
-
const branch = ciConf
|
|
71
|
+
const ciConf = ciConfig();
|
|
72
|
+
const repository = ciConf.repository;
|
|
73
|
+
const branch = ciConf.refName;
|
|
70
74
|
|
|
71
75
|
if (!repository) {
|
|
72
76
|
throw new Error("缺少配置 ci.repository (环境变量 GITHUB_REPOSITORY)");
|
package/tsconfig.json
CHANGED
package/src/publish.command.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Command, CommandRunner, Option } from "nest-commander";
|
|
2
|
-
import { t } from "@spaceflow/core";
|
|
3
|
-
import { PublishService } from "./publish.service";
|
|
4
|
-
|
|
5
|
-
export interface PublishOptions {
|
|
6
|
-
dryRun: boolean;
|
|
7
|
-
ci: boolean;
|
|
8
|
-
prerelease?: string;
|
|
9
|
-
/** 预演模式:执行 hooks 但不修改文件/git */
|
|
10
|
-
rehearsal: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@Command({
|
|
14
|
-
name: "publish",
|
|
15
|
-
description: t("publish:description"),
|
|
16
|
-
})
|
|
17
|
-
export class PublishCommand extends CommandRunner {
|
|
18
|
-
constructor(protected readonly publishService: PublishService) {
|
|
19
|
-
super();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async run(_passedParams: string[], options: PublishOptions): Promise<void> {
|
|
23
|
-
if (options.rehearsal) {
|
|
24
|
-
console.log(t("publish:rehearsalMode"));
|
|
25
|
-
} else if (options.dryRun) {
|
|
26
|
-
console.log(t("publish:dryRunMode"));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const context = this.publishService.getContextFromEnv(options);
|
|
31
|
-
await this.publishService.execute(context);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error(
|
|
34
|
-
t("common.executionFailed", { error: error instanceof Error ? error.message : error }),
|
|
35
|
-
);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Option({
|
|
41
|
-
flags: "-d, --dry-run",
|
|
42
|
-
description: t("common.options.dryRun"),
|
|
43
|
-
})
|
|
44
|
-
parseDryRun(val: boolean): boolean {
|
|
45
|
-
return val;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Option({
|
|
49
|
-
flags: "-c, --ci",
|
|
50
|
-
description: t("common.options.ci"),
|
|
51
|
-
})
|
|
52
|
-
parseCi(val: boolean): boolean {
|
|
53
|
-
return val;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@Option({
|
|
57
|
-
flags: "-p, --prerelease <tag>",
|
|
58
|
-
description: t("publish:options.prerelease"),
|
|
59
|
-
})
|
|
60
|
-
parsePrerelease(val: string): string {
|
|
61
|
-
return val;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@Option({
|
|
65
|
-
flags: "-r, --rehearsal",
|
|
66
|
-
description: t("publish:options.rehearsal"),
|
|
67
|
-
})
|
|
68
|
-
parseRehearsal(val: boolean): boolean {
|
|
69
|
-
return val;
|
|
70
|
-
}
|
|
71
|
-
}
|
package/src/publish.module.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Module } from "@nestjs/common";
|
|
2
|
-
import { ConfigModule } from "@nestjs/config";
|
|
3
|
-
import { GitProviderModule, ConfigReaderModule, ciConfig } from "@spaceflow/core";
|
|
4
|
-
import { PublishCommand } from "./publish.command";
|
|
5
|
-
import { PublishService } from "./publish.service";
|
|
6
|
-
import { MonorepoService } from "./monorepo.service";
|
|
7
|
-
|
|
8
|
-
@Module({
|
|
9
|
-
imports: [ConfigModule.forFeature(ciConfig), GitProviderModule.forFeature(), ConfigReaderModule],
|
|
10
|
-
providers: [PublishCommand, PublishService, MonorepoService],
|
|
11
|
-
})
|
|
12
|
-
export class PublishModule {}
|