-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
66 lines (57 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var expandGlobs = require('./expand-globs'),
writeBundles = require('./write-bundles'),
EventEmitter = require('events').EventEmitter;
module.exports = simplifyify;
/**
* @typedef {{
* outfile: string,
* exclude: string,
* standalone: string,
* bundle: boolean,
* debug: boolean,
* minify: boolean,
* test: boolean,
* watch: boolean
* }} Options
*/
/**
* The Simplifyify API
*
* @param {string|string[]} globs - One or more file paths and/or glob patterns
* @param {Options} [options] - Simplifyify CLI options
* @returns {EventEmitter}
*/
function simplifyify(globs, options) {
options = options || {};
var events = new EventEmitter();
process.nextTick(simplifyifyAsync);
return events;
/**
* Do everything asynchronously, even parameter validation.
*/
function simplifyifyAsync() {
try {
// Validate the entry files
if (!globs || globs.length === 0) {
events.emit('error', new Error('No entry files were specified'));
return;
}
if (!Array.isArray(globs)) {
globs = [globs];
}
// Expand the glob(s) into a list of entry files and output files
var fileSets = expandGlobs(globs, options);
if (fileSets.length === 0) {
events.emit('error', new Error('No matching entry files were found'));
return;
}
fileSets.forEach(function(fileSet) {
writeBundles(fileSet, events, options);
});
}
catch (e) {
events.emit('error', e);
}
}
}