@varlet/release 0.4.4 → 1.0.1
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 +163 -161
- package/README.zh-CN.md +163 -161
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +19 -0
- package/dist/index.d.ts +39 -26
- package/dist/index.js +287 -299
- package/package.json +36 -33
- package/bin/index.js +0 -47
- package/dist/index.cjs +0 -409
- package/dist/index.d.cts +0 -41
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/release",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "publish all packages, generate changelogs and check commit messages",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"varlet",
|
|
7
|
-
"release",
|
|
8
6
|
"changelog",
|
|
9
|
-
"commit-lint"
|
|
7
|
+
"commit-lint",
|
|
8
|
+
"release",
|
|
9
|
+
"varlet"
|
|
10
10
|
],
|
|
11
11
|
"bugs": "https://github.com/varletjs/release/issues",
|
|
12
12
|
"repository": {
|
|
@@ -19,15 +19,12 @@
|
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
|
-
"
|
|
23
|
-
"require": "./dist/index.cjs"
|
|
22
|
+
"default": "./dist/index.js"
|
|
24
23
|
}
|
|
25
24
|
},
|
|
26
|
-
"main": "./dist/index.cjs",
|
|
27
|
-
"module": "./dist/index.js",
|
|
28
25
|
"types": "./dist/index.d.ts",
|
|
29
26
|
"bin": {
|
|
30
|
-
"vr": "
|
|
27
|
+
"vr": "dist/cli.js"
|
|
31
28
|
},
|
|
32
29
|
"files": [
|
|
33
30
|
"dist"
|
|
@@ -37,51 +34,57 @@
|
|
|
37
34
|
"commit-msg": "pnpm run commit-lint -p $1"
|
|
38
35
|
},
|
|
39
36
|
"lint-staged": {
|
|
37
|
+
"*.{md}": "prettier --write",
|
|
40
38
|
"*.{ts,js}": [
|
|
41
39
|
"prettier --write",
|
|
42
40
|
"eslint --fix"
|
|
43
41
|
],
|
|
44
|
-
"
|
|
42
|
+
"package.json": "prettier --write"
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
|
-
"@
|
|
45
|
+
"@clack/prompts": "^1.0.0",
|
|
48
46
|
"commander": "^11.1.0",
|
|
49
47
|
"conventional-changelog": "^5.1.0",
|
|
50
|
-
"fs-extra": "^11.
|
|
51
|
-
"
|
|
52
|
-
"nanospinner": "^1.1.0",
|
|
53
|
-
"rslog": "^1.2.3",
|
|
48
|
+
"fs-extra": "^11.3.3",
|
|
49
|
+
"rslog": "^2.0.0",
|
|
54
50
|
"semver": "^7.5.4",
|
|
55
|
-
"tinyexec": "^0.
|
|
51
|
+
"tinyexec": "^1.0.2"
|
|
56
52
|
},
|
|
57
53
|
"devDependencies": {
|
|
58
54
|
"@configurajs/eslint": "^0.1.2",
|
|
59
55
|
"@configurajs/prettier": "^0.1.4",
|
|
56
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.7.1",
|
|
60
57
|
"@types/conventional-changelog": "^3.1.5",
|
|
61
58
|
"@types/fs-extra": "^11.0.4",
|
|
62
|
-
"@types/node": "^
|
|
59
|
+
"@types/node": "^22.14.0",
|
|
63
60
|
"@types/semver": "^7.5.5",
|
|
64
|
-
"@
|
|
65
|
-
"eslint": "^9.
|
|
66
|
-
"lint-staged": "^
|
|
67
|
-
"prettier": "^3.1
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
61
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
62
|
+
"eslint": "^9.39.2",
|
|
63
|
+
"lint-staged": "^16.2.7",
|
|
64
|
+
"prettier": "^3.8.1",
|
|
65
|
+
"prettier-plugin-packagejson": "^3.0.0",
|
|
66
|
+
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
67
|
+
"rimraf": "^6.1.2",
|
|
68
|
+
"simple-git-hooks": "^2.13.1",
|
|
69
|
+
"tsdown": "^0.20.3",
|
|
70
|
+
"typescript": "^5.9.3",
|
|
71
|
+
"vitest": "^4.0.18"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
|
-
"node": "
|
|
75
|
-
"pnpm": ">=
|
|
74
|
+
"node": "^20.19.0 || >=22.12.0",
|
|
75
|
+
"pnpm": ">=10.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
|
-
"build": "
|
|
78
|
+
"build": "tsdown",
|
|
79
79
|
"clean": "rimraf node_modules dist",
|
|
80
|
-
"commit-lint": "node
|
|
81
|
-
"dev": "
|
|
82
|
-
"format": "prettier --write .",
|
|
83
|
-
"lint": "eslint --
|
|
84
|
-
"release": "pnpm build && node
|
|
80
|
+
"commit-lint": "node dist/cli.js commit-lint",
|
|
81
|
+
"dev": "tsdown --watch",
|
|
82
|
+
"format": "eslint . --fix && prettier --write .",
|
|
83
|
+
"lint": "eslint . && prettier --check .",
|
|
84
|
+
"release": "pnpm build && vitest run && node scripts/release.js",
|
|
85
|
+
"release:dev": "pnpm build && node scripts/release.js",
|
|
86
|
+
"test": "vitest",
|
|
87
|
+
"test:coverage": "vitest run --coverage",
|
|
85
88
|
"type-check": "tsc --noEmit"
|
|
86
89
|
}
|
|
87
90
|
}
|
package/bin/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander'
|
|
3
|
-
import fse from 'fs-extra'
|
|
4
|
-
import { changelog, commitLint, publish, release } from '../dist/index.js'
|
|
5
|
-
|
|
6
|
-
const program = new Command()
|
|
7
|
-
|
|
8
|
-
const packageJson = fse.readJSONSync(new URL('../package.json', import.meta.url))
|
|
9
|
-
|
|
10
|
-
program.version(packageJson.version)
|
|
11
|
-
|
|
12
|
-
program
|
|
13
|
-
.command('release')
|
|
14
|
-
.option('-r --remote <remote>', 'Remote name')
|
|
15
|
-
.option('-s --skip-npm-publish', 'Skip npm publish')
|
|
16
|
-
.option('-sc --skip-changelog', 'Skip generate changelog')
|
|
17
|
-
.option('-sgt --skip-git-tag', 'Skip git tag')
|
|
18
|
-
.option('-nt --npm-tag <npmTag>', 'Npm tag')
|
|
19
|
-
.option('-c --check-remote-version', 'Check remote version')
|
|
20
|
-
.description('Release all packages and generate changelogs')
|
|
21
|
-
.action((options) => release(options))
|
|
22
|
-
|
|
23
|
-
program
|
|
24
|
-
.command('publish')
|
|
25
|
-
.option('-c --check-remote-version', 'Check remote version')
|
|
26
|
-
.option('-nt --npm-tag <npmTag>', 'Npm tag')
|
|
27
|
-
.description('Publish to npm')
|
|
28
|
-
.action((options) => publish(options))
|
|
29
|
-
|
|
30
|
-
program
|
|
31
|
-
.command('changelog')
|
|
32
|
-
.option('-rc --releaseCount <releaseCount>', 'Release count')
|
|
33
|
-
.option('-f --file <file>', 'Changelog filename')
|
|
34
|
-
.option('-p --preset <preset>', 'Changelog preset')
|
|
35
|
-
.description('Generate changelog')
|
|
36
|
-
.action((options) => changelog(options))
|
|
37
|
-
|
|
38
|
-
program
|
|
39
|
-
.command('commit-lint')
|
|
40
|
-
.option('-p --commitMessagePath <path>', 'Git commit message path')
|
|
41
|
-
.option('-r --commitMessageRe <reg>', 'Validate the regular of whether the commit message passes')
|
|
42
|
-
.option('-e --errorMessage <message>', 'Validation failed to display error messages')
|
|
43
|
-
.option('-w --warningMessage <message>', 'Validation failed to display warning messages')
|
|
44
|
-
.description('Lint commit message')
|
|
45
|
-
.action((option) => commitLint(option))
|
|
46
|
-
|
|
47
|
-
program.parse()
|
package/dist/index.cjs
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
COMMIT_MESSAGE_RE: () => COMMIT_MESSAGE_RE,
|
|
34
|
-
changelog: () => changelog,
|
|
35
|
-
commitLint: () => commitLint,
|
|
36
|
-
getCommitMessage: () => getCommitMessage,
|
|
37
|
-
isSameVersion: () => isSameVersion,
|
|
38
|
-
isVersionCommitMessage: () => isVersionCommitMessage,
|
|
39
|
-
publish: () => publish,
|
|
40
|
-
release: () => release,
|
|
41
|
-
updateVersion: () => updateVersion
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(src_exports);
|
|
44
|
-
|
|
45
|
-
// src/release.ts
|
|
46
|
-
var import_path2 = require("path");
|
|
47
|
-
var import_prompts = require("@inquirer/prompts");
|
|
48
|
-
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
49
|
-
var import_glob = require("glob");
|
|
50
|
-
var import_nanospinner2 = require("nanospinner");
|
|
51
|
-
var import_rslog = require("rslog");
|
|
52
|
-
var import_semver = __toESM(require("semver"), 1);
|
|
53
|
-
var import_tinyexec = require("tinyexec");
|
|
54
|
-
|
|
55
|
-
// src/changelog.ts
|
|
56
|
-
var import_path = require("path");
|
|
57
|
-
var import_conventional_changelog = __toESM(require("conventional-changelog"), 1);
|
|
58
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
59
|
-
var import_nanospinner = require("nanospinner");
|
|
60
|
-
var { createWriteStream } = import_fs_extra.default;
|
|
61
|
-
function changelog({
|
|
62
|
-
releaseCount = 0,
|
|
63
|
-
file = "CHANGELOG.md",
|
|
64
|
-
preset = "angular",
|
|
65
|
-
writerOpts = {
|
|
66
|
-
transform(commit, context) {
|
|
67
|
-
let discard = true;
|
|
68
|
-
const issues = [];
|
|
69
|
-
commit.notes.forEach((note) => {
|
|
70
|
-
note.title = "BREAKING CHANGES";
|
|
71
|
-
discard = false;
|
|
72
|
-
});
|
|
73
|
-
if (commit.type === "feat") {
|
|
74
|
-
commit.type = "Features";
|
|
75
|
-
} else if (commit.type === "fix") {
|
|
76
|
-
commit.type = "Bug Fixes";
|
|
77
|
-
} else if (commit.type === "perf") {
|
|
78
|
-
commit.type = "Performance Improvements";
|
|
79
|
-
} else if (commit.type === "revert" || commit.revert) {
|
|
80
|
-
commit.type = "Reverts";
|
|
81
|
-
} else if (commit.type === "refactor") {
|
|
82
|
-
commit.type = "Code Refactoring";
|
|
83
|
-
} else if (discard) {
|
|
84
|
-
return false;
|
|
85
|
-
} else if (commit.type === "docs") {
|
|
86
|
-
commit.type = "Documentation";
|
|
87
|
-
} else if (commit.type === "style") {
|
|
88
|
-
commit.type = "Styles";
|
|
89
|
-
} else if (commit.type === "test") {
|
|
90
|
-
commit.type = "Tests";
|
|
91
|
-
} else if (commit.type === "build") {
|
|
92
|
-
commit.type = "Build System";
|
|
93
|
-
} else if (commit.type === "ci") {
|
|
94
|
-
commit.type = "Continuous Integration";
|
|
95
|
-
}
|
|
96
|
-
if (commit.scope === "*") {
|
|
97
|
-
commit.scope = "";
|
|
98
|
-
}
|
|
99
|
-
if (typeof commit.hash === "string") {
|
|
100
|
-
commit.shortHash = commit.hash.substring(0, 7);
|
|
101
|
-
}
|
|
102
|
-
if (typeof commit.subject === "string") {
|
|
103
|
-
let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl;
|
|
104
|
-
if (url) {
|
|
105
|
-
url = `${url}/issues/`;
|
|
106
|
-
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
|
|
107
|
-
issues.push(issue);
|
|
108
|
-
return `[#${issue}](${url}${issue})`;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (context.host) {
|
|
112
|
-
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
|
|
113
|
-
if (username.includes("/")) {
|
|
114
|
-
return `@${username}`;
|
|
115
|
-
}
|
|
116
|
-
return `[@${username}](${context.host}/${username})`;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
commit.references = commit.references.filter((reference) => {
|
|
121
|
-
if (issues.indexOf(reference.issue) === -1) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
});
|
|
126
|
-
return commit;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
} = {}) {
|
|
130
|
-
const s = (0, import_nanospinner.createSpinner)("Generating changelog").start();
|
|
131
|
-
return new Promise((resolve2) => {
|
|
132
|
-
(0, import_conventional_changelog.default)(
|
|
133
|
-
{
|
|
134
|
-
preset,
|
|
135
|
-
releaseCount
|
|
136
|
-
},
|
|
137
|
-
void 0,
|
|
138
|
-
void 0,
|
|
139
|
-
void 0,
|
|
140
|
-
writerOpts
|
|
141
|
-
).pipe(createWriteStream((0, import_path.resolve)(process.cwd(), file))).on("close", () => {
|
|
142
|
-
s.success({ text: "Changelog generated success!" });
|
|
143
|
-
resolve2();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/release.ts
|
|
149
|
-
var cwd = process.cwd();
|
|
150
|
-
var { writeFileSync, readJSONSync } = import_fs_extra2.default;
|
|
151
|
-
var releaseTypes = ["patch", "minor", "major", "prepatch", "preminor", "premajor"];
|
|
152
|
-
var BACK_HINT = "Back to previous step";
|
|
153
|
-
async function isWorktreeEmpty() {
|
|
154
|
-
const ret = await (0, import_tinyexec.x)("git", ["status", "--porcelain"]);
|
|
155
|
-
return !ret.stdout;
|
|
156
|
-
}
|
|
157
|
-
async function isSameVersion(version) {
|
|
158
|
-
const s = (0, import_nanospinner2.createSpinner)("Check remote version...").start();
|
|
159
|
-
const packageJsones = getPackageJsons();
|
|
160
|
-
const packageJson = packageJsones.find((packageJson2) => !packageJson2.config.private) || packageJsones[0];
|
|
161
|
-
if (packageJson) {
|
|
162
|
-
const { config } = packageJson;
|
|
163
|
-
try {
|
|
164
|
-
await (0, import_tinyexec.x)("npm", ["view", `${config.name}@${version ?? config.version}`, "version"], {
|
|
165
|
-
throwOnError: true
|
|
166
|
-
});
|
|
167
|
-
s.warn({
|
|
168
|
-
text: `The npm package has a same remote version ${version ?? config.version}.`
|
|
169
|
-
});
|
|
170
|
-
return true;
|
|
171
|
-
} catch {
|
|
172
|
-
s.success();
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async function publish({ preRelease, checkRemoteVersion, npmTag }) {
|
|
178
|
-
const s = (0, import_nanospinner2.createSpinner)("Publishing all packages").start();
|
|
179
|
-
const args = ["-r", "publish", "--no-git-checks", "--access", "public"];
|
|
180
|
-
if (checkRemoteVersion && await isSameVersion()) {
|
|
181
|
-
import_rslog.logger.error("publishing automatically skipped.");
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (preRelease) {
|
|
185
|
-
args.push("--tag", "alpha");
|
|
186
|
-
} else if (npmTag) {
|
|
187
|
-
args.push("--tag", npmTag);
|
|
188
|
-
}
|
|
189
|
-
const ret = await (0, import_tinyexec.x)("pnpm", args, { throwOnError: true });
|
|
190
|
-
s.success({ text: "Publish all packages successfully" });
|
|
191
|
-
ret.stdout && import_rslog.logger.log(ret.stdout);
|
|
192
|
-
}
|
|
193
|
-
async function pushGit(version, remote = "origin", skipGitTag = false) {
|
|
194
|
-
const s = (0, import_nanospinner2.createSpinner)("Pushing to remote git repository").start();
|
|
195
|
-
await (0, import_tinyexec.x)("git", ["add", "."], {
|
|
196
|
-
throwOnError: true
|
|
197
|
-
});
|
|
198
|
-
await (0, import_tinyexec.x)("git", ["commit", "-m", `v${version}`], {
|
|
199
|
-
throwOnError: true
|
|
200
|
-
});
|
|
201
|
-
if (!skipGitTag) {
|
|
202
|
-
await (0, import_tinyexec.x)("git", ["tag", `v${version}`], {
|
|
203
|
-
throwOnError: true
|
|
204
|
-
});
|
|
205
|
-
await (0, import_tinyexec.x)("git", ["push", remote, `v${version}`], {
|
|
206
|
-
throwOnError: true
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
const ret = await (0, import_tinyexec.x)("git", ["push"], {
|
|
210
|
-
throwOnError: true
|
|
211
|
-
});
|
|
212
|
-
s.success({ text: "Push remote repository successfully" });
|
|
213
|
-
ret.stdout && import_rslog.logger.log(ret.stdout);
|
|
214
|
-
}
|
|
215
|
-
function getPackageJsons() {
|
|
216
|
-
const packageJsons = ["package.json", ...import_glob.glob.sync("packages/*/package.json")];
|
|
217
|
-
return packageJsons.map((path) => {
|
|
218
|
-
const filePath = (0, import_path2.resolve)(cwd, path);
|
|
219
|
-
return {
|
|
220
|
-
config: readJSONSync(filePath),
|
|
221
|
-
filePath
|
|
222
|
-
};
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
function updateVersion(version) {
|
|
226
|
-
const packageJsons = getPackageJsons();
|
|
227
|
-
packageJsons.forEach(({ config, filePath }) => {
|
|
228
|
-
config.version = version;
|
|
229
|
-
writeFileSync(filePath, JSON.stringify(config, null, 2));
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
async function confirmRegistry() {
|
|
233
|
-
const registry = (await (0, import_tinyexec.x)("npm", ["config", "get", "registry"])).stdout;
|
|
234
|
-
const ret = await (0, import_prompts.confirm)({
|
|
235
|
-
message: `Current registry is: ${registry}`
|
|
236
|
-
});
|
|
237
|
-
return ret;
|
|
238
|
-
}
|
|
239
|
-
async function confirmVersion(currentVersion, expectVersion) {
|
|
240
|
-
const ret = await (0, import_prompts.select)({
|
|
241
|
-
message: "Version confirm",
|
|
242
|
-
choices: [`All packages version ${currentVersion} -> ${expectVersion}`, BACK_HINT].map((value) => ({
|
|
243
|
-
name: value,
|
|
244
|
-
value
|
|
245
|
-
}))
|
|
246
|
-
});
|
|
247
|
-
return ret;
|
|
248
|
-
}
|
|
249
|
-
async function confirmRefs(remote = "origin") {
|
|
250
|
-
const { stdout } = await (0, import_tinyexec.x)("git", ["remote", "-v"]);
|
|
251
|
-
const reg = new RegExp(`${remote} (.*) \\(push`);
|
|
252
|
-
const repo = stdout.match(reg)?.[1];
|
|
253
|
-
const { stdout: branch } = await (0, import_tinyexec.x)("git", ["branch", "--show-current"]);
|
|
254
|
-
const ret = await (0, import_prompts.confirm)({
|
|
255
|
-
message: `Current refs ${repo}:refs/for/${branch}`
|
|
256
|
-
});
|
|
257
|
-
return ret;
|
|
258
|
-
}
|
|
259
|
-
async function getReleaseType() {
|
|
260
|
-
const releaseType = await (0, import_prompts.select)({
|
|
261
|
-
message: "Please select release type",
|
|
262
|
-
choices: releaseTypes.map((type) => ({ name: type, value: type }))
|
|
263
|
-
});
|
|
264
|
-
return releaseType;
|
|
265
|
-
}
|
|
266
|
-
async function getReleaseVersion(currentVersion) {
|
|
267
|
-
let isPreRelease = false;
|
|
268
|
-
let expectVersion = "";
|
|
269
|
-
let confirmVersionRet = "";
|
|
270
|
-
do {
|
|
271
|
-
const type = await getReleaseType();
|
|
272
|
-
isPreRelease = type.startsWith("pre");
|
|
273
|
-
expectVersion = import_semver.default.inc(currentVersion, type, `alpha.${Date.now()}`);
|
|
274
|
-
expectVersion = isPreRelease ? expectVersion.slice(0, -2) : expectVersion;
|
|
275
|
-
confirmVersionRet = await confirmVersion(currentVersion, expectVersion);
|
|
276
|
-
} while (confirmVersionRet === BACK_HINT);
|
|
277
|
-
return { isPreRelease, expectVersion };
|
|
278
|
-
}
|
|
279
|
-
async function release(options) {
|
|
280
|
-
try {
|
|
281
|
-
const currentVersion = readJSONSync((0, import_path2.resolve)(cwd, "package.json")).version;
|
|
282
|
-
if (!currentVersion) {
|
|
283
|
-
import_rslog.logger.error("Your package is missing the version field");
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
if (!await isWorktreeEmpty()) {
|
|
287
|
-
import_rslog.logger.error("Git worktree is not empty, please commit changed");
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (!await confirmRefs(options.remote)) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
if (!options.skipNpmPublish && !await confirmRegistry()) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const { isPreRelease, expectVersion } = await getReleaseVersion(currentVersion);
|
|
297
|
-
if (options.checkRemoteVersion && await isSameVersion(expectVersion)) {
|
|
298
|
-
import_rslog.logger.error("Please check remote version.");
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
updateVersion(expectVersion);
|
|
302
|
-
if (options.task) {
|
|
303
|
-
await options.task(expectVersion, currentVersion);
|
|
304
|
-
}
|
|
305
|
-
if (!options.skipNpmPublish) {
|
|
306
|
-
await publish({ preRelease: isPreRelease, npmTag: options.npmTag });
|
|
307
|
-
}
|
|
308
|
-
if (!isPreRelease) {
|
|
309
|
-
if (!options.skipChangelog) {
|
|
310
|
-
await changelog();
|
|
311
|
-
}
|
|
312
|
-
await pushGit(expectVersion, options.remote, options.skipGitTag);
|
|
313
|
-
}
|
|
314
|
-
import_rslog.logger.success(`Release version ${expectVersion} successfully!`);
|
|
315
|
-
if (isPreRelease) {
|
|
316
|
-
try {
|
|
317
|
-
await (0, import_tinyexec.x)("git", ["restore", "**/package.json"], {
|
|
318
|
-
throwOnError: true
|
|
319
|
-
});
|
|
320
|
-
} catch {
|
|
321
|
-
}
|
|
322
|
-
try {
|
|
323
|
-
await (0, import_tinyexec.x)("git", ["restore", "package.json"], {
|
|
324
|
-
throwOnError: true
|
|
325
|
-
});
|
|
326
|
-
} catch {
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
} catch (error) {
|
|
330
|
-
import_rslog.logger.error(error.toString());
|
|
331
|
-
process.exit(1);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// src/commitLint.ts
|
|
336
|
-
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
337
|
-
var import_rslog2 = require("rslog");
|
|
338
|
-
var import_semver2 = __toESM(require("semver"), 1);
|
|
339
|
-
var { readFileSync } = import_fs_extra3.default;
|
|
340
|
-
var COMMIT_MESSAGE_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor|merge|wip)(\(.+\))?!?: (.|\n)+/;
|
|
341
|
-
var ERROR_MESSAGE = "Commit message invalid.";
|
|
342
|
-
var WARNING_MESSAGE = `The rules for commit messages are as follows
|
|
343
|
-
|
|
344
|
-
Example:
|
|
345
|
-
|
|
346
|
-
feat: add a new feature
|
|
347
|
-
feat(ui/button): add a new feature in the ui/button scope
|
|
348
|
-
|
|
349
|
-
fix: fix a bug
|
|
350
|
-
fix(ui/button): fix a bug in the ui/button scope
|
|
351
|
-
|
|
352
|
-
docs: fix an error in the documentation
|
|
353
|
-
docs(ui/button): fix a documentation error in the ui/button scope
|
|
354
|
-
|
|
355
|
-
Allowed types:
|
|
356
|
-
- fix
|
|
357
|
-
- feat
|
|
358
|
-
- docs
|
|
359
|
-
- perf
|
|
360
|
-
- test
|
|
361
|
-
- types
|
|
362
|
-
- style
|
|
363
|
-
- build
|
|
364
|
-
- chore
|
|
365
|
-
- release
|
|
366
|
-
- refactor
|
|
367
|
-
- revert
|
|
368
|
-
- merge
|
|
369
|
-
- wip
|
|
370
|
-
|
|
371
|
-
Commit message reference: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y
|
|
372
|
-
\u53C2\u8003\u962E\u4E00\u5CF0Commit message\u7F16\u5199\u6307\u5357: https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html`;
|
|
373
|
-
function isVersionCommitMessage(message) {
|
|
374
|
-
return message.startsWith("v") && import_semver2.default.valid(message.slice(1));
|
|
375
|
-
}
|
|
376
|
-
function getCommitMessage(commitMessagePath) {
|
|
377
|
-
return readFileSync(commitMessagePath, "utf-8").trim();
|
|
378
|
-
}
|
|
379
|
-
function commitLint(options) {
|
|
380
|
-
const {
|
|
381
|
-
commitMessagePath,
|
|
382
|
-
commitMessageRe = COMMIT_MESSAGE_RE,
|
|
383
|
-
errorMessage = ERROR_MESSAGE,
|
|
384
|
-
warningMessage = WARNING_MESSAGE
|
|
385
|
-
} = options;
|
|
386
|
-
if (!commitMessagePath) {
|
|
387
|
-
import_rslog2.logger.error("commitMessagePath is required");
|
|
388
|
-
process.exit(1);
|
|
389
|
-
}
|
|
390
|
-
const commitMessage = getCommitMessage(commitMessagePath);
|
|
391
|
-
const isValidCommitMessage = new RegExp(commitMessageRe).test(commitMessage);
|
|
392
|
-
if (!isVersionCommitMessage(commitMessage) && !isValidCommitMessage) {
|
|
393
|
-
import_rslog2.logger.error(errorMessage);
|
|
394
|
-
import_rslog2.logger.warn(warningMessage);
|
|
395
|
-
process.exit(1);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
399
|
-
0 && (module.exports = {
|
|
400
|
-
COMMIT_MESSAGE_RE,
|
|
401
|
-
changelog,
|
|
402
|
-
commitLint,
|
|
403
|
-
getCommitMessage,
|
|
404
|
-
isSameVersion,
|
|
405
|
-
isVersionCommitMessage,
|
|
406
|
-
publish,
|
|
407
|
-
release,
|
|
408
|
-
updateVersion
|
|
409
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import conventionalChangelog from 'conventional-changelog';
|
|
2
|
-
|
|
3
|
-
declare function isSameVersion(version?: string): Promise<boolean | undefined>;
|
|
4
|
-
interface PublishCommandOptions {
|
|
5
|
-
preRelease?: boolean;
|
|
6
|
-
checkRemoteVersion?: boolean;
|
|
7
|
-
npmTag?: string;
|
|
8
|
-
}
|
|
9
|
-
declare function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>;
|
|
10
|
-
declare function updateVersion(version: string): void;
|
|
11
|
-
interface ReleaseCommandOptions {
|
|
12
|
-
remote?: string;
|
|
13
|
-
npmTag?: string;
|
|
14
|
-
skipNpmPublish?: boolean;
|
|
15
|
-
skipChangelog?: boolean;
|
|
16
|
-
skipGitTag?: boolean;
|
|
17
|
-
checkRemoteVersion?: boolean;
|
|
18
|
-
task?(newVersion: string, oldVersion: string): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
declare function release(options: ReleaseCommandOptions): Promise<void>;
|
|
21
|
-
|
|
22
|
-
interface ChangelogCommandOptions {
|
|
23
|
-
file?: string;
|
|
24
|
-
releaseCount?: number;
|
|
25
|
-
preset?: 'angular' | 'atom' | 'codemirror' | 'conventionalcommits' | 'ember' | 'eslint' | 'express' | 'jquery' | 'jshint';
|
|
26
|
-
writerOpts?: Parameters<typeof conventionalChangelog>['4'];
|
|
27
|
-
}
|
|
28
|
-
declare function changelog({ releaseCount, file, preset, writerOpts, }?: ChangelogCommandOptions): Promise<void>;
|
|
29
|
-
|
|
30
|
-
declare const COMMIT_MESSAGE_RE: RegExp;
|
|
31
|
-
declare function isVersionCommitMessage(message: string): string | false | null;
|
|
32
|
-
declare function getCommitMessage(commitMessagePath: string): string;
|
|
33
|
-
interface CommitLintCommandOptions {
|
|
34
|
-
commitMessagePath: string;
|
|
35
|
-
commitMessageRe?: string | RegExp;
|
|
36
|
-
errorMessage?: string;
|
|
37
|
-
warningMessage?: string;
|
|
38
|
-
}
|
|
39
|
-
declare function commitLint(options: CommitLintCommandOptions): void;
|
|
40
|
-
|
|
41
|
-
export { COMMIT_MESSAGE_RE, type ChangelogCommandOptions, type CommitLintCommandOptions, type PublishCommandOptions, type ReleaseCommandOptions, changelog, commitLint, getCommitMessage, isSameVersion, isVersionCommitMessage, publish, release, updateVersion };
|