akanjs 2.0.2 → 2.0.4

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.
@@ -36,12 +36,10 @@ export class ApplicationRunner extends runner("application") {
36
36
  dict: { appName, companyName: workspace.repoName, startDomain: "localhost" },
37
37
  options: { libs },
38
38
  });
39
- await workspace.setTsPaths("app", appName);
40
39
  return AppExecutor.from(workspace, appName);
41
40
  }
42
41
  async removeApplication(app: App) {
43
42
  await app.workspace.exec(`rm -rf apps/${app.name}`);
44
- await app.workspace.unsetTsPaths("app", app.name);
45
43
  }
46
44
  async getConfig(app: App) {
47
45
  return await app.getConfig();
package/cli/index.js CHANGED
@@ -865,7 +865,7 @@ import {
865
865
  spawn
866
866
  } from "child_process";
867
867
  import { readFileSync as readFileSync3 } from "fs";
868
- import { mkdir as mkdir2, readdir as readDirEntries, stat as stat2 } from "fs/promises";
868
+ import { copyFile, mkdir as mkdir2, readdir as readDirEntries, stat as stat2 } from "fs/promises";
869
869
  import path7 from "path";
870
870
  var {$ } = globalThis.Bun;
871
871
  import chalk4 from "chalk";
@@ -2294,6 +2294,39 @@ ${summary.join(", ")} found${output.join(`
2294
2294
  }
2295
2295
  }
2296
2296
 
2297
+ var staticTemplateFileExtensions = new Set([
2298
+ ".avif",
2299
+ ".bmp",
2300
+ ".cjs",
2301
+ ".css",
2302
+ ".eot",
2303
+ ".gif",
2304
+ ".html",
2305
+ ".ico",
2306
+ ".jpeg",
2307
+ ".jpg",
2308
+ ".js",
2309
+ ".json",
2310
+ ".map",
2311
+ ".md",
2312
+ ".mjs",
2313
+ ".mp3",
2314
+ ".mp4",
2315
+ ".ogg",
2316
+ ".otf",
2317
+ ".pdf",
2318
+ ".png",
2319
+ ".svg",
2320
+ ".ttf",
2321
+ ".txt",
2322
+ ".wasm",
2323
+ ".wav",
2324
+ ".webm",
2325
+ ".webp",
2326
+ ".woff",
2327
+ ".woff2",
2328
+ ".xml"
2329
+ ]);
2297
2330
  var execEmoji = {
2298
2331
  workspace: "\uD83C\uDFE0",
2299
2332
  app: "\uD83D\uDE80",
@@ -2689,6 +2722,15 @@ class Executor {
2689
2722
  const convertedContent = Object.entries(dict).reduce((data, [key, value]) => data.replace(new RegExp(`<%= ${key} %>`, "g"), value), content);
2690
2723
  this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
2691
2724
  return this.writeFile(convertedTargetPath, convertedContent, { overwrite });
2725
+ } else if (staticTemplateFileExtensions.has(path7.extname(targetPath).toLowerCase())) {
2726
+ const convertedTargetPath = Object.entries(dict).reduce((path8, [key, value]) => path8.replace(new RegExp(`__${key}__`, "g"), value), targetPath);
2727
+ const writePath = this.getPath(convertedTargetPath);
2728
+ const dirname3 = path7.dirname(writePath);
2729
+ if (!await FileSys.dirExists(dirname3))
2730
+ await mkdir2(dirname3, { recursive: true });
2731
+ await copyFile(templatePath, writePath);
2732
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
2733
+ return { filePath: writePath, content: "" };
2692
2734
  } else
2693
2735
  return null;
2694
2736
  }
@@ -2827,28 +2869,24 @@ class WorkspaceExecutor extends Executor {
2827
2869
  const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
2828
2870
  return [appNames, libNames, pkgNames];
2829
2871
  }
2830
- async setTsPaths(type, name) {
2872
+ async setPkgTsPaths(name) {
2831
2873
  const rootTsConfig = await this.readJson("tsconfig.json");
2832
2874
  rootTsConfig.compilerOptions.paths ??= {};
2833
- if (type === "lib" || type === "pkg")
2834
- rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
2835
- rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
2836
- rootTsConfig.compilerOptions.paths[`@${type}s/${name}/*`] = [`${type}s/${name}/*`];
2837
- if (type === "lib" || type === "pkg")
2838
- rootTsConfig.compilerOptions.paths[`@${type}s/${name}`] = [`${type}s/${name}/index.ts`];
2875
+ rootTsConfig.compilerOptions.paths[name] = [`./pkgs/${name}/index.ts`];
2876
+ rootTsConfig.compilerOptions.paths[`${name}/*`] = [`./pkgs/${name}/*`];
2839
2877
  if (rootTsConfig.references) {
2840
- if (!rootTsConfig.references.some((ref) => ref.path === `./${type}s/${name}/tsconfig.json`))
2841
- rootTsConfig.references.push({ path: `./${type}s/${name}/tsconfig.json` });
2878
+ if (!rootTsConfig.references.some((ref) => ref.path === `./pkgs/${name}/tsconfig.json`))
2879
+ rootTsConfig.references.push({ path: `./pkgs/${name}/tsconfig.json` });
2842
2880
  }
2843
2881
  await this.writeJson("tsconfig.json", rootTsConfig);
2844
2882
  return this;
2845
2883
  }
2846
- async unsetTsPaths(type, name) {
2884
+ async unsetPkgTsPaths(name) {
2847
2885
  const rootTsConfig = await this.readJson("tsconfig.json");
2848
- const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths ?? {}).filter((key) => !key.startsWith(`@${name}`) && !key.startsWith(`@${type}s/${name}`));
2886
+ const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths ?? {}).filter((key) => key !== name && key !== `${name}/*`);
2849
2887
  rootTsConfig.compilerOptions.paths = Object.fromEntries(filteredKeys.map((key) => [key, rootTsConfig.compilerOptions.paths?.[key] ?? []]));
2850
2888
  if (rootTsConfig.references) {
2851
- rootTsConfig.references = rootTsConfig.references.filter((ref) => !ref.path.startsWith(`./${type}s/${name}`));
2889
+ rootTsConfig.references = rootTsConfig.references.filter((ref) => ref.path !== `./pkgs/${name}/tsconfig.json`);
2852
2890
  }
2853
2891
  await this.writeJson("tsconfig.json", rootTsConfig);
2854
2892
  return this;
@@ -3120,10 +3158,6 @@ class SysExecutor extends Executor {
3120
3158
  await this.scan();
3121
3159
  return fileContents;
3122
3160
  }
3123
- setTsPaths() {
3124
- this.workspace.setTsPaths(this.type, this.name);
3125
- return this;
3126
- }
3127
3161
  }
3128
3162
 
3129
3163
  class AppExecutor extends SysExecutor {
@@ -9341,13 +9375,11 @@ class LibraryRunner extends runner("library") {
9341
9375
  async createLibrary(libName, workspace) {
9342
9376
  await workspace.exec(`mkdir -p libs/${libName}`);
9343
9377
  await workspace.applyTemplate({ basePath: `libs/${libName}`, template: "libRoot", dict: { libName } });
9344
- await workspace.setTsPaths("lib", libName);
9345
9378
  const lib = LibExecutor.from(workspace, libName);
9346
9379
  return lib;
9347
9380
  }
9348
9381
  async removeLibrary(lib) {
9349
9382
  await lib.workspace.exec(`rm -rf libs/${lib.name}`);
9350
- await lib.workspace.unsetTsPaths("lib", lib.name);
9351
9383
  }
9352
9384
  async#copyInstalledLibrary(workspace, libName) {
9353
9385
  const installedPackageJson = `node_modules/akanjs/libs/${libName}/package.json`;
@@ -9368,7 +9400,6 @@ class LibraryRunner extends runner("library") {
9368
9400
  if (!copiedFromInstalledPackage)
9369
9401
  await this.#copyLibraryFromRepository(workspace, libName);
9370
9402
  await workspace.cp(`libs/${libName}/env/env.server.example.ts`, `libs/${libName}/env/env.server.testing.ts`);
9371
- await workspace.setTsPaths("lib", libName);
9372
9403
  await workspace.commit(`Add ${libName} library`);
9373
9404
  return LibExecutor.from(workspace, libName);
9374
9405
  }
@@ -9449,12 +9480,10 @@ class ApplicationRunner extends runner("application") {
9449
9480
  dict: { appName, companyName: workspace.repoName, startDomain: "localhost" },
9450
9481
  options: { libs }
9451
9482
  });
9452
- await workspace.setTsPaths("app", appName);
9453
9483
  return AppExecutor.from(workspace, appName);
9454
9484
  }
9455
9485
  async removeApplication(app) {
9456
9486
  await app.workspace.exec(`rm -rf apps/${app.name}`);
9457
- await app.workspace.unsetTsPaths("app", app.name);
9458
9487
  }
9459
9488
  async getConfig(app) {
9460
9489
  return await app.getConfig();
@@ -10048,11 +10077,11 @@ class PackageRunner extends runner("package") {
10048
10077
  }
10049
10078
  async createPackage(workspace, pkgName) {
10050
10079
  await workspace.applyTemplate({ basePath: `pkgs/${pkgName}`, template: "pkgRoot", dict: { pkgName } });
10051
- await workspace.setTsPaths("pkg", pkgName);
10080
+ await workspace.setPkgTsPaths(pkgName);
10052
10081
  }
10053
10082
  async removePackage(pkg) {
10054
10083
  await pkg.workspace.exec(`rm -rf pkgs/${pkg.name}`);
10055
- await pkg.workspace.unsetTsPaths("pkg", pkg.name);
10084
+ await pkg.workspace.unsetPkgTsPaths(pkg.name);
10056
10085
  }
10057
10086
  async scanSync(pkg) {
10058
10087
  const scanResult = await pkg.scan();
@@ -5,13 +5,11 @@ export class LibraryRunner extends runner("library") {
5
5
  async createLibrary(libName: string, workspace: Workspace) {
6
6
  await workspace.exec(`mkdir -p libs/${libName}`);
7
7
  await workspace.applyTemplate({ basePath: `libs/${libName}`, template: "libRoot", dict: { libName } });
8
- await workspace.setTsPaths("lib", libName);
9
8
  const lib = LibExecutor.from(workspace, libName);
10
9
  return lib;
11
10
  }
12
11
  async removeLibrary(lib: Lib) {
13
12
  await lib.workspace.exec(`rm -rf libs/${lib.name}`);
14
- await lib.workspace.unsetTsPaths("lib", lib.name);
15
13
  }
16
14
 
17
15
  async #copyInstalledLibrary(workspace: Workspace, libName: string) {
@@ -32,7 +30,6 @@ export class LibraryRunner extends runner("library") {
32
30
  const copiedFromInstalledPackage = await this.#copyInstalledLibrary(workspace, libName);
33
31
  if (!copiedFromInstalledPackage) await this.#copyLibraryFromRepository(workspace, libName);
34
32
  await workspace.cp(`libs/${libName}/env/env.server.example.ts`, `libs/${libName}/env/env.server.testing.ts`);
35
- await workspace.setTsPaths("lib", libName);
36
33
  await workspace.commit(`Add ${libName} library`);
37
34
  return LibExecutor.from(workspace, libName);
38
35
  }
@@ -23,11 +23,11 @@ export class PackageRunner extends runner("package") {
23
23
  }
24
24
  async createPackage(workspace: Workspace, pkgName: string) {
25
25
  await workspace.applyTemplate({ basePath: `pkgs/${pkgName}`, template: "pkgRoot", dict: { pkgName } });
26
- await workspace.setTsPaths("pkg", pkgName);
26
+ await workspace.setPkgTsPaths(pkgName);
27
27
  }
28
28
  async removePackage(pkg: Pkg) {
29
29
  await pkg.workspace.exec(`rm -rf pkgs/${pkg.name}`);
30
- await pkg.workspace.unsetTsPaths("pkg", pkg.name);
30
+ await pkg.workspace.unsetPkgTsPaths(pkg.name);
31
31
  }
32
32
  async scanSync(pkg: Pkg) {
33
33
  const scanResult = await pkg.scan();
@@ -8,7 +8,7 @@ import {
8
8
  spawn,
9
9
  } from "node:child_process";
10
10
  import { readFileSync } from "node:fs";
11
- import { mkdir, readdir as readDirEntries, stat } from "node:fs/promises";
11
+ import { copyFile, mkdir, readdir as readDirEntries, stat } from "node:fs/promises";
12
12
  import path from "node:path";
13
13
  import {
14
14
  capitalize,
@@ -30,6 +30,40 @@ import { Spinner } from "./spinner";
30
30
  import { TypeChecker } from "./typeChecker";
31
31
  import type { FileContent, PackageJson, TsConfigJson } from "./types";
32
32
 
33
+ const staticTemplateFileExtensions = new Set([
34
+ ".avif",
35
+ ".bmp",
36
+ ".cjs",
37
+ ".css",
38
+ ".eot",
39
+ ".gif",
40
+ ".html",
41
+ ".ico",
42
+ ".jpeg",
43
+ ".jpg",
44
+ ".js",
45
+ ".json",
46
+ ".map",
47
+ ".md",
48
+ ".mjs",
49
+ ".mp3",
50
+ ".mp4",
51
+ ".ogg",
52
+ ".otf",
53
+ ".pdf",
54
+ ".png",
55
+ ".svg",
56
+ ".ttf",
57
+ ".txt",
58
+ ".wasm",
59
+ ".wav",
60
+ ".webm",
61
+ ".webp",
62
+ ".woff",
63
+ ".woff2",
64
+ ".xml",
65
+ ]);
66
+
33
67
  export const execEmoji = {
34
68
  workspace: "🏠",
35
69
  app: "🚀",
@@ -451,6 +485,17 @@ export class Executor {
451
485
  );
452
486
  this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
453
487
  return this.writeFile(convertedTargetPath, convertedContent, { overwrite });
488
+ } else if (staticTemplateFileExtensions.has(path.extname(targetPath).toLowerCase())) {
489
+ const convertedTargetPath = Object.entries(dict).reduce(
490
+ (path, [key, value]) => path.replace(new RegExp(`__${key}__`, "g"), value),
491
+ targetPath,
492
+ );
493
+ const writePath = this.getPath(convertedTargetPath);
494
+ const dirname = path.dirname(writePath);
495
+ if (!(await FileSys.dirExists(dirname))) await mkdir(dirname, { recursive: true });
496
+ await copyFile(templatePath, writePath);
497
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
498
+ return { filePath: writePath, content: "" };
454
499
  } else return null;
455
500
  }
456
501
  async _applyTemplate({
@@ -636,33 +681,29 @@ export class WorkspaceExecutor extends Executor {
636
681
  const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
637
682
  return [appNames, libNames, pkgNames] as [string[], string[], string[]];
638
683
  }
639
- async setTsPaths(type: "app" | "lib" | "pkg", name: string) {
684
+ async setPkgTsPaths(name: string) {
640
685
  const rootTsConfig = (await this.readJson("tsconfig.json")) as TsConfigJson;
641
686
  rootTsConfig.compilerOptions.paths ??= {};
642
- if (type === "lib" || type === "pkg")
643
- rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
644
- rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
645
- rootTsConfig.compilerOptions.paths[`@${type}s/${name}/*`] = [`${type}s/${name}/*`];
646
- if (type === "lib" || type === "pkg")
647
- rootTsConfig.compilerOptions.paths[`@${type}s/${name}`] = [`${type}s/${name}/index.ts`];
687
+ rootTsConfig.compilerOptions.paths[name] = [`./pkgs/${name}/index.ts`];
688
+ rootTsConfig.compilerOptions.paths[`${name}/*`] = [`./pkgs/${name}/*`];
648
689
  if (rootTsConfig.references) {
649
- if (!rootTsConfig.references.some((ref) => ref.path === `./${type}s/${name}/tsconfig.json`))
650
- rootTsConfig.references.push({ path: `./${type}s/${name}/tsconfig.json` });
690
+ if (!rootTsConfig.references.some((ref) => ref.path === `./pkgs/${name}/tsconfig.json`))
691
+ rootTsConfig.references.push({ path: `./pkgs/${name}/tsconfig.json` });
651
692
  }
652
693
  await this.writeJson("tsconfig.json", rootTsConfig);
653
694
  return this;
654
695
  }
655
- async unsetTsPaths(type: "app" | "lib" | "pkg", name: string) {
696
+ async unsetPkgTsPaths(name: string) {
656
697
  const rootTsConfig = (await this.readJson("tsconfig.json")) as TsConfigJson;
657
698
  const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths ?? {}).filter(
658
- (key) => !key.startsWith(`@${name}`) && !key.startsWith(`@${type}s/${name}`),
699
+ (key) => key !== name && key !== `${name}/*`,
659
700
  );
660
701
  rootTsConfig.compilerOptions.paths = Object.fromEntries(
661
702
  filteredKeys.map((key) => [key, rootTsConfig.compilerOptions.paths?.[key] ?? []]),
662
703
  );
663
704
  if (rootTsConfig.references) {
664
705
  rootTsConfig.references = rootTsConfig.references.filter(
665
- (ref) => !ref.path.startsWith(`./${type}s/${name}`),
706
+ (ref) => ref.path !== `./pkgs/${name}/tsconfig.json`,
666
707
  ) as TsConfigJson["references"];
667
708
  }
668
709
  await this.writeJson("tsconfig.json", rootTsConfig);
@@ -1023,10 +1064,6 @@ export class SysExecutor extends Executor {
1023
1064
  await this.scan();
1024
1065
  return fileContents;
1025
1066
  }
1026
- setTsPaths() {
1027
- this.workspace.setTsPaths(this.type, this.name);
1028
- return this;
1029
- }
1030
1067
  }
1031
1068
 
1032
1069
  interface AppExecutorOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "bin": {