@fabricorg/fabric-gen 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/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/chunk-OKPHRFAQ.js +72 -0
- package/dist/chunk-OKPHRFAQ.js.map +1 -0
- package/dist/cli.cjs +108 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +23 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add the thin `fabric-gen` CLI with deterministic target selection, check-only drift detection, and
|
|
8
|
+
stale-file reporting.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @fabricorg/gen-types@0.2.0
|
|
16
|
+
- @fabricorg/gen-events@0.2.0
|
|
17
|
+
- @fabricorg/gen-capability@0.2.0
|
|
18
|
+
- @fabricorg/gen-docs@0.2.0
|
|
19
|
+
- @fabricorg/gen-prisma@0.2.0
|
|
20
|
+
- @fabricorg/gen-graphql@0.2.0
|
|
21
|
+
- @fabricorg/gen-sdui@0.2.0
|
|
22
|
+
- @fabricorg/compiler@0.2.0
|
|
23
|
+
|
|
24
|
+
## 0.1.0
|
|
25
|
+
|
|
26
|
+
- Add the thin deterministic generator CLI with write and check-only modes.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fabric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# `fabric-gen`
|
|
2
|
+
|
|
3
|
+
Thin CLI over independently versioned Fabric generator targets.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
fabric-gen --input fabric-manifest.json --out generated
|
|
7
|
+
fabric-gen --input fabric-manifest.json --out generated --check
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
`--check` performs no writes and fails for changed or stale artifacts. Generated files contain a
|
|
11
|
+
manifest digest and generator version, never timestamps.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// index.ts
|
|
4
|
+
import { mkdir, readFile, readdir, writeFile } from "fs/promises";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { compileManifestBundle, runGenerator } from "@fabricorg/compiler";
|
|
7
|
+
import { capabilityGenerator } from "@fabricorg/gen-capability";
|
|
8
|
+
import { docsGenerator } from "@fabricorg/gen-docs";
|
|
9
|
+
import { eventsGenerator } from "@fabricorg/gen-events";
|
|
10
|
+
import { typesGenerator } from "@fabricorg/gen-types";
|
|
11
|
+
import { prismaGenerator } from "@fabricorg/gen-prisma";
|
|
12
|
+
import { graphqlGenerator } from "@fabricorg/gen-graphql";
|
|
13
|
+
import { sduiGenerator } from "@fabricorg/gen-sdui";
|
|
14
|
+
var GENERATOR_TARGETS = {
|
|
15
|
+
types: typesGenerator,
|
|
16
|
+
events: eventsGenerator,
|
|
17
|
+
capability: capabilityGenerator,
|
|
18
|
+
docs: docsGenerator,
|
|
19
|
+
prisma: prismaGenerator,
|
|
20
|
+
graphql: graphqlGenerator,
|
|
21
|
+
sdui: sduiGenerator
|
|
22
|
+
};
|
|
23
|
+
var compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
24
|
+
async function generateFromManifest(options) {
|
|
25
|
+
const input = JSON.parse(await readFile(options.inputPath, "utf8"));
|
|
26
|
+
const bundle = "modules" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };
|
|
27
|
+
const ir = compileManifestBundle(bundle);
|
|
28
|
+
const files = (await Promise.all(options.targets.map(async (name) => {
|
|
29
|
+
const target = GENERATOR_TARGETS[name];
|
|
30
|
+
if (!target) throw new Error(`Unknown generator target "${name}".`);
|
|
31
|
+
return (await runGenerator(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));
|
|
32
|
+
}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));
|
|
33
|
+
const expected = new Set(files.map((file) => file.path));
|
|
34
|
+
const existing = await listFiles(options.outputDirectory);
|
|
35
|
+
const selectedPrefixes = options.targets.map((target) => `${target}/`);
|
|
36
|
+
const stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));
|
|
37
|
+
const changed = [];
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
const target = path.join(options.outputDirectory, file.path);
|
|
40
|
+
let current;
|
|
41
|
+
try {
|
|
42
|
+
current = await readFile(target, "utf8");
|
|
43
|
+
} catch {
|
|
44
|
+
current = void 0;
|
|
45
|
+
}
|
|
46
|
+
if (current !== file.content) {
|
|
47
|
+
changed.push(file.path);
|
|
48
|
+
if (!options.check) {
|
|
49
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
50
|
+
await writeFile(target, file.content, "utf8");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(", ")}`);
|
|
55
|
+
return { changed, stale, files };
|
|
56
|
+
}
|
|
57
|
+
async function listFiles(directory, prefix = "") {
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
61
|
+
} catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(path.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));
|
|
65
|
+
return nested.flat().sort();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
GENERATOR_TARGETS,
|
|
70
|
+
generateFromManifest
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-OKPHRFAQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { mkdir, readFile, readdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { compileManifestBundle, runGenerator, type GeneratedFile, type GeneratorTarget } from \"@fabricorg/compiler\";\nimport { capabilityGenerator } from \"@fabricorg/gen-capability\";\nimport { docsGenerator } from \"@fabricorg/gen-docs\";\nimport { eventsGenerator } from \"@fabricorg/gen-events\";\nimport { typesGenerator } from \"@fabricorg/gen-types\";\nimport { prismaGenerator } from \"@fabricorg/gen-prisma\";\nimport { graphqlGenerator } from \"@fabricorg/gen-graphql\";\nimport { sduiGenerator } from \"@fabricorg/gen-sdui\";\n\nexport const GENERATOR_TARGETS: Record<string, GeneratorTarget> = {\n\ttypes: typesGenerator,\n\tevents: eventsGenerator,\n\tcapability: capabilityGenerator,\n\tdocs: docsGenerator,\n\tprisma: prismaGenerator,\n\tgraphql: graphqlGenerator,\n\tsdui: sduiGenerator,\n};\nconst compareCanonicalStrings = (left: string, right: string): number => left < right ? -1 : left > right ? 1 : 0;\n\nexport interface GenerateOptions { inputPath: string; outputDirectory: string; targets: string[]; check?: boolean; }\nexport interface GenerateResult { changed: string[]; stale: string[]; files: GeneratedFile[]; }\n\nexport async function generateFromManifest(options: GenerateOptions): Promise<GenerateResult> {\n\tconst input = JSON.parse(await readFile(options.inputPath, \"utf8\"));\n\tconst bundle = \"modules\" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };\n\tconst ir = compileManifestBundle(bundle);\n\tconst files = (await Promise.all(options.targets.map(async (name) => {\n\t\tconst target = GENERATOR_TARGETS[name];\n\t\tif (!target) throw new Error(`Unknown generator target \"${name}\".`);\n\t\treturn (await runGenerator(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));\n\t}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));\n\tconst expected = new Set(files.map((file) => file.path));\n\tconst existing = await listFiles(options.outputDirectory);\n\tconst selectedPrefixes = options.targets.map((target) => `${target}/`);\n\tconst stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));\n\tconst changed: string[] = [];\n\tfor (const file of files) {\n\t\tconst target = path.join(options.outputDirectory, file.path);\n\t\tlet current: string | undefined;\n\t\ttry { current = await readFile(target, \"utf8\"); } catch { current = undefined; }\n\t\tif (current !== file.content) {\n\t\t\tchanged.push(file.path);\n\t\t\tif (!options.check) { await mkdir(path.dirname(target), { recursive: true }); await writeFile(target, file.content, \"utf8\"); }\n\t\t}\n\t}\n\tif (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(\", \")}`);\n\treturn { changed, stale, files };\n}\n\nasync function listFiles(directory: string, prefix = \"\"): Promise<string[]> {\n\tlet entries;\n\ttry { entries = await readdir(directory, { withFileTypes: true }); } catch { return []; }\n\tconst nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(path.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));\n\treturn nested.flat().sort();\n}\n"],"mappings":";;;AAAA,SAAS,OAAO,UAAU,SAAS,iBAAiB;AACpD,OAAO,UAAU;AACjB,SAAS,uBAAuB,oBAA8D;AAC9F,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAEvB,IAAM,oBAAqD;AAAA,EACjE,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACP;AACA,IAAM,0BAA0B,CAAC,MAAc,UAA0B,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAKhH,eAAsB,qBAAqB,SAAmD;AAC7F,QAAM,QAAQ,KAAK,MAAM,MAAM,SAAS,QAAQ,WAAW,MAAM,CAAC;AAClE,QAAM,SAAS,aAAa,QAAQ,QAAQ,EAAE,iBAAiB,MAAM,iBAAiB,SAAS,CAAC,KAAK,EAAE;AACvG,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,UAAU,MAAM,QAAS,OAAM,IAAI,MAAM,gCAAgC,CAAC,GAAG,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,SAAS,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;AACzK,SAAO,EAAE,SAAS,OAAO,MAAM;AAChC;AAEA,eAAe,UAAU,WAAmB,SAAS,IAAuB;AAC3E,MAAI;AACJ,MAAI;AAAE,cAAU,MAAM,QAAQ,WAAW,EAAE,eAAe,KAAK,CAAC;AAAA,EAAG,QAAQ;AAAE,WAAO,CAAC;AAAA,EAAG;AACxF,QAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ,IAAI,CAAC,UAAU,MAAM,YAAY,IAAI,UAAU,KAAK,KAAK,WAAW,MAAM,IAAI,GAAG,GAAG,MAAM,GAAG,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC;AAClL,SAAO,OAAO,KAAK,EAAE,KAAK;AAC3B;","names":[]}
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// index.ts
|
|
27
|
+
var import_promises = require("fs/promises");
|
|
28
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
29
|
+
var import_compiler = require("@fabricorg/compiler");
|
|
30
|
+
var import_gen_capability = require("@fabricorg/gen-capability");
|
|
31
|
+
var import_gen_docs = require("@fabricorg/gen-docs");
|
|
32
|
+
var import_gen_events = require("@fabricorg/gen-events");
|
|
33
|
+
var import_gen_types = require("@fabricorg/gen-types");
|
|
34
|
+
var import_gen_prisma = require("@fabricorg/gen-prisma");
|
|
35
|
+
var import_gen_graphql = require("@fabricorg/gen-graphql");
|
|
36
|
+
var import_gen_sdui = require("@fabricorg/gen-sdui");
|
|
37
|
+
var GENERATOR_TARGETS = {
|
|
38
|
+
types: import_gen_types.typesGenerator,
|
|
39
|
+
events: import_gen_events.eventsGenerator,
|
|
40
|
+
capability: import_gen_capability.capabilityGenerator,
|
|
41
|
+
docs: import_gen_docs.docsGenerator,
|
|
42
|
+
prisma: import_gen_prisma.prismaGenerator,
|
|
43
|
+
graphql: import_gen_graphql.graphqlGenerator,
|
|
44
|
+
sdui: import_gen_sdui.sduiGenerator
|
|
45
|
+
};
|
|
46
|
+
var compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
47
|
+
async function generateFromManifest(options) {
|
|
48
|
+
const input = JSON.parse(await (0, import_promises.readFile)(options.inputPath, "utf8"));
|
|
49
|
+
const bundle = "modules" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };
|
|
50
|
+
const ir = (0, import_compiler.compileManifestBundle)(bundle);
|
|
51
|
+
const files = (await Promise.all(options.targets.map(async (name) => {
|
|
52
|
+
const target = GENERATOR_TARGETS[name];
|
|
53
|
+
if (!target) throw new Error(`Unknown generator target "${name}".`);
|
|
54
|
+
return (await (0, import_compiler.runGenerator)(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));
|
|
55
|
+
}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));
|
|
56
|
+
const expected = new Set(files.map((file) => file.path));
|
|
57
|
+
const existing = await listFiles(options.outputDirectory);
|
|
58
|
+
const selectedPrefixes = options.targets.map((target) => `${target}/`);
|
|
59
|
+
const stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));
|
|
60
|
+
const changed = [];
|
|
61
|
+
for (const file of files) {
|
|
62
|
+
const target = import_node_path.default.join(options.outputDirectory, file.path);
|
|
63
|
+
let current;
|
|
64
|
+
try {
|
|
65
|
+
current = await (0, import_promises.readFile)(target, "utf8");
|
|
66
|
+
} catch {
|
|
67
|
+
current = void 0;
|
|
68
|
+
}
|
|
69
|
+
if (current !== file.content) {
|
|
70
|
+
changed.push(file.path);
|
|
71
|
+
if (!options.check) {
|
|
72
|
+
await (0, import_promises.mkdir)(import_node_path.default.dirname(target), { recursive: true });
|
|
73
|
+
await (0, import_promises.writeFile)(target, file.content, "utf8");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(", ")}`);
|
|
78
|
+
return { changed, stale, files };
|
|
79
|
+
}
|
|
80
|
+
async function listFiles(directory, prefix = "") {
|
|
81
|
+
let entries;
|
|
82
|
+
try {
|
|
83
|
+
entries = await (0, import_promises.readdir)(directory, { withFileTypes: true });
|
|
84
|
+
} catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(import_node_path.default.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));
|
|
88
|
+
return nested.flat().sort();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// cli.ts
|
|
92
|
+
var args = process.argv.slice(2);
|
|
93
|
+
var value = (flag) => {
|
|
94
|
+
const index = args.indexOf(flag);
|
|
95
|
+
return index >= 0 ? args[index + 1] : void 0;
|
|
96
|
+
};
|
|
97
|
+
var inputPath = value("--input");
|
|
98
|
+
var outputDirectory = value("--out");
|
|
99
|
+
if (!inputPath || !outputDirectory) {
|
|
100
|
+
console.error("Usage: fabric-gen --input manifest.json --out generated [--targets types,events,capability,docs] [--check]");
|
|
101
|
+
process.exitCode = 2;
|
|
102
|
+
} else {
|
|
103
|
+
generateFromManifest({ inputPath, outputDirectory, targets: (value("--targets") ?? "types,events,capability,docs").split(",").filter(Boolean), check: args.includes("--check") }).then((result) => console.log(`${args.includes("--check") ? "Checked" : "Generated"} ${result.files.length} files.`)).catch((error) => {
|
|
104
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts","../cli.ts"],"sourcesContent":["import { mkdir, readFile, readdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { compileManifestBundle, runGenerator, type GeneratedFile, type GeneratorTarget } from \"@fabricorg/compiler\";\nimport { capabilityGenerator } from \"@fabricorg/gen-capability\";\nimport { docsGenerator } from \"@fabricorg/gen-docs\";\nimport { eventsGenerator } from \"@fabricorg/gen-events\";\nimport { typesGenerator } from \"@fabricorg/gen-types\";\nimport { prismaGenerator } from \"@fabricorg/gen-prisma\";\nimport { graphqlGenerator } from \"@fabricorg/gen-graphql\";\nimport { sduiGenerator } from \"@fabricorg/gen-sdui\";\n\nexport const GENERATOR_TARGETS: Record<string, GeneratorTarget> = {\n\ttypes: typesGenerator,\n\tevents: eventsGenerator,\n\tcapability: capabilityGenerator,\n\tdocs: docsGenerator,\n\tprisma: prismaGenerator,\n\tgraphql: graphqlGenerator,\n\tsdui: sduiGenerator,\n};\nconst compareCanonicalStrings = (left: string, right: string): number => left < right ? -1 : left > right ? 1 : 0;\n\nexport interface GenerateOptions { inputPath: string; outputDirectory: string; targets: string[]; check?: boolean; }\nexport interface GenerateResult { changed: string[]; stale: string[]; files: GeneratedFile[]; }\n\nexport async function generateFromManifest(options: GenerateOptions): Promise<GenerateResult> {\n\tconst input = JSON.parse(await readFile(options.inputPath, \"utf8\"));\n\tconst bundle = \"modules\" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };\n\tconst ir = compileManifestBundle(bundle);\n\tconst files = (await Promise.all(options.targets.map(async (name) => {\n\t\tconst target = GENERATOR_TARGETS[name];\n\t\tif (!target) throw new Error(`Unknown generator target \"${name}\".`);\n\t\treturn (await runGenerator(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));\n\t}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));\n\tconst expected = new Set(files.map((file) => file.path));\n\tconst existing = await listFiles(options.outputDirectory);\n\tconst selectedPrefixes = options.targets.map((target) => `${target}/`);\n\tconst stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));\n\tconst changed: string[] = [];\n\tfor (const file of files) {\n\t\tconst target = path.join(options.outputDirectory, file.path);\n\t\tlet current: string | undefined;\n\t\ttry { current = await readFile(target, \"utf8\"); } catch { current = undefined; }\n\t\tif (current !== file.content) {\n\t\t\tchanged.push(file.path);\n\t\t\tif (!options.check) { await mkdir(path.dirname(target), { recursive: true }); await writeFile(target, file.content, \"utf8\"); }\n\t\t}\n\t}\n\tif (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(\", \")}`);\n\treturn { changed, stale, files };\n}\n\nasync function listFiles(directory: string, prefix = \"\"): Promise<string[]> {\n\tlet entries;\n\ttry { entries = await readdir(directory, { withFileTypes: true }); } catch { return []; }\n\tconst nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(path.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));\n\treturn nested.flat().sort();\n}\n","import { generateFromManifest } from \"./index\";\n\nconst args = process.argv.slice(2);\nconst value = (flag: string): string | undefined => { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; };\nconst inputPath = value(\"--input\");\nconst outputDirectory = value(\"--out\");\nif (!inputPath || !outputDirectory) {\n\tconsole.error(\"Usage: fabric-gen --input manifest.json --out generated [--targets types,events,capability,docs] [--check]\");\n\tprocess.exitCode = 2;\n} else {\n\tgenerateFromManifest({ inputPath, outputDirectory, targets: (value(\"--targets\") ?? \"types,events,capability,docs\").split(\",\").filter(Boolean), check: args.includes(\"--check\") })\n\t\t.then((result) => console.log(`${args.includes(\"--check\") ? \"Checked\" : \"Generated\"} ${result.files.length} files.`))\n\t\t.catch((error: unknown) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sBAAoD;AACpD,uBAAiB;AACjB,sBAA8F;AAC9F,4BAAoC;AACpC,sBAA8B;AAC9B,wBAAgC;AAChC,uBAA+B;AAC/B,wBAAgC;AAChC,yBAAiC;AACjC,sBAA8B;AAEvB,IAAM,oBAAqD;AAAA,EACjE,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACP;AACA,IAAM,0BAA0B,CAAC,MAAc,UAA0B,OAAO,QAAQ,KAAK,OAAO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iB,UAAU,MAAM,WAAW,KAAK,gCAAgC,MAAM,GAAG,EAAE,OAAO,OAAO,GAAG,OAAO,KAAK,SAAS,SAAS,EAAE,CAAC,EAC9K,KAAK,CAAC,WAAW,QAAQ,IAAI,GAAG,KAAK,SAAS,SAAS,IAAI,YAAY,WAAW,IAAI,OAAO,MAAM,MAAM,SAAS,CAAC,EACnH,MAAM,CAAC,UAAmB;AAAE,YAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAG,YAAQ,WAAW;AAAA,EAAG,CAAC;AAC7H;","names":["path"]}
|
package/dist/cli.d.cts
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
generateFromManifest
|
|
4
|
+
} from "./chunk-OKPHRFAQ.js";
|
|
5
|
+
|
|
6
|
+
// cli.ts
|
|
7
|
+
var args = process.argv.slice(2);
|
|
8
|
+
var value = (flag) => {
|
|
9
|
+
const index = args.indexOf(flag);
|
|
10
|
+
return index >= 0 ? args[index + 1] : void 0;
|
|
11
|
+
};
|
|
12
|
+
var inputPath = value("--input");
|
|
13
|
+
var outputDirectory = value("--out");
|
|
14
|
+
if (!inputPath || !outputDirectory) {
|
|
15
|
+
console.error("Usage: fabric-gen --input manifest.json --out generated [--targets types,events,capability,docs] [--check]");
|
|
16
|
+
process.exitCode = 2;
|
|
17
|
+
} else {
|
|
18
|
+
generateFromManifest({ inputPath, outputDirectory, targets: (value("--targets") ?? "types,events,capability,docs").split(",").filter(Boolean), check: args.includes("--check") }).then((result) => console.log(`${args.includes("--check") ? "Checked" : "Generated"} ${result.files.length} files.`)).catch((error) => {
|
|
19
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../cli.ts"],"sourcesContent":["import { generateFromManifest } from \"./index\";\n\nconst args = process.argv.slice(2);\nconst value = (flag: string): string | undefined => { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; };\nconst inputPath = value(\"--input\");\nconst outputDirectory = value(\"--out\");\nif (!inputPath || !outputDirectory) {\n\tconsole.error(\"Usage: fabric-gen --input manifest.json --out generated [--targets types,events,capability,docs] [--check]\");\n\tprocess.exitCode = 2;\n} else {\n\tgenerateFromManifest({ inputPath, outputDirectory, targets: (value(\"--targets\") ?? \"types,events,capability,docs\").split(\",\").filter(Boolean), check: args.includes(\"--check\") })\n\t\t.then((result) => console.log(`${args.includes(\"--check\") ? \"Checked\" : \"Generated\"} ${result.files.length} files.`))\n\t\t.catch((error: unknown) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });\n}\n"],"mappings":";;;;;;AAEA,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,QAAQ,CAAC,SAAqC;AAAE,QAAM,QAAQ,KAAK,QAAQ,IAAI;AAAG,SAAO,SAAS,IAAI,KAAK,QAAQ,CAAC,IAAI;AAAW;AACzI,IAAM,YAAY,MAAM,SAAS;AACjC,IAAM,kBAAkB,MAAM,OAAO;AACrC,IAAI,CAAC,aAAa,CAAC,iBAAiB;AACnC,UAAQ,MAAM,4GAA4G;AAC1H,UAAQ,WAAW;AACpB,OAAO;AACN,uBAAqB,EAAE,WAAW,iBAAiB,UAAU,MAAM,WAAW,KAAK,gCAAgC,MAAM,GAAG,EAAE,OAAO,OAAO,GAAG,OAAO,KAAK,SAAS,SAAS,EAAE,CAAC,EAC9K,KAAK,CAAC,WAAW,QAAQ,IAAI,GAAG,KAAK,SAAS,SAAS,IAAI,YAAY,WAAW,IAAI,OAAO,MAAM,MAAM,SAAS,CAAC,EACnH,MAAM,CAAC,UAAmB;AAAE,YAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAG,YAAQ,WAAW;AAAA,EAAG,CAAC;AAC7H;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
GENERATOR_TARGETS: () => GENERATOR_TARGETS,
|
|
35
|
+
generateFromManifest: () => generateFromManifest
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_promises = require("fs/promises");
|
|
39
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
40
|
+
var import_compiler = require("@fabricorg/compiler");
|
|
41
|
+
var import_gen_capability = require("@fabricorg/gen-capability");
|
|
42
|
+
var import_gen_docs = require("@fabricorg/gen-docs");
|
|
43
|
+
var import_gen_events = require("@fabricorg/gen-events");
|
|
44
|
+
var import_gen_types = require("@fabricorg/gen-types");
|
|
45
|
+
var import_gen_prisma = require("@fabricorg/gen-prisma");
|
|
46
|
+
var import_gen_graphql = require("@fabricorg/gen-graphql");
|
|
47
|
+
var import_gen_sdui = require("@fabricorg/gen-sdui");
|
|
48
|
+
var GENERATOR_TARGETS = {
|
|
49
|
+
types: import_gen_types.typesGenerator,
|
|
50
|
+
events: import_gen_events.eventsGenerator,
|
|
51
|
+
capability: import_gen_capability.capabilityGenerator,
|
|
52
|
+
docs: import_gen_docs.docsGenerator,
|
|
53
|
+
prisma: import_gen_prisma.prismaGenerator,
|
|
54
|
+
graphql: import_gen_graphql.graphqlGenerator,
|
|
55
|
+
sdui: import_gen_sdui.sduiGenerator
|
|
56
|
+
};
|
|
57
|
+
var compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
58
|
+
async function generateFromManifest(options) {
|
|
59
|
+
const input = JSON.parse(await (0, import_promises.readFile)(options.inputPath, "utf8"));
|
|
60
|
+
const bundle = "modules" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };
|
|
61
|
+
const ir = (0, import_compiler.compileManifestBundle)(bundle);
|
|
62
|
+
const files = (await Promise.all(options.targets.map(async (name) => {
|
|
63
|
+
const target = GENERATOR_TARGETS[name];
|
|
64
|
+
if (!target) throw new Error(`Unknown generator target "${name}".`);
|
|
65
|
+
return (await (0, import_compiler.runGenerator)(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));
|
|
66
|
+
}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));
|
|
67
|
+
const expected = new Set(files.map((file) => file.path));
|
|
68
|
+
const existing = await listFiles(options.outputDirectory);
|
|
69
|
+
const selectedPrefixes = options.targets.map((target) => `${target}/`);
|
|
70
|
+
const stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));
|
|
71
|
+
const changed = [];
|
|
72
|
+
for (const file of files) {
|
|
73
|
+
const target = import_node_path.default.join(options.outputDirectory, file.path);
|
|
74
|
+
let current;
|
|
75
|
+
try {
|
|
76
|
+
current = await (0, import_promises.readFile)(target, "utf8");
|
|
77
|
+
} catch {
|
|
78
|
+
current = void 0;
|
|
79
|
+
}
|
|
80
|
+
if (current !== file.content) {
|
|
81
|
+
changed.push(file.path);
|
|
82
|
+
if (!options.check) {
|
|
83
|
+
await (0, import_promises.mkdir)(import_node_path.default.dirname(target), { recursive: true });
|
|
84
|
+
await (0, import_promises.writeFile)(target, file.content, "utf8");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(", ")}`);
|
|
89
|
+
return { changed, stale, files };
|
|
90
|
+
}
|
|
91
|
+
async function listFiles(directory, prefix = "") {
|
|
92
|
+
let entries;
|
|
93
|
+
try {
|
|
94
|
+
entries = await (0, import_promises.readdir)(directory, { withFileTypes: true });
|
|
95
|
+
} catch {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(import_node_path.default.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));
|
|
99
|
+
return nested.flat().sort();
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
GENERATOR_TARGETS,
|
|
104
|
+
generateFromManifest
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { mkdir, readFile, readdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { compileManifestBundle, runGenerator, type GeneratedFile, type GeneratorTarget } from \"@fabricorg/compiler\";\nimport { capabilityGenerator } from \"@fabricorg/gen-capability\";\nimport { docsGenerator } from \"@fabricorg/gen-docs\";\nimport { eventsGenerator } from \"@fabricorg/gen-events\";\nimport { typesGenerator } from \"@fabricorg/gen-types\";\nimport { prismaGenerator } from \"@fabricorg/gen-prisma\";\nimport { graphqlGenerator } from \"@fabricorg/gen-graphql\";\nimport { sduiGenerator } from \"@fabricorg/gen-sdui\";\n\nexport const GENERATOR_TARGETS: Record<string, GeneratorTarget> = {\n\ttypes: typesGenerator,\n\tevents: eventsGenerator,\n\tcapability: capabilityGenerator,\n\tdocs: docsGenerator,\n\tprisma: prismaGenerator,\n\tgraphql: graphqlGenerator,\n\tsdui: sduiGenerator,\n};\nconst compareCanonicalStrings = (left: string, right: string): number => left < right ? -1 : left > right ? 1 : 0;\n\nexport interface GenerateOptions { inputPath: string; outputDirectory: string; targets: string[]; check?: boolean; }\nexport interface GenerateResult { changed: string[]; stale: string[]; files: GeneratedFile[]; }\n\nexport async function generateFromManifest(options: GenerateOptions): Promise<GenerateResult> {\n\tconst input = JSON.parse(await readFile(options.inputPath, \"utf8\"));\n\tconst bundle = \"modules\" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };\n\tconst ir = compileManifestBundle(bundle);\n\tconst files = (await Promise.all(options.targets.map(async (name) => {\n\t\tconst target = GENERATOR_TARGETS[name];\n\t\tif (!target) throw new Error(`Unknown generator target \"${name}\".`);\n\t\treturn (await runGenerator(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));\n\t}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));\n\tconst expected = new Set(files.map((file) => file.path));\n\tconst existing = await listFiles(options.outputDirectory);\n\tconst selectedPrefixes = options.targets.map((target) => `${target}/`);\n\tconst stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));\n\tconst changed: string[] = [];\n\tfor (const file of files) {\n\t\tconst target = path.join(options.outputDirectory, file.path);\n\t\tlet current: string | undefined;\n\t\ttry { current = await readFile(target, \"utf8\"); } catch { current = undefined; }\n\t\tif (current !== file.content) {\n\t\t\tchanged.push(file.path);\n\t\t\tif (!options.check) { await mkdir(path.dirname(target), { recursive: true }); await writeFile(target, file.content, \"utf8\"); }\n\t\t}\n\t}\n\tif (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(\", \")}`);\n\treturn { changed, stale, files };\n}\n\nasync function listFiles(directory: string, prefix = \"\"): Promise<string[]> {\n\tlet entries;\n\ttry { entries = await readdir(directory, { withFileTypes: true }); } catch { return []; }\n\tconst nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(path.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));\n\treturn nested.flat().sort();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoD;AACpD,uBAAiB;AACjB,sBAA8F;AAC9F,4BAAoC;AACpC,sBAA8B;AAC9B,wBAAgC;AAChC,uBAA+B;AAC/B,wBAAgC;AAChC,yBAAiC;AACjC,sBAA8B;AAEvB,IAAM,oBAAqD;AAAA,EACjE,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACP;AACA,IAAM,0BAA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AC/E,QAAI,YAAY,KAAK,SAAS;AAC7B,cAAQ,KAAK,KAAK,IAAI;AACtB,UAAI,CAAC,QAAQ,OAAO;AAAE,kBAAM,uBAAM,iBAAAA,QAAK,QAAQ,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;AAAG,kBAAM,2BAAU,QAAQ,KAAK,SAAS,MAAM;AAAA,MAAG;AAAA,IAC9H;AAAA,EACD;AACA,MAAI,QAAQ,UAAU,QAAQ,UAAU,MAAM,QAAS,OAAM,IAAI,MAAM,gCAAgC,CAAC,GAAG,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,SAAS,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;AACzK,SAAO,EAAE,SAAS,OAAO,MAAM;AAChC;AAEA,eAAe,UAAU,WAAmB,SAAS,IAAuB;AAC3E,MAAI;AACJ,MAAI;AAAE,cAAU,UAAM,yBAAQ,WAAW,EAAE,eAAe,KAAK,CAAC;AAAA,EAAG,QAAQ;AAAE,WAAO,CAAC;AAAA,EAAG;AACxF,QAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ,IAAI,CAAC,UAAU,MAAM,YAAY,IAAI,UAAU,iBAAAA,QAAK,KAAK,WAAW,MAAM,IAAI,GAAG,GAAG,MAAM,GAAG,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC;AAClL,SAAO,OAAO,KAAK,EAAE,KAAK;AAC3B;","names":["path"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GeneratorTarget, GeneratedFile } from '@fabricorg/compiler';
|
|
2
|
+
|
|
3
|
+
declare const GENERATOR_TARGETS: Record<string, GeneratorTarget>;
|
|
4
|
+
interface GenerateOptions {
|
|
5
|
+
inputPath: string;
|
|
6
|
+
outputDirectory: string;
|
|
7
|
+
targets: string[];
|
|
8
|
+
check?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface GenerateResult {
|
|
11
|
+
changed: string[];
|
|
12
|
+
stale: string[];
|
|
13
|
+
files: GeneratedFile[];
|
|
14
|
+
}
|
|
15
|
+
declare function generateFromManifest(options: GenerateOptions): Promise<GenerateResult>;
|
|
16
|
+
|
|
17
|
+
export { GENERATOR_TARGETS, type GenerateOptions, type GenerateResult, generateFromManifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GeneratorTarget, GeneratedFile } from '@fabricorg/compiler';
|
|
2
|
+
|
|
3
|
+
declare const GENERATOR_TARGETS: Record<string, GeneratorTarget>;
|
|
4
|
+
interface GenerateOptions {
|
|
5
|
+
inputPath: string;
|
|
6
|
+
outputDirectory: string;
|
|
7
|
+
targets: string[];
|
|
8
|
+
check?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface GenerateResult {
|
|
11
|
+
changed: string[];
|
|
12
|
+
stale: string[];
|
|
13
|
+
files: GeneratedFile[];
|
|
14
|
+
}
|
|
15
|
+
declare function generateFromManifest(options: GenerateOptions): Promise<GenerateResult>;
|
|
16
|
+
|
|
17
|
+
export { GENERATOR_TARGETS, type GenerateOptions, type GenerateResult, generateFromManifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fabricorg/fabric-gen",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Thin CLI for deterministic Fabric manifest generator targets.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"fabric-gen": "./dist/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"CHANGELOG.md"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@fabricorg/compiler": "^0.2.0",
|
|
31
|
+
"@fabricorg/gen-capability": "^0.2.0",
|
|
32
|
+
"@fabricorg/gen-docs": "^0.2.0",
|
|
33
|
+
"@fabricorg/gen-events": "^0.2.0",
|
|
34
|
+
"@fabricorg/gen-graphql": "^0.2.0",
|
|
35
|
+
"@fabricorg/gen-prisma": "^0.2.0",
|
|
36
|
+
"@fabricorg/gen-sdui": "^0.2.0",
|
|
37
|
+
"@fabricorg/gen-types": "^0.2.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.10.0",
|
|
41
|
+
"tsup": "^8.5.0",
|
|
42
|
+
"typescript": "^5.7.3",
|
|
43
|
+
"vitest": "^4.1.5",
|
|
44
|
+
"@fabricorg/platform": "^0.11.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"type-check": "tsc --noEmit",
|
|
56
|
+
"test": "vitest run"
|
|
57
|
+
}
|
|
58
|
+
}
|