@akanjs/config 0.9.13 → 0.9.15

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.
@@ -31,9 +31,11 @@ __export(akanConfig_exports, {
31
31
  getLibConfig: () => getLibConfig,
32
32
  getNextConfig: () => getNextConfig,
33
33
  makeAppConfig: () => makeAppConfig,
34
+ makeDockerfile: () => makeDockerfile,
34
35
  makeLibConfig: () => makeLibConfig
35
36
  });
36
37
  module.exports = __toCommonJS(akanConfig_exports);
38
+ var import_config = require("@akanjs/config");
37
39
  var import_fs = __toESM(require("fs"));
38
40
  var import_path = __toESM(require("path"));
39
41
  var import_nextConfig = require("./nextConfig");
@@ -43,43 +45,11 @@ const makeAppConfig = (config, props) => {
43
45
  rootLib: config.rootLib,
44
46
  libs: config.libs ?? [],
45
47
  backend: {
46
- dockerfile: config.backend?.dockerfile ?? `FROM node:22-slim
47
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
48
- 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/*
49
- ARG TARGETARCH
50
- 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
51
- RUN mkdir -p /workspace
52
- WORKDIR /workspace
53
- COPY ./package.json ./package.json
54
- RUN npx pnpm i --prod
55
- COPY . .
56
- ENV PORT 8080
57
- ENV NODE_OPTIONS=--max_old_space_size=8192
58
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
59
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
60
- ENV NEXT_PUBLIC_APP_NAME=${name}
61
- ENV NEXT_PUBLIC_ENV=${env}
62
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
63
- CMD ["node", "main.js"]`,
48
+ docker: makeDockerfile("backend", config.backend?.docker ?? {}, props),
64
49
  explicitDependencies: config.backend?.explicitDependencies ?? []
65
50
  },
66
51
  frontend: {
67
- dockerfile: config.frontend?.dockerfile ?? `FROM node:22-alpine
68
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
69
- RUN apk --no-cache add git
70
- RUN mkdir -p /workspace
71
- WORKDIR /workspace
72
- COPY ./package.json ./package.json
73
- RUN npx pnpm i --prod
74
- COPY . .
75
- ENV PORT 4200
76
- ENV NODE_OPTIONS=--max_old_space_size=8192
77
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
78
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
79
- ENV NEXT_PUBLIC_APP_NAME=${name}
80
- ENV NEXT_PUBLIC_ENV=${env}
81
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
82
- CMD ["npm", "start"]`,
52
+ docker: makeDockerfile("frontend", config.frontend?.docker ?? {}, props),
83
53
  nextConfig: (0, import_nextConfig.withBase)(
84
54
  name,
85
55
  config.frontend?.nextConfig ? typeof config.frontend.nextConfig === "function" ? config.frontend.nextConfig() : config.frontend.nextConfig : {},
@@ -139,3 +109,87 @@ const getNextConfig = (configImp, appData) => {
139
109
  const akanConfig = makeAppConfig(config, props);
140
110
  return akanConfig.frontend.nextConfig;
141
111
  };
112
+ const getDockerRunScripts = (runs) => {
113
+ return runs.map((run) => {
114
+ if (typeof run === "string")
115
+ return `RUN ${run}`;
116
+ else
117
+ return Object.entries(run).map(
118
+ ([arch, script]) => `RUN if [ "$TARGETARCH" = "${arch}" ]; then ${script} fi`
119
+ ).join("\n");
120
+ });
121
+ };
122
+ const getDockerImageScript = (image, defaultImage) => {
123
+ if (typeof image === "string")
124
+ return `FROM ${image}`;
125
+ else
126
+ return import_config.archs.map((arch) => `FROM ${image[arch] ?? defaultImage} AS ${arch}`).join("\n");
127
+ };
128
+ const makeDockerfile = (type, config, props) => {
129
+ const { name, repoName, serveDomain, env } = props;
130
+ if (config.content)
131
+ return { content: config.content, image: {}, preRuns: [], postRuns: [], command: [] };
132
+ const preRunScripts = getDockerRunScripts(config.preRuns ?? []);
133
+ const postRunScripts = getDockerRunScripts(config.postRuns ?? []);
134
+ if (type === "backend") {
135
+ const imageScript = config.image ? getDockerImageScript(config.image, "node:22-slim") : "FROM node:22-slim";
136
+ const command = config.command ?? ["node", "main.js"];
137
+ const content = `${imageScript}
138
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
139
+ RUN apt-get update && apt-get upgrade -y
140
+ 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/*
141
+ ARG TARGETARCH
142
+ 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
143
+ ${preRunScripts.join("\n")}
144
+ RUN mkdir -p /workspace
145
+ WORKDIR /workspace
146
+ COPY ./package.json ./package.json
147
+ RUN npx pnpm i --prod
148
+ COPY . .
149
+ ENV PORT=8080
150
+ ENV NODE_OPTIONS=--max_old_space_size=8192
151
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
152
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
153
+ ENV NEXT_PUBLIC_APP_NAME=${name}
154
+ ENV NEXT_PUBLIC_ENV=${env}
155
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
156
+ ${postRunScripts.join("\n")}
157
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
158
+ return {
159
+ content,
160
+ image: imageScript,
161
+ preRuns: config.preRuns ?? [],
162
+ postRuns: config.postRuns ?? [],
163
+ command
164
+ };
165
+ } else {
166
+ const imageScript = config.image ? getDockerImageScript(config.image, "node:22-alpine") : "FROM node:22-alpine";
167
+ const command = config.command ?? ["npm", "start"];
168
+ const content = `${imageScript}
169
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
170
+ ARG TARGETARCH
171
+ RUN apk --no-cache add git
172
+ ${preRunScripts.join("\n")}
173
+ RUN mkdir -p /workspace
174
+ WORKDIR /workspace
175
+ COPY ./package.json ./package.json
176
+ RUN npx pnpm i --prod
177
+ COPY . .
178
+ ENV PORT 4200
179
+ ENV NODE_OPTIONS=--max_old_space_size=8192
180
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
181
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
182
+ ENV NEXT_PUBLIC_APP_NAME=${name}
183
+ ENV NEXT_PUBLIC_ENV=${env}
184
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
185
+ ${postRunScripts.join("\n")}
186
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
187
+ return {
188
+ content,
189
+ image: imageScript,
190
+ preRuns: config.preRuns ?? [],
191
+ postRuns: config.postRuns ?? [],
192
+ command
193
+ };
194
+ }
195
+ };
package/cjs/src/types.js CHANGED
@@ -17,9 +17,11 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var types_exports = {};
19
19
  __export(types_exports, {
20
+ archs: () => archs,
20
21
  getDefaultFileScan: () => getDefaultFileScan
21
22
  });
22
23
  module.exports = __toCommonJS(types_exports);
24
+ const archs = ["amd64", "arm64"];
23
25
  const getDefaultFileScan = () => ({
24
26
  constants: {
25
27
  databases: [],
@@ -1,3 +1,6 @@
1
+ import {
2
+ archs
3
+ } from "@akanjs/config";
1
4
  import fs from "fs";
2
5
  import path from "path";
3
6
  import { withBase } from "./nextConfig";
@@ -7,43 +10,11 @@ const makeAppConfig = (config, props) => {
7
10
  rootLib: config.rootLib,
8
11
  libs: config.libs ?? [],
9
12
  backend: {
10
- dockerfile: config.backend?.dockerfile ?? `FROM node:22-slim
11
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
12
- 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/*
13
- ARG TARGETARCH
14
- 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
15
- RUN mkdir -p /workspace
16
- WORKDIR /workspace
17
- COPY ./package.json ./package.json
18
- RUN npx pnpm i --prod
19
- COPY . .
20
- ENV PORT 8080
21
- ENV NODE_OPTIONS=--max_old_space_size=8192
22
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
23
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
24
- ENV NEXT_PUBLIC_APP_NAME=${name}
25
- ENV NEXT_PUBLIC_ENV=${env}
26
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
27
- CMD ["node", "main.js"]`,
13
+ docker: makeDockerfile("backend", config.backend?.docker ?? {}, props),
28
14
  explicitDependencies: config.backend?.explicitDependencies ?? []
29
15
  },
30
16
  frontend: {
31
- dockerfile: config.frontend?.dockerfile ?? `FROM node:22-alpine
32
- RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
33
- RUN apk --no-cache add git
34
- RUN mkdir -p /workspace
35
- WORKDIR /workspace
36
- COPY ./package.json ./package.json
37
- RUN npx pnpm i --prod
38
- COPY . .
39
- ENV PORT 4200
40
- ENV NODE_OPTIONS=--max_old_space_size=8192
41
- ENV NEXT_PUBLIC_REPO_NAME=${repoName}
42
- ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
43
- ENV NEXT_PUBLIC_APP_NAME=${name}
44
- ENV NEXT_PUBLIC_ENV=${env}
45
- ENV NEXT_PUBLIC_OPERATION_MODE=cloud
46
- CMD ["npm", "start"]`,
17
+ docker: makeDockerfile("frontend", config.frontend?.docker ?? {}, props),
47
18
  nextConfig: withBase(
48
19
  name,
49
20
  config.frontend?.nextConfig ? typeof config.frontend.nextConfig === "function" ? config.frontend.nextConfig() : config.frontend.nextConfig : {},
@@ -103,10 +74,95 @@ const getNextConfig = (configImp, appData) => {
103
74
  const akanConfig = makeAppConfig(config, props);
104
75
  return akanConfig.frontend.nextConfig;
105
76
  };
77
+ const getDockerRunScripts = (runs) => {
78
+ return runs.map((run) => {
79
+ if (typeof run === "string")
80
+ return `RUN ${run}`;
81
+ else
82
+ return Object.entries(run).map(
83
+ ([arch, script]) => `RUN if [ "$TARGETARCH" = "${arch}" ]; then ${script} fi`
84
+ ).join("\n");
85
+ });
86
+ };
87
+ const getDockerImageScript = (image, defaultImage) => {
88
+ if (typeof image === "string")
89
+ return `FROM ${image}`;
90
+ else
91
+ return archs.map((arch) => `FROM ${image[arch] ?? defaultImage} AS ${arch}`).join("\n");
92
+ };
93
+ const makeDockerfile = (type, config, props) => {
94
+ const { name, repoName, serveDomain, env } = props;
95
+ if (config.content)
96
+ return { content: config.content, image: {}, preRuns: [], postRuns: [], command: [] };
97
+ const preRunScripts = getDockerRunScripts(config.preRuns ?? []);
98
+ const postRunScripts = getDockerRunScripts(config.postRuns ?? []);
99
+ if (type === "backend") {
100
+ const imageScript = config.image ? getDockerImageScript(config.image, "node:22-slim") : "FROM node:22-slim";
101
+ const command = config.command ?? ["node", "main.js"];
102
+ const content = `${imageScript}
103
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
104
+ RUN apt-get update && apt-get upgrade -y
105
+ 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/*
106
+ ARG TARGETARCH
107
+ 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
108
+ ${preRunScripts.join("\n")}
109
+ RUN mkdir -p /workspace
110
+ WORKDIR /workspace
111
+ COPY ./package.json ./package.json
112
+ RUN npx pnpm i --prod
113
+ COPY . .
114
+ ENV PORT=8080
115
+ ENV NODE_OPTIONS=--max_old_space_size=8192
116
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
117
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
118
+ ENV NEXT_PUBLIC_APP_NAME=${name}
119
+ ENV NEXT_PUBLIC_ENV=${env}
120
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
121
+ ${postRunScripts.join("\n")}
122
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
123
+ return {
124
+ content,
125
+ image: imageScript,
126
+ preRuns: config.preRuns ?? [],
127
+ postRuns: config.postRuns ?? [],
128
+ command
129
+ };
130
+ } else {
131
+ const imageScript = config.image ? getDockerImageScript(config.image, "node:22-alpine") : "FROM node:22-alpine";
132
+ const command = config.command ?? ["npm", "start"];
133
+ const content = `${imageScript}
134
+ RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
135
+ ARG TARGETARCH
136
+ RUN apk --no-cache add git
137
+ ${preRunScripts.join("\n")}
138
+ RUN mkdir -p /workspace
139
+ WORKDIR /workspace
140
+ COPY ./package.json ./package.json
141
+ RUN npx pnpm i --prod
142
+ COPY . .
143
+ ENV PORT 4200
144
+ ENV NODE_OPTIONS=--max_old_space_size=8192
145
+ ENV NEXT_PUBLIC_REPO_NAME=${repoName}
146
+ ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
147
+ ENV NEXT_PUBLIC_APP_NAME=${name}
148
+ ENV NEXT_PUBLIC_ENV=${env}
149
+ ENV NEXT_PUBLIC_OPERATION_MODE=cloud
150
+ ${postRunScripts.join("\n")}
151
+ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
152
+ return {
153
+ content,
154
+ image: imageScript,
155
+ preRuns: config.preRuns ?? [],
156
+ postRuns: config.postRuns ?? [],
157
+ command
158
+ };
159
+ }
160
+ };
106
161
  export {
107
162
  getAppConfig,
108
163
  getLibConfig,
109
164
  getNextConfig,
110
165
  makeAppConfig,
166
+ makeDockerfile,
111
167
  makeLibConfig
112
168
  };
package/esm/src/types.js CHANGED
@@ -1,3 +1,4 @@
1
+ const archs = ["amd64", "arm64"];
1
2
  const getDefaultFileScan = () => ({
2
3
  constants: {
3
4
  databases: [],
@@ -34,5 +35,6 @@ const getDefaultFileScan = () => ({
34
35
  }
35
36
  });
36
37
  export {
38
+ archs,
37
39
  getDefaultFileScan
38
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/config",
3
- "version": "0.9.13",
3
+ "version": "0.9.15",
4
4
  "sourceType": "module",
5
5
  "module": {
6
6
  "access": "public"
@@ -1,7 +1,8 @@
1
- import type { AppConfig, AppConfigResult, DeepPartial, LibConfigResult, RunnerProps } from "@akanjs/config";
1
+ import { type AppConfig, type AppConfigResult, type DeepPartial, type DockerConfig, type LibConfigResult, type RunnerProps } from "@akanjs/config";
2
2
  import type { NextConfig } from "next";
3
3
  export declare const makeAppConfig: (config: DeepPartial<AppConfigResult>, props: RunnerProps) => AppConfigResult;
4
4
  export declare const getAppConfig: (appRoot: string, props: RunnerProps) => Promise<AppConfigResult>;
5
5
  export declare const makeLibConfig: (config: DeepPartial<LibConfigResult>, props: RunnerProps) => LibConfigResult;
6
6
  export declare const getLibConfig: (libRoot: string, props: RunnerProps) => Promise<LibConfigResult>;
7
7
  export declare const getNextConfig: (configImp: AppConfig, appData: any) => NextConfig | (() => Promise<NextConfig> | NextConfig);
8
+ export declare const makeDockerfile: (type: "backend" | "frontend", config: DeepPartial<DockerConfig>, props: RunnerProps) => DockerConfig;
package/src/types.d.ts CHANGED
@@ -7,19 +7,33 @@ export interface RunnerProps {
7
7
  env: "testing" | "local" | "debug" | "develop" | "main";
8
8
  command?: string;
9
9
  }
10
- export type Arch = "amd64" | "arm64";
10
+ export declare const archs: readonly ["amd64", "arm64"];
11
+ export type Arch = (typeof archs)[number];
11
12
  export type ExplicitDependencies = string[] | {
12
13
  [key in Arch]: string[];
13
14
  };
15
+ export interface DockerConfig {
16
+ content: string;
17
+ image: string | {
18
+ [key in Arch]?: string;
19
+ };
20
+ preRuns: (string | {
21
+ [key in Arch]?: string;
22
+ })[];
23
+ postRuns: (string | {
24
+ [key in Arch]?: string;
25
+ })[];
26
+ command: string[];
27
+ }
14
28
  export interface AppConfigResult {
15
29
  rootLib?: string;
16
30
  libs: string[];
17
31
  backend: {
18
- dockerfile: string;
32
+ docker: DockerConfig;
19
33
  explicitDependencies: ExplicitDependencies;
20
34
  };
21
35
  frontend: {
22
- dockerfile: string;
36
+ docker: DockerConfig;
23
37
  nextConfig: NextConfig | (() => Promise<NextConfig> | NextConfig);
24
38
  routes?: {
25
39
  basePath?: string;