blob: b189d47d0b75628f1cd86fce30ff72d276c8cca7 (
plain) (
blame)
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
|
/*
* Copyright (c) 2014-2019 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
*/
const fs = require('fs');
const path = require('path');
const THEME_JS_OUT_FILTER = f => /.*theme.*\.js/.test(f);
function deleteFile(filename) {
fs.access(filename, fs.constants.W_OK, err => {
if (err) {
console.error(`${filename} does not exist or cannot be deleted.`);
} else {
fs.unlink(filename, unlinkErr => {
if (unlinkErr) {
throw unlinkErr;
}
console.log(`deleted ${filename}`);
});
}
});
}
module.exports = {
createFileList: dir => {
const scoutBuild = require('./constants');
let content = '';
fs.readdirSync(dir, {withFileTypes: true})
.filter(dirent => dirent.isFile())
.map(dirent => dirent.name)
.filter(fileName => fileName !== scoutBuild.fileListName)
.filter(fileName => !THEME_JS_OUT_FILTER(fileName))
.map(fileName => `${fileName}\n`)
.forEach(line => content += line);
fs.writeFileSync(path.join(dir, scoutBuild.fileListName), content, {flag: 'w'});
console.log(`created ${scoutBuild.fileListName}:\n${content}`);
},
cleanOutDir: dir => {
if (!fs.existsSync(dir)) {
return;
}
fs.readdirSync(dir)
.filter(THEME_JS_OUT_FILTER)
.forEach(f => deleteFile(path.join(dir, f)));
}
};
|