@akanjs/devkit 0.0.142 → 0.0.144
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/cjs/src/aiEditor.js +151 -13
- package/cjs/src/builder.js +1 -2
- package/cjs/src/commandDecorators/argMeta.js +4 -1
- package/cjs/src/commandDecorators/command.js +44 -6
- package/cjs/src/executors.js +165 -60
- package/cjs/src/guideline.js +15 -0
- package/cjs/src/index.js +5 -1
- package/cjs/src/linter.js +238 -0
- package/cjs/src/prompter.js +78 -0
- package/cjs/src/typeChecker.js +203 -0
- package/cjs/src/uploadRelease.js +59 -33
- package/esm/src/aiEditor.js +157 -14
- package/esm/src/builder.js +1 -2
- package/esm/src/commandDecorators/argMeta.js +3 -1
- package/esm/src/commandDecorators/command.js +45 -7
- package/esm/src/executors.js +165 -61
- package/esm/src/guideline.js +0 -0
- package/esm/src/index.js +2 -0
- package/esm/src/linter.js +205 -0
- package/esm/src/prompter.js +45 -0
- package/esm/src/typeChecker.js +170 -0
- package/esm/src/uploadRelease.js +59 -33
- package/package.json +3 -1
- package/src/aiEditor.d.ts +23 -4
- package/src/commandDecorators/argMeta.d.ts +6 -2
- package/src/executors.d.ts +74 -23
- package/src/guideline.d.ts +19 -0
- package/src/index.d.ts +2 -0
- package/src/linter.d.ts +109 -0
- package/src/prompter.d.ts +13 -0
- package/src/typeChecker.d.ts +49 -0
- package/src/types.d.ts +4 -0
- package/src/uploadRelease.d.ts +1 -1
package/esm/src/executors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from "@akanjs/common";
|
|
1
|
+
import { capitalize, Logger } from "@akanjs/common";
|
|
2
2
|
import {
|
|
3
3
|
getAppConfig,
|
|
4
4
|
getDefaultFileScan,
|
|
@@ -11,13 +11,16 @@ import fs from "fs";
|
|
|
11
11
|
import fsPromise from "fs/promises";
|
|
12
12
|
import path from "path";
|
|
13
13
|
import { TypeScriptDependencyScanner } from "./dependencyScanner";
|
|
14
|
+
import { Linter } from "./linter";
|
|
14
15
|
import { Spinner } from "./spinner";
|
|
16
|
+
import { TypeChecker } from "./typeChecker";
|
|
15
17
|
const execEmoji = {
|
|
16
18
|
workspace: "\u{1F3E0}",
|
|
17
19
|
app: "\u{1F680}",
|
|
18
20
|
lib: "\u{1F527}",
|
|
19
21
|
pkg: "\u{1F4E6}",
|
|
20
22
|
dist: "\u{1F4BF}",
|
|
23
|
+
module: "\u2699\uFE0F",
|
|
21
24
|
default: "\u2708\uFE0F"
|
|
22
25
|
// for sys executor
|
|
23
26
|
};
|
|
@@ -30,6 +33,8 @@ class Executor {
|
|
|
30
33
|
logger;
|
|
31
34
|
cwdPath;
|
|
32
35
|
emoji = execEmoji.default;
|
|
36
|
+
typeChecker = null;
|
|
37
|
+
linter = null;
|
|
33
38
|
constructor(name, cwdPath) {
|
|
34
39
|
this.name = name;
|
|
35
40
|
this.logger = new Logger(name);
|
|
@@ -64,28 +69,32 @@ class Executor {
|
|
|
64
69
|
spawn(command, args = [], options = {}) {
|
|
65
70
|
const proc = spawn(command, args, {
|
|
66
71
|
cwd: this.cwdPath,
|
|
67
|
-
stdio: "inherit",
|
|
72
|
+
// stdio: "inherit",
|
|
68
73
|
...options
|
|
69
74
|
});
|
|
75
|
+
let stdout = "";
|
|
76
|
+
proc.stdout?.on("data", (data) => {
|
|
77
|
+
stdout += data;
|
|
78
|
+
});
|
|
70
79
|
proc.stdout?.on("data", (data) => {
|
|
71
80
|
this.#stdout(data);
|
|
72
81
|
});
|
|
73
82
|
proc.stderr?.on("data", (data) => {
|
|
74
|
-
this.#
|
|
83
|
+
this.#stdout(data);
|
|
75
84
|
});
|
|
76
85
|
return new Promise((resolve, reject) => {
|
|
77
86
|
proc.on("exit", (code, signal) => {
|
|
78
87
|
if (!!code || signal)
|
|
79
|
-
reject({ code, signal });
|
|
88
|
+
reject({ code, signal, stdout });
|
|
80
89
|
else
|
|
81
|
-
resolve(
|
|
90
|
+
resolve(stdout);
|
|
82
91
|
});
|
|
83
92
|
});
|
|
84
93
|
}
|
|
85
94
|
fork(modulePath, args = [], options = {}) {
|
|
86
95
|
const proc = fork(modulePath, args, {
|
|
87
96
|
cwd: this.cwdPath,
|
|
88
|
-
stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
97
|
+
// stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
89
98
|
...options
|
|
90
99
|
});
|
|
91
100
|
proc.stdout?.on("data", (data) => {
|
|
@@ -103,45 +112,70 @@ class Executor {
|
|
|
103
112
|
});
|
|
104
113
|
});
|
|
105
114
|
}
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
getPath(filePath) {
|
|
116
|
+
if (path.isAbsolute(filePath))
|
|
117
|
+
return filePath;
|
|
118
|
+
const baseParts = this.cwdPath.split("/").filter(Boolean);
|
|
119
|
+
const targetParts = filePath.split("/").filter(Boolean);
|
|
120
|
+
let overlapLength = 0;
|
|
121
|
+
for (let i = 1; i <= Math.min(baseParts.length, targetParts.length); i++) {
|
|
122
|
+
let isOverlap = true;
|
|
123
|
+
for (let j = 0; j < i; j++)
|
|
124
|
+
if (baseParts[baseParts.length - i + j] !== targetParts[j]) {
|
|
125
|
+
isOverlap = false;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (isOverlap)
|
|
129
|
+
overlapLength = i;
|
|
130
|
+
}
|
|
131
|
+
const result = overlapLength > 0 ? `/${[...baseParts, ...targetParts.slice(overlapLength)].join("/")}` : `${this.cwdPath}/${filePath}`;
|
|
132
|
+
return result.replace(/\/+/g, "/");
|
|
108
133
|
}
|
|
109
134
|
mkdir(dirPath) {
|
|
110
|
-
const writePath = this
|
|
135
|
+
const writePath = this.getPath(dirPath);
|
|
111
136
|
if (!fs.existsSync(writePath))
|
|
112
137
|
fs.mkdirSync(writePath, { recursive: true });
|
|
113
138
|
this.logger.verbose(`Make directory ${writePath}`);
|
|
114
139
|
return this;
|
|
115
140
|
}
|
|
141
|
+
async readdir(dirPath) {
|
|
142
|
+
const readPath = this.getPath(dirPath);
|
|
143
|
+
try {
|
|
144
|
+
return await fsPromise.readdir(readPath);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
116
149
|
exists(filePath) {
|
|
117
|
-
const readPath = this
|
|
150
|
+
const readPath = this.getPath(filePath);
|
|
118
151
|
return fs.existsSync(readPath);
|
|
119
152
|
}
|
|
120
153
|
remove(filePath) {
|
|
121
|
-
const readPath = this
|
|
154
|
+
const readPath = this.getPath(filePath);
|
|
122
155
|
if (fs.existsSync(readPath))
|
|
123
156
|
fs.unlinkSync(readPath);
|
|
124
157
|
this.logger.verbose(`Remove file ${readPath}`);
|
|
125
158
|
return this;
|
|
126
159
|
}
|
|
127
160
|
removeDir(dirPath) {
|
|
128
|
-
const readPath = this
|
|
161
|
+
const readPath = this.getPath(dirPath);
|
|
129
162
|
if (fs.existsSync(readPath))
|
|
130
163
|
fs.rmSync(readPath, { recursive: true });
|
|
131
164
|
this.logger.verbose(`Remove directory ${readPath}`);
|
|
132
165
|
return this;
|
|
133
166
|
}
|
|
134
167
|
writeFile(filePath, content, { overwrite = true } = {}) {
|
|
135
|
-
const writePath = this
|
|
168
|
+
const writePath = this.getPath(filePath);
|
|
136
169
|
const dir = path.dirname(writePath);
|
|
137
170
|
if (!fs.existsSync(dir))
|
|
138
171
|
fs.mkdirSync(dir, { recursive: true });
|
|
139
|
-
|
|
172
|
+
let contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
|
|
140
173
|
if (fs.existsSync(writePath)) {
|
|
141
174
|
const currentContent = fs.readFileSync(writePath, "utf8");
|
|
142
|
-
if (currentContent === contentStr || !overwrite)
|
|
175
|
+
if (currentContent === contentStr || !overwrite) {
|
|
143
176
|
this.logger.verbose(`File ${writePath} is unchanged`);
|
|
144
|
-
|
|
177
|
+
contentStr = fs.readFileSync(writePath, "utf-8");
|
|
178
|
+
} else {
|
|
145
179
|
fs.writeFileSync(writePath, contentStr, "utf8");
|
|
146
180
|
this.logger.verbose(`File ${writePath} is changed`);
|
|
147
181
|
}
|
|
@@ -149,28 +183,28 @@ class Executor {
|
|
|
149
183
|
fs.writeFileSync(writePath, contentStr, "utf8");
|
|
150
184
|
this.logger.verbose(`File ${writePath} is created`);
|
|
151
185
|
}
|
|
152
|
-
return
|
|
186
|
+
return { filePath: writePath, content: contentStr };
|
|
153
187
|
}
|
|
154
188
|
writeJson(filePath, content) {
|
|
155
189
|
this.writeFile(filePath, JSON.stringify(content, null, 2) + "\n");
|
|
156
190
|
return this;
|
|
157
191
|
}
|
|
158
|
-
getLocalFile(
|
|
159
|
-
const
|
|
160
|
-
const content = this.readFile(
|
|
161
|
-
return {
|
|
192
|
+
getLocalFile(targetPath) {
|
|
193
|
+
const filePath = path.isAbsolute(targetPath) ? targetPath : targetPath.replace(this.cwdPath, "");
|
|
194
|
+
const content = this.readFile(filePath);
|
|
195
|
+
return { filePath, content };
|
|
162
196
|
}
|
|
163
197
|
readFile(filePath) {
|
|
164
|
-
const readPath = this
|
|
198
|
+
const readPath = this.getPath(filePath);
|
|
165
199
|
return fs.readFileSync(readPath, "utf8");
|
|
166
200
|
}
|
|
167
201
|
readJson(filePath) {
|
|
168
|
-
const readPath = this
|
|
202
|
+
const readPath = this.getPath(filePath);
|
|
169
203
|
return JSON.parse(fs.readFileSync(readPath, "utf8"));
|
|
170
204
|
}
|
|
171
205
|
async cp(srcPath, destPath) {
|
|
172
|
-
const src = this
|
|
173
|
-
const dest = this
|
|
206
|
+
const src = this.getPath(srcPath);
|
|
207
|
+
const dest = this.getPath(destPath);
|
|
174
208
|
await fsPromise.cp(src, dest, { recursive: true });
|
|
175
209
|
}
|
|
176
210
|
log(msg) {
|
|
@@ -206,7 +240,7 @@ class Executor {
|
|
|
206
240
|
const getContent = require(templatePath);
|
|
207
241
|
const result = getContent.default(scanResult ?? null, dict);
|
|
208
242
|
if (result === null)
|
|
209
|
-
return;
|
|
243
|
+
return null;
|
|
210
244
|
const filename = typeof result === "object" ? result.filename : path.basename(targetPath).replace(".js", ".ts");
|
|
211
245
|
const content = typeof result === "object" ? result.content : result;
|
|
212
246
|
const dirname = path.dirname(targetPath);
|
|
@@ -215,7 +249,7 @@ class Executor {
|
|
|
215
249
|
`${dirname}/${filename}`
|
|
216
250
|
);
|
|
217
251
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
218
|
-
this.writeFile(convertedTargetPath, content, { overwrite });
|
|
252
|
+
return this.writeFile(convertedTargetPath, content, { overwrite });
|
|
219
253
|
} else if (targetPath.endsWith(".template")) {
|
|
220
254
|
const content = await fsPromise.readFile(templatePath, "utf8");
|
|
221
255
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
@@ -227,10 +261,11 @@ class Executor {
|
|
|
227
261
|
content
|
|
228
262
|
);
|
|
229
263
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
230
|
-
this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
231
|
-
}
|
|
264
|
+
return this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
265
|
+
} else
|
|
266
|
+
return null;
|
|
232
267
|
}
|
|
233
|
-
async
|
|
268
|
+
async _applyTemplate({
|
|
234
269
|
basePath,
|
|
235
270
|
template,
|
|
236
271
|
scanResult,
|
|
@@ -240,22 +275,24 @@ class Executor {
|
|
|
240
275
|
const templatePath = `${__dirname}/src/templates${template ? `/${template}` : ""}`.replace(".ts", ".js");
|
|
241
276
|
if (fs.statSync(templatePath).isFile()) {
|
|
242
277
|
const filename = path.basename(templatePath);
|
|
243
|
-
await this.#applyTemplateFile(
|
|
278
|
+
const fileContent = await this.#applyTemplateFile(
|
|
244
279
|
{ templatePath, targetPath: path.join(basePath, filename), scanResult, overwrite },
|
|
245
280
|
dict
|
|
246
281
|
);
|
|
282
|
+
return fileContent ? [fileContent] : [];
|
|
247
283
|
} else {
|
|
248
|
-
const subdirs = await
|
|
249
|
-
await Promise.all(
|
|
284
|
+
const subdirs = await this.readdir(templatePath);
|
|
285
|
+
const fileContents = (await Promise.all(
|
|
250
286
|
subdirs.map(async (subdir) => {
|
|
251
287
|
const subpath = path.join(templatePath, subdir);
|
|
252
|
-
if (fs.statSync(subpath).isFile())
|
|
253
|
-
await this.#applyTemplateFile(
|
|
288
|
+
if (fs.statSync(subpath).isFile()) {
|
|
289
|
+
const fileContent = await this.#applyTemplateFile(
|
|
254
290
|
{ templatePath: subpath, targetPath: path.join(basePath, subdir), scanResult, overwrite },
|
|
255
291
|
dict
|
|
256
292
|
);
|
|
257
|
-
|
|
258
|
-
|
|
293
|
+
return fileContent ? [fileContent] : [];
|
|
294
|
+
} else
|
|
295
|
+
return await this._applyTemplate({
|
|
259
296
|
basePath: path.join(basePath, subdir),
|
|
260
297
|
template: path.join(template, subdir),
|
|
261
298
|
scanResult,
|
|
@@ -263,9 +300,41 @@ class Executor {
|
|
|
263
300
|
overwrite
|
|
264
301
|
});
|
|
265
302
|
})
|
|
266
|
-
);
|
|
303
|
+
)).flat();
|
|
304
|
+
return fileContents;
|
|
267
305
|
}
|
|
268
306
|
}
|
|
307
|
+
async applyTemplate(options) {
|
|
308
|
+
const dict = {
|
|
309
|
+
...options.dict ?? {},
|
|
310
|
+
...Object.fromEntries(
|
|
311
|
+
Object.entries(options.dict ?? {}).map(([key, value]) => [capitalize(key), capitalize(value)])
|
|
312
|
+
)
|
|
313
|
+
};
|
|
314
|
+
return this._applyTemplate({ ...options, dict });
|
|
315
|
+
}
|
|
316
|
+
getTypeChecker() {
|
|
317
|
+
this.typeChecker ??= new TypeChecker(this);
|
|
318
|
+
return this.typeChecker;
|
|
319
|
+
}
|
|
320
|
+
typeCheck(filePath) {
|
|
321
|
+
const path2 = this.getPath(filePath);
|
|
322
|
+
const typeChecker = this.getTypeChecker();
|
|
323
|
+
const { diagnostics, errors, warnings } = typeChecker.check(path2);
|
|
324
|
+
const message = typeChecker.formatDiagnostics(diagnostics);
|
|
325
|
+
return { diagnostics, errors, warnings, message };
|
|
326
|
+
}
|
|
327
|
+
getLinter() {
|
|
328
|
+
this.linter ??= new Linter(this.cwdPath);
|
|
329
|
+
return this.linter;
|
|
330
|
+
}
|
|
331
|
+
async lint(filePath, { fix = false, dryRun = false } = {}) {
|
|
332
|
+
const path2 = this.getPath(filePath);
|
|
333
|
+
const linter = this.getLinter();
|
|
334
|
+
const { results, errors, warnings } = await linter.lint(path2, { fix, dryRun });
|
|
335
|
+
const message = linter.formatLintResults(results);
|
|
336
|
+
return { results, message, errors, warnings };
|
|
337
|
+
}
|
|
269
338
|
}
|
|
270
339
|
class WorkspaceExecutor extends Executor {
|
|
271
340
|
workspaceRoot;
|
|
@@ -378,7 +447,7 @@ class WorkspaceExecutor extends Executor {
|
|
|
378
447
|
async getDirInModule(basePath, name) {
|
|
379
448
|
const AVOID_DIRS = ["__lib", "__scalar", `_`, `_${name}`];
|
|
380
449
|
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
381
|
-
const dirs = await
|
|
450
|
+
const dirs = await this.readdir(dirname);
|
|
382
451
|
await Promise.all(
|
|
383
452
|
dirs.map(async (dir) => {
|
|
384
453
|
if (dir.includes("_") || AVOID_DIRS.includes(dir))
|
|
@@ -405,7 +474,7 @@ class WorkspaceExecutor extends Executor {
|
|
|
405
474
|
async #getDirHasFile(basePath, targetFilename) {
|
|
406
475
|
const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
|
|
407
476
|
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
408
|
-
const dirs = await
|
|
477
|
+
const dirs = await this.readdir(dirname);
|
|
409
478
|
await Promise.all(
|
|
410
479
|
dirs.map(async (dir) => {
|
|
411
480
|
if (AVOID_DIRS.includes(dir))
|
|
@@ -503,14 +572,14 @@ class SysExecutor extends Executor {
|
|
|
503
572
|
if (!fs.existsSync(`${this.cwdPath}/lib/__scalar`))
|
|
504
573
|
fs.mkdirSync(`${this.cwdPath}/lib/__scalar`, { recursive: true });
|
|
505
574
|
const files = getDefaultFileScan();
|
|
506
|
-
const dirnames = (await
|
|
575
|
+
const dirnames = (await this.readdir("lib")).filter(
|
|
507
576
|
(name) => fs.lstatSync(`${this.cwdPath}/lib/${name}`).isDirectory()
|
|
508
577
|
);
|
|
509
578
|
const databaseDirs = dirnames.filter((name) => !name.startsWith("_"));
|
|
510
579
|
const serviceDirs = dirnames.filter((name) => name.startsWith("_") && !name.startsWith("__"));
|
|
511
580
|
await Promise.all(
|
|
512
581
|
databaseDirs.map(async (name) => {
|
|
513
|
-
const filenames = await
|
|
582
|
+
const filenames = await this.readdir(path.join("lib", name));
|
|
514
583
|
filenames.forEach((filename) => {
|
|
515
584
|
if (filename.endsWith(".constant.ts"))
|
|
516
585
|
files.constants.databases.push(name);
|
|
@@ -532,7 +601,7 @@ class SysExecutor extends Executor {
|
|
|
532
601
|
await Promise.all(
|
|
533
602
|
serviceDirs.map(async (dirname) => {
|
|
534
603
|
const name = dirname.slice(1);
|
|
535
|
-
const filenames = await
|
|
604
|
+
const filenames = await this.readdir(path.join("lib", dirname));
|
|
536
605
|
filenames.forEach((filename) => {
|
|
537
606
|
if (filename.endsWith(".dictionary.ts"))
|
|
538
607
|
files.dictionary.services.push(name);
|
|
@@ -547,12 +616,10 @@ class SysExecutor extends Executor {
|
|
|
547
616
|
});
|
|
548
617
|
})
|
|
549
618
|
);
|
|
550
|
-
const scalarDirs = (await
|
|
551
|
-
(name) => !name.startsWith("_")
|
|
552
|
-
);
|
|
619
|
+
const scalarDirs = (await this.readdir("lib/__scalar")).filter((name) => !name.startsWith("_"));
|
|
553
620
|
await Promise.all(
|
|
554
621
|
scalarDirs.map(async (name) => {
|
|
555
|
-
const filenames = await
|
|
622
|
+
const filenames = await this.readdir(path.join("lib/__scalar", name));
|
|
556
623
|
filenames.forEach((filename) => {
|
|
557
624
|
if (filename.endsWith(".constant.ts"))
|
|
558
625
|
files.constants.scalars.push(name);
|
|
@@ -599,11 +666,11 @@ class SysExecutor extends Executor {
|
|
|
599
666
|
dependencies: [...npmDepSet].filter((dep) => !dep.startsWith("@akanjs")),
|
|
600
667
|
libs: Object.fromEntries(akanConfig.libs.map((libName) => [libName, libScanResults[libName]]))
|
|
601
668
|
};
|
|
602
|
-
await this.
|
|
603
|
-
await this.
|
|
604
|
-
await this.
|
|
669
|
+
await this._applyTemplate({ basePath: "lib", template: "lib", scanResult });
|
|
670
|
+
await this._applyTemplate({ basePath: ".", template: "server.ts", scanResult });
|
|
671
|
+
await this._applyTemplate({ basePath: ".", template: "client.ts", scanResult });
|
|
605
672
|
if (this.type === "lib")
|
|
606
|
-
await this.
|
|
673
|
+
await this._applyTemplate({ basePath: ".", template: "index.ts", scanResult });
|
|
607
674
|
this.writeJson(`akan.${this.type}.json`, scanResult);
|
|
608
675
|
if (this.type === "app")
|
|
609
676
|
return scanResult;
|
|
@@ -626,33 +693,33 @@ class SysExecutor extends Executor {
|
|
|
626
693
|
this.writeJson("package.json", libPkgJsonWithDeps);
|
|
627
694
|
return scanResult;
|
|
628
695
|
}
|
|
629
|
-
getLocalFile(
|
|
630
|
-
const
|
|
631
|
-
const content = this.workspace.readFile(
|
|
632
|
-
return {
|
|
696
|
+
getLocalFile(targetPath) {
|
|
697
|
+
const filePath = path.isAbsolute(targetPath) ? targetPath : `${this.type}s/${this.name}/${targetPath}`;
|
|
698
|
+
const content = this.workspace.readFile(filePath);
|
|
699
|
+
return { filePath, content };
|
|
633
700
|
}
|
|
634
701
|
async getDatabaseModules() {
|
|
635
|
-
const databaseModules = (await
|
|
702
|
+
const databaseModules = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
|
|
636
703
|
return databaseModules;
|
|
637
704
|
}
|
|
638
705
|
async getServiceModules() {
|
|
639
|
-
const serviceModules = (await
|
|
706
|
+
const serviceModules = (await this.readdir("lib")).filter((name) => name.startsWith("_") && !name.startsWith("__")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/${name}/${name}.service.ts`));
|
|
640
707
|
return serviceModules;
|
|
641
708
|
}
|
|
642
709
|
async getScalarModules() {
|
|
643
|
-
const scalarModules = (await
|
|
710
|
+
const scalarModules = (await this.readdir("lib/__scalar")).filter((name) => !name.startsWith("_")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
|
|
644
711
|
return scalarModules;
|
|
645
712
|
}
|
|
646
713
|
async getViewComponents() {
|
|
647
|
-
const viewComponents = (await
|
|
714
|
+
const viewComponents = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/${name}/${name}.View.tsx`));
|
|
648
715
|
return viewComponents;
|
|
649
716
|
}
|
|
650
717
|
async getUnitComponents() {
|
|
651
|
-
const unitComponents = (await
|
|
718
|
+
const unitComponents = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/${name}/${name}.Unit.tsx`));
|
|
652
719
|
return unitComponents;
|
|
653
720
|
}
|
|
654
721
|
async getTemplateComponents() {
|
|
655
|
-
const templateComponents = (await
|
|
722
|
+
const templateComponents = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/${name}/${name}.Template.tsx`));
|
|
656
723
|
return templateComponents;
|
|
657
724
|
}
|
|
658
725
|
async getViewsSourceCode() {
|
|
@@ -683,10 +750,35 @@ class SysExecutor extends Executor {
|
|
|
683
750
|
const modules = await this.getModules();
|
|
684
751
|
return modules.map((module) => this.getLocalFile(`lib/${module}/${module}.constant.ts`));
|
|
685
752
|
}
|
|
753
|
+
async getConstantFilesWithLibs() {
|
|
754
|
+
const config = await this.getConfig();
|
|
755
|
+
const sysContantFiles = await this.getConstantFiles();
|
|
756
|
+
const sysScalarConstantFiles = await this.getScalarConstantFiles();
|
|
757
|
+
const libConstantFiles = await Promise.all(
|
|
758
|
+
config.libs.map(async (lib) => [
|
|
759
|
+
...await LibExecutor.from(this, lib).getConstantFiles(),
|
|
760
|
+
...await LibExecutor.from(this, lib).getScalarConstantFiles()
|
|
761
|
+
])
|
|
762
|
+
);
|
|
763
|
+
return [...sysContantFiles, ...sysScalarConstantFiles, ...libConstantFiles.flat()];
|
|
764
|
+
}
|
|
686
765
|
async getDictionaryFiles() {
|
|
687
766
|
const modules = await this.getModules();
|
|
688
767
|
return modules.map((module) => this.getLocalFile(`lib/${module}/${module}.dictionary.ts`));
|
|
689
768
|
}
|
|
769
|
+
async applyTemplate(options) {
|
|
770
|
+
const dict = {
|
|
771
|
+
...options.dict ?? {},
|
|
772
|
+
...Object.fromEntries(
|
|
773
|
+
Object.entries(options.dict ?? {}).map(([key, value]) => [capitalize(key), capitalize(value)])
|
|
774
|
+
)
|
|
775
|
+
};
|
|
776
|
+
const akanConfig = await this.getConfig();
|
|
777
|
+
const scanResult = await this.scan({ akanConfig });
|
|
778
|
+
const fileContents = await this._applyTemplate({ ...options, scanResult, dict });
|
|
779
|
+
await this.scan({ akanConfig });
|
|
780
|
+
return fileContents;
|
|
781
|
+
}
|
|
690
782
|
setTsPaths() {
|
|
691
783
|
this.workspace.setTsPaths(this.type, this.name);
|
|
692
784
|
return this;
|
|
@@ -792,10 +884,22 @@ class PkgExecutor extends Executor {
|
|
|
792
884
|
return pkgScanResult;
|
|
793
885
|
}
|
|
794
886
|
}
|
|
887
|
+
class ModuleExecutor extends Executor {
|
|
888
|
+
sys;
|
|
889
|
+
emoji = execEmoji.module;
|
|
890
|
+
constructor({ sys, name }) {
|
|
891
|
+
super(name, `${sys.workspace.workspaceRoot}/${sys.type}s/${sys.name}/lib/${name}`);
|
|
892
|
+
this.sys = sys;
|
|
893
|
+
}
|
|
894
|
+
static from(sysExecutor, name) {
|
|
895
|
+
return new ModuleExecutor({ sys: sysExecutor, name });
|
|
896
|
+
}
|
|
897
|
+
}
|
|
795
898
|
export {
|
|
796
899
|
AppExecutor,
|
|
797
900
|
Executor,
|
|
798
901
|
LibExecutor,
|
|
902
|
+
ModuleExecutor,
|
|
799
903
|
PkgExecutor,
|
|
800
904
|
SysExecutor,
|
|
801
905
|
WorkspaceExecutor,
|
|
File without changes
|