@currentjs/gen 0.5.0 ā 0.5.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/CHANGELOG.md +19 -0
- package/README.md +374 -996
- package/dist/cli.js +28 -10
- package/dist/commands/createModel.d.ts +1 -0
- package/dist/commands/createModel.js +764 -0
- package/dist/commands/createModule.js +13 -0
- package/dist/commands/generateAll.d.ts +1 -0
- package/dist/commands/generateAll.js +1 -1
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/{createApp.js ā init.js} +2 -2
- package/dist/commands/migrateCommit.js +33 -68
- package/dist/generators/controllerGenerator.d.ts +7 -0
- package/dist/generators/controllerGenerator.js +56 -17
- package/dist/generators/domainLayerGenerator.js +51 -8
- package/dist/generators/dtoGenerator.js +13 -8
- package/dist/generators/serviceGenerator.d.ts +6 -0
- package/dist/generators/serviceGenerator.js +219 -23
- package/dist/generators/storeGenerator.d.ts +4 -0
- package/dist/generators/storeGenerator.js +116 -9
- package/dist/generators/templateGenerator.d.ts +1 -0
- package/dist/generators/templateGenerator.js +8 -2
- package/dist/generators/templates/appTemplates.js +1 -1
- package/dist/generators/templates/data/cursorRulesTemplate +11 -755
- package/dist/generators/templates/data/frontendScriptTemplate +11 -4
- package/dist/generators/templates/data/mainViewTemplate +1 -0
- package/dist/generators/templates/storeTemplates.d.ts +1 -1
- package/dist/generators/templates/storeTemplates.js +3 -26
- package/dist/generators/useCaseGenerator.js +6 -3
- package/dist/types/configTypes.d.ts +6 -0
- package/dist/utils/migrationUtils.d.ts +9 -19
- package/dist/utils/migrationUtils.js +80 -110
- package/dist/utils/promptUtils.d.ts +37 -0
- package/dist/utils/promptUtils.js +149 -0
- package/dist/utils/typeUtils.d.ts +4 -0
- package/dist/utils/typeUtils.js +7 -0
- package/package.json +1 -1
- package/dist/commands/createApp.d.ts +0 -1
- package/dist/commands/migratePush.d.ts +0 -1
- package/dist/commands/migratePush.js +0 -135
- package/dist/commands/migrateUpdate.d.ts +0 -1
- package/dist/commands/migrateUpdate.js +0 -147
- package/dist/commands/newGenerateAll.d.ts +0 -4
- package/dist/commands/newGenerateAll.js +0 -336
- package/dist/generators/domainModelGenerator.d.ts +0 -41
- package/dist/generators/domainModelGenerator.js +0 -242
- package/dist/generators/newControllerGenerator.d.ts +0 -55
- package/dist/generators/newControllerGenerator.js +0 -644
- package/dist/generators/newServiceGenerator.d.ts +0 -19
- package/dist/generators/newServiceGenerator.js +0 -266
- package/dist/generators/newStoreGenerator.d.ts +0 -39
- package/dist/generators/newStoreGenerator.js +0 -408
- package/dist/generators/newTemplateGenerator.d.ts +0 -29
- package/dist/generators/newTemplateGenerator.js +0 -510
- package/dist/generators/storeGeneratorV2.d.ts +0 -31
- package/dist/generators/storeGeneratorV2.js +0 -190
- package/dist/generators/templates/controllerTemplates.d.ts +0 -43
- package/dist/generators/templates/controllerTemplates.js +0 -82
- package/dist/generators/templates/newStoreTemplates.d.ts +0 -5
- package/dist/generators/templates/newStoreTemplates.js +0 -141
- package/dist/generators/templates/serviceTemplates.d.ts +0 -16
- package/dist/generators/templates/serviceTemplates.js +0 -59
- package/dist/generators/templates/validationTemplates.d.ts +0 -25
- package/dist/generators/templates/validationTemplates.js +0 -66
- package/dist/generators/templates/viewTemplates.d.ts +0 -25
- package/dist/generators/templates/viewTemplates.js +0 -491
- package/dist/generators/validationGenerator.d.ts +0 -29
- package/dist/generators/validationGenerator.js +0 -250
- package/dist/utils/new_parts_of_migrationUtils.d.ts +0 -0
- package/dist/utils/new_parts_of_migrationUtils.js +0 -164
- package/howto.md +0 -667
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createRl = createRl;
|
|
37
|
+
exports.promptText = promptText;
|
|
38
|
+
exports.promptNumber = promptNumber;
|
|
39
|
+
exports.promptYesNo = promptYesNo;
|
|
40
|
+
exports.promptSelect = promptSelect;
|
|
41
|
+
exports.promptMultiSelect = promptMultiSelect;
|
|
42
|
+
const readline = __importStar(require("readline"));
|
|
43
|
+
const colors_1 = require("./colors");
|
|
44
|
+
function createRl() {
|
|
45
|
+
return readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
46
|
+
}
|
|
47
|
+
function ask(rl, question) {
|
|
48
|
+
return new Promise(resolve => rl.question(question, resolve));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Ask for free-form text.
|
|
52
|
+
* If allowEmpty is false (default), re-prompts until non-blank is entered.
|
|
53
|
+
*/
|
|
54
|
+
async function promptText(rl, question, opts = {}) {
|
|
55
|
+
const { allowEmpty = false, defaultValue } = opts;
|
|
56
|
+
const suffix = defaultValue !== undefined ? colors_1.colors.gray(` (${defaultValue})`) : '';
|
|
57
|
+
while (true) {
|
|
58
|
+
const raw = await ask(rl, `${question}${suffix} `);
|
|
59
|
+
const value = raw.trim();
|
|
60
|
+
if (value !== '')
|
|
61
|
+
return value;
|
|
62
|
+
if (allowEmpty)
|
|
63
|
+
return defaultValue !== null && defaultValue !== void 0 ? defaultValue : '';
|
|
64
|
+
console.log(colors_1.colors.yellow(' Value is required. Please enter something.'));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Ask for a number. Re-prompts on invalid input.
|
|
69
|
+
*/
|
|
70
|
+
async function promptNumber(rl, question, defaultValue) {
|
|
71
|
+
const suffix = defaultValue !== undefined ? colors_1.colors.gray(` (${defaultValue})`) : colors_1.colors.gray(' (leave blank to skip)');
|
|
72
|
+
const raw = await ask(rl, `${question}${suffix} `);
|
|
73
|
+
const trimmed = raw.trim();
|
|
74
|
+
if (trimmed === '')
|
|
75
|
+
return defaultValue;
|
|
76
|
+
const n = Number(trimmed);
|
|
77
|
+
if (isNaN(n)) {
|
|
78
|
+
console.log(colors_1.colors.yellow(' Invalid number, skipping.'));
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Yes/No prompt. Returns true for yes.
|
|
85
|
+
*/
|
|
86
|
+
async function promptYesNo(rl, question, defaultYes = true) {
|
|
87
|
+
const hint = defaultYes ? colors_1.colors.gray('[Y/n]') : colors_1.colors.gray('[y/N]');
|
|
88
|
+
const raw = await ask(rl, `${question} ${hint} `);
|
|
89
|
+
const trimmed = raw.trim().toLowerCase();
|
|
90
|
+
if (trimmed === '')
|
|
91
|
+
return defaultYes;
|
|
92
|
+
return trimmed === 'y' || trimmed === 'yes';
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Single-select from a list of choices. Returns the chosen item.
|
|
96
|
+
*/
|
|
97
|
+
async function promptSelect(rl, question, choices) {
|
|
98
|
+
console.log(colors_1.colors.bold(question));
|
|
99
|
+
choices.forEach((c, i) => {
|
|
100
|
+
console.log(` ${colors_1.colors.cyan(String(i + 1).padStart(2))}. ${c.label}`);
|
|
101
|
+
});
|
|
102
|
+
while (true) {
|
|
103
|
+
const raw = await ask(rl, ` ${colors_1.colors.gray('Enter number:')} `);
|
|
104
|
+
const n = parseInt(raw.trim(), 10);
|
|
105
|
+
if (!isNaN(n) && n >= 1 && n <= choices.length) {
|
|
106
|
+
return choices[n - 1];
|
|
107
|
+
}
|
|
108
|
+
console.log(colors_1.colors.yellow(` Please enter a number between 1 and ${choices.length}.`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Multi-select from a list of choices.
|
|
113
|
+
* User types comma-separated numbers, "all", or "none".
|
|
114
|
+
* Returns array of selected items (may be empty).
|
|
115
|
+
*/
|
|
116
|
+
async function promptMultiSelect(rl, question, choices, opts = {}) {
|
|
117
|
+
const { allowNone = true, defaultAll = false } = opts;
|
|
118
|
+
console.log(colors_1.colors.bold(question));
|
|
119
|
+
choices.forEach((c, i) => {
|
|
120
|
+
console.log(` ${colors_1.colors.cyan(String(i + 1).padStart(2))}. ${c.label}`);
|
|
121
|
+
});
|
|
122
|
+
const hint = defaultAll ? colors_1.colors.gray('(comma-separated, "all", or "none" ā default: all)') : colors_1.colors.gray('(comma-separated, "all", or "none")');
|
|
123
|
+
while (true) {
|
|
124
|
+
const raw = await ask(rl, ` ${hint} `);
|
|
125
|
+
const trimmed = raw.trim().toLowerCase();
|
|
126
|
+
if (trimmed === '' && defaultAll)
|
|
127
|
+
return [...choices];
|
|
128
|
+
if (trimmed === 'all')
|
|
129
|
+
return [...choices];
|
|
130
|
+
if (trimmed === 'none') {
|
|
131
|
+
if (allowNone)
|
|
132
|
+
return [];
|
|
133
|
+
console.log(colors_1.colors.yellow(' At least one selection is required.'));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const parts = trimmed.split(',').map(s => s.trim()).filter(Boolean);
|
|
137
|
+
const indices = parts.map(p => parseInt(p, 10));
|
|
138
|
+
if (indices.some(n => isNaN(n) || n < 1 || n > choices.length)) {
|
|
139
|
+
console.log(colors_1.colors.yellow(` Please enter numbers between 1 and ${choices.length}, "all", or "none".`));
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const selected = [...new Set(indices)].map(n => choices[n - 1]);
|
|
143
|
+
if (selected.length === 0 && !allowNone) {
|
|
144
|
+
console.log(colors_1.colors.yellow(' At least one selection is required.'));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
return selected;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -13,6 +13,10 @@ export declare function capitalize(str: string): string;
|
|
|
13
13
|
* Map a YAML field type to TypeScript type, resolving aggregates and value objects by name.
|
|
14
14
|
*/
|
|
15
15
|
export declare function mapType(yamlType: string, aggregates?: Set<string> | Map<string, unknown>, valueObjects?: Set<string> | Map<string, unknown>): string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a YAML field type references another aggregate entity.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isAggregateReference(yamlType: string, aggregates?: Set<string> | Map<string, unknown>): boolean;
|
|
16
20
|
/**
|
|
17
21
|
* Map a YAML type to the store row TypeScript type (value objects become string).
|
|
18
22
|
*/
|
package/dist/utils/typeUtils.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ROW_TYPE_MAPPING = exports.TYPE_MAPPING = void 0;
|
|
7
7
|
exports.capitalize = capitalize;
|
|
8
8
|
exports.mapType = mapType;
|
|
9
|
+
exports.isAggregateReference = isAggregateReference;
|
|
9
10
|
exports.mapRowType = mapRowType;
|
|
10
11
|
/** Standard YAML type to TypeScript (domain) type mapping. */
|
|
11
12
|
exports.TYPE_MAPPING = {
|
|
@@ -55,6 +56,12 @@ function mapType(yamlType, aggregates, valueObjects) {
|
|
|
55
56
|
}
|
|
56
57
|
return (_a = exports.TYPE_MAPPING[yamlType]) !== null && _a !== void 0 ? _a : 'any';
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if a YAML field type references another aggregate entity.
|
|
61
|
+
*/
|
|
62
|
+
function isAggregateReference(yamlType, aggregates) {
|
|
63
|
+
return !!(aggregates === null || aggregates === void 0 ? void 0 : aggregates.has(yamlType));
|
|
64
|
+
}
|
|
58
65
|
/**
|
|
59
66
|
* Map a YAML type to the store row TypeScript type (value objects become string).
|
|
60
67
|
*/
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function handleCreateApp(rawName?: string): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function handleMigratePush(yamlPath?: string): Promise<void>;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.handleMigratePush = handleMigratePush;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const colors_1 = require("../utils/colors");
|
|
40
|
-
const cliUtils_1 = require("../utils/cliUtils");
|
|
41
|
-
const migrationUtils_1 = require("../utils/migrationUtils");
|
|
42
|
-
async function handleMigratePush(yamlPath) {
|
|
43
|
-
let connection;
|
|
44
|
-
try {
|
|
45
|
-
const resolvedYamlPath = (0, cliUtils_1.resolveYamlPath)(yamlPath);
|
|
46
|
-
const projectRoot = path.dirname(resolvedYamlPath);
|
|
47
|
-
const migrationsDir = path.join(projectRoot, 'migrations');
|
|
48
|
-
// Check if migrations directory exists
|
|
49
|
-
if (!fs.existsSync(migrationsDir)) {
|
|
50
|
-
// eslint-disable-next-line no-console
|
|
51
|
-
console.log(colors_1.colors.yellow('ā ļø No migrations directory found. Run "currentjs migrate commit" first.'));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Get all migration files
|
|
55
|
-
const migrationFiles = fs.readdirSync(migrationsDir)
|
|
56
|
-
.filter(f => f.endsWith('.sql'))
|
|
57
|
-
.sort();
|
|
58
|
-
if (migrationFiles.length === 0) {
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.log(colors_1.colors.yellow('ā ļø No migration files found. Run "currentjs migrate commit" first.'));
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
console.log(colors_1.colors.cyan('\nš Connecting to database...'));
|
|
65
|
-
// Verify environment variables
|
|
66
|
-
if (!process.env.DB_HOST || !process.env.DB_USER || !process.env.DB_NAME) {
|
|
67
|
-
// eslint-disable-next-line no-console
|
|
68
|
-
console.log(colors_1.colors.yellow('\nš” Database configuration:'));
|
|
69
|
-
// eslint-disable-next-line no-console
|
|
70
|
-
console.log(colors_1.colors.gray(` Host: ${process.env.DB_HOST || 'localhost (default)'}`));
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.log(colors_1.colors.gray(` Port: ${process.env.DB_PORT || '3306 (default)'}`));
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.log(colors_1.colors.gray(` User: ${process.env.DB_USER || 'root (default)'}`));
|
|
75
|
-
// eslint-disable-next-line no-console
|
|
76
|
-
console.log(colors_1.colors.gray(` Database: ${process.env.DB_NAME || 'test (default)'}`));
|
|
77
|
-
if (!process.env.DB_HOST || !process.env.DB_USER || !process.env.DB_NAME) {
|
|
78
|
-
// eslint-disable-next-line no-console
|
|
79
|
-
console.log(colors_1.colors.yellow('\nā ļø Environment variables not set. Using defaults.'));
|
|
80
|
-
// eslint-disable-next-line no-console
|
|
81
|
-
console.log(colors_1.colors.cyan(' Set DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME to configure.'));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
connection = await (0, migrationUtils_1.connectToDatabase)();
|
|
85
|
-
// eslint-disable-next-line no-console
|
|
86
|
-
console.log(colors_1.colors.green('ā Connected to database'));
|
|
87
|
-
// Get already applied migrations
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
console.log(colors_1.colors.cyan('\nš Checking applied migrations...'));
|
|
90
|
-
const appliedMigrations = await (0, migrationUtils_1.getAppliedMigrations)(connection);
|
|
91
|
-
// eslint-disable-next-line no-console
|
|
92
|
-
console.log(colors_1.colors.gray(` Applied: ${appliedMigrations.length} migration(s)`));
|
|
93
|
-
// Find pending migrations
|
|
94
|
-
const pendingMigrations = migrationFiles.filter(f => !appliedMigrations.includes(f));
|
|
95
|
-
if (pendingMigrations.length === 0) {
|
|
96
|
-
// eslint-disable-next-line no-console
|
|
97
|
-
console.log(colors_1.colors.green('\nā
Database is up to date. No pending migrations.'));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
// eslint-disable-next-line no-console
|
|
101
|
-
console.log(colors_1.colors.cyan(`\nš Applying ${pendingMigrations.length} migration(s)...`));
|
|
102
|
-
// Apply pending migrations
|
|
103
|
-
for (const migrationFile of pendingMigrations) {
|
|
104
|
-
const migrationPath = path.join(migrationsDir, migrationFile);
|
|
105
|
-
const migrationSQL = fs.readFileSync(migrationPath, 'utf8');
|
|
106
|
-
// eslint-disable-next-line no-console
|
|
107
|
-
console.log(colors_1.colors.gray(` ā ${migrationFile}...`));
|
|
108
|
-
try {
|
|
109
|
-
await (0, migrationUtils_1.executeMigration)(connection, migrationSQL);
|
|
110
|
-
await (0, migrationUtils_1.recordMigration)(connection, migrationFile);
|
|
111
|
-
// eslint-disable-next-line no-console
|
|
112
|
-
console.log(colors_1.colors.green(` ā ${migrationFile} applied`));
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
// eslint-disable-next-line no-console
|
|
116
|
-
console.error(colors_1.colors.red(` ā Failed to apply ${migrationFile}:`));
|
|
117
|
-
// eslint-disable-next-line no-console
|
|
118
|
-
console.error(colors_1.colors.red(` ${error instanceof Error ? error.message : String(error)}`));
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// eslint-disable-next-line no-console
|
|
123
|
-
console.log(colors_1.colors.green('\nā
All migrations applied successfully!'));
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
// eslint-disable-next-line no-console
|
|
127
|
-
console.error(colors_1.colors.red('\nā Error applying migrations:'), error instanceof Error ? error.message : String(error));
|
|
128
|
-
process.exitCode = 1;
|
|
129
|
-
}
|
|
130
|
-
finally {
|
|
131
|
-
if (connection) {
|
|
132
|
-
await connection.end();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function handleMigrateUpdate(yamlPath?: string): Promise<void>;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.handleMigrateUpdate = handleMigrateUpdate;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const colors_1 = require("../utils/colors");
|
|
40
|
-
const cliUtils_1 = require("../utils/cliUtils");
|
|
41
|
-
const migrationUtils_1 = require("../utils/migrationUtils");
|
|
42
|
-
async function handleMigrateUpdate(yamlPath) {
|
|
43
|
-
let connection;
|
|
44
|
-
try {
|
|
45
|
-
const resolvedYamlPath = (0, cliUtils_1.resolveYamlPath)(yamlPath);
|
|
46
|
-
const projectRoot = path.dirname(resolvedYamlPath);
|
|
47
|
-
const migrationsDir = path.join(projectRoot, 'migrations');
|
|
48
|
-
const stateFilePath = path.join(migrationsDir, 'schema_state.yaml');
|
|
49
|
-
// Ensure migrations directory exists
|
|
50
|
-
if (!fs.existsSync(migrationsDir)) {
|
|
51
|
-
fs.mkdirSync(migrationsDir, { recursive: true });
|
|
52
|
-
}
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
console.log(colors_1.colors.cyan('\nš Connecting to database...'));
|
|
55
|
-
// Verify environment variables
|
|
56
|
-
if (!process.env.DB_HOST || !process.env.DB_USER || !process.env.DB_NAME) {
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.log(colors_1.colors.yellow('\nš” Database configuration:'));
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.log(colors_1.colors.gray(` Host: ${process.env.DB_HOST || 'localhost (default)'}`));
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.log(colors_1.colors.gray(` Port: ${process.env.DB_PORT || '3306 (default)'}`));
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
console.log(colors_1.colors.gray(` User: ${process.env.DB_USER || 'root (default)'}`));
|
|
65
|
-
// eslint-disable-next-line no-console
|
|
66
|
-
console.log(colors_1.colors.gray(` Database: ${process.env.DB_NAME || 'test (default)'}`));
|
|
67
|
-
if (!process.env.DB_HOST || !process.env.DB_USER || !process.env.DB_NAME) {
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.log(colors_1.colors.yellow('\nā ļø Environment variables not set. Using defaults.'));
|
|
70
|
-
// eslint-disable-next-line no-console
|
|
71
|
-
console.log(colors_1.colors.cyan(' Set DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME to configure.'));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
connection = await (0, migrationUtils_1.connectToDatabase)();
|
|
75
|
-
// eslint-disable-next-line no-console
|
|
76
|
-
console.log(colors_1.colors.green('ā Connected to database'));
|
|
77
|
-
// Extract schema from database
|
|
78
|
-
// eslint-disable-next-line no-console
|
|
79
|
-
console.log(colors_1.colors.cyan('\nš Extracting schema from database...'));
|
|
80
|
-
const dbModels = await (0, migrationUtils_1.extractSchemaFromDatabase)(connection);
|
|
81
|
-
if (dbModels.length === 0) {
|
|
82
|
-
// eslint-disable-next-line no-console
|
|
83
|
-
console.log(colors_1.colors.yellow('ā ļø No tables found in database.'));
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// eslint-disable-next-line no-console
|
|
87
|
-
console.log(colors_1.colors.green(`ā Found ${dbModels.length} table(s): ${dbModels.map(m => m.name).join(', ')}`));
|
|
88
|
-
// Load current state
|
|
89
|
-
const currentState = (0, migrationUtils_1.loadSchemaState)(stateFilePath);
|
|
90
|
-
if (currentState) {
|
|
91
|
-
// eslint-disable-next-line no-console
|
|
92
|
-
console.log(colors_1.colors.cyan(`š Current schema state loaded (version: ${currentState.version})`));
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// eslint-disable-next-line no-console
|
|
96
|
-
console.log(colors_1.colors.cyan('š No current schema state found'));
|
|
97
|
-
}
|
|
98
|
-
// Compare database schema with current state
|
|
99
|
-
// eslint-disable-next-line no-console
|
|
100
|
-
console.log(colors_1.colors.cyan('\nš Comparing database schema with current state...'));
|
|
101
|
-
const sqlStatements = (0, migrationUtils_1.compareSchemas)(currentState, dbModels);
|
|
102
|
-
if (sqlStatements.length === 0 || sqlStatements.every(s => s.trim() === '' || s.startsWith('--'))) {
|
|
103
|
-
// eslint-disable-next-line no-console
|
|
104
|
-
console.log(colors_1.colors.green('ā
Database schema matches current state. No changes to record.'));
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// Generate migration file
|
|
108
|
-
const timestamp = (0, migrationUtils_1.generateTimestamp)();
|
|
109
|
-
const migrationFileName = (0, migrationUtils_1.getMigrationFileName)(timestamp);
|
|
110
|
-
const migrationFilePath = path.join(migrationsDir, migrationFileName);
|
|
111
|
-
const migrationHeader = `-- Migration: Database schema sync
|
|
112
|
-
-- Created: ${new Date().toISOString().split('T')[0]}
|
|
113
|
-
-- Timestamp: ${timestamp}
|
|
114
|
-
-- Source: Database schema extraction
|
|
115
|
-
|
|
116
|
-
`;
|
|
117
|
-
const migrationContent = migrationHeader + sqlStatements.join('\n');
|
|
118
|
-
fs.writeFileSync(migrationFilePath, migrationContent);
|
|
119
|
-
// Update state file
|
|
120
|
-
const newState = {
|
|
121
|
-
models: dbModels,
|
|
122
|
-
version: timestamp,
|
|
123
|
-
timestamp: new Date().toISOString()
|
|
124
|
-
};
|
|
125
|
-
(0, migrationUtils_1.saveSchemaState)(stateFilePath, newState);
|
|
126
|
-
// eslint-disable-next-line no-console
|
|
127
|
-
console.log(colors_1.colors.green('\nā
Migration created from database schema!'));
|
|
128
|
-
// eslint-disable-next-line no-console
|
|
129
|
-
console.log(colors_1.colors.gray(` File: ${migrationFileName}`));
|
|
130
|
-
// eslint-disable-next-line no-console
|
|
131
|
-
console.log(colors_1.colors.gray(` Path: ${migrationFilePath}`));
|
|
132
|
-
// eslint-disable-next-line no-console
|
|
133
|
-
console.log(colors_1.colors.cyan('\nš” Schema state updated to match database.'));
|
|
134
|
-
// eslint-disable-next-line no-console
|
|
135
|
-
console.log(colors_1.colors.cyan(' You can now modify your YAML files and run "currentjs migrate commit" to create new migrations.'));
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
// eslint-disable-next-line no-console
|
|
139
|
-
console.error(colors_1.colors.red('\nā Error updating migration from database:'), error instanceof Error ? error.message : String(error));
|
|
140
|
-
process.exitCode = 1;
|
|
141
|
-
}
|
|
142
|
-
finally {
|
|
143
|
-
if (connection) {
|
|
144
|
-
await connection.end();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|