Browse Source

on second thoughts, dont auto-install. will cause problems in many cases

ghi-672
Rich-Harris 9 years ago
parent
commit
138d255af4
  1. 43
      bin/getRollupWatch.js
  2. 2
      bin/handleError.js
  3. 55
      bin/runRollup.js

43
bin/getRollupWatch.js

@ -1,43 +0,0 @@
var chalk = require( 'chalk' );
var relative = require( 'require-relative' );
module.exports = function getRollupWatch () {
try {
watch = relative( 'rollup-watch', process.cwd() );
return Promise.resolve( watch );
} catch ( err ) {
if ( err.code === 'MODULE_NOT_FOUND' ) {
return installRollupWatch().then( () => {
return relative( 'rollup-watch', process.cwd() );
});
} else {
return Promise.reject( err );
}
}
};
function installRollupWatch () {
console.error( 'rollup --watch depends on the rollup-watch package, which could not be found. You can install it globally with ' + chalk.cyan( 'npm install -g rollup-watch' ) + '. Do this now? ' + chalk.green.bold( '[y/n]' ) );
process.stdin.setEncoding( 'utf8' );
return new Promise( ( fulfil, reject ) => {
process.stdin.on( 'readable', function () {
var chunk = process.stdin.read();
if ( !chunk ) return;
if ( /^y(?:es)?$/i.test( chunk ) ) {
console.error( 'installing rollup-watch...' );
child = require( 'child_process' ).exec( 'npm install --global rollup-watch', err => {
if ( err ) {
reject( err );
} else {
fulfil();
}
});
} else {
reject( new Error( 'aborted' ) );
}
});
});
}

2
bin/handleError.js

@ -30,7 +30,7 @@ var handlers = {
},
ROLLUP_WATCH_NOT_INSTALLED: function ( err ) {
console.error( chalk.red( 'failed to find or install rollup-watch' ) );
console.error( 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' ) );
},
WATCHER_MISSING_INPUT_OR_OUTPUT: function ( err ) {

55
bin/runRollup.js

@ -1,8 +1,8 @@
require( 'source-map-support' ).install();
var path = require( 'path' );
var relative = require( 'require-relative' );
var handleError = require( './handleError' );
var getRollupWatch = require( './getRollupWatch' );
var chalk = require( 'chalk' );
var rollup = require( '../' );
@ -134,30 +134,35 @@ function execute ( options, command ) {
handleError({ code: 'WATCHER_MISSING_INPUT_OR_OUTPUT' });
}
getRollupWatch()
.then( watch => {
const watcher = watch( rollup, options );
watcher.on( 'event', event => {
switch ( event.code ) {
case 'STARTING':
console.error( 'checking rollup-watch version...' );
break;
case 'BUILD_START':
console.error( 'bundling...' );
break;
case 'BUILD_END':
console.error( 'bundled in ' + event.duration + 'ms. Watching for changes...' );
break;
default:
console.error( 'unknown event', event );
}
});
})
.catch( handleError );
try {
var watch = relative( 'rollup-watch', process.cwd() );
var watcher = watch( rollup, options );
watcher.on( 'event', event => {
switch ( event.code ) {
case 'STARTING':
console.error( 'checking rollup-watch version...' );
break;
case 'BUILD_START':
console.error( 'bundling...' );
break;
case 'BUILD_END':
console.error( 'bundled in ' + event.duration + 'ms. Watching for changes...' );
break;
default:
console.error( 'unknown event', event );
}
});
} catch ( err ) {
if ( err.code === 'MODULE_NOT_FOUND' ) {
err.code = 'ROLLUP_WATCH_NOT_INSTALLED';
}
handleError( err );
}
} else {
bundle( options ).catch( handleError );
}

Loading…
Cancel
Save