@noego/proper 0.0.4 → 0.0.6
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/bin/cli.js +55 -17
- package/bin/cli.js.map +1 -1
- package/bin/cli.mjs +55 -17
- package/bin/cli.mjs.map +1 -1
- package/bin/index.d.mts +11 -1
- package/bin/index.d.ts +11 -1
- package/bin/index.js +54 -17
- package/bin/index.js.map +1 -1
- package/bin/index.mjs +60 -17
- package/bin/index.mjs.map +1 -1
- package/package.json +2 -1
package/bin/cli.js
CHANGED
|
@@ -73,6 +73,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
73
73
|
|
|
74
74
|
// cli.ts
|
|
75
75
|
var import_register = require("source-map-support/register");
|
|
76
|
+
var import_cjs = require("tsx/cjs");
|
|
76
77
|
|
|
77
78
|
// framework/MigrationCLi.ts
|
|
78
79
|
var import_minimist = __toESM(require("minimist"));
|
|
@@ -408,26 +409,50 @@ var SqlMigrationBuilder = class {
|
|
|
408
409
|
|
|
409
410
|
// framework/MigrationDirectoryReader.ts
|
|
410
411
|
var MigrationDirectoryReader = class {
|
|
411
|
-
constructor(directory, read_strategy, sqlrunner) {
|
|
412
|
+
constructor(directory, read_strategy, sqlrunner, dialect = "sql") {
|
|
412
413
|
this.directory = directory;
|
|
413
414
|
this.read_strategy = read_strategy;
|
|
414
415
|
this.sqlrunner = sqlrunner;
|
|
416
|
+
this.dialect = dialect;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Resolves the appropriate file for a migration based on dialect.
|
|
420
|
+
* Priority: dialect-specific file > generic file
|
|
421
|
+
*/
|
|
422
|
+
resolveFile(baseName, direction) {
|
|
423
|
+
const dialectExt = this.dialect === "sql" ? "mysql" : "sqlite";
|
|
424
|
+
const dialectFile = import_path.default.join(this.directory, `${baseName}.${dialectExt}.${direction}.sql`);
|
|
425
|
+
if (import_fs.default.existsSync(dialectFile)) return dialectFile;
|
|
426
|
+
const genericFile = import_path.default.join(this.directory, `${baseName}.${direction}.sql`);
|
|
427
|
+
if (import_fs.default.existsSync(genericFile)) return genericFile;
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Checks if a file path is dialect-specific (contains .mysql. or .sqlite. in the name)
|
|
432
|
+
*/
|
|
433
|
+
isDialectSpecific(filePath) {
|
|
434
|
+
return /\.(mysql|sqlite)\.(up|down)\.sql$/i.test(filePath);
|
|
415
435
|
}
|
|
416
436
|
loadMigrations(table, connection) {
|
|
417
437
|
import_fs.default.existsSync(this.directory) || import_fs.default.mkdirSync(this.directory);
|
|
418
438
|
const dir_content = import_fs.default.readdirSync(this.directory, { withFileTypes: true }).filter((file) => file.isFile()).map((file) => file.name);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
file
|
|
425
|
-
};
|
|
426
|
-
}).sort();
|
|
439
|
+
const uniqueKeys = /* @__PURE__ */ new Set();
|
|
440
|
+
dir_content.forEach((file) => {
|
|
441
|
+
const key = file.replace(/(?:\.(mysql|sqlite))?\.(up|down)\.(sql|js)/i, "").toLowerCase();
|
|
442
|
+
uniqueKeys.add(key);
|
|
443
|
+
});
|
|
427
444
|
const migration_sorter = {};
|
|
428
|
-
|
|
429
|
-
const builder =
|
|
430
|
-
this.
|
|
445
|
+
uniqueKeys.forEach((migration_key) => {
|
|
446
|
+
const builder = new SqlMigrationBuilder(migration_key);
|
|
447
|
+
const upFile = this.resolveFile(migration_key, "up");
|
|
448
|
+
const downFile = this.resolveFile(migration_key, "down");
|
|
449
|
+
if (upFile) {
|
|
450
|
+
this.loadMigration(builder, upFile);
|
|
451
|
+
}
|
|
452
|
+
if (downFile) {
|
|
453
|
+
this.loadMigration(builder, downFile);
|
|
454
|
+
}
|
|
455
|
+
migration_sorter[migration_key] = builder;
|
|
431
456
|
});
|
|
432
457
|
const keys = Object.keys(migration_sorter);
|
|
433
458
|
keys.sort();
|
|
@@ -454,12 +479,16 @@ var MigrationDirectoryReader = class {
|
|
|
454
479
|
}
|
|
455
480
|
sql_up(file) {
|
|
456
481
|
let content = import_fs.default.readFileSync(file).toString();
|
|
457
|
-
|
|
482
|
+
if (!this.isDialectSpecific(file)) {
|
|
483
|
+
content = this.read_strategy(content);
|
|
484
|
+
}
|
|
458
485
|
return content.trim();
|
|
459
486
|
}
|
|
460
487
|
sql_down(file) {
|
|
461
488
|
let content = import_fs.default.readFileSync(file).toString();
|
|
462
|
-
|
|
489
|
+
if (!this.isDialectSpecific(file)) {
|
|
490
|
+
content = this.read_strategy(content);
|
|
491
|
+
}
|
|
463
492
|
return content.trim();
|
|
464
493
|
}
|
|
465
494
|
};
|
|
@@ -837,7 +866,7 @@ var MigrationRunnerFactory = class _MigrationRunnerFactory {
|
|
|
837
866
|
}
|
|
838
867
|
const setup = new MigrationSetup(sqlrunner, config);
|
|
839
868
|
const read_strategy = this.getReadStategy(config);
|
|
840
|
-
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner);
|
|
869
|
+
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner, config.database);
|
|
841
870
|
yield setup.setup();
|
|
842
871
|
return new MySQLMigrationRunner(config, migration_files, setup, sqlrunner, driverConnection);
|
|
843
872
|
});
|
|
@@ -858,7 +887,7 @@ var MigrationRunnerFactory = class _MigrationRunnerFactory {
|
|
|
858
887
|
}
|
|
859
888
|
const setup = new MigrationSetup(sqlrunner, config);
|
|
860
889
|
const read_strategy = this.getReadStategy(config);
|
|
861
|
-
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner);
|
|
890
|
+
const migration_files = new MigrationDirectoryReader(config.migration_folder, read_strategy, sqlrunner, config.database);
|
|
862
891
|
return new MySQLMigrationRunner(config, migration_files, setup, sqlrunner, conn);
|
|
863
892
|
});
|
|
864
893
|
}
|
|
@@ -1242,10 +1271,19 @@ function runSqlSeed(runner, resolved, direction) {
|
|
|
1242
1271
|
yield runner.query(sql);
|
|
1243
1272
|
});
|
|
1244
1273
|
}
|
|
1274
|
+
function loadSeedModule(modulePath) {
|
|
1275
|
+
return __async(this, null, function* () {
|
|
1276
|
+
const resolved = import_path2.default.resolve(modulePath);
|
|
1277
|
+
if (resolved.endsWith(".ts")) {
|
|
1278
|
+
return require(resolved);
|
|
1279
|
+
}
|
|
1280
|
+
return import(resolved);
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1245
1283
|
function runModuleSeed(runner, resolved, migrationConfig, options, direction) {
|
|
1246
1284
|
return __async(this, null, function* () {
|
|
1247
1285
|
const { log } = options;
|
|
1248
|
-
const module2 = yield
|
|
1286
|
+
const module2 = yield loadSeedModule(resolved.upPath);
|
|
1249
1287
|
const handler = module2[direction];
|
|
1250
1288
|
if (typeof handler !== "function") {
|
|
1251
1289
|
throw new Error(`Seed module "${resolved.name}" does not export ${direction}()`);
|