@tanagram/cli 0.1.14 โ†’ 0.1.16

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/README.md CHANGED
@@ -28,7 +28,7 @@ tanagram --help
28
28
  - Node.js >= 14.0.0
29
29
  - **Anthropic API Key** (required for LLM-based policy extraction)
30
30
 
31
- The CLI is written in Go but distributed via npm for easier installation and version management. Pre-built binaries are automatically downloaded during installation (no Go compiler needed!).
31
+ The CLI is written in Go but distributed via npm for easier installation and version management. During installation, npm automatically downloads the Go compiler and builds the binary for your platform (no manual setup needed!).
32
32
 
33
33
  ### API Key Setup
34
34
 
@@ -244,32 +244,17 @@ To publish a new version:
244
244
  # 1. Update version in package.json
245
245
  npm version patch # or minor, or major
246
246
 
247
- # 2. Commit the version bump
248
- git add package.json
247
+ # 2. Commit and tag
248
+ git add package.json package-lock.json
249
249
  git commit -m "Bump version to $(node -p "require('./package.json').version")"
250
-
251
- # 3. Build binaries for all platforms
252
- ./build-release.sh
253
-
254
- # 4. Create and push git tag
255
250
  git tag v$(node -p "require('./package.json').version")
256
251
  git push && git push origin --tags
257
252
 
258
- # 5. Upload binaries to GitHub release (choose one):
259
-
260
- # Option A: Using gh CLI (recommended)
261
- gh release create v$(node -p "require('./package.json').version") ./dist/* \
262
- --title "v$(node -p "require('./package.json').version")" \
263
- --generate-notes
264
-
265
- # Option B: Manually upload at
266
- # https://github.com/tanagram/cli/releases/new
267
-
268
- # 6. Publish to npm (binaries must be on GitHub first!)
253
+ # 3. Publish to npm
269
254
  npm publish
270
255
  ```
271
256
 
272
- **Important:** Upload binaries to GitHub releases BEFORE publishing to npm. The install script downloads pre-built binaries from GitHub releases.
257
+ **Note:** The Go compiler is automatically downloaded and used during `npm install` via the `go-bin` package, so no pre-built binaries needed!
273
258
 
274
259
  ## License
275
260
 
package/bin/tanagram CHANGED
Binary file
package/install.js CHANGED
@@ -1,121 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { execSync } = require('child_process');
4
- const https = require('https');
5
4
  const fs = require('fs');
6
5
  const path = require('path');
7
6
  const os = require('os');
8
7
 
9
- const GITHUB_REPO = 'tanagram/cli';
10
- const packageJson = require('./package.json');
11
- const VERSION = packageJson.version;
12
-
13
- // Get platform-specific binary info
14
- function getBinaryInfo() {
15
- const platform = os.platform();
16
- const arch = os.arch();
17
-
18
- let binaryName = 'tanagram';
19
- let platformString = '';
20
-
21
- if (platform === 'darwin') {
22
- platformString = arch === 'arm64' ? 'darwin-arm64' : 'darwin-amd64';
23
- } else if (platform === 'linux') {
24
- platformString = arch === 'arm64' ? 'linux-arm64' : 'linux-amd64';
25
- } else if (platform === 'win32') {
26
- platformString = 'windows-amd64';
27
- binaryName = 'tanagram.exe';
28
- } else {
29
- return null;
30
- }
31
-
32
- return {
33
- binaryName,
34
- platformString,
35
- downloadUrl: `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/tanagram-${platformString}${platform === 'win32' ? '.exe' : ''}`
36
- };
37
- }
38
-
39
- // Download file from URL
40
- function downloadFile(url, destPath) {
41
- return new Promise((resolve, reject) => {
42
- https.get(url, {
43
- headers: { 'User-Agent': 'tanagram-installer' },
44
- followRedirect: true
45
- }, (response) => {
46
- if (response.statusCode === 301 || response.statusCode === 302) {
47
- return downloadFile(response.headers.location, destPath)
48
- .then(resolve)
49
- .catch(reject);
50
- }
51
-
52
- if (response.statusCode !== 200) {
53
- reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
54
- return;
55
- }
56
-
57
- const file = fs.createWriteStream(destPath);
58
- response.pipe(file);
59
-
60
- file.on('finish', () => {
61
- file.close();
62
- resolve();
63
- });
64
-
65
- file.on('error', (err) => {
66
- fs.unlink(destPath, () => {});
67
- reject(err);
68
- });
69
- }).on('error', reject);
70
- });
71
- }
72
-
73
- // Try to download pre-built binary
74
- async function downloadBinary() {
75
- const binaryInfo = getBinaryInfo();
76
-
77
- if (!binaryInfo) {
78
- throw new Error(`Unsupported platform: ${os.platform()}-${os.arch()}`);
79
- }
80
-
81
- const binDir = path.join(__dirname, 'bin');
82
- if (!fs.existsSync(binDir)) {
83
- fs.mkdirSync(binDir, { recursive: true });
84
- }
85
-
86
- const binaryPath = path.join(binDir, binaryInfo.binaryName);
87
-
88
- console.log(`๐Ÿ“ฆ Downloading Tanagram CLI v${VERSION} for ${binaryInfo.platformString}...`);
89
-
90
- try {
91
- await downloadFile(binaryInfo.downloadUrl, binaryPath);
92
-
93
- if (os.platform() !== 'win32') {
94
- fs.chmodSync(binaryPath, '755');
95
- }
96
-
97
- console.log(`โœ“ Tanagram CLI installed successfully`);
98
- return true;
99
- } catch (error) {
100
- console.log(`โš  Could not download pre-built binary: ${error.message}`);
101
- return false;
102
- }
103
- }
104
-
105
- // Check if Go is installed
106
- function checkGo() {
107
- try {
108
- execSync('go version', { stdio: 'ignore' });
109
- return true;
110
- } catch (error) {
111
- return false;
112
- }
113
- }
114
-
115
- // Build from source as fallback
116
- function buildFromSource() {
117
- console.log('๐Ÿ”ง Building from source...');
8
+ const GO_VERSION = '1.21.0';
118
9
 
10
+ // Build binary using go-bin
11
+ async function buildWithGoBin() {
119
12
  const platform = os.platform();
120
13
  const arch = os.arch();
121
14
  const goos = platform === 'win32' ? 'windows' : platform;
@@ -128,21 +21,40 @@ function buildFromSource() {
128
21
  fs.mkdirSync(binDir, { recursive: true });
129
22
  }
130
23
 
24
+ console.log('๐Ÿ“ฆ Installing Go compiler via npm...');
25
+
131
26
  try {
132
- execSync(`go build -o "${binaryPath}" .`, {
27
+ // Install Go using go-bin
28
+ const goBin = require('go-bin');
29
+ const goDir = await goBin({ version: GO_VERSION, dir: __dirname });
30
+ const goPath = path.join(goDir, 'bin', 'go');
31
+
32
+ console.log('๐Ÿ”ง Building Tanagram CLI...');
33
+
34
+ // Build the binary using the downloaded Go
35
+ execSync(`"${goPath}" build -o "${binaryPath}" .`, {
133
36
  cwd: __dirname,
134
37
  stdio: 'inherit',
135
- env: { ...process.env, GOOS: goos, GOARCH: goarch }
38
+ env: {
39
+ ...process.env,
40
+ GOOS: goos,
41
+ GOARCH: goarch,
42
+ GOROOT: goDir
43
+ }
136
44
  });
137
45
 
138
46
  if (platform !== 'win32') {
139
47
  fs.chmodSync(binaryPath, '755');
140
48
  }
141
49
 
142
- console.log(`โœ“ Tanagram CLI built successfully`);
50
+ // Clean up Go installation
51
+ console.log('๐Ÿงน Cleaning up...');
52
+ fs.rmSync(goDir, { recursive: true, force: true });
53
+
54
+ console.log('โœ“ Tanagram CLI installed successfully');
143
55
  return true;
144
56
  } catch (error) {
145
- console.error('Failed to build from source:', error.message);
57
+ console.error('Failed to build with go-bin:', error.message);
146
58
  return false;
147
59
  }
148
60
  }
@@ -150,29 +62,11 @@ function buildFromSource() {
150
62
  // Main installation flow
151
63
  (async () => {
152
64
  try {
153
- const downloaded = await downloadBinary();
154
- if (downloaded) {
155
- process.exit(0);
156
- }
157
-
158
- console.log('Attempting to build from source as fallback...');
159
-
160
- if (!checkGo()) {
161
- console.error('\nโŒ Installation failed:');
162
- console.error(' - Could not download pre-built binary');
163
- console.error(' - Go is not installed for building from source\n');
164
- console.error('Please either:');
165
- console.error(' 1. Try again later (binaries may not be published yet), or');
166
- console.error(' 2. Install Go from https://golang.org/dl/\n');
167
- process.exit(1);
168
- }
169
-
170
- const built = buildFromSource();
65
+ const built = await buildWithGoBin();
171
66
  if (!built) {
172
67
  console.error('\nโŒ Installation failed');
173
68
  process.exit(1);
174
69
  }
175
-
176
70
  process.exit(0);
177
71
  } catch (error) {
178
72
  console.error('Installation error:', error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanagram/cli",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Tanagram - Catch sloppy code before it ships",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -30,7 +30,6 @@
30
30
  "files": [
31
31
  "bin/",
32
32
  "checker/",
33
- "cli/",
34
33
  "commands/",
35
34
  "extractor/",
36
35
  "fixtures/",