@famgia/omnify-cli 0.0.3 → 0.0.5
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/README.md +261 -23
- package/dist/index.cjs +301 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +307 -93
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
#!/usr/bin/env node
|
|
3
2
|
"use strict";
|
|
4
3
|
var __create = Object.create;
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
@@ -36,12 +35,15 @@ __export(index_exports, {
|
|
|
36
35
|
loadConfig: () => loadConfig
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_node_fs4 = require("fs");
|
|
39
|
+
var import_node_path6 = require("path");
|
|
39
40
|
var import_commander = require("commander");
|
|
40
41
|
var import_omnify_core6 = require("@famgia/omnify-core");
|
|
41
42
|
|
|
42
43
|
// src/commands/init.ts
|
|
43
44
|
var import_node_fs = require("fs");
|
|
44
45
|
var import_node_path = require("path");
|
|
46
|
+
var import_prompts = require("@inquirer/prompts");
|
|
45
47
|
|
|
46
48
|
// src/output/logger.ts
|
|
47
49
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
@@ -168,7 +170,7 @@ var logger = new Logger();
|
|
|
168
170
|
|
|
169
171
|
// src/commands/init.ts
|
|
170
172
|
var EXAMPLE_SCHEMA = `# Example User schema
|
|
171
|
-
# See https://
|
|
173
|
+
# See https://github.com/famgia/omnify for documentation
|
|
172
174
|
|
|
173
175
|
name: User
|
|
174
176
|
displayName: User Account
|
|
@@ -193,78 +195,193 @@ options:
|
|
|
193
195
|
timestamps: true
|
|
194
196
|
softDelete: true
|
|
195
197
|
`;
|
|
196
|
-
|
|
198
|
+
function generateConfig(config) {
|
|
199
|
+
const imports = [`import { defineConfig } from '@famgia/omnify';`];
|
|
200
|
+
const plugins = [];
|
|
201
|
+
if (config.migrationTool === "laravel") {
|
|
202
|
+
imports.push(`import laravel from '@famgia/omnify-laravel/plugin';`);
|
|
203
|
+
plugins.push(` laravel({
|
|
204
|
+
migrationsPath: '${config.migrationsPath}',
|
|
205
|
+
typesPath: '${config.typesPath}',
|
|
206
|
+
singleFile: true,
|
|
207
|
+
generateMigrations: true,
|
|
208
|
+
generateTypes: ${config.generateTypes},
|
|
209
|
+
}),`);
|
|
210
|
+
}
|
|
211
|
+
if (config.migrationTool === "prisma") {
|
|
212
|
+
plugins.push(` // Prisma plugin coming soon!
|
|
213
|
+
// prisma({ schemaPath: 'prisma/schema.prisma' }),`);
|
|
214
|
+
}
|
|
215
|
+
if (config.migrationTool === "drizzle") {
|
|
216
|
+
plugins.push(` // Drizzle plugin coming soon!
|
|
217
|
+
// drizzle({ schemaPath: 'src/db/schema.ts' }),`);
|
|
218
|
+
}
|
|
219
|
+
if (config.migrationTool === "none" && config.generateTypes) {
|
|
220
|
+
imports.push(`import laravel from '@famgia/omnify-laravel/plugin';`);
|
|
221
|
+
plugins.push(` laravel({
|
|
222
|
+
typesPath: '${config.typesPath}',
|
|
223
|
+
generateMigrations: false,
|
|
224
|
+
generateTypes: true,
|
|
225
|
+
}),`);
|
|
226
|
+
}
|
|
227
|
+
const dbUrlExamples = {
|
|
228
|
+
mysql: "mysql://root:password@localhost:3306/omnify_dev",
|
|
229
|
+
postgres: "postgres://postgres:password@localhost:5432/omnify_dev",
|
|
230
|
+
sqlite: "sqlite://./omnify_dev.db"
|
|
231
|
+
};
|
|
232
|
+
return `${imports.join("\n")}
|
|
197
233
|
|
|
198
234
|
export default defineConfig({
|
|
199
235
|
// Schema files location
|
|
200
|
-
schemasDir: '
|
|
236
|
+
schemasDir: '${config.schemasDir}',
|
|
237
|
+
|
|
238
|
+
// Lock file for tracking schema changes
|
|
239
|
+
lockFilePath: './omnify.lock',
|
|
201
240
|
|
|
202
241
|
// Database configuration
|
|
203
242
|
database: {
|
|
204
|
-
driver: '
|
|
205
|
-
//
|
|
206
|
-
// devUrl: '
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
// Output configuration
|
|
210
|
-
output: {
|
|
211
|
-
laravel: {
|
|
212
|
-
migrationsPath: 'database/migrations',
|
|
213
|
-
},
|
|
214
|
-
typescript: {
|
|
215
|
-
path: 'types',
|
|
216
|
-
singleFile: true,
|
|
217
|
-
},
|
|
243
|
+
driver: '${config.database}',
|
|
244
|
+
// REQUIRED: Set your development database URL
|
|
245
|
+
// devUrl: '${dbUrlExamples[config.database]}',
|
|
218
246
|
},
|
|
219
247
|
|
|
220
|
-
//
|
|
248
|
+
// Generator plugins
|
|
221
249
|
plugins: [
|
|
222
|
-
|
|
250
|
+
${plugins.join("\n\n")}
|
|
223
251
|
],
|
|
224
252
|
});
|
|
225
253
|
`;
|
|
254
|
+
}
|
|
226
255
|
async function runInit(options) {
|
|
227
256
|
const cwd = process.cwd();
|
|
228
|
-
logger.header("
|
|
229
|
-
|
|
230
|
-
|
|
257
|
+
logger.header("Omnify Project Setup");
|
|
258
|
+
logger.newline();
|
|
259
|
+
const configPath2 = (0, import_node_path.resolve)(cwd, "omnify.config.ts");
|
|
260
|
+
if ((0, import_node_fs.existsSync)(configPath2) && !options.force) {
|
|
231
261
|
logger.warn("omnify.config.ts already exists. Use --force to overwrite.");
|
|
232
262
|
return;
|
|
233
263
|
}
|
|
234
|
-
|
|
264
|
+
let config;
|
|
265
|
+
if (options.yes) {
|
|
266
|
+
config = {
|
|
267
|
+
database: "mysql",
|
|
268
|
+
migrationTool: "laravel",
|
|
269
|
+
generateTypes: true,
|
|
270
|
+
migrationsPath: "database/migrations",
|
|
271
|
+
typesPath: "resources/js/types",
|
|
272
|
+
schemasDir: "./schemas"
|
|
273
|
+
};
|
|
274
|
+
logger.info("Using default configuration...");
|
|
275
|
+
} else {
|
|
276
|
+
logger.info("Answer a few questions to configure your project:\n");
|
|
277
|
+
const database = await (0, import_prompts.select)({
|
|
278
|
+
message: "Which database?",
|
|
279
|
+
choices: [
|
|
280
|
+
{ name: "MySQL / MariaDB", value: "mysql" },
|
|
281
|
+
{ name: "PostgreSQL", value: "postgres" },
|
|
282
|
+
{ name: "SQLite", value: "sqlite" }
|
|
283
|
+
],
|
|
284
|
+
default: "mysql"
|
|
285
|
+
});
|
|
286
|
+
const migrationTool = await (0, import_prompts.select)({
|
|
287
|
+
message: "Which migration tool?",
|
|
288
|
+
choices: [
|
|
289
|
+
{ name: "Laravel (PHP)", value: "laravel" },
|
|
290
|
+
{ name: "Prisma (coming soon)", value: "prisma", disabled: true },
|
|
291
|
+
{ name: "Drizzle (coming soon)", value: "drizzle", disabled: true },
|
|
292
|
+
{ name: "None (types only)", value: "none" }
|
|
293
|
+
],
|
|
294
|
+
default: "laravel"
|
|
295
|
+
});
|
|
296
|
+
const generateTypes = await (0, import_prompts.confirm)({
|
|
297
|
+
message: "Generate TypeScript types?",
|
|
298
|
+
default: true
|
|
299
|
+
});
|
|
300
|
+
const defaultPaths = {
|
|
301
|
+
laravel: { migrations: "database/migrations", types: "resources/js/types" },
|
|
302
|
+
prisma: { migrations: "prisma/migrations", types: "src/types" },
|
|
303
|
+
drizzle: { migrations: "drizzle", types: "src/types" },
|
|
304
|
+
none: { migrations: "", types: "types" }
|
|
305
|
+
};
|
|
306
|
+
const defaults = defaultPaths[migrationTool];
|
|
307
|
+
let migrationsPath = defaults.migrations;
|
|
308
|
+
let typesPath = defaults.types;
|
|
309
|
+
if (migrationTool !== "none") {
|
|
310
|
+
migrationsPath = await (0, import_prompts.input)({
|
|
311
|
+
message: "Migrations output path:",
|
|
312
|
+
default: defaults.migrations
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
if (generateTypes) {
|
|
316
|
+
typesPath = await (0, import_prompts.input)({
|
|
317
|
+
message: "TypeScript types path:",
|
|
318
|
+
default: defaults.types
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
const schemasDir2 = await (0, import_prompts.input)({
|
|
322
|
+
message: "Schemas directory:",
|
|
323
|
+
default: "./schemas"
|
|
324
|
+
});
|
|
325
|
+
config = {
|
|
326
|
+
database,
|
|
327
|
+
migrationTool,
|
|
328
|
+
generateTypes,
|
|
329
|
+
migrationsPath,
|
|
330
|
+
typesPath,
|
|
331
|
+
schemasDir: schemasDir2
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
logger.newline();
|
|
335
|
+
logger.step("Creating project files...");
|
|
336
|
+
const schemasDir = (0, import_node_path.resolve)(cwd, config.schemasDir);
|
|
235
337
|
if (!(0, import_node_fs.existsSync)(schemasDir)) {
|
|
236
338
|
(0, import_node_fs.mkdirSync)(schemasDir, { recursive: true });
|
|
237
|
-
logger.
|
|
238
|
-
} else {
|
|
239
|
-
logger.debug("schemas/ directory already exists");
|
|
339
|
+
logger.debug(`Created ${config.schemasDir}/ directory`);
|
|
240
340
|
}
|
|
241
341
|
const examplePath = (0, import_node_path.resolve)(schemasDir, "User.yaml");
|
|
242
342
|
if (!(0, import_node_fs.existsSync)(examplePath) || options.force) {
|
|
243
343
|
(0, import_node_fs.writeFileSync)(examplePath, EXAMPLE_SCHEMA);
|
|
244
|
-
logger.
|
|
245
|
-
} else {
|
|
246
|
-
logger.debug("Example schema already exists");
|
|
344
|
+
logger.debug("Created example schema: User.yaml");
|
|
247
345
|
}
|
|
248
|
-
|
|
249
|
-
|
|
346
|
+
const configContent = generateConfig(config);
|
|
347
|
+
(0, import_node_fs.writeFileSync)(configPath2, configContent);
|
|
348
|
+
logger.debug("Created omnify.config.ts");
|
|
250
349
|
logger.newline();
|
|
251
|
-
logger.success("Project initialized
|
|
350
|
+
logger.success("Project initialized!");
|
|
252
351
|
logger.newline();
|
|
253
|
-
|
|
352
|
+
const toolName = config.migrationTool === "laravel" ? "Laravel" : config.migrationTool === "prisma" ? "Prisma" : config.migrationTool === "drizzle" ? "Drizzle" : "None";
|
|
353
|
+
logger.info("Configuration:");
|
|
254
354
|
logger.list([
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
'Run "omnify diff" to preview changes',
|
|
259
|
-
'Run "omnify generate" to create migrations and types'
|
|
355
|
+
`Database: ${config.database}`,
|
|
356
|
+
`Migration tool: ${toolName}`,
|
|
357
|
+
`TypeScript types: ${config.generateTypes ? "Yes" : "No"}`
|
|
260
358
|
]);
|
|
359
|
+
logger.newline();
|
|
360
|
+
logger.info("Files created:");
|
|
361
|
+
logger.list(["omnify.config.ts", `${config.schemasDir}/User.yaml`]);
|
|
362
|
+
logger.newline();
|
|
363
|
+
logger.info("Next steps:");
|
|
364
|
+
logger.newline();
|
|
365
|
+
logger.step("1. Set database URL in omnify.config.ts");
|
|
366
|
+
logger.newline();
|
|
367
|
+
logger.step("2. Define schemas in " + config.schemasDir + "/");
|
|
368
|
+
logger.newline();
|
|
369
|
+
logger.step("3. Generate:");
|
|
370
|
+
logger.info(" npx omnify validate");
|
|
371
|
+
logger.info(" npx omnify generate");
|
|
372
|
+
logger.newline();
|
|
261
373
|
}
|
|
262
374
|
function registerInitCommand(program2) {
|
|
263
|
-
program2.command("init").description("Initialize a new omnify project").option("-f, --force", "Overwrite existing files").action(async (options) => {
|
|
375
|
+
program2.command("init").description("Initialize a new omnify project").option("-f, --force", "Overwrite existing files").option("-y, --yes", "Use default configuration (skip prompts)").action(async (options) => {
|
|
264
376
|
try {
|
|
265
377
|
await runInit(options);
|
|
266
378
|
} catch (error) {
|
|
267
379
|
if (error instanceof Error) {
|
|
380
|
+
if (error.message.includes("User force closed")) {
|
|
381
|
+
logger.newline();
|
|
382
|
+
logger.info("Setup cancelled.");
|
|
383
|
+
process.exit(0);
|
|
384
|
+
}
|
|
268
385
|
logger.error(error.message);
|
|
269
386
|
}
|
|
270
387
|
process.exit(1);
|
|
@@ -290,20 +407,20 @@ var CONFIG_FILES = [
|
|
|
290
407
|
function findConfigFile(startDir) {
|
|
291
408
|
const cwd = (0, import_node_path2.resolve)(startDir);
|
|
292
409
|
for (const filename of CONFIG_FILES) {
|
|
293
|
-
const
|
|
294
|
-
if ((0, import_node_fs2.existsSync)(
|
|
295
|
-
return
|
|
410
|
+
const configPath2 = (0, import_node_path2.resolve)(cwd, filename);
|
|
411
|
+
if ((0, import_node_fs2.existsSync)(configPath2)) {
|
|
412
|
+
return configPath2;
|
|
296
413
|
}
|
|
297
414
|
}
|
|
298
415
|
return null;
|
|
299
416
|
}
|
|
300
|
-
async function loadConfigFile(
|
|
301
|
-
const jiti = (0, import_jiti.createJiti)(
|
|
417
|
+
async function loadConfigFile(configPath2) {
|
|
418
|
+
const jiti = (0, import_jiti.createJiti)(configPath2, {
|
|
302
419
|
interopDefault: true,
|
|
303
420
|
moduleCache: false
|
|
304
421
|
});
|
|
305
422
|
try {
|
|
306
|
-
const module2 = await jiti.import(
|
|
423
|
+
const module2 = await jiti.import(configPath2);
|
|
307
424
|
const config = module2;
|
|
308
425
|
if ("default" in config) {
|
|
309
426
|
return config.default;
|
|
@@ -317,12 +434,12 @@ async function loadConfigFile(configPath) {
|
|
|
317
434
|
);
|
|
318
435
|
}
|
|
319
436
|
}
|
|
320
|
-
async function resolvePlugins(plugins,
|
|
437
|
+
async function resolvePlugins(plugins, configPath2) {
|
|
321
438
|
if (!plugins || plugins.length === 0) {
|
|
322
439
|
return [];
|
|
323
440
|
}
|
|
324
441
|
const resolved = [];
|
|
325
|
-
const configDir =
|
|
442
|
+
const configDir = configPath2 ? (0, import_node_path2.dirname)(configPath2) : process.cwd();
|
|
326
443
|
for (const plugin of plugins) {
|
|
327
444
|
if (typeof plugin === "string") {
|
|
328
445
|
const jiti = (0, import_jiti.createJiti)(configDir, {
|
|
@@ -346,8 +463,8 @@ async function resolvePlugins(plugins, configPath) {
|
|
|
346
463
|
}
|
|
347
464
|
return resolved;
|
|
348
465
|
}
|
|
349
|
-
async function resolveConfig(userConfig,
|
|
350
|
-
const plugins = await resolvePlugins(userConfig.plugins,
|
|
466
|
+
async function resolveConfig(userConfig, configPath2) {
|
|
467
|
+
const plugins = await resolvePlugins(userConfig.plugins, configPath2);
|
|
351
468
|
const databaseConfig = {
|
|
352
469
|
driver: userConfig.database.driver,
|
|
353
470
|
enableFieldComments: userConfig.database.enableFieldComments ?? false
|
|
@@ -414,13 +531,13 @@ function requireDevUrl(config) {
|
|
|
414
531
|
}
|
|
415
532
|
async function loadConfig(startDir = process.cwd()) {
|
|
416
533
|
const cwd = (0, import_node_path2.resolve)(startDir);
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
419
|
-
const userConfig = await loadConfigFile(
|
|
420
|
-
const config = await resolveConfig(userConfig,
|
|
534
|
+
const configPath2 = findConfigFile(cwd);
|
|
535
|
+
if (configPath2) {
|
|
536
|
+
const userConfig = await loadConfigFile(configPath2);
|
|
537
|
+
const config = await resolveConfig(userConfig, configPath2);
|
|
421
538
|
return {
|
|
422
539
|
config,
|
|
423
|
-
configPath
|
|
540
|
+
configPath: configPath2
|
|
424
541
|
};
|
|
425
542
|
}
|
|
426
543
|
throw (0, import_omnify_core2.configNotFoundError)((0, import_node_path2.resolve)(cwd, "omnify.config.ts"));
|
|
@@ -435,9 +552,9 @@ async function runValidate(options) {
|
|
|
435
552
|
logger.header("Validating Schemas");
|
|
436
553
|
logger.debug("Loading configuration...");
|
|
437
554
|
logger.timing("Config load start");
|
|
438
|
-
const { config, configPath } = await loadConfig();
|
|
555
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
439
556
|
logger.timing("Config loaded");
|
|
440
|
-
const rootDir =
|
|
557
|
+
const rootDir = configPath2 ? (0, import_node_path3.dirname)(configPath2) : process.cwd();
|
|
441
558
|
validateConfig(config, rootDir);
|
|
442
559
|
const schemaPath = (0, import_node_path3.resolve)(rootDir, config.schemasDir);
|
|
443
560
|
logger.step(`Loading schemas from ${schemaPath}`);
|
|
@@ -516,8 +633,8 @@ async function runDiff(options) {
|
|
|
516
633
|
logger.setVerbose(options.verbose ?? false);
|
|
517
634
|
logger.header("Checking for Schema Changes");
|
|
518
635
|
logger.debug("Loading configuration...");
|
|
519
|
-
const { config, configPath } = await loadConfig();
|
|
520
|
-
const rootDir =
|
|
636
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
637
|
+
const rootDir = configPath2 ? (0, import_node_path4.dirname)(configPath2) : process.cwd();
|
|
521
638
|
validateConfig(config, rootDir);
|
|
522
639
|
requireDevUrl(config);
|
|
523
640
|
const schemaPath = (0, import_node_path4.resolve)(rootDir, config.schemasDir);
|
|
@@ -591,12 +708,94 @@ var import_node_path5 = require("path");
|
|
|
591
708
|
var import_omnify_core5 = require("@famgia/omnify-core");
|
|
592
709
|
var import_omnify_atlas2 = require("@famgia/omnify-atlas");
|
|
593
710
|
var import_omnify_laravel = require("@famgia/omnify-laravel");
|
|
711
|
+
function hasPluginGenerators(plugins) {
|
|
712
|
+
return plugins.some((p) => p.generators && p.generators.length > 0);
|
|
713
|
+
}
|
|
714
|
+
function writeGeneratorOutputs(outputs, rootDir) {
|
|
715
|
+
const counts = { migrations: 0, types: 0, other: 0 };
|
|
716
|
+
for (const output of outputs) {
|
|
717
|
+
const filePath = (0, import_node_path5.resolve)(rootDir, output.path);
|
|
718
|
+
const dir = (0, import_node_path5.dirname)(filePath);
|
|
719
|
+
if (!(0, import_node_fs3.existsSync)(dir)) {
|
|
720
|
+
(0, import_node_fs3.mkdirSync)(dir, { recursive: true });
|
|
721
|
+
logger.debug(`Created directory: ${dir}`);
|
|
722
|
+
}
|
|
723
|
+
(0, import_node_fs3.writeFileSync)(filePath, output.content);
|
|
724
|
+
logger.debug(`Created: ${output.path}`);
|
|
725
|
+
if (output.type === "migration") counts.migrations++;
|
|
726
|
+
else if (output.type === "type") counts.types++;
|
|
727
|
+
else counts.other++;
|
|
728
|
+
}
|
|
729
|
+
return counts;
|
|
730
|
+
}
|
|
731
|
+
async function runPluginGeneration(plugins, schemas, rootDir, verbose) {
|
|
732
|
+
const pluginManager = new import_omnify_core5.PluginManager({
|
|
733
|
+
cwd: rootDir,
|
|
734
|
+
verbose,
|
|
735
|
+
logger: {
|
|
736
|
+
debug: (msg) => logger.debug(msg),
|
|
737
|
+
info: (msg) => logger.info(msg),
|
|
738
|
+
warn: (msg) => logger.warn(msg),
|
|
739
|
+
error: (msg) => logger.error(msg)
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
for (const plugin of plugins) {
|
|
743
|
+
await pluginManager.register(plugin);
|
|
744
|
+
}
|
|
745
|
+
const result = await pluginManager.runGenerators(schemas);
|
|
746
|
+
if (!result.success) {
|
|
747
|
+
for (const error of result.errors) {
|
|
748
|
+
logger.error(`Generator ${error.generatorName} failed: ${error.message}`);
|
|
749
|
+
}
|
|
750
|
+
throw new Error("Generator execution failed");
|
|
751
|
+
}
|
|
752
|
+
return writeGeneratorOutputs(result.outputs, rootDir);
|
|
753
|
+
}
|
|
754
|
+
function runDirectGeneration(schemas, config, rootDir, options) {
|
|
755
|
+
let migrationsGenerated = 0;
|
|
756
|
+
let typesGenerated = 0;
|
|
757
|
+
if (!options.typesOnly) {
|
|
758
|
+
logger.step("Generating Laravel migrations...");
|
|
759
|
+
const migrationsDir = (0, import_node_path5.resolve)(rootDir, config.output.laravel.migrationsPath);
|
|
760
|
+
if (!(0, import_node_fs3.existsSync)(migrationsDir)) {
|
|
761
|
+
(0, import_node_fs3.mkdirSync)(migrationsDir, { recursive: true });
|
|
762
|
+
logger.debug(`Created directory: ${migrationsDir}`);
|
|
763
|
+
}
|
|
764
|
+
const migrations = (0, import_omnify_laravel.generateMigrations)(schemas);
|
|
765
|
+
for (const migration of migrations) {
|
|
766
|
+
const filePath = (0, import_node_path5.resolve)(migrationsDir, migration.fileName);
|
|
767
|
+
(0, import_node_fs3.writeFileSync)(filePath, migration.content);
|
|
768
|
+
logger.debug(`Created: ${migration.fileName}`);
|
|
769
|
+
migrationsGenerated++;
|
|
770
|
+
}
|
|
771
|
+
logger.success(`Generated ${migrationsGenerated} migration(s)`);
|
|
772
|
+
}
|
|
773
|
+
if (!options.migrationsOnly) {
|
|
774
|
+
logger.step("Generating TypeScript types...");
|
|
775
|
+
const typesDir = (0, import_node_path5.resolve)(rootDir, config.output.typescript.path);
|
|
776
|
+
if (!(0, import_node_fs3.existsSync)(typesDir)) {
|
|
777
|
+
(0, import_node_fs3.mkdirSync)(typesDir, { recursive: true });
|
|
778
|
+
logger.debug(`Created directory: ${typesDir}`);
|
|
779
|
+
}
|
|
780
|
+
const typeFiles = (0, import_omnify_laravel.generateTypeScript)(schemas, {
|
|
781
|
+
singleFile: config.output.typescript.singleFile
|
|
782
|
+
});
|
|
783
|
+
for (const file of typeFiles) {
|
|
784
|
+
const filePath = (0, import_node_path5.resolve)(typesDir, file.fileName);
|
|
785
|
+
(0, import_node_fs3.writeFileSync)(filePath, file.content);
|
|
786
|
+
logger.debug(`Created: ${file.fileName}`);
|
|
787
|
+
typesGenerated++;
|
|
788
|
+
}
|
|
789
|
+
logger.success(`Generated ${typesGenerated} TypeScript file(s)`);
|
|
790
|
+
}
|
|
791
|
+
return { migrations: migrationsGenerated, types: typesGenerated };
|
|
792
|
+
}
|
|
594
793
|
async function runGenerate(options) {
|
|
595
794
|
logger.setVerbose(options.verbose ?? false);
|
|
596
795
|
logger.header("Generating Outputs");
|
|
597
796
|
logger.debug("Loading configuration...");
|
|
598
|
-
const { config, configPath } = await loadConfig();
|
|
599
|
-
const rootDir =
|
|
797
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
798
|
+
const rootDir = configPath2 ? (0, import_node_path5.dirname)(configPath2) : process.cwd();
|
|
600
799
|
validateConfig(config, rootDir);
|
|
601
800
|
requireDevUrl(config);
|
|
602
801
|
const schemaPath = (0, import_node_path5.resolve)(rootDir, config.schemasDir);
|
|
@@ -633,39 +832,30 @@ async function runGenerate(options) {
|
|
|
633
832
|
}
|
|
634
833
|
let migrationsGenerated = 0;
|
|
635
834
|
let typesGenerated = 0;
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
835
|
+
const usePlugins = hasPluginGenerators(config.plugins);
|
|
836
|
+
if (usePlugins) {
|
|
837
|
+
logger.step("Running plugin generators...");
|
|
838
|
+
const counts = await runPluginGeneration(
|
|
839
|
+
config.plugins,
|
|
840
|
+
schemas,
|
|
841
|
+
rootDir,
|
|
842
|
+
options.verbose ?? false
|
|
843
|
+
);
|
|
844
|
+
migrationsGenerated = counts.migrations;
|
|
845
|
+
typesGenerated = counts.types;
|
|
846
|
+
if (counts.migrations > 0) {
|
|
847
|
+
logger.success(`Generated ${counts.migrations} migration(s)`);
|
|
649
848
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (!options.migrationsOnly) {
|
|
653
|
-
logger.step("Generating TypeScript types...");
|
|
654
|
-
const typesDir = (0, import_node_path5.resolve)(rootDir, config.output.typescript.path);
|
|
655
|
-
if (!(0, import_node_fs3.existsSync)(typesDir)) {
|
|
656
|
-
(0, import_node_fs3.mkdirSync)(typesDir, { recursive: true });
|
|
657
|
-
logger.debug(`Created directory: ${typesDir}`);
|
|
849
|
+
if (counts.types > 0) {
|
|
850
|
+
logger.success(`Generated ${counts.types} TypeScript file(s)`);
|
|
658
851
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
});
|
|
662
|
-
for (const file of typeFiles) {
|
|
663
|
-
const filePath = (0, import_node_path5.resolve)(typesDir, file.fileName);
|
|
664
|
-
(0, import_node_fs3.writeFileSync)(filePath, file.content);
|
|
665
|
-
logger.debug(`Created: ${file.fileName}`);
|
|
666
|
-
typesGenerated++;
|
|
852
|
+
if (counts.other > 0) {
|
|
853
|
+
logger.success(`Generated ${counts.other} other file(s)`);
|
|
667
854
|
}
|
|
668
|
-
|
|
855
|
+
} else {
|
|
856
|
+
const counts = runDirectGeneration(schemas, config, rootDir, options);
|
|
857
|
+
migrationsGenerated = counts.migrations;
|
|
858
|
+
typesGenerated = counts.types;
|
|
669
859
|
}
|
|
670
860
|
logger.step("Updating lock file...");
|
|
671
861
|
await (0, import_omnify_atlas2.updateLockFile)(lockPath, schemas);
|
|
@@ -724,7 +914,26 @@ process.on("unhandledRejection", (reason) => {
|
|
|
724
914
|
}
|
|
725
915
|
process.exit(1);
|
|
726
916
|
});
|
|
727
|
-
|
|
917
|
+
var args = process.argv.slice(2);
|
|
918
|
+
var firstArg = args[0];
|
|
919
|
+
var hasCommand = firstArg !== void 0 && !firstArg.startsWith("-");
|
|
920
|
+
var configPath = (0, import_node_path6.resolve)(process.cwd(), "omnify.config.ts");
|
|
921
|
+
var hasConfig = (0, import_node_fs4.existsSync)(configPath);
|
|
922
|
+
if (!hasCommand && !hasConfig) {
|
|
923
|
+
runInit({}).catch((error) => {
|
|
924
|
+
if (error instanceof Error) {
|
|
925
|
+
if (error.message.includes("User force closed")) {
|
|
926
|
+
logger.newline();
|
|
927
|
+
logger.info("Setup cancelled.");
|
|
928
|
+
process.exit(0);
|
|
929
|
+
}
|
|
930
|
+
logger.error(error.message);
|
|
931
|
+
}
|
|
932
|
+
process.exit(1);
|
|
933
|
+
});
|
|
934
|
+
} else {
|
|
935
|
+
program.parse();
|
|
936
|
+
}
|
|
728
937
|
// Annotate the CommonJS export names for ESM import in node:
|
|
729
938
|
0 && (module.exports = {
|
|
730
939
|
defineConfig,
|