forked from DevExpress/testcafe-browser-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
172 lines (145 loc) · 4.98 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
var path = require('path');
var childProcess = require('child_process');
var gulp = require('gulp');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var flatten = require('gulp-flatten');
var mocha = require('gulp-mocha');
var msbuild = require('gulp-msbuild');
var concat = require('gulp-concat');
var jsdoc = require('gulp-jsdoc-to-markdown');
var remoteSrc = require('gulp-remote-src');
var changed = require('gulp-changed');
var del = require('del');
var through = require('through2');
var Promise = require('pinkie');
var pify = require('pify');
var exec = pify(childProcess.exec, Promise);
// Windows bin
gulp.task('clean-win-bin', function (cb) {
del('bin/win', cb);
});
gulp.task('build-win-executables', ['clean-win-bin'], function () {
return gulp
.src('src/natives/**/*.csproj')
.pipe(msbuild({
targets: ['Clean', 'Build']
}));
});
gulp.task('copy-win-executables', ['build-win-executables'], function () {
return gulp
.src([
'src/natives/**/win/bin/Release/*.exe',
'src/natives/**/win/bin/Release/*.config'
])
.pipe(flatten())
.pipe(gulp.dest('bin/win'));
});
// Mac bin
gulp.task('clean-mac-bin', function (callback) {
del('bin/mac', callback);
});
gulp.task('build-mac-executables', ['clean-mac-bin'], function () {
function make (options) {
return through.obj(function (file, enc, callback) {
if (file.isNull()) {
callback(null, file);
return;
}
var dirPath = path.dirname(file.path).replace(/ /g, '\\ ');
exec('make -C ' + dirPath, { env: options })
.then(function () {
callback(null, file);
})
.catch(callback);
});
}
return gulp
.src('src/natives/**/mac/Makefile')
.pipe(make({
DEST: path.join(__dirname, 'bin/mac')
}));
});
gulp.task('copy-mac-scripts', ['clean-mac-bin'], function () {
return gulp
.src('src/natives/**/mac/*.scpt')
.pipe(flatten())
.pipe(gulp.dest('bin/mac'));
});
// Test
gulp.task('run-playground-win', ['build-win'], function () {
require('./test/playground/index');
});
gulp.task('run-playground-mac', ['build-mac'], function () {
require('./test/playground/index');
});
gulp.task('test', ['build-lib'], function () {
return gulp
.src('test/tests/*-test.js')
.pipe(mocha({
ui: 'bdd',
reporter: 'spec',
timeout: typeof v8debug === 'undefined' ? 2000 : Infinity // NOTE: disable timeouts in debug
}));
});
// General tasks
gulp.task('update-device-database', function () {
function transform () {
return through.obj(function (file, enc, callback) {
var deviceDatabase = {};
JSON
.parse(file.contents.toString())
.forEach(function (device) {
var deviceId = device['Device Name'].toLowerCase().split(' ').join('');
var portraitWidth = Number(device['Portrait Width']);
var landscapeWidth = Number(device['Landscape Width']);
if (!isNaN(portraitWidth) && !isNaN(landscapeWidth)) {
deviceDatabase[deviceId] = {
portraitWidth: portraitWidth,
landscapeWidth: landscapeWidth
};
}
});
file.contents = new Buffer(JSON.stringify(deviceDatabase));
callback(null, file);
});
}
var destDir = 'data/';
return remoteSrc('devices.json', { base: 'http://viewportsizes.com/' })
.pipe(transform())
.pipe(changed(destDir, { hasChanged: changed.compareSha1Digest }))
.pipe(gulp.dest(destDir));
});
gulp.task('lint', function () {
return gulp
.src([
'src/**/*.js',
'test/**/*.js',
'!test/playground/public/**/*',
'Gulpfile.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('clean-lib', function (cb) {
del('lib', cb);
});
gulp.task('transpile-lib', ['lint', 'clean-lib'], function () {
return gulp
.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'));
});
gulp.task('build-lib', ['transpile-lib', 'docs']);
gulp.task('build-win', ['build-lib', 'copy-win-executables']);
gulp.task('build-mac', ['build-lib', 'build-mac-executables', 'copy-mac-scripts']);
gulp.task('docs', ['transpile-lib'], function () {
var destDir = './';
return gulp
.src('lib/**/*.js')
.pipe(concat('API.md'))
.pipe(jsdoc({ plugin: 'dmd-plugin-async' }))
.pipe(changed(destDir, { hasChanged: changed.compareSha1Digest }))
.pipe(gulp.dest(destDir));
});