@doki-land/nifty 0.0.0 → 0.0.2

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.
Files changed (42) hide show
  1. package/cli/nifty.mjs +11 -11
  2. package/locales/en-US/cli.json +64 -0
  3. package/locales/locales.json +4 -0
  4. package/package.json +22 -19
  5. package/src/cli/authArgs.ts +52 -52
  6. package/src/cli/bump-cmd.ts +55 -0
  7. package/src/cli/bump.ts +237 -237
  8. package/src/cli/change-logs-cmd.ts +97 -0
  9. package/src/cli/cli.ts +45 -0
  10. package/src/cli/context.ts +36 -26
  11. package/src/cli/index.ts +9 -8
  12. package/src/cli/install-native-cmd.ts +22 -0
  13. package/src/cli/install-native.ts +80 -0
  14. package/src/cli/lint-cmd.ts +33 -0
  15. package/src/cli/lint.ts +113 -109
  16. package/src/cli/main.ts +1 -64
  17. package/src/cli/options.ts +40 -0
  18. package/src/cli/publish-cmd.ts +34 -0
  19. package/src/cli/publish.ts +95 -85
  20. package/src/cli/resolveNpm.ts +16 -16
  21. package/src/cli/retime-cmd.ts +62 -0
  22. package/src/cli/reword-cmd.ts +87 -0
  23. package/src/cli/trust-cmd.ts +38 -0
  24. package/src/cli/trust.ts +83 -77
  25. package/src/cli/update-cmd.ts +20 -0
  26. package/src/cli/update.ts +185 -182
  27. package/src/cli/upload-cmd.ts +44 -0
  28. package/src/cli/upload.ts +313 -280
  29. package/src/cli/workspace.ts +124 -124
  30. package/src/config/defineConfig.ts +12 -12
  31. package/src/config/detectProject.ts +189 -189
  32. package/src/config/index.ts +25 -25
  33. package/src/config/loadConfig.ts +129 -129
  34. package/src/config/types.ts +57 -43
  35. package/src/git.ts +61 -61
  36. package/src/github.ts +184 -184
  37. package/src/gitmoji.ts +77 -77
  38. package/src/index.ts +36 -36
  39. package/src/native.ts +507 -277
  40. package/src/nifty.ts +95 -95
  41. package/src/types.ts +40 -40
  42. package/Readme.md +0 -30
@@ -1,26 +1,36 @@
1
- import { resolve } from "node:path";
2
-
3
- import { loadConfig } from "../config/loadConfig.js";
4
-
5
- /** Parse shared CLI flags used across nifty commands. */
6
- export function parseCliContext(argv: string[]): { cwd: string; dryRun: boolean } {
7
- let cwd = process.cwd();
8
- let dryRun = false;
9
-
10
- for (let i = 0; i < argv.length; i += 1) {
11
- const arg = argv[i];
12
- if (arg === "--dry-run") {
13
- dryRun = true;
14
- } else if (arg === "-C" || arg === "--cwd") {
15
- cwd = resolve(argv[++i] ?? cwd);
16
- }
17
- }
18
-
19
- return { cwd, dryRun };
20
- }
21
-
22
- /** Ensure `nifty.config.*` exists before running a command (skip create on `--dry-run`). */
23
- export async function bootstrapNiftyConfig(argv: string[]): Promise<void> {
24
- const { cwd, dryRun } = parseCliContext(argv);
25
- await loadConfig({ cwd, createIfMissing: !dryRun });
26
- }
1
+ import { resolve } from "node:path";
2
+
3
+ import type { ParsedOptions } from "@vmz/commander";
4
+
5
+ import { loadConfig } from "../config/loadConfig.js";
6
+ import { cwdFrom } from "./options.js";
7
+
8
+ /** Parse shared CLI flags used across nifty commands. */
9
+ export function parseCliContext(argv: string[]): { cwd: string; dryRun: boolean } {
10
+ let cwd = process.cwd();
11
+ let dryRun = false;
12
+
13
+ for (let i = 0; i < argv.length; i += 1) {
14
+ const arg = argv[i];
15
+ if (arg === "--dry-run") {
16
+ dryRun = true;
17
+ } else if (arg === "-C" || arg === "--cwd") {
18
+ cwd = resolve(argv[++i] ?? cwd);
19
+ }
20
+ }
21
+
22
+ return { cwd, dryRun };
23
+ }
24
+
25
+ /** Ensure `nifty.config.*` exists before running a command (skip create on `--dry-run`). */
26
+ export async function bootstrapNiftyConfig(argv: string[]): Promise<void> {
27
+ const { cwd, dryRun } = parseCliContext(argv);
28
+ await loadConfig({ cwd, createIfMissing: !dryRun });
29
+ }
30
+
31
+ /** Commander action hook: load config from parsed global/command flags. */
32
+ export async function bootstrapFromOptions(options: ParsedOptions): Promise<void> {
33
+ const cwd = cwdFrom(options) ?? process.cwd();
34
+ const dryRun = options["dry-run"] === true;
35
+ await loadConfig({ cwd, createIfMissing: !dryRun });
36
+ }
package/src/cli/index.ts CHANGED
@@ -1,8 +1,9 @@
1
- export { runCli } from "./main.js";
2
- export { bumpSemver, bumpWorkspace, runBump, type BumpKind, type BumpOptions, type BumpReport } from "./bump.js";
3
- export { runPublish, type PublishOptions, type PublishReport } from "./publish.js";
4
- export { runTrust, type TrustReport } from "./trust.js";
5
- export { runUpdate } from "./update.js";
6
- export { runLint } from "./lint.js";
7
- export { runUpload } from "./upload.js";
8
- export { findWorkspaceRoot, listWorkspacePackages, type WorkspacePackage } from "./workspace.js";
1
+ export { runCli } from "./main.js";
2
+ export { bumpSemver, bumpWorkspace, runBump, type BumpKind, type BumpOptions, type BumpReport } from "./bump.js";
3
+ export { runPublish, type PublishOptions, type PublishReport } from "./publish.js";
4
+ export { runTrust, type TrustReport } from "./trust.js";
5
+ export { runUpdate } from "./update.js";
6
+ export { runLint } from "./lint.js";
7
+ export { runUpload } from "./upload.js";
8
+ export { installNativeFromOptions, type InstallNativeOptions } from "./install-native.js";
9
+ export { findWorkspaceRoot, listWorkspacePackages, type WorkspacePackage } from "./workspace.js";
@@ -0,0 +1,22 @@
1
+ import type { Cli, ParsedOptions } from "@vmz/commander";
2
+
3
+ import { installNativeFromOptions } from "./install-native.js";
4
+ import { cwdFrom, str } from "./options.js";
5
+
6
+ export function registerInstallNativeCommand(cli: Cli): void {
7
+ cli.command("install-native", "cli.cmd.install-native")
8
+ .option("--from <dir>", "cli.opt.from-artifacts")
9
+ .action(async (options) => cmdInstallNative(options));
10
+ }
11
+
12
+ export async function cmdInstallNative(options: ParsedOptions): Promise<number> {
13
+ const from =
14
+ str(options, "from") ??
15
+ process.env.NATIVE_ARTIFACT_ROOT ??
16
+ "native-artifacts";
17
+ installNativeFromOptions({
18
+ from,
19
+ cwd: cwdFrom(options),
20
+ });
21
+ return 0;
22
+ }
@@ -0,0 +1,80 @@
1
+ import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
2
+ import { basename, dirname, join, relative, resolve } from "node:path";
3
+
4
+ import { detectProjectLayout } from "../config/detectProject.js";
5
+
6
+ /** Basename of a built .node file → platform package directory under projects/packages/. */
7
+ const PACKAGE_BY_ASSET: Record<string, string> = {
8
+ "nifty-win32-x64-msvc.node": "nifty-win32-x64",
9
+ "nifty-linux-x64-gnu.node": "nifty-linux-x64",
10
+ "nifty-linux-arm64-gnu.node": "nifty-linux-arm64",
11
+ "nifty-darwin-x64.node": "nifty-darwin-x64",
12
+ "nifty-darwin-arm64.node": "nifty-darwin-arm64",
13
+ };
14
+
15
+ /** Matrix platforms that must be present after install (matches publish-npm.yml). */
16
+ const REQUIRED_PACKAGES = ["nifty-win32-x64", "nifty-linux-x64", "nifty-darwin-arm64"];
17
+
18
+ export type InstallNativeOptions = {
19
+ /** Downloaded CI artifact tree (walked recursively for .node files). */
20
+ from: string;
21
+ cwd?: string;
22
+ };
23
+
24
+ function walkNodes(dir: string): string[] {
25
+ const out: string[] = [];
26
+ if (!existsSync(dir)) {
27
+ return out;
28
+ }
29
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
30
+ const full = join(dir, entry.name);
31
+ if (entry.isDirectory()) {
32
+ out.push(...walkNodes(full));
33
+ } else if (entry.isFile() && entry.name.endsWith(".node")) {
34
+ out.push(full);
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+
40
+ function libHasNode(libDir: string): boolean {
41
+ return existsSync(libDir) && readdirSync(libDir).some((name) => name.endsWith(".node"));
42
+ }
43
+
44
+ /** Copy matrix .node artifacts into platform package lib dirs for npm publish. */
45
+ export function installNativeFromOptions(options: InstallNativeOptions): void {
46
+ const layout = detectProjectLayout(options.cwd ?? process.cwd());
47
+ const artifactRoot = resolve(layout.root, options.from);
48
+ const nodes = walkNodes(artifactRoot);
49
+ if (nodes.length === 0) {
50
+ throw new Error(`install-native: no .node files under ${artifactRoot}`);
51
+ }
52
+
53
+ let installed = 0;
54
+ for (const file of nodes) {
55
+ const base = basename(file);
56
+ const packageDir = PACKAGE_BY_ASSET[base];
57
+ if (!packageDir) {
58
+ console.log(`skip unmapped artifact ${relative(artifactRoot, file)}`);
59
+ continue;
60
+ }
61
+ const dest = join(layout.root, "projects/packages", packageDir, "lib", base);
62
+ mkdirSync(dirname(dest), { recursive: true });
63
+ copyFileSync(file, dest);
64
+ console.log(`installed ${relative(layout.root, dest)}`);
65
+ installed += 1;
66
+ }
67
+
68
+ if (installed === 0) {
69
+ throw new Error("install-native: no mapped platform .node files installed");
70
+ }
71
+
72
+ for (const packageDir of REQUIRED_PACKAGES) {
73
+ const libDir = join(layout.root, "projects/packages", packageDir, "lib");
74
+ if (!libHasNode(libDir)) {
75
+ throw new Error(`install-native: missing .node under ${packageDir}/lib`);
76
+ }
77
+ }
78
+
79
+ console.log(`install-native: ${installed} native binary(ies) ready for npm publish`);
80
+ }
@@ -0,0 +1,33 @@
1
+ import type { Cli, ParsedOptions } from "@vmz/commander";
2
+
3
+ import { bootstrapFromOptions } from "./context.js";
4
+ import { lintCommits, type LintOptions } from "./lint.js";
5
+ import { cwdFrom, str, strList } from "./options.js";
6
+
7
+ export function registerLintCommands(cli: Cli): void {
8
+ registerLintLike(cli, "lint", "cli.cmd.lint", false);
9
+ registerLintLike(cli, "check", "cli.cmd.check", true);
10
+ }
11
+
12
+ function registerLintLike(cli: Cli, name: string, helpId: string, check: boolean): void {
13
+ cli.command(name, helpId)
14
+ .option("--from <ref>", "cli.opt.from")
15
+ .option("--to <ref>", "cli.opt.to")
16
+ .option("-s, --subject <text>...", "cli.opt.subject")
17
+ .action(async (options) => cmdLint(options, check));
18
+ }
19
+
20
+ export async function cmdLint(options: ParsedOptions, check: boolean): Promise<number> {
21
+ await bootstrapFromOptions(options);
22
+ const lintOptions: LintOptions = {
23
+ subjects: strList(options, "subject"),
24
+ from: str(options, "from"),
25
+ to: str(options, "to"),
26
+ cwd: cwdFrom(options),
27
+ };
28
+ const errorCount = await lintCommits(lintOptions, check);
29
+ if (check && errorCount > 0) {
30
+ throw new Error(`found ${errorCount} lint error(s)`);
31
+ }
32
+ return 0;
33
+ }
package/src/cli/lint.ts CHANGED
@@ -1,109 +1,113 @@
1
- import { loadNiftyNative } from "../native.js";
2
-
3
- const KNOWN_GITMOJIS = ["✨", "🎨", "🚀", "🐛", "🚑", "🔥", "💥", "♻️", "🔧", "📝", "👷", "🧹", "⬆️", "🧪", "🔨", "📦"];
4
-
5
- type LintOptions = {
6
- subjects: string[];
7
- from?: string;
8
- to?: string;
9
- cwd?: string;
10
- };
11
-
12
- type LintDiagnostic = {
13
- rule: string;
14
- severity: "error" | "warning";
15
- message: string;
16
- subject?: string;
17
- };
18
-
19
- export async function runLint(argv: string[], check: boolean): Promise<void> {
20
- const options = parseLintArgs(argv);
21
- const native = loadNiftyNative();
22
- const subjects: string[] = [];
23
-
24
- if (options.subjects.length > 0) {
25
- subjects.push(...options.subjects);
26
- } else {
27
- const cwd = options.cwd ?? process.cwd();
28
- const repoRoot = native.git["discover-root"](cwd);
29
- const toRef = options.to ?? "HEAD";
30
- const commits = native.git["collect-commits"](repoRoot, options.from, toRef);
31
- subjects.push(...commits.map((commit) => commit.subject));
32
- }
33
-
34
- const diagnostics = subjects.flatMap((subject) => lintSubject(subject, native));
35
- for (const item of diagnostics) {
36
- const prefix = item.severity === "error" ? "error" : "warning";
37
- const suffix = item.subject ? ` (${item.subject})` : "";
38
- console.log(`${prefix} [${item.rule}] ${item.message}${suffix}`);
39
- }
40
-
41
- const errorCount = diagnostics.filter((item) => item.severity === "error").length;
42
- if (check && errorCount > 0) {
43
- throw new Error(`found ${errorCount} lint error(s)`);
44
- }
45
- }
46
-
47
- function parseLintArgs(argv: string[]): LintOptions {
48
- const options: LintOptions = { subjects: [] };
49
- for (let i = 0; i < argv.length; i += 1) {
50
- const arg = argv[i];
51
- if (arg === "--from") {
52
- options.from = argv[++i];
53
- } else if (arg === "--to") {
54
- options.to = argv[++i];
55
- } else if (arg === "-C" || arg === "--cwd") {
56
- options.cwd = argv[++i];
57
- } else if (arg === "-s" || arg === "--subject") {
58
- options.subjects.push(argv[++i]);
59
- }
60
- }
61
- return options;
62
- }
63
-
64
- function lintSubject(subject: string, native: ReturnType<typeof loadNiftyNative>): LintDiagnostic[] {
65
- const out: LintDiagnostic[] = [];
66
- if (!native.gitmoji["validate-subject"](subject)) {
67
- out.push({
68
- rule: "gitmoji/subject",
69
- severity: "error",
70
- message: "commit subject must start with a known gitmoji followed by a space",
71
- subject,
72
- });
73
- return out;
74
- }
75
-
76
- const gitmoji = native.gitmoji["leading-gitmoji"](subject);
77
- if (gitmoji && !KNOWN_GITMOJIS.includes(gitmoji)) {
78
- out.push({
79
- rule: "gitmoji/known",
80
- severity: "error",
81
- message: `gitmoji ${gitmoji} is not in the Nifty known gitmoji list`,
82
- subject,
83
- });
84
- }
85
-
86
- const body = native.gitmoji["strip-gitmoji"](subject).trim();
87
- if (!body) {
88
- out.push({
89
- rule: "gitmoji/body",
90
- severity: "warning",
91
- message: "commit subject body must not be empty after the gitmoji prefix",
92
- subject,
93
- });
94
- }
95
-
96
- if (gitmoji) {
97
- const expected = native.gitmoji["format-subject"](gitmoji, body);
98
- if (expected !== subject.trim()) {
99
- out.push({
100
- rule: "gitmoji/format",
101
- severity: "warning",
102
- message: `subject should be formatted as ${expected}`,
103
- subject,
104
- });
105
- }
106
- }
107
-
108
- return out;
109
- }
1
+ import { loadNiftyNative } from "../native.js";
2
+
3
+ const KNOWN_GITMOJIS = ["✨", "🎨", "🚀", "🐛", "🚑", "🔥", "💥", "♻️", "🔧", "📝", "👷", "🧹", "⬆️", "🧪", "🔨", "📦"];
4
+
5
+ export type LintOptions = {
6
+ subjects: string[];
7
+ from?: string;
8
+ to?: string;
9
+ cwd?: string;
10
+ };
11
+
12
+ type LintDiagnostic = {
13
+ rule: string;
14
+ severity: "error" | "warning";
15
+ message: string;
16
+ subject?: string;
17
+ };
18
+
19
+ export async function runLint(argv: string[], check: boolean): Promise<void> {
20
+ const options = parseLintArgs(argv);
21
+ const errorCount = await lintCommits(options, check);
22
+ if (check && errorCount > 0) {
23
+ throw new Error(`found ${errorCount} lint error(s)`);
24
+ }
25
+ }
26
+
27
+ export async function lintCommits(options: LintOptions, check: boolean): Promise<number> {
28
+ const native = loadNiftyNative();
29
+ const subjects: string[] = [];
30
+
31
+ if (options.subjects.length > 0) {
32
+ subjects.push(...options.subjects);
33
+ } else {
34
+ const cwd = options.cwd ?? process.cwd();
35
+ const repoRoot = native.git["discover-root"](cwd);
36
+ const toRef = options.to ?? "HEAD";
37
+ const commits = native.git["collect-commits"](repoRoot, options.from, toRef);
38
+ subjects.push(...commits.map((commit) => commit.subject));
39
+ }
40
+
41
+ const diagnostics = subjects.flatMap((subject) => lintSubject(subject, native));
42
+ for (const item of diagnostics) {
43
+ const prefix = item.severity === "error" ? "error" : "warning";
44
+ const suffix = item.subject ? ` (${item.subject})` : "";
45
+ console.log(`${prefix} [${item.rule}] ${item.message}${suffix}`);
46
+ }
47
+
48
+ return diagnostics.filter((item) => item.severity === "error").length;
49
+ }
50
+
51
+ function parseLintArgs(argv: string[]): LintOptions {
52
+ const options: LintOptions = { subjects: [] };
53
+ for (let i = 0; i < argv.length; i += 1) {
54
+ const arg = argv[i];
55
+ if (arg === "--from") {
56
+ options.from = argv[++i];
57
+ } else if (arg === "--to") {
58
+ options.to = argv[++i];
59
+ } else if (arg === "-C" || arg === "--cwd") {
60
+ options.cwd = argv[++i];
61
+ } else if (arg === "-s" || arg === "--subject") {
62
+ options.subjects.push(argv[++i]);
63
+ }
64
+ }
65
+ return options;
66
+ }
67
+
68
+ function lintSubject(subject: string, native: ReturnType<typeof loadNiftyNative>): LintDiagnostic[] {
69
+ const out: LintDiagnostic[] = [];
70
+ if (!native.gitmoji["validate-subject"](subject)) {
71
+ out.push({
72
+ rule: "gitmoji/subject",
73
+ severity: "error",
74
+ message: "commit subject must start with a known gitmoji followed by a space",
75
+ subject,
76
+ });
77
+ return out;
78
+ }
79
+
80
+ const gitmoji = native.gitmoji["leading-gitmoji"](subject);
81
+ if (gitmoji && !KNOWN_GITMOJIS.includes(gitmoji)) {
82
+ out.push({
83
+ rule: "gitmoji/known",
84
+ severity: "error",
85
+ message: `gitmoji ${gitmoji} is not in the Nifty known gitmoji list`,
86
+ subject,
87
+ });
88
+ }
89
+
90
+ const body = native.gitmoji["strip-gitmoji"](subject).trim();
91
+ if (!body) {
92
+ out.push({
93
+ rule: "gitmoji/body",
94
+ severity: "warning",
95
+ message: "commit subject body must not be empty after the gitmoji prefix",
96
+ subject,
97
+ });
98
+ }
99
+
100
+ if (gitmoji) {
101
+ const expected = native.gitmoji["format-subject"](gitmoji, body);
102
+ if (expected !== subject.trim()) {
103
+ out.push({
104
+ rule: "gitmoji/format",
105
+ severity: "warning",
106
+ message: `subject should be formatted as ${expected}`,
107
+ subject,
108
+ });
109
+ }
110
+ }
111
+
112
+ return out;
113
+ }
package/src/cli/main.ts CHANGED
@@ -1,64 +1 @@
1
- import { runBump } from "./bump.js";
2
- import { bootstrapNiftyConfig } from "./context.js";
3
- import { runLint } from "./lint.js";
4
- import { runPublish } from "./publish.js";
5
- import { runTrust } from "./trust.js";
6
- import { runUpdate } from "./update.js";
7
- import { runUpload } from "./upload.js";
8
-
9
- export async function runCli(argv: string[]): Promise<number> {
10
- const [command, ...rest] = argv;
11
-
12
- if (!command || command === "-h" || command === "--help") {
13
- printHelp();
14
- return 0;
15
- }
16
-
17
- try {
18
- await bootstrapNiftyConfig(rest);
19
- switch (command) {
20
- case "update":
21
- await runUpdate(rest);
22
- return 0;
23
- case "lint":
24
- await runLint(rest, false);
25
- return 0;
26
- case "check":
27
- await runLint(rest, true);
28
- return 0;
29
- case "upload":
30
- await runUpload(rest);
31
- return 0;
32
- case "bump":
33
- await runBump(rest);
34
- return 0;
35
- case "publish":
36
- await runPublish(rest);
37
- return 0;
38
- case "trust":
39
- await runTrust(rest);
40
- return 0;
41
- default:
42
- console.error(`unknown command: ${command}`);
43
- printHelp();
44
- return 1;
45
- }
46
- } catch (error) {
47
- console.error(`error: ${error instanceof Error ? error.message : String(error)}`);
48
- return 1;
49
- }
50
- }
51
-
52
- function printHelp(): void {
53
- console.log(`nifty — Nifty tooling for hybrid cargo + npm projects
54
-
55
- Usage:
56
- nifty update [-i] [-C cwd]
57
- nifty lint [--from ref] [--to ref] [-s subject] [-C cwd]
58
- nifty check [--from ref] [--to ref] [-s subject] [-C cwd]
59
- nifty upload (--release | --pages | --both) [options]
60
- nifty bump [patch|minor|major|version] [--dry-run] [-C cwd]
61
- nifty publish [--dry-run] [--tag <tag>] [--access public] [-C cwd]
62
- nifty trust [--only <pkg>] [--dry-run] [-C cwd]
63
- `);
64
- }
1
+ export { runCli } from "./cli.js";
@@ -0,0 +1,40 @@
1
+ import { resolve } from "node:path";
2
+
3
+ import type { ParsedOptions } from "@vmz/commander";
4
+
5
+ import { resolveNpmExecutable } from "./resolveNpm.js";
6
+ import type { AuthCliOptions } from "./authArgs.js";
7
+
8
+ export function cwdFrom(options: ParsedOptions): string | undefined {
9
+ const value = options.cwd;
10
+ return typeof value === "string" && value.length > 0 ? resolve(value) : undefined;
11
+ }
12
+
13
+ export function flag(options: ParsedOptions, key: string): boolean {
14
+ return options[key] === true;
15
+ }
16
+
17
+ export function str(options: ParsedOptions, key: string): string | undefined {
18
+ const value = options[key];
19
+ return typeof value === "string" && value.length > 0 ? value : undefined;
20
+ }
21
+
22
+ export function strList(options: ParsedOptions, key: string): string[] {
23
+ const value = options[key];
24
+ if (Array.isArray(value)) {
25
+ return value.filter((entry): entry is string => typeof entry === "string" && entry.length > 0);
26
+ }
27
+ if (typeof value === "string" && value.length > 0) {
28
+ return [value];
29
+ }
30
+ return [];
31
+ }
32
+
33
+ export function authFromOptions(options: ParsedOptions): AuthCliOptions {
34
+ return {
35
+ otp: str(options, "otp"),
36
+ totpSecret: str(options, "totp-secret"),
37
+ token: str(options, "npm-token") ?? str(options, "token"),
38
+ npm: resolveNpmExecutable(),
39
+ };
40
+ }
@@ -0,0 +1,34 @@
1
+ import type { Cli, ParsedOptions } from "@vmz/commander";
2
+
3
+ import { loadNiftyNative } from "../native.js";
4
+ import { authPayload } from "./authArgs.js";
5
+ import { bootstrapFromOptions } from "./context.js";
6
+ import { printPublishReport } from "./publish.js";
7
+ import { authFromOptions, cwdFrom, flag, str } from "./options.js";
8
+
9
+ export function registerPublishCommand(cli: Cli): void {
10
+ cli.command("publish", "cli.cmd.publish")
11
+ .option("--dry-run", "cli.opt.dry-run")
12
+ .option("--refresh", "cli.opt.refresh")
13
+ .option("--tag <tag>", "cli.opt.tag")
14
+ .option("--access <access>", "cli.opt.access")
15
+ .option("--otp <code>", "cli.opt.otp")
16
+ .option("--totp-secret <secret>", "cli.opt.totp-secret")
17
+ .option("--npm-token <token>", "cli.opt.npm-token")
18
+ .action(async (options) => cmdPublish(options));
19
+ }
20
+
21
+ export async function cmdPublish(options: ParsedOptions): Promise<number> {
22
+ await bootstrapFromOptions(options);
23
+ const native = loadNiftyNative();
24
+ const report = native.publisher["publish-workspace"]({
25
+ cwd: cwdFrom(options),
26
+ dryRun: flag(options, "dry-run"),
27
+ refresh: flag(options, "refresh"),
28
+ tag: str(options, "tag"),
29
+ access: str(options, "access") ?? "public",
30
+ ...authPayload(authFromOptions(options)),
31
+ });
32
+ printPublishReport(report, flag(options, "dry-run"));
33
+ return 0;
34
+ }