@tgrv/cli 1.0.0
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/bin/tgrv.exe +0 -0
- package/index.js +51 -0
- package/package.json +13 -0
package/bin/tgrv.exe
ADDED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
|
|
14
|
+
const platform = os.platform();
|
|
15
|
+
const arch = os.arch();
|
|
16
|
+
const pkgName = `@tgrv/tgrv-${platform}-${arch}`;
|
|
17
|
+
const binName = platform === 'win32' ? 'tgrv.exe' : 'tgrv';
|
|
18
|
+
|
|
19
|
+
function resolveBinary() {
|
|
20
|
+
// 1. Resolve via optionalDependencies
|
|
21
|
+
try {
|
|
22
|
+
const pkgPath = require.resolve(`${pkgName}/package.json`);
|
|
23
|
+
const binaryPath = path.join(path.dirname(pkgPath), 'bin', binName);
|
|
24
|
+
if (fs.existsSync(binaryPath)) return binaryPath;
|
|
25
|
+
} catch (e) {}
|
|
26
|
+
|
|
27
|
+
// 2. Monorepo fallback (local dev)
|
|
28
|
+
const monorepoPath = path.join(__dirname, '..', `tgrv-${platform}-${arch}`, 'bin', binName);
|
|
29
|
+
if (fs.existsSync(monorepoPath)) return monorepoPath;
|
|
30
|
+
|
|
31
|
+
// 3. Fallback to sibling bin
|
|
32
|
+
const siblingBin = path.join(__dirname, 'bin', binName);
|
|
33
|
+
if (fs.existsSync(siblingBin)) return siblingBin;
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const binaryPath = resolveBinary();
|
|
39
|
+
|
|
40
|
+
if (!binaryPath) {
|
|
41
|
+
console.error(`\n[TGRV FATAL] Binary not found for platform: ${platform}-${arch}`);
|
|
42
|
+
console.error(`Optional dependency '${pkgName}' might have failed to install.\n`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const args = process.argv.slice(2);
|
|
47
|
+
const tgrv = spawn(binaryPath, args, { stdio: 'inherit' });
|
|
48
|
+
|
|
49
|
+
tgrv.on('exit', (code) => {
|
|
50
|
+
process.exit(code || 0);
|
|
51
|
+
});
|
package/package.json
ADDED