-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkarpeslop-cli.js
More file actions
52 lines (42 loc) · 1.45 KB
/
karpeslop-cli.js
File metadata and controls
52 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
// This is an ES module wrapper for the KarpeSlop CLI tool
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Get the path to the TypeScript file and local tsx binary
const detectorPath = join(__dirname, 'ai-slop-detector.ts');
const tsxPath = join(__dirname, 'node_modules', '.bin', 'tsx');
const tsxPathWin = join(__dirname, 'node_modules', '.bin', 'tsx.cmd');
// Check if we're on Windows
const isWindows = process.platform === 'win32';
const tsxCommand = isWindows ? tsxPathWin : tsxPath;
// Get command line arguments, excluding the first two (node and script path)
const args = process.argv.slice(2);
// Run with local tsx
const child = spawn(
tsxCommand,
[detectorPath, ...args],
{ stdio: 'inherit', cwd: process.cwd() }
);
child.on('error', (err) => {
console.error('Failed to start karpeslop:', err.message);
// Fallback: try to run via node with tsx import
if (err.code === 'ENOENT') {
const nodeChild = spawn(
'node',
['--import', 'tsx', detectorPath, ...args],
{ stdio: 'inherit', cwd: process.cwd() }
);
nodeChild.on('error', (nodeErr) => {
console.error('Fallback execution also failed:', nodeErr.message);
process.exit(1);
});
} else {
process.exit(1);
}
});
child.on('exit', (code) => {
process.exit(code || 0);
});