@akanjs/devkit 1.0.20 → 2.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +65 -0
- package/README.md +62 -6
- package/aiEditor.ts +304 -0
- package/akanApp/akanApp.host.ts +393 -0
- package/akanApp/index.ts +1 -0
- package/akanConfig/akanConfig.test.ts +236 -0
- package/akanConfig/akanConfig.ts +384 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/types.ts +23 -0
- package/applicationBuildReporter.ts +69 -0
- package/applicationBuildRunner.ts +302 -0
- package/applicationReleasePackager.ts +206 -0
- package/artifact/implicitRootLayout.ts +155 -0
- package/artifact/index.ts +1 -0
- package/artifact/routeSeedIndex.test.ts +98 -0
- package/artifact/routeSeedIndex.ts +130 -0
- package/auth.ts +41 -0
- package/builder.ts +164 -0
- package/capacitor.base.config.ts +88 -0
- package/capacitorApp.ts +440 -0
- package/commandDecorators/argMeta.ts +102 -0
- package/commandDecorators/command.ts +351 -0
- package/commandDecorators/commandBuilder.ts +224 -0
- package/commandDecorators/commandDecorators.test.ts +212 -0
- package/commandDecorators/commandMeta.ts +7 -0
- package/commandDecorators/dependencyBuilder.ts +100 -0
- package/{esm/src/commandDecorators/helpFormatter.js → commandDecorators/helpFormatter.ts} +100 -47
- package/{esm/src/commandDecorators/index.js → commandDecorators/index.ts} +4 -2
- package/commandDecorators/targetMeta.ts +31 -0
- package/commandDecorators/types.ts +10 -0
- package/constants.ts +25 -0
- package/createTunnel.ts +36 -0
- package/dependencyScanner.ts +357 -0
- package/devkitUtils.test.ts +259 -0
- package/executors.test.ts +315 -0
- package/executors.ts +1390 -0
- package/{esm/src/extractDeps.js → extractDeps.ts} +26 -20
- package/{esm/src/fileEditor.js → fileEditor.ts} +51 -32
- package/fileSys.ts +39 -0
- package/frontendBuild/allRoutesBuilder.ts +103 -0
- package/frontendBuild/buildRouteClient.test.ts +190 -0
- package/frontendBuild/clientBuildTypes.ts +114 -0
- package/frontendBuild/clientEntriesBundler.ts +303 -0
- package/frontendBuild/clientEntryDiscovery.ts +199 -0
- package/frontendBuild/csrArtifactBuilder.ts +237 -0
- package/frontendBuild/cssCompiler.ts +286 -0
- package/frontendBuild/cssImportResolver.ts +116 -0
- package/frontendBuild/fontOptimizer.ts +427 -0
- package/frontendBuild/frontendBuild.test.ts +204 -0
- package/frontendBuild/hmrChangeClassifier.ts +28 -0
- package/frontendBuild/hmrWatcher.ts +102 -0
- package/frontendBuild/index.ts +18 -0
- package/frontendBuild/pagesBundleBuilder.ts +137 -0
- package/frontendBuild/pagesEntrySourceGenerator.ts +37 -0
- package/frontendBuild/precompressArtifacts.ts +59 -0
- package/frontendBuild/routeClientBuilder.ts +290 -0
- package/frontendBuild/routesManifestArtifactSerializer.ts +62 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +139 -0
- package/frontendBuild/vendorSpecifiers.ts +16 -0
- package/frontendBuild/watchRootResolver.ts +28 -0
- package/getCredentials.ts +19 -0
- package/getDirname.ts +3 -0
- package/getModelFileData.ts +59 -0
- package/getRelatedCnsts.ts +313 -0
- package/guideline.ts +19 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +51 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +152 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +331 -0
- package/incrementalBuilder/index.ts +1 -0
- package/{esm/src/index.js → index.ts} +28 -15
- package/lint/no-deep-internal-import.grit +25 -0
- package/lint/no-import-client-functions.grit +32 -0
- package/lint/no-import-external-library.grit +21 -0
- package/lint/no-js-private-class-method.grit +42 -0
- package/lint/no-use-client-in-server.grit +7 -0
- package/lint/non-scalar-props-restricted.grit +13 -0
- package/linter.ts +271 -0
- package/mobile/index.ts +1 -0
- package/mobile/mobileTarget.test.ts +53 -0
- package/mobile/mobileTarget.ts +88 -0
- package/package.json +48 -31
- package/prompter.ts +72 -0
- package/scanInfo.ts +606 -0
- package/selectModel.ts +11 -0
- package/{esm/src/spinner.js → spinner.ts} +22 -28
- package/{esm/src/capacitorApp.js → src/capacitorApp.ts} +82 -81
- package/sshTunnel.ts +152 -0
- package/{esm/src/streamAi.js → streamAi.ts} +18 -12
- package/transforms/barrelAnalyzer.ts +278 -0
- package/transforms/barrelImportsPlugin.ts +504 -0
- package/transforms/externalizeFrameworkPlugin.ts +185 -0
- package/transforms/index.ts +5 -0
- package/transforms/rscUseClientTransform.ts +59 -0
- package/transforms/transforms.test.ts +208 -0
- package/transforms/useClientBundlePlugin.ts +47 -0
- package/tsconfig.json +37 -0
- package/typeChecker.ts +264 -0
- package/types.ts +44 -0
- package/ui/MultiScrollList.tsx +242 -0
- package/ui/ScrollList.tsx +107 -0
- package/ui/index.ts +2 -0
- package/{esm/src/uploadRelease.js → uploadRelease.ts} +50 -34
- package/{esm/src/useStdoutDimensions.js → useStdoutDimensions.ts} +5 -5
- package/cjs/index.js +0 -21
- package/cjs/src/aiEditor.js +0 -311
- package/cjs/src/auth.js +0 -72
- package/cjs/src/builder.js +0 -114
- package/cjs/src/capacitorApp.js +0 -313
- package/cjs/src/commandDecorators/argMeta.js +0 -88
- package/cjs/src/commandDecorators/command.js +0 -324
- package/cjs/src/commandDecorators/commandMeta.js +0 -30
- package/cjs/src/commandDecorators/helpFormatter.js +0 -211
- package/cjs/src/commandDecorators/index.js +0 -31
- package/cjs/src/commandDecorators/targetMeta.js +0 -57
- package/cjs/src/commandDecorators/types.js +0 -15
- package/cjs/src/constants.js +0 -46
- package/cjs/src/createTunnel.js +0 -49
- package/cjs/src/dependencyScanner.js +0 -220
- package/cjs/src/executors.js +0 -964
- package/cjs/src/extractDeps.js +0 -103
- package/cjs/src/fileEditor.js +0 -120
- package/cjs/src/getCredentials.js +0 -44
- package/cjs/src/getDirname.js +0 -38
- package/cjs/src/getModelFileData.js +0 -66
- package/cjs/src/getRelatedCnsts.js +0 -260
- package/cjs/src/guideline.js +0 -15
- package/cjs/src/index.js +0 -65
- package/cjs/src/linter.js +0 -238
- package/cjs/src/prompter.js +0 -85
- package/cjs/src/scanInfo.js +0 -491
- package/cjs/src/selectModel.js +0 -46
- package/cjs/src/spinner.js +0 -93
- package/cjs/src/streamAi.js +0 -62
- package/cjs/src/typeChecker.js +0 -207
- package/cjs/src/types.js +0 -15
- package/cjs/src/uploadRelease.js +0 -112
- package/cjs/src/useStdoutDimensions.js +0 -43
- package/esm/index.js +0 -1
- package/esm/src/aiEditor.js +0 -282
- package/esm/src/auth.js +0 -42
- package/esm/src/builder.js +0 -81
- package/esm/src/commandDecorators/argMeta.js +0 -54
- package/esm/src/commandDecorators/command.js +0 -290
- package/esm/src/commandDecorators/commandMeta.js +0 -7
- package/esm/src/commandDecorators/targetMeta.js +0 -33
- package/esm/src/commandDecorators/types.js +0 -0
- package/esm/src/constants.js +0 -17
- package/esm/src/createTunnel.js +0 -26
- package/esm/src/dependencyScanner.js +0 -187
- package/esm/src/executors.js +0 -928
- package/esm/src/getCredentials.js +0 -11
- package/esm/src/getDirname.js +0 -5
- package/esm/src/getModelFileData.js +0 -33
- package/esm/src/getRelatedCnsts.js +0 -221
- package/esm/src/guideline.js +0 -0
- package/esm/src/linter.js +0 -205
- package/esm/src/prompter.js +0 -51
- package/esm/src/scanInfo.js +0 -455
- package/esm/src/selectModel.js +0 -13
- package/esm/src/typeChecker.js +0 -174
- package/esm/src/types.js +0 -0
- package/index.d.ts +0 -1
- package/src/aiEditor.d.ts +0 -50
- package/src/auth.d.ts +0 -9
- package/src/builder.d.ts +0 -18
- package/src/capacitorApp.d.ts +0 -39
- package/src/commandDecorators/argMeta.d.ts +0 -67
- package/src/commandDecorators/command.d.ts +0 -2
- package/src/commandDecorators/commandMeta.d.ts +0 -2
- package/src/commandDecorators/helpFormatter.d.ts +0 -3
- package/src/commandDecorators/index.d.ts +0 -6
- package/src/commandDecorators/targetMeta.d.ts +0 -19
- package/src/commandDecorators/types.d.ts +0 -1
- package/src/constants.d.ts +0 -26
- package/src/createTunnel.d.ts +0 -8
- package/src/dependencyScanner.d.ts +0 -23
- package/src/executors.d.ts +0 -296
- package/src/extractDeps.d.ts +0 -7
- package/src/fileEditor.d.ts +0 -16
- package/src/getCredentials.d.ts +0 -12
- package/src/getDirname.d.ts +0 -1
- package/src/getModelFileData.d.ts +0 -16
- package/src/getRelatedCnsts.d.ts +0 -53
- package/src/guideline.d.ts +0 -19
- package/src/index.d.ts +0 -23
- package/src/linter.d.ts +0 -109
- package/src/prompter.d.ts +0 -14
- package/src/scanInfo.d.ts +0 -82
- package/src/selectModel.d.ts +0 -1
- package/src/spinner.d.ts +0 -20
- package/src/streamAi.d.ts +0 -6
- package/src/typeChecker.d.ts +0 -52
- package/src/types.d.ts +0 -31
- package/src/uploadRelease.d.ts +0 -10
- package/src/useStdoutDimensions.d.ts +0 -1
package/esm/src/auth.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import {
|
|
3
|
-
akanCloudBackendUrl,
|
|
4
|
-
akanCloudHost,
|
|
5
|
-
basePath,
|
|
6
|
-
configPath,
|
|
7
|
-
defaultAkanGlobalConfig,
|
|
8
|
-
defaultHostConfig
|
|
9
|
-
} from "./constants";
|
|
10
|
-
const getAkanGlobalConfig = () => {
|
|
11
|
-
const akanConfig = fs.existsSync(configPath) ? JSON.parse(fs.readFileSync(configPath, "utf8")) : defaultAkanGlobalConfig;
|
|
12
|
-
return akanConfig;
|
|
13
|
-
};
|
|
14
|
-
const setAkanGlobalConfig = (akanConfig) => {
|
|
15
|
-
fs.mkdirSync(basePath, { recursive: true });
|
|
16
|
-
fs.writeFileSync(configPath, JSON.stringify(akanConfig, null, 2));
|
|
17
|
-
};
|
|
18
|
-
const getHostConfig = (host = akanCloudHost) => {
|
|
19
|
-
const akanConfig = getAkanGlobalConfig();
|
|
20
|
-
return akanConfig.cloudHost[host] ?? defaultHostConfig;
|
|
21
|
-
};
|
|
22
|
-
const setHostConfig = (host = akanCloudHost, config = {}) => {
|
|
23
|
-
const akanConfig = getAkanGlobalConfig();
|
|
24
|
-
akanConfig.cloudHost[host] = config;
|
|
25
|
-
setAkanGlobalConfig(akanConfig);
|
|
26
|
-
};
|
|
27
|
-
const getSelf = async (token) => {
|
|
28
|
-
try {
|
|
29
|
-
const res = await fetch(`${akanCloudBackendUrl}/user/getSelf`, { headers: { Authorization: `Bearer ${token}` } });
|
|
30
|
-
const user = await res.json();
|
|
31
|
-
return user;
|
|
32
|
-
} catch (e) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
export {
|
|
37
|
-
getAkanGlobalConfig,
|
|
38
|
-
getHostConfig,
|
|
39
|
-
getSelf,
|
|
40
|
-
setAkanGlobalConfig,
|
|
41
|
-
setHostConfig
|
|
42
|
-
};
|
package/esm/src/builder.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as esbuild from "esbuild";
|
|
2
|
-
import { dtsPlugin } from "esbuild-plugin-d.ts";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import { extractDependencies } from "./extractDeps";
|
|
5
|
-
const assetExtensions = [".css", ".md", ".js", ".png", ".ico", ".svg", ".json", ".template"];
|
|
6
|
-
const assetLoader = Object.fromEntries(assetExtensions.map((ext) => [ext, "copy"]));
|
|
7
|
-
class Builder {
|
|
8
|
-
#executor;
|
|
9
|
-
#distExecutor;
|
|
10
|
-
#pkgJson;
|
|
11
|
-
#rootPackageJson;
|
|
12
|
-
constructor({ executor, distExecutor, pkgJson, rootPackageJson }) {
|
|
13
|
-
this.#executor = executor;
|
|
14
|
-
this.#distExecutor = distExecutor;
|
|
15
|
-
this.#pkgJson = pkgJson;
|
|
16
|
-
this.#rootPackageJson = rootPackageJson;
|
|
17
|
-
}
|
|
18
|
-
#getBuildOptions(format, { bundle = false, additionalEntryPoints = [] } = {}) {
|
|
19
|
-
return {
|
|
20
|
-
entryPoints: [
|
|
21
|
-
...bundle ? [`${this.#executor.cwdPath}/index.ts`] : [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
|
|
22
|
-
...additionalEntryPoints
|
|
23
|
-
],
|
|
24
|
-
bundle,
|
|
25
|
-
packages: "external",
|
|
26
|
-
splitting: false,
|
|
27
|
-
platform: this.#pkgJson.esbuild?.platform,
|
|
28
|
-
format,
|
|
29
|
-
outdir: `${this.#distExecutor.cwdPath}/${format}`,
|
|
30
|
-
logLevel: "error",
|
|
31
|
-
// external: ["react", "react-dom"],
|
|
32
|
-
loader: assetLoader
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
#getAssetBuildOptions() {
|
|
36
|
-
return {
|
|
37
|
-
write: true,
|
|
38
|
-
bundle: false,
|
|
39
|
-
entryPoints: [
|
|
40
|
-
`${this.#executor.cwdPath}/**/*.css`,
|
|
41
|
-
`${this.#executor.cwdPath}/**/*.md`,
|
|
42
|
-
`${this.#executor.cwdPath}/**/*.js`
|
|
43
|
-
],
|
|
44
|
-
outdir: this.#distExecutor.cwdPath,
|
|
45
|
-
logLevel: "error",
|
|
46
|
-
loader: assetLoader
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
async build(options = {}) {
|
|
50
|
-
if (fs.existsSync(this.#distExecutor.cwdPath))
|
|
51
|
-
await this.#distExecutor.exec(`rm -rf ${this.#distExecutor.cwdPath}`);
|
|
52
|
-
const plugins = [dtsPlugin({ tsconfig: `${this.#executor.cwdPath}/tsconfig.json` })];
|
|
53
|
-
const [buildResult] = await Promise.all([
|
|
54
|
-
esbuild.build({ ...this.#getBuildOptions("cjs", options), write: false, plugins }),
|
|
55
|
-
esbuild.build({ write: true, ...this.#getBuildOptions("esm", options) }),
|
|
56
|
-
esbuild.build({ ...this.#getAssetBuildOptions() })
|
|
57
|
-
]);
|
|
58
|
-
const existingDeps = Object.keys(this.#pkgJson.dependencies ?? {});
|
|
59
|
-
const dependencies = extractDependencies(buildResult.outputFiles, this.#rootPackageJson, existingDeps);
|
|
60
|
-
const pkgPackageJson = {
|
|
61
|
-
...this.#pkgJson,
|
|
62
|
-
main: "./index.js",
|
|
63
|
-
engines: { node: ">=20" },
|
|
64
|
-
dependencies,
|
|
65
|
-
exports: {
|
|
66
|
-
...this.#pkgJson.exports ?? {},
|
|
67
|
-
".": {
|
|
68
|
-
require: "./cjs/index.js",
|
|
69
|
-
import: "./esm/index.js",
|
|
70
|
-
types: "./index.d.ts"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
|
|
75
|
-
this.#distExecutor.setPackageJson(pkgPackageJson);
|
|
76
|
-
this.#executor.setPackageJson(pkgPackageJson);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export {
|
|
80
|
-
Builder
|
|
81
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
const argTypes = ["Argument", "Option"];
|
|
3
|
-
const internalArgTypes = ["Workspace", "App", "Lib", "Sys", "Pkg", "Module", "Exec"];
|
|
4
|
-
const getArgMetas = (command, key) => {
|
|
5
|
-
const allArgMetas = getArgMetasOnPrototype(command.prototype, key);
|
|
6
|
-
const argMetas = allArgMetas.filter((argMeta) => argMeta.type === "Option");
|
|
7
|
-
const internalArgMetas = allArgMetas.filter((argMeta) => argMeta.type !== "Option");
|
|
8
|
-
return [allArgMetas, argMetas, internalArgMetas];
|
|
9
|
-
};
|
|
10
|
-
const getArgMetasOnPrototype = (prototype, key) => {
|
|
11
|
-
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
12
|
-
};
|
|
13
|
-
const setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
14
|
-
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
15
|
-
};
|
|
16
|
-
const getArg = (type) => function(name, argsOption = {}) {
|
|
17
|
-
return function(prototype, key, idx) {
|
|
18
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
19
|
-
argMetas[idx] = { name, argsOption, key, idx, type };
|
|
20
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
const Argument = getArg("Argument");
|
|
24
|
-
const Option = getArg("Option");
|
|
25
|
-
const createArgMetaDecorator = (type) => {
|
|
26
|
-
return function(option = {}) {
|
|
27
|
-
return function(prototype, key, idx) {
|
|
28
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
29
|
-
argMetas[idx] = { key, idx, type, option };
|
|
30
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const App = createArgMetaDecorator("App");
|
|
35
|
-
const Lib = createArgMetaDecorator("Lib");
|
|
36
|
-
const Sys = createArgMetaDecorator("Sys");
|
|
37
|
-
const Exec = createArgMetaDecorator("Exec");
|
|
38
|
-
const Pkg = createArgMetaDecorator("Pkg");
|
|
39
|
-
const Module = createArgMetaDecorator("Module");
|
|
40
|
-
const Workspace = createArgMetaDecorator("Workspace");
|
|
41
|
-
export {
|
|
42
|
-
App,
|
|
43
|
-
Argument,
|
|
44
|
-
Exec,
|
|
45
|
-
Lib,
|
|
46
|
-
Module,
|
|
47
|
-
Option,
|
|
48
|
-
Pkg,
|
|
49
|
-
Sys,
|
|
50
|
-
Workspace,
|
|
51
|
-
argTypes,
|
|
52
|
-
getArgMetas,
|
|
53
|
-
internalArgTypes
|
|
54
|
-
};
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { Logger } from "@akanjs/common";
|
|
2
|
-
import { confirm, input, select } from "@inquirer/prompts";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import { program } from "commander";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import { getDirname } from "..";
|
|
7
|
-
import { AppExecutor, Executor, LibExecutor, ModuleExecutor, PkgExecutor, WorkspaceExecutor } from "../executors";
|
|
8
|
-
import { getArgMetas } from "./argMeta";
|
|
9
|
-
import { formatCommandHelp, formatHelp } from "./helpFormatter";
|
|
10
|
-
import { getTargetMetas } from "./targetMeta";
|
|
11
|
-
const camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
12
|
-
const handleOption = (programCommand, argMeta) => {
|
|
13
|
-
const {
|
|
14
|
-
type,
|
|
15
|
-
flag = argMeta.name.slice(0, 1).toLowerCase(),
|
|
16
|
-
desc = argMeta.name,
|
|
17
|
-
example,
|
|
18
|
-
enum: enumChoices,
|
|
19
|
-
ask
|
|
20
|
-
} = argMeta.argsOption;
|
|
21
|
-
const kebabName = camelToKebabCase(argMeta.name);
|
|
22
|
-
const choices = enumChoices?.map(
|
|
23
|
-
(choice) => typeof choice === "object" ? { value: choice.value, name: choice.label } : { value: choice, name: choice.toString() }
|
|
24
|
-
);
|
|
25
|
-
programCommand.option(
|
|
26
|
-
`-${flag}, --${kebabName}${type === "boolean" ? " [boolean]" : ` <${kebabName}>`}`,
|
|
27
|
-
`${desc}${ask ? ` (${ask})` : ""}${example ? ` (example: ${example})` : ""}${choices ? ` (choices: ${choices.map((choice) => choice.name).join(", ")})` : ""}`
|
|
28
|
-
);
|
|
29
|
-
return programCommand;
|
|
30
|
-
};
|
|
31
|
-
const handleArgument = (programCommand, argMeta) => {
|
|
32
|
-
const kebabName = camelToKebabCase(argMeta.name);
|
|
33
|
-
if ((argMeta.argsOption.type ?? "string") !== "string")
|
|
34
|
-
throw new Error(`Argument type must be string: ${argMeta.name}`);
|
|
35
|
-
programCommand.argument(
|
|
36
|
-
`[${kebabName}]`,
|
|
37
|
-
`${argMeta.argsOption.desc}${argMeta.argsOption.example ? ` (example: ${argMeta.argsOption.example})` : ""}`
|
|
38
|
-
);
|
|
39
|
-
return programCommand;
|
|
40
|
-
};
|
|
41
|
-
const convertOptionValue = (value, type) => {
|
|
42
|
-
if (type === "string")
|
|
43
|
-
return value;
|
|
44
|
-
else if (type === "number")
|
|
45
|
-
return Number(value);
|
|
46
|
-
else
|
|
47
|
-
return value === true || value === "true";
|
|
48
|
-
};
|
|
49
|
-
const getOptionValue = async (argMeta, opt) => {
|
|
50
|
-
const {
|
|
51
|
-
name,
|
|
52
|
-
argsOption: { enum: enumChoices, default: defaultValue, type, desc, nullable, example, ask }
|
|
53
|
-
} = argMeta;
|
|
54
|
-
if (opt[argMeta.name] !== void 0)
|
|
55
|
-
return convertOptionValue(opt[argMeta.name], type ?? "string");
|
|
56
|
-
else if (defaultValue !== void 0)
|
|
57
|
-
return defaultValue;
|
|
58
|
-
else if (nullable)
|
|
59
|
-
return null;
|
|
60
|
-
if (enumChoices) {
|
|
61
|
-
const choices = enumChoices.map(
|
|
62
|
-
(choice2) => typeof choice2 === "object" ? { value: choice2.value, name: choice2.label } : { value: choice2, name: choice2.toString() }
|
|
63
|
-
);
|
|
64
|
-
const choice = await select({ message: ask ?? desc ?? `Select the ${name} value`, choices });
|
|
65
|
-
return choice;
|
|
66
|
-
} else if (type === "boolean") {
|
|
67
|
-
const message = ask ?? desc ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
|
|
68
|
-
return await confirm({ message });
|
|
69
|
-
} else {
|
|
70
|
-
const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
71
|
-
if (argMeta.argsOption.nullable)
|
|
72
|
-
return await input({ message });
|
|
73
|
-
else
|
|
74
|
-
return convertOptionValue(await input({ message }), type ?? "string");
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const getArgumentValue = async (argMeta, value) => {
|
|
78
|
-
const {
|
|
79
|
-
name,
|
|
80
|
-
argsOption: { default: defaultValue, type, desc, nullable, example, ask }
|
|
81
|
-
} = argMeta;
|
|
82
|
-
if (value !== void 0)
|
|
83
|
-
return value;
|
|
84
|
-
else if (defaultValue !== void 0)
|
|
85
|
-
return defaultValue;
|
|
86
|
-
else if (nullable)
|
|
87
|
-
return null;
|
|
88
|
-
const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
89
|
-
return await input({ message });
|
|
90
|
-
};
|
|
91
|
-
const getInternalArgumentValue = async (argMeta, value, workspace) => {
|
|
92
|
-
if (argMeta.type === "Workspace")
|
|
93
|
-
return workspace;
|
|
94
|
-
const sysType = argMeta.type.toLowerCase();
|
|
95
|
-
const [appNames, libNames, pkgNames] = await workspace.getExecs();
|
|
96
|
-
if (sysType === "sys") {
|
|
97
|
-
if (value && appNames.includes(value))
|
|
98
|
-
return AppExecutor.from(workspace, value);
|
|
99
|
-
else if (value && libNames.includes(value))
|
|
100
|
-
return LibExecutor.from(workspace, value);
|
|
101
|
-
else {
|
|
102
|
-
const sysName = await select({
|
|
103
|
-
message: `Select the App or Lib name`,
|
|
104
|
-
choices: [...appNames, ...libNames]
|
|
105
|
-
});
|
|
106
|
-
if (appNames.includes(sysName))
|
|
107
|
-
return AppExecutor.from(workspace, sysName);
|
|
108
|
-
else if (libNames.includes(sysName))
|
|
109
|
-
return LibExecutor.from(workspace, sysName);
|
|
110
|
-
else
|
|
111
|
-
throw new Error(`Invalid system name: ${sysName}`);
|
|
112
|
-
}
|
|
113
|
-
} else if (sysType === "exec") {
|
|
114
|
-
if (value && appNames.includes(value))
|
|
115
|
-
return AppExecutor.from(workspace, value);
|
|
116
|
-
else if (value && libNames.includes(value))
|
|
117
|
-
return LibExecutor.from(workspace, value);
|
|
118
|
-
else if (value && pkgNames.includes(value))
|
|
119
|
-
return PkgExecutor.from(workspace, value);
|
|
120
|
-
else {
|
|
121
|
-
const execName = await select({
|
|
122
|
-
message: `Select the App or Lib or Pkg name`,
|
|
123
|
-
choices: [...appNames, ...libNames, ...pkgNames]
|
|
124
|
-
});
|
|
125
|
-
if (appNames.includes(execName))
|
|
126
|
-
return AppExecutor.from(workspace, execName);
|
|
127
|
-
else if (libNames.includes(execName))
|
|
128
|
-
return LibExecutor.from(workspace, execName);
|
|
129
|
-
else if (pkgNames.includes(execName))
|
|
130
|
-
return PkgExecutor.from(workspace, execName);
|
|
131
|
-
else
|
|
132
|
-
throw new Error(`Invalid system name: ${execName}`);
|
|
133
|
-
}
|
|
134
|
-
} else if (sysType === "app") {
|
|
135
|
-
if (value && appNames.includes(value))
|
|
136
|
-
return AppExecutor.from(workspace, value);
|
|
137
|
-
const appName = await select({ message: `Select the ${sysType} name`, choices: appNames });
|
|
138
|
-
return AppExecutor.from(workspace, appName);
|
|
139
|
-
} else if (sysType === "lib") {
|
|
140
|
-
if (value && libNames.includes(value))
|
|
141
|
-
return LibExecutor.from(workspace, value);
|
|
142
|
-
const libName = await select({ message: `Select the ${sysType} name`, choices: libNames });
|
|
143
|
-
return LibExecutor.from(workspace, libName);
|
|
144
|
-
} else if (sysType === "pkg") {
|
|
145
|
-
const pkgs = await workspace.getPkgs();
|
|
146
|
-
if (value && pkgs.includes(value))
|
|
147
|
-
return PkgExecutor.from(workspace, value);
|
|
148
|
-
const pkgName = await select({ message: `Select the ${sysType} name`, choices: pkgs });
|
|
149
|
-
return PkgExecutor.from(workspace, pkgName);
|
|
150
|
-
} else if (sysType === "module") {
|
|
151
|
-
if (value) {
|
|
152
|
-
const [sysName, moduleName2] = value.split(":");
|
|
153
|
-
if (appNames.includes(sysName)) {
|
|
154
|
-
const app = AppExecutor.from(workspace, sysName);
|
|
155
|
-
const modules2 = await app.getModules();
|
|
156
|
-
if (modules2.includes(moduleName2))
|
|
157
|
-
return ModuleExecutor.from(app, moduleName2);
|
|
158
|
-
else
|
|
159
|
-
throw new Error(`Invalid module name: ${moduleName2}`);
|
|
160
|
-
} else if (libNames.includes(sysName)) {
|
|
161
|
-
const lib = LibExecutor.from(workspace, sysName);
|
|
162
|
-
const modules2 = await lib.getModules();
|
|
163
|
-
if (modules2.includes(moduleName2))
|
|
164
|
-
return ModuleExecutor.from(lib, moduleName2);
|
|
165
|
-
} else
|
|
166
|
-
throw new Error(`Invalid system name: ${sysName}`);
|
|
167
|
-
}
|
|
168
|
-
const { type, name } = await select({
|
|
169
|
-
message: `select the App or Lib name`,
|
|
170
|
-
choices: [
|
|
171
|
-
...appNames.map((name2) => ({ name: name2, value: { type: "app", name: name2 } })),
|
|
172
|
-
...libNames.map((name2) => ({ name: name2, value: { type: "lib", name: name2 } }))
|
|
173
|
-
]
|
|
174
|
-
});
|
|
175
|
-
const executor = type === "app" ? AppExecutor.from(workspace, name) : LibExecutor.from(workspace, name);
|
|
176
|
-
const modules = await executor.getModules();
|
|
177
|
-
const moduleName = await select({
|
|
178
|
-
message: `Select the module name`,
|
|
179
|
-
choices: modules.map((name2) => ({ name: `${executor.name}:${name2}`, value: name2 }))
|
|
180
|
-
});
|
|
181
|
-
return ModuleExecutor.from(executor, moduleName);
|
|
182
|
-
} else
|
|
183
|
-
throw new Error(`Invalid system type: ${argMeta.type}`);
|
|
184
|
-
};
|
|
185
|
-
const runCommands = async (...commands) => {
|
|
186
|
-
process.on("unhandledRejection", (error) => {
|
|
187
|
-
process.exit(1);
|
|
188
|
-
});
|
|
189
|
-
const __dirname = getDirname(import.meta.url);
|
|
190
|
-
const hasPackageJson = fs.existsSync(`${__dirname}/../package.json`);
|
|
191
|
-
process.env.AKAN_VERSION = hasPackageJson ? JSON.parse(fs.readFileSync(`${__dirname}/../package.json`, "utf8")).version : "0.0.1";
|
|
192
|
-
const hasHelpFlag = process.argv.includes("--help") || process.argv.includes("-h");
|
|
193
|
-
const hasCommand = process.argv.length > 2 && !process.argv[2].startsWith("-");
|
|
194
|
-
if (hasHelpFlag || !hasCommand) {
|
|
195
|
-
if (process.argv.length === 2 || process.argv.length === 3 && hasHelpFlag) {
|
|
196
|
-
Logger.rawLog(formatHelp(commands, process.env.AKAN_VERSION));
|
|
197
|
-
process.exit(0);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
program.version(process.env.AKAN_VERSION).description("Akan CLI").configureHelp({
|
|
201
|
-
helpWidth: 100
|
|
202
|
-
});
|
|
203
|
-
const akanBasePackageJson = fs.existsSync("./node_modules/@akanjs/base/package.json") ? JSON.parse(fs.readFileSync("./node_modules/@akanjs/base/package.json", "utf8")) : null;
|
|
204
|
-
if (akanBasePackageJson && akanBasePackageJson.version !== process.env.AKAN_VERSION) {
|
|
205
|
-
Logger.rawLog(
|
|
206
|
-
chalk.yellow(
|
|
207
|
-
`
|
|
208
|
-
Akan CLI version is mismatch with installed package. ${process.env.AKAN_VERSION} (global) vs ${akanBasePackageJson.version} (base)
|
|
209
|
-
It may cause unexpected behavior. Run \`akan update\` to update latest akanjs.`
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
for (const command of commands) {
|
|
214
|
-
const targetMetas = getTargetMetas(command);
|
|
215
|
-
for (const targetMeta of targetMetas) {
|
|
216
|
-
const kebabKey = camelToKebabCase(targetMeta.key);
|
|
217
|
-
const commandNames = targetMeta.targetOption.short === true ? [
|
|
218
|
-
kebabKey,
|
|
219
|
-
typeof targetMeta.targetOption.short === "string" ? targetMeta.targetOption.short : kebabKey.split("-").map((s) => s.slice(0, 1)).join("")
|
|
220
|
-
] : [kebabKey];
|
|
221
|
-
for (const commandName of commandNames) {
|
|
222
|
-
let programCommand = program.command(commandName, {
|
|
223
|
-
hidden: targetMeta.targetOption.devOnly
|
|
224
|
-
});
|
|
225
|
-
const [allArgMetas] = getArgMetas(command, targetMeta.key);
|
|
226
|
-
for (const argMeta of allArgMetas) {
|
|
227
|
-
if (argMeta.type === "Option")
|
|
228
|
-
programCommand = handleOption(programCommand, argMeta);
|
|
229
|
-
else if (argMeta.type === "Argument")
|
|
230
|
-
programCommand = handleArgument(programCommand, argMeta);
|
|
231
|
-
else if (argMeta.type === "Workspace")
|
|
232
|
-
continue;
|
|
233
|
-
else if (argMeta.type === "Module") {
|
|
234
|
-
programCommand = programCommand.argument(
|
|
235
|
-
`[sys-name:module-name]`,
|
|
236
|
-
`${argMeta.type} in this workspace (apps|libs)/<sys-name>/lib/<module-name>`
|
|
237
|
-
);
|
|
238
|
-
} else {
|
|
239
|
-
const sysType = argMeta.type.toLowerCase();
|
|
240
|
-
programCommand = programCommand.argument(
|
|
241
|
-
`[${sysType}]`,
|
|
242
|
-
`${sysType} in this workspace ${sysType}s/<${sysType}Name>`
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
programCommand = programCommand.option(`-v, --verbose [boolean]`, `verbose output`);
|
|
247
|
-
programCommand.helpInformation = () => {
|
|
248
|
-
return formatCommandHelp(command, targetMeta.key);
|
|
249
|
-
};
|
|
250
|
-
programCommand.action(async (...args) => {
|
|
251
|
-
Logger.rawLog();
|
|
252
|
-
const cmdArgs = args.slice(0, args.length - 2);
|
|
253
|
-
const opt = args[args.length - 2];
|
|
254
|
-
const commandArgs = [];
|
|
255
|
-
const workspace = WorkspaceExecutor.fromRoot();
|
|
256
|
-
for (const argMeta of allArgMetas) {
|
|
257
|
-
if (argMeta.type === "Option")
|
|
258
|
-
commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt);
|
|
259
|
-
else if (argMeta.type === "Argument")
|
|
260
|
-
commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx]);
|
|
261
|
-
else
|
|
262
|
-
commandArgs[argMeta.idx] = await getInternalArgumentValue(
|
|
263
|
-
argMeta,
|
|
264
|
-
cmdArgs[argMeta.idx],
|
|
265
|
-
workspace
|
|
266
|
-
);
|
|
267
|
-
if (commandArgs[argMeta.idx] instanceof AppExecutor)
|
|
268
|
-
process.env.NEXT_PUBLIC_APP_NAME = commandArgs[argMeta.idx].name;
|
|
269
|
-
if (opt.verbose)
|
|
270
|
-
Executor.setVerbose(true);
|
|
271
|
-
}
|
|
272
|
-
const cmd = new command();
|
|
273
|
-
try {
|
|
274
|
-
await cmd[targetMeta.key](...commandArgs);
|
|
275
|
-
Logger.rawLog();
|
|
276
|
-
} catch (e) {
|
|
277
|
-
const errMsg = e instanceof Error ? e.message : typeof e === "string" ? e : JSON.stringify(e);
|
|
278
|
-
Logger.rawLog(`
|
|
279
|
-
${chalk.red(errMsg)}`);
|
|
280
|
-
throw e;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
await program.parseAsync(process.argv);
|
|
287
|
-
};
|
|
288
|
-
export {
|
|
289
|
-
runCommands
|
|
290
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const getTargetMetas = (command) => {
|
|
2
|
-
const targetMetaMap = Reflect.getMetadata("target", command.prototype);
|
|
3
|
-
if (!targetMetaMap)
|
|
4
|
-
throw new Error(`TargetMeta is not defined for ${command.name}`);
|
|
5
|
-
return [...targetMetaMap.values()];
|
|
6
|
-
};
|
|
7
|
-
const getTargetMetaMapOnPrototype = (prototype) => {
|
|
8
|
-
const targetMetaMap = Reflect.getMetadata("target", prototype);
|
|
9
|
-
return targetMetaMap ?? /* @__PURE__ */ new Map();
|
|
10
|
-
};
|
|
11
|
-
const setTargetMetaMapOnPrototype = (prototype, targetMetaMap) => {
|
|
12
|
-
Reflect.defineMetadata("target", targetMetaMap, prototype);
|
|
13
|
-
};
|
|
14
|
-
const getTarget = (type) => (targetOption = {}) => {
|
|
15
|
-
return (prototype, key, descriptor) => {
|
|
16
|
-
const metadataMap = getTargetMetaMapOnPrototype(prototype);
|
|
17
|
-
metadataMap.set(key, {
|
|
18
|
-
key,
|
|
19
|
-
descriptor,
|
|
20
|
-
targetOption: { ...targetOption, type }
|
|
21
|
-
});
|
|
22
|
-
setTargetMetaMapOnPrototype(prototype, metadataMap);
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
const Target = {
|
|
26
|
-
Public: getTarget("public"),
|
|
27
|
-
Cloud: getTarget("cloud"),
|
|
28
|
-
Dev: getTarget("dev")
|
|
29
|
-
};
|
|
30
|
-
export {
|
|
31
|
-
Target,
|
|
32
|
-
getTargetMetas
|
|
33
|
-
};
|
|
File without changes
|
package/esm/src/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { homedir } from "os";
|
|
2
|
-
const basePath = `${homedir()}/.akan`;
|
|
3
|
-
const configPath = `${basePath}/config.json`;
|
|
4
|
-
const akanCloudHost = process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? "http://localhost" : "https://cloud.akanjs.com";
|
|
5
|
-
const akanCloudBackendUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":8080" : ""}/backend`;
|
|
6
|
-
const akanCloudClientUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":4200" : ""}`;
|
|
7
|
-
const defaultHostConfig = {};
|
|
8
|
-
const defaultAkanGlobalConfig = { cloudHost: {}, llm: null };
|
|
9
|
-
export {
|
|
10
|
-
akanCloudBackendUrl,
|
|
11
|
-
akanCloudClientUrl,
|
|
12
|
-
akanCloudHost,
|
|
13
|
-
basePath,
|
|
14
|
-
configPath,
|
|
15
|
-
defaultAkanGlobalConfig,
|
|
16
|
-
defaultHostConfig
|
|
17
|
-
};
|
package/esm/src/createTunnel.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createTunnel as create } from "tunnel-ssh";
|
|
2
|
-
const getSshTunnelOptions = (app, environment) => {
|
|
3
|
-
const { serveDomain, repoName } = app.workspace.getBaseDevEnv();
|
|
4
|
-
return {
|
|
5
|
-
host: `${app.name}-${environment}.${serveDomain}`,
|
|
6
|
-
port: process.env.SSH_TUNNEL_PORT ? parseInt(process.env.SSH_TUNNEL_PORT) : 32767,
|
|
7
|
-
username: process.env.SSH_TUNNEL_USERNAME ?? "root",
|
|
8
|
-
password: process.env.SSH_TUNNEL_PASSWORD ?? repoName
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
const createTunnel = async ({ app, environment, port = 27017 }) => {
|
|
12
|
-
const tunnelOptions = { autoClose: true, reconnectOnError: true };
|
|
13
|
-
const sshOptions = getSshTunnelOptions(app, environment);
|
|
14
|
-
const serverOptions = { port };
|
|
15
|
-
const forwardOptions = {
|
|
16
|
-
srcAddr: "0.0.0.0",
|
|
17
|
-
srcPort: port,
|
|
18
|
-
dstAddr: `mongo-0.mongo-svc.${app.name}-${environment}`,
|
|
19
|
-
dstPort: 27017
|
|
20
|
-
};
|
|
21
|
-
const [server, client] = await create(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
22
|
-
return `localhost:${port}`;
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
createTunnel
|
|
26
|
-
};
|