@akanjs/devkit 0.0.92 → 0.0.94

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.md ADDED
@@ -0,0 +1,11 @@
1
+ # akan
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build akan` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test akan` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "0.0.92",
3
+ "version": "0.0.94",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -37,5 +37,8 @@
37
37
  "require": "./index.js",
38
38
  "import": "./index.mjs"
39
39
  }
40
+ },
41
+ "esbuild": {
42
+ "platform": "node"
40
43
  }
41
44
  }
package/src/builder.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { PackageJson } from "./types";
2
1
  import { Executor } from "./executors";
2
+ import { PackageJson } from "./types";
3
+ interface BuildOptions {
4
+ bundle?: boolean;
5
+ additionalEntryPoints?: string[];
6
+ }
3
7
  interface BuilderOptions {
4
- name: string;
5
8
  executor: Executor;
6
9
  distExecutor: Executor;
7
10
  pkgJson: PackageJson;
@@ -9,8 +12,7 @@ interface BuilderOptions {
9
12
  }
10
13
  export declare class Builder {
11
14
  #private;
12
- name: string;
13
- constructor({ name, executor, distExecutor, pkgJson, rootPackageJson }: BuilderOptions);
14
- build(): Promise<void>;
15
+ constructor({ executor, distExecutor, pkgJson, rootPackageJson }: BuilderOptions);
16
+ build(options?: BuildOptions): Promise<void>;
15
17
  }
16
18
  export {};
package/src/builder.js CHANGED
@@ -32,61 +32,61 @@ __export(builder_exports, {
32
32
  module.exports = __toCommonJS(builder_exports);
33
33
  var esbuild = __toESM(require("esbuild"));
34
34
  var import_esbuild_plugin_d = require("esbuild-plugin-d.ts");
35
+ var import_fs = __toESM(require("fs"));
35
36
  var import_extractDeps = require("./extractDeps");
36
37
  class Builder {
37
- name;
38
38
  #executor;
39
39
  #distExecutor;
40
40
  #pkgJson;
41
41
  #rootPackageJson;
42
- constructor({ name, executor, distExecutor, pkgJson, rootPackageJson }) {
43
- this.name = name;
42
+ constructor({ executor, distExecutor, pkgJson, rootPackageJson }) {
44
43
  this.#executor = executor;
45
44
  this.#distExecutor = distExecutor;
46
45
  this.#pkgJson = pkgJson;
47
46
  this.#rootPackageJson = rootPackageJson;
48
47
  }
49
- async build() {
50
- let buildResult;
51
- const platform = [
52
- "@akanjs/devkit",
53
- "@akanjs/document",
54
- "@akanjs/lint",
55
- "@akanjs/nest",
56
- "@akanjs/server",
57
- "@akanjs/service"
58
- ].includes(this.name) ? "node" : ["@akanjs/client", "@akanjs/next", "@akanjs/store", "@akanjs/ui"].includes(this.name) ? "browser" : "neutral";
59
- buildResult = await esbuild.build({
60
- write: false,
61
- entryPoints: [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
62
- bundle: false,
48
+ #getBuildOptions(format, { bundle = false, additionalEntryPoints = [] } = {}) {
49
+ return {
50
+ entryPoints: [
51
+ ...bundle ? [`${this.#executor.cwdPath}/index.ts`] : [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
52
+ ...additionalEntryPoints
53
+ ],
54
+ bundle,
63
55
  packages: "external",
64
56
  splitting: false,
65
- platform,
66
- format: "cjs",
57
+ platform: this.#pkgJson.esbuild?.platform,
58
+ format,
67
59
  outdir: this.#distExecutor.cwdPath,
68
- outExtension: { ".js": this.#pkgJson.type === "module" ? ".cjs" : ".js" },
69
- logLevel: "error",
70
- plugins: [(0, import_esbuild_plugin_d.dtsPlugin)({ tsconfig: `${this.#executor.cwdPath}/tsconfig.json` })]
71
- });
72
- await esbuild.build({
60
+ outExtension: format === "cjs" ? { ".js": this.#pkgJson.type === "module" ? ".cjs" : ".js" } : { ".js": this.#pkgJson.type === "module" ? ".js" : ".mjs" },
61
+ logLevel: "error"
62
+ };
63
+ }
64
+ #getAssetBuildOptions() {
65
+ return {
73
66
  write: true,
74
- entryPoints: [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
75
67
  bundle: false,
76
- packages: "external",
77
- splitting: false,
78
- platform,
79
- format: "esm",
68
+ entryPoints: [
69
+ `${this.#executor.cwdPath}/**/*.css`,
70
+ `${this.#executor.cwdPath}/**/*.md`,
71
+ `${this.#executor.cwdPath}/**/*.template`,
72
+ `${this.#executor.cwdPath}/**/*.js`
73
+ ],
80
74
  outdir: this.#distExecutor.cwdPath,
81
- outExtension: { ".js": this.#pkgJson.type === "module" ? ".js" : ".mjs" },
82
75
  logLevel: "error",
83
- plugins: []
84
- });
85
- const dependencies = buildResult.outputFiles ? (0, import_extractDeps.extractDependencies)(
86
- buildResult.outputFiles,
87
- this.#rootPackageJson,
88
- Object.keys(this.#pkgJson.dependencies ?? {})
89
- ) : {};
76
+ loader: { ".css": "copy", ".md": "copy", ".template": "copy", ".js": "copy" }
77
+ };
78
+ }
79
+ async build(options = {}) {
80
+ if (import_fs.default.existsSync(this.#distExecutor.cwdPath))
81
+ await this.#distExecutor.exec(`rm -rf ${this.#distExecutor.cwdPath}`);
82
+ const plugins = [(0, import_esbuild_plugin_d.dtsPlugin)({ tsconfig: `${this.#executor.cwdPath}/tsconfig.json` })];
83
+ const [buildResult] = await Promise.all([
84
+ esbuild.build({ ...this.#getBuildOptions("cjs", options), write: false, plugins }),
85
+ esbuild.build({ write: true, ...this.#getBuildOptions("esm", options) }),
86
+ esbuild.build({ ...this.#getAssetBuildOptions() })
87
+ ]);
88
+ const existingDeps = Object.keys(this.#pkgJson.dependencies ?? {});
89
+ const dependencies = (0, import_extractDeps.extractDependencies)(buildResult.outputFiles, this.#rootPackageJson, existingDeps);
90
90
  const pkgPackageJson = {
91
91
  ...this.#pkgJson,
92
92
  main: "./index.js",
@@ -100,8 +100,7 @@ class Builder {
100
100
  ...this.#pkgJson.exports ?? {}
101
101
  }
102
102
  };
103
- if (buildResult.outputFiles)
104
- buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
103
+ buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
105
104
  this.#distExecutor.writeJson("package.json", pkgPackageJson);
106
105
  }
107
106
  }
package/src/builder.mjs CHANGED
@@ -1,60 +1,60 @@
1
1
  import * as esbuild from "esbuild";
2
2
  import { dtsPlugin } from "esbuild-plugin-d.ts";
3
+ import fs from "fs";
3
4
  import { extractDependencies } from "./extractDeps";
4
5
  class Builder {
5
- name;
6
6
  #executor;
7
7
  #distExecutor;
8
8
  #pkgJson;
9
9
  #rootPackageJson;
10
- constructor({ name, executor, distExecutor, pkgJson, rootPackageJson }) {
11
- this.name = name;
10
+ constructor({ executor, distExecutor, pkgJson, rootPackageJson }) {
12
11
  this.#executor = executor;
13
12
  this.#distExecutor = distExecutor;
14
13
  this.#pkgJson = pkgJson;
15
14
  this.#rootPackageJson = rootPackageJson;
16
15
  }
17
- async build() {
18
- let buildResult;
19
- const platform = [
20
- "@akanjs/devkit",
21
- "@akanjs/document",
22
- "@akanjs/lint",
23
- "@akanjs/nest",
24
- "@akanjs/server",
25
- "@akanjs/service"
26
- ].includes(this.name) ? "node" : ["@akanjs/client", "@akanjs/next", "@akanjs/store", "@akanjs/ui"].includes(this.name) ? "browser" : "neutral";
27
- buildResult = await esbuild.build({
28
- write: false,
29
- entryPoints: [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
30
- bundle: false,
16
+ #getBuildOptions(format, { bundle = false, additionalEntryPoints = [] } = {}) {
17
+ return {
18
+ entryPoints: [
19
+ ...bundle ? [`${this.#executor.cwdPath}/index.ts`] : [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
20
+ ...additionalEntryPoints
21
+ ],
22
+ bundle,
31
23
  packages: "external",
32
24
  splitting: false,
33
- platform,
34
- format: "cjs",
25
+ platform: this.#pkgJson.esbuild?.platform,
26
+ format,
35
27
  outdir: this.#distExecutor.cwdPath,
36
- outExtension: { ".js": this.#pkgJson.type === "module" ? ".cjs" : ".js" },
37
- logLevel: "error",
38
- plugins: [dtsPlugin({ tsconfig: `${this.#executor.cwdPath}/tsconfig.json` })]
39
- });
40
- await esbuild.build({
28
+ outExtension: format === "cjs" ? { ".js": this.#pkgJson.type === "module" ? ".cjs" : ".js" } : { ".js": this.#pkgJson.type === "module" ? ".js" : ".mjs" },
29
+ logLevel: "error"
30
+ };
31
+ }
32
+ #getAssetBuildOptions() {
33
+ return {
41
34
  write: true,
42
- entryPoints: [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
43
35
  bundle: false,
44
- packages: "external",
45
- splitting: false,
46
- platform,
47
- format: "esm",
36
+ entryPoints: [
37
+ `${this.#executor.cwdPath}/**/*.css`,
38
+ `${this.#executor.cwdPath}/**/*.md`,
39
+ `${this.#executor.cwdPath}/**/*.template`,
40
+ `${this.#executor.cwdPath}/**/*.js`
41
+ ],
48
42
  outdir: this.#distExecutor.cwdPath,
49
- outExtension: { ".js": this.#pkgJson.type === "module" ? ".js" : ".mjs" },
50
43
  logLevel: "error",
51
- plugins: []
52
- });
53
- const dependencies = buildResult.outputFiles ? extractDependencies(
54
- buildResult.outputFiles,
55
- this.#rootPackageJson,
56
- Object.keys(this.#pkgJson.dependencies ?? {})
57
- ) : {};
44
+ loader: { ".css": "copy", ".md": "copy", ".template": "copy", ".js": "copy" }
45
+ };
46
+ }
47
+ async build(options = {}) {
48
+ if (fs.existsSync(this.#distExecutor.cwdPath))
49
+ await this.#distExecutor.exec(`rm -rf ${this.#distExecutor.cwdPath}`);
50
+ const plugins = [dtsPlugin({ tsconfig: `${this.#executor.cwdPath}/tsconfig.json` })];
51
+ const [buildResult] = await Promise.all([
52
+ esbuild.build({ ...this.#getBuildOptions("cjs", options), write: false, plugins }),
53
+ esbuild.build({ write: true, ...this.#getBuildOptions("esm", options) }),
54
+ esbuild.build({ ...this.#getAssetBuildOptions() })
55
+ ]);
56
+ const existingDeps = Object.keys(this.#pkgJson.dependencies ?? {});
57
+ const dependencies = extractDependencies(buildResult.outputFiles, this.#rootPackageJson, existingDeps);
58
58
  const pkgPackageJson = {
59
59
  ...this.#pkgJson,
60
60
  main: "./index.js",
@@ -68,8 +68,7 @@ class Builder {
68
68
  ...this.#pkgJson.exports ?? {}
69
69
  }
70
70
  };
71
- if (buildResult.outputFiles)
72
- buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
71
+ buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
73
72
  this.#distExecutor.writeJson("package.json", pkgPackageJson);
74
73
  }
75
74
  }
@@ -30,14 +30,14 @@ __export(command_exports, {
30
30
  runCommands: () => runCommands
31
31
  });
32
32
  module.exports = __toCommonJS(command_exports);
33
+ var import_common = require("@akanjs/common");
33
34
  var import_prompts = require("@inquirer/prompts");
35
+ var import_chalk = __toESM(require("chalk"));
34
36
  var import_commander = require("commander");
35
37
  var import_fs = __toESM(require("fs"));
36
- var import_chalk = __toESM(require("chalk"));
37
38
  var import_executors = require("../executors");
38
39
  var import_argMeta = require("./argMeta");
39
40
  var import_targetMeta = require("./targetMeta");
40
- var import_common = require("@akanjs/common");
41
41
  const camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
42
42
  const handleOption = (programCommand, argMeta) => {
43
43
  const {
@@ -1,11 +1,11 @@
1
+ import { Logger } from "@akanjs/common";
1
2
  import { confirm, input, select } from "@inquirer/prompts";
3
+ import chalk from "chalk";
2
4
  import { program } from "commander";
3
5
  import fs from "fs";
4
- import chalk from "chalk";
5
6
  import { AppExecutor, LibExecutor, PkgExecutor, WorkspaceExecutor } from "../executors";
6
7
  import { getArgMetas } from "./argMeta";
7
8
  import { getTargetMetas } from "./targetMeta";
8
- import { Logger } from "@akanjs/common";
9
9
  const camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
10
10
  const handleOption = (programCommand, argMeta) => {
11
11
  const {
@@ -52,7 +52,7 @@ export declare class WorkspaceExecutor extends Executor {
52
52
  getBaseDevEnv(): {
53
53
  repoName: string;
54
54
  serveDomain: string;
55
- env: "debug" | "testing" | "local" | "develop" | "main";
55
+ env: "testing" | "local" | "debug" | "develop" | "main";
56
56
  name?: string | undefined;
57
57
  };
58
58
  scan(): Promise<WorkspaceScanResult>;
package/src/executors.js CHANGED
@@ -37,12 +37,12 @@ __export(executors_exports, {
37
37
  module.exports = __toCommonJS(executors_exports);
38
38
  var import_common = require("@akanjs/common");
39
39
  var import_config = require("@akanjs/config");
40
+ var import_chalk = __toESM(require("chalk"));
40
41
  var import_child_process = require("child_process");
41
42
  var import_dotenv = __toESM(require("dotenv"));
42
43
  var import_fs = __toESM(require("fs"));
43
44
  var import_promises = __toESM(require("fs/promises"));
44
45
  var import_path = __toESM(require("path"));
45
- var import_chalk = __toESM(require("chalk"));
46
46
  var import_dependencyScanner = require("./dependencyScanner");
47
47
  class Executor {
48
48
  logger;
@@ -72,8 +72,11 @@ class Executor {
72
72
  }
73
73
  spawn(command, args = [], options = {}) {
74
74
  const proc = (0, import_child_process.spawn)(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
75
+ proc.stdout?.on("data", (data) => {
76
+ import_common.Logger.raw(import_chalk.default.dim(data.toString()));
77
+ });
75
78
  proc.stderr?.on("data", (data) => {
76
- import_common.Logger.raw(import_chalk.default.red(data.toString()));
79
+ import_common.Logger.raw(import_chalk.default.dim(data.toString()));
77
80
  });
78
81
  return new Promise((resolve, reject) => {
79
82
  proc.on("exit", (code, signal) => {
@@ -188,7 +191,7 @@ class Executor {
188
191
  overwrite = true
189
192
  }, dict = {}) {
190
193
  if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
191
- const getContent = await import(templatePath);
194
+ const getContent = require(templatePath);
192
195
  const result = getContent.default(scanResult ?? null, dict);
193
196
  if (result === null)
194
197
  return;
package/src/executors.mjs CHANGED
@@ -4,12 +4,12 @@ import {
4
4
  getDefaultFileScan,
5
5
  getLibConfig
6
6
  } from "@akanjs/config";
7
+ import chalk from "chalk";
7
8
  import { exec, fork, spawn } from "child_process";
8
9
  import dotenv from "dotenv";
9
10
  import fs from "fs";
10
11
  import fsPromise from "fs/promises";
11
12
  import path from "path";
12
- import chalk from "chalk";
13
13
  import { TypeScriptDependencyScanner } from "./dependencyScanner";
14
14
  class Executor {
15
15
  logger;
@@ -39,8 +39,11 @@ class Executor {
39
39
  }
40
40
  spawn(command, args = [], options = {}) {
41
41
  const proc = spawn(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
42
+ proc.stdout?.on("data", (data) => {
43
+ Logger.raw(chalk.dim(data.toString()));
44
+ });
42
45
  proc.stderr?.on("data", (data) => {
43
- Logger.raw(chalk.red(data.toString()));
46
+ Logger.raw(chalk.dim(data.toString()));
44
47
  });
45
48
  return new Promise((resolve, reject) => {
46
49
  proc.on("exit", (code, signal) => {
@@ -155,7 +158,7 @@ class Executor {
155
158
  overwrite = true
156
159
  }, dict = {}) {
157
160
  if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
158
- const getContent = await import(templatePath);
161
+ const getContent = require(templatePath);
159
162
  const result = getContent.default(scanResult ?? null, dict);
160
163
  if (result === null)
161
164
  return;
package/src/index.d.ts CHANGED
@@ -14,3 +14,4 @@ export * from "./capacitorApp";
14
14
  export * from "./extractDeps";
15
15
  export * from "./commandDecorators";
16
16
  export * from "./aiEditor";
17
+ export * from "./builder";
package/src/index.js CHANGED
@@ -30,6 +30,7 @@ __reExport(src_exports, require("./capacitorApp"), module.exports);
30
30
  __reExport(src_exports, require("./extractDeps"), module.exports);
31
31
  __reExport(src_exports, require("./commandDecorators"), module.exports);
32
32
  __reExport(src_exports, require("./aiEditor"), module.exports);
33
+ __reExport(src_exports, require("./builder"), module.exports);
33
34
  // Annotate the CommonJS export names for ESM import in node:
34
35
  0 && (module.exports = {
35
36
  ...require("./createTunnel"),
@@ -47,5 +48,6 @@ __reExport(src_exports, require("./aiEditor"), module.exports);
47
48
  ...require("./capacitorApp"),
48
49
  ...require("./extractDeps"),
49
50
  ...require("./commandDecorators"),
50
- ...require("./aiEditor")
51
+ ...require("./aiEditor"),
52
+ ...require("./builder")
51
53
  });
package/src/index.mjs CHANGED
@@ -14,3 +14,4 @@ export * from "./capacitorApp";
14
14
  export * from "./extractDeps";
15
15
  export * from "./commandDecorators";
16
16
  export * from "./aiEditor";
17
+ export * from "./builder";
package/src/types.d.ts CHANGED
@@ -10,6 +10,9 @@ export interface PackageJson {
10
10
  peerDependencies?: Record<string, string>;
11
11
  engines?: Record<string, string>;
12
12
  exports?: Record<string, Record<string, string>>;
13
+ esbuild?: {
14
+ platform?: "node" | "browser" | "neutral";
15
+ };
13
16
  }
14
17
  export interface TsConfigJson {
15
18
  extends?: string;