@lakindu_perera/toren 1.0.7 → 1.0.9
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/CHANGELOG.md +26 -0
- package/README.md +120 -31
- package/dist/cli/toren.d.ts +24 -0
- package/dist/cli/toren.js +254 -0
- package/dist/cli/toren.js.map +1 -0
- package/dist/detectors/config-detector.d.ts +3 -0
- package/dist/detectors/config-detector.js +58 -0
- package/dist/detectors/config-detector.js.map +1 -0
- package/dist/detectors/health-detector.d.ts +12 -0
- package/dist/detectors/health-detector.js +53 -0
- package/dist/detectors/health-detector.js.map +1 -0
- package/dist/detectors/important-files-detector.d.ts +51 -0
- package/dist/detectors/important-files-detector.js +455 -0
- package/dist/detectors/important-files-detector.js.map +1 -0
- package/dist/detectors/package-manager-detector.d.ts +7 -0
- package/dist/detectors/package-manager-detector.js +35 -0
- package/dist/detectors/package-manager-detector.js.map +1 -0
- package/dist/detectors/project-info-detector.d.ts +13 -0
- package/dist/detectors/project-info-detector.js +97 -0
- package/dist/detectors/project-info-detector.js.map +1 -0
- package/dist/detectors/script-detector.d.ts +42 -0
- package/dist/detectors/script-detector.js +199 -0
- package/dist/detectors/script-detector.js.map +1 -0
- package/dist/focused-output.d.ts +27 -0
- package/dist/focused-output.js +201 -0
- package/dist/focused-output.js.map +1 -0
- package/dist/lifecycle.d.ts +2 -0
- package/dist/lifecycle.js +114 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/renderers/console-renderer.d.ts +19 -0
- package/dist/renderers/console-renderer.js +361 -0
- package/dist/renderers/console-renderer.js.map +1 -0
- package/dist/renderers/html-renderer.d.ts +14 -0
- package/{src → dist}/renderers/html-renderer.js +263 -201
- package/dist/renderers/html-renderer.js.map +1 -0
- package/dist/renderers/index.d.ts +6 -0
- package/dist/renderers/index.js +12 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/json-renderer.d.ts +10 -0
- package/dist/renderers/json-renderer.js +127 -0
- package/dist/renderers/json-renderer.js.map +1 -0
- package/dist/renderers/markdown-renderer.d.ts +13 -0
- package/dist/renderers/markdown-renderer.js +360 -0
- package/dist/renderers/markdown-renderer.js.map +1 -0
- package/dist/scanner/scan.d.ts +2 -0
- package/dist/scanner/scan.js +573 -0
- package/dist/scanner/scan.js.map +1 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +16 -7
- package/bin/toren.js +0 -308
- package/src/detectors/config-detector.js +0 -81
- package/src/detectors/script-detector.js +0 -32
- package/src/focused-output.js +0 -146
- package/src/lifecycle.js +0 -124
- package/src/renderers/console-renderer.js +0 -350
- package/src/renderers/index.js +0 -41
- package/src/renderers/json-renderer.js +0 -154
- package/src/renderers/markdown-renderer.js +0 -337
- package/src/scanner/scan.js +0 -532
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakindu_perera/toren",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A powerful codebase scanner CLI tool for project analysis, framework detection, and understanding repository structure instantly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"toren": "
|
|
7
|
+
"toren": "dist/cli/toren.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"
|
|
11
|
-
"src",
|
|
10
|
+
"dist",
|
|
12
11
|
"LICENSE",
|
|
13
|
-
"README.md"
|
|
12
|
+
"README.md",
|
|
13
|
+
"CHANGELOG.md"
|
|
14
14
|
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
15
18
|
"scripts": {
|
|
16
|
-
"start": "node
|
|
19
|
+
"start": "node dist/cli/toren.js",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"build": "tsc",
|
|
17
22
|
"test": "node --test",
|
|
18
|
-
"lint": "node --check
|
|
23
|
+
"lint": "node --check dist/cli/toren.js dist/scanner/scan.js dist/lifecycle.js dist/renderers/index.js dist/renderers/console-renderer.js dist/renderers/json-renderer.js dist/renderers/markdown-renderer.js dist/renderers/html-renderer.js dist/detectors/config-detector.js dist/detectors/script-detector.js dist/detectors/package-manager-detector.js"
|
|
19
24
|
},
|
|
20
25
|
"keywords": [
|
|
21
26
|
"cli tool",
|
|
@@ -40,5 +45,9 @@
|
|
|
40
45
|
"license": "MIT",
|
|
41
46
|
"engines": {
|
|
42
47
|
"node": ">=18.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^26.4.0",
|
|
51
|
+
"typescript": "^7.0.2"
|
|
43
52
|
}
|
|
44
53
|
}
|
package/bin/toren.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Toren CLI — Entry Point
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* toren [path] Scan <path> (defaults to current directory)
|
|
7
|
-
* toren --format <type> Select output format (default: console)
|
|
8
|
-
* toren --json Legacy alias for --format json
|
|
9
|
-
* toren --version Print version
|
|
10
|
-
* toren --help Print usage
|
|
11
|
-
* toren --doctor Check global installation health
|
|
12
|
-
* toren --uninstall Safely remove global installation
|
|
13
|
-
* toren --include-hidden Include hidden files (dot-files) in scan
|
|
14
|
-
* toren --max-files <N> Override the max file scan limit
|
|
15
|
-
*
|
|
16
|
-
* Adding a new output format
|
|
17
|
-
* ──────────────────────────
|
|
18
|
-
* 1. Create src/renderers/<format>-renderer.js
|
|
19
|
-
* and export: render(result, options?) => void
|
|
20
|
-
* 2. Register it in src/renderers/index.js
|
|
21
|
-
*
|
|
22
|
-
* No changes to this file are required.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { createRequire } from 'node:module';
|
|
26
|
-
import { scan } from '../src/scanner/scan.js';
|
|
27
|
-
import renderers from '../src/renderers/index.js';
|
|
28
|
-
import { getFocusedModeInfo, renderFocusedMode, FOCUSED_FLAGS } from '../src/focused-output.js';
|
|
29
|
-
import { runDoctor, runUninstall } from '../src/lifecycle.js';
|
|
30
|
-
|
|
31
|
-
const require = createRequire(import.meta.url);
|
|
32
|
-
const pkg = require('../package.json');
|
|
33
|
-
|
|
34
|
-
/** Format used when no --format flag is supplied. */
|
|
35
|
-
const DEFAULT_FORMAT = 'console';
|
|
36
|
-
|
|
37
|
-
/** Derived from the registry — always in sync with available renderers. */
|
|
38
|
-
const SUPPORTED_FORMATS = Object.keys(renderers);
|
|
39
|
-
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
// Helpers
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
function printError(title, message, detailLabel, detailValue) {
|
|
45
|
-
console.error(`\x1b[31m✖ ${title}\x1b[0m\n`);
|
|
46
|
-
console.error(`${message}\n`);
|
|
47
|
-
if (detailLabel && detailValue) {
|
|
48
|
-
console.error(`${detailLabel}:\n`);
|
|
49
|
-
console.error(`${detailValue}\n`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function printHelp() {
|
|
54
|
-
const formatList = SUPPORTED_FORMATS.map(f => {
|
|
55
|
-
const suffix = f === DEFAULT_FORMAT ? ' (default)' : '';
|
|
56
|
-
return ` --format ${f.padEnd(10)}${suffix}`;
|
|
57
|
-
}).join('\n');
|
|
58
|
-
|
|
59
|
-
console.log(`
|
|
60
|
-
\x1b[1mToren\x1b[0m v${pkg.version}
|
|
61
|
-
Fast Repository Discovery CLI
|
|
62
|
-
|
|
63
|
-
\x1b[1mUSAGE\x1b[0m
|
|
64
|
-
toren [path] [options]
|
|
65
|
-
|
|
66
|
-
\x1b[1mCOMMANDS\x1b[0m
|
|
67
|
-
--project-type Show detected project type only
|
|
68
|
-
--frameworks Show detected frameworks only
|
|
69
|
-
--entry-points Show detected entry points only
|
|
70
|
-
--structure Show repository structure only
|
|
71
|
-
--configs Show detected project configuration files
|
|
72
|
-
--scripts Show available package scripts only
|
|
73
|
-
--include-hidden Include hidden files and folders
|
|
74
|
-
--max-files <n> Set scan file limit
|
|
75
|
-
--doctor Run CLI diagnostics
|
|
76
|
-
--uninstall Remove Toren global installation
|
|
77
|
-
--help Show this help message
|
|
78
|
-
--version Show version number
|
|
79
|
-
|
|
80
|
-
\x1b[1mOUTPUT FORMATS\x1b[0m
|
|
81
|
-
${formatList}
|
|
82
|
-
|
|
83
|
-
\x1b[1mEXAMPLES\x1b[0m
|
|
84
|
-
toren . Scan the current directory
|
|
85
|
-
toren ./my-project Scan a specific project folder
|
|
86
|
-
toren --format json . Output results as JSON
|
|
87
|
-
toren --format markdown . > out.md Save a Markdown report to a file
|
|
88
|
-
toren --format html . > out.html Save an HTML report to a file
|
|
89
|
-
toren . --configs Show project configuration files
|
|
90
|
-
toren . --frameworks Show detected frameworks
|
|
91
|
-
`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ---------------------------------------------------------------------------
|
|
95
|
-
// Argument parsing
|
|
96
|
-
// ---------------------------------------------------------------------------
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @typedef {Object} ParsedArgs
|
|
100
|
-
* @property {'exit'|'wait'|'scan'} action
|
|
101
|
-
* @property {string} [target] - Resolved path to scan
|
|
102
|
-
* @property {string} [format] - Renderer format name
|
|
103
|
-
* @property {boolean} [includeHidden] - Whether to include hidden files
|
|
104
|
-
* @property {number} [maxFiles] - Max files to scan
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Parse process.argv into a structured options object.
|
|
109
|
-
*
|
|
110
|
-
* Returns { action: 'exit' } when the process should exit immediately.
|
|
111
|
-
* Returns { action: 'wait' } when an async interactive command is running.
|
|
112
|
-
* Returns { action: 'scan', target, format } for normal scan operations.
|
|
113
|
-
*
|
|
114
|
-
* @returns {ParsedArgs}
|
|
115
|
-
*/
|
|
116
|
-
function parseArgs() {
|
|
117
|
-
const args = process.argv.slice(2);
|
|
118
|
-
|
|
119
|
-
// ── Informational flags ─────────────────────────────────────────────────
|
|
120
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
121
|
-
printHelp();
|
|
122
|
-
return { action: 'exit', code: 0 };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (args.includes('--version') || args.includes('-V') || args.includes('-v')) {
|
|
126
|
-
console.log(`Toren ${pkg.version}`);
|
|
127
|
-
return { action: 'exit', code: 0 };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ── Lifecycle commands ──────────────────────────────────────────────────
|
|
131
|
-
if (args.includes('--doctor')) {
|
|
132
|
-
runDoctor(pkg.version);
|
|
133
|
-
return { action: 'exit', code: 0 };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (args.includes('--uninstall')) {
|
|
137
|
-
runUninstall();
|
|
138
|
-
return { action: 'wait' };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ── Output format ───────────────────────────────────────────────────────
|
|
142
|
-
// --json is a legacy alias for --format json, kept for backwards
|
|
143
|
-
// compatibility. It will be removed in a future major version.
|
|
144
|
-
let format = DEFAULT_FORMAT;
|
|
145
|
-
|
|
146
|
-
const formatIdx = args.indexOf('--format');
|
|
147
|
-
if (formatIdx !== -1) {
|
|
148
|
-
const nextToken = args[formatIdx + 1];
|
|
149
|
-
// If the next token is missing or starts with '-', the user omitted the value.
|
|
150
|
-
if (nextToken === undefined || nextToken.startsWith('-')) {
|
|
151
|
-
printError(
|
|
152
|
-
'Missing value',
|
|
153
|
-
'The --format flag requires a valid output format.',
|
|
154
|
-
'Supported formats',
|
|
155
|
-
SUPPORTED_FORMATS.join(', ')
|
|
156
|
-
);
|
|
157
|
-
return { action: 'exit', code: 1 };
|
|
158
|
-
}
|
|
159
|
-
format = nextToken;
|
|
160
|
-
} else if (args.includes('--json')) {
|
|
161
|
-
format = 'json';
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// ── Focused Output Flags ────────────────────────────────────────────────
|
|
165
|
-
const focusedInfo = getFocusedModeInfo(args);
|
|
166
|
-
|
|
167
|
-
if (focusedInfo.error) {
|
|
168
|
-
printError(focusedInfo.title, focusedInfo.message, focusedInfo.detailLabel, focusedInfo.detailValue);
|
|
169
|
-
return { action: 'exit', code: 1 };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const focusedMode = focusedInfo.mode;
|
|
173
|
-
|
|
174
|
-
// ── Hidden files ────────────────────────────────────────────────────────
|
|
175
|
-
const includeHidden = args.includes('--include-hidden');
|
|
176
|
-
|
|
177
|
-
// ── Target path ─────────────────────────────────────────────────────────
|
|
178
|
-
// Build the set of tokens that are consumed as values by named flags so
|
|
179
|
-
// we don't accidentally treat them as the positional path argument.
|
|
180
|
-
const consumedValues = new Set();
|
|
181
|
-
if (formatIdx !== -1 && args[formatIdx + 1] !== undefined && !args[formatIdx + 1].startsWith('-')) {
|
|
182
|
-
consumedValues.add(args[formatIdx + 1]);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// ── Max files ───────────────────────────────────────────────────────────
|
|
186
|
-
let maxFiles = undefined;
|
|
187
|
-
const maxFilesIdx = args.indexOf('--max-files');
|
|
188
|
-
if (maxFilesIdx !== -1) {
|
|
189
|
-
const rawVal = args[maxFilesIdx + 1];
|
|
190
|
-
if (rawVal === undefined || rawVal.startsWith('-')) {
|
|
191
|
-
printError(
|
|
192
|
-
'Missing value',
|
|
193
|
-
'The --max-files flag requires a numeric value.',
|
|
194
|
-
'Example',
|
|
195
|
-
'toren --max-files 100000'
|
|
196
|
-
);
|
|
197
|
-
return { action: 'exit', code: 1 };
|
|
198
|
-
}
|
|
199
|
-
maxFiles = parseInt(rawVal, 10);
|
|
200
|
-
if (isNaN(maxFiles) || maxFiles < 1) {
|
|
201
|
-
printError(
|
|
202
|
-
'Invalid value',
|
|
203
|
-
'The --max-files flag must be a positive integer.',
|
|
204
|
-
'Provided value',
|
|
205
|
-
rawVal
|
|
206
|
-
);
|
|
207
|
-
return { action: 'exit', code: 1 };
|
|
208
|
-
}
|
|
209
|
-
consumedValues.add(rawVal);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// First non-flag, non-consumed token is the target path; default to cwd.
|
|
213
|
-
const target = args.find(a => !a.startsWith('-') && !consumedValues.has(a)) ?? '.';
|
|
214
|
-
|
|
215
|
-
// ── Unknown flag check ──────────────────────────────────────────────────
|
|
216
|
-
const knownFlags = new Set([
|
|
217
|
-
'--help', '-h',
|
|
218
|
-
'--version', '-V', '-v',
|
|
219
|
-
'--doctor',
|
|
220
|
-
'--uninstall',
|
|
221
|
-
'--format',
|
|
222
|
-
'--json',
|
|
223
|
-
...FOCUSED_FLAGS,
|
|
224
|
-
'--include-hidden',
|
|
225
|
-
'--max-files',
|
|
226
|
-
]);
|
|
227
|
-
|
|
228
|
-
const unknownFlag = args.find(
|
|
229
|
-
a => a.startsWith('-') && !knownFlags.has(a) && !consumedValues.has(a),
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
if (unknownFlag) {
|
|
233
|
-
printError(
|
|
234
|
-
'Unknown option',
|
|
235
|
-
'An unrecognized flag was provided.',
|
|
236
|
-
'Flag',
|
|
237
|
-
unknownFlag
|
|
238
|
-
);
|
|
239
|
-
return { action: 'exit', code: 1 };
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return { action: 'scan', target, format, includeHidden, maxFiles, focusedMode };
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ---------------------------------------------------------------------------
|
|
246
|
-
// Format validation
|
|
247
|
-
// ---------------------------------------------------------------------------
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Assert that `format` has a registered renderer.
|
|
251
|
-
* Prints a descriptive error message and exits with code 1 if not found.
|
|
252
|
-
*
|
|
253
|
-
* @param {string} format
|
|
254
|
-
*/
|
|
255
|
-
function assertValidFormat(format) {
|
|
256
|
-
if (renderers[format]) return;
|
|
257
|
-
|
|
258
|
-
printError(
|
|
259
|
-
'Unsupported output format',
|
|
260
|
-
'The requested output format is not supported.',
|
|
261
|
-
'Format',
|
|
262
|
-
format
|
|
263
|
-
);
|
|
264
|
-
process.exit(1);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// ---------------------------------------------------------------------------
|
|
268
|
-
// Main
|
|
269
|
-
// ---------------------------------------------------------------------------
|
|
270
|
-
|
|
271
|
-
(function main() {
|
|
272
|
-
const parsed = parseArgs();
|
|
273
|
-
|
|
274
|
-
if (parsed.action === 'exit') {
|
|
275
|
-
process.exit(parsed.code ?? 0);
|
|
276
|
-
}
|
|
277
|
-
if (parsed.action === 'wait') return;
|
|
278
|
-
|
|
279
|
-
// Validate before scanning — fail fast on bad format names.
|
|
280
|
-
assertValidFormat(parsed.format);
|
|
281
|
-
|
|
282
|
-
const render = renderers[parsed.format];
|
|
283
|
-
|
|
284
|
-
try {
|
|
285
|
-
const result = scan(parsed.target, {
|
|
286
|
-
includeHidden: parsed.includeHidden,
|
|
287
|
-
maxFiles: parsed.maxFiles,
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
if (parsed.focusedMode) {
|
|
291
|
-
renderFocusedMode(parsed.focusedMode, result);
|
|
292
|
-
} else {
|
|
293
|
-
render(result, { cwd: process.cwd() });
|
|
294
|
-
}
|
|
295
|
-
} catch (err) {
|
|
296
|
-
// Render errors in the requested format where possible.
|
|
297
|
-
if (parsed.format === 'json') {
|
|
298
|
-
console.error(JSON.stringify({ error: err.message }, null, 2));
|
|
299
|
-
} else {
|
|
300
|
-
if (err.title) {
|
|
301
|
-
printError(err.title, err.message, err.detailLabel, err.detailValue);
|
|
302
|
-
} else {
|
|
303
|
-
printError('Scan failed', err.message);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
process.exit(1);
|
|
307
|
-
}
|
|
308
|
-
})();
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Configuration file detector
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Detects common configuration files in the root of the repository.
|
|
7
|
-
*
|
|
8
|
-
* @param {string[]} flatFiles - Array of relative file paths from the scanner
|
|
9
|
-
* @returns {{ configs: string[] }}
|
|
10
|
-
*/
|
|
11
|
-
export function detectConfigs(flatFiles) {
|
|
12
|
-
const configPatterns = [
|
|
13
|
-
// Package
|
|
14
|
-
/^package\.json$/,
|
|
15
|
-
/^package-lock\.json$/,
|
|
16
|
-
/^pnpm-lock\.yaml$/,
|
|
17
|
-
/^yarn\.lock$/,
|
|
18
|
-
/^bun\.lockb$/,
|
|
19
|
-
|
|
20
|
-
// TypeScript
|
|
21
|
-
/^tsconfig\.json$/,
|
|
22
|
-
/^jsconfig\.json$/,
|
|
23
|
-
|
|
24
|
-
// Frontend
|
|
25
|
-
/^vite\.config\.[a-zA-Z0-9]+$/,
|
|
26
|
-
/^next\.config\.[a-zA-Z0-9]+$/,
|
|
27
|
-
/^nuxt\.config\.[a-zA-Z0-9]+$/,
|
|
28
|
-
/^astro\.config\.[a-zA-Z0-9]+$/,
|
|
29
|
-
/^angular\.json$/,
|
|
30
|
-
|
|
31
|
-
// Build
|
|
32
|
-
/^webpack\.config\.[a-zA-Z0-9]+$/,
|
|
33
|
-
/^rollup\.config\.[a-zA-Z0-9]+$/,
|
|
34
|
-
/^turbo\.json$/,
|
|
35
|
-
/^nx\.json$/,
|
|
36
|
-
|
|
37
|
-
// Styling
|
|
38
|
-
/^tailwind\.config\.[a-zA-Z0-9]+$/,
|
|
39
|
-
/^postcss\.config\.[a-zA-Z0-9]+$/,
|
|
40
|
-
|
|
41
|
-
// Lint
|
|
42
|
-
/^eslint\.config\.[a-zA-Z0-9]+$/,
|
|
43
|
-
/^\.eslintrc.*$/,
|
|
44
|
-
/^prettier\.config\.[a-zA-Z0-9]+$/,
|
|
45
|
-
/^\.prettierrc.*$/,
|
|
46
|
-
|
|
47
|
-
// Backend
|
|
48
|
-
/^pom\.xml$/,
|
|
49
|
-
/^build\.gradle$/,
|
|
50
|
-
/^build\.gradle\.kts$/,
|
|
51
|
-
|
|
52
|
-
// Languages
|
|
53
|
-
/^requirements\.txt$/,
|
|
54
|
-
/^pyproject\.toml$/,
|
|
55
|
-
/^Cargo\.toml$/,
|
|
56
|
-
/^go\.mod$/,
|
|
57
|
-
|
|
58
|
-
// Deployment
|
|
59
|
-
/^Dockerfile$/,
|
|
60
|
-
/^docker-compose\.ya?ml$/
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
const matchedSet = new Set();
|
|
64
|
-
|
|
65
|
-
for (const file of flatFiles) {
|
|
66
|
-
// Ensure we only match files at the root of the repository
|
|
67
|
-
if (file.includes('/')) continue;
|
|
68
|
-
|
|
69
|
-
for (const pattern of configPatterns) {
|
|
70
|
-
if (pattern.test(file)) {
|
|
71
|
-
matchedSet.add(file);
|
|
72
|
-
break; // Stop checking patterns once a match is found
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Convert Set to Array and sort alphabetically
|
|
78
|
-
const configs = Array.from(matchedSet).sort();
|
|
79
|
-
|
|
80
|
-
return { configs };
|
|
81
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Detects npm/package scripts from package.json in the project root.
|
|
6
|
-
*
|
|
7
|
-
* @param {string} rootPath - The absolute path of the scanned root
|
|
8
|
-
* @returns {{ scripts: Array<{name: string, command: string}> }}
|
|
9
|
-
*/
|
|
10
|
-
export function detectScripts(rootPath) {
|
|
11
|
-
const scripts = [];
|
|
12
|
-
const pkgPath = path.join(rootPath, 'package.json');
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
if (fs.existsSync(pkgPath)) {
|
|
16
|
-
const content = fs.readFileSync(pkgPath, 'utf8');
|
|
17
|
-
const pkg = JSON.parse(content);
|
|
18
|
-
|
|
19
|
-
if (pkg.scripts && typeof pkg.scripts === 'object') {
|
|
20
|
-
for (const [name, command] of Object.entries(pkg.scripts)) {
|
|
21
|
-
if (typeof command === 'string') {
|
|
22
|
-
scripts.push({ name, command });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
// Return empty scripts on malformed or unreadable package.json
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return { scripts };
|
|
32
|
-
}
|
package/src/focused-output.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Toren — Focused Output Mode Handler
|
|
3
|
-
*
|
|
4
|
-
* Handles the six focused output flags:
|
|
5
|
-
* --project-type --frameworks --entry-points
|
|
6
|
-
* --structure --configs --scripts
|
|
7
|
-
*
|
|
8
|
-
* Design contract:
|
|
9
|
-
* - Each flag renders exactly one section to stdout using the console visual
|
|
10
|
-
* style (ANSI colours, section header + divider).
|
|
11
|
-
* - Empty-state messages are canonical strings declared in EMPTY below.
|
|
12
|
-
* They must end with a period and stay in sync with console-renderer.js.
|
|
13
|
-
* - No business logic. All data comes from the ScanResult passed in.
|
|
14
|
-
* - Stateless: renderFocusedMode() may be called multiple times safely.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { renderStructure } from './renderers/console-renderer.js';
|
|
18
|
-
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
// Canonical empty-state messages
|
|
21
|
-
// Keep these in sync with the equivalent strings in console-renderer.js.
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
const EMPTY = {
|
|
25
|
-
frameworks: 'No frameworks detected.',
|
|
26
|
-
entryPoints: 'No entry points detected.',
|
|
27
|
-
configs: 'No configuration files detected.',
|
|
28
|
-
scripts: 'No package scripts detected.',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const FOCUSED_FLAGS = [
|
|
32
|
-
'--project-type',
|
|
33
|
-
'--frameworks',
|
|
34
|
-
'--entry-points',
|
|
35
|
-
'--structure',
|
|
36
|
-
'--configs',
|
|
37
|
-
'--scripts'
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Validates focused flags in the provided arguments.
|
|
42
|
-
*
|
|
43
|
-
* @param {string[]} args Process arguments
|
|
44
|
-
* @returns {{ error: boolean, message?: string, mode?: string|null }}
|
|
45
|
-
*/
|
|
46
|
-
export function getFocusedModeInfo(args) {
|
|
47
|
-
const activeFlags = FOCUSED_FLAGS.filter(flag => args.includes(flag));
|
|
48
|
-
|
|
49
|
-
if (activeFlags.length > 1) {
|
|
50
|
-
return {
|
|
51
|
-
error: true,
|
|
52
|
-
title: 'Conflicting options',
|
|
53
|
-
message: 'Focused output flags are mutually exclusive.',
|
|
54
|
-
detailLabel: 'Provided flags',
|
|
55
|
-
detailValue: activeFlags.join(', ')
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
error: false,
|
|
61
|
-
mode: activeFlags[0] || null
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Print a bold-white section title followed by a dim matched-length divider
|
|
67
|
-
* and a blank line — same visual pattern as console-renderer.js's section().
|
|
68
|
-
*
|
|
69
|
-
* @param {string} title
|
|
70
|
-
*/
|
|
71
|
-
function printSectionHeader(title) {
|
|
72
|
-
console.log(`\x1b[1m\x1b[97m${title}\x1b[0m`);
|
|
73
|
-
console.log(`\x1b[2m${'─'.repeat(title.length)}\x1b[0m`);
|
|
74
|
-
console.log('');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Print a focused section: header, then items or an empty-state message.
|
|
79
|
-
*
|
|
80
|
-
* @param {string} title - Section heading
|
|
81
|
-
* @param {string[]} items - Pre-formatted lines to print
|
|
82
|
-
* @param {string} emptyMsg - Canonical empty-state message (ends with '.')
|
|
83
|
-
*/
|
|
84
|
-
function section(title, items, emptyMsg) {
|
|
85
|
-
printSectionHeader(title);
|
|
86
|
-
|
|
87
|
-
if (!items || items.length === 0) {
|
|
88
|
-
console.log(`\x1b[2m${emptyMsg}\x1b[0m`);
|
|
89
|
-
} else {
|
|
90
|
-
for (const item of items) {
|
|
91
|
-
console.log(item);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Renders the scan result based on the active focused mode.
|
|
98
|
-
*
|
|
99
|
-
* @param {string} mode Active focused mode flag
|
|
100
|
-
* @param {import('./scanner/scan.js').ScanResult} result
|
|
101
|
-
*/
|
|
102
|
-
export function renderFocusedMode(mode, result) {
|
|
103
|
-
switch (mode) {
|
|
104
|
-
case '--project-type': {
|
|
105
|
-
// projectType is always a string; 'Unknown' when undetected.
|
|
106
|
-
section('Project Type', [result.projectType], 'Unknown');
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
case '--frameworks': {
|
|
111
|
-
const frameworks = (!result.projectType || result.projectType === 'Unknown')
|
|
112
|
-
? []
|
|
113
|
-
: [result.projectType];
|
|
114
|
-
section('Frameworks', frameworks, EMPTY.frameworks);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
case '--entry-points': {
|
|
119
|
-
section('Entry Points', result.entryPoints || [], EMPTY.entryPoints);
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
case '--structure': {
|
|
124
|
-
renderStructure(result);
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
case '--configs': {
|
|
129
|
-
section('Configuration Files', result.configs || [], EMPTY.configs);
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
case '--scripts': {
|
|
134
|
-
const scriptsList = [];
|
|
135
|
-
if (result.scripts && result.scripts.length > 0) {
|
|
136
|
-
const maxNameLen = Math.max(...result.scripts.map(s => s.name.length));
|
|
137
|
-
for (const s of result.scripts) {
|
|
138
|
-
const paddedName = s.name.padEnd(maxNameLen, ' ');
|
|
139
|
-
scriptsList.push(`\x1b[97m${paddedName}\x1b[0m \x1b[2m${s.command}\x1b[0m`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
section('Package Scripts', scriptsList, EMPTY.scripts);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|