Skip to content

Commit

Permalink
chore: download task
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 8, 2017
1 parent dbdf7fb commit 438f7eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
14 changes: 4 additions & 10 deletions lib/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ const versionInfo = {
function buildModuleName(info) {
return info.binversion + '-' + info.abi + '-' + info.platform + '-' + info.arch;
}
const moduleName = buildModuleName(versionInfo);
const bindingRoot = path.dirname(__filename) + '/fcopy_binding';
const bindingPath = bindingRoot + '/' + moduleName + '.node';

function downloadIfNeeded(abi) {
const requestAbi = arguments.length === 0 ? versionInfo.abi : abi;
const fileName = buildModuleName(Object.assign({}, versionInfo, {
abi: requestAbi,
}));
function downloadIfNeeded(versionInfo) {
const fileName = buildModuleName(versionInfo);
console.log('downloading', fileName);
const target = bindingRoot + '/' + fileName + '.node';
const url = URL.replace('{0}', versionInfo.binversion).replace('{1}', fileName);
return createBindingDirectory()
Expand Down Expand Up @@ -76,10 +71,9 @@ function httpDownload(url, target) {
}

module.exports = {
bindingPath,
bindingPath: bindingRoot + '/' + buildModuleName(versionInfo) + '.node',
bindingRoot,
buildModuleName,
downloadIfNeeded,
moduleName,
versionInfo,
};
22 changes: 14 additions & 8 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ if (!fs.existsSync(binding.bindingRoot)) {

if (process.env.FCOPY_REBUILD) {
rebuildBinding();
} else if (process.argv.length === 3 && process.argv[2] === '--download') {
Promise.all(Object.keys(packageJson.binary.abis).map(v => {
return Promise.all(['win32', 'darwin', 'linux'].map(platform => downloadBinding(v, platform)));
}))
.catch(err => {
console.error(err);
process.exitCode = 1;
});
} else if (fs.existsSync(binding.bindingPath)) {
// do nothing if the required binding exists
} else {
downloadBinding(binding.versionInfo.abi).then(function download() {
downloadBinding(binding.versionInfo.abi, process.platform).then(function download() {
const otherAbis = Object.keys(packageJson.binary.abis).filter(function(abi) {
return abi !== binding.versionInfo.abi;
});
Expand All @@ -27,16 +35,14 @@ if (process.env.FCOPY_REBUILD) {

function downloadBindings(abis) {
return Promise.all(abis.map(function mapAbi(v) {
return downloadBinding(v);
return downloadBinding(v, process.platform);
}));
}

function downloadBinding(abi) {
const fileName = binding.buildModuleName(Object.assign({}, binding.versionInfo, {
abi,
function downloadBinding(abi, platform) {
return binding.downloadIfNeeded(Object.assign({}, binding.versionInfo, {
abi, platform,
}));
console.log('downloading', fileName);
return binding.downloadIfNeeded(abi);
}

function rebuildBinding() {
Expand All @@ -47,7 +53,7 @@ function rebuildBinding() {

const output = cp.spawnSync(nodegyp, [
'rebuild',
'--modname=' + binding.moduleName,
'--modname=' + binding.buildModuleName(binding.versionInfo),
], {
cwd: path.resolve(__dirname, '..'),
stdio: ['inherit', 'inherit', 'inherit'],
Expand Down

0 comments on commit 438f7eb

Please sign in to comment.