|
1 | 1 | #!/usr/bin/env node |
2 | | -// This is an ES module wrapper for the KarpeSlop CLI tool |
| 2 | +// The published entry point. The prepare script (run by npm install, npm link and npm pack) compiles the TypeScript sources to dist/. |
| 3 | +import { main } from './dist/ai-slop-detector.js'; |
3 | 4 |
|
4 | | -import { spawn } from 'child_process'; |
5 | | -import { createRequire } from 'module'; |
6 | | -import { fileURLToPath } from 'url'; |
7 | | -import { dirname, join } from 'path'; |
8 | | - |
9 | | -const require = createRequire(import.meta.url); |
10 | | -const __filename = fileURLToPath(import.meta.url); |
11 | | -const __dirname = dirname(__filename); |
12 | | - |
13 | | -// Resolve the tsx loader from this package's dependencies so published |
14 | | -// installs do not depend on a specific node_modules/.bin layout. |
15 | | -const detectorPath = join(__dirname, 'ai-slop-detector.ts'); |
16 | | -const tsxLoaderPath = require.resolve('tsx'); |
17 | | - |
18 | | -function exitCodeForSignal(signal) { |
19 | | - const signalExitCodes = { |
20 | | - SIGINT: 130, |
21 | | - SIGTERM: 143, |
22 | | - SIGHUP: 129, |
23 | | - SIGQUIT: 131 |
24 | | - }; |
25 | | - |
26 | | - return signalExitCodes[signal] || 1; |
27 | | -} |
28 | | - |
29 | | -function handleChildExit(code, signal) { |
30 | | - if (signal) { |
31 | | - process.exit(exitCodeForSignal(signal)); |
32 | | - } |
33 | | - process.exit(code ?? 0); |
34 | | -} |
35 | | - |
36 | | -// Get command line arguments, excluding the first two (node and script path) |
37 | | -const args = process.argv.slice(2); |
38 | | - |
39 | | -// Run the detector through Node with the resolved tsx loader. |
40 | | -const child = spawn( |
41 | | - process.execPath, |
42 | | - ['--import', tsxLoaderPath, detectorPath, ...args], |
43 | | - { stdio: 'inherit', cwd: process.cwd() } |
44 | | -); |
45 | | - |
46 | | -child.on('error', (err) => { |
47 | | - console.error('Failed to start karpeslop:', err.message); |
| 5 | +main().catch(error => { |
| 6 | + console.error('KarpeSlop failed:', error); |
48 | 7 | process.exit(1); |
49 | 8 | }); |
50 | | - |
51 | | -child.on('exit', handleChildExit); |
0 commit comments