-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (34 loc) · 1.17 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
var shell = require('shelljs');
var runScriptOnChangePreprocessor = function(args, logger, config) {
var log = logger.create('preprocessor.custom');
var script = (config && config.script) || null;
var stopOnError = (config && config.stopOnError) || false;
var messageOnError = (config && config.messageOnError) || null;
var runOnlyOnce = (config && config.runOnlyOnce) || null;
var scriptHasRun = false;
return function(content, file, done) {
var result = null;
if(runOnlyOnce && scriptHasRun) {
log.debug('script has been executed, not gonna run again, exiting');
return done(null, content);
}
if (script) {
result = shell.exec(script);
scriptHasRun = true;
}
log.debug('shell execution result', result);
if (result && result.code !== 0 && stopOnError) {
if (messageOnError) {
log.error(messageOnError);
}
done(new Error(result.output), null);
} else {
done(null, content);
}
};
};
runScriptOnChangePreprocessor.$inject = ['args', 'logger', 'config.runscript'];
// PUBLISH DI MODULE
module.exports = {
'preprocessor:runscript': ['factory', runScriptOnChangePreprocessor]
};