-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (102 loc) · 2.79 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
const gulp = require('gulp');
const rename = require('gulp-rename');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const rm = require('gulp-rimraf');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const htmlreplace = require('gulp-html-replace');
const htmlmin = require('gulp-htmlmin');
const cleanCSS = require('gulp-clean-css');
const minimist = require('minimist');
const sftp = require('gulp-sftp');
const browserSync = require('browser-sync').create();
const args = minimist(process.argv.slice(2));
const paths = {
scripts: ['./src/**/*.js']
};
function compile() {
return gulp.src(paths.scripts, { base: './src' })
//.pipe(sourcemaps.init())
.pipe(babel())
.on('error', swallowError)
//.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build/intermediate'));
}
function lint() {
return gulp.src(paths.scripts)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function browserifyCode() {
var stream = browserify({
entries: './build/intermediate/Browser.js',
})
.bundle();
return stream.pipe(source('doodle.js'))
.pipe(gulp.dest('./build'));
}
function minifyJs() {
return gulp.src('./build/doodle.js')
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./build'));
}
function minifyCss() {
return gulp.src('./src/doodle.css')
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./build'));
};
function swallowError(error) {
console.log(error.toString());
this.emit('end');
}
gulp.task('compile', compile);
gulp.task('browserify', ['compile'], browserifyCode);
gulp.task('minify-js', ['browserify'], minifyJs);
gulp.task('minify-css', ['browserify'], minifyCss);
gulp.task('build', ['compile', 'browserify']);
gulp.task('dist', ['minify-js', 'minify-css'], function() {
return gulp.src('./src/index.html')
.pipe(htmlreplace({
cssInline: {
src: gulp.src('./build/doodle.min.css'),
tpl: '<style>%s</style>'
},
jsInline: {
src: gulp.src('./build/doodle.min.js'),
tpl: '<script type="text/javascript">%s</script>'
}
}))
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('./dist/'));
});
gulp.task('upload', function() {
return gulp.src('dist/index.html')
.pipe(sftp({
host: args.host,
user: args.user,
pass: args.pass,
remotePath: args.remote
}));
});
gulp.task('js-watch', ['build'], function (done) {
browserSync.reload();
done();
});
gulp.task('serve', ['build'], function () {
browserSync.init({
server: {
baseDir: './src',
routes: {
'/build': './build'
}
}
});
gulp.watch(paths.scripts, ['js-watch']);
});
gulp.task('watch', ['build'], () => { gulp.watch(paths.scripts, ['build']); });
gulp.task('vet', lint);
gulp.task('default', ['build']);