-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·67 lines (52 loc) · 1.58 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
const gulp = require('gulp');
const cp = require('child_process');
const exec = cp.exec;
const open = require('open');
const Q = require('q');
const runSequence = require('gulp-sequence');
gulp.task('dev', ['watch-scss', 'open', 'next-dev'], function() {
console.log('Successfully start dev task');
});
function genDefered(cmd, callback) {
return function() {
const defered = Q.defer();
const task = exec(cmd, function(err, stdout, stderr){
if (err) {
console.log(err);
defered.reject(stderr);
throw err;
}
console.info('Successfully start '+ cmd +' task');
defered.resolve(callback);
});
task.stdout.pipe(process.stdout);
return defered.promise;
}
}
const noop = function() { return true;};
const sassCMD = 'sass --watch scss/:css/ -t compressed --sourcemap=none &';
const nextCMD = 'npm run dev';
const sassTaskCallback = genDefered(sassCMD, noop);
const nextTaskCallback = genDefered(nextCMD, noop);
gulp.task('watch-scss', sassTaskCallback);
gulp.task('next-dev', nextTaskCallback);
gulp.task('default', ['dev']);
gulp.task('next-build', genDefered('npm run build', noop));
gulp.task('open', function() {
const defered = Q.defer();
setTimeout(function() {
open('http://localhost:3000');
console.log('Broswer has been succefully opened');
defered.resolve();
}, 25000);
return defered.promise;
});
gulp.task('next-start', genDefered('npm run start', noop));
gulp.task('build', function() {
const d = Q.defer();
runSequence('next-build', function() {
console.log('Project has been successfully built');
d.resolve();
});
return d.promise;
});