@tanagram/cli 0.1.19 → 0.1.21

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/install.js +78 -26
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -6,9 +6,65 @@ const path = require('path');
6
6
  const os = require('os');
7
7
 
8
8
  const GO_VERSION = '1.21.0';
9
+ const GO_CACHE_DIR = path.join(os.homedir(), '.tanagram', `go-${GO_VERSION}`);
9
10
 
10
- // Build binary using go-bin
11
- async function buildWithGoBin() {
11
+ // Check if Go is already installed locally
12
+ function checkLocalGo() {
13
+ try {
14
+ const version = execSync('go version', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] });
15
+ console.log(`✓ Found local Go: ${version.trim()}`);
16
+ return 'go';
17
+ } catch (error) {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ // Check if go-bin was previously cached
23
+ function checkCachedGo() {
24
+ const cachedGoPath = path.join(GO_CACHE_DIR, 'bin', 'go');
25
+ if (fs.existsSync(cachedGoPath)) {
26
+ console.log(`✓ Using cached Go from ${GO_CACHE_DIR}`);
27
+ return cachedGoPath;
28
+ }
29
+ return null;
30
+ }
31
+
32
+ // Download and cache Go using go-bin
33
+ async function downloadGo() {
34
+ console.log('📦 Downloading Go compiler via npm...');
35
+
36
+ try {
37
+ // Load go-bin
38
+ let goBin;
39
+ try {
40
+ goBin = require('go-bin');
41
+ } catch (err) {
42
+ const parentPath = path.join(__dirname, '..', '..', 'go-bin');
43
+ goBin = require(parentPath);
44
+ }
45
+
46
+ // Create cache directory
47
+ const cacheParent = path.dirname(GO_CACHE_DIR);
48
+ if (!fs.existsSync(cacheParent)) {
49
+ fs.mkdirSync(cacheParent, { recursive: true });
50
+ }
51
+
52
+ // Download Go to cache
53
+ const goDir = await goBin({
54
+ version: GO_VERSION,
55
+ dir: cacheParent,
56
+ includeTag: true
57
+ });
58
+
59
+ console.log(`✓ Go cached at ${goDir}`);
60
+ return path.join(goDir, 'bin', 'go');
61
+ } catch (error) {
62
+ throw new Error(`Failed to download Go: ${error.message}`);
63
+ }
64
+ }
65
+
66
+ // Build the binary
67
+ function buildBinary(goCommand) {
12
68
  const platform = os.platform();
13
69
  const arch = os.arch();
14
70
  const goos = platform === 'win32' ? 'windows' : platform;
@@ -21,26 +77,16 @@ async function buildWithGoBin() {
21
77
  fs.mkdirSync(binDir, { recursive: true });
22
78
  }
23
79
 
24
- console.log('📦 Installing Go compiler via npm...');
80
+ console.log('🔧 Building Tanagram CLI...');
25
81
 
26
82
  try {
27
- // Install Go using go-bin (resolve from parent node_modules)
28
- const goBinPath = path.join(__dirname, '..', 'go-bin');
29
- const goBin = require(goBinPath);
30
- const goDir = await goBin({ version: GO_VERSION, dir: __dirname });
31
- const goPath = path.join(goDir, 'bin', 'go');
32
-
33
- console.log('🔧 Building Tanagram CLI...');
34
-
35
- // Build the binary using the downloaded Go
36
- execSync(`"${goPath}" build -o "${binaryPath}" .`, {
83
+ execSync(`"${goCommand}" build -o "${binaryPath}" .`, {
37
84
  cwd: __dirname,
38
85
  stdio: 'inherit',
39
86
  env: {
40
87
  ...process.env,
41
88
  GOOS: goos,
42
- GOARCH: goarch,
43
- GOROOT: goDir
89
+ GOARCH: goarch
44
90
  }
45
91
  });
46
92
 
@@ -48,29 +94,35 @@ async function buildWithGoBin() {
48
94
  fs.chmodSync(binaryPath, '755');
49
95
  }
50
96
 
51
- // Clean up Go installation
52
- console.log('🧹 Cleaning up...');
53
- fs.rmSync(goDir, { recursive: true, force: true });
54
-
55
97
  console.log('✓ Tanagram CLI installed successfully');
56
98
  return true;
57
99
  } catch (error) {
58
- console.error('Failed to build with go-bin:', error.message);
59
- return false;
100
+ throw new Error(`Build failed: ${error.message}`);
60
101
  }
61
102
  }
62
103
 
63
104
  // Main installation flow
64
105
  (async () => {
65
106
  try {
66
- const built = await buildWithGoBin();
67
- if (!built) {
68
- console.error('\n❌ Installation failed');
69
- process.exit(1);
107
+ // 1. Check if Go is already installed locally
108
+ let goCommand = checkLocalGo();
109
+
110
+ // 2. If not, check if we have a cached go-bin download
111
+ if (!goCommand) {
112
+ goCommand = checkCachedGo();
70
113
  }
114
+
115
+ // 3. If still no Go, download via go-bin and cache it
116
+ if (!goCommand) {
117
+ goCommand = await downloadGo();
118
+ }
119
+
120
+ // 4. Build the binary
121
+ buildBinary(goCommand);
122
+
71
123
  process.exit(0);
72
124
  } catch (error) {
73
- console.error('Installation error:', error.message);
125
+ console.error('\n❌ Installation failed:', error.message);
74
126
  process.exit(1);
75
127
  }
76
128
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanagram/cli",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Tanagram - Catch sloppy code before it ships",
5
5
  "main": "index.js",
6
6
  "bin": {