This commit is contained in:
Iuri Matias 2018-04-20 19:52:51 -04:00
parent cf02a10656
commit 41f04234d0
4 changed files with 6 additions and 141 deletions

View File

@ -279,7 +279,6 @@ class CodeGenerator {
async.waterfall([ async.waterfall([
function getWeb3Location(next) { function getWeb3Location(next) {
self.events.request("version:get:web3", function(web3Version) { self.events.request("version:get:web3", function(web3Version) {
console.dir("event request for web3 " + web3Version);
if (web3Version === "1.0.0-beta") { if (web3Version === "1.0.0-beta") {
return next(null, fs.embarkPath("js/web3-1.0.min.js")); return next(null, fs.embarkPath("js/web3-1.0.min.js"));
} else { } else {

View File

@ -117,7 +117,6 @@ Config.prototype.loadContractsConfigFile = function() {
"solc": "0.4.17" "solc": "0.4.17"
}; };
var versions = utils.recursiveMerge(defaultVersions, this.embarkConfig.versions || {}); var versions = utils.recursiveMerge(defaultVersions, this.embarkConfig.versions || {});
console.dir(versions);
var configObject = { var configObject = {
"default": { "default": {

View File

@ -63,13 +63,8 @@ class LibraryManager {
listenToCommandsToGetLibrary() { listenToCommandsToGetLibrary() {
let npm = new Npm({logger: this.embark.logger}); let npm = new Npm({logger: this.embark.logger});
// the installed package e.g solc
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => { this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
npm.getPackageVersion(libName, version, false, false, cb); npm.getPackageVersion(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

@ -1,5 +1,3 @@
// here be dragons
// TODO: this is horrible and needs to be refactored ASAP
let utils = require('../utils/utils.js'); let utils = require('../utils/utils.js');
let fs = require('../core/fs.js'); let fs = require('../core/fs.js');
@ -11,58 +9,10 @@ class Npm {
this.logger = options.logger; this.logger = options.logger;
} }
downloadFromGit(registryJSON, packageName, version, returnContent, callback) { getPackageVersion(packageName, version, callback) {
console.dir("==== downloadFromGit "); let self = this;
console.dir(arguments); let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version;
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);
return callback("error");
}
let fileLocation = "https://raw.githubusercontent.com/" + repoName + "/" + gitHead + "/dist/web3.min.js";
console.dir("fileLocation is " + fileLocation);
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
console.dir("packageDirectory is " + packageDirectory);
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(packageName, version, returnContent, callback) {
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
console.dir("packageDirectory: " + packageDirectory);
let manager = new PluginManager({pluginsPath: packageDirectory}); let manager = new PluginManager({pluginsPath: packageDirectory});
@ -72,86 +22,8 @@ class Npm {
this.logger.info("downloading " + packageName + " " + version + "...."); this.logger.info("downloading " + packageName + " " + version + "....");
manager.install(packageName, version).then((result) => { 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); callback(null , result.location);
} }).catch(callback);
}).catch((error) => {
console.dir("======> error");
console.dir(error);
callback(error);
});
}
old_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) {
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) {
// 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);
//}
//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);
// }
//});
} }
} }