Browse Source

enable rollup-init

rollup-init
Rich-Harris 8 years ago
parent
commit
b2d71a3cf6
  1. 4
      bin/src/handleError.js
  2. 5
      bin/src/index.js
  3. 15
      bin/src/initProject.js
  4. 1
      package.json

4
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' ) );
}

5
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 );
}

15
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 );
}
}

1
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"

Loading…
Cancel
Save