From b2d71a3cf6fe2ab353deedf11330fef1d325f5fd Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 19 Aug 2016 09:40:34 -0400 Subject: [PATCH] enable rollup-init --- bin/src/handleError.js | 4 ++++ bin/src/index.js | 5 +++++ bin/src/initProject.js | 15 +++++++++++++++ package.json | 1 + 4 files changed, 25 insertions(+) create mode 100644 bin/src/initProject.js diff --git a/bin/src/handleError.js b/bin/src/handleError.js index 80892fd..3bfe263 100644 --- a/bin/src/handleError.js +++ b/bin/src/handleError.js @@ -41,6 +41,10 @@ const handlers = { stderr( chalk.red( 'rollup --watch depends on the rollup-watch package, which could not be found. You can install it globally (recommended) with ' ) + chalk.cyan( 'npm install -g rollup-watch' ) ); }, + ROLLUP_INIT_NOT_INSTALLED: () => { + stderr( chalk.red( 'rollup init depends on the rollup-init package, which could not be found. You can install it globally (recommended) with ' ) + chalk.cyan( 'npm install -g rollup-init' ) ); + }, + WATCHER_MISSING_INPUT_OR_OUTPUT: () => { stderr( chalk.red( 'must specify --input and --output when using rollup --watch' ) ); } diff --git a/bin/src/index.js b/bin/src/index.js index 1b8f1e6..aa5fda0 100644 --- a/bin/src/index.js +++ b/bin/src/index.js @@ -2,6 +2,7 @@ import minimist from 'minimist'; import help from './help.md'; import { version } from '../../package.json'; import runRollup from './runRollup'; +import initProject from './initProject'; const command = minimist( process.argv.slice( 2 ), { alias: { @@ -33,6 +34,10 @@ else if ( command.version ) { console.log( `rollup version ${version}` ); // eslint-disable-line no-console } +else if ( command._[0] === 'init' ) { + initProject(); +} + else { runRollup( command ); } diff --git a/bin/src/initProject.js b/bin/src/initProject.js new file mode 100644 index 0000000..b9daf78 --- /dev/null +++ b/bin/src/initProject.js @@ -0,0 +1,15 @@ +import relative from 'require-relative'; +import handleError from './handleError.js'; + +export default function () { + try { + const init = relative( 'rollup-init', process.cwd() ); + init( process.cwd() ); + } catch ( err ) { + if ( err.code === 'MODULE_NOT_FOUND' ) { + err.code = 'ROLLUP_INIT_NOT_INSTALLED'; + } + + handleError( err ); + } +} diff --git a/package.json b/package.json index 8007949..6747f93 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "build": "git rev-parse HEAD > .commithash && rollup -c", "watch": "rollup -c -w", "build:cli": "rollup -c rollup.config.cli.js", + "watch:cli": "rollup -c rollup.config.cli.js -w", "build:browser": "git rev-parse HEAD > .commithash && rollup -c rollup.config.browser.js -o dist/rollup.browser.js", "prepublish": "npm run lint && npm test && npm run build:browser", "lint": "eslint src browser test/test.js test/utils test/**/_config.js"