-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (105 loc) · 2.99 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*!
* customize-watch <https://github.com/nknapp/customize-watch>
*
* Copyright (c) 2015 Nils Knappmeier.
* Released under the MIT license.
*/
'use strict'
var customize = require('customize')
module.exports = function watcher () {
return new Recustomize(customize)
}
Object.keys(customize).forEach(key => {
module.exports[key] = customize[key]
})
module.exports.Customize = Recustomize
/**
* Recustomize has the same interface as Customize, but instead of storing
* the current configuration-state, it stores a function that computes the state.
* The only difference is the [watch()](#Recustomize+watch)-method. It can be
* used to emit an event every time one of the input files is added, removed or changed.
*
* @param {function():customize} builder a builder function for a Customize object
*
* @constructor
*/
function Recustomize (builder) {
/**
* Wrap the method of a Customize object such that
* instead of the new Customize object, new Recustomize object
* with the appropriate builder-function is returned
*
* @param fnName
* @returns {Function}
* @api private
*/
function wrap (fnName) {
/* dynamic arguments */
return function () {
var args = arguments
return new Recustomize(function () {
var customize = builder()
return customize[fnName].apply(customize, args)
})
}
}
/**
* Wrapped function. See [customize](https://github.com/nknapp/customize) for details
* @api private
*/
this.merge = wrap('merge')
/**
* Wrapped function. See [customize](https://github.com/nknapp/customize) for details
* @api private
*/
this.registerEngine = wrap('registerEngine')
/**
* Wrapped function. See [customize](https://github.com/nknapp/customize) for details
* @type {Function}
*/
this.configSchema = function () {
return builder().configSchema()
}
/**
* Wrapped function. See [customize](https://github.com/nknapp/customize) for details
* @api private
*/
this.load = wrap('load')
/**
* Return the configuation object
* @returns {Promise<object>}
* @api private
*/
this.buildConfig = function () {
return builder().buildConfig()
}
/**
* Return a list of files and directories that need to be watched
* in watch-mode.
* @return {Promise<object<string[]>>} a list of paths to files or directories for each engine
* @api private
*/
this.watched = function () {
return builder().watched()
}
/**
* Register file-watchers for all relevant files.
* Rebuild the config and run the appropriate engine, whenever
* a file has changed.
* @return {EventEmitter}
*/
this.watch = function () {
return require('./lib/watcher.js')(this)
}
/**
* Wraps the run(...)-method of the customize object, rebuilding the whole configuration
* before running.
* @returns {object}
* @api private
*/
/* dynamic args */
this.run = function () {
var custObj = builder()
return custObj.run.apply(custObj, arguments)
}
}