]>
git.immae.eu Git - github/fretlink/purs-loader.git/blob - src/bundle.js
3 const path
= require('path');
5 const Promise
= require('bluebird')
7 const fs
= Promise
.promisifyAll(require('fs'))
9 const spawn
= require('cross-spawn')
11 const debug
= require('debug')('purs-loader');
13 const dargs
= require('./dargs');
15 module
.exports
= function bundle(options
, bundleModules
) {
20 const bundleCommand
= options
.pscBundle
|| 'purs';
22 const bundleArgs
= (options
.pscBundle
? [] : [ 'bundle' ]).concat(dargs(Object
.assign({
23 _: [path
.join(options
.output
, '*', '*.js')],
24 output: options
.bundleOutput
,
25 namespace: options
.bundleNamespace
,
26 }, options
.pscBundleArgs
)));
28 bundleModules
.forEach(name
=> bundleArgs
.push('--module', name
))
30 debug('bundle: %s %O', bundleCommand
, bundleArgs
);
32 return (new Promise((resolve
, reject
) => {
33 debug('bundling PureScript...')
35 const compilation
= spawn(bundleCommand
, bundleArgs
)
37 compilation
.stdout
.on('data', data
=> stdout
.push(data
.toString()))
39 compilation
.stderr
.on('data', data
=> stderr
.push(data
.toString()))
41 compilation
.on('close', code
=> {
42 debug('finished bundling PureScript.')
45 const errorMessage
= stderr
.join('');
47 if (errorMessage
.length
) {
48 reject(new Error(`bundling failed: ${errorMessage}`))
51 reject(new Error('bundling failed'))
55 resolve(fs
.appendFileAsync(options
.bundleOutput
, `module.exports = ${options.bundleNamespace}`))