-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
41 lines (33 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var path = require( 'path' );
var pattern = /#\s*sourceMappingURL=([^\s]+)/;
module.exports = function sorcery ( inputdir, outputdir, options ) {
var sander = require( 'sander' ),
_sorcery = require( 'sorcery' );
return sander.lsr( inputdir ).then( function ( files ) {
var promises, queue = [];
promises = files.map( function ( file ) {
if ( file.slice( -4 ) === '.map' ) {
return; // don't link intermediate sourcemaps
}
return _sorcery.load( path.join( inputdir, file ) ).then( function ( chain ) {
var map, promises;
if ( !chain ) {
// this is an original source
return sander.link( inputdir, file ).to( outputdir, file );
}
// don't write yet, as the .map file could be overwritten by an
// existing .map file. Instead, enqueue it
queue.push({
dest: path.join( outputdir, file ),
chain: chain
});
});
});
return sander.Promise.all( promises ).then( function () {
var promises = queue.map( function ( item ) {
return item.chain.write( item.dest, options );
});
return sander.Promise.all( promises );
});
});
};