-
Notifications
You must be signed in to change notification settings - Fork 29
/
gulpfile.js
executable file
·124 lines (111 loc) · 3.48 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
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var stringify = require('stringify');
var del = require('del');
var inline = require('gulp-inline');
var htmlmin = require('gulp-htmlmin');
var sass = require('gulp-sass');
var sourceMaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var sassify = require('sassify');
var autoprefixify = require('./src/scripts/vendor/autoprefixify');
var insert = require('gulp-insert');
var clayPackage = require('./package.json');
var sassIncludePaths = [].concat(
require('bourbon').includePaths,
'src/styles'
);
var sassifyOptions = {
base64Encode: false,
sourceMap: false,
sourceMapEmbed: false,
sourceMapContents: false,
outputStyle: 'compact',
includePaths: sassIncludePaths
};
var autoprefixerOptions = {
browsers: ['Android 4', 'iOS 8'],
cascade: false
};
var stringifyOptions = ['.html', '.tpl'];
var versionMessage = '/* Clay - https://github.com/pebble/clay - Version: ' +
clayPackage.version +
' - Build Date: ' + new Date().toISOString() + ' */\n';
gulp.task('clean-js', function() {
return del(['tmp/config-page.js']);
});
gulp.task('js', ['clean-js'], function() {
return browserify('src/scripts/config-page.js', { debug: true })
.transform('deamdify')
.bundle()
.pipe(source('config-page.js'))
.pipe(gulp.dest('./tmp/'));
});
gulp.task('clean-sass', function() {
return del(['tmp/config-page.scss']);
});
gulp.task('sass', ['clean-sass'], function() {
gulp.src('./src/styles/config-page.scss')
.pipe(sourceMaps.init())
.pipe(sass({
includePaths: sassIncludePaths
}).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(sourceMaps.write('./'))
.pipe(gulp.dest('tmp'));
});
gulp.task('inlineHtml', ['js', 'sass'], function() {
return gulp.src('src/config-page.html')
.pipe(inline())
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
removeTagWhitespace: true,
removeRedundantAttributes: true,
caseSensitive: true,
minifyJS: true,
minifyCSS: true
}))
.pipe(gulp.dest('tmp/'));
});
gulp.task('clay', ['inlineHtml'], function() {
return browserify('index.js', {
debug: false,
standalone: clayPackage.name
})
.transform('deamdify')
.transform(stringify(stringifyOptions))
.transform(sassify, sassifyOptions)
.transform(autoprefixify, autoprefixerOptions)
.require(require.resolve('./index'), {expose: clayPackage.name})
.exclude('message_keys')
.bundle()
.pipe(source('index.js'))
.pipe(buffer())
.pipe(uglify({
preserveComments: 'license'
}))
.pipe(insert.prepend(versionMessage))
.pipe(gulp.dest('./src/js'));
});
gulp.task('dev-js', ['js', 'sass'], function() {
return browserify('dev/dev.js', { debug: true })
.transform(stringify(stringifyOptions))
.transform('deamdify')
.transform(sassify, sassifyOptions)
.transform(autoprefixify, autoprefixerOptions)
.ignore('message_keys')
.bundle()
.pipe(source('dev.js'))
.pipe(gulp.dest('./tmp/'));
});
gulp.task('default', ['clay']);
gulp.task('dev', ['dev-js'], function() {
gulp.watch('src/styles/**/*.scss', ['sass']);
gulp.watch(['src/scripts/**/*.js', 'src/templates/**/*.tpl'], ['js']);
gulp.watch(['src/**', 'dev/**/*.js'], ['dev-js']);
});