This repository was archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathgulpfile.js
More file actions
131 lines (122 loc) · 3.9 KB
/
gulpfile.js
File metadata and controls
131 lines (122 loc) · 3.9 KB
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
'use strict';
var fs = require('fs'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
gulp = require('gulp-param')(require('gulp'), process.argv),
jshint = require('gulp-jshint'),
header = require('gulp-header'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
minifyCss = require('gulp-minify-css'),
concat = require('gulp-concat'),
replace = require('gulp-replace'),
plumber = require('gulp-plumber'),
historyApiFallback = require('connect-history-api-fallback'),
path = require('path'),
del = require('del'),
yuidoc = require("gulp-yuidoc");
var fileList = JSON.parse(fs.readFileSync('build.json'));
var bower = JSON.parse(fs.readFileSync('bower.json'));
var docTask = function(src, dest) {
return gulp.src(src)
.pipe(yuidoc())
.pipe(gulp.dest(dest));
};
var cleanTask = function(src) {
return del(src);
};
var scriptTask = function (src, dest, conf) {
return gulp.src(src)
.pipe(plumber())
.pipe(jshint())
.pipe(sourcemaps.init())
.pipe(replace(/'use strict';/g, ''))
.pipe(concat(conf.name + '.js'))
.pipe(gulp.dest(dest))
.pipe(uglify())
.pipe(header('/**\n' +
' * <%= project.name %> - <%= project.description %>\n' +
' * @version <%= project.version %>\n' +
' * @link <%= project.homepage %>\n' +
' * @license <%= project.license %>\n' +
' */\n' +
'', {project: conf}))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest));
};
var styleTask = function (src, dest, conf) {
return gulp.src(src)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat(conf.name + '.css'))
.pipe(gulp.dest(dest))
.pipe(minifyCss())
.pipe(header('/**\n' +
' * <%= project.name %> - <%= project.description %>\n' +
' * @version <%= project.version %>\n' +
' * @link <%= project.homepage %>\n' +
' * @license <%= project.license %>\n' +
' */\n' +
'', {project: conf}))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest));
};
var watchTask = function () {
gulp.watch(['demo/**/*.html'], reload);
gulp.watch(['src/**/*.js'], ['js', reload]);
gulp.watch(['src/**/*.css'], ['css', reload]);
};
var serveTask = function () {
browserSync({
port: 5000,
notify: false,
logPrefix: 'MSJS',
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: {
baseDir: ['demo', 'bower_components'],
middleware: [historyApiFallback()],
routes: {
'/dist': 'dist'
}
}
});
};
gulp.task('doc', function () {
return docTask(fileList, 'docs/api');
});
gulp.task('clean', function () {
return cleanTask(['.tmp', 'dist']);
});
gulp.task('js', function (tag) {
var conf = {
name: bower.name,
description: bower.description,
version: tag || bower.version,
homepage: bower.homepage,
license: bower.license
};
return scriptTask(fileList, 'dist', conf);
});
gulp.task('css', function (tag) {
var conf = {
name: bower.name,
description: bower.description,
version: tag || bower.version,
homepage: bower.homepage,
license: bower.license
};
return styleTask('src/**/*.css', 'dist', conf);
});
gulp.task('watch', function () {
return watchTask();
});
gulp.task('serve', ['default', 'watch'], function () {
return serveTask();
});
gulp.task('default', ['clean', 'js', 'css']);