forked from eBay/skin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
128 lines (115 loc) · 4.45 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
var gulp = require('gulp');
var less = require('gulp-less');
var path = require('path');
var child_process = require('child_process');
var banner = require('gulp-banner');
var pkg = require('./package.json');
var flatten = require('gulp-flatten');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var LessPluginCleanCSS = require('less-plugin-clean-css');
var cleanCSSPlugin = new LessPluginCleanCSS({ advanced: true });
var LessPluginAutoPrefix = require('less-plugin-autoprefix');
var autoprefixPlugin = new LessPluginAutoPrefix();
var distTarget = './dist';
var siteStaticTarget = './_site/static';
var docsStaticTarget = './docs/static';
var minifiedFileExtensionName = '.min.css';
var cdnTarget = './_cdn/skin/v' + pkg.version;
var comment = [
'/*!',
'Skin v<%= pkg.version %>',
'Copyright 2017 eBay! Inc. All rights reserved.',
'Licensed under the BSD License.',
'https://github.com/eBay/skin/blob/master/LICENSE.txt"',
'*/\n',
].join('\n');
// Compile all modules to /dist
function modules() {
return gulp
.src([
'./src/less/**/*.less',
'!./src/**/base/*.less',
'!./src/less/**/*-static.less',
'!./src/less/bundles/**/*.less',
'!./src/less/gh/**/*.less',
'!./src/less/grid/**/*.less',
'!./src/less/less/**/*.less',
'!./src/less/mixins/**/*.less',
'!./src/less/variables/**/*.less',
'!./src/less/properties/**/*.less',
])
.pipe(less({ plugins: [autoprefixPlugin] }))
.pipe(gulp.dest(distTarget));
}
// Compile and minify the full skin bundle to docs/static, _site/static and cdn
function megabundle() {
return gulp
.src(['./src/less/bundles/skin/**/*.less'])
.pipe(banner(comment, { pkg: pkg }))
.pipe(
rename(function (path) {
path.extname = minifiedFileExtensionName;
})
)
.pipe(less({ plugins: [autoprefixPlugin] }))
.pipe(less({ plugins: [cleanCSSPlugin] }))
.pipe(gulp.dest(docsStaticTarget))
.pipe(gulp.dest(siteStaticTarget))
.pipe(gulp.dest(cdnTarget));
}
// Static Server + watching src & docs files
function server() {
// Start the server.
browserSync.init({ server: '_site' });
// Watch less files under src/less. Resync CSS on change.
gulp.watch('src/less/**/*.less', gulp.series('default', injectSkinCSS));
// Watch less files under docs. Resync CSS on change.
gulp.watch('docs/src/less/**/*.less', syncDocsCss);
// Watch js files under docs. Resync JS on change.
gulp.watch('docs/src/js/**/*.js', syncDocsJs);
// Watch html files under docs. Regenerate _site on change.
gulp.watch('docs/**/*.html', syncDocsHtml);
// Watch html files under _site. Resync browser on change.
gulp.watch('_site/**/*.html').on('change', browserSync.reload);
}
// Inject Skin CSS into browsers
function injectSkinCSS() {
return gulp.src(['_site/**/*.css', '_site/**/*.min.css']).pipe(browserSync.stream());
}
// Re-lasso the docs CSS, copy to jekyll _site/static, inject into browsers
function syncDocsCss() {
return child_process
.spawn('npm', ['run', 'lasso:docs'], { stdio: 'inherit' })
.on('close', function () {
gulp.src(['./docs/static/ds4/docs.min.css'])
.pipe(gulp.dest(siteStaticTarget + '/ds4'))
.pipe(browserSync.stream());
gulp.src(['./docs/static/ds6/docs.min.css'])
.pipe(gulp.dest(siteStaticTarget + '/ds6'))
.pipe(browserSync.stream());
});
}
// Re-lasso the docs JS, copy it to jekyll _site/static, then reload browsers
function syncDocsJs() {
return child_process
.spawn('npm', ['run', 'lasso:docs'], { stdio: 'inherit' })
.on('close', function () {
gulp.src(['./docs/static/ds4/docs.min.js']).pipe(gulp.dest(siteStaticTarget + '/ds4'));
gulp.src(['./docs/static/ds6/docs.min.js']).pipe(gulp.dest(siteStaticTarget + '/ds6'));
browserSync.reload();
});
}
// Run Jekyll build
function syncDocsHtml(cb) {
return child_process
.spawn(
'bundler',
['exec', 'jekyll', 'build', '--config', 'docs/_config.yml,docs/_config.localhost.yml'],
{ stdio: 'inherit' }
)
.on('close', cb);
}
// public tasks listed below
exports.server = server;
exports.default = gulp.series(gulp.parallel(modules, megabundle));