@doki-land/nifty 0.1.1 → 0.1.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 +2 -2
- package/package.json +6 -6
- package/src/cli/authArgs.ts +29 -29
- package/src/cli/bump-cmd.ts +15 -15
- package/src/cli/bump.ts +79 -79
- package/src/cli/change-logs-cmd.ts +26 -26
- package/src/cli/cli.ts +3 -3
- package/src/cli/commit-cmd.ts +76 -78
- package/src/cli/commit-lint-report.ts +46 -48
- package/src/cli/context.ts +9 -9
- package/src/cli/format-cmd.ts +6 -6
- package/src/cli/format.ts +15 -15
- package/src/cli/install-native-cmd.ts +4 -4
- package/src/cli/install-native.ts +24 -24
- package/src/cli/lint-cmd.ts +11 -11
- package/src/cli/lint.ts +48 -52
- package/src/cli/options.ts +14 -14
- package/src/cli/publish-cmd.ts +12 -18
- package/src/cli/publish.ts +38 -38
- package/src/cli/resolveNpm.ts +3 -3
- package/src/cli/retime-cmd.ts +18 -18
- package/src/cli/trust-cmd.ts +11 -11
- package/src/cli/trust.ts +26 -26
- package/src/cli/update-cmd.ts +5 -5
- package/src/cli/update.ts +12 -12
- package/src/cli/upload-cmd.ts +17 -17
- package/src/cli/upload.ts +131 -131
- package/src/cli/workspace.ts +46 -46
- package/src/config/authorMap.ts +4 -8
- package/src/config/defineConfig.ts +5 -5
- package/src/config/detectProject.ts +46 -46
- package/src/config/formatPresets.ts +24 -24
- package/src/config/loadConfig.ts +35 -35
- package/src/config/trustPayload.ts +6 -6
- package/src/config/types.ts +37 -37
- package/src/git.ts +14 -14
- package/src/github.ts +54 -54
- package/src/gitmoji.ts +18 -18
- package/src/native.ts +595 -599
- package/src/nifty.ts +29 -31
- package/src/types.ts +17 -17
package/src/cli/commit-cmd.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { bootstrapFromOptions } from "./context.js";
|
|
|
7
7
|
import { lintCommits, type LintOptions } from "./lint.js";
|
|
8
8
|
import { cwdFrom, flag, str, strList } from "./options.js";
|
|
9
9
|
|
|
10
|
-
export function registerCommitCommand(cli
|
|
10
|
+
export function registerCommitCommand(cli: Cli): void {
|
|
11
11
|
const commit = cli.command("commit", "cli.cmd.commit");
|
|
12
12
|
|
|
13
13
|
commit
|
|
@@ -17,7 +17,7 @@ export function registerCommitCommand(cli : Cli) : void {
|
|
|
17
17
|
.option("--path <file>", "cli.opt.path")
|
|
18
18
|
.option("--with-lint", "cli.opt.with-lint")
|
|
19
19
|
.option("--errors-only", "cli.opt.errors-only")
|
|
20
|
-
.action(async(options) =>cmdCommitExport(options));
|
|
20
|
+
.action(async(options) => cmdCommitExport(options));
|
|
21
21
|
|
|
22
22
|
commit
|
|
23
23
|
.command("apply", "cli.cmd.commit.apply")
|
|
@@ -25,7 +25,7 @@ export function registerCommitCommand(cli : Cli) : void {
|
|
|
25
25
|
.option("--ref <ref>", "cli.opt.ref")
|
|
26
26
|
.option("--path <file>", "cli.opt.path")
|
|
27
27
|
.option("--dry-run", "cli.opt.dry-run")
|
|
28
|
-
.action(async(options) =>cmdCommitApply(options));
|
|
28
|
+
.action(async(options) => cmdCommitApply(options));
|
|
29
29
|
|
|
30
30
|
commit
|
|
31
31
|
.command("scan", "cli.cmd.commit.scan")
|
|
@@ -34,7 +34,7 @@ export function registerCommitCommand(cli : Cli) : void {
|
|
|
34
34
|
.option("-s, --subject <text>...", "cli.opt.subject")
|
|
35
35
|
.option("--json", "cli.opt.json")
|
|
36
36
|
.option("--errors-only", "cli.opt.errors-only")
|
|
37
|
-
.action(async(options) =>cmdCommitScan(options));
|
|
37
|
+
.action(async(options) => cmdCommitScan(options));
|
|
38
38
|
|
|
39
39
|
commit
|
|
40
40
|
.command("audit", "cli.cmd.commit.audit")
|
|
@@ -43,33 +43,33 @@ export function registerCommitCommand(cli : Cli) : void {
|
|
|
43
43
|
.option("-s, --subject <text>...", "cli.opt.subject")
|
|
44
44
|
.option("--json", "cli.opt.json")
|
|
45
45
|
.option("--errors-only", "cli.opt.errors-only")
|
|
46
|
-
.action(async(options) =>cmdCommitAudit(options));
|
|
46
|
+
.action(async(options) => cmdCommitAudit(options));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export async function cmdCommitExport(options
|
|
49
|
+
export async function cmdCommitExport(options: ParsedOptions): Promise < number> {
|
|
50
50
|
await bootstrapFromOptions(options);
|
|
51
51
|
const base = requireStr(options, "base");
|
|
52
52
|
const path = str(options, "path") ?? "commit.pending.json";
|
|
53
53
|
const native = loadNiftyNative();
|
|
54
54
|
const report = native.history["commit-export"]({
|
|
55
|
-
cwd
|
|
55
|
+
cwd: cwdFrom(options),
|
|
56
56
|
base,
|
|
57
|
-
ref
|
|
57
|
+
ref: str(options, "ref"),
|
|
58
58
|
path,
|
|
59
59
|
});
|
|
60
60
|
console.log(`export: wrote ${report.count} commit entry(ies) to ${report.path}`);
|
|
61
61
|
|
|
62
|
-
if(flag(options, "with-lint")){
|
|
62
|
+
if (flag(options, "with-lint")) {
|
|
63
63
|
const errorCount = await lintAndAnnotateExport({
|
|
64
64
|
path,
|
|
65
|
-
from
|
|
66
|
-
to
|
|
67
|
-
cwd
|
|
68
|
-
json
|
|
69
|
-
errorsOnly
|
|
70
|
-
reportTitle
|
|
65
|
+
from: base,
|
|
66
|
+
to: str(options, "ref") ?? "HEAD",
|
|
67
|
+
cwd: cwdFrom(options) ?? process.cwd(),
|
|
68
|
+
json: flag(options, "json"),
|
|
69
|
+
errorsOnly: flag(options, "errors-only"),
|
|
70
|
+
reportTitle: "commit export lint",
|
|
71
71
|
});
|
|
72
|
-
if(errorCount>0){
|
|
72
|
+
if (errorCount > 0) {
|
|
73
73
|
return 1;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -77,30 +77,30 @@ export async function cmdCommitExport(options : ParsedOptions) : Promise<number>
|
|
|
77
77
|
return 0;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
export async function cmdCommitApply(options
|
|
80
|
+
export async function cmdCommitApply(options: ParsedOptions): Promise < number> {
|
|
81
81
|
await bootstrapFromOptions(options);
|
|
82
82
|
const base = requireStr(options, "base");
|
|
83
83
|
const path = requireStr(options, "path");
|
|
84
84
|
const dryRun = flag(options, "dry-run");
|
|
85
85
|
const native = loadNiftyNative();
|
|
86
86
|
const report = native.history["commit-apply"]({
|
|
87
|
-
cwd
|
|
87
|
+
cwd: cwdFrom(options),
|
|
88
88
|
base,
|
|
89
|
-
ref
|
|
89
|
+
ref: str(options, "ref"),
|
|
90
90
|
path,
|
|
91
91
|
dryRun,
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
if(dryRun){
|
|
95
|
-
if(report.changes.length === 0){
|
|
94
|
+
if (dryRun) {
|
|
95
|
+
if (report.changes.length === 0) {
|
|
96
96
|
console.log("dry-run: no commit objects need rewriting");
|
|
97
97
|
return 0;
|
|
98
98
|
}
|
|
99
99
|
console.log(`dry-run: ${report.changes.length} commit object(s) would be rewritten on ${report.refName}\n`);
|
|
100
|
-
for(const change of report.changes){
|
|
100
|
+
for (const change of report.changes) {
|
|
101
101
|
console.log(`${change.oldOid} ${change.oldSubject}`);
|
|
102
102
|
console.log(` -> ${change.newSubject}`);
|
|
103
|
-
if(change.parentsRelinked && !change.messageChanged){
|
|
103
|
+
if (change.parentsRelinked && !change.messageChanged) {
|
|
104
104
|
console.log(" (parent chain relink only)");
|
|
105
105
|
}
|
|
106
106
|
console.log();
|
|
@@ -111,115 +111,113 @@ export async function cmdCommitApply(options : ParsedOptions) : Promise<number>{
|
|
|
111
111
|
console.log(
|
|
112
112
|
`applied ${report.changes.length} commit object(s); ${report.oldTip} -> ${report.newTip ?? report.oldTip}`,
|
|
113
113
|
);
|
|
114
|
-
for(const change of report.changes){
|
|
114
|
+
for (const change of report.changes) {
|
|
115
115
|
console.log(` ${change.oldOid} ${change.newSubject}`);
|
|
116
116
|
}
|
|
117
117
|
return 0;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export async function cmdCommitScan(options
|
|
120
|
+
export async function cmdCommitScan(options: ParsedOptions): Promise < number> {
|
|
121
121
|
await bootstrapFromOptions(options);
|
|
122
|
-
await lintCommits({ ...commitLintOptions(options), reportTitle
|
|
122
|
+
await lintCommits({ ...commitLintOptions(options), reportTitle: "commit scan" }, false, true);
|
|
123
123
|
return 0;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export async function cmdCommitAudit(options
|
|
126
|
+
export async function cmdCommitAudit(options: ParsedOptions): Promise < number> {
|
|
127
127
|
await bootstrapFromOptions(options);
|
|
128
128
|
const errorCount = await lintCommits(commitLintOptions(options), false, true);
|
|
129
|
-
return errorCount>0 ? 1 : 0;
|
|
129
|
+
return errorCount > 0 ? 1 : 0;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
function commitLintOptions(options
|
|
132
|
+
function commitLintOptions(options: ParsedOptions): LintOptions {
|
|
133
133
|
return {
|
|
134
|
-
subjects
|
|
135
|
-
from
|
|
136
|
-
to
|
|
137
|
-
cwd
|
|
138
|
-
scanCargo
|
|
139
|
-
commitOnly
|
|
140
|
-
json
|
|
141
|
-
errorsOnly
|
|
142
|
-
reportTitle
|
|
134
|
+
subjects: strList(options, "subject"),
|
|
135
|
+
from: str(options, "from"),
|
|
136
|
+
to: str(options, "to"),
|
|
137
|
+
cwd: cwdFrom(options),
|
|
138
|
+
scanCargo: false,
|
|
139
|
+
commitOnly: true,
|
|
140
|
+
json: flag(options, "json"),
|
|
141
|
+
errorsOnly: flag(options, "errors-only"),
|
|
142
|
+
reportTitle: "commit audit",
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
type ExportDocument = {
|
|
147
|
-
version
|
|
148
|
-
entries
|
|
149
|
-
hash
|
|
150
|
-
message
|
|
151
|
-
violations
|
|
152
|
-
rule
|
|
153
|
-
severity
|
|
154
|
-
message
|
|
147
|
+
version: number;
|
|
148
|
+
entries: Array < {
|
|
149
|
+
hash: string;
|
|
150
|
+
message: string;
|
|
151
|
+
violations?: Array < {
|
|
152
|
+
rule: string;
|
|
153
|
+
severity: "error" | "warning" | "info";
|
|
154
|
+
message: string;
|
|
155
155
|
}>;
|
|
156
156
|
}>;
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
-
async function lintAndAnnotateExport(options
|
|
160
|
-
path
|
|
161
|
-
from
|
|
162
|
-
to
|
|
163
|
-
cwd
|
|
164
|
-
json
|
|
165
|
-
errorsOnly
|
|
166
|
-
reportTitle
|
|
167
|
-
})
|
|
159
|
+
async function lintAndAnnotateExport(options: {
|
|
160
|
+
path: string;
|
|
161
|
+
from: string;
|
|
162
|
+
to: string;
|
|
163
|
+
cwd: string;
|
|
164
|
+
json: boolean;
|
|
165
|
+
errorsOnly: boolean;
|
|
166
|
+
reportTitle: string;
|
|
167
|
+
}): Promise < number> {
|
|
168
168
|
const native = loadNiftyNative();
|
|
169
169
|
const report = native.lint.run({
|
|
170
|
-
cwd
|
|
171
|
-
fromRef
|
|
172
|
-
toRef
|
|
173
|
-
commitOnly
|
|
174
|
-
scanCargo
|
|
170
|
+
cwd: options.cwd,
|
|
171
|
+
fromRef: options.from,
|
|
172
|
+
toRef: options.to,
|
|
173
|
+
commitOnly: true,
|
|
174
|
+
scanCargo: false,
|
|
175
175
|
});
|
|
176
|
-
const diagnostics = options.errorsOnly
|
|
177
|
-
? report.diagnostics.filter((item) =>item.severity === "error")
|
|
178
|
-
: report.diagnostics;
|
|
176
|
+
const diagnostics = options.errorsOnly ? report.diagnostics.filter((item) => item.severity === "error") : report.diagnostics;
|
|
179
177
|
|
|
180
|
-
if(options.json){
|
|
178
|
+
if (options.json) {
|
|
181
179
|
const { printCommitLintReport } = await import("./commit-lint-report.js");
|
|
182
180
|
printCommitLintReport(diagnostics, report.errorCount, report.warningCount, {
|
|
183
|
-
json
|
|
184
|
-
errorsOnly
|
|
185
|
-
title
|
|
181
|
+
json: true,
|
|
182
|
+
errorsOnly: options.errorsOnly,
|
|
183
|
+
title: options.reportTitle,
|
|
186
184
|
});
|
|
187
185
|
} else {
|
|
188
186
|
const { printCommitLintReport } = await import("./commit-lint-report.js");
|
|
189
187
|
printCommitLintReport(diagnostics, report.errorCount, report.warningCount, {
|
|
190
|
-
errorsOnly
|
|
191
|
-
title
|
|
188
|
+
errorsOnly: options.errorsOnly,
|
|
189
|
+
title: options.reportTitle,
|
|
192
190
|
});
|
|
193
191
|
}
|
|
194
192
|
|
|
195
|
-
const byHash = new Map<string, Array<{ rule
|
|
196
|
-
for(const item of diagnostics){
|
|
197
|
-
if(!item.hash){
|
|
193
|
+
const byHash = new Map < string, Array < { rule: string; severity: "error" | "warning" | "info"; message: string }>>();
|
|
194
|
+
for (const item of diagnostics) {
|
|
195
|
+
if (!item.hash) {
|
|
198
196
|
continue;
|
|
199
197
|
}
|
|
200
198
|
const bucket = byHash.get(item.hash) ?? [];
|
|
201
|
-
bucket.push({ rule
|
|
199
|
+
bucket.push({ rule: item.rule, severity: item.severity, message: item.message });
|
|
202
200
|
byHash.set(item.hash, bucket);
|
|
203
201
|
}
|
|
204
202
|
|
|
205
203
|
const text = await readFile(options.path, "utf8");
|
|
206
204
|
const document = JSON.parse(text)as ExportDocument;
|
|
207
|
-
document.entries = document.entries.map((entry) =>{
|
|
205
|
+
document.entries = document.entries.map((entry) => {
|
|
208
206
|
const violations = byHash.get(entry.hash);
|
|
209
|
-
if(!violations || violations.length === 0){
|
|
207
|
+
if (!violations || violations.length === 0) {
|
|
210
208
|
return entry;
|
|
211
209
|
}
|
|
212
210
|
return { ...entry, violations };
|
|
213
211
|
});
|
|
214
212
|
await writeFile(options.path, `${JSON.stringify(document, null, 2)}\n`, "utf8");
|
|
215
|
-
const violationCount = document.entries.filter((entry) =>entry.violations && entry.violations.length>0).length;
|
|
213
|
+
const violationCount = document.entries.filter((entry) => entry.violations && entry.violations.length > 0).length;
|
|
216
214
|
console.log(`export: annotated ${violationCount} commit entry(ies) with lint violations in ${options.path}`);
|
|
217
215
|
return report.errorCount;
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
function requireStr(options
|
|
218
|
+
function requireStr(options: ParsedOptions, key: string): string {
|
|
221
219
|
const value = str(options, key);
|
|
222
|
-
if(!value){
|
|
220
|
+
if (!value) {
|
|
223
221
|
throw new Error(`missing required --${key}`);
|
|
224
222
|
}
|
|
225
223
|
return value;
|
|
@@ -1,101 +1,99 @@
|
|
|
1
1
|
export type CommitLintDiagnostic = {
|
|
2
|
-
rule
|
|
3
|
-
severity
|
|
4
|
-
message
|
|
5
|
-
subject
|
|
6
|
-
hash
|
|
7
|
-
path
|
|
8
|
-
line
|
|
2
|
+
rule: string;
|
|
3
|
+
severity: "error" | "warning" | "info";
|
|
4
|
+
message: string;
|
|
5
|
+
subject?: string;
|
|
6
|
+
hash?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
line?: number;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export type CommitLintReportOptions = {
|
|
12
|
-
json
|
|
13
|
-
errorsOnly
|
|
14
|
-
title
|
|
12
|
+
json?: boolean;
|
|
13
|
+
errorsOnly?: boolean;
|
|
14
|
+
title?: string;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
type CommitLintGroup = {
|
|
18
|
-
hash
|
|
19
|
-
subject
|
|
20
|
-
items
|
|
18
|
+
hash?: string;
|
|
19
|
+
subject?: string;
|
|
20
|
+
items: CommitLintDiagnostic[];
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export function printCommitLintReport(
|
|
24
|
-
diagnostics
|
|
25
|
-
errorCount
|
|
26
|
-
warningCount
|
|
27
|
-
options
|
|
28
|
-
)
|
|
29
|
-
const filtered = options.errorsOnly
|
|
30
|
-
? diagnostics.filter((item) =>item.severity === "error")
|
|
31
|
-
: diagnostics;
|
|
24
|
+
diagnostics: CommitLintDiagnostic[],
|
|
25
|
+
errorCount: number,
|
|
26
|
+
warningCount: number,
|
|
27
|
+
options: CommitLintReportOptions = { },
|
|
28
|
+
): void {
|
|
29
|
+
const filtered = options.errorsOnly ? diagnostics.filter((item) => item.severity === "error") : diagnostics;
|
|
32
30
|
|
|
33
|
-
if(options.json){
|
|
31
|
+
if (options.json) {
|
|
34
32
|
const payload = {
|
|
35
33
|
errorCount,
|
|
36
34
|
warningCount,
|
|
37
|
-
diagnostics
|
|
38
|
-
groups
|
|
39
|
-
summaryByRule
|
|
35
|
+
diagnostics: filtered,
|
|
36
|
+
groups: groupCommitDiagnostics(filtered),
|
|
37
|
+
summaryByRule: summarizeByRule(filtered),
|
|
40
38
|
};
|
|
41
39
|
console.log(JSON.stringify(payload, null, 2));
|
|
42
40
|
return;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
const title = options.title ?? "commit lint";
|
|
46
|
-
if(filtered.length === 0){
|
|
44
|
+
if (filtered.length === 0) {
|
|
47
45
|
console.log(`${title}: no issues found`);
|
|
48
46
|
return;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
const groups = groupCommitDiagnostics(filtered);
|
|
52
|
-
const commitCount = groups.filter((group) =>group.hash || group.subject).length;
|
|
50
|
+
const commitCount = groups.filter((group) => group.hash || group.subject).length;
|
|
53
51
|
console.log(`${title}: ${errorCount} error(s), ${warningCount} warning(s) in ${commitCount} commit(s)\n`);
|
|
54
52
|
|
|
55
|
-
for(const group of groups){
|
|
53
|
+
for (const group of groups) {
|
|
56
54
|
printCommitGroup(group);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
const summary = summarizeByRule(filtered.filter((item) =>item.severity === "error"));
|
|
60
|
-
if(summary.length>0){
|
|
57
|
+
const summary = summarizeByRule(filtered.filter((item) => item.severity === "error"));
|
|
58
|
+
if (summary.length > 0) {
|
|
61
59
|
console.log("summary by rule:");
|
|
62
|
-
for(const[rule, count]of summary){
|
|
60
|
+
for (const[rule, count]of summary) {
|
|
63
61
|
console.log(` ${rule} ${count}`);
|
|
64
62
|
}
|
|
65
63
|
console.log();
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
function groupCommitDiagnostics(diagnostics
|
|
70
|
-
const groups = new Map<string, CommitLintGroup>();
|
|
71
|
-
const order
|
|
67
|
+
function groupCommitDiagnostics(diagnostics: CommitLintDiagnostic[]): CommitLintGroup[] {
|
|
68
|
+
const groups = new Map < string, CommitLintGroup > ();
|
|
69
|
+
const order: string[] = [];
|
|
72
70
|
|
|
73
|
-
for(const item of diagnostics){
|
|
71
|
+
for (const item of diagnostics) {
|
|
74
72
|
const key = item.hash ?? item.subject ?? "__inline__";
|
|
75
|
-
if(!groups.has(key)){
|
|
73
|
+
if (!groups.has(key)) {
|
|
76
74
|
groups.set(key, {
|
|
77
|
-
hash
|
|
78
|
-
subject
|
|
79
|
-
items
|
|
75
|
+
hash: item.hash,
|
|
76
|
+
subject: item.subject,
|
|
77
|
+
items: [],
|
|
80
78
|
});
|
|
81
79
|
order.push(key);
|
|
82
80
|
}
|
|
83
|
-
groups.get(key)
|
|
81
|
+
groups.get(key)?.items.push(item);
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
return order.map((key) =>groups.get(key)!);
|
|
84
|
+
return order.map((key) => groups.get(key)!);
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
function summarizeByRule(diagnostics
|
|
90
|
-
const counts = new Map<string, number>();
|
|
91
|
-
for(const item of diagnostics){
|
|
87
|
+
function summarizeByRule(diagnostics: CommitLintDiagnostic[]): Array < [string, number] > {
|
|
88
|
+
const counts = new Map < string, number > ();
|
|
89
|
+
for (const item of diagnostics) {
|
|
92
90
|
counts.set(item.rule, (counts.get(item.rule) ?? 0) + 1);
|
|
93
91
|
}
|
|
94
|
-
return[...counts.entries()].sort((left, right) =>right[1] - left[1] || left[0].localeCompare(right[0]));
|
|
92
|
+
return[...counts.entries()].sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0]));
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
function printCommitGroup(group
|
|
98
|
-
if(group.hash || group.subject){
|
|
95
|
+
function printCommitGroup(group: CommitLintGroup): void {
|
|
96
|
+
if (group.hash || group.subject) {
|
|
99
97
|
const hash = group.hash ? `${group.hash.slice(0, 8)} ` : "";
|
|
100
98
|
const subject = group.subject ?? "(no subject)";
|
|
101
99
|
console.log(`${hash}${subject}`);
|
|
@@ -103,7 +101,7 @@ function printCommitGroup(group : CommitLintGroup) : void {
|
|
|
103
101
|
console.log("(inline subject lint)");
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
for(const item of group.items){
|
|
104
|
+
for (const item of group.items) {
|
|
107
105
|
console.log(` ${item.severity} ${item.rule} ${item.message}`);
|
|
108
106
|
}
|
|
109
107
|
console.log();
|
package/src/cli/context.ts
CHANGED
|
@@ -6,16 +6,16 @@ import { loadConfig } from "../config/loadConfig.js";
|
|
|
6
6
|
import { cwdFrom } from "./options.js";
|
|
7
7
|
|
|
8
8
|
/** Parse shared CLI flags used across nifty commands. */
|
|
9
|
-
export function parseCliContext(argv
|
|
9
|
+
export function parseCliContext(argv: string[]): { cwd: string; dryRun: boolean } {
|
|
10
10
|
let cwd = process.cwd();
|
|
11
11
|
let dryRun = false;
|
|
12
12
|
|
|
13
|
-
for(let i = 0; i<argv.length; i += 1){
|
|
13
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
14
14
|
const arg = argv[i];
|
|
15
|
-
if(arg === "--dry-run"){
|
|
15
|
+
if (arg === "--dry-run") {
|
|
16
16
|
dryRun = true;
|
|
17
|
-
} else if(arg === "-C" || arg === "--cwd"){
|
|
18
|
-
cwd = resolve(argv[
|
|
17
|
+
} else if (arg === "-C" || arg === "--cwd") {
|
|
18
|
+
cwd = resolve(argv[++i] ?? cwd);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -23,14 +23,14 @@ export function parseCliContext(argv : string[]) : { cwd : string; dryRun : bool
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** Ensure `nifty.config.*` exists before running a command (skip create on `--dry-run`). */
|
|
26
|
-
export async function bootstrapNiftyConfig(argv
|
|
26
|
+
export async function bootstrapNiftyConfig(argv: string[]): Promise < void> {
|
|
27
27
|
const { cwd, dryRun } = parseCliContext(argv);
|
|
28
|
-
await loadConfig({ cwd, createIfMissing
|
|
28
|
+
await loadConfig({ cwd, createIfMissing: !dryRun });
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Commander action hook: load config from parsed global/command flags. */
|
|
32
|
-
export async function bootstrapFromOptions(options
|
|
32
|
+
export async function bootstrapFromOptions(options: ParsedOptions): Promise < void> {
|
|
33
33
|
const cwd = cwdFrom(options) ?? process.cwd();
|
|
34
34
|
const dryRun = options["dry-run"] === true;
|
|
35
|
-
await loadConfig({ cwd, createIfMissing
|
|
35
|
+
await loadConfig({ cwd, createIfMissing: !dryRun });
|
|
36
36
|
}
|
package/src/cli/format-cmd.ts
CHANGED
|
@@ -4,19 +4,19 @@ import { bootstrapFromOptions } from "./context.js";
|
|
|
4
4
|
import { formatWorkspace } from "./format.js";
|
|
5
5
|
import { cwdFrom, flag } from "./options.js";
|
|
6
6
|
|
|
7
|
-
export function registerFormatCommand(cli
|
|
7
|
+
export function registerFormatCommand(cli: Cli): void {
|
|
8
8
|
cli.command("format", "cli.cmd.format")
|
|
9
9
|
.option("--check", "cli.opt.check")
|
|
10
|
-
.action(async(options) =>cmdFormat(options));
|
|
10
|
+
.action(async(options) => cmdFormat(options));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export async function cmdFormat(options
|
|
13
|
+
export async function cmdFormat(options: ParsedOptions): Promise < number> {
|
|
14
14
|
await bootstrapFromOptions(options);
|
|
15
15
|
const exitCode = await formatWorkspace({
|
|
16
|
-
check
|
|
17
|
-
cwd
|
|
16
|
+
check: flag(options, "check"),
|
|
17
|
+
cwd: cwdFrom(options),
|
|
18
18
|
});
|
|
19
|
-
if(exitCode!== 0){
|
|
19
|
+
if (exitCode !== 0) {
|
|
20
20
|
throw new Error("format check failed");
|
|
21
21
|
}
|
|
22
22
|
return 0;
|
package/src/cli/format.ts
CHANGED
|
@@ -2,38 +2,38 @@ import { loadConfig, resolveFormatConfig } from "../config/index.js";
|
|
|
2
2
|
import { loadNiftyNative } from "../native.js";
|
|
3
3
|
|
|
4
4
|
export type FormatOptions = {
|
|
5
|
-
check
|
|
6
|
-
cwd
|
|
5
|
+
check?: boolean;
|
|
6
|
+
cwd?: string;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export async function formatWorkspace(options
|
|
9
|
+
export async function formatWorkspace(options: FormatOptions): Promise < number> {
|
|
10
10
|
const cwd = options.cwd ?? process.cwd();
|
|
11
|
-
const { config } = await loadConfig({ cwd, createIfMissing
|
|
11
|
+
const { config } = await loadConfig({ cwd, createIfMissing: false, env: { command: "format" } });
|
|
12
12
|
const resolved = resolveFormatConfig(config.format);
|
|
13
13
|
const native = loadNiftyNative();
|
|
14
14
|
const report = native.formatter.run({
|
|
15
15
|
cwd,
|
|
16
|
-
check
|
|
17
|
-
includes
|
|
18
|
-
excludes
|
|
19
|
-
rust
|
|
20
|
-
javascript
|
|
21
|
-
style
|
|
16
|
+
check: options.check,
|
|
17
|
+
includes: resolved.includes,
|
|
18
|
+
excludes: resolved.excludes,
|
|
19
|
+
rust: resolved.rust,
|
|
20
|
+
javascript: resolved.javascript,
|
|
21
|
+
style: resolved.style,
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
if(report.errors.length>0){
|
|
25
|
-
for(const message of report.errors){
|
|
24
|
+
if (report.errors.length > 0) {
|
|
25
|
+
for (const message of report.errors) {
|
|
26
26
|
console.error(`error: ${message}`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
if(report.formatted === 0 && report.unchanged>0 && report.errors.length === 0){
|
|
30
|
+
if (report.formatted === 0 && report.unchanged > 0 && report.errors.length === 0) {
|
|
31
31
|
console.log(`format: no changes needed (preset ${resolved.preset})`);
|
|
32
|
-
} else if(report.errors.length === 0){
|
|
32
|
+
} else if (report.errors.length === 0) {
|
|
33
33
|
console.log(
|
|
34
34
|
`format: ${report.formatted} file(s) updated, ${report.unchanged} unchanged (preset ${resolved.preset})`,
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
return report.errors.length>0 ? 1 : 0;
|
|
38
|
+
return report.errors.length > 0 ? 1 : 0;
|
|
39
39
|
}
|
|
@@ -3,20 +3,20 @@ import type { Cli, ParsedOptions } from "@vmz/commander";
|
|
|
3
3
|
import { installNativeFromOptions } from "./install-native.js";
|
|
4
4
|
import { cwdFrom, str } from "./options.js";
|
|
5
5
|
|
|
6
|
-
export function registerInstallNativeCommand(cli
|
|
6
|
+
export function registerInstallNativeCommand(cli: Cli): void {
|
|
7
7
|
cli.command("install-native", "cli.cmd.install-native")
|
|
8
8
|
.option("--from <dir>", "cli.opt.from-artifacts")
|
|
9
|
-
.action(async(options) =>cmdInstallNative(options));
|
|
9
|
+
.action(async(options) => cmdInstallNative(options));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export async function cmdInstallNative(options
|
|
12
|
+
export async function cmdInstallNative(options: ParsedOptions): Promise < number> {
|
|
13
13
|
const from =
|
|
14
14
|
str(options, "from") ??
|
|
15
15
|
process.env.NATIVE_ARTIFACT_ROOT ??
|
|
16
16
|
"native-artifacts";
|
|
17
17
|
installNativeFromOptions({
|
|
18
18
|
from,
|
|
19
|
-
cwd
|
|
19
|
+
cwd: cwdFrom(options),
|
|
20
20
|
});
|
|
21
21
|
return 0;
|
|
22
22
|
}
|