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