@stacksjs/buddy 0.70.72 → 0.70.73
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/dist/commands/lint.js +11 -27
- package/package.json +1 -1
package/dist/commands/lint.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
1
|
import process from "node:process";
|
|
3
|
-
import { intro, log, onUnknownSubcommand, outro
|
|
4
|
-
import { path } from "@stacksjs/path";
|
|
2
|
+
import { intro, log, onUnknownSubcommand, outro } from "@stacksjs/cli";
|
|
5
3
|
import { ExitCode } from "@stacksjs/types";
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
return `bun storage/framework/core/actions/src/lint/${entry}.ts`;
|
|
10
|
-
try {
|
|
11
|
-
const pkgJson = Bun.resolveSync("@stacksjs/actions/package.json", path.projectPath()), dist = path.resolve(path.dirname(pkgJson), `dist/lint/${entry}.js`);
|
|
12
|
-
if (existsSync(dist))
|
|
13
|
-
return `bun ${dist}`;
|
|
14
|
-
} catch {}
|
|
15
|
-
return `bun storage/framework/core/actions/src/lint/${entry}.ts`;
|
|
16
|
-
}
|
|
17
|
-
function exitOnFailure(result, label) {
|
|
18
|
-
if (!result || typeof result !== "object" || !("isErr" in result))
|
|
19
|
-
return;
|
|
20
|
-
const marker = result.isErr;
|
|
21
|
-
if (typeof marker === "function" ? marker() : marker === !0) {
|
|
4
|
+
async function runStyleAction(entry, label, options) {
|
|
5
|
+
const actions = await import("@stacksjs/actions"), { ok } = await actions[entry](options);
|
|
6
|
+
if (!ok) {
|
|
22
7
|
log.error(`${label} reported failure`);
|
|
23
8
|
process.exit(ExitCode.FatalError);
|
|
24
9
|
}
|
|
@@ -34,28 +19,27 @@ export function lint(buddy) {
|
|
|
34
19
|
};
|
|
35
20
|
buddy.command("lint", descriptions.lint).option("-f, --fix", descriptions.lintFix, { default: !1 }).option("-p, --project [project]", descriptions.project, { default: !1 }).option("--verbose", descriptions.verbose, { default: !1 }).action(async (options) => {
|
|
36
21
|
log.debug("Running `buddy lint` ...", options);
|
|
37
|
-
const startTime = await intro("buddy lint")
|
|
38
|
-
|
|
22
|
+
const startTime = await intro("buddy lint");
|
|
23
|
+
await runStyleAction(options.fix ? "lintFix" : "lintProject", "lint");
|
|
39
24
|
await outro("Linted your project", { startTime, useSeconds: !0 });
|
|
40
25
|
});
|
|
41
26
|
buddy.command("lint:fix", descriptions.lintFix).option("-p, --project [project]", descriptions.project, { default: !1 }).option("--verbose", descriptions.verbose, { default: !1 }).action(async (options) => {
|
|
42
27
|
log.debug("Running `buddy lint:fix` ...", options);
|
|
43
28
|
const startTime = await intro("buddy lint:fix");
|
|
44
29
|
log.info("Fixing lint errors...");
|
|
45
|
-
|
|
46
|
-
exitOnFailure(result, "lint:fix");
|
|
30
|
+
await runStyleAction("lintFix", "lint:fix");
|
|
47
31
|
await outro("Fixed lint errors", { startTime, useSeconds: !0 });
|
|
48
32
|
});
|
|
49
33
|
buddy.command("format", descriptions.format).option("-w, --write", "Write changes to files", { default: !1 }).option("-c, --check", descriptions.formatCheck, { default: !1 }).option("--verbose", descriptions.verbose, { default: !1 }).action(async (options) => {
|
|
50
34
|
log.debug("Running `buddy format` ...", options);
|
|
51
|
-
const startTime = await intro("buddy format")
|
|
52
|
-
|
|
35
|
+
const startTime = await intro("buddy format");
|
|
36
|
+
await runStyleAction("formatProject", "format", options.check ? { check: !0 } : { write: !0 });
|
|
53
37
|
await outro("Formatted your project", { startTime, useSeconds: !0 });
|
|
54
38
|
});
|
|
55
39
|
buddy.command("format:check", descriptions.formatCheck).option("--verbose", descriptions.verbose, { default: !1 }).action(async (options) => {
|
|
56
40
|
log.debug("Running `buddy format:check` ...", options);
|
|
57
|
-
const startTime = await intro("buddy format:check")
|
|
58
|
-
|
|
41
|
+
const startTime = await intro("buddy format:check");
|
|
42
|
+
await runStyleAction("formatProject", "format:check", { check: !0 });
|
|
59
43
|
await outro("Format check complete", { startTime, useSeconds: !0 });
|
|
60
44
|
});
|
|
61
45
|
onUnknownSubcommand(buddy, "lint");
|