1
- // Initialize modules
1
+ // Gulp plugins
2
2
import { src , dest , watch , series , parallel } from 'gulp' ;
3
- import yargs from 'yargs ' ;
4
- import sass from 'gulp-sass ' ;
3
+ import banner from 'gulp-banner ' ;
4
+ import bumpVersion from 'gulp-bump ' ;
5
5
import cleanCss from 'gulp-clean-css' ;
6
+ import conventionalChangelog from 'gulp-conventional-changelog' ;
6
7
import gulpif from 'gulp-if' ;
8
+ import imagemin from 'gulp-imagemin' ;
9
+ import notify from 'gulp-notify' ;
7
10
import postcss from 'gulp-postcss' ;
11
+ import prompt from 'gulp-prompt' ;
12
+ import replace from 'gulp-replace' ;
13
+ import run from 'gulp-run' ;
14
+ import sass from 'gulp-sass' ;
8
15
import sourcemaps from 'gulp-sourcemaps' ;
16
+ import wpPot from 'gulp-wp-pot' ;
17
+ import zip from 'gulp-zip' ;
18
+
19
+ // Other plugins
20
+ import pkg from './package.json' ;
9
21
import autoprefixer from 'autoprefixer' ;
10
- import imagemin from 'gulp-imagemin' ;
11
22
import del from 'del' ;
12
- import webpack from 'webpack-stream' ;
13
23
import named from 'vinyl-named' ;
14
24
import browserSync from 'browser-sync' ;
15
- import zip from 'gulp-zip' ;
16
- import pkg from './package.json' ;
17
- import replace from 'gulp-replace' ;
18
- import wpPot from 'gulp-wp-pot' ;
19
- import banner from 'gulp-banner' ;
20
- import prompt from 'gulp-prompt' ;
21
- import bumpVersion from 'gulp-bump' ;
22
- import conventionalChangelog from 'gulp-conventional-changelog' ;
23
- import notify from 'gulp-notify' ;
24
- import run from 'gulp-run' ;
25
+ import webpack from 'webpack-stream' ;
26
+ import yargs from 'yargs' ;
25
27
28
+ // Configs
26
29
const PRODUCTION = yargs . argv . prod ;
27
30
const server = browserSync . create ( ) ;
31
+ require ( 'dotenv' ) . config ( ) ;
32
+ const dist = `wwwroot/wp-content/themes/${ pkg . name } ` ;
28
33
29
34
// Browsersync
30
35
const serve = done => {
@@ -54,7 +59,10 @@ const comment = '/*\n' +
54
59
'*/\n' ;
55
60
56
61
// Clean
57
- export const clean = ( ) => del ( [ 'dist' , 'build' ] ) ;
62
+ export const clean = ( ) => del ( [ dist , 'build' ] ) ;
63
+
64
+ // Clean all
65
+ export const cleanall = ( ) => del ( [ dist , 'build' , 'wwwroot' ] ) ;
58
66
59
67
// Styles
60
68
export const styles = ( ) => {
@@ -66,7 +74,7 @@ export const styles = () => {
66
74
compatibility : 'ie8'
67
75
} ) ) )
68
76
. pipe ( gulpif ( ! PRODUCTION , sourcemaps . write ( ) ) )
69
- . pipe ( dest ( ' dist/css') )
77
+ . pipe ( dest ( dist + '/assets /css') )
70
78
. pipe ( server . stream ( ) ) ;
71
79
} ;
72
80
@@ -76,20 +84,20 @@ const addBanner = () => {
76
84
. pipe ( banner ( comment , {
77
85
pkg
78
86
} ) )
79
- . pipe ( dest ( ' dist/php' ) ) ;
87
+ . pipe ( dest ( dist ) ) ;
80
88
} ;
81
89
82
90
// Images
83
91
export const images = ( ) => {
84
92
return src ( 'src/images/**/*.{jpg,jpeg,png,svg,gif}' )
85
93
. pipe ( gulpif ( PRODUCTION , imagemin ( ) ) )
86
- . pipe ( dest ( ' dist/images') ) ;
94
+ . pipe ( dest ( dist + '/assets /images') ) ;
87
95
} ;
88
96
89
97
// Copy
90
98
export const copy = ( ) => {
91
99
return src ( 'src/**/*.{php,mo,po,htaccess}' )
92
- . pipe ( dest ( ' dist' ) ) ;
100
+ . pipe ( dest ( dist ) ) ;
93
101
} ;
94
102
95
103
// Copy production htaccess
@@ -125,7 +133,7 @@ export const scripts = () => {
125
133
jquery : 'jQuery'
126
134
}
127
135
} ) )
128
- . pipe ( dest ( ' dist/js') ) ;
136
+ . pipe ( dest ( dist + '/assets /js') ) ;
129
137
} ;
130
138
131
139
// Bump version x.x.1
@@ -236,6 +244,21 @@ export const addRelease = () => {
236
244
return run ( `git add CHANGELOG.md README.md package.json && git commit --amend --no-edit && git tag v${ pkg . version } -m "Version ${ pkg . version } " && git push && git push --tags` ) . exec ( ) ;
237
245
} ;
238
246
247
+ // Run vagrant up and install its dependencies to work with WordPress
248
+ const setupEnvironment = ( ) => {
249
+ return run ( 'vagrant up' ) . exec ( ) ;
250
+ } ;
251
+
252
+ // Sets the configuration
253
+ const setConfig = ( ) => {
254
+ return src ( './wwwroot/wp-config.php' )
255
+ . pipe ( replace ( 'database_name_here' , process . env . LOCAL_DB_NAME ) )
256
+ . pipe ( replace ( 'username_here' , process . env . LOCAL_DB_USER ) )
257
+ . pipe ( replace ( 'password_here' , process . env . LOCAL_DB_PASS ) )
258
+ . pipe ( dest ( './wwwroot' ) ) ;
259
+ } ;
260
+
261
+ export const setup = series ( setupEnvironment , setConfig ) ;
239
262
export const dev = series ( clean , parallel ( styles , images , copy , scripts ) , addBanner , serve , watchForChanges ) ;
240
263
export const build = series ( clean , parallel ( styles , images , copy , scripts ) , addBanner , copyHtaccessProduction , compress ) ;
241
264
export const bump = series ( bumpPrompt ) ;
0 commit comments