@akanjs/devkit 0.0.44 → 0.0.46
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 +1455 -1865
- package/package.json +1 -5
package/index.js
CHANGED
|
@@ -1,1957 +1,1547 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
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);
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
// pkgs/@akanjs/devkit/index.ts
|
|
30
|
+
var devkit_exports = {};
|
|
31
|
+
__export(devkit_exports, {
|
|
32
|
+
App: () => App,
|
|
33
|
+
AppExecutor: () => AppExecutor,
|
|
34
|
+
CapacitorApp: () => CapacitorApp,
|
|
35
|
+
Commands: () => Commands,
|
|
36
|
+
DistAppExecutor: () => DistAppExecutor,
|
|
37
|
+
DistLibExecutor: () => DistLibExecutor,
|
|
38
|
+
DistPkgExecutor: () => DistPkgExecutor,
|
|
39
|
+
Executor: () => Executor,
|
|
40
|
+
Lib: () => Lib,
|
|
41
|
+
LibExecutor: () => LibExecutor,
|
|
42
|
+
Option: () => Option,
|
|
43
|
+
Pkg: () => Pkg,
|
|
44
|
+
PkgExecutor: () => PkgExecutor,
|
|
45
|
+
Sys: () => Sys,
|
|
46
|
+
SysExecutor: () => SysExecutor,
|
|
47
|
+
Target: () => Target,
|
|
48
|
+
TypeScriptDependencyScanner: () => TypeScriptDependencyScanner,
|
|
49
|
+
Workspace: () => Workspace,
|
|
50
|
+
WorkspaceExecutor: () => WorkspaceExecutor,
|
|
51
|
+
akanCloudBackendUrl: () => akanCloudBackendUrl,
|
|
52
|
+
akanCloudClientUrl: () => akanCloudClientUrl,
|
|
53
|
+
akanCloudHost: () => akanCloudHost,
|
|
54
|
+
argTypes: () => argTypes,
|
|
55
|
+
basePath: () => basePath,
|
|
56
|
+
configPath: () => configPath,
|
|
57
|
+
createTunnel: () => createTunnel,
|
|
58
|
+
defaultAkanGlobalConfig: () => defaultAkanGlobalConfig,
|
|
59
|
+
defaultHostConfig: () => defaultHostConfig,
|
|
60
|
+
extractDependencies: () => extractDependencies,
|
|
61
|
+
getAkanGlobalConfig: () => getAkanGlobalConfig,
|
|
62
|
+
getArgMetas: () => getArgMetas,
|
|
63
|
+
getBaseDevEnv: () => getBaseDevEnv,
|
|
64
|
+
getCredentials: () => getCredentials,
|
|
65
|
+
getDependencies: () => getDependencies,
|
|
66
|
+
getHostConfig: () => getHostConfig,
|
|
67
|
+
getModelFileData: () => getModelFileData,
|
|
68
|
+
getRelatedCnsts: () => getRelatedCnsts,
|
|
69
|
+
getSelf: () => getSelf,
|
|
70
|
+
getSshTunnelOptions: () => getSshTunnelOptions,
|
|
71
|
+
getTargetMetas: () => getTargetMetas,
|
|
72
|
+
installExternalLib: () => installExternalLib,
|
|
73
|
+
internalArgTypes: () => internalArgTypes,
|
|
74
|
+
runCommands: () => runCommands,
|
|
75
|
+
selectModel: () => selectModel,
|
|
76
|
+
setAkanGlobalConfig: () => setAkanGlobalConfig,
|
|
77
|
+
setHostConfig: () => setHostConfig,
|
|
78
|
+
streamAi: () => streamAi,
|
|
79
|
+
uploadRelease: () => uploadRelease
|
|
80
|
+
});
|
|
81
|
+
module.exports = __toCommonJS(devkit_exports);
|
|
55
82
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
// pkgs/@akanjs/devkit/src/baseDevEnv.ts
|
|
84
|
+
var getBaseDevEnv = () => {
|
|
85
|
+
const appName = process.env.NEXT_PUBLIC_APP_NAME;
|
|
86
|
+
const repoName = process.env.NEXT_PUBLIC_REPO_NAME;
|
|
87
|
+
if (!repoName)
|
|
88
|
+
throw new Error("NEXT_PUBLIC_REPO_NAME is not set");
|
|
89
|
+
const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN;
|
|
90
|
+
if (!serveDomain)
|
|
91
|
+
throw new Error("NEXT_PUBLIC_SERVE_DOMAIN is not set");
|
|
92
|
+
const env = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
93
|
+
if (!env)
|
|
94
|
+
throw new Error("NEXT_PUBLIC_ENV is not set");
|
|
95
|
+
return { ...appName ? { appName } : {}, repoName, serveDomain, env };
|
|
96
|
+
};
|
|
97
|
+
var getSshTunnelOptions = (appName, environment) => {
|
|
98
|
+
const { serveDomain, repoName } = getBaseDevEnv();
|
|
99
|
+
return {
|
|
100
|
+
host: `${appName}-${environment}.${serveDomain}`,
|
|
101
|
+
port: process.env.SSU_TUNNEL_PORT ? parseInt(process.env.SSU_TUNNEL_PORT) : 32767,
|
|
102
|
+
username: process.env.SSU_TUNNEL_USERNAME ?? "root",
|
|
103
|
+
password: process.env.SSU_TUNNEL_PASSWORD ?? repoName
|
|
70
104
|
};
|
|
105
|
+
};
|
|
71
106
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
107
|
+
// pkgs/@akanjs/devkit/src/createTunnel.ts
|
|
108
|
+
var import_tunnel_ssh = require("tunnel-ssh");
|
|
109
|
+
var createTunnel = async ({ appName, environment, port = 27017 }) => {
|
|
110
|
+
const tunnelOptions = { autoClose: true, reconnectOnError: true };
|
|
111
|
+
const sshOptions = getSshTunnelOptions(appName, environment);
|
|
112
|
+
const serverOptions = { port };
|
|
113
|
+
const forwardOptions = {
|
|
114
|
+
srcAddr: "0.0.0.0",
|
|
115
|
+
srcPort: port,
|
|
116
|
+
dstAddr: `mongo-0.mongo-svc.${appName}-${environment}`,
|
|
117
|
+
dstPort: 27017
|
|
80
118
|
};
|
|
119
|
+
const [server, client] = await (0, import_tunnel_ssh.createTunnel)(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
120
|
+
return `localhost:${port}`;
|
|
121
|
+
};
|
|
81
122
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
// pkgs/@akanjs/devkit/src/getCredentials.ts
|
|
124
|
+
var import_fs = __toESM(require("fs"));
|
|
125
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
126
|
+
var getCredentials = (app, environment) => {
|
|
127
|
+
const secret = import_js_yaml.default.load(
|
|
128
|
+
import_fs.default.readFileSync(`${app.workspace.workspaceRoot}/infra/app/values/${app.name}-secret.yaml`, "utf-8")
|
|
129
|
+
);
|
|
130
|
+
return secret[environment];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// pkgs/@akanjs/devkit/src/getDependencies.ts
|
|
134
|
+
var import_devkit = require("@nx/devkit");
|
|
135
|
+
var addLibDepSet = (depName, { libDepSet, npmDepSet, dependencies }) => {
|
|
136
|
+
const deps = dependencies[depName];
|
|
137
|
+
if (!deps)
|
|
138
|
+
throw new Error(`No dependencies found for project or library ${depName}`);
|
|
139
|
+
for (const dep of deps) {
|
|
140
|
+
if (dep.target.startsWith("npm:"))
|
|
141
|
+
npmDepSet.add(dep.target);
|
|
142
|
+
else if (libDepSet.has(dep.target))
|
|
143
|
+
continue;
|
|
144
|
+
else {
|
|
145
|
+
libDepSet.add(dep.target);
|
|
146
|
+
addLibDepSet(dep.target, { libDepSet, npmDepSet, dependencies });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var getDependencies = async (projectName) => {
|
|
151
|
+
const graph = await (0, import_devkit.createProjectGraphAsync)();
|
|
152
|
+
const [libDepSet, npmDepSet] = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
|
|
153
|
+
const dependencies = graph.dependencies;
|
|
154
|
+
const projectDeps = dependencies[projectName];
|
|
155
|
+
if (!projectDeps)
|
|
156
|
+
throw new Error(`No dependencies found for project ${projectName}`);
|
|
157
|
+
addLibDepSet(projectName, { libDepSet, npmDepSet, dependencies });
|
|
158
|
+
return {
|
|
159
|
+
libDeps: [...libDepSet.values()],
|
|
160
|
+
npmDeps: [...npmDepSet.values()].map((depName) => depName.replace("npm:", ""))
|
|
111
161
|
};
|
|
162
|
+
};
|
|
112
163
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
164
|
+
// pkgs/@akanjs/devkit/src/uploadRelease.ts
|
|
165
|
+
var import_axios = __toESM(require("axios"));
|
|
166
|
+
var import_form_data = __toESM(require("form-data"));
|
|
167
|
+
var import_fs2 = __toESM(require("fs"));
|
|
168
|
+
var uploadRelease = async (projectName, {
|
|
169
|
+
workspaceRoot,
|
|
170
|
+
environment,
|
|
171
|
+
buildNum,
|
|
172
|
+
platformVersion,
|
|
173
|
+
local
|
|
174
|
+
}) => {
|
|
175
|
+
const basePath2 = local ? "http://localhost:8080/backend" : "https://akasys.akamir.com/backend";
|
|
176
|
+
const buildPath = `${workspaceRoot}/releases/builds/${projectName}-release.tar.gz`;
|
|
177
|
+
const appBuildPath = `${workspaceRoot}/releases/builds/${projectName}-appBuild.zip`;
|
|
178
|
+
const sourcePath = `${workspaceRoot}/releases/sources/${projectName}-source.tar.gz`;
|
|
179
|
+
const formData = new import_form_data.default();
|
|
180
|
+
const build = import_fs2.default.readFileSync(buildPath);
|
|
181
|
+
const source = import_fs2.default.readFileSync(sourcePath);
|
|
182
|
+
const appBuild = import_fs2.default.readFileSync(appBuildPath);
|
|
183
|
+
const buildStat = import_fs2.default.statSync(buildPath);
|
|
184
|
+
const sourceStat = import_fs2.default.statSync(sourcePath);
|
|
185
|
+
const appBuildStat = import_fs2.default.statSync(appBuildPath);
|
|
186
|
+
formData.append("files", build, `${projectName}-release.tar.gz`);
|
|
187
|
+
formData.append("files", source, `${projectName}-source.tar.gz`);
|
|
188
|
+
formData.append("files", appBuild, `${projectName}-appBuild.zip`);
|
|
189
|
+
formData.append(
|
|
190
|
+
"metas",
|
|
191
|
+
JSON.stringify([
|
|
192
|
+
{ lastModifiedAt: buildStat.mtime, size: buildStat.size },
|
|
193
|
+
{ lastModifiedAt: sourceStat.mtime, size: sourceStat.size },
|
|
194
|
+
{ lastModifiedAt: appBuildStat.mtime, size: appBuildStat.size }
|
|
195
|
+
])
|
|
196
|
+
);
|
|
197
|
+
formData.append("type", "release");
|
|
198
|
+
try {
|
|
199
|
+
const [buildFile, sourceFile, appBuildFile] = (await import_axios.default.post(`${basePath2}/file/addFilesRestApi`, formData)).data;
|
|
200
|
+
const major = platformVersion ? parseInt(platformVersion.split(".")[0]) : 1;
|
|
201
|
+
const minor = platformVersion ? parseInt(platformVersion.split(".")[1]) : 0;
|
|
202
|
+
const patch = platformVersion ? parseInt(platformVersion.split(".")[2]) : 0;
|
|
203
|
+
const latestRelease = await import_axios.default.get(
|
|
204
|
+
`${basePath2}/release/findVersionRelease?appName=${projectName}&branch=${environment}&major=${major}&minor=${minor}`
|
|
145
205
|
);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
const release = (await import_axios.default.post(
|
|
156
|
-
`${basePath2}/release/pushRelease/${projectName}/${environment}/${major}/${minor}/${sourceFile.id}/${buildFile.id}/${appBuildFile.id}`
|
|
157
|
-
)).data;
|
|
158
|
-
return release;
|
|
159
|
-
} catch (e) {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
206
|
+
const release = (await import_axios.default.post(
|
|
207
|
+
`${basePath2}/release/pushRelease/${projectName}/${environment}/${major}/${minor}/${sourceFile.id}/${buildFile.id}/${appBuildFile.id}`
|
|
208
|
+
)).data;
|
|
209
|
+
return release;
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
163
214
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
};
|
|
215
|
+
// pkgs/@akanjs/devkit/src/getModelFileData.ts
|
|
216
|
+
var import_fs3 = __toESM(require("fs"));
|
|
217
|
+
var getModelFileData = (modulePath, modelName) => {
|
|
218
|
+
const moduleType = modulePath.startsWith("apps") ? "app" : "lib";
|
|
219
|
+
const moduleName = modulePath.split("/")[1];
|
|
220
|
+
const constantFilePath = `${modulePath}/lib/${modelName}/${modelName}.constant.ts`;
|
|
221
|
+
const unitFilePath = `${modulePath}/lib/${modelName}/${modelName}.Unit.tsx`;
|
|
222
|
+
const viewFilePath = `${modulePath}/lib/${modelName}/${modelName}.View.tsx`;
|
|
223
|
+
const constantFileStr = import_fs3.default.readFileSync(constantFilePath, "utf8");
|
|
224
|
+
const unitFileStr = import_fs3.default.readFileSync(unitFilePath, "utf8");
|
|
225
|
+
const viewFileStr = import_fs3.default.readFileSync(viewFilePath, "utf8");
|
|
226
|
+
const constantFileLines = constantFileStr.split("\n");
|
|
227
|
+
const importLibNames = constantFileLines.filter((line) => line.startsWith("import { cnst as ")).map((line) => line.split("cnst as ")[1].split(" ")[0]);
|
|
228
|
+
const importLocalPaths = constantFileLines.filter((line) => line.startsWith("import { ") && line.includes('from "../')).map((line) => line.split("from ")[1].split('"')[1]);
|
|
229
|
+
const importModelNames = importLocalPaths.map((path3) => path3.split("/")[1]).filter((name) => !name.startsWith("_"));
|
|
230
|
+
const hasImportScalar = !!importLocalPaths.map((path3) => path3.split("/")[1]).filter((name) => name.startsWith("_")).length;
|
|
231
|
+
return {
|
|
232
|
+
moduleType,
|
|
233
|
+
moduleName,
|
|
234
|
+
modelName,
|
|
235
|
+
constantFilePath,
|
|
236
|
+
unitFilePath,
|
|
237
|
+
viewFilePath,
|
|
238
|
+
importModelNames,
|
|
239
|
+
hasImportScalar,
|
|
240
|
+
importLibNames,
|
|
241
|
+
constantFileStr,
|
|
242
|
+
unitFileStr,
|
|
243
|
+
viewFileStr
|
|
194
244
|
};
|
|
245
|
+
};
|
|
195
246
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
247
|
+
// pkgs/@akanjs/devkit/src/getRelatedCnsts.ts
|
|
248
|
+
var import_fs4 = __toESM(require("fs"));
|
|
249
|
+
var import_ora = __toESM(require("ora"));
|
|
250
|
+
var ts = __toESM(require("typescript"));
|
|
251
|
+
var getRelatedCnsts = (constantFilePath) => {
|
|
252
|
+
const tsConfigPath = `./tsconfig.json`;
|
|
253
|
+
const configFile = ts.readConfigFile(tsConfigPath, (path3) => {
|
|
254
|
+
return ts.sys.readFile(path3);
|
|
255
|
+
});
|
|
256
|
+
const parsedConfig = ts.parseJsonConfigFileContent(
|
|
257
|
+
configFile.config,
|
|
258
|
+
ts.sys,
|
|
259
|
+
import_fs4.default.realpathSync(tsConfigPath).replace(/[^/\\]+$/, "")
|
|
260
|
+
);
|
|
261
|
+
const propertyMap = /* @__PURE__ */ new Map();
|
|
262
|
+
function findPropertyOriginAll(filePath) {
|
|
263
|
+
const program2 = ts.createProgram([filePath], parsedConfig.options);
|
|
264
|
+
const checker = program2.getTypeChecker();
|
|
265
|
+
const source = program2.getSourceFile(filePath);
|
|
266
|
+
if (!source)
|
|
267
|
+
return null;
|
|
268
|
+
function visit(node) {
|
|
215
269
|
if (!source)
|
|
216
|
-
return
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
isLibModule: true,
|
|
236
|
-
isImport: false,
|
|
237
|
-
libName: left.text,
|
|
238
|
-
isScalar
|
|
239
|
-
});
|
|
240
|
-
} else
|
|
241
|
-
propertyMap.set(key, {
|
|
242
|
-
filePath: filePath2,
|
|
243
|
-
isLibModule: true,
|
|
244
|
-
isImport: false,
|
|
245
|
-
libName: left.text,
|
|
246
|
-
isScalar
|
|
247
|
-
});
|
|
248
|
-
findPropertyOriginAll(filePath2);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
} else if (ts.isImportDeclaration(node)) {
|
|
252
|
-
const importPath = node.moduleSpecifier.getText().slice(1, -1);
|
|
253
|
-
if (importPath.startsWith(".")) {
|
|
254
|
-
const resolved = ts.resolveModuleName(importPath, filePath, parsedConfig.options, ts.sys).resolvedModule?.resolvedFileName;
|
|
255
|
-
const moduleName = importPath.split("/").pop()?.split(".")[0] ?? "";
|
|
256
|
-
const property = propertyMap.get(moduleName);
|
|
257
|
-
const isScalar = importPath.includes("_");
|
|
258
|
-
if (moduleName && resolved && (!property || property.filePath !== resolved)) {
|
|
259
|
-
propertyMap.set(moduleName, {
|
|
260
|
-
filePath: resolved,
|
|
261
|
-
isLibModule: false,
|
|
262
|
-
isImport: true,
|
|
270
|
+
return;
|
|
271
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
272
|
+
const left = node.expression;
|
|
273
|
+
const right = node.name;
|
|
274
|
+
const { line } = ts.getLineAndCharacterOfPosition(source, node.getStart());
|
|
275
|
+
const sourceLines = source.getFullText().split("\n");
|
|
276
|
+
if (ts.isIdentifier(left) && sourceLines.length && (sourceLines[line].includes(`@Field.Prop(() => ${left.text}.${right.text}`) || sourceLines[line].includes(`base.Filter(${left.text}.${right.text},`))) {
|
|
277
|
+
const symbol = checker.getSymbolAtLocation(right);
|
|
278
|
+
if (symbol?.declarations && symbol.declarations.length > 0) {
|
|
279
|
+
const key = symbol.declarations[0].getSourceFile().fileName.split("/").pop()?.split(".")[0] ?? "";
|
|
280
|
+
const property = propertyMap.get(key);
|
|
281
|
+
const isScalar = symbol.declarations[0].getSourceFile().fileName.includes("_");
|
|
282
|
+
const filePath2 = symbol.declarations[0].getSourceFile().fileName.replace(`${ts.sys.getCurrentDirectory()}/`, "");
|
|
283
|
+
if (property) {
|
|
284
|
+
propertyMap.set(`${left.text}.${right.text}`, {
|
|
285
|
+
filePath: filePath2,
|
|
286
|
+
isLibModule: true,
|
|
287
|
+
isImport: false,
|
|
288
|
+
libName: left.text,
|
|
263
289
|
isScalar
|
|
264
290
|
});
|
|
265
|
-
|
|
266
|
-
|
|
291
|
+
} else
|
|
292
|
+
propertyMap.set(key, {
|
|
293
|
+
filePath: filePath2,
|
|
294
|
+
isLibModule: true,
|
|
295
|
+
isImport: false,
|
|
296
|
+
libName: left.text,
|
|
297
|
+
isScalar
|
|
298
|
+
});
|
|
299
|
+
findPropertyOriginAll(filePath2);
|
|
267
300
|
}
|
|
268
301
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const right = node.name;
|
|
285
|
-
if (ts.isIdentifier(left) && left.text === aliasName && right.text === libName) {
|
|
286
|
-
const symbol = checker.getSymbolAtLocation(right);
|
|
287
|
-
if (symbol?.declarations && symbol.declarations.length > 0) {
|
|
288
|
-
return symbol.declarations[0].getSourceFile().fileName;
|
|
289
|
-
}
|
|
302
|
+
} else if (ts.isImportDeclaration(node)) {
|
|
303
|
+
const importPath = node.moduleSpecifier.getText().slice(1, -1);
|
|
304
|
+
if (importPath.startsWith(".")) {
|
|
305
|
+
const resolved = ts.resolveModuleName(importPath, filePath, parsedConfig.options, ts.sys).resolvedModule?.resolvedFileName;
|
|
306
|
+
const moduleName = importPath.split("/").pop()?.split(".")[0] ?? "";
|
|
307
|
+
const property = propertyMap.get(moduleName);
|
|
308
|
+
const isScalar = importPath.includes("_");
|
|
309
|
+
if (moduleName && resolved && (!property || property.filePath !== resolved)) {
|
|
310
|
+
propertyMap.set(moduleName, {
|
|
311
|
+
filePath: resolved,
|
|
312
|
+
isLibModule: false,
|
|
313
|
+
isImport: true,
|
|
314
|
+
isScalar
|
|
315
|
+
});
|
|
316
|
+
findPropertyOriginAll(resolved);
|
|
290
317
|
}
|
|
291
318
|
}
|
|
292
|
-
return ts.forEachChild(node, visit) || null;
|
|
293
319
|
}
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
// pkgs/@akanjs/devkit/src/streamAi.ts
|
|
316
|
-
var import_prompts2 = __require("@langchain/core/prompts");
|
|
317
|
-
var import_runnables = __require("@langchain/core/runnables");
|
|
318
|
-
var import_openai = __require("@langchain/openai");
|
|
319
|
-
var streamAi = async (question, callback) => {
|
|
320
|
-
const createStreamingModel = (apiKey = process.env.DEEPSEEK_API_KEY) => {
|
|
321
|
-
if (!apiKey)
|
|
322
|
-
throw new Error(`process.env.DEEPSEEK_API_KEY is not set`);
|
|
323
|
-
return new import_openai.ChatOpenAI({
|
|
324
|
-
modelName: "deepseek-reasoner",
|
|
325
|
-
temperature: 0.7,
|
|
326
|
-
streaming: true,
|
|
327
|
-
// Enable streaming
|
|
328
|
-
configuration: { baseURL: "https://api.deepseek.com/v1", apiKey }
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
const createProcessingChain = () => {
|
|
332
|
-
return import_runnables.RunnableSequence.from([import_prompts2.PromptTemplate.fromTemplate(`Answer concisely: {question}`), createStreamingModel()]);
|
|
333
|
-
};
|
|
334
|
-
try {
|
|
335
|
-
const chain = createProcessingChain();
|
|
336
|
-
const stream = await chain.stream({ question });
|
|
337
|
-
let fullResponse = "";
|
|
338
|
-
for await (const chunk of stream) {
|
|
339
|
-
const content = chunk.content;
|
|
340
|
-
if (typeof content === "string") {
|
|
341
|
-
fullResponse += content;
|
|
342
|
-
callback(content);
|
|
320
|
+
ts.forEachChild(node, visit);
|
|
321
|
+
}
|
|
322
|
+
visit(source);
|
|
323
|
+
return propertyMap;
|
|
324
|
+
}
|
|
325
|
+
function findPropertyOrigin(filePath, aliasName, libName) {
|
|
326
|
+
const program2 = ts.createProgram([filePath], parsedConfig.options);
|
|
327
|
+
const checker = program2.getTypeChecker();
|
|
328
|
+
const source = program2.getSourceFile(filePath);
|
|
329
|
+
const propertyMap2 = /* @__PURE__ */ new Map();
|
|
330
|
+
if (!source)
|
|
331
|
+
return null;
|
|
332
|
+
function visit(node) {
|
|
333
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
334
|
+
const left = node.expression;
|
|
335
|
+
const right = node.name;
|
|
336
|
+
if (ts.isIdentifier(left) && left.text === aliasName && right.text === libName) {
|
|
337
|
+
const symbol = checker.getSymbolAtLocation(right);
|
|
338
|
+
if (symbol?.declarations && symbol.declarations.length > 0) {
|
|
339
|
+
return symbol.declarations[0].getSourceFile().fileName;
|
|
340
|
+
}
|
|
343
341
|
}
|
|
344
342
|
}
|
|
345
|
-
return
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
var import_dayjs2 = __toESM(__require("dayjs"));
|
|
356
|
-
|
|
357
|
-
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
358
|
-
var import_dayjs3 = __toESM(__require("dayjs"));
|
|
359
|
-
var import_customParseFormat = __toESM(__require("dayjs/plugin/customParseFormat"));
|
|
360
|
-
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
361
|
-
|
|
362
|
-
// pkgs/@akanjs/common/src/pluralize.ts
|
|
363
|
-
var import_pluralize = __toESM(__require("pluralize"));
|
|
364
|
-
|
|
365
|
-
// pkgs/@akanjs/common/src/capitalize.ts
|
|
366
|
-
var capitalize = (str) => {
|
|
367
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// pkgs/@akanjs/common/src/Logger.ts
|
|
371
|
-
var import_dayjs4 = __toESM(__require("dayjs"));
|
|
372
|
-
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
373
|
-
var clc = {
|
|
374
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
375
|
-
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
376
|
-
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
377
|
-
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
378
|
-
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
379
|
-
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
380
|
-
};
|
|
381
|
-
var colorizeMap = {
|
|
382
|
-
trace: clc.bold,
|
|
383
|
-
verbose: clc.cyanBright,
|
|
384
|
-
debug: clc.magentaBright,
|
|
385
|
-
log: clc.green,
|
|
386
|
-
info: clc.green,
|
|
387
|
-
warn: clc.yellow,
|
|
388
|
-
error: clc.red
|
|
389
|
-
};
|
|
390
|
-
var Logger = class _Logger {
|
|
391
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
392
|
-
"InstanceLoader",
|
|
393
|
-
"RoutesResolver",
|
|
394
|
-
"RouterExplorer",
|
|
395
|
-
"NestFactory",
|
|
396
|
-
"WebSocketsController",
|
|
397
|
-
"GraphQLModule",
|
|
398
|
-
"NestApplication"
|
|
399
|
-
]);
|
|
400
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
401
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
402
|
-
static #startAt = (0, import_dayjs4.default)();
|
|
403
|
-
static setLevel(level) {
|
|
404
|
-
this.level = level;
|
|
405
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
406
|
-
}
|
|
407
|
-
name;
|
|
408
|
-
constructor(name) {
|
|
409
|
-
this.name = name;
|
|
410
|
-
}
|
|
411
|
-
trace(msg, context = "") {
|
|
412
|
-
if (_Logger.#levelIdx <= 0)
|
|
413
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
414
|
-
}
|
|
415
|
-
verbose(msg, context = "") {
|
|
416
|
-
if (_Logger.#levelIdx <= 1)
|
|
417
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
418
|
-
}
|
|
419
|
-
debug(msg, context = "") {
|
|
420
|
-
if (_Logger.#levelIdx <= 2)
|
|
421
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
422
|
-
}
|
|
423
|
-
log(msg, context = "") {
|
|
424
|
-
if (_Logger.#levelIdx <= 3)
|
|
425
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
426
|
-
}
|
|
427
|
-
info(msg, context = "") {
|
|
428
|
-
if (_Logger.#levelIdx <= 4)
|
|
429
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
430
|
-
}
|
|
431
|
-
warn(msg, context = "") {
|
|
432
|
-
if (_Logger.#levelIdx <= 5)
|
|
433
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
434
|
-
}
|
|
435
|
-
error(msg, context = "") {
|
|
436
|
-
if (_Logger.#levelIdx <= 6)
|
|
437
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
438
|
-
}
|
|
439
|
-
raw(msg, method) {
|
|
440
|
-
_Logger.rawLog(msg, method);
|
|
441
|
-
}
|
|
442
|
-
rawLog(msg, method) {
|
|
443
|
-
_Logger.rawLog(msg, method);
|
|
444
|
-
}
|
|
445
|
-
static trace(msg, context = "") {
|
|
446
|
-
if (_Logger.#levelIdx <= 0)
|
|
447
|
-
_Logger.#printMessages("App", msg, context, "trace");
|
|
448
|
-
}
|
|
449
|
-
static verbose(msg, context = "") {
|
|
450
|
-
if (_Logger.#levelIdx <= 1)
|
|
451
|
-
_Logger.#printMessages("App", msg, context, "verbose");
|
|
452
|
-
}
|
|
453
|
-
static debug(msg, context = "") {
|
|
454
|
-
if (_Logger.#levelIdx <= 2)
|
|
455
|
-
_Logger.#printMessages("App", msg, context, "debug");
|
|
456
|
-
}
|
|
457
|
-
static log(msg, context = "") {
|
|
458
|
-
if (_Logger.#levelIdx <= 3)
|
|
459
|
-
_Logger.#printMessages("App", msg, context, "log");
|
|
460
|
-
}
|
|
461
|
-
static info(msg, context = "") {
|
|
462
|
-
if (_Logger.#levelIdx <= 4)
|
|
463
|
-
_Logger.#printMessages("App", msg, context, "info");
|
|
464
|
-
}
|
|
465
|
-
static warn(msg, context = "") {
|
|
466
|
-
if (_Logger.#levelIdx <= 5)
|
|
467
|
-
_Logger.#printMessages("App", msg, context, "warn");
|
|
468
|
-
}
|
|
469
|
-
static error(msg, context = "") {
|
|
470
|
-
if (_Logger.#levelIdx <= 6)
|
|
471
|
-
_Logger.#printMessages("App", msg, context, "error");
|
|
472
|
-
}
|
|
473
|
-
static #colorize(msg, logLevel) {
|
|
474
|
-
return colorizeMap[logLevel](msg);
|
|
475
|
-
}
|
|
476
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
477
|
-
if (this.#ignoreCtxSet.has(context))
|
|
478
|
-
return;
|
|
479
|
-
const now = (0, import_dayjs4.default)();
|
|
480
|
-
const processMsg = this.#colorize(
|
|
481
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
482
|
-
logLevel
|
|
483
|
-
);
|
|
484
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
485
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
486
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
487
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
488
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
489
|
-
if (typeof window === "undefined")
|
|
490
|
-
process[writeStreamType].write(
|
|
491
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
492
|
-
`
|
|
493
|
-
);
|
|
494
|
-
else
|
|
495
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
496
|
-
`);
|
|
497
|
-
}
|
|
498
|
-
static rawLog(msg, method) {
|
|
499
|
-
this.raw(`${msg}
|
|
500
|
-
`, method);
|
|
501
|
-
}
|
|
502
|
-
static raw(msg, method) {
|
|
503
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
504
|
-
global.process.stdout.write(msg);
|
|
505
|
-
else
|
|
506
|
-
console.log(msg);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
343
|
+
return ts.forEachChild(node, visit) || null;
|
|
344
|
+
}
|
|
345
|
+
return visit(source);
|
|
346
|
+
}
|
|
347
|
+
const spinner = (0, import_ora.default)("Finding property origin...");
|
|
348
|
+
spinner.start();
|
|
349
|
+
const paths = findPropertyOriginAll(constantFilePath);
|
|
350
|
+
spinner.succeed("property origin found.");
|
|
351
|
+
return { paths };
|
|
352
|
+
};
|
|
509
353
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const repoName = process.env.NEXT_PUBLIC_REPO_NAME;
|
|
519
|
-
if (!repoName)
|
|
520
|
-
throw new Error("NEXT_PUBLIC_REPO_NAME is not set");
|
|
521
|
-
const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN;
|
|
522
|
-
if (!serveDomain)
|
|
523
|
-
throw new Error("NEXT_PUBLIC_SERVE_DOMAIN is not set");
|
|
524
|
-
const env = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
525
|
-
if (!env)
|
|
526
|
-
throw new Error("NEXT_PUBLIC_ENV is not set");
|
|
527
|
-
return { appName, repoName, serveDomain, env };
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
// pkgs/@akanjs/config/src/nextConfig.ts
|
|
531
|
-
var import_bundle_analyzer = __toESM(__require("@next/bundle-analyzer"));
|
|
532
|
-
var import_next_pwa = __toESM(__require("next-pwa"));
|
|
533
|
-
var import_cache = __toESM(__require("next-pwa/cache"));
|
|
534
|
-
var import_path = __toESM(__require("path"));
|
|
535
|
-
var composePlugins = (...plugins) => {
|
|
536
|
-
return function(baseConfig) {
|
|
537
|
-
return async function combined(phase, context) {
|
|
538
|
-
let config = baseConfig;
|
|
539
|
-
for (const plugin of plugins) {
|
|
540
|
-
const fn = plugin;
|
|
541
|
-
const configOrFn = fn(config);
|
|
542
|
-
if (typeof configOrFn === "function")
|
|
543
|
-
config = await configOrFn(phase, context);
|
|
544
|
-
else
|
|
545
|
-
config = configOrFn;
|
|
546
|
-
}
|
|
547
|
-
return config;
|
|
548
|
-
};
|
|
549
|
-
};
|
|
550
|
-
};
|
|
551
|
-
var commandType = process.env.AKAN_COMMAND_TYPE?.includes("serve") ? "serve" : process.env.AKAN_COMMAND_TYPE?.includes("build") ? "build" : "deploy";
|
|
552
|
-
var withPWA = (0, import_next_pwa.default)({
|
|
553
|
-
dest: "public",
|
|
554
|
-
register: true,
|
|
555
|
-
skipWaiting: true,
|
|
556
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
557
|
-
runtimeCaching: import_cache.default,
|
|
558
|
-
disable: commandType === "serve"
|
|
354
|
+
// pkgs/@akanjs/devkit/src/selectModel.ts
|
|
355
|
+
var import_prompts = require("@inquirer/prompts");
|
|
356
|
+
var import_fs5 = __toESM(require("fs"));
|
|
357
|
+
var selectModel = async (modulePath) => {
|
|
358
|
+
const modelNames = import_fs5.default.readdirSync(`${modulePath}/lib`).filter((dir) => !dir.includes(".") && !dir.startsWith("_"));
|
|
359
|
+
const modelName = await (0, import_prompts.select)({
|
|
360
|
+
message: "Select the model to create the unit for",
|
|
361
|
+
choices: modelNames.map((name) => ({ name, value: name }))
|
|
559
362
|
});
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
return composePlugins(
|
|
563
|
-
(0, import_bundle_analyzer.default)({ enabled: process.env.ANALYZE === "true" }),
|
|
564
|
-
...commandType !== "serve" || process.env.USE_PWA === "true" ? [withPWA] : []
|
|
565
|
-
)({
|
|
566
|
-
...config,
|
|
567
|
-
eslint: { ...config.eslint, ignoreDuringBuilds: true },
|
|
568
|
-
env: {
|
|
569
|
-
...config.env,
|
|
570
|
-
basePaths: routes.map(({ basePath: basePath2 }) => basePath2).join(",")
|
|
571
|
-
},
|
|
572
|
-
transpilePackages: [
|
|
573
|
-
"swiper",
|
|
574
|
-
"ssr-window",
|
|
575
|
-
"dom7",
|
|
576
|
-
...libs.map((lib) => `@${lib}`),
|
|
577
|
-
"@akanjs/base",
|
|
578
|
-
"@akanjs/common",
|
|
579
|
-
"@akanjs/next",
|
|
580
|
-
"@akanjs/ui",
|
|
581
|
-
"@akanjs/client",
|
|
582
|
-
"@akanjs/server",
|
|
583
|
-
"@akanjs/service",
|
|
584
|
-
"@akanjs/signal",
|
|
585
|
-
"@akanjs/store",
|
|
586
|
-
"@akanjs/dictionary",
|
|
587
|
-
"@akanjs/constant",
|
|
588
|
-
"@akanjs/config",
|
|
589
|
-
"@akanjs/document"
|
|
590
|
-
],
|
|
591
|
-
reactStrictMode: commandType === "serve" ? false : true,
|
|
592
|
-
experimental: {
|
|
593
|
-
...config.experimental ?? {},
|
|
594
|
-
optimizePackageImports: [
|
|
595
|
-
...[appName, ...libs].map((lib) => [`@${lib}/ui`, `@${lib}/next`, `@${lib}/common`, `@${lib}/client`]).flat(),
|
|
596
|
-
"@contract",
|
|
597
|
-
"@akanjs/next",
|
|
598
|
-
"@akanjs/common"
|
|
599
|
-
]
|
|
600
|
-
},
|
|
601
|
-
// modularizeImports: {
|
|
602
|
-
// "react-icons/?(((\\w*)?/?)*)": {
|
|
603
|
-
// transform: "@react-icons/all-files/{{ matches.[1] }}/{{member}}",
|
|
604
|
-
// skipDefaultConversion: true,
|
|
605
|
-
// },
|
|
606
|
-
// lodash: { transform: "lodash/{{member}}", preventFullImport: true },
|
|
607
|
-
// ...Object.fromEntries(
|
|
608
|
-
// [appName, ...libs].reduce(
|
|
609
|
-
// (acc, lib) => [
|
|
610
|
-
// ...acc,
|
|
611
|
-
// [`@${lib}/ui`, { transform: `@${lib}/ui/{{member}}`, skipDefaultConversion: true }],
|
|
612
|
-
// [`@${lib}/next`, { transform: `@${lib}/next/{{member}}`, skipDefaultConversion: true }],
|
|
613
|
-
// [`@${lib}/common`, { transform: `@${lib}/common/{{member}}`, skipDefaultConversion: true }],
|
|
614
|
-
// [`@${lib}/client`, { transform: `@${lib}/lib/{{ camelCase member }}`, skipDefaultConversion: true }],
|
|
615
|
-
// ],
|
|
616
|
-
// [
|
|
617
|
-
// ["@contract", { transform: `@contract/src/{{member}}`, skipDefaultConversion: true }],
|
|
618
|
-
// [`@akanjs/next`, { transform: `@akanjs/next/src/{{member}}`, skipDefaultConversion: true }],
|
|
619
|
-
// [`@akanjs/common`, { transform: `@akanjs/common/src/{{member}}`, skipDefaultConversion: true }],
|
|
620
|
-
// ]
|
|
621
|
-
// )
|
|
622
|
-
// ),
|
|
623
|
-
// ...(config.modularizeImports ?? {}),
|
|
624
|
-
// },
|
|
625
|
-
images: {
|
|
626
|
-
formats: ["image/avif", "image/webp"],
|
|
627
|
-
...config.images ?? {},
|
|
628
|
-
remotePatterns: [
|
|
629
|
-
...config.images?.remotePatterns ?? [],
|
|
630
|
-
...routes.map(({ domains }) => [
|
|
631
|
-
...domains.main?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? [],
|
|
632
|
-
...domains.develop?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? [],
|
|
633
|
-
...domains.debug?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? []
|
|
634
|
-
]).flat(),
|
|
635
|
-
{ protocol: "https", hostname: `**.${devDomain}` }
|
|
636
|
-
]
|
|
637
|
-
},
|
|
638
|
-
webpack: (config2) => {
|
|
639
|
-
config2.resolve.alias.canvas = false;
|
|
640
|
-
config2.resolve.alias.encoding = false;
|
|
641
|
-
if (process.env.USE_AKANJS_PKGS === "true")
|
|
642
|
-
config2.resolve.alias["@akanjs/config"] = import_path.default.resolve(__dirname, "../../../../pkgs/@akanjs/config");
|
|
643
|
-
return config2;
|
|
644
|
-
},
|
|
645
|
-
redirects() {
|
|
646
|
-
return routes.map(({ basePath: basePath2, domains }) => [
|
|
647
|
-
{ basePath: basePath2, domain: `${basePath2}-debug.${devDomain}` },
|
|
648
|
-
{ basePath: basePath2, domain: `${basePath2}-develop.${devDomain}` },
|
|
649
|
-
{ basePath: basePath2, domain: `${basePath2}-main.${devDomain}` },
|
|
650
|
-
...domains.main?.map((domain) => ({ basePath: basePath2, domain })) ?? [],
|
|
651
|
-
...domains.develop?.map((domain) => ({ basePath: basePath2, domain })) ?? [],
|
|
652
|
-
...domains.debug?.map((domain) => ({ basePath: basePath2, domain })) ?? []
|
|
653
|
-
]).flat().map(({ basePath: basePath2, domain }) => ({
|
|
654
|
-
source: `/:locale/${basePath2}/:path*`,
|
|
655
|
-
has: [{ type: "host", value: domain }],
|
|
656
|
-
permanent: true,
|
|
657
|
-
destination: "/:locale/:path*"
|
|
658
|
-
}));
|
|
659
|
-
},
|
|
660
|
-
rewrites() {
|
|
661
|
-
return routes.map(({ basePath: basePath2, domains }) => [
|
|
662
|
-
{ basePath: basePath2, domain: `${basePath2}-debug.${devDomain}` },
|
|
663
|
-
{ basePath: basePath2, domain: `${basePath2}-develop.${devDomain}` },
|
|
664
|
-
{ basePath: basePath2, domain: `${basePath2}-main.${devDomain}` },
|
|
665
|
-
...domains.main?.map((domain) => ({ basePath: basePath2, domain })) ?? [],
|
|
666
|
-
...domains.develop?.map((domain) => ({ basePath: basePath2, domain })) ?? [],
|
|
667
|
-
...domains.debug?.map((domain) => ({ basePath: basePath2, domain })) ?? []
|
|
668
|
-
]).flat().map(({ basePath: basePath2, domain }) => [
|
|
669
|
-
{
|
|
670
|
-
source: "/:locale",
|
|
671
|
-
has: [{ type: "host", value: domain }],
|
|
672
|
-
destination: `/:locale/${basePath2}`
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
source: `/:locale/:path((?!${basePath2}$)(?!admin(?:/|$)).*)`,
|
|
676
|
-
has: [{ type: "host", value: domain }],
|
|
677
|
-
destination: `/:locale/${basePath2}/:path*`
|
|
678
|
-
}
|
|
679
|
-
]).flat();
|
|
680
|
-
}
|
|
681
|
-
});
|
|
682
|
-
};
|
|
363
|
+
return modelName;
|
|
364
|
+
};
|
|
683
365
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
|
|
700
|
-
RUN apt-get update && apt-get upgrade -y
|
|
701
|
-
RUN apt-get install -y 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
|
|
702
|
-
ARG TARGETARCH
|
|
703
|
-
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
|
|
704
|
-
RUN apt-get install -y git redis build-essential python3
|
|
705
|
-
RUN rm -rf /var/lib/apt/lists/*
|
|
706
|
-
RUN mkdir -p /workspace
|
|
707
|
-
WORKDIR /workspace
|
|
708
|
-
COPY ./package.json ./package.json
|
|
709
|
-
RUN npx pnpm i --prod
|
|
710
|
-
COPY . .
|
|
711
|
-
ENV PORT 8080
|
|
712
|
-
ENV NODE_OPTIONS=--max_old_space_size=8192
|
|
713
|
-
ENV NEXT_PUBLIC_REPO_NAME=${repoName}
|
|
714
|
-
ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
|
|
715
|
-
ENV NEXT_PUBLIC_APP_NAME=${appName}
|
|
716
|
-
ENV NEXT_PUBLIC_ENV=${env}
|
|
717
|
-
ENV NEXT_PUBLIC_OPERATION_MODE=cloud
|
|
718
|
-
CMD ["node", "main.js"]`,
|
|
719
|
-
explicitDependencies: config.backend?.explicitDependencies ?? []
|
|
720
|
-
},
|
|
721
|
-
frontend: {
|
|
722
|
-
dockerfile: config.frontend?.dockerfile ?? `FROM node:22-alpine
|
|
723
|
-
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
|
|
724
|
-
RUN apk --no-cache add git
|
|
725
|
-
RUN mkdir -p /workspace
|
|
726
|
-
WORKDIR /workspace
|
|
727
|
-
COPY ./package.json ./package.json
|
|
728
|
-
RUN npx pnpm i --prod
|
|
729
|
-
COPY . .
|
|
730
|
-
ENV PORT 4200
|
|
731
|
-
ENV NODE_OPTIONS=--max_old_space_size=8192
|
|
732
|
-
ENV NEXT_PUBLIC_REPO_NAME=${repoName}
|
|
733
|
-
ENV NEXT_PUBLIC_SERVE_DOMAIN=${serveDomain}
|
|
734
|
-
ENV NEXT_PUBLIC_APP_NAME=${appName}
|
|
735
|
-
ENV NEXT_PUBLIC_ENV=${env}
|
|
736
|
-
ENV NEXT_PUBLIC_OPERATION_MODE=cloud
|
|
737
|
-
CMD ["npm", "start"]`,
|
|
738
|
-
nextConfig: withBase(
|
|
739
|
-
appName,
|
|
740
|
-
config.frontend?.nextConfig ? typeof config.frontend.nextConfig === "function" ? config.frontend.nextConfig() : config.frontend.nextConfig : {},
|
|
741
|
-
config.libs ?? [],
|
|
742
|
-
config.frontend?.routes
|
|
743
|
-
),
|
|
744
|
-
explicitDependencies: config.frontend?.explicitDependencies ?? []
|
|
745
|
-
}
|
|
746
|
-
};
|
|
366
|
+
// pkgs/@akanjs/devkit/src/streamAi.ts
|
|
367
|
+
var import_prompts2 = require("@langchain/core/prompts");
|
|
368
|
+
var import_runnables = require("@langchain/core/runnables");
|
|
369
|
+
var import_openai = require("@langchain/openai");
|
|
370
|
+
var streamAi = async (question, callback) => {
|
|
371
|
+
const createStreamingModel = (apiKey = process.env.DEEPSEEK_API_KEY) => {
|
|
372
|
+
if (!apiKey)
|
|
373
|
+
throw new Error(`process.env.DEEPSEEK_API_KEY is not set`);
|
|
374
|
+
return new import_openai.ChatOpenAI({
|
|
375
|
+
modelName: "deepseek-reasoner",
|
|
376
|
+
temperature: 0.7,
|
|
377
|
+
streaming: true,
|
|
378
|
+
// Enable streaming
|
|
379
|
+
configuration: { baseURL: "https://api.deepseek.com/v1", apiKey }
|
|
380
|
+
});
|
|
747
381
|
};
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
if (!import_fs6.default.existsSync(akanConfigPath))
|
|
751
|
-
throw new Error(`application akan.config.ts is not found ${appRoot}`);
|
|
752
|
-
const configImp = (await import(`${appRoot}/akan.config.ts`)).default;
|
|
753
|
-
const config = typeof configImp === "function" ? configImp(props) : configImp;
|
|
754
|
-
return makeAppConfig(config, props);
|
|
382
|
+
const createProcessingChain = () => {
|
|
383
|
+
return import_runnables.RunnableSequence.from([import_prompts2.PromptTemplate.fromTemplate(`Answer concisely: {question}`), createStreamingModel()]);
|
|
755
384
|
};
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
385
|
+
try {
|
|
386
|
+
const chain = createProcessingChain();
|
|
387
|
+
const stream = await chain.stream({ question });
|
|
388
|
+
let fullResponse = "";
|
|
389
|
+
for await (const chunk of stream) {
|
|
390
|
+
const content = chunk.content;
|
|
391
|
+
if (typeof content === "string") {
|
|
392
|
+
fullResponse += content;
|
|
393
|
+
callback(content);
|
|
765
394
|
}
|
|
766
|
-
};
|
|
767
|
-
};
|
|
768
|
-
var getLibConfig = async (libRoot, props) => {
|
|
769
|
-
const akanConfigPath = import_path2.default.join(libRoot, "akan.config.ts");
|
|
770
|
-
if (!import_fs6.default.existsSync(akanConfigPath))
|
|
771
|
-
throw new Error(`library akan.config.ts is not found ${libRoot}`);
|
|
772
|
-
const configImp = (await import(`${libRoot}/akan.config.ts`)).default;
|
|
773
|
-
const config = typeof configImp === "function" ? configImp(props) : configImp;
|
|
774
|
-
return makeLibConfig(config, props);
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
// pkgs/@akanjs/config/index.ts
|
|
778
|
-
var getDefaultFileScan = () => ({
|
|
779
|
-
constants: {
|
|
780
|
-
databases: [],
|
|
781
|
-
scalars: []
|
|
782
|
-
},
|
|
783
|
-
dictionary: {
|
|
784
|
-
databases: [],
|
|
785
|
-
services: [],
|
|
786
|
-
scalars: []
|
|
787
|
-
},
|
|
788
|
-
documents: {
|
|
789
|
-
databases: [],
|
|
790
|
-
scalars: []
|
|
791
|
-
},
|
|
792
|
-
services: {
|
|
793
|
-
databases: [],
|
|
794
|
-
services: [],
|
|
795
|
-
scalars: []
|
|
796
|
-
},
|
|
797
|
-
signal: {
|
|
798
|
-
databases: [],
|
|
799
|
-
services: [],
|
|
800
|
-
scalars: []
|
|
801
|
-
},
|
|
802
|
-
store: {
|
|
803
|
-
databases: [],
|
|
804
|
-
services: [],
|
|
805
|
-
scalars: []
|
|
806
|
-
},
|
|
807
|
-
components: {
|
|
808
|
-
databases: [],
|
|
809
|
-
services: [],
|
|
810
|
-
scalars: []
|
|
811
395
|
}
|
|
812
|
-
|
|
396
|
+
return { content: fullResponse };
|
|
397
|
+
} catch (error) {
|
|
398
|
+
throw new Error("Failed to stream response");
|
|
399
|
+
}
|
|
400
|
+
};
|
|
813
401
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
402
|
+
// pkgs/@akanjs/devkit/src/executors.ts
|
|
403
|
+
var import_common = require("@akanjs/common");
|
|
404
|
+
var import_config = require("@akanjs/config");
|
|
405
|
+
var import_child_process = require("child_process");
|
|
406
|
+
var import_fs6 = __toESM(require("fs"));
|
|
407
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
408
|
+
var import_path = __toESM(require("path"));
|
|
819
409
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}
|
|
410
|
+
// pkgs/@akanjs/devkit/src/dependencyScanner.ts
|
|
411
|
+
var fs6 = __toESM(require("fs"));
|
|
412
|
+
var path = __toESM(require("path"));
|
|
413
|
+
var ts2 = __toESM(require("typescript"));
|
|
414
|
+
var TypeScriptDependencyScanner = class {
|
|
415
|
+
constructor(directory) {
|
|
416
|
+
this.directory = directory;
|
|
417
|
+
}
|
|
418
|
+
#fileDependencies = /* @__PURE__ */ new Map();
|
|
419
|
+
#visitedFiles = /* @__PURE__ */ new Set();
|
|
420
|
+
async getImportSets(depSets) {
|
|
421
|
+
const fileDependencies = await this.getDependencies();
|
|
422
|
+
const importedDepSets = new Array(depSets.length);
|
|
423
|
+
for (let i = 0; i < depSets.length; i++)
|
|
424
|
+
importedDepSets[i] = /* @__PURE__ */ new Set();
|
|
425
|
+
fileDependencies.forEach((imps) => {
|
|
426
|
+
imps.forEach((imp) => {
|
|
427
|
+
if (imp.startsWith("."))
|
|
428
|
+
return;
|
|
429
|
+
const moduleName = imp;
|
|
430
|
+
const moduleNameParts = moduleName.split("/");
|
|
431
|
+
const subModuleLength = moduleNameParts.length;
|
|
432
|
+
for (let i = 0; i < subModuleLength; i++) {
|
|
433
|
+
const importName = moduleNameParts.slice(0, i + 1).join("/");
|
|
434
|
+
for (let j = 0; j < depSets.length; j++) {
|
|
435
|
+
if (depSets[j].has(importName)) {
|
|
436
|
+
importedDepSets[j].add(importName);
|
|
437
|
+
return;
|
|
849
438
|
}
|
|
850
439
|
}
|
|
851
|
-
});
|
|
852
|
-
});
|
|
853
|
-
return importedDepSets;
|
|
854
|
-
}
|
|
855
|
-
async getDependencies() {
|
|
856
|
-
this.#fileDependencies.clear();
|
|
857
|
-
this.#visitedFiles.clear();
|
|
858
|
-
const files = await this.#findTypeScriptFiles(this.directory);
|
|
859
|
-
for (const file of files)
|
|
860
|
-
await this.#analyzeFile(file, this.directory);
|
|
861
|
-
return this.#fileDependencies;
|
|
862
|
-
}
|
|
863
|
-
async #findTypeScriptFiles(directory) {
|
|
864
|
-
const files = [];
|
|
865
|
-
const processDirectory = async (dir) => {
|
|
866
|
-
const entries = await fs7.promises.readdir(dir, { withFileTypes: true });
|
|
867
|
-
for (const entry of entries) {
|
|
868
|
-
const fullPath = path3.join(dir, entry.name);
|
|
869
|
-
if (entry.isDirectory()) {
|
|
870
|
-
if (!["node_modules", "dist", "build", ".git", ".next", "public", "ios", "android"].includes(entry.name))
|
|
871
|
-
await processDirectory(fullPath);
|
|
872
|
-
} else if (entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".tsx")))
|
|
873
|
-
files.push(fullPath);
|
|
874
440
|
}
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
return importedDepSets;
|
|
444
|
+
}
|
|
445
|
+
async getDependencies() {
|
|
446
|
+
this.#fileDependencies.clear();
|
|
447
|
+
this.#visitedFiles.clear();
|
|
448
|
+
const files = await this.#findTypeScriptFiles(this.directory);
|
|
449
|
+
for (const file of files)
|
|
450
|
+
await this.#analyzeFile(file, this.directory);
|
|
451
|
+
return this.#fileDependencies;
|
|
452
|
+
}
|
|
453
|
+
async #findTypeScriptFiles(directory) {
|
|
454
|
+
const files = [];
|
|
455
|
+
const processDirectory = async (dir) => {
|
|
456
|
+
const entries = await fs6.promises.readdir(dir, { withFileTypes: true });
|
|
457
|
+
for (const entry of entries) {
|
|
458
|
+
const fullPath = path.join(dir, entry.name);
|
|
459
|
+
if (entry.isDirectory()) {
|
|
460
|
+
if (!["node_modules", "dist", "build", ".git", ".next", "public", "ios", "android"].includes(entry.name))
|
|
461
|
+
await processDirectory(fullPath);
|
|
462
|
+
} else if (entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".tsx")))
|
|
463
|
+
files.push(fullPath);
|
|
896
464
|
}
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const moduleSpecifier = node.moduleSpecifier;
|
|
913
|
-
if (ts2.isStringLiteral(moduleSpecifier))
|
|
914
|
-
imports.push(moduleSpecifier.text);
|
|
465
|
+
};
|
|
466
|
+
await processDirectory(directory);
|
|
467
|
+
return files;
|
|
468
|
+
}
|
|
469
|
+
async #analyzeFile(filePath, baseDir) {
|
|
470
|
+
if (this.#visitedFiles.has(filePath))
|
|
471
|
+
return;
|
|
472
|
+
this.#visitedFiles.add(filePath);
|
|
473
|
+
try {
|
|
474
|
+
const fileContent = await fs6.promises.readFile(filePath, "utf-8");
|
|
475
|
+
const imports = this.#extractImports(fileContent, filePath);
|
|
476
|
+
const resolvedImports = imports.map((importPath) => {
|
|
477
|
+
if (importPath.startsWith(".")) {
|
|
478
|
+
const resolvedPath = "./" + path.join(path.relative(baseDir, filePath), importPath);
|
|
479
|
+
return this.#ensureExtension(resolvedPath);
|
|
915
480
|
}
|
|
916
|
-
|
|
917
|
-
};
|
|
918
|
-
|
|
919
|
-
|
|
481
|
+
return importPath;
|
|
482
|
+
});
|
|
483
|
+
const relativePath = path.relative(baseDir, filePath);
|
|
484
|
+
this.#fileDependencies.set(relativePath, resolvedImports);
|
|
485
|
+
} catch (error) {
|
|
920
486
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
487
|
+
}
|
|
488
|
+
#ensureExtension(filePath) {
|
|
489
|
+
if (fs6.existsSync(`${filePath}.ts`))
|
|
490
|
+
return `${filePath}.ts`;
|
|
491
|
+
else if (fs6.existsSync(`${filePath}.tsx`))
|
|
492
|
+
return `${filePath}.tsx`;
|
|
493
|
+
else if (fs6.existsSync(filePath))
|
|
494
|
+
return filePath;
|
|
495
|
+
return `${filePath}.ts`;
|
|
496
|
+
}
|
|
497
|
+
#extractImports(source, filePath) {
|
|
498
|
+
const imports = [];
|
|
499
|
+
const sourceFile = ts2.createSourceFile(filePath, source, ts2.ScriptTarget.Latest, true);
|
|
500
|
+
const visit = (node) => {
|
|
501
|
+
if (ts2.isImportDeclaration(node)) {
|
|
502
|
+
const moduleSpecifier = node.moduleSpecifier;
|
|
503
|
+
if (ts2.isStringLiteral(moduleSpecifier))
|
|
504
|
+
imports.push(moduleSpecifier.text);
|
|
505
|
+
}
|
|
506
|
+
ts2.forEachChild(node, visit);
|
|
507
|
+
};
|
|
508
|
+
visit(sourceFile);
|
|
509
|
+
return imports;
|
|
510
|
+
}
|
|
511
|
+
generateDependencyGraph() {
|
|
512
|
+
let graph = "Dependency Graph:\n\n";
|
|
513
|
+
for (const [file, imports] of this.#fileDependencies.entries()) {
|
|
514
|
+
graph += `${file}:
|
|
925
515
|
`;
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
516
|
+
const projectImports = imports.filter((i) => !i.startsWith("react") && !i.startsWith("@"));
|
|
517
|
+
const externalImports = imports.filter((i) => i.startsWith("react") || i.startsWith("@"));
|
|
518
|
+
if (projectImports.length > 0) {
|
|
519
|
+
graph += " Project dependencies:\n";
|
|
520
|
+
projectImports.forEach((imp) => {
|
|
521
|
+
graph += ` \u2192 ${imp}
|
|
932
522
|
`;
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
if (externalImports.length > 0) {
|
|
526
|
+
graph += " External dependencies:\n";
|
|
527
|
+
externalImports.forEach((imp) => {
|
|
528
|
+
graph += ` \u2192 ${imp}
|
|
939
529
|
`;
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
graph += "\n";
|
|
530
|
+
});
|
|
943
531
|
}
|
|
944
|
-
|
|
532
|
+
graph += "\n";
|
|
945
533
|
}
|
|
946
|
-
|
|
534
|
+
return graph;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
947
537
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
});
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
spawn(command, args = [], options = {}) {
|
|
976
|
-
const proc = (0, import_child_process.spawn)(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
|
|
977
|
-
proc.stderr?.on("data", (data) => {
|
|
978
|
-
Logger.raw(data.toString());
|
|
979
|
-
});
|
|
980
|
-
return new Promise((resolve, reject) => {
|
|
981
|
-
proc.on("exit", (code, signal) => {
|
|
982
|
-
if (!!code || signal)
|
|
983
|
-
reject({ code, signal });
|
|
984
|
-
else
|
|
985
|
-
resolve({ code, signal });
|
|
986
|
-
});
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
fork(modulePath, args = [], options = {}) {
|
|
990
|
-
const proc = (0, import_child_process.fork)(modulePath, args, {
|
|
991
|
-
cwd: this.cwdPath,
|
|
992
|
-
stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
993
|
-
...options
|
|
994
|
-
});
|
|
995
|
-
proc.stdout?.on("data", (data) => {
|
|
996
|
-
Logger.raw(data.toString());
|
|
538
|
+
// pkgs/@akanjs/devkit/src/executors.ts
|
|
539
|
+
var Executor = class {
|
|
540
|
+
logger;
|
|
541
|
+
cwdPath;
|
|
542
|
+
constructor(name, cwdPath) {
|
|
543
|
+
this.logger = new import_common.Logger(name);
|
|
544
|
+
this.cwdPath = cwdPath;
|
|
545
|
+
if (!import_fs6.default.existsSync(cwdPath))
|
|
546
|
+
import_fs6.default.mkdirSync(cwdPath, { recursive: true });
|
|
547
|
+
}
|
|
548
|
+
exec(command, options = {}) {
|
|
549
|
+
const proc = (0, import_child_process.exec)(command, { cwd: this.cwdPath, ...options });
|
|
550
|
+
proc.stdout?.on("data", (data) => {
|
|
551
|
+
import_common.Logger.raw(data.toString());
|
|
552
|
+
});
|
|
553
|
+
proc.stderr?.on("data", (data) => {
|
|
554
|
+
import_common.Logger.raw(data.toString());
|
|
555
|
+
});
|
|
556
|
+
return new Promise((resolve, reject) => {
|
|
557
|
+
proc.on("exit", (code, signal) => {
|
|
558
|
+
if (!!code || signal)
|
|
559
|
+
reject({ code, signal });
|
|
560
|
+
else
|
|
561
|
+
resolve({ code, signal });
|
|
997
562
|
});
|
|
998
|
-
|
|
999
|
-
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
spawn(command, args = [], options = {}) {
|
|
566
|
+
const proc = (0, import_child_process.spawn)(command, args, { cwd: this.cwdPath, stdio: "inherit", ...options });
|
|
567
|
+
proc.stderr?.on("data", (data) => {
|
|
568
|
+
import_common.Logger.raw(data.toString());
|
|
569
|
+
});
|
|
570
|
+
return new Promise((resolve, reject) => {
|
|
571
|
+
proc.on("exit", (code, signal) => {
|
|
572
|
+
if (!!code || signal)
|
|
573
|
+
reject({ code, signal });
|
|
574
|
+
else
|
|
575
|
+
resolve({ code, signal });
|
|
1000
576
|
});
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
fork(modulePath, args = [], options = {}) {
|
|
580
|
+
const proc = (0, import_child_process.fork)(modulePath, args, {
|
|
581
|
+
cwd: this.cwdPath,
|
|
582
|
+
stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
583
|
+
...options
|
|
584
|
+
});
|
|
585
|
+
proc.stdout?.on("data", (data) => {
|
|
586
|
+
import_common.Logger.raw(data.toString());
|
|
587
|
+
});
|
|
588
|
+
proc.stderr?.on("data", (data) => {
|
|
589
|
+
import_common.Logger.raw(data.toString());
|
|
590
|
+
});
|
|
591
|
+
return new Promise((resolve, reject) => {
|
|
592
|
+
proc.on("exit", (code, signal) => {
|
|
593
|
+
if (!!code || signal)
|
|
594
|
+
reject({ code, signal });
|
|
595
|
+
else
|
|
596
|
+
resolve({ code, signal });
|
|
1008
597
|
});
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
} else {
|
|
1032
|
-
import_fs7.default.writeFileSync(writePath, contentStr, "utf8");
|
|
1033
|
-
this.logger.verbose(`File ${writePath} is created`);
|
|
1034
|
-
}
|
|
1035
|
-
return this;
|
|
1036
|
-
}
|
|
1037
|
-
writeJson(filePath, content) {
|
|
1038
|
-
this.writeFile(filePath, JSON.stringify(content, null, 2));
|
|
1039
|
-
return this;
|
|
1040
|
-
}
|
|
1041
|
-
readFile(filePath) {
|
|
1042
|
-
const readPath = import_path3.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
1043
|
-
return import_fs7.default.readFileSync(readPath, "utf8");
|
|
1044
|
-
}
|
|
1045
|
-
readJson(filePath) {
|
|
1046
|
-
const readPath = import_path3.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
1047
|
-
return JSON.parse(import_fs7.default.readFileSync(readPath, "utf8"));
|
|
1048
|
-
}
|
|
1049
|
-
async cp(srcPath, destPath) {
|
|
1050
|
-
const src = import_path3.default.isAbsolute(srcPath) ? srcPath : `${this.cwdPath}/${srcPath}`;
|
|
1051
|
-
const dest = import_path3.default.isAbsolute(destPath) ? destPath : `${this.cwdPath}/${destPath}`;
|
|
1052
|
-
await import_promises.default.cp(src, dest, { recursive: true });
|
|
1053
|
-
}
|
|
1054
|
-
log(msg) {
|
|
1055
|
-
this.logger.info(msg);
|
|
1056
|
-
return this;
|
|
1057
|
-
}
|
|
1058
|
-
verbose(msg) {
|
|
1059
|
-
this.logger.verbose(msg);
|
|
1060
|
-
return this;
|
|
1061
|
-
}
|
|
1062
|
-
getTsConfig(pathname) {
|
|
1063
|
-
const tsconfig = this.readJson(pathname);
|
|
1064
|
-
if (tsconfig.extends) {
|
|
1065
|
-
const extendsTsconfig = this.getTsConfig(tsconfig.extends);
|
|
1066
|
-
return {
|
|
1067
|
-
...extendsTsconfig,
|
|
1068
|
-
...tsconfig,
|
|
1069
|
-
compilerOptions: { ...extendsTsconfig.compilerOptions, ...tsconfig.compilerOptions }
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
return tsconfig;
|
|
1073
|
-
}
|
|
1074
|
-
async #applyTemplateFile({
|
|
1075
|
-
templatePath,
|
|
1076
|
-
targetPath,
|
|
1077
|
-
scanResult
|
|
1078
|
-
}, dict = {}) {
|
|
1079
|
-
if (targetPath.endsWith(".js")) {
|
|
1080
|
-
const getContent = await import(templatePath);
|
|
1081
|
-
const content = getContent.default(scanResult ?? null, dict);
|
|
1082
|
-
const convertedTargetPath = Object.entries(dict).reduce(
|
|
1083
|
-
(path5, [key, value]) => path5.replace(new RegExp(`__${key}__`, "g"), value),
|
|
1084
|
-
targetPath.replace(".js", ".ts")
|
|
1085
|
-
);
|
|
1086
|
-
if (content === null)
|
|
1087
|
-
return;
|
|
1088
|
-
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
1089
|
-
this.writeFile(convertedTargetPath, content);
|
|
1090
|
-
} else if (targetPath.endsWith(".template")) {
|
|
1091
|
-
const content = await import_promises.default.readFile(templatePath, "utf8");
|
|
1092
|
-
const convertedTargetPath = Object.entries(dict).reduce(
|
|
1093
|
-
(path5, [key, value]) => path5.replace(new RegExp(`__${key}__`, "g"), value),
|
|
1094
|
-
targetPath.slice(0, -9)
|
|
1095
|
-
);
|
|
1096
|
-
const convertedContent = Object.entries(dict).reduce(
|
|
1097
|
-
(content2, [key, value]) => content2.replace(new RegExp(`<%= ${key} %>`, "g"), value),
|
|
1098
|
-
content
|
|
1099
|
-
);
|
|
1100
|
-
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
1101
|
-
this.writeFile(convertedTargetPath, convertedContent);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
async applyTemplate({
|
|
1105
|
-
basePath: basePath2,
|
|
1106
|
-
template,
|
|
1107
|
-
scanResult,
|
|
1108
|
-
dict = {}
|
|
1109
|
-
}) {
|
|
1110
|
-
const templatePath = `${__dirname}/src/templates${template ? `/${template}` : ""}`.replace(".ts", ".js");
|
|
1111
|
-
if (import_fs7.default.statSync(templatePath).isFile()) {
|
|
1112
|
-
const filename = import_path3.default.basename(templatePath);
|
|
1113
|
-
await this.#applyTemplateFile({ templatePath, targetPath: import_path3.default.join(basePath2, filename), scanResult }, dict);
|
|
1114
|
-
} else {
|
|
1115
|
-
if (!import_fs7.default.existsSync(basePath2))
|
|
1116
|
-
await import_promises.default.mkdir(basePath2, { recursive: true });
|
|
1117
|
-
const subdirs = await import_promises.default.readdir(templatePath);
|
|
1118
|
-
await Promise.all(
|
|
1119
|
-
subdirs.map(async (subdir) => {
|
|
1120
|
-
const subpath = import_path3.default.join(templatePath, subdir);
|
|
1121
|
-
if (import_fs7.default.statSync(subpath).isFile())
|
|
1122
|
-
await this.#applyTemplateFile(
|
|
1123
|
-
{ templatePath: subpath, targetPath: import_path3.default.join(basePath2, subdir), scanResult },
|
|
1124
|
-
dict
|
|
1125
|
-
);
|
|
1126
|
-
else
|
|
1127
|
-
await this.applyTemplate({
|
|
1128
|
-
basePath: import_path3.default.join(basePath2, subdir),
|
|
1129
|
-
template: import_path3.default.join(template, subdir),
|
|
1130
|
-
scanResult,
|
|
1131
|
-
dict
|
|
1132
|
-
});
|
|
1133
|
-
})
|
|
1134
|
-
);
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
mkdir(dirPath) {
|
|
601
|
+
const writePath = import_path.default.isAbsolute(dirPath) ? dirPath : `${this.cwdPath}/${dirPath}`;
|
|
602
|
+
if (!import_fs6.default.existsSync(writePath))
|
|
603
|
+
import_fs6.default.mkdirSync(writePath, { recursive: true });
|
|
604
|
+
this.logger.verbose(`Make directory ${writePath}`);
|
|
605
|
+
return this;
|
|
606
|
+
}
|
|
607
|
+
writeFile(filePath, content) {
|
|
608
|
+
const writePath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
609
|
+
const dir = import_path.default.dirname(writePath);
|
|
610
|
+
if (!import_fs6.default.existsSync(dir))
|
|
611
|
+
import_fs6.default.mkdirSync(dir, { recursive: true });
|
|
612
|
+
const contentStr = typeof content === "string" ? content : JSON.stringify(content, null, 2);
|
|
613
|
+
if (import_fs6.default.existsSync(writePath)) {
|
|
614
|
+
const currentContent = import_fs6.default.readFileSync(writePath, "utf8");
|
|
615
|
+
if (currentContent === contentStr)
|
|
616
|
+
this.logger.verbose(`File ${writePath} is unchanged`);
|
|
617
|
+
else {
|
|
618
|
+
import_fs6.default.writeFileSync(writePath, contentStr, "utf8");
|
|
619
|
+
this.logger.verbose(`File ${writePath} is changed`);
|
|
1135
620
|
}
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
)
|
|
1172
|
-
]);
|
|
621
|
+
} else {
|
|
622
|
+
import_fs6.default.writeFileSync(writePath, contentStr, "utf8");
|
|
623
|
+
this.logger.verbose(`File ${writePath} is created`);
|
|
624
|
+
}
|
|
625
|
+
return this;
|
|
626
|
+
}
|
|
627
|
+
writeJson(filePath, content) {
|
|
628
|
+
this.writeFile(filePath, JSON.stringify(content, null, 2));
|
|
629
|
+
return this;
|
|
630
|
+
}
|
|
631
|
+
readFile(filePath) {
|
|
632
|
+
const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
633
|
+
return import_fs6.default.readFileSync(readPath, "utf8");
|
|
634
|
+
}
|
|
635
|
+
readJson(filePath) {
|
|
636
|
+
const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
|
|
637
|
+
return JSON.parse(import_fs6.default.readFileSync(readPath, "utf8"));
|
|
638
|
+
}
|
|
639
|
+
async cp(srcPath, destPath) {
|
|
640
|
+
const src = import_path.default.isAbsolute(srcPath) ? srcPath : `${this.cwdPath}/${srcPath}`;
|
|
641
|
+
const dest = import_path.default.isAbsolute(destPath) ? destPath : `${this.cwdPath}/${destPath}`;
|
|
642
|
+
await import_promises.default.cp(src, dest, { recursive: true });
|
|
643
|
+
}
|
|
644
|
+
log(msg) {
|
|
645
|
+
this.logger.info(msg);
|
|
646
|
+
return this;
|
|
647
|
+
}
|
|
648
|
+
verbose(msg) {
|
|
649
|
+
this.logger.verbose(msg);
|
|
650
|
+
return this;
|
|
651
|
+
}
|
|
652
|
+
getTsConfig(pathname) {
|
|
653
|
+
const tsconfig = this.readJson(pathname);
|
|
654
|
+
if (tsconfig.extends) {
|
|
655
|
+
const extendsTsconfig = this.getTsConfig(tsconfig.extends);
|
|
1173
656
|
return {
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
apps: Object.fromEntries(appScanResults.map((app) => [app.name, app])),
|
|
1178
|
-
libs: Object.fromEntries(libScanResults.map((lib) => [lib.name, lib])),
|
|
1179
|
-
pkgs: Object.fromEntries(pkgScanResults.map((pkg) => [pkg.name, pkg]))
|
|
657
|
+
...extendsTsconfig,
|
|
658
|
+
...tsconfig,
|
|
659
|
+
compilerOptions: { ...extendsTsconfig.compilerOptions, ...tsconfig.compilerOptions }
|
|
1180
660
|
};
|
|
1181
661
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
async #getDirHasFile(basePath2, targetFilename) {
|
|
1196
|
-
const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
|
|
1197
|
-
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
1198
|
-
const dirs = await import_promises.default.readdir(dirname);
|
|
1199
|
-
await Promise.all(
|
|
1200
|
-
dirs.map(async (dir) => {
|
|
1201
|
-
if (AVOID_DIRS.includes(dir))
|
|
1202
|
-
return;
|
|
1203
|
-
const dirPath = import_path3.default.join(dirname, dir);
|
|
1204
|
-
if (import_fs7.default.lstatSync(dirPath).isDirectory()) {
|
|
1205
|
-
const hasTargetFile = import_fs7.default.existsSync(import_path3.default.join(dirPath, targetFilename));
|
|
1206
|
-
if (hasTargetFile)
|
|
1207
|
-
results.push(`${prefix}${dir}`);
|
|
1208
|
-
if (maxDepth > 0)
|
|
1209
|
-
await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
1210
|
-
}
|
|
1211
|
-
})
|
|
1212
|
-
);
|
|
1213
|
-
return results;
|
|
1214
|
-
};
|
|
1215
|
-
return await getDirs(basePath2);
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
1218
|
-
var SysExecutor = class extends Executor {
|
|
1219
|
-
workspace;
|
|
1220
|
-
name;
|
|
1221
|
-
type;
|
|
1222
|
-
constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
|
|
1223
|
-
super(`${name} Sys Executor`, `${workspace.workspaceRoot}/${type}s/${name}`);
|
|
1224
|
-
this.workspace = workspace;
|
|
1225
|
-
this.name = name;
|
|
1226
|
-
this.type = type;
|
|
1227
|
-
}
|
|
1228
|
-
async getConfig(command) {
|
|
1229
|
-
return this.type === "app" ? await getAppConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command }) : await getLibConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
1230
|
-
}
|
|
1231
|
-
async scan({
|
|
1232
|
-
tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`),
|
|
1233
|
-
akanConfig
|
|
1234
|
-
}, libScanResults = {}) {
|
|
1235
|
-
if (libScanResults[this.name])
|
|
1236
|
-
return libScanResults[this.name];
|
|
1237
|
-
const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
|
|
1238
|
-
const scanner = new TypeScriptDependencyScanner(this.cwdPath);
|
|
1239
|
-
const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
|
|
1240
|
-
const pkgPathSet = new Set(
|
|
1241
|
-
Object.keys(tsconfig.compilerOptions.paths).filter((path5) => tsconfig.compilerOptions.paths[path5].some((resolve) => resolve.startsWith("pkgs/"))).map((path5) => path5.replace("/*", ""))
|
|
662
|
+
return tsconfig;
|
|
663
|
+
}
|
|
664
|
+
async #applyTemplateFile({
|
|
665
|
+
templatePath,
|
|
666
|
+
targetPath,
|
|
667
|
+
scanResult
|
|
668
|
+
}, dict = {}) {
|
|
669
|
+
if (targetPath.endsWith(".js")) {
|
|
670
|
+
const getContent = await import(templatePath);
|
|
671
|
+
const content = getContent.default(scanResult ?? null, dict);
|
|
672
|
+
const convertedTargetPath = Object.entries(dict).reduce(
|
|
673
|
+
(path3, [key, value]) => path3.replace(new RegExp(`__${key}__`, "g"), value),
|
|
674
|
+
targetPath.replace(".js", ".ts")
|
|
1242
675
|
);
|
|
1243
|
-
|
|
1244
|
-
|
|
676
|
+
if (content === null)
|
|
677
|
+
return;
|
|
678
|
+
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
679
|
+
this.writeFile(convertedTargetPath, content);
|
|
680
|
+
} else if (targetPath.endsWith(".template")) {
|
|
681
|
+
const content = await import_promises.default.readFile(templatePath, "utf8");
|
|
682
|
+
const convertedTargetPath = Object.entries(dict).reduce(
|
|
683
|
+
(path3, [key, value]) => path3.replace(new RegExp(`__${key}__`, "g"), value),
|
|
684
|
+
targetPath.slice(0, -9)
|
|
1245
685
|
);
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
return tsconfig.compilerOptions.paths[path5][0].split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
1250
|
-
});
|
|
1251
|
-
const libDeps = [...libPathDepSet].map((path5) => {
|
|
1252
|
-
const pathSplitLength = path5.split("/").length;
|
|
1253
|
-
return tsconfig.compilerOptions.paths[path5][0].split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
1254
|
-
}).filter((libName) => libName !== this.name);
|
|
1255
|
-
if (!import_fs7.default.existsSync(`${this.cwdPath}/lib/__scalar`))
|
|
1256
|
-
import_fs7.default.mkdirSync(`${this.cwdPath}/lib/__scalar`, { recursive: true });
|
|
1257
|
-
const files = getDefaultFileScan();
|
|
1258
|
-
const dirnames = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter(
|
|
1259
|
-
(name) => import_fs7.default.lstatSync(`${this.cwdPath}/lib/${name}`).isDirectory()
|
|
686
|
+
const convertedContent = Object.entries(dict).reduce(
|
|
687
|
+
(content2, [key, value]) => content2.replace(new RegExp(`<%= ${key} %>`, "g"), value),
|
|
688
|
+
content
|
|
1260
689
|
);
|
|
1261
|
-
|
|
1262
|
-
|
|
690
|
+
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
691
|
+
this.writeFile(convertedTargetPath, convertedContent);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
async applyTemplate({
|
|
695
|
+
basePath: basePath2,
|
|
696
|
+
template,
|
|
697
|
+
scanResult,
|
|
698
|
+
dict = {}
|
|
699
|
+
}) {
|
|
700
|
+
const templatePath = `${__dirname}/src/templates${template ? `/${template}` : ""}`.replace(".ts", ".js");
|
|
701
|
+
if (import_fs6.default.statSync(templatePath).isFile()) {
|
|
702
|
+
const filename = import_path.default.basename(templatePath);
|
|
703
|
+
await this.#applyTemplateFile({ templatePath, targetPath: import_path.default.join(basePath2, filename), scanResult }, dict);
|
|
704
|
+
} else {
|
|
705
|
+
if (!import_fs6.default.existsSync(basePath2))
|
|
706
|
+
await import_promises.default.mkdir(basePath2, { recursive: true });
|
|
707
|
+
const subdirs = await import_promises.default.readdir(templatePath);
|
|
1263
708
|
await Promise.all(
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
files.store.databases.push(name);
|
|
1279
|
-
else if (filename === "index.tsx")
|
|
1280
|
-
files.components.databases.push(name);
|
|
1281
|
-
});
|
|
709
|
+
subdirs.map(async (subdir) => {
|
|
710
|
+
const subpath = import_path.default.join(templatePath, subdir);
|
|
711
|
+
if (import_fs6.default.statSync(subpath).isFile())
|
|
712
|
+
await this.#applyTemplateFile(
|
|
713
|
+
{ templatePath: subpath, targetPath: import_path.default.join(basePath2, subdir), scanResult },
|
|
714
|
+
dict
|
|
715
|
+
);
|
|
716
|
+
else
|
|
717
|
+
await this.applyTemplate({
|
|
718
|
+
basePath: import_path.default.join(basePath2, subdir),
|
|
719
|
+
template: import_path.default.join(template, subdir),
|
|
720
|
+
scanResult,
|
|
721
|
+
dict
|
|
722
|
+
});
|
|
1282
723
|
})
|
|
1283
724
|
);
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
var WorkspaceExecutor = class _WorkspaceExecutor extends Executor {
|
|
729
|
+
workspaceRoot;
|
|
730
|
+
repoName;
|
|
731
|
+
constructor({ workspaceRoot, repoName }) {
|
|
732
|
+
super(`${repoName} Executor`, workspaceRoot);
|
|
733
|
+
this.workspaceRoot = workspaceRoot;
|
|
734
|
+
this.repoName = repoName;
|
|
735
|
+
}
|
|
736
|
+
static fromRoot() {
|
|
737
|
+
const repoName = import_path.default.basename(process.cwd());
|
|
738
|
+
return new _WorkspaceExecutor({ workspaceRoot: process.cwd(), repoName });
|
|
739
|
+
}
|
|
740
|
+
async scan() {
|
|
741
|
+
const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
|
|
742
|
+
const [appScanResults, libScanResults, pkgScanResults] = await Promise.all([
|
|
743
|
+
Promise.all(
|
|
744
|
+
appNames.map(async (appName) => {
|
|
745
|
+
const app = AppExecutor.from(this, appName);
|
|
746
|
+
const akanConfig = await app.getConfig("scan");
|
|
747
|
+
return await app.scan({ akanConfig });
|
|
1300
748
|
})
|
|
1301
|
-
)
|
|
1302
|
-
|
|
1303
|
-
(
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
const filenames = await import_promises.default.readdir(import_path3.default.join(this.cwdPath, "lib/__scalar", name));
|
|
1308
|
-
filenames.forEach((filename) => {
|
|
1309
|
-
if (filename.endsWith(".constant.ts"))
|
|
1310
|
-
files.constants.scalars.push(name);
|
|
1311
|
-
else if (filename.endsWith(".dictionary.ts"))
|
|
1312
|
-
files.dictionary.scalars.push(name);
|
|
1313
|
-
else if (filename.endsWith(".document.ts"))
|
|
1314
|
-
files.documents.scalars.push(name);
|
|
1315
|
-
else if (filename.endsWith(".service.ts"))
|
|
1316
|
-
files.services.scalars.push(name);
|
|
1317
|
-
else if (filename.endsWith(".signal.ts"))
|
|
1318
|
-
files.signal.scalars.push(name);
|
|
1319
|
-
else if (filename.endsWith(".store.ts"))
|
|
1320
|
-
files.store.scalars.push(name);
|
|
1321
|
-
else if (filename === "index.ts")
|
|
1322
|
-
files.components.scalars.push(name);
|
|
1323
|
-
});
|
|
749
|
+
),
|
|
750
|
+
Promise.all(
|
|
751
|
+
libNames.map(async (libName) => {
|
|
752
|
+
const lib = LibExecutor.from(this, libName);
|
|
753
|
+
const akanConfig = await lib.getConfig("scan");
|
|
754
|
+
return await lib.scan({ akanConfig });
|
|
1324
755
|
})
|
|
1325
|
-
)
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
return scanResult;
|
|
1359
|
-
}
|
|
1360
|
-
async getDatabaseModules() {
|
|
1361
|
-
const databaseModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs7.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
|
|
1362
|
-
return databaseModules;
|
|
1363
|
-
}
|
|
1364
|
-
async getServiceModules() {
|
|
1365
|
-
const serviceModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => name.startsWith("_") && !name.startsWith("__")).filter((name) => import_fs7.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.service.ts`));
|
|
1366
|
-
return serviceModules;
|
|
1367
|
-
}
|
|
1368
|
-
async getScalarModules() {
|
|
1369
|
-
const scalarModules = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs7.default.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
|
|
1370
|
-
return scalarModules;
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
var AppExecutor = class _AppExecutor extends SysExecutor {
|
|
1374
|
-
constructor({ workspace, name }) {
|
|
1375
|
-
super({ workspace, name, type: "app" });
|
|
1376
|
-
}
|
|
1377
|
-
static from(executor, name) {
|
|
1378
|
-
if (executor instanceof WorkspaceExecutor)
|
|
1379
|
-
return new _AppExecutor({ workspace: executor, name });
|
|
1380
|
-
return new _AppExecutor({ workspace: executor.workspace, name });
|
|
1381
|
-
}
|
|
1382
|
-
async getConfig(command) {
|
|
1383
|
-
return await getAppConfig(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
1384
|
-
}
|
|
1385
|
-
async syncAssets(libDeps) {
|
|
1386
|
-
const projectPublicLibPath = `${this.cwdPath}/public/libs`;
|
|
1387
|
-
if (import_fs7.default.existsSync(projectPublicLibPath))
|
|
1388
|
-
await import_promises.default.rm(projectPublicLibPath, { recursive: true });
|
|
1389
|
-
const targetDeps = libDeps.filter((dep) => import_fs7.default.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/public`));
|
|
1390
|
-
await Promise.all(targetDeps.map((dep) => import_promises.default.mkdir(`${projectPublicLibPath}/${dep}`, { recursive: true })));
|
|
756
|
+
),
|
|
757
|
+
Promise.all(
|
|
758
|
+
pkgNames.map(async (pkgName) => {
|
|
759
|
+
return await PkgExecutor.from(this, pkgName).scan();
|
|
760
|
+
})
|
|
761
|
+
)
|
|
762
|
+
]);
|
|
763
|
+
return {
|
|
764
|
+
appNames,
|
|
765
|
+
libNames,
|
|
766
|
+
pkgNames,
|
|
767
|
+
apps: Object.fromEntries(appScanResults.map((app) => [app.name, app])),
|
|
768
|
+
libs: Object.fromEntries(libScanResults.map((lib) => [lib.name, lib])),
|
|
769
|
+
pkgs: Object.fromEntries(pkgScanResults.map((pkg) => [pkg.name, pkg]))
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
async getApps() {
|
|
773
|
+
return await this.#getDirHasFile(`${this.workspaceRoot}/apps`, "akan.config.ts");
|
|
774
|
+
}
|
|
775
|
+
async getLibs() {
|
|
776
|
+
return await this.#getDirHasFile(`${this.workspaceRoot}/libs`, "akan.config.ts");
|
|
777
|
+
}
|
|
778
|
+
async getSyss() {
|
|
779
|
+
const [appNames, libNames] = await Promise.all([this.getApps(), this.getLibs()]);
|
|
780
|
+
return [appNames, libNames];
|
|
781
|
+
}
|
|
782
|
+
async getPkgs() {
|
|
783
|
+
return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
|
|
784
|
+
}
|
|
785
|
+
async #getDirHasFile(basePath2, targetFilename) {
|
|
786
|
+
const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
|
|
787
|
+
const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
|
|
788
|
+
const dirs = await import_promises.default.readdir(dirname);
|
|
1391
789
|
await Promise.all(
|
|
1392
|
-
|
|
1393
|
-
(
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
790
|
+
dirs.map(async (dir) => {
|
|
791
|
+
if (AVOID_DIRS.includes(dir))
|
|
792
|
+
return;
|
|
793
|
+
const dirPath = import_path.default.join(dirname, dir);
|
|
794
|
+
if (import_fs6.default.lstatSync(dirPath).isDirectory()) {
|
|
795
|
+
const hasTargetFile = import_fs6.default.existsSync(import_path.default.join(dirPath, targetFilename));
|
|
796
|
+
if (hasTargetFile)
|
|
797
|
+
results.push(`${prefix}${dir}`);
|
|
798
|
+
if (maxDepth > 0)
|
|
799
|
+
await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
800
|
+
}
|
|
801
|
+
})
|
|
1397
802
|
);
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
return
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
this.
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
803
|
+
return results;
|
|
804
|
+
};
|
|
805
|
+
return await getDirs(basePath2);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
var SysExecutor = class extends Executor {
|
|
809
|
+
workspace;
|
|
810
|
+
name;
|
|
811
|
+
type;
|
|
812
|
+
constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
|
|
813
|
+
super(`${name} Sys Executor`, `${workspace.workspaceRoot}/${type}s/${name}`);
|
|
814
|
+
this.workspace = workspace;
|
|
815
|
+
this.name = name;
|
|
816
|
+
this.type = type;
|
|
817
|
+
}
|
|
818
|
+
async getConfig(command) {
|
|
819
|
+
return this.type === "app" ? await (0, import_config.getAppConfig)(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command }) : await (0, import_config.getLibConfig)(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
820
|
+
}
|
|
821
|
+
async scan({
|
|
822
|
+
tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`),
|
|
823
|
+
akanConfig
|
|
824
|
+
}, libScanResults = {}) {
|
|
825
|
+
if (libScanResults[this.name])
|
|
826
|
+
return libScanResults[this.name];
|
|
827
|
+
const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
|
|
828
|
+
const scanner = new TypeScriptDependencyScanner(this.cwdPath);
|
|
829
|
+
const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
|
|
830
|
+
const pkgPathSet = new Set(
|
|
831
|
+
Object.keys(tsconfig.compilerOptions.paths).filter((path3) => tsconfig.compilerOptions.paths[path3].some((resolve) => resolve.startsWith("pkgs/"))).map((path3) => path3.replace("/*", ""))
|
|
832
|
+
);
|
|
833
|
+
const libPathSet = new Set(
|
|
834
|
+
Object.keys(tsconfig.compilerOptions.paths).filter((path3) => tsconfig.compilerOptions.paths[path3].some((resolve) => resolve.startsWith("libs/"))).map((path3) => path3.replace("/*", ""))
|
|
835
|
+
);
|
|
836
|
+
const [npmDepSet, pkgPathDepSet, libPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet, libPathSet]);
|
|
837
|
+
const pkgDeps = [...pkgPathDepSet].map((path3) => {
|
|
838
|
+
const pathSplitLength = path3.split("/").length;
|
|
839
|
+
return tsconfig.compilerOptions.paths[path3][0].split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
840
|
+
});
|
|
841
|
+
const libDeps = [...libPathDepSet].map((path3) => {
|
|
842
|
+
const pathSplitLength = path3.split("/").length;
|
|
843
|
+
return tsconfig.compilerOptions.paths[path3][0].split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
844
|
+
}).filter((libName) => libName !== this.name);
|
|
845
|
+
if (!import_fs6.default.existsSync(`${this.cwdPath}/lib/__scalar`))
|
|
846
|
+
import_fs6.default.mkdirSync(`${this.cwdPath}/lib/__scalar`, { recursive: true });
|
|
847
|
+
const files = (0, import_config.getDefaultFileScan)();
|
|
848
|
+
const dirnames = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter(
|
|
849
|
+
(name) => import_fs6.default.lstatSync(`${this.cwdPath}/lib/${name}`).isDirectory()
|
|
850
|
+
);
|
|
851
|
+
const databaseDirs = dirnames.filter((name) => !name.startsWith("_"));
|
|
852
|
+
const serviceDirs = dirnames.filter((name) => name.startsWith("_") && !name.startsWith("__"));
|
|
853
|
+
await Promise.all(
|
|
854
|
+
databaseDirs.map(async (name) => {
|
|
855
|
+
const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib", name));
|
|
856
|
+
filenames.forEach((filename) => {
|
|
857
|
+
if (filename.endsWith(".constant.ts"))
|
|
858
|
+
files.constants.databases.push(name);
|
|
859
|
+
else if (filename.endsWith(".dictionary.ts"))
|
|
860
|
+
files.dictionary.databases.push(name);
|
|
861
|
+
else if (filename.endsWith(".document.ts"))
|
|
862
|
+
files.documents.databases.push(name);
|
|
863
|
+
else if (filename.endsWith(".service.ts"))
|
|
864
|
+
files.services.databases.push(name);
|
|
865
|
+
else if (filename.endsWith(".signal.ts"))
|
|
866
|
+
files.signal.databases.push(name);
|
|
867
|
+
else if (filename.endsWith(".store.ts"))
|
|
868
|
+
files.store.databases.push(name);
|
|
869
|
+
else if (filename === "index.tsx")
|
|
870
|
+
files.components.databases.push(name);
|
|
871
|
+
});
|
|
872
|
+
})
|
|
873
|
+
);
|
|
874
|
+
await Promise.all(
|
|
875
|
+
serviceDirs.map(async (dirname) => {
|
|
876
|
+
const name = dirname.slice(1);
|
|
877
|
+
const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib", dirname));
|
|
878
|
+
filenames.forEach((filename) => {
|
|
879
|
+
if (filename.endsWith(".dictionary.ts"))
|
|
880
|
+
files.dictionary.services.push(name);
|
|
881
|
+
else if (filename.endsWith(".service.ts"))
|
|
882
|
+
files.services.services.push(name);
|
|
883
|
+
else if (filename.endsWith(".signal.ts"))
|
|
884
|
+
files.signal.services.push(name);
|
|
885
|
+
else if (filename.endsWith(".store.ts"))
|
|
886
|
+
files.store.services.push(name);
|
|
887
|
+
else if (filename === "index.tsx")
|
|
888
|
+
files.components.services.push(name);
|
|
889
|
+
});
|
|
890
|
+
})
|
|
891
|
+
);
|
|
892
|
+
const scalarDirs = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter(
|
|
893
|
+
(name) => !name.startsWith("_")
|
|
894
|
+
);
|
|
895
|
+
await Promise.all(
|
|
896
|
+
scalarDirs.map(async (name) => {
|
|
897
|
+
const filenames = await import_promises.default.readdir(import_path.default.join(this.cwdPath, "lib/__scalar", name));
|
|
898
|
+
filenames.forEach((filename) => {
|
|
899
|
+
if (filename.endsWith(".constant.ts"))
|
|
900
|
+
files.constants.scalars.push(name);
|
|
901
|
+
else if (filename.endsWith(".dictionary.ts"))
|
|
902
|
+
files.dictionary.scalars.push(name);
|
|
903
|
+
else if (filename.endsWith(".document.ts"))
|
|
904
|
+
files.documents.scalars.push(name);
|
|
905
|
+
else if (filename.endsWith(".service.ts"))
|
|
906
|
+
files.services.scalars.push(name);
|
|
907
|
+
else if (filename.endsWith(".signal.ts"))
|
|
908
|
+
files.signal.scalars.push(name);
|
|
909
|
+
else if (filename.endsWith(".store.ts"))
|
|
910
|
+
files.store.scalars.push(name);
|
|
911
|
+
else if (filename === "index.ts")
|
|
912
|
+
files.components.scalars.push(name);
|
|
913
|
+
});
|
|
914
|
+
})
|
|
915
|
+
);
|
|
916
|
+
const missingLibDeps = [];
|
|
917
|
+
libDeps.forEach((libName) => {
|
|
918
|
+
if (!akanConfig.libs.includes(libName))
|
|
919
|
+
missingLibDeps.push(libName);
|
|
920
|
+
});
|
|
921
|
+
if (missingLibDeps.length)
|
|
922
|
+
throw new Error(
|
|
923
|
+
`Missing libs: ${missingLibDeps.join(", ")}, add these dependencies in akan.config.ts as { libs: [...other deps, ${missingLibDeps.join(", ")}] }`
|
|
1461
924
|
);
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
this.
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
925
|
+
for (const libName of libDeps) {
|
|
926
|
+
if (libScanResults[libName])
|
|
927
|
+
continue;
|
|
928
|
+
const lib = new LibExecutor({ workspace: this.workspace, name: libName });
|
|
929
|
+
const akanConfig2 = await lib.getConfig();
|
|
930
|
+
libScanResults[libName] = await lib.scan({ akanConfig: akanConfig2 }, libScanResults);
|
|
931
|
+
}
|
|
932
|
+
const scanResult = {
|
|
933
|
+
name: this.name,
|
|
934
|
+
type: this.type,
|
|
935
|
+
akanConfig,
|
|
936
|
+
files,
|
|
937
|
+
libDeps,
|
|
938
|
+
pkgDeps,
|
|
939
|
+
dependencies: [...npmDepSet],
|
|
940
|
+
libs: Object.fromEntries(libDeps.map((libName) => [libName, libScanResults[libName]]))
|
|
941
|
+
};
|
|
942
|
+
await this.applyTemplate({ basePath: "lib", template: "lib", scanResult });
|
|
943
|
+
await this.applyTemplate({ basePath: ".", template: "server.ts", scanResult });
|
|
944
|
+
await this.applyTemplate({ basePath: ".", template: "client.ts", scanResult });
|
|
945
|
+
if (this.type === "lib")
|
|
946
|
+
await this.applyTemplate({ basePath: ".", template: "index.ts", scanResult });
|
|
947
|
+
this.writeJson(`akan.${this.type}.json`, scanResult);
|
|
948
|
+
return scanResult;
|
|
949
|
+
}
|
|
950
|
+
async getDatabaseModules() {
|
|
951
|
+
const databaseModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs6.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
|
|
952
|
+
return databaseModules;
|
|
953
|
+
}
|
|
954
|
+
async getServiceModules() {
|
|
955
|
+
const serviceModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => name.startsWith("_") && !name.startsWith("__")).filter((name) => import_fs6.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.service.ts`));
|
|
956
|
+
return serviceModules;
|
|
957
|
+
}
|
|
958
|
+
async getScalarModules() {
|
|
959
|
+
const scalarModules = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs6.default.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
|
|
960
|
+
return scalarModules;
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
var AppExecutor = class _AppExecutor extends SysExecutor {
|
|
964
|
+
constructor({ workspace, name }) {
|
|
965
|
+
super({ workspace, name, type: "app" });
|
|
966
|
+
}
|
|
967
|
+
static from(executor, name) {
|
|
968
|
+
if (executor instanceof WorkspaceExecutor)
|
|
969
|
+
return new _AppExecutor({ workspace: executor, name });
|
|
970
|
+
return new _AppExecutor({ workspace: executor.workspace, name });
|
|
971
|
+
}
|
|
972
|
+
async getConfig(command) {
|
|
973
|
+
return await (0, import_config.getAppConfig)(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
974
|
+
}
|
|
975
|
+
async syncAssets(libDeps) {
|
|
976
|
+
const projectPublicLibPath = `${this.cwdPath}/public/libs`;
|
|
977
|
+
if (import_fs6.default.existsSync(projectPublicLibPath))
|
|
978
|
+
await import_promises.default.rm(projectPublicLibPath, { recursive: true });
|
|
979
|
+
const targetDeps = libDeps.filter((dep) => import_fs6.default.existsSync(`${this.workspace.workspaceRoot}/libs/${dep}/public`));
|
|
980
|
+
await Promise.all(targetDeps.map((dep) => import_promises.default.mkdir(`${projectPublicLibPath}/${dep}`, { recursive: true })));
|
|
981
|
+
await Promise.all(
|
|
982
|
+
targetDeps.map(
|
|
983
|
+
(dep) => import_promises.default.cp(`${this.workspace.workspaceRoot}/libs/${dep}/public`, `${projectPublicLibPath}/${dep}`, {
|
|
984
|
+
recursive: true
|
|
985
|
+
})
|
|
986
|
+
)
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
var DistAppExecutor = class _DistAppExecutor extends Executor {
|
|
991
|
+
name;
|
|
992
|
+
constructor({ workspace, name }) {
|
|
993
|
+
super(`${name} Dist App Executor`, `${workspace.workspaceRoot}/dist/apps/${name}`);
|
|
994
|
+
this.name = name;
|
|
995
|
+
}
|
|
996
|
+
static from(executor, name) {
|
|
997
|
+
if (executor instanceof WorkspaceExecutor)
|
|
998
|
+
return new _DistAppExecutor({ workspace: executor, name });
|
|
999
|
+
return new _DistAppExecutor({ workspace: executor.workspace, name });
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
var LibExecutor = class _LibExecutor extends SysExecutor {
|
|
1003
|
+
workspaceRoot;
|
|
1004
|
+
repoName;
|
|
1005
|
+
constructor({ workspace, name }) {
|
|
1006
|
+
super({ workspace, name, type: "lib" });
|
|
1007
|
+
}
|
|
1008
|
+
static from(executor, name) {
|
|
1009
|
+
if (executor instanceof WorkspaceExecutor)
|
|
1010
|
+
return new _LibExecutor({ workspace: executor, name });
|
|
1011
|
+
return new _LibExecutor({ workspace: executor.workspace, name });
|
|
1012
|
+
}
|
|
1013
|
+
async getConfig(command) {
|
|
1014
|
+
return await (0, import_config.getLibConfig)(this.cwdPath, { ...getBaseDevEnv(), appName: this.name, command });
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
var DistLibExecutor = class _DistLibExecutor extends Executor {
|
|
1018
|
+
name;
|
|
1019
|
+
constructor({ workspace, name }) {
|
|
1020
|
+
super(`${name} Dist Lib Executor`, `${workspace.workspaceRoot}/dist/libs/${name}`);
|
|
1021
|
+
this.name = name;
|
|
1022
|
+
}
|
|
1023
|
+
static from(executor, name) {
|
|
1024
|
+
if (executor instanceof WorkspaceExecutor)
|
|
1025
|
+
return new DistAppExecutor({ workspace: executor, name });
|
|
1026
|
+
return new _DistLibExecutor({ workspace: executor.workspace, name });
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
var PkgExecutor = class _PkgExecutor extends Executor {
|
|
1030
|
+
workspace;
|
|
1031
|
+
name;
|
|
1032
|
+
constructor({ workspace = WorkspaceExecutor.fromRoot(), name }) {
|
|
1033
|
+
super(`${name} Pkg Executor`, `${workspace.workspaceRoot}/pkgs/${name}`);
|
|
1034
|
+
this.workspace = workspace;
|
|
1035
|
+
this.name = name;
|
|
1036
|
+
}
|
|
1037
|
+
static from(executor, name) {
|
|
1038
|
+
if (executor instanceof WorkspaceExecutor)
|
|
1039
|
+
return new _PkgExecutor({ workspace: executor, name });
|
|
1040
|
+
return new _PkgExecutor({ workspace: executor.workspace, name });
|
|
1041
|
+
}
|
|
1042
|
+
async scan({
|
|
1043
|
+
packageJson = this.readJson(`${this.cwdPath}/package.json`),
|
|
1044
|
+
tsconfig = this.getTsConfig(`${this.cwdPath}/tsconfig.json`)
|
|
1045
|
+
} = {}) {
|
|
1046
|
+
const rootPackageJson = this.readJson(`${this.workspace.workspaceRoot}/package.json`);
|
|
1047
|
+
const scanner = new TypeScriptDependencyScanner(this.cwdPath);
|
|
1048
|
+
const npmSet = new Set(Object.keys({ ...rootPackageJson.dependencies, ...rootPackageJson.devDependencies }));
|
|
1049
|
+
const pkgPathSet = new Set(
|
|
1050
|
+
Object.keys(tsconfig.compilerOptions.paths).filter((path3) => tsconfig.compilerOptions.paths[path3].some((resolve) => resolve.startsWith("pkgs/"))).map((path3) => path3.replace("/*", ""))
|
|
1051
|
+
);
|
|
1052
|
+
const [npmDepSet, pkgPathDepSet] = await scanner.getImportSets([npmSet, pkgPathSet]);
|
|
1053
|
+
const pkgDeps = [...pkgPathDepSet].map((path3) => {
|
|
1054
|
+
const pathSplitLength = path3.split("/").length;
|
|
1055
|
+
return tsconfig.compilerOptions.paths[path3][0].split("/").slice(1, 1 + pathSplitLength).join("/");
|
|
1056
|
+
}).filter((pkg) => pkg !== this.name);
|
|
1057
|
+
const pkgScanResult = {
|
|
1058
|
+
name: this.name,
|
|
1059
|
+
pkgDeps,
|
|
1060
|
+
dependencies: [...npmDepSet]
|
|
1061
|
+
};
|
|
1062
|
+
return pkgScanResult;
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
var DistPkgExecutor = class _DistPkgExecutor extends Executor {
|
|
1066
|
+
workspaceRoot;
|
|
1067
|
+
repoName;
|
|
1068
|
+
name;
|
|
1069
|
+
constructor({ workspaceRoot, repoName, name }) {
|
|
1070
|
+
super(`${name} Dist Pkg Executor`, `${workspaceRoot}/dist/pkgs/${name}`);
|
|
1071
|
+
this.workspaceRoot = workspaceRoot;
|
|
1072
|
+
this.repoName = repoName;
|
|
1073
|
+
this.name = name;
|
|
1074
|
+
}
|
|
1075
|
+
static from(workspaceExecutor, name) {
|
|
1076
|
+
return new _DistPkgExecutor({
|
|
1077
|
+
workspaceRoot: workspaceExecutor.workspaceRoot,
|
|
1078
|
+
repoName: workspaceExecutor.repoName,
|
|
1079
|
+
name
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1493
1083
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1084
|
+
// pkgs/@akanjs/devkit/src/constants.ts
|
|
1085
|
+
var import_os = require("os");
|
|
1086
|
+
var basePath = `${(0, import_os.homedir)()}/.akan`;
|
|
1087
|
+
var configPath = `${basePath}/config.json`;
|
|
1088
|
+
var akanCloudHost = process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? "http://localhost" : "https://akasys-debug.akamir.com";
|
|
1089
|
+
var akanCloudBackendUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":8080" : ""}/backend`;
|
|
1090
|
+
var akanCloudClientUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":4200" : ""}`;
|
|
1091
|
+
var defaultHostConfig = {};
|
|
1092
|
+
var defaultAkanGlobalConfig = {};
|
|
1503
1093
|
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1094
|
+
// pkgs/@akanjs/devkit/src/auth.ts
|
|
1095
|
+
var import_fs7 = __toESM(require("fs"));
|
|
1096
|
+
var getAkanGlobalConfig = () => {
|
|
1097
|
+
const akanConfig = import_fs7.default.existsSync(configPath) ? JSON.parse(import_fs7.default.readFileSync(configPath, "utf8")) : defaultAkanGlobalConfig;
|
|
1098
|
+
return akanConfig;
|
|
1099
|
+
};
|
|
1100
|
+
var setAkanGlobalConfig = (akanConfig) => {
|
|
1101
|
+
import_fs7.default.mkdirSync(basePath, { recursive: true });
|
|
1102
|
+
import_fs7.default.writeFileSync(configPath, JSON.stringify(akanConfig, null, 2));
|
|
1103
|
+
};
|
|
1104
|
+
var getHostConfig = (host = akanCloudHost) => {
|
|
1105
|
+
const akanConfig = getAkanGlobalConfig();
|
|
1106
|
+
return akanConfig[host] ?? defaultHostConfig;
|
|
1107
|
+
};
|
|
1108
|
+
var setHostConfig = (host = akanCloudHost, config = {}) => {
|
|
1109
|
+
const akanConfig = getAkanGlobalConfig();
|
|
1110
|
+
akanConfig[host] = config;
|
|
1111
|
+
setAkanGlobalConfig(akanConfig);
|
|
1112
|
+
};
|
|
1113
|
+
var getSelf = async (token) => {
|
|
1114
|
+
try {
|
|
1115
|
+
const res = await fetch(`${akanCloudBackendUrl}/user/getSelf`, { headers: { Authorization: `Bearer ${token}` } });
|
|
1116
|
+
const user = await res.json();
|
|
1117
|
+
return user;
|
|
1118
|
+
} catch (e) {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1532
1122
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1123
|
+
// pkgs/@akanjs/devkit/src/capacitorApp.ts
|
|
1124
|
+
var import_common2 = require("@akanjs/common");
|
|
1125
|
+
var import_project = require("@trapezedev/project");
|
|
1126
|
+
var import_fs8 = __toESM(require("fs"));
|
|
1127
|
+
var CapacitorApp = class {
|
|
1128
|
+
constructor(app) {
|
|
1129
|
+
this.app = app;
|
|
1130
|
+
}
|
|
1131
|
+
project;
|
|
1132
|
+
iosTargetName = "App";
|
|
1133
|
+
async init() {
|
|
1134
|
+
const project = new import_project.MobileProject(this.app.cwdPath, {
|
|
1135
|
+
android: { path: "android" },
|
|
1136
|
+
ios: { path: "ios/App" }
|
|
1137
|
+
});
|
|
1138
|
+
await project.load();
|
|
1139
|
+
if (!project.android)
|
|
1140
|
+
throw new Error(`Android is not added, Please add platform first
|
|
1550
1141
|
akan serve-android ${this.app.name}`);
|
|
1551
|
-
|
|
1552
|
-
|
|
1142
|
+
if (!project.ios)
|
|
1143
|
+
throw new Error(`iOS is not added, Please add platform first
|
|
1553
1144
|
akan serve-ios ${this.app.name}`);
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
}
|
|
1615
|
-
this.app.logger.info(`Adding ${feature} to android`);
|
|
1616
|
-
this.project.android.getAndroidManifest().injectFragment("manifest", `<uses-feature android:name="${feature}" />`);
|
|
1145
|
+
this.project = project;
|
|
1146
|
+
return this;
|
|
1147
|
+
}
|
|
1148
|
+
async save() {
|
|
1149
|
+
await this.project.commit();
|
|
1150
|
+
}
|
|
1151
|
+
async releaseIos() {
|
|
1152
|
+
const isAdded = import_fs8.default.existsSync(`${this.app.cwdPath}/ios/App/Podfile`);
|
|
1153
|
+
if (!isAdded) {
|
|
1154
|
+
await this.app.spawn("npx cap add ios");
|
|
1155
|
+
await this.app.spawn("npx @capacitor/assets generate");
|
|
1156
|
+
} else
|
|
1157
|
+
this.app.log(`iOS already added, skip adding process`);
|
|
1158
|
+
await this.app.spawn("cross-env", ["APP_OPERATION_MODE=release", "npx", "cap", "sync", "ios"]);
|
|
1159
|
+
}
|
|
1160
|
+
async releaseAndroid() {
|
|
1161
|
+
const isAdded = import_fs8.default.existsSync(`${this.app.cwdPath}/android/app/build.gradle`);
|
|
1162
|
+
if (!isAdded) {
|
|
1163
|
+
await this.app.spawn("npx cap add android");
|
|
1164
|
+
await this.app.spawn("npx @capacitor/assets generate");
|
|
1165
|
+
} else
|
|
1166
|
+
this.app.log(`android already added, skip adding process`);
|
|
1167
|
+
await this.app.spawn("cross-env", ["APP_OPERATION_MODE=release", "npx", "cap", "sync", "android"]);
|
|
1168
|
+
}
|
|
1169
|
+
async addCamera() {
|
|
1170
|
+
await this.#setPermissionInIos({
|
|
1171
|
+
cameraUsageDescription: "$(PRODUCT_NAME) requires access to the camera to take photos.",
|
|
1172
|
+
photoAddUsageDescription: "$(PRODUCT_NAME) requires access to the photo library to take photos.",
|
|
1173
|
+
photoUsageDescription: "$(PRODUCT_NAME) requires access to the photo library to take photos."
|
|
1174
|
+
});
|
|
1175
|
+
this.#setPermissionsInAndroid(["READ_MEDIA_IMAGES", "READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"]);
|
|
1176
|
+
}
|
|
1177
|
+
async addContact() {
|
|
1178
|
+
await this.#setPermissionInIos({
|
|
1179
|
+
contactsUsageDescription: "$(PRODUCT_NAME) requires access to the contacts to add new contacts."
|
|
1180
|
+
});
|
|
1181
|
+
this.#setPermissionsInAndroid(["READ_CONTACTS", "WRITE_CONTACTS"]);
|
|
1182
|
+
}
|
|
1183
|
+
async addLocation() {
|
|
1184
|
+
await this.#setPermissionInIos({
|
|
1185
|
+
locationAlwaysUsageDescription: "$(PRODUCT_NAME) requires access to the location to get the user's location.",
|
|
1186
|
+
locationWhenInUseUsageDescription: "$(PRODUCT_NAME) requires access to the location to get the user's location."
|
|
1187
|
+
});
|
|
1188
|
+
this.#setPermissionsInAndroid(["ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION"]);
|
|
1189
|
+
this.#setFeaturesInAndroid(["android.hardware.location.gps"]);
|
|
1190
|
+
}
|
|
1191
|
+
async #setPermissionInIos(permissions) {
|
|
1192
|
+
const updateNs = Object.fromEntries(
|
|
1193
|
+
Object.entries(permissions).map(([key, value]) => [`NS${(0, import_common2.capitalize)(key)}`, value])
|
|
1194
|
+
);
|
|
1195
|
+
await Promise.all([
|
|
1196
|
+
this.project.ios.updateInfoPlist(this.iosTargetName, "Debug", updateNs),
|
|
1197
|
+
this.project.ios.updateInfoPlist(this.iosTargetName, "Release", updateNs)
|
|
1198
|
+
]);
|
|
1199
|
+
}
|
|
1200
|
+
#setFeaturesInAndroid(features) {
|
|
1201
|
+
for (const feature of features) {
|
|
1202
|
+
if (this.#hasFeatureInAndroid(feature)) {
|
|
1203
|
+
this.app.logger.info(`${feature} already exists in android`);
|
|
1204
|
+
return this;
|
|
1617
1205
|
}
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
this.app.logger.info(
|
|
1638
|
-
this
|
|
1206
|
+
this.app.logger.info(`Adding ${feature} to android`);
|
|
1207
|
+
this.project.android.getAndroidManifest().injectFragment("manifest", `<uses-feature android:name="${feature}" />`);
|
|
1208
|
+
}
|
|
1209
|
+
return this;
|
|
1210
|
+
}
|
|
1211
|
+
#getFeaturesInAndroid() {
|
|
1212
|
+
const androidManifest = this.project.android.getAndroidManifest();
|
|
1213
|
+
const element = androidManifest.getDocumentElement();
|
|
1214
|
+
if (!element)
|
|
1215
|
+
throw new Error("manifest not found");
|
|
1216
|
+
const usesFeature = element.getElementsByTagName("uses-feature");
|
|
1217
|
+
return Array.from(usesFeature).map((feature) => feature.getAttribute("android:name"));
|
|
1218
|
+
}
|
|
1219
|
+
#hasFeatureInAndroid(feature) {
|
|
1220
|
+
return this.#getFeaturesInAndroid().includes(feature);
|
|
1221
|
+
}
|
|
1222
|
+
#setPermissionsInAndroid(permissions) {
|
|
1223
|
+
for (const permission of permissions) {
|
|
1224
|
+
if (this.#hasPermissionInAndroid(permission)) {
|
|
1225
|
+
this.app.logger.info(`${permission} already exists in android`);
|
|
1226
|
+
return this;
|
|
1639
1227
|
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1228
|
+
this.app.logger.info(`Adding ${permission} to android`);
|
|
1229
|
+
this.project.android.getAndroidManifest().injectFragment("manifest", `<uses-permission android:name="android.permission.${permission}" />`);
|
|
1230
|
+
}
|
|
1231
|
+
return this;
|
|
1232
|
+
}
|
|
1233
|
+
#getPermissionsInAndroid() {
|
|
1234
|
+
const androidManifest = this.project.android.getAndroidManifest();
|
|
1235
|
+
const element = androidManifest.getDocumentElement();
|
|
1236
|
+
if (!element)
|
|
1237
|
+
throw new Error("manifest not found");
|
|
1238
|
+
const usesPermission = element.getElementsByTagName("uses-permission");
|
|
1239
|
+
return Array.from(usesPermission).map((permission) => permission.getAttribute("android:name"));
|
|
1240
|
+
}
|
|
1241
|
+
#hasPermissionInAndroid(permission) {
|
|
1242
|
+
return this.#getPermissionsInAndroid().includes(permission);
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1654
1245
|
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1246
|
+
// pkgs/@akanjs/devkit/src/extractDeps.ts
|
|
1247
|
+
var fs10 = __toESM(require("fs"));
|
|
1248
|
+
var NODE_NATIVE_MODULE_SET = /* @__PURE__ */ new Set([
|
|
1249
|
+
"assert",
|
|
1250
|
+
"async_hooks",
|
|
1251
|
+
"buffer",
|
|
1252
|
+
"child_process",
|
|
1253
|
+
"cluster",
|
|
1254
|
+
"console",
|
|
1255
|
+
"constants",
|
|
1256
|
+
"crypto",
|
|
1257
|
+
"dgram",
|
|
1258
|
+
"dns",
|
|
1259
|
+
"domain",
|
|
1260
|
+
"events",
|
|
1261
|
+
"fs",
|
|
1262
|
+
"http",
|
|
1263
|
+
"http2",
|
|
1264
|
+
"https",
|
|
1265
|
+
"inspector",
|
|
1266
|
+
"module",
|
|
1267
|
+
"net",
|
|
1268
|
+
"os",
|
|
1269
|
+
"path",
|
|
1270
|
+
"perf_hooks",
|
|
1271
|
+
"process",
|
|
1272
|
+
"punycode",
|
|
1273
|
+
"querystring",
|
|
1274
|
+
"readline",
|
|
1275
|
+
"repl",
|
|
1276
|
+
"stream",
|
|
1277
|
+
"string_decoder",
|
|
1278
|
+
"timers",
|
|
1279
|
+
"tls",
|
|
1280
|
+
"trace_events",
|
|
1281
|
+
"tty",
|
|
1282
|
+
"url",
|
|
1283
|
+
"util",
|
|
1284
|
+
"v8",
|
|
1285
|
+
"vm",
|
|
1286
|
+
"wasi",
|
|
1287
|
+
"worker_threads",
|
|
1288
|
+
"zlib"
|
|
1289
|
+
]);
|
|
1290
|
+
var extractDependencies = (bundlePath, pacakgeJson, defaultDependencies = []) => {
|
|
1291
|
+
if (!pacakgeJson.dependencies)
|
|
1292
|
+
throw new Error("No dependencies found in package.json");
|
|
1293
|
+
const code = fs10.readFileSync(bundlePath, "utf8");
|
|
1294
|
+
const dependencies = new Set(defaultDependencies);
|
|
1295
|
+
const existingDependencies = /* @__PURE__ */ new Set([
|
|
1296
|
+
...Object.keys(pacakgeJson.dependencies ?? {}),
|
|
1297
|
+
...Object.keys(pacakgeJson.devDependencies ?? {})
|
|
1698
1298
|
]);
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
const code = fs11.readFileSync(bundlePath, "utf8");
|
|
1703
|
-
const dependencies = new Set(defaultDependencies);
|
|
1704
|
-
const existingDependencies = /* @__PURE__ */ new Set([
|
|
1705
|
-
...Object.keys(pacakgeJson.dependencies ?? {}),
|
|
1706
|
-
...Object.keys(pacakgeJson.devDependencies ?? {})
|
|
1707
|
-
]);
|
|
1708
|
-
const versionObj = {
|
|
1709
|
-
...pacakgeJson.dependencies ?? {},
|
|
1710
|
-
...pacakgeJson.devDependencies ?? {}
|
|
1711
|
-
};
|
|
1712
|
-
const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
|
|
1713
|
-
let requireMatch;
|
|
1714
|
-
while ((requireMatch = requireRegex.exec(code)) !== null) {
|
|
1715
|
-
const moduleName = requireMatch[1];
|
|
1716
|
-
const moduleNameParts = moduleName.split("/");
|
|
1717
|
-
const subModuleLength = moduleNameParts.length;
|
|
1718
|
-
for (let i = 0; i < subModuleLength; i++) {
|
|
1719
|
-
const libName = moduleNameParts.slice(0, i + 1).join("/");
|
|
1720
|
-
if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName))
|
|
1721
|
-
dependencies.add(libName);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
return Object.fromEntries(
|
|
1725
|
-
[...dependencies].sort().map((dep) => {
|
|
1726
|
-
const version = versionObj[dep];
|
|
1727
|
-
if (!version)
|
|
1728
|
-
throw new Error(`No version found for ${dep}`);
|
|
1729
|
-
return [dep, version];
|
|
1730
|
-
})
|
|
1731
|
-
);
|
|
1299
|
+
const versionObj = {
|
|
1300
|
+
...pacakgeJson.dependencies ?? {},
|
|
1301
|
+
...pacakgeJson.devDependencies ?? {}
|
|
1732
1302
|
};
|
|
1303
|
+
const requireRegex = /require\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
|
|
1304
|
+
let requireMatch;
|
|
1305
|
+
while ((requireMatch = requireRegex.exec(code)) !== null) {
|
|
1306
|
+
const moduleName = requireMatch[1];
|
|
1307
|
+
const moduleNameParts = moduleName.split("/");
|
|
1308
|
+
const subModuleLength = moduleNameParts.length;
|
|
1309
|
+
for (let i = 0; i < subModuleLength; i++) {
|
|
1310
|
+
const libName = moduleNameParts.slice(0, i + 1).join("/");
|
|
1311
|
+
if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName))
|
|
1312
|
+
dependencies.add(libName);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
return Object.fromEntries(
|
|
1316
|
+
[...dependencies].sort().map((dep) => {
|
|
1317
|
+
const version = versionObj[dep];
|
|
1318
|
+
if (!version)
|
|
1319
|
+
throw new Error(`No version found for ${dep}`);
|
|
1320
|
+
return [dep, version];
|
|
1321
|
+
})
|
|
1322
|
+
);
|
|
1323
|
+
};
|
|
1733
1324
|
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1325
|
+
// pkgs/@akanjs/devkit/src/commandDecorators/argMeta.ts
|
|
1326
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
1327
|
+
var argTypes = ["Option"];
|
|
1328
|
+
var internalArgTypes = ["Workspace", "App", "Lib", "Sys", "Pkg"];
|
|
1329
|
+
var getArgMetas = (command, key) => {
|
|
1330
|
+
const allArgMetas = getArgMetasOnPrototype(command.prototype, key);
|
|
1331
|
+
const argMetas = allArgMetas.filter((argMeta) => argMeta.type === "Option");
|
|
1332
|
+
const internalArgMetas = allArgMetas.filter((argMeta) => argMeta.type !== "Option");
|
|
1333
|
+
return [allArgMetas, argMetas, internalArgMetas];
|
|
1334
|
+
};
|
|
1335
|
+
var getArgMetasOnPrototype = (prototype, key) => {
|
|
1336
|
+
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
1337
|
+
};
|
|
1338
|
+
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
1339
|
+
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
1340
|
+
};
|
|
1341
|
+
var getArg = (type) => function(name, argsOption = {}) {
|
|
1342
|
+
return function(prototype, key, idx) {
|
|
1343
|
+
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1344
|
+
argMetas[idx] = { name, argsOption, key, idx, type };
|
|
1345
|
+
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1746
1346
|
};
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1347
|
+
};
|
|
1348
|
+
var Option = getArg("Option");
|
|
1349
|
+
var createArgMetaDecorator = (type) => {
|
|
1350
|
+
return function(option = {}) {
|
|
1751
1351
|
return function(prototype, key, idx) {
|
|
1752
1352
|
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
1753
|
-
argMetas[idx] = {
|
|
1353
|
+
argMetas[idx] = { key, idx, type, option };
|
|
1754
1354
|
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1755
1355
|
};
|
|
1756
1356
|
};
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
1764
|
-
};
|
|
1765
|
-
};
|
|
1766
|
-
};
|
|
1767
|
-
var App = createArgMetaDecorator("App");
|
|
1768
|
-
var Lib = createArgMetaDecorator("Lib");
|
|
1769
|
-
var Sys = createArgMetaDecorator("Sys");
|
|
1770
|
-
var Pkg = createArgMetaDecorator("Pkg");
|
|
1771
|
-
var Workspace = createArgMetaDecorator("Workspace");
|
|
1357
|
+
};
|
|
1358
|
+
var App = createArgMetaDecorator("App");
|
|
1359
|
+
var Lib = createArgMetaDecorator("Lib");
|
|
1360
|
+
var Sys = createArgMetaDecorator("Sys");
|
|
1361
|
+
var Pkg = createArgMetaDecorator("Pkg");
|
|
1362
|
+
var Workspace = createArgMetaDecorator("Workspace");
|
|
1772
1363
|
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
};
|
|
1364
|
+
// pkgs/@akanjs/devkit/src/commandDecorators/commandMeta.ts
|
|
1365
|
+
var Commands = () => {
|
|
1366
|
+
return function(target) {
|
|
1777
1367
|
};
|
|
1368
|
+
};
|
|
1778
1369
|
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
};
|
|
1803
|
-
};
|
|
1804
|
-
var Target = {
|
|
1805
|
-
Public: getTarget("public"),
|
|
1806
|
-
Cloud: getTarget("cloud"),
|
|
1807
|
-
Dev: getTarget("dev")
|
|
1370
|
+
// pkgs/@akanjs/devkit/src/commandDecorators/targetMeta.ts
|
|
1371
|
+
var getTargetMetas = (command) => {
|
|
1372
|
+
const targetMetaMap = Reflect.getMetadata("target", command.prototype);
|
|
1373
|
+
if (!targetMetaMap)
|
|
1374
|
+
throw new Error(`TargetMeta is not defined for ${command.name}`);
|
|
1375
|
+
return [...targetMetaMap.values()];
|
|
1376
|
+
};
|
|
1377
|
+
var getTargetMetaMapOnPrototype = (prototype) => {
|
|
1378
|
+
const targetMetaMap = Reflect.getMetadata("target", prototype);
|
|
1379
|
+
return targetMetaMap ?? /* @__PURE__ */ new Map();
|
|
1380
|
+
};
|
|
1381
|
+
var setTargetMetaMapOnPrototype = (prototype, targetMetaMap) => {
|
|
1382
|
+
Reflect.defineMetadata("target", targetMetaMap, prototype);
|
|
1383
|
+
};
|
|
1384
|
+
var getTarget = (type) => (targetOption = {}) => {
|
|
1385
|
+
return (prototype, key, descriptor) => {
|
|
1386
|
+
const metadataMap = getTargetMetaMapOnPrototype(prototype);
|
|
1387
|
+
metadataMap.set(key, {
|
|
1388
|
+
key,
|
|
1389
|
+
descriptor,
|
|
1390
|
+
targetOption: { ...targetOption, type }
|
|
1391
|
+
});
|
|
1392
|
+
setTargetMetaMapOnPrototype(prototype, metadataMap);
|
|
1808
1393
|
};
|
|
1394
|
+
};
|
|
1395
|
+
var Target = {
|
|
1396
|
+
Public: getTarget("public"),
|
|
1397
|
+
Cloud: getTarget("cloud"),
|
|
1398
|
+
Dev: getTarget("dev")
|
|
1399
|
+
};
|
|
1809
1400
|
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1401
|
+
// pkgs/@akanjs/devkit/src/commandDecorators/command.ts
|
|
1402
|
+
var import_prompts3 = require("@inquirer/prompts");
|
|
1403
|
+
var import_commander = require("commander");
|
|
1404
|
+
var import_dotenv = __toESM(require("dotenv"));
|
|
1405
|
+
var camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
1406
|
+
var handleOption = (programCommand, argMeta) => {
|
|
1407
|
+
const {
|
|
1408
|
+
type,
|
|
1409
|
+
flag = argMeta.name.slice(0, 1).toLowerCase(),
|
|
1410
|
+
desc = argMeta.name,
|
|
1411
|
+
example,
|
|
1412
|
+
enum: choices,
|
|
1413
|
+
ask
|
|
1414
|
+
} = argMeta.argsOption;
|
|
1415
|
+
const kebabName = camelToKebabCase(argMeta.name);
|
|
1416
|
+
programCommand.option(
|
|
1417
|
+
`-${flag}, --${kebabName} <${kebabName}>`,
|
|
1418
|
+
`${desc}${ask ? ` (${ask})` : ""}${example ? ` (example: ${example})` : ""}${choices ? ` (choices: ${choices.join(", ")})` : ""}`
|
|
1419
|
+
);
|
|
1420
|
+
return programCommand;
|
|
1421
|
+
};
|
|
1422
|
+
var convertOptionValue = (value, type) => {
|
|
1423
|
+
if (type === "string")
|
|
1424
|
+
return value;
|
|
1425
|
+
else if (type === "number")
|
|
1426
|
+
return Number(value);
|
|
1427
|
+
else
|
|
1428
|
+
return value === "true";
|
|
1429
|
+
};
|
|
1430
|
+
var getOptionValue = async (argMeta, opt) => {
|
|
1431
|
+
const {
|
|
1432
|
+
name,
|
|
1433
|
+
argsOption: { enum: choices, default: defaultValue, type, desc, nullable, example, ask }
|
|
1434
|
+
} = argMeta;
|
|
1435
|
+
if (opt[argMeta.name] !== void 0)
|
|
1436
|
+
return convertOptionValue(opt[argMeta.name], type ?? "string");
|
|
1437
|
+
else if (defaultValue !== void 0)
|
|
1438
|
+
return defaultValue;
|
|
1439
|
+
else if (nullable)
|
|
1440
|
+
return null;
|
|
1441
|
+
if (choices) {
|
|
1442
|
+
const choice = await (0, import_prompts3.select)({
|
|
1443
|
+
message: ask ?? `Select the ${name} value`,
|
|
1444
|
+
choices: choices.map((choice2) => choice2.toString())
|
|
1445
|
+
});
|
|
1446
|
+
return choice;
|
|
1447
|
+
} else if (type === "boolean") {
|
|
1448
|
+
const message = ask ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
|
|
1449
|
+
return await (0, import_prompts3.confirm)({ message });
|
|
1450
|
+
} else {
|
|
1451
|
+
const message = ask ?? `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
1452
|
+
if (argMeta.argsOption.nullable)
|
|
1453
|
+
return await (0, import_prompts3.input)({ message });
|
|
1836
1454
|
else
|
|
1837
|
-
return
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
if (
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
const
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
for (const targetMeta of targetMetas) {
|
|
1908
|
-
const kebabKey = camelToKebabCase(targetMeta.key);
|
|
1909
|
-
const commandNames = targetMeta.targetOption.short === true ? [
|
|
1910
|
-
kebabKey,
|
|
1911
|
-
typeof targetMeta.targetOption.short === "string" ? targetMeta.targetOption.short : kebabKey.split("-").map((s) => s.slice(0, 1)).join("")
|
|
1912
|
-
] : [kebabKey];
|
|
1913
|
-
for (const commandName of commandNames) {
|
|
1914
|
-
let programCommand = import_commander.program.command(commandName, {
|
|
1915
|
-
hidden: targetMeta.targetOption.devOnly
|
|
1916
|
-
});
|
|
1917
|
-
const [allArgMetas] = getArgMetas(command, targetMeta.key);
|
|
1455
|
+
return convertOptionValue(await (0, import_prompts3.input)({ message }), type ?? "string");
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
var getArgumentValue = async (argMeta, value, workspace) => {
|
|
1459
|
+
if (argMeta.type === "Workspace")
|
|
1460
|
+
return workspace;
|
|
1461
|
+
const sysType = argMeta.type.toLowerCase();
|
|
1462
|
+
if (sysType === "sys") {
|
|
1463
|
+
const [appNames, libNames] = await workspace.getSyss();
|
|
1464
|
+
const sysName = await (0, import_prompts3.select)({
|
|
1465
|
+
message: `Select the App or Lib name`,
|
|
1466
|
+
choices: [...appNames, ...libNames]
|
|
1467
|
+
});
|
|
1468
|
+
if (appNames.includes(sysName))
|
|
1469
|
+
return AppExecutor.from(workspace, sysName);
|
|
1470
|
+
else
|
|
1471
|
+
return LibExecutor.from(workspace, sysName);
|
|
1472
|
+
} else if (sysType === "app") {
|
|
1473
|
+
if (value)
|
|
1474
|
+
return AppExecutor.from(workspace, value);
|
|
1475
|
+
const apps = await workspace.getApps();
|
|
1476
|
+
const appName = await (0, import_prompts3.select)({ message: `Select the ${sysType} name`, choices: apps });
|
|
1477
|
+
return AppExecutor.from(workspace, appName);
|
|
1478
|
+
} else if (sysType === "lib") {
|
|
1479
|
+
if (value)
|
|
1480
|
+
return LibExecutor.from(workspace, value);
|
|
1481
|
+
const libs = await workspace.getLibs();
|
|
1482
|
+
const libName = await (0, import_prompts3.select)({ message: `Select the ${sysType} name`, choices: libs });
|
|
1483
|
+
return LibExecutor.from(workspace, libName);
|
|
1484
|
+
} else if (sysType === "pkg") {
|
|
1485
|
+
if (value)
|
|
1486
|
+
return PkgExecutor.from(workspace, value);
|
|
1487
|
+
const pkgs = await workspace.getPkgs();
|
|
1488
|
+
const pkgName = await (0, import_prompts3.select)({ message: `Select the ${sysType} name`, choices: pkgs });
|
|
1489
|
+
return PkgExecutor.from(workspace, pkgName);
|
|
1490
|
+
} else
|
|
1491
|
+
throw new Error(`Invalid system type: ${argMeta.type}`);
|
|
1492
|
+
};
|
|
1493
|
+
var runCommands = async (...commands) => {
|
|
1494
|
+
import_dotenv.default.config();
|
|
1495
|
+
import_commander.program.version("0.0.1").description("An example CLI for managing a directory");
|
|
1496
|
+
for (const command of commands) {
|
|
1497
|
+
const targetMetas = getTargetMetas(command);
|
|
1498
|
+
for (const targetMeta of targetMetas) {
|
|
1499
|
+
const kebabKey = camelToKebabCase(targetMeta.key);
|
|
1500
|
+
const commandNames = targetMeta.targetOption.short === true ? [
|
|
1501
|
+
kebabKey,
|
|
1502
|
+
typeof targetMeta.targetOption.short === "string" ? targetMeta.targetOption.short : kebabKey.split("-").map((s) => s.slice(0, 1)).join("")
|
|
1503
|
+
] : [kebabKey];
|
|
1504
|
+
for (const commandName of commandNames) {
|
|
1505
|
+
let programCommand = import_commander.program.command(commandName, {
|
|
1506
|
+
hidden: targetMeta.targetOption.devOnly
|
|
1507
|
+
});
|
|
1508
|
+
const [allArgMetas] = getArgMetas(command, targetMeta.key);
|
|
1509
|
+
for (const argMeta of allArgMetas) {
|
|
1510
|
+
if (argMeta.type === "Option")
|
|
1511
|
+
programCommand = handleOption(programCommand, argMeta);
|
|
1512
|
+
else if (argMeta.type === "Workspace")
|
|
1513
|
+
continue;
|
|
1514
|
+
const sysType = argMeta.type.toLowerCase();
|
|
1515
|
+
programCommand = programCommand.argument(
|
|
1516
|
+
`[${sysType}]`,
|
|
1517
|
+
`${sysType} in this workspace ${sysType}s/<${sysType}Name>`
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
programCommand.action(async (...args) => {
|
|
1521
|
+
const cmdArgs = args.slice(0, args.length - 2);
|
|
1522
|
+
const opt = args[args.length - 2];
|
|
1523
|
+
const commandArgs = [];
|
|
1524
|
+
const workspace = WorkspaceExecutor.fromRoot();
|
|
1918
1525
|
for (const argMeta of allArgMetas) {
|
|
1919
1526
|
if (argMeta.type === "Option")
|
|
1920
|
-
|
|
1921
|
-
else
|
|
1922
|
-
|
|
1923
|
-
const sysType = argMeta.type.toLowerCase();
|
|
1924
|
-
programCommand = programCommand.argument(
|
|
1925
|
-
`[${sysType}]`,
|
|
1926
|
-
`${sysType} in this workspace ${sysType}s/<${sysType}Name>`
|
|
1927
|
-
);
|
|
1527
|
+
commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt);
|
|
1528
|
+
else
|
|
1529
|
+
commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace);
|
|
1928
1530
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
const commandArgs = [];
|
|
1933
|
-
const workspace = WorkspaceExecutor.fromRoot();
|
|
1934
|
-
for (const argMeta of allArgMetas) {
|
|
1935
|
-
if (argMeta.type === "Option")
|
|
1936
|
-
commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt);
|
|
1937
|
-
else
|
|
1938
|
-
commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace);
|
|
1939
|
-
}
|
|
1940
|
-
const cmd = new command();
|
|
1941
|
-
await cmd[targetMeta.key](...commandArgs);
|
|
1942
|
-
});
|
|
1943
|
-
}
|
|
1531
|
+
const cmd = new command();
|
|
1532
|
+
await cmd[targetMeta.key](...commandArgs);
|
|
1533
|
+
});
|
|
1944
1534
|
}
|
|
1945
1535
|
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1536
|
+
}
|
|
1537
|
+
await import_commander.program.parseAsync(process.argv);
|
|
1538
|
+
};
|
|
1948
1539
|
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
})();
|
|
1540
|
+
// pkgs/@akanjs/devkit/src/installExternalLib.ts
|
|
1541
|
+
var installExternalLib = async (libName, workspace) => {
|
|
1542
|
+
workspace.log(`Installing ${libName} library as git subtree...`);
|
|
1543
|
+
await workspace.exec(`git remote add ${libName} git@github.com:akan-team/${libName}.git`);
|
|
1544
|
+
await workspace.exec(`git subtree add --prefix=libs/${libName} ${libName} main`);
|
|
1545
|
+
};
|
|
1956
1546
|
//!Field.Prop 거르기가 빡세네.
|
|
1957
1547
|
//! Temp
|