UNPKG

1.47 kBJavaScriptView Raw
1'use strict'
2
3/**
4 * Compile a specified source folder.
5 * @public
6 * @param {Array} routes - Array of route configurations.
7 * @param {String} srcPath - Path to the source folder.
8 * @param {String} distPath - Path to the destination folder.
9 * @param {Object} opts - Additional optional options.
10 * @param {Function} next - The callback that handles the response. Receives the following properties: err.
11 */
12module.exports = function(routes, srcPath, distPath, opts, next) {
13
14 // Require modules on function call to speed up the initial launch
15 const async = require('async')
16 const validate = require('./validate')
17 const clean = require('./clean')
18 const copy = require('./copy')
19 const run = require('./run')
20
21 // Current working directory
22 const cwdPath = process.cwd()
23
24 // Make opts optional and use opts as next when next is undefined
25 // Next will be validated at a later juncture
26 if (next==null) next = opts
27
28 try {
29
30 next = validate.next(next)
31 routes = routes.map(validate.route)
32 srcPath = validate.path(srcPath)
33 distPath = validate.path(distPath)
34 opts = validate.opts(opts)
35
36 } catch (err) {
37
38 return next(err)
39
40 }
41
42 // Handlers may use promises which could lead to unhandled rejections
43 process.on('unhandledRejection', next)
44
45 async.series([
46
47 (next) => clean(distPath, cwdPath, opts, next),
48 (next) => copy(routes, srcPath, distPath, opts, next),
49 (next) => run(routes, srcPath, distPath, opts, next)
50
51 ], next)
52
53}
\No newline at end of file