-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
154 lines (138 loc) · 3.07 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
/**
* Supported Packages
* List here all dependencies necessary to run required tasks.
*
* @since 1.0.0
*/
const fs = require("fs");
const gulp = require("gulp");
const clean = require("gulp-clean");
const copy = require("gulp-copy");
const archiver = require("gulp-archiver");
const makepot = require("gulp-wp-pot");
const gettext = require("gulp-gettext");
const phpcs = require("gulp-phpcs"); // @todo: Include in a `test` task
const phpunit = require("gulp-phpunit"); // @todo: Include in a `test` task
/**
* Package (pkg)
*
* @desc Call `package.json` file.
*
* @since 1.0.0
*/
const pkg = require("./package.json");
/**
* Development Paths & Files
*
* @since 1.0.0
*/
const srcFiles = {
phpcs: ["leighton-quito.php", "leighton-quito-loader.php"],
makepot: ["leighton-quito.php", "leighton-quito-loader.php", "includes/**/*.php", "api/**/*.php"],
};
/**
* Makepot
*
* @desc Gulp task to create POT files.
*
* @since 1.0.0
*/
gulp.task("makepot", () =>
gulp
.src(srcFiles.makepot)
.pipe(
makepot({
domain: pkg.name,
package: "Leighton Quito",
bugReport: "https://github.com/iamleigh/leighton-quito-amp/issues",
metadataFile: "leighton-quito.php",
})
)
.pipe(gulp.dest(`languages/${pkg.name}.pot`))
);
/**
* Get Text
*
* @desc Grab languages files.
*
* @since 1.0.0
*/
gulp.task("gettext", () => gulp.src("languages/*.po").pipe(gettext()).pipe(gulp.dest("languages")));
/**
* Translate (i18n)
*
* @desc Run `makepot` and `gettext` tasks in parallel.
*
* @since 1.0.0
*/
gulp.task("i18n", gulp.parallel(["makepot", "gettext"]));
/**
* Package
*
* @desc Pack the plugin for release.
*
* @since 1.0.0
*/
gulp.task(
"package",
gulp.series(
() => gulp.src(["dist", pkg.name, `${pkg.name}.*.zip`], { read: false, allowEmpty: true }).pipe(clean()),
() =>
gulp
.src([
"leighton-quito.php",
"leighton-quito-loader.php",
"uninstall.php",
"LICENSE",
"README.md",
"api/**/*",
"assets/css/**/*",
"assets/images/**/*",
"assets/js/**/*",
"languages/**",
"includes/**/*",
"vendor/autoload.php",
"vendor/bin/**/*",
"vendor/composer/**/*",
"vendor/myclabs/**/*",
])
.pipe(copy(pkg.name)),
() =>
gulp
.src(pkg.name + "/**/*", { base: "." })
.pipe(archiver(`${pkg.name}.${pkg.version}.zip`))
.pipe(gulp.dest(".")),
(done) =>
fs.rename(pkg.name, "dist", (err) => {
if (err) throw err;
done();
})
)
);
/**
* Challenge Package
*
* @desc Pack the plugin to submit for challenge.
*
* @since 1.0.0
*/
gulp.task(
"challenge",
gulp.series(
() =>
gulp
.src(["challenge", pkg.name, `${pkg.name}-challenge.*.zip`], { read: false, allowEmpty: true })
.pipe(clean()),
() => gulp.src(["**/*", "!dist/**/*", "!challenge/**/*", "!node_modules/**/*"]).pipe(copy(pkg.name)),
() =>
gulp
.src(pkg.name + "/**/*", { base: "." })
.pipe(archiver(`${pkg.name}-challenge.${pkg.version}.zip`))
.pipe(gulp.dest(".")),
(done) =>
fs.rename(pkg.name, "challenge", (err) => {
if (err) throw err;
done();
})
)
);