@peiyanlu/release 0.0.12 → 0.0.14
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/dist/cli.mjs +59 -58
- package/dist/index.d.mts +8 -1
- package/dist/index.mjs +4 -3
- package/package.json +14 -14
package/dist/cli.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { Octokit } from "@octokit/rest";
|
|
|
19
19
|
import { contentType } from "mime-types";
|
|
20
20
|
import open from "open";
|
|
21
21
|
import { glob } from "tinyglobby";
|
|
22
|
-
//#region node_modules/.pnpm/tsdown@0.
|
|
22
|
+
//#region node_modules/.pnpm/tsdown@0.22.1_publint@0.3.21_typescript@6.0.3/node_modules/tsdown/esm-shims.js
|
|
23
23
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
24
24
|
const getDirname = () => path.dirname(getFilename());
|
|
25
25
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
@@ -108,15 +108,15 @@ const MSG = {
|
|
|
108
108
|
},
|
|
109
109
|
NPM: {
|
|
110
110
|
START: "Publishing npm package",
|
|
111
|
-
END: (url) => `
|
|
111
|
+
END: (url) => url ? `Published npm package: ${underline(dim(url))}` : "NPM publish skipped"
|
|
112
112
|
},
|
|
113
113
|
GIT: {
|
|
114
114
|
START: "Creating git commit, tag & push",
|
|
115
|
-
END: "Git commit, tag & push completed"
|
|
115
|
+
END: (push) => push ? "Git commit, tag & push completed" : "Git commit, tag & push skipped"
|
|
116
116
|
},
|
|
117
117
|
GITHUB: {
|
|
118
118
|
START: "Creating GitHub release",
|
|
119
|
-
END: (url) => `GitHub release
|
|
119
|
+
END: (url) => url ? `Created GitHub release: ${underline(dim(url))}` : "GitHub release skipped"
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
PROMPT: {
|
|
@@ -156,13 +156,23 @@ const MSG = {
|
|
|
156
156
|
//#region src/git/commit.ts
|
|
157
157
|
const gitCheck = async (ctx, config) => {
|
|
158
158
|
const { pkg: { name } } = ctx;
|
|
159
|
-
const { git: { requireRepository, requireRemote, requireWorkDirClean } } = config;
|
|
159
|
+
const { git: { requireRepository, requireRemote, requireWorkDirClean }, ignoreGit, ignoreGithub } = config;
|
|
160
|
+
if (ignoreGit) {
|
|
161
|
+
ctx.noGit = true;
|
|
162
|
+
ctx.noGitHub = true;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
160
165
|
if (!await isGitRepo()) if (requireRepository) throw new Error(MSG.ERROR.GIT_REGISTRY(name));
|
|
161
166
|
else {
|
|
162
167
|
ctx.noGit = true;
|
|
168
|
+
ctx.noGitHub = true;
|
|
163
169
|
return;
|
|
164
170
|
}
|
|
165
171
|
if (requireWorkDirClean && !await isWorkingDirClean()) throw new Error(MSG.ERROR.GIT_WORKDIR);
|
|
172
|
+
if (ignoreGithub) {
|
|
173
|
+
ctx.noGitHub = true;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
166
176
|
const { remoteName, remoteUrl } = await getRemote();
|
|
167
177
|
if (!remoteUrl) if (requireRemote) throw new Error(MSG.ERROR.GIT_REMOTE(name));
|
|
168
178
|
else {
|
|
@@ -228,11 +238,11 @@ const abortGroupPrompt = (ctx) => {
|
|
|
228
238
|
ctx && gitRollback(ctx);
|
|
229
239
|
abortTask(MSG.ABORT.CANCEL);
|
|
230
240
|
};
|
|
231
|
-
const abortOnError = (err, ctx) => {
|
|
241
|
+
const abortOnError = (err, ctx, exit = true) => {
|
|
232
242
|
ctx && gitRollback(ctx);
|
|
233
243
|
const msg = err.message.replace(/^\[(github|npm|git)]/, (a) => red(a));
|
|
234
244
|
log.message(`\n${msg}\n`);
|
|
235
|
-
process.exit(1);
|
|
245
|
+
exit && process.exit(1);
|
|
236
246
|
};
|
|
237
247
|
const taskEnd = (msg) => {
|
|
238
248
|
outro(msg);
|
|
@@ -293,39 +303,15 @@ const formatTemplate = async (ctx, config) => {
|
|
|
293
303
|
};
|
|
294
304
|
//#endregion
|
|
295
305
|
//#region src/version/prompts.ts
|
|
296
|
-
let Release = /* @__PURE__ */ function(Release) {
|
|
297
|
-
Release["MAJOR"] = "major";
|
|
298
|
-
Release["MINOR"] = "minor";
|
|
299
|
-
Release["PATCH"] = "patch";
|
|
300
|
-
Release["RELEASE"] = "release";
|
|
301
|
-
return Release;
|
|
302
|
-
}({});
|
|
303
|
-
let PreRelease = /* @__PURE__ */ function(PreRelease) {
|
|
304
|
-
PreRelease["MAJOR"] = "premajor";
|
|
305
|
-
PreRelease["MINOR"] = "preminor";
|
|
306
|
-
PreRelease["PATCH"] = "prepatch";
|
|
307
|
-
PreRelease["RELEASE"] = "prerelease";
|
|
308
|
-
return PreRelease;
|
|
309
|
-
}({});
|
|
310
|
-
let PreId = /* @__PURE__ */ function(PreId) {
|
|
311
|
-
PreId["ALPHA"] = "alpha";
|
|
312
|
-
PreId["BETA"] = "beta";
|
|
313
|
-
PreId["RC"] = "rc";
|
|
314
|
-
PreId["NET"] = "next";
|
|
315
|
-
PreId["CANARY"] = "canary";
|
|
316
|
-
PreId["NIGHT"] = "nightly";
|
|
317
|
-
PreId["DEV"] = "dev";
|
|
318
|
-
return PreId;
|
|
319
|
-
}({});
|
|
320
306
|
const createVersionMap = (current) => ({
|
|
321
|
-
patch: inc(current,
|
|
322
|
-
minor: inc(current,
|
|
323
|
-
major: inc(current,
|
|
324
|
-
release: inc(current,
|
|
325
|
-
prerelease: inc(current,
|
|
326
|
-
prepatch: inc(current,
|
|
327
|
-
preminor: inc(current,
|
|
328
|
-
premajor: inc(current,
|
|
307
|
+
patch: inc(current, "patch"),
|
|
308
|
+
minor: inc(current, "minor"),
|
|
309
|
+
major: inc(current, "major"),
|
|
310
|
+
release: inc(current, "release"),
|
|
311
|
+
prerelease: inc(current, "prerelease"),
|
|
312
|
+
prepatch: inc(current, "prepatch", "beta"),
|
|
313
|
+
preminor: inc(current, "preminor", "beta"),
|
|
314
|
+
premajor: inc(current, "premajor", "beta")
|
|
329
315
|
});
|
|
330
316
|
const option = (label, value, hint) => ({
|
|
331
317
|
label,
|
|
@@ -402,7 +388,7 @@ const createDefaultContext = () => {
|
|
|
402
388
|
access: "public",
|
|
403
389
|
registry: "https://registry.npmjs.org"
|
|
404
390
|
},
|
|
405
|
-
preId:
|
|
391
|
+
preId: "beta",
|
|
406
392
|
preBase: "0"
|
|
407
393
|
},
|
|
408
394
|
npm: {
|
|
@@ -458,7 +444,12 @@ const createDefaultConfig = (isCI) => {
|
|
|
458
444
|
toTag(pkg, version) {
|
|
459
445
|
return `v${version}`;
|
|
460
446
|
},
|
|
461
|
-
tagPrefix
|
|
447
|
+
tagPrefix(pkg) {
|
|
448
|
+
return "";
|
|
449
|
+
},
|
|
450
|
+
ignoreGit: false,
|
|
451
|
+
ignoreNpm: false,
|
|
452
|
+
ignoreGithub: false,
|
|
462
453
|
git: {
|
|
463
454
|
commit: isCI,
|
|
464
455
|
tag: isCI,
|
|
@@ -638,7 +629,7 @@ const parsePreset = async () => {
|
|
|
638
629
|
{{#each commits}}
|
|
639
630
|
{{> commit root=@root}}
|
|
640
631
|
{{/each}}
|
|
641
|
-
{{/each}}`.trim()
|
|
632
|
+
{{/each}}`.trim();
|
|
642
633
|
return preset;
|
|
643
634
|
};
|
|
644
635
|
const createGenerator = async ({ getPkgDir, tagPrefix }) => {
|
|
@@ -658,14 +649,15 @@ const getChangelog = async ({ getPkgDir, tagPrefix }) => {
|
|
|
658
649
|
const generateChangelog = async ({ getPkgDir, tagPrefix }) => {
|
|
659
650
|
const infile = join(getPkgDir(), "CHANGELOG.md");
|
|
660
651
|
if (!existsSync(infile)) await writeFile(infile, "");
|
|
661
|
-
const
|
|
652
|
+
const exist = readFileSync(infile, "utf-8");
|
|
662
653
|
const generator = await createGenerator({
|
|
663
654
|
getPkgDir,
|
|
664
655
|
tagPrefix
|
|
665
656
|
});
|
|
666
657
|
const writeStream = createWriteStream(infile);
|
|
667
658
|
for await (const chunk of generator.write()) writeStream.write(chunk);
|
|
668
|
-
writeStream.write(
|
|
659
|
+
if (exist.trim().length) writeStream.write(eol(2));
|
|
660
|
+
writeStream.write(exist);
|
|
669
661
|
writeStream.end();
|
|
670
662
|
await finished(writeStream);
|
|
671
663
|
};
|
|
@@ -683,14 +675,18 @@ const runGitPrompts = async (ctx, config) => {
|
|
|
683
675
|
return Promise.resolve(commit);
|
|
684
676
|
})();
|
|
685
677
|
},
|
|
686
|
-
tag: () => {
|
|
687
|
-
return shouldPrompt(tag) ? confirm({ message: question(MSG.PROMPT.GIT_TAG(currentTag), "git") }) : (() => {
|
|
678
|
+
tag: ({ results: { commit } }) => {
|
|
679
|
+
return shouldPrompt(tag) ? commit ? confirm({ message: question(MSG.PROMPT.GIT_TAG(currentTag), "git") }) : (() => {
|
|
680
|
+
return Promise.resolve(false);
|
|
681
|
+
})() : (() => {
|
|
688
682
|
logs.push(yellow`git.tag`);
|
|
689
683
|
return Promise.resolve(tag);
|
|
690
684
|
})();
|
|
691
685
|
},
|
|
692
|
-
push: () => {
|
|
693
|
-
return shouldPrompt(push) ? confirm({ message: question(MSG.PROMPT.GIT_PUSH, "git") }) : (() => {
|
|
686
|
+
push: ({ results: { commit, tag } }) => {
|
|
687
|
+
return shouldPrompt(push) ? commit || tag ? confirm({ message: question(MSG.PROMPT.GIT_PUSH, "git") }) : (() => {
|
|
688
|
+
return Promise.resolve(false);
|
|
689
|
+
})() : (() => {
|
|
694
690
|
logs.push(yellow`git.push`);
|
|
695
691
|
return Promise.resolve(push);
|
|
696
692
|
})();
|
|
@@ -989,7 +985,7 @@ var Action = class {
|
|
|
989
985
|
info(MSG.INFO.CONFIG(configPath));
|
|
990
986
|
console.log();
|
|
991
987
|
intro(prepare ? MSG.INTRO_PREPARE(dryRun) : MSG.INTRO(dryRun));
|
|
992
|
-
const { isMonorepo, packages, getPkgDir } = config;
|
|
988
|
+
const { isMonorepo, packages, getPkgDir, ignoreNpm } = config;
|
|
993
989
|
if (isMonorepo) {
|
|
994
990
|
if (ci) {
|
|
995
991
|
if (!defPkg) abortTask(MSG.ABORT.MONOREPO_CI_NO_PACKAGE);
|
|
@@ -1035,7 +1031,7 @@ var Action = class {
|
|
|
1035
1031
|
toPreRelease: false,
|
|
1036
1032
|
publishConfig: { ...publishConfig }
|
|
1037
1033
|
},
|
|
1038
|
-
noNpm: pkgPrivate
|
|
1034
|
+
noNpm: pkgPrivate || ignoreNpm
|
|
1039
1035
|
});
|
|
1040
1036
|
const { messages } = await publint({ pkgDir });
|
|
1041
1037
|
for (const message of messages) {
|
|
@@ -1080,7 +1076,7 @@ var Action = class {
|
|
|
1080
1076
|
]).catch(abortOnError);
|
|
1081
1077
|
}
|
|
1082
1078
|
async bumpTask(ctx, config) {
|
|
1083
|
-
const { pkg: { current }, dryRun, isCI, showRelease, showChangelog, selectedPkg } = ctx;
|
|
1079
|
+
const { pkg: { current }, dryRun, isCI, showRelease, showChangelog, selectedPkg, noGit } = ctx;
|
|
1084
1080
|
const { isMonorepo, hooks, getPkgDir, tagPrefix } = config;
|
|
1085
1081
|
const need = (ctx) => {
|
|
1086
1082
|
const { pkg: { next }, isIncrement } = ctx;
|
|
@@ -1110,6 +1106,7 @@ var Action = class {
|
|
|
1110
1106
|
}
|
|
1111
1107
|
}]).catch((err) => abortOnError(err, ctx));
|
|
1112
1108
|
await runLifeCycleHook(hooks, "after:bump", dryRun);
|
|
1109
|
+
if (noGit) return;
|
|
1113
1110
|
const { from, to } = await resolveChangelogRange(isIncrement, isMonorepo ? `${tagPrefix?.(selectedPkg)}*` : "*");
|
|
1114
1111
|
const commits = await getLog(from, to, getPkgDir(selectedPkg));
|
|
1115
1112
|
const changelog = await getChangelog({
|
|
@@ -1124,8 +1121,9 @@ var Action = class {
|
|
|
1124
1121
|
} else msg("GIT", MSG.LOG.CHANGELOG_EMPTY);
|
|
1125
1122
|
}
|
|
1126
1123
|
async changelogTask(ctx, config) {
|
|
1127
|
-
const { isIncrement, dryRun, selectedPkg } = ctx;
|
|
1124
|
+
const { isIncrement, dryRun, selectedPkg, noGit } = ctx;
|
|
1128
1125
|
const { getPkgDir, tagPrefix } = config;
|
|
1126
|
+
if (noGit) return;
|
|
1129
1127
|
await tasks([{
|
|
1130
1128
|
title: MSG.TASK.CHANGELOG.START,
|
|
1131
1129
|
task: async () => {
|
|
@@ -1152,7 +1150,8 @@ var Action = class {
|
|
|
1152
1150
|
title: MSG.TASK.GIT.START,
|
|
1153
1151
|
task: async () => {
|
|
1154
1152
|
await commitAndTag(ctx, config);
|
|
1155
|
-
|
|
1153
|
+
const { git: { push } } = config;
|
|
1154
|
+
return success(MSG.TASK.GIT.END(Boolean(push)), dryRun);
|
|
1156
1155
|
}
|
|
1157
1156
|
}]).catch((err) => abortOnError(err, ctx));
|
|
1158
1157
|
await runLifeCycleHook(hooks, "after:push", dryRun);
|
|
@@ -1172,10 +1171,11 @@ var Action = class {
|
|
|
1172
1171
|
await publishNpm(ctx, config);
|
|
1173
1172
|
} else throw err;
|
|
1174
1173
|
});
|
|
1175
|
-
const
|
|
1174
|
+
const { npm: { publish } } = config;
|
|
1175
|
+
const url = publish ? getPackageUrl(name, next) : void 0;
|
|
1176
1176
|
return success(MSG.TASK.NPM.END(url), dryRun);
|
|
1177
1177
|
}
|
|
1178
|
-
}]).catch((err) => abortOnError(err, ctx));
|
|
1178
|
+
}]).catch((err) => abortOnError(err, ctx, false));
|
|
1179
1179
|
await runLifeCycleHook(hooks, "after:publish", dryRun);
|
|
1180
1180
|
}
|
|
1181
1181
|
async githubTask(ctx, config) {
|
|
@@ -1187,12 +1187,13 @@ var Action = class {
|
|
|
1187
1187
|
await tasks([{
|
|
1188
1188
|
title: MSG.TASK.GITHUB.START,
|
|
1189
1189
|
task: async () => {
|
|
1190
|
-
const { github: { owner, repo }, git: { currentTag } } = ctx;
|
|
1191
1190
|
await createRelease(ctx, config);
|
|
1192
|
-
const
|
|
1191
|
+
const { github: { owner, repo }, git: { currentTag } } = ctx;
|
|
1192
|
+
const { github: { release } } = config;
|
|
1193
|
+
const url = release ? getGithubReleaseUrl(owner, repo, currentTag) : void 0;
|
|
1193
1194
|
return success(MSG.TASK.GITHUB.END(url), dryRun);
|
|
1194
1195
|
}
|
|
1195
|
-
}]).catch((err) => abortOnError(err, ctx));
|
|
1196
|
+
}]).catch((err) => abortOnError(err, ctx, false));
|
|
1196
1197
|
await runLifeCycleHook(hooks, "after:release", dryRun);
|
|
1197
1198
|
}
|
|
1198
1199
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -24,7 +24,13 @@ interface ReleaseConfig {
|
|
|
24
24
|
/** 使用 monorepo 时使用 toTag,例如 `${pkg}@${version}`,默认为 `v${version}` 作为单仓库 */
|
|
25
25
|
toTag: (pkg: string, version: string) => string;
|
|
26
26
|
/** 作为 CHANGELOG 标题的 Tag 前缀,多包场景下需要 `${pkg}@` */
|
|
27
|
-
tagPrefix: ((pkg: string) => string
|
|
27
|
+
tagPrefix: ((pkg: string) => string) | undefined;
|
|
28
|
+
/** 忽略 git、github 环境检查以及后续操作 */
|
|
29
|
+
ignoreGit: boolean | undefined;
|
|
30
|
+
/** 忽略 npm 环境检查以及后续操作 */
|
|
31
|
+
ignoreNpm: boolean | undefined;
|
|
32
|
+
/** 忽略 github 环境检查以及后续操作 */
|
|
33
|
+
ignoreGithub: boolean | undefined;
|
|
28
34
|
/**
|
|
29
35
|
* Git 相关配置
|
|
30
36
|
* 影响提交、打 tag、推送等本地/远程 Git 行为。
|
|
@@ -32,6 +38,7 @@ interface ReleaseConfig {
|
|
|
32
38
|
git: {
|
|
33
39
|
/**
|
|
34
40
|
* 是否创建 Git 提交
|
|
41
|
+
* 影响创建 Tag 和推送
|
|
35
42
|
*/
|
|
36
43
|
commit: boolean | undefined;
|
|
37
44
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -174,7 +174,7 @@ const parsePreset = async () => {
|
|
|
174
174
|
{{#each commits}}
|
|
175
175
|
{{> commit root=@root}}
|
|
176
176
|
{{/each}}
|
|
177
|
-
{{/each}}`.trim()
|
|
177
|
+
{{/each}}`.trim();
|
|
178
178
|
return preset;
|
|
179
179
|
};
|
|
180
180
|
const createGenerator = async ({ getPkgDir, tagPrefix }) => {
|
|
@@ -194,14 +194,15 @@ const getChangelog = async ({ getPkgDir, tagPrefix }) => {
|
|
|
194
194
|
const generateChangelog = async ({ getPkgDir, tagPrefix }) => {
|
|
195
195
|
const infile = join(getPkgDir(), "CHANGELOG.md");
|
|
196
196
|
if (!existsSync(infile)) await writeFile(infile, "");
|
|
197
|
-
const
|
|
197
|
+
const exist = readFileSync(infile, "utf-8");
|
|
198
198
|
const generator = await createGenerator({
|
|
199
199
|
getPkgDir,
|
|
200
200
|
tagPrefix
|
|
201
201
|
});
|
|
202
202
|
const writeStream = createWriteStream(infile);
|
|
203
203
|
for await (const chunk of generator.write()) writeStream.write(chunk);
|
|
204
|
-
writeStream.write(
|
|
204
|
+
if (exist.trim().length) writeStream.write(eol(2));
|
|
205
|
+
writeStream.write(exist);
|
|
205
206
|
writeStream.end();
|
|
206
207
|
await finished(writeStream);
|
|
207
208
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peiyanlu/release",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Release project tool.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,30 +26,30 @@
|
|
|
26
26
|
"test:cov": "vitest run --coverage"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@actions/core": "^3.0.
|
|
30
|
-
"@actions/github": "^9.
|
|
31
|
-
"@clack/prompts": "^1.
|
|
29
|
+
"@actions/core": "^3.0.1",
|
|
30
|
+
"@actions/github": "^9.1.1",
|
|
31
|
+
"@clack/prompts": "^1.5.0",
|
|
32
32
|
"@octokit/rest": "^22.0.1",
|
|
33
33
|
"@peiyanlu/cli-utils": "^0.0.8",
|
|
34
34
|
"@peiyanlu/ts-utils": "^0.0.5",
|
|
35
|
-
"ansis": "^4.
|
|
36
|
-
"commander": "^
|
|
35
|
+
"ansis": "^4.3.1",
|
|
36
|
+
"commander": "^15.0.0",
|
|
37
37
|
"conventional-changelog": "^7.2.0",
|
|
38
38
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
39
39
|
"mime-types": "^3.0.2",
|
|
40
40
|
"open": "^11.0.0",
|
|
41
|
-
"publint": "^0.3.
|
|
42
|
-
"semver": "^7.
|
|
43
|
-
"tinyglobby": "^0.2.
|
|
41
|
+
"publint": "^0.3.21",
|
|
42
|
+
"semver": "^7.8.1",
|
|
43
|
+
"tinyglobby": "^0.2.17"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/mime-types": "^3.0.1",
|
|
47
|
-
"@types/node": "^
|
|
47
|
+
"@types/node": "^24.12.4",
|
|
48
48
|
"@types/semver": "^7.7.1",
|
|
49
|
-
"@vitest/coverage-v8": "^4.1.
|
|
50
|
-
"tsdown": "^0.
|
|
51
|
-
"typescript": "^6.0.
|
|
52
|
-
"vitest": "^4.1.
|
|
49
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
50
|
+
"tsdown": "^0.22.1",
|
|
51
|
+
"typescript": "^6.0.3",
|
|
52
|
+
"vitest": "^4.1.8"
|
|
53
53
|
},
|
|
54
54
|
"author": {
|
|
55
55
|
"name": "YanluPei",
|