@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.
- package/cli/nifty.mjs +11 -11
- package/locales/en-US/cli.json +64 -0
- package/locales/locales.json +4 -0
- package/package.json +22 -19
- package/src/cli/authArgs.ts +52 -52
- package/src/cli/bump-cmd.ts +55 -0
- package/src/cli/bump.ts +237 -237
- package/src/cli/change-logs-cmd.ts +97 -0
- package/src/cli/cli.ts +45 -0
- package/src/cli/context.ts +36 -26
- package/src/cli/index.ts +9 -8
- package/src/cli/install-native-cmd.ts +22 -0
- package/src/cli/install-native.ts +80 -0
- package/src/cli/lint-cmd.ts +33 -0
- package/src/cli/lint.ts +113 -109
- package/src/cli/main.ts +1 -64
- package/src/cli/options.ts +40 -0
- package/src/cli/publish-cmd.ts +34 -0
- package/src/cli/publish.ts +95 -85
- package/src/cli/resolveNpm.ts +16 -16
- package/src/cli/retime-cmd.ts +62 -0
- package/src/cli/reword-cmd.ts +87 -0
- package/src/cli/trust-cmd.ts +38 -0
- package/src/cli/trust.ts +83 -77
- package/src/cli/update-cmd.ts +20 -0
- package/src/cli/update.ts +185 -182
- package/src/cli/upload-cmd.ts +44 -0
- package/src/cli/upload.ts +313 -280
- package/src/cli/workspace.ts +124 -124
- package/src/config/defineConfig.ts +12 -12
- package/src/config/detectProject.ts +189 -189
- package/src/config/index.ts +25 -25
- package/src/config/loadConfig.ts +129 -129
- package/src/config/types.ts +57 -43
- package/src/git.ts +61 -61
- package/src/github.ts +184 -184
- package/src/gitmoji.ts +77 -77
- package/src/index.ts +36 -36
- package/src/native.ts +507 -277
- package/src/nifty.ts +95 -95
- package/src/types.ts +40 -40
- package/Readme.md +0 -30
package/src/cli/publish.ts
CHANGED
|
@@ -1,85 +1,95 @@
|
|
|
1
|
-
import { loadNiftyNative } from "../native.js";
|
|
2
|
-
import { authPayload, parseAuthArgs } from "./authArgs.js";
|
|
3
|
-
|
|
4
|
-
export type PublishOptions = {
|
|
5
|
-
cwd?: string;
|
|
6
|
-
dryRun?: boolean;
|
|
7
|
-
tag?: string;
|
|
8
|
-
access?: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type PublishReport = {
|
|
12
|
-
root: string;
|
|
13
|
-
order: string[];
|
|
14
|
-
published: string[];
|
|
15
|
-
skipped: string[];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
let
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} else if (arg
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
console.log(`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.log(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
import { loadNiftyNative } from "../native.js";
|
|
2
|
+
import { authPayload, parseAuthArgs } from "./authArgs.js";
|
|
3
|
+
|
|
4
|
+
export type PublishOptions = {
|
|
5
|
+
cwd?: string;
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
tag?: string;
|
|
8
|
+
access?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type PublishReport = {
|
|
12
|
+
root: string;
|
|
13
|
+
order: string[];
|
|
14
|
+
published: string[];
|
|
15
|
+
skipped: string[];
|
|
16
|
+
skippedVersions: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export async function runPublish(argv: string[]): Promise<void> {
|
|
20
|
+
const options = parsePublishArgs(argv);
|
|
21
|
+
const native = loadNiftyNative();
|
|
22
|
+
const report = native.publisher["publish-workspace"]({
|
|
23
|
+
cwd: options.cwd,
|
|
24
|
+
dryRun: options.dryRun,
|
|
25
|
+
refresh: options.refresh,
|
|
26
|
+
tag: options.tag,
|
|
27
|
+
access: options.access,
|
|
28
|
+
...authPayload(options.auth),
|
|
29
|
+
});
|
|
30
|
+
printPublishReport(report, options.dryRun);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parsePublishArgs(argv: string[]) {
|
|
34
|
+
let cwd: string | undefined;
|
|
35
|
+
let dryRun = false;
|
|
36
|
+
let refresh = false;
|
|
37
|
+
let tag: string | undefined;
|
|
38
|
+
let access = "public";
|
|
39
|
+
const auth = parseAuthArgs(argv);
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
42
|
+
const arg = argv[i];
|
|
43
|
+
if (arg === "--dry-run") {
|
|
44
|
+
dryRun = true;
|
|
45
|
+
} else if (arg === "--refresh") {
|
|
46
|
+
refresh = true;
|
|
47
|
+
} else if (arg === "-C" || arg === "--cwd") {
|
|
48
|
+
cwd = argv[++i];
|
|
49
|
+
} else if (arg === "--tag") {
|
|
50
|
+
tag = argv[++i];
|
|
51
|
+
} else if (arg === "--access") {
|
|
52
|
+
access = argv[++i];
|
|
53
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
54
|
+
printPublishHelp();
|
|
55
|
+
process.exit(0);
|
|
56
|
+
} else if (arg.startsWith("-")) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { cwd, dryRun, refresh, tag, access, auth };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function printPublishReport(report: PublishReport, dryRun?: boolean): void {
|
|
65
|
+
const prefix = dryRun ? "would publish" : "published";
|
|
66
|
+
console.log(`${prefix} workspace ${report.root}`);
|
|
67
|
+
if (report.skipped.length > 0) {
|
|
68
|
+
console.log(`skipped private packages: ${report.skipped.join(", ")}`);
|
|
69
|
+
}
|
|
70
|
+
if (report.skippedVersions.length > 0) {
|
|
71
|
+
console.log(`skipped already published: ${report.skippedVersions.join(", ")}`);
|
|
72
|
+
}
|
|
73
|
+
console.log("publish order:");
|
|
74
|
+
for (const name of report.order) {
|
|
75
|
+
const marker = report.published.includes(name) ? prefix : "pending";
|
|
76
|
+
console.log(` ${marker}: ${name}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function printPublishHelp(): void {
|
|
81
|
+
console.log(`nifty publish — publish workspace npm packages in dependency order
|
|
82
|
+
|
|
83
|
+
OTP/TOTP is generated in nifty-publisher (set NPM_TOTP_SECRET in .env.placeholder.local).
|
|
84
|
+
Publish state is cached in .cache/npm-placeholder.json.
|
|
85
|
+
|
|
86
|
+
Usage:
|
|
87
|
+
nifty publish
|
|
88
|
+
nifty publish --dry-run
|
|
89
|
+
nifty publish --refresh
|
|
90
|
+
nifty publish --tag next
|
|
91
|
+
nifty publish --access public
|
|
92
|
+
nifty publish --otp 123456
|
|
93
|
+
nifty publish -C <cwd>
|
|
94
|
+
`);
|
|
95
|
+
}
|
package/src/cli/resolveNpm.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
|
|
4
|
-
/** Resolve npm next to the active Node binary (Windows needs `npm.cmd`). */
|
|
5
|
-
export function resolveNpmExecutable(): string {
|
|
6
|
-
if (process.env.NIFTY_NPM) {
|
|
7
|
-
return process.env.NIFTY_NPM;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const sibling = join(dirname(process.execPath), process.platform === "win32" ? "npm.cmd" : "npm");
|
|
11
|
-
if (existsSync(sibling)) {
|
|
12
|
-
return sibling;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
16
|
-
}
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** Resolve npm next to the active Node binary (Windows needs `npm.cmd`). */
|
|
5
|
+
export function resolveNpmExecutable(): string {
|
|
6
|
+
if (process.env.NIFTY_NPM) {
|
|
7
|
+
return process.env.NIFTY_NPM;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const sibling = join(dirname(process.execPath), process.platform === "win32" ? "npm.cmd" : "npm");
|
|
11
|
+
if (existsSync(sibling)) {
|
|
12
|
+
return sibling;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
16
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
+
|
|
3
|
+
import { loadNiftyNative } from "../native.js";
|
|
4
|
+
import { bootstrapFromOptions } from "./context.js";
|
|
5
|
+
import { cwdFrom, str } from "./options.js";
|
|
6
|
+
|
|
7
|
+
export function registerRetimeCommand(cli: Cli): void {
|
|
8
|
+
const retime = cli.command("retime", "cli.cmd.retime")
|
|
9
|
+
.option("-s, --start-date <start>", "cli.opt.start-date")
|
|
10
|
+
.option("--end-date <end>", "cli.opt.end-date")
|
|
11
|
+
.option("-b, --branch <branch>", "cli.opt.branch")
|
|
12
|
+
.option("--tip <ref>", "cli.opt.tip");
|
|
13
|
+
|
|
14
|
+
retime
|
|
15
|
+
.command("root", "cli.cmd.retime.root")
|
|
16
|
+
.option("-s, --start-date <start>", "cli.opt.start-date")
|
|
17
|
+
.option("--end-date <end>", "cli.opt.end-date")
|
|
18
|
+
.option("-b, --branch <branch>", "cli.opt.branch")
|
|
19
|
+
.option("--tip <ref>", "cli.opt.tip")
|
|
20
|
+
.option("-m, --message <text>", "cli.opt.message")
|
|
21
|
+
.action(async (options) => cmdRetimeRoot(options));
|
|
22
|
+
|
|
23
|
+
retime.action(async (options) => cmdRetimeRange(options));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function cmdRetimeRange(options: ParsedOptions): Promise<number> {
|
|
27
|
+
await bootstrapFromOptions(options);
|
|
28
|
+
const commit = options._[0];
|
|
29
|
+
if (!commit) {
|
|
30
|
+
throw new Error("missing commit hash for range retime");
|
|
31
|
+
}
|
|
32
|
+
const native = loadNiftyNative();
|
|
33
|
+
const report = native.history["retime-range"]({
|
|
34
|
+
cwd: cwdFrom(options),
|
|
35
|
+
commit,
|
|
36
|
+
startDate: str(options, "start-date"),
|
|
37
|
+
endDate: str(options, "end-date"),
|
|
38
|
+
branch: str(options, "branch"),
|
|
39
|
+
tip: str(options, "tip"),
|
|
40
|
+
});
|
|
41
|
+
printRetimeSummary(report);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function cmdRetimeRoot(options: ParsedOptions): Promise<number> {
|
|
46
|
+
await bootstrapFromOptions(options);
|
|
47
|
+
const native = loadNiftyNative();
|
|
48
|
+
const report = native.history["retime-root"]({
|
|
49
|
+
cwd: cwdFrom(options),
|
|
50
|
+
startDate: str(options, "start-date"),
|
|
51
|
+
endDate: str(options, "end-date"),
|
|
52
|
+
branch: str(options, "branch"),
|
|
53
|
+
tip: str(options, "tip"),
|
|
54
|
+
message: str(options, "message"),
|
|
55
|
+
});
|
|
56
|
+
printRetimeSummary(report);
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function printRetimeSummary(report: { rewritten: number; branch: string; newTip: string }): void {
|
|
61
|
+
console.log(`retimed ${report.rewritten} commit(s) on branch ${report.branch}; tip ${report.newTip}`);
|
|
62
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
+
|
|
3
|
+
import { loadNiftyNative } from "../native.js";
|
|
4
|
+
import { bootstrapFromOptions } from "./context.js";
|
|
5
|
+
import { cwdFrom, flag, str } from "./options.js";
|
|
6
|
+
|
|
7
|
+
export function registerRewordCommand(cli: Cli): void {
|
|
8
|
+
const reword = cli.command("reword", "cli.cmd.reword");
|
|
9
|
+
|
|
10
|
+
reword
|
|
11
|
+
.command("export", "cli.cmd.reword.export")
|
|
12
|
+
.option("--base <ref>", "cli.opt.base")
|
|
13
|
+
.option("--ref <ref>", "cli.opt.ref")
|
|
14
|
+
.option("--path <file>", "cli.opt.path")
|
|
15
|
+
.action(async (options) => cmdRewordExport(options));
|
|
16
|
+
|
|
17
|
+
reword
|
|
18
|
+
.command("rewrite", "cli.cmd.reword.rewrite")
|
|
19
|
+
.option("--base <ref>", "cli.opt.base")
|
|
20
|
+
.option("--ref <ref>", "cli.opt.ref")
|
|
21
|
+
.option("--path <file>", "cli.opt.path")
|
|
22
|
+
.option("--dry-run", "cli.opt.dry-run")
|
|
23
|
+
.action(async (options) => cmdRewordRewrite(options));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function cmdRewordExport(options: ParsedOptions): Promise<number> {
|
|
27
|
+
await bootstrapFromOptions(options);
|
|
28
|
+
const base = requireStr(options, "base");
|
|
29
|
+
const path = str(options, "path") ?? "reword.pending.json";
|
|
30
|
+
const native = loadNiftyNative();
|
|
31
|
+
const report = native.history["reword-export"]({
|
|
32
|
+
cwd: cwdFrom(options),
|
|
33
|
+
base,
|
|
34
|
+
ref: str(options, "ref"),
|
|
35
|
+
path,
|
|
36
|
+
});
|
|
37
|
+
console.log(`export: wrote ${report.count} commit entry(ies) to ${report.path}`);
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function cmdRewordRewrite(options: ParsedOptions): Promise<number> {
|
|
42
|
+
await bootstrapFromOptions(options);
|
|
43
|
+
const base = requireStr(options, "base");
|
|
44
|
+
const path = requireStr(options, "path");
|
|
45
|
+
const dryRun = flag(options, "dry-run");
|
|
46
|
+
const native = loadNiftyNative();
|
|
47
|
+
const report = native.history["reword-rewrite"]({
|
|
48
|
+
cwd: cwdFrom(options),
|
|
49
|
+
base,
|
|
50
|
+
ref: str(options, "ref"),
|
|
51
|
+
path,
|
|
52
|
+
dryRun,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (dryRun) {
|
|
56
|
+
if (report.changes.length === 0) {
|
|
57
|
+
console.log("dry-run: no commit objects need rewriting");
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
console.log(`dry-run: ${report.changes.length} commit object(s) would be rewritten on ${report.refName}\n`);
|
|
61
|
+
for (const change of report.changes) {
|
|
62
|
+
console.log(`${change.oldOid} ${change.oldSubject}`);
|
|
63
|
+
console.log(` -> ${change.newSubject}`);
|
|
64
|
+
if (change.parentsRelinked && !change.messageChanged) {
|
|
65
|
+
console.log(" (parent chain relink only)");
|
|
66
|
+
}
|
|
67
|
+
console.log();
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log(
|
|
73
|
+
`rewrote ${report.changes.length} commit object(s); ${report.oldTip} -> ${report.newTip ?? report.oldTip}`,
|
|
74
|
+
);
|
|
75
|
+
for (const change of report.changes) {
|
|
76
|
+
console.log(` ${change.oldOid} ${change.newSubject}`);
|
|
77
|
+
}
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function requireStr(options: ParsedOptions, key: string): string {
|
|
82
|
+
const value = str(options, key);
|
|
83
|
+
if (!value) {
|
|
84
|
+
throw new Error(`missing required --${key}`);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
+
|
|
3
|
+
import { loadNiftyNative } from "../native.js";
|
|
4
|
+
import { authPayload } from "./authArgs.js";
|
|
5
|
+
import { loadConfig } from "../config/loadConfig.js";
|
|
6
|
+
import { bootstrapFromOptions } from "./context.js";
|
|
7
|
+
import { printTrustReport } from "./trust.js";
|
|
8
|
+
import { authFromOptions, cwdFrom, flag, str } from "./options.js";
|
|
9
|
+
|
|
10
|
+
export function registerTrustCommand(cli: Cli): void {
|
|
11
|
+
cli.command("trust", "cli.cmd.trust")
|
|
12
|
+
.option("--dry-run", "cli.opt.dry-run")
|
|
13
|
+
.option("--refresh", "cli.opt.refresh")
|
|
14
|
+
.option("--only <package>", "cli.opt.only")
|
|
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) => cmdTrust(options));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function cmdTrust(options: ParsedOptions): Promise<number> {
|
|
22
|
+
await bootstrapFromOptions(options);
|
|
23
|
+
const { config } = await loadConfig({ cwd: cwdFrom(options), createIfMissing: false });
|
|
24
|
+
const native = loadNiftyNative();
|
|
25
|
+
const report = native.publisher["trust-workspace"]({
|
|
26
|
+
cwd: cwdFrom(options),
|
|
27
|
+
dryRun: flag(options, "dry-run"),
|
|
28
|
+
refresh: flag(options, "refresh"),
|
|
29
|
+
only: str(options, "only"),
|
|
30
|
+
packages: config.publish?.packages,
|
|
31
|
+
...authPayload(authFromOptions(options)),
|
|
32
|
+
});
|
|
33
|
+
printTrustReport(report);
|
|
34
|
+
if (report.failed.length > 0) {
|
|
35
|
+
throw new Error(`trust failed for ${report.failed.length} package(s)`);
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
package/src/cli/trust.ts
CHANGED
|
@@ -1,77 +1,83 @@
|
|
|
1
|
-
import { loadNiftyNative } from "../native.js";
|
|
2
|
-
import { authPayload, parseAuthArgs } from "./authArgs.js";
|
|
3
|
-
|
|
4
|
-
export type TrustReport = {
|
|
5
|
-
root: string;
|
|
6
|
-
configured: string[];
|
|
7
|
-
skipped: string[];
|
|
8
|
-
failed: string[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export async function runTrust(argv: string[]): Promise<void> {
|
|
12
|
-
const options = parseTrustArgs(argv);
|
|
13
|
-
const native = loadNiftyNative();
|
|
14
|
-
const report = native.publisher["trust-workspace"]({
|
|
15
|
-
cwd: options.cwd,
|
|
16
|
-
dryRun: options.dryRun,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} else if (arg === "--
|
|
36
|
-
|
|
37
|
-
} else if (arg === "-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
console.log(`
|
|
53
|
-
for (const name of report.
|
|
54
|
-
console.log(`
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
nifty trust
|
|
76
|
-
|
|
77
|
-
|
|
1
|
+
import { loadNiftyNative } from "../native.js";
|
|
2
|
+
import { authPayload, parseAuthArgs } from "./authArgs.js";
|
|
3
|
+
|
|
4
|
+
export type TrustReport = {
|
|
5
|
+
root: string;
|
|
6
|
+
configured: string[];
|
|
7
|
+
skipped: string[];
|
|
8
|
+
failed: string[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function runTrust(argv: string[]): Promise<void> {
|
|
12
|
+
const options = parseTrustArgs(argv);
|
|
13
|
+
const native = loadNiftyNative();
|
|
14
|
+
const report = native.publisher["trust-workspace"]({
|
|
15
|
+
cwd: options.cwd,
|
|
16
|
+
dryRun: options.dryRun,
|
|
17
|
+
refresh: options.refresh,
|
|
18
|
+
only: options.only,
|
|
19
|
+
...authPayload(options.auth),
|
|
20
|
+
});
|
|
21
|
+
printTrustReport(report);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function parseTrustArgs(argv: string[]) {
|
|
25
|
+
let cwd: string | undefined;
|
|
26
|
+
let dryRun = false;
|
|
27
|
+
let refresh = false;
|
|
28
|
+
let only: string | undefined;
|
|
29
|
+
const auth = parseAuthArgs(argv);
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
32
|
+
const arg = argv[i];
|
|
33
|
+
if (arg === "--dry-run") {
|
|
34
|
+
dryRun = true;
|
|
35
|
+
} else if (arg === "--refresh") {
|
|
36
|
+
refresh = true;
|
|
37
|
+
} else if (arg === "-C" || arg === "--cwd") {
|
|
38
|
+
cwd = argv[++i];
|
|
39
|
+
} else if (arg === "--only") {
|
|
40
|
+
only = argv[++i];
|
|
41
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
42
|
+
printTrustHelp();
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { cwd, dryRun, refresh, only, auth };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function printTrustReport(report: TrustReport): void {
|
|
51
|
+
console.log(`trust workspace ${report.root}`);
|
|
52
|
+
console.log(` configured: ${report.configured.length}`);
|
|
53
|
+
for (const name of report.configured) {
|
|
54
|
+
console.log(` + ${name}`);
|
|
55
|
+
}
|
|
56
|
+
console.log(` skipped: ${report.skipped.length}`);
|
|
57
|
+
for (const name of report.skipped) {
|
|
58
|
+
console.log(` = ${name}`);
|
|
59
|
+
}
|
|
60
|
+
if (report.failed.length > 0) {
|
|
61
|
+
console.log(` failed: ${report.failed.length}`);
|
|
62
|
+
for (const name of report.failed) {
|
|
63
|
+
console.log(` ! ${name}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function printTrustHelp(): void {
|
|
69
|
+
console.log(`nifty trust — configure npm Trusted Publisher for workspace packages
|
|
70
|
+
|
|
71
|
+
Reads NPM_TOTP_SECRET / NPM_OTP / NPM_TOKEN from env or .env.placeholder.local.
|
|
72
|
+
Trust list cache lives in .cache/npm-placeholder.json.
|
|
73
|
+
|
|
74
|
+
Usage:
|
|
75
|
+
nifty trust
|
|
76
|
+
nifty trust --only @doki-land/nifty
|
|
77
|
+
nifty trust --dry-run
|
|
78
|
+
nifty trust --refresh
|
|
79
|
+
nifty trust --totp-secret <base32>
|
|
80
|
+
nifty trust --otp 123456
|
|
81
|
+
nifty trust -C <cwd>
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
+
|
|
3
|
+
import { bootstrapFromOptions } from "./context.js";
|
|
4
|
+
import { updateWorkspace } from "./update.js";
|
|
5
|
+
import { cwdFrom, flag } from "./options.js";
|
|
6
|
+
|
|
7
|
+
export function registerUpdateCommand(cli: Cli): void {
|
|
8
|
+
cli.command("update", "cli.cmd.update")
|
|
9
|
+
.option("-i, --interactive", "cli.opt.interactive")
|
|
10
|
+
.action(async (options) => cmdUpdate(options));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function cmdUpdate(options: ParsedOptions): Promise<number> {
|
|
14
|
+
await bootstrapFromOptions(options);
|
|
15
|
+
await updateWorkspace({
|
|
16
|
+
interactive: flag(options, "interactive"),
|
|
17
|
+
cwd: cwdFrom(options),
|
|
18
|
+
});
|
|
19
|
+
return 0;
|
|
20
|
+
}
|