Skip to content

Commit

Permalink
preinstall.js
Browse files Browse the repository at this point in the history
+ rewrote the preinstall.py in js so the library can be installed without python requirement
+ integrate PR LedgerHQ#29
+ fixes installation of the library on windows. At least on Travis it was failing with python error (some SSL errors)
  • Loading branch information
gre committed Apr 23, 2019
1 parent 12b1276 commit 86582a6
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 45 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@ledgerhq/ledger-core",
"version": "2.3.0-beta.1",
"libcoreVersion": "2.7.0-rc-ad6ac9",
"description": "Ledger Core Library cross-platform C++ bindings for NodeJs",
"main": "js/index.js",
"repository": {
Expand All @@ -9,7 +10,7 @@
},
"gypfile": true,
"scripts": {
"preinstall": "python preinstall.py",
"preinstall": "node preinstall.js",
"gypinstall": "node-gyp rebuild",
"gypclean": "node-gyp clean",
"gypconfig": "node-gyp configure",
Expand Down Expand Up @@ -42,6 +43,7 @@
"eslint-config-prettier": "^2.9.0",
"node-gyp": "^3.6.2",
"prettier": "^1.12.1",
"request": "^2.88.0",
"rimraf": "^2.5.3"
}
}
75 changes: 75 additions & 0 deletions preinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const fs = require('fs')
const path = require('path')
var request = require('request')
const { libcoreVersion } = require('./package.json')

const perPlatform = {
linux: {
dir: 'linux',
files: ['libledger-core.so'],
chmod: 0o755,
},
darwin: {
dir: 'macos',
files: ['libledger-core.dylib'],
chmod: 0o755,
},
win32: {
dir: 'win/vs2015',
file: ['ledger-core.dll', 'ledger-core.lib', 'crypto.dll'],
},
}

const conf = perPlatform[process.platform]
if (!conf) {
console.error(`Platform ${process.platform} is not supported`)
process.exit(1)
}
const endpointURL = `https://s3-eu-west-1.amazonaws.com/ledger-lib-ledger-core/${libcoreVersion}/${
conf.dir
}`

if (!fs.existsSync('lib')) {
fs.mkdirSync('lib')
}

conf.files.reduce(
(p, file) =>
p.then(() =>
get(file).then(() => {
if (conf.chmod) {
fs.chmodSync(`lib/${file}`, conf.chmod)
}
}),
),
Promise.resolve(),
)

function get(file) {
return new Promise((resolve, reject) => {
const dest = `lib/${file}`
if (process.env.LEDGER_CORE_LOCAL_BUILD) {
const src = path.join(process.env.LEDGER_CORE_LOCAL_BUILD, file)
console.log(`Copy ${src} -> ${dest}`)
fs.copyFile(src, dest, err => {
if (err) reject(err)
else resolve()
})
} else {
const url = `${endpointURL}/${file}`
console.log(`Downloading ${url} ...`)
const f = fs.createWriteStream(dest)
f.on('finish', () => {
console.log(`${file} downloaded.`)
f.close(resolve)
})
request
.get(url)
.on('error', err => {
fs.unlink(dest)
reject(err)
})
.pipe(f)
}
})
}
43 changes: 0 additions & 43 deletions preinstall.py

This file was deleted.

Loading

0 comments on commit 86582a6

Please sign in to comment.