mirror of https://github.com/embarklabs/embark.git
Merge pull request #375 from embark-framework/fix_package_management
Fix package management
This commit is contained in:
commit
782044ef7c
|
@ -1 +0,0 @@
|
|||
{}
|
|
@ -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 || {});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"default": {
|
||||
"versions": {
|
||||
"web3.js": "1.0.0-beta.27",
|
||||
"web3": "1.0.0-beta.27",
|
||||
"solc": "0.4.17"
|
||||
},
|
||||
"deployment": {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"webserver": false
|
||||
},
|
||||
"versions": {
|
||||
"web3.js": "1.0.0-beta",
|
||||
"web3": "1.0.0-beta",
|
||||
"solc": "0.4.17"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pragma solidity ^0.4.17;
|
||||
pragma solidity ^0.4.18;
|
||||
contract AnotherStorage {
|
||||
address public simpleStorageAddress;
|
||||
address simpleStorageAddress2;
|
||||
|
|
|
@ -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": {}
|
||||
|
|
Loading…
Reference in New Issue