ilana-orm 1.0.1 → 1.0.2
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/cli/ilana.js +77 -1
- package/package.json +1 -1
package/cli/ilana.js
CHANGED
|
@@ -64,6 +64,19 @@ function isTypeScriptProject() {
|
|
|
64
64
|
return fs.existsSync(path.join(process.cwd(), 'tsconfig.json'));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
function isESModuleProject() {
|
|
68
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
69
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
70
|
+
try {
|
|
71
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
72
|
+
return packageJson.type === 'module';
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
function getFileExtension() {
|
|
68
81
|
return isTypeScriptProject() ? '.ts' : '.js';
|
|
69
82
|
}
|
|
@@ -339,7 +352,69 @@ const commands = {
|
|
|
339
352
|
// Create config file if it doesn't exist
|
|
340
353
|
const configPath = 'ilana.config.js';
|
|
341
354
|
if (!fs.existsSync(configPath)) {
|
|
342
|
-
const
|
|
355
|
+
const isESModule = isESModuleProject();
|
|
356
|
+
const configTemplate = isESModule ? getESModuleConfigTemplate() : getCommonJSConfigTemplate();
|
|
357
|
+
|
|
358
|
+
function getESModuleConfigTemplate() {
|
|
359
|
+
return `import 'dotenv/config';
|
|
360
|
+
import Database from 'ilana-orm/database/connection';
|
|
361
|
+
|
|
362
|
+
const config = {
|
|
363
|
+
default: process.env.DB_CONNECTION || 'mysql',
|
|
364
|
+
timezone: process.env.DB_TIMEZONE || 'UTC',
|
|
365
|
+
|
|
366
|
+
connections: {
|
|
367
|
+
sqlite: {
|
|
368
|
+
client: 'sqlite3',
|
|
369
|
+
connection: {
|
|
370
|
+
filename: process.env.DB_FILENAME || './database.sqlite'
|
|
371
|
+
},
|
|
372
|
+
useNullAsDefault: true
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
mysql: {
|
|
376
|
+
client: 'mysql2',
|
|
377
|
+
connection: {
|
|
378
|
+
host: process.env.DB_HOST || 'localhost',
|
|
379
|
+
port: process.env.DB_PORT || 3306,
|
|
380
|
+
user: process.env.DB_USERNAME || 'root',
|
|
381
|
+
password: process.env.DB_PASSWORD || '',
|
|
382
|
+
database: process.env.DB_DATABASE || 'your_database',
|
|
383
|
+
timezone: process.env.DB_TIMEZONE || 'UTC'
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
postgres: {
|
|
388
|
+
client: 'pg',
|
|
389
|
+
connection: {
|
|
390
|
+
host: process.env.DB_HOST || 'localhost',
|
|
391
|
+
port: process.env.DB_PORT || 5432,
|
|
392
|
+
user: process.env.DB_USERNAME || 'postgres',
|
|
393
|
+
password: process.env.DB_PASSWORD || '',
|
|
394
|
+
database: process.env.DB_DATABASE || 'your_database'
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
migrations: {
|
|
400
|
+
directory: './database/migrations',
|
|
401
|
+
tableName: 'migrations'
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
seeds: {
|
|
405
|
+
directory: './database/seeds'
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// Auto-initialize database connections
|
|
410
|
+
Database.configure(config);
|
|
411
|
+
|
|
412
|
+
export default config;
|
|
413
|
+
`;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function getCommonJSConfigTemplate() {
|
|
417
|
+
return `require('dotenv').config();
|
|
343
418
|
const Database = require('ilana-orm/database/connection');
|
|
344
419
|
|
|
345
420
|
const config = {
|
|
@@ -394,6 +469,7 @@ Database.configure(config);
|
|
|
394
469
|
|
|
395
470
|
module.exports = config;
|
|
396
471
|
`;
|
|
472
|
+
}
|
|
397
473
|
fs.writeFileSync(configPath, configTemplate);
|
|
398
474
|
console.log(`Created config file: ${configPath}`);
|
|
399
475
|
}
|