diff --git a/README.md b/README.md index 277bde6..79e2959 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # lerna-terminal [![build status](https://img.shields.io/travis/smollweide/lerna-terminal/master.svg)](https://travis-ci.org/smollweide/lerna-terminal) -> Powerful cli ui for lerna - replace `lerna run ` with `lerna-terminal `. +> Powerful cli ui for lerna - replace `lerna run ` with `lerna-terminal `. ![kapture 2017-11-02 at 17 25 41](https://user-images.githubusercontent.com/2912007/32337702-08be4f34-bff3-11e7-808b-54c9bd09a0c9.gif) @@ -20,7 +20,7 @@ $ npm install lerna-terminal $ lerna-terminal --help Usage - $ lerna-terminal [options] + $ lerna-terminal [options] Options -V, --version Output the version number diff --git a/src/commander/index.js b/src/commander/index.js index 383691b..5d09a57 100644 --- a/src/commander/index.js +++ b/src/commander/index.js @@ -8,9 +8,9 @@ const packageData = require('../../package.json'); function runCommander() { program .version(packageData.version) - .arguments('') - .action(scriptNames => { - program.scripts = scriptNames.split(','); + .arguments('') + .action(scriptName => { + program.script = scriptName; }) .option('-i, --ignoredPackages [string]', 'Add packages which should be ignored') .option('-f, --focus [string]', 'Focus one subterminal initially') @@ -19,7 +19,7 @@ function runCommander() { .parse(process.argv); /* istanbul ignore next */ - if (!program.scripts || !Array.isArray(program.scripts) || program.scripts.length < 1) { + if (!program.script) { throw new Error('--script is required'); } } diff --git a/src/index.js b/src/index.js index 69b33ee..1773141 100755 --- a/src/index.js +++ b/src/index.js @@ -5,19 +5,15 @@ const { runCommander } = require('./commander'); const { resizeListener } = require('./getDimensions'); const { provideStore } = require('./store'); -const { getProgram } = require('./commander'); const commandListener = require('./commandListener'); const runNpmScripts = require('./runNpmScripts'); const render = require('./render'); const executeCmd = require('./executeCmd'); const handleKillProcess = require('./handleKillProcess'); -const program = getProgram(); runCommander(); provideStore(); -program.scripts.forEach(scriptName => { - runNpmScripts(scriptName); -}); +runNpmScripts(); resizeListener(render); commandListener(executeCmd); handleKillProcess(); diff --git a/src/runNpmScripts/index.js b/src/runNpmScripts/index.js index e46c466..efad276 100644 --- a/src/runNpmScripts/index.js +++ b/src/runNpmScripts/index.js @@ -17,20 +17,19 @@ const parseText = text => { }; /** - * @param {string} scriptName - npm script name * @returns {Object} state **/ -function runNpmScripts(scriptName) { +function runNpmScripts() { const commands = getScriptCommands(); const program = getProgram(); const state = getState(); - if (!commands[scriptName]) { + if (!commands[program.script]) { throw new Error("the given script wasn't found!"); } - Object.keys(commands[scriptName]).forEach(index => { - const packagePath = commands[scriptName][index]; + Object.keys(commands[program.script]).forEach(index => { + const packagePath = commands[program.script][index]; const packageName = path.basename(packagePath); if (isIgnoredPackage(packagePath, program.ignoredPackages)) { return; @@ -39,7 +38,7 @@ function runNpmScripts(scriptName) { log: [], }; state[packageName].terminal = runNpmScript({ - scriptName, + scriptName: program.script, packagePath, onRecieve(text) { if (text.search('\x1Bc') >= 0) { diff --git a/src/runNpmScripts/index.spec.js b/src/runNpmScripts/index.spec.js index 48c6c12..a8b0d25 100644 --- a/src/runNpmScripts/index.spec.js +++ b/src/runNpmScripts/index.spec.js @@ -34,7 +34,7 @@ describe('runNpmScripts', () => { getScriptCommands.mockImplementation(() => ({})); getProgram.mockImplementation(() => ({ script: 'start' })); expect(() => { - runNpmScripts('start'); + runNpmScripts(); }).toThrow(); }); it('packages ignored', () => { @@ -42,7 +42,7 @@ describe('runNpmScripts', () => { getScriptCommands.mockImplementation(() => ({ start: ['/path/to/package/utils', '/path/to/package/ui'] })); getProgram.mockImplementation(() => ({ script: 'start' })); isIgnoredPackage.mockImplementation(() => true); - runNpmScripts('start'); + runNpmScripts(); }); it('packages in state', () => { getState.mockImplementation(() => ({})); @@ -50,7 +50,7 @@ describe('runNpmScripts', () => { isIgnoredPackage.mockImplementation(() => false); basename.mockImplementation(_path => _path.split('/')[4]); runNpmScript.mockImplementation(() => 'terminal'); - expect(runNpmScripts('start')).toEqual({ + expect(runNpmScripts()).toEqual({ ui: { log: [], terminal: 'terminal' }, utils: { log: [], terminal: 'terminal' }, }); @@ -67,7 +67,7 @@ describe('runNpmScripts', () => { onRecieve('test\n'); onRecieve('test2'); }); - expect(runNpmScripts('start').utils.log).toEqual(['test', '', 'test2']); + expect(runNpmScripts().utils.log).toEqual(['test', '', 'test2']); }); it('package.terminal.onError -> update log', () => { getState.mockImplementation(() => ({})); @@ -81,7 +81,7 @@ describe('runNpmScripts', () => { onError('test\n'); onError('test2'); }); - expect(runNpmScripts('start').utils.log).toEqual(['test', '', 'test2']); + expect(runNpmScripts().utils.log).toEqual(['test', '', 'test2']); }); it('package.terminal.onExit -> update log', () => { getState.mockImplementation(() => ({})); @@ -94,7 +94,7 @@ describe('runNpmScripts', () => { runNpmScript.mockImplementation(({ onExit }) => { onExit(); }); - expect(runNpmScripts('start').utils.log).toEqual(['stop: utils']); + expect(runNpmScripts().utils.log).toEqual(['stop: utils']); }); it('package.terminal.onRecieve \x1Bc -> clear log', () => { getState.mockImplementation(() => ({})); @@ -107,7 +107,7 @@ describe('runNpmScripts', () => { runNpmScript.mockImplementation(({ onRecieve }) => { onRecieve('\x1Bc'); }); - expect(runNpmScripts('start').utils.log).toEqual(['']); + expect(runNpmScripts().utils.log).toEqual(['']); }); it('package.terminal.onError \x1Bc -> clear log', () => { getState.mockImplementation(() => ({})); @@ -120,6 +120,6 @@ describe('runNpmScripts', () => { runNpmScript.mockImplementation(({ onError }) => { onError('\x1Bc'); }); - expect(runNpmScripts('start').utils.log).toEqual(['']); + expect(runNpmScripts().utils.log).toEqual(['']); }); });