-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
86 lines (71 loc) · 2.4 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
///////////////////
// Version 1.0.0 //
///////////////////
/// CONFIG ///
var theme_name = "test"; // This is the name of your theme
var project_name = "test"; // This is the name of your wordpress project. It needs to be equal to the 'Local' folder where wordpress is installed.
/// VARIABLES ///
var gulp = require('gulp');
var sass = require('gulp-sass');
var clean = require('gulp-clean');
var shell = require('gulp-shell');
var plumber = require('gulp-plumber');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
var location_wp = "local-sites/" + project_name + "/app/public/wp-content/themes/" + theme_name;
var location_build = "build";
var version = "1.0.0";
/// TASKS ///
gulp.task('default', function(){
console.log(" ");
console.log(" Theme: " + theme_name );
console.log(" ");
console.log(" gulp build │ Compile all files to /build/");
console.log(" gulp sass │ Compile sass files to /build/");
console.log(" gulp php │ Compile php files to /build/");
console.log(" gulp clean │ Clean build directory");
console.log(" gulp deploy │ Deploy to local wordpress server");
console.log(" gulp watch │ Watch changes, build and deploy automatically");
console.log(" ");
console.log(" Version: " + version);
console.log(" ");
});
gulp.task('build', function(){
return gulp.src(['src/**/*'])
.pipe(plumber())
.pipe(gulp.dest(location_build));
});
gulp.task('clean', function(){
return gulp.src(location_build)
.pipe(plumber())
.pipe(clean());
})
gulp.task('sass', function(){
return gulp.src('src/sass/**/*.scss')
.pipe(plumber())
.pipe(sass())
.pipe(gulp.dest(location_build))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('php', function(){
return gulp.src('src/**/*.php')
.pipe(plumber())
.pipe(gulp.dest(location_build))
.pipe(browserSync.reload({
stream: true
})
);
})
gulp.task('deploy', function(){
return gulp.src('build/**/*')
.pipe(shell('cp -R '+ location_build +'/. ~/' + location_wp));
});
gulp.task('watch', function() {
browserSync.init({
proxy: theme_name + ".dev"
});
gulp.watch('src/**/*.php', () => runSequence(['php'], ['deploy'])).on("change", browserSync.reload)
gulp.watch('src/sass/**/*.scss', () => runSequence(['sass'], ['deploy'])).on("change", browserSync.reload)
});