forked from samclarke/SCEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (89 loc) · 2.4 KB
/
gulpfile.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
import fs from 'fs';
import gulp from 'gulp';
import rename from 'gulp-rename';
import sass from 'gulp-sass';
import CleanCSS from 'clean-css';
import map from 'vinyl-map';
import zip from 'gulp-zip';
import { rollup } from 'rollup';
import { terser } from 'rollup-plugin-terser';
let
addFile = (n, x, b) =>
{
let
d = b ? `${x}/${n}` : x,
f = () =>
rollup({
input: `./src/${d}.js`
}).then(bundle =>
{
bundle.write(
{
file: `./dist/${d}.js`,
name: n.replace(/\W+/g,'_'),
format: 'iife'
}
);
bundle.write(
{
file: `./dist/${d}.min.js`,
name: n.replace(/\W+/g,'_'),
format: 'iife', plugins: [terser()]
}
);
});
f.displayName = `Compiling ${d}.js...`;
return f;
},
javascript = done =>
{
let
out = [],
mapFiles = d => fs.readdirSync(d).filter(x => !x.includes('-icons'))
.map(x => addFile(x.slice(0, -3), d.slice(4), true));
out.push(addFile('sceditor','sceditor', false));
out.push(addFile('bbcode','formats', true));
out.push(addFile('sceditor','sceditor.bbcode', false));
out.push(addFile('xhtml','formats', true));
out.push(addFile('sceditor','sceditor.xhtml', false));
out = out.concat(mapFiles('src/languages'));
out = out.concat(mapFiles('src/icons'));
out = out.concat(mapFiles('src/plugins'));
return gulp.parallel(...out, seriesDone =>
{
seriesDone();
done();
})();
},
sprites = fs.readdirSync('src/themes/icons/famfamfam')
.filter(x => x.slice(-3).toLowerCase() === 'png'),
sprite = cb =>
{
sprites.sort();
var spriteObj = [];
for (const sprite of sprites)
{
var data = fs.readFileSync(`src/themes/icons/famfamfam/${sprite}`, 'base64');
spriteObj.push(`${sprite.slice(0, -4).toLowerCase()}: '${data}'`);
}
fs.writeFileSync('src/icons/famfamfam-icons.js', `export default\n{\n\t${spriteObj.join(',\n\t')};\n}\n`);
return cb();
},
css = () =>
gulp.src('src/themes/*.scss')
.pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError))
.pipe(gulp.dest('dist'))
.pipe(map(buff => new CleanCSS().minify(buff.toString()).styles))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist')),
z = () =>
gulp.src(['dist/**/*', '!dist/sceditor.zip'])
.pipe(zip('sceditor.zip'))
.pipe(gulp.dest('dist'));
export default gulp.series(gulp.parallel(javascript, sprite, css), z);
export {
sprite,
javascript,
css,
zip as z
};