@akanjs/devkit 0.0.39 → 0.0.40

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.
@@ -0,0 +1,715 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var executors_exports = {};
30
+ __export(executors_exports, {
31
+ AppExecutor: () => AppExecutor,
32
+ DistAppExecutor: () => DistAppExecutor,
33
+ DistLibExecutor: () => DistLibExecutor,
34
+ DistPkgExecutor: () => DistPkgExecutor,
35
+ Executor: () => Executor,
36
+ LibExecutor: () => LibExecutor,
37
+ PkgExecutor: () => PkgExecutor,
38
+ SysExecutor: () => SysExecutor,
39
+ WorkspaceExecutor: () => WorkspaceExecutor
40
+ });
41
+ module.exports = __toCommonJS(executors_exports);
42
+ var import_common = require("@akanjs/common");
43
+ var import_config = require("@akanjs/config");
44
+ var import_child_process = require("child_process");
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_baseDevEnv = require("./baseDevEnv");
49
+ var import_dependencyScanner = require("./dependencyScanner");
50
+ class Executor {
51
+ static {
52
+ __name(this, "Executor");
53
+ }
54
+ logger;
55
+ cwdPath;
56
+ constructor(name, cwdPath) {
57
+ this.logger = new import_common.Logger(name);
58
+ this.cwdPath = cwdPath;
59
+ if (!import_fs.default.existsSync(cwdPath)) import_fs.default.mkdirSync(cwdPath, {
60
+ recursive: true
61
+ });
62
+ }
63
+ exec(command, options = {}) {
64
+ const proc = (0, import_child_process.exec)(command, {
65
+ cwd: this.cwdPath,
66
+ ...options
67
+ });
68
+ proc.stdout?.on("data", (data) => {
69
+ import_common.Logger.raw(data.toString());
70
+ });
71
+ proc.stderr?.on("data", (data) => {
72
+ import_common.Logger.raw(data.toString());
73
+ });
74
+ return new Promise((resolve, reject) => {
75
+ proc.on("exit", (code, signal) => {
76
+ if (!!code || signal) reject({
77
+ code,
78
+ signal
79
+ });
80
+ else resolve({
81
+ code,
82
+ signal
83
+ });
84
+ });
85
+ });
86
+ }
87
+ spawn(command, args = [], options = {}) {
88
+ const proc = (0, import_child_process.spawn)(command, args, {
89
+ cwd: this.cwdPath,
90
+ stdio: "inherit",
91
+ ...options
92
+ });
93
+ proc.stderr?.on("data", (data) => {
94
+ import_common.Logger.raw(data.toString());
95
+ });
96
+ return new Promise((resolve, reject) => {
97
+ proc.on("exit", (code, signal) => {
98
+ if (!!code || signal) reject({
99
+ code,
100
+ signal
101
+ });
102
+ else resolve({
103
+ code,
104
+ signal
105
+ });
106
+ });
107
+ });
108
+ }
109
+ fork(modulePath, args = [], options = {}) {
110
+ const proc = (0, import_child_process.fork)(modulePath, args, {
111
+ cwd: this.cwdPath,
112
+ stdio: [
113
+ "ignore",
114
+ "inherit",
115
+ "inherit",
116
+ "ipc"
117
+ ],
118
+ ...options
119
+ });
120
+ proc.stdout?.on("data", (data) => {
121
+ import_common.Logger.raw(data.toString());
122
+ });
123
+ proc.stderr?.on("data", (data) => {
124
+ import_common.Logger.raw(data.toString());
125
+ });
126
+ return new Promise((resolve, reject) => {
127
+ proc.on("exit", (code, signal) => {
128
+ if (!!code || signal) reject({
129
+ code,
130
+ signal
131
+ });
132
+ else resolve({
133
+ code,
134
+ signal
135
+ });
136
+ });
137
+ });
138
+ }
139
+ mkdir(dirPath) {
140
+ const writePath = import_path.default.isAbsolute(dirPath) ? dirPath : `${this.cwdPath}/${dirPath}`;
141
+ if (!import_fs.default.existsSync(writePath)) import_fs.default.mkdirSync(writePath, {
142
+ recursive: true
143
+ });
144
+ this.logger.verbose(`Make directory ${writePath}`);
145
+ return this;
146
+ }
147
+ writeFile(filePath, content) {
148
+ const writePath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
149
+ const dir = import_path.default.dirname(writePath);
150
+ if (!import_fs.default.existsSync(dir)) import_fs.default.mkdirSync(dir, {
151
+ recursive: true
152
+ });
153
+ const contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
154
+ if (import_fs.default.existsSync(writePath)) {
155
+ const currentContent = import_fs.default.readFileSync(writePath, "utf8");
156
+ if (currentContent === contentStr)
157
+ this.logger.verbose(`File ${writePath} is unchanged`);
158
+ else {
159
+ import_fs.default.writeFileSync(writePath, contentStr, "utf8");
160
+ this.logger.debug(`File ${writePath} is changed`);
161
+ }
162
+ } else {
163
+ import_fs.default.writeFileSync(writePath, contentStr, "utf8");
164
+ this.logger.debug(`File ${writePath} is created`);
165
+ }
166
+ return this;
167
+ }
168
+ writeJson(filePath, content) {
169
+ this.writeFile(filePath, JSON.stringify(content, null, 2));
170
+ return this;
171
+ }
172
+ readFile(filePath) {
173
+ const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
174
+ return import_fs.default.readFileSync(readPath, "utf8");
175
+ }
176
+ readJson(filePath) {
177
+ const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
178
+ return JSON.parse(import_fs.default.readFileSync(readPath, "utf8"));
179
+ }
180
+ async cp(srcPath, destPath) {
181
+ const src = import_path.default.isAbsolute(srcPath) ? srcPath : `${this.cwdPath}/${srcPath}`;
182
+ const dest = import_path.default.isAbsolute(destPath) ? destPath : `${this.cwdPath}/${destPath}`;
183
+ await import_promises.default.cp(src, dest, {
184
+ recursive: true
185
+ });
186
+ }
187
+ log(msg) {
188
+ this.logger.info(msg);
189
+ return this;
190
+ }
191
+ verbose(msg) {
192
+ this.logger.verbose(msg);
193
+ return this;
194
+ }
195
+ getTsConfig(pathname) {
196
+ const tsconfig = this.readJson(pathname);
197
+ if (tsconfig.extends) {
198
+ const extendsTsconfig = this.getTsConfig(tsconfig.extends);
199
+ return {
200
+ ...extendsTsconfig,
201
+ ...tsconfig,
202
+ compilerOptions: {
203
+ ...extendsTsconfig.compilerOptions,
204
+ ...tsconfig.compilerOptions
205
+ }
206
+ };
207
+ }
208
+ return tsconfig;
209
+ }
210
+ async #applyTemplateFile({ templatePath, targetPath, scanResult }, dict = {}) {
211
+ if (targetPath.endsWith(".js")) {
212
+ const getContent = await import(templatePath);
213
+ const content = getContent.default(scanResult ?? null, dict);
214
+ const convertedTargetPath = Object.entries(dict).reduce((path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value), targetPath.replace(".js", ".ts"));
215
+ if (content === null) return;
216
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
217
+ this.writeFile(convertedTargetPath, content);
218
+ } else if (targetPath.endsWith(".template")) {
219
+ const content = await import_promises.default.readFile(templatePath, "utf8");
220
+ const convertedTargetPath = Object.entries(dict).reduce((path2, [key, value]) => path2.replace(new RegExp(`__${key}__`, "g"), value), targetPath.slice(0, -9));
221
+ const convertedContent = Object.entries(dict).reduce((content2, [key, value]) => content2.replace(new RegExp(`<%= ${key} %>`, "g"), value), content);
222
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
223
+ this.writeFile(convertedTargetPath, convertedContent);
224
+ }
225
+ }
226
+ async applyTemplate({ basePath, template, scanResult, dict = {} }) {
227
+ const templatePath = `${__dirname}/src/templates${template ? `/${template}` : ""}`.replace(".ts", ".js");
228
+ if (import_fs.default.statSync(templatePath).isFile()) {
229
+ const filename = import_path.default.basename(templatePath);
230
+ await this.#applyTemplateFile({
231
+ templatePath,
232
+ targetPath: import_path.default.join(basePath, filename),
233
+ scanResult
234
+ }, dict);
235
+ } else {
236
+ if (!import_fs.default.existsSync(basePath)) await import_promises.default.mkdir(basePath, {
237
+ recursive: true
238
+ });
239
+ const subdirs = await import_promises.default.readdir(templatePath);
240
+ await Promise.all(subdirs.map(async (subdir) => {
241
+ const subpath = import_path.default.join(templatePath, subdir);
242
+ if (import_fs.default.statSync(subpath).isFile()) await this.#applyTemplateFile({
243
+ templatePath: subpath,
244
+ targetPath: import_path.default.join(basePath, subdir),
245
+ scanResult
246
+ }, dict);
247
+ else await this.applyTemplate({
248
+ basePath: import_path.default.join(basePath, subdir),
249
+ template: import_path.default.join(template, subdir),
250
+ scanResult,
251
+ dict
252
+ });
253
+ }));
254
+ }
255
+ }
256
+ }
257
+ class WorkspaceExecutor extends Executor {
258
+ static {
259
+ __name(this, "WorkspaceExecutor");
260
+ }
261
+ workspaceRoot;
262
+ repoName;
263
+ constructor({ workspaceRoot, repoName }) {
264
+ super(`${repoName} Executor`, workspaceRoot);
265
+ this.workspaceRoot = workspaceRoot;
266
+ this.repoName = repoName;
267
+ }
268
+ static fromRoot() {
269
+ const repoName = import_path.default.basename(process.cwd());
270
+ return new WorkspaceExecutor({
271
+ workspaceRoot: process.cwd(),
272
+ repoName
273
+ });
274
+ }
275
+ async scan() {
276
+ const [appNames, libNames, pkgNames] = await Promise.all([
277
+ this.getApps(),
278
+ this.getLibs(),
279
+ this.getPkgs()
280
+ ]);
281
+ const [appScanResults, libScanResults, pkgScanResults] = await Promise.all([
282
+ Promise.all(appNames.map(async (appName) => {
283
+ const app = AppExecutor.from(this, appName);
284
+ const akanConfig = await app.getConfig("scan");
285
+ return await app.scan({
286
+ akanConfig
287
+ });
288
+ })),
289
+ Promise.all(libNames.map(async (libName) => {
290
+ const lib = LibExecutor.from(this, libName);
291
+ const akanConfig = await lib.getConfig("scan");
292
+ return await lib.scan({
293
+ akanConfig
294
+ });
295
+ })),
296
+ Promise.all(pkgNames.map(async (pkgName) => {
297
+ return await PkgExecutor.from(this, pkgName).scan();
298
+ }))
299
+ ]);
300
+ return {
301
+ appNames,
302
+ libNames,
303
+ pkgNames,
304
+ apps: Object.fromEntries(appScanResults.map((app) => [
305
+ app.name,
306
+ app
307
+ ])),
308
+ libs: Object.fromEntries(libScanResults.map((lib) => [
309
+ lib.name,
310
+ lib
311
+ ])),
312
+ pkgs: Object.fromEntries(pkgScanResults.map((pkg) => [
313
+ pkg.name,
314
+ pkg
315
+ ]))
316
+ };
317
+ }
318
+ async getApps() {
319
+ return await this.#getDirHasFile(`${this.workspaceRoot}/apps`, "akan.config.ts");
320
+ }
321
+ async getLibs() {
322
+ return await this.#getDirHasFile(`${this.workspaceRoot}/libs`, "akan.config.ts");
323
+ }
324
+ async getSyss() {
325
+ const [appNames, libNames] = await Promise.all([
326
+ this.getApps(),
327
+ this.getLibs()
328
+ ]);
329
+ return [
330
+ appNames,
331
+ libNames
332
+ ];
333
+ }
334
+ async getPkgs() {
335
+ return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
336
+ }
337
+ async #getDirHasFile(basePath, targetFilename) {
338
+ const AVOID_DIRS = [
339
+ "node_modules",
340
+ "dist",
341
+ "public",
342
+ "./next"
343
+ ];
344
+ const getDirs = /* @__PURE__ */ __name(async (dirname, maxDepth = 3, results = [], prefix = "") => {
345
+ const dirs = await import_promises.default.readdir(dirname);
346
+ await Promise.all(dirs.map(async (dir) => {
347
+ if (AVOID_DIRS.includes(dir)) return;
348
+ const dirPath = import_path.default.join(dirname, dir);
349
+ if (import_fs.default.lstatSync(dirPath).isDirectory()) {
350
+ const hasTargetFile = import_fs.default.existsSync(import_path.default.join(dirPath, targetFilename));
351
+ if (hasTargetFile) results.push(`${prefix}${dir}`);
352
+ if (maxDepth > 0) await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
353
+ }
354
+ }));
355
+ return results;
356
+ }, "getDirs");
357
+ return await getDirs(basePath);
358
+ }
359
+ }
360
+ class SysExecutor extends Executor {
361
+ static {
362
+ __name(this, "SysExecutor");
363
+ }
364
+ workspace;
365
+ name;
366
+ type;
367
+ constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
368
+ super(`${name} Sys Executor`, `${workspace.workspaceRoot}/${type}s/${name}`);
369
+ this.workspace = workspace;
370
+ this.name = name;
371
+ this.type = type;
372
+ }
373
+ async getConfig(command) {
374
+ return this.type === "app" ? await (0, import_config.getAppConfig)(this.cwdPath, {
375
+ ...import_baseDevEnv.baseDevEnv,
376
+ appName: this.name,
377
+ command
378
+ }) : await (0, import_config.getLibConfig)(this.cwdPath, {
379
+ ...import_baseDevEnv.baseDevEnv,
380
+ appName: this.name,
381
+ command
382
+ });
383
+ }
384
+ async scan({ tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`), akanConfig }, libScanResults = {}) {
385
+ if (libScanResults[this.name]) return libScanResults[this.name];
386
+ const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
387
+ const scanner = new import_dependencyScanner.TypeScriptDependencyScanner(this.cwdPath);
388
+ const npmSet = new Set(Object.keys({
389
+ ...rootPackageJson.dependencies,
390
+ ...rootPackageJson.devDependencies
391
+ }));
392
+ const pkgPathSet = new Set(Object.keys(tsconfig.compilerOptions.paths).filter((path2) => tsconfig.compilerOptions.paths[path2].some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", "")));
393
+ const libPathSet = new Set(Object.keys(tsconfig.compilerOptions.paths).filter((path2) => tsconfig.compilerOptions.paths[path2].some((resolve) => resolve.startsWith("libs/"))).map((path2) => path2.replace("/*", "")));
394
+ const [npmDepSet, pkgPathDepSet, libPathDepSet] = await scanner.getImportSets([
395
+ npmSet,
396
+ pkgPathSet,
397
+ libPathSet
398
+ ]);
399
+ const pkgDeps = [
400
+ ...pkgPathDepSet
401
+ ].map((path2) => {
402
+ const pathSplitLength = path2.split("/").length;
403
+ return tsconfig.compilerOptions.paths[path2][0].split("/").slice(1, 1 + pathSplitLength).join("/");
404
+ });
405
+ const libDeps = [
406
+ ...libPathDepSet
407
+ ].map((path2) => {
408
+ const pathSplitLength = path2.split("/").length;
409
+ return tsconfig.compilerOptions.paths[path2][0].split("/").slice(1, 1 + pathSplitLength).join("/");
410
+ }).filter((libName) => libName !== this.name);
411
+ if (!import_fs.default.existsSync(`${this.cwdPath}/lib/__scalar`)) import_fs.default.mkdirSync(`${this.cwdPath}/lib/__scalar`, {
412
+ recursive: true
413
+ });
414
+ const files = (0, import_config.getDefaultFileScan)();
415
+ const dirnames = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => import_fs.default.lstatSync(`${this.cwdPath}/lib/${name}`).isDirectory());
416
+ const databaseDirs = dirnames.filter((name) => !name.startsWith("_"));
417
+ const serviceDirs = dirnames.filter((name) => name.startsWith("_") && !name.startsWith("__"));
418
+ await Promise.all(databaseDirs.map(async (name) => {
419
+ const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib", name));
420
+ filenames.forEach((filename) => {
421
+ if (filename.endsWith(".constant.ts")) files.constants.databases.push(name);
422
+ else if (filename.endsWith(".dictionary.ts")) files.dictionary.databases.push(name);
423
+ else if (filename.endsWith(".document.ts")) files.documents.databases.push(name);
424
+ else if (filename.endsWith(".service.ts")) files.services.databases.push(name);
425
+ else if (filename.endsWith(".signal.ts")) files.signal.databases.push(name);
426
+ else if (filename.endsWith(".store.ts")) files.store.databases.push(name);
427
+ else if (filename === "index.tsx") files.components.databases.push(name);
428
+ });
429
+ }));
430
+ await Promise.all(serviceDirs.map(async (dirname) => {
431
+ const name = dirname.slice(1);
432
+ const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib", dirname));
433
+ filenames.forEach((filename) => {
434
+ if (filename.endsWith(".dictionary.ts")) files.dictionary.services.push(name);
435
+ else if (filename.endsWith(".service.ts")) files.services.services.push(name);
436
+ else if (filename.endsWith(".signal.ts")) files.signal.services.push(name);
437
+ else if (filename.endsWith(".store.ts")) files.store.services.push(name);
438
+ else if (filename === "index.tsx") files.components.services.push(name);
439
+ });
440
+ }));
441
+ const scalarDirs = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_"));
442
+ await Promise.all(scalarDirs.map(async (name) => {
443
+ const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib/__scalar", name));
444
+ filenames.forEach((filename) => {
445
+ if (filename.endsWith(".constant.ts")) files.constants.scalars.push(name);
446
+ else if (filename.endsWith(".dictionary.ts")) files.dictionary.scalars.push(name);
447
+ else if (filename.endsWith(".document.ts")) files.documents.scalars.push(name);
448
+ else if (filename.endsWith(".service.ts")) files.services.scalars.push(name);
449
+ else if (filename.endsWith(".signal.ts")) files.signal.scalars.push(name);
450
+ else if (filename.endsWith(".store.ts")) files.store.scalars.push(name);
451
+ else if (filename === "index.ts") files.components.scalars.push(name);
452
+ });
453
+ }));
454
+ const missingLibDeps = [];
455
+ libDeps.forEach((libName) => {
456
+ if (!akanConfig.libs.includes(libName)) missingLibDeps.push(libName);
457
+ });
458
+ if (missingLibDeps.length) throw new Error(`Missing libs: ${missingLibDeps.join(", ")}, add these dependencies in akan.config.ts as { libs: [...other deps, ${missingLibDeps.join(", ")}] }`);
459
+ for (const libName of libDeps) {
460
+ if (libScanResults[libName]) continue;
461
+ const lib = new LibExecutor({
462
+ workspace: this.workspace,
463
+ name: libName
464
+ });
465
+ const akanConfig2 = await lib.getConfig();
466
+ libScanResults[libName] = await lib.scan({
467
+ akanConfig: akanConfig2
468
+ }, libScanResults);
469
+ }
470
+ const scanResult = {
471
+ name: this.name,
472
+ type: this.type,
473
+ akanConfig,
474
+ files,
475
+ libDeps,
476
+ pkgDeps,
477
+ dependencies: [
478
+ ...npmDepSet
479
+ ],
480
+ libs: Object.fromEntries(libDeps.map((libName) => [
481
+ libName,
482
+ libScanResults[libName]
483
+ ]))
484
+ };
485
+ await this.applyTemplate({
486
+ basePath: "lib",
487
+ template: "lib",
488
+ scanResult
489
+ });
490
+ await this.applyTemplate({
491
+ basePath: ".",
492
+ template: "server.ts",
493
+ scanResult
494
+ });
495
+ await this.applyTemplate({
496
+ basePath: ".",
497
+ template: "client.ts",
498
+ scanResult
499
+ });
500
+ if (this.type === "lib") await this.applyTemplate({
501
+ basePath: ".",
502
+ template: "index.ts",
503
+ scanResult
504
+ });
505
+ this.writeJson(`akan.${this.type}.json`, scanResult);
506
+ return scanResult;
507
+ }
508
+ async getDatabaseModules() {
509
+ const databaseModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
510
+ return databaseModules;
511
+ }
512
+ async getServiceModules() {
513
+ const serviceModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => name.startsWith("_") && !name.startsWith("__")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.service.ts`));
514
+ return serviceModules;
515
+ }
516
+ async getScalarModules() {
517
+ const scalarModules = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
518
+ return scalarModules;
519
+ }
520
+ }
521
+ class AppExecutor extends SysExecutor {
522
+ static {
523
+ __name(this, "AppExecutor");
524
+ }
525
+ constructor({ workspace, name }) {
526
+ super({
527
+ workspace,
528
+ name,
529
+ type: "app"
530
+ });
531
+ }
532
+ static from(executor, name) {
533
+ if (executor instanceof WorkspaceExecutor) return new AppExecutor({
534
+ workspace: executor,
535
+ name
536
+ });
537
+ return new AppExecutor({
538
+ workspace: executor.workspace,
539
+ name
540
+ });
541
+ }
542
+ async getConfig(command) {
543
+ return await (0, import_config.getAppConfig)(this.cwdPath, {
544
+ ...import_baseDevEnv.baseDevEnv,
545
+ appName: this.name,
546
+ command
547
+ });
548
+ }
549
+ async syncAssets(libDeps) {
550
+ const projectPublicLibPath = `${this.cwdPath}/public/libs`;
551
+ if (import_fs.default.existsSync(projectPublicLibPath)) await import_promises.default.rm(projectPublicLibPath, {
552
+ recursive: true
553
+ });
554
+ const targetDeps = libDeps.filter((dep) => import_fs.default.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/public`));
555
+ await Promise.all(targetDeps.map((dep) => import_promises.default.mkdir(`${projectPublicLibPath}/${dep}`, {
556
+ recursive: true
557
+ })));
558
+ await Promise.all(targetDeps.map((dep) => import_promises.default.cp(`${this.workspace.workspaceRoot}/libs/${dep}/public`, `${projectPublicLibPath}/${dep}`, {
559
+ recursive: true
560
+ })));
561
+ }
562
+ }
563
+ class DistAppExecutor extends Executor {
564
+ static {
565
+ __name(this, "DistAppExecutor");
566
+ }
567
+ name;
568
+ constructor({ workspace, name }) {
569
+ super(`${name} Dist App Executor`, `${workspace.workspaceRoot}/dist/apps/${name}`);
570
+ this.name = name;
571
+ }
572
+ static from(executor, name) {
573
+ if (executor instanceof WorkspaceExecutor) return new DistAppExecutor({
574
+ workspace: executor,
575
+ name
576
+ });
577
+ return new DistAppExecutor({
578
+ workspace: executor.workspace,
579
+ name
580
+ });
581
+ }
582
+ }
583
+ class LibExecutor extends SysExecutor {
584
+ static {
585
+ __name(this, "LibExecutor");
586
+ }
587
+ workspaceRoot;
588
+ repoName;
589
+ constructor({ workspace, name }) {
590
+ super({
591
+ workspace,
592
+ name,
593
+ type: "lib"
594
+ });
595
+ }
596
+ static from(executor, name) {
597
+ if (executor instanceof WorkspaceExecutor) return new LibExecutor({
598
+ workspace: executor,
599
+ name
600
+ });
601
+ return new LibExecutor({
602
+ workspace: executor.workspace,
603
+ name
604
+ });
605
+ }
606
+ async getConfig(command) {
607
+ return await (0, import_config.getLibConfig)(this.cwdPath, {
608
+ ...import_baseDevEnv.baseDevEnv,
609
+ appName: this.name,
610
+ command
611
+ });
612
+ }
613
+ }
614
+ class DistLibExecutor extends Executor {
615
+ static {
616
+ __name(this, "DistLibExecutor");
617
+ }
618
+ name;
619
+ constructor({ workspace, name }) {
620
+ super(`${name} Dist Lib Executor`, `${workspace.workspaceRoot}/dist/libs/${name}`);
621
+ this.name = name;
622
+ }
623
+ static from(executor, name) {
624
+ if (executor instanceof WorkspaceExecutor) return new DistAppExecutor({
625
+ workspace: executor,
626
+ name
627
+ });
628
+ return new DistLibExecutor({
629
+ workspace: executor.workspace,
630
+ name
631
+ });
632
+ }
633
+ }
634
+ class PkgExecutor extends Executor {
635
+ static {
636
+ __name(this, "PkgExecutor");
637
+ }
638
+ workspace;
639
+ name;
640
+ constructor({ workspace = WorkspaceExecutor.fromRoot(), name }) {
641
+ super(`${name} Pkg Executor`, `${workspace.workspaceRoot}/pkgs/${name}`);
642
+ this.workspace = workspace;
643
+ this.name = name;
644
+ }
645
+ static from(executor, name) {
646
+ if (executor instanceof WorkspaceExecutor) return new PkgExecutor({
647
+ workspace: executor,
648
+ name
649
+ });
650
+ return new PkgExecutor({
651
+ workspace: executor.workspace,
652
+ name
653
+ });
654
+ }
655
+ async scan({ packageJson = this.readJson(`${this.cwdPath}/package.json`), tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`) } = {}) {
656
+ const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
657
+ const scanner = new import_dependencyScanner.TypeScriptDependencyScanner(this.cwdPath);
658
+ const npmSet = new Set(Object.keys({
659
+ ...rootPackageJson.dependencies,
660
+ ...rootPackageJson.devDependencies
661
+ }));
662
+ const pkgPathSet = new Set(Object.keys(tsconfig.compilerOptions.paths).filter((path2) => tsconfig.compilerOptions.paths[path2].some((resolve) => resolve.startsWith("pkgs/"))).map((path2) => path2.replace("/*", "")));
663
+ const [npmDepSet, pkgPathDepSet] = await scanner.getImportSets([
664
+ npmSet,
665
+ pkgPathSet
666
+ ]);
667
+ const pkgDeps = [
668
+ ...pkgPathDepSet
669
+ ].map((path2) => {
670
+ const pathSplitLength = path2.split("/").length;
671
+ return tsconfig.compilerOptions.paths[path2][0].split("/").slice(1, 1 + pathSplitLength).join("/");
672
+ }).filter((pkg) => pkg !== this.name);
673
+ const pkgScanResult = {
674
+ name: this.name,
675
+ pkgDeps,
676
+ dependencies: [
677
+ ...npmDepSet
678
+ ]
679
+ };
680
+ return pkgScanResult;
681
+ }
682
+ }
683
+ class DistPkgExecutor extends Executor {
684
+ static {
685
+ __name(this, "DistPkgExecutor");
686
+ }
687
+ workspaceRoot;
688
+ repoName;
689
+ name;
690
+ constructor({ workspaceRoot, repoName, name }) {
691
+ super(`${name} Dist Pkg Executor`, `${workspaceRoot}/dist/pkgs/${name}`);
692
+ this.workspaceRoot = workspaceRoot;
693
+ this.repoName = repoName;
694
+ this.name = name;
695
+ }
696
+ static from(workspaceExecutor, name) {
697
+ return new DistPkgExecutor({
698
+ workspaceRoot: workspaceExecutor.workspaceRoot,
699
+ repoName: workspaceExecutor.repoName,
700
+ name
701
+ });
702
+ }
703
+ }
704
+ // Annotate the CommonJS export names for ESM import in node:
705
+ 0 && (module.exports = {
706
+ AppExecutor,
707
+ DistAppExecutor,
708
+ DistLibExecutor,
709
+ DistPkgExecutor,
710
+ Executor,
711
+ LibExecutor,
712
+ PkgExecutor,
713
+ SysExecutor,
714
+ WorkspaceExecutor
715
+ });