Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions downloadCurrentVersion.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"lint": "node ./node_modules/semistandard/bin/cmd.js",
"prepublish": "node downloadCurrentVersion.js && node verifyVersion.js",
"prepublish": "./solcjs-get && node verifyVersion.js",
"pretest": "npm run lint",
"test": "tape ./test/index.js",
"coverage": "node ./node_modules/nyc/bin/nyc.js --reporter=lcov --reporter=text-summary ./node_modules/tape/bin/tape ./test/index.js",
Expand Down
141 changes: 141 additions & 0 deletions solcjs-get
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env node

// This is used to download the correct binary version
// as part of the prepublish step.

var pkg = require('./package.json');
var fs = require('fs-extra');
var https = require('follow-redirects').https;
var MemoryStream = require('memorystream');
var path = require('path');
var yargs = require('yargs')

var localBinaryDir = 'bin';

yargs
.usage('Usage: solcjs-get [options] [version]')
.option('list', {
describe: 'List all the versions available for download.',
type: 'bool'
})
.option('all', {
describe: 'Download all the versions. Additionally, use --nightly to get the nightly builds.',
type: 'bool'
})
.option('nightly', {
describe: 'Combined with --all, it adds the nightly builds to the list.',
type: 'bool'
})
.option('releases', {
describe: 'Get all the release builds.',
type: 'bool'
})
.option('clean', {
describe: 'Delete all the compiler binaries from ./bin.',
type: 'bool'
})
.showHelpOnFail(false, 'Specify --help for available options.')
.help();

var argv = yargs.argv;
var requestedVersion = argv._[0];

function getVersionList (cb) {
console.log('Retrieving available version list...');

var mem = new MemoryStream(null, { readable: false });
https.get('https://solc-bin.ethereum.org/bin/list.json', function (response) {
if (response.statusCode !== 200) {
console.log('Error downloading file: ' + response.statusCode);
process.exit(1);
}
response.pipe(mem);
response.on('end', function () {
cb(mem.toString());
});
});
}

function downloadBinary (version, cb) {
console.log('Downloading version', version);
var targetPath = path.join(localBinaryDir, version);

https.get('https://solc-bin.ethereum.org/bin/' + version, function (response) {
if (response.statusCode !== 200) {
console.log('Error downloading file: ' + response.statusCode);
process.exit(1);
}

fs.ensureDirSync(localBinaryDir);

var file = fs.createWriteStream(targetPath);

response.pipe(file);
file.on('finish', function () {
file.close(function () {
console.log('Done.');
if (cb)
cb(targetPath);
});
});
});
}

if (argv.list) {
console.log('Getting the list of all versions ...');
getVersionList(function (list) {
list = JSON.parse(list).builds;
for (var i = list.length - 1; i >= 0; i--) {
console.log(list[i].version, list[i].path);
}
process.exit(0);
});
} else if (argv.clean) {
console.log('Removing all local compilers in ' + localBinaryDir + ' ...');
fs.remove(localBinaryDir, function (err) {
if (err)
return console.error(err);

console.log('Success! Cleaned ' + localBinaryDir);
process.exit(0);
});
} else if (argv.all) {
console.log('Getting all the versions ...');
getVersionList(function (list) {
list = JSON.parse(list).builds;
for (var i = list.length - 1; i >= 0; i--) {
var target = list[i].path;
if (target.indexOf('nightly') > 0 && !argv.nightly)
continue;

downloadBinary(target);
}
});
} else if (argv.releases) {
console.log('Getting all the releases ...');
getVersionList(function (list) {
list = JSON.parse(list).releases;
for (var key in list) {
downloadBinary(list[key]);
}
});
} else {
getVersionList(function (list) {
list = JSON.parse(list);

var wanted = null;
if (requestedVersion) {
console.log('Requested version: ' + requestedVersion);
wanted = requestedVersion;
} else {
console.log('Requested version: latest release');
wanted = list.releases[pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1]];
}

downloadBinary(wanted, function (file) {
if (!requestedVersion) {
fs.copy(file, 'soljson.js'); // for backward compatibility
}
});
});
}