This repository has been archived by the owner on May 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·110 lines (90 loc) · 2.58 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
require('dotenv').config()
//Variables
const gulp = require('gulp'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
prettier = require('gulp-prettier'),
replace = require('gulp-replace'),
browserSync = require('browser-sync').create(),
reload = browserSync.reload,
zip = require('gulp-zip')
//File Paths
const sassFiles = 'src/scss/**/*.scss',
mainSassFile = 'src/scss/style.scss',
cssFiles = '.',
sourceMaps = '/src/maps',
styleSheet = `<?php echo get_template_directory_uri(); ?>/style.css`,
currentDate = Date.now(),
buildFiles = {
folders: ['functions', 'layouts', 'src/fonts', 'src/img', 'src/js'],
files: ['footer.php', 'functions.php', 'header.php', 'index.php', 'single.php']
},
buildFolder = './_dist/'
//Compile main sass into css
function sassy() {
return gulp
.src(mainSassFile)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError)) //Using gulp-sass
.pipe(sourcemaps.write(sourceMaps))
.pipe(gulp.dest(cssFiles))
}
//Watch for changes in sass files and running sass compile
function watch() {
browserSync.init({
port: process.env.PORT || 3000,
proxy: process.env.WP_URL,
open: false
})
gulp.watch(sassFiles, sassy)
gulp.watch([
'./*.php',
'./layouts/**/*.php',
'./partials/**/*.php',
'./woocommerce/**/*.php',
'./src/scss/**/*.scss',
]).on('change', reload)
}
function styleVersion() {
const thisVersion = styleSheet + '?v=' + currentDate
return gulp
.src(`${buildFolder}header.php`)
.pipe(replace(styleSheet, thisVersion))
.pipe(gulp.dest(buildFolder))
}
async function build() {
await sassy();
console.log('Compiled Sass')
await buildFiles.folders.forEach(file => {
gulp.src(`${file}/*`)
.pipe(gulp.dest(`${buildFolder}${file}`))
console.log(`Copied ${file}/`)
})
await buildFiles.files.forEach(file => {
gulp.src(`./${file}`)
.pipe(gulp.dest(buildFolder))
console.log(`Copied ${file}`)
})
setTimeout(() => {
styleVersion();
console.log(`Added version to css file`)
}, 2000)
setTimeout(() => {
return gulp.src(`${buildFolder}**`)
.pipe(zip(`${process.env.THEME_NAME}.zip`))
.pipe(gulp.dest('.'))
}, 4000)
// if(gulp.src(`${buildFolder}**`).length) {
// console.log('folder is there')
// return gulp.src(`${buildFolder}**`)
// .pipe(zip(`${process.env.THEME_NAME}.zip`))
// .pipe(gulp.dest('.'))
// }
// else {
// console.log('folder not there yet')
// }
}
exports.sassy = sassy
exports.watch = watch
exports.styleVersion = styleVersion
exports.build = build