forked from LucaPipolo/acf-field-address
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
130 lines (105 loc) · 3.29 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
'use strict'
require('dotenv').config()
const gulp = require('gulp')
const gulpsync = require('gulp-sync')(gulp)
const gutil = require('gulp-util')
const dbTask = require('gulp-db')
const mysqldump = require('mysqldump')
const gmcfp = require('gulp-mysql-command-file-processor')
const livereload = require('gulp-livereload')
const webpack = require('webpack')
const del = require('del')
const fs = require('fs')
const ACF_ADDRESS_ROOT = process.env.ACF_ADDRESS_ROOT
/* ------------------------- Gulp Tasks -------------------------------- */
/**
* Gulp
* default task: `gulp`
* alias for `gulp build`
*/
gulp.task('default', [ 'build' ])
/**
* Gulp watch `gulp watch`
* Watch Files For Changes and recompile on change.
*/
gulp.task('watch', [ 'webpack:build-dev', 'webpack:watch-dev' ])
gulp.task('webpack:watch-dev', () => {
livereload.listen()
gulp.watch(`./${ACF_ADDRESS_ROOT}/**/*.php`, [ 'livereload' ])
gulp.watch(`./${ACF_ADDRESS_ROOT}/js/*.js`, [ 'webpack:build-dev' ])
gulp.watch(`./${ACF_ADDRESS_ROOT}/scss/*.scss`, [ 'webpack:build-dev' ])
})
gulp.task('livereload', (cb) => {
livereload.reload()
cb()
})
gulp.task('build', gulpsync.sync([ 'clean:dist', [ 'webpack:build' ] ]))
gulp.task('clean:dist', () => {
return del([
`${ACF_ADDRESS_ROOT}/dist/*`
])
})
gulp.task('webpack:build', (cb) => {
let webpackConfig = Object.create(require('./webpack.make')({
BUILD: true,
TEST: false
}, ACF_ADDRESS_ROOT))
let compiler = webpack(webpackConfig)
compiler.run((err, stats) => {
if(err) throw new gutil.PluginError('webpack:build', err)
gutil.log('[webpack:build]', stats.toString({
colors: true
}))
cb()
})
})
let webpackDevConfig = Object.create(require('./webpack.make')({
BUILD: false,
TEST: false
}, ACF_ADDRESS_ROOT))
// create a single instance of the compiler to allow caching
let devCompiler = webpack(webpackDevConfig)
gulp.task('webpack:build-dev', (cb) => {
// run webpack
devCompiler.run((err, stats) => {
if(err) throw new gutil.PluginError('webpack:build-dev', err)
gutil.log('[webpack:build-dev]', stats.toString({
colors: true
}))
livereload.reload()
cb()
})
})
/* ------------------------- Gulp Deploy Tasks -------------------------------- */
/**
* Gulp Database Init `gulp db:init`
* Initializes your local database with test database.
*/
gulp.task('db:init', gulpsync.sync([ 'db:drop', 'db:create', 'db:populate' ]))
let dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT || 3306
}
let dbManager = dbTask(Object.assign({}, dbConfig, { dialect: 'mysql', database: null }))
gulp.task('db:create', dbManager.create(process.env.DB_NAME))
gulp.task('db:drop', dbManager.drop(process.env.DB_NAME))
gulp.task('db:populate', cb => {
gulp.src('./tests/_data/dump.sql')
.pipe(gmcfp(dbConfig.user, dbConfig.password, dbConfig.host, dbConfig.port, dbConfig.database))
.pipe(gulp.dest('./tests/fixtures'))
cb()
})
/**
* This is a helper task that updates tests/_data/dump.sql
*/
gulp.task('dump:local', (cb) => {
let config = Object.assign({}, dbConfig, { dest:'./tests/_data/dump.sql' })
mysqldump(config, err => {
if(err) throw new Error(err)
process.exit(0)
})
cb()
})