@doki-land/nifty 0.0.4 → 0.0.5
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 +68 -68
- package/locales/locales.json +4 -4
- package/package.json +16 -20
- package/src/cli/authArgs.ts +52 -52
- package/src/cli/bump-cmd.ts +55 -55
- package/src/cli/bump.ts +237 -237
- package/src/cli/change-logs-cmd.ts +97 -97
- package/src/cli/cli.ts +47 -47
- package/src/cli/context.ts +36 -36
- package/src/cli/format-cmd.ts +23 -23
- package/src/cli/format.ts +28 -28
- package/src/cli/index.ts +9 -9
- package/src/cli/install-native-cmd.ts +22 -22
- package/src/cli/install-native.ts +80 -80
- package/src/cli/lint-cmd.ts +35 -35
- package/src/cli/lint.ts +102 -102
- package/src/cli/main.ts +1 -1
- package/src/cli/options.ts +40 -40
- package/src/cli/publish-cmd.ts +38 -38
- package/src/cli/publish.ts +95 -95
- package/src/cli/resolveNpm.ts +16 -16
- package/src/cli/retime-cmd.ts +62 -62
- package/src/cli/reword-cmd.ts +87 -87
- package/src/cli/trust-cmd.ts +38 -38
- package/src/cli/trust.ts +83 -83
- package/src/cli/update-cmd.ts +20 -20
- package/src/cli/update.ts +32 -32
- package/src/cli/upload-cmd.ts +44 -44
- package/src/cli/upload.ts +313 -313
- 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 -57
- 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 +665 -665
- package/src/nifty.ts +95 -95
- package/src/types.ts +40 -40
- package/README.md +0 -29
package/src/cli/lint.ts
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { loadConfig } from "../config/loadConfig.js";
|
|
2
|
-
import { loadNiftyNative } from "../native.js";
|
|
3
|
-
|
|
4
|
-
export type LintOptions = {
|
|
5
|
-
subjects: string[];
|
|
6
|
-
from?: string;
|
|
7
|
-
to?: string;
|
|
8
|
-
cwd?: string;
|
|
9
|
-
scanCargo?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type LintDiagnostic = {
|
|
13
|
-
rule: string;
|
|
14
|
-
severity: "error" | "warning" | "info";
|
|
15
|
-
message: string;
|
|
16
|
-
subject?: string;
|
|
17
|
-
hash?: string;
|
|
18
|
-
path?: string;
|
|
19
|
-
line?: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type LintRuleConfig = {
|
|
23
|
-
id: string;
|
|
24
|
-
enabled?: boolean;
|
|
25
|
-
severity?: "error" | "warning" | "info";
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export async function runLint(argv: string[], check: boolean): Promise<void> {
|
|
29
|
-
const options = parseLintArgs(argv);
|
|
30
|
-
const errorCount = await lintCommits(options, check);
|
|
31
|
-
if (check && errorCount > 0) {
|
|
32
|
-
throw new Error(`found ${errorCount} lint error(s)`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function lintCommits(options: LintOptions, check: boolean): Promise<number> {
|
|
37
|
-
const native = loadNiftyNative();
|
|
38
|
-
const cwd = options.cwd ?? process.cwd();
|
|
39
|
-
const { config } = await loadConfig({ cwd, createIfMissing: false });
|
|
40
|
-
const rules: LintRuleConfig[] | undefined = config.lint?.rules?.map((rule) => ({
|
|
41
|
-
id: rule.id,
|
|
42
|
-
enabled: rule.enabled,
|
|
43
|
-
severity: rule.severity,
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
const runner = check ? native.lint.check : native.lint.run;
|
|
47
|
-
const report = runner({
|
|
48
|
-
cwd,
|
|
49
|
-
fromRef: options.from,
|
|
50
|
-
toRef: options.to,
|
|
51
|
-
subjects: options.subjects.length > 0 ? options.subjects : undefined,
|
|
52
|
-
rules,
|
|
53
|
-
scanCargo: options.scanCargo,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
for (const item of report.diagnostics) {
|
|
57
|
-
printDiagnostic(item);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (report.diagnostics.length > 0) {
|
|
61
|
-
console.log(`lint: ${report.errorCount} error(s), ${report.warningCount} warning(s)`);
|
|
62
|
-
} else {
|
|
63
|
-
console.log("lint: no issues found");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return report.errorCount;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function printDiagnostic(item: LintDiagnostic): void {
|
|
70
|
-
const prefix = item.severity === "error" ? "error" : item.severity === "warning" ? "warning" : "info";
|
|
71
|
-
if (item.subject) {
|
|
72
|
-
console.log(`${prefix} [${item.rule}] ${item.message} (${item.subject})`);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const location =
|
|
76
|
-
item.path !== undefined
|
|
77
|
-
? item.line !== undefined
|
|
78
|
-
? `${item.path}:${item.line}`
|
|
79
|
-
: item.path
|
|
80
|
-
: undefined;
|
|
81
|
-
const suffix = location ? ` @ ${location}` : "";
|
|
82
|
-
console.log(`${prefix} [${item.rule}] ${item.message}${suffix}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function parseLintArgs(argv: string[]): LintOptions {
|
|
86
|
-
const options: LintOptions = { subjects: [] };
|
|
87
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
88
|
-
const arg = argv[i];
|
|
89
|
-
if (arg === "--from") {
|
|
90
|
-
options.from = argv[++i];
|
|
91
|
-
} else if (arg === "--to") {
|
|
92
|
-
options.to = argv[++i];
|
|
93
|
-
} else if (arg === "-C" || arg === "--cwd") {
|
|
94
|
-
options.cwd = argv[++i];
|
|
95
|
-
} else if (arg === "-s" || arg === "--subject") {
|
|
96
|
-
options.subjects.push(argv[++i]);
|
|
97
|
-
} else if (arg === "--no-cargo") {
|
|
98
|
-
options.scanCargo = false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return options;
|
|
102
|
-
}
|
|
1
|
+
import { loadConfig } from "../config/loadConfig.js";
|
|
2
|
+
import { loadNiftyNative } from "../native.js";
|
|
3
|
+
|
|
4
|
+
export type LintOptions = {
|
|
5
|
+
subjects: string[];
|
|
6
|
+
from?: string;
|
|
7
|
+
to?: string;
|
|
8
|
+
cwd?: string;
|
|
9
|
+
scanCargo?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type LintDiagnostic = {
|
|
13
|
+
rule: string;
|
|
14
|
+
severity: "error" | "warning" | "info";
|
|
15
|
+
message: string;
|
|
16
|
+
subject?: string;
|
|
17
|
+
hash?: string;
|
|
18
|
+
path?: string;
|
|
19
|
+
line?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type LintRuleConfig = {
|
|
23
|
+
id: string;
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
severity?: "error" | "warning" | "info";
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export async function runLint(argv: string[], check: boolean): Promise<void> {
|
|
29
|
+
const options = parseLintArgs(argv);
|
|
30
|
+
const errorCount = await lintCommits(options, check);
|
|
31
|
+
if (check && errorCount > 0) {
|
|
32
|
+
throw new Error(`found ${errorCount} lint error(s)`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function lintCommits(options: LintOptions, check: boolean): Promise<number> {
|
|
37
|
+
const native = loadNiftyNative();
|
|
38
|
+
const cwd = options.cwd ?? process.cwd();
|
|
39
|
+
const { config } = await loadConfig({ cwd, createIfMissing: false });
|
|
40
|
+
const rules: LintRuleConfig[] | undefined = config.lint?.rules?.map((rule) => ({
|
|
41
|
+
id: rule.id,
|
|
42
|
+
enabled: rule.enabled,
|
|
43
|
+
severity: rule.severity,
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
const runner = check ? native.lint.check : native.lint.run;
|
|
47
|
+
const report = runner({
|
|
48
|
+
cwd,
|
|
49
|
+
fromRef: options.from,
|
|
50
|
+
toRef: options.to,
|
|
51
|
+
subjects: options.subjects.length > 0 ? options.subjects : undefined,
|
|
52
|
+
rules,
|
|
53
|
+
scanCargo: options.scanCargo,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
for (const item of report.diagnostics) {
|
|
57
|
+
printDiagnostic(item);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (report.diagnostics.length > 0) {
|
|
61
|
+
console.log(`lint: ${report.errorCount} error(s), ${report.warningCount} warning(s)`);
|
|
62
|
+
} else {
|
|
63
|
+
console.log("lint: no issues found");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return report.errorCount;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function printDiagnostic(item: LintDiagnostic): void {
|
|
70
|
+
const prefix = item.severity === "error" ? "error" : item.severity === "warning" ? "warning" : "info";
|
|
71
|
+
if (item.subject) {
|
|
72
|
+
console.log(`${prefix} [${item.rule}] ${item.message} (${item.subject})`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const location =
|
|
76
|
+
item.path !== undefined
|
|
77
|
+
? item.line !== undefined
|
|
78
|
+
? `${item.path}:${item.line}`
|
|
79
|
+
: item.path
|
|
80
|
+
: undefined;
|
|
81
|
+
const suffix = location ? ` @ ${location}` : "";
|
|
82
|
+
console.log(`${prefix} [${item.rule}] ${item.message}${suffix}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parseLintArgs(argv: string[]): LintOptions {
|
|
86
|
+
const options: LintOptions = { subjects: [] };
|
|
87
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
88
|
+
const arg = argv[i];
|
|
89
|
+
if (arg === "--from") {
|
|
90
|
+
options.from = argv[++i];
|
|
91
|
+
} else if (arg === "--to") {
|
|
92
|
+
options.to = argv[++i];
|
|
93
|
+
} else if (arg === "-C" || arg === "--cwd") {
|
|
94
|
+
options.cwd = argv[++i];
|
|
95
|
+
} else if (arg === "-s" || arg === "--subject") {
|
|
96
|
+
options.subjects.push(argv[++i]);
|
|
97
|
+
} else if (arg === "--no-cargo") {
|
|
98
|
+
options.scanCargo = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return options;
|
|
102
|
+
}
|
package/src/cli/main.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { runCli } from "./cli.js";
|
|
1
|
+
export { runCli } from "./cli.js";
|
package/src/cli/options.ts
CHANGED
|
@@ -1,40 +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
|
-
}
|
|
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
|
+
}
|
package/src/cli/publish-cmd.ts
CHANGED
|
@@ -1,38 +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 { bootstrapFromOptions } from "./context.js";
|
|
6
|
-
import { printPublishReport } from "./publish.js";
|
|
7
|
-
import { authFromOptions, cwdFrom, flag, str, strList } 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("--package <name>", "cli.opt.package")
|
|
14
|
-
.option("--tag <tag>", "cli.opt.tag")
|
|
15
|
-
.option("--access <access>", "cli.opt.access")
|
|
16
|
-
.option("--otp <code>", "cli.opt.otp")
|
|
17
|
-
.option("--totp-secret <secret>", "cli.opt.totp-secret")
|
|
18
|
-
.option("--npm-token <token>", "cli.opt.npm-token")
|
|
19
|
-
.action(async (options) => cmdPublish(options));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function cmdPublish(options: ParsedOptions): Promise<number> {
|
|
23
|
-
await bootstrapFromOptions(options);
|
|
24
|
-
const packages = strList(options, "package");
|
|
25
|
-
const native = loadNiftyNative();
|
|
26
|
-
const report = native.publisher["publish-workspace"]({
|
|
27
|
-
cwd: cwdFrom(options),
|
|
28
|
-
dryRun: flag(options, "dry-run"),
|
|
29
|
-
refresh: flag(options, "refresh"),
|
|
30
|
-
tag: str(options, "tag"),
|
|
31
|
-
access: str(options, "access") ?? "public",
|
|
32
|
-
...(packages.length === 1 ? { only: packages[0] } : {}),
|
|
33
|
-
...(packages.length > 1 ? { packages } : {}),
|
|
34
|
-
...authPayload(authFromOptions(options)),
|
|
35
|
-
});
|
|
36
|
-
printPublishReport(report, flag(options, "dry-run"));
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
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, strList } 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("--package <name>", "cli.opt.package")
|
|
14
|
+
.option("--tag <tag>", "cli.opt.tag")
|
|
15
|
+
.option("--access <access>", "cli.opt.access")
|
|
16
|
+
.option("--otp <code>", "cli.opt.otp")
|
|
17
|
+
.option("--totp-secret <secret>", "cli.opt.totp-secret")
|
|
18
|
+
.option("--npm-token <token>", "cli.opt.npm-token")
|
|
19
|
+
.action(async (options) => cmdPublish(options));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function cmdPublish(options: ParsedOptions): Promise<number> {
|
|
23
|
+
await bootstrapFromOptions(options);
|
|
24
|
+
const packages = strList(options, "package");
|
|
25
|
+
const native = loadNiftyNative();
|
|
26
|
+
const report = native.publisher["publish-workspace"]({
|
|
27
|
+
cwd: cwdFrom(options),
|
|
28
|
+
dryRun: flag(options, "dry-run"),
|
|
29
|
+
refresh: flag(options, "refresh"),
|
|
30
|
+
tag: str(options, "tag"),
|
|
31
|
+
access: str(options, "access") ?? "public",
|
|
32
|
+
...(packages.length === 1 ? { only: packages[0] } : {}),
|
|
33
|
+
...(packages.length > 1 ? { packages } : {}),
|
|
34
|
+
...authPayload(authFromOptions(options)),
|
|
35
|
+
});
|
|
36
|
+
printPublishReport(report, flag(options, "dry-run"));
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
package/src/cli/publish.ts
CHANGED
|
@@ -1,95 +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
|
-
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
|
-
}
|
|
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
|
+
}
|