@sjcrh/proteinpaint-rust 2.58.0 → 2.59.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.
@@ -0,0 +1,119 @@
1
+ const https = require('https')
2
+ const fs = require('fs')
3
+ const os = require('os')
4
+ const path = require('path')
5
+ const { exec } = require('child_process')
6
+ const tar = require('tar')
7
+
8
+ // Read package.json to get version and pp_release_tag
9
+ const packageJson = require(path.join(__dirname, 'package.json'))
10
+ const { version, pp_release_tag } = packageJson
11
+
12
+ const targetDirectory = './target/release'
13
+
14
+ function downloadBinary(url, outputPath) {
15
+ const file = fs.createWriteStream(outputPath)
16
+ https
17
+ .get(url, function (response) {
18
+ if (response.statusCode >= 200 && response.statusCode <= 299) {
19
+ response.pipe(file)
20
+ file.on('finish', function () {
21
+ file.close()
22
+ console.log('Pre-compiled binaries download completed.')
23
+ extractAndClean(outputPath)
24
+ })
25
+ } else if (response.statusCode >= 300 && response.statusCode <= 399) {
26
+ if (response.headers.location) {
27
+ downloadBinary(response.headers.location, outputPath)
28
+ } else {
29
+ console.error('Redirection without location header encountered.')
30
+ compileFromSource()
31
+ }
32
+ } else {
33
+ console.error('Failed to download the binary. Compiling from source...')
34
+ compileFromSource()
35
+ }
36
+ })
37
+ .on('error', function (err) {
38
+ console.error('Error downloading the file:', err.message)
39
+ compileFromSource()
40
+ })
41
+ }
42
+
43
+ function compileFromSource() {
44
+ console.log('Starting compilation from source...')
45
+ const compileProcess = exec('cargo build --release', { cwd: path.join(__dirname) })
46
+
47
+ compileProcess.stdout.on('data', data => {
48
+ console.log(data.toString()) // Print standard output from cargo to console
49
+ })
50
+
51
+ compileProcess.stderr.on('data', data => {
52
+ console.error(data.toString()) // Print standard error from cargo to console as error
53
+ })
54
+
55
+ compileProcess.on('exit', code => {
56
+ if (code === 0) {
57
+ console.log('Compilation successful.')
58
+ } else {
59
+ console.error(`Compilation failed with exit code ${code}`)
60
+ }
61
+ })
62
+ }
63
+
64
+ function extractAndClean(tarPath) {
65
+ // Ensure target directory exists
66
+ fs.mkdirSync(targetDirectory, { recursive: true })
67
+
68
+ // Extract tar.gz file to target/release directory
69
+ tar
70
+ .x({
71
+ file: tarPath,
72
+ cwd: targetDirectory // Change directory to target/release
73
+ })
74
+ .then(() => {
75
+ console.log('Extraction complete.')
76
+ makeBinariesExecutable()
77
+ // Remove the tar file after successful extraction
78
+ fs.unlink(tarPath, err => {
79
+ if (err) {
80
+ console.error('Error removing the tar file:', err)
81
+ } else {
82
+ console.log('Tar file removed.')
83
+ }
84
+ })
85
+ })
86
+ .catch(err => {
87
+ console.error('Error during extraction:', err)
88
+ })
89
+ }
90
+
91
+ function makeBinariesExecutable() {
92
+ // Construct the full path to the directory
93
+ const fullPath = path.join(__dirname, targetDirectory)
94
+ const command = `chmod -R +x ${fullPath}`
95
+
96
+ exec(command, (error, stdout, stderr) => {
97
+ if (error) {
98
+ console.error(`Error setting executable permissions: ${error.message}`)
99
+ return
100
+ }
101
+ if (stderr) {
102
+ console.error(`Error output from chmod: ${stderr}`)
103
+ return
104
+ }
105
+ console.log(`Set executable permissions for all files in ${fullPath}`)
106
+ })
107
+ }
108
+
109
+ const architecture = os.arch()
110
+ let binaryUrl = ''
111
+
112
+ if (architecture === 'x64') {
113
+ binaryUrl = `https://github.com/stjude/proteinpaint/releases/download/${pp_release_tag}/rust-binaries-${version}-linux-x64.tar.gz`
114
+ const outputPath = path.join(__dirname, 'binaries.tar.gz')
115
+ downloadBinary(binaryUrl, outputPath)
116
+ } else {
117
+ console.log('Unsupported architecture, attempting to compile from source...')
118
+ compileFromSource()
119
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.58.0",
2
+ "version": "2.59.0",
3
3
  "name": "@sjcrh/proteinpaint-rust",
4
4
  "description": "Rust-based utilities for proteinpaint",
5
5
  "main": "index.js",
@@ -9,7 +9,7 @@
9
9
  "scripts": {
10
10
  "dev": "cargo build --release",
11
11
  "build": "cargo build --release",
12
- "postinstall": "if [ ! -d ./test ] & [ ! -d ./target/release ]; then cargo build --release; fi",
12
+ "postinstall": "if [ ! -d ./test ] & [ ! -d ./target/release ]; then node ./downloadBinariesOrCompileSource.js; fi",
13
13
  "test": "tape **/test/*.spec.js",
14
14
  "test:unit": "tape **/test/*.unit.spec.js",
15
15
  "test:integration": "echo 'TODO: rust integration tests'"
@@ -25,13 +25,18 @@
25
25
  "index.js",
26
26
  "Cargo.toml",
27
27
  "src",
28
+ "downloadBinariesOrCompileSource.js",
28
29
  "LICENSE/*"
29
30
  ],
30
31
  "bugs": {
31
32
  "url": "https://github.com/stjude/proteinpaint"
32
33
  },
33
34
  "homepage": "https://github.com/stjude/proteinpaint#readme",
35
+ "dependencies": {
36
+ "tar": "^7.1.0"
37
+ },
34
38
  "devDependencies": {
35
39
  "tape": "^5.2.2"
36
- }
40
+ },
41
+ "pp_release_tag": "v2.59.0"
37
42
  }