@verikit/cli 0.2.3 → 0.25.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.
Files changed (48) hide show
  1. package/bin/verikit.js +4 -0
  2. package/dist/cli.d.ts +10 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +97 -0
  5. package/dist/field-spec.d.ts +17 -0
  6. package/dist/field-spec.d.ts.map +1 -0
  7. package/dist/field-spec.js +64 -0
  8. package/dist/imports.d.ts +14 -0
  9. package/dist/imports.d.ts.map +1 -0
  10. package/dist/imports.js +12 -0
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +7 -52
  14. package/dist/load-resources.d.ts +38 -0
  15. package/dist/load-resources.d.ts.map +1 -0
  16. package/dist/load-resources.js +71 -0
  17. package/dist/names.d.ts +21 -0
  18. package/dist/names.d.ts.map +1 -0
  19. package/dist/names.js +73 -0
  20. package/dist/project.d.ts +41 -0
  21. package/dist/project.d.ts.map +1 -0
  22. package/dist/project.js +196 -0
  23. package/dist/render-registry.d.ts +20 -0
  24. package/dist/render-registry.d.ts.map +1 -0
  25. package/dist/render-registry.js +86 -0
  26. package/dist/render-resource.d.ts +26 -0
  27. package/dist/render-resource.d.ts.map +1 -0
  28. package/dist/render-resource.js +141 -0
  29. package/dist/render-schema.d.ts +13 -0
  30. package/dist/render-schema.d.ts.map +1 -0
  31. package/dist/render-schema.js +172 -0
  32. package/dist/wire-actions.d.ts +18 -0
  33. package/dist/wire-actions.d.ts.map +1 -0
  34. package/dist/wire-actions.js +32 -0
  35. package/package.json +30 -32
  36. package/README.md +0 -73
  37. package/dist/commands/init.js +0 -235
  38. package/dist/detect/database.js +0 -7
  39. package/dist/detect/framework.js +0 -25
  40. package/dist/detect/package-manager.js +0 -41
  41. package/dist/detect/project.js +0 -22
  42. package/dist/generators/route.js +0 -22
  43. package/dist/generators/server.js +0 -38
  44. package/dist/generators/theme.js +0 -25
  45. package/dist/install/capabilities.js +0 -45
  46. package/dist/install/dependencies.js +0 -21
  47. package/dist/utils/banner.js +0 -6
  48. package/dist/utils/fs.js +0 -29
package/bin/verikit.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ // Committed rather than built so package managers can link the `verikit`
3
+ // command before a workspace build has run; it needs dist/ only when it runs.
4
+ import "../dist/index.js";
package/dist/cli.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const USAGE: string;
2
+ export interface CliEnvironment {
3
+ argv: string[];
4
+ cwd: string;
5
+ log: (message: string) => void;
6
+ error: (message: string) => void;
7
+ }
8
+ /** Runs the CLI. Resolves to the process exit code. */
9
+ export declare function main(env: CliEnvironment): Promise<number>;
10
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,KAAK,QAmBgB,CAAC;AAEnC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AA4FD,uDAAuD;AACvD,wBAAsB,IAAI,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAO/D"}
package/dist/cli.js ADDED
@@ -0,0 +1,97 @@
1
+ import { parseArgs } from "node:util";
2
+ import { FIELD_TYPES } from "./field-spec.js";
3
+ import { generate, makeAction, makeResource, readConfig, } from "./project.js";
4
+ export const USAGE = `Usage: verikit <command> [options]
5
+
6
+ Commands:
7
+ make:resource <Name> [field:type ...] Create resources/<name>.ts, then regenerate
8
+ make:action <resource> <name> Declare an action in resources/<resource>.actions.ts,
9
+ create its handler in actions/<resource>/<name>.ts
10
+ generate:schema [--check] Regenerate db/schema.ts, resources/index.ts,
11
+ and actions/index.ts from resources/
12
+
13
+ Field types: ${FIELD_TYPES.filter((type) => type !== "select" && type !== "belongsTo").join(", ")},
14
+ select:<option>,<option>, belongsTo:<resource>
15
+ Fields are required; end a field with ? to make it nullable.
16
+
17
+ Example:
18
+ verikit make:resource Post title:text body:textarea? status:select:draft,published
19
+
20
+ Options:
21
+ --force Overwrite an existing file (make:*)
22
+ --check Fail if generated files are out of date (generate:schema)
23
+ -h, --help Show this message`;
24
+ function printReport(env, report) {
25
+ for (const file of report.created)
26
+ env.log(` created ${file}`);
27
+ for (const file of report.updated)
28
+ env.log(` updated ${file}`);
29
+ for (const warning of report.warnings)
30
+ env.error(` warning ${warning}`);
31
+ if (report.notes.length > 0) {
32
+ env.log(`\n${report.notes.join("\n")}`);
33
+ }
34
+ }
35
+ function expectArgs(positionals, min, max, usage) {
36
+ const count = positionals.length - 1;
37
+ if (count < min || count > max) {
38
+ throw new Error(`Usage: verikit ${usage}`);
39
+ }
40
+ }
41
+ async function run(env) {
42
+ const { values, positionals } = parseArgs({
43
+ args: env.argv,
44
+ allowPositionals: true,
45
+ options: {
46
+ force: { type: "boolean", default: false },
47
+ check: { type: "boolean", default: false },
48
+ help: { type: "boolean", short: "h", default: false },
49
+ },
50
+ });
51
+ const [command] = positionals;
52
+ if (values.help || command === undefined) {
53
+ env.log(USAGE);
54
+ return values.help ? 0 : 1;
55
+ }
56
+ const config = readConfig(env.cwd);
57
+ const force = values.force;
58
+ switch (command) {
59
+ case "make:resource": {
60
+ expectArgs(positionals, 1, Infinity, "make:resource <Name> [field:type ...]");
61
+ printReport(env, await makeResource(config, positionals[1], positionals.slice(2), {
62
+ force,
63
+ }));
64
+ return 0;
65
+ }
66
+ case "make:action": {
67
+ expectArgs(positionals, 2, 2, "make:action <resource> <name>");
68
+ printReport(env, await makeAction(config, positionals[1], positionals[2], { force }));
69
+ return 0;
70
+ }
71
+ case "generate:schema": {
72
+ expectArgs(positionals, 0, 0, "generate:schema [--check]");
73
+ const report = await generate(config, { check: values.check });
74
+ printReport(env, report);
75
+ if (report.stale.length > 0) {
76
+ env.error(`Out of date: ${report.stale.join(", ")}. Run \`verikit generate:schema\` and commit the result.`);
77
+ return 1;
78
+ }
79
+ if (report.created.length + report.updated.length === 0) {
80
+ env.log("Generated files are up to date.");
81
+ }
82
+ return 0;
83
+ }
84
+ default:
85
+ throw new Error(`Unknown command "${command}".\n\n${USAGE}`);
86
+ }
87
+ }
88
+ /** Runs the CLI. Resolves to the process exit code. */
89
+ export async function main(env) {
90
+ try {
91
+ return await run(env);
92
+ }
93
+ catch (error) {
94
+ env.error(error.message);
95
+ return 1;
96
+ }
97
+ }
@@ -0,0 +1,17 @@
1
+ export declare const FIELD_TYPES: readonly ["text", "textarea", "email", "number", "integer", "boolean", "date", "datetime", "select", "belongsTo"];
2
+ export type FieldType = (typeof FIELD_TYPES)[number];
3
+ /** One `name:type[:arg][?]` argument to `make:resource`. */
4
+ export interface FieldSpec {
5
+ name: string;
6
+ type: FieldType;
7
+ nullable: boolean;
8
+ /** Options for `select`. */
9
+ options?: string[];
10
+ /** Target resource name for `belongsTo`. */
11
+ target?: string;
12
+ }
13
+ /** Parses `title:text`, `body:textarea?`, `status:select:draft,published`, or `author:belongsTo:user`. */
14
+ export declare function parseFieldSpec(spec: string): FieldSpec;
15
+ /** Rejects two specs that would produce the same field. */
16
+ export declare function assertUniqueFields(specs: readonly FieldSpec[]): void;
17
+ //# sourceMappingURL=field-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-spec.d.ts","sourceRoot":"","sources":["../src/field-spec.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,mHAWd,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,4DAA4D;AAC5D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAKD,0GAA0G;AAC1G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAuDtD;AAED,2DAA2D;AAC3D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAepE"}
@@ -0,0 +1,64 @@
1
+ import { camelCase, invalidIdentifier } from "./names.js";
2
+ export const FIELD_TYPES = [
3
+ "text",
4
+ "textarea",
5
+ "email",
6
+ "number",
7
+ "integer",
8
+ "boolean",
9
+ "date",
10
+ "datetime",
11
+ "select",
12
+ "belongsTo",
13
+ ];
14
+ /** Field names the generated table or record already uses. */
15
+ const RESERVED_FIELDS = ["id", "revision"];
16
+ /** Parses `title:text`, `body:textarea?`, `status:select:draft,published`, or `author:belongsTo:user`. */
17
+ export function parseFieldSpec(spec) {
18
+ const nullable = spec.endsWith("?");
19
+ const [rawName = "", rawType = "", ...rest] = (nullable ? spec.slice(0, -1) : spec).split(":");
20
+ const arg = rest.join(":");
21
+ const name = camelCase(rawName);
22
+ const invalid = invalidIdentifier(name, RESERVED_FIELDS);
23
+ if (invalid) {
24
+ throw new Error(`Field "${spec}": ${invalid}`);
25
+ }
26
+ const type = FIELD_TYPES.find((candidate) => candidate.toLowerCase() === rawType.toLowerCase());
27
+ if (!type) {
28
+ throw new Error(`Field "${spec}": unknown type "${rawType}". Use one of: ${FIELD_TYPES.join(", ")}.`);
29
+ }
30
+ if (type === "select") {
31
+ const options = arg
32
+ .split(",")
33
+ .map((option) => option.trim())
34
+ .filter(Boolean);
35
+ if (options.length === 0) {
36
+ throw new Error(`Field "${spec}": list the options, e.g. ${name}:select:draft,published`);
37
+ }
38
+ return { name, type, nullable, options };
39
+ }
40
+ if (type === "belongsTo") {
41
+ const target = camelCase(arg);
42
+ if (!target) {
43
+ throw new Error(`Field "${spec}": name the target resource, e.g. ${name}:belongsTo:user`);
44
+ }
45
+ return { name, type, nullable, target };
46
+ }
47
+ if (arg) {
48
+ throw new Error(`Field "${spec}": type "${type}" takes no argument.`);
49
+ }
50
+ return { name, type, nullable };
51
+ }
52
+ /** Rejects two specs that would produce the same field. */
53
+ export function assertUniqueFields(specs) {
54
+ const seen = new Set();
55
+ for (const spec of specs) {
56
+ const names = spec.type === "belongsTo" ? [spec.name, `${spec.name}Id`] : [spec.name];
57
+ for (const name of names) {
58
+ if (seen.has(name)) {
59
+ throw new Error(`Field "${name}" is defined twice.`);
60
+ }
61
+ seen.add(name);
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,14 @@
1
+ /** Where generated files import Verikit from. */
2
+ export interface ImportSources {
3
+ /** defineResource, fields, relationships. */
4
+ core: string;
5
+ /** action(). */
6
+ runtime: string;
7
+ /** ServerResourceConfig. */
8
+ server: string;
9
+ }
10
+ /** For apps that install the scoped @verikit/* packages. */
11
+ export declare const SCOPED_IMPORTS: ImportSources;
12
+ /** For apps that install the `verikit` meta-package. */
13
+ export declare const META_IMPORTS: ImportSources;
14
+ //# sourceMappingURL=imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4DAA4D;AAC5D,eAAO,MAAM,cAAc,EAAE,aAI5B,CAAC;AAEF,wDAAwD;AACxD,eAAO,MAAM,YAAY,EAAE,aAI1B,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** For apps that install the scoped @verikit/* packages. */
2
+ export const SCOPED_IMPORTS = {
3
+ core: "@verikit/core",
4
+ runtime: "@verikit/runtime",
5
+ server: "@verikit/server",
6
+ };
7
+ /** For apps that install the `verikit` meta-package. */
8
+ export const META_IMPORTS = {
9
+ core: "verikit",
10
+ runtime: "verikit",
11
+ server: "verikit/server",
12
+ };
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js CHANGED
@@ -1,53 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import { realpathSync } from "node:fs";
4
- import { pathToFileURL } from "node:url";
5
- import { InitAbort, runInit } from "./commands/init.js";
6
- /**
7
- * Bridges a commander action to `runInit`, translating a thrown `InitAbort` into
8
- * `process.exitCode` instead of letting it surface as an unhandled rejection.
9
- */
10
- export async function runInitCommand(opts, run = runInit) {
11
- try {
12
- await run(opts);
13
- }
14
- catch (err) {
15
- if (err instanceof InitAbort) {
16
- process.exitCode = err.code;
17
- return;
18
- }
19
- throw err;
20
- }
21
- }
22
- /** `run` overrides what `init`/`install` ultimately call used in tests to avoid driving a real interactive prompt. */
23
- export function createProgram(run = runInit) {
24
- const program = new Command();
25
- program
26
- .name("verikit")
27
- .description("Scaffolding CLI for VeriKit")
28
- .version("0.1.0");
29
- program
30
- .command("init")
31
- .description("Detect your stack, install VeriKit packages, and generate the integration")
32
- .option("--skip-install", "Generate files without installing dependencies")
33
- .option("--dry-run", "Show what would be installed and generated without changing anything")
34
- .action((opts) => runInitCommand(opts, run));
35
- program
36
- .command("install")
37
- .description("Install VeriKit packages for your detected stack, without generating integration files")
38
- .option("--dry-run", "Show what would be installed without changing anything")
39
- .action((opts) => runInitCommand({ ...opts, packagesOnly: true }, run));
40
- return program;
41
- }
42
- /* node:coverage disable */
43
- // `process.argv[1]` is the path used to invoke this script when run through npm/npx's `bin`
44
- // symlink (node_modules/.bin/verikit -> .../dist/index.js), that's the symlink path, while
45
- // `import.meta.url` is Node's ESM loader resolving to the real, symlink-followed path. Without
46
- // realpathSync here the two never match, `isMain` is always false, and the CLI silently no-ops
47
- // for every real install only direct `node dist/index.js` invocations happened to line up.
48
- const isMain = typeof process.argv[1] === "string" &&
49
- import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href;
50
- if (isMain) {
51
- void createProgram().parseAsync(process.argv);
52
- }
53
- /* node:coverage enable */
2
+ import { main } from "./cli.js";
3
+ process.exitCode = await main({
4
+ argv: process.argv.slice(2),
5
+ cwd: process.cwd(),
6
+ log: (message) => console.log(message),
7
+ error: (message) => console.error(message),
8
+ });
@@ -0,0 +1,38 @@
1
+ /** The parts of a finalized field schema the generators read. */
2
+ export interface FieldInfo {
3
+ fieldType: string;
4
+ required?: boolean;
5
+ nullable?: boolean;
6
+ unique?: boolean;
7
+ defaultValue?: unknown;
8
+ step?: number;
9
+ multiple?: boolean;
10
+ options?: readonly {
11
+ value: unknown;
12
+ }[];
13
+ }
14
+ /** The parts of a finalized relationship schema the generators read. */
15
+ export interface RelationshipInfo {
16
+ relationshipType: string;
17
+ resource: string;
18
+ foreignKey?: unknown;
19
+ }
20
+ /** A resource found in the resources directory. */
21
+ export interface LoadedResource {
22
+ name: string;
23
+ exportName: string;
24
+ /** File name inside the resources directory, e.g. "blog-post.ts". */
25
+ file: string;
26
+ hasTable: boolean;
27
+ fields: Record<string, FieldInfo>;
28
+ relationships: Record<string, RelationshipInfo>;
29
+ }
30
+ export declare const REGISTRY_FILE = "index.ts";
31
+ /** The `.ts` files in `dir` other than the generated registry, sorted. */
32
+ export declare function moduleFiles(dir: string): string[];
33
+ /**
34
+ * Imports every resource module in `dir` (Node strips the TypeScript types)
35
+ * and collects the resources they export, sorted by file then export name.
36
+ */
37
+ export declare function loadResources(dir: string): Promise<LoadedResource[]>;
38
+ //# sourceMappingURL=load-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-resources.d.ts","sourceRoot":"","sources":["../src/load-resources.ts"],"names":[],"mappings":"AAIA,iEAAiE;AACjE,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,SAAS;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CACzC;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CACjD;AAsBD,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAajD;AAID;;;GAGG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA8D1E"}
@@ -0,0 +1,71 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ /** Duck-typed, since the app's copy of @verikit/core isn't this package's. */
5
+ function isResource(value) {
6
+ return (typeof value === "object" &&
7
+ value !== null &&
8
+ typeof value.name === "string" &&
9
+ typeof value.toSchema === "function" &&
10
+ typeof value.fields === "object");
11
+ }
12
+ export const REGISTRY_FILE = "index.ts";
13
+ /** The `.ts` files in `dir` other than the generated registry, sorted. */
14
+ export function moduleFiles(dir) {
15
+ if (!existsSync(dir)) {
16
+ return [];
17
+ }
18
+ return readdirSync(dir)
19
+ .filter((file) => file.endsWith(".ts") &&
20
+ !file.endsWith(".d.ts") &&
21
+ file !== REGISTRY_FILE)
22
+ .sort();
23
+ }
24
+ let importCount = 0;
25
+ /**
26
+ * Imports every resource module in `dir` (Node strips the TypeScript types)
27
+ * and collects the resources they export, sorted by file then export name.
28
+ */
29
+ export async function loadResources(dir) {
30
+ const loaded = [];
31
+ for (const file of moduleFiles(dir)) {
32
+ // A fresh query string makes repeated runs in one process re-read the file.
33
+ const url = `${pathToFileURL(path.join(dir, file)).href}?verikit=${importCount++}`;
34
+ let exports;
35
+ try {
36
+ exports = (await import(url));
37
+ }
38
+ catch (error) {
39
+ throw new Error(`Couldn't load ${path.join(path.basename(dir), file)}: ${error.message}`, { cause: error });
40
+ }
41
+ for (const [exportName, value] of Object.entries(exports).sort(([a], [b]) => a.localeCompare(b))) {
42
+ if (!isResource(value)) {
43
+ continue;
44
+ }
45
+ const schema = value.toSchema();
46
+ loaded.push({
47
+ name: value.name,
48
+ exportName,
49
+ file,
50
+ hasTable: value.table !== undefined,
51
+ fields: schema.fields,
52
+ relationships: schema.relationships,
53
+ });
54
+ }
55
+ }
56
+ const byName = new Map();
57
+ const byExport = new Map();
58
+ for (const resource of loaded) {
59
+ const sameName = byName.get(resource.name);
60
+ if (sameName) {
61
+ throw new Error(`Two resources are named "${resource.name}" (${sameName.file} and ${resource.file}).`);
62
+ }
63
+ const sameExport = byExport.get(resource.exportName);
64
+ if (sameExport) {
65
+ throw new Error(`Two files export "${resource.exportName}" (${sameExport.file} and ${resource.file}). Rename one export.`);
66
+ }
67
+ byName.set(resource.name, resource);
68
+ byExport.set(resource.exportName, resource);
69
+ }
70
+ return loaded;
71
+ }
@@ -0,0 +1,21 @@
1
+ /** Splits camelCase, PascalCase, kebab-case, snake_case, and spaced names into lowercase words. */
2
+ export declare function words(name: string): string[];
3
+ export declare function camelCase(name: string): string;
4
+ export declare function kebabCase(name: string): string;
5
+ export declare function snakeCase(name: string): string;
6
+ /** "publishedAt" → "Published at". */
7
+ export declare function sentenceCase(name: string): string;
8
+ /** English plural of one lowercase word; good enough for table names. */
9
+ export declare function pluralize(word: string): string;
10
+ /** "blogPost" → "blogPosts". */
11
+ export declare function pluralCamelCase(name: string): string;
12
+ /** "blogPost" → "blog_posts". */
13
+ export declare function pluralSnakeCase(name: string): string;
14
+ /**
15
+ * Returns why `name` can't be a generated identifier, or `undefined` if it
16
+ * can. `extraReserved` adds names the generated files already use.
17
+ */
18
+ export declare function invalidIdentifier(name: string, extraReserved?: readonly string[]): string | undefined;
19
+ /** A relative file path as an import specifier: "x.ts" becomes "./x.ts". */
20
+ export declare function importSpecifier(relativePath: string): string;
21
+ //# sourceMappingURL=names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAO5C;AAMD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,sCAAsC;AACtC,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW9C;AAQD,gCAAgC;AAChC,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,iCAAiC;AACjC,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAYD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,aAAa,GAAE,SAAS,MAAM,EAAO,GACpC,MAAM,GAAG,SAAS,CAUpB;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAG5D"}
package/dist/names.js ADDED
@@ -0,0 +1,73 @@
1
+ /** Splits camelCase, PascalCase, kebab-case, snake_case, and spaced names into lowercase words. */
2
+ export function words(name) {
3
+ return name
4
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
5
+ .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2")
6
+ .split(/[\s_-]+/)
7
+ .filter(Boolean)
8
+ .map((word) => word.toLowerCase());
9
+ }
10
+ function capitalize(word) {
11
+ return word.charAt(0).toUpperCase() + word.slice(1);
12
+ }
13
+ export function camelCase(name) {
14
+ const [first = "", ...rest] = words(name);
15
+ return first + rest.map(capitalize).join("");
16
+ }
17
+ export function kebabCase(name) {
18
+ return words(name).join("-");
19
+ }
20
+ export function snakeCase(name) {
21
+ return words(name).join("_");
22
+ }
23
+ /** "publishedAt" → "Published at". */
24
+ export function sentenceCase(name) {
25
+ return capitalize(words(name).join(" "));
26
+ }
27
+ /** English plural of one lowercase word; good enough for table names. */
28
+ export function pluralize(word) {
29
+ if (/[^aeiou]y$/.test(word)) {
30
+ return `${word.slice(0, -1)}ies`;
31
+ }
32
+ if (/(s|x|z|ch|sh)$/.test(word)) {
33
+ // A name like "posts" is usually already plural.
34
+ return /[^s]s$/.test(word) ? word : `${word}es`;
35
+ }
36
+ return `${word}s`;
37
+ }
38
+ function pluralWords(name) {
39
+ const parts = words(name);
40
+ const last = parts.pop();
41
+ return last === undefined ? [] : [...parts, pluralize(last)];
42
+ }
43
+ /** "blogPost" → "blogPosts". */
44
+ export function pluralCamelCase(name) {
45
+ return camelCase(pluralWords(name).join(" "));
46
+ }
47
+ /** "blogPost" → "blog_posts". */
48
+ export function pluralSnakeCase(name) {
49
+ return pluralWords(name).join("_");
50
+ }
51
+ const RESERVED = new Set(("await break case catch class const continue debugger default delete do " +
52
+ "else enum export extends false finally for function if implements import " +
53
+ "in instanceof interface let new null package private protected public " +
54
+ "return static super switch this throw true try typeof var void while " +
55
+ "with yield").split(" "));
56
+ /**
57
+ * Returns why `name` can't be a generated identifier, or `undefined` if it
58
+ * can. `extraReserved` adds names the generated files already use.
59
+ */
60
+ export function invalidIdentifier(name, extraReserved = []) {
61
+ if (!/^[a-z][A-Za-z0-9]*$/.test(name)) {
62
+ return `"${name}" must start with a letter and contain only letters and digits.`;
63
+ }
64
+ if (RESERVED.has(name) || extraReserved.includes(name)) {
65
+ return `"${name}" is a reserved name.`;
66
+ }
67
+ return undefined;
68
+ }
69
+ /** A relative file path as an import specifier: "x.ts" becomes "./x.ts". */
70
+ export function importSpecifier(relativePath) {
71
+ const posix = relativePath.split("\\").join("/");
72
+ return posix.startsWith(".") ? posix : `./${posix}`;
73
+ }
@@ -0,0 +1,41 @@
1
+ import { type ImportSources } from "./imports.js";
2
+ import { type Dialect } from "./render-schema.js";
3
+ /** Where an app keeps the files the generators read and write. */
4
+ export interface ProjectConfig {
5
+ root: string;
6
+ dialect: Dialect;
7
+ resourcesDir: string;
8
+ actionsDir: string;
9
+ schemaFile: string;
10
+ permissionsFile: string;
11
+ /** `verikit` when the app depends on the meta-package, else the scoped packages. */
12
+ imports: ImportSources;
13
+ }
14
+ /** Reads the optional `"verikit"` key of `root/package.json`. */
15
+ export declare function readConfig(root: string): ProjectConfig;
16
+ /** What a command changed, for the CLI to report. */
17
+ export interface Report {
18
+ created: string[];
19
+ updated: string[];
20
+ stale: string[];
21
+ warnings: string[];
22
+ notes: string[];
23
+ }
24
+ /**
25
+ * Regenerates the resource registry, action registry, and Drizzle schema from
26
+ * the resources directory. With `check`, reports out-of-date files instead.
27
+ */
28
+ export declare function generate(config: ProjectConfig, { check }?: {
29
+ check?: boolean;
30
+ }, report?: Report): Promise<Report>;
31
+ /** Adds `name: "open"` to the `permissions` map, if the file has one. */
32
+ export declare function addOpenPermission(file: string, name: string): boolean;
33
+ /** `make:resource <Name> [field:type ...]`. */
34
+ export declare function makeResource(config: ProjectConfig, rawName: string, fieldArgs: readonly string[], { force }?: {
35
+ force?: boolean;
36
+ }): Promise<Report>;
37
+ /** `make:action <resource> <name>`. */
38
+ export declare function makeAction(config: ProjectConfig, resourceArg: string, rawName: string, { force }?: {
39
+ force?: boolean;
40
+ }): Promise<Report>;
41
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAqBhF,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEhE,kEAAkE;AAClE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,oFAAoF;IACpF,OAAO,EAAE,aAAa,CAAC;CACxB;AAUD,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA8BtD;AAED,qDAAqD;AACrD,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAeD;;;GAGG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,aAAa,EACrB,EAAE,KAAa,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,EAC3C,MAAM,GAAE,MAAsB,GAC7B,OAAO,CAAC,MAAM,CAAC,CAoDjB;AAsBD,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAuBrE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,EAAE,KAAa,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,OAAO,CAAC,MAAM,CAAC,CA0DjB;AAED,uCAAuC;AACvC,wBAAsB,UAAU,CAC9B,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,EAAE,KAAa,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,OAAO,CAAC,MAAM,CAAC,CAyFjB"}