-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGulpfile.babel.js
141 lines (122 loc) · 3.61 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
137
138
139
140
141
/*eslint-disable no-console */
import App from './src/app.js'
import autoprefixer from 'autoprefixer'
import babelify from 'babelify'
import browserify from 'browserify'
import buffer from 'vinyl-buffer'
import chalk from 'chalk'
import csswring from 'csswring'
import confirm from 'gulp-confirm'
import connect from 'gulp-connect'
import eslint from 'gulp-eslint'
import fs from 'fs'
import gulp from 'gulp'
import gzip from 'gulp-gzip'
import jscs from 'gulp-jscs'
import { Server } from 'karma'
import { join } from 'path'
import precss from 'precss'
import postcss from 'gulp-postcss'
import { createElement } from 'react'
import { renderToString } from 'react-dom/server'
import rename from 'gulp-rename'
import replace from 'gulp-replace'
import source from 'vinyl-source-stream'
import s3 from 'gulp-s3'
import uglify from 'gulp-uglify'
const karmaConfig = join(__dirname, 'karma.conf.js')
gulp.task('compile', ['copy:icons', 'copy:normalize', 'index.html', 'copy:manifest', 'javascript', 'style'])
gulp.task('connect', () => {
connect.server({
root : 'dist',
livereload : true
})
})
gulp.task('copy:icons', () => {
gulp.src('src/icons/*')
.pipe(gulp.dest('dist/'))
})
gulp.task('copy:manifest', () => {
gulp.src('src/manifest-template')
.pipe(replace(/:revision-date/, new Date().getTime()))
.pipe(rename('cache.manifest'))
.pipe(gulp.dest('dist/'))
})
gulp.task('copy:normalize', () => {
gulp.src('node_modules/normalize.css/normalize.css')
.pipe(gulp.dest('dist/'))
})
gulp.task('index.html', () => {
gulp.src('src/layout.html')
.pipe(rename('index.html'))
// replace the <!-- main --> comment in index.html with rendered App component
.pipe(replace('<!-- main -->', renderToString(createElement(App))))
.pipe(gulp.dest('dist'))
})
gulp.task('javascript', ['index.html'], () => {
browserify('./src/app.js')
.transform(babelify)
.bundle()
.on('error', (err) => {
console.log(chalk.bold.red(err))
})
.pipe(source('main.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist'))
})
gulp.task('karma:single', (done) => {
new Server({
configFile : karmaConfig,
singleRun : true
}, done).start()
})
gulp.task('style', () => {
const processors = [
autoprefixer({ browsers : ['last 2 versions'], cascade : false }),
precss,
csswring()
]
gulp.src('src/main.css')
.pipe(postcss(processors))
.pipe(gulp.dest('dist'))
})
gulp.task('watch', () => {
gulp.watch(['src/**/*.js*'], ['compile', 'lint', 'test'])
gulp.watch(['src/**/*.html*'], ['index.html', 'copy:manifest'])
gulp.watch(['src/**/*.css'], ['style', 'copy:manifest'])
})
gulp.task('compress:js', () => {
gulp.src('dist/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist'))
})
gulp.task('deploy', ['compress:js'], () => {
const configPath = 'farely-aws.json'
if (!fs.existsSync(configPath)) {
return console.log(chalk.bold.red(`${configPath} not found.`))
}
gulp.src('./dist/**')
.pipe(confirm({
question : 'You\'re sure you want to release? (y/n)',
input : '_key:y' // Proceed only if 'y' is entered
}))
.pipe(gzip())
.pipe(s3(JSON.parse(fs.readFileSync(configPath)), {
uploadPath : '/',
headers : {
'x-amz-acl' : 'public-read'
}
}))
})
gulp.task('default', ['compile', 'connect', 'lint', 'test', 'watch'])
gulp.task('lint', () => {
gulp.src(['src/**/*.{js}', '!node_modules/**'])
.pipe(jscs())
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
gulp.task('test', ['lint', 'karma:single'])
/*eslint-enable no-console */