-
Notifications
You must be signed in to change notification settings - Fork 22
/
gulpfile.js
98 lines (91 loc) · 2.74 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
95
96
97
98
var tmplFolder = 'tmpl'; //template folder
var srcFolder = 'src'; //source folder
var buildFolder = 'build'; //build folder
var gulp = require('gulp');
var watch = require('gulp-watch');
var fs = require('fs');
var combineTool = require('../magix-composer/index');
var del = require('del');
var ts = require('typescript');
combineTool.config({
debug: true,
tmplFolder: tmplFolder,
srcFolder: srcFolder,
projectName: 'xl',
loaderType: 'module',
galleries: {
mxRoot: 'gallery/'
},
scopedCss: [
'./tmpl/style/index.css',
'./tmpl/os/theme/index.css'
],
compileJSStart(content) {
var str = ts.transpileModule(content, {
compilerOptions: {
lib: ['es7'],
target: 'es2018',
module: ts.ModuleKind.ESNext
}
});
str = str.outputText;
return str;
}
});
gulp.task('cleanSrc', function () {
return del(srcFolder);
});
gulp.task('combine', gulp.series('cleanSrc', function () {
return combineTool.combine().catch(e => {
console.error('combine error', e);
});
}));
gulp.task('watch', gulp.series('combine', function () {
watch(tmplFolder + '/**/*', function (e) {
if (fs.existsSync(e.path)) {
combineTool.processFile(e.path).catch(e => {
console.log('process file error', e);
});
} else {
combineTool.removeFile(e.path);
}
});
}));
var uglify = require('gulp-terser');
gulp.task('cleanBuild', function () {
return del(buildFolder);
});
gulp.task('build', gulp.series('cleanBuild', function () {
combineTool.config({
debug: false
});
return combineTool.combine().then(() => {
return gulp.src(srcFolder + '/**/*.js')
.pipe(uglify({
module: true,
compress: {
drop_console: true,
global_defs: {
DEBUG: false
}
},
output: {
ascii_only: true
}
}))
.pipe(gulp.dest(buildFolder));
});
}));
gulp.task('embed', (cb) => {
let c = fs.readFileSync('./build/boot.js') + '';
let index = fs.readFileSync('./index.html') + '';
c = c.replace(/\$/g, '$&$&');
index = index.replace(/<script[^>]*?>[\s\S]*?<\/script>/, '<script>' + c + '</script>');
fs.writeFileSync('./index.html', index);
let c1 = fs.readFileSync('./build/book.js') + '';
let book = fs.readFileSync('./book.html') + '';
c1 = c1.replace(/\$/g, '$&$&');
book = book.replace(/<script[^>]*?>[\s\S]*?<\/script>/, '<script>' + c1 + '</script>');
fs.writeFileSync('./book.html', book);
cb();
});