-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
136 lines (125 loc) · 3.94 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
var fs = require('fs')
var gulp = require('gulp')
var path = require('path')
var sass = require('gulp-sass')
var autoprefixer = require('gulp-autoprefixer')
var sourcemaps = require('gulp-sourcemaps')
var cleanCSS = require('gulp-clean-css')
var rename = require('gulp-rename')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var connect = require('gulp-connect')
var open = require('gulp-open')
var babel = require('gulp-babel')
var replace = require('gulp-replace')
var wrapper = require('gulp-wrapper')
var Paths = {
HERE : './',
DIST : 'template/fulldoc/html/assets',
DIST_TOOLKIT_JS : 'template/fulldoc/html/assets/toolkit.js',
SCSS_TOOLKIT_SOURCES : './src/scss/toolkit*',
SCSS : './src/scss/**/**',
JS : [
"./src/js/bootstrap/util.js",
"./src/js/bootstrap/alert.js",
"./src/js/bootstrap/button.js",
"./src/js/bootstrap/carousel.js",
"./src/js/bootstrap/collapse.js",
"./src/js/bootstrap/dropdown.js",
"./src/js/bootstrap/modal.js",
"./src/js/bootstrap/tooltip.js",
"./src/js/bootstrap/popover.js",
"./src/js/bootstrap/scrollspy.js",
"./src/js/bootstrap/tab.js",
'./src/js/custom/*'
]
}
var banner = '/*!\n' +
' * Bootstrap\n' +
' * Copyright 2011-2016\n' +
' * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n' +
' */\n'
var jqueryCheck = 'if (typeof jQuery === \'undefined\') {\n' +
' throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\\\'s JavaScript.\')\n' +
'}\n'
var jqueryVersionCheck = '+function ($) {\n' +
' var version = $.fn.jquery.split(\' \')[0].split(\'.\')\n' +
' if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] >= 4)) {\n' +
' throw new Error(\'Bootstrap\\\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0\')\n' +
' }\n' +
'}(jQuery);\n\n'
gulp.task('default', ['scss-min', 'js-min'])
gulp.task('watch', function () {
gulp.watch(Paths.SCSS, ['scss-min']);
gulp.watch(Paths.JS, ['js-min']);
})
gulp.task('docs', ['server'], function () {
gulp.src(__filename)
.pipe(open({uri: 'http://localhost:9001/docs/'}))
})
gulp.task('server', function () {
connect.server({
root: 'docs',
port: 9001,
livereload: true
})
})
gulp.task('scss', function () {
return gulp.src(Paths.SCSS_TOOLKIT_SOURCES)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write(Paths.HERE))
.pipe(gulp.dest(Paths.DIST))
})
gulp.task('scss-min', ['scss'], function () {
return gulp.src(Paths.SCSS_TOOLKIT_SOURCES)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({compatibility: 'ie9'}))
.pipe(autoprefixer())
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write(Paths.HERE))
.pipe(gulp.dest(Paths.DIST))
})
gulp.task('js', function () {
return gulp.src(Paths.JS)
.pipe(concat('toolkit.js'))
.pipe(replace(/^(export|import).*/gm, ''))
.pipe(babel({
"compact" : false,
"presets": [
[
"es2015",
{
"modules": false,
"loose": true
}
]
],
"plugins": [
"transform-es2015-modules-strip"
]
}
))
.pipe(wrapper({
header: banner +
"\n" +
jqueryCheck +
"\n" +
jqueryVersionCheck +
"\n+function () {\n",
footer: '\n}();\n'
}))
.pipe(gulp.dest(Paths.DIST))
})
gulp.task('js-min', ['js'], function () {
return gulp.src(Paths.DIST_TOOLKIT_JS)
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(Paths.DIST))
})