pubz 0.2.0 → 0.2.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 +0 -1
- package/dist/cli.js +54 -9
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -247,8 +247,7 @@ function run(command, args, cwd) {
|
|
|
247
247
|
return new Promise((resolve2) => {
|
|
248
248
|
const proc = spawn(command, args, {
|
|
249
249
|
cwd,
|
|
250
|
-
stdio: ["inherit", "pipe", "pipe"]
|
|
251
|
-
shell: true
|
|
250
|
+
stdio: ["inherit", "pipe", "pipe"]
|
|
252
251
|
});
|
|
253
252
|
let output = "";
|
|
254
253
|
proc.stdout?.on("data", (data) => {
|
|
@@ -330,18 +329,43 @@ async function publishPackage(pkg, registry, otp, dryRun) {
|
|
|
330
329
|
console.log(` ${pkg.name} published successfully`);
|
|
331
330
|
return { success: true };
|
|
332
331
|
}
|
|
333
|
-
async function
|
|
332
|
+
async function hasUncommittedChanges(cwd) {
|
|
333
|
+
const result = await run("git", ["status", "--porcelain"], cwd);
|
|
334
|
+
const output = result.output.trim();
|
|
335
|
+
if (!output) {
|
|
336
|
+
return { hasChanges: false, files: [] };
|
|
337
|
+
}
|
|
338
|
+
const files = output.split(`
|
|
339
|
+
`).map((line) => line.slice(3));
|
|
340
|
+
return { hasChanges: true, files };
|
|
341
|
+
}
|
|
342
|
+
async function commitVersionBump(version, cwd, dryRun) {
|
|
334
343
|
const tagName = `v${version}`;
|
|
335
344
|
if (dryRun) {
|
|
336
|
-
console.log(`[DRY RUN] Would
|
|
345
|
+
console.log(`[DRY RUN] Would commit version bump for ${tagName}`);
|
|
337
346
|
return { success: true };
|
|
338
347
|
}
|
|
339
348
|
const statusResult = await run("git", ["status", "--porcelain"], cwd);
|
|
340
|
-
if (statusResult.output.trim()) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
349
|
+
if (!statusResult.output.trim()) {
|
|
350
|
+
return { success: true };
|
|
351
|
+
}
|
|
352
|
+
console.log("Committing version bump...");
|
|
353
|
+
const addResult = await run("git", ["add", "-A"], cwd);
|
|
354
|
+
if (addResult.code !== 0) {
|
|
355
|
+
return { success: false, error: "Failed to stage changes" };
|
|
356
|
+
}
|
|
357
|
+
const commitResult = await run("git", ["commit", "-m", `chore: release ${tagName}`], cwd);
|
|
358
|
+
if (commitResult.code !== 0) {
|
|
359
|
+
return { success: false, error: "Failed to commit changes" };
|
|
360
|
+
}
|
|
361
|
+
console.log(" Changes committed");
|
|
362
|
+
return { success: true };
|
|
363
|
+
}
|
|
364
|
+
async function createGitTag(version, cwd, dryRun) {
|
|
365
|
+
const tagName = `v${version}`;
|
|
366
|
+
if (dryRun) {
|
|
367
|
+
console.log(`[DRY RUN] Would create git tag: ${tagName}`);
|
|
368
|
+
return { success: true };
|
|
345
369
|
}
|
|
346
370
|
const tagResult = await run("git", ["tag", tagName], cwd);
|
|
347
371
|
if (tagResult.code !== 0) {
|
|
@@ -510,6 +534,21 @@ async function main() {
|
|
|
510
534
|
console.log("pubz - npm package publisher");
|
|
511
535
|
console.log("=============================");
|
|
512
536
|
console.log("");
|
|
537
|
+
const uncommitted = await hasUncommittedChanges(cwd);
|
|
538
|
+
if (uncommitted.hasChanges && !options.dryRun) {
|
|
539
|
+
console.log("Error: You have uncommitted changes:");
|
|
540
|
+
console.log("");
|
|
541
|
+
for (const file of uncommitted.files.slice(0, 10)) {
|
|
542
|
+
console.log(` ${file}`);
|
|
543
|
+
}
|
|
544
|
+
if (uncommitted.files.length > 10) {
|
|
545
|
+
console.log(` ... and ${uncommitted.files.length - 10} more`);
|
|
546
|
+
}
|
|
547
|
+
console.log("");
|
|
548
|
+
console.log("Please commit or stash your changes before publishing.");
|
|
549
|
+
closePrompt();
|
|
550
|
+
process.exit(1);
|
|
551
|
+
}
|
|
513
552
|
console.log("Discovering packages...");
|
|
514
553
|
console.log("");
|
|
515
554
|
let packages = await discoverPackages(cwd);
|
|
@@ -579,6 +618,12 @@ async function main() {
|
|
|
579
618
|
for (const pkg of packages) {
|
|
580
619
|
pkg.version = newVersion;
|
|
581
620
|
}
|
|
621
|
+
const commitResult = await commitVersionBump(newVersion, cwd, options.dryRun);
|
|
622
|
+
if (!commitResult.success) {
|
|
623
|
+
console.error(`Failed to commit version bump: ${commitResult.error}`);
|
|
624
|
+
closePrompt();
|
|
625
|
+
process.exit(1);
|
|
626
|
+
}
|
|
582
627
|
console.log("");
|
|
583
628
|
}
|
|
584
629
|
}
|