From 2ed4eee831e4260ef93f336d83c7df1037302060 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Jul 2017 18:26:44 -0400 Subject: [PATCH] display loading message when new libs are being installed --- lib/contracts/compiler.js | 2 +- lib/contracts/solcW.js | 8 +++++--- lib/core/config.js | 3 ++- lib/pipeline/npm.js | 15 +++++++++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/contracts/compiler.js b/lib/contracts/compiler.js index 137fbc66..8eeb800b 100644 --- a/lib/contracts/compiler.js +++ b/lib/contracts/compiler.js @@ -69,7 +69,7 @@ class Compiler { }, function loadCompiler(callback) { // TODO: there ino need to load this twice - solcW = new SolcW(self.solcVersion); + solcW = new SolcW({logger: self.logger, solcVersion: self.solcVersion}); if (solcW.isCompilerLoaded()) { return callback(); } diff --git a/lib/contracts/solcW.js b/lib/contracts/solcW.js index 9acce168..a37d82b2 100644 --- a/lib/contracts/solcW.js +++ b/lib/contracts/solcW.js @@ -1,14 +1,15 @@ let utils = require('../utils/utils.js'); let solcProcess; let compilerLoaded = false; -var npm = require('../pipeline/npm.js'); +var Npm = require('../pipeline/npm.js'); let path = require('path'); let currentSolcVersion = require('../../package.json').dependencies.solc; class SolcW { - constructor(solcVersion) { - this.solcVersion = solcVersion; + constructor(options) { + this.solcVersion = options.solcVersion; + this.logger = options.logger; } load_compiler(done) { @@ -27,6 +28,7 @@ class SolcW { if (this.solcVersion === currentSolcVersion) { solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'}); } else { + let npm = new Npm({logger: this.logger}); npm.getPackageVersion('solc', this.solcVersion, false, function(location) { let requirePath = path.join(process.env.PWD, location); solcProcess.send({action: 'loadCompiler', solcLocation: requirePath}); diff --git a/lib/core/config.js b/lib/core/config.js index 23224c72..6665e7b4 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -2,7 +2,7 @@ var fs = require('./fs.js'); var File = require('./file.js'); var Plugins = require('./plugins.js'); var utils = require('../utils/utils.js'); -var npm = require('../pipeline/npm.js'); +var Npm = require('../pipeline/npm.js'); // TODO: add wrapper for fs so it can also work in the browser // can work with both read and save @@ -240,6 +240,7 @@ Config.prototype.loadFiles = function(files) { //if (false) { //readFiles.push(new File({filename: 'web3-' + web3Version + '.js', type: 'custom', resolver: function(callback) { readFiles.push(new File({filename: 'web3.js', type: 'custom', resolver: function(callback) { + let npm = new Npm({logger: self.logger}); npm.getPackageVersion('web3', web3Version, 'dist/web3.js', function(web3Content) { callback(web3Content); }); diff --git a/lib/pipeline/npm.js b/lib/pipeline/npm.js index cd9367b3..3f4bdfea 100644 --- a/lib/pipeline/npm.js +++ b/lib/pipeline/npm.js @@ -6,8 +6,14 @@ let http = require('follow-redirects').http; let https = require('follow-redirects').https; var tar = require('tar'); -module.exports = { - getPackageVersion: function(packageName, version, returnContent, callback) { +class Npm { + + constructor(options) { + this.logger = options.logger; + } + + getPackageVersion(packageName, version, returnContent, callback) { + let self = this; let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version; utils.httpsGet(npmRegistry, function (res) { @@ -45,7 +51,7 @@ module.exports = { } } else { fs.mkdirpSync(packageDirectory); - //self.logger.info("downloading " + packageName + " " + version + "...."); + self.logger.info("downloading " + packageName + " " + version + "...."); download(tarball, packageDirectory + "/downloaded_package.tgz", function() { o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe( @@ -68,5 +74,6 @@ module.exports = { }); }); } -}; +} +module.exports = Npm;