You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

62 lines
1.3 KiB

require( 'source-map-support' ).install();
var path = require( 'path' );
var sander = require( 'sander' );
var Promise = sander.Promise;
var handleError = require( './handleError' );
var rollup = require( '../' );
module.exports = function ( options ) {
if ( options._.length > 1 ) {
handleError({ code: 'ONE_AT_A_TIME' });
}
if ( options._.length === 1 ) {
if ( options.input ) {
handleError({ code: 'DUPLICATE_IMPORT_OPTIONS' });
}
options.input = options._[0];
}
try {
bundle( options ).catch( handleError );
} catch ( err ) {
handleError( err );
}
};
function bundle ( options, method ) {
var bundleOptions, file;
if ( !options.input ) {
handleError({ code: 'MISSING_INPUT_OPTION' });
}
return rollup.rollup({
entry: options.input
}).then( function ( bundle ) {
var generateOptions = {
dest: options.output,
format: options.format
};
if ( options.output ) {
return bundle.write( generateOptions );
}
if ( options.sourcemap && options.sourcemap !== 'inline' ) {
handleError({ code: 'MISSING_OUTPUT_OPTION' });
}
var result = bundle.generate( generateOptions );
var code = result.code;
if ( options.sourcemap === 'inline' ) {
code += '\n//# sourceMappingURL=' + map.toUrl();
}
process.stdout.write( code );
});
}