This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
271 lines (204 loc) · 9.14 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* globals require */
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var del = require('del');
var insert = require('gulp-insert');
var jscs = require('gulp-jscs');
var jsdoc = require('gulp-jsdoc');
var jshint = require('gulp-jshint');
var jshintStylishReporter = require('jshint-stylish');
var merge = require('merge-stream');
var path = require('path');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var runSequence = require('run-sequence');
var uglify = require('gulp-uglify');
var util = require('gulp-util');
var wrapUMD = require('gulp-wrap-umd');
// ------------------------- //
// Helpers //
// ------------------------- //
String.EMPTY = '';
String.SPACE = ' ';
// ------------------------- //
// Configuration //
// ------------------------- //
var config = {
pkg: require('./package.json'),
build: { dir: 'build/' },
dist: { dir: 'dist/' },
docs: { dir: 'docs/' },
lint: {},
reports: { dir: 'reports/' },
src: { dir: 'src/' },
tests: { dir: 'test/' },
umd: {
exports: '(function() {\n'
+ ' var ret = {};\n'
+ ' Object.defineProperties(ret, {\n'
+ ' disableStickyTableHeader: {\n'
+ ' configurable: false,\n'
+ ' enumerable: true,\n'
+ ' writable: false,\n'
+ ' value: disableStickyTableHeader\n'
+ ' },\n'
+ ' enableStickyTableHeader: {\n'
+ ' configurable: false,\n'
+ ' enumerable: true,\n'
+ ' writable: false,\n'
+ ' value: enableStickyTableHeader\n'
+ ' },\n'
+ ' manager: {\n'
+ ' configurable: false,\n'
+ ' enumerable: true,\n'
+ ' writable: false,\n'
+ ' value: _globalSTHManager\n'
+ ' },\n'
+ ' StickyTableHeader: {\n'
+ ' configurable: false,\n'
+ ' enumerable: true,\n'
+ ' writable: false,\n'
+ ' value: StickyTableHeader\n'
+ ' }\n'
+ ' });\n'
+ ' return ret;\n'
+ '})()',
namespace: 'STH'
}
};
config.fileHeader = "/*!\n * sticky-table-headers.js (" + config.pkg.version + ")\n *\n * Copyright (c) " + (new Date()).getFullYear() + " Brandon Sara (http://bsara.github.io)\n * Licensed under the CPOL-1.02 (https://github.com/bsara/stickytableheaders.js/blob/v" + config.pkg.version + "/LICENSE.md)\n */\n\n";
config.lint.selectors = [
'gulpfile.js',
path.join(config.src.dir, '**/*.js'),
path.join(config.tests.dir, '**/*.js')
];
// ------------------------- //
// Tasks //
// ------------------------- //
gulp.task('default', [ 'help' ]);
gulp.task('help', function() {
var header = util.colors.bold.blue;
var task = util.colors.green;
console.log(String.EMPTY);
console.log(header("sticky-table-headers.js Gulp Tasks"));
console.log(header("------------------------------------------------------------------------------"));
console.log(" " + task("help") + " (" + util.colors.yellow("default") + ") - Displays this message.");
console.log(String.EMPTY);
console.log(" " + task("build") + " - Builds the project.");
console.log(" " + task("rebuild") + " - Cleans the build folder, then builds the project.");
console.log(" " + task("docs") + " - Generates documentation based on inline JSDoc comments.");
console.log(" " + task("dist") + " - Performs all needed tasks to prepare the built project");
console.log(" for a new release.");
// console.log(String.EMPTY);
// console.log(" " + task("test") + " - Runs the project's tests.");
console.log(String.EMPTY);
console.log(" " + task("clean") + " - Runs all available cleaning tasks in parallel.");
console.log(" " + task("clean:build") + " - Cleans the build output directory.");
console.log(" " + task("clean:docs") + " - Cleans the documentation output directory.");
console.log(" " + task("clean:dist") + " - Cleans the distribution output directory.");
console.log(" " + task("clean:reports") + " - Cleans the reports output directory.");
console.log(String.EMPTY);
console.log(" " + task("lint") + " - Runs all available linting tasks in parallel.");
console.log(" " + task("jshint") + " - Runs JSHint on the project source files.");
console.log(" " + task("jscs") + " - Runs JSCS on the project source files.");
console.log(String.EMPTY);
});
// Build Tasks
// ----------------
gulp.task('build', function() {
var manualInitScripts = gulp.src([
path.join(config.src.dir, '_sth.js'),
path.join(config.src.dir, 'sticky-table-header.js'),
path.join(config.src.dir, 'sticky-table-header-manager.js'),
path.join(config.src.dir, 'enable-disable.js')
])
.pipe(concat('sticky-table-headers.js'));
var autoInitScripts = gulp.src([
path.join(config.src.dir, '_sth.js'),
path.join(config.src.dir, 'sticky-table-header.js'),
path.join(config.src.dir, 'sticky-table-header-manager.js'),
path.join(config.src.dir, 'enable-disable.js'),
path.join(config.src.dir, 'auto-init.js')
])
.pipe(concat('sticky-table-headers.auto-init.js'));
var scripts = merge(manualInitScripts, autoInitScripts)
.pipe(replace(/\s*\/\/\s*js(hint\s|cs:).*$/gmi, String.EMPTY))
.pipe(replace(/\s*\/\*\s*(js(hint|lint|cs:)|global(|s)|exported)\s.*?\*\/\s*\n/gmi, String.EMPTY))
.pipe(wrapUMD({
namespace: config.umd.namespace,
exports: config.umd.exports
}))
.pipe(insert.prepend(config.fileHeader));
var styles = gulp.src(path.join(config.src.dir, "**/*.css"))
.pipe(autoprefixer({
browsers: [ 'last 10 versions' ],
remove: true
}))
.pipe(rename({ basename: 'sticky-table-headers' }))
.pipe(insert.prepend(config.fileHeader))
.pipe(gulp.dest(config.build.dir))
.pipe(rename({ extname: '.scss' }));
return merge(scripts, styles)
.pipe(gulp.dest(config.build.dir));
});
gulp.task('rebuild', function(callback) {
runSequence('clean:build', 'build', callback);
});
gulp.task('dist', [ 'clean:build', 'clean:dist' ], function(callback) {
runSequence('lint', 'build', 'test', 'docs', function(err) {
if (err) {
callback(err);
return;
}
var srcFiles = gulp.src(path.join(config.build.dir, '**/*'));
var minifyScripts = gulp.src(path.join(config.build.dir, '**/*.js'))
.pipe(uglify({ preserveComments: 'some' }));
var minifyStyles = gulp.src(path.join(config.build.dir, '**/*.css'))
.pipe(cssmin());
var renameMinifiedFiles = merge(minifyScripts, minifyStyles)
.pipe(rename({ suffix: '.min' }));
merge(srcFiles, renameMinifiedFiles)
.pipe(gulp.dest(config.dist.dir));
callback();
});
});
gulp.task('docs', [ 'clean:docs' ], function() {
return gulp.src([ path.join(config.src.dir, '**/*.js'), 'README.md' ])
.pipe(jsdoc.parser(null, 'sticky-table-headers.js'))
.pipe(jsdoc.generator(config.docs.dir));
});
// Test Tasks
// ----------------
gulp.task('test', [ 'lint' ], function() {
util.log(util.colors.yellow("Tests are not yet implemented!"));
});
// Clean Tasks
// ----------------
gulp.task('clean', [ 'clean:build', 'clean:dist', 'clean:docs', 'clean:reports' ]);
gulp.task('clean:build', function() {
return del(config.build.dir);
});
gulp.task('clean:dist', function() {
return del(config.dist.dir);
});
gulp.task('clean:docs', function() {
return del(config.docs.dir);
});
gulp.task('clean:reports', function() {
return del(config.reports.dir);
});
// Lint Tasks
// ----------------
gulp.task('lint', [ 'jshint', 'jscs' ]);
gulp.task('jshint', function() {
return gulp.src(config.lint.selectors)
.pipe(jshint())
.pipe(jshint.reporter(jshintStylishReporter, { verbose: true }))
.pipe(jshint.reporter('fail', { verbose: true }));
});
gulp.task('jscs', function() {
return gulp.src(config.lint.selectors)
.pipe(jscs({ verbose: true }));
});