forked from cryogenian/slamdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
228 lines (199 loc) · 6.6 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
"use strict";
var gulp = require("gulp"),
header = require("gulp-header"),
contentFilter = require("gulp-content-filter"),
purescript = require("gulp-purescript"),
webpack = require("webpack-stream"),
rimraf = require("rimraf"),
fs = require("fs"),
trimlines = require("gulp-trimlines"),
less = require("gulp-less"),
sequence = require("run-sequence"),
replace = require("gulp-replace"),
footer = require("gulp-footer");
var slamDataSources = [
"src/**/*.purs",
];
var vendorSources = [
"bower_components/purescript-*/src/**/*.purs",
];
var sources = slamDataSources.concat(vendorSources);
var testSources = [
"test/src/**/*.purs"
].concat(sources);
var foreigns = [
"src/**/*.js",
"bower_components/purescript-*/src/**/*.js",
"test/src/**/*.js"
];
// Webdriver thinks elements which are obscured by elements with fixed positions
// are visible. By and large fixed positions fall back gracefully to
// absolute positions so this task can be used to swap the two after less
// compilation.
// This task can be reverted by the `less` task.
gulp.task('prevent-css-transitions-and-remove-fixed-positions', function() {
var css = fs.readFileSync("test/prevent-css-transitions.css", "utf8");
gulp.src(['public/css/main.css'])
.pipe(footer(css))
.pipe(replace('fixed', 'absolute'))
.pipe(gulp.dest('public/css'));
});
gulp.task("clean", function () {
[
"output",
"tmp",
"public/js/file.js",
"public/js/filesystem.js",
"public/js/workspace.js",
"public/js/auth_redirect.js",
"public/css/main.css"
].forEach(function (path) {
rimraf.sync(path);
});
});
gulp.task("make", function() {
return purescript.psc({
src: testSources,
ffi: foreigns
});
});
gulp.task("add-headers", ["replace-headers"], function () {
// read in the license header
var licenseHeader = "{-\n" + fs.readFileSync('LICENSE.header', 'utf8') + "-}\n\n";
// filter out files that already have a license header
var contentFilterParams = { include: /^(?!\{-\nCopyright)/ };
// prepend license header to all source files
return gulp.src(slamDataSources, {base: "./"})
.pipe(contentFilter(contentFilterParams))
.pipe(header(licenseHeader))
.pipe(gulp.dest("./"));
});
/**
* To switch license file
* + Copy old license file to `headers` folder
* + Run `gulp add-headers`
* + Remove `headers` folder
**/
gulp.task("replace-headers", function() {
var licenseHeader =
"{-\n" + fs.readFileSync('LICENSE.header', 'utf8') + "-}";
return (function() {
// Extract old header files
try {
return fs.readdirSync("./headers").filter(function(name) {
return /.*\.header/.test(name);
});
} catch (e) {
// don't warn here, it's ok if `headers` folder is empty or doesn't exist
return [];
}
}()).map(function(name) {
// Read their content
var file = "./headers/" + name;
var fileContent;
try {
fileContent = "{-\n" + fs.readFileSync(file, "utf8") + "-}";
} catch (e) {
// warn here, we don't know maybe we must read this file but it has
// incorrect permissions
console.warn(e.message);
fileContent = undefined;
}
return fileContent;
}).filter(function(content) {
// Filter empty files and files with incorrect permissions
return typeof content !== "undefined";
}).reduce(function(acc, content) {
// Foldl gulp task
return function() {
return acc().pipe(replace(content, licenseHeader));
};
}, function() {
// Initial gulp task
return gulp.src(slamDataSources, {base: "./"});
// run gulp task
})().pipe(gulp.dest("./"));
});
gulp.task("trim-whitespace", function () {
var options = { leading: false };
return gulp.src(slamDataSources, {base: "./"})
.pipe(trimlines(options))
.pipe(gulp.dest("."));
});
var bundleTasks = [];
var mkBundleTask = function (name, main) {
gulp.task("prebundle-" + name, function() {
return purescript.pscBundle({
src: "output/**/*.js",
output: "tmp/" + name + ".js",
module: main,
main: main,
optimize: ["uncurry"]
});
});
gulp.task("bundle-" + name, ["prebundle-" + name], function () {
return gulp.src("tmp/" + name + ".js")
.pipe(webpack({
resolve: {
modulesDirectories: ["node_modules"]
},
output: { filename: name + ".js" },
module: {
loaders: [
{
include: /\.json$/,
loaders: ["json-loader"]
},
{
test: require.resolve("echarts"),
loader: "expose?echarts"
}
]
}
})).pipe(gulp.dest("public/js"));
});
return "bundle-" + name;
};
gulp.task("bundle", [
mkBundleTask("filesystem", "SlamData.FileSystem"),
mkBundleTask("workspace", "SlamData.Workspace"),
mkBundleTask("auth_redirect", "SlamData.AuthRedirect"),
]);
gulp.task("make-bundle", function () {
sequence("make", "bundle");
});
gulp.task("bundle-test", ["bundle"], function() {
sequence("less", "prevent-css-transitions-and-remove-fixed-positions", function() {
return purescript.pscBundle({
src: "output/**/*.js",
output: "test/index.js",
module: "Test.SlamData.Feature.Main",
main: "Test.SlamData.Feature.Main"
});
});
});
gulp.task("bundle-property-tests", function() {
return purescript.pscBundle({
src: "output/**/*.js",
output: "tmp/js/property-tests.js",
module: "Test.SlamData.Property",
main: "Test.SlamData.Property"
});
});
var mkWatch = function(name, target, files) {
gulp.task(name, [target], function() {
return gulp.watch(files, [target]);
});
};
var allSources = sources.concat(foreigns);
mkWatch("watch-file", "bundle-file", allSources);
mkWatch("watch-workspace", "bundle-workspace", allSources);
mkWatch("watch-auth_redirect", "bundle-auth_redirect", allSources);
gulp.task("less", function() {
return gulp.src(["less/main.less"])
.pipe(less({ paths: ["less/**/*.less"] }))
.pipe(gulp.dest("public/css"));
});
mkWatch("watch-less", "less", ["less/**/*.less"]);
gulp.task("full", ["clean", "add-headers", "trim-whitespace", "less", "make-bundle"]);
gulp.task("default", ["less", "make-bundle"]);