@treeship/cli-linux-x64 0.1.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/binary.js ADDED
@@ -0,0 +1,2 @@
1
+ const path = require('path');
2
+ module.exports = path.join(__dirname, 'bin', 'treeship');
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@treeship/cli-linux-x64",
3
+ "version": "0.1.0",
4
+ "description": "Treeship CLI binary for linux x64",
5
+ "os": ["linux"],
6
+ "cpu": ["x64"],
7
+ "license": "Apache-2.0",
8
+ "scripts": {
9
+ "postinstall": "node postinstall.js"
10
+ }
11
+ }
package/postinstall.js ADDED
@@ -0,0 +1,41 @@
1
+ const https = require('https');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const VERSION = require('./package.json').version;
6
+ const BINARY_NAME = 'treeship-linux-x86_64';
7
+ const URL = 'https://github.com/zerkerlabs/treeship/releases/download/v' + VERSION + '/' + BINARY_NAME;
8
+ const DEST = path.join(__dirname, 'bin', 'treeship');
9
+
10
+ if (fs.existsSync(DEST)) process.exit(0);
11
+
12
+ fs.mkdirSync(path.join(__dirname, 'bin'), { recursive: true });
13
+
14
+ console.log('treeship: downloading ' + BINARY_NAME + '...');
15
+
16
+ function download(url) {
17
+ https.get(url, (res) => {
18
+ if (res.statusCode === 302 || res.statusCode === 301) {
19
+ download(res.headers.location);
20
+ return;
21
+ }
22
+ if (res.statusCode !== 200) {
23
+ console.error('treeship: download failed (' + res.statusCode + ')');
24
+ console.error('Install manually: cargo install treeship-cli');
25
+ process.exit(0);
26
+ }
27
+ const file = fs.createWriteStream(DEST);
28
+ res.pipe(file);
29
+ file.on('finish', () => {
30
+ file.close();
31
+ fs.chmodSync(DEST, 0o755);
32
+ console.log('treeship: installed');
33
+ });
34
+ }).on('error', () => {
35
+ console.error('treeship: download failed');
36
+ console.error('Install manually: cargo install treeship-cli');
37
+ process.exit(0);
38
+ });
39
+ }
40
+
41
+ download(URL);