1 | import Promise from 'es6-promise/lib/es6-promise/promise.js';
|
2 | import { basename } from './utils/path.js';
|
3 | import { writeFile } from './utils/fs.js';
|
4 | import { keys } from './utils/object.js';
|
5 | import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
|
6 | import Bundle from './Bundle.js';
|
7 |
|
8 | export const VERSION = '<@VERSION@>';
|
9 |
|
10 | export function rollup ( options ) {
|
11 | if ( !options || !options.entry ) {
|
12 | throw new Error( 'You must supply options.entry to rollup' );
|
13 | }
|
14 |
|
15 | if ( options.transform || options.load || options.resolveId || options.resolveExternal ) {
|
16 | throw new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' );
|
17 | }
|
18 |
|
19 | const bundle = new Bundle( options );
|
20 |
|
21 | return bundle.build().then( () => {
|
22 | return {
|
23 | imports: bundle.externalModules.map( module => module.id ),
|
24 | exports: keys( bundle.entryModule.exports ),
|
25 | modules: bundle.orderedModules.map( module => {
|
26 | return { id: module.id };
|
27 | }),
|
28 |
|
29 | generate: options => bundle.render( options ),
|
30 | write: options => {
|
31 | if ( !options || !options.dest ) {
|
32 | throw new Error( 'You must supply options.dest to bundle.write' );
|
33 | }
|
34 |
|
35 | const dest = options.dest;
|
36 | let { code, map } = bundle.render( options );
|
37 |
|
38 | let promises = [];
|
39 |
|
40 | if ( options.sourceMap ) {
|
41 | let url;
|
42 |
|
43 | if ( options.sourceMap === 'inline' ) {
|
44 | url = map.toUrl();
|
45 | } else {
|
46 | url = `${basename( dest )}.map`;
|
47 | promises.push( writeFile( dest + '.map', map.toString() ) );
|
48 | }
|
49 |
|
50 | code += `\n//# ${SOURCEMAPPING_URL}=${url}`;
|
51 | }
|
52 |
|
53 | promises.push( writeFile( dest, code ) );
|
54 | return Promise.all( promises );
|
55 | }
|
56 | };
|
57 | });
|
58 | }
|