diff --git a/chains.json b/chains.json deleted file mode 100644 index 0967ef424..000000000 --- a/chains.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/lib/core/config.js b/lib/core/config.js index 4bb29c1e3..f89bf8b17 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -112,7 +112,7 @@ Config.prototype.loadBlockchainConfigFile = function() { Config.prototype.loadContractsConfigFile = function() { var defaultVersions = { - "web3.js": "1.0.0-beta", + "web3": "1.0.0-beta", "solc": "0.4.17" }; var versions = utils.recursiveMerge(defaultVersions, this.embarkConfig.versions || {}); diff --git a/lib/versions/library_manager.js b/lib/versions/library_manager.js index 3589a8378..05bf2879a 100644 --- a/lib/versions/library_manager.js +++ b/lib/versions/library_manager.js @@ -21,7 +21,7 @@ class LibraryManager { this.versions = {}; let solcVersionInConfig = this.contractsConfig.versions.solc; - let web3VersionInConfig = this.contractsConfig.versions["web3.js"]; + let web3VersionInConfig = this.contractsConfig.versions["web3"]; let ipfsApiVersion = this.storageConfig.versions["ipfs-api"]; this.versions['solc'] = solcVersionInConfig; @@ -64,10 +64,7 @@ class LibraryManager { listenToCommandsToGetLibrary() { let npm = new Npm({logger: this.embark.logger}); this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => { - npm.getPackageVersion(libName, version, false, false, cb); - }); - this.embark.events.setCommandHandler('version:getPackageContent', (libName, version, cb) => { - npm.getPackageVersion(libName, version, false, true, cb); + npm.getPackageVersion(libName, version, cb); }); } diff --git a/lib/versions/npm.js b/lib/versions/npm.js index 44b9844f7..a6d50246b 100644 --- a/lib/versions/npm.js +++ b/lib/versions/npm.js @@ -1,113 +1,26 @@ -// here be dragons -// TODO: this is horrible and needs to be refactored ASAP -let utils = require('../utils/utils.js'); let fs = require('../core/fs.js'); +let PluginManager = require('live-plugin-manager').PluginManager; + class Npm { constructor(options) { this.logger = options.logger; } - downloadFromGit(registryJSON, packageName, version, returnContent, callback) { - let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git",""); - let gitHead = registryJSON.gitHead; - - if (!gitHead) { - this.logger.error("Could not download " + packageName + " " + version); - return callback("error"); - } - - let fileLocation = "https://raw.githubusercontent.com/" + repoName + "/" + gitHead + "/dist/web3.min.js"; - - let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; - if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) { - if (returnContent) { - let distFile = packageDirectory + packageName + ".js"; - callback(null, fs.readFileSync(distFile).toString()); - } else { - callback(null, packageDirectory); - } - } else { - fs.mkdirpSync(packageDirectory); - this.logger.info("downloading " + packageName + " " + version + "...."); - - utils.downloadFile(fileLocation, packageDirectory + "/" + packageName + ".js", function() { - utils.extractTar(packageDirectory + "/" + packageName + ".js", packageDirectory, function() { - if (returnContent) { - let distFile = packageDirectory + packageName + ".js"; - callback(null, fs.readFileSync(distFile).toString()); - } else { - callback(null, packageDirectory); - } - }); - }); - } - } - - downloadFromNpm(registryJSON, packageName, version, returnContent, callback) { - let tarball = registryJSON.dist.tarball; - - let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; - if (fs.existsSync(packageDirectory + "/downloaded_package.tgz") && fs.existsSync(packageDirectory + "package.json")) { - if (returnContent) { - let distFile = packageDirectory + returnContent; - callback(null, fs.readFileSync(distFile).toString()); - } else { - callback(null, packageDirectory); - } - } else { - fs.mkdirpSync(packageDirectory); - this.logger.info("downloading " + packageName + " " + version + "...."); - - utils.downloadFile(tarball, packageDirectory + "/downloaded_package.tgz", function() { - utils.extractTar(packageDirectory + "/downloaded_package.tgz", packageDirectory, function() { - if (returnContent) { - let distFile = packageDirectory + returnContent; - callback(null, fs.readFileSync(distFile).toString()); - } else { - callback(null, packageDirectory); - } - }); - }); - } - } - - // TODO: callback should accept an error - getPackageVersion(packageName, version, returnContent, getFromGit, callback) { - let self = this; - let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version; + getPackageVersion(packageName, version, callback) { let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; - if (fs.existsSync(packageDirectory) && fs.existsSync(packageDirectory + "package.json")) { - let content; - if (getFromGit && returnContent) { - let distFile = packageDirectory + packageName + ".js"; - content = fs.readFileSync(distFile).toString(); - } else if (returnContent) { - let distFile = packageDirectory + returnContent; - content = fs.readFileSync(distFile).toString(); - } else { - content = packageDirectory; - } - return callback(null, content); + let manager = new PluginManager({pluginsPath: packageDirectory}); + + if (fs.existsSync(packageDirectory + packageName)) { + return callback(null, packageDirectory + packageName); } - utils.httpsGet(npmRegistry, function (err, body) { - if (err) { - if (err.code === 'ENOTFOUND') { - return callback("can't reach " + err.hostname + " to download " + packageName + " " + version + " - are you connected to the internet?"); - } - return callback(err); - } - let registryJSON = JSON.parse(body); - - if (getFromGit) { - self.downloadFromGit(registryJSON, packageName, version, returnContent, callback); - } else { - self.downloadFromNpm(registryJSON, packageName, version, returnContent, callback); - } - }); + this.logger.info("downloading " + packageName + " " + version + "...."); + manager.install(packageName, version).then((result) => { + callback(null , result.location); + }).catch(callback); } } diff --git a/package.json b/package.json index e34b98e4a..28aa1df62 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "globule": "^1.1.0", "http-shutdown": "^1.2.0", "ipfs-api": "17.2.4", + "live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git", "merge": "^1.2.0", "mocha": "^2.2.5", "orbit-db": "^0.17.3", diff --git a/templates/boilerplate/embark.json b/templates/boilerplate/embark.json index 37d16797b..0a5bfef57 100644 --- a/templates/boilerplate/embark.json +++ b/templates/boilerplate/embark.json @@ -9,7 +9,7 @@ "buildDir": "dist/", "config": "config/", "versions": { - "web3.js": "1.0.0-beta", + "web3": "1.0.0-beta", "solc": "0.4.17", "ipfs-api": "17.2.4" }, diff --git a/templates/demo/embark.json b/templates/demo/embark.json index 9ad970177..909673725 100644 --- a/templates/demo/embark.json +++ b/templates/demo/embark.json @@ -8,7 +8,7 @@ "buildDir": "dist/", "config": "config/", "versions": { - "web3.js": "1.0.0-beta", + "web3": "1.0.0-beta", "solc": "0.4.17", "ipfs-api": "17.2.4" }, diff --git a/test/config.js b/test/config.js index ebc2b594d..75aa79577 100644 --- a/test/config.js +++ b/test/config.js @@ -38,7 +38,7 @@ describe('embark.Config', function () { it('should load contract config correctly', function () { config.loadContractsConfigFile(); let expectedConfig = { - versions: {'web3.js': '1.0.0-beta', solc: '0.4.17'}, + versions: {'web3': '1.0.0-beta', solc: '0.4.17'}, deployment: {host: 'localhost', port: 8545, type: 'rpc'}, dappConnection: ['$WEB3', 'localhost:8545'], "gas": "auto", diff --git a/test_apps/contracts_app/contracts.json b/test_apps/contracts_app/contracts.json index c15d84b00..d4112a285 100644 --- a/test_apps/contracts_app/contracts.json +++ b/test_apps/contracts_app/contracts.json @@ -1,7 +1,7 @@ { "default": { "versions": { - "web3.js": "1.0.0-beta.27", + "web3": "1.0.0-beta.27", "solc": "0.4.17" }, "deployment": { diff --git a/test_apps/contracts_app/embark.json b/test_apps/contracts_app/embark.json index 0eefbfab2..4f2b9380f 100644 --- a/test_apps/contracts_app/embark.json +++ b/test_apps/contracts_app/embark.json @@ -9,7 +9,7 @@ "webserver": false }, "versions": { - "web3.js": "1.0.0-beta", + "web3": "1.0.0-beta", "solc": "0.4.17" } } diff --git a/test_apps/test_app/app/contracts/another_storage.sol b/test_apps/test_app/app/contracts/another_storage.sol index 92233769b..d8e0a1a81 100644 --- a/test_apps/test_app/app/contracts/another_storage.sol +++ b/test_apps/test_app/app/contracts/another_storage.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.17; +pragma solidity ^0.4.18; contract AnotherStorage { address public simpleStorageAddress; address simpleStorageAddress2; diff --git a/test_apps/test_app/embark.json b/test_apps/test_app/embark.json index 0d56876bb..66dfb0066 100644 --- a/test_apps/test_app/embark.json +++ b/test_apps/test_app/embark.json @@ -16,7 +16,8 @@ "config": "config/", "versions": { "solc": "0.4.18", - "ipfs-api": "17.2.6" + "web3": "1.0.0-beta.34", + "ipfs-api": "17.2.7" }, "plugins": { "embark-service": {}