-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflyfile.js
161 lines (137 loc) · 3.28 KB
/
flyfile.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import path from 'path'
import cp from 'child_process'
import fs from 'fs'
import _ from 'lodash'
import { Server } from 'karma'
import webpack, { DefinePlugin } from 'webpack'
import webpackConfig from './webpack.config.js'
import browserSync from 'browser-sync'
import spa from 'browser-sync-spa'
import ghPages from 'gh-pages'
import git from 'git-rev-sync'
import sprity from 'sprity'
import Imagemin from 'imagemin'
import jsonminify from 'jsonminify'
const paths = {
build: path.resolve('build'),
}
const config = {
deploy: {
branch: 'release',
message: git.short() + ' - Update ' + (new Date()).toISOString(),
logger: (message) => console.log(message),
},
}
let Mock
let isMockStart = false
export function* clear() {
yield this
.clear(paths.build)
}
export function* lint() {
yield this
.source('src/js/**/*.js')
.eslint()
}
export function* test() {
new Server({
configFile: path.resolve(__dirname, 'karma.conf.js'),
singleRun: true,
}).start()
}
export function* compile() {
yield this
.source('src/**/*.md')
.marked()
.minify({ ext: 'html' })
.target(paths.build)
yield this
.source('src/**/*.json')
.filter((data) => jsonminify(`${data}`))
.target(paths.build)
}
export function* mock() {
if (isMockStart) {
this.log('Restarting development server.')
Mock.kill('SIGTERM')
}
Mock = (function startup() {
isMockStart = true
return cp.fork('./mock.js', {
env: Object.assign({NODE_ENV: 'development'}, process.env),
})
})()
process.on('exit', () => Mock.kill('SIGTERM'))
}
export function* sprite() {
sprity.create({
src: ['src/img/sprites/**/*'],
out: 'src/img',
cssPath: '../img',
name: 'sprites',
processor: 'sass',
'style-type': 'sass',
style: '../css/_sprites.sass',
orientation: 'binary-tree',
split: true,
})
}
export function* image() {
new Imagemin()
.src('src/img/**/*.{gif,jpg,png,svg}')
.dest(paths.build + '/img-min')
.run()
}
export function* webpackBuild() {
webpackConfig.plugins = webpackConfig.plugins.concat(
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
},
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
)
yield this
.source('src/js/index.js')
.webpack(webpackConfig)
}
export function* release() {
ghPages.publish(paths.build, config.deploy)
}
export function* master() {
config.deploy.branch = 'master'
ghPages.publish('build', config.deploy)
}
export function* view() {
const options = {
server: {
baseDir: paths.build,
},
port: 4000,
logPrefix: 'Laima',
logConnections: true,
}
browserSync(options)
browserSync.use(spa())
}
export default function* () {
yield this
.watch('src/**/*.+(md|json)', 'compile')
yield this
.watch(['./mock.js', './api.js'], 'mock')
const server = (function startup() {
return cp.fork('./server.js', {
env: Object.assign({NODE_ENV: 'development'}, process.env),
})
})()
process.on('exit', () => server.kill('SIGTERM'))
}
export function* prebuild() {
yield this
.start(['lint', 'test'], { parallel: true })
}
export function* build() {
yield this
.start(['clear', 'compile', 'webpackBuild', 'mock', 'view'])
}