@akanjs/devkit 0.0.91 → 0.0.92

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "0.0.91",
3
+ "version": "0.0.92",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,6 +23,8 @@
23
23
  "chalk": "^5.4.1",
24
24
  "commander": "^13.1.0",
25
25
  "dotenv": "^16.4.7",
26
+ "esbuild": "^0.19.2",
27
+ "esbuild-plugin-d.ts": "^1.3.1",
26
28
  "form-data": "^4.0.1",
27
29
  "js-yaml": "^4.1.0",
28
30
  "ora": "^3.4.0",
@@ -0,0 +1,16 @@
1
+ import { PackageJson } from "./types";
2
+ import { Executor } from "./executors";
3
+ interface BuilderOptions {
4
+ name: string;
5
+ executor: Executor;
6
+ distExecutor: Executor;
7
+ pkgJson: PackageJson;
8
+ rootPackageJson: PackageJson;
9
+ }
10
+ export declare class Builder {
11
+ #private;
12
+ name: string;
13
+ constructor({ name, executor, distExecutor, pkgJson, rootPackageJson }: BuilderOptions);
14
+ build(): Promise<void>;
15
+ }
16
+ export {};
package/src/builder.js ADDED
@@ -0,0 +1,111 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var builder_exports = {};
29
+ __export(builder_exports, {
30
+ Builder: () => Builder
31
+ });
32
+ module.exports = __toCommonJS(builder_exports);
33
+ var esbuild = __toESM(require("esbuild"));
34
+ var import_esbuild_plugin_d = require("esbuild-plugin-d.ts");
35
+ var import_extractDeps = require("./extractDeps");
36
+ class Builder {
37
+ name;
38
+ #executor;
39
+ #distExecutor;
40
+ #pkgJson;
41
+ #rootPackageJson;
42
+ constructor({ name, executor, distExecutor, pkgJson, rootPackageJson }) {
43
+ this.name = name;
44
+ this.#executor = executor;
45
+ this.#distExecutor = distExecutor;
46
+ this.#pkgJson = pkgJson;
47
+ this.#rootPackageJson = rootPackageJson;
48
+ }
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,
63
+ packages: "external",
64
+ splitting: false,
65
+ platform,
66
+ format: "cjs",
67
+ 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({
73
+ write: true,
74
+ entryPoints: [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
75
+ bundle: false,
76
+ packages: "external",
77
+ splitting: false,
78
+ platform,
79
+ format: "esm",
80
+ outdir: this.#distExecutor.cwdPath,
81
+ outExtension: { ".js": this.#pkgJson.type === "module" ? ".js" : ".mjs" },
82
+ 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
+ ) : {};
90
+ const pkgPackageJson = {
91
+ ...this.#pkgJson,
92
+ main: "./index.js",
93
+ engines: { node: ">=22" },
94
+ dependencies,
95
+ exports: {
96
+ ".": {
97
+ require: this.#pkgJson.type === "module" ? "./index.cjs" : "./index.js",
98
+ import: this.#pkgJson.type === "module" ? "./index.js" : "./index.mjs"
99
+ },
100
+ ...this.#pkgJson.exports ?? {}
101
+ }
102
+ };
103
+ if (buildResult.outputFiles)
104
+ buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
105
+ this.#distExecutor.writeJson("package.json", pkgPackageJson);
106
+ }
107
+ }
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ Builder
111
+ });
@@ -0,0 +1,78 @@
1
+ import * as esbuild from "esbuild";
2
+ import { dtsPlugin } from "esbuild-plugin-d.ts";
3
+ import { extractDependencies } from "./extractDeps";
4
+ class Builder {
5
+ name;
6
+ #executor;
7
+ #distExecutor;
8
+ #pkgJson;
9
+ #rootPackageJson;
10
+ constructor({ name, executor, distExecutor, pkgJson, rootPackageJson }) {
11
+ this.name = name;
12
+ this.#executor = executor;
13
+ this.#distExecutor = distExecutor;
14
+ this.#pkgJson = pkgJson;
15
+ this.#rootPackageJson = rootPackageJson;
16
+ }
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,
31
+ packages: "external",
32
+ splitting: false,
33
+ platform,
34
+ format: "cjs",
35
+ 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({
41
+ write: true,
42
+ entryPoints: [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
43
+ bundle: false,
44
+ packages: "external",
45
+ splitting: false,
46
+ platform,
47
+ format: "esm",
48
+ outdir: this.#distExecutor.cwdPath,
49
+ outExtension: { ".js": this.#pkgJson.type === "module" ? ".js" : ".mjs" },
50
+ logLevel: "error",
51
+ plugins: []
52
+ });
53
+ const dependencies = buildResult.outputFiles ? extractDependencies(
54
+ buildResult.outputFiles,
55
+ this.#rootPackageJson,
56
+ Object.keys(this.#pkgJson.dependencies ?? {})
57
+ ) : {};
58
+ const pkgPackageJson = {
59
+ ...this.#pkgJson,
60
+ main: "./index.js",
61
+ engines: { node: ">=22" },
62
+ dependencies,
63
+ exports: {
64
+ ".": {
65
+ require: this.#pkgJson.type === "module" ? "./index.cjs" : "./index.js",
66
+ import: this.#pkgJson.type === "module" ? "./index.js" : "./index.mjs"
67
+ },
68
+ ...this.#pkgJson.exports ?? {}
69
+ }
70
+ };
71
+ if (buildResult.outputFiles)
72
+ buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
73
+ this.#distExecutor.writeJson("package.json", pkgPackageJson);
74
+ }
75
+ }
76
+ export {
77
+ Builder
78
+ };
@@ -33,9 +33,11 @@ module.exports = __toCommonJS(command_exports);
33
33
  var import_prompts = require("@inquirer/prompts");
34
34
  var import_commander = require("commander");
35
35
  var import_fs = __toESM(require("fs"));
36
+ var import_chalk = __toESM(require("chalk"));
36
37
  var import_executors = require("../executors");
37
38
  var import_argMeta = require("./argMeta");
38
39
  var import_targetMeta = require("./targetMeta");
40
+ var import_common = require("@akanjs/common");
39
41
  const camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
40
42
  const handleOption = (programCommand, argMeta) => {
41
43
  const {
@@ -48,7 +50,7 @@ const handleOption = (programCommand, argMeta) => {
48
50
  } = argMeta.argsOption;
49
51
  const kebabName = camelToKebabCase(argMeta.name);
50
52
  programCommand.option(
51
- `-${flag}, --${kebabName} <${kebabName}>`,
53
+ `-${flag}, --${kebabName}${type === "boolean" ? " [boolean]" : ` <${kebabName}>`}`,
52
54
  `${desc}${ask ? ` (${ask})` : ""}${example ? ` (example: ${example})` : ""}${choices ? ` (choices: ${choices.join(", ")})` : ""}`
53
55
  );
54
56
  return programCommand;
@@ -59,7 +61,7 @@ const convertOptionValue = (value, type) => {
59
61
  else if (type === "number")
60
62
  return Number(value);
61
63
  else
62
- return value === "true";
64
+ return value === true || value === "true";
63
65
  };
64
66
  const getOptionValue = async (argMeta, opt) => {
65
67
  const {
@@ -74,15 +76,15 @@ const getOptionValue = async (argMeta, opt) => {
74
76
  return null;
75
77
  if (choices) {
76
78
  const choice = await (0, import_prompts.select)({
77
- message: ask ?? `Select the ${name} value`,
79
+ message: ask ?? desc ?? `Select the ${name} value`,
78
80
  choices: choices.map((choice2) => choice2.toString())
79
81
  });
80
82
  return choice;
81
83
  } else if (type === "boolean") {
82
- const message = ask ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
84
+ const message = ask ?? desc ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
83
85
  return await (0, import_prompts.confirm)({ message });
84
86
  } else {
85
- const message = ask ? `${ask}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
87
+ const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
86
88
  if (argMeta.argsOption.nullable)
87
89
  return await (0, import_prompts.input)({ message });
88
90
  else
@@ -170,7 +172,12 @@ const runCommands = async (...commands) => {
170
172
  commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace);
171
173
  }
172
174
  const cmd = new command();
173
- await cmd[targetMeta.key](...commandArgs);
175
+ try {
176
+ await cmd[targetMeta.key](...commandArgs);
177
+ } catch (e) {
178
+ const errMsg = e instanceof Error ? e.message : typeof e === "string" ? e : JSON.stringify(e);
179
+ import_common.Logger.error(`Command Error: ${import_chalk.default.red(errMsg)}`);
180
+ }
174
181
  });
175
182
  }
176
183
  }
@@ -1,9 +1,11 @@
1
1
  import { confirm, input, select } from "@inquirer/prompts";
2
2
  import { program } from "commander";
3
3
  import fs from "fs";
4
+ import chalk from "chalk";
4
5
  import { AppExecutor, LibExecutor, PkgExecutor, WorkspaceExecutor } from "../executors";
5
6
  import { getArgMetas } from "./argMeta";
6
7
  import { getTargetMetas } from "./targetMeta";
8
+ import { Logger } from "@akanjs/common";
7
9
  const camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
8
10
  const handleOption = (programCommand, argMeta) => {
9
11
  const {
@@ -16,7 +18,7 @@ const handleOption = (programCommand, argMeta) => {
16
18
  } = argMeta.argsOption;
17
19
  const kebabName = camelToKebabCase(argMeta.name);
18
20
  programCommand.option(
19
- `-${flag}, --${kebabName} <${kebabName}>`,
21
+ `-${flag}, --${kebabName}${type === "boolean" ? " [boolean]" : ` <${kebabName}>`}`,
20
22
  `${desc}${ask ? ` (${ask})` : ""}${example ? ` (example: ${example})` : ""}${choices ? ` (choices: ${choices.join(", ")})` : ""}`
21
23
  );
22
24
  return programCommand;
@@ -27,7 +29,7 @@ const convertOptionValue = (value, type) => {
27
29
  else if (type === "number")
28
30
  return Number(value);
29
31
  else
30
- return value === "true";
32
+ return value === true || value === "true";
31
33
  };
32
34
  const getOptionValue = async (argMeta, opt) => {
33
35
  const {
@@ -42,15 +44,15 @@ const getOptionValue = async (argMeta, opt) => {
42
44
  return null;
43
45
  if (choices) {
44
46
  const choice = await select({
45
- message: ask ?? `Select the ${name} value`,
47
+ message: ask ?? desc ?? `Select the ${name} value`,
46
48
  choices: choices.map((choice2) => choice2.toString())
47
49
  });
48
50
  return choice;
49
51
  } else if (type === "boolean") {
50
- const message = ask ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
52
+ const message = ask ?? desc ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
51
53
  return await confirm({ message });
52
54
  } else {
53
- const message = ask ? `${ask}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
55
+ const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
54
56
  if (argMeta.argsOption.nullable)
55
57
  return await input({ message });
56
58
  else
@@ -138,7 +140,12 @@ const runCommands = async (...commands) => {
138
140
  commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace);
139
141
  }
140
142
  const cmd = new command();
141
- await cmd[targetMeta.key](...commandArgs);
143
+ try {
144
+ await cmd[targetMeta.key](...commandArgs);
145
+ } catch (e) {
146
+ const errMsg = e instanceof Error ? e.message : typeof e === "string" ? e : JSON.stringify(e);
147
+ Logger.error(`Command Error: ${chalk.red(errMsg)}`);
148
+ }
142
149
  });
143
150
  }
144
151
  }
@@ -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" | "develop" | "main";
55
+ env: "debug" | "testing" | "local" | "develop" | "main";
56
56
  name?: string | undefined;
57
57
  };
58
58
  scan(): Promise<WorkspaceScanResult>;
package/src/executors.js CHANGED
@@ -42,6 +42,7 @@ var import_dotenv = __toESM(require("dotenv"));
42
42
  var import_fs = __toESM(require("fs"));
43
43
  var import_promises = __toESM(require("fs/promises"));
44
44
  var import_path = __toESM(require("path"));
45
+ var import_chalk = __toESM(require("chalk"));
45
46
  var import_dependencyScanner = require("./dependencyScanner");
46
47
  class Executor {
47
48
  logger;
@@ -58,7 +59,7 @@ class Executor {
58
59
  import_common.Logger.raw(data.toString());
59
60
  });
60
61
  proc.stderr?.on("data", (data) => {
61
- import_common.Logger.raw(data.toString());
62
+ import_common.Logger.raw(import_chalk.default.red(data.toString()));
62
63
  });
63
64
  return new Promise((resolve, reject) => {
64
65
  proc.on("exit", (code, signal) => {
@@ -72,7 +73,7 @@ class Executor {
72
73
  spawn(command, args = [], options = {}) {
73
74
  const proc = (0, import_child_process.spawn)(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
74
75
  proc.stderr?.on("data", (data) => {
75
- import_common.Logger.raw(data.toString());
76
+ import_common.Logger.raw(import_chalk.default.red(data.toString()));
76
77
  });
77
78
  return new Promise((resolve, reject) => {
78
79
  proc.on("exit", (code, signal) => {
package/src/executors.mjs CHANGED
@@ -9,6 +9,7 @@ import dotenv from "dotenv";
9
9
  import fs from "fs";
10
10
  import fsPromise from "fs/promises";
11
11
  import path from "path";
12
+ import chalk from "chalk";
12
13
  import { TypeScriptDependencyScanner } from "./dependencyScanner";
13
14
  class Executor {
14
15
  logger;
@@ -25,7 +26,7 @@ class Executor {
25
26
  Logger.raw(data.toString());
26
27
  });
27
28
  proc.stderr?.on("data", (data) => {
28
- Logger.raw(data.toString());
29
+ Logger.raw(chalk.red(data.toString()));
29
30
  });
30
31
  return new Promise((resolve, reject) => {
31
32
  proc.on("exit", (code, signal) => {
@@ -39,7 +40,7 @@ class Executor {
39
40
  spawn(command, args = [], options = {}) {
40
41
  const proc = spawn(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
41
42
  proc.stderr?.on("data", (data) => {
42
- Logger.raw(data.toString());
43
+ Logger.raw(chalk.red(data.toString()));
43
44
  });
44
45
  return new Promise((resolve, reject) => {
45
46
  proc.on("exit", (code, signal) => {
@@ -1,5 +1,6 @@
1
1
  import type { PackageJson } from "./types";
2
2
  export declare const extractDependencies: (filepaths: {
3
+ path: string;
3
4
  text: string;
4
5
  }[], pacakgeJson: PackageJson, defaultDependencies?: string[]) => {
5
6
  [k: string]: string;
@@ -75,7 +75,7 @@ const extractDependencies = (filepaths, pacakgeJson, defaultDependencies = []) =
75
75
  ...pacakgeJson.devDependencies ?? {}
76
76
  };
77
77
  const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
78
- for (const { text } of filepaths) {
78
+ for (const { text } of filepaths.filter(({ path }) => path.endsWith(".js"))) {
79
79
  let requireMatch;
80
80
  while ((requireMatch = requireRegex.exec(text)) !== null) {
81
81
  const moduleName = requireMatch[1];
@@ -53,7 +53,7 @@ const extractDependencies = (filepaths, pacakgeJson, defaultDependencies = []) =
53
53
  ...pacakgeJson.devDependencies ?? {}
54
54
  };
55
55
  const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
56
- for (const { text } of filepaths) {
56
+ for (const { text } of filepaths.filter(({ path }) => path.endsWith(".js"))) {
57
57
  let requireMatch;
58
58
  while ((requireMatch = requireRegex.exec(text)) !== null) {
59
59
  const moduleName = requireMatch[1];