@varlet/release 0.2.11 → 0.3.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/bin/index.js +47 -41
- package/dist/index.cjs +52 -52
- package/dist/index.js +52 -52
- package/package.json +5 -6
package/bin/index.js
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { release, publish, changelog, commitLint } from '../dist/index.js'
|
|
3
|
-
import { Command } from 'commander'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
program
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
.option('-c --check-remote-version', 'Check remote version')
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
.option('-
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
.option('-
|
|
35
|
-
.
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { release, publish, changelog, commitLint } from '../dist/index.js'
|
|
3
|
+
import { Command } from 'commander'
|
|
4
|
+
import { fileURLToPath } from 'url'
|
|
5
|
+
import fse from 'fs-extra'
|
|
6
|
+
|
|
7
|
+
const program = new Command()
|
|
8
|
+
|
|
9
|
+
const packageJson = fse.readJSONSync(fileURLToPath(new URL('../package.json', import.meta.url)))
|
|
10
|
+
|
|
11
|
+
program.version(packageJson.version)
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.command('release')
|
|
15
|
+
.option('-r --remote <remote>', 'Remote name')
|
|
16
|
+
.option('-s --skip-npm-publish', 'Skip npm publish')
|
|
17
|
+
.option('-sc --skip-changelog', 'Skip generate changelog')
|
|
18
|
+
.option('-sgt --skip-git-tag', 'Skip git tag')
|
|
19
|
+
.option('-nt --npm-tag <npmTag>', 'Npm tag')
|
|
20
|
+
.option('-c --check-remote-version', 'Check remote version')
|
|
21
|
+
.description('Release all packages and generate changelogs')
|
|
22
|
+
.action(async (options) => release(options))
|
|
23
|
+
|
|
24
|
+
program
|
|
25
|
+
.command('publish')
|
|
26
|
+
.option('-c --check-remote-version', 'Check remote version')
|
|
27
|
+
.option('-nt --npm-tag <npmTag>', 'Npm tag')
|
|
28
|
+
.description('Publish to npm')
|
|
29
|
+
.action(async (options) => publish(options))
|
|
30
|
+
|
|
31
|
+
program
|
|
32
|
+
.command('changelog')
|
|
33
|
+
.option('-rc --releaseCount <releaseCount>', 'Release count')
|
|
34
|
+
.option('-f --file <file>', 'Changelog filename')
|
|
35
|
+
.description('Generate changelog')
|
|
36
|
+
.action(async (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(async (option) => commitLint(option))
|
|
46
|
+
|
|
47
|
+
program.parse()
|
package/dist/index.cjs
CHANGED
|
@@ -67,8 +67,8 @@ var logger_default = {
|
|
|
67
67
|
|
|
68
68
|
// src/release.ts
|
|
69
69
|
var import_semver = __toESM(require("semver"), 1);
|
|
70
|
-
var
|
|
71
|
-
var
|
|
70
|
+
var import_prompts = require("@inquirer/prompts");
|
|
71
|
+
var import_tinyexec = require("tinyexec");
|
|
72
72
|
var import_nanospinner2 = require("nanospinner");
|
|
73
73
|
var import_glob = require("glob");
|
|
74
74
|
var import_path2 = require("path");
|
|
@@ -95,11 +95,10 @@ function changelog({ releaseCount = 0, file = "CHANGELOG.md" } = {}) {
|
|
|
95
95
|
// src/release.ts
|
|
96
96
|
var cwd = process.cwd();
|
|
97
97
|
var { writeFileSync, readJSONSync } = import_fs_extra2.default;
|
|
98
|
-
var { prompt } = import_inquirer.default;
|
|
99
98
|
var releaseTypes = ["premajor", "preminor", "prepatch", "major", "minor", "patch"];
|
|
100
99
|
var BACK_HINT = "Back to previous step";
|
|
101
100
|
async function isWorktreeEmpty() {
|
|
102
|
-
const ret = await (0,
|
|
101
|
+
const ret = await (0, import_tinyexec.x)("git", ["status", "--porcelain"]);
|
|
103
102
|
return !ret.stdout;
|
|
104
103
|
}
|
|
105
104
|
async function isSameVersion(version) {
|
|
@@ -109,7 +108,9 @@ async function isSameVersion(version) {
|
|
|
109
108
|
if (packageJson) {
|
|
110
109
|
const { config } = packageJson;
|
|
111
110
|
try {
|
|
112
|
-
await (0,
|
|
111
|
+
await (0, import_tinyexec.x)("npm", ["view", `${config.name}@${version ?? config.version}`, "version"], {
|
|
112
|
+
throwOnError: true
|
|
113
|
+
});
|
|
113
114
|
s.warn({
|
|
114
115
|
text: `The npm package has a same remote version ${config.version}.`
|
|
115
116
|
});
|
|
@@ -132,7 +133,7 @@ async function publish({ preRelease, checkRemoteVersion, npmTag }) {
|
|
|
132
133
|
} else if (npmTag) {
|
|
133
134
|
args.push("--tag", npmTag);
|
|
134
135
|
}
|
|
135
|
-
const ret = await (0,
|
|
136
|
+
const ret = await (0, import_tinyexec.x)("pnpm", args);
|
|
136
137
|
if (ret.stderr && ret.stderr.includes("npm ERR!")) {
|
|
137
138
|
throw new Error("\n" + ret.stderr);
|
|
138
139
|
} else {
|
|
@@ -142,13 +143,23 @@ async function publish({ preRelease, checkRemoteVersion, npmTag }) {
|
|
|
142
143
|
}
|
|
143
144
|
async function pushGit(version, remote = "origin", skipGitTag = false) {
|
|
144
145
|
const s = (0, import_nanospinner2.createSpinner)("Pushing to remote git repository").start();
|
|
145
|
-
await (0,
|
|
146
|
-
|
|
146
|
+
await (0, import_tinyexec.x)("git", ["add", "."], {
|
|
147
|
+
throwOnError: true
|
|
148
|
+
});
|
|
149
|
+
await (0, import_tinyexec.x)("git", ["commit", "-m", `v${version}`], {
|
|
150
|
+
throwOnError: true
|
|
151
|
+
});
|
|
147
152
|
if (!skipGitTag) {
|
|
148
|
-
await (0,
|
|
149
|
-
|
|
153
|
+
await (0, import_tinyexec.x)("git", ["tag", `v${version}`], {
|
|
154
|
+
throwOnError: true
|
|
155
|
+
});
|
|
156
|
+
await (0, import_tinyexec.x)("git", ["push", remote, `v${version}`], {
|
|
157
|
+
throwOnError: true
|
|
158
|
+
});
|
|
150
159
|
}
|
|
151
|
-
const ret = await (0,
|
|
160
|
+
const ret = await (0, import_tinyexec.x)("git", ["push"], {
|
|
161
|
+
throwOnError: true
|
|
162
|
+
});
|
|
152
163
|
s.success({ text: "Push remote repository successfully" });
|
|
153
164
|
ret.stdout && logger_default.info(ret.stdout);
|
|
154
165
|
}
|
|
@@ -170,53 +181,38 @@ function updateVersion(version) {
|
|
|
170
181
|
});
|
|
171
182
|
}
|
|
172
183
|
async function confirmRegistry() {
|
|
173
|
-
const registry = (await (0,
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
type: "confirm",
|
|
179
|
-
message: `Current registry is: ${registry}`
|
|
180
|
-
}
|
|
181
|
-
]);
|
|
182
|
-
return ret[name];
|
|
184
|
+
const registry = (await (0, import_tinyexec.x)("npm", ["config", "get", "registry"])).stdout;
|
|
185
|
+
const ret = await (0, import_prompts.confirm)({
|
|
186
|
+
message: `Current registry is: ${registry}`
|
|
187
|
+
});
|
|
188
|
+
return ret;
|
|
183
189
|
}
|
|
184
190
|
async function confirmVersion(currentVersion, expectVersion) {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
{
|
|
188
|
-
name,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return ret[name];
|
|
191
|
+
const ret = await (0, import_prompts.select)({
|
|
192
|
+
message: "Version confirm",
|
|
193
|
+
choices: [`All packages version ${currentVersion} -> ${expectVersion}`, BACK_HINT].map((value) => ({
|
|
194
|
+
name: value,
|
|
195
|
+
value
|
|
196
|
+
}))
|
|
197
|
+
});
|
|
198
|
+
return ret;
|
|
194
199
|
}
|
|
195
200
|
async function confirmRefs(remote = "origin") {
|
|
196
|
-
const { stdout } = await (0,
|
|
201
|
+
const { stdout } = await (0, import_tinyexec.x)("git", ["remote", "-v"]);
|
|
197
202
|
const reg = new RegExp(`${remote} (.*) \\(push`);
|
|
198
203
|
const repo = stdout.match(reg)?.[1];
|
|
199
|
-
const { stdout: branch } = await (0,
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
type: "confirm",
|
|
205
|
-
message: `Current refs ${repo}:refs/for/${branch}`
|
|
206
|
-
}
|
|
207
|
-
]);
|
|
208
|
-
return ret[name];
|
|
204
|
+
const { stdout: branch } = await (0, import_tinyexec.x)("git", ["branch", "--show-current"]);
|
|
205
|
+
const ret = await (0, import_prompts.confirm)({
|
|
206
|
+
message: `Current refs ${repo}:refs/for/${branch}`
|
|
207
|
+
});
|
|
208
|
+
return ret;
|
|
209
209
|
}
|
|
210
210
|
async function getReleaseType() {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
{
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
choices: releaseTypes
|
|
217
|
-
}
|
|
218
|
-
]);
|
|
219
|
-
return ret[name];
|
|
211
|
+
const releaseType = await (0, import_prompts.select)({
|
|
212
|
+
message: "Please select release type",
|
|
213
|
+
choices: releaseTypes.map((type) => ({ name: type, value: type }))
|
|
214
|
+
});
|
|
215
|
+
return releaseType;
|
|
220
216
|
}
|
|
221
217
|
async function getReleaseVersion(currentVersion) {
|
|
222
218
|
let isPreRelease = false;
|
|
@@ -269,11 +265,15 @@ async function release(options) {
|
|
|
269
265
|
logger_default.success(`Release version ${expectVersion} successfully!`);
|
|
270
266
|
if (isPreRelease) {
|
|
271
267
|
try {
|
|
272
|
-
await (0,
|
|
268
|
+
await (0, import_tinyexec.x)("git", ["restore", "**/package.json"], {
|
|
269
|
+
throwOnError: true
|
|
270
|
+
});
|
|
273
271
|
} catch {
|
|
274
272
|
}
|
|
275
273
|
try {
|
|
276
|
-
await (0,
|
|
274
|
+
await (0, import_tinyexec.x)("git", ["restore", "package.json"], {
|
|
275
|
+
throwOnError: true
|
|
276
|
+
});
|
|
277
277
|
} catch {
|
|
278
278
|
}
|
|
279
279
|
}
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var logger_default = {
|
|
|
23
23
|
|
|
24
24
|
// src/release.ts
|
|
25
25
|
import semver from "semver";
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
26
|
+
import { confirm, select } from "@inquirer/prompts";
|
|
27
|
+
import { x as exec } from "tinyexec";
|
|
28
28
|
import { createSpinner as createSpinner2 } from "nanospinner";
|
|
29
29
|
import { glob } from "glob";
|
|
30
30
|
import { resolve } from "path";
|
|
@@ -51,11 +51,10 @@ function changelog({ releaseCount = 0, file = "CHANGELOG.md" } = {}) {
|
|
|
51
51
|
// src/release.ts
|
|
52
52
|
var cwd = process.cwd();
|
|
53
53
|
var { writeFileSync, readJSONSync } = fse2;
|
|
54
|
-
var { prompt } = inquirer;
|
|
55
54
|
var releaseTypes = ["premajor", "preminor", "prepatch", "major", "minor", "patch"];
|
|
56
55
|
var BACK_HINT = "Back to previous step";
|
|
57
56
|
async function isWorktreeEmpty() {
|
|
58
|
-
const ret = await
|
|
57
|
+
const ret = await exec("git", ["status", "--porcelain"]);
|
|
59
58
|
return !ret.stdout;
|
|
60
59
|
}
|
|
61
60
|
async function isSameVersion(version) {
|
|
@@ -65,7 +64,9 @@ async function isSameVersion(version) {
|
|
|
65
64
|
if (packageJson) {
|
|
66
65
|
const { config } = packageJson;
|
|
67
66
|
try {
|
|
68
|
-
await
|
|
67
|
+
await exec("npm", ["view", `${config.name}@${version ?? config.version}`, "version"], {
|
|
68
|
+
throwOnError: true
|
|
69
|
+
});
|
|
69
70
|
s.warn({
|
|
70
71
|
text: `The npm package has a same remote version ${config.version}.`
|
|
71
72
|
});
|
|
@@ -88,7 +89,7 @@ async function publish({ preRelease, checkRemoteVersion, npmTag }) {
|
|
|
88
89
|
} else if (npmTag) {
|
|
89
90
|
args.push("--tag", npmTag);
|
|
90
91
|
}
|
|
91
|
-
const ret = await
|
|
92
|
+
const ret = await exec("pnpm", args);
|
|
92
93
|
if (ret.stderr && ret.stderr.includes("npm ERR!")) {
|
|
93
94
|
throw new Error("\n" + ret.stderr);
|
|
94
95
|
} else {
|
|
@@ -98,13 +99,23 @@ async function publish({ preRelease, checkRemoteVersion, npmTag }) {
|
|
|
98
99
|
}
|
|
99
100
|
async function pushGit(version, remote = "origin", skipGitTag = false) {
|
|
100
101
|
const s = createSpinner2("Pushing to remote git repository").start();
|
|
101
|
-
await
|
|
102
|
-
|
|
102
|
+
await exec("git", ["add", "."], {
|
|
103
|
+
throwOnError: true
|
|
104
|
+
});
|
|
105
|
+
await exec("git", ["commit", "-m", `v${version}`], {
|
|
106
|
+
throwOnError: true
|
|
107
|
+
});
|
|
103
108
|
if (!skipGitTag) {
|
|
104
|
-
await
|
|
105
|
-
|
|
109
|
+
await exec("git", ["tag", `v${version}`], {
|
|
110
|
+
throwOnError: true
|
|
111
|
+
});
|
|
112
|
+
await exec("git", ["push", remote, `v${version}`], {
|
|
113
|
+
throwOnError: true
|
|
114
|
+
});
|
|
106
115
|
}
|
|
107
|
-
const ret = await
|
|
116
|
+
const ret = await exec("git", ["push"], {
|
|
117
|
+
throwOnError: true
|
|
118
|
+
});
|
|
108
119
|
s.success({ text: "Push remote repository successfully" });
|
|
109
120
|
ret.stdout && logger_default.info(ret.stdout);
|
|
110
121
|
}
|
|
@@ -126,53 +137,38 @@ function updateVersion(version) {
|
|
|
126
137
|
});
|
|
127
138
|
}
|
|
128
139
|
async function confirmRegistry() {
|
|
129
|
-
const registry = (await
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
type: "confirm",
|
|
135
|
-
message: `Current registry is: ${registry}`
|
|
136
|
-
}
|
|
137
|
-
]);
|
|
138
|
-
return ret[name];
|
|
140
|
+
const registry = (await exec("npm", ["config", "get", "registry"])).stdout;
|
|
141
|
+
const ret = await confirm({
|
|
142
|
+
message: `Current registry is: ${registry}`
|
|
143
|
+
});
|
|
144
|
+
return ret;
|
|
139
145
|
}
|
|
140
146
|
async function confirmVersion(currentVersion, expectVersion) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
{
|
|
144
|
-
name,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return ret[name];
|
|
147
|
+
const ret = await select({
|
|
148
|
+
message: "Version confirm",
|
|
149
|
+
choices: [`All packages version ${currentVersion} -> ${expectVersion}`, BACK_HINT].map((value) => ({
|
|
150
|
+
name: value,
|
|
151
|
+
value
|
|
152
|
+
}))
|
|
153
|
+
});
|
|
154
|
+
return ret;
|
|
150
155
|
}
|
|
151
156
|
async function confirmRefs(remote = "origin") {
|
|
152
|
-
const { stdout } = await
|
|
157
|
+
const { stdout } = await exec("git", ["remote", "-v"]);
|
|
153
158
|
const reg = new RegExp(`${remote} (.*) \\(push`);
|
|
154
159
|
const repo = stdout.match(reg)?.[1];
|
|
155
|
-
const { stdout: branch } = await
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
type: "confirm",
|
|
161
|
-
message: `Current refs ${repo}:refs/for/${branch}`
|
|
162
|
-
}
|
|
163
|
-
]);
|
|
164
|
-
return ret[name];
|
|
160
|
+
const { stdout: branch } = await exec("git", ["branch", "--show-current"]);
|
|
161
|
+
const ret = await confirm({
|
|
162
|
+
message: `Current refs ${repo}:refs/for/${branch}`
|
|
163
|
+
});
|
|
164
|
+
return ret;
|
|
165
165
|
}
|
|
166
166
|
async function getReleaseType() {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
{
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
choices: releaseTypes
|
|
173
|
-
}
|
|
174
|
-
]);
|
|
175
|
-
return ret[name];
|
|
167
|
+
const releaseType = await select({
|
|
168
|
+
message: "Please select release type",
|
|
169
|
+
choices: releaseTypes.map((type) => ({ name: type, value: type }))
|
|
170
|
+
});
|
|
171
|
+
return releaseType;
|
|
176
172
|
}
|
|
177
173
|
async function getReleaseVersion(currentVersion) {
|
|
178
174
|
let isPreRelease = false;
|
|
@@ -225,11 +221,15 @@ async function release(options) {
|
|
|
225
221
|
logger_default.success(`Release version ${expectVersion} successfully!`);
|
|
226
222
|
if (isPreRelease) {
|
|
227
223
|
try {
|
|
228
|
-
await
|
|
224
|
+
await exec("git", ["restore", "**/package.json"], {
|
|
225
|
+
throwOnError: true
|
|
226
|
+
});
|
|
229
227
|
} catch {
|
|
230
228
|
}
|
|
231
229
|
try {
|
|
232
|
-
await
|
|
230
|
+
await exec("git", ["restore", "package.json"], {
|
|
231
|
+
throwOnError: true
|
|
232
|
+
});
|
|
233
233
|
} catch {
|
|
234
234
|
}
|
|
235
235
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/release",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "release all packages and generate changelogs",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"varlet",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/conventional-changelog": "^3.1.5",
|
|
48
48
|
"@types/fs-extra": "^11.0.4",
|
|
49
|
-
"@types/inquirer": "^9.0.7",
|
|
50
49
|
"@types/node": "^20.9.0",
|
|
51
50
|
"@types/semver": "^7.5.5",
|
|
52
51
|
"@varlet/eslint-config": "^2.18.4",
|
|
@@ -54,19 +53,19 @@
|
|
|
54
53
|
"lint-staged": "^15.2.0",
|
|
55
54
|
"prettier": "^3.1.0",
|
|
56
55
|
"simple-git-hooks": "^2.9.0",
|
|
57
|
-
"tsup": "^8.0
|
|
56
|
+
"tsup": "^8.3.0",
|
|
58
57
|
"typescript": "^5.2.2"
|
|
59
58
|
},
|
|
60
59
|
"dependencies": {
|
|
60
|
+
"@inquirer/prompts": "^6.0.1",
|
|
61
61
|
"commander": "^11.1.0",
|
|
62
62
|
"conventional-changelog": "^5.1.0",
|
|
63
|
-
"execa": "^8.0.1",
|
|
64
63
|
"fs-extra": "^11.1.1",
|
|
65
64
|
"glob": "^10.3.10",
|
|
66
|
-
"inquirer": "^9.2.12",
|
|
67
65
|
"nanospinner": "^1.1.0",
|
|
68
66
|
"picocolors": "^1.0.0",
|
|
69
|
-
"semver": "^7.5.4"
|
|
67
|
+
"semver": "^7.5.4",
|
|
68
|
+
"tinyexec": "^0.3.0"
|
|
70
69
|
},
|
|
71
70
|
"scripts": {
|
|
72
71
|
"dev": "tsup --watch",
|