mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-10 22:16:20 +00:00
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() {
|
Config.prototype.loadContractsConfigFile = function() {
|
||||||
var defaultVersions = {
|
var defaultVersions = {
|
||||||
"web3.js": "1.0.0-beta",
|
"web3": "1.0.0-beta",
|
||||||
"solc": "0.4.17"
|
"solc": "0.4.17"
|
||||||
};
|
};
|
||||||
var versions = utils.recursiveMerge(defaultVersions, this.embarkConfig.versions || {});
|
var versions = utils.recursiveMerge(defaultVersions, this.embarkConfig.versions || {});
|
||||||
|
@ -21,7 +21,7 @@ class LibraryManager {
|
|||||||
this.versions = {};
|
this.versions = {};
|
||||||
|
|
||||||
let solcVersionInConfig = this.contractsConfig.versions.solc;
|
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"];
|
let ipfsApiVersion = this.storageConfig.versions["ipfs-api"];
|
||||||
|
|
||||||
this.versions['solc'] = solcVersionInConfig;
|
this.versions['solc'] = solcVersionInConfig;
|
||||||
@ -64,10 +64,7 @@ class LibraryManager {
|
|||||||
listenToCommandsToGetLibrary() {
|
listenToCommandsToGetLibrary() {
|
||||||
let npm = new Npm({logger: this.embark.logger});
|
let npm = new Npm({logger: this.embark.logger});
|
||||||
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);
|
||||||
});
|
|
||||||
this.embark.events.setCommandHandler('version:getPackageContent', (libName, version, cb) => {
|
|
||||||
npm.getPackageVersion(libName, version, false, true, 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 fs = require('../core/fs.js');
|
||||||
|
|
||||||
|
let PluginManager = require('live-plugin-manager').PluginManager;
|
||||||
|
|
||||||
class Npm {
|
class Npm {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadFromGit(registryJSON, packageName, version, returnContent, callback) {
|
getPackageVersion(packageName, version, 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 + '/';
|
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
|
||||||
if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) {
|
|
||||||
if (returnContent) {
|
let manager = new PluginManager({pluginsPath: packageDirectory});
|
||||||
let distFile = packageDirectory + packageName + ".js";
|
|
||||||
callback(null, fs.readFileSync(distFile).toString());
|
if (fs.existsSync(packageDirectory + packageName)) {
|
||||||
} else {
|
return callback(null, packageDirectory + packageName);
|
||||||
callback(null, packageDirectory);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fs.mkdirpSync(packageDirectory);
|
|
||||||
this.logger.info("downloading " + packageName + " " + version + "....");
|
this.logger.info("downloading " + packageName + " " + version + "....");
|
||||||
|
manager.install(packageName, version).then((result) => {
|
||||||
utils.downloadFile(fileLocation, packageDirectory + "/" + packageName + ".js", function() {
|
callback(null , result.location);
|
||||||
utils.extractTar(packageDirectory + "/" + packageName + ".js", packageDirectory, function() {
|
}).catch(callback);
|
||||||
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;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"globule": "^1.1.0",
|
"globule": "^1.1.0",
|
||||||
"http-shutdown": "^1.2.0",
|
"http-shutdown": "^1.2.0",
|
||||||
"ipfs-api": "17.2.4",
|
"ipfs-api": "17.2.4",
|
||||||
|
"live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git",
|
||||||
"merge": "^1.2.0",
|
"merge": "^1.2.0",
|
||||||
"mocha": "^2.2.5",
|
"mocha": "^2.2.5",
|
||||||
"orbit-db": "^0.17.3",
|
"orbit-db": "^0.17.3",
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"buildDir": "dist/",
|
"buildDir": "dist/",
|
||||||
"config": "config/",
|
"config": "config/",
|
||||||
"versions": {
|
"versions": {
|
||||||
"web3.js": "1.0.0-beta",
|
"web3": "1.0.0-beta",
|
||||||
"solc": "0.4.17",
|
"solc": "0.4.17",
|
||||||
"ipfs-api": "17.2.4"
|
"ipfs-api": "17.2.4"
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"buildDir": "dist/",
|
"buildDir": "dist/",
|
||||||
"config": "config/",
|
"config": "config/",
|
||||||
"versions": {
|
"versions": {
|
||||||
"web3.js": "1.0.0-beta",
|
"web3": "1.0.0-beta",
|
||||||
"solc": "0.4.17",
|
"solc": "0.4.17",
|
||||||
"ipfs-api": "17.2.4"
|
"ipfs-api": "17.2.4"
|
||||||
},
|
},
|
||||||
|
@ -38,7 +38,7 @@ describe('embark.Config', function () {
|
|||||||
it('should load contract config correctly', function () {
|
it('should load contract config correctly', function () {
|
||||||
config.loadContractsConfigFile();
|
config.loadContractsConfigFile();
|
||||||
let expectedConfig = {
|
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'},
|
deployment: {host: 'localhost', port: 8545, type: 'rpc'},
|
||||||
dappConnection: ['$WEB3', 'localhost:8545'],
|
dappConnection: ['$WEB3', 'localhost:8545'],
|
||||||
"gas": "auto",
|
"gas": "auto",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"default": {
|
"default": {
|
||||||
"versions": {
|
"versions": {
|
||||||
"web3.js": "1.0.0-beta.27",
|
"web3": "1.0.0-beta.27",
|
||||||
"solc": "0.4.17"
|
"solc": "0.4.17"
|
||||||
},
|
},
|
||||||
"deployment": {
|
"deployment": {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"webserver": false
|
"webserver": false
|
||||||
},
|
},
|
||||||
"versions": {
|
"versions": {
|
||||||
"web3.js": "1.0.0-beta",
|
"web3": "1.0.0-beta",
|
||||||
"solc": "0.4.17"
|
"solc": "0.4.17"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pragma solidity ^0.4.17;
|
pragma solidity ^0.4.18;
|
||||||
contract AnotherStorage {
|
contract AnotherStorage {
|
||||||
address public simpleStorageAddress;
|
address public simpleStorageAddress;
|
||||||
address simpleStorageAddress2;
|
address simpleStorageAddress2;
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"config": "config/",
|
"config": "config/",
|
||||||
"versions": {
|
"versions": {
|
||||||
"solc": "0.4.18",
|
"solc": "0.4.18",
|
||||||
"ipfs-api": "17.2.6"
|
"web3": "1.0.0-beta.34",
|
||||||
|
"ipfs-api": "17.2.7"
|
||||||
},
|
},
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"embark-service": {}
|
"embark-service": {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user