@aiready/core 0.23.2 → 0.23.3
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/dist/__tests__/parser-factory.test.d.ts +1 -1
- package/dist/__tests__/parser-factory.test.js +62 -50
- package/dist/__tests__/python-parser.test.d.ts +1 -1
- package/dist/__tests__/python-parser.test.js +111 -109
- package/dist/__tests__/scoring.test.d.ts +1 -1
- package/dist/__tests__/scoring.test.js +193 -176
- package/dist/chunk-3YI4IS3D.mjs +191 -173
- package/dist/chunk-5HIXDC3X.mjs +273 -251
- package/dist/chunk-5V3L53AE.mjs +805 -0
- package/dist/chunk-CKVKHN3G.mjs +228 -211
- package/dist/chunk-COHIBX3Q.mjs +213 -195
- package/dist/chunk-CWRCDSKZ.mjs +91 -82
- package/dist/chunk-D3D3NCRR.mjs +147 -129
- package/dist/chunk-HCFYP7UD.mjs +805 -0
- package/dist/chunk-HFLFBA6F.mjs +79 -72
- package/dist/chunk-HKSARRCD.mjs +66 -58
- package/dist/chunk-JJ5JL5FX.mjs +91 -82
- package/dist/chunk-KDSTXVLQ.mjs +724 -0
- package/dist/chunk-KI7XORTN.mjs +91 -82
- package/dist/chunk-LTMHFNFK.mjs +690 -0
- package/dist/chunk-LTNXTXRI.mjs +228 -211
- package/dist/chunk-M22BXHBR.mjs +805 -0
- package/dist/chunk-MH3A3LX6.mjs +200 -182
- package/dist/chunk-NGHT7JOG.mjs +697 -0
- package/dist/chunk-OQ6IGDXG.mjs +147 -129
- package/dist/chunk-QAFB3HXQ.mjs +181 -165
- package/dist/chunk-QQBKXHLU.mjs +678 -0
- package/dist/chunk-RDHYGES7.mjs +678 -0
- package/dist/chunk-SWTDBVYJ.mjs +228 -213
- package/dist/chunk-UIWL5JQB.mjs +79 -72
- package/dist/chunk-UQGI67WR.mjs +79 -72
- package/dist/chunk-UTZOO4XO.mjs +147 -131
- package/dist/chunk-X4F46I5L.mjs +213 -195
- package/dist/chunk-XKK7YHPX.mjs +204 -186
- package/dist/chunk-YCA4FTEK.mjs +190 -172
- package/dist/chunk-ZSZRRTJM.mjs +719 -0
- package/dist/client-BgmiMoil.d.mts +1344 -0
- package/dist/client-BgmiMoil.d.ts +1344 -0
- package/dist/client-BxGrPuuN.d.mts +1191 -0
- package/dist/client-BxGrPuuN.d.ts +1191 -0
- package/dist/client-D-cn9ydj.d.mts +1136 -0
- package/dist/client-D-cn9ydj.d.ts +1136 -0
- package/dist/client-D9seCH4K.d.mts +1334 -0
- package/dist/client-D9seCH4K.d.ts +1334 -0
- package/dist/client-DIXIh7rw.d.mts +1193 -0
- package/dist/client-DIXIh7rw.d.ts +1193 -0
- package/dist/client-DVHXWOHw.d.mts +1245 -0
- package/dist/client-DVHXWOHw.d.ts +1245 -0
- package/dist/client.d.mts +2 -1098
- package/dist/client.d.ts +2 -1098
- package/dist/client.js +23 -43
- package/dist/client.mjs +3 -25
- package/dist/index.d.mts +325 -103
- package/dist/index.d.ts +325 -103
- package/dist/index.js +307 -324
- package/dist/index.mjs +283 -306
- package/dist/parsers/parser-factory.d.ts +45 -45
- package/dist/parsers/parser-factory.js +86 -84
- package/dist/parsers/python-parser.d.ts +33 -28
- package/dist/parsers/python-parser.js +224 -222
- package/dist/parsers/typescript-parser.d.ts +15 -10
- package/dist/parsers/typescript-parser.js +223 -197
- package/dist/scoring.d.ts +59 -49
- package/dist/scoring.js +129 -127
- package/dist/types/language.d.ts +104 -93
- package/dist/types/language.js +23 -23
- package/dist/types.d.ts +105 -87
- package/dist/types.js +1 -1
- package/dist/utils/ast-parser.d.ts +42 -33
- package/dist/utils/ast-parser.js +159 -162
- package/dist/utils/cli-helpers.d.ts +27 -10
- package/dist/utils/cli-helpers.js +45 -43
- package/dist/utils/config.d.ts +8 -3
- package/dist/utils/config.js +67 -69
- package/dist/utils/file-scanner.d.ts +1 -1
- package/dist/utils/file-scanner.js +80 -76
- package/dist/utils/metrics.d.ts +1 -1
- package/dist/utils/metrics.js +2 -2
- package/package.json +1 -1
package/dist/utils/ast-parser.js
CHANGED
|
@@ -3,214 +3,211 @@ import { parse } from '@typescript-eslint/typescript-estree';
|
|
|
3
3
|
* Parse TypeScript/JavaScript file and extract exports with their import dependencies
|
|
4
4
|
*/
|
|
5
5
|
export function parseFileExports(code, filePath) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
6
|
+
try {
|
|
7
|
+
const ast = parse(code, {
|
|
8
|
+
loc: true,
|
|
9
|
+
range: true,
|
|
10
|
+
jsx: filePath.endsWith('.tsx') || filePath.endsWith('.jsx'),
|
|
11
|
+
filePath,
|
|
12
|
+
});
|
|
13
|
+
const imports = extractFileImports(ast);
|
|
14
|
+
const exports = extractExportsWithDependencies(ast, imports);
|
|
15
|
+
return { exports, imports };
|
|
16
|
+
} catch (error) {
|
|
17
|
+
// Fallback to empty if parsing fails
|
|
18
|
+
return { exports: [], imports: [] };
|
|
19
|
+
}
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Extract all imports from the file
|
|
24
23
|
*/
|
|
25
24
|
function extractFileImports(ast) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
specifiers.push('*');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
imports.push({ source, specifiers, isTypeOnly });
|
|
25
|
+
const imports = [];
|
|
26
|
+
for (const node of ast.body) {
|
|
27
|
+
if (node.type === 'ImportDeclaration') {
|
|
28
|
+
const source = node.source.value;
|
|
29
|
+
const specifiers = [];
|
|
30
|
+
const isTypeOnly = node.importKind === 'type';
|
|
31
|
+
for (const spec of node.specifiers) {
|
|
32
|
+
if (spec.type === 'ImportSpecifier') {
|
|
33
|
+
const imported = spec.imported;
|
|
34
|
+
const importName =
|
|
35
|
+
imported.type === 'Identifier' ? imported.name : imported.value;
|
|
36
|
+
specifiers.push(importName);
|
|
37
|
+
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
38
|
+
specifiers.push('default');
|
|
39
|
+
} else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
40
|
+
specifiers.push('*');
|
|
46
41
|
}
|
|
42
|
+
}
|
|
43
|
+
imports.push({ source, specifiers, isTypeOnly });
|
|
47
44
|
}
|
|
48
|
-
|
|
45
|
+
}
|
|
46
|
+
return imports;
|
|
49
47
|
}
|
|
50
48
|
/**
|
|
51
49
|
* Extract exports and their import dependencies
|
|
52
50
|
*/
|
|
53
51
|
function extractExportsWithDependencies(ast, fileImports) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else if (node.type === 'ExportDefaultDeclaration') {
|
|
74
|
-
const usedImports = findUsedImports(node.declaration, importedNames);
|
|
75
|
-
const typeReferences = extractTypeReferences(node.declaration);
|
|
76
|
-
exports.push({
|
|
77
|
-
name: 'default',
|
|
78
|
-
type: 'default',
|
|
79
|
-
imports: usedImports,
|
|
80
|
-
dependencies: [],
|
|
81
|
-
typeReferences,
|
|
82
|
-
loc: node.loc,
|
|
83
|
-
});
|
|
52
|
+
const exports = [];
|
|
53
|
+
const importedNames = new Set(fileImports.flatMap((imp) => imp.specifiers));
|
|
54
|
+
for (const node of ast.body) {
|
|
55
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
56
|
+
if (node.declaration) {
|
|
57
|
+
const exportNodes = extractFromDeclaration(node.declaration);
|
|
58
|
+
for (const exp of exportNodes) {
|
|
59
|
+
const usedImports = findUsedImports(node.declaration, importedNames);
|
|
60
|
+
const typeReferences = extractTypeReferences(node.declaration);
|
|
61
|
+
exports.push({
|
|
62
|
+
...exp,
|
|
63
|
+
imports: usedImports,
|
|
64
|
+
dependencies: [],
|
|
65
|
+
typeReferences,
|
|
66
|
+
loc: node.loc,
|
|
67
|
+
});
|
|
84
68
|
}
|
|
69
|
+
}
|
|
70
|
+
} else if (node.type === 'ExportDefaultDeclaration') {
|
|
71
|
+
const usedImports = findUsedImports(node.declaration, importedNames);
|
|
72
|
+
const typeReferences = extractTypeReferences(node.declaration);
|
|
73
|
+
exports.push({
|
|
74
|
+
name: 'default',
|
|
75
|
+
type: 'default',
|
|
76
|
+
imports: usedImports,
|
|
77
|
+
dependencies: [],
|
|
78
|
+
typeReferences,
|
|
79
|
+
loc: node.loc,
|
|
80
|
+
});
|
|
85
81
|
}
|
|
86
|
-
|
|
82
|
+
}
|
|
83
|
+
return exports;
|
|
87
84
|
}
|
|
88
85
|
/**
|
|
89
86
|
* Extract export information from a declaration
|
|
90
87
|
*/
|
|
91
88
|
function extractFromDeclaration(declaration) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
results.push({ name: declaration.id.name, type: 'interface' });
|
|
89
|
+
const results = [];
|
|
90
|
+
if (
|
|
91
|
+
declaration.type === 'FunctionDeclaration' &&
|
|
92
|
+
'id' in declaration &&
|
|
93
|
+
declaration.id
|
|
94
|
+
) {
|
|
95
|
+
results.push({ name: declaration.id.name, type: 'function' });
|
|
96
|
+
} else if (
|
|
97
|
+
declaration.type === 'ClassDeclaration' &&
|
|
98
|
+
'id' in declaration &&
|
|
99
|
+
declaration.id
|
|
100
|
+
) {
|
|
101
|
+
results.push({ name: declaration.id.name, type: 'class' });
|
|
102
|
+
} else if (declaration.type === 'VariableDeclaration') {
|
|
103
|
+
for (const declarator of declaration.declarations) {
|
|
104
|
+
if (declarator.id.type === 'Identifier') {
|
|
105
|
+
results.push({ name: declarator.id.name, type: 'const' });
|
|
106
|
+
}
|
|
111
107
|
}
|
|
112
|
-
|
|
108
|
+
} else if (declaration.type === 'TSTypeAliasDeclaration') {
|
|
109
|
+
results.push({ name: declaration.id.name, type: 'type' });
|
|
110
|
+
} else if (declaration.type === 'TSInterfaceDeclaration') {
|
|
111
|
+
results.push({ name: declaration.id.name, type: 'interface' });
|
|
112
|
+
}
|
|
113
|
+
return results;
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Find which imports are used within a node
|
|
116
117
|
*/
|
|
117
118
|
function findUsedImports(node, importedNames) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
else if ('type' in value) {
|
|
135
|
-
visit(value);
|
|
136
|
-
}
|
|
119
|
+
const usedImports = new Set();
|
|
120
|
+
function visit(n) {
|
|
121
|
+
if (n.type === 'Identifier' && importedNames.has(n.name)) {
|
|
122
|
+
usedImports.add(n.name);
|
|
123
|
+
}
|
|
124
|
+
// Recursively visit child nodes
|
|
125
|
+
for (const key in n) {
|
|
126
|
+
const value = n[key];
|
|
127
|
+
if (value && typeof value === 'object') {
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
value.forEach((child) => {
|
|
130
|
+
if (child && typeof child === 'object' && 'type' in child) {
|
|
131
|
+
visit(child);
|
|
137
132
|
}
|
|
133
|
+
});
|
|
134
|
+
} else if ('type' in value) {
|
|
135
|
+
visit(value);
|
|
138
136
|
}
|
|
137
|
+
}
|
|
139
138
|
}
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
}
|
|
140
|
+
visit(node);
|
|
141
|
+
return Array.from(usedImports);
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Calculate import-based similarity between two exports (Jaccard index)
|
|
145
145
|
*/
|
|
146
146
|
export function calculateImportSimilarity(export1, export2) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
if (export1.imports.length === 0 && export2.imports.length === 0) {
|
|
148
|
+
return 1; // Both have no imports = perfectly similar
|
|
149
|
+
}
|
|
150
|
+
const set1 = new Set(export1.imports);
|
|
151
|
+
const set2 = new Set(export2.imports);
|
|
152
|
+
const intersection = new Set([...set1].filter((x) => set2.has(x)));
|
|
153
|
+
const union = new Set([...set1, ...set2]);
|
|
154
|
+
return intersection.size / union.size;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Extract TypeScript type references from a node
|
|
158
158
|
* Collects all type identifiers used in type annotations
|
|
159
159
|
*/
|
|
160
160
|
function extractTypeReferences(node) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
current = current.left;
|
|
178
|
-
}
|
|
179
|
-
if (current.type === 'Identifier') {
|
|
180
|
-
types.add(current.name);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
161
|
+
const types = new Set();
|
|
162
|
+
function visit(n) {
|
|
163
|
+
if (!n || typeof n !== 'object') return;
|
|
164
|
+
// Type references
|
|
165
|
+
if (n.type === 'TSTypeReference' && n.typeName) {
|
|
166
|
+
if (n.typeName.type === 'Identifier') {
|
|
167
|
+
types.add(n.typeName.name);
|
|
168
|
+
} else if (n.typeName.type === 'TSQualifiedName') {
|
|
169
|
+
// Handle qualified names like A.B.C
|
|
170
|
+
let current = n.typeName;
|
|
171
|
+
while (current.type === 'TSQualifiedName') {
|
|
172
|
+
if (current.right?.type === 'Identifier') {
|
|
173
|
+
types.add(current.right.name);
|
|
174
|
+
}
|
|
175
|
+
current = current.left;
|
|
183
176
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (n.expression.type === 'Identifier') {
|
|
187
|
-
types.add(n.expression.name);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// Recursively visit children
|
|
191
|
-
for (const key of Object.keys(n)) {
|
|
192
|
-
const value = n[key];
|
|
193
|
-
if (Array.isArray(value)) {
|
|
194
|
-
value.forEach(visit);
|
|
195
|
-
}
|
|
196
|
-
else if (value && typeof value === 'object') {
|
|
197
|
-
visit(value);
|
|
198
|
-
}
|
|
177
|
+
if (current.type === 'Identifier') {
|
|
178
|
+
types.add(current.name);
|
|
199
179
|
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Interface references
|
|
183
|
+
if (n.type === 'TSInterfaceHeritage' && n.expression) {
|
|
184
|
+
if (n.expression.type === 'Identifier') {
|
|
185
|
+
types.add(n.expression.name);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Recursively visit children
|
|
189
|
+
for (const key of Object.keys(n)) {
|
|
190
|
+
const value = n[key];
|
|
191
|
+
if (Array.isArray(value)) {
|
|
192
|
+
value.forEach(visit);
|
|
193
|
+
} else if (value && typeof value === 'object') {
|
|
194
|
+
visit(value);
|
|
195
|
+
}
|
|
200
196
|
}
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
}
|
|
198
|
+
visit(node);
|
|
199
|
+
return Array.from(types);
|
|
203
200
|
}
|
|
204
201
|
export function parseCode(code, language) {
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
// Deprecated: Use parseFileExports instead
|
|
203
|
+
return null;
|
|
207
204
|
}
|
|
208
205
|
export function extractFunctions(ast) {
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
// Deprecated
|
|
207
|
+
return [];
|
|
211
208
|
}
|
|
212
209
|
export function extractImports(ast) {
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
// Deprecated
|
|
211
|
+
return [];
|
|
215
212
|
}
|
|
216
|
-
//# sourceMappingURL=ast-parser.js.map
|
|
213
|
+
//# sourceMappingURL=ast-parser.js.map
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Common CLI configuration interface
|
|
3
3
|
*/
|
|
4
4
|
export interface CLIOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
rootDir: string;
|
|
6
|
+
include?: string[];
|
|
7
|
+
exclude?: string[];
|
|
8
|
+
[key: string]: any;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Resolve output file path, defaulting to .aiready directory
|
|
@@ -15,23 +15,40 @@ export interface CLIOptions {
|
|
|
15
15
|
* @param workingDir - Working directory (default: process.cwd())
|
|
16
16
|
* @returns Resolved absolute path
|
|
17
17
|
*/
|
|
18
|
-
export declare function resolveOutputPath(
|
|
18
|
+
export declare function resolveOutputPath(
|
|
19
|
+
userPath: string | undefined,
|
|
20
|
+
defaultFilename: string,
|
|
21
|
+
workingDir?: string
|
|
22
|
+
): string;
|
|
19
23
|
/**
|
|
20
24
|
* Load and merge configuration with CLI options
|
|
21
25
|
*/
|
|
22
|
-
export declare function loadMergedConfig<T extends Record<string, any>>(
|
|
26
|
+
export declare function loadMergedConfig<T extends Record<string, any>>(
|
|
27
|
+
directory: string,
|
|
28
|
+
defaults: T,
|
|
29
|
+
cliOptions: Partial<T>
|
|
30
|
+
): Promise<
|
|
31
|
+
T & {
|
|
23
32
|
rootDir: string;
|
|
24
|
-
}
|
|
33
|
+
}
|
|
34
|
+
>;
|
|
25
35
|
/**
|
|
26
36
|
* Handle JSON output for CLI commands
|
|
27
37
|
*/
|
|
28
|
-
export declare function handleJSONOutput(
|
|
38
|
+
export declare function handleJSONOutput(
|
|
39
|
+
data: any,
|
|
40
|
+
outputFile?: string,
|
|
41
|
+
successMessage?: string
|
|
42
|
+
): void;
|
|
29
43
|
/**
|
|
30
44
|
* Common error handler for CLI commands
|
|
31
45
|
*/
|
|
32
|
-
export declare function handleCLIError(
|
|
46
|
+
export declare function handleCLIError(
|
|
47
|
+
error: unknown,
|
|
48
|
+
commandName: string
|
|
49
|
+
): never;
|
|
33
50
|
/**
|
|
34
51
|
* Calculate elapsed time and format for display
|
|
35
52
|
*/
|
|
36
53
|
export declare function getElapsedTime(startTime: number): string;
|
|
37
|
-
//# sourceMappingURL=cli-helpers.d.ts.map
|
|
54
|
+
//# sourceMappingURL=cli-helpers.d.ts.map
|
|
@@ -9,68 +9,70 @@ import { loadConfig, mergeConfigWithDefaults } from '../index';
|
|
|
9
9
|
* @param workingDir - Working directory (default: process.cwd())
|
|
10
10
|
* @returns Resolved absolute path
|
|
11
11
|
*/
|
|
12
|
-
export function resolveOutputPath(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
export function resolveOutputPath(
|
|
13
|
+
userPath,
|
|
14
|
+
defaultFilename,
|
|
15
|
+
workingDir = process.cwd()
|
|
16
|
+
) {
|
|
17
|
+
let outputPath;
|
|
18
|
+
if (userPath) {
|
|
19
|
+
// User provided a path, use it as-is
|
|
20
|
+
outputPath = userPath;
|
|
21
|
+
} else {
|
|
22
|
+
// Default to .aiready directory
|
|
23
|
+
const aireadyDir = join(workingDir, '.aiready');
|
|
24
|
+
outputPath = join(aireadyDir, defaultFilename);
|
|
25
|
+
}
|
|
26
|
+
// Ensure parent directory exists (works for both default and custom paths)
|
|
27
|
+
const parentDir = dirname(outputPath);
|
|
28
|
+
if (!existsSync(parentDir)) {
|
|
29
|
+
mkdirSync(parentDir, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
return outputPath;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* Load and merge configuration with CLI options
|
|
32
35
|
*/
|
|
33
36
|
export async function loadMergedConfig(directory, defaults, cliOptions) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
// Load config file if it exists
|
|
38
|
+
const config = await loadConfig(directory);
|
|
39
|
+
// Merge config with defaults
|
|
40
|
+
const mergedConfig = mergeConfigWithDefaults(config, defaults);
|
|
41
|
+
// Override with CLI options (CLI takes precedence)
|
|
42
|
+
const result = {
|
|
43
|
+
...mergedConfig,
|
|
44
|
+
...cliOptions,
|
|
45
|
+
rootDir: directory,
|
|
46
|
+
};
|
|
47
|
+
return result;
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
50
|
* Handle JSON output for CLI commands
|
|
48
51
|
*/
|
|
49
52
|
export function handleJSONOutput(data, outputFile, successMessage) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
writeFileSync(outputFile, JSON.stringify(data, null, 2));
|
|
57
|
-
console.log(successMessage || `✅ Results saved to ${outputFile}`);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
console.log(JSON.stringify(data, null, 2));
|
|
53
|
+
if (outputFile) {
|
|
54
|
+
// Ensure directory exists
|
|
55
|
+
const dir = dirname(outputFile);
|
|
56
|
+
if (!existsSync(dir)) {
|
|
57
|
+
mkdirSync(dir, { recursive: true });
|
|
61
58
|
}
|
|
59
|
+
writeFileSync(outputFile, JSON.stringify(data, null, 2));
|
|
60
|
+
console.log(successMessage || `✅ Results saved to ${outputFile}`);
|
|
61
|
+
} else {
|
|
62
|
+
console.log(JSON.stringify(data, null, 2));
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
66
|
* Common error handler for CLI commands
|
|
65
67
|
*/
|
|
66
68
|
export function handleCLIError(error, commandName) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
console.error(`❌ ${commandName} failed:`, error);
|
|
70
|
+
process.exit(1);
|
|
69
71
|
}
|
|
70
72
|
/**
|
|
71
73
|
* Calculate elapsed time and format for display
|
|
72
74
|
*/
|
|
73
75
|
export function getElapsedTime(startTime) {
|
|
74
|
-
|
|
76
|
+
return ((Date.now() - startTime) / 1000).toFixed(2);
|
|
75
77
|
}
|
|
76
|
-
//# sourceMappingURL=cli-helpers.js.map
|
|
78
|
+
//# sourceMappingURL=cli-helpers.js.map
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { AIReadyConfig } from '../types';
|
|
2
|
-
export declare function loadConfig(
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare function loadConfig(
|
|
3
|
+
rootDir: string
|
|
4
|
+
): Promise<AIReadyConfig | null>;
|
|
5
|
+
export declare function mergeConfigWithDefaults(
|
|
6
|
+
userConfig: AIReadyConfig | null,
|
|
7
|
+
defaults: any
|
|
8
|
+
): any;
|
|
9
|
+
//# sourceMappingURL=config.d.ts.map
|