@akanjs/devkit 0.0.139 → 0.0.141
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 +1 -1
- package/cjs/src/commandDecorators/argMeta.js +4 -1
- package/cjs/src/commandDecorators/command.js +37 -2
- package/cjs/src/executors.js +76 -15
- package/esm/src/aiEditor.js +1 -1
- package/esm/src/commandDecorators/argMeta.js +3 -1
- package/esm/src/commandDecorators/command.js +37 -2
- package/esm/src/executors.js +76 -15
- package/package.json +1 -1
- package/src/commandDecorators/argMeta.d.ts +2 -1
- package/src/executors.d.ts +22 -3
package/cjs/src/aiEditor.js
CHANGED
|
@@ -122,7 +122,7 @@ class AiSession {
|
|
|
122
122
|
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
123
123
|
let fullResponse = "", tokenIdx = 0;
|
|
124
124
|
for await (const chunk of stream) {
|
|
125
|
-
if (loader.isSpinning())
|
|
125
|
+
if (loader.isSpinning() && chunk.content.length)
|
|
126
126
|
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
127
127
|
const content = chunk.content;
|
|
128
128
|
if (typeof content === "string") {
|
|
@@ -18,6 +18,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
18
18
|
var argMeta_exports = {};
|
|
19
19
|
__export(argMeta_exports, {
|
|
20
20
|
App: () => App,
|
|
21
|
+
Argument: () => Argument,
|
|
21
22
|
Exec: () => Exec,
|
|
22
23
|
Lib: () => Lib,
|
|
23
24
|
Option: () => Option,
|
|
@@ -30,7 +31,7 @@ __export(argMeta_exports, {
|
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(argMeta_exports);
|
|
32
33
|
var import_reflect_metadata = require("reflect-metadata");
|
|
33
|
-
const argTypes = ["Option"];
|
|
34
|
+
const argTypes = ["Argument", "Option"];
|
|
34
35
|
const internalArgTypes = ["Workspace", "App", "Lib", "Sys", "Pkg", "Exec"];
|
|
35
36
|
const getArgMetas = (command, key) => {
|
|
36
37
|
const allArgMetas = getArgMetasOnPrototype(command.prototype, key);
|
|
@@ -51,6 +52,7 @@ const getArg = (type) => function(name, argsOption = {}) {
|
|
|
51
52
|
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
52
53
|
};
|
|
53
54
|
};
|
|
55
|
+
const Argument = getArg("Argument");
|
|
54
56
|
const Option = getArg("Option");
|
|
55
57
|
const createArgMetaDecorator = (type) => {
|
|
56
58
|
return function(option = {}) {
|
|
@@ -70,6 +72,7 @@ const Workspace = createArgMetaDecorator("Workspace");
|
|
|
70
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
73
|
0 && (module.exports = {
|
|
72
74
|
App,
|
|
75
|
+
Argument,
|
|
73
76
|
Exec,
|
|
74
77
|
Lib,
|
|
75
78
|
Option,
|
|
@@ -55,6 +55,16 @@ const handleOption = (programCommand, argMeta) => {
|
|
|
55
55
|
);
|
|
56
56
|
return programCommand;
|
|
57
57
|
};
|
|
58
|
+
const handleArgument = (programCommand, argMeta) => {
|
|
59
|
+
const kebabName = camelToKebabCase(argMeta.name);
|
|
60
|
+
if ((argMeta.argsOption.type ?? "string") !== "string")
|
|
61
|
+
throw new Error(`Argument type must be string: ${argMeta.name}`);
|
|
62
|
+
programCommand.argument(
|
|
63
|
+
`[${kebabName}]`,
|
|
64
|
+
`${argMeta.argsOption.desc}${argMeta.argsOption.example ? ` (example: ${argMeta.argsOption.example})` : ""}`
|
|
65
|
+
);
|
|
66
|
+
return programCommand;
|
|
67
|
+
};
|
|
58
68
|
const convertOptionValue = (value, type) => {
|
|
59
69
|
if (type === "string")
|
|
60
70
|
return value;
|
|
@@ -91,7 +101,21 @@ const getOptionValue = async (argMeta, opt) => {
|
|
|
91
101
|
return convertOptionValue(await (0, import_prompts.input)({ message }), type ?? "string");
|
|
92
102
|
}
|
|
93
103
|
};
|
|
94
|
-
const getArgumentValue = async (argMeta, value
|
|
104
|
+
const getArgumentValue = async (argMeta, value) => {
|
|
105
|
+
const {
|
|
106
|
+
name,
|
|
107
|
+
argsOption: { default: defaultValue, type, desc, nullable, example, ask }
|
|
108
|
+
} = argMeta;
|
|
109
|
+
if (value !== void 0)
|
|
110
|
+
return value;
|
|
111
|
+
else if (defaultValue !== void 0)
|
|
112
|
+
return defaultValue;
|
|
113
|
+
else if (nullable)
|
|
114
|
+
return null;
|
|
115
|
+
const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
116
|
+
return await (0, import_prompts.input)({ message });
|
|
117
|
+
};
|
|
118
|
+
const getInternalArgumentValue = async (argMeta, value, workspace) => {
|
|
95
119
|
if (argMeta.type === "Workspace")
|
|
96
120
|
return workspace;
|
|
97
121
|
const sysType = argMeta.type.toLowerCase();
|
|
@@ -156,6 +180,7 @@ const getArgumentValue = async (argMeta, value, workspace) => {
|
|
|
156
180
|
const runCommands = async (...commands) => {
|
|
157
181
|
process.on("unhandledRejection", (error) => {
|
|
158
182
|
console.error(import_chalk.default.red("[fatal]"), error);
|
|
183
|
+
process.exit(1);
|
|
159
184
|
});
|
|
160
185
|
const hasPackageJson = import_fs.default.existsSync(`${__dirname}/../package.json`);
|
|
161
186
|
const version = hasPackageJson ? JSON.parse(import_fs.default.readFileSync(`${__dirname}/../package.json`, "utf8")).version : "0.0.1";
|
|
@@ -176,6 +201,8 @@ const runCommands = async (...commands) => {
|
|
|
176
201
|
for (const argMeta of allArgMetas) {
|
|
177
202
|
if (argMeta.type === "Option")
|
|
178
203
|
programCommand = handleOption(programCommand, argMeta);
|
|
204
|
+
else if (argMeta.type === "Argument")
|
|
205
|
+
programCommand = handleArgument(programCommand, argMeta);
|
|
179
206
|
else if (argMeta.type === "Workspace")
|
|
180
207
|
continue;
|
|
181
208
|
const sysType = argMeta.type.toLowerCase();
|
|
@@ -186,6 +213,7 @@ const runCommands = async (...commands) => {
|
|
|
186
213
|
}
|
|
187
214
|
programCommand = programCommand.option(`-v, --verbose [boolean]`, `verbose output`);
|
|
188
215
|
programCommand.action(async (...args) => {
|
|
216
|
+
import_common.Logger.rawLog();
|
|
189
217
|
const cmdArgs = args.slice(0, args.length - 2);
|
|
190
218
|
const opt = args[args.length - 2];
|
|
191
219
|
const commandArgs = [];
|
|
@@ -193,8 +221,14 @@ const runCommands = async (...commands) => {
|
|
|
193
221
|
for (const argMeta of allArgMetas) {
|
|
194
222
|
if (argMeta.type === "Option")
|
|
195
223
|
commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt);
|
|
224
|
+
else if (argMeta.type === "Argument")
|
|
225
|
+
commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx]);
|
|
196
226
|
else
|
|
197
|
-
commandArgs[argMeta.idx] = await
|
|
227
|
+
commandArgs[argMeta.idx] = await getInternalArgumentValue(
|
|
228
|
+
argMeta,
|
|
229
|
+
cmdArgs[argMeta.idx],
|
|
230
|
+
workspace
|
|
231
|
+
);
|
|
198
232
|
if (commandArgs[argMeta.idx] instanceof import_executors.AppExecutor)
|
|
199
233
|
process.env.NEXT_PUBLIC_APP_NAME = commandArgs[argMeta.idx].name;
|
|
200
234
|
if (opt.verbose)
|
|
@@ -203,6 +237,7 @@ const runCommands = async (...commands) => {
|
|
|
203
237
|
const cmd = new command();
|
|
204
238
|
try {
|
|
205
239
|
await cmd[targetMeta.key](...commandArgs);
|
|
240
|
+
import_common.Logger.rawLog();
|
|
206
241
|
} catch (e) {
|
|
207
242
|
const errMsg = e instanceof Error ? e.message : typeof e === "string" ? e : JSON.stringify(e);
|
|
208
243
|
import_common.Logger.error(`Command Error: ${import_chalk.default.red(errMsg)}`);
|
package/cjs/src/executors.js
CHANGED
|
@@ -71,13 +71,20 @@ class Executor {
|
|
|
71
71
|
if (!import_fs.default.existsSync(cwdPath))
|
|
72
72
|
import_fs.default.mkdirSync(cwdPath, { recursive: true });
|
|
73
73
|
}
|
|
74
|
+
#stdout(data) {
|
|
75
|
+
if (Executor.verbose)
|
|
76
|
+
import_common.Logger.raw(import_chalk.default.dim(data.toString()));
|
|
77
|
+
}
|
|
78
|
+
#stderr(data) {
|
|
79
|
+
import_common.Logger.raw(import_chalk.default.red(data.toString()));
|
|
80
|
+
}
|
|
74
81
|
exec(command, options = {}) {
|
|
75
82
|
const proc = (0, import_child_process.exec)(command, { cwd: this.cwdPath, ...options });
|
|
76
83
|
proc.stdout?.on("data", (data) => {
|
|
77
|
-
|
|
84
|
+
this.#stdout(data);
|
|
78
85
|
});
|
|
79
86
|
proc.stderr?.on("data", (data) => {
|
|
80
|
-
|
|
87
|
+
this.#stdout(data);
|
|
81
88
|
});
|
|
82
89
|
return new Promise((resolve, reject) => {
|
|
83
90
|
proc.on("exit", (code, signal) => {
|
|
@@ -91,14 +98,14 @@ class Executor {
|
|
|
91
98
|
spawn(command, args = [], options = {}) {
|
|
92
99
|
const proc = (0, import_child_process.spawn)(command, args, {
|
|
93
100
|
cwd: this.cwdPath,
|
|
94
|
-
stdio:
|
|
101
|
+
stdio: "inherit",
|
|
95
102
|
...options
|
|
96
103
|
});
|
|
97
104
|
proc.stdout?.on("data", (data) => {
|
|
98
|
-
|
|
105
|
+
this.#stdout(data);
|
|
99
106
|
});
|
|
100
107
|
proc.stderr?.on("data", (data) => {
|
|
101
|
-
|
|
108
|
+
this.#stderr(data);
|
|
102
109
|
});
|
|
103
110
|
return new Promise((resolve, reject) => {
|
|
104
111
|
proc.on("exit", (code, signal) => {
|
|
@@ -112,14 +119,14 @@ class Executor {
|
|
|
112
119
|
fork(modulePath, args = [], options = {}) {
|
|
113
120
|
const proc = (0, import_child_process.fork)(modulePath, args, {
|
|
114
121
|
cwd: this.cwdPath,
|
|
115
|
-
stdio:
|
|
122
|
+
stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
116
123
|
...options
|
|
117
124
|
});
|
|
118
125
|
proc.stdout?.on("data", (data) => {
|
|
119
|
-
|
|
126
|
+
this.#stdout(data);
|
|
120
127
|
});
|
|
121
128
|
proc.stderr?.on("data", (data) => {
|
|
122
|
-
|
|
129
|
+
this.#stderr(data);
|
|
123
130
|
});
|
|
124
131
|
return new Promise((resolve, reject) => {
|
|
125
132
|
proc.on("exit", (code, signal) => {
|
|
@@ -144,6 +151,20 @@ class Executor {
|
|
|
144
151
|
const readPath = this.#getPath(filePath);
|
|
145
152
|
return import_fs.default.existsSync(readPath);
|
|
146
153
|
}
|
|
154
|
+
remove(filePath) {
|
|
155
|
+
const readPath = this.#getPath(filePath);
|
|
156
|
+
if (import_fs.default.existsSync(readPath))
|
|
157
|
+
import_fs.default.unlinkSync(readPath);
|
|
158
|
+
this.logger.verbose(`Remove file ${readPath}`);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
removeDir(dirPath) {
|
|
162
|
+
const readPath = this.#getPath(dirPath);
|
|
163
|
+
if (import_fs.default.existsSync(readPath))
|
|
164
|
+
import_fs.default.rmSync(readPath, { recursive: true });
|
|
165
|
+
this.logger.verbose(`Remove directory ${readPath}`);
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
147
168
|
writeFile(filePath, content, { overwrite = true } = {}) {
|
|
148
169
|
const writePath = this.#getPath(filePath);
|
|
149
170
|
const dir = import_path.default.dirname(writePath);
|
|
@@ -364,23 +385,41 @@ class WorkspaceExecutor extends Executor {
|
|
|
364
385
|
}
|
|
365
386
|
setTsPaths(type, name) {
|
|
366
387
|
const rootTsConfig = this.readJson("tsconfig.json");
|
|
367
|
-
if (type === "lib")
|
|
388
|
+
if (type === "lib" || type === "pkg")
|
|
368
389
|
rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
|
|
369
390
|
rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
|
|
391
|
+
if (rootTsConfig.references) {
|
|
392
|
+
if (!rootTsConfig.references.some((ref) => ref.path === `./${type}s/${name}/tsconfig.json`))
|
|
393
|
+
rootTsConfig.references.push({ path: `./${type}s/${name}/tsconfig.json` });
|
|
394
|
+
}
|
|
395
|
+
this.writeJson("tsconfig.json", rootTsConfig);
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
unsetTsPaths(type, name) {
|
|
399
|
+
const rootTsConfig = this.readJson("tsconfig.json");
|
|
400
|
+
const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths).filter((key) => !key.startsWith(`@${name}`));
|
|
401
|
+
rootTsConfig.compilerOptions.paths = Object.fromEntries(
|
|
402
|
+
filteredKeys.map((key) => [key, rootTsConfig.compilerOptions.paths[key]])
|
|
403
|
+
);
|
|
404
|
+
if (rootTsConfig.references) {
|
|
405
|
+
rootTsConfig.references = rootTsConfig.references.filter(
|
|
406
|
+
(ref) => !ref.path.startsWith(`./${type}s/${name}`)
|
|
407
|
+
);
|
|
408
|
+
}
|
|
370
409
|
this.writeJson("tsconfig.json", rootTsConfig);
|
|
371
410
|
return this;
|
|
372
411
|
}
|
|
373
412
|
async getDirInModule(basePath, name) {
|
|
374
|
-
const AVOID_DIRS = ["__lib", "__scalar", `_${name}`];
|
|
413
|
+
const AVOID_DIRS = ["__lib", "__scalar", `_`, `_${name}`];
|
|
375
414
|
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
376
415
|
const dirs = await import_promises.default.readdir(dirname);
|
|
377
416
|
await Promise.all(
|
|
378
417
|
dirs.map(async (dir) => {
|
|
379
|
-
if (AVOID_DIRS.includes(dir))
|
|
418
|
+
if (dir.includes("_") || AVOID_DIRS.includes(dir))
|
|
380
419
|
return;
|
|
381
420
|
const dirPath = import_path.default.join(dirname, dir);
|
|
382
421
|
if (import_fs.default.lstatSync(dirPath).isDirectory()) {
|
|
383
|
-
results.push(`${
|
|
422
|
+
results.push(`${prefix}${dir}`);
|
|
384
423
|
if (maxDepth > 0)
|
|
385
424
|
await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
386
425
|
}
|
|
@@ -427,6 +466,22 @@ class WorkspaceExecutor extends Executor {
|
|
|
427
466
|
];
|
|
428
467
|
return scalarConstantExampleFiles;
|
|
429
468
|
}
|
|
469
|
+
async getConstantFiles() {
|
|
470
|
+
const [appNames, libNames] = await this.getSyss();
|
|
471
|
+
const moduleConstantExampleFiles = [
|
|
472
|
+
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getConstantFiles()))).flat(),
|
|
473
|
+
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getConstantFiles()))).flat()
|
|
474
|
+
];
|
|
475
|
+
return moduleConstantExampleFiles;
|
|
476
|
+
}
|
|
477
|
+
async getDictionaryFiles() {
|
|
478
|
+
const [appNames, libNames] = await this.getSyss();
|
|
479
|
+
const moduleDictionaryExampleFiles = [
|
|
480
|
+
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getDictionaryFiles()))).flat(),
|
|
481
|
+
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getDictionaryFiles()))).flat()
|
|
482
|
+
];
|
|
483
|
+
return moduleDictionaryExampleFiles;
|
|
484
|
+
}
|
|
430
485
|
async getViewFiles() {
|
|
431
486
|
const [appNames, libNames] = await this.getSyss();
|
|
432
487
|
const viewExampleFiles = [
|
|
@@ -656,9 +711,15 @@ class SysExecutor extends Executor {
|
|
|
656
711
|
}
|
|
657
712
|
async getScalarDictionaryFiles() {
|
|
658
713
|
const scalarModules = await this.getScalarModules();
|
|
659
|
-
return scalarModules.map(
|
|
660
|
-
|
|
661
|
-
|
|
714
|
+
return scalarModules.map((scalarModule) => this.getLocalFile(`lib/${scalarModule}/${scalarModule}.dictionary.ts`));
|
|
715
|
+
}
|
|
716
|
+
async getConstantFiles() {
|
|
717
|
+
const modules = await this.getModules();
|
|
718
|
+
return modules.map((module2) => this.getLocalFile(`lib/${module2}/${module2}.constant.ts`));
|
|
719
|
+
}
|
|
720
|
+
async getDictionaryFiles() {
|
|
721
|
+
const modules = await this.getModules();
|
|
722
|
+
return modules.map((module2) => this.getLocalFile(`lib/${module2}/${module2}.dictionary.ts`));
|
|
662
723
|
}
|
|
663
724
|
setTsPaths() {
|
|
664
725
|
this.workspace.setTsPaths(this.type, this.name);
|
package/esm/src/aiEditor.js
CHANGED
|
@@ -89,7 +89,7 @@ class AiSession {
|
|
|
89
89
|
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
90
90
|
let fullResponse = "", tokenIdx = 0;
|
|
91
91
|
for await (const chunk of stream) {
|
|
92
|
-
if (loader.isSpinning())
|
|
92
|
+
if (loader.isSpinning() && chunk.content.length)
|
|
93
93
|
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
94
94
|
const content = chunk.content;
|
|
95
95
|
if (typeof content === "string") {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
const argTypes = ["Option"];
|
|
2
|
+
const argTypes = ["Argument", "Option"];
|
|
3
3
|
const internalArgTypes = ["Workspace", "App", "Lib", "Sys", "Pkg", "Exec"];
|
|
4
4
|
const getArgMetas = (command, key) => {
|
|
5
5
|
const allArgMetas = getArgMetasOnPrototype(command.prototype, key);
|
|
@@ -20,6 +20,7 @@ const getArg = (type) => function(name, argsOption = {}) {
|
|
|
20
20
|
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
const Argument = getArg("Argument");
|
|
23
24
|
const Option = getArg("Option");
|
|
24
25
|
const createArgMetaDecorator = (type) => {
|
|
25
26
|
return function(option = {}) {
|
|
@@ -38,6 +39,7 @@ const Pkg = createArgMetaDecorator("Pkg");
|
|
|
38
39
|
const Workspace = createArgMetaDecorator("Workspace");
|
|
39
40
|
export {
|
|
40
41
|
App,
|
|
42
|
+
Argument,
|
|
41
43
|
Exec,
|
|
42
44
|
Lib,
|
|
43
45
|
Option,
|
|
@@ -23,6 +23,16 @@ const handleOption = (programCommand, argMeta) => {
|
|
|
23
23
|
);
|
|
24
24
|
return programCommand;
|
|
25
25
|
};
|
|
26
|
+
const handleArgument = (programCommand, argMeta) => {
|
|
27
|
+
const kebabName = camelToKebabCase(argMeta.name);
|
|
28
|
+
if ((argMeta.argsOption.type ?? "string") !== "string")
|
|
29
|
+
throw new Error(`Argument type must be string: ${argMeta.name}`);
|
|
30
|
+
programCommand.argument(
|
|
31
|
+
`[${kebabName}]`,
|
|
32
|
+
`${argMeta.argsOption.desc}${argMeta.argsOption.example ? ` (example: ${argMeta.argsOption.example})` : ""}`
|
|
33
|
+
);
|
|
34
|
+
return programCommand;
|
|
35
|
+
};
|
|
26
36
|
const convertOptionValue = (value, type) => {
|
|
27
37
|
if (type === "string")
|
|
28
38
|
return value;
|
|
@@ -59,7 +69,21 @@ const getOptionValue = async (argMeta, opt) => {
|
|
|
59
69
|
return convertOptionValue(await input({ message }), type ?? "string");
|
|
60
70
|
}
|
|
61
71
|
};
|
|
62
|
-
const getArgumentValue = async (argMeta, value
|
|
72
|
+
const getArgumentValue = async (argMeta, value) => {
|
|
73
|
+
const {
|
|
74
|
+
name,
|
|
75
|
+
argsOption: { default: defaultValue, type, desc, nullable, example, ask }
|
|
76
|
+
} = argMeta;
|
|
77
|
+
if (value !== void 0)
|
|
78
|
+
return value;
|
|
79
|
+
else if (defaultValue !== void 0)
|
|
80
|
+
return defaultValue;
|
|
81
|
+
else if (nullable)
|
|
82
|
+
return null;
|
|
83
|
+
const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
84
|
+
return await input({ message });
|
|
85
|
+
};
|
|
86
|
+
const getInternalArgumentValue = async (argMeta, value, workspace) => {
|
|
63
87
|
if (argMeta.type === "Workspace")
|
|
64
88
|
return workspace;
|
|
65
89
|
const sysType = argMeta.type.toLowerCase();
|
|
@@ -124,6 +148,7 @@ const getArgumentValue = async (argMeta, value, workspace) => {
|
|
|
124
148
|
const runCommands = async (...commands) => {
|
|
125
149
|
process.on("unhandledRejection", (error) => {
|
|
126
150
|
console.error(chalk.red("[fatal]"), error);
|
|
151
|
+
process.exit(1);
|
|
127
152
|
});
|
|
128
153
|
const hasPackageJson = fs.existsSync(`${__dirname}/../package.json`);
|
|
129
154
|
const version = hasPackageJson ? JSON.parse(fs.readFileSync(`${__dirname}/../package.json`, "utf8")).version : "0.0.1";
|
|
@@ -144,6 +169,8 @@ const runCommands = async (...commands) => {
|
|
|
144
169
|
for (const argMeta of allArgMetas) {
|
|
145
170
|
if (argMeta.type === "Option")
|
|
146
171
|
programCommand = handleOption(programCommand, argMeta);
|
|
172
|
+
else if (argMeta.type === "Argument")
|
|
173
|
+
programCommand = handleArgument(programCommand, argMeta);
|
|
147
174
|
else if (argMeta.type === "Workspace")
|
|
148
175
|
continue;
|
|
149
176
|
const sysType = argMeta.type.toLowerCase();
|
|
@@ -154,6 +181,7 @@ const runCommands = async (...commands) => {
|
|
|
154
181
|
}
|
|
155
182
|
programCommand = programCommand.option(`-v, --verbose [boolean]`, `verbose output`);
|
|
156
183
|
programCommand.action(async (...args) => {
|
|
184
|
+
Logger.rawLog();
|
|
157
185
|
const cmdArgs = args.slice(0, args.length - 2);
|
|
158
186
|
const opt = args[args.length - 2];
|
|
159
187
|
const commandArgs = [];
|
|
@@ -161,8 +189,14 @@ const runCommands = async (...commands) => {
|
|
|
161
189
|
for (const argMeta of allArgMetas) {
|
|
162
190
|
if (argMeta.type === "Option")
|
|
163
191
|
commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt);
|
|
192
|
+
else if (argMeta.type === "Argument")
|
|
193
|
+
commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx]);
|
|
164
194
|
else
|
|
165
|
-
commandArgs[argMeta.idx] = await
|
|
195
|
+
commandArgs[argMeta.idx] = await getInternalArgumentValue(
|
|
196
|
+
argMeta,
|
|
197
|
+
cmdArgs[argMeta.idx],
|
|
198
|
+
workspace
|
|
199
|
+
);
|
|
166
200
|
if (commandArgs[argMeta.idx] instanceof AppExecutor)
|
|
167
201
|
process.env.NEXT_PUBLIC_APP_NAME = commandArgs[argMeta.idx].name;
|
|
168
202
|
if (opt.verbose)
|
|
@@ -171,6 +205,7 @@ const runCommands = async (...commands) => {
|
|
|
171
205
|
const cmd = new command();
|
|
172
206
|
try {
|
|
173
207
|
await cmd[targetMeta.key](...commandArgs);
|
|
208
|
+
Logger.rawLog();
|
|
174
209
|
} catch (e) {
|
|
175
210
|
const errMsg = e instanceof Error ? e.message : typeof e === "string" ? e : JSON.stringify(e);
|
|
176
211
|
Logger.error(`Command Error: ${chalk.red(errMsg)}`);
|
package/esm/src/executors.js
CHANGED
|
@@ -37,13 +37,20 @@ class Executor {
|
|
|
37
37
|
if (!fs.existsSync(cwdPath))
|
|
38
38
|
fs.mkdirSync(cwdPath, { recursive: true });
|
|
39
39
|
}
|
|
40
|
+
#stdout(data) {
|
|
41
|
+
if (Executor.verbose)
|
|
42
|
+
Logger.raw(chalk.dim(data.toString()));
|
|
43
|
+
}
|
|
44
|
+
#stderr(data) {
|
|
45
|
+
Logger.raw(chalk.red(data.toString()));
|
|
46
|
+
}
|
|
40
47
|
exec(command, options = {}) {
|
|
41
48
|
const proc = exec(command, { cwd: this.cwdPath, ...options });
|
|
42
49
|
proc.stdout?.on("data", (data) => {
|
|
43
|
-
|
|
50
|
+
this.#stdout(data);
|
|
44
51
|
});
|
|
45
52
|
proc.stderr?.on("data", (data) => {
|
|
46
|
-
|
|
53
|
+
this.#stdout(data);
|
|
47
54
|
});
|
|
48
55
|
return new Promise((resolve, reject) => {
|
|
49
56
|
proc.on("exit", (code, signal) => {
|
|
@@ -57,14 +64,14 @@ class Executor {
|
|
|
57
64
|
spawn(command, args = [], options = {}) {
|
|
58
65
|
const proc = spawn(command, args, {
|
|
59
66
|
cwd: this.cwdPath,
|
|
60
|
-
stdio:
|
|
67
|
+
stdio: "inherit",
|
|
61
68
|
...options
|
|
62
69
|
});
|
|
63
70
|
proc.stdout?.on("data", (data) => {
|
|
64
|
-
|
|
71
|
+
this.#stdout(data);
|
|
65
72
|
});
|
|
66
73
|
proc.stderr?.on("data", (data) => {
|
|
67
|
-
|
|
74
|
+
this.#stderr(data);
|
|
68
75
|
});
|
|
69
76
|
return new Promise((resolve, reject) => {
|
|
70
77
|
proc.on("exit", (code, signal) => {
|
|
@@ -78,14 +85,14 @@ class Executor {
|
|
|
78
85
|
fork(modulePath, args = [], options = {}) {
|
|
79
86
|
const proc = fork(modulePath, args, {
|
|
80
87
|
cwd: this.cwdPath,
|
|
81
|
-
stdio:
|
|
88
|
+
stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
82
89
|
...options
|
|
83
90
|
});
|
|
84
91
|
proc.stdout?.on("data", (data) => {
|
|
85
|
-
|
|
92
|
+
this.#stdout(data);
|
|
86
93
|
});
|
|
87
94
|
proc.stderr?.on("data", (data) => {
|
|
88
|
-
|
|
95
|
+
this.#stderr(data);
|
|
89
96
|
});
|
|
90
97
|
return new Promise((resolve, reject) => {
|
|
91
98
|
proc.on("exit", (code, signal) => {
|
|
@@ -110,6 +117,20 @@ class Executor {
|
|
|
110
117
|
const readPath = this.#getPath(filePath);
|
|
111
118
|
return fs.existsSync(readPath);
|
|
112
119
|
}
|
|
120
|
+
remove(filePath) {
|
|
121
|
+
const readPath = this.#getPath(filePath);
|
|
122
|
+
if (fs.existsSync(readPath))
|
|
123
|
+
fs.unlinkSync(readPath);
|
|
124
|
+
this.logger.verbose(`Remove file ${readPath}`);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
removeDir(dirPath) {
|
|
128
|
+
const readPath = this.#getPath(dirPath);
|
|
129
|
+
if (fs.existsSync(readPath))
|
|
130
|
+
fs.rmSync(readPath, { recursive: true });
|
|
131
|
+
this.logger.verbose(`Remove directory ${readPath}`);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
113
134
|
writeFile(filePath, content, { overwrite = true } = {}) {
|
|
114
135
|
const writePath = this.#getPath(filePath);
|
|
115
136
|
const dir = path.dirname(writePath);
|
|
@@ -330,23 +351,41 @@ class WorkspaceExecutor extends Executor {
|
|
|
330
351
|
}
|
|
331
352
|
setTsPaths(type, name) {
|
|
332
353
|
const rootTsConfig = this.readJson("tsconfig.json");
|
|
333
|
-
if (type === "lib")
|
|
354
|
+
if (type === "lib" || type === "pkg")
|
|
334
355
|
rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
|
|
335
356
|
rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
|
|
357
|
+
if (rootTsConfig.references) {
|
|
358
|
+
if (!rootTsConfig.references.some((ref) => ref.path === `./${type}s/${name}/tsconfig.json`))
|
|
359
|
+
rootTsConfig.references.push({ path: `./${type}s/${name}/tsconfig.json` });
|
|
360
|
+
}
|
|
361
|
+
this.writeJson("tsconfig.json", rootTsConfig);
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
unsetTsPaths(type, name) {
|
|
365
|
+
const rootTsConfig = this.readJson("tsconfig.json");
|
|
366
|
+
const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths).filter((key) => !key.startsWith(`@${name}`));
|
|
367
|
+
rootTsConfig.compilerOptions.paths = Object.fromEntries(
|
|
368
|
+
filteredKeys.map((key) => [key, rootTsConfig.compilerOptions.paths[key]])
|
|
369
|
+
);
|
|
370
|
+
if (rootTsConfig.references) {
|
|
371
|
+
rootTsConfig.references = rootTsConfig.references.filter(
|
|
372
|
+
(ref) => !ref.path.startsWith(`./${type}s/${name}`)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
336
375
|
this.writeJson("tsconfig.json", rootTsConfig);
|
|
337
376
|
return this;
|
|
338
377
|
}
|
|
339
378
|
async getDirInModule(basePath, name) {
|
|
340
|
-
const AVOID_DIRS = ["__lib", "__scalar", `_${name}`];
|
|
379
|
+
const AVOID_DIRS = ["__lib", "__scalar", `_`, `_${name}`];
|
|
341
380
|
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
342
381
|
const dirs = await fsPromise.readdir(dirname);
|
|
343
382
|
await Promise.all(
|
|
344
383
|
dirs.map(async (dir) => {
|
|
345
|
-
if (AVOID_DIRS.includes(dir))
|
|
384
|
+
if (dir.includes("_") || AVOID_DIRS.includes(dir))
|
|
346
385
|
return;
|
|
347
386
|
const dirPath = path.join(dirname, dir);
|
|
348
387
|
if (fs.lstatSync(dirPath).isDirectory()) {
|
|
349
|
-
results.push(`${
|
|
388
|
+
results.push(`${prefix}${dir}`);
|
|
350
389
|
if (maxDepth > 0)
|
|
351
390
|
await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
352
391
|
}
|
|
@@ -393,6 +432,22 @@ class WorkspaceExecutor extends Executor {
|
|
|
393
432
|
];
|
|
394
433
|
return scalarConstantExampleFiles;
|
|
395
434
|
}
|
|
435
|
+
async getConstantFiles() {
|
|
436
|
+
const [appNames, libNames] = await this.getSyss();
|
|
437
|
+
const moduleConstantExampleFiles = [
|
|
438
|
+
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getConstantFiles()))).flat(),
|
|
439
|
+
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getConstantFiles()))).flat()
|
|
440
|
+
];
|
|
441
|
+
return moduleConstantExampleFiles;
|
|
442
|
+
}
|
|
443
|
+
async getDictionaryFiles() {
|
|
444
|
+
const [appNames, libNames] = await this.getSyss();
|
|
445
|
+
const moduleDictionaryExampleFiles = [
|
|
446
|
+
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getDictionaryFiles()))).flat(),
|
|
447
|
+
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getDictionaryFiles()))).flat()
|
|
448
|
+
];
|
|
449
|
+
return moduleDictionaryExampleFiles;
|
|
450
|
+
}
|
|
396
451
|
async getViewFiles() {
|
|
397
452
|
const [appNames, libNames] = await this.getSyss();
|
|
398
453
|
const viewExampleFiles = [
|
|
@@ -622,9 +677,15 @@ class SysExecutor extends Executor {
|
|
|
622
677
|
}
|
|
623
678
|
async getScalarDictionaryFiles() {
|
|
624
679
|
const scalarModules = await this.getScalarModules();
|
|
625
|
-
return scalarModules.map(
|
|
626
|
-
|
|
627
|
-
|
|
680
|
+
return scalarModules.map((scalarModule) => this.getLocalFile(`lib/${scalarModule}/${scalarModule}.dictionary.ts`));
|
|
681
|
+
}
|
|
682
|
+
async getConstantFiles() {
|
|
683
|
+
const modules = await this.getModules();
|
|
684
|
+
return modules.map((module) => this.getLocalFile(`lib/${module}/${module}.constant.ts`));
|
|
685
|
+
}
|
|
686
|
+
async getDictionaryFiles() {
|
|
687
|
+
const modules = await this.getModules();
|
|
688
|
+
return modules.map((module) => this.getLocalFile(`lib/${module}/${module}.dictionary.ts`));
|
|
628
689
|
}
|
|
629
690
|
setTsPaths() {
|
|
630
691
|
this.workspace.setTsPaths(this.type, this.name);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import type { AppExecutor, Executor, LibExecutor, PkgExecutor, SysExecutor, WorkspaceExecutor } from "../executors";
|
|
3
3
|
import type { Type } from "./types";
|
|
4
|
-
export declare const argTypes: readonly ["Option"];
|
|
4
|
+
export declare const argTypes: readonly ["Argument", "Option"];
|
|
5
5
|
export type ArgType = (typeof argTypes)[number];
|
|
6
6
|
export declare const internalArgTypes: readonly ["Workspace", "App", "Lib", "Sys", "Pkg", "Exec"];
|
|
7
7
|
export type InternalArgType = (typeof internalArgTypes)[number];
|
|
@@ -31,6 +31,7 @@ export interface InternalArgMeta {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
export declare const getArgMetas: (command: Type, key: string) => [(ArgMeta | InternalArgMeta)[], ArgMeta[], InternalArgMeta[]];
|
|
34
|
+
export declare const Argument: (name: string, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
|
|
34
35
|
export declare const Option: (name: string, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
|
|
35
36
|
export declare const App: (option?: {
|
|
36
37
|
nullable?: boolean;
|
package/src/executors.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare class Executor {
|
|
|
28
28
|
fork(modulePath: string, args?: string[], options?: ForkOptions): Promise<unknown>;
|
|
29
29
|
mkdir(dirPath: string): this;
|
|
30
30
|
exists(filePath: string): boolean;
|
|
31
|
+
remove(filePath: string): this;
|
|
32
|
+
removeDir(dirPath: string): this;
|
|
31
33
|
writeFile(filePath: string, content: string | object, { overwrite }?: {
|
|
32
34
|
overwrite?: boolean;
|
|
33
35
|
}): this;
|
|
@@ -71,7 +73,7 @@ export declare class WorkspaceExecutor extends Executor {
|
|
|
71
73
|
getBaseDevEnv(): {
|
|
72
74
|
repoName: string;
|
|
73
75
|
serveDomain: string;
|
|
74
|
-
env: "
|
|
76
|
+
env: "debug" | "testing" | "local" | "develop" | "main";
|
|
75
77
|
name?: string | undefined;
|
|
76
78
|
};
|
|
77
79
|
scan(): Promise<WorkspaceScanResult>;
|
|
@@ -80,7 +82,8 @@ export declare class WorkspaceExecutor extends Executor {
|
|
|
80
82
|
getSyss(): Promise<[string[], string[]]>;
|
|
81
83
|
getPkgs(): Promise<string[]>;
|
|
82
84
|
getExecs(): Promise<[string[], string[], string[]]>;
|
|
83
|
-
setTsPaths(type: "app" | "lib", name: string): this;
|
|
85
|
+
setTsPaths(type: "app" | "lib" | "pkg", name: string): this;
|
|
86
|
+
unsetTsPaths(type: "app" | "lib" | "pkg", name: string): this;
|
|
84
87
|
getDirInModule(basePath: string, name: string): Promise<string[]>;
|
|
85
88
|
commit(message: string, { init, add }?: {
|
|
86
89
|
init?: boolean;
|
|
@@ -90,6 +93,14 @@ export declare class WorkspaceExecutor extends Executor {
|
|
|
90
93
|
filepath: string;
|
|
91
94
|
content: string;
|
|
92
95
|
}[]>;
|
|
96
|
+
getConstantFiles(): Promise<{
|
|
97
|
+
filepath: string;
|
|
98
|
+
content: string;
|
|
99
|
+
}[]>;
|
|
100
|
+
getDictionaryFiles(): Promise<{
|
|
101
|
+
filepath: string;
|
|
102
|
+
content: string;
|
|
103
|
+
}[]>;
|
|
93
104
|
getViewFiles(): Promise<{
|
|
94
105
|
filepath: string;
|
|
95
106
|
content: string;
|
|
@@ -144,6 +155,14 @@ export declare class SysExecutor extends Executor {
|
|
|
144
155
|
filepath: string;
|
|
145
156
|
content: string;
|
|
146
157
|
}[]>;
|
|
158
|
+
getConstantFiles(): Promise<{
|
|
159
|
+
filepath: string;
|
|
160
|
+
content: string;
|
|
161
|
+
}[]>;
|
|
162
|
+
getDictionaryFiles(): Promise<{
|
|
163
|
+
filepath: string;
|
|
164
|
+
content: string;
|
|
165
|
+
}[]>;
|
|
147
166
|
setTsPaths(): this;
|
|
148
167
|
}
|
|
149
168
|
interface AppExecutorOptions {
|
|
@@ -155,7 +174,7 @@ export declare class AppExecutor extends SysExecutor {
|
|
|
155
174
|
emoji: string;
|
|
156
175
|
constructor({ workspace, name }: AppExecutorOptions);
|
|
157
176
|
static from(executor: SysExecutor | WorkspaceExecutor, name: string): AppExecutor;
|
|
158
|
-
getEnv(): "
|
|
177
|
+
getEnv(): "debug" | "testing" | "local" | "develop" | "main";
|
|
159
178
|
getConfig(command?: string): Promise<AppConfigResult>;
|
|
160
179
|
syncAssets(libDeps: string[]): Promise<void>;
|
|
161
180
|
}
|