@akanjs/devkit 0.0.89 → 0.0.90
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 +21 -1
- package/index.mjs +1 -0
- package/package.json +5 -4
- package/src/aiEditor.d.ts +14 -0
- package/src/aiEditor.js +110 -21
- package/src/aiEditor.mjs +124 -0
- package/src/auth.js +48 -18
- package/src/auth.mjs +42 -0
- package/src/capacitorApp.js +42 -9
- package/src/{capacitorApp.cjs → capacitorApp.mjs} +9 -42
- package/src/commandDecorators/argMeta.js +34 -3
- package/src/commandDecorators/{argMeta.cjs → argMeta.mjs} +3 -34
- package/src/commandDecorators/command.js +68 -35
- package/src/commandDecorators/{command.cjs → command.mjs} +35 -68
- package/src/commandDecorators/commandMeta.js +25 -2
- package/src/commandDecorators/commandMeta.mjs +7 -0
- package/src/commandDecorators/index.js +29 -5
- package/src/commandDecorators/index.mjs +5 -0
- package/src/commandDecorators/targetMeta.js +26 -2
- package/src/commandDecorators/targetMeta.mjs +33 -0
- package/src/commandDecorators/types.js +15 -0
- package/src/commandDecorators/types.mjs +0 -0
- package/src/constants.d.ts +8 -1
- package/src/constants.js +34 -5
- package/src/constants.mjs +18 -0
- package/src/createTunnel.js +27 -4
- package/src/createTunnel.mjs +26 -0
- package/src/dependencyScanner.js +38 -5
- package/src/{dependencyScanner.cjs → dependencyScanner.mjs} +5 -38
- package/src/executors.d.ts +21 -1
- package/src/executors.js +172 -84
- package/src/{executors.cjs → executors.mjs} +138 -118
- package/src/extractDeps.js +25 -2
- package/src/{extractDeps.cjs → extractDeps.mjs} +2 -25
- package/src/getCredentials.js +39 -6
- package/src/getCredentials.mjs +11 -0
- package/src/getModelFileData.js +39 -6
- package/src/getModelFileData.mjs +33 -0
- package/src/getRelatedCnsts.d.ts +52 -8
- package/src/getRelatedCnsts.js +205 -54
- package/src/getRelatedCnsts.mjs +221 -0
- package/src/index.js +51 -16
- package/src/index.mjs +16 -0
- package/src/selectModel.js +39 -6
- package/src/selectModel.mjs +13 -0
- package/src/streamAi.js +30 -7
- package/src/streamAi.mjs +39 -0
- package/src/types.js +15 -0
- package/src/types.mjs +0 -0
- package/src/uploadRelease.js +48 -15
- package/src/uploadRelease.mjs +52 -0
- package/index.cjs +0 -21
- package/src/aiEditor.cjs +0 -92
- package/src/auth.cjs +0 -72
- package/src/commandDecorators/commandMeta.cjs +0 -30
- package/src/commandDecorators/index.cjs +0 -29
- package/src/commandDecorators/targetMeta.cjs +0 -57
- package/src/commandDecorators/types.cjs +0 -15
- package/src/constants.cjs +0 -47
- package/src/createTunnel.cjs +0 -49
- package/src/getCredentials.cjs +0 -44
- package/src/getModelFileData.cjs +0 -66
- package/src/getRelatedCnsts.cjs +0 -142
- package/src/index.cjs +0 -51
- package/src/selectModel.cjs +0 -46
- package/src/streamAi.cjs +0 -62
- package/src/types.cjs +0 -15
- package/src/uploadRelease.cjs +0 -85
package/src/getModelFileData.js
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var getModelFileData_exports = {};
|
|
29
|
+
__export(getModelFileData_exports, {
|
|
30
|
+
getModelFileData: () => getModelFileData
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(getModelFileData_exports);
|
|
33
|
+
var import_fs = __toESM(require("fs"));
|
|
2
34
|
const getModelFileData = (modulePath, modelName) => {
|
|
3
35
|
const moduleType = modulePath.startsWith("apps") ? "app" : "lib";
|
|
4
36
|
const moduleName = modulePath.split("/")[1];
|
|
5
37
|
const constantFilePath = `${modulePath}/lib/${modelName}/${modelName}.constant.ts`;
|
|
6
38
|
const unitFilePath = `${modulePath}/lib/${modelName}/${modelName}.Unit.tsx`;
|
|
7
39
|
const viewFilePath = `${modulePath}/lib/${modelName}/${modelName}.View.tsx`;
|
|
8
|
-
const constantFileStr =
|
|
9
|
-
const unitFileStr =
|
|
10
|
-
const viewFileStr =
|
|
40
|
+
const constantFileStr = import_fs.default.readFileSync(constantFilePath, "utf8");
|
|
41
|
+
const unitFileStr = import_fs.default.readFileSync(unitFilePath, "utf8");
|
|
42
|
+
const viewFileStr = import_fs.default.readFileSync(viewFilePath, "utf8");
|
|
11
43
|
const constantFileLines = constantFileStr.split("\n");
|
|
12
44
|
const importLibNames = constantFileLines.filter((line) => line.startsWith("import { cnst as ")).map((line) => line.split("cnst as ")[1].split(" ")[0]);
|
|
13
45
|
const importLocalPaths = constantFileLines.filter((line) => line.startsWith("import { ") && line.includes('from "../')).map((line) => line.split("from ")[1].split('"')[1]);
|
|
@@ -28,6 +60,7 @@ const getModelFileData = (modulePath, modelName) => {
|
|
|
28
60
|
viewFileStr
|
|
29
61
|
};
|
|
30
62
|
};
|
|
31
|
-
export
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
32
65
|
getModelFileData
|
|
33
|
-
};
|
|
66
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
const getModelFileData = (modulePath, modelName) => {
|
|
3
|
+
const moduleType = modulePath.startsWith("apps") ? "app" : "lib";
|
|
4
|
+
const moduleName = modulePath.split("/")[1];
|
|
5
|
+
const constantFilePath = `${modulePath}/lib/${modelName}/${modelName}.constant.ts`;
|
|
6
|
+
const unitFilePath = `${modulePath}/lib/${modelName}/${modelName}.Unit.tsx`;
|
|
7
|
+
const viewFilePath = `${modulePath}/lib/${modelName}/${modelName}.View.tsx`;
|
|
8
|
+
const constantFileStr = fs.readFileSync(constantFilePath, "utf8");
|
|
9
|
+
const unitFileStr = fs.readFileSync(unitFilePath, "utf8");
|
|
10
|
+
const viewFileStr = fs.readFileSync(viewFilePath, "utf8");
|
|
11
|
+
const constantFileLines = constantFileStr.split("\n");
|
|
12
|
+
const importLibNames = constantFileLines.filter((line) => line.startsWith("import { cnst as ")).map((line) => line.split("cnst as ")[1].split(" ")[0]);
|
|
13
|
+
const importLocalPaths = constantFileLines.filter((line) => line.startsWith("import { ") && line.includes('from "../')).map((line) => line.split("from ")[1].split('"')[1]);
|
|
14
|
+
const importModelNames = importLocalPaths.map((path) => path.split("/")[1]).filter((name) => !name.startsWith("_"));
|
|
15
|
+
const hasImportScalar = !!importLocalPaths.map((path) => path.split("/")[1]).filter((name) => name.startsWith("_")).length;
|
|
16
|
+
return {
|
|
17
|
+
moduleType,
|
|
18
|
+
moduleName,
|
|
19
|
+
modelName,
|
|
20
|
+
constantFilePath,
|
|
21
|
+
unitFilePath,
|
|
22
|
+
viewFilePath,
|
|
23
|
+
importModelNames,
|
|
24
|
+
hasImportScalar,
|
|
25
|
+
importLibNames,
|
|
26
|
+
constantFileStr,
|
|
27
|
+
unitFileStr,
|
|
28
|
+
viewFileStr
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
getModelFileData
|
|
33
|
+
};
|
package/src/getRelatedCnsts.d.ts
CHANGED
|
@@ -1,9 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript 설정 파일을 읽고 파싱하는 함수
|
|
4
|
+
*/
|
|
5
|
+
export declare const parseTsConfig: (tsConfigPath?: string) => ts.ParsedCommandLine;
|
|
6
|
+
/**
|
|
7
|
+
* 파일 내의 임포트를 기반으로 관련 파일을 수집하는 함수
|
|
8
|
+
*/
|
|
9
|
+
export declare const collectImportedFiles: (constantFilePath: string, parsedConfig: ts.ParsedCommandLine) => {
|
|
10
|
+
allFilesToAnalyze: Set<string>;
|
|
11
|
+
analyzedFiles: Set<string>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* export 선언을 기반으로 관련 파일을 수집하는 함수
|
|
15
|
+
*/
|
|
16
|
+
export declare const collectExportedFiles: (constantFilePath: string, parsedConfig: ts.ParsedCommandLine) => {
|
|
17
|
+
allFilesToAnalyze: Set<string>;
|
|
18
|
+
analyzedFiles: Set<string>;
|
|
9
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* TypeScript 프로그램 생성 함수
|
|
22
|
+
*/
|
|
23
|
+
export declare const createTsProgram: (filePaths: Set<string>, options: ts.CompilerOptions) => {
|
|
24
|
+
program: ts.Program;
|
|
25
|
+
checker: ts.TypeChecker;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 심볼 캐싱 및 조회 함수 생성기
|
|
29
|
+
*/
|
|
30
|
+
export declare const createSymbolCache: (checker: ts.TypeChecker) => (node: ts.Node) => ts.Symbol | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* 파일 속성 분석 함수
|
|
33
|
+
*/
|
|
34
|
+
export declare const analyzeProperties: (filesToAnalyze: Set<string>, program: ts.Program, checker: ts.TypeChecker) => Map<string, {
|
|
35
|
+
filePath: string;
|
|
36
|
+
isLibModule: boolean;
|
|
37
|
+
isImport: boolean;
|
|
38
|
+
isScalar: boolean;
|
|
39
|
+
source: string;
|
|
40
|
+
libName?: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* 메인 함수: 상수 파일 관련 요소 분석
|
|
44
|
+
*/
|
|
45
|
+
export declare const getRelatedCnsts: (constantFilePath: string) => {
|
|
46
|
+
filePath: string;
|
|
47
|
+
isLibModule: boolean;
|
|
48
|
+
isImport: boolean;
|
|
49
|
+
isScalar: boolean;
|
|
50
|
+
source: string;
|
|
51
|
+
libName?: string;
|
|
52
|
+
key: string;
|
|
53
|
+
}[];
|
package/src/getRelatedCnsts.js
CHANGED
|
@@ -1,23 +1,183 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var getRelatedCnsts_exports = {};
|
|
29
|
+
__export(getRelatedCnsts_exports, {
|
|
30
|
+
analyzeProperties: () => analyzeProperties,
|
|
31
|
+
collectExportedFiles: () => collectExportedFiles,
|
|
32
|
+
collectImportedFiles: () => collectImportedFiles,
|
|
33
|
+
createSymbolCache: () => createSymbolCache,
|
|
34
|
+
createTsProgram: () => createTsProgram,
|
|
35
|
+
getRelatedCnsts: () => getRelatedCnsts,
|
|
36
|
+
parseTsConfig: () => parseTsConfig
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(getRelatedCnsts_exports);
|
|
39
|
+
var fs = __toESM(require("fs"));
|
|
40
|
+
var import_ora = __toESM(require("ora"));
|
|
41
|
+
var ts = __toESM(require("typescript"));
|
|
42
|
+
const parseTsConfig = (tsConfigPath = "./tsconfig.json") => {
|
|
6
43
|
const configFile = ts.readConfigFile(tsConfigPath, (path) => {
|
|
7
44
|
return ts.sys.readFile(path);
|
|
8
45
|
});
|
|
9
|
-
|
|
46
|
+
return ts.parseJsonConfigFileContent(
|
|
10
47
|
configFile.config,
|
|
11
48
|
ts.sys,
|
|
12
49
|
fs.realpathSync(tsConfigPath).replace(/[^/\\]+$/, "")
|
|
13
50
|
);
|
|
51
|
+
};
|
|
52
|
+
const collectImportedFiles = (constantFilePath, parsedConfig) => {
|
|
53
|
+
const allFilesToAnalyze = /* @__PURE__ */ new Set([constantFilePath]);
|
|
54
|
+
const analyzedFiles = /* @__PURE__ */ new Set();
|
|
55
|
+
const spinner = (0, import_ora.default)("Collecting related files...");
|
|
56
|
+
spinner.start();
|
|
57
|
+
function collectImported(filePath) {
|
|
58
|
+
if (analyzedFiles.has(filePath))
|
|
59
|
+
return;
|
|
60
|
+
analyzedFiles.add(filePath);
|
|
61
|
+
const tempProgram = ts.createProgram([filePath], parsedConfig.options);
|
|
62
|
+
const source = tempProgram.getSourceFile(filePath);
|
|
63
|
+
if (!source)
|
|
64
|
+
return;
|
|
65
|
+
function collectImports(node) {
|
|
66
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
67
|
+
const importPath = node.moduleSpecifier.text;
|
|
68
|
+
if (importPath.startsWith(".")) {
|
|
69
|
+
const resolved = ts.resolveModuleName(importPath, filePath, parsedConfig.options, ts.sys).resolvedModule?.resolvedFileName;
|
|
70
|
+
if (resolved && !allFilesToAnalyze.has(resolved)) {
|
|
71
|
+
allFilesToAnalyze.add(resolved);
|
|
72
|
+
collectImported(resolved);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
ts.forEachChild(node, collectImports);
|
|
77
|
+
}
|
|
78
|
+
collectImports(source);
|
|
79
|
+
}
|
|
80
|
+
collectImported(constantFilePath);
|
|
81
|
+
spinner.succeed(`Found ${allFilesToAnalyze.size} related files.`);
|
|
82
|
+
return {
|
|
83
|
+
allFilesToAnalyze,
|
|
84
|
+
analyzedFiles
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const collectExportedFiles = (constantFilePath, parsedConfig) => {
|
|
88
|
+
const allFilesToAnalyze = /* @__PURE__ */ new Set([constantFilePath]);
|
|
89
|
+
const analyzedFiles = /* @__PURE__ */ new Set();
|
|
90
|
+
const spinner = (0, import_ora.default)("Collecting files from exports...");
|
|
91
|
+
spinner.start();
|
|
92
|
+
function collectExported(filePath) {
|
|
93
|
+
if (analyzedFiles.has(filePath))
|
|
94
|
+
return;
|
|
95
|
+
analyzedFiles.add(filePath);
|
|
96
|
+
const tempProgram = ts.createProgram([filePath], parsedConfig.options);
|
|
97
|
+
const source = tempProgram.getSourceFile(filePath);
|
|
98
|
+
if (!source)
|
|
99
|
+
return;
|
|
100
|
+
function collectExports(node) {
|
|
101
|
+
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier) && !node.exportClause) {
|
|
102
|
+
const exportPath = node.moduleSpecifier.text;
|
|
103
|
+
if (exportPath.startsWith(".")) {
|
|
104
|
+
const resolved = ts.resolveModuleName(exportPath, filePath, parsedConfig.options, ts.sys).resolvedModule?.resolvedFileName;
|
|
105
|
+
if (resolved && !allFilesToAnalyze.has(resolved)) {
|
|
106
|
+
allFilesToAnalyze.add(resolved);
|
|
107
|
+
collectExported(resolved);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} else if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
111
|
+
const exportPath = node.moduleSpecifier.text;
|
|
112
|
+
if (exportPath.startsWith(".")) {
|
|
113
|
+
const resolved = ts.resolveModuleName(exportPath, filePath, parsedConfig.options, ts.sys).resolvedModule?.resolvedFileName;
|
|
114
|
+
if (resolved && !allFilesToAnalyze.has(resolved)) {
|
|
115
|
+
allFilesToAnalyze.add(resolved);
|
|
116
|
+
collectExported(resolved);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} else if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
120
|
+
const importPath = node.moduleSpecifier.text;
|
|
121
|
+
if (importPath.startsWith(".")) {
|
|
122
|
+
const resolved = ts.resolveModuleName(importPath, filePath, parsedConfig.options, ts.sys).resolvedModule?.resolvedFileName;
|
|
123
|
+
if (resolved && !allFilesToAnalyze.has(resolved)) {
|
|
124
|
+
allFilesToAnalyze.add(resolved);
|
|
125
|
+
collectExported(resolved);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if ((ts.isVariableStatement(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
130
|
+
}
|
|
131
|
+
ts.forEachChild(node, collectExports);
|
|
132
|
+
}
|
|
133
|
+
collectExports(source);
|
|
134
|
+
}
|
|
135
|
+
collectExported(constantFilePath);
|
|
136
|
+
spinner.succeed(`Found ${allFilesToAnalyze.size} related files from exports.`);
|
|
137
|
+
return {
|
|
138
|
+
allFilesToAnalyze,
|
|
139
|
+
analyzedFiles
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
const createTsProgram = (filePaths, options) => {
|
|
143
|
+
const spinner = (0, import_ora.default)("Creating TypeScript program for all files...");
|
|
144
|
+
spinner.start();
|
|
145
|
+
const program = ts.createProgram(Array.from(filePaths), options);
|
|
146
|
+
const checker = program.getTypeChecker();
|
|
147
|
+
spinner.succeed("TypeScript program created.");
|
|
148
|
+
return {
|
|
149
|
+
program,
|
|
150
|
+
checker
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
const createSymbolCache = (checker) => {
|
|
154
|
+
const symbolCache = /* @__PURE__ */ new Map();
|
|
155
|
+
return (node) => {
|
|
156
|
+
const cacheKey = `${node.getSourceFile().fileName}:${node.pos}:${node.end}`;
|
|
157
|
+
if (!symbolCache.has(cacheKey)) {
|
|
158
|
+
symbolCache.set(cacheKey, checker.getSymbolAtLocation(node));
|
|
159
|
+
}
|
|
160
|
+
return symbolCache.get(cacheKey);
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
const analyzeProperties = (filesToAnalyze, program, checker) => {
|
|
14
164
|
const propertyMap = /* @__PURE__ */ new Map();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
165
|
+
const analyzedFiles = /* @__PURE__ */ new Set();
|
|
166
|
+
const sourceLineCache = /* @__PURE__ */ new Map();
|
|
167
|
+
const getCachedSymbol = createSymbolCache(checker);
|
|
168
|
+
const spinner = (0, import_ora.default)("Analyzing property relationships...");
|
|
169
|
+
spinner.start();
|
|
170
|
+
function analyzeFileProperties(filePath) {
|
|
171
|
+
if (analyzedFiles.has(filePath))
|
|
172
|
+
return;
|
|
173
|
+
analyzedFiles.add(filePath);
|
|
18
174
|
const source = program.getSourceFile(filePath);
|
|
19
175
|
if (!source)
|
|
20
|
-
return
|
|
176
|
+
return;
|
|
177
|
+
if (!sourceLineCache.has(filePath)) {
|
|
178
|
+
sourceLineCache.set(filePath, source.getFullText().split("\n"));
|
|
179
|
+
}
|
|
180
|
+
const sourceLines = sourceLineCache.get(filePath);
|
|
21
181
|
function visit(node) {
|
|
22
182
|
if (!source)
|
|
23
183
|
return;
|
|
@@ -25,38 +185,38 @@ const getRelatedCnsts = (constantFilePath) => {
|
|
|
25
185
|
const left = node.expression;
|
|
26
186
|
const right = node.name;
|
|
27
187
|
const { line } = ts.getLineAndCharacterOfPosition(source, node.getStart());
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (ts.isIdentifier(left) && sourceLines.length && (sourceLines[line].includes(`@Field.Prop(() => ${left.text}.${right.text}`) || sourceLines[line].includes(`base.Filter(${left.text}.${right.text},`))) {
|
|
31
|
-
const symbol = checker.getSymbolAtLocation(right);
|
|
188
|
+
if (ts.isIdentifier(left) && sourceLines && sourceLines.length > line && (sourceLines[line].includes(`@Field.Prop(() => ${left.text}.${right.text}`) || sourceLines[line].includes(`base.Filter(${left.text}.${right.text},`))) {
|
|
189
|
+
const symbol = getCachedSymbol(right);
|
|
32
190
|
if (symbol?.declarations && symbol.declarations.length > 0) {
|
|
33
191
|
const key = symbol.declarations[0].getSourceFile().fileName.split("/").pop()?.split(".")[0] ?? "";
|
|
34
192
|
const property = propertyMap.get(key);
|
|
35
193
|
const isScalar = symbol.declarations[0].getSourceFile().fileName.includes("_");
|
|
36
|
-
const
|
|
194
|
+
const symbolFilePath = symbol.declarations[0].getSourceFile().fileName.replace(`${ts.sys.getCurrentDirectory()}/`, "");
|
|
37
195
|
if (property) {
|
|
38
196
|
propertyMap.set(`${left.text}.${right.text}`, {
|
|
39
|
-
filePath:
|
|
197
|
+
filePath: symbolFilePath,
|
|
40
198
|
isLibModule: true,
|
|
41
199
|
isImport: false,
|
|
42
200
|
libName: left.text,
|
|
201
|
+
source: fs.readFileSync(symbolFilePath, "utf-8"),
|
|
43
202
|
isScalar
|
|
44
203
|
});
|
|
45
|
-
} else
|
|
204
|
+
} else {
|
|
46
205
|
propertyMap.set(key, {
|
|
47
|
-
filePath:
|
|
206
|
+
filePath: symbolFilePath,
|
|
48
207
|
isLibModule: true,
|
|
49
208
|
isImport: false,
|
|
50
209
|
libName: left.text,
|
|
51
|
-
isScalar
|
|
210
|
+
isScalar,
|
|
211
|
+
source: fs.readFileSync(symbolFilePath, "utf-8")
|
|
52
212
|
});
|
|
53
|
-
|
|
213
|
+
}
|
|
54
214
|
}
|
|
55
215
|
}
|
|
56
|
-
} else if (ts.isImportDeclaration(node)) {
|
|
57
|
-
const importPath = node.moduleSpecifier.
|
|
216
|
+
} else if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
217
|
+
const importPath = node.moduleSpecifier.text;
|
|
58
218
|
if (importPath.startsWith(".")) {
|
|
59
|
-
const resolved = ts.resolveModuleName(importPath, filePath,
|
|
219
|
+
const resolved = ts.resolveModuleName(importPath, filePath, program.getCompilerOptions(), ts.sys).resolvedModule?.resolvedFileName;
|
|
60
220
|
const moduleName = importPath.split("/").pop()?.split(".")[0] ?? "";
|
|
61
221
|
const property = propertyMap.get(moduleName);
|
|
62
222
|
const isScalar = importPath.includes("_");
|
|
@@ -65,45 +225,36 @@ const getRelatedCnsts = (constantFilePath) => {
|
|
|
65
225
|
filePath: resolved,
|
|
66
226
|
isLibModule: false,
|
|
67
227
|
isImport: true,
|
|
68
|
-
isScalar
|
|
228
|
+
isScalar,
|
|
229
|
+
source: fs.readFileSync(resolved, "utf-8")
|
|
69
230
|
});
|
|
70
|
-
findPropertyOriginAll(resolved);
|
|
71
231
|
}
|
|
72
232
|
}
|
|
73
233
|
}
|
|
74
234
|
ts.forEachChild(node, visit);
|
|
75
235
|
}
|
|
76
236
|
visit(source);
|
|
77
|
-
return propertyMap;
|
|
78
237
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const checker = program.getTypeChecker();
|
|
82
|
-
const source = program.getSourceFile(filePath);
|
|
83
|
-
const propertyMap2 = /* @__PURE__ */ new Map();
|
|
84
|
-
if (!source)
|
|
85
|
-
return null;
|
|
86
|
-
function visit(node) {
|
|
87
|
-
if (ts.isPropertyAccessExpression(node)) {
|
|
88
|
-
const left = node.expression;
|
|
89
|
-
const right = node.name;
|
|
90
|
-
if (ts.isIdentifier(left) && left.text === aliasName && right.text === libName) {
|
|
91
|
-
const symbol = checker.getSymbolAtLocation(right);
|
|
92
|
-
if (symbol?.declarations && symbol.declarations.length > 0) {
|
|
93
|
-
return symbol.declarations[0].getSourceFile().fileName;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return ts.forEachChild(node, visit) || null;
|
|
98
|
-
}
|
|
99
|
-
return visit(source);
|
|
238
|
+
for (const filePath of filesToAnalyze) {
|
|
239
|
+
analyzeFileProperties(filePath);
|
|
100
240
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const paths = findPropertyOriginAll(constantFilePath);
|
|
104
|
-
spinner.succeed("property origin found.");
|
|
105
|
-
return { paths };
|
|
241
|
+
spinner.succeed(`Analysis complete. Found ${propertyMap.size} properties.`);
|
|
242
|
+
return propertyMap;
|
|
106
243
|
};
|
|
107
|
-
|
|
108
|
-
|
|
244
|
+
const getRelatedCnsts = (constantFilePath) => {
|
|
245
|
+
const parsedConfig = parseTsConfig();
|
|
246
|
+
const { allFilesToAnalyze } = collectImportedFiles(constantFilePath, parsedConfig);
|
|
247
|
+
const { program, checker } = createTsProgram(allFilesToAnalyze, parsedConfig.options);
|
|
248
|
+
const propertyMap = analyzeProperties(allFilesToAnalyze, program, checker);
|
|
249
|
+
return Array.from(propertyMap.entries()).map(([key, value]) => ({ key, ...value }));
|
|
109
250
|
};
|
|
251
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
+
0 && (module.exports = {
|
|
253
|
+
analyzeProperties,
|
|
254
|
+
collectExportedFiles,
|
|
255
|
+
collectImportedFiles,
|
|
256
|
+
createSymbolCache,
|
|
257
|
+
createTsProgram,
|
|
258
|
+
getRelatedCnsts,
|
|
259
|
+
parseTsConfig
|
|
260
|
+
});
|