@doki-land/nifty 0.0.4 → 0.0.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/cli/nifty.mjs +11 -11
- package/locales/en-US/cli.json +70 -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/{reword-cmd.ts → commit-cmd.ts} +128 -87
- package/src/cli/context.ts +36 -36
- package/src/cli/format-cmd.ts +23 -23
- package/src/cli/format.ts +39 -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 +108 -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/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/formatPresets.ts +55 -0
- package/src/config/index.ts +28 -25
- package/src/config/loadConfig.ts +129 -129
- package/src/config/types.ts +78 -57
- package/src/git.ts +61 -61
- package/src/github.ts +184 -184
- package/src/gitmoji.ts +77 -77
- package/src/index.ts +40 -36
- package/src/native.ts +756 -665
- package/src/nifty.ts +95 -95
- package/src/types.ts +40 -40
- package/README.md +0 -29
package/src/cli/cli.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { dirname, join } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
|
|
4
|
-
import { createCli } from "@vmz/commander";
|
|
5
|
-
|
|
6
|
-
import { registerBumpCommand } from "./bump-cmd.js";
|
|
7
|
-
import { registerFormatCommand } from "./format-cmd.js";
|
|
8
|
-
import { registerChangeLogsCommand } from "./change-logs-cmd.js";
|
|
9
|
-
import { registerInstallNativeCommand } from "./install-native-cmd.js";
|
|
10
|
-
import { registerLintCommands } from "./lint-cmd.js";
|
|
11
|
-
import { registerPublishCommand } from "./publish-cmd.js";
|
|
12
|
-
import { registerRetimeCommand } from "./retime-cmd.js";
|
|
13
|
-
import {
|
|
14
|
-
import { registerTrustCommand } from "./trust-cmd.js";
|
|
15
|
-
import { registerUpdateCommand } from "./update-cmd.js";
|
|
16
|
-
import { registerUploadCommand } from "./upload-cmd.js";
|
|
17
|
-
|
|
18
|
-
function buildNiftyCli() {
|
|
19
|
-
const localesRoot = join(dirname(fileURLToPath(import.meta.url)), "../../locales");
|
|
20
|
-
const cli = createCli("nifty")
|
|
21
|
-
.locales(localesRoot)
|
|
22
|
-
.intro("cli.intro")
|
|
23
|
-
.option("-C, --cwd <dir>", "cli.opt.cwd");
|
|
24
|
-
|
|
25
|
-
registerUpdateCommand(cli);
|
|
26
|
-
registerFormatCommand(cli);
|
|
27
|
-
registerLintCommands(cli);
|
|
28
|
-
registerUploadCommand(cli);
|
|
29
|
-
registerInstallNativeCommand(cli);
|
|
30
|
-
registerBumpCommand(cli);
|
|
31
|
-
registerPublishCommand(cli);
|
|
32
|
-
registerTrustCommand(cli);
|
|
33
|
-
|
|
34
|
-
registerRetimeCommand(cli);
|
|
35
|
-
registerChangeLogsCommand(cli);
|
|
36
|
-
|
|
37
|
-
return cli;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function runCli(argv: string[]): Promise<number> {
|
|
41
|
-
try {
|
|
42
|
-
return await buildNiftyCli().parse(argv);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
45
|
-
return 1;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import { createCli } from "@vmz/commander";
|
|
5
|
+
|
|
6
|
+
import { registerBumpCommand } from "./bump-cmd.js";
|
|
7
|
+
import { registerFormatCommand } from "./format-cmd.js";
|
|
8
|
+
import { registerChangeLogsCommand } from "./change-logs-cmd.js";
|
|
9
|
+
import { registerInstallNativeCommand } from "./install-native-cmd.js";
|
|
10
|
+
import { registerLintCommands } from "./lint-cmd.js";
|
|
11
|
+
import { registerPublishCommand } from "./publish-cmd.js";
|
|
12
|
+
import { registerRetimeCommand } from "./retime-cmd.js";
|
|
13
|
+
import { registerCommitCommand } from "./commit-cmd.js";
|
|
14
|
+
import { registerTrustCommand } from "./trust-cmd.js";
|
|
15
|
+
import { registerUpdateCommand } from "./update-cmd.js";
|
|
16
|
+
import { registerUploadCommand } from "./upload-cmd.js";
|
|
17
|
+
|
|
18
|
+
function buildNiftyCli() {
|
|
19
|
+
const localesRoot = join(dirname(fileURLToPath(import.meta.url)), "../../locales");
|
|
20
|
+
const cli = createCli("nifty")
|
|
21
|
+
.locales(localesRoot)
|
|
22
|
+
.intro("cli.intro")
|
|
23
|
+
.option("-C, --cwd <dir>", "cli.opt.cwd");
|
|
24
|
+
|
|
25
|
+
registerUpdateCommand(cli);
|
|
26
|
+
registerFormatCommand(cli);
|
|
27
|
+
registerLintCommands(cli);
|
|
28
|
+
registerUploadCommand(cli);
|
|
29
|
+
registerInstallNativeCommand(cli);
|
|
30
|
+
registerBumpCommand(cli);
|
|
31
|
+
registerPublishCommand(cli);
|
|
32
|
+
registerTrustCommand(cli);
|
|
33
|
+
registerCommitCommand(cli);
|
|
34
|
+
registerRetimeCommand(cli);
|
|
35
|
+
registerChangeLogsCommand(cli);
|
|
36
|
+
|
|
37
|
+
return cli;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function runCli(argv: string[]): Promise<number> {
|
|
41
|
+
try {
|
|
42
|
+
return await buildNiftyCli().parse(argv);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,87 +1,128 @@
|
|
|
1
|
-
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
-
|
|
3
|
-
import { loadNiftyNative } from "../native.js";
|
|
4
|
-
import { bootstrapFromOptions } from "./context.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
.option("--
|
|
14
|
-
.option("--
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
.option("--
|
|
21
|
-
.option("--
|
|
22
|
-
.option("--
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function
|
|
42
|
-
await bootstrapFromOptions(options);
|
|
43
|
-
const base = requireStr(options, "base");
|
|
44
|
-
const path =
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
+
|
|
3
|
+
import { loadNiftyNative } from "../native.js";
|
|
4
|
+
import { bootstrapFromOptions } from "./context.js";
|
|
5
|
+
import { lintCommits, type LintOptions } from "./lint.js";
|
|
6
|
+
import { cwdFrom, flag, str, strList } from "./options.js";
|
|
7
|
+
|
|
8
|
+
export function registerCommitCommand(cli: Cli): void {
|
|
9
|
+
const commit = cli.command("commit", "cli.cmd.commit");
|
|
10
|
+
|
|
11
|
+
commit
|
|
12
|
+
.command("export", "cli.cmd.commit.export")
|
|
13
|
+
.option("--base <ref>", "cli.opt.base")
|
|
14
|
+
.option("--ref <ref>", "cli.opt.ref")
|
|
15
|
+
.option("--path <file>", "cli.opt.path")
|
|
16
|
+
.action(async (options) => cmdCommitExport(options));
|
|
17
|
+
|
|
18
|
+
commit
|
|
19
|
+
.command("apply", "cli.cmd.commit.apply")
|
|
20
|
+
.option("--base <ref>", "cli.opt.base")
|
|
21
|
+
.option("--ref <ref>", "cli.opt.ref")
|
|
22
|
+
.option("--path <file>", "cli.opt.path")
|
|
23
|
+
.option("--dry-run", "cli.opt.dry-run")
|
|
24
|
+
.action(async (options) => cmdCommitApply(options));
|
|
25
|
+
|
|
26
|
+
commit
|
|
27
|
+
.command("scan", "cli.cmd.commit.scan")
|
|
28
|
+
.option("--from <ref>", "cli.opt.from")
|
|
29
|
+
.option("--to <ref>", "cli.opt.to")
|
|
30
|
+
.option("-s, --subject <text>...", "cli.opt.subject")
|
|
31
|
+
.action(async (options) => cmdCommitScan(options));
|
|
32
|
+
|
|
33
|
+
commit
|
|
34
|
+
.command("audit", "cli.cmd.commit.audit")
|
|
35
|
+
.option("--from <ref>", "cli.opt.from")
|
|
36
|
+
.option("--to <ref>", "cli.opt.to")
|
|
37
|
+
.option("-s, --subject <text>...", "cli.opt.subject")
|
|
38
|
+
.action(async (options) => cmdCommitAudit(options));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function cmdCommitExport(options: ParsedOptions): Promise<number> {
|
|
42
|
+
await bootstrapFromOptions(options);
|
|
43
|
+
const base = requireStr(options, "base");
|
|
44
|
+
const path = str(options, "path") ?? "commit.pending.json";
|
|
45
|
+
const native = loadNiftyNative();
|
|
46
|
+
const report = native.history["commit-export"]({
|
|
47
|
+
cwd: cwdFrom(options),
|
|
48
|
+
base,
|
|
49
|
+
ref: str(options, "ref"),
|
|
50
|
+
path,
|
|
51
|
+
});
|
|
52
|
+
console.log(`export: wrote ${report.count} commit entry(ies) to ${report.path}`);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function cmdCommitApply(options: ParsedOptions): Promise<number> {
|
|
57
|
+
await bootstrapFromOptions(options);
|
|
58
|
+
const base = requireStr(options, "base");
|
|
59
|
+
const path = requireStr(options, "path");
|
|
60
|
+
const dryRun = flag(options, "dry-run");
|
|
61
|
+
const native = loadNiftyNative();
|
|
62
|
+
const report = native.history["commit-apply"]({
|
|
63
|
+
cwd: cwdFrom(options),
|
|
64
|
+
base,
|
|
65
|
+
ref: str(options, "ref"),
|
|
66
|
+
path,
|
|
67
|
+
dryRun,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (dryRun) {
|
|
71
|
+
if (report.changes.length === 0) {
|
|
72
|
+
console.log("dry-run: no commit objects need rewriting");
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
console.log(`dry-run: ${report.changes.length} commit object(s) would be rewritten on ${report.refName}\n`);
|
|
76
|
+
for (const change of report.changes) {
|
|
77
|
+
console.log(`${change.oldOid} ${change.oldSubject}`);
|
|
78
|
+
console.log(` -> ${change.newSubject}`);
|
|
79
|
+
if (change.parentsRelinked && !change.messageChanged) {
|
|
80
|
+
console.log(" (parent chain relink only)");
|
|
81
|
+
}
|
|
82
|
+
console.log();
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(
|
|
88
|
+
`applied ${report.changes.length} commit object(s); ${report.oldTip} -> ${report.newTip ?? report.oldTip}`,
|
|
89
|
+
);
|
|
90
|
+
for (const change of report.changes) {
|
|
91
|
+
console.log(` ${change.oldOid} ${change.newSubject}`);
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function cmdCommitScan(options: ParsedOptions): Promise<number> {
|
|
97
|
+
await bootstrapFromOptions(options);
|
|
98
|
+
await lintCommits(commitLintOptions(options), false, true);
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function cmdCommitAudit(options: ParsedOptions): Promise<number> {
|
|
103
|
+
await bootstrapFromOptions(options);
|
|
104
|
+
const errorCount = await lintCommits(commitLintOptions(options), true, true);
|
|
105
|
+
if (errorCount > 0) {
|
|
106
|
+
throw new Error(`found ${errorCount} commit audit error(s)`);
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function commitLintOptions(options: ParsedOptions): LintOptions {
|
|
112
|
+
return {
|
|
113
|
+
subjects: strList(options, "subject"),
|
|
114
|
+
from: str(options, "from"),
|
|
115
|
+
to: str(options, "to"),
|
|
116
|
+
cwd: cwdFrom(options),
|
|
117
|
+
scanCargo: false,
|
|
118
|
+
commitOnly: true,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function requireStr(options: ParsedOptions, key: string): string {
|
|
123
|
+
const value = str(options, key);
|
|
124
|
+
if (!value) {
|
|
125
|
+
throw new Error(`missing required --${key}`);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
package/src/cli/context.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
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
|
-
}
|
|
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/format-cmd.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
-
|
|
3
|
-
import { bootstrapFromOptions } from "./context.js";
|
|
4
|
-
import { formatWorkspace } from "./format.js";
|
|
5
|
-
import { cwdFrom, flag } from "./options.js";
|
|
6
|
-
|
|
7
|
-
export function registerFormatCommand(cli: Cli): void {
|
|
8
|
-
cli.command("format", "cli.cmd.format")
|
|
9
|
-
.option("--check", "cli.opt.check")
|
|
10
|
-
.action(async (options) => cmdFormat(options));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function cmdFormat(options: ParsedOptions): Promise<number> {
|
|
14
|
-
await bootstrapFromOptions(options);
|
|
15
|
-
const exitCode = await formatWorkspace({
|
|
16
|
-
check: flag(options, "check"),
|
|
17
|
-
cwd: cwdFrom(options),
|
|
18
|
-
});
|
|
19
|
-
if (exitCode !== 0) {
|
|
20
|
-
throw new Error("format check failed");
|
|
21
|
-
}
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
1
|
+
import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
2
|
+
|
|
3
|
+
import { bootstrapFromOptions } from "./context.js";
|
|
4
|
+
import { formatWorkspace } from "./format.js";
|
|
5
|
+
import { cwdFrom, flag } from "./options.js";
|
|
6
|
+
|
|
7
|
+
export function registerFormatCommand(cli: Cli): void {
|
|
8
|
+
cli.command("format", "cli.cmd.format")
|
|
9
|
+
.option("--check", "cli.opt.check")
|
|
10
|
+
.action(async (options) => cmdFormat(options));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function cmdFormat(options: ParsedOptions): Promise<number> {
|
|
14
|
+
await bootstrapFromOptions(options);
|
|
15
|
+
const exitCode = await formatWorkspace({
|
|
16
|
+
check: flag(options, "check"),
|
|
17
|
+
cwd: cwdFrom(options),
|
|
18
|
+
});
|
|
19
|
+
if (exitCode !== 0) {
|
|
20
|
+
throw new Error("format check failed");
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
package/src/cli/format.ts
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import { loadConfig, resolveFormatConfig } from "../config/index.js";
|
|
2
|
+
import { loadNiftyNative } from "../native.js";
|
|
3
|
+
|
|
4
|
+
export type FormatOptions = {
|
|
5
|
+
check?: boolean;
|
|
6
|
+
cwd?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export async function formatWorkspace(options: FormatOptions): Promise<number> {
|
|
10
|
+
const cwd = options.cwd ?? process.cwd();
|
|
11
|
+
const { config } = await loadConfig({ cwd, createIfMissing: false, env: { command: "format" } });
|
|
12
|
+
const resolved = resolveFormatConfig(config.format);
|
|
13
|
+
const native = loadNiftyNative();
|
|
14
|
+
const report = native.formatter.run({
|
|
15
|
+
cwd,
|
|
16
|
+
check: options.check,
|
|
17
|
+
includes: resolved.includes,
|
|
18
|
+
excludes: resolved.excludes,
|
|
19
|
+
rust: resolved.rust,
|
|
20
|
+
javascript: resolved.javascript,
|
|
21
|
+
styleConfig: resolved.style,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (report.errors.length > 0) {
|
|
25
|
+
for (const message of report.errors) {
|
|
26
|
+
console.error(`error: ${message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (report.formatted === 0 && report.unchanged > 0 && report.errors.length === 0) {
|
|
31
|
+
console.log(`format: no changes needed (preset ${resolved.preset})`);
|
|
32
|
+
} else if (report.errors.length === 0) {
|
|
33
|
+
console.log(
|
|
34
|
+
`format: ${report.formatted} file(s) updated, ${report.unchanged} unchanged (preset ${resolved.preset})`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return report.errors.length > 0 ? 1 : 0;
|
|
39
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -1,9 +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 { installNativeFromOptions, type InstallNativeOptions } from "./install-native.js";
|
|
9
|
-
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";
|
|
@@ -1,22 +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
|
-
}
|
|
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
|
+
}
|