@akanjs/cli 0.0.86 → 0.0.87
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/index.js
CHANGED
|
@@ -32,40 +32,25 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
32
32
|
};
|
|
33
33
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
34
34
|
|
|
35
|
-
// pkgs/@akanjs/devkit/src/
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
const repoName =
|
|
39
|
-
if (!repoName)
|
|
40
|
-
throw new Error("NEXT_PUBLIC_REPO_NAME is not set");
|
|
41
|
-
const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN;
|
|
42
|
-
if (!serveDomain)
|
|
43
|
-
throw new Error("NEXT_PUBLIC_SERVE_DOMAIN is not set");
|
|
44
|
-
const env = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
45
|
-
if (!env)
|
|
46
|
-
throw new Error("NEXT_PUBLIC_ENV is not set");
|
|
47
|
-
return { ...appName ? { appName } : {}, repoName, serveDomain, env };
|
|
48
|
-
};
|
|
49
|
-
var getSshTunnelOptions = (appName, environment) => {
|
|
50
|
-
const { serveDomain, repoName } = getBaseDevEnv();
|
|
35
|
+
// pkgs/@akanjs/devkit/src/createTunnel.ts
|
|
36
|
+
var import_tunnel_ssh = require("tunnel-ssh");
|
|
37
|
+
var getSshTunnelOptions = (app, environment) => {
|
|
38
|
+
const { serveDomain, repoName } = app.workspace.getBaseDevEnv();
|
|
51
39
|
return {
|
|
52
|
-
host: `${
|
|
53
|
-
port: process.env.
|
|
54
|
-
username: process.env.
|
|
55
|
-
password: process.env.
|
|
40
|
+
host: `${app.name}-${environment}.${serveDomain}`,
|
|
41
|
+
port: process.env.SSH_TUNNEL_PORT ? parseInt(process.env.SSH_TUNNEL_PORT) : 32767,
|
|
42
|
+
username: process.env.SSH_TUNNEL_USERNAME ?? "root",
|
|
43
|
+
password: process.env.SSH_TUNNEL_PASSWORD ?? repoName
|
|
56
44
|
};
|
|
57
45
|
};
|
|
58
|
-
|
|
59
|
-
// pkgs/@akanjs/devkit/src/createTunnel.ts
|
|
60
|
-
var import_tunnel_ssh = require("tunnel-ssh");
|
|
61
|
-
var createTunnel = async ({ appName, environment, port = 27017 }) => {
|
|
46
|
+
var createTunnel = async ({ app, environment, port = 27017 }) => {
|
|
62
47
|
const tunnelOptions = { autoClose: true, reconnectOnError: true };
|
|
63
|
-
const sshOptions = getSshTunnelOptions(
|
|
48
|
+
const sshOptions = getSshTunnelOptions(app, environment);
|
|
64
49
|
const serverOptions = { port };
|
|
65
50
|
const forwardOptions = {
|
|
66
51
|
srcAddr: "0.0.0.0",
|
|
67
52
|
srcPort: port,
|
|
68
|
-
dstAddr: `mongo-0.mongo-svc.${
|
|
53
|
+
dstAddr: `mongo-0.mongo-svc.${app.name}-${environment}`,
|
|
69
54
|
dstPort: 27017
|
|
70
55
|
};
|
|
71
56
|
const [server, client] = await (0, import_tunnel_ssh.createTunnel)(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
@@ -379,7 +364,7 @@ var Logger = class _Logger {
|
|
|
379
364
|
"NestApplication"
|
|
380
365
|
]);
|
|
381
366
|
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
382
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
367
|
+
static #levelIdx = logLevels.findIndex((l) => l === (process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log"));
|
|
383
368
|
static #startAt = (0, import_dayjs4.default)();
|
|
384
369
|
static setLevel(level) {
|
|
385
370
|
this.level = level;
|
|
@@ -805,6 +790,7 @@ var import_child_process = require("child_process");
|
|
|
805
790
|
var import_fs7 = __toESM(require("fs"), 1);
|
|
806
791
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
807
792
|
var import_path3 = __toESM(require("path"), 1);
|
|
793
|
+
var import_dotenv = __toESM(require("dotenv"), 1);
|
|
808
794
|
|
|
809
795
|
// pkgs/@akanjs/devkit/src/dependencyScanner.ts
|
|
810
796
|
var fs7 = __toESM(require("fs"), 1);
|
|
@@ -1029,7 +1015,7 @@ var Executor = class {
|
|
|
1029
1015
|
const readPath = this.#getPath(filePath);
|
|
1030
1016
|
return import_fs7.default.existsSync(readPath);
|
|
1031
1017
|
}
|
|
1032
|
-
writeFile(filePath, content) {
|
|
1018
|
+
writeFile(filePath, content, { overwrite = true } = {}) {
|
|
1033
1019
|
const writePath = this.#getPath(filePath);
|
|
1034
1020
|
const dir = import_path3.default.dirname(writePath);
|
|
1035
1021
|
if (!import_fs7.default.existsSync(dir))
|
|
@@ -1037,7 +1023,7 @@ var Executor = class {
|
|
|
1037
1023
|
const contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
|
|
1038
1024
|
if (import_fs7.default.existsSync(writePath)) {
|
|
1039
1025
|
const currentContent = import_fs7.default.readFileSync(writePath, "utf8");
|
|
1040
|
-
if (currentContent === contentStr)
|
|
1026
|
+
if (currentContent === contentStr || !overwrite)
|
|
1041
1027
|
this.logger.verbose(`File ${writePath} is unchanged`);
|
|
1042
1028
|
else {
|
|
1043
1029
|
import_fs7.default.writeFileSync(writePath, contentStr, "utf8");
|
|
@@ -1094,7 +1080,8 @@ var Executor = class {
|
|
|
1094
1080
|
async #applyTemplateFile({
|
|
1095
1081
|
templatePath,
|
|
1096
1082
|
targetPath,
|
|
1097
|
-
scanResult
|
|
1083
|
+
scanResult,
|
|
1084
|
+
overwrite = true
|
|
1098
1085
|
}, dict = {}) {
|
|
1099
1086
|
if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
|
|
1100
1087
|
const getContent = await import(templatePath);
|
|
@@ -1128,12 +1115,16 @@ var Executor = class {
|
|
|
1128
1115
|
basePath: basePath2,
|
|
1129
1116
|
template,
|
|
1130
1117
|
scanResult,
|
|
1131
|
-
dict = {}
|
|
1118
|
+
dict = {},
|
|
1119
|
+
overwrite = true
|
|
1132
1120
|
}) {
|
|
1133
1121
|
const templatePath = `${__dirname}/src/templates${template ? `/${template}` : ""}`.replace(".ts", ".js");
|
|
1134
1122
|
if (import_fs7.default.statSync(templatePath).isFile()) {
|
|
1135
1123
|
const filename = import_path3.default.basename(templatePath);
|
|
1136
|
-
await this.#applyTemplateFile(
|
|
1124
|
+
await this.#applyTemplateFile(
|
|
1125
|
+
{ templatePath, targetPath: import_path3.default.join(basePath2, filename), scanResult, overwrite },
|
|
1126
|
+
dict
|
|
1127
|
+
);
|
|
1137
1128
|
} else {
|
|
1138
1129
|
const subdirs = await import_promises.default.readdir(templatePath);
|
|
1139
1130
|
await Promise.all(
|
|
@@ -1141,7 +1132,7 @@ var Executor = class {
|
|
|
1141
1132
|
const subpath = import_path3.default.join(templatePath, subdir);
|
|
1142
1133
|
if (import_fs7.default.statSync(subpath).isFile())
|
|
1143
1134
|
await this.#applyTemplateFile(
|
|
1144
|
-
{ templatePath: subpath, targetPath: import_path3.default.join(basePath2, subdir), scanResult },
|
|
1135
|
+
{ templatePath: subpath, targetPath: import_path3.default.join(basePath2, subdir), scanResult, overwrite },
|
|
1145
1136
|
dict
|
|
1146
1137
|
);
|
|
1147
1138
|
else
|
|
@@ -1149,7 +1140,8 @@ var Executor = class {
|
|
|
1149
1140
|
basePath: import_path3.default.join(basePath2, subdir),
|
|
1150
1141
|
template: import_path3.default.join(template, subdir),
|
|
1151
1142
|
scanResult,
|
|
1152
|
-
dict
|
|
1143
|
+
dict,
|
|
1144
|
+
overwrite
|
|
1153
1145
|
});
|
|
1154
1146
|
})
|
|
1155
1147
|
);
|
|
@@ -1168,6 +1160,20 @@ var WorkspaceExecutor = class _WorkspaceExecutor extends Executor {
|
|
|
1168
1160
|
const repoName = import_path3.default.basename(process.cwd());
|
|
1169
1161
|
return new _WorkspaceExecutor({ workspaceRoot: process.cwd(), repoName });
|
|
1170
1162
|
}
|
|
1163
|
+
getBaseDevEnv() {
|
|
1164
|
+
const envFile = import_dotenv.default.parse(this.readFile(".env"));
|
|
1165
|
+
const appName = process.env.NEXT_PUBLIC_APP_NAME ?? envFile.NEXT_PUBLIC_APP_NAME;
|
|
1166
|
+
const repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? envFile.NEXT_PUBLIC_REPO_NAME;
|
|
1167
|
+
if (!repoName)
|
|
1168
|
+
throw new Error("NEXT_PUBLIC_REPO_NAME is not set");
|
|
1169
|
+
const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? envFile.NEXT_PUBLIC_SERVE_DOMAIN;
|
|
1170
|
+
if (!serveDomain)
|
|
1171
|
+
throw new Error("NEXT_PUBLIC_SERVE_DOMAIN is not set");
|
|
1172
|
+
const env = process.env.NEXT_PUBLIC_ENV ?? envFile.NEXT_PUBLIC_ENV ?? "debug";
|
|
1173
|
+
if (!env)
|
|
1174
|
+
throw new Error("NEXT_PUBLIC_ENV is not set");
|
|
1175
|
+
return { ...appName ? { appName } : {}, repoName, serveDomain, env };
|
|
1176
|
+
}
|
|
1171
1177
|
async scan() {
|
|
1172
1178
|
const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
|
|
1173
1179
|
const [appScanResults, libScanResults, pkgScanResults] = await Promise.all([
|
|
@@ -1270,7 +1276,7 @@ var SysExecutor = class extends Executor {
|
|
|
1270
1276
|
this.type = type;
|
|
1271
1277
|
}
|
|
1272
1278
|
async getConfig(command) {
|
|
1273
|
-
return this.type === "app" ? await getAppConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command }) : await getLibConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
1279
|
+
return this.type === "app" ? await getAppConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), appName: this.name, command }) : await getLibConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), appName: this.name, command });
|
|
1274
1280
|
}
|
|
1275
1281
|
async scan({
|
|
1276
1282
|
tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`),
|
|
@@ -1468,7 +1474,7 @@ var AppExecutor = class _AppExecutor extends SysExecutor {
|
|
|
1468
1474
|
return new _AppExecutor({ workspace: executor.workspace, name });
|
|
1469
1475
|
}
|
|
1470
1476
|
async getConfig(command) {
|
|
1471
|
-
return await getAppConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
1477
|
+
return await getAppConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), appName: this.name, command });
|
|
1472
1478
|
}
|
|
1473
1479
|
async syncAssets(libDeps) {
|
|
1474
1480
|
const projectPublicLibPath = `${this.cwdPath}/public/libs`;
|
|
@@ -1509,7 +1515,7 @@ var LibExecutor = class _LibExecutor extends SysExecutor {
|
|
|
1509
1515
|
return new _LibExecutor({ workspace: executor.workspace, name });
|
|
1510
1516
|
}
|
|
1511
1517
|
async getConfig(command) {
|
|
1512
|
-
return await getLibConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
1518
|
+
return await getLibConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), appName: this.name, command });
|
|
1513
1519
|
}
|
|
1514
1520
|
};
|
|
1515
1521
|
var PkgExecutor = class _PkgExecutor extends Executor {
|
|
@@ -2096,7 +2102,7 @@ var AiSession = class _AiSession {
|
|
|
2096
2102
|
|
|
2097
2103
|
// pkgs/@akanjs/cli/src/library/library.runner.ts
|
|
2098
2104
|
var import_compare_versions = require("compare-versions");
|
|
2099
|
-
var
|
|
2105
|
+
var import_dotenv2 = __toESM(require("dotenv"));
|
|
2100
2106
|
var LibraryRunner = class {
|
|
2101
2107
|
async scanSync(lib) {
|
|
2102
2108
|
const akanConfig = await lib.getConfig();
|
|
@@ -2150,7 +2156,7 @@ var LibraryRunner = class {
|
|
|
2150
2156
|
lib.logger.log(`${lib.name} library pulled from ${branch} branch`);
|
|
2151
2157
|
}
|
|
2152
2158
|
#getEnv(lib, env = {}) {
|
|
2153
|
-
const rootEnv =
|
|
2159
|
+
const rootEnv = import_dotenv2.default.parse(lib.workspace.readFile(".env"));
|
|
2154
2160
|
return {
|
|
2155
2161
|
...process.env,
|
|
2156
2162
|
...rootEnv,
|
|
@@ -2216,7 +2222,7 @@ var import_prompts6 = require("@langchain/core/prompts");
|
|
|
2216
2222
|
var import_runnables2 = require("@langchain/core/runnables");
|
|
2217
2223
|
var import_openai3 = require("@langchain/openai");
|
|
2218
2224
|
var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
|
|
2219
|
-
var
|
|
2225
|
+
var import_dotenv3 = __toESM(require("dotenv"));
|
|
2220
2226
|
var esbuild = __toESM(require("esbuild"));
|
|
2221
2227
|
var import_fs12 = __toESM(require("fs"));
|
|
2222
2228
|
var import_promises2 = __toESM(require("fs/promises"));
|
|
@@ -3201,13 +3207,17 @@ var ApplicationRunner = class {
|
|
|
3201
3207
|
return AppExecutor.from(workspace, appName);
|
|
3202
3208
|
}
|
|
3203
3209
|
async scanSync(app) {
|
|
3204
|
-
const akanConfig = await getAppConfig(app.cwdPath, {
|
|
3210
|
+
const akanConfig = await getAppConfig(app.cwdPath, {
|
|
3211
|
+
...app.workspace.getBaseDevEnv(),
|
|
3212
|
+
appName: app.name,
|
|
3213
|
+
command: "serve"
|
|
3214
|
+
});
|
|
3205
3215
|
const scanResult = await app.scan({ akanConfig });
|
|
3206
3216
|
await app.syncAssets(scanResult.akanConfig.libs);
|
|
3207
3217
|
return scanResult;
|
|
3208
3218
|
}
|
|
3209
3219
|
#getEnv(app, env = {}) {
|
|
3210
|
-
const rootEnv =
|
|
3220
|
+
const rootEnv = import_dotenv3.default.parse(app.workspace.readFile(".env"));
|
|
3211
3221
|
return {
|
|
3212
3222
|
...process.env,
|
|
3213
3223
|
...rootEnv,
|
|
@@ -3218,8 +3228,10 @@ var ApplicationRunner = class {
|
|
|
3218
3228
|
}
|
|
3219
3229
|
async #prepareCommand(app, distApp, type, target) {
|
|
3220
3230
|
await distApp.exec(`rm -rf ${target}`);
|
|
3221
|
-
if (target === "frontend")
|
|
3231
|
+
if (target === "frontend") {
|
|
3232
|
+
await app.exec("rm -rf .next");
|
|
3222
3233
|
app.writeFile("next.config.ts", defaultNextConfigFile);
|
|
3234
|
+
}
|
|
3223
3235
|
return { env: this.#getEnv(app, { AKAN_COMMAND_TYPE: type }) };
|
|
3224
3236
|
}
|
|
3225
3237
|
async buildBackend(app, distApp) {
|
|
@@ -3454,7 +3466,7 @@ var ApplicationRunner = class {
|
|
|
3454
3466
|
return `mongodb://localhost:27017/${app.name}-${environment}`;
|
|
3455
3467
|
const secret = getCredentials(app, environment);
|
|
3456
3468
|
const mongoAccount = secret.mongo.account.user;
|
|
3457
|
-
const localUrl = await createTunnel({
|
|
3469
|
+
const localUrl = await createTunnel({ app, environment });
|
|
3458
3470
|
const mongoUri = `mongodb://${mongoAccount.username}:${encodeURIComponent(
|
|
3459
3471
|
mongoAccount.password
|
|
3460
3472
|
)}@${localUrl}/${app.name}-${environment}`;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { AppExecutor } from "./executors";
|
|
1
2
|
interface TunnelOption {
|
|
2
|
-
|
|
3
|
+
app: AppExecutor;
|
|
3
4
|
environment: string;
|
|
4
5
|
port?: number;
|
|
5
6
|
}
|
|
6
|
-
export declare const createTunnel: ({
|
|
7
|
+
export declare const createTunnel: ({ app, environment, port }: TunnelOption) => Promise<string>;
|
|
7
8
|
export {};
|
|
@@ -15,7 +15,9 @@ export declare class Executor {
|
|
|
15
15
|
fork(modulePath: string, args?: string[], options?: ForkOptions): Promise<unknown>;
|
|
16
16
|
mkdir(dirPath: string): this;
|
|
17
17
|
exists(filePath: string): boolean;
|
|
18
|
-
writeFile(filePath: string, content: string | object
|
|
18
|
+
writeFile(filePath: string, content: string | object, { overwrite }?: {
|
|
19
|
+
overwrite?: boolean;
|
|
20
|
+
}): this;
|
|
19
21
|
writeJson(filePath: string, content: object): this;
|
|
20
22
|
getLocalFile(filePath: string): {
|
|
21
23
|
filepath: string;
|
|
@@ -27,13 +29,14 @@ export declare class Executor {
|
|
|
27
29
|
log(msg: string): this;
|
|
28
30
|
verbose(msg: string): this;
|
|
29
31
|
getTsConfig(pathname: string): TsConfigJson;
|
|
30
|
-
applyTemplate({ basePath, template, scanResult, dict, }: {
|
|
32
|
+
applyTemplate({ basePath, template, scanResult, dict, overwrite, }: {
|
|
31
33
|
basePath: string;
|
|
32
34
|
template: string;
|
|
33
35
|
scanResult?: AppScanResult | LibScanResult | null;
|
|
34
36
|
dict?: {
|
|
35
37
|
[key: string]: string;
|
|
36
38
|
};
|
|
39
|
+
overwrite?: boolean;
|
|
37
40
|
}): Promise<void>;
|
|
38
41
|
}
|
|
39
42
|
interface ExecutorOptions {
|
|
@@ -46,6 +49,12 @@ export declare class WorkspaceExecutor extends Executor {
|
|
|
46
49
|
repoName: string;
|
|
47
50
|
constructor({ workspaceRoot, repoName }: ExecutorOptions);
|
|
48
51
|
static fromRoot(): WorkspaceExecutor;
|
|
52
|
+
getBaseDevEnv(): {
|
|
53
|
+
repoName: string;
|
|
54
|
+
serveDomain: string;
|
|
55
|
+
env: "debug" | "testing" | "develop" | "main";
|
|
56
|
+
appName?: string | undefined;
|
|
57
|
+
};
|
|
49
58
|
scan(): Promise<WorkspaceScanResult>;
|
|
50
59
|
getApps(): Promise<string[]>;
|
|
51
60
|
getLibs(): Promise<string[]>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SshOptions } from "tunnel-ssh";
|
|
2
|
-
interface BaseDevEnv {
|
|
3
|
-
appName?: string;
|
|
4
|
-
repoName: string;
|
|
5
|
-
serveDomain: string;
|
|
6
|
-
env: "testing" | "debug" | "develop" | "main";
|
|
7
|
-
}
|
|
8
|
-
export declare const getBaseDevEnv: () => BaseDevEnv;
|
|
9
|
-
export declare const getSshTunnelOptions: (appName: string, environment: string) => SshOptions;
|
|
10
|
-
export {};
|