diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..b77f5b05 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,147 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "type": "node", + "request": "launch", + "name": "Embark: Mocha All", + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "args": [ + "--colors", + "--no-timeouts", + "${workspaceFolder}/test/" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Embark: Mocha Current File", + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "args": [ + "--colors", + "--no-timeouts", + "${file}" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Embark: embark test", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/lib/tests/test_embark", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Test app: Embark test", + "cwd": "${workspaceFolder}/test_apps/test_app/", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "test" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Test app: Embark new testapp123", + "cwd": "${workspaceFolder}/test_apps/test_app/", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "new", + "testapp123" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Test app: Embark upload", + "cwd": "${workspaceFolder}/test_apps/test_app/", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "upload" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Test app: Embark run", + "cwd": "${workspaceFolder}/test_apps/test_app/", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "run", + "--nodashboard" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Embark demo from main repo: Embark run", + "cwd": "${workspaceFolder}/../../embk-fw/embark/embark_demo/", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "run" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Embark demo from dapp-bin: Embark run", + "cwd": "${workspaceFolder}/../../embk-fw/dapp-bin/embark_demo/", + "autoAttachChildProcesses": false, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "run", + "--nodashboard" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Embark react routes demo: Embark run", + "cwd": "${workspaceFolder}/../../emizzle/embark-demo-react-routes/", + "autoAttachChildProcesses": true, + //"preLaunchTask": "npm_install", + "program": "${workspaceFolder}/bin/embark", + "args": [ + "run" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + + ] +} \ No newline at end of file diff --git a/lib/core/engine.js b/lib/core/engine.js index 68e1b731..6e9faf33 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -16,6 +16,7 @@ class Engine { this.logLevel = options.logLevel; this.events = options.events; this.context = options.context; + this.useDashboard = options.useDashboard; } init(_options) { @@ -185,7 +186,7 @@ class Engine { this.ipc.serve(); } - this.registerModule('solidity', {ipc: this.ipc}); + this.registerModule('solidity', {ipc: this.ipc, useDashboard: this.useDashboard}); this.registerModule('vyper'); this.registerModule('profiler'); this.registerModule('fuzzer'); diff --git a/lib/index.js b/lib/index.js index a773dafe..410c1eb6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -80,7 +80,8 @@ class Embark { embarkConfig: options.embarkConfig || 'embark.json', logFile: options.logFile, logLevel: options.logLevel, - context: self.context + context: self.context, + useDashboard: options.useDashboard }); engine.init(); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 9fbc50eb..c70d51c1 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -10,6 +10,7 @@ class Solidity { this.contractDirectories = embark.config.contractDirectories; this.solcAlreadyLoaded = false; this.solcW = null; + this.useDashboard = options.useDashboard; embark.registerCompiler(".sol", this.compile_solidity.bind(this)); } @@ -49,7 +50,7 @@ class Solidity { if (self.solcAlreadyLoaded) { return callback(); } - self.solcW = new SolcW({logger: self.logger, events: self.events, ipc: self.ipc}); + self.solcW = new SolcW({logger: self.logger, events: self.events, ipc: self.ipc, useDashboard: self.useDashboard}); self.logger.info(__("loading solc compiler") + ".."); self.solcW.load_compiler(function (err) { diff --git a/lib/modules/solidity/solcP.js b/lib/modules/solidity/solcP.js index 060c9ae1..934cbad7 100644 --- a/lib/modules/solidity/solcP.js +++ b/lib/modules/solidity/solcP.js @@ -12,7 +12,7 @@ class SolcProcess extends ProcessWrapper { constructor(options){ super(); this._logger = options.logger; - this._npm = options.npm; + this._showSpinner = options.showSpinner === true; } findImports(filename) { @@ -34,11 +34,11 @@ class SolcProcess extends ProcessWrapper { installAndLoadCompiler(solcVersion, packagePath){ let self = this; - return new Promise((resolve) => { + return new Promise((resolve, reject) => { let manager = new PluginManager({pluginsPath: packagePath}); let timer; if (!fs.existsSync(packagePath)) { - timer = new NpmTimer({logger: self._logger, packageName: 'solc', version: solcVersion, showSpinner: true}); + timer = new NpmTimer({logger: self._logger, packageName: 'solc', version: solcVersion, showSpinner: self._showSpinner}); } if(timer) timer.start(); @@ -46,7 +46,7 @@ class SolcProcess extends ProcessWrapper { self.solc = manager.require('solc'); if(timer) timer.end(); resolve(); - }); + }).catch(reject); }); } diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index bc5df52e..a551ab65 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -12,6 +12,7 @@ class SolcW { this.ipc = options.ipc; this.compilerLoaded = false; this.solcProcess = null; + this.useDashboard = options.useDashboard; } load_compiler(done) { @@ -43,16 +44,15 @@ class SolcW { this.solcProcess.once("result", "initiated", () => { this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { - self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'}); - } else { - self.events.request("version:getPackagePath", "solc", solcVersion, function(err, path) { - if (err) { - return done(err); - } - let requirePath = fs.dappPath(path); - self.solcProcess.send({action: 'installAndLoadCompiler', solcVersion: solcVersion, packagePath: requirePath}); - }); - } + return self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'}); + } + self.events.request("version:getPackagePath", "solc", solcVersion, function(err, path) { + if (err) { + return done(err); + } + let requirePath = fs.dappPath(path); + self.solcProcess.send({action: 'installAndLoadCompiler', solcVersion: solcVersion, packagePath: requirePath}); + }); }); }); @@ -60,7 +60,7 @@ class SolcW { self.compilerLoaded = true; done(); }); - this.solcProcess.send({action: "init", options: {logger: self.logger}}); + this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}}); if (this.ipc.isServer()) { this.ipc.on('compile', self.compile.bind(this)); diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index 1c79b1e0..cc44791c 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -80,12 +80,10 @@ class Swarm { let currentPIterationVersion = require('../../../package.json').dependencies["p-iteration"]; if (pIterationVersion !== currentPIterationVersion) { self.events.request("version:getPackageLocation", "p-iteration", pIterationVersion, function(err, location) { - if(!err){ - self.embark.registerImportFile("p-iteration", fs.dappPath(location)); - } - else{ - self.logger.error("Error getting package location for p-iteration: " + err); + if(err){ + return self.logger.error("Error getting package location for p-iteration: " + err); } + self.embark.registerImportFile("p-iteration", fs.dappPath(location)); }); } }); diff --git a/lib/versions/npm.js b/lib/versions/npm.js index 1e58c0cc..0864817e 100644 --- a/lib/versions/npm.js +++ b/lib/versions/npm.js @@ -34,8 +34,7 @@ class Npm { if(this._isInstalling(packageName, version)){ this._installing[packageName + version].push(callback); }else{ - this._installing[packageName + version] = new Array(callback); - + this._installing[packageName + version] = [callback]; const timer = new NpmTimer({logger: this._logger, packageName: packageName, version: version}); timer.start(); @@ -49,7 +48,9 @@ class Npm { delete this._installing[packageName + version]; //callback(null, result.location); }).catch(err => { - callback(err); + this._installing[packageName + version].forEach((cb) => { + cb(err); + }); }); } } diff --git a/lib/versions/npmTimer.js b/lib/versions/npmTimer.js index efaa34b2..99a84a9c 100644 --- a/lib/versions/npmTimer.js +++ b/lib/versions/npmTimer.js @@ -7,7 +7,7 @@ i18n.setOrDetectLocale('en'); class NpmTimer{ constructor(options){ - this._logger = options.logger; + this._logger = (options.logger && typeof options.logger.info == 'function') ? options.logger : console; this._packageName = options.packageName; this._version = options.version; this._showSpinner = options.showSpinner || false; @@ -55,22 +55,13 @@ class NpmTimer{ if(entry.duration > 4000){ strDuration = strDuration.red; } - this._log(strDuration); + this._logger.info(strDuration); } }); } return this._observer; } - - _log(msg){ - if(typeof this._logger.info == 'function'){ - this._logger.info(msg); - } - else{ // occurs in subprocess as functions are not serialised/deserialised properly - console.log(msg.green); - } - } start(){ let self = this; @@ -83,7 +74,7 @@ class NpmTimer{ text: strDownloadStart }).start(); }else{ - this._log(strDownloadStart); + this._logger.info(strDownloadStart); } // mark our start time