-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
93 lines (78 loc) · 2.88 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
const browserify = require("browserify");
const gulp = require("gulp");
const log = require("gulplog");
const rename = require("gulp-rename");
const replace = require("gulp-replace");
const source = require("vinyl-source-stream");
const camelCase = require("lodash.camelcase");
const generateSections = require("./templates/Sections");
const generateFeatures = require("./templates/Features");
const generateConfigurables = require("./templates/Configurables");
const standalone = "HFX";
const main = "./src/HFX.js";
const core = "./src/core/*.js";
const sections = "./src/sections/*.js";
const features = "./src/features/**/*.js";
const browserifyOptions = {
entries: main,
standalone: standalone
};
gulp.task("build", asyncComplete => {
browserify(browserifyOptions)
.on("error", log.error)
.bundle()
.pipe(source(main))
.pipe(rename(`${standalone}.js`))
.pipe(gulp.dest("./extension/release/js"));
generateSections();
generateFeatures();
generateConfigurables();
asyncComplete();
});
const copyNodeAssets = (name, assets, substitute = null) => {
assets = assets.map(asset => `./node_modules/${name}/${asset}`);
let stream = gulp.src(assets);
if (substitute !== null) {
stream = stream.pipe(replace(substitute.pattern, substitute.replacement));
}
stream.pipe(gulp.dest(`./extension/assets/lib/${name}`));
};
const babelifyNodeAsset = (name, entry) => {
const main = `./node_modules/${name}/${entry}`;
const standalone = camelCase(name).replace(/^\w/g, (m) => m.toUpperCase());
const browserifyOptions = {
entries: main,
standalone: standalone
};
browserify(browserifyOptions)
.on("error", log.error)
.transform("babelify", {
sourceMaps: false,
presets: [
"@babel/preset-env"
],
plugins: [
"@babel/plugin-transform-runtime"
]
})
.bundle()
.pipe(source(entry))
.pipe(gulp.dest(`./extension/assets/lib/${name}`));
};
gulp.task("libs", asyncComplete => {
copyNodeAssets("jquery", ["dist/jquery.min.js"]);
copyNodeAssets("bootstrap", ["dist/css/bootstrap.min.css", "dist/js/bootstrap.min.js"]);
copyNodeAssets("font-awesome", ["css/font-awesome.min.css", "fonts/*"], {pattern: /url\((?:'|")\.\.\/fonts\/([^'"]+)(?:'|")\)/g, replacement: "url(\"./$1\")"});
copyNodeAssets("moment", ["min/moment.min.js", "min/moment.min.js.map"]);
copyNodeAssets("chart.js", ["dist/Chart.bundle.min.js"]);
copyNodeAssets("@yaireo/tagify", ["dist/jQuery.tagify.min.js", "dist/tagify.css"]);
copyNodeAssets("intro.js", ["minified/intro.min.js", "minified/introjs.min.css"]);
copyNodeAssets("@webcomponents/custom-elements", ["custom-elements.min.js"]);
babelifyNodeAsset("emoji-picker-element", "index.js");
asyncComplete();
});
gulp.task("watch", asyncComplete => {
gulp.watch([main, core, sections, features], gulp.series("build"));
asyncComplete();
});
gulp.task("default", gulp.series("build"));