use web3 naming instead of web3.js; check if package already exists

This commit is contained in:
Iuri Matias 2018-04-20 19:45:57 -04:00
parent 1b6d747dbd
commit cf02a10656
8 changed files with 56 additions and 23 deletions

View File

@ -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));
});
}

View File

@ -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": {

View File

@ -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);
});
}

View File

@ -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);
// }
//});
}
}

View File

@ -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"
},

View File

@ -1,7 +1,7 @@
{
"default": {
"versions": {
"web3.js": "1.0.0-beta.27",
"web3": "1.0.0-beta.27",
"solc": "0.4.17"
},
"deployment": {

View File

@ -9,7 +9,7 @@
"webserver": false
},
"versions": {
"web3.js": "1.0.0-beta",
"web3": "1.0.0-beta",
"solc": "0.4.17"
}
}

View File

@ -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": {}