-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
122 lines (104 loc) · 3.31 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const del = require("del");
const gulp = require("gulp");
const eslint = require("gulp-eslint");
const minify = require("gulp-minify");
const open = require("gulp-open");
const prettier = require("gulp-prettier");
const os = require("os");
const zip = require("gulp-zip");
const included_modules = [
"node_modules/monaco-editor/min/**/*",
"node_modules/monaco-editor/LICENSE",
"node_modules/requirejs/require.js",
];
const test_modules = [
"node_modules/jasmine-core/lib/jasmine-core/boot.js",
"node_modules/jasmine-core/lib/jasmine-core/jasmine.js",
"node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js",
"node_modules/jasmine-core/lib/jasmine-core/jasmine.css",
"node_modules/sinon-chrome/bundle/sinon-chrome.min.js",
];
gulp.task("clean-test", function () {
return del(["tests/**/*", "!tests/spec/**", "!tests/SpecRunner.html"]);
});
gulp.task("clean-build", function () {
return del(["build/**/*"]);
});
gulp.task("clean", gulp.series("clean-test", "clean-build"));
gulp.task("minify-sources", function () {
return gulp
.src("src/**/*")
.pipe(
minify({
noSource: true,
ext: {
min: ".js",
},
})
)
.pipe(gulp.dest("build"));
});
gulp.task("include-minified-modules", function () {
return gulp
.src(included_modules, {
base: "node_modules",
})
.pipe(
minify({
noSource: true,
ext: {
min: ".js",
},
exclude: ["monaco-editor"], // Already minified.
preserveComments: "some", // Preserve licensing information in require.js.
})
)
.pipe(gulp.dest("build/lib"));
});
gulp.task("produce-zip", function () {
return gulp.src("build/**/*").pipe(zip("codext.zip")).pipe(gulp.dest("build"));
});
gulp.task("copy-test-modules", function () {
return gulp
.src(test_modules, {
base: "node_modules",
})
.pipe(gulp.dest("tests"));
});
gulp.task("run-tests-chrome", function () {
const browser = os.platform() === "linux" ? "google-chrome" : os.platform() === "darwin" ? "google chrome" : "chrome";
return gulp.src("./tests/SpecRunner.html").pipe(
open({
app: browser,
})
);
});
gulp.task("run-tests-firefox", function () {
return gulp.src("./tests/SpecRunner.html").pipe(
open({
app: "firefox",
})
);
});
gulp.task("test", gulp.series("clean-test", "copy-test-modules", "run-tests-chrome"));
gulp.task("test-firefox", gulp.series("clean", "copy-test-modules", "run-tests-firefox"));
gulp.task("build", gulp.series("clean-build", "minify-sources", "include-minified-modules", "produce-zip"));
gulp.task("lint-src", function () {
return gulp.src("src/**/*.js").pipe(eslint(".eslintrc.json")).pipe(eslint.format()).pipe(eslint.failAfterError());
});
gulp.task("lint-test", function () {
return gulp
.src(["tests/**.js", "!tests/sinon-chrome/**", "!tests/jasmine-core/**"])
.pipe(eslint("tests/.eslintrc.json"))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task("lint", gulp.series("lint-src", "lint-test"));
gulp.task("prettify", function () {
return gulp
.src(["src/**/*.js", "tests/**/*.js", "gulpfile.js"])
.pipe(prettier({ printWidth: 120 }))
.pipe(gulp.dest((file) => file.base));
});
// The default task (called when you run `gulp` from cli)
gulp.task("default", gulp.series("build"));