@fenglimg/fabric-cli 1.0.0 → 1.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.
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ t
4
+ } from "./chunk-6ICJICVU.js";
5
+
6
+ // src/commands/hooks.ts
7
+ import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
8
+ import { dirname, isAbsolute, join, parse, resolve } from "path";
9
+ import { fileURLToPath } from "url";
10
+ import { defineCommand } from "citty";
11
+ var hooksCommand = defineCommand({
12
+ meta: {
13
+ name: "hooks",
14
+ description: t("cli.hooks.description")
15
+ },
16
+ subCommands: {
17
+ install: defineCommand({
18
+ meta: {
19
+ name: "install",
20
+ description: t("cli.hooks.install.description")
21
+ },
22
+ args: {
23
+ target: {
24
+ type: "string",
25
+ description: t("cli.hooks.install.args.target.description"),
26
+ default: process.cwd()
27
+ }
28
+ },
29
+ async run({ args }) {
30
+ const result = await installHooks(args.target);
31
+ if (result.hookAction === "skipped") {
32
+ writeStderr(t("cli.hooks.install.hook-skipped", { path: result.hookPath }));
33
+ } else if (result.hookAction === "appended") {
34
+ writeStderr(t("cli.hooks.install.hook-appended", { path: result.hookPath }));
35
+ } else {
36
+ writeStderr(t("cli.hooks.install.hook-created", { path: result.hookPath }));
37
+ }
38
+ if (result.prepareAction === "left") {
39
+ writeStderr(t("cli.hooks.install.prepare-left", { path: result.packageJsonPath }));
40
+ } else {
41
+ writeStderr(t("cli.hooks.install.prepare-added", { path: result.packageJsonPath }));
42
+ }
43
+ }
44
+ })
45
+ }
46
+ });
47
+ var hooks_default = hooksCommand;
48
+ async function installHooks(target, options = {}) {
49
+ const normalizedTarget = normalizeTarget(target);
50
+ assertExistingDirectory(normalizedTarget);
51
+ const huskyDir = join(normalizedTarget, ".husky");
52
+ const hookPath = join(huskyDir, "pre-commit");
53
+ const packageJsonPath = join(normalizedTarget, "package.json");
54
+ if (!existsSync(packageJsonPath)) {
55
+ throw new Error(t("cli.hooks.errors.package-json-required", { path: packageJsonPath }));
56
+ }
57
+ mkdirSync(huskyDir, { recursive: true });
58
+ const templateContent = readFileSync(findTemplatePath("templates/husky/pre-commit"), "utf8");
59
+ const hookAction = installHookFile(hookPath, templateContent, options.force);
60
+ chmodSync(hookPath, 493);
61
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
62
+ const scripts = packageJson.scripts && typeof packageJson.scripts === "object" && !Array.isArray(packageJson.scripts) ? packageJson.scripts : {};
63
+ const hadPrepare = typeof scripts.prepare === "string" && scripts.prepare.trim().length > 0;
64
+ let prepareAction = "left";
65
+ if (!hadPrepare) {
66
+ scripts.prepare = "husky install";
67
+ packageJson.scripts = scripts;
68
+ writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
69
+ `, "utf8");
70
+ prepareAction = "added";
71
+ }
72
+ const installed = [];
73
+ const skipped = [];
74
+ if (hookAction === "skipped") {
75
+ skipped.push(hookPath);
76
+ } else {
77
+ installed.push(hookPath);
78
+ }
79
+ if (prepareAction === "left") {
80
+ skipped.push(packageJsonPath);
81
+ } else {
82
+ installed.push(packageJsonPath);
83
+ }
84
+ return {
85
+ installed,
86
+ skipped,
87
+ hookPath,
88
+ packageJsonPath,
89
+ hookAction,
90
+ prepareAction
91
+ };
92
+ }
93
+ function normalizeTarget(targetInput) {
94
+ return isAbsolute(targetInput) ? targetInput : resolve(process.cwd(), targetInput);
95
+ }
96
+ function assertExistingDirectory(target) {
97
+ if (!existsSync(target) || !statSync(target).isDirectory()) {
98
+ throw new Error(t("cli.shared.target-invalid", { target }));
99
+ }
100
+ }
101
+ function installHookFile(hookPath, templateContent, force) {
102
+ if (existsSync(hookPath)) {
103
+ if (force) {
104
+ writeFileSync(hookPath, templateContent, "utf8");
105
+ return "overwritten";
106
+ }
107
+ const existing = readFileSync(hookPath, "utf8");
108
+ if (existing.includes("FAB_BIN=")) {
109
+ return "skipped";
110
+ }
111
+ const fabricBlock = templateContent.replace(/^#!\/bin\/sh\n/, "");
112
+ const separator = existing.endsWith("\n") ? "\n" : "\n\n";
113
+ writeFileSync(hookPath, `${existing}${separator}# --- Fabric ---
114
+ ${fabricBlock}`, "utf8");
115
+ return "appended";
116
+ }
117
+ writeFileSync(hookPath, templateContent, "utf8");
118
+ return "created";
119
+ }
120
+ function findTemplatePath(relativePath) {
121
+ const currentModuleDir = dirname(fileURLToPath(import.meta.url));
122
+ const candidates = [
123
+ ...templateCandidatesFrom(process.cwd(), relativePath),
124
+ ...templateCandidatesFrom(currentModuleDir, relativePath)
125
+ ];
126
+ for (const candidate of candidates) {
127
+ if (existsSync(candidate)) {
128
+ return candidate;
129
+ }
130
+ }
131
+ throw new Error(t("cli.shared.template-not-found", { path: relativePath }));
132
+ }
133
+ function templateCandidatesFrom(start, relativePath) {
134
+ const candidates = [];
135
+ let current = resolve(start);
136
+ while (true) {
137
+ candidates.push(join(current, ...relativePath.split("/")));
138
+ const parent = dirname(current);
139
+ if (parent === current || parse(current).root === current) {
140
+ break;
141
+ }
142
+ current = parent;
143
+ }
144
+ return candidates.reverse();
145
+ }
146
+ function writeStderr(message) {
147
+ process.stderr.write(`${message}
148
+ `);
149
+ }
150
+
151
+ export {
152
+ hooksCommand,
153
+ hooks_default,
154
+ installHooks
155
+ };
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ configCmd,
4
+ config_default,
5
+ installMcpClients,
6
+ parseClientFilter
7
+ } from "./chunk-MDI7523D.js";
8
+ import "./chunk-VMYPJPKV.js";
9
+ import "./chunk-6ICJICVU.js";
10
+ export {
11
+ configCmd,
12
+ config_default as default,
13
+ installMcpClients,
14
+ parseClientFilter
15
+ };
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ padEnd,
4
+ paint,
5
+ symbol
6
+ } from "./chunk-WWNXR34K.js";
7
+ import {
8
+ resolveDevMode
9
+ } from "./chunk-AEOYCVBG.js";
10
+ import {
11
+ t
12
+ } from "./chunk-6ICJICVU.js";
13
+
14
+ // src/commands/doctor.ts
15
+ import { defineCommand } from "citty";
16
+ import { runDoctorAuditReport, runDoctorReport } from "@fenglimg/fabric-server";
17
+ var DEFAULT_AUDIT_WINDOW_MINUTES = 5;
18
+ var doctorCommand = defineCommand({
19
+ meta: {
20
+ name: "doctor",
21
+ description: t("cli.doctor.description")
22
+ },
23
+ args: {
24
+ target: {
25
+ type: "string",
26
+ description: t("cli.doctor.args.target.description")
27
+ },
28
+ audit: {
29
+ type: "boolean",
30
+ description: t("cli.doctor.args.audit.description"),
31
+ default: false
32
+ },
33
+ "window-minutes": {
34
+ type: "string",
35
+ description: t("cli.doctor.args.window-minutes.description"),
36
+ default: String(DEFAULT_AUDIT_WINDOW_MINUTES)
37
+ }
38
+ },
39
+ async run({ args }) {
40
+ const workspaceRoot = process.cwd();
41
+ const resolution = resolveDevMode(args.target, workspaceRoot);
42
+ const report = await runDoctorReport(resolution.target);
43
+ writeStdout(`${renderStatus(report.status)} ${paint.ai("fab doctor")} ${paint.human(resolution.target)}`);
44
+ for (const check of report.checks) {
45
+ writeStdout(`${renderStatus(check.status)} ${check.name}: ${check.message}`);
46
+ }
47
+ if (!args.audit) {
48
+ return;
49
+ }
50
+ const auditReport = await runDoctorAuditReport(resolution.target, {
51
+ force: true,
52
+ windowMs: parseWindowMinutes(args["window-minutes"])
53
+ });
54
+ if (auditReport.mode === "off") {
55
+ writeStderr(t("cli.doctor.audit.preview-only"));
56
+ }
57
+ if (auditReport.checkedPathCount === 0) {
58
+ writeStderr(t("cli.doctor.audit.none"));
59
+ return;
60
+ }
61
+ if (auditReport.violationCount === 0) {
62
+ writeStderr(
63
+ `${symbol.ok} ${t("cli.doctor.audit.clean", {
64
+ count: String(auditReport.checkedPathCount),
65
+ window: formatDuration(auditReport.windowMs)
66
+ })}`
67
+ );
68
+ return;
69
+ }
70
+ const writer = auditReport.mode === "strict" ? console.error : console.warn;
71
+ writer(
72
+ t("cli.doctor.audit.violations", {
73
+ count: String(auditReport.violationCount),
74
+ window: formatDuration(auditReport.windowMs)
75
+ })
76
+ );
77
+ writeStderr(
78
+ `${padEnd(t("cli.doctor.audit.table.path"), 32)} ${padEnd(t("cli.doctor.audit.table.edit"), 22)} ${padEnd(t("cli.doctor.audit.table.rules"), 22)} ${t("cli.doctor.audit.table.intent")}`
79
+ );
80
+ for (const violation of auditReport.violations) {
81
+ writeStderr(
82
+ `${padEnd(violation.path, 32)} ${padEnd(new Date(violation.editTs).toISOString(), 22)} ${padEnd(formatRulesTs(violation.lastGetRulesTs), 22)} ${violation.intent}`
83
+ );
84
+ }
85
+ if (auditReport.mode === "strict") {
86
+ process.exitCode = 1;
87
+ }
88
+ }
89
+ });
90
+ var doctor_default = doctorCommand;
91
+ function renderStatus(status) {
92
+ if (status === "ok") {
93
+ return symbol.ok;
94
+ }
95
+ if (status === "warn") {
96
+ return symbol.warn;
97
+ }
98
+ return symbol.error;
99
+ }
100
+ function parseWindowMinutes(value) {
101
+ const minutes = Number.parseInt(value ?? String(DEFAULT_AUDIT_WINDOW_MINUTES), 10);
102
+ if (!Number.isInteger(minutes) || minutes < 1) {
103
+ throw new Error(t("cli.doctor.errors.invalid-window", { value: value ?? "<unset>" }));
104
+ }
105
+ return minutes * 60 * 1e3;
106
+ }
107
+ function formatDuration(durationMs) {
108
+ const minutes = Math.max(Math.floor(durationMs / (60 * 1e3)), 1);
109
+ return `${minutes}m`;
110
+ }
111
+ function formatRulesTs(value) {
112
+ return value === null ? t("cli.shared.none") : new Date(value).toISOString();
113
+ }
114
+ function writeStdout(message) {
115
+ process.stdout.write(`${message}
116
+ `);
117
+ }
118
+ function writeStderr(message) {
119
+ process.stderr.write(`${message}
120
+ `);
121
+ }
122
+ export {
123
+ doctor_default as default,
124
+ doctorCommand
125
+ };
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ hooksCommand,
4
+ hooks_default,
5
+ installHooks
6
+ } from "./chunk-YDZJRLHL.js";
7
+ import "./chunk-6ICJICVU.js";
8
+ export {
9
+ hooks_default as default,
10
+ hooksCommand,
11
+ installHooks
12
+ };
package/dist/index.js CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- t
4
- } from "./chunk-6ICJICVU.js";
5
2
 
6
3
  // src/index.ts
7
4
  import { realpathSync } from "fs";
@@ -11,24 +8,43 @@ import { defineCommand, runMain } from "citty";
11
8
 
12
9
  // src/commands/index.ts
13
10
  var allCommands = {
14
- bootstrap: () => import("./bootstrap-PMIA4W6G.js").then((module) => module.default),
15
- init: () => import("./init-G6Q3OOMC.js").then((module) => module.default),
16
- scan: () => import("./scan-6CURGC3D.js").then((module) => module.default),
17
- serve: () => import("./serve-4J2CQY25.js").then((module) => module.default),
18
- "sync-meta": () => import("./sync-meta-L6M4AEUT.js").then((module) => module.default),
11
+ init: () => import("./init-3FPLOABB.js").then((module) => module.default),
12
+ scan: () => import("./scan-WKDSKEBB.js").then((module) => module.default),
13
+ serve: () => import("./serve-MMN4GYLM.js").then((module) => module.default),
14
+ doctor: () => import("./doctor-5KJGOV2P.js").then((module) => module.default),
15
+ "sync-meta": () => import("./sync-meta-THZSEM7Y.js").then((module) => module.default),
19
16
  "human-lint": () => import("./human-lint-YSFOZHZ7.js").then((module) => module.default),
20
17
  "ledger-append": () => import("./ledger-append-XZ5SX4O5.js").then((module) => module.default),
21
- hooks: () => import("./hooks-5S5IRVQE.js").then((module) => module.default),
22
- config: () => import("./config-PXEEXWLM.js").then((module) => module.configCmd),
23
- "pre-commit": () => import("./pre-commit-IEIXHKOD.js").then((module) => module.default)
18
+ "pre-commit": () => import("./pre-commit-CJ7EDKJK.js").then((module) => module.default),
19
+ bootstrap: () => import("./bootstrap-IUL4SAAK.js").then((module) => ({
20
+ ...module.default,
21
+ meta: {
22
+ ...module.default.meta,
23
+ hidden: true
24
+ }
25
+ })),
26
+ config: () => import("./config-3JBB77TX.js").then((module) => ({
27
+ ...module.configCmd,
28
+ meta: {
29
+ ...module.configCmd.meta,
30
+ hidden: true
31
+ }
32
+ })),
33
+ hooks: () => import("./hooks-ZSWVH2JD.js").then((module) => ({
34
+ ...module.default,
35
+ meta: {
36
+ ...module.default.meta,
37
+ hidden: true
38
+ }
39
+ }))
24
40
  };
25
41
 
26
42
  // src/index.ts
27
43
  var main = defineCommand({
28
44
  meta: {
29
- name: "fab",
30
- version: "1.0.0",
31
- description: t("cli.main.description")
45
+ name: "fabric",
46
+ version: "1.2.0",
47
+ description: 'Initialize and manage Fabric projects. Use "fabric init" for one-shot setup.'
32
48
  },
33
49
  subCommands: allCommands
34
50
  });