@raven.js/cli 1.0.0-alpha.15 → 1.0.0-alpha.17

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.
Files changed (2) hide show
  1. package/bin/raven +29 -46
  2. package/package.json +6 -6
package/bin/raven CHANGED
@@ -1,59 +1,42 @@
1
1
  #!/usr/bin/env node
2
2
  const { spawn } = require('child_process');
3
3
  const path = require('path');
4
- const fs = require('fs');
4
+ const os = require('os');
5
5
 
6
- const targets = [
7
- 'linux-x64',
8
- 'linux-arm64',
9
- 'darwin-x64',
10
- 'darwin-arm64',
11
- 'windows-x64'
12
- ];
6
+ const knownWindowsPackages = {
7
+ 'win32 x64': '@raven.js/cli-windows-x64'
8
+ };
13
9
 
14
- let binaryPath = null;
10
+ const knownUnixlikePackages = {
11
+ 'linux x64': '@raven.js/cli-linux-x64',
12
+ 'linux arm64': '@raven.js/cli-linux-arm64',
13
+ 'darwin x64': '@raven.js/cli-darwin-x64',
14
+ 'darwin arm64': '@raven.js/cli-darwin-arm64'
15
+ };
15
16
 
16
- // 方法 1: 使用 require.resolve
17
- for (const target of targets) {
18
- try {
19
- const pkgPath = require.resolve(`@raven.js/cli-${target}`);
20
- const pkgDir = path.dirname(pkgPath);
21
- const candidate = path.join(pkgDir, process.platform === 'win32' ? 'raven.exe' : 'raven');
22
- if (fs.existsSync(candidate)) {
23
- binaryPath = candidate;
24
- break;
25
- }
26
- } catch (e) {
27
- continue;
17
+ function pkgAndSubpathForCurrentPlatform() {
18
+ let pkg;
19
+ let subpath;
20
+ const platformKey = `${process.platform} ${os.arch()}`;
21
+
22
+ if (platformKey in knownWindowsPackages) {
23
+ pkg = knownWindowsPackages[platformKey];
24
+ subpath = 'bin/raven.exe';
25
+ } else if (platformKey in knownUnixlikePackages) {
26
+ pkg = knownUnixlikePackages[platformKey];
27
+ subpath = 'bin/raven';
28
+ } else {
29
+ throw new Error(`Unsupported platform: ${platformKey}`);
28
30
  }
31
+
32
+ return { pkg, subpath };
29
33
  }
30
34
 
31
- // 方法 2: 如果 require.resolve 失败,尝试手动在 node_modules 中查找
32
- if (!binaryPath) {
33
- let currentDir = __dirname;
34
- while (currentDir && currentDir !== path.dirname(currentDir)) {
35
- const nodeModulesDir = path.join(currentDir, 'node_modules');
36
- if (fs.existsSync(nodeModulesDir)) {
37
- for (const target of targets) {
38
- const pkgDir = path.join(nodeModulesDir, '@raven.js', `cli-${target}`);
39
- if (fs.existsSync(pkgDir)) {
40
- const candidate = path.join(pkgDir, process.platform === 'win32' ? 'raven.exe' : 'raven');
41
- if (fs.existsSync(candidate)) {
42
- binaryPath = candidate;
43
- break;
44
- }
45
- }
46
- }
47
- if (binaryPath) break;
48
- }
49
- currentDir = path.dirname(currentDir);
50
- }
51
- }
52
-
53
- if (!binaryPath) {
54
- console.error('No compatible binary found for your platform');
55
- process.exit(1);
35
+ function generateBinPath() {
36
+ const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
37
+ return require.resolve(`${pkg}/${subpath}`);
56
38
  }
57
39
 
40
+ const binaryPath = generateBinPath();
58
41
  const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
59
42
  child.on('exit', (code) => process.exit(code || 0));
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@raven.js/cli",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.17",
4
4
  "description": "CLI tool for RavenJS framework",
5
5
  "bin": {
6
6
  "raven": "./bin/raven"
7
7
  },
8
8
  "optionalDependencies": {
9
- "@raven.js/cli-linux-x64": "1.0.0-alpha.15",
10
- "@raven.js/cli-linux-arm64": "1.0.0-alpha.15",
11
- "@raven.js/cli-darwin-x64": "1.0.0-alpha.15",
12
- "@raven.js/cli-darwin-arm64": "1.0.0-alpha.15",
13
- "@raven.js/cli-windows-x64": "1.0.0-alpha.15"
9
+ "@raven.js/cli-linux-x64": "1.0.0-alpha.17",
10
+ "@raven.js/cli-linux-arm64": "1.0.0-alpha.17",
11
+ "@raven.js/cli-darwin-x64": "1.0.0-alpha.17",
12
+ "@raven.js/cli-darwin-arm64": "1.0.0-alpha.17",
13
+ "@raven.js/cli-windows-x64": "1.0.0-alpha.17"
14
14
  },
15
15
  "keywords": [
16
16
  "ravenjs",