@versionsmith/cli 0.0.2 → 0.0.3
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/index.js +59 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -128,8 +128,9 @@ versionsmith initialized successfully!
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// src/commands/add.ts
|
|
131
|
-
import { writeFileSync as writeFileSync3 } from "fs";
|
|
132
|
-
import {
|
|
131
|
+
import { writeFileSync as writeFileSync3, readFileSync as readFileSync2, readdirSync as readdirSync2, existsSync as existsSync4 } from "fs";
|
|
132
|
+
import { join as join4 } from "path";
|
|
133
|
+
import { checkbox, input as input2, confirm as confirm2, select } from "@inquirer/prompts";
|
|
133
134
|
|
|
134
135
|
// src/utils/changelog.ts
|
|
135
136
|
var CHANGE_TYPES = [
|
|
@@ -436,7 +437,38 @@ async function add(cwd = process.cwd()) {
|
|
|
436
437
|
process.exit(1);
|
|
437
438
|
}
|
|
438
439
|
const dir = getVersionsmithDir(cwd);
|
|
439
|
-
|
|
440
|
+
const existingFiles = existsSync4(dir) ? readdirSync2(dir).filter((f) => f.endsWith(".md") && f !== ".gitkeep") : [];
|
|
441
|
+
let targetFile = null;
|
|
442
|
+
let existingEntries = {};
|
|
443
|
+
if (existingFiles.length === 1) {
|
|
444
|
+
targetFile = existingFiles[0];
|
|
445
|
+
const content2 = readFileSync2(join4(dir, targetFile), "utf-8");
|
|
446
|
+
existingEntries = parseChangeset(content2).entries;
|
|
447
|
+
console.log(`
|
|
448
|
+
Appending to existing entry: .versionsmith/${targetFile}
|
|
449
|
+
`);
|
|
450
|
+
} else if (existingFiles.length > 1) {
|
|
451
|
+
const CREATE_NEW = "__create_new__";
|
|
452
|
+
const choice = await select({
|
|
453
|
+
message: "Existing changelog entries found. Append to one or create new?",
|
|
454
|
+
choices: [
|
|
455
|
+
...existingFiles.map((f) => ({ name: f, value: f })),
|
|
456
|
+
{ name: "Create new entry", value: CREATE_NEW }
|
|
457
|
+
]
|
|
458
|
+
});
|
|
459
|
+
if (choice !== CREATE_NEW) {
|
|
460
|
+
targetFile = choice;
|
|
461
|
+
const content2 = readFileSync2(join4(dir, targetFile), "utf-8");
|
|
462
|
+
existingEntries = parseChangeset(content2).entries;
|
|
463
|
+
console.log(`
|
|
464
|
+
Appending to: .versionsmith/${targetFile}
|
|
465
|
+
`);
|
|
466
|
+
} else {
|
|
467
|
+
console.log("\nCreate a new changelog entry\n");
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
console.log("\nCreate a new changelog entry\n");
|
|
471
|
+
}
|
|
440
472
|
const selectedTypes = await checkbox({
|
|
441
473
|
message: "Select the type(s) of change (space to select, enter to confirm):",
|
|
442
474
|
choices: CHANGE_TYPES.map((t) => ({
|
|
@@ -465,8 +497,9 @@ async function add(cwd = process.cwd()) {
|
|
|
465
497
|
}
|
|
466
498
|
entries[type] = items;
|
|
467
499
|
}
|
|
500
|
+
const finalEntries = targetFile ? mergeChangesets([{ entries: existingEntries }, { entries }]) : entries;
|
|
468
501
|
console.log("\n--- Preview ---");
|
|
469
|
-
console.log(renderEntries(
|
|
502
|
+
console.log(renderEntries(finalEntries));
|
|
470
503
|
console.log("---------------\n");
|
|
471
504
|
const confirmed = await confirm2({
|
|
472
505
|
message: "Save this changelog entry?",
|
|
@@ -476,12 +509,19 @@ async function add(cwd = process.cwd()) {
|
|
|
476
509
|
console.log("Aborted. No file written.");
|
|
477
510
|
return;
|
|
478
511
|
}
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
512
|
+
const content = renderEntries(finalEntries);
|
|
513
|
+
if (targetFile) {
|
|
514
|
+
const filePath = join4(dir, targetFile);
|
|
515
|
+
writeFileSync3(filePath, content, "utf-8");
|
|
516
|
+
console.log(`
|
|
517
|
+
Updated: .versionsmith/${targetFile}`);
|
|
518
|
+
} else {
|
|
519
|
+
const name = generateName(dir);
|
|
520
|
+
const filePath = changesetPath(dir, name);
|
|
521
|
+
writeFileSync3(filePath, content, "utf-8");
|
|
522
|
+
console.log(`
|
|
484
523
|
Saved: .versionsmith/${name}.md`);
|
|
524
|
+
}
|
|
485
525
|
console.log(
|
|
486
526
|
"\nCommit this file alongside your changes. When ready to release, run:"
|
|
487
527
|
);
|
|
@@ -506,13 +546,13 @@ function typeDescription(type) {
|
|
|
506
546
|
|
|
507
547
|
// src/commands/release.ts
|
|
508
548
|
import {
|
|
509
|
-
existsSync as
|
|
510
|
-
readdirSync as
|
|
511
|
-
readFileSync as
|
|
549
|
+
existsSync as existsSync5,
|
|
550
|
+
readdirSync as readdirSync3,
|
|
551
|
+
readFileSync as readFileSync3,
|
|
512
552
|
writeFileSync as writeFileSync4,
|
|
513
553
|
unlinkSync
|
|
514
554
|
} from "fs";
|
|
515
|
-
import { join as
|
|
555
|
+
import { join as join5 } from "path";
|
|
516
556
|
async function release(options = {}) {
|
|
517
557
|
const cwd = options.cwd ?? process.cwd();
|
|
518
558
|
if (!isInitialized(cwd)) {
|
|
@@ -523,8 +563,8 @@ async function release(options = {}) {
|
|
|
523
563
|
}
|
|
524
564
|
const config = readConfig(cwd);
|
|
525
565
|
const dir = getVersionsmithDir(cwd);
|
|
526
|
-
const changelogPath =
|
|
527
|
-
const files =
|
|
566
|
+
const changelogPath = join5(cwd, config.changelog);
|
|
567
|
+
const files = existsSync5(dir) ? readdirSync3(dir).filter(
|
|
528
568
|
(f) => f.endsWith(".md") && f !== ".gitkeep"
|
|
529
569
|
) : [];
|
|
530
570
|
if (files.length === 0 && !options.version) {
|
|
@@ -533,13 +573,13 @@ async function release(options = {}) {
|
|
|
533
573
|
return;
|
|
534
574
|
}
|
|
535
575
|
const changesets = files.map((f) => {
|
|
536
|
-
const content =
|
|
576
|
+
const content = readFileSync3(join5(dir, f), "utf-8");
|
|
537
577
|
return parseChangeset(content);
|
|
538
578
|
});
|
|
539
579
|
const merged = mergeChangesets(changesets);
|
|
540
580
|
let parsed = { header: config.header, releases: [] };
|
|
541
|
-
if (
|
|
542
|
-
const existing =
|
|
581
|
+
if (existsSync5(changelogPath)) {
|
|
582
|
+
const existing = readFileSync3(changelogPath, "utf-8");
|
|
543
583
|
parsed = parseChangelog(existing);
|
|
544
584
|
if (!parsed.header.trim()) {
|
|
545
585
|
parsed = { ...parsed, header: config.header };
|
|
@@ -561,7 +601,7 @@ Merging entries into [Unreleased]
|
|
|
561
601
|
const rendered = renderChangelog(updated.header, updated.releases);
|
|
562
602
|
writeFileSync4(changelogPath, rendered, "utf-8");
|
|
563
603
|
for (const f of files) {
|
|
564
|
-
unlinkSync(
|
|
604
|
+
unlinkSync(join5(dir, f));
|
|
565
605
|
}
|
|
566
606
|
console.log(`Updated ${config.changelog}`);
|
|
567
607
|
if (files.length > 0) {
|