@varlet/release 2.0.0 → 2.1.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/dist/cli.js +4 -4
- package/dist/index.d.ts +26 -12
- package/dist/index.js +2 -2
- package/dist/{src-CkbCVkad.js → src-_TFLfQjD.js} +51 -55
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as release, i as
|
|
2
|
+
import { c as release, i as lockfileCheck, p as commitLint, s as publish, u as changelog } from "./src-_TFLfQjD.js";
|
|
3
3
|
import { cli, command } from "cleye";
|
|
4
4
|
//#endregion
|
|
5
5
|
//#region src/cli.ts
|
|
6
6
|
cli({
|
|
7
7
|
name: "vr",
|
|
8
|
-
version: "2.
|
|
8
|
+
version: "2.1.0",
|
|
9
9
|
commands: [
|
|
10
10
|
command({
|
|
11
11
|
name: "release",
|
|
@@ -102,7 +102,7 @@ cli({
|
|
|
102
102
|
help: { description: "Lint commit message" }
|
|
103
103
|
}, (argv) => commitLint(argv.flags)),
|
|
104
104
|
command({
|
|
105
|
-
name: "lockfile-
|
|
105
|
+
name: "lockfile-check",
|
|
106
106
|
flags: {
|
|
107
107
|
packageManager: {
|
|
108
108
|
type: String,
|
|
@@ -117,7 +117,7 @@ cli({
|
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
119
|
help: { description: "Check if lockfile has been updated and optionally install dependencies" }
|
|
120
|
-
}, (argv) =>
|
|
120
|
+
}, (argv) => lockfileCheck(argv.flags))
|
|
121
121
|
]
|
|
122
122
|
});
|
|
123
123
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConventionalChangelog } from "standard-changelog";
|
|
2
2
|
|
|
3
3
|
//#region src/release.d.ts
|
|
4
4
|
interface PackageJsonConfig {
|
|
@@ -38,20 +38,34 @@ interface ReleaseCommandOptions {
|
|
|
38
38
|
declare function release(options: ReleaseCommandOptions): Promise<void>;
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/changelog.d.ts
|
|
41
|
-
|
|
41
|
+
declare const COMMIT_TYPE_MAP: {
|
|
42
|
+
readonly feat: "Features";
|
|
43
|
+
readonly fix: "Bug Fixes";
|
|
44
|
+
readonly perf: "Performance Improvements";
|
|
45
|
+
readonly revert: "Reverts";
|
|
46
|
+
readonly refactor: "Refactoring";
|
|
47
|
+
readonly docs: "Documentation";
|
|
48
|
+
readonly style: "Styles";
|
|
49
|
+
readonly test: "Tests";
|
|
50
|
+
readonly build: "Build System";
|
|
51
|
+
readonly ci: "Continuous Integration";
|
|
52
|
+
};
|
|
53
|
+
interface ChangelogOptions {
|
|
42
54
|
cwd?: string;
|
|
43
|
-
file?: string;
|
|
44
55
|
releaseCount?: number;
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
file?: string;
|
|
57
|
+
showTypes?: (keyof typeof COMMIT_TYPE_MAP)[];
|
|
58
|
+
outputUnreleased?: boolean;
|
|
59
|
+
writerOpt?: Parameters<ConventionalChangelog["writer"]>[0];
|
|
47
60
|
}
|
|
48
61
|
declare function changelog({
|
|
49
62
|
cwd,
|
|
50
63
|
releaseCount,
|
|
51
64
|
file,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
showTypes,
|
|
66
|
+
outputUnreleased,
|
|
67
|
+
writerOpt
|
|
68
|
+
}?: ChangelogOptions): Promise<void>;
|
|
55
69
|
//#endregion
|
|
56
70
|
//#region src/commitLint.d.ts
|
|
57
71
|
declare const COMMIT_HEADER_RE: RegExp;
|
|
@@ -66,15 +80,15 @@ interface CommitLintCommandOptions {
|
|
|
66
80
|
}
|
|
67
81
|
declare function commitLint(options: CommitLintCommandOptions): void;
|
|
68
82
|
//#endregion
|
|
69
|
-
//#region src/
|
|
83
|
+
//#region src/lockfileCheck.d.ts
|
|
70
84
|
type PackageManager = "npm" | "yarn" | "pnpm";
|
|
71
|
-
interface
|
|
85
|
+
interface LockfileCheckOptions {
|
|
72
86
|
packageManager?: PackageManager;
|
|
73
87
|
install?: boolean;
|
|
74
88
|
}
|
|
75
89
|
declare function getLockfilePath(packageManager: PackageManager): string;
|
|
76
90
|
declare function checkLockfileSync(packageManager: PackageManager): Promise<boolean>;
|
|
77
91
|
declare function installDependencies(packageManager: PackageManager): Promise<void>;
|
|
78
|
-
declare function
|
|
92
|
+
declare function lockfileCheck(options?: LockfileCheckOptions): Promise<void>;
|
|
79
93
|
//#endregion
|
|
80
|
-
export { COMMIT_HEADER_RE, COMMIT_MESSAGE_RE,
|
|
94
|
+
export { COMMIT_HEADER_RE, COMMIT_MESSAGE_RE, ChangelogOptions, CommitLintCommandOptions, LockfileCheckOptions, PackageManager, PublishCommandOptions, ReleaseCommandOptions, changelog, checkLockfileSync, commitLint, getCommitMessage, getLockfilePath, getPackageJsons, installDependencies, isSameVersion, isVersionCommitMessage, lockfileCheck, publish, release, updateVersion };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as getPackageJsons, c as release, d as COMMIT_HEADER_RE, f as COMMIT_MESSAGE_RE, h as isVersionCommitMessage, i as
|
|
2
|
-
export { COMMIT_HEADER_RE, COMMIT_MESSAGE_RE, changelog, checkLockfileSync, commitLint, getCommitMessage, getLockfilePath, getPackageJsons, installDependencies, isSameVersion, isVersionCommitMessage,
|
|
1
|
+
import { a as getPackageJsons, c as release, d as COMMIT_HEADER_RE, f as COMMIT_MESSAGE_RE, h as isVersionCommitMessage, i as lockfileCheck, l as updateVersion, m as getCommitMessage, n as getLockfilePath, o as isSameVersion, p as commitLint, r as installDependencies, s as publish, t as checkLockfileSync, u as changelog } from "./src-_TFLfQjD.js";
|
|
2
|
+
export { COMMIT_HEADER_RE, COMMIT_MESSAGE_RE, changelog, checkLockfileSync, commitLint, getCommitMessage, getLockfilePath, getPackageJsons, installDependencies, isSameVersion, isVersionCommitMessage, lockfileCheck, publish, release, updateVersion };
|
|
@@ -5,7 +5,7 @@ import { cancel, confirm, isCancel, select, spinner } from "@clack/prompts";
|
|
|
5
5
|
import { logger } from "rslog";
|
|
6
6
|
import semver from "semver";
|
|
7
7
|
import { x } from "tinyexec";
|
|
8
|
-
import {
|
|
8
|
+
import { StandardChangelog } from "standard-changelog";
|
|
9
9
|
//#region src/commitLint.ts
|
|
10
10
|
const COMMIT_HEADER_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor|merge|wip)(?:\(([^)]+)\))?(!)?:\s(.+)$/;
|
|
11
11
|
const COMMIT_MESSAGE_RE = new RegExp(COMMIT_HEADER_RE.source.replace(/\$$/, "") + "(?:\\n[\\s\\S]+)?$");
|
|
@@ -76,13 +76,14 @@ const COMMIT_TYPE_MAP = {
|
|
|
76
76
|
build: "Build System",
|
|
77
77
|
ci: "Continuous Integration"
|
|
78
78
|
};
|
|
79
|
-
const ALWAYS_SHOW_TYPES =
|
|
79
|
+
const ALWAYS_SHOW_TYPES = [
|
|
80
80
|
"feat",
|
|
81
81
|
"fix",
|
|
82
82
|
"perf",
|
|
83
83
|
"revert",
|
|
84
84
|
"refactor"
|
|
85
|
-
]
|
|
85
|
+
];
|
|
86
|
+
const BREAKING_CHANGE_RE = /BREAKING CHANGES?:\s*([\s\S]+)/;
|
|
86
87
|
const MAIN_TEMPLATE = `{{> header}}
|
|
87
88
|
|
|
88
89
|
{{> footer}}
|
|
@@ -111,6 +112,15 @@ function linkify(text, context, issues) {
|
|
|
111
112
|
if (context.host) result = result.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => username.includes("/") ? `@${username}` : `[@${username}](${context.host}/${username})`);
|
|
112
113
|
return result;
|
|
113
114
|
}
|
|
115
|
+
function extractBreakingText(commit) {
|
|
116
|
+
const body = typeof commit.body === "string" ? commit.body : "";
|
|
117
|
+
const footer = typeof commit.footer === "string" ? commit.footer : "";
|
|
118
|
+
const match = BREAKING_CHANGE_RE.exec(`${footer}\n${body}`);
|
|
119
|
+
if (match?.[1]) return match[1].trim();
|
|
120
|
+
if (typeof commit.subject === "string" && commit.subject) return commit.subject;
|
|
121
|
+
if (typeof commit.header === "string" && commit.header) return commit.header;
|
|
122
|
+
return "";
|
|
123
|
+
}
|
|
114
124
|
function tryParseHeader(commit) {
|
|
115
125
|
if (typeof commit.header !== "string") return null;
|
|
116
126
|
const match = COMMIT_HEADER_RE.exec(commit.header.trim());
|
|
@@ -124,24 +134,19 @@ function tryParseHeader(commit) {
|
|
|
124
134
|
}
|
|
125
135
|
function processBreakingChanges(commit, context, issues) {
|
|
126
136
|
let discard = true;
|
|
127
|
-
commit.notes
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return repoUrl ? ` ([${shortHash}](${repoUrl}/commit/${commit.hash}))` : ` (${shortHash})`;
|
|
133
|
-
};
|
|
134
|
-
const hashLink = getCommitHashLink();
|
|
137
|
+
commit.notes.forEach((note) => {
|
|
138
|
+
note.title = "BREAKING CHANGES";
|
|
139
|
+
discard = false;
|
|
140
|
+
});
|
|
141
|
+
const hadBreakingNotes = commit.notes.length > 0;
|
|
135
142
|
const addBreakingNote = () => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
if (!hadBreakingNotes) {
|
|
144
|
+
const text = linkify(extractBreakingText(commit), context, issues);
|
|
145
|
+
commit.notes.push({
|
|
146
|
+
title: "BREAKING CHANGES",
|
|
147
|
+
text
|
|
148
|
+
});
|
|
140
149
|
}
|
|
141
|
-
commit.notes.push({
|
|
142
|
-
title: "BREAKING CHANGES",
|
|
143
|
-
text
|
|
144
|
-
});
|
|
145
150
|
discard = false;
|
|
146
151
|
};
|
|
147
152
|
const parsed = tryParseHeader(commit);
|
|
@@ -157,51 +162,42 @@ function processBreakingChanges(commit, context, issues) {
|
|
|
157
162
|
}
|
|
158
163
|
return discard;
|
|
159
164
|
}
|
|
160
|
-
function mapCommitType(commit, discard) {
|
|
161
|
-
if (commit.revert)
|
|
162
|
-
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
+
function mapCommitType(commit, discard, showTypes) {
|
|
166
|
+
if (commit.revert) commit.type = "revert";
|
|
167
|
+
if (!commit.type) return false;
|
|
165
168
|
const mapped = COMMIT_TYPE_MAP[commit.type];
|
|
166
169
|
if (mapped) {
|
|
167
|
-
if (
|
|
170
|
+
if (showTypes.includes(commit.type) || !discard) {
|
|
168
171
|
commit.type = mapped;
|
|
169
172
|
return true;
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
return !discard;
|
|
173
176
|
}
|
|
174
|
-
function
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (typeof mutableCommit.hash === "string") mutableCommit.shortHash = mutableCommit.hash.substring(0, 7);
|
|
188
|
-
if (typeof mutableCommit.subject === "string") mutableCommit.subject = linkify(mutableCommit.subject, context, issues);
|
|
189
|
-
if (mutableCommit.references) mutableCommit.references = mutableCommit.references.filter((ref) => !issues.includes(ref.issue));
|
|
190
|
-
return mutableCommit;
|
|
177
|
+
function createDefaultWriterOpts({ showTypes }) {
|
|
178
|
+
return {
|
|
179
|
+
mainTemplate: MAIN_TEMPLATE,
|
|
180
|
+
transform(_commit, context) {
|
|
181
|
+
const commit = JSON.parse(JSON.stringify(_commit));
|
|
182
|
+
const issues = [];
|
|
183
|
+
if (!mapCommitType(commit, processBreakingChanges(commit, context, issues), showTypes)) return null;
|
|
184
|
+
if (commit.scope === "*") commit.scope = "";
|
|
185
|
+
if (typeof commit.hash === "string") commit.shortHash = commit.hash.substring(0, 7);
|
|
186
|
+
if (typeof commit.subject === "string") commit.subject = linkify(commit.subject, context, issues);
|
|
187
|
+
commit.references = commit.references.filter((ref) => !issues.includes(ref.issue));
|
|
188
|
+
return commit;
|
|
189
|
+
}
|
|
191
190
|
};
|
|
192
191
|
}
|
|
193
|
-
function changelog({ cwd = process.cwd(), releaseCount = 0, file = "CHANGELOG.md",
|
|
192
|
+
function changelog({ cwd = process.cwd(), releaseCount = 0, file = "CHANGELOG.md", showTypes = ALWAYS_SHOW_TYPES, outputUnreleased, writerOpt } = {}) {
|
|
194
193
|
const s = spinner();
|
|
195
194
|
s.start("Generating changelog");
|
|
195
|
+
const defaultWriterOpts = writerOpt || createDefaultWriterOpts({ showTypes });
|
|
196
196
|
return new Promise((resolve$1) => {
|
|
197
|
-
new
|
|
197
|
+
new StandardChangelog(cwd).readPackage().options({
|
|
198
198
|
releaseCount,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}).writer({
|
|
202
|
-
mainTemplate,
|
|
203
|
-
transform: (commit) => commit
|
|
204
|
-
}).writeStream().pipe(createWriteStream(resolve(cwd, file))).on("close", () => {
|
|
199
|
+
outputUnreleased
|
|
200
|
+
}).writer(defaultWriterOpts).writeStream().pipe(createWriteStream(resolve(cwd, file))).on("close", () => {
|
|
205
201
|
s.stop("Changelog generated successfully!");
|
|
206
202
|
resolve$1();
|
|
207
203
|
});
|
|
@@ -236,8 +232,8 @@ function unwrapPromptResult(result) {
|
|
|
236
232
|
}
|
|
237
233
|
return result;
|
|
238
234
|
}
|
|
239
|
-
function execGit(...args) {
|
|
240
|
-
return x("git", args, { throwOnError: true });
|
|
235
|
+
async function execGit(...args) {
|
|
236
|
+
return await x("git", args, { throwOnError: true });
|
|
241
237
|
}
|
|
242
238
|
function logStdout(ret) {
|
|
243
239
|
if (ret.stdout) logger.log(ret.stdout);
|
|
@@ -420,7 +416,7 @@ async function release(options) {
|
|
|
420
416
|
}
|
|
421
417
|
}
|
|
422
418
|
//#endregion
|
|
423
|
-
//#region src/
|
|
419
|
+
//#region src/lockfileCheck.ts
|
|
424
420
|
function getLockfilePath(packageManager) {
|
|
425
421
|
switch (packageManager) {
|
|
426
422
|
case "pnpm": return "pnpm-lock.yaml";
|
|
@@ -461,7 +457,7 @@ async function installDependencies(packageManager) {
|
|
|
461
457
|
throw error;
|
|
462
458
|
}
|
|
463
459
|
}
|
|
464
|
-
async function
|
|
460
|
+
async function lockfileCheck(options = {}) {
|
|
465
461
|
try {
|
|
466
462
|
const pkgManager = options.packageManager || "pnpm";
|
|
467
463
|
const installFlag = options.install || false;
|
|
@@ -474,4 +470,4 @@ async function lockfileSyncCheck(options = {}) {
|
|
|
474
470
|
}
|
|
475
471
|
}
|
|
476
472
|
//#endregion
|
|
477
|
-
export { getPackageJsons as a, release as c, COMMIT_HEADER_RE as d, COMMIT_MESSAGE_RE as f, isVersionCommitMessage as h,
|
|
473
|
+
export { getPackageJsons as a, release as c, COMMIT_HEADER_RE as d, COMMIT_MESSAGE_RE as f, isVersionCommitMessage as h, lockfileCheck as i, updateVersion as l, getCommitMessage as m, getLockfilePath as n, isSameVersion as o, commitLint as p, installDependencies as r, publish as s, checkLockfileSync as t, changelog as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/release",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "publish all packages, generate changelogs and check commit messages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"changelog",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@clack/prompts": "^1.2.0",
|
|
34
34
|
"cleye": "^2.3.0",
|
|
35
|
-
"conventional-changelog": "^7.2.0",
|
|
36
35
|
"rslog": "^2.1.1",
|
|
37
36
|
"semver": "^7.7.4",
|
|
37
|
+
"standard-changelog": "^7.0.1",
|
|
38
38
|
"tinyexec": "^1.1.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|