From cf02a106569f7dbd5dc1f06eec2fe98072b6f7de Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 20 Apr 2018 19:45:57 -0400 Subject: [PATCH] use web3 naming instead of web3.js; check if package already exists --- lib/contracts/code_generator.js | 2 + lib/core/config.js | 3 +- lib/versions/library_manager.js | 6 ++- lib/versions/npm.js | 56 +++++++++++++++++++------- package.json | 4 +- test_apps/contracts_app/contracts.json | 2 +- test_apps/contracts_app/embark.json | 2 +- test_apps/test_app/embark.json | 4 +- 8 files changed, 56 insertions(+), 23 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 3072cd81b..7e43697d1 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -279,10 +279,12 @@ class CodeGenerator { async.waterfall([ function getWeb3Location(next) { self.events.request("version:get:web3", function(web3Version) { + console.dir("event request for web3 " + web3Version); if (web3Version === "1.0.0-beta") { return next(null, fs.embarkPath("js/web3-1.0.min.js")); } else { self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) { + //self.events.request("version:getFileLocation", "web3", web3Version, function(err, location) { return next(null, fs.dappPath(location)); }); } diff --git a/lib/core/config.js b/lib/core/config.js index a77185d6b..913b36667 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -113,10 +113,11 @@ 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 || {}); + console.dir(versions); var configObject = { "default": { diff --git a/lib/versions/library_manager.js b/lib/versions/library_manager.js index 3589a8378..13ab87d65 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; @@ -63,10 +63,12 @@ class LibraryManager { listenToCommandsToGetLibrary() { let npm = new Npm({logger: this.embark.logger}); + // the installed package e.g solc 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) => { + // only the file e.g dist/web3.js + this.embark.events.setCommandHandler('version:getFileLocation', (libName, version, cb) => { npm.getPackageVersion(libName, version, false, true, cb); }); } diff --git a/lib/versions/npm.js b/lib/versions/npm.js index d06e584fb..e983b24b0 100644 --- a/lib/versions/npm.js +++ b/lib/versions/npm.js @@ -12,8 +12,18 @@ class Npm { } downloadFromGit(registryJSON, packageName, version, returnContent, callback) { + console.dir("==== downloadFromGit "); + console.dir(arguments); + + + + callback(null, ""); + } + + old_downloadFromGit(registryJSON, packageName, version, returnContent, callback) { let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git",""); let gitHead = registryJSON.gitHead; + console.dir(registryJSON); if (!gitHead) { this.logger.error("Could not download " + packageName + " " + version); @@ -21,8 +31,10 @@ class Npm { } let fileLocation = "https://raw.githubusercontent.com/" + repoName + "/" + gitHead + "/dist/web3.min.js"; + console.dir("fileLocation is " + fileLocation); let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + console.dir("packageDirectory is " + packageDirectory); if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) { if (returnContent) { let distFile = packageDirectory + packageName + ".js"; @@ -48,18 +60,29 @@ class Npm { } - downloadFromNpm(registryJSON, packageName, version, returnContent, callback) { + downloadFromNpm(packageName, version, returnContent, callback) { let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + console.dir("packageDirectory: " + packageDirectory); let manager = new PluginManager({pluginsPath: packageDirectory}); + if (fs.existsSync(packageDirectory + packageName)) { + return callback(null, packageDirectory + packageName); + } + this.logger.info("downloading " + packageName + " " + version + "...."); manager.install(packageName, version).then((result) => { + console.dir("== result"); + console.dir(result); if (returnContent) { callback(null , fs.readFileSync(result.mainFile).toString()); } else { callback(null , result.location); } + }).catch((error) => { + console.dir("======> error"); + console.dir(error); + callback(error); }); } @@ -93,10 +116,13 @@ class Npm { // TODO: callback should accept an error getPackageVersion(packageName, version, returnContent, getFromGit, callback) { + console.dir(arguments); let self = this; let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version; let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + self.downloadFromNpm(packageName, version, returnContent, callback); + //if (fs.existsSync(packageDirectory) && fs.existsSync(packageDirectory + "package.json")) { // let content; // if (getFromGit && returnContent) { @@ -111,21 +137,21 @@ class Npm { // return callback(null, content); //} - 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); + //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); - } - }); + // if (getFromGit) { + // self.downloadFromGit(registryJSON, packageName, version, returnContent, callback); + // } else { + // self.downloadFromNpm(registryJSON, packageName, version, returnContent, callback); + // } + //}); } } diff --git a/package.json b/package.json index 6c15f2e81..50d6d24e4 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "globule": "^1.1.0", "http-shutdown": "^1.2.0", "ipfs-api": "17.2.4", - "live-plugin-manager": "^0.11.0", + "live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git", "merge": "^1.2.0", "mocha": "^2.2.5", "orbit-db": "^0.17.3", @@ -61,7 +61,7 @@ "underscore.string": "^3.3.4", "url-loader": "^0.6.2", "viz.js": "^1.8.1", - "web3": "1.0.0-beta.34", + "web3": "1.0.0-beta.32", "webpack": "^3.10.0", "window-size": "^1.1.0" }, 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/embark.json b/test_apps/test_app/embark.json index 365290c22..66dfb0066 100644 --- a/test_apps/test_app/embark.json +++ b/test_apps/test_app/embark.json @@ -15,7 +15,9 @@ "buildDir": "dist/", "config": "config/", "versions": { - "solc": "0.4.18" + "solc": "0.4.18", + "web3": "1.0.0-beta.34", + "ipfs-api": "17.2.7" }, "plugins": { "embark-service": {}