-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgulpfile.js
More file actions
56 lines (45 loc) · 1.33 KB
/
gulpfile.js
File metadata and controls
56 lines (45 loc) · 1.33 KB
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
/* eslint-disable implicit-arrow-linebreak) */
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const through2 = require('through2');
const sourceFiles = [
'./files/editor.html',
'./node_modules/@actualwave/messageport-dispatcher/dist/messageport-dispatcher.min.js',
'./files/initscript.js',
];
const createStream = (data) => {
return through2.obj((target, enc, cb) => {
const { base } = path.parse(target.path);
console.log('Add module: ', base);
data[base] = target.contents.toString();
cb();
});
};
const loadFileData = (filePath, data) => {
return new Promise((res) => {
gulp
.src(filePath)
.pipe(createStream(data))
.pipe(gulp.dest('./tmp/'))
.on('end', () => {
res(data);
});
});
};
const loadData = (files, data = {}) =>
new Promise((res, rej) => {
Promise.all(files.map((file) => loadFileData(file, data)))
.then(() => res(data))
.catch(rej);
});
const createBundle = (files) =>
loadData(files).then((data) => {
if (!fs.existsSync('./source/assets')) {
fs.mkdirSync('./source/assets');
}
fs.writeFileSync('./source/assets/webview_bundle.json', JSON.stringify(data, null, 2));
});
const webview = () => createBundle(sourceFiles);
exports.webview = webview;
exports.default = gulp.series(webview);