-
Notifications
You must be signed in to change notification settings - Fork 93
/
gulpfile.js
194 lines (170 loc) · 4.86 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
var gulp = require('gulp'),
artoo = require('gulp-artoo'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
mocha = require('gulp-mocha'),
phantomMocha = require('gulp-mocha-phantomjs'),
replace = require('gulp-replace'),
rename = require('gulp-rename'),
header = require('gulp-header'),
webserver = require('gulp-webserver'),
pkg = require('./package.json');
// Utilities
var jsFiles = [
'src/artoo.js',
'src/third_party/emmett.js',
'src/third_party/jquery.simulate.js',
'src/artoo.beep.js',
'src/artoo.settings.js',
'src/artoo.helpers.js',
'src/artoo.parsers.js',
'src/artoo.writers.js',
'src/artoo.browser.js',
'src/artoo.log.js',
'src/artoo.dependencies.js',
'src/artoo.countermeasures.js',
'src/methods/artoo.methods.ajaxSniffer.js',
'src/methods/artoo.methods.ajaxSpider.js',
'src/methods/artoo.methods.autoExpand.js',
'src/methods/artoo.methods.autoScroll.js',
'src/methods/artoo.methods.cookies.js',
'src/methods/artoo.methods.save.js',
'src/methods/artoo.methods.scrape.js',
'src/methods/artoo.methods.store.js',
'src/methods/artoo.methods.ui.js',
'src/artoo.init.js'
];
var nodeFiles = [
'src/artoo.js',
'src/node/artoo.node.shim.js',
'src/third_party/emmett.js',
'src/node/artoo.node.js',
'src/artoo.helpers.js',
'src/artoo.parsers.js',
'src/artoo.writers.js',
'src/node/artoo.node.helpers.js',
'src/methods/artoo.methods.scrape.js',
'src/node/artoo.node.require.js'
];
var chromeFiles = [
'src/chrome/artoo.chrome.js'
];
var phantomFiles = [
'src/phantom/artoo.phantom.js'
];
function lintFilter(i) {
return !~i.indexOf('third_party');
}
// Testing
gulp.task('browser-test', function() {
return gulp.src('./test/unit.html')
.pipe(replace(
/<!-- START ARTOO IMPORTS -->[\s\S]*<!-- END ARTOO IMPORTS -->/g,
['<!-- START ARTOO IMPORTS -->'].concat(
jsFiles.slice(0, -1).map(function(path) {
return ' <script src="../' + path + '"></script>';
})
).concat(' <!-- END ARTOO IMPORTS -->').join('\n')
))
.pipe(gulp.dest('./test'))
.pipe(phantomMocha({reporter: 'spec'}));
});
// Linting
gulp.task('lint', function() {
var avoidFlags = {
'-W055': true,
'-W040': true,
'-W064': true,
'-W061': true,
'-W103': true,
'-W002': true
};
return gulp.src(jsFiles.filter(lintFilter))
.pipe(jshint(avoidFlags))
.pipe(jshint.reporter('default'));
});
// Building
function build_one(name, files) {
return gulp.src(jsFiles.concat(name !== 'concat' ? files : []))
.pipe(concat('artoo.' + name + '.js'))
.pipe(gulp.dest('./build'));
}
function browser() {
return build_one('concat')
.pipe(uglify())
.pipe(header('/* artoo.js - <%= description %> - Version: <%= version %> - Author: <%= author.name %> - medialab SciencesPo */\n', pkg))
.pipe(rename('artoo.min.js'))
.pipe(gulp.dest('./build'));
};
function chrome() {
return build_one('chrome', chromeFiles);
};
function phantom() {
return build_one('phantom', phantomFiles);
};
function nodefiles() {
return gulp.src(nodeFiles)
.pipe(concat('artoo.node.js'))
.pipe(gulp.dest('./build'));
};
var build = gulp.series(browser, chrome, phantom, nodefiles);
// Bookmarklets
gulp.task('bookmarklet.dev', function() {
var opts = {
random: true,
loadingText: null,
url: '//localhost:8000/build/artoo.concat.js',
settings: {
env: 'dev',
reload: true
}
};
return artoo.blank('bookmarklet.dev.min.js')
.pipe(artoo(opts))
.pipe(gulp.dest('./build/bookmarklets'));
});
gulp.task('bookmarklet.prod', function() {
return artoo.blank('bookmarklet.prod.min.js')
.pipe(artoo())
.pipe(gulp.dest('./build/bookmarklets'));
});
gulp.task('bookmarklet.edge', function() {
return artoo.blank('bookmarklet.edge.min.js')
.pipe(artoo({
version: 'edge',
loadingText: 'artoo.js edge version is loading...'
}))
.pipe(gulp.dest('./build/bookmarklets'));
});
// Watching
gulp.task('watch', gulp.series(build, function() {
gulp.watch(jsFiles, ['build']);
}));
// Serving
gulp.task('serve', function() {
return gulp.src('./')
.pipe(webserver({
directoryListing: true
}));
});
gulp.task('serve.https', function() {
return gulp.src('./')
.pipe(webserver({
directoryListing: true,
https: true
}));
});
gulp.task('node-test', gulp.series(build, function() {
return gulp.src('./test/endpoint.js')
.pipe(mocha({reporter: 'spec'}));
}));
exports.build = build
// Macro-tasks
exports.bookmarklets = gulp.series('bookmarklet.dev', 'bookmarklet.prod', 'bookmarklet.edge');
var test = gulp.series('browser-test', 'node-test');
exports.test = test
exports.work = gulp.series('watch', 'serve');
exports.https = gulp.series('watch', 'serve.https');
exports.default = gulp.series('lint', test, build);
exports.chrome = chrome