/
_config.js
51 lines (49 loc) · 1.31 KB
/
_config.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
const fs = require('fs');
const path = require('path');
const { atomicWriteFileSync } = require('../../../../utils');
let configFile;
module.exports = {
description: 'keeps watching the config file in case the config is changed to an invalid state',
command: 'rollup -cw',
before() {
configFile = path.resolve(__dirname, 'rollup.config.js');
fs.writeFileSync(
configFile,
'export default {\n' +
'\tinput: "main.js",\n' +
'\toutput: {\n' +
'\t\tfile: "_actual/main1.js",\n' +
'\t\tformat: "es"\n' +
'\t}\n' +
'};'
);
},
after() {
// synchronous sometimes does not seem to work, probably because the watch is not yet removed properly
setTimeout(() => fs.unlinkSync(configFile), 300);
},
abortOnStderr(data) {
if (data.includes(`created _actual${path.sep}main1.js`)) {
atomicWriteFileSync(configFile, 'throw new Error("Config contains errors");');
return false;
}
if (data.includes('Config contains errors')) {
setTimeout(() => {
atomicWriteFileSync(
configFile,
'export default {\n' +
'\tinput: "main.js",\n' +
'\toutput: {\n' +
'\t\tfile: "_actual/main2.js",\n' +
'\t\tformat: "es"\n' +
'\t}\n' +
'};'
);
}, 400);
return false;
}
if (data.includes(`created _actual${path.sep}main2.js`)) {
return true;
}
}
};