@akanjs/devkit 0.0.54 → 0.0.56

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.cjs ADDED
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var devkit_exports = {};
16
+ module.exports = __toCommonJS(devkit_exports);
17
+ __reExport(devkit_exports, require("./src"), module.exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,5 +14,25 @@
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
17
- "dependencies": {}
17
+ "dependencies": {
18
+ "@inquirer/prompts": "^7.2.1",
19
+ "@langchain/core": "^0.3.27",
20
+ "@langchain/openai": "^0.3.16",
21
+ "@nx/devkit": "^20.7.2",
22
+ "@trapezedev/project": "^7.1.3",
23
+ "axios": "^1.7.9",
24
+ "commander": "^13.1.0",
25
+ "form-data": "^4.0.1",
26
+ "js-yaml": "^4.1.0",
27
+ "ora": "^3.4.0",
28
+ "reflect-metadata": "^0.2.2",
29
+ "tunnel-ssh": "^5.2.0",
30
+ "typescript": "^5.8.3"
31
+ },
32
+ "exports": {
33
+ ".": {
34
+ "require": "./index.cjs",
35
+ "import": "./index.js"
36
+ }
37
+ }
18
38
  }
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var aiEditor_exports = {};
19
+ __export(aiEditor_exports, {
20
+ AiEditor: () => AiEditor
21
+ });
22
+ module.exports = __toCommonJS(aiEditor_exports);
23
+ var import_prompts = require("@langchain/core/prompts");
24
+ var import_runnables = require("@langchain/core/runnables");
25
+ var import_openai = require("@langchain/openai");
26
+ class AiEditor {
27
+ chat;
28
+ constructor(apiKey = process.env.DEEPSEEK_API_KEY) {
29
+ this.chat = new import_openai.ChatOpenAI({
30
+ modelName: "deepseek-reasoner",
31
+ temperature: 0.7,
32
+ streaming: true,
33
+ // Enable streaming
34
+ configuration: { baseURL: "https://api.deepseek.com/v1", apiKey }
35
+ });
36
+ }
37
+ #createProcessingChain() {
38
+ return import_runnables.RunnableSequence.from([import_prompts.PromptTemplate.fromTemplate(`Answer concisely: {question}`), this.chat]);
39
+ }
40
+ async edit(question) {
41
+ const chain = this.#createProcessingChain();
42
+ const stream = await chain.stream({ question });
43
+ for await (const chunk of stream) {
44
+ }
45
+ }
46
+ }
package/src/auth.cjs ADDED
@@ -0,0 +1,64 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var auth_exports = {};
29
+ __export(auth_exports, {
30
+ getAkanGlobalConfig: () => getAkanGlobalConfig,
31
+ getHostConfig: () => getHostConfig,
32
+ getSelf: () => getSelf,
33
+ setAkanGlobalConfig: () => setAkanGlobalConfig,
34
+ setHostConfig: () => setHostConfig
35
+ });
36
+ module.exports = __toCommonJS(auth_exports);
37
+ var import_fs = __toESM(require("fs"), 1);
38
+ var import_constants = require("./constants");
39
+ const getAkanGlobalConfig = () => {
40
+ const akanConfig = import_fs.default.existsSync(import_constants.configPath) ? JSON.parse(import_fs.default.readFileSync(import_constants.configPath, "utf8")) : import_constants.defaultAkanGlobalConfig;
41
+ return akanConfig;
42
+ };
43
+ const setAkanGlobalConfig = (akanConfig) => {
44
+ import_fs.default.mkdirSync(import_constants.basePath, { recursive: true });
45
+ import_fs.default.writeFileSync(import_constants.configPath, JSON.stringify(akanConfig, null, 2));
46
+ };
47
+ const getHostConfig = (host = import_constants.akanCloudHost) => {
48
+ const akanConfig = getAkanGlobalConfig();
49
+ return akanConfig[host] ?? import_constants.defaultHostConfig;
50
+ };
51
+ const setHostConfig = (host = import_constants.akanCloudHost, config = {}) => {
52
+ const akanConfig = getAkanGlobalConfig();
53
+ akanConfig[host] = config;
54
+ setAkanGlobalConfig(akanConfig);
55
+ };
56
+ const getSelf = async (token) => {
57
+ try {
58
+ const res = await fetch(`${import_constants.akanCloudBackendUrl}/user/getSelf`, { headers: { Authorization: `Bearer ${token}` } });
59
+ const user = await res.json();
60
+ return user;
61
+ } catch (e) {
62
+ return null;
63
+ }
64
+ };
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var baseDevEnv_exports = {};
19
+ __export(baseDevEnv_exports, {
20
+ getBaseDevEnv: () => getBaseDevEnv,
21
+ getSshTunnelOptions: () => getSshTunnelOptions
22
+ });
23
+ module.exports = __toCommonJS(baseDevEnv_exports);
24
+ const getBaseDevEnv = () => {
25
+ const appName = process.env.NEXT_PUBLIC_APP_NAME;
26
+ const repoName = process.env.NEXT_PUBLIC_REPO_NAME;
27
+ if (!repoName)
28
+ throw new Error("NEXT_PUBLIC_REPO_NAME is not set");
29
+ const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN;
30
+ if (!serveDomain)
31
+ throw new Error("NEXT_PUBLIC_SERVE_DOMAIN is not set");
32
+ const env = process.env.NEXT_PUBLIC_ENV ?? "debug";
33
+ if (!env)
34
+ throw new Error("NEXT_PUBLIC_ENV is not set");
35
+ return { ...appName ? { appName } : {}, repoName, serveDomain, env };
36
+ };
37
+ const getSshTunnelOptions = (appName, environment) => {
38
+ const { serveDomain, repoName } = getBaseDevEnv();
39
+ return {
40
+ host: `${appName}-${environment}.${serveDomain}`,
41
+ port: process.env.SSU_TUNNEL_PORT ? parseInt(process.env.SSU_TUNNEL_PORT) : 32767,
42
+ username: process.env.SSU_TUNNEL_USERNAME ?? "root",
43
+ password: process.env.SSU_TUNNEL_PASSWORD ?? repoName
44
+ };
45
+ };
@@ -0,0 +1,153 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var capacitorApp_exports = {};
29
+ __export(capacitorApp_exports, {
30
+ CapacitorApp: () => CapacitorApp
31
+ });
32
+ module.exports = __toCommonJS(capacitorApp_exports);
33
+ var import_common = require("@akanjs/common");
34
+ var import_project = require("@trapezedev/project");
35
+ var import_fs = __toESM(require("fs"), 1);
36
+ class CapacitorApp {
37
+ constructor(app) {
38
+ this.app = app;
39
+ }
40
+ project;
41
+ iosTargetName = "App";
42
+ async init() {
43
+ const project = new import_project.MobileProject(this.app.cwdPath, {
44
+ android: { path: "android" },
45
+ ios: { path: "ios/App" }
46
+ });
47
+ await project.load();
48
+ if (!project.android)
49
+ throw new Error(`Android is not added, Please add platform first
50
+ akan serve-android ${this.app.name}`);
51
+ if (!project.ios)
52
+ throw new Error(`iOS is not added, Please add platform first
53
+ akan serve-ios ${this.app.name}`);
54
+ this.project = project;
55
+ return this;
56
+ }
57
+ async save() {
58
+ await this.project.commit();
59
+ }
60
+ async releaseIos() {
61
+ const isAdded = import_fs.default.existsSync(`${this.app.cwdPath}/ios/App/Podfile`);
62
+ if (!isAdded) {
63
+ await this.app.spawn("npx cap add ios");
64
+ await this.app.spawn("npx @capacitor/assets generate");
65
+ } else
66
+ this.app.log(`iOS already added, skip adding process`);
67
+ await this.app.spawn("cross-env", ["APP_OPERATION_MODE=release", "npx", "cap", "sync", "ios"]);
68
+ }
69
+ async releaseAndroid() {
70
+ const isAdded = import_fs.default.existsSync(`${this.app.cwdPath}/android/app/build.gradle`);
71
+ if (!isAdded) {
72
+ await this.app.spawn("npx cap add android");
73
+ await this.app.spawn("npx @capacitor/assets generate");
74
+ } else
75
+ this.app.log(`android already added, skip adding process`);
76
+ await this.app.spawn("cross-env", ["APP_OPERATION_MODE=release", "npx", "cap", "sync", "android"]);
77
+ }
78
+ async addCamera() {
79
+ await this.#setPermissionInIos({
80
+ cameraUsageDescription: "$(PRODUCT_NAME) requires access to the camera to take photos.",
81
+ photoAddUsageDescription: "$(PRODUCT_NAME) requires access to the photo library to take photos.",
82
+ photoUsageDescription: "$(PRODUCT_NAME) requires access to the photo library to take photos."
83
+ });
84
+ this.#setPermissionsInAndroid(["READ_MEDIA_IMAGES", "READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"]);
85
+ }
86
+ async addContact() {
87
+ await this.#setPermissionInIos({
88
+ contactsUsageDescription: "$(PRODUCT_NAME) requires access to the contacts to add new contacts."
89
+ });
90
+ this.#setPermissionsInAndroid(["READ_CONTACTS", "WRITE_CONTACTS"]);
91
+ }
92
+ async addLocation() {
93
+ await this.#setPermissionInIos({
94
+ locationAlwaysUsageDescription: "$(PRODUCT_NAME) requires access to the location to get the user's location.",
95
+ locationWhenInUseUsageDescription: "$(PRODUCT_NAME) requires access to the location to get the user's location."
96
+ });
97
+ this.#setPermissionsInAndroid(["ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION"]);
98
+ this.#setFeaturesInAndroid(["android.hardware.location.gps"]);
99
+ }
100
+ async #setPermissionInIos(permissions) {
101
+ const updateNs = Object.fromEntries(
102
+ Object.entries(permissions).map(([key, value]) => [`NS${(0, import_common.capitalize)(key)}`, value])
103
+ );
104
+ await Promise.all([
105
+ this.project.ios.updateInfoPlist(this.iosTargetName, "Debug", updateNs),
106
+ this.project.ios.updateInfoPlist(this.iosTargetName, "Release", updateNs)
107
+ ]);
108
+ }
109
+ #setFeaturesInAndroid(features) {
110
+ for (const feature of features) {
111
+ if (this.#hasFeatureInAndroid(feature)) {
112
+ this.app.logger.info(`${feature} already exists in android`);
113
+ return this;
114
+ }
115
+ this.app.logger.info(`Adding ${feature} to android`);
116
+ this.project.android.getAndroidManifest().injectFragment("manifest", `<uses-feature android:name="${feature}" />`);
117
+ }
118
+ return this;
119
+ }
120
+ #getFeaturesInAndroid() {
121
+ const androidManifest = this.project.android.getAndroidManifest();
122
+ const element = androidManifest.getDocumentElement();
123
+ if (!element)
124
+ throw new Error("manifest not found");
125
+ const usesFeature = element.getElementsByTagName("uses-feature");
126
+ return Array.from(usesFeature).map((feature) => feature.getAttribute("android:name"));
127
+ }
128
+ #hasFeatureInAndroid(feature) {
129
+ return this.#getFeaturesInAndroid().includes(feature);
130
+ }
131
+ #setPermissionsInAndroid(permissions) {
132
+ for (const permission of permissions) {
133
+ if (this.#hasPermissionInAndroid(permission)) {
134
+ this.app.logger.info(`${permission} already exists in android`);
135
+ return this;
136
+ }
137
+ this.app.logger.info(`Adding ${permission} to android`);
138
+ this.project.android.getAndroidManifest().injectFragment("manifest", `<uses-permission android:name="android.permission.${permission}" />`);
139
+ }
140
+ return this;
141
+ }
142
+ #getPermissionsInAndroid() {
143
+ const androidManifest = this.project.android.getAndroidManifest();
144
+ const element = androidManifest.getDocumentElement();
145
+ if (!element)
146
+ throw new Error("manifest not found");
147
+ const usesPermission = element.getElementsByTagName("uses-permission");
148
+ return Array.from(usesPermission).map((permission) => permission.getAttribute("android:name"));
149
+ }
150
+ #hasPermissionInAndroid(permission) {
151
+ return this.#getPermissionsInAndroid().includes(permission);
152
+ }
153
+ }
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var argMeta_exports = {};
19
+ __export(argMeta_exports, {
20
+ App: () => App,
21
+ Lib: () => Lib,
22
+ Option: () => Option,
23
+ Pkg: () => Pkg,
24
+ Sys: () => Sys,
25
+ Workspace: () => Workspace,
26
+ argTypes: () => argTypes,
27
+ getArgMetas: () => getArgMetas,
28
+ internalArgTypes: () => internalArgTypes
29
+ });
30
+ module.exports = __toCommonJS(argMeta_exports);
31
+ var import_reflect_metadata = require("reflect-metadata");
32
+ const argTypes = ["Option"];
33
+ const internalArgTypes = ["Workspace", "App", "Lib", "Sys", "Pkg"];
34
+ const getArgMetas = (command, key) => {
35
+ const allArgMetas = getArgMetasOnPrototype(command.prototype, key);
36
+ const argMetas = allArgMetas.filter((argMeta) => argMeta.type === "Option");
37
+ const internalArgMetas = allArgMetas.filter((argMeta) => argMeta.type !== "Option");
38
+ return [allArgMetas, argMetas, internalArgMetas];
39
+ };
40
+ const getArgMetasOnPrototype = (prototype, key) => {
41
+ return Reflect.getMetadata("args", prototype, key) ?? [];
42
+ };
43
+ const setArgMetasOnPrototype = (prototype, key, argMetas) => {
44
+ Reflect.defineMetadata("args", argMetas, prototype, key);
45
+ };
46
+ const getArg = (type) => function(name, argsOption = {}) {
47
+ return function(prototype, key, idx) {
48
+ const argMetas = getArgMetasOnPrototype(prototype, key);
49
+ argMetas[idx] = { name, argsOption, key, idx, type };
50
+ setArgMetasOnPrototype(prototype, key, argMetas);
51
+ };
52
+ };
53
+ const Option = getArg("Option");
54
+ const createArgMetaDecorator = (type) => {
55
+ return function(option = {}) {
56
+ return function(prototype, key, idx) {
57
+ const argMetas = getArgMetasOnPrototype(prototype, key);
58
+ argMetas[idx] = { key, idx, type, option };
59
+ setArgMetasOnPrototype(prototype, key, argMetas);
60
+ };
61
+ };
62
+ };
63
+ const App = createArgMetaDecorator("App");
64
+ const Lib = createArgMetaDecorator("Lib");
65
+ const Sys = createArgMetaDecorator("Sys");
66
+ const Pkg = createArgMetaDecorator("Pkg");
67
+ const Workspace = createArgMetaDecorator("Workspace");
@@ -0,0 +1,160 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var command_exports = {};
19
+ __export(command_exports, {
20
+ runCommands: () => runCommands
21
+ });
22
+ module.exports = __toCommonJS(command_exports);
23
+ var import_prompts = require("@inquirer/prompts");
24
+ var import_commander = require("commander");
25
+ var import_executors = require("../executors");
26
+ var import_argMeta = require("./argMeta");
27
+ var import_targetMeta = require("./targetMeta");
28
+ const camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
29
+ const handleOption = (programCommand, argMeta) => {
30
+ const {
31
+ type,
32
+ flag = argMeta.name.slice(0, 1).toLowerCase(),
33
+ desc = argMeta.name,
34
+ example,
35
+ enum: choices,
36
+ ask
37
+ } = argMeta.argsOption;
38
+ const kebabName = camelToKebabCase(argMeta.name);
39
+ programCommand.option(
40
+ `-${flag}, --${kebabName} <${kebabName}>`,
41
+ `${desc}${ask ? ` (${ask})` : ""}${example ? ` (example: ${example})` : ""}${choices ? ` (choices: ${choices.join(", ")})` : ""}`
42
+ );
43
+ return programCommand;
44
+ };
45
+ const convertOptionValue = (value, type) => {
46
+ if (type === "string")
47
+ return value;
48
+ else if (type === "number")
49
+ return Number(value);
50
+ else
51
+ return value === "true";
52
+ };
53
+ const getOptionValue = async (argMeta, opt) => {
54
+ const {
55
+ name,
56
+ argsOption: { enum: choices, default: defaultValue, type, desc, nullable, example, ask }
57
+ } = argMeta;
58
+ if (opt[argMeta.name] !== void 0)
59
+ return convertOptionValue(opt[argMeta.name], type ?? "string");
60
+ else if (defaultValue !== void 0)
61
+ return defaultValue;
62
+ else if (nullable)
63
+ return null;
64
+ if (choices) {
65
+ const choice = await (0, import_prompts.select)({
66
+ message: ask ?? `Select the ${name} value`,
67
+ choices: choices.map((choice2) => choice2.toString())
68
+ });
69
+ return choice;
70
+ } else if (type === "boolean") {
71
+ const message = ask ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
72
+ return await (0, import_prompts.confirm)({ message });
73
+ } else {
74
+ const message = ask ?? `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
75
+ if (argMeta.argsOption.nullable)
76
+ return await (0, import_prompts.input)({ message });
77
+ else
78
+ return convertOptionValue(await (0, import_prompts.input)({ message }), type ?? "string");
79
+ }
80
+ };
81
+ const getArgumentValue = async (argMeta, value, workspace) => {
82
+ if (argMeta.type === "Workspace")
83
+ return workspace;
84
+ const sysType = argMeta.type.toLowerCase();
85
+ if (sysType === "sys") {
86
+ const [appNames, libNames] = await workspace.getSyss();
87
+ const sysName = await (0, import_prompts.select)({
88
+ message: `Select the App or Lib name`,
89
+ choices: [...appNames, ...libNames]
90
+ });
91
+ if (appNames.includes(sysName))
92
+ return import_executors.AppExecutor.from(workspace, sysName);
93
+ else
94
+ return import_executors.LibExecutor.from(workspace, sysName);
95
+ } else if (sysType === "app") {
96
+ if (value)
97
+ return import_executors.AppExecutor.from(workspace, value);
98
+ const apps = await workspace.getApps();
99
+ const appName = await (0, import_prompts.select)({ message: `Select the ${sysType} name`, choices: apps });
100
+ return import_executors.AppExecutor.from(workspace, appName);
101
+ } else if (sysType === "lib") {
102
+ if (value)
103
+ return import_executors.LibExecutor.from(workspace, value);
104
+ const libs = await workspace.getLibs();
105
+ const libName = await (0, import_prompts.select)({ message: `Select the ${sysType} name`, choices: libs });
106
+ return import_executors.LibExecutor.from(workspace, libName);
107
+ } else if (sysType === "pkg") {
108
+ if (value)
109
+ return import_executors.PkgExecutor.from(workspace, value);
110
+ const pkgs = await workspace.getPkgs();
111
+ const pkgName = await (0, import_prompts.select)({ message: `Select the ${sysType} name`, choices: pkgs });
112
+ return import_executors.PkgExecutor.from(workspace, pkgName);
113
+ } else
114
+ throw new Error(`Invalid system type: ${argMeta.type}`);
115
+ };
116
+ const runCommands = async (...commands) => {
117
+ import_commander.program.version("0.0.1").description("An example CLI for managing a directory");
118
+ for (const command of commands) {
119
+ const targetMetas = (0, import_targetMeta.getTargetMetas)(command);
120
+ for (const targetMeta of targetMetas) {
121
+ const kebabKey = camelToKebabCase(targetMeta.key);
122
+ const commandNames = targetMeta.targetOption.short === true ? [
123
+ kebabKey,
124
+ typeof targetMeta.targetOption.short === "string" ? targetMeta.targetOption.short : kebabKey.split("-").map((s) => s.slice(0, 1)).join("")
125
+ ] : [kebabKey];
126
+ for (const commandName of commandNames) {
127
+ let programCommand = import_commander.program.command(commandName, {
128
+ hidden: targetMeta.targetOption.devOnly
129
+ });
130
+ const [allArgMetas] = (0, import_argMeta.getArgMetas)(command, targetMeta.key);
131
+ for (const argMeta of allArgMetas) {
132
+ if (argMeta.type === "Option")
133
+ programCommand = handleOption(programCommand, argMeta);
134
+ else if (argMeta.type === "Workspace")
135
+ continue;
136
+ const sysType = argMeta.type.toLowerCase();
137
+ programCommand = programCommand.argument(
138
+ `[${sysType}]`,
139
+ `${sysType} in this workspace ${sysType}s/<${sysType}Name>`
140
+ );
141
+ }
142
+ programCommand.action(async (...args) => {
143
+ const cmdArgs = args.slice(0, args.length - 2);
144
+ const opt = args[args.length - 2];
145
+ const commandArgs = [];
146
+ const workspace = import_executors.WorkspaceExecutor.fromRoot();
147
+ for (const argMeta of allArgMetas) {
148
+ if (argMeta.type === "Option")
149
+ commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt);
150
+ else
151
+ commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace);
152
+ }
153
+ const cmd = new command();
154
+ await cmd[targetMeta.key](...commandArgs);
155
+ });
156
+ }
157
+ }
158
+ }
159
+ await import_commander.program.parseAsync(process.argv);
160
+ };
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var commandMeta_exports = {};
19
+ __export(commandMeta_exports, {
20
+ Commands: () => Commands
21
+ });
22
+ module.exports = __toCommonJS(commandMeta_exports);
23
+ const Commands = () => {
24
+ return function(target) {
25
+ };
26
+ };
@@ -0,0 +1,21 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var commandDecorators_exports = {};
16
+ module.exports = __toCommonJS(commandDecorators_exports);
17
+ __reExport(commandDecorators_exports, require("./argMeta"), module.exports);
18
+ __reExport(commandDecorators_exports, require("./commandMeta"), module.exports);
19
+ __reExport(commandDecorators_exports, require("./targetMeta"), module.exports);
20
+ __reExport(commandDecorators_exports, require("./types"), module.exports);
21
+ __reExport(commandDecorators_exports, require("./command"), module.exports);