@akanjs/devkit 1.0.20 → 2.1.0-rc.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/README.ko.md +65 -0
- package/README.md +62 -6
- package/aiEditor.ts +304 -0
- package/akanApp/akanApp.host.ts +393 -0
- package/akanApp/index.ts +1 -0
- package/akanConfig/akanConfig.test.ts +236 -0
- package/akanConfig/akanConfig.ts +384 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/types.ts +23 -0
- package/applicationBuildReporter.ts +69 -0
- package/applicationBuildRunner.ts +302 -0
- package/applicationReleasePackager.ts +206 -0
- package/artifact/implicitRootLayout.ts +155 -0
- package/artifact/index.ts +1 -0
- package/artifact/routeSeedIndex.test.ts +98 -0
- package/artifact/routeSeedIndex.ts +130 -0
- package/auth.ts +41 -0
- package/builder.ts +164 -0
- package/capacitor.base.config.ts +88 -0
- package/capacitorApp.ts +440 -0
- package/commandDecorators/argMeta.ts +102 -0
- package/commandDecorators/command.ts +351 -0
- package/commandDecorators/commandBuilder.ts +224 -0
- package/commandDecorators/commandDecorators.test.ts +212 -0
- package/commandDecorators/commandMeta.ts +7 -0
- package/commandDecorators/dependencyBuilder.ts +100 -0
- package/{esm/src/commandDecorators/helpFormatter.js → commandDecorators/helpFormatter.ts} +100 -47
- package/{esm/src/commandDecorators/index.js → commandDecorators/index.ts} +4 -2
- package/commandDecorators/targetMeta.ts +31 -0
- package/commandDecorators/types.ts +10 -0
- package/constants.ts +25 -0
- package/createTunnel.ts +36 -0
- package/dependencyScanner.ts +357 -0
- package/devkitUtils.test.ts +259 -0
- package/executors.test.ts +315 -0
- package/executors.ts +1390 -0
- package/{esm/src/extractDeps.js → extractDeps.ts} +26 -20
- package/{esm/src/fileEditor.js → fileEditor.ts} +51 -32
- package/fileSys.ts +39 -0
- package/frontendBuild/allRoutesBuilder.ts +103 -0
- package/frontendBuild/buildRouteClient.test.ts +190 -0
- package/frontendBuild/clientBuildTypes.ts +114 -0
- package/frontendBuild/clientEntriesBundler.ts +303 -0
- package/frontendBuild/clientEntryDiscovery.ts +199 -0
- package/frontendBuild/csrArtifactBuilder.ts +237 -0
- package/frontendBuild/cssCompiler.ts +286 -0
- package/frontendBuild/cssImportResolver.ts +116 -0
- package/frontendBuild/fontOptimizer.ts +427 -0
- package/frontendBuild/frontendBuild.test.ts +204 -0
- package/frontendBuild/hmrChangeClassifier.ts +28 -0
- package/frontendBuild/hmrWatcher.ts +102 -0
- package/frontendBuild/index.ts +18 -0
- package/frontendBuild/pagesBundleBuilder.ts +137 -0
- package/frontendBuild/pagesEntrySourceGenerator.ts +37 -0
- package/frontendBuild/precompressArtifacts.ts +59 -0
- package/frontendBuild/routeClientBuilder.ts +290 -0
- package/frontendBuild/routesManifestArtifactSerializer.ts +62 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +139 -0
- package/frontendBuild/vendorSpecifiers.ts +16 -0
- package/frontendBuild/watchRootResolver.ts +28 -0
- package/getCredentials.ts +19 -0
- package/getDirname.ts +3 -0
- package/getModelFileData.ts +59 -0
- package/getRelatedCnsts.ts +313 -0
- package/guideline.ts +19 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +51 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +152 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +331 -0
- package/incrementalBuilder/index.ts +1 -0
- package/{esm/src/index.js → index.ts} +28 -15
- package/lint/no-deep-internal-import.grit +25 -0
- package/lint/no-import-client-functions.grit +32 -0
- package/lint/no-import-external-library.grit +21 -0
- package/lint/no-js-private-class-method.grit +42 -0
- package/lint/no-use-client-in-server.grit +7 -0
- package/lint/non-scalar-props-restricted.grit +13 -0
- package/linter.ts +271 -0
- package/mobile/index.ts +1 -0
- package/mobile/mobileTarget.test.ts +53 -0
- package/mobile/mobileTarget.ts +88 -0
- package/package.json +48 -31
- package/prompter.ts +72 -0
- package/scanInfo.ts +606 -0
- package/selectModel.ts +11 -0
- package/{esm/src/spinner.js → spinner.ts} +22 -28
- package/{esm/src/capacitorApp.js → src/capacitorApp.ts} +82 -81
- package/sshTunnel.ts +152 -0
- package/{esm/src/streamAi.js → streamAi.ts} +18 -12
- package/transforms/barrelAnalyzer.ts +278 -0
- package/transforms/barrelImportsPlugin.ts +504 -0
- package/transforms/externalizeFrameworkPlugin.ts +185 -0
- package/transforms/index.ts +5 -0
- package/transforms/rscUseClientTransform.ts +59 -0
- package/transforms/transforms.test.ts +208 -0
- package/transforms/useClientBundlePlugin.ts +47 -0
- package/tsconfig.json +37 -0
- package/typeChecker.ts +264 -0
- package/types.ts +44 -0
- package/ui/MultiScrollList.tsx +242 -0
- package/ui/ScrollList.tsx +107 -0
- package/ui/index.ts +2 -0
- package/{esm/src/uploadRelease.js → uploadRelease.ts} +50 -34
- package/{esm/src/useStdoutDimensions.js → useStdoutDimensions.ts} +5 -5
- package/cjs/index.js +0 -21
- package/cjs/src/aiEditor.js +0 -311
- package/cjs/src/auth.js +0 -72
- package/cjs/src/builder.js +0 -114
- package/cjs/src/capacitorApp.js +0 -313
- package/cjs/src/commandDecorators/argMeta.js +0 -88
- package/cjs/src/commandDecorators/command.js +0 -324
- package/cjs/src/commandDecorators/commandMeta.js +0 -30
- package/cjs/src/commandDecorators/helpFormatter.js +0 -211
- package/cjs/src/commandDecorators/index.js +0 -31
- package/cjs/src/commandDecorators/targetMeta.js +0 -57
- package/cjs/src/commandDecorators/types.js +0 -15
- package/cjs/src/constants.js +0 -46
- package/cjs/src/createTunnel.js +0 -49
- package/cjs/src/dependencyScanner.js +0 -220
- package/cjs/src/executors.js +0 -964
- package/cjs/src/extractDeps.js +0 -103
- package/cjs/src/fileEditor.js +0 -120
- package/cjs/src/getCredentials.js +0 -44
- package/cjs/src/getDirname.js +0 -38
- package/cjs/src/getModelFileData.js +0 -66
- package/cjs/src/getRelatedCnsts.js +0 -260
- package/cjs/src/guideline.js +0 -15
- package/cjs/src/index.js +0 -65
- package/cjs/src/linter.js +0 -238
- package/cjs/src/prompter.js +0 -85
- package/cjs/src/scanInfo.js +0 -491
- package/cjs/src/selectModel.js +0 -46
- package/cjs/src/spinner.js +0 -93
- package/cjs/src/streamAi.js +0 -62
- package/cjs/src/typeChecker.js +0 -207
- package/cjs/src/types.js +0 -15
- package/cjs/src/uploadRelease.js +0 -112
- package/cjs/src/useStdoutDimensions.js +0 -43
- package/esm/index.js +0 -1
- package/esm/src/aiEditor.js +0 -282
- package/esm/src/auth.js +0 -42
- package/esm/src/builder.js +0 -81
- package/esm/src/commandDecorators/argMeta.js +0 -54
- package/esm/src/commandDecorators/command.js +0 -290
- package/esm/src/commandDecorators/commandMeta.js +0 -7
- package/esm/src/commandDecorators/targetMeta.js +0 -33
- package/esm/src/commandDecorators/types.js +0 -0
- package/esm/src/constants.js +0 -17
- package/esm/src/createTunnel.js +0 -26
- package/esm/src/dependencyScanner.js +0 -187
- package/esm/src/executors.js +0 -928
- package/esm/src/getCredentials.js +0 -11
- package/esm/src/getDirname.js +0 -5
- package/esm/src/getModelFileData.js +0 -33
- package/esm/src/getRelatedCnsts.js +0 -221
- package/esm/src/guideline.js +0 -0
- package/esm/src/linter.js +0 -205
- package/esm/src/prompter.js +0 -51
- package/esm/src/scanInfo.js +0 -455
- package/esm/src/selectModel.js +0 -13
- package/esm/src/typeChecker.js +0 -174
- package/esm/src/types.js +0 -0
- package/index.d.ts +0 -1
- package/src/aiEditor.d.ts +0 -50
- package/src/auth.d.ts +0 -9
- package/src/builder.d.ts +0 -18
- package/src/capacitorApp.d.ts +0 -39
- package/src/commandDecorators/argMeta.d.ts +0 -67
- package/src/commandDecorators/command.d.ts +0 -2
- package/src/commandDecorators/commandMeta.d.ts +0 -2
- package/src/commandDecorators/helpFormatter.d.ts +0 -3
- package/src/commandDecorators/index.d.ts +0 -6
- package/src/commandDecorators/targetMeta.d.ts +0 -19
- package/src/commandDecorators/types.d.ts +0 -1
- package/src/constants.d.ts +0 -26
- package/src/createTunnel.d.ts +0 -8
- package/src/dependencyScanner.d.ts +0 -23
- package/src/executors.d.ts +0 -296
- package/src/extractDeps.d.ts +0 -7
- package/src/fileEditor.d.ts +0 -16
- package/src/getCredentials.d.ts +0 -12
- package/src/getDirname.d.ts +0 -1
- package/src/getModelFileData.d.ts +0 -16
- package/src/getRelatedCnsts.d.ts +0 -53
- package/src/guideline.d.ts +0 -19
- package/src/index.d.ts +0 -23
- package/src/linter.d.ts +0 -109
- package/src/prompter.d.ts +0 -14
- package/src/scanInfo.d.ts +0 -82
- package/src/selectModel.d.ts +0 -1
- package/src/spinner.d.ts +0 -20
- package/src/streamAi.d.ts +0 -6
- package/src/typeChecker.d.ts +0 -52
- package/src/types.d.ts +0 -31
- package/src/uploadRelease.d.ts +0 -10
- package/src/useStdoutDimensions.d.ts +0 -1
package/cjs/src/executors.js
DELETED
|
@@ -1,964 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var executors_exports = {};
|
|
29
|
-
__export(executors_exports, {
|
|
30
|
-
AppExecutor: () => AppExecutor,
|
|
31
|
-
Executor: () => Executor,
|
|
32
|
-
LibExecutor: () => LibExecutor,
|
|
33
|
-
ModuleExecutor: () => ModuleExecutor,
|
|
34
|
-
PkgExecutor: () => PkgExecutor,
|
|
35
|
-
SysExecutor: () => SysExecutor,
|
|
36
|
-
WorkspaceExecutor: () => WorkspaceExecutor,
|
|
37
|
-
execEmoji: () => execEmoji
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(executors_exports);
|
|
40
|
-
var import_common = require("@akanjs/common");
|
|
41
|
-
var import_config = require("@akanjs/config");
|
|
42
|
-
var import_chalk = __toESM(require("chalk"));
|
|
43
|
-
var import_child_process = require("child_process");
|
|
44
|
-
var import_dotenv = __toESM(require("dotenv"));
|
|
45
|
-
var import_fs = __toESM(require("fs"));
|
|
46
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
47
|
-
var import_path = __toESM(require("path"));
|
|
48
|
-
var import_getDirname = require("./getDirname");
|
|
49
|
-
var import_linter = require("./linter");
|
|
50
|
-
var import_scanInfo = require("./scanInfo");
|
|
51
|
-
var import_spinner = require("./spinner");
|
|
52
|
-
var import_typeChecker = require("./typeChecker");
|
|
53
|
-
const import_meta = {};
|
|
54
|
-
const execEmoji = {
|
|
55
|
-
workspace: "\u{1F3E0}",
|
|
56
|
-
app: "\u{1F680}",
|
|
57
|
-
lib: "\u{1F527}",
|
|
58
|
-
pkg: "\u{1F4E6}",
|
|
59
|
-
dist: "\u{1F4BF}",
|
|
60
|
-
module: "\u2699\uFE0F",
|
|
61
|
-
default: "\u2708\uFE0F"
|
|
62
|
-
// for sys executor
|
|
63
|
-
};
|
|
64
|
-
class Executor {
|
|
65
|
-
static verbose = false;
|
|
66
|
-
static setVerbose(verbose) {
|
|
67
|
-
Executor.verbose = verbose;
|
|
68
|
-
}
|
|
69
|
-
name;
|
|
70
|
-
logger;
|
|
71
|
-
logs;
|
|
72
|
-
cwdPath;
|
|
73
|
-
emoji = execEmoji.default;
|
|
74
|
-
typeChecker = null;
|
|
75
|
-
linter = null;
|
|
76
|
-
constructor(name, cwdPath) {
|
|
77
|
-
this.name = name;
|
|
78
|
-
this.logger = new import_common.Logger(name);
|
|
79
|
-
this.logs = [];
|
|
80
|
-
this.cwdPath = cwdPath;
|
|
81
|
-
if (!import_fs.default.existsSync(cwdPath))
|
|
82
|
-
import_fs.default.mkdirSync(cwdPath, { recursive: true });
|
|
83
|
-
}
|
|
84
|
-
#stdout(data) {
|
|
85
|
-
if (Executor.verbose)
|
|
86
|
-
import_common.Logger.raw(import_chalk.default.dim(data.toString()));
|
|
87
|
-
}
|
|
88
|
-
#stderr(data) {
|
|
89
|
-
import_common.Logger.raw(import_chalk.default.red(data.toString()));
|
|
90
|
-
}
|
|
91
|
-
exec(command, options = {}) {
|
|
92
|
-
const proc = (0, import_child_process.exec)(command, { cwd: this.cwdPath, ...options });
|
|
93
|
-
proc.stdout?.on("data", (data) => {
|
|
94
|
-
this.#stdout(data);
|
|
95
|
-
});
|
|
96
|
-
proc.stderr?.on("data", (data) => {
|
|
97
|
-
this.#stdout(data);
|
|
98
|
-
});
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
proc.on("exit", (code, signal) => {
|
|
101
|
-
if (!!code || signal)
|
|
102
|
-
reject({ code, signal });
|
|
103
|
-
else
|
|
104
|
-
resolve({ code, signal });
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
spawn(command, args = [], options = {}) {
|
|
109
|
-
const proc = (0, import_child_process.spawn)(command, args, {
|
|
110
|
-
cwd: this.cwdPath,
|
|
111
|
-
// stdio: "inherit",
|
|
112
|
-
...options
|
|
113
|
-
});
|
|
114
|
-
let stdout = "";
|
|
115
|
-
let stderr = "";
|
|
116
|
-
proc.stdout?.on("data", (data) => {
|
|
117
|
-
stdout += data.toString();
|
|
118
|
-
this.logs.push(data.toString());
|
|
119
|
-
this.#stdout(data);
|
|
120
|
-
});
|
|
121
|
-
proc.stderr?.on("data", (data) => {
|
|
122
|
-
stderr += data.toString();
|
|
123
|
-
this.logs.push(data.toString());
|
|
124
|
-
this.#stdout(data);
|
|
125
|
-
});
|
|
126
|
-
return new Promise((resolve, reject) => {
|
|
127
|
-
proc.on("exit", (code, signal) => {
|
|
128
|
-
if (code !== 0 || signal)
|
|
129
|
-
reject(stdout);
|
|
130
|
-
else
|
|
131
|
-
resolve(stdout);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
spawnSync(command, args = [], options = {}) {
|
|
136
|
-
const proc = (0, import_child_process.spawn)(command, args, {
|
|
137
|
-
cwd: this.cwdPath,
|
|
138
|
-
// stdio: "inherit",
|
|
139
|
-
...options
|
|
140
|
-
});
|
|
141
|
-
return proc;
|
|
142
|
-
}
|
|
143
|
-
fork(modulePath, args = [], options = {}) {
|
|
144
|
-
const proc = (0, import_child_process.fork)(modulePath, args, {
|
|
145
|
-
cwd: this.cwdPath,
|
|
146
|
-
// stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
147
|
-
...options
|
|
148
|
-
});
|
|
149
|
-
proc.stdout?.on("data", (data) => {
|
|
150
|
-
this.#stdout(data);
|
|
151
|
-
});
|
|
152
|
-
proc.stderr?.on("data", (data) => {
|
|
153
|
-
this.#stderr(data);
|
|
154
|
-
});
|
|
155
|
-
return new Promise((resolve, reject) => {
|
|
156
|
-
proc.on("exit", (code, signal) => {
|
|
157
|
-
if (!!code || signal)
|
|
158
|
-
reject({ code, signal });
|
|
159
|
-
else
|
|
160
|
-
resolve({ code, signal });
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
getPath(filePath) {
|
|
165
|
-
if (import_path.default.isAbsolute(filePath))
|
|
166
|
-
return filePath;
|
|
167
|
-
const baseParts = this.cwdPath.split("/").filter(Boolean);
|
|
168
|
-
const targetParts = filePath.split("/").filter(Boolean);
|
|
169
|
-
let overlapLength = 0;
|
|
170
|
-
for (let i = 1; i <= Math.min(baseParts.length, targetParts.length); i++) {
|
|
171
|
-
let isOverlap = true;
|
|
172
|
-
for (let j = 0; j < i; j++)
|
|
173
|
-
if (baseParts[baseParts.length - i + j] !== targetParts[j]) {
|
|
174
|
-
isOverlap = false;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
if (isOverlap)
|
|
178
|
-
overlapLength = i;
|
|
179
|
-
}
|
|
180
|
-
const result = overlapLength > 0 ? `/${[...baseParts, ...targetParts.slice(overlapLength)].join("/")}` : `${this.cwdPath}/${filePath}`;
|
|
181
|
-
return result.replace(/\/+/g, "/");
|
|
182
|
-
}
|
|
183
|
-
mkdir(dirPath) {
|
|
184
|
-
const writePath = this.getPath(dirPath);
|
|
185
|
-
if (!import_fs.default.existsSync(writePath))
|
|
186
|
-
import_fs.default.mkdirSync(writePath, { recursive: true });
|
|
187
|
-
this.logger.verbose(`Make directory ${writePath}`);
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
|
-
async readdir(dirPath) {
|
|
191
|
-
const readPath = this.getPath(dirPath);
|
|
192
|
-
try {
|
|
193
|
-
return await import_promises.default.readdir(readPath);
|
|
194
|
-
} catch (error) {
|
|
195
|
-
return [];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
async getFilesAndDirs(dirPath) {
|
|
199
|
-
const paths = await this.readdir(dirPath);
|
|
200
|
-
const files = [];
|
|
201
|
-
const dirs = [];
|
|
202
|
-
const fullDirPath = this.getPath(dirPath);
|
|
203
|
-
await Promise.all(
|
|
204
|
-
paths.map(async (p) => {
|
|
205
|
-
const stats = await import_promises.default.stat(import_path.default.join(fullDirPath, p));
|
|
206
|
-
if (stats.isDirectory())
|
|
207
|
-
dirs.push(p);
|
|
208
|
-
else
|
|
209
|
-
files.push(p);
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
|
-
return { files, dirs };
|
|
213
|
-
}
|
|
214
|
-
exists(filePath) {
|
|
215
|
-
const readPath = this.getPath(filePath);
|
|
216
|
-
return import_fs.default.existsSync(readPath);
|
|
217
|
-
}
|
|
218
|
-
remove(filePath) {
|
|
219
|
-
const readPath = this.getPath(filePath);
|
|
220
|
-
if (import_fs.default.existsSync(readPath))
|
|
221
|
-
import_fs.default.unlinkSync(readPath);
|
|
222
|
-
this.logger.verbose(`Remove file ${readPath}`);
|
|
223
|
-
return this;
|
|
224
|
-
}
|
|
225
|
-
async removeDir(dirPath) {
|
|
226
|
-
const readPath = this.getPath(dirPath);
|
|
227
|
-
if (import_fs.default.existsSync(readPath))
|
|
228
|
-
await import_fs.default.promises.rm(readPath, { recursive: true });
|
|
229
|
-
this.logger.verbose(`Remove directory ${readPath}`);
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
writeFile(filePath, content, { overwrite = true } = {}) {
|
|
233
|
-
const writePath = this.getPath(filePath);
|
|
234
|
-
const dir = import_path.default.dirname(writePath);
|
|
235
|
-
if (!import_fs.default.existsSync(dir))
|
|
236
|
-
import_fs.default.mkdirSync(dir, { recursive: true });
|
|
237
|
-
let contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
|
|
238
|
-
if (import_fs.default.existsSync(writePath)) {
|
|
239
|
-
const currentContent = import_fs.default.readFileSync(writePath, "utf8");
|
|
240
|
-
if (currentContent === contentStr || !overwrite) {
|
|
241
|
-
this.logger.verbose(`File ${writePath} is unchanged`);
|
|
242
|
-
contentStr = import_fs.default.readFileSync(writePath, "utf-8");
|
|
243
|
-
} else {
|
|
244
|
-
import_fs.default.writeFileSync(writePath, contentStr, "utf8");
|
|
245
|
-
if (import_common.Logger.isVerbose())
|
|
246
|
-
this.logger.rawLog(import_chalk.default.yellow(`File Update: ${filePath}`));
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
import_fs.default.writeFileSync(writePath, contentStr, "utf8");
|
|
250
|
-
this.logger.rawLog(import_chalk.default.green(`File Create: ${filePath}`));
|
|
251
|
-
}
|
|
252
|
-
return { filePath: writePath, content: contentStr };
|
|
253
|
-
}
|
|
254
|
-
writeJson(filePath, content) {
|
|
255
|
-
this.writeFile(filePath, JSON.stringify(content, null, 2) + "\n");
|
|
256
|
-
return this;
|
|
257
|
-
}
|
|
258
|
-
getLocalFile(targetPath) {
|
|
259
|
-
const filePath = import_path.default.isAbsolute(targetPath) ? targetPath : targetPath.replace(this.cwdPath, "");
|
|
260
|
-
const content = this.readFile(filePath);
|
|
261
|
-
return { filePath, content };
|
|
262
|
-
}
|
|
263
|
-
readFile(filePath) {
|
|
264
|
-
const readPath = this.getPath(filePath);
|
|
265
|
-
return import_fs.default.readFileSync(readPath, "utf8");
|
|
266
|
-
}
|
|
267
|
-
readJson(filePath) {
|
|
268
|
-
const readPath = this.getPath(filePath);
|
|
269
|
-
return JSON.parse(import_fs.default.readFileSync(readPath, "utf8"));
|
|
270
|
-
}
|
|
271
|
-
async cp(srcPath, destPath) {
|
|
272
|
-
const src = this.getPath(srcPath);
|
|
273
|
-
const dest = this.getPath(destPath);
|
|
274
|
-
if (!import_fs.default.existsSync(src))
|
|
275
|
-
return;
|
|
276
|
-
const isDirectory = import_fs.default.statSync(src).isDirectory();
|
|
277
|
-
if (!import_fs.default.existsSync(dest) && isDirectory)
|
|
278
|
-
await import_promises.default.mkdir(dest, { recursive: true });
|
|
279
|
-
await import_promises.default.cp(src, dest, { recursive: true });
|
|
280
|
-
}
|
|
281
|
-
log(msg) {
|
|
282
|
-
this.logger.info(msg);
|
|
283
|
-
return this;
|
|
284
|
-
}
|
|
285
|
-
verbose(msg) {
|
|
286
|
-
this.logger.verbose(msg);
|
|
287
|
-
return this;
|
|
288
|
-
}
|
|
289
|
-
debug(msg) {
|
|
290
|
-
this.logger.debug(msg);
|
|
291
|
-
return this;
|
|
292
|
-
}
|
|
293
|
-
spinning(msg, { prefix = `${this.emoji}${this.name}`, indent = 0, enableSpin = !Executor.verbose } = {}) {
|
|
294
|
-
return new import_spinner.Spinner(msg, { prefix, indent, enableSpin }).start();
|
|
295
|
-
}
|
|
296
|
-
#tsconfig = null;
|
|
297
|
-
getTsConfig(pathname = "tsconfig.json", { refresh } = {}) {
|
|
298
|
-
if (this.#tsconfig && !refresh)
|
|
299
|
-
return this.#tsconfig;
|
|
300
|
-
const tsconfig = this.readJson(pathname);
|
|
301
|
-
if (tsconfig.extends) {
|
|
302
|
-
const extendsTsconfig = this.getTsConfig(tsconfig.extends);
|
|
303
|
-
return {
|
|
304
|
-
...extendsTsconfig,
|
|
305
|
-
...tsconfig,
|
|
306
|
-
compilerOptions: { ...extendsTsconfig.compilerOptions, ...tsconfig.compilerOptions }
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
this.#tsconfig = tsconfig;
|
|
310
|
-
return tsconfig;
|
|
311
|
-
}
|
|
312
|
-
setTsConfig(tsconfig) {
|
|
313
|
-
this.writeJson("tsconfig.json", tsconfig);
|
|
314
|
-
this.#tsconfig = tsconfig;
|
|
315
|
-
}
|
|
316
|
-
#packageJson = null;
|
|
317
|
-
getPackageJson({ refresh } = {}) {
|
|
318
|
-
if (this.#packageJson && !refresh)
|
|
319
|
-
return this.#packageJson;
|
|
320
|
-
const packageJson = this.readJson("package.json");
|
|
321
|
-
this.#packageJson = packageJson;
|
|
322
|
-
return packageJson;
|
|
323
|
-
}
|
|
324
|
-
setPackageJson(packageJson) {
|
|
325
|
-
this.writeJson("package.json", packageJson);
|
|
326
|
-
this.#packageJson = packageJson;
|
|
327
|
-
}
|
|
328
|
-
#gitignorePatterns = [];
|
|
329
|
-
getGitignorePatterns() {
|
|
330
|
-
if (this.#gitignorePatterns.length)
|
|
331
|
-
return this.#gitignorePatterns;
|
|
332
|
-
const gitignore = this.readFile(".gitignore");
|
|
333
|
-
this.#gitignorePatterns = gitignore.split("\n").map((line) => line.trim()).filter((line) => !!line && !line.startsWith("#"));
|
|
334
|
-
return this.#gitignorePatterns;
|
|
335
|
-
}
|
|
336
|
-
async #applyTemplateFile({
|
|
337
|
-
templatePath,
|
|
338
|
-
targetPath,
|
|
339
|
-
scanInfo,
|
|
340
|
-
overwrite = true
|
|
341
|
-
}, dict = {}, options = {}) {
|
|
342
|
-
if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
|
|
343
|
-
const getContent = await import(templatePath);
|
|
344
|
-
const result = await getContent.default(scanInfo ?? null, dict, options);
|
|
345
|
-
if (result === null)
|
|
346
|
-
return null;
|
|
347
|
-
const filename = typeof result === "object" ? result.filename : import_path.default.basename(targetPath).replace(".js", ".ts");
|
|
348
|
-
const content = typeof result === "object" ? result.content : result;
|
|
349
|
-
const dirname = import_path.default.dirname(targetPath);
|
|
350
|
-
const convertedTargetPath = Object.entries(dict).reduce(
|
|
351
|
-
(path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value),
|
|
352
|
-
`${dirname}/${filename}`
|
|
353
|
-
);
|
|
354
|
-
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
355
|
-
return this.writeFile(convertedTargetPath, content, { overwrite });
|
|
356
|
-
} else if (targetPath.endsWith(".template")) {
|
|
357
|
-
const content = await import_promises.default.readFile(templatePath, "utf8");
|
|
358
|
-
const convertedTargetPath = Object.entries(dict).reduce(
|
|
359
|
-
(path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value),
|
|
360
|
-
targetPath.slice(0, -9)
|
|
361
|
-
);
|
|
362
|
-
const convertedContent = Object.entries(dict).reduce(
|
|
363
|
-
(data, [key, value]) => data.replace(new RegExp(`<%= ${key} %>`, "g"), value),
|
|
364
|
-
content
|
|
365
|
-
);
|
|
366
|
-
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
367
|
-
return this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
368
|
-
} else
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
async _applyTemplate({
|
|
372
|
-
basePath,
|
|
373
|
-
template,
|
|
374
|
-
scanInfo,
|
|
375
|
-
dict = {},
|
|
376
|
-
options = {},
|
|
377
|
-
overwrite = true
|
|
378
|
-
}) {
|
|
379
|
-
const templatePath = `${(0, import_getDirname.getDirname)(import_meta.url)}/src/templates${template ? `/${template}` : ""}`;
|
|
380
|
-
const prefixTemplatePath = templatePath.endsWith(".tsx") ? templatePath : templatePath.replace(".ts", ".js");
|
|
381
|
-
if (import_fs.default.statSync(prefixTemplatePath).isFile()) {
|
|
382
|
-
const filename = import_path.default.basename(prefixTemplatePath);
|
|
383
|
-
const fileContent = await this.#applyTemplateFile(
|
|
384
|
-
{ templatePath: prefixTemplatePath, targetPath: import_path.default.join(basePath, filename), scanInfo, overwrite },
|
|
385
|
-
dict,
|
|
386
|
-
options
|
|
387
|
-
);
|
|
388
|
-
return fileContent ? [fileContent] : [];
|
|
389
|
-
} else {
|
|
390
|
-
const subdirs = await this.readdir(templatePath);
|
|
391
|
-
const fileContents = (await Promise.all(
|
|
392
|
-
subdirs.map(async (subdir) => {
|
|
393
|
-
const subpath = import_path.default.join(templatePath, subdir);
|
|
394
|
-
if (import_fs.default.statSync(subpath).isFile()) {
|
|
395
|
-
const fileContent = await this.#applyTemplateFile(
|
|
396
|
-
{ templatePath: subpath, targetPath: import_path.default.join(basePath, subdir), scanInfo, overwrite },
|
|
397
|
-
dict,
|
|
398
|
-
options
|
|
399
|
-
);
|
|
400
|
-
return fileContent ? [fileContent] : [];
|
|
401
|
-
} else
|
|
402
|
-
return await this._applyTemplate({
|
|
403
|
-
basePath: import_path.default.join(basePath, subdir),
|
|
404
|
-
template: import_path.default.join(template, subdir),
|
|
405
|
-
scanInfo,
|
|
406
|
-
dict,
|
|
407
|
-
overwrite,
|
|
408
|
-
options
|
|
409
|
-
});
|
|
410
|
-
})
|
|
411
|
-
)).flat();
|
|
412
|
-
return fileContents;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
async applyTemplate(options) {
|
|
416
|
-
const dict = {
|
|
417
|
-
...options.dict ?? {},
|
|
418
|
-
...Object.fromEntries(
|
|
419
|
-
Object.entries(options.dict ?? {}).map(([key, value]) => [(0, import_common.capitalize)(key), (0, import_common.capitalize)(value)])
|
|
420
|
-
)
|
|
421
|
-
};
|
|
422
|
-
return this._applyTemplate({ ...options, dict });
|
|
423
|
-
}
|
|
424
|
-
getTypeChecker() {
|
|
425
|
-
this.typeChecker ??= new import_typeChecker.TypeChecker(this);
|
|
426
|
-
return this.typeChecker;
|
|
427
|
-
}
|
|
428
|
-
typeCheck(filePath) {
|
|
429
|
-
const path2 = this.getPath(filePath);
|
|
430
|
-
const typeChecker = this.getTypeChecker();
|
|
431
|
-
const { fileDiagnostics, fileErrors, fileWarnings } = typeChecker.check(path2);
|
|
432
|
-
const message = typeChecker.formatDiagnostics(fileDiagnostics);
|
|
433
|
-
return { fileDiagnostics, fileErrors, fileWarnings, message };
|
|
434
|
-
}
|
|
435
|
-
getLinter() {
|
|
436
|
-
this.linter ??= new import_linter.Linter(this.cwdPath);
|
|
437
|
-
return this.linter;
|
|
438
|
-
}
|
|
439
|
-
async lint(filePath, { fix = false, dryRun = false } = {}) {
|
|
440
|
-
const path2 = this.getPath(filePath);
|
|
441
|
-
const linter = this.getLinter();
|
|
442
|
-
const { results, errors, warnings } = await linter.lint(path2, { fix, dryRun });
|
|
443
|
-
const message = linter.formatLintResults(results);
|
|
444
|
-
return { results, message, errors, warnings };
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
class WorkspaceExecutor extends Executor {
|
|
448
|
-
workspaceRoot;
|
|
449
|
-
repoName;
|
|
450
|
-
emoji = execEmoji.workspace;
|
|
451
|
-
constructor({ workspaceRoot, repoName }) {
|
|
452
|
-
super("workspace", workspaceRoot);
|
|
453
|
-
this.workspaceRoot = workspaceRoot;
|
|
454
|
-
this.repoName = repoName;
|
|
455
|
-
}
|
|
456
|
-
static #execs = /* @__PURE__ */ new Map();
|
|
457
|
-
static fromRoot({
|
|
458
|
-
workspaceRoot = process.cwd(),
|
|
459
|
-
repoName = import_path.default.basename(process.cwd())
|
|
460
|
-
} = {}) {
|
|
461
|
-
return this.#execs.get(repoName) ?? new WorkspaceExecutor({ workspaceRoot, repoName });
|
|
462
|
-
}
|
|
463
|
-
getBaseDevEnv() {
|
|
464
|
-
const envFile = import_dotenv.default.parse(this.readFile(".env"));
|
|
465
|
-
const appName = process.env.NEXT_PUBLIC_APP_NAME ?? envFile.NEXT_PUBLIC_APP_NAME;
|
|
466
|
-
const repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? envFile.NEXT_PUBLIC_REPO_NAME;
|
|
467
|
-
if (!repoName)
|
|
468
|
-
throw new Error("NEXT_PUBLIC_REPO_NAME is not set");
|
|
469
|
-
const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? envFile.NEXT_PUBLIC_SERVE_DOMAIN;
|
|
470
|
-
if (!serveDomain)
|
|
471
|
-
throw new Error("NEXT_PUBLIC_SERVE_DOMAIN is not set");
|
|
472
|
-
const portOffset = parseInt(process.env.PORT_OFFSET ?? envFile.PORT_OFFSET ?? "0");
|
|
473
|
-
const env = process.env.NEXT_PUBLIC_ENV ?? envFile.NEXT_PUBLIC_ENV ?? "debug";
|
|
474
|
-
if (!env)
|
|
475
|
-
throw new Error("NEXT_PUBLIC_ENV is not set");
|
|
476
|
-
return { ...appName ? { name: appName } : {}, repoName, serveDomain, env, portOffset };
|
|
477
|
-
}
|
|
478
|
-
async scan() {
|
|
479
|
-
return await import_scanInfo.WorkspaceInfo.fromExecutor(this);
|
|
480
|
-
}
|
|
481
|
-
async getApps() {
|
|
482
|
-
if (!import_fs.default.existsSync(`${this.workspaceRoot}/apps`))
|
|
483
|
-
return [];
|
|
484
|
-
return await this.#getDirHasFile(`${this.workspaceRoot}/apps`, "akan.config.ts");
|
|
485
|
-
}
|
|
486
|
-
async getLibs() {
|
|
487
|
-
if (!import_fs.default.existsSync(`${this.workspaceRoot}/libs`))
|
|
488
|
-
return [];
|
|
489
|
-
return await this.#getDirHasFile(`${this.workspaceRoot}/libs`, "akan.config.ts");
|
|
490
|
-
}
|
|
491
|
-
async getSyss() {
|
|
492
|
-
const [appNames, libNames] = await Promise.all([this.getApps(), this.getLibs()]);
|
|
493
|
-
return [appNames, libNames];
|
|
494
|
-
}
|
|
495
|
-
async getPkgs() {
|
|
496
|
-
if (!import_fs.default.existsSync(`${this.workspaceRoot}/pkgs`))
|
|
497
|
-
return [];
|
|
498
|
-
return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
|
|
499
|
-
}
|
|
500
|
-
async getExecs() {
|
|
501
|
-
const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
|
|
502
|
-
return [appNames, libNames, pkgNames];
|
|
503
|
-
}
|
|
504
|
-
setTsPaths(type, name) {
|
|
505
|
-
const rootTsConfig = this.readJson("tsconfig.json");
|
|
506
|
-
rootTsConfig.compilerOptions.paths ??= {};
|
|
507
|
-
if (type === "lib" || type === "pkg")
|
|
508
|
-
rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
|
|
509
|
-
rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
|
|
510
|
-
if (rootTsConfig.references) {
|
|
511
|
-
if (!rootTsConfig.references.some((ref) => ref.path === `./${type}s/${name}/tsconfig.json`))
|
|
512
|
-
rootTsConfig.references.push({ path: `./${type}s/${name}/tsconfig.json` });
|
|
513
|
-
}
|
|
514
|
-
this.writeJson("tsconfig.json", rootTsConfig);
|
|
515
|
-
return this;
|
|
516
|
-
}
|
|
517
|
-
unsetTsPaths(type, name) {
|
|
518
|
-
const rootTsConfig = this.readJson("tsconfig.json");
|
|
519
|
-
const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths ?? {}).filter(
|
|
520
|
-
(key) => !key.startsWith(`@${name}`)
|
|
521
|
-
);
|
|
522
|
-
rootTsConfig.compilerOptions.paths = Object.fromEntries(
|
|
523
|
-
filteredKeys.map((key) => [key, rootTsConfig.compilerOptions.paths?.[key] ?? []])
|
|
524
|
-
);
|
|
525
|
-
if (rootTsConfig.references) {
|
|
526
|
-
rootTsConfig.references = rootTsConfig.references.filter(
|
|
527
|
-
(ref) => !ref.path.startsWith(`./${type}s/${name}`)
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
this.writeJson("tsconfig.json", rootTsConfig);
|
|
531
|
-
return this;
|
|
532
|
-
}
|
|
533
|
-
async getDirInModule(basePath, name) {
|
|
534
|
-
const AVOID_DIRS = ["__lib", "__scalar", `_`, `_${name}`];
|
|
535
|
-
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
536
|
-
const dirs = await this.readdir(dirname);
|
|
537
|
-
await Promise.all(
|
|
538
|
-
dirs.map(async (dir) => {
|
|
539
|
-
if (dir.includes("_") || AVOID_DIRS.includes(dir))
|
|
540
|
-
return;
|
|
541
|
-
const dirPath = import_path.default.join(dirname, dir);
|
|
542
|
-
if (import_fs.default.lstatSync(dirPath).isDirectory()) {
|
|
543
|
-
results.push(`${prefix}${dir}`);
|
|
544
|
-
if (maxDepth > 0)
|
|
545
|
-
await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
546
|
-
}
|
|
547
|
-
})
|
|
548
|
-
);
|
|
549
|
-
return results;
|
|
550
|
-
};
|
|
551
|
-
return await getDirs(basePath);
|
|
552
|
-
}
|
|
553
|
-
async commit(message, { init = false, add = true } = {}) {
|
|
554
|
-
if (init)
|
|
555
|
-
await this.exec(`git init --quiet`);
|
|
556
|
-
if (add)
|
|
557
|
-
await this.exec(`git add .`);
|
|
558
|
-
await this.exec(`git commit --quiet -m "${message}"`);
|
|
559
|
-
}
|
|
560
|
-
async #getDirHasFile(basePath, targetFilename) {
|
|
561
|
-
const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
|
|
562
|
-
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
563
|
-
const dirs = await this.readdir(dirname);
|
|
564
|
-
await Promise.all(
|
|
565
|
-
dirs.map(async (dir) => {
|
|
566
|
-
if (AVOID_DIRS.includes(dir))
|
|
567
|
-
return;
|
|
568
|
-
const dirPath = import_path.default.join(dirname, dir);
|
|
569
|
-
if (import_fs.default.lstatSync(dirPath).isDirectory()) {
|
|
570
|
-
const hasTargetFile = import_fs.default.existsSync(import_path.default.join(dirPath, targetFilename));
|
|
571
|
-
if (hasTargetFile)
|
|
572
|
-
results.push(`${prefix}${dir}`);
|
|
573
|
-
if (maxDepth > 0)
|
|
574
|
-
await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
575
|
-
}
|
|
576
|
-
})
|
|
577
|
-
);
|
|
578
|
-
return results;
|
|
579
|
-
};
|
|
580
|
-
return await getDirs(basePath);
|
|
581
|
-
}
|
|
582
|
-
async getScalarConstantFiles() {
|
|
583
|
-
const [appNames, libNames] = await this.getSyss();
|
|
584
|
-
const scalarConstantExampleFiles = [
|
|
585
|
-
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getScalarConstantFiles()))).flat(),
|
|
586
|
-
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getScalarConstantFiles()))).flat()
|
|
587
|
-
];
|
|
588
|
-
return scalarConstantExampleFiles;
|
|
589
|
-
}
|
|
590
|
-
async getConstantFiles() {
|
|
591
|
-
const [appNames, libNames] = await this.getSyss();
|
|
592
|
-
const moduleConstantExampleFiles = [
|
|
593
|
-
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getConstantFiles()))).flat(),
|
|
594
|
-
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getConstantFiles()))).flat()
|
|
595
|
-
];
|
|
596
|
-
return moduleConstantExampleFiles;
|
|
597
|
-
}
|
|
598
|
-
async getDictionaryFiles() {
|
|
599
|
-
const [appNames, libNames] = await this.getSyss();
|
|
600
|
-
const moduleDictionaryExampleFiles = [
|
|
601
|
-
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getDictionaryFiles()))).flat(),
|
|
602
|
-
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getDictionaryFiles()))).flat()
|
|
603
|
-
];
|
|
604
|
-
return moduleDictionaryExampleFiles;
|
|
605
|
-
}
|
|
606
|
-
async getViewFiles() {
|
|
607
|
-
const [appNames, libNames] = await this.getSyss();
|
|
608
|
-
const viewExampleFiles = [
|
|
609
|
-
...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getViewsSourceCode()))).flat(),
|
|
610
|
-
...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getViewsSourceCode()))).flat()
|
|
611
|
-
];
|
|
612
|
-
return viewExampleFiles;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
class SysExecutor extends Executor {
|
|
616
|
-
workspace;
|
|
617
|
-
name;
|
|
618
|
-
type;
|
|
619
|
-
emoji;
|
|
620
|
-
constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
|
|
621
|
-
super(name, `${workspace.workspaceRoot}/${type}s/${name}`);
|
|
622
|
-
this.workspace = workspace;
|
|
623
|
-
this.name = name;
|
|
624
|
-
this.type = type;
|
|
625
|
-
this.emoji = execEmoji[type];
|
|
626
|
-
}
|
|
627
|
-
#akanConfig = null;
|
|
628
|
-
async getConfig({ refresh } = {}) {
|
|
629
|
-
if (this.#akanConfig && !refresh)
|
|
630
|
-
return this.#akanConfig;
|
|
631
|
-
const tsconfig = this.getTsConfig();
|
|
632
|
-
this.#akanConfig = this.type === "app" ? await (0, import_config.getAppConfig)(
|
|
633
|
-
this.cwdPath,
|
|
634
|
-
{ ...this.workspace.getBaseDevEnv(), type: "app", name: this.name },
|
|
635
|
-
tsconfig
|
|
636
|
-
) : await (0, import_config.getLibConfig)(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "lib", name: this.name });
|
|
637
|
-
return this.#akanConfig;
|
|
638
|
-
}
|
|
639
|
-
async getModules() {
|
|
640
|
-
const path2 = this.type === "app" ? `apps/${this.name}/lib` : `libs/${this.name}/lib`;
|
|
641
|
-
return await this.workspace.getDirInModule(path2, this.name);
|
|
642
|
-
}
|
|
643
|
-
#scanInfo = null;
|
|
644
|
-
async scan({
|
|
645
|
-
refresh,
|
|
646
|
-
write = true,
|
|
647
|
-
writeLib = true
|
|
648
|
-
} = {}) {
|
|
649
|
-
if (this.#scanInfo && !refresh)
|
|
650
|
-
return this.#scanInfo;
|
|
651
|
-
const scanInfo = this.type === "app" ? await import_scanInfo.AppInfo.fromExecutor(this, { refresh }) : await import_scanInfo.LibInfo.fromExecutor(this, { refresh });
|
|
652
|
-
if (write) {
|
|
653
|
-
await Promise.all([
|
|
654
|
-
this._applyTemplate({ basePath: "env", template: "env", scanInfo }),
|
|
655
|
-
this._applyTemplate({ basePath: "lib", template: "lib", scanInfo }),
|
|
656
|
-
this._applyTemplate({ basePath: ".", template: "server.ts", scanInfo }),
|
|
657
|
-
this._applyTemplate({ basePath: ".", template: "client.ts", scanInfo }),
|
|
658
|
-
this.type === "lib" ? this._applyTemplate({ basePath: ".", template: "index.ts", scanInfo }) : null,
|
|
659
|
-
...scanInfo.getDatabaseModules().map(
|
|
660
|
-
(model) => this._applyTemplate({
|
|
661
|
-
basePath: `lib/${model}`,
|
|
662
|
-
template: "moduleRoot",
|
|
663
|
-
scanInfo,
|
|
664
|
-
dict: { model, Model: (0, import_common.capitalize)(model) }
|
|
665
|
-
})
|
|
666
|
-
),
|
|
667
|
-
...scanInfo.getServiceModules().map(
|
|
668
|
-
(model) => this._applyTemplate({
|
|
669
|
-
basePath: `lib/_${model}`,
|
|
670
|
-
template: "moduleRoot",
|
|
671
|
-
scanInfo,
|
|
672
|
-
dict: { model, Model: (0, import_common.capitalize)(model) }
|
|
673
|
-
})
|
|
674
|
-
)
|
|
675
|
-
]);
|
|
676
|
-
this.writeJson(`akan.${this.type}.json`, scanInfo.getScanResult());
|
|
677
|
-
if (this.type === "lib")
|
|
678
|
-
this.#updateDependencies(scanInfo);
|
|
679
|
-
if (writeLib) {
|
|
680
|
-
const libInfos = [...scanInfo.getLibInfos().values()];
|
|
681
|
-
await Promise.all(
|
|
682
|
-
libInfos.map((libInfo) => [
|
|
683
|
-
libInfo.exec._applyTemplate({ basePath: "env", template: "env", scanInfo: libInfo }),
|
|
684
|
-
libInfo.exec._applyTemplate({ basePath: "lib", template: "lib", scanInfo: libInfo }),
|
|
685
|
-
libInfo.exec._applyTemplate({ basePath: ".", template: "server.ts", scanInfo: libInfo }),
|
|
686
|
-
libInfo.exec._applyTemplate({ basePath: ".", template: "client.ts", scanInfo: libInfo }),
|
|
687
|
-
libInfo.exec._applyTemplate({ basePath: ".", template: "index.ts", scanInfo: libInfo }),
|
|
688
|
-
...libInfo.getDatabaseModules().map(
|
|
689
|
-
(model) => libInfo.exec._applyTemplate({
|
|
690
|
-
basePath: `lib/${model}`,
|
|
691
|
-
template: "moduleRoot",
|
|
692
|
-
scanInfo: libInfo,
|
|
693
|
-
dict: { model, Model: (0, import_common.capitalize)(model) }
|
|
694
|
-
})
|
|
695
|
-
),
|
|
696
|
-
...libInfo.getServiceModules().map(
|
|
697
|
-
(model) => libInfo.exec._applyTemplate({
|
|
698
|
-
basePath: `lib/_${model}`,
|
|
699
|
-
template: "moduleRoot",
|
|
700
|
-
scanInfo: libInfo,
|
|
701
|
-
dict: { model, Model: (0, import_common.capitalize)(model) }
|
|
702
|
-
})
|
|
703
|
-
)
|
|
704
|
-
]).flat()
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
this.#scanInfo = scanInfo;
|
|
709
|
-
return scanInfo;
|
|
710
|
-
}
|
|
711
|
-
#updateDependencies(scanInfo) {
|
|
712
|
-
const rootPackageJson = this.workspace.getPackageJson();
|
|
713
|
-
const libPackageJson = this.getPackageJson();
|
|
714
|
-
const dependencies = scanInfo.getScanResult().dependencies;
|
|
715
|
-
const libPkgJsonWithDeps = {
|
|
716
|
-
...libPackageJson,
|
|
717
|
-
dependencies: {
|
|
718
|
-
...libPackageJson.dependencies,
|
|
719
|
-
...Object.fromEntries(
|
|
720
|
-
dependencies.filter((dep) => rootPackageJson.dependencies?.[dep]).sort().map((dep) => [dep, rootPackageJson.dependencies?.[dep]])
|
|
721
|
-
)
|
|
722
|
-
},
|
|
723
|
-
devDependencies: {
|
|
724
|
-
...libPackageJson.devDependencies,
|
|
725
|
-
...Object.fromEntries(
|
|
726
|
-
dependencies.filter((dep) => rootPackageJson.devDependencies?.[dep]).sort().map((dep) => [dep, rootPackageJson.devDependencies?.[dep]])
|
|
727
|
-
)
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
this.setPackageJson(libPkgJsonWithDeps);
|
|
731
|
-
}
|
|
732
|
-
getLocalFile(targetPath) {
|
|
733
|
-
const filePath = import_path.default.isAbsolute(targetPath) ? targetPath : `${this.type}s/${this.name}/${targetPath}`;
|
|
734
|
-
const content = this.workspace.readFile(filePath);
|
|
735
|
-
return { filePath, content };
|
|
736
|
-
}
|
|
737
|
-
async getDatabaseModules() {
|
|
738
|
-
const databaseModules = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
|
|
739
|
-
return databaseModules;
|
|
740
|
-
}
|
|
741
|
-
async getServiceModules() {
|
|
742
|
-
const serviceModules = (await this.readdir("lib")).filter((name) => name.startsWith("_") && !name.startsWith("__")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.service.ts`));
|
|
743
|
-
return serviceModules;
|
|
744
|
-
}
|
|
745
|
-
async getScalarModules() {
|
|
746
|
-
const scalarModules = (await this.readdir("lib/__scalar")).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
|
|
747
|
-
return scalarModules;
|
|
748
|
-
}
|
|
749
|
-
async getViewComponents() {
|
|
750
|
-
const viewComponents = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.View.tsx`));
|
|
751
|
-
return viewComponents;
|
|
752
|
-
}
|
|
753
|
-
async getUnitComponents() {
|
|
754
|
-
const unitComponents = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.Unit.tsx`));
|
|
755
|
-
return unitComponents;
|
|
756
|
-
}
|
|
757
|
-
async getTemplateComponents() {
|
|
758
|
-
const templateComponents = (await this.readdir("lib")).filter((name) => !name.startsWith("_") && !name.startsWith("__") && !name.endsWith(".ts")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.Template.tsx`));
|
|
759
|
-
return templateComponents;
|
|
760
|
-
}
|
|
761
|
-
async getViewsSourceCode() {
|
|
762
|
-
const viewComponents = await this.getViewComponents();
|
|
763
|
-
return viewComponents.map((viewComponent) => this.getLocalFile(`lib/${viewComponent}/${viewComponent}.View.tsx`));
|
|
764
|
-
}
|
|
765
|
-
async getUnitsSourceCode() {
|
|
766
|
-
const unitComponents = await this.getUnitComponents();
|
|
767
|
-
return unitComponents.map((unitComponent) => this.getLocalFile(`lib/${unitComponent}/${unitComponent}.Unit.tsx`));
|
|
768
|
-
}
|
|
769
|
-
async getTemplatesSourceCode() {
|
|
770
|
-
const templateComponents = await this.getTemplateComponents();
|
|
771
|
-
return templateComponents.map(
|
|
772
|
-
(templateComponent) => this.getLocalFile(`lib/${templateComponent}/${templateComponent}.Template.tsx`)
|
|
773
|
-
);
|
|
774
|
-
}
|
|
775
|
-
async getScalarConstantFiles() {
|
|
776
|
-
const scalarModules = await this.getScalarModules();
|
|
777
|
-
return scalarModules.map(
|
|
778
|
-
(scalarModule) => this.getLocalFile(`lib/__scalar/${scalarModule}/${scalarModule}.constant.ts`)
|
|
779
|
-
);
|
|
780
|
-
}
|
|
781
|
-
async getScalarDictionaryFiles() {
|
|
782
|
-
const scalarModules = await this.getScalarModules();
|
|
783
|
-
return scalarModules.map((scalarModule) => this.getLocalFile(`lib/${scalarModule}/${scalarModule}.dictionary.ts`));
|
|
784
|
-
}
|
|
785
|
-
async getConstantFiles() {
|
|
786
|
-
const modules = await this.getModules();
|
|
787
|
-
return modules.map((module2) => this.getLocalFile(`lib/${module2}/${module2}.constant.ts`));
|
|
788
|
-
}
|
|
789
|
-
async getConstantFilesWithLibs() {
|
|
790
|
-
const scanInfo = this.type === "app" ? await import_scanInfo.AppInfo.fromExecutor(this) : await import_scanInfo.LibInfo.fromExecutor(this);
|
|
791
|
-
const sysContantFiles = await this.getConstantFiles();
|
|
792
|
-
const sysScalarConstantFiles = await this.getScalarConstantFiles();
|
|
793
|
-
const libDeps = scanInfo.getLibs();
|
|
794
|
-
const libConstantFiles = await Promise.all(
|
|
795
|
-
libDeps.map(async (lib) => [
|
|
796
|
-
...await LibExecutor.from(this, lib).getConstantFiles(),
|
|
797
|
-
...await LibExecutor.from(this, lib).getScalarConstantFiles()
|
|
798
|
-
])
|
|
799
|
-
);
|
|
800
|
-
return [...sysContantFiles, ...sysScalarConstantFiles, ...libConstantFiles.flat()];
|
|
801
|
-
}
|
|
802
|
-
async getDictionaryFiles() {
|
|
803
|
-
const modules = await this.getModules();
|
|
804
|
-
return modules.map((module2) => this.getLocalFile(`lib/${module2}/${module2}.dictionary.ts`));
|
|
805
|
-
}
|
|
806
|
-
async applyTemplate(options) {
|
|
807
|
-
const dict = {
|
|
808
|
-
...options.dict ?? {},
|
|
809
|
-
...Object.fromEntries(
|
|
810
|
-
Object.entries(options.dict ?? {}).map(([key, value]) => [(0, import_common.capitalize)(key), (0, import_common.capitalize)(value)])
|
|
811
|
-
)
|
|
812
|
-
};
|
|
813
|
-
const akanConfig = await this.getConfig();
|
|
814
|
-
const scanInfo = await this.scan();
|
|
815
|
-
const fileContents = await this._applyTemplate({ ...options, scanInfo, dict });
|
|
816
|
-
await this.scan();
|
|
817
|
-
return fileContents;
|
|
818
|
-
}
|
|
819
|
-
setTsPaths() {
|
|
820
|
-
this.workspace.setTsPaths(this.type, this.name);
|
|
821
|
-
return this;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
class AppExecutor extends SysExecutor {
|
|
825
|
-
dist;
|
|
826
|
-
emoji = execEmoji.app;
|
|
827
|
-
constructor({ workspace, name }) {
|
|
828
|
-
super({ workspace, name, type: "app" });
|
|
829
|
-
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/apps/${name}`);
|
|
830
|
-
}
|
|
831
|
-
static #execs = /* @__PURE__ */ new Map();
|
|
832
|
-
static from(executor, name) {
|
|
833
|
-
const exec2 = this.#execs.get(name);
|
|
834
|
-
if (exec2)
|
|
835
|
-
return exec2;
|
|
836
|
-
else if (executor instanceof WorkspaceExecutor)
|
|
837
|
-
return new AppExecutor({ workspace: executor, name });
|
|
838
|
-
else
|
|
839
|
-
return new AppExecutor({ workspace: executor.workspace, name });
|
|
840
|
-
}
|
|
841
|
-
getEnv() {
|
|
842
|
-
return this.workspace.getBaseDevEnv().env;
|
|
843
|
-
}
|
|
844
|
-
#akanConfig = null;
|
|
845
|
-
async getConfig({ refresh } = {}) {
|
|
846
|
-
if (this.#akanConfig && !refresh)
|
|
847
|
-
return this.#akanConfig;
|
|
848
|
-
this.#akanConfig = await (0, import_config.getAppConfig)(
|
|
849
|
-
this.cwdPath,
|
|
850
|
-
{ ...this.workspace.getBaseDevEnv(), type: "app", name: this.name },
|
|
851
|
-
this.getTsConfig()
|
|
852
|
-
);
|
|
853
|
-
return this.#akanConfig;
|
|
854
|
-
}
|
|
855
|
-
async syncAssets(libDeps) {
|
|
856
|
-
const projectPublicPath = `${this.cwdPath}/public`;
|
|
857
|
-
const projectAssetsPath = `${this.cwdPath}/assets`;
|
|
858
|
-
const projectPublicLibPath = `${projectPublicPath}/libs`;
|
|
859
|
-
const projectAssetsLibPath = `${projectAssetsPath}/libs`;
|
|
860
|
-
await Promise.all([this.removeDir(projectPublicLibPath), this.removeDir(projectAssetsLibPath)]);
|
|
861
|
-
const targetPublicDeps = libDeps.filter((dep) => this.exists(`${this.workspace.workspaceRoot}/libs/${dep}/public`));
|
|
862
|
-
const targetAssetsDeps = libDeps.filter((dep) => this.exists(`${this.workspace.workspaceRoot}/libs/${dep}/assets`));
|
|
863
|
-
targetPublicDeps.forEach((dep) => this.mkdir(`${projectPublicLibPath}/${dep}`));
|
|
864
|
-
targetAssetsDeps.forEach((dep) => this.mkdir(`${projectAssetsLibPath}/${dep}`));
|
|
865
|
-
await Promise.all([
|
|
866
|
-
...targetPublicDeps.map(
|
|
867
|
-
(dep) => this.cp(`${this.workspace.workspaceRoot}/libs/${dep}/public`, `${projectPublicLibPath}/${dep}`)
|
|
868
|
-
),
|
|
869
|
-
...targetAssetsDeps.map(
|
|
870
|
-
(dep) => this.cp(`${this.workspace.workspaceRoot}/libs/${dep}/assets`, `${projectAssetsLibPath}/${dep}`)
|
|
871
|
-
)
|
|
872
|
-
]);
|
|
873
|
-
}
|
|
874
|
-
async increaseBuildNum() {
|
|
875
|
-
await (0, import_config.increaseBuildNum)(
|
|
876
|
-
this.cwdPath,
|
|
877
|
-
{ ...this.workspace.getBaseDevEnv(), type: "app", name: this.name },
|
|
878
|
-
this.getTsConfig()
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
async decreaseBuildNum() {
|
|
882
|
-
await (0, import_config.decreaseBuildNum)(
|
|
883
|
-
this.cwdPath,
|
|
884
|
-
{ ...this.workspace.getBaseDevEnv(), type: "app", name: this.name },
|
|
885
|
-
this.getTsConfig()
|
|
886
|
-
);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
class LibExecutor extends SysExecutor {
|
|
890
|
-
dist;
|
|
891
|
-
emoji = execEmoji.lib;
|
|
892
|
-
constructor({ workspace, name }) {
|
|
893
|
-
super({ workspace, name, type: "lib" });
|
|
894
|
-
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/libs/${name}`);
|
|
895
|
-
}
|
|
896
|
-
static #execs = /* @__PURE__ */ new Map();
|
|
897
|
-
static from(executor, name) {
|
|
898
|
-
const exec2 = this.#execs.get(name);
|
|
899
|
-
if (exec2)
|
|
900
|
-
return exec2;
|
|
901
|
-
else if (executor instanceof WorkspaceExecutor)
|
|
902
|
-
return new LibExecutor({ workspace: executor, name });
|
|
903
|
-
else
|
|
904
|
-
return new LibExecutor({ workspace: executor.workspace, name });
|
|
905
|
-
}
|
|
906
|
-
#akanConfig = null;
|
|
907
|
-
async getConfig({ refresh } = {}) {
|
|
908
|
-
if (this.#akanConfig && !refresh)
|
|
909
|
-
return this.#akanConfig;
|
|
910
|
-
this.#akanConfig = await (0, import_config.getLibConfig)(this.cwdPath, {
|
|
911
|
-
...this.workspace.getBaseDevEnv(),
|
|
912
|
-
type: "lib",
|
|
913
|
-
name: this.name
|
|
914
|
-
});
|
|
915
|
-
return this.#akanConfig;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
class PkgExecutor extends Executor {
|
|
919
|
-
workspace;
|
|
920
|
-
name;
|
|
921
|
-
dist;
|
|
922
|
-
emoji = execEmoji.pkg;
|
|
923
|
-
constructor({ workspace = WorkspaceExecutor.fromRoot(), name }) {
|
|
924
|
-
super(name, `${workspace.workspaceRoot}/pkgs/${name}`);
|
|
925
|
-
this.workspace = workspace;
|
|
926
|
-
this.name = name;
|
|
927
|
-
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/pkgs/${name}`);
|
|
928
|
-
}
|
|
929
|
-
static from(executor, name) {
|
|
930
|
-
if (executor instanceof WorkspaceExecutor)
|
|
931
|
-
return new PkgExecutor({ workspace: executor, name });
|
|
932
|
-
return new PkgExecutor({ workspace: executor.workspace, name });
|
|
933
|
-
}
|
|
934
|
-
#scanInfo = null;
|
|
935
|
-
async scan({ refresh } = {}) {
|
|
936
|
-
if (this.#scanInfo && !refresh)
|
|
937
|
-
return this.#scanInfo;
|
|
938
|
-
const scanInfo = await import_scanInfo.PkgInfo.fromExecutor(this, { refresh });
|
|
939
|
-
this.#scanInfo = scanInfo;
|
|
940
|
-
return scanInfo;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
class ModuleExecutor extends Executor {
|
|
944
|
-
sys;
|
|
945
|
-
emoji = execEmoji.module;
|
|
946
|
-
constructor({ sys, name }) {
|
|
947
|
-
super(name, `${sys.workspace.workspaceRoot}/${sys.type}s/${sys.name}/lib/${name}`);
|
|
948
|
-
this.sys = sys;
|
|
949
|
-
}
|
|
950
|
-
static from(sysExecutor, name) {
|
|
951
|
-
return new ModuleExecutor({ sys: sysExecutor, name });
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
955
|
-
0 && (module.exports = {
|
|
956
|
-
AppExecutor,
|
|
957
|
-
Executor,
|
|
958
|
-
LibExecutor,
|
|
959
|
-
ModuleExecutor,
|
|
960
|
-
PkgExecutor,
|
|
961
|
-
SysExecutor,
|
|
962
|
-
WorkspaceExecutor,
|
|
963
|
-
execEmoji
|
|
964
|
-
});
|