@currentjs/gen 0.1.1
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 +7 -0
- package/LICENSE +56 -0
- package/README.md +686 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +143 -0
- package/dist/commands/commit.d.ts +1 -0
- package/dist/commands/commit.js +153 -0
- package/dist/commands/createApp.d.ts +1 -0
- package/dist/commands/createApp.js +64 -0
- package/dist/commands/createModule.d.ts +1 -0
- package/dist/commands/createModule.js +121 -0
- package/dist/commands/diff.d.ts +1 -0
- package/dist/commands/diff.js +164 -0
- package/dist/commands/generateAll.d.ts +4 -0
- package/dist/commands/generateAll.js +305 -0
- package/dist/commands/infer.d.ts +1 -0
- package/dist/commands/infer.js +179 -0
- package/dist/generators/controllerGenerator.d.ts +20 -0
- package/dist/generators/controllerGenerator.js +280 -0
- package/dist/generators/domainModelGenerator.d.ts +33 -0
- package/dist/generators/domainModelGenerator.js +175 -0
- package/dist/generators/serviceGenerator.d.ts +39 -0
- package/dist/generators/serviceGenerator.js +379 -0
- package/dist/generators/storeGenerator.d.ts +31 -0
- package/dist/generators/storeGenerator.js +191 -0
- package/dist/generators/templateGenerator.d.ts +11 -0
- package/dist/generators/templateGenerator.js +143 -0
- package/dist/generators/templates/appTemplates.d.ts +27 -0
- package/dist/generators/templates/appTemplates.js +1621 -0
- package/dist/generators/templates/controllerTemplates.d.ts +43 -0
- package/dist/generators/templates/controllerTemplates.js +82 -0
- package/dist/generators/templates/index.d.ts +5 -0
- package/dist/generators/templates/index.js +21 -0
- package/dist/generators/templates/serviceTemplates.d.ts +15 -0
- package/dist/generators/templates/serviceTemplates.js +54 -0
- package/dist/generators/templates/storeTemplates.d.ts +9 -0
- package/dist/generators/templates/storeTemplates.js +260 -0
- package/dist/generators/templates/validationTemplates.d.ts +25 -0
- package/dist/generators/templates/validationTemplates.js +66 -0
- package/dist/generators/templates/viewTemplates.d.ts +16 -0
- package/dist/generators/templates/viewTemplates.js +359 -0
- package/dist/generators/validationGenerator.d.ts +24 -0
- package/dist/generators/validationGenerator.js +199 -0
- package/dist/utils/cliUtils.d.ts +6 -0
- package/dist/utils/cliUtils.js +71 -0
- package/dist/utils/colors.d.ts +26 -0
- package/dist/utils/colors.js +80 -0
- package/dist/utils/commitUtils.d.ts +46 -0
- package/dist/utils/commitUtils.js +377 -0
- package/dist/utils/constants.d.ts +52 -0
- package/dist/utils/constants.js +64 -0
- package/dist/utils/generationRegistry.d.ts +25 -0
- package/dist/utils/generationRegistry.js +192 -0
- package/howto.md +556 -0
- package/package.json +44 -0
|
@@ -0,0 +1,192 @@
|
|
|
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.initGenerationRegistry = initGenerationRegistry;
|
|
37
|
+
exports.computeContentHash = computeContentHash;
|
|
38
|
+
exports.loadRegistry = loadRegistry;
|
|
39
|
+
exports.saveRegistry = saveRegistry;
|
|
40
|
+
exports.getStoredHash = getStoredHash;
|
|
41
|
+
exports.updateStoredHash = updateStoredHash;
|
|
42
|
+
exports.updateStoredHunks = updateStoredHunks;
|
|
43
|
+
exports.writeGeneratedFile = writeGeneratedFile;
|
|
44
|
+
exports.ensureCommitsDir = ensureCommitsDir;
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const constants_1 = require("./constants");
|
|
48
|
+
const crypto = __importStar(require("crypto"));
|
|
49
|
+
const readline = __importStar(require("readline"));
|
|
50
|
+
const commitUtils_1 = require("./commitUtils");
|
|
51
|
+
const colors_1 = require("./colors");
|
|
52
|
+
let projectRootDir = null;
|
|
53
|
+
function initGenerationRegistry(rootDir) {
|
|
54
|
+
projectRootDir = rootDir;
|
|
55
|
+
}
|
|
56
|
+
function getRegistryFilePath() {
|
|
57
|
+
if (!projectRootDir) {
|
|
58
|
+
throw new Error('Generation registry is not initialized. Call initGenerationRegistry(rootDir) first.');
|
|
59
|
+
}
|
|
60
|
+
// Store at project root as registry.json
|
|
61
|
+
return path.join(projectRootDir, constants_1.COMMON_FILES.REGISTRY_JSON);
|
|
62
|
+
}
|
|
63
|
+
function computeContentHash(contents) {
|
|
64
|
+
return crypto.createHash('sha256').update(contents).digest('hex');
|
|
65
|
+
}
|
|
66
|
+
function loadRegistry() {
|
|
67
|
+
const file = getRegistryFilePath();
|
|
68
|
+
if (!fs.existsSync(file))
|
|
69
|
+
return {};
|
|
70
|
+
try {
|
|
71
|
+
const raw = fs.readFileSync(file, 'utf8');
|
|
72
|
+
const data = JSON.parse(raw);
|
|
73
|
+
return data || {};
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function saveRegistry(data) {
|
|
80
|
+
const file = getRegistryFilePath();
|
|
81
|
+
fs.writeFileSync(file, JSON.stringify(data, null, 2));
|
|
82
|
+
}
|
|
83
|
+
function getStoredHash(filePath) {
|
|
84
|
+
var _a, _b, _c;
|
|
85
|
+
const registry = loadRegistry();
|
|
86
|
+
const root = projectRootDir || process.cwd();
|
|
87
|
+
const abs = path.resolve(filePath);
|
|
88
|
+
const rel = path.relative(root, abs);
|
|
89
|
+
// Prefer relative key; fall back to absolute for backward compatibility
|
|
90
|
+
return (_b = (_a = registry[rel]) === null || _a === void 0 ? void 0 : _a.hash) !== null && _b !== void 0 ? _b : (_c = registry[abs]) === null || _c === void 0 ? void 0 : _c.hash;
|
|
91
|
+
}
|
|
92
|
+
function updateStoredHash(filePath, hash) {
|
|
93
|
+
const registry = loadRegistry();
|
|
94
|
+
const root = projectRootDir || process.cwd();
|
|
95
|
+
const abs = path.resolve(filePath);
|
|
96
|
+
const rel = path.relative(root, abs);
|
|
97
|
+
// Write only relative key
|
|
98
|
+
const prev = registry[rel] || {};
|
|
99
|
+
registry[rel] = { ...prev, hash, updatedAt: new Date().toISOString() };
|
|
100
|
+
// Clean old absolute key if present
|
|
101
|
+
if (registry[abs]) {
|
|
102
|
+
delete registry[abs];
|
|
103
|
+
}
|
|
104
|
+
saveRegistry(registry);
|
|
105
|
+
}
|
|
106
|
+
function updateStoredHunks(filePath, hunks, baseHash, resultHash) {
|
|
107
|
+
const registry = loadRegistry();
|
|
108
|
+
const root = projectRootDir || process.cwd();
|
|
109
|
+
const abs = path.resolve(filePath);
|
|
110
|
+
const rel = path.relative(root, abs);
|
|
111
|
+
const prev = registry[rel] || {};
|
|
112
|
+
registry[rel] = {
|
|
113
|
+
...prev,
|
|
114
|
+
diffFormat: 'hunks-v1',
|
|
115
|
+
diffHunks: hunks,
|
|
116
|
+
diffBaseHash: baseHash,
|
|
117
|
+
diffResultHash: resultHash,
|
|
118
|
+
diffUpdatedAt: new Date().toISOString()
|
|
119
|
+
};
|
|
120
|
+
// cleanup old absolute key if present
|
|
121
|
+
if (registry[abs])
|
|
122
|
+
delete registry[abs];
|
|
123
|
+
saveRegistry(registry);
|
|
124
|
+
}
|
|
125
|
+
async function promptYesNo(question) {
|
|
126
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
127
|
+
const answer = await new Promise(resolve => rl.question(`${question} [y/N]: `, resolve));
|
|
128
|
+
rl.close();
|
|
129
|
+
return ['y', 'yes'].includes(answer.trim().toLowerCase());
|
|
130
|
+
}
|
|
131
|
+
async function writeGeneratedFile(filePath, contents, options) {
|
|
132
|
+
const force = (options === null || options === void 0 ? void 0 : options.force) === true;
|
|
133
|
+
const silent = (options === null || options === void 0 ? void 0 : options.silent) === true;
|
|
134
|
+
const skipOnConflict = (options === null || options === void 0 ? void 0 : options.skipOnConflict) === true;
|
|
135
|
+
const abs = path.resolve(filePath);
|
|
136
|
+
const newHash = computeContentHash(contents);
|
|
137
|
+
const exists = fs.existsSync(abs);
|
|
138
|
+
if (!exists) {
|
|
139
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
140
|
+
fs.writeFileSync(abs, contents);
|
|
141
|
+
updateStoredHash(abs, newHash);
|
|
142
|
+
if (!silent)
|
|
143
|
+
console.log(colors_1.colors.blue(`[V] Generated ${path.relative(projectRootDir || process.cwd(), abs)}`));
|
|
144
|
+
return 'written';
|
|
145
|
+
}
|
|
146
|
+
const storedHash = getStoredHash(abs);
|
|
147
|
+
const currentContent = fs.readFileSync(abs, 'utf8');
|
|
148
|
+
const currentHash = computeContentHash(currentContent);
|
|
149
|
+
if (currentHash === newHash) {
|
|
150
|
+
// Nothing to do
|
|
151
|
+
return 'unchanged';
|
|
152
|
+
}
|
|
153
|
+
// If we have a stored hash and it matches current, safe to overwrite
|
|
154
|
+
const isUserModified = !storedHash || storedHash !== currentHash;
|
|
155
|
+
if (isUserModified && !force) {
|
|
156
|
+
const rel = path.relative(projectRootDir || process.cwd(), abs);
|
|
157
|
+
// Try commits auto-apply path
|
|
158
|
+
const applied = (0, commitUtils_1.tryApplyCommitsToGenerated)(abs, contents);
|
|
159
|
+
if (applied.applied) {
|
|
160
|
+
fs.writeFileSync(abs, applied.content);
|
|
161
|
+
updateStoredHash(abs, computeContentHash(applied.content));
|
|
162
|
+
if (!silent)
|
|
163
|
+
console.log(colors_1.colors.cyan(`Updated (with commits) ${rel}`));
|
|
164
|
+
return 'written';
|
|
165
|
+
}
|
|
166
|
+
if (skipOnConflict) {
|
|
167
|
+
if (!silent)
|
|
168
|
+
console.log(colors_1.colors.yellow(`Skipped ${rel}`));
|
|
169
|
+
return 'skipped';
|
|
170
|
+
}
|
|
171
|
+
const overwrite = await promptYesNo(`File modified since last generation: ${rel}. Overwrite?`);
|
|
172
|
+
if (!overwrite) {
|
|
173
|
+
if (!silent)
|
|
174
|
+
console.log(colors_1.colors.yellow(`Skipped ${rel}`));
|
|
175
|
+
return 'skipped';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
fs.writeFileSync(abs, contents);
|
|
179
|
+
updateStoredHash(abs, newHash);
|
|
180
|
+
if (!silent)
|
|
181
|
+
console.log(colors_1.colors.blue(`Updated ${path.relative(projectRootDir || process.cwd(), abs)}`));
|
|
182
|
+
return 'written';
|
|
183
|
+
}
|
|
184
|
+
function ensureCommitsDir() {
|
|
185
|
+
if (!projectRootDir) {
|
|
186
|
+
throw new Error('Generation registry is not initialized. Call initGenerationRegistry(rootDir) first.');
|
|
187
|
+
}
|
|
188
|
+
// Store commits at project root/commits
|
|
189
|
+
const commitsDir = path.join(projectRootDir, 'commits');
|
|
190
|
+
fs.mkdirSync(commitsDir, { recursive: true });
|
|
191
|
+
return commitsDir;
|
|
192
|
+
}
|