@doki-land/nifty 0.1.0 → 0.1.1
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 +81 -81
- package/src/cli/change-logs-cmd.ts +26 -26
- package/src/cli/cli.ts +3 -3
- package/src/cli/commit-cmd.ts +77 -77
- package/src/cli/commit-lint-report.ts +44 -44
- 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 +49 -49
- package/src/cli/options.ts +16 -16
- package/src/cli/publish-cmd.ts +16 -16
- 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 +132 -132
- package/src/cli/workspace.ts +49 -49
- package/src/config/authorMap.ts +4 -4
- package/src/config/defineConfig.ts +5 -5
- package/src/config/detectProject.ts +46 -46
- package/src/config/formatPresets.ts +26 -26
- package/src/config/loadConfig.ts +35 -35
- package/src/config/trustPayload.ts +7 -7
- package/src/config/types.ts +38 -38
- package/src/git.ts +14 -14
- package/src/github.ts +54 -54
- package/src/gitmoji.ts +18 -18
- package/src/native.ts +600 -600
- package/src/nifty.ts +30 -30
- 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: Cli): void {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
46
|
+
.action(async(options) =>cmdCommitAudit(options));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export async function cmdCommitExport(options: ParsedOptions): Promise<number>
|
|
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: cwdFrom(options),
|
|
55
|
+
cwd : cwdFrom(options),
|
|
56
56
|
base,
|
|
57
|
-
ref: str(options, "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
|
|
62
|
+
if(flag(options, "with-lint")){
|
|
63
63
|
const errorCount = await lintAndAnnotateExport({
|
|
64
64
|
path,
|
|
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",
|
|
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
|
|
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: ParsedOptions): Promise<number>
|
|
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: cwdFrom(options),
|
|
87
|
+
cwd : cwdFrom(options),
|
|
88
88
|
base,
|
|
89
|
-
ref: str(options, "ref"),
|
|
89
|
+
ref : str(options, "ref"),
|
|
90
90
|
path,
|
|
91
91
|
dryRun,
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
if
|
|
95
|
-
if
|
|
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
|
|
100
|
+
for(const change of report.changes){
|
|
101
101
|
console.log(`${change.oldOid} ${change.oldSubject}`);
|
|
102
102
|
console.log(` -> ${change.newSubject}`);
|
|
103
|
-
if
|
|
103
|
+
if(change.parentsRelinked && !change.messageChanged){
|
|
104
104
|
console.log(" (parent chain relink only)");
|
|
105
105
|
}
|
|
106
106
|
console.log();
|
|
@@ -111,115 +111,115 @@ 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
|
|
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: ParsedOptions): Promise<number>
|
|
120
|
+
export async function cmdCommitScan(options : ParsedOptions) : Promise<number>{
|
|
121
121
|
await bootstrapFromOptions(options);
|
|
122
|
-
await lintCommits({ ...commitLintOptions(options), reportTitle: "commit scan" }, false, true);
|
|
122
|
+
await lintCommits({ ...commitLintOptions(options), reportTitle : "commit scan" }, false, true);
|
|
123
123
|
return 0;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export async function cmdCommitAudit(options: ParsedOptions): Promise<number>
|
|
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
|
|
129
|
+
return errorCount>0 ? 1 : 0;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
function commitLintOptions(options: ParsedOptions): LintOptions {
|
|
132
|
+
function commitLintOptions(options : ParsedOptions) : LintOptions {
|
|
133
133
|
return {
|
|
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",
|
|
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: number;
|
|
148
|
-
entries: Array<{
|
|
149
|
-
hash: string;
|
|
150
|
-
message: string;
|
|
151
|
-
violations
|
|
152
|
-
rule: string;
|
|
153
|
-
severity: "error" | "warning" | "info";
|
|
154
|
-
message: string;
|
|
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: string;
|
|
161
|
-
from: string;
|
|
162
|
-
to: string;
|
|
163
|
-
cwd: string;
|
|
164
|
-
json: boolean;
|
|
165
|
-
errorsOnly: boolean;
|
|
166
|
-
reportTitle: string;
|
|
167
|
-
}): Promise<number>
|
|
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: options.cwd,
|
|
171
|
-
fromRef: options.from,
|
|
172
|
-
toRef: options.to,
|
|
173
|
-
commitOnly: true,
|
|
174
|
-
scanCargo: false,
|
|
170
|
+
cwd : options.cwd,
|
|
171
|
+
fromRef : options.from,
|
|
172
|
+
toRef : options.to,
|
|
173
|
+
commitOnly : true,
|
|
174
|
+
scanCargo : false,
|
|
175
175
|
});
|
|
176
176
|
const diagnostics = options.errorsOnly
|
|
177
|
-
? report.diagnostics.filter((item) =>
|
|
177
|
+
? report.diagnostics.filter((item) =>item.severity === "error")
|
|
178
178
|
: report.diagnostics;
|
|
179
179
|
|
|
180
|
-
if
|
|
180
|
+
if(options.json){
|
|
181
181
|
const { printCommitLintReport } = await import("./commit-lint-report.js");
|
|
182
182
|
printCommitLintReport(diagnostics, report.errorCount, report.warningCount, {
|
|
183
|
-
json: true,
|
|
184
|
-
errorsOnly: options.errorsOnly,
|
|
185
|
-
title: options.reportTitle,
|
|
183
|
+
json : true,
|
|
184
|
+
errorsOnly : options.errorsOnly,
|
|
185
|
+
title : options.reportTitle,
|
|
186
186
|
});
|
|
187
187
|
} else {
|
|
188
188
|
const { printCommitLintReport } = await import("./commit-lint-report.js");
|
|
189
189
|
printCommitLintReport(diagnostics, report.errorCount, report.warningCount, {
|
|
190
|
-
errorsOnly: options.errorsOnly,
|
|
191
|
-
title: options.reportTitle,
|
|
190
|
+
errorsOnly : options.errorsOnly,
|
|
191
|
+
title : options.reportTitle,
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
const byHash = new Map<string, Array<{ rule: string; severity: "error" | "warning" | "info"; message: string }>>();
|
|
196
|
-
for
|
|
197
|
-
if
|
|
195
|
+
const byHash = new Map<string, Array<{ rule : string; severity : "error" | "warning" | "info"; message : string }>>();
|
|
196
|
+
for(const item of diagnostics){
|
|
197
|
+
if(!item.hash){
|
|
198
198
|
continue;
|
|
199
199
|
}
|
|
200
200
|
const bucket = byHash.get(item.hash) ?? [];
|
|
201
|
-
bucket.push({ rule: item.rule, severity: item.severity, message: item.message });
|
|
201
|
+
bucket.push({ rule : item.rule, severity : item.severity, message : item.message });
|
|
202
202
|
byHash.set(item.hash, bucket);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
const text = await readFile(options.path, "utf8");
|
|
206
|
-
const document = JSON.parse(text)
|
|
207
|
-
document.entries = document.entries.map((entry) =>
|
|
206
|
+
const document = JSON.parse(text)as ExportDocument;
|
|
207
|
+
document.entries = document.entries.map((entry) =>{
|
|
208
208
|
const violations = byHash.get(entry.hash);
|
|
209
|
-
if
|
|
209
|
+
if(!violations || violations.length === 0){
|
|
210
210
|
return entry;
|
|
211
211
|
}
|
|
212
212
|
return { ...entry, violations };
|
|
213
213
|
});
|
|
214
214
|
await writeFile(options.path, `${JSON.stringify(document, null, 2)}\n`, "utf8");
|
|
215
|
-
const violationCount = document.entries.filter((entry) =>
|
|
215
|
+
const violationCount = document.entries.filter((entry) =>entry.violations && entry.violations.length>0).length;
|
|
216
216
|
console.log(`export: annotated ${violationCount} commit entry(ies) with lint violations in ${options.path}`);
|
|
217
217
|
return report.errorCount;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
function requireStr(options: ParsedOptions, key: string): string {
|
|
220
|
+
function requireStr(options : ParsedOptions, key : string) : string {
|
|
221
221
|
const value = str(options, key);
|
|
222
|
-
if
|
|
222
|
+
if(!value){
|
|
223
223
|
throw new Error(`missing required --${key}`);
|
|
224
224
|
}
|
|
225
225
|
return value;
|
|
@@ -1,101 +1,101 @@
|
|
|
1
1
|
export type CommitLintDiagnostic = {
|
|
2
|
-
rule: string;
|
|
3
|
-
severity: "error" | "warning" | "info";
|
|
4
|
-
message: string;
|
|
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: CommitLintDiagnostic[];
|
|
18
|
+
hash ? : string;
|
|
19
|
+
subject ? : string;
|
|
20
|
+
items : CommitLintDiagnostic[];
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export function printCommitLintReport(
|
|
24
|
-
diagnostics: CommitLintDiagnostic[],
|
|
25
|
-
errorCount: number,
|
|
26
|
-
warningCount: number,
|
|
27
|
-
options: CommitLintReportOptions = {},
|
|
28
|
-
): void {
|
|
24
|
+
diagnostics : CommitLintDiagnostic[],
|
|
25
|
+
errorCount : number,
|
|
26
|
+
warningCount : number,
|
|
27
|
+
options : CommitLintReportOptions = { },
|
|
28
|
+
) : void {
|
|
29
29
|
const filtered = options.errorsOnly
|
|
30
|
-
? diagnostics.filter((item) =>
|
|
30
|
+
? diagnostics.filter((item) =>item.severity === "error")
|
|
31
31
|
: diagnostics;
|
|
32
32
|
|
|
33
|
-
if
|
|
33
|
+
if(options.json){
|
|
34
34
|
const payload = {
|
|
35
35
|
errorCount,
|
|
36
36
|
warningCount,
|
|
37
|
-
diagnostics: filtered,
|
|
38
|
-
groups: groupCommitDiagnostics(filtered),
|
|
39
|
-
summaryByRule: summarizeByRule(filtered),
|
|
37
|
+
diagnostics : filtered,
|
|
38
|
+
groups : groupCommitDiagnostics(filtered),
|
|
39
|
+
summaryByRule : summarizeByRule(filtered),
|
|
40
40
|
};
|
|
41
41
|
console.log(JSON.stringify(payload, null, 2));
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const title = options.title ?? "commit lint";
|
|
46
|
-
if
|
|
46
|
+
if(filtered.length === 0){
|
|
47
47
|
console.log(`${title}: no issues found`);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const groups = groupCommitDiagnostics(filtered);
|
|
52
|
-
const commitCount = groups.filter((group) =>
|
|
52
|
+
const commitCount = groups.filter((group) =>group.hash || group.subject).length;
|
|
53
53
|
console.log(`${title}: ${errorCount} error(s), ${warningCount} warning(s) in ${commitCount} commit(s)\n`);
|
|
54
54
|
|
|
55
|
-
for
|
|
55
|
+
for(const group of groups){
|
|
56
56
|
printCommitGroup(group);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const summary = summarizeByRule(filtered.filter((item) =>
|
|
60
|
-
if
|
|
59
|
+
const summary = summarizeByRule(filtered.filter((item) =>item.severity === "error"));
|
|
60
|
+
if(summary.length>0){
|
|
61
61
|
console.log("summary by rule:");
|
|
62
|
-
for
|
|
62
|
+
for(const[rule, count]of summary){
|
|
63
63
|
console.log(` ${rule} ${count}`);
|
|
64
64
|
}
|
|
65
65
|
console.log();
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function groupCommitDiagnostics(diagnostics: CommitLintDiagnostic[]): CommitLintGroup[]
|
|
69
|
+
function groupCommitDiagnostics(diagnostics : CommitLintDiagnostic[]) : CommitLintGroup[]{
|
|
70
70
|
const groups = new Map<string, CommitLintGroup>();
|
|
71
|
-
const order: string[] = [];
|
|
71
|
+
const order : string[] = [];
|
|
72
72
|
|
|
73
|
-
for
|
|
73
|
+
for(const item of diagnostics){
|
|
74
74
|
const key = item.hash ?? item.subject ?? "__inline__";
|
|
75
|
-
if
|
|
75
|
+
if(!groups.has(key)){
|
|
76
76
|
groups.set(key, {
|
|
77
|
-
hash: item.hash,
|
|
78
|
-
subject: item.subject,
|
|
79
|
-
items: [],
|
|
77
|
+
hash : item.hash,
|
|
78
|
+
subject : item.subject,
|
|
79
|
+
items : [],
|
|
80
80
|
});
|
|
81
81
|
order.push(key);
|
|
82
82
|
}
|
|
83
|
-
groups.get(key)?.items.push(item);
|
|
83
|
+
groups.get(key) ?.items.push(item);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
return order.map((key) =>
|
|
86
|
+
return order.map((key) =>groups.get(key)!);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
function summarizeByRule(diagnostics: CommitLintDiagnostic[]): Array<[string, number]>
|
|
89
|
+
function summarizeByRule(diagnostics : CommitLintDiagnostic[]) : Array<[string, number]>{
|
|
90
90
|
const counts = new Map<string, number>();
|
|
91
|
-
for
|
|
91
|
+
for(const item of diagnostics){
|
|
92
92
|
counts.set(item.rule, (counts.get(item.rule) ?? 0) + 1);
|
|
93
93
|
}
|
|
94
|
-
return
|
|
94
|
+
return[...counts.entries()].sort((left, right) =>right[1] - left[1] || left[0].localeCompare(right[0]));
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function printCommitGroup(group: CommitLintGroup): void {
|
|
98
|
-
if
|
|
97
|
+
function printCommitGroup(group : CommitLintGroup) : void {
|
|
98
|
+
if(group.hash || group.subject){
|
|
99
99
|
const hash = group.hash ? `${group.hash.slice(0, 8)} ` : "";
|
|
100
100
|
const subject = group.subject ?? "(no subject)";
|
|
101
101
|
console.log(`${hash}${subject}`);
|
|
@@ -103,7 +103,7 @@ function printCommitGroup(group: CommitLintGroup): void {
|
|
|
103
103
|
console.log("(inline subject lint)");
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
for
|
|
106
|
+
for(const item of group.items){
|
|
107
107
|
console.log(` ${item.severity} ${item.rule} ${item.message}`);
|
|
108
108
|
}
|
|
109
109
|
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: string[]): { cwd: string; dryRun: boolean }
|
|
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
|
|
13
|
+
for(let i = 0; i<argv.length; i += 1){
|
|
14
14
|
const arg = argv[i];
|
|
15
|
-
if
|
|
15
|
+
if(arg === "--dry-run"){
|
|
16
16
|
dryRun = true;
|
|
17
|
-
} else if
|
|
18
|
-
cwd = resolve(argv[++i] ?? cwd);
|
|
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: boolean
|
|
|
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: string[]): Promise<void>
|
|
26
|
+
export async function bootstrapNiftyConfig(argv : string[]) : Promise<void>{
|
|
27
27
|
const { cwd, dryRun } = parseCliContext(argv);
|
|
28
|
-
await loadConfig({ cwd, createIfMissing: !dryRun });
|
|
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: ParsedOptions): Promise<void>
|
|
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: !dryRun });
|
|
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: Cli): void {
|
|
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
|
|
10
|
+
.action(async(options) =>cmdFormat(options));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export async function cmdFormat(options: ParsedOptions): Promise<number>
|
|
13
|
+
export async function cmdFormat(options : ParsedOptions) : Promise<number>{
|
|
14
14
|
await bootstrapFromOptions(options);
|
|
15
15
|
const exitCode = await formatWorkspace({
|
|
16
|
-
check: flag(options, "check"),
|
|
17
|
-
cwd: cwdFrom(options),
|
|
16
|
+
check : flag(options, "check"),
|
|
17
|
+
cwd : cwdFrom(options),
|
|
18
18
|
});
|
|
19
|
-
if
|
|
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: FormatOptions): Promise<number>
|
|
9
|
+
export async function formatWorkspace(options : FormatOptions) : Promise<number>{
|
|
10
10
|
const cwd = options.cwd ?? process.cwd();
|
|
11
|
-
const { config } = await loadConfig({ cwd, createIfMissing: false, env: { command: "format" } });
|
|
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: options.check,
|
|
17
|
-
includes: resolved.includes,
|
|
18
|
-
excludes: resolved.excludes,
|
|
19
|
-
rust: resolved.rust,
|
|
20
|
-
javascript: resolved.javascript,
|
|
21
|
-
style: resolved.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
|
|
25
|
-
for
|
|
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
|
|
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
|
|
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
|
|
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: Cli): void {
|
|
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
|
|
9
|
+
.action(async(options) =>cmdInstallNative(options));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export async function cmdInstallNative(options: ParsedOptions): Promise<number>
|
|
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: cwdFrom(options),
|
|
19
|
+
cwd : cwdFrom(options),
|
|
20
20
|
});
|
|
21
21
|
return 0;
|
|
22
22
|
}
|