pubz 0.2.4 → 0.2.6
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 +96 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
4
4
|
|
|
5
|
+
// src/cli.ts
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join as join4 } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
5
10
|
// src/colors.ts
|
|
6
11
|
var isColorSupported = process.env.FORCE_COLOR !== "0" && (process.env.FORCE_COLOR !== undefined || process.stdout.isTTY && process.env.TERM !== "dumb");
|
|
7
12
|
var fmt = (open, close) => {
|
|
@@ -303,13 +308,52 @@ async function multiSelect(message, options, allSelectedByDefault = true) {
|
|
|
303
308
|
});
|
|
304
309
|
}
|
|
305
310
|
|
|
306
|
-
// src/
|
|
311
|
+
// src/auth.ts
|
|
307
312
|
import { spawn } from "node:child_process";
|
|
313
|
+
async function checkNpmAuth(registry) {
|
|
314
|
+
return new Promise((resolve2) => {
|
|
315
|
+
const proc = spawn("npm", ["whoami", "--registry", registry], {
|
|
316
|
+
stdio: ["inherit", "pipe", "pipe"]
|
|
317
|
+
});
|
|
318
|
+
let stdout = "";
|
|
319
|
+
let stderr = "";
|
|
320
|
+
proc.stdout?.on("data", (data) => {
|
|
321
|
+
stdout += data.toString();
|
|
322
|
+
});
|
|
323
|
+
proc.stderr?.on("data", (data) => {
|
|
324
|
+
stderr += data.toString();
|
|
325
|
+
});
|
|
326
|
+
proc.on("close", (code) => {
|
|
327
|
+
if (code === 0 && stdout.trim()) {
|
|
328
|
+
resolve2({ authenticated: true, username: stdout.trim() });
|
|
329
|
+
} else {
|
|
330
|
+
resolve2({ authenticated: false });
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
async function npmLogin(registry) {
|
|
336
|
+
return new Promise((resolve2) => {
|
|
337
|
+
const proc = spawn("npm", ["login", "--registry", registry], {
|
|
338
|
+
stdio: "inherit"
|
|
339
|
+
});
|
|
340
|
+
proc.on("close", (code) => {
|
|
341
|
+
if (code === 0) {
|
|
342
|
+
resolve2({ success: true });
|
|
343
|
+
} else {
|
|
344
|
+
resolve2({ success: false, error: "Login failed or was cancelled" });
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/publish.ts
|
|
351
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
308
352
|
import { readFile as readFile2, stat as stat3 } from "node:fs/promises";
|
|
309
353
|
import { join as join3 } from "node:path";
|
|
310
354
|
function run(command, args, cwd) {
|
|
311
355
|
return new Promise((resolve2) => {
|
|
312
|
-
const proc =
|
|
356
|
+
const proc = spawn2(command, args, {
|
|
313
357
|
cwd,
|
|
314
358
|
stdio: ["inherit", "pipe", "pipe"]
|
|
315
359
|
});
|
|
@@ -528,11 +572,20 @@ var REGISTRIES = {
|
|
|
528
572
|
npm: "https://registry.npmjs.org",
|
|
529
573
|
github: "https://npm.pkg.github.com"
|
|
530
574
|
};
|
|
575
|
+
function getVersion() {
|
|
576
|
+
const __dirname2 = dirname(fileURLToPath(import.meta.url));
|
|
577
|
+
const pkgPath = join4(__dirname2, "..", "package.json");
|
|
578
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
579
|
+
return pkg.version;
|
|
580
|
+
}
|
|
531
581
|
function printUsage() {
|
|
532
582
|
console.log(`
|
|
533
583
|
pubz - Interactive npm package publisher
|
|
534
584
|
|
|
535
|
-
Usage: pubz [options]
|
|
585
|
+
Usage: pubz [command] [options]
|
|
586
|
+
|
|
587
|
+
Commands:
|
|
588
|
+
version Show version number
|
|
536
589
|
|
|
537
590
|
Options:
|
|
538
591
|
--dry-run Show what would be published without actually publishing
|
|
@@ -597,6 +650,10 @@ function parseArgs(args) {
|
|
|
597
650
|
return options;
|
|
598
651
|
}
|
|
599
652
|
async function main() {
|
|
653
|
+
if (process.argv[2] === "version") {
|
|
654
|
+
console.log(getVersion());
|
|
655
|
+
process.exit(0);
|
|
656
|
+
}
|
|
600
657
|
const options = parseArgs(process.argv.slice(2));
|
|
601
658
|
if (options.help) {
|
|
602
659
|
printUsage();
|
|
@@ -759,6 +816,42 @@ async function main() {
|
|
|
759
816
|
console.log("");
|
|
760
817
|
console.log(`Publishing to: ${cyan(registry)}`);
|
|
761
818
|
console.log("");
|
|
819
|
+
if (!options.dryRun) {
|
|
820
|
+
console.log(cyan("Verifying npm authentication..."));
|
|
821
|
+
const authResult = await checkNpmAuth(registry);
|
|
822
|
+
if (!authResult.authenticated) {
|
|
823
|
+
if (options.ci) {
|
|
824
|
+
console.error(red(bold("Error:")) + " Not authenticated to npm.");
|
|
825
|
+
console.log("");
|
|
826
|
+
console.log(muted("In CI mode, you need to configure authentication:"));
|
|
827
|
+
console.log(muted(" - Set NPM_TOKEN environment variable"));
|
|
828
|
+
console.log(muted(" - Or configure .npmrc with auth token"));
|
|
829
|
+
console.log(muted(" - Or use OIDC Trusted Publishing"));
|
|
830
|
+
closePrompt();
|
|
831
|
+
process.exit(1);
|
|
832
|
+
}
|
|
833
|
+
console.log("");
|
|
834
|
+
console.log(yellow("Not logged in to npm.") + " Starting login...");
|
|
835
|
+
console.log("");
|
|
836
|
+
const loginResult = await npmLogin(registry);
|
|
837
|
+
if (!loginResult.success) {
|
|
838
|
+
console.error(red(bold("Login failed:")) + ` ${loginResult.error}`);
|
|
839
|
+
closePrompt();
|
|
840
|
+
process.exit(1);
|
|
841
|
+
}
|
|
842
|
+
const verifyAuth = await checkNpmAuth(registry);
|
|
843
|
+
if (!verifyAuth.authenticated) {
|
|
844
|
+
console.error(red(bold("Error:")) + " Login did not complete successfully.");
|
|
845
|
+
closePrompt();
|
|
846
|
+
process.exit(1);
|
|
847
|
+
}
|
|
848
|
+
console.log("");
|
|
849
|
+
console.log(green("Logged in as") + ` ${cyan(verifyAuth.username ?? "unknown")}`);
|
|
850
|
+
} else {
|
|
851
|
+
console.log(green("Authenticated as") + ` ${cyan(authResult.username ?? "unknown")}`);
|
|
852
|
+
}
|
|
853
|
+
console.log("");
|
|
854
|
+
}
|
|
762
855
|
if (!options.skipBuild) {
|
|
763
856
|
console.log(bold(cyan("Step 2:")) + " Building Packages");
|
|
764
857
|
console.log(dim("─".repeat(30)));
|