-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (113 loc) · 3.24 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
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var rimraf = require('rimraf');
var log = require('fancy-log');
var beep = require('beeper');
//var react = require('gulp-react');
var $ = require('gulp-load-plugins')();
var paths = {
root: './src',
ampRoot: '../../../../',
rootStuff: './src/*.{png,jpg,ico,html,txt,xml}',
dist: './dist/',
scripts: {
entry: './src/main.js',
compiled: './src/compiled-js/',
sources: [
'./src/models/*.js',
'./src/views/*.js',
'./src/tree/*.js',
'./src/lib/*.js',
'./gulpfile.js'
]
},
stylesheets: {
entry: './src/less/amp-filters.less',
compiled: './src/compiled-css/',
sources: ['./src/less/**/*.less'],
testStyles: './bower_components/mocha/mocha.css'
},
img: {
src: [
'./src/img/**'
],
dest: './dist/img/'
}
};
function _browserifier(entry, destFolder, destName, options) {
options = options || {};
options.entries = entry;
var bundler = browserify(options);
bundler.transform('brfs');
/*bundler.external([
'backbone',
// don't need bootstrap here, as it just registers jQ plugins
'jquery',
'underscore'
]);*/
var bundle = function() {
log('bundle: start');
return bundler.bundle()
.on('end', function() { log('bundle: finished'); })
.on('error', function(e) { log('bundle: error: ', e); })
.pipe(source(destName))
.pipe(gulp.dest(destFolder));
};
return {
bundler: bundler,
bundle: bundle
};
}
gulp.task('lint', function() {
gulp.src(paths.scripts.sources)
.pipe($.plumber())
.pipe($.jscs())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('browserify', function() {
var stuff = _browserifier(paths.scripts.entry,
paths.scripts.compiled, 'amp-filter.js',{debug: true, standalone: 'ampFilter'});
return stuff.bundle();
});
gulp.task('clean', function(cb) {
return rimraf(paths.dist, cb);
});
gulp.task('build-js', gulp.series('browserify', function() {
return gulp.src(paths.scripts.compiled + 'amp-filter.js')
//.pipe(react())
.pipe($.streamify($.uglify))
.pipe(gulp.dest(paths.dist));
}));
gulp.task('less', function() {
return gulp.src(paths.stylesheets.entry)
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.less())
.on('error', log)
.on('error', beep)
.pipe($.sourcemaps.write())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.concat('amp-filter.css'))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(paths.stylesheets.compiled));
});
gulp.task('build-css', gulp.series('less', function() {
return gulp.src(paths.stylesheets.compiled + 'amp-filter.css')
.pipe($.csso())
.pipe(gulp.dest(paths.dist));
}));
gulp.task('images', function() {
return gulp.src(paths.img.src)
.pipe(gulp.dest(paths.img.dest));
});
gulp.task('build-static', gulp.series('images', function() {
return gulp.src('./src/{fonts,img}/**/*')
.pipe(gulp.dest(paths.dist));
}));
gulp.task('build-rootstuff', function() {
return gulp.src(paths.rootStuff)
.pipe(gulp.dest(paths.dist));
});
gulp.task('build', gulp.series('clean', 'build-js', gulp.parallel('build-css', 'build-static', 'build-rootstuff')));