forked from elementary/houston
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
136 lines (117 loc) · 2.98 KB
/
gulpfile.babel.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
/**
* gulpfile.babel.js
* Transcodes and builds all needed files.
*/
import del from 'del'
import gulp from 'gulp'
import path from 'path'
import babel from 'gulp-babel'
import cssnext from 'postcss-cssnext'
import gulpWebpack from 'webpack-stream'
import postcss from 'gulp-postcss'
import webpack from 'webpack'
import webpackConfig from './webpack.babel.js'
const browsers = [
'last 4 version',
'not ie <= 11'
]
/**
* functionCopy
* Returns gulp task for copying files based on file input
*
* @param {String} [file] - path of file to copy
* @returns {Stream} - a gulp stream
*/
const functionCopy = (file) => {
const buildFiles = (file == null) ? ['src/**/*', '!src/**/*.js', '!src/**/*.css'] : file
return gulp.src(buildFiles, { base: 'src' })
.pipe(gulp.dest('build'))
}
/**
* functionBabel
* Returns gulp task for building with babel based on file input
*
* @param {String} [file] - path of file to build with babel
* @returns {Stream} - a gulp stream
*/
const functionBabel = (file) => {
const buildFiles = (file == null) ? ['src/**/*.js', '!src/houston/public/scripts/app.js'] : file
return gulp.src(buildFiles, { base: 'src' })
.pipe(babel())
.pipe(gulp.dest('build'))
}
/**
* functionPostCSS
* Returns gulp task for building stylesheets with PostCSS
*
* @param {String} [file] - path of the file to build with PostCSS
* @returns {Stream} - a gulp stream
*/
const functionPostCSS = (file) => {
const buildFiles = (file == null) ? ['src/**/*.css'] : file
return gulp.src(buildFiles, { base: 'src' })
.pipe(postcss([
cssnext({ browsers })
]))
.pipe(gulp.dest('build'))
}
/**
* functionWebpack
* Returns gulp task for building client side webpack bundle
*
* @returns {String} - a gulp stream
*/
const functionWebpack = () => {
return gulp.src('src/houston/public/scripts/app.js')
.pipe(gulpWebpack(webpackConfig, webpack))
.pipe(gulp.dest('build/houston/public/scripts'))
}
/**
* clean
* Removes any compiled files
*/
gulp.task('clean', () => {
return del(['build'])
})
/**
* build
* Runs all build related tasks
*/
gulp.task('build', ['build-copy', 'build-babel', 'build-postcss', 'build-webpack'])
/**
* build-copy
* Copies all non built files to build directory
*/
gulp.task('build-copy', () => functionCopy())
/**
* build-babel
* Builds all src/ code with babel
*/
gulp.task('build-babel', () => functionBabel())
/**
* build-postcss
* Builds all src/ stylesheets with PostCSS
*/
gulp.task('build-postcss', () => functionPostCSS())
/**
* build-webpack
* Builds client side webpack bundle
*/
gulp.task('build-webpack', () => functionWebpack())
/**
* watch
* Watches files for change
*/
gulp.task('watch', () => {
gulp.watch('src/**/*', (obj) => {
if (obj == null || obj.type !== 'changed') return
if (path.extname(obj.path) === '.css') {
functionPostCSS(obj.path)
} else if (path.extname(obj.path) === '.js') {
functionBabel(obj.path)
functionWebpack()
} else {
functionCopy(obj.path)
}
})
})