@moonbase.sh/gorilla-engine 0.1.0 → 0.2.0
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/README.md +77 -8
- package/dist/index.cjs +514 -122
- package/dist/index.d.cts +147 -12
- package/dist/index.d.ts +147 -12
- package/dist/index.js +508 -120
- package/dist/moonbase-gorilla-engine.js +801 -0
- package/package.json +7 -4
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
import process2 from "process";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import fs2 from "fs/promises";
|
|
8
|
+
import path2 from "path";
|
|
9
|
+
import { parseArgs } from "util";
|
|
10
|
+
|
|
11
|
+
// src/doctor.ts
|
|
12
|
+
import fs from "fs/promises";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import process from "process";
|
|
15
|
+
var TESTED = {
|
|
16
|
+
"node": ">=18",
|
|
17
|
+
"react": "19",
|
|
18
|
+
"@gorilla-engine-sdk/gorilla-engine-react": "1.6",
|
|
19
|
+
"typescript": "5 || 6"
|
|
20
|
+
};
|
|
21
|
+
var moduleName = "@moonbase.sh/gorilla-engine";
|
|
22
|
+
var toolchain = [
|
|
23
|
+
{ name: "react", tested: TESTED.react },
|
|
24
|
+
{ name: "@gorilla-engine-sdk/gorilla-engine-react", tested: TESTED["@gorilla-engine-sdk/gorilla-engine-react"] },
|
|
25
|
+
{ name: "typescript", tested: TESTED.typescript },
|
|
26
|
+
{ name: moduleName }
|
|
27
|
+
];
|
|
28
|
+
var gates = [
|
|
29
|
+
{ key: "audioEnabledOnStartup", what: "audio" },
|
|
30
|
+
{ key: "midiEnabledOnStartup", what: "MIDI" }
|
|
31
|
+
];
|
|
32
|
+
var sourceFile = /\.(?:tsx?|jsx?|mjs|cjs)$/;
|
|
33
|
+
var declarationFile = /\.d\.ts$/;
|
|
34
|
+
var skippedFolders = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage"]);
|
|
35
|
+
var largestSource = 1024 * 1024;
|
|
36
|
+
var drawable = /\.(?:otf|ttf|png|jpe?g|gif|svg|webp)$/i;
|
|
37
|
+
var hasExtension = /\.[a-z0-9]+$/i;
|
|
38
|
+
var appVersionKey = /\bappVersion["']?\s*:\s*$/;
|
|
39
|
+
var moduleSpecifier = /(?:\bfrom|\bimport|\brequire\s*\(|\bimport\s*\()\s*$/;
|
|
40
|
+
var beforeRegExp = /* @__PURE__ */ new Set(["", "(", ",", "=", ":", "[", "!", "&", "|", "?", "{", ";", "+", "-", "*", "%", "~", "^"]);
|
|
41
|
+
var keywordBeforeRegExp = /(?:^|[^\w$])(?:return|typeof|case|do|else|in|of|void|yield|await|throw|new|delete)$/;
|
|
42
|
+
var diffContext = 2;
|
|
43
|
+
var noNewline = "\";
|
|
44
|
+
async function checkProject(projectFile, options = {}) {
|
|
45
|
+
const file = path.resolve(projectFile);
|
|
46
|
+
const root = path.dirname(file);
|
|
47
|
+
const project = await readProject(file, projectFile);
|
|
48
|
+
if (typeof project === "string")
|
|
49
|
+
return report(projectFile, [{ level: "error", check: "project", message: project }]);
|
|
50
|
+
const sources = await readSources(root, path.join(root, "src"));
|
|
51
|
+
return report(projectFile, [
|
|
52
|
+
...describeProject(project),
|
|
53
|
+
checkGates(project, options),
|
|
54
|
+
...checkVersions(project, sources, options),
|
|
55
|
+
...await checkAssets(project, sources, root),
|
|
56
|
+
await checkEntry(project, root),
|
|
57
|
+
...await checkToolchain(root)
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
function report(projectFile, findings) {
|
|
61
|
+
return {
|
|
62
|
+
projectFile,
|
|
63
|
+
findings,
|
|
64
|
+
errors: findings.filter((finding) => finding.level === "error").length,
|
|
65
|
+
warnings: findings.filter((finding) => finding.level === "warning").length
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function readProject(file, given) {
|
|
69
|
+
const name = path.basename(file);
|
|
70
|
+
let text2;
|
|
71
|
+
try {
|
|
72
|
+
text2 = await fs.readFile(file, "utf8");
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const code = error.code;
|
|
75
|
+
if (code === "ENOENT")
|
|
76
|
+
return `There is no project file at ${given}.`;
|
|
77
|
+
if (code === "EISDIR")
|
|
78
|
+
return `${given} is a folder. Name the project's .ugep file instead.`;
|
|
79
|
+
return `Could not read ${given}: ${error.message}`;
|
|
80
|
+
}
|
|
81
|
+
let json;
|
|
82
|
+
try {
|
|
83
|
+
json = JSON.parse(text2);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return `${name} does not parse as JSON (${error.message}). Gorilla Engine writes its project file as JSON, so this is not one, or an edit by hand broke it.`;
|
|
86
|
+
}
|
|
87
|
+
if (!isRecord(json))
|
|
88
|
+
return `${name} parses as JSON, but as ${describeValue(json)} rather than an object with a pluginConfig. Is it a Gorilla Engine project file?`;
|
|
89
|
+
if (!isRecord(json.pluginConfig)) {
|
|
90
|
+
const keys = Object.keys(json);
|
|
91
|
+
const found = json.pluginConfig !== void 0 ? `its pluginConfig is ${describeValue(json.pluginConfig)}` : keys.length === 0 ? "it is an empty object" : `it has no pluginConfig, only ${list(keys.slice(0, 6))}${keys.length > 6 ? ` and ${keys.length - 6} more` : ""}`;
|
|
92
|
+
return `${name} parses as JSON, but ${found}. A Gorilla Engine project file keeps the plugin's settings in a pluginConfig object.`;
|
|
93
|
+
}
|
|
94
|
+
return { name, text: text2, json, plugin: json.pluginConfig };
|
|
95
|
+
}
|
|
96
|
+
function describeProject(project) {
|
|
97
|
+
const name = text(project.plugin.name);
|
|
98
|
+
const manufacturer = text(project.plugin.manufacturer);
|
|
99
|
+
const format = text(project.json.version);
|
|
100
|
+
const findings = [{
|
|
101
|
+
level: "ok",
|
|
102
|
+
check: "project",
|
|
103
|
+
message: `${project.name} is ${name ?? "a plugin"}${manufacturer ? ` by ${manufacturer}` : ""}, a Gorilla Engine project${format ? ` (format ${format})` : ""}.`
|
|
104
|
+
}];
|
|
105
|
+
const missing = [name ? null : "name", manufacturer ? null : "manufacturer"].filter(isDefined);
|
|
106
|
+
if (missing.length > 0) {
|
|
107
|
+
findings.push({
|
|
108
|
+
level: "warning",
|
|
109
|
+
check: "project",
|
|
110
|
+
message: `pluginConfig has no ${missing.join(" or ")}. The module keeps the license in a folder named after the manufacturer and the plugin (on macOS, ~/Library/Application Support/<manufacturer>/<plugin>), and without them it falls back to "Moonbase" and "Plugin", which every plugin without them shares.`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return findings;
|
|
114
|
+
}
|
|
115
|
+
function checkGates(project, options) {
|
|
116
|
+
if (options.lockAudioAndMidi === false)
|
|
117
|
+
return { level: "ok", check: "gates", message: "Skipped: with lockAudioAndMidi: false the module leaves audio and MIDI to the plugin." };
|
|
118
|
+
const open = gates.filter((gate) => project.plugin[gate.key] !== false);
|
|
119
|
+
if (open.length === 0)
|
|
120
|
+
return { level: "ok", check: "gates", message: "audioEnabledOnStartup and midiEnabledOnStartup are false, so audio and MIDI stay off until the module finds a license or a trial and turns them on." };
|
|
121
|
+
const states = open.map((gate) => project.plugin[gate.key] === void 0 ? `${gate.key} is not set` : `${gate.key} is ${JSON.stringify(project.plugin[gate.key])}`);
|
|
122
|
+
const what = open.map((gate) => gate.what).join(" and ");
|
|
123
|
+
const edits = gateEdits(splitLines(project.text).lines, open.map((gate) => gate.key));
|
|
124
|
+
return {
|
|
125
|
+
level: "error",
|
|
126
|
+
check: "gates",
|
|
127
|
+
message: `In ${project.name}, ${states.join(" and ")}, so Gorilla Engine lets ${what} through from the moment the plugin loads, before the module's JavaScript has run. JavaScript cannot protect that moment, only the project file can: set ${open.length === 1 ? "it" : "both"} to false, and the module turns ${what} on once the plugin has a license or a trial. (A plugin that passes lockAudioAndMidi: false does not use the module's gate, and this check does not apply to it.)`,
|
|
128
|
+
...edits && { fix: unifiedDiff(project.name, project.text, edits) }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function gateEdits(lines, keys) {
|
|
132
|
+
const pluginConfig = lines.findIndex((line) => /"pluginConfig"\s*:/.test(line));
|
|
133
|
+
const changed = /* @__PURE__ */ new Map();
|
|
134
|
+
const missing = [];
|
|
135
|
+
for (const key of keys) {
|
|
136
|
+
const setting = new RegExp(`("${key}"\\s*:\\s*)(true|false|null|"(?:[^"\\\\]|\\\\.)*"|[-+.\\deE]+)`);
|
|
137
|
+
const index = lines.findIndex((line, at) => at >= pluginConfig && setting.test(line));
|
|
138
|
+
if (index === -1)
|
|
139
|
+
missing.push(key);
|
|
140
|
+
else
|
|
141
|
+
changed.set(index, (changed.get(index) ?? lines[index]).replace(setting, "$1false"));
|
|
142
|
+
}
|
|
143
|
+
const edits = [...changed].map(([line, text2]) => ({ line, remove: 1, insert: [text2] }));
|
|
144
|
+
if (missing.length > 0) {
|
|
145
|
+
if (pluginConfig === -1 || !/\{\s*$/.test(lines[pluginConfig]))
|
|
146
|
+
return void 0;
|
|
147
|
+
const indent2 = /^\s*/.exec(lines[pluginConfig + 1] ?? "")?.[0] ?? "";
|
|
148
|
+
edits.push({ line: pluginConfig + 1, remove: 0, insert: missing.map((key) => `${indent2}"${key}": false,`) });
|
|
149
|
+
}
|
|
150
|
+
return edits;
|
|
151
|
+
}
|
|
152
|
+
function checkVersions(project, sources, options) {
|
|
153
|
+
const findings = [];
|
|
154
|
+
const version = text(project.plugin.version);
|
|
155
|
+
const versionString = text(project.plugin.versionString);
|
|
156
|
+
if (version && versionString && !sameVersion(version, versionString)) {
|
|
157
|
+
const lines = splitLines(project.text).lines;
|
|
158
|
+
const edit = valueEdit(lines, "versionString", version);
|
|
159
|
+
findings.push({
|
|
160
|
+
level: "error",
|
|
161
|
+
check: "versions",
|
|
162
|
+
message: `In ${project.name}, pluginConfig.version is ${version} but versionString is ${versionString}. They name the same release, so set versionString to ${version}, or both to the version you are releasing.`,
|
|
163
|
+
...edit && { fix: unifiedDiff(project.name, project.text, [edit]) }
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const projectVersion = version ?? versionString;
|
|
167
|
+
if (!projectVersion) {
|
|
168
|
+
findings.push({ level: "warning", check: "versions", message: `pluginConfig in ${project.name} has neither a version nor a versionString, so there is nothing to compare the module's appVersion with.` });
|
|
169
|
+
return findings;
|
|
170
|
+
}
|
|
171
|
+
const consequence = "Moonbase compares appVersion with the product's releases, for the update prompt and for licenses that cover only some versions";
|
|
172
|
+
if (options.appVersion !== void 0) {
|
|
173
|
+
findings.push(sameVersion(options.appVersion, projectVersion) ? { level: "ok", check: "versions", message: `appVersion ${options.appVersion}, as given to the check, matches the project's version.` } : { level: "error", check: "versions", message: `appVersion ${options.appVersion}, as given to the check, is not the project's version ${projectVersion}. ${consequence}, so customers running ${projectVersion} would count as running ${options.appVersion}.` });
|
|
174
|
+
return findings;
|
|
175
|
+
}
|
|
176
|
+
const found = sources.flatMap((source) => source.literals.filter((literal) => appVersionKey.test(source.code.slice(Math.max(0, literal.start - 48), literal.start))).map((literal) => ({ source, literal })));
|
|
177
|
+
const values = [...new Set(found.map((location) => location.literal.value))];
|
|
178
|
+
if (values.length === 0) {
|
|
179
|
+
findings.push({
|
|
180
|
+
level: "warning",
|
|
181
|
+
check: "versions",
|
|
182
|
+
message: `Found no appVersion in src/ (an appVersion: followed by a string), so the check cannot compare it with the project's version ${projectVersion}. If the plugin reads it from somewhere else, give it to the check (--app-version).`
|
|
183
|
+
});
|
|
184
|
+
} else if (values.length > 1) {
|
|
185
|
+
findings.push({
|
|
186
|
+
level: "warning",
|
|
187
|
+
check: "versions",
|
|
188
|
+
message: `src/ sets appVersion to ${list(values.map((value) => `${value} (${where(found.filter((location) => location.literal.value === value))})`))}. The check cannot tell which one the module is given: give it to the check (--app-version).`
|
|
189
|
+
});
|
|
190
|
+
} else if (!sameVersion(values[0], projectVersion)) {
|
|
191
|
+
findings.push({
|
|
192
|
+
level: "error",
|
|
193
|
+
check: "versions",
|
|
194
|
+
message: `The module is given appVersion ${values[0]} (${where(found)}), but the project's version is ${projectVersion}. ${consequence}, so customers running ${projectVersion} would count as running ${values[0]}.`,
|
|
195
|
+
fix: diffSources(found.map((location) => ({ ...location, value: projectVersion })))
|
|
196
|
+
});
|
|
197
|
+
} else {
|
|
198
|
+
findings.push({ level: "ok", check: "versions", message: `appVersion ${values[0]} (${where(found)}) matches the project's version.` });
|
|
199
|
+
}
|
|
200
|
+
return findings;
|
|
201
|
+
}
|
|
202
|
+
function valueEdit(lines, key, value) {
|
|
203
|
+
const setting = new RegExp(`("${key}"\\s*:\\s*)"(?:[^"\\\\]|\\\\.)*"`);
|
|
204
|
+
const index = lines.findIndex((line) => setting.test(line));
|
|
205
|
+
return index === -1 ? void 0 : { line: index, remove: 1, insert: [lines[index].replace(setting, `$1${JSON.stringify(value)}`)] };
|
|
206
|
+
}
|
|
207
|
+
function diffSources(changes) {
|
|
208
|
+
const files = [...new Set(changes.map((change) => change.source))];
|
|
209
|
+
return files.map((source) => {
|
|
210
|
+
const lines = splitLines(source.text).lines;
|
|
211
|
+
const byLine = /* @__PURE__ */ new Map();
|
|
212
|
+
for (const change of changes.filter((change2) => change2.source === source))
|
|
213
|
+
byLine.set(change.literal.line - 1, [...byLine.get(change.literal.line - 1) ?? [], change]);
|
|
214
|
+
const edits = [...byLine].map(([index, onLine]) => {
|
|
215
|
+
const lineStart = source.lineStarts[index];
|
|
216
|
+
let line = lines[index];
|
|
217
|
+
for (const { literal, value } of onLine.sort((a, b) => b.literal.start - a.literal.start))
|
|
218
|
+
line = line.slice(0, literal.start - lineStart + 1) + value + line.slice(literal.end - lineStart - 1);
|
|
219
|
+
return { line: index, remove: 1, insert: [line] };
|
|
220
|
+
});
|
|
221
|
+
return unifiedDiff(source.file, source.text, edits);
|
|
222
|
+
}).join("\n");
|
|
223
|
+
}
|
|
224
|
+
async function checkAssets(project, sources, root) {
|
|
225
|
+
const findings = [];
|
|
226
|
+
const entries = Array.isArray(project.json.assetFiles) ? project.json.assetFiles : [];
|
|
227
|
+
const folders = /* @__PURE__ */ new Map();
|
|
228
|
+
for (const entry of entries) {
|
|
229
|
+
if (!isRecord(entry) || typeof entry.name !== "string" || typeof entry.path !== "string")
|
|
230
|
+
continue;
|
|
231
|
+
const relative = entry.path.replace(/\\/g, "/");
|
|
232
|
+
const absolute = path.resolve(root, relative);
|
|
233
|
+
if (await exists(absolute)) {
|
|
234
|
+
folders.set(entry.name, { path: relative, absolute });
|
|
235
|
+
} else {
|
|
236
|
+
folders.set(entry.name, null);
|
|
237
|
+
findings.push({ level: "error", check: "assets", message: `The asset folder "${entry.name}" in ${project.name} is ${relative}, which does not exist. Gorilla Engine looks for paths like ${entry.name}/... there.` });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const present = [...folders].flatMap(([name, folder]) => folder ? [`${name} (${folder.path})`] : []);
|
|
241
|
+
if (present.length > 0)
|
|
242
|
+
findings.push({ level: "ok", check: "assets", message: `The asset folders exist: ${list(present)}.` });
|
|
243
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
244
|
+
const missing = /* @__PURE__ */ new Map();
|
|
245
|
+
const unknown = /* @__PURE__ */ new Map();
|
|
246
|
+
for (const source of sources) {
|
|
247
|
+
for (const literal of source.literals) {
|
|
248
|
+
const value = literal.value;
|
|
249
|
+
const slash = value.indexOf("/");
|
|
250
|
+
if (slash <= 0 || value.includes("://") || /[\n\r]/.test(value) || /^[.@~$#]/.test(value))
|
|
251
|
+
continue;
|
|
252
|
+
if (moduleSpecifier.test(source.code.slice(Math.max(0, literal.start - 24), literal.start)))
|
|
253
|
+
continue;
|
|
254
|
+
const head = value.slice(0, slash);
|
|
255
|
+
const rest = value.slice(slash + 1);
|
|
256
|
+
if (folders.has(head)) {
|
|
257
|
+
const folder = folders.get(head);
|
|
258
|
+
if (!folder || !rest || !hasExtension.test(rest) || resolved.has(value))
|
|
259
|
+
continue;
|
|
260
|
+
const known = missing.get(value);
|
|
261
|
+
if (known) {
|
|
262
|
+
known.locations.push({ source, literal });
|
|
263
|
+
} else if (await isFile(path.join(folder.absolute, rest))) {
|
|
264
|
+
resolved.add(value);
|
|
265
|
+
} else {
|
|
266
|
+
missing.set(value, { expected: `${folder.path.replace(/\/$/, "")}/${rest}`, locations: [{ source, literal }] });
|
|
267
|
+
}
|
|
268
|
+
} else if (drawable.test(value) && /^[\w-]+$/.test(head)) {
|
|
269
|
+
const known = unknown.get(head) ?? { values: /* @__PURE__ */ new Set(), locations: [] };
|
|
270
|
+
known.values.add(value);
|
|
271
|
+
known.locations.push({ source, literal });
|
|
272
|
+
unknown.set(head, known);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
for (const [value, { expected, locations }] of missing) {
|
|
277
|
+
findings.push({ level: "error", check: "assets", message: `${where(locations)} ${locations.length === 1 ? "refers" : "refer"} to ${value}, which Gorilla Engine looks for at ${expected}, and there is no such file.` });
|
|
278
|
+
}
|
|
279
|
+
for (const [head, { values, locations }] of unknown) {
|
|
280
|
+
const names = [...folders.keys()];
|
|
281
|
+
findings.push({
|
|
282
|
+
level: "warning",
|
|
283
|
+
check: "assets",
|
|
284
|
+
message: `${where(locations)} ${locations.length === 1 ? "refers" : "refer"} to ${list([...values])}, but ${project.name} has no asset folder named "${head}"${names.length > 0 ? ` (it has ${list(names.map((name) => `"${name}"`))})` : ""}, so Gorilla Engine will not find ${values.size === 1 ? "it" : "them"}. Add the folder to assetFiles, or use one the project has.`
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
if (resolved.size > 0) {
|
|
288
|
+
const shown = [...resolved].slice(0, 4);
|
|
289
|
+
findings.push({ level: "ok", check: "assets", message: `${resolved.size} asset ${resolved.size === 1 ? "path" : "paths"} in src/ ${resolved.size === 1 ? "resolves" : "resolve"}: ${shown.join(", ")}${resolved.size > shown.length ? ` and ${resolved.size - shown.length} more` : ""}.` });
|
|
290
|
+
}
|
|
291
|
+
if (findings.length === 0)
|
|
292
|
+
findings.push({ level: "ok", check: "assets", message: `${project.name} has no asset folders, and src/ refers to none.` });
|
|
293
|
+
return findings;
|
|
294
|
+
}
|
|
295
|
+
async function checkEntry(project, root) {
|
|
296
|
+
const files = Array.isArray(project.json.scriptFiles) ? project.json.scriptFiles : [];
|
|
297
|
+
const entry = scriptPath(project.json.scriptEntryPoint) ?? files.filter((file) => isRecord(file) && (file.entryPoint === "yes" || file.entryPoint === true)).map(scriptPath).find(isDefined);
|
|
298
|
+
if (!entry)
|
|
299
|
+
return { level: "warning", check: "entry", message: `${project.name} sets no script entry point (scriptEntryPoint), so Gorilla Engine has no script to run and the module never starts. Set the built bundle as the entry point.` };
|
|
300
|
+
const built = await isFile(path.resolve(root, entry.replace(/\\/g, "/")));
|
|
301
|
+
return { level: "ok", check: "entry", message: `The script entry point is ${entry}${built ? "" : ", which the build writes (not built yet)"}.` };
|
|
302
|
+
}
|
|
303
|
+
function scriptPath(value) {
|
|
304
|
+
return isRecord(value) ? text(value.path) : void 0;
|
|
305
|
+
}
|
|
306
|
+
async function checkToolchain(root) {
|
|
307
|
+
const findings = [tested("Node.js", process.versions.node, TESTED.node)];
|
|
308
|
+
const manifest = await readJson(path.join(root, "package.json"));
|
|
309
|
+
for (const { name, tested: range } of toolchain) {
|
|
310
|
+
const installed = await installedVersion(root, name);
|
|
311
|
+
if (installed) {
|
|
312
|
+
findings.push(range ? tested(name, installed, range) : { level: "ok", check: "toolchain", message: `${name} ${installed}` });
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const wanted = declaredRange(manifest, name);
|
|
316
|
+
if (wanted) {
|
|
317
|
+
const untested = range && satisfies(wanted, range) === false ? ` It also asks for a version that is not tested (tested: ${describeRange(range)}).` : "";
|
|
318
|
+
findings.push({ level: "warning", check: "toolchain", message: `${name} is in package.json (${wanted}) but not installed in node_modules: run your package manager's install.${untested}` });
|
|
319
|
+
} else if (range) {
|
|
320
|
+
findings.push({ level: "warning", check: "toolchain", message: `${name} is not installed, and not in package.json (tested: ${describeRange(range)}).` });
|
|
321
|
+
} else {
|
|
322
|
+
findings.push({ level: "error", check: "toolchain", message: `${name} is not installed, and not in package.json. Add it with npm install ${name}.` });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return findings;
|
|
326
|
+
}
|
|
327
|
+
function tested(name, version, range) {
|
|
328
|
+
const result = satisfies(version, range);
|
|
329
|
+
if (result)
|
|
330
|
+
return { level: "ok", check: "toolchain", message: `${name} ${version}` };
|
|
331
|
+
if (result === void 0)
|
|
332
|
+
return { level: "warning", check: "toolchain", message: `Could not tell which version of ${name} "${version}" is (tested: ${describeRange(range)}).` };
|
|
333
|
+
return { level: "warning", check: "toolchain", message: `${name} ${version} is not tested with ${moduleName} (tested: ${describeRange(range)}). It may well work, but if something misbehaves, try a tested version first.` };
|
|
334
|
+
}
|
|
335
|
+
async function installedVersion(root, name) {
|
|
336
|
+
let folder = root;
|
|
337
|
+
while (true) {
|
|
338
|
+
const manifest = await readJson(path.join(folder, "node_modules", ...name.split("/"), "package.json"));
|
|
339
|
+
if (typeof manifest?.version === "string")
|
|
340
|
+
return manifest.version;
|
|
341
|
+
const parent = path.dirname(folder);
|
|
342
|
+
if (parent === folder)
|
|
343
|
+
return void 0;
|
|
344
|
+
folder = parent;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function declaredRange(manifest, name) {
|
|
348
|
+
for (const kind of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
349
|
+
const dependencies = manifest?.[kind];
|
|
350
|
+
if (isRecord(dependencies) && typeof dependencies[name] === "string")
|
|
351
|
+
return dependencies[name];
|
|
352
|
+
}
|
|
353
|
+
return void 0;
|
|
354
|
+
}
|
|
355
|
+
function satisfies(version, range) {
|
|
356
|
+
const have = versionNumbers(version);
|
|
357
|
+
if (have.length === 0)
|
|
358
|
+
return void 0;
|
|
359
|
+
return range.split("||").some((alternative) => {
|
|
360
|
+
const wanted = alternative.trim();
|
|
361
|
+
if (wanted.startsWith(">="))
|
|
362
|
+
return compareVersions(have, versionNumbers(wanted.slice(2))) >= 0;
|
|
363
|
+
return versionNumbers(wanted).every((part, index) => have[index] === part);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function versionNumbers(version) {
|
|
367
|
+
const match = /\d+(?:\.\d+)*/.exec(version);
|
|
368
|
+
return match ? match[0].split(".").map(Number) : [];
|
|
369
|
+
}
|
|
370
|
+
function compareVersions(a, b) {
|
|
371
|
+
for (let index = 0; index < Math.max(a.length, b.length); index++) {
|
|
372
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
373
|
+
if (difference !== 0)
|
|
374
|
+
return difference;
|
|
375
|
+
}
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
function describeRange(range) {
|
|
379
|
+
return range.split("||").map((alternative) => alternative.trim()).map((alternative) => alternative.startsWith(">=") ? `${alternative.slice(2)} and later` : alternative).join(" or ");
|
|
380
|
+
}
|
|
381
|
+
function sameVersion(a, b) {
|
|
382
|
+
return a.trim().replace(/^v/i, "") === b.trim().replace(/^v/i, "");
|
|
383
|
+
}
|
|
384
|
+
async function readSources(root, folder, sources = []) {
|
|
385
|
+
let entries;
|
|
386
|
+
try {
|
|
387
|
+
entries = await fs.readdir(folder, { withFileTypes: true });
|
|
388
|
+
} catch {
|
|
389
|
+
return sources;
|
|
390
|
+
}
|
|
391
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
392
|
+
for (const entry of entries) {
|
|
393
|
+
const full = path.join(folder, entry.name);
|
|
394
|
+
if (entry.isDirectory()) {
|
|
395
|
+
if (!entry.name.startsWith(".") && !skippedFolders.has(entry.name))
|
|
396
|
+
await readSources(root, full, sources);
|
|
397
|
+
} else if (entry.isFile() && sourceFile.test(entry.name) && !declarationFile.test(entry.name)) {
|
|
398
|
+
const text2 = await fs.readFile(full, "utf8").catch(() => void 0);
|
|
399
|
+
if (text2 !== void 0 && text2.length <= largestSource)
|
|
400
|
+
sources.push({ file: path.relative(root, full).split(path.sep).join("/"), text: text2, ...scanSource(text2) });
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return sources;
|
|
404
|
+
}
|
|
405
|
+
function scanSource(text2) {
|
|
406
|
+
const lineStarts = [0];
|
|
407
|
+
for (let index2 = text2.indexOf("\n"); index2 !== -1; index2 = text2.indexOf("\n", index2 + 1))
|
|
408
|
+
lineStarts.push(index2 + 1);
|
|
409
|
+
const lineOf = (offset) => {
|
|
410
|
+
let low = 0;
|
|
411
|
+
let high = lineStarts.length - 1;
|
|
412
|
+
while (low < high) {
|
|
413
|
+
const middle = Math.ceil((low + high) / 2);
|
|
414
|
+
if (lineStarts[middle] <= offset)
|
|
415
|
+
low = middle;
|
|
416
|
+
else
|
|
417
|
+
high = middle - 1;
|
|
418
|
+
}
|
|
419
|
+
return low + 1;
|
|
420
|
+
};
|
|
421
|
+
const literals = [];
|
|
422
|
+
const code = [];
|
|
423
|
+
let copied = 0;
|
|
424
|
+
let previous = "";
|
|
425
|
+
let previousAt = -1;
|
|
426
|
+
let index = 0;
|
|
427
|
+
const blank = (end) => {
|
|
428
|
+
code.push(text2.slice(copied, index), text2.slice(index, end).replace(/[^\n]/g, " "));
|
|
429
|
+
copied = end;
|
|
430
|
+
index = end;
|
|
431
|
+
};
|
|
432
|
+
while (index < text2.length) {
|
|
433
|
+
const char = text2[index];
|
|
434
|
+
const next = text2[index + 1];
|
|
435
|
+
if (char === "/" && next === "/") {
|
|
436
|
+
const end = text2.indexOf("\n", index);
|
|
437
|
+
blank(end === -1 ? text2.length : end);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (char === "/" && next === "*") {
|
|
441
|
+
const end = text2.indexOf("*/", index + 2);
|
|
442
|
+
blank(end === -1 ? text2.length : end + 2);
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (char === "'" || char === '"') {
|
|
446
|
+
let cursor = index + 1;
|
|
447
|
+
let value = "";
|
|
448
|
+
while (cursor < text2.length && text2[cursor] !== char && text2[cursor] !== "\n") {
|
|
449
|
+
if (text2[cursor] === "\\") {
|
|
450
|
+
value += text2[cursor + 1] ?? "";
|
|
451
|
+
cursor += 2;
|
|
452
|
+
} else {
|
|
453
|
+
value += text2[cursor];
|
|
454
|
+
cursor++;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (text2[cursor] === char) {
|
|
458
|
+
literals.push({ value, start: index, end: cursor + 1, line: lineOf(index) });
|
|
459
|
+
previous = char;
|
|
460
|
+
previousAt = cursor;
|
|
461
|
+
index = cursor + 1;
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
index++;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (char === "`") {
|
|
468
|
+
let cursor = index + 1;
|
|
469
|
+
let value = "";
|
|
470
|
+
let interpolated = false;
|
|
471
|
+
let depth = 0;
|
|
472
|
+
while (cursor < text2.length) {
|
|
473
|
+
const current = text2[cursor];
|
|
474
|
+
if (current === "\\") {
|
|
475
|
+
value += text2[cursor + 1] ?? "";
|
|
476
|
+
cursor += 2;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (depth === 0 && current === "`")
|
|
480
|
+
break;
|
|
481
|
+
if (depth === 0 && current === "$" && text2[cursor + 1] === "{") {
|
|
482
|
+
interpolated = true;
|
|
483
|
+
depth = 1;
|
|
484
|
+
cursor += 2;
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
if (depth === 0)
|
|
488
|
+
value += current;
|
|
489
|
+
else if (current === "{")
|
|
490
|
+
depth++;
|
|
491
|
+
else if (current === "}")
|
|
492
|
+
depth--;
|
|
493
|
+
cursor++;
|
|
494
|
+
}
|
|
495
|
+
if (!interpolated && cursor < text2.length)
|
|
496
|
+
literals.push({ value, start: index, end: cursor + 1, line: lineOf(index) });
|
|
497
|
+
previous = char;
|
|
498
|
+
previousAt = cursor;
|
|
499
|
+
index = cursor + 1;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (char === "/" && (beforeRegExp.has(previous) || keywordBeforeRegExp.test(text2.slice(Math.max(0, previousAt - 9), previousAt + 1)))) {
|
|
503
|
+
let cursor = index + 1;
|
|
504
|
+
let inClass = false;
|
|
505
|
+
while (cursor < text2.length && text2[cursor] !== "\n" && (inClass || text2[cursor] !== "/")) {
|
|
506
|
+
if (text2[cursor] === "\\")
|
|
507
|
+
cursor++;
|
|
508
|
+
else if (text2[cursor] === "[")
|
|
509
|
+
inClass = true;
|
|
510
|
+
else if (text2[cursor] === "]")
|
|
511
|
+
inClass = false;
|
|
512
|
+
cursor++;
|
|
513
|
+
}
|
|
514
|
+
if (text2[cursor] === "/") {
|
|
515
|
+
previous = "/";
|
|
516
|
+
previousAt = cursor;
|
|
517
|
+
index = cursor + 1;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (!/\s/.test(char)) {
|
|
522
|
+
previous = char;
|
|
523
|
+
previousAt = index;
|
|
524
|
+
}
|
|
525
|
+
index++;
|
|
526
|
+
}
|
|
527
|
+
code.push(text2.slice(copied));
|
|
528
|
+
return { code: code.join(""), literals, lineStarts };
|
|
529
|
+
}
|
|
530
|
+
function splitLines(text2) {
|
|
531
|
+
const lines = text2.split(/\r?\n/);
|
|
532
|
+
const endsWithNewline = lines.length > 1 && lines[lines.length - 1] === "";
|
|
533
|
+
if (endsWithNewline)
|
|
534
|
+
lines.pop();
|
|
535
|
+
return { lines, endsWithNewline };
|
|
536
|
+
}
|
|
537
|
+
function unifiedDiff(file, text2, edits) {
|
|
538
|
+
const { lines, endsWithNewline } = splitLines(text2);
|
|
539
|
+
const sorted = [...edits].sort((a, b) => a.line - b.line || a.remove - b.remove);
|
|
540
|
+
const out = [`--- a/${file}`, `+++ b/${file}`];
|
|
541
|
+
let offset = 0;
|
|
542
|
+
let first = 0;
|
|
543
|
+
while (first < sorted.length) {
|
|
544
|
+
let last = first;
|
|
545
|
+
while (last + 1 < sorted.length && sorted[last + 1].line - (sorted[last].line + sorted[last].remove) <= 2 * diffContext)
|
|
546
|
+
last++;
|
|
547
|
+
const start = Math.max(0, sorted[first].line - diffContext);
|
|
548
|
+
const end = Math.min(lines.length, sorted[last].line + sorted[last].remove + diffContext);
|
|
549
|
+
const body = [];
|
|
550
|
+
let cursor = start;
|
|
551
|
+
let removed = 0;
|
|
552
|
+
let added = 0;
|
|
553
|
+
for (const edit of sorted.slice(first, last + 1)) {
|
|
554
|
+
for (; cursor < edit.line; cursor++)
|
|
555
|
+
body.push(` ${lines[cursor]}`);
|
|
556
|
+
for (let count2 = 0; count2 < edit.remove; count2++) {
|
|
557
|
+
body.push(`-${lines[cursor++]}`);
|
|
558
|
+
if (cursor === lines.length && !endsWithNewline)
|
|
559
|
+
body.push(noNewline);
|
|
560
|
+
}
|
|
561
|
+
body.push(...edit.insert.map((line) => `+${line}`));
|
|
562
|
+
if (edit.remove > 0 && edit.insert.length > 0 && cursor === lines.length && !endsWithNewline)
|
|
563
|
+
body.push(noNewline);
|
|
564
|
+
removed += edit.remove;
|
|
565
|
+
added += edit.insert.length;
|
|
566
|
+
}
|
|
567
|
+
const trailing = cursor < end;
|
|
568
|
+
for (; cursor < end; cursor++)
|
|
569
|
+
body.push(` ${lines[cursor]}`);
|
|
570
|
+
if (trailing && end === lines.length && !endsWithNewline)
|
|
571
|
+
body.push(noNewline);
|
|
572
|
+
const length = end - start;
|
|
573
|
+
out.push(`@@ -${start + 1},${length} +${start + 1 + offset},${length - removed + added} @@`, ...body);
|
|
574
|
+
offset += added - removed;
|
|
575
|
+
first = last + 1;
|
|
576
|
+
}
|
|
577
|
+
return out.join("\n");
|
|
578
|
+
}
|
|
579
|
+
function where(locations) {
|
|
580
|
+
const named = [...new Set(locations.map(({ source, literal }) => `${source.file}:${literal.line}`))];
|
|
581
|
+
return named.length <= 2 ? named.join(" and ") : `${named.slice(0, 2).join(", ")} and ${named.length - 2} more`;
|
|
582
|
+
}
|
|
583
|
+
function list(items) {
|
|
584
|
+
return items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
585
|
+
}
|
|
586
|
+
async function exists(file) {
|
|
587
|
+
return fs.stat(file).then(() => true, () => false);
|
|
588
|
+
}
|
|
589
|
+
async function isFile(file) {
|
|
590
|
+
return fs.stat(file).then((stat) => stat.isFile(), () => false);
|
|
591
|
+
}
|
|
592
|
+
async function readJson(file) {
|
|
593
|
+
try {
|
|
594
|
+
const json = JSON.parse(await fs.readFile(file, "utf8"));
|
|
595
|
+
return isRecord(json) ? json : void 0;
|
|
596
|
+
} catch {
|
|
597
|
+
return void 0;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function text(value) {
|
|
601
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
602
|
+
}
|
|
603
|
+
function describeValue(value) {
|
|
604
|
+
if (value === null)
|
|
605
|
+
return "null";
|
|
606
|
+
if (Array.isArray(value))
|
|
607
|
+
return "an array";
|
|
608
|
+
return typeof value === "object" ? "an object" : `a ${typeof value}`;
|
|
609
|
+
}
|
|
610
|
+
function isRecord(value) {
|
|
611
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
612
|
+
}
|
|
613
|
+
function isDefined(value) {
|
|
614
|
+
return value !== null && value !== void 0;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/cli.ts
|
|
618
|
+
var UsageError = class extends Error {
|
|
619
|
+
constructor(message, showUsage = true) {
|
|
620
|
+
super(message);
|
|
621
|
+
this.showUsage = showUsage;
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
var usage = `Usage: moonbase-gorilla-engine doctor [project.ugep] [options]
|
|
625
|
+
|
|
626
|
+
Checks a Gorilla Engine project's setup for @moonbase.sh/gorilla-engine: the startup gates on
|
|
627
|
+
audio and MIDI, the versions, the assets the code refers to, the script entry point and the
|
|
628
|
+
toolchain. It only reads files. It changes nothing, and shows each fix as a diff for you to
|
|
629
|
+
review and apply yourself.
|
|
630
|
+
|
|
631
|
+
Without a project file, it checks the one .ugep file in the current folder.
|
|
632
|
+
|
|
633
|
+
Options:
|
|
634
|
+
--app-version <x.y.z> The appVersion the plugin gives the module, when the check cannot
|
|
635
|
+
find it in src/
|
|
636
|
+
--no-gate The plugin passes lockAudioAndMidi: false, so skip the check of the
|
|
637
|
+
startup gates
|
|
638
|
+
--json Print the report as JSON
|
|
639
|
+
-h, --help Show this help`;
|
|
640
|
+
var titles = {
|
|
641
|
+
project: "Project file",
|
|
642
|
+
gates: "Startup gates",
|
|
643
|
+
versions: "Versions",
|
|
644
|
+
assets: "Assets",
|
|
645
|
+
entry: "Script entry point",
|
|
646
|
+
toolchain: "Toolchain"
|
|
647
|
+
};
|
|
648
|
+
var severity = ["error", "warning", "ok"];
|
|
649
|
+
var width = 100;
|
|
650
|
+
var indent = 10;
|
|
651
|
+
async function main(argv, io) {
|
|
652
|
+
const [command, ...args] = argv;
|
|
653
|
+
try {
|
|
654
|
+
switch (command) {
|
|
655
|
+
case "doctor":
|
|
656
|
+
return await doctor(args, io);
|
|
657
|
+
case "help":
|
|
658
|
+
case "--help":
|
|
659
|
+
case "-h":
|
|
660
|
+
print(io.out, usage);
|
|
661
|
+
return 0;
|
|
662
|
+
case void 0:
|
|
663
|
+
print(io.err, usage);
|
|
664
|
+
return 2;
|
|
665
|
+
default:
|
|
666
|
+
throw new UsageError(`There is no command "${command}".`);
|
|
667
|
+
}
|
|
668
|
+
} catch (error) {
|
|
669
|
+
if (error instanceof UsageError) {
|
|
670
|
+
io.err(error.message);
|
|
671
|
+
if (error.showUsage) {
|
|
672
|
+
io.err("");
|
|
673
|
+
print(io.err, usage);
|
|
674
|
+
} else {
|
|
675
|
+
io.err('Run "moonbase-gorilla-engine help" for how to use it.');
|
|
676
|
+
}
|
|
677
|
+
return 2;
|
|
678
|
+
}
|
|
679
|
+
io.err(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
680
|
+
return 1;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
async function doctor(args, io) {
|
|
684
|
+
const { values, positionals } = readArguments(args);
|
|
685
|
+
if (values.help) {
|
|
686
|
+
print(io.out, usage);
|
|
687
|
+
return 0;
|
|
688
|
+
}
|
|
689
|
+
if (positionals.length > 1)
|
|
690
|
+
throw new UsageError(`doctor checks one project file, and was given ${positionals.length}.`);
|
|
691
|
+
const appVersion = values["app-version"];
|
|
692
|
+
if (appVersion !== void 0 && !appVersion.trim())
|
|
693
|
+
throw new UsageError("--app-version takes a version, like 1.2.0.");
|
|
694
|
+
const projectFile = await findProject(positionals[0], io.cwd);
|
|
695
|
+
const report2 = await checkProject(projectFile, {
|
|
696
|
+
...appVersion !== void 0 && { appVersion: appVersion.trim() },
|
|
697
|
+
...values["no-gate"] && { lockAudioAndMidi: false }
|
|
698
|
+
});
|
|
699
|
+
if (values.json)
|
|
700
|
+
print(io.out, JSON.stringify(report2, null, 2));
|
|
701
|
+
else
|
|
702
|
+
printReport(report2, io);
|
|
703
|
+
return report2.errors > 0 ? 1 : 0;
|
|
704
|
+
}
|
|
705
|
+
function readArguments(args) {
|
|
706
|
+
try {
|
|
707
|
+
return parseArgs({
|
|
708
|
+
args,
|
|
709
|
+
allowPositionals: true,
|
|
710
|
+
strict: true,
|
|
711
|
+
options: {
|
|
712
|
+
"app-version": { type: "string" },
|
|
713
|
+
"no-gate": { type: "boolean", default: false },
|
|
714
|
+
"json": { type: "boolean", default: false },
|
|
715
|
+
"help": { type: "boolean", short: "h", default: false }
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
} catch (error) {
|
|
719
|
+
const unknown = /Unknown option '([^']+)'/.exec(error.message);
|
|
720
|
+
throw new UsageError(unknown ? `There is no option "${unknown[1]}".` : error.message);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
async function findProject(given, cwd) {
|
|
724
|
+
const target = given === void 0 ? cwd : path2.resolve(cwd, given);
|
|
725
|
+
if (given !== void 0) {
|
|
726
|
+
const stat = await fs2.stat(target).catch(() => void 0);
|
|
727
|
+
if (!stat?.isDirectory())
|
|
728
|
+
return target;
|
|
729
|
+
}
|
|
730
|
+
const entries = await fs2.readdir(target, { withFileTypes: true });
|
|
731
|
+
const projects = entries.filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith(".ugep")).map((entry) => entry.name).sort();
|
|
732
|
+
const folder = given === void 0 ? `the current folder (${target})` : target;
|
|
733
|
+
if (projects.length === 0)
|
|
734
|
+
throw new UsageError(`There is no .ugep project file in ${folder}. Run this in your Gorilla Engine project's folder, or name its project file.`, false);
|
|
735
|
+
if (projects.length > 1)
|
|
736
|
+
throw new UsageError(`There are ${projects.length} .ugep project files in ${folder}: ${projects.join(", ")}. Name the one to check.`, false);
|
|
737
|
+
return path2.join(target, projects[0]);
|
|
738
|
+
}
|
|
739
|
+
function printReport(report2, io) {
|
|
740
|
+
io.out(`Checking ${shortPath(report2.projectFile, io.cwd)}`);
|
|
741
|
+
const checks = [...new Set(report2.findings.map((finding) => finding.check))];
|
|
742
|
+
for (const check of checks) {
|
|
743
|
+
io.out("");
|
|
744
|
+
io.out(titles[check] ?? check);
|
|
745
|
+
const findings = report2.findings.filter((finding) => finding.check === check).sort((a, b) => severity.indexOf(a.level) - severity.indexOf(b.level));
|
|
746
|
+
for (const finding of findings) {
|
|
747
|
+
const [first, ...rest] = wrap(finding.message, width - indent);
|
|
748
|
+
io.out(` ${finding.level.padEnd(indent - 2)}${first}`);
|
|
749
|
+
for (const line of rest)
|
|
750
|
+
io.out(`${" ".repeat(indent)}${line}`);
|
|
751
|
+
if (finding.fix) {
|
|
752
|
+
io.out(`${" ".repeat(indent)}Suggested fix, to review and apply yourself:`);
|
|
753
|
+
for (const line of finding.fix.split("\n"))
|
|
754
|
+
io.out(`${" ".repeat(indent + 2)}${line}`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
io.out("");
|
|
759
|
+
io.out(summary(report2));
|
|
760
|
+
}
|
|
761
|
+
function summary(report2) {
|
|
762
|
+
const { errors, warnings } = report2;
|
|
763
|
+
if (errors > 0)
|
|
764
|
+
return `${count(errors, "error")}${warnings > 0 ? ` and ${count(warnings, "warning")}` : ""}. Nothing was changed: fix ${errors === 1 ? "it" : "them"}, then run the check again.`;
|
|
765
|
+
if (warnings > 0)
|
|
766
|
+
return `No errors, ${count(warnings, "warning")}. Licensing should work, but ${warnings === 1 ? "it is" : "they are"} worth a look.`;
|
|
767
|
+
return "No problems found.";
|
|
768
|
+
}
|
|
769
|
+
function count(n, noun) {
|
|
770
|
+
return `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
771
|
+
}
|
|
772
|
+
function shortPath(file, cwd) {
|
|
773
|
+
const absolute = path2.resolve(cwd, file);
|
|
774
|
+
const relative = path2.relative(cwd, absolute);
|
|
775
|
+
return relative && !relative.startsWith("..") && !path2.isAbsolute(relative) ? relative : absolute;
|
|
776
|
+
}
|
|
777
|
+
function wrap(text2, columns) {
|
|
778
|
+
const lines = [];
|
|
779
|
+
let line = "";
|
|
780
|
+
for (const word of text2.split(" ")) {
|
|
781
|
+
if (line && line.length + 1 + word.length > columns) {
|
|
782
|
+
lines.push(line);
|
|
783
|
+
line = word;
|
|
784
|
+
} else {
|
|
785
|
+
line = line ? `${line} ${word}` : word;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
lines.push(line);
|
|
789
|
+
return lines;
|
|
790
|
+
}
|
|
791
|
+
function print(write, text2) {
|
|
792
|
+
for (const line of text2.split("\n"))
|
|
793
|
+
write(line);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/bin.ts
|
|
797
|
+
main(process2.argv.slice(2), { out: (line) => process2.stdout.write(`${line}
|
|
798
|
+
`), err: (line) => process2.stderr.write(`${line}
|
|
799
|
+
`), cwd: process2.cwd() }).then((exitCode) => {
|
|
800
|
+
process2.exitCode = exitCode;
|
|
801
|
+
});
|