crudora 0.2.0 → 0.2.1
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/cli.js +55 -65
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1692 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +404 -0
- package/dist/index.d.ts +404 -15
- package/dist/index.js +1685 -27
- package/dist/index.js.map +1 -1
- package/dist/scripts/copy-assets.js +0 -21
- package/package.json +5 -4
- package/scripts/copy-assets.js +0 -21
- package/dist/core/crudora.d.ts +0 -49
- package/dist/core/crudora.d.ts.map +0 -1
- package/dist/core/crudora.js +0 -370
- package/dist/core/crudora.js.map +0 -1
- package/dist/core/crudoraServer.d.ts +0 -84
- package/dist/core/crudoraServer.d.ts.map +0 -1
- package/dist/core/crudoraServer.js +0 -202
- package/dist/core/crudoraServer.js.map +0 -1
- package/dist/core/drizzleTableBuilder.d.ts +0 -6
- package/dist/core/drizzleTableBuilder.d.ts.map +0 -1
- package/dist/core/drizzleTableBuilder.js +0 -175
- package/dist/core/drizzleTableBuilder.js.map +0 -1
- package/dist/core/model.d.ts +0 -58
- package/dist/core/model.d.ts.map +0 -1
- package/dist/core/model.js +0 -64
- package/dist/core/model.js.map +0 -1
- package/dist/core/repository.d.ts +0 -106
- package/dist/core/repository.d.ts.map +0 -1
- package/dist/core/repository.js +0 -607
- package/dist/core/repository.js.map +0 -1
- package/dist/core/schemaGenerator.d.ts +0 -6
- package/dist/core/schemaGenerator.d.ts.map +0 -1
- package/dist/core/schemaGenerator.js +0 -248
- package/dist/core/schemaGenerator.js.map +0 -1
- package/dist/decorators/model.d.ts +0 -64
- package/dist/decorators/model.d.ts.map +0 -1
- package/dist/decorators/model.js +0 -138
- package/dist/decorators/model.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/logger.type.d.ts +0 -7
- package/dist/types/logger.type.d.ts.map +0 -1
- package/dist/types/logger.type.js +0 -3
- package/dist/types/logger.type.js.map +0 -1
- package/dist/types/model.type.d.ts +0 -38
- package/dist/types/model.type.d.ts.map +0 -1
- package/dist/types/model.type.js +0 -3
- package/dist/types/model.type.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -7
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -107
- package/dist/utils/validation.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,72 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!existsSync(entryPath)) {
|
|
26
|
-
console.error(`Error: entry file not found — ${entryPath}`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import "reflect-metadata";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
7
|
+
import { resolve } from "path";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
9
|
+
import { createRequire } from "module";
|
|
10
|
+
import path from "path";
|
|
11
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
var __dirname = path.dirname(__filename);
|
|
13
|
+
var _require = createRequire(import.meta.url);
|
|
14
|
+
var pkg = JSON.parse(readFileSync(resolve(__dirname, "..", "package.json"), "utf-8"));
|
|
15
|
+
var program = new Command();
|
|
16
|
+
program.name("crudora").description("Crudora CLI \u2014 tools for Crudora projects").version(pkg.version ?? "0.0.0");
|
|
17
|
+
program.command("generate-schema").description("Generate a Drizzle TypeScript schema file from registered Crudora models").option("-e, --entry <file>", "Entry file (JS/TS) that exports a CrudoraServer or Crudora instance", "src/server.ts").option("-o, --output <file>", "Output path for the generated schema", "src/db/schema.ts").action(async (opts) => {
|
|
18
|
+
const entryPath = resolve(process.cwd(), opts.entry);
|
|
19
|
+
if (!existsSync(entryPath)) {
|
|
20
|
+
console.error(`Error: entry file not found \u2014 ${entryPath}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
let mod;
|
|
29
25
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
const crudora = typeof instance.getCrudora === 'function' ? instance.getCrudora() : instance;
|
|
51
|
-
if (typeof crudora.generateDrizzleSchema !== 'function') {
|
|
52
|
-
console.error('Error: could not find generateDrizzleSchema() on the exported instance.');
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
const schema = crudora.generateDrizzleSchema();
|
|
56
|
-
const outputPath = resolve(process.cwd(), opts.output);
|
|
57
|
-
const cwd = process.cwd() + path.sep;
|
|
58
|
-
if (!outputPath.startsWith(cwd)) {
|
|
59
|
-
console.error('Error: output path must be within the project directory.');
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
writeFileSync(outputPath, schema, 'utf-8');
|
|
63
|
-
console.log(`Schema written to ${outputPath}`);
|
|
64
|
-
console.log('Run: npx drizzle-kit push — to apply the schema to your database.');
|
|
26
|
+
mod = await import(pathToFileURL(entryPath).href);
|
|
27
|
+
} catch {
|
|
28
|
+
try {
|
|
29
|
+
_require("ts-node/register");
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
mod = _require(entryPath);
|
|
33
|
+
}
|
|
34
|
+
const instance = mod.default ?? mod.server ?? mod.crudora;
|
|
35
|
+
if (!instance) {
|
|
36
|
+
console.error(
|
|
37
|
+
'Error: entry file must export a CrudoraServer or Crudora instance as default, "server", or "crudora".'
|
|
38
|
+
);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const crudora = typeof instance.getCrudora === "function" ? instance.getCrudora() : instance;
|
|
42
|
+
if (typeof crudora.generateDrizzleSchema !== "function") {
|
|
43
|
+
console.error("Error: could not find generateDrizzleSchema() on the exported instance.");
|
|
44
|
+
process.exit(1);
|
|
65
45
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
46
|
+
const schema = crudora.generateDrizzleSchema();
|
|
47
|
+
const outputPath = resolve(process.cwd(), opts.output);
|
|
48
|
+
const cwd = process.cwd() + path.sep;
|
|
49
|
+
if (!outputPath.startsWith(cwd)) {
|
|
50
|
+
console.error("Error: output path must be within the project directory.");
|
|
51
|
+
process.exit(1);
|
|
69
52
|
}
|
|
53
|
+
writeFileSync(outputPath, schema, "utf-8");
|
|
54
|
+
console.log(`Schema written to ${outputPath}`);
|
|
55
|
+
console.log("Run: npx drizzle-kit push \u2014 to apply the schema to your database.");
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error("Error generating schema:", err.message);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
70
60
|
});
|
|
71
61
|
program.parse();
|
|
72
62
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { Command } from 'commander';\nimport { readFileSync, writeFileSync, existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport { createRequire } from 'module';\nimport path from 'path';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst _require = createRequire(import.meta.url);\n\nconst pkg = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf-8'));\n\nconst program = new Command();\n\nprogram\n .name('crudora')\n .description('Crudora CLI — tools for Crudora projects')\n .version(pkg.version ?? '0.0.0');\n\nprogram\n .command('generate-schema')\n .description('Generate a Drizzle TypeScript schema file from registered Crudora models')\n .option('-e, --entry <file>', 'Entry file (JS/TS) that exports a CrudoraServer or Crudora instance', 'src/server.ts')\n .option('-o, --output <file>', 'Output path for the generated schema', 'src/db/schema.ts')\n .action(async (opts) => {\n const entryPath = resolve(process.cwd(), opts.entry);\n if (!existsSync(entryPath)) {\n console.error(`Error: entry file not found — ${entryPath}`);\n process.exit(1);\n }\n\n try {\n let mod: any;\n try {\n // ESM dynamic import — works for compiled .js / .mjs entry files\n mod = await import(pathToFileURL(entryPath).href);\n } catch {\n // Fallback: CJS require — for pre-compiled CommonJS output\n try {\n _require('ts-node/register');\n } catch {\n // ts-node not installed — entry must be pre-compiled JS\n }\n mod = _require(entryPath);\n }\n const instance = mod.default ?? mod.server ?? mod.crudora;\n\n if (!instance) {\n console.error(\n 'Error: entry file must export a CrudoraServer or Crudora instance as default, \"server\", or \"crudora\".',\n );\n process.exit(1);\n }\n\n const crudora = typeof instance.getCrudora === 'function' ? instance.getCrudora() : instance;\n\n if (typeof crudora.generateDrizzleSchema !== 'function') {\n console.error('Error: could not find generateDrizzleSchema() on the exported instance.');\n process.exit(1);\n }\n\n const schema: string = crudora.generateDrizzleSchema();\n const outputPath = resolve(process.cwd(), opts.output);\n const cwd = process.cwd() + path.sep;\n if (!outputPath.startsWith(cwd)) {\n console.error('Error: output path must be within the project directory.');\n process.exit(1);\n }\n writeFileSync(outputPath, schema, 'utf-8');\n console.log(`Schema written to ${outputPath}`);\n console.log('Run: npx drizzle-kit push — to apply the schema to your database.');\n } catch (err: any) {\n console.error('Error generating schema:', err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