pubz 0.5.2 → 0.6.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/dist/cli.js +116 -43
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
4
4
|
|
|
5
5
|
// src/cli.ts
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
|
-
import { dirname, join as
|
|
7
|
+
import { dirname, join as join5 } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
|
|
10
10
|
// src/colors.ts
|
|
@@ -570,7 +570,114 @@ async function pushGitTag(version, cwd, dryRun) {
|
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
// src/changelog.ts
|
|
573
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
574
|
+
|
|
575
|
+
// src/claude.ts
|
|
573
576
|
import { spawn as spawn3 } from "node:child_process";
|
|
577
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
578
|
+
import { join as join4 } from "node:path";
|
|
579
|
+
async function resolveCredentials() {
|
|
580
|
+
const home = process.env.HOME ?? "";
|
|
581
|
+
if (!process.env.CLAUDE_CODE_OAUTH_TOKEN) {
|
|
582
|
+
try {
|
|
583
|
+
const tokenFile = join4(home, ".claude", "agent-oauth-token");
|
|
584
|
+
const token = (await readFile3(tokenFile, "utf-8")).trim();
|
|
585
|
+
if (token) {
|
|
586
|
+
process.env.CLAUDE_CODE_OAUTH_TOKEN = token;
|
|
587
|
+
}
|
|
588
|
+
} catch {}
|
|
589
|
+
}
|
|
590
|
+
if (!process.env.CLAUDE_CODE_OAUTH_TOKEN && process.platform === "darwin") {
|
|
591
|
+
try {
|
|
592
|
+
const token = await new Promise((resolve2) => {
|
|
593
|
+
const proc = spawn3("security", [
|
|
594
|
+
"find-generic-password",
|
|
595
|
+
"-s",
|
|
596
|
+
"Claude Code-credentials",
|
|
597
|
+
"-w"
|
|
598
|
+
], { stdio: ["ignore", "pipe", "pipe"] });
|
|
599
|
+
let stdout = "";
|
|
600
|
+
proc.stdout?.on("data", (d) => {
|
|
601
|
+
stdout += d.toString();
|
|
602
|
+
});
|
|
603
|
+
proc.on("close", (code) => {
|
|
604
|
+
if (code !== 0)
|
|
605
|
+
return resolve2(null);
|
|
606
|
+
try {
|
|
607
|
+
const creds = JSON.parse(stdout.trim());
|
|
608
|
+
const accessToken = creds?.claudeAiOauth?.accessToken;
|
|
609
|
+
resolve2(typeof accessToken === "string" && accessToken.length > 0 ? accessToken : null);
|
|
610
|
+
} catch {
|
|
611
|
+
resolve2(null);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
proc.on("error", () => resolve2(null));
|
|
615
|
+
});
|
|
616
|
+
if (token) {
|
|
617
|
+
process.env.CLAUDE_CODE_OAUTH_TOKEN = token;
|
|
618
|
+
}
|
|
619
|
+
} catch {}
|
|
620
|
+
}
|
|
621
|
+
if (!process.env.CLAUDE_CODE_OAUTH_TOKEN) {
|
|
622
|
+
try {
|
|
623
|
+
const raw = await readFile3(join4(home, ".claude.json"), "utf-8");
|
|
624
|
+
const creds = JSON.parse(raw);
|
|
625
|
+
const accessToken = creds?.claudeAiOauth?.accessToken;
|
|
626
|
+
if (typeof accessToken === "string" && accessToken.length > 0) {
|
|
627
|
+
process.env.CLAUDE_CODE_OAUTH_TOKEN = accessToken;
|
|
628
|
+
}
|
|
629
|
+
} catch {}
|
|
630
|
+
}
|
|
631
|
+
if (process.env.CLAUDE_CODE_OAUTH_TOKEN) {
|
|
632
|
+
delete process.env.ANTHROPIC_API_KEY;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async function isClaudeAvailable() {
|
|
636
|
+
return new Promise((resolve2) => {
|
|
637
|
+
const proc = spawn3("which", ["claude"], {
|
|
638
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
639
|
+
});
|
|
640
|
+
proc.on("close", (code) => resolve2(code === 0));
|
|
641
|
+
proc.on("error", () => resolve2(false));
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
async function runClaudePrompt(prompt2) {
|
|
645
|
+
await resolveCredentials();
|
|
646
|
+
return new Promise((resolve2) => {
|
|
647
|
+
const proc = spawn3("claude", ["-p", prompt2, "--no-session-persistence"], {
|
|
648
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
649
|
+
cwd: "/tmp"
|
|
650
|
+
});
|
|
651
|
+
let output = "";
|
|
652
|
+
let stderr = "";
|
|
653
|
+
proc.stdout?.on("data", (data) => {
|
|
654
|
+
output += data.toString();
|
|
655
|
+
});
|
|
656
|
+
proc.stderr?.on("data", (data) => {
|
|
657
|
+
stderr += data.toString();
|
|
658
|
+
});
|
|
659
|
+
proc.on("close", (code) => {
|
|
660
|
+
if (code === 0 && output.trim()) {
|
|
661
|
+
resolve2(output.trim());
|
|
662
|
+
} else {
|
|
663
|
+
debug(`claude CLI exited with code ${code}`);
|
|
664
|
+
if (stderr.trim()) {
|
|
665
|
+
debug(`claude stderr: ${stderr.trim()}`);
|
|
666
|
+
}
|
|
667
|
+
if (!output.trim() && code === 0) {
|
|
668
|
+
debug("claude CLI returned empty output");
|
|
669
|
+
}
|
|
670
|
+
resolve2(null);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
proc.on("error", (err) => {
|
|
674
|
+
debug(`Failed to spawn claude CLI: ${err.message}`);
|
|
675
|
+
resolve2(null);
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/changelog.ts
|
|
574
681
|
function parseGitRemoteUrl(remoteUrl) {
|
|
575
682
|
const sshMatch = remoteUrl.match(/^git@([^:]+):(.+?)(?:\.git)?$/);
|
|
576
683
|
if (sshMatch) {
|
|
@@ -584,7 +691,7 @@ function parseGitRemoteUrl(remoteUrl) {
|
|
|
584
691
|
}
|
|
585
692
|
function runSilent(command, args, cwd) {
|
|
586
693
|
return new Promise((resolve2) => {
|
|
587
|
-
const proc =
|
|
694
|
+
const proc = spawn4(command, args, {
|
|
588
695
|
cwd,
|
|
589
696
|
stdio: ["ignore", "pipe", "pipe"]
|
|
590
697
|
});
|
|
@@ -667,10 +774,6 @@ async function generateChangelog(cwd) {
|
|
|
667
774
|
const markdown = formatChangelogMarkdown(commits, repoUrl);
|
|
668
775
|
return { commits, terminal, markdown, previousTag, repoUrl };
|
|
669
776
|
}
|
|
670
|
-
async function isClaudeAvailable() {
|
|
671
|
-
const result = await runSilent("which", ["claude"], process.cwd());
|
|
672
|
-
return result.code === 0;
|
|
673
|
-
}
|
|
674
777
|
async function generateAIReleaseNotes(commits, version) {
|
|
675
778
|
const filtered = commits.filter((c) => !isReleaseCommit(c.message));
|
|
676
779
|
if (filtered.length === 0)
|
|
@@ -683,37 +786,7 @@ Here are the commits included in this release:
|
|
|
683
786
|
${commitList}
|
|
684
787
|
|
|
685
788
|
Write concise, user-friendly release notes in markdown. Group related changes under headings if appropriate (e.g. Features, Bug Fixes, Improvements). Focus on what changed and why it matters to users — not implementation details. Do not include a title or version header. Output only the markdown body.`;
|
|
686
|
-
return
|
|
687
|
-
const proc = spawn3("claude", ["-p", prompt2], {
|
|
688
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
689
|
-
});
|
|
690
|
-
let output = "";
|
|
691
|
-
let stderr = "";
|
|
692
|
-
proc.stdout?.on("data", (data) => {
|
|
693
|
-
output += data.toString();
|
|
694
|
-
});
|
|
695
|
-
proc.stderr?.on("data", (data) => {
|
|
696
|
-
stderr += data.toString();
|
|
697
|
-
});
|
|
698
|
-
proc.on("close", (code) => {
|
|
699
|
-
if (code === 0 && output.trim()) {
|
|
700
|
-
resolve2(output.trim());
|
|
701
|
-
} else {
|
|
702
|
-
debug(`claude CLI exited with code ${code}`);
|
|
703
|
-
if (stderr.trim()) {
|
|
704
|
-
debug(`claude stderr: ${stderr.trim()}`);
|
|
705
|
-
}
|
|
706
|
-
if (!output.trim() && code === 0) {
|
|
707
|
-
debug("claude CLI returned empty output");
|
|
708
|
-
}
|
|
709
|
-
resolve2(null);
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
proc.on("error", (err) => {
|
|
713
|
-
debug(`Failed to spawn claude CLI: ${err.message}`);
|
|
714
|
-
resolve2(null);
|
|
715
|
-
});
|
|
716
|
-
});
|
|
789
|
+
return runClaudePrompt(prompt2);
|
|
717
790
|
}
|
|
718
791
|
async function createGitHubRelease(version, body, cwd, dryRun) {
|
|
719
792
|
const tagName = `v${version}`;
|
|
@@ -733,12 +806,12 @@ async function createGitHubRelease(version, body, cwd, dryRun) {
|
|
|
733
806
|
}
|
|
734
807
|
|
|
735
808
|
// src/version.ts
|
|
736
|
-
import { readFile as
|
|
809
|
+
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
737
810
|
async function transformWorkspaceProtocolForPublish(packages, newVersion, dryRun) {
|
|
738
811
|
const packageNames = new Set(packages.map((p) => p.name));
|
|
739
812
|
const transforms = [];
|
|
740
813
|
for (const pkg of packages) {
|
|
741
|
-
const content = await
|
|
814
|
+
const content = await readFile4(pkg.packageJsonPath, "utf-8");
|
|
742
815
|
const packageJson = JSON.parse(content);
|
|
743
816
|
let modified = false;
|
|
744
817
|
for (const depType of [
|
|
@@ -787,7 +860,7 @@ async function restoreWorkspaceProtocol(transforms) {
|
|
|
787
860
|
byPath.set(transform.packageJsonPath, existing);
|
|
788
861
|
}
|
|
789
862
|
for (const [packageJsonPath, pathTransforms] of byPath) {
|
|
790
|
-
const content = await
|
|
863
|
+
const content = await readFile4(packageJsonPath, "utf-8");
|
|
791
864
|
const packageJson = JSON.parse(content);
|
|
792
865
|
for (const transform of pathTransforms) {
|
|
793
866
|
const deps = packageJson[transform.depType];
|
|
@@ -823,7 +896,7 @@ function previewBump(version, type) {
|
|
|
823
896
|
return `${version} -> ${newVersion}`;
|
|
824
897
|
}
|
|
825
898
|
async function updatePackageVersion(pkg, newVersion, dryRun) {
|
|
826
|
-
const content = await
|
|
899
|
+
const content = await readFile4(pkg.packageJsonPath, "utf-8");
|
|
827
900
|
const packageJson = JSON.parse(content);
|
|
828
901
|
packageJson.version = newVersion;
|
|
829
902
|
if (dryRun) {
|
|
@@ -837,7 +910,7 @@ async function updatePackageVersion(pkg, newVersion, dryRun) {
|
|
|
837
910
|
async function updateLocalDependencyVersions(packages, newVersion, dryRun) {
|
|
838
911
|
const packageNames = new Set(packages.map((p) => p.name));
|
|
839
912
|
for (const pkg of packages) {
|
|
840
|
-
const content = await
|
|
913
|
+
const content = await readFile4(pkg.packageJsonPath, "utf-8");
|
|
841
914
|
const packageJson = JSON.parse(content);
|
|
842
915
|
let modified = false;
|
|
843
916
|
for (const depType of [
|
|
@@ -881,7 +954,7 @@ var REGISTRIES = {
|
|
|
881
954
|
};
|
|
882
955
|
function getVersion() {
|
|
883
956
|
const __dirname2 = dirname(fileURLToPath(import.meta.url));
|
|
884
|
-
const pkgPath =
|
|
957
|
+
const pkgPath = join5(__dirname2, "..", "package.json");
|
|
885
958
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
886
959
|
return pkg.version;
|
|
887
960
|
}
|