-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
154 lines (140 loc) · 3.88 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Variables
let gulp = require('gulp');
let browserSync = require('browser-sync');
let reload = browserSync.reload;
let plugins = require('gulp-load-plugins');
let $ = plugins();
let request = require('request');
let config = require('./gulp.config.js');
let syncy = require('syncy');
let webpackStream = require('webpack-stream');
let webpack = require('webpack');
let defaultTasks = ['php', 'screenshot', 'sass', 'scripts', 'images', 'fonts'];
// Tasks
gulp.task('sass', function () {
return gulp.src(`${config.development_path}/sass/**/style.scss`)
.pipe($.plumber())
.pipe($.sass({
includePaths: [
'node_modules',
'bower_components',
`${config.development_path}/sass`
]
}).on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 5 versions']
}))
.pipe($.concat('style.css'))
.pipe($.cssnano())
.pipe(gulp.dest(`${config.tmp_path}/wordpress/wp-content/themes/${config.theme_path}`));
});
gulp.task('scripts', function () {
return gulp.src(`${config.development_path}/js/main.js`)
.pipe($.plumber())
.pipe(webpackStream({
output: {
filename: 'main.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015']
}
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({mangle: true})
]
}))
.pipe(gulp.dest(`${config.tmp_path}/wordpress/wp-content/themes/${config.theme_path}/js`));
});
gulp.task('images', function (done) {
syncy(
[`${config.development_path}/images/**/*`],
`${config.tmp_path}/wordpress/wp-content/themes/${config.theme_path}`,
{
verbose: true,
base: config.development_path,
ignoreInDest: '!images/**/*'
}
)
.then(() => {
done();
})
.catch(err => {
done(err);
});
});
gulp.task('fonts', function (done) {
syncy(
[`${config.development_path}/fonts/**/*`],
`${config.tmp_path}/wordpress/wp-content/themes/${config.theme_path}`,
{
verbose: true,
base: config.development_path,
ignoreInDest: '!fonts/**/*'
}
)
.then(() => {
done();
})
.catch(err => {
done(err);
});
});
gulp.task('php', function (done) {
syncy(
[`${config.development_path}/**/*.php`],
`${config.tmp_path}/wordpress/wp-content/themes/${config.theme_path}`,
{
verbose: true,
base: config.development_path,
ignoreInDest: '!**/*.php'
}
)
.then(() => {
done();
})
.catch(err => {
done(err);
});
});
gulp.task('wordpress', function () {
return $.download('https://wordpress.org/latest.zip')
.pipe($.unzip())
.pipe(gulp.dest(config.tmp_path));
});
gulp.task('screenshot', function () {
return gulp.src('screenshot.png')
.pipe(gulp.dest(`${config.tmp_path}/wordpress/wp-content/themes/${config.theme_path}`));
});
gulp.task('build', defaultTasks, function () {
return gulp.src(`${config.tmp_path}/wordpress/**/*`)
.pipe(gulp.dest(config.dist_path));
});
gulp.task('default', function () {
gulp.start('build');
});
gulp.task('watch', defaultTasks, function () {
$.connectPhp.server({
base: `${config.tmp_path}/wordpress`
}, function () {
browserSync({
proxy: '127.0.0.1:8000',
notify: false
});
});
gulp.watch(`${config.development_path}/images/**/*`, ['images']);
gulp.watch(`${config.development_path}/fonts/**/*`, ['fonts']);
gulp.watch(`${config.development_path}/js/**/*.js`, ['scripts']);
gulp.watch(`${config.development_path}/sass/**/*.{scss,sass}`, ['sass']);
gulp.watch(`${config.development_path}/**/*.php`, ['php']);
gulp.watch(`${config.development_path}/**/*`).on('change', function (e) {
reload();
});
});