-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.babel.js
137 lines (123 loc) · 4.37 KB
/
gulpfile.babel.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import gulp from "gulp";
import pkg from "./package.json";
import cssNano from "gulp-cssnano";
import uglify from "gulp-uglify";
import replace from "gulp-replace";
import rimraf from "gulp-rimraf";
import scss from "gulp-sass";
import rename from "gulp-rename";
import preprocess from "gulp-preprocess";
import browserify from "browserify";
import "babelify";
import sourceStream from "vinyl-source-stream";
import buffer from "vinyl-buffer";
import fs from "fs";
import preprocessify from "preprocessify";
//import sourcemaps from "gulp-sourcemaps";
import { getAutomaton } from "./src/client/js/parser/_build";
let INSTALLER_CLASS_NAME = `${ pkg["packageName"] }.Installer`;
let dir = __dirname,
dest = `${dir}/build`,
source = `${dir}/src`,
context = {
includeBase: dest,
context: {
package: pkg,
compileAfter: "", // is set during "pre-cls" task.
themes: "", // is set after css move task
autocompleteAutomaton: [],
ruleMappings: {}
}
},
themes = []; // reassigned
const sass = require('gulp-sass')(require('sass'));
function themesReady () { // triggered when build is done
themes = fs.readdirSync(`${ dest }/client/css/themes`);
context.context.themes = themes.map(function (n) {
return ', "' + n.replace(/\..*$/, "") + '": "css/themes/' + n + '"';
}).join("");
}
gulp.task("prepare", function (cb) {
let aut = [];
console.log(`Compiling autocomplete and highlight rules...`);
try {
aut = getAutomaton();
context.context.autocompleteAutomaton = JSON.stringify(aut.automaton);
context.context.ruleMappings = JSON.stringify(aut.ruleMappings);
} catch (e) {
console.error.apply(console, e);
cb(e);
}
console.log(`Automaton ready and has ${ aut.automaton.length } states with ${
aut.automaton.reduce((a, b) =>
(typeof a === "number" ? a : a.length) + (typeof b === "number" ? b : b.length))
} rules.`);
cb();
});
gulp.task("clean", gulp.series("prepare", function () {
return gulp.src(dest, { read: false, allowEmpty: true })
.pipe(rimraf());
}));
gulp.task("html", gulp.series(function () {
return gulp.src(`${ source }/client/index.html`)
.pipe(preprocess(context))
.pipe(gulp.dest(`${ dest }/client`));
}));
gulp.task("scss", gulp.series(() => {
return gulp.src([`${source}/client/scss/index.scss`])
.pipe(preprocess(context))
.pipe(sass())
.pipe(cssNano({
zindex: false
}))
.pipe(gulp.dest(`${dest}/client/css`));
}));
gulp.task("copy-css-themes", gulp.series(function () {
return gulp.src(`${ source }/client/scss/themes/*.*`)
.pipe(preprocess(context))
.pipe(sass())
.pipe(cssNano())
.pipe(gulp.dest(`${ dest }/client/css/themes/`));
}));
// Need css themes directory copied to collect themes names.
gulp.task("css", gulp.series("scss", "copy-css-themes", function (cb) {
themesReady();
cb();
}));
gulp.task("js", gulp.series("css", function () {
let bundler = browserify({
entries: `${source}/client/js/index.js`,
debug: true
}).transform(preprocessify, {
includeExtensions: ['.js'],
context: context.context
});
bundler.transform("babelify", { presets: ["es2015"] });
return bundler.bundle()
.on("error", function (err) { console.error("An error occurred during bundling:", err); })
.pipe(sourceStream("index.js"))
.pipe(buffer())
//.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify({
output: {
ascii_only: true,
width: 25000,
max_line_len: 15000,
comments: "some"
},
}))
.pipe(replace(/\x0b|\x1b/g, e => `\\x${ e === "\x0b" ? 0 : 1 }b`))
.pipe(replace(/[\x00-\x08]/g, e => `\\x0${ e.charCodeAt(0) }`))
//.pipe(sourcemaps.write())
.pipe(gulp.dest(`${ dest }/client/js`));
}));
gulp.task("readme", gulp.series(function () {
return gulp.src(`${ dir }/readme.md`)
.pipe(gulp.dest(`${ dest }`));
}));
gulp.task("cls", gulp.series("js", "js", "html", "css", "readme", () => {
return gulp.src([`${ source }/cls/**/*.cls`])
.pipe(preprocess(context))
.pipe(gulp.dest(`${dest}/cls`));
}));
gulp.task("default", gulp.series("clean", "cls"));