-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
102 lines (90 loc) · 2.36 KB
/
gulpfile.js
File metadata and controls
102 lines (90 loc) · 2.36 KB
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
const gulp = require("gulp");
const browserSync = require("browser-sync").create();
const fs = require("fs");
const packageJson = require("./package.json");
// Paths
const paths = {
images: "assets/images/**/*",
dist: {
images: "assets/images",
},
};
// BrowserSync
function browserSyncInit() {
browserSync.init({
proxy: process.env.WP_HOME || "http://localhost:10000",
files: ["./**/*.php", "./assets/js/dist/*.js", "./assets/css/*.css"],
injectChanges: true,
notify: false,
open: false,
});
}
// Image optimization
async function optimizeImages() {
const imagemin = (await import("gulp-imagemin")).default;
return gulp
.src(paths.images)
.pipe(imagemin())
.pipe(gulp.dest(paths.dist.images))
.pipe(browserSync.stream());
}
// Version sync
function syncVersion() {
const version = packageJson.version;
// Update style.css
const styleContent = `/*
Theme Name: WordPress Theme Starter Pack
Theme URI: https://your-website.com
Author: Your Name
Author URI: https://your-website.com
Version: ${version}
Text Domain: wptsp
*/`;
fs.promises.writeFile("style.css", styleContent);
// Update theme.json if it exists
try {
const themeJson = require("./theme.json");
themeJson.version = version;
fs.promises.writeFile("theme.json", JSON.stringify(themeJson, null, 2));
} catch (e) {
// theme.json doesn't exist, that's fine
}
}
// Create theme zip
async function createZip() {
const themeName = "wptsp";
const version = packageJson.version;
const outputName = `${themeName}-${version}.zip`;
const zip = (await import("gulp-zip")).default;
return gulp
.src([
"**/*",
"!node_modules/**",
"!assets/js/src/**",
"!assets/scss/**",
"!gulpfile.js",
"!package.json",
"!package-lock.json",
"!.git/**",
"!.gitignore",
"!scripts/**",
"!webpack.config.js",
"!CHANGELOG.md",
])
.pipe(zip(outputName))
.pipe(gulp.dest("./"));
}
// Watch task
function watch() {
gulp.watch(paths.images, optimizeImages);
}
// Export tasks
exports.images = optimizeImages;
exports.zip = createZip;
exports["version-sync"] = syncVersion;
exports.watch = watch;
exports.browserSync = browserSyncInit;
// Default task (development)
exports.default = gulp.parallel(watch, browserSyncInit);
// Build task
exports.build = gulp.series(optimizeImages);