@famgia/omnify-cli 0.0.4 → 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 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +307 -92
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -35,12 +35,15 @@ __export(index_exports, {
|
|
|
35
35
|
loadConfig: () => loadConfig
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_node_fs4 = require("fs");
|
|
39
|
+
var import_node_path6 = require("path");
|
|
38
40
|
var import_commander = require("commander");
|
|
39
41
|
var import_omnify_core6 = require("@famgia/omnify-core");
|
|
40
42
|
|
|
41
43
|
// src/commands/init.ts
|
|
42
44
|
var import_node_fs = require("fs");
|
|
43
45
|
var import_node_path = require("path");
|
|
46
|
+
var import_prompts = require("@inquirer/prompts");
|
|
44
47
|
|
|
45
48
|
// src/output/logger.ts
|
|
46
49
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
@@ -167,7 +170,7 @@ var logger = new Logger();
|
|
|
167
170
|
|
|
168
171
|
// src/commands/init.ts
|
|
169
172
|
var EXAMPLE_SCHEMA = `# Example User schema
|
|
170
|
-
# See https://
|
|
173
|
+
# See https://github.com/famgia/omnify for documentation
|
|
171
174
|
|
|
172
175
|
name: User
|
|
173
176
|
displayName: User Account
|
|
@@ -192,78 +195,193 @@ options:
|
|
|
192
195
|
timestamps: true
|
|
193
196
|
softDelete: true
|
|
194
197
|
`;
|
|
195
|
-
|
|
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")}
|
|
196
233
|
|
|
197
234
|
export default defineConfig({
|
|
198
235
|
// Schema files location
|
|
199
|
-
schemasDir: '
|
|
236
|
+
schemasDir: '${config.schemasDir}',
|
|
237
|
+
|
|
238
|
+
// Lock file for tracking schema changes
|
|
239
|
+
lockFilePath: './omnify.lock',
|
|
200
240
|
|
|
201
241
|
// Database configuration
|
|
202
242
|
database: {
|
|
203
|
-
driver: '
|
|
204
|
-
//
|
|
205
|
-
// devUrl: '
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
// Output configuration
|
|
209
|
-
output: {
|
|
210
|
-
laravel: {
|
|
211
|
-
migrationsPath: 'database/migrations',
|
|
212
|
-
},
|
|
213
|
-
typescript: {
|
|
214
|
-
path: 'types',
|
|
215
|
-
singleFile: true,
|
|
216
|
-
},
|
|
243
|
+
driver: '${config.database}',
|
|
244
|
+
// REQUIRED: Set your development database URL
|
|
245
|
+
// devUrl: '${dbUrlExamples[config.database]}',
|
|
217
246
|
},
|
|
218
247
|
|
|
219
|
-
//
|
|
248
|
+
// Generator plugins
|
|
220
249
|
plugins: [
|
|
221
|
-
|
|
250
|
+
${plugins.join("\n\n")}
|
|
222
251
|
],
|
|
223
252
|
});
|
|
224
253
|
`;
|
|
254
|
+
}
|
|
225
255
|
async function runInit(options) {
|
|
226
256
|
const cwd = process.cwd();
|
|
227
|
-
logger.header("
|
|
228
|
-
|
|
229
|
-
|
|
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) {
|
|
230
261
|
logger.warn("omnify.config.ts already exists. Use --force to overwrite.");
|
|
231
262
|
return;
|
|
232
263
|
}
|
|
233
|
-
|
|
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);
|
|
234
337
|
if (!(0, import_node_fs.existsSync)(schemasDir)) {
|
|
235
338
|
(0, import_node_fs.mkdirSync)(schemasDir, { recursive: true });
|
|
236
|
-
logger.
|
|
237
|
-
} else {
|
|
238
|
-
logger.debug("schemas/ directory already exists");
|
|
339
|
+
logger.debug(`Created ${config.schemasDir}/ directory`);
|
|
239
340
|
}
|
|
240
341
|
const examplePath = (0, import_node_path.resolve)(schemasDir, "User.yaml");
|
|
241
342
|
if (!(0, import_node_fs.existsSync)(examplePath) || options.force) {
|
|
242
343
|
(0, import_node_fs.writeFileSync)(examplePath, EXAMPLE_SCHEMA);
|
|
243
|
-
logger.
|
|
244
|
-
} else {
|
|
245
|
-
logger.debug("Example schema already exists");
|
|
344
|
+
logger.debug("Created example schema: User.yaml");
|
|
246
345
|
}
|
|
247
|
-
|
|
248
|
-
|
|
346
|
+
const configContent = generateConfig(config);
|
|
347
|
+
(0, import_node_fs.writeFileSync)(configPath2, configContent);
|
|
348
|
+
logger.debug("Created omnify.config.ts");
|
|
249
349
|
logger.newline();
|
|
250
|
-
logger.success("Project initialized
|
|
350
|
+
logger.success("Project initialized!");
|
|
251
351
|
logger.newline();
|
|
252
|
-
|
|
352
|
+
const toolName = config.migrationTool === "laravel" ? "Laravel" : config.migrationTool === "prisma" ? "Prisma" : config.migrationTool === "drizzle" ? "Drizzle" : "None";
|
|
353
|
+
logger.info("Configuration:");
|
|
253
354
|
logger.list([
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
'Run "omnify diff" to preview changes',
|
|
258
|
-
'Run "omnify generate" to create migrations and types'
|
|
355
|
+
`Database: ${config.database}`,
|
|
356
|
+
`Migration tool: ${toolName}`,
|
|
357
|
+
`TypeScript types: ${config.generateTypes ? "Yes" : "No"}`
|
|
259
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();
|
|
260
373
|
}
|
|
261
374
|
function registerInitCommand(program2) {
|
|
262
|
-
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) => {
|
|
263
376
|
try {
|
|
264
377
|
await runInit(options);
|
|
265
378
|
} catch (error) {
|
|
266
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
|
+
}
|
|
267
385
|
logger.error(error.message);
|
|
268
386
|
}
|
|
269
387
|
process.exit(1);
|
|
@@ -289,20 +407,20 @@ var CONFIG_FILES = [
|
|
|
289
407
|
function findConfigFile(startDir) {
|
|
290
408
|
const cwd = (0, import_node_path2.resolve)(startDir);
|
|
291
409
|
for (const filename of CONFIG_FILES) {
|
|
292
|
-
const
|
|
293
|
-
if ((0, import_node_fs2.existsSync)(
|
|
294
|
-
return
|
|
410
|
+
const configPath2 = (0, import_node_path2.resolve)(cwd, filename);
|
|
411
|
+
if ((0, import_node_fs2.existsSync)(configPath2)) {
|
|
412
|
+
return configPath2;
|
|
295
413
|
}
|
|
296
414
|
}
|
|
297
415
|
return null;
|
|
298
416
|
}
|
|
299
|
-
async function loadConfigFile(
|
|
300
|
-
const jiti = (0, import_jiti.createJiti)(
|
|
417
|
+
async function loadConfigFile(configPath2) {
|
|
418
|
+
const jiti = (0, import_jiti.createJiti)(configPath2, {
|
|
301
419
|
interopDefault: true,
|
|
302
420
|
moduleCache: false
|
|
303
421
|
});
|
|
304
422
|
try {
|
|
305
|
-
const module2 = await jiti.import(
|
|
423
|
+
const module2 = await jiti.import(configPath2);
|
|
306
424
|
const config = module2;
|
|
307
425
|
if ("default" in config) {
|
|
308
426
|
return config.default;
|
|
@@ -316,12 +434,12 @@ async function loadConfigFile(configPath) {
|
|
|
316
434
|
);
|
|
317
435
|
}
|
|
318
436
|
}
|
|
319
|
-
async function resolvePlugins(plugins,
|
|
437
|
+
async function resolvePlugins(plugins, configPath2) {
|
|
320
438
|
if (!plugins || plugins.length === 0) {
|
|
321
439
|
return [];
|
|
322
440
|
}
|
|
323
441
|
const resolved = [];
|
|
324
|
-
const configDir =
|
|
442
|
+
const configDir = configPath2 ? (0, import_node_path2.dirname)(configPath2) : process.cwd();
|
|
325
443
|
for (const plugin of plugins) {
|
|
326
444
|
if (typeof plugin === "string") {
|
|
327
445
|
const jiti = (0, import_jiti.createJiti)(configDir, {
|
|
@@ -345,8 +463,8 @@ async function resolvePlugins(plugins, configPath) {
|
|
|
345
463
|
}
|
|
346
464
|
return resolved;
|
|
347
465
|
}
|
|
348
|
-
async function resolveConfig(userConfig,
|
|
349
|
-
const plugins = await resolvePlugins(userConfig.plugins,
|
|
466
|
+
async function resolveConfig(userConfig, configPath2) {
|
|
467
|
+
const plugins = await resolvePlugins(userConfig.plugins, configPath2);
|
|
350
468
|
const databaseConfig = {
|
|
351
469
|
driver: userConfig.database.driver,
|
|
352
470
|
enableFieldComments: userConfig.database.enableFieldComments ?? false
|
|
@@ -413,13 +531,13 @@ function requireDevUrl(config) {
|
|
|
413
531
|
}
|
|
414
532
|
async function loadConfig(startDir = process.cwd()) {
|
|
415
533
|
const cwd = (0, import_node_path2.resolve)(startDir);
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
418
|
-
const userConfig = await loadConfigFile(
|
|
419
|
-
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);
|
|
420
538
|
return {
|
|
421
539
|
config,
|
|
422
|
-
configPath
|
|
540
|
+
configPath: configPath2
|
|
423
541
|
};
|
|
424
542
|
}
|
|
425
543
|
throw (0, import_omnify_core2.configNotFoundError)((0, import_node_path2.resolve)(cwd, "omnify.config.ts"));
|
|
@@ -434,9 +552,9 @@ async function runValidate(options) {
|
|
|
434
552
|
logger.header("Validating Schemas");
|
|
435
553
|
logger.debug("Loading configuration...");
|
|
436
554
|
logger.timing("Config load start");
|
|
437
|
-
const { config, configPath } = await loadConfig();
|
|
555
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
438
556
|
logger.timing("Config loaded");
|
|
439
|
-
const rootDir =
|
|
557
|
+
const rootDir = configPath2 ? (0, import_node_path3.dirname)(configPath2) : process.cwd();
|
|
440
558
|
validateConfig(config, rootDir);
|
|
441
559
|
const schemaPath = (0, import_node_path3.resolve)(rootDir, config.schemasDir);
|
|
442
560
|
logger.step(`Loading schemas from ${schemaPath}`);
|
|
@@ -515,8 +633,8 @@ async function runDiff(options) {
|
|
|
515
633
|
logger.setVerbose(options.verbose ?? false);
|
|
516
634
|
logger.header("Checking for Schema Changes");
|
|
517
635
|
logger.debug("Loading configuration...");
|
|
518
|
-
const { config, configPath } = await loadConfig();
|
|
519
|
-
const rootDir =
|
|
636
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
637
|
+
const rootDir = configPath2 ? (0, import_node_path4.dirname)(configPath2) : process.cwd();
|
|
520
638
|
validateConfig(config, rootDir);
|
|
521
639
|
requireDevUrl(config);
|
|
522
640
|
const schemaPath = (0, import_node_path4.resolve)(rootDir, config.schemasDir);
|
|
@@ -590,12 +708,94 @@ var import_node_path5 = require("path");
|
|
|
590
708
|
var import_omnify_core5 = require("@famgia/omnify-core");
|
|
591
709
|
var import_omnify_atlas2 = require("@famgia/omnify-atlas");
|
|
592
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
|
+
}
|
|
593
793
|
async function runGenerate(options) {
|
|
594
794
|
logger.setVerbose(options.verbose ?? false);
|
|
595
795
|
logger.header("Generating Outputs");
|
|
596
796
|
logger.debug("Loading configuration...");
|
|
597
|
-
const { config, configPath } = await loadConfig();
|
|
598
|
-
const rootDir =
|
|
797
|
+
const { config, configPath: configPath2 } = await loadConfig();
|
|
798
|
+
const rootDir = configPath2 ? (0, import_node_path5.dirname)(configPath2) : process.cwd();
|
|
599
799
|
validateConfig(config, rootDir);
|
|
600
800
|
requireDevUrl(config);
|
|
601
801
|
const schemaPath = (0, import_node_path5.resolve)(rootDir, config.schemasDir);
|
|
@@ -632,39 +832,30 @@ async function runGenerate(options) {
|
|
|
632
832
|
}
|
|
633
833
|
let migrationsGenerated = 0;
|
|
634
834
|
let typesGenerated = 0;
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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)`);
|
|
648
848
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (!options.migrationsOnly) {
|
|
652
|
-
logger.step("Generating TypeScript types...");
|
|
653
|
-
const typesDir = (0, import_node_path5.resolve)(rootDir, config.output.typescript.path);
|
|
654
|
-
if (!(0, import_node_fs3.existsSync)(typesDir)) {
|
|
655
|
-
(0, import_node_fs3.mkdirSync)(typesDir, { recursive: true });
|
|
656
|
-
logger.debug(`Created directory: ${typesDir}`);
|
|
849
|
+
if (counts.types > 0) {
|
|
850
|
+
logger.success(`Generated ${counts.types} TypeScript file(s)`);
|
|
657
851
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
});
|
|
661
|
-
for (const file of typeFiles) {
|
|
662
|
-
const filePath = (0, import_node_path5.resolve)(typesDir, file.fileName);
|
|
663
|
-
(0, import_node_fs3.writeFileSync)(filePath, file.content);
|
|
664
|
-
logger.debug(`Created: ${file.fileName}`);
|
|
665
|
-
typesGenerated++;
|
|
852
|
+
if (counts.other > 0) {
|
|
853
|
+
logger.success(`Generated ${counts.other} other file(s)`);
|
|
666
854
|
}
|
|
667
|
-
|
|
855
|
+
} else {
|
|
856
|
+
const counts = runDirectGeneration(schemas, config, rootDir, options);
|
|
857
|
+
migrationsGenerated = counts.migrations;
|
|
858
|
+
typesGenerated = counts.types;
|
|
668
859
|
}
|
|
669
860
|
logger.step("Updating lock file...");
|
|
670
861
|
await (0, import_omnify_atlas2.updateLockFile)(lockPath, schemas);
|
|
@@ -723,7 +914,26 @@ process.on("unhandledRejection", (reason) => {
|
|
|
723
914
|
}
|
|
724
915
|
process.exit(1);
|
|
725
916
|
});
|
|
726
|
-
|
|
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
|
+
}
|
|
727
937
|
// Annotate the CommonJS export names for ESM import in node:
|
|
728
938
|
0 && (module.exports = {
|
|
729
939
|
defineConfig,
|