-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
198 lines (171 loc) · 5.71 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
var gulp = require('gulp');
// CSS Build
var less = require('gulp-less');
var cssmin = require('gulp-cssmin');
// JS Build
var watchify = require('watchify');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
// Utils
var gutil = require('gulp-util');
var del = require('del');
var runSequence = require('run-sequence');
var assign = require('lodash.assign');
// Output
var rename = require('gulp-rename');
var header = require('gulp-header');
// Standalone Templates
var handlebars = require('gulp-handlebars');
var wrap = require('gulp-wrap');
var declare = require('gulp-declare');
var concat = require('gulp-concat');
// Versioning
var bump = require('gulp-bump');
// Configuration
var pkg = require('./package.json');
var banner = ['/*!',
' * PJAX Table v<%= pkg.version %> (<%= pkg.homepage %>)',
' * Copyright ' + (new Date()).getFullYear(),
' * <%= pkg.author %>',
' */\n'
].join('\n');
var output_names = {
standalone_vendor_js: 'standalone_vendor.js',
less: 'pjax_table.css',
lessmin: 'pjax_table.min.css',
js: 'pjax_table.js'
};
var paths = {
json: [
'./bower.json',
'./package.json'
],
js: [
'./src/js/pjax_table.js'
],
standalone_vendor_css: [
'./bower_components/fontawesome/css/font-awesome.css'
],
standalone_vendor_fonts: [
'./bower_components/fontawesome/fonts/*'
],
standalone_vendor_js: [
'./bower_components/jquery/dist/jquery.js',
'./bower_components/jquery-pjax/jquery.pjax.js',
'./bower_components/spin.js/spin.js',
'./bower_components/spin.js/jquery.spin.js',
'./bower_components/chance/chance.js',
'./bower_components/handlebars/handlebars.runtime.js'
],
all_less: ['./src/less/**/*.less'],
less: ['./src/less/table.less'],
templates: ['./src/templates/*.hbs'],
};
// add custom browserify options here
var customOpts = {
entries: paths.js
};
var dev_opts = assign({}, watchify.args, customOpts);
var dev_b = watchify(browserify(dev_opts));
var dist_opts = assign({}, watchify.args, customOpts);
var dist_b = watchify(browserify(dist_opts));
var editableCellOpts = {
entries: ['./src/js/cell_plugins/editable_cell.js']
}
var dist_editable_cell_opts = assign({}, watchify.args, editableCellOpts)
var dist_editable_cell = watchify(browserify(dist_editable_cell_opts))
gulp.task('clean', function(cb) {
del(['dist/**/*', 'standalone/js/vendor/*', 'standalone/js/templates.js'], cb);
});
gulp.task('bump-patch', function(){ return gulp.src(paths.json).pipe(bump()).pipe(gulp.dest('./')); });
gulp.task('bump-minor', function(){ return gulp.src(paths.json).pipe(bump({ type: 'minor' })).pipe(gulp.dest('./')); });
gulp.task('bump-major', function(){ return gulp.src(paths.json).pipe(bump({ type: 'major' })).pipe(gulp.dest('./')); });
gulp.task('templates', function(){
gulp.src(paths.templates)
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'UI.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('./standalone/js'));
});
gulp.task('standalone_vendor_js', function() {
return gulp.src(paths.standalone_vendor_js)
.pipe(concat(output_names.standalone_vendor_js))
.pipe(gulp.dest('./standalone/js/vendor'));
});
gulp.task('standalone_vendor_css', function() {
return gulp.src(paths.standalone_vendor_css)
.pipe(gulp.dest('./standalone/css'));
});
gulp.task('standalone_vendor_fonts', function() {
return gulp.src(paths.standalone_vendor_fonts)
.pipe(gulp.dest('./standalone/fonts'));
});
gulp.task('js', function() {
return dev_b.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('pjax_table.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist/js'));
});
gulp.task('js_min', function() {
return dist_b.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('pjax_table.js'))
.pipe(buffer()) // for uglify
.pipe(uglify({ preserveComments: 'some' }))
.pipe(header(banner, { pkg: pkg }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/js'));
});
gulp.task('editable_cell_js', function() {
return dist_editable_cell.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('cell_plugins/editable_cell.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist/js'));
});
gulp.task('editable_cell_js_min', function() {
return dist_editable_cell.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('cell_plugins/editable_cell.js'))
.pipe(buffer()) // for uglify
.pipe(uglify({ preserveComments: 'some' }))
.pipe(header(banner, { pkg: pkg }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/js'));
});
gulp.task('less', function() {
return gulp.src(paths.less)
.pipe(less({ strictMath: true }))
.pipe(header(banner, { pkg: pkg }))
.pipe(rename(output_names.less))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('lessmin', function() {
return gulp.src(paths.less)
.pipe(less({ strictMath: true }))
.pipe(cssmin({ keepSpecialComments: 1 }))
.pipe(header(banner, { pkg: pkg }))
.pipe(rename(output_names.lessmin))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('less_copy', function() {
return gulp.src(paths.all_less)
.pipe(gulp.dest('./dist/less'));
});
gulp.task('default', function(callback){
runSequence('clean', 'js', 'js_min', 'editable_cell_js', 'editable_cell_js_min', 'less', 'lessmin', [
'less_copy',
'templates',
'standalone_vendor_js',
'standalone_vendor_css',
'standalone_vendor_fonts'
], callback);
});