@akanjs/cli 0.9.12 → 0.9.14

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/esm/index.js CHANGED
@@ -380,8 +380,8 @@ import * as fs3 from "fs";
380
380
  import ora2 from "ora";
381
381
  import * as ts from "typescript";
382
382
  var parseTsConfig = (tsConfigPath = "./tsconfig.json") => {
383
- const configFile = ts.readConfigFile(tsConfigPath, (path10) => {
384
- return ts.sys.readFile(path10);
383
+ const configFile = ts.readConfigFile(tsConfigPath, (path9) => {
384
+ return ts.sys.readFile(path9);
385
385
  });
386
386
  return ts.parseJsonConfigFileContent(
387
387
  configFile.config,
@@ -544,13 +544,12 @@ import { ChatOpenAI } from "@langchain/openai";
544
544
 
545
545
  // pkgs/@akanjs/config/src/akanConfig.ts
546
546
  import fs4 from "fs";
547
- import path2 from "path";
547
+ import path from "path";
548
548
 
549
549
  // pkgs/@akanjs/config/src/nextConfig.ts
550
550
  import withAnalyze from "@next/bundle-analyzer";
551
551
  import pwa from "next-pwa";
552
552
  import runtimeCaching from "next-pwa/cache.js";
553
- import path from "path";
554
553
  var composePlugins = (...plugins) => {
555
554
  return function(baseConfig) {
556
555
  return async function combined(phase, context2) {
@@ -570,7 +569,6 @@ var composePlugins = (...plugins) => {
570
569
  var commandType = process.env.AKAN_COMMAND_TYPE?.includes("start") ? "start" : process.env.AKAN_COMMAND_TYPE?.includes("build") ? "build" : "deploy";
571
570
  var devDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "akanjs.com";
572
571
  var withBase = (appName, config, libs, routes = []) => {
573
- const __dirname = path.dirname(new URL(import.meta.url).pathname);
574
572
  const withPWA = pwa({
575
573
  dest: "public",
576
574
  register: true,
@@ -641,15 +639,13 @@ var withBase = (appName, config, libs, routes = []) => {
641
639
  webpack: (config2) => {
642
640
  config2.resolve.alias.canvas = false;
643
641
  config2.resolve.alias.encoding = false;
644
- if (process.env.USE_AKANJS_PKGS === "true")
645
- config2.resolve.alias["@akanjs/config"] = path.resolve(__dirname, "../../../../pkgs/@akanjs/config");
646
642
  return config2;
647
643
  },
648
644
  turbopack: {
649
645
  resolveAlias: {
650
646
  // canvas: false,
651
647
  // encoding: false,
652
- ...process.env.USE_AKANJS_PKGS === "true" ? { "@akanjs/config": path.resolve(__dirname, "../../../../pkgs/@akanjs/config") } : {},
648
+ // ...(process.env.USE_AKANJS_PKGS === "true" ? { "@akanjs/config": "../../pkgs/@akanjs/config" } : {}),
653
649
  ...config.turbopack?.resolveAlias ?? {}
654
650
  }
655
651
  },
@@ -708,43 +704,11 @@ var makeAppConfig = (config, props) => {
708
704
  rootLib: config.rootLib,
709
705
  libs: config.libs ?? [],
710
706
  backend: {
711
- dockerfile: config.backend?.dockerfile ?? `FROM node:22-slim
712
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
713
- RUN apt-get update && apt-get upgrade -y && apt-get install -y git redis build-essential python3 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils udev ffmpeg && rm -rf /var/lib/apt/lists/*
714
- ARG TARGETARCH
715
- RUN if [ "$TARGETARCH" = "amd64" ]; then wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && apt-get install -y ./mongodb-database-tools-*.deb && rm -f mongodb-database-tools-*.deb; fi
716
- RUN mkdir -p /workspace
717
- WORKDIR /workspace
718
- COPY ./package.json ./package.json
719
- RUN npx pnpm i --prod
720
- COPY . .
721
- ENV PORT 8080
722
- ENV NODE_OPTIONS=--max_old_space_size=8192
723
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
724
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
725
- ENV NEXT_PUBLIC_APP_NAME=${name}
726
- ENV NEXT_PUBLIC_ENV=${env}
727
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
728
- CMD ["node", "main.js"]`,
707
+ docker: makeDockerfile("backend", config.backend?.docker ?? {}, props),
729
708
  explicitDependencies: config.backend?.explicitDependencies ?? []
730
709
  },
731
710
  frontend: {
732
- dockerfile: config.frontend?.dockerfile ?? `FROM node:22-alpine
733
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
734
- RUN apk --no-cache add git
735
- RUN mkdir -p /workspace
736
- WORKDIR /workspace
737
- COPY ./package.json ./package.json
738
- RUN npx pnpm i --prod
739
- COPY . .
740
- ENV PORT 4200
741
- ENV NODE_OPTIONS=--max_old_space_size=8192
742
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
743
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
744
- ENV NEXT_PUBLIC_APP_NAME=${name}
745
- ENV NEXT_PUBLIC_ENV=${env}
746
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
747
- CMD ["npm", "start"]`,
711
+ docker: makeDockerfile("frontend", config.frontend?.docker ?? {}, props),
748
712
  nextConfig: withBase(
749
713
  name,
750
714
  config.frontend?.nextConfig ? typeof config.frontend.nextConfig === "function" ? config.frontend.nextConfig() : config.frontend.nextConfig : {},
@@ -763,7 +727,7 @@ CMD ["npm", "start"]`,
763
727
  };
764
728
  };
765
729
  var getAppConfig = async (appRoot, props) => {
766
- const akanConfigPath = path2.join(appRoot, "akan.config.ts");
730
+ const akanConfigPath = path.join(appRoot, "akan.config.ts");
767
731
  if (!fs4.existsSync(akanConfigPath))
768
732
  throw new Error(`application akan.config.ts is not found ${appRoot}`);
769
733
  const configImp = (await import(`${appRoot}/akan.config.ts`)).default;
@@ -783,13 +747,95 @@ var makeLibConfig = (config, props) => {
783
747
  };
784
748
  };
785
749
  var getLibConfig = async (libRoot, props) => {
786
- const akanConfigPath = path2.join(libRoot, "akan.config.ts");
750
+ const akanConfigPath = path.join(libRoot, "akan.config.ts");
787
751
  if (!fs4.existsSync(akanConfigPath))
788
752
  throw new Error(`library akan.config.ts is not found ${libRoot}`);
789
753
  const configImp = (await import(`${libRoot}/akan.config.ts`)).default;
790
754
  const config = typeof configImp === "function" ? configImp(props) : configImp;
791
755
  return makeLibConfig(config, props);
792
756
  };
757
+ var getDockerRunScripts = (runs) => {
758
+ return runs.map((run) => {
759
+ if (typeof run === "string")
760
+ return `RUN ${run}`;
761
+ else
762
+ return Object.entries(run).map(([arch, script]) => `RUN if [ "$TARGETARCH" = "${arch}" ]; then ${script}; fi`).join("\n");
763
+ });
764
+ };
765
+ var getDockerImageScript = (image) => {
766
+ if (typeof image === "string")
767
+ return `FROM ${image}`;
768
+ else
769
+ return Object.entries(image).map(([arch, image2]) => `FROM ${image2} AS ${arch}`).join("\n");
770
+ };
771
+ var makeDockerfile = (type, config, props) => {
772
+ const { name, repoName, serveDomain, env } = props;
773
+ if (config.content)
774
+ return { content: config.content, image: {}, preRuns: [], postRuns: [], command: [] };
775
+ const preRunScripts = getDockerRunScripts(config.preRuns ?? []);
776
+ const postRunScripts = getDockerRunScripts(config.postRuns ?? []);
777
+ if (type === "backend") {
778
+ const imageScript = config.image ? getDockerImageScript(config.image) : "FROM node:22-slim";
779
+ const command = config.command ?? ["node", "main.js"];
780
+ const content = `${imageScript}
781
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
782
+ RUN apt-get update && apt-get upgrade -y
783
+ RUN apt-get install -y git redis build-essential python3 ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils udev ffmpeg && rm -rf /var/lib/apt/lists/*
784
+ ARG TARGETARCH
785
+ RUN if [ "$TARGETARCH" = "amd64" ]; then wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && apt-get install -y ./mongodb-database-tools-*.deb && rm -f mongodb-database-tools-*.deb; fi
786
+ ${preRunScripts.join("\n")}
787
+ RUN mkdir -p /workspace
788
+ WORKDIR /workspace
789
+ COPY ./package.json ./package.json
790
+ RUN npx pnpm i --prod
791
+ COPY . .
792
+ ENV PORT 8080
793
+ ENV NODE_OPTIONS=--max_old_space_size=8192
794
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
795
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
796
+ ENV NEXT_PUBLIC_APP_NAME=${name}
797
+ ENV NEXT_PUBLIC_ENV=${env}
798
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
799
+ ${postRunScripts.join("\n")}
800
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
801
+ return {
802
+ content,
803
+ image: imageScript,
804
+ preRuns: config.preRuns ?? [],
805
+ postRuns: config.postRuns ?? [],
806
+ command
807
+ };
808
+ } else {
809
+ const imageScript = config.image ? getDockerImageScript(config.image) : "FROM node:22-alpine";
810
+ const command = config.command ?? ["npm", "start"];
811
+ const content = `${imageScript}
812
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
813
+ ARG TARGETARCH
814
+ RUN apk --no-cache add git
815
+ ${preRunScripts.join("\n")}
816
+ RUN mkdir -p /workspace
817
+ WORKDIR /workspace
818
+ COPY ./package.json ./package.json
819
+ RUN npx pnpm i --prod
820
+ COPY . .
821
+ ENV PORT 4200
822
+ ENV NODE_OPTIONS=--max_old_space_size=8192
823
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
824
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
825
+ ENV NEXT_PUBLIC_APP_NAME=${name}
826
+ ENV NEXT_PUBLIC_ENV=${env}
827
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
828
+ ${postRunScripts.join("\n")}
829
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
830
+ return {
831
+ content,
832
+ image: imageScript,
833
+ preRuns: config.preRuns ?? [],
834
+ postRuns: config.postRuns ?? [],
835
+ command
836
+ };
837
+ }
838
+ };
793
839
 
794
840
  // pkgs/@akanjs/config/src/types.ts
795
841
  var getDefaultFileScan = () => ({
@@ -834,11 +880,11 @@ import { exec, fork, spawn } from "child_process";
834
880
  import dotenv from "dotenv";
835
881
  import fs8 from "fs";
836
882
  import fsPromise from "fs/promises";
837
- import path7 from "path";
883
+ import path6 from "path";
838
884
 
839
885
  // pkgs/@akanjs/devkit/src/dependencyScanner.ts
840
886
  import * as fs5 from "fs";
841
- import * as path3 from "path";
887
+ import * as path2 from "path";
842
888
  import * as ts2 from "typescript";
843
889
  var TypeScriptDependencyScanner = class {
844
890
  constructor(directory) {
@@ -884,7 +930,7 @@ var TypeScriptDependencyScanner = class {
884
930
  const processDirectory = async (dir) => {
885
931
  const entries = await fs5.promises.readdir(dir, { withFileTypes: true });
886
932
  for (const entry of entries) {
887
- const fullPath = path3.join(dir, entry.name);
933
+ const fullPath = path2.join(dir, entry.name);
888
934
  if (entry.isDirectory()) {
889
935
  if (!["node_modules", "dist", "build", ".git", ".next", "public", "ios", "android"].includes(entry.name))
890
936
  await processDirectory(fullPath);
@@ -904,12 +950,12 @@ var TypeScriptDependencyScanner = class {
904
950
  const imports = this.#extractImports(fileContent, filePath);
905
951
  const resolvedImports = imports.map((importPath) => {
906
952
  if (importPath.startsWith(".")) {
907
- const resolvedPath = "./" + path3.join(path3.relative(baseDir, filePath), importPath);
953
+ const resolvedPath = "./" + path2.join(path2.relative(baseDir, filePath), importPath);
908
954
  return this.#ensureExtension(resolvedPath);
909
955
  }
910
956
  return importPath;
911
957
  });
912
- const relativePath = path3.relative(baseDir, filePath);
958
+ const relativePath = path2.relative(baseDir, filePath);
913
959
  this.#fileDependencies.set(relativePath, resolvedImports);
914
960
  } catch (error) {
915
961
  }
@@ -984,14 +1030,14 @@ var TypeScriptDependencyScanner = class {
984
1030
  };
985
1031
 
986
1032
  // pkgs/@akanjs/devkit/src/getDirname.ts
987
- import path4 from "path";
988
- var getDirname = (url) => path4.dirname(new URL(url).pathname);
1033
+ import path3 from "path";
1034
+ var getDirname = (url) => path3.dirname(new URL(url).pathname);
989
1035
 
990
1036
  // pkgs/@akanjs/devkit/src/linter.ts
991
1037
  import chalk from "chalk";
992
1038
  import { ESLint } from "eslint";
993
1039
  import * as fs6 from "fs";
994
- import * as path5 from "path";
1040
+ import * as path4 from "path";
995
1041
  var Linter = class {
996
1042
  #logger = new Logger("Linter");
997
1043
  #eslint;
@@ -1001,10 +1047,10 @@ var Linter = class {
1001
1047
  this.#eslint = new ESLint({ cwd: this.lintRoot, errorOnUnmatchedPattern: false });
1002
1048
  }
1003
1049
  #findEslintRootPath(dir) {
1004
- const configPath2 = path5.join(dir, "eslint.config.ts");
1050
+ const configPath2 = path4.join(dir, "eslint.config.ts");
1005
1051
  if (fs6.existsSync(configPath2))
1006
1052
  return dir;
1007
- const parentDir = path5.dirname(dir);
1053
+ const parentDir = path4.dirname(dir);
1008
1054
  return this.#findEslintRootPath(parentDir);
1009
1055
  }
1010
1056
  async lint(filePath, { fix = false, dryRun = false } = {}) {
@@ -1193,7 +1239,7 @@ ${errorText}, ${warningText} found`];
1193
1239
  // pkgs/@akanjs/devkit/src/typeChecker.ts
1194
1240
  import chalk2 from "chalk";
1195
1241
  import * as fs7 from "fs";
1196
- import * as path6 from "path";
1242
+ import * as path5 from "path";
1197
1243
  import * as ts3 from "typescript";
1198
1244
  var TypeChecker = class {
1199
1245
  configPath;
@@ -1208,7 +1254,7 @@ var TypeChecker = class {
1208
1254
  const parsedConfig = ts3.parseJsonConfigFileContent(
1209
1255
  this.configFile.config,
1210
1256
  ts3.sys,
1211
- path6.dirname(this.configPath),
1257
+ path5.dirname(this.configPath),
1212
1258
  void 0,
1213
1259
  this.configPath
1214
1260
  );
@@ -1474,7 +1520,7 @@ var Executor = class _Executor {
1474
1520
  });
1475
1521
  }
1476
1522
  getPath(filePath) {
1477
- if (path7.isAbsolute(filePath))
1523
+ if (path6.isAbsolute(filePath))
1478
1524
  return filePath;
1479
1525
  const baseParts = this.cwdPath.split("/").filter(Boolean);
1480
1526
  const targetParts = filePath.split("/").filter(Boolean);
@@ -1527,7 +1573,7 @@ var Executor = class _Executor {
1527
1573
  }
1528
1574
  writeFile(filePath, content, { overwrite = true } = {}) {
1529
1575
  const writePath = this.getPath(filePath);
1530
- const dir = path7.dirname(writePath);
1576
+ const dir = path6.dirname(writePath);
1531
1577
  if (!fs8.existsSync(dir))
1532
1578
  fs8.mkdirSync(dir, { recursive: true });
1533
1579
  let contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
@@ -1551,7 +1597,7 @@ var Executor = class _Executor {
1551
1597
  return this;
1552
1598
  }
1553
1599
  getLocalFile(targetPath) {
1554
- const filePath = path7.isAbsolute(targetPath) ? targetPath : targetPath.replace(this.cwdPath, "");
1600
+ const filePath = path6.isAbsolute(targetPath) ? targetPath : targetPath.replace(this.cwdPath, "");
1555
1601
  const content = this.readFile(filePath);
1556
1602
  return { filePath, content };
1557
1603
  }
@@ -1602,11 +1648,11 @@ var Executor = class _Executor {
1602
1648
  const result = getContent.default(scanResult ?? null, dict);
1603
1649
  if (result === null)
1604
1650
  return null;
1605
- const filename = typeof result === "object" ? result.filename : path7.basename(targetPath).replace(".js", ".ts");
1651
+ const filename = typeof result === "object" ? result.filename : path6.basename(targetPath).replace(".js", ".ts");
1606
1652
  const content = typeof result === "object" ? result.content : result;
1607
- const dirname3 = path7.dirname(targetPath);
1653
+ const dirname3 = path6.dirname(targetPath);
1608
1654
  const convertedTargetPath = Object.entries(dict).reduce(
1609
- (path10, [key, value]) => path10.replace(new RegExp(`__${key}__`, "g"), value),
1655
+ (path9, [key, value]) => path9.replace(new RegExp(`__${key}__`, "g"), value),
1610
1656
  `${dirname3}/${filename}`
1611
1657
  );
1612
1658
  this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
@@ -1614,7 +1660,7 @@ var Executor = class _Executor {
1614
1660
  } else if (targetPath.endsWith(".template")) {
1615
1661
  const content = await fsPromise.readFile(templatePath, "utf8");
1616
1662
  const convertedTargetPath = Object.entries(dict).reduce(
1617
- (path10, [key, value]) => path10.replace(new RegExp(`__${key}__`, "g"), value),
1663
+ (path9, [key, value]) => path9.replace(new RegExp(`__${key}__`, "g"), value),
1618
1664
  targetPath.slice(0, -9)
1619
1665
  );
1620
1666
  const convertedContent = Object.entries(dict).reduce(
@@ -1636,9 +1682,9 @@ var Executor = class _Executor {
1636
1682
  const templatePath = `${getDirname(import.meta.url)}/src/templates${template ? `/${template}` : ""}`;
1637
1683
  const prefixTemplatePath = templatePath.endsWith(".tsx") ? templatePath : templatePath.replace(".ts", ".js");
1638
1684
  if (fs8.statSync(prefixTemplatePath).isFile()) {
1639
- const filename = path7.basename(prefixTemplatePath);
1685
+ const filename = path6.basename(prefixTemplatePath);
1640
1686
  const fileContent = await this.#applyTemplateFile(
1641
- { templatePath: prefixTemplatePath, targetPath: path7.join(basePath2, filename), scanResult, overwrite },
1687
+ { templatePath: prefixTemplatePath, targetPath: path6.join(basePath2, filename), scanResult, overwrite },
1642
1688
  dict
1643
1689
  );
1644
1690
  return fileContent ? [fileContent] : [];
@@ -1646,17 +1692,17 @@ var Executor = class _Executor {
1646
1692
  const subdirs = await this.readdir(templatePath);
1647
1693
  const fileContents = (await Promise.all(
1648
1694
  subdirs.map(async (subdir) => {
1649
- const subpath = path7.join(templatePath, subdir);
1695
+ const subpath = path6.join(templatePath, subdir);
1650
1696
  if (fs8.statSync(subpath).isFile()) {
1651
1697
  const fileContent = await this.#applyTemplateFile(
1652
- { templatePath: subpath, targetPath: path7.join(basePath2, subdir), scanResult, overwrite },
1698
+ { templatePath: subpath, targetPath: path6.join(basePath2, subdir), scanResult, overwrite },
1653
1699
  dict
1654
1700
  );
1655
1701
  return fileContent ? [fileContent] : [];
1656
1702
  } else
1657
1703
  return await this._applyTemplate({
1658
- basePath: path7.join(basePath2, subdir),
1659
- template: path7.join(template, subdir),
1704
+ basePath: path6.join(basePath2, subdir),
1705
+ template: path6.join(template, subdir),
1660
1706
  scanResult,
1661
1707
  dict,
1662
1708
  overwrite
@@ -1680,9 +1726,9 @@ var Executor = class _Executor {
1680
1726
  return this.typeChecker;
1681
1727
  }
1682
1728
  typeCheck(filePath) {
1683
- const path10 = this.getPath(filePath);
1729
+ const path9 = this.getPath(filePath);
1684
1730
  const typeChecker = this.getTypeChecker();
1685
- const { fileDiagnostics, fileErrors, fileWarnings } = typeChecker.check(path10);
1731
+ const { fileDiagnostics, fileErrors, fileWarnings } = typeChecker.check(path9);
1686
1732
  const message = typeChecker.formatDiagnostics(fileDiagnostics);
1687
1733
  return { fileDiagnostics, fileErrors, fileWarnings, message };
1688
1734
  }
@@ -1691,9 +1737,9 @@ var Executor = class _Executor {
1691
1737
  return this.linter;
1692
1738
  }
1693
1739
  async lint(filePath, { fix = false, dryRun = false } = {}) {
1694
- const path10 = this.getPath(filePath);
1740
+ const path9 = this.getPath(filePath);
1695
1741
  const linter = this.getLinter();
1696
- const { results, errors, warnings } = await linter.lint(path10, { fix, dryRun });
1742
+ const { results, errors, warnings } = await linter.lint(path9, { fix, dryRun });
1697
1743
  const message = linter.formatLintResults(results);
1698
1744
  return { results, message, errors, warnings };
1699
1745
  }
@@ -1708,7 +1754,7 @@ var WorkspaceExecutor = class _WorkspaceExecutor extends Executor {
1708
1754
  this.repoName = repoName;
1709
1755
  }
1710
1756
  static fromRoot() {
1711
- const repoName = path7.basename(process.cwd());
1757
+ const repoName = path6.basename(process.cwd());
1712
1758
  return new _WorkspaceExecutor({ workspaceRoot: process.cwd(), repoName });
1713
1759
  }
1714
1760
  getBaseDevEnv() {
@@ -1817,7 +1863,7 @@ var WorkspaceExecutor = class _WorkspaceExecutor extends Executor {
1817
1863
  dirs.map(async (dir) => {
1818
1864
  if (dir.includes("_") || AVOID_DIRS.includes(dir))
1819
1865
  return;
1820
- const dirPath = path7.join(dirname3, dir);
1866
+ const dirPath = path6.join(dirname3, dir);
1821
1867
  if (fs8.lstatSync(dirPath).isDirectory()) {
1822
1868
  results.push(`${prefix}${dir}`);
1823
1869
  if (maxDepth > 0)
@@ -1844,9 +1890,9 @@ var WorkspaceExecutor = class _WorkspaceExecutor extends Executor {
1844
1890
  dirs.map(async (dir) => {
1845
1891
  if (AVOID_DIRS.includes(dir))
1846
1892
  return;
1847
- const dirPath = path7.join(dirname3, dir);
1893
+ const dirPath = path6.join(dirname3, dir);
1848
1894
  if (fs8.lstatSync(dirPath).isDirectory()) {
1849
- const hasTargetFile = fs8.existsSync(path7.join(dirPath, targetFilename));
1895
+ const hasTargetFile = fs8.existsSync(path6.join(dirPath, targetFilename));
1850
1896
  if (hasTargetFile)
1851
1897
  results.push(`${prefix}${dir}`);
1852
1898
  if (maxDepth > 0)
@@ -1907,8 +1953,8 @@ var SysExecutor = class extends Executor {
1907
1953
  return this.type === "app" ? await getAppConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "app", name: this.name, command }) : await getLibConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "lib", name: this.name, command });
1908
1954
  }
1909
1955
  async getModules() {
1910
- const path10 = this.type === "app" ? `apps/${this.name}/lib` : `libs/${this.name}/lib`;
1911
- return await this.workspace.getDirInModule(path10, this.name);
1956
+ const path9 = this.type === "app" ? `apps/${this.name}/lib` : `libs/${this.name}/lib`;
1957
+ return await this.workspace.getDirInModule(path9, this.name);
1912
1958
  }
1913
1959
  async scan({
1914
1960
  tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`),
@@ -1920,19 +1966,19 @@ var SysExecutor = class extends Executor {
1920
1966
  const scanner = new TypeScriptDependencyScanner(this.cwdPath);
1921
1967
  const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
1922
1968
  const pkgPathSet = new Set(
1923
- Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path10) => tsconfig.compilerOptions.paths?.[path10]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path10) => path10.replace("/*", ""))
1969
+ Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path9) => tsconfig.compilerOptions.paths?.[path9]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path9) => path9.replace("/*", ""))
1924
1970
  );
1925
1971
  const libPathSet = new Set(
1926
- Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path10) => tsconfig.compilerOptions.paths?.[path10]?.some((resolve) => resolve.startsWith("libs/"))).map((path10) => path10.replace("/*", ""))
1972
+ Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path9) => tsconfig.compilerOptions.paths?.[path9]?.some((resolve) => resolve.startsWith("libs/"))).map((path9) => path9.replace("/*", ""))
1927
1973
  );
1928
1974
  const [npmDepSet, pkgPathDepSet, libPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet, libPathSet]);
1929
- const pkgDeps = [...pkgPathDepSet].map((path10) => {
1930
- const pathSplitLength = path10.split("/").length;
1931
- return (tsconfig.compilerOptions.paths?.[path10]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
1975
+ const pkgDeps = [...pkgPathDepSet].map((path9) => {
1976
+ const pathSplitLength = path9.split("/").length;
1977
+ return (tsconfig.compilerOptions.paths?.[path9]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
1932
1978
  });
1933
- const libDeps = [...libPathDepSet].map((path10) => {
1934
- const pathSplitLength = path10.split("/").length;
1935
- return (tsconfig.compilerOptions.paths?.[path10]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
1979
+ const libDeps = [...libPathDepSet].map((path9) => {
1980
+ const pathSplitLength = path9.split("/").length;
1981
+ return (tsconfig.compilerOptions.paths?.[path9]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
1936
1982
  }).filter((libName) => libName !== this.name);
1937
1983
  if (!fs8.existsSync(`${this.cwdPath}/lib/__scalar`))
1938
1984
  fs8.mkdirSync(`${this.cwdPath}/lib/__scalar`, { recursive: true });
@@ -1944,7 +1990,7 @@ var SysExecutor = class extends Executor {
1944
1990
  const serviceDirs = dirnames.filter((name) => name.startsWith("_") && !name.startsWith("__"));
1945
1991
  await Promise.all(
1946
1992
  databaseDirs.map(async (name) => {
1947
- const filenames = await this.readdir(path7.join("lib", name));
1993
+ const filenames = await this.readdir(path6.join("lib", name));
1948
1994
  filenames.forEach((filename) => {
1949
1995
  if (filename.endsWith(".constant.ts"))
1950
1996
  files.constants.databases.push(name);
@@ -1966,7 +2012,7 @@ var SysExecutor = class extends Executor {
1966
2012
  await Promise.all(
1967
2013
  serviceDirs.map(async (dirname3) => {
1968
2014
  const name = dirname3.slice(1);
1969
- const filenames = await this.readdir(path7.join("lib", dirname3));
2015
+ const filenames = await this.readdir(path6.join("lib", dirname3));
1970
2016
  filenames.forEach((filename) => {
1971
2017
  if (filename.endsWith(".dictionary.ts"))
1972
2018
  files.dictionary.services.push(name);
@@ -1984,7 +2030,7 @@ var SysExecutor = class extends Executor {
1984
2030
  const scalarDirs = (await this.readdir("lib/__scalar")).filter((name) => !name.startsWith("_"));
1985
2031
  await Promise.all(
1986
2032
  scalarDirs.map(async (name) => {
1987
- const filenames = await this.readdir(path7.join("lib/__scalar", name));
2033
+ const filenames = await this.readdir(path6.join("lib/__scalar", name));
1988
2034
  filenames.forEach((filename) => {
1989
2035
  if (filename.endsWith(".constant.ts"))
1990
2036
  files.constants.scalars.push(name);
@@ -2059,7 +2105,7 @@ var SysExecutor = class extends Executor {
2059
2105
  return scanResult;
2060
2106
  }
2061
2107
  getLocalFile(targetPath) {
2062
- const filePath = path7.isAbsolute(targetPath) ? targetPath : `${this.type}s/${this.name}/${targetPath}`;
2108
+ const filePath = path6.isAbsolute(targetPath) ? targetPath : `${this.type}s/${this.name}/${targetPath}`;
2063
2109
  const content = this.workspace.readFile(filePath);
2064
2110
  return { filePath, content };
2065
2111
  }
@@ -2174,17 +2220,28 @@ var AppExecutor = class _AppExecutor extends SysExecutor {
2174
2220
  }
2175
2221
  async syncAssets(libDeps) {
2176
2222
  const projectPublicLibPath = `${this.cwdPath}/public/libs`;
2177
- if (fs8.existsSync(projectPublicLibPath))
2178
- await fsPromise.rm(projectPublicLibPath, { recursive: true });
2223
+ const projectAssetsLibPath = `${this.cwdPath}/assets/libs`;
2224
+ await Promise.all([
2225
+ fs8.existsSync(projectPublicLibPath) && fsPromise.rm(projectPublicLibPath, { recursive: true }),
2226
+ fs8.existsSync(projectAssetsLibPath) && fsPromise.rm(projectAssetsLibPath, { recursive: true })
2227
+ ]);
2179
2228
  const targetDeps = libDeps.filter((dep) => fs8.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/public`));
2180
- await Promise.all(targetDeps.map((dep) => fsPromise.mkdir(`${projectPublicLibPath}/${dep}`, { recursive: true })));
2181
- await Promise.all(
2182
- targetDeps.map(
2183
- (dep) => fsPromise.cp(`${this.workspace.workspaceRoot}/libs/${dep}/public`, `${projectPublicLibPath}/${dep}`, {
2229
+ await Promise.all([
2230
+ ...targetDeps.map((dep) => fsPromise.mkdir(`${projectPublicLibPath}/${dep}`, { recursive: true })),
2231
+ ...targetDeps.map((dep) => fsPromise.mkdir(`${projectAssetsLibPath}/${dep}`, { recursive: true }))
2232
+ ]);
2233
+ await Promise.all([
2234
+ ...targetDeps.map(
2235
+ (dep) => fs8.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/public`) && fsPromise.cp(`${this.workspace.workspaceRoot}/libs/${dep}/public`, `${projectPublicLibPath}/${dep}`, {
2236
+ recursive: true
2237
+ })
2238
+ ),
2239
+ ...targetDeps.map(
2240
+ (dep) => fs8.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/assets`) && fsPromise.cp(`${this.workspace.workspaceRoot}/libs/${dep}/assets`, `${projectAssetsLibPath}/${dep}`, {
2184
2241
  recursive: true
2185
2242
  })
2186
2243
  )
2187
- );
2244
+ ]);
2188
2245
  }
2189
2246
  };
2190
2247
  var LibExecutor = class _LibExecutor extends SysExecutor {
@@ -2234,12 +2291,12 @@ var PkgExecutor = class _PkgExecutor extends Executor {
2234
2291
  const scanner = new TypeScriptDependencyScanner(this.cwdPath);
2235
2292
  const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
2236
2293
  const pkgPathSet = new Set(
2237
- Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path10) => tsconfig.compilerOptions.paths?.[path10]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path10) => path10.replace("/*", ""))
2294
+ Object.keys(tsconfig.compilerOptions.paths ?? {}).filter((path9) => tsconfig.compilerOptions.paths?.[path9]?.some((resolve) => resolve.startsWith("pkgs/"))).map((path9) => path9.replace("/*", ""))
2238
2295
  );
2239
2296
  const [npmDepSet, pkgPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet]);
2240
- const pkgDeps = [...pkgPathDepSet].map((path10) => {
2241
- const pathSplitLength = path10.split("/").length;
2242
- return (tsconfig.compilerOptions.paths?.[path10]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
2297
+ const pkgDeps = [...pkgPathDepSet].map((path9) => {
2298
+ const pathSplitLength = path9.split("/").length;
2299
+ return (tsconfig.compilerOptions.paths?.[path9]?.[0] ?? "*").split("/").slice(1, 1 + pathSplitLength).join("/");
2243
2300
  }).filter((pkg) => pkg !== this.name);
2244
2301
  const pkgScanResult = {
2245
2302
  name: this.name,
@@ -2549,8 +2606,8 @@ var extractDependencies = (filepaths, pacakgeJson, defaultDependencies = []) =>
2549
2606
  ...pacakgeJson.dependencies ?? {},
2550
2607
  ...pacakgeJson.devDependencies ?? {}
2551
2608
  };
2552
- const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
2553
- for (const { text } of filepaths.filter(({ path: path10 }) => path10.endsWith(".js"))) {
2609
+ const requireRegex = /(?:require\s*\(|import\s*(?:[\w\s{},*]*\s+from\s*)?|import\s*\()\s*['"`]([^'"`]+)['"`]/g;
2610
+ for (const { text } of filepaths.filter(({ path: path9 }) => path9.endsWith(".js"))) {
2554
2611
  let requireMatch;
2555
2612
  while ((requireMatch = requireRegex.exec(text)) !== null) {
2556
2613
  const moduleName = requireMatch[1];
@@ -3476,7 +3533,7 @@ import fsPromise3 from "fs/promises";
3476
3533
  import yaml2 from "js-yaml";
3477
3534
  import openBrowser from "open";
3478
3535
  import ora3 from "ora";
3479
- import path8 from "path";
3536
+ import path7 from "path";
3480
3537
  import * as vite from "vite";
3481
3538
  import commonjs from "vite-plugin-commonjs";
3482
3539
  import { nodePolyfills } from "vite-plugin-node-polyfills";
@@ -3915,6 +3972,8 @@ var ApplicationRunner = class {
3915
3972
  app.writeFile("next.config.ts", defaultNextConfigFile);
3916
3973
  } else if (target === "csr")
3917
3974
  await app.workspace.exec("rm -rf node_modules/.vite");
3975
+ else if (target === "backend")
3976
+ await app.cp("assets", path7.join(app.dist.cwdPath, "backend", "assets"));
3918
3977
  return { env: this.#getEnv(app, { AKAN_COMMAND_TYPE: type }) };
3919
3978
  }
3920
3979
  async buildBackend(app) {
@@ -3943,7 +4002,7 @@ var ApplicationRunner = class {
3943
4002
  dependencies
3944
4003
  };
3945
4004
  app.dist.writeJson("backend/package.json", appPackageJson);
3946
- app.dist.writeFile(path8.join(app.dist.cwdPath, "backend", "Dockerfile"), akanConfig.backend.dockerfile);
4005
+ app.dist.writeFile(path7.join(app.dist.cwdPath, "backend", "Dockerfile"), akanConfig.backend.docker.content);
3947
4006
  }
3948
4007
  async startBackend(app, { open: open2 = false, onStart } = {}) {
3949
4008
  const { env } = await this.#prepareCommand(app, "start", "backend");
@@ -3954,7 +4013,7 @@ var ApplicationRunner = class {
3954
4013
  packages: "external",
3955
4014
  platform: "node",
3956
4015
  format: "cjs",
3957
- outdir: path8.join(app.dist.cwdPath, "backend"),
4016
+ outdir: path7.join(app.dist.cwdPath, "backend"),
3958
4017
  logLevel: "warning"
3959
4018
  });
3960
4019
  await ctx.watch();
@@ -3962,7 +4021,7 @@ var ApplicationRunner = class {
3962
4021
  onStart?.();
3963
4022
  if (open2)
3964
4023
  setTimeout(() => openBrowser("http://localhost:8080/backend/graphql"), 3e3);
3965
- await app.dist.spawn("node", ["--watch", "backend/main.js"], { env, stdio: "inherit" });
4024
+ await app.dist.spawn("node", ["--watch", "main.js"], { env, stdio: "inherit", cwd: `${app.dist.cwdPath}/backend` });
3966
4025
  }
3967
4026
  async buildFrontend(app, { spawnOptions } = {}) {
3968
4027
  const { env } = await this.#prepareCommand(app, "build", "frontend");
@@ -3977,7 +4036,6 @@ var ApplicationRunner = class {
3977
4036
  format: "esm",
3978
4037
  write: false,
3979
4038
  logLevel: "warning"
3980
- // footer: { js: "module.exports = module.exports.default;" },
3981
4039
  });
3982
4040
  const rootPackageJson = app.workspace.readJson("package.json");
3983
4041
  const dependencies = extractDependencies(buildResult.outputFiles, rootPackageJson, ["next", "react", "react-dom"]);
@@ -3992,10 +4050,10 @@ var ApplicationRunner = class {
3992
4050
  };
3993
4051
  app.dist.writeJson("frontend/package.json", appPackageJson);
3994
4052
  await Promise.all([
3995
- app.cp(".next", path8.join(app.dist.cwdPath, "frontend", ".next")),
3996
- app.cp("public", path8.join(app.dist.cwdPath, "frontend", "public"))
4053
+ app.cp(".next", path7.join(app.dist.cwdPath, "frontend", ".next")),
4054
+ app.cp("public", path7.join(app.dist.cwdPath, "frontend", "public"))
3997
4055
  ]);
3998
- app.dist.writeFile("frontend/Dockerfile", akanConfig.frontend.dockerfile);
4056
+ app.dist.writeFile("frontend/Dockerfile", akanConfig.frontend.docker.content);
3999
4057
  }
4000
4058
  async startFrontend(app, { open: open2 = false, turbo = true, onStart } = {}) {
4001
4059
  const { env } = await this.#prepareCommand(app, "start", "frontend");
@@ -4255,8 +4313,8 @@ var ApplicationRunner = class {
4255
4313
  )
4256
4314
  );
4257
4315
  await Promise.all(
4258
- [".next", "ios", "android", "public/libs"].map(async (path10) => {
4259
- const targetPath = `${sourceRoot}/apps/${app.name}/${path10}`;
4316
+ [".next", "ios", "android", "public/libs"].map(async (path9) => {
4317
+ const targetPath = `${sourceRoot}/apps/${app.name}/${path9}`;
4260
4318
  if (fs14.existsSync(targetPath))
4261
4319
  await fsPromise3.rm(targetPath, { recursive: true, force: true });
4262
4320
  })
@@ -4274,7 +4332,7 @@ var ApplicationRunner = class {
4274
4332
  ];
4275
4333
  await Promise.all(
4276
4334
  syncPaths.map(
4277
- (path10) => fsPromise3.cp(`${app.workspace.cwdPath}/${path10}`, `${sourceRoot}/${path10}`, { recursive: true })
4335
+ (path9) => fsPromise3.cp(`${app.workspace.cwdPath}/${path9}`, `${sourceRoot}/${path9}`, { recursive: true })
4278
4336
  )
4279
4337
  );
4280
4338
  const tsconfig = app.workspace.readJson("tsconfig.json");
@@ -4978,6 +5036,15 @@ ${chalk6.green("\u27A4")} Authentication Required`));
4978
5036
  Logger.info("All libraries are published to npm");
4979
5037
  }
4980
5038
  async update(workspace) {
5039
+ if (!workspace.exists("package.json"))
5040
+ await workspace.spawn("npm", ["update", "-g", "@akanjs/cli", "--latest"]);
5041
+ else
5042
+ await Promise.all([
5043
+ workspace.spawn("npm", ["update", "-g", "@akanjs/cli", "--latest"]),
5044
+ this.#updateAkanPkgs(workspace)
5045
+ ]);
5046
+ }
5047
+ async #updateAkanPkgs(workspace) {
4981
5048
  const latestPublishedVersionOfBase = await latestVersion("@akanjs/base");
4982
5049
  const rootPackageJson = workspace.readJson("package.json");
4983
5050
  if (!rootPackageJson.dependencies)
@@ -4991,10 +5058,7 @@ ${chalk6.green("\u27A4")} Authentication Required`));
4991
5058
  Object.assign(rootPackageJson.devDependencies ?? {}, { [dependency]: latestPublishedVersionOfBase });
4992
5059
  });
4993
5060
  workspace.writeJson("package.json", rootPackageJson);
4994
- await Promise.all([
4995
- workspace.spawn("npm", ["update", "-g", "@akanjs/cli", "--latest"]),
4996
- workspace.spawn("pnpm", ["install"])
4997
- ]);
5061
+ await workspace.spawn("pnpm", ["install"]);
4998
5062
  }
4999
5063
  };
5000
5064
 
@@ -5650,13 +5714,9 @@ var ModuleScript = class {
5650
5714
  // pkgs/@akanjs/cli/src/module/module.command.ts
5651
5715
  var ModuleCommand = class {
5652
5716
  moduleScript = new ModuleScript();
5653
- async createModule(sys3, moduleName, description, schemaDescription, ai) {
5717
+ async createModule(moduleName, sys3) {
5654
5718
  const name = lowerlize(moduleName.replace(/ /g, ""));
5655
- if (ai) {
5656
- await this.moduleScript.createModule(sys3, name, description, schemaDescription);
5657
- } else {
5658
- await this.moduleScript.createModuleTemplate(sys3, name);
5659
- }
5719
+ await this.moduleScript.createModuleTemplate(sys3, name);
5660
5720
  }
5661
5721
  removeModule(module) {
5662
5722
  this.moduleScript.removeModule(module);
@@ -5673,11 +5733,8 @@ var ModuleCommand = class {
5673
5733
  };
5674
5734
  __decorateClass([
5675
5735
  Target.Public(),
5676
- __decorateParam(0, Sys()),
5677
- __decorateParam(1, Argument("moduleName", { desc: "name of module" })),
5678
- __decorateParam(2, Option("description", { desc: "description of module" })),
5679
- __decorateParam(3, Option("schemaDescription", { desc: "schema description of module" })),
5680
- __decorateParam(4, Option("ai", { type: "boolean", default: false, desc: "use ai to create module" }))
5736
+ __decorateParam(0, Argument("moduleName", { desc: "name of module" })),
5737
+ __decorateParam(1, Sys())
5681
5738
  ], ModuleCommand.prototype, "createModule", 1);
5682
5739
  __decorateClass([
5683
5740
  Target.Public(),
@@ -5774,12 +5831,12 @@ PageCommand = __decorateClass([
5774
5831
 
5775
5832
  // pkgs/@akanjs/cli/src/workspace/workspace.runner.ts
5776
5833
  import latestVersion2 from "latest-version";
5777
- import path9 from "path";
5834
+ import path8 from "path";
5778
5835
  import { v5 as uuid } from "uuid";
5779
5836
  var WorkspaceRunner = class {
5780
5837
  async createWorkspace(repoName, appName, dirname3 = ".") {
5781
5838
  const cwdPath = process.cwd();
5782
- const workspaceRoot = path9.join(cwdPath, dirname3, repoName);
5839
+ const workspaceRoot = path8.join(cwdPath, dirname3, repoName);
5783
5840
  const workspace = new WorkspaceExecutor({ workspaceRoot, repoName });
5784
5841
  const templateSpinner = workspace.spinning(`Creating workspace template files in ${dirname3}/${repoName}...`);
5785
5842
  await workspace.applyTemplate({
@@ -5977,15 +6034,15 @@ var GuidelinePrompt = class extends Prompter {
5977
6034
  async #getScanFilePaths(matchPattern, { avoidDirs = ["node_modules", ".next"], filterText } = {}) {
5978
6035
  const matchingPaths = fsPromise5.glob(matchPattern, {
5979
6036
  cwd: this.workspace.workspaceRoot,
5980
- exclude: (path10) => avoidDirs.some((dir) => path10.includes(dir))
6037
+ exclude: (path9) => avoidDirs.some((dir) => path9.includes(dir))
5981
6038
  });
5982
6039
  const paths = [];
5983
- for await (const path10 of matchingPaths) {
5984
- const fileContent = fs16.readFileSync(path10, "utf-8");
6040
+ for await (const path9 of matchingPaths) {
6041
+ const fileContent = fs16.readFileSync(path9, "utf-8");
5985
6042
  const textFilter = filterText ? new RegExp(filterText) : null;
5986
6043
  if (filterText && !textFilter?.test(fileContent))
5987
6044
  continue;
5988
- paths.push(path10);
6045
+ paths.push(path9);
5989
6046
  }
5990
6047
  return paths;
5991
6048
  }