@repo-toolkit/changelog 0.6.0 → 0.7.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/cli.js +32 -137
- package/package.json +4 -3
package/cli.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import {
|
|
5
|
-
import { isAbsolute as isAbsolute2, resolve as resolve2 } from "path";
|
|
6
|
-
import { pathToFileURL } from "url";
|
|
4
|
+
import { loadConfigFile, parseFlags } from "@repo-toolkit/publish-package";
|
|
7
5
|
|
|
8
6
|
// src/index.ts
|
|
9
7
|
import { createWriteStream } from "fs";
|
|
@@ -173,6 +171,17 @@ async function generateChangelog(options = {}) {
|
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
// src/cli.ts
|
|
174
|
+
var SPECS = [
|
|
175
|
+
{ name: "config" },
|
|
176
|
+
{ name: "cwd" },
|
|
177
|
+
{ name: "output" },
|
|
178
|
+
{ name: "tag-prefix" },
|
|
179
|
+
{ name: "release-count" },
|
|
180
|
+
{ name: "append", boolean: true, negatable: true },
|
|
181
|
+
{ name: "first-release", boolean: true, negatable: true },
|
|
182
|
+
{ name: "skip-unstable", boolean: true, negatable: true },
|
|
183
|
+
{ name: "output-unreleased", boolean: true, negatable: true }
|
|
184
|
+
];
|
|
176
185
|
function printHelp() {
|
|
177
186
|
console.log(`repo-toolkit-changelog
|
|
178
187
|
|
|
@@ -192,13 +201,6 @@ Options:
|
|
|
192
201
|
-h, --help Show this help message
|
|
193
202
|
`);
|
|
194
203
|
}
|
|
195
|
-
function readValue(argv, index, flag) {
|
|
196
|
-
const value = argv[index + 1];
|
|
197
|
-
if (!value || value.startsWith("-")) {
|
|
198
|
-
throw new Error(`Missing value for ${flag}.`);
|
|
199
|
-
}
|
|
200
|
-
return value;
|
|
201
|
-
}
|
|
202
204
|
function parseNumber(value, flag) {
|
|
203
205
|
const parsed = Number.parseInt(value, 10);
|
|
204
206
|
if (Number.isNaN(parsed)) {
|
|
@@ -206,137 +208,30 @@ function parseNumber(value, flag) {
|
|
|
206
208
|
}
|
|
207
209
|
return parsed;
|
|
208
210
|
}
|
|
209
|
-
function
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const contents = await readFile(resolvedPath, "utf8");
|
|
222
|
-
const parsed = JSON.parse(contents);
|
|
223
|
-
if (!isObject(parsed)) {
|
|
224
|
-
throw new Error(`Config file must export an object: ${resolvedPath}`);
|
|
225
|
-
}
|
|
226
|
-
return parsed;
|
|
227
|
-
}
|
|
228
|
-
const loaded = await import(pathToFileURL(resolvedPath).href);
|
|
229
|
-
const config = loaded.default ?? loaded;
|
|
230
|
-
if (!isObject(config)) {
|
|
231
|
-
throw new Error(`Config file must export an object: ${resolvedPath}`);
|
|
232
|
-
}
|
|
233
|
-
return config;
|
|
234
|
-
}
|
|
235
|
-
function parseArgs(argv) {
|
|
236
|
-
const parsedArgs = {
|
|
237
|
-
options: {}
|
|
238
|
-
};
|
|
239
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
240
|
-
const arg = argv[index];
|
|
241
|
-
if (arg === "--") {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (arg === "-h" || arg === "--help") {
|
|
245
|
-
printHelp();
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
if (arg === "--config") {
|
|
249
|
-
parsedArgs.configPath = readValue(argv, index, arg);
|
|
250
|
-
index += 1;
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (arg.startsWith("--config=")) {
|
|
254
|
-
parsedArgs.configPath = arg.slice("--config=".length);
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (arg === "--cwd") {
|
|
258
|
-
parsedArgs.options.cwd = readValue(argv, index, arg);
|
|
259
|
-
index += 1;
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (arg.startsWith("--cwd=")) {
|
|
263
|
-
parsedArgs.options.cwd = arg.slice("--cwd=".length);
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
if (arg === "--output") {
|
|
267
|
-
parsedArgs.options.outputFile = readValue(argv, index, arg);
|
|
268
|
-
index += 1;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
if (arg.startsWith("--output=")) {
|
|
272
|
-
parsedArgs.options.outputFile = arg.slice("--output=".length);
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (arg === "--tag-prefix") {
|
|
276
|
-
parsedArgs.options.tagPrefix = readValue(argv, index, arg);
|
|
277
|
-
index += 1;
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
if (arg.startsWith("--tag-prefix=")) {
|
|
281
|
-
parsedArgs.options.tagPrefix = arg.slice("--tag-prefix=".length);
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (arg === "--release-count") {
|
|
285
|
-
parsedArgs.options.releaseCount = parseNumber(readValue(argv, index, arg), arg);
|
|
286
|
-
index += 1;
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
if (arg.startsWith("--release-count=")) {
|
|
290
|
-
parsedArgs.options.releaseCount = parseNumber(arg.slice("--release-count=".length), "--release-count");
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
if (arg === "--append") {
|
|
294
|
-
parsedArgs.options.append = true;
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
if (arg === "--no-append") {
|
|
298
|
-
parsedArgs.options.append = false;
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
if (arg === "--first-release") {
|
|
302
|
-
parsedArgs.options.firstRelease = true;
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
if (arg === "--no-first-release") {
|
|
306
|
-
parsedArgs.options.firstRelease = false;
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (arg === "--skip-unstable") {
|
|
310
|
-
parsedArgs.options.skipUnstable = true;
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
if (arg === "--no-skip-unstable") {
|
|
314
|
-
parsedArgs.options.skipUnstable = false;
|
|
315
|
-
continue;
|
|
316
|
-
}
|
|
317
|
-
if (arg === "--output-unreleased") {
|
|
318
|
-
parsedArgs.options.outputUnreleased = true;
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
if (arg === "--no-output-unreleased") {
|
|
322
|
-
parsedArgs.options.outputUnreleased = false;
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
throw new Error(`Unknown argument: ${arg}`);
|
|
326
|
-
}
|
|
327
|
-
return parsedArgs;
|
|
211
|
+
function buildOptions(values) {
|
|
212
|
+
const options = {};
|
|
213
|
+
if (values.cwd) options.cwd = values.cwd;
|
|
214
|
+
if (values.output) options.outputFile = values.output;
|
|
215
|
+
if (values["tag-prefix"]) options.tagPrefix = values["tag-prefix"];
|
|
216
|
+
if (values["release-count"] !== void 0)
|
|
217
|
+
options.releaseCount = parseNumber(values["release-count"], "--release-count");
|
|
218
|
+
if (values.append !== void 0) options.append = values.append === "true";
|
|
219
|
+
if (values["first-release"] !== void 0) options.firstRelease = values["first-release"] === "true";
|
|
220
|
+
if (values["skip-unstable"] !== void 0) options.skipUnstable = values["skip-unstable"] === "true";
|
|
221
|
+
if (values["output-unreleased"] !== void 0) options.outputUnreleased = values["output-unreleased"] === "true";
|
|
222
|
+
return options;
|
|
328
223
|
}
|
|
329
224
|
async function main() {
|
|
330
|
-
const
|
|
331
|
-
if (!
|
|
225
|
+
const result = parseFlags(process.argv.slice(2), SPECS);
|
|
226
|
+
if (!result) {
|
|
227
|
+
printHelp();
|
|
332
228
|
return;
|
|
333
229
|
}
|
|
334
|
-
const
|
|
335
|
-
const options =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const outputPath = await generateChangelog(options);
|
|
230
|
+
const configPath = result.values.config;
|
|
231
|
+
const options = buildOptions(result.values);
|
|
232
|
+
const config = configPath ? await loadConfigFile(configPath, options.cwd) : {};
|
|
233
|
+
const merged = { ...config, ...options };
|
|
234
|
+
const outputPath = await generateChangelog(merged);
|
|
340
235
|
console.log(`Changelog generated at ${outputPath}.`);
|
|
341
236
|
}
|
|
342
237
|
main().catch((error) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repo-toolkit/changelog",
|
|
3
3
|
"description": "Shared conventional changelog preset, generator, and CLI for repository releases",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"keywords": [
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"node": ">=20"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@repo-toolkit/publish-package": "0.7.1",
|
|
30
31
|
"conventional-changelog": "^7.2.1",
|
|
31
32
|
"conventional-changelog-conventionalcommits": "^9.3.1"
|
|
32
33
|
},
|
|
@@ -36,12 +37,12 @@
|
|
|
36
37
|
],
|
|
37
38
|
"author": "Junmin Ahn",
|
|
38
39
|
"bugs": {
|
|
39
|
-
"url": "https://github.com/egose/
|
|
40
|
+
"url": "https://github.com/egose/repo-toolkit/issues"
|
|
40
41
|
},
|
|
41
42
|
"license": "Apache-2.0",
|
|
42
43
|
"repository": {
|
|
43
44
|
"type": "git",
|
|
44
|
-
"url": "git+https://github.com/egose/
|
|
45
|
+
"url": "git+https://github.com/egose/repo-toolkit.git",
|
|
45
46
|
"directory": "packages/changelog"
|
|
46
47
|
}
|
|
47
48
|
}
|