-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.js
134 lines (115 loc) · 3.13 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
const path = require('path');
const gulp = require('gulp');
const zip = require('gulp-zip');
const del = require('del');
const changeFileContent = require('gulp-change-file-content');
const yargs = require('yargs/yargs');
const parseVersionString = require('parse-version-string').default;
const pkg = require('./package.json');
const currentVersion = pkg.version;
const currentVersionData = parseVersionString(pkg.version);
const bumpFiles = {
// Version in the package file.
'./package.json': /("version": ")[0-9][0-9.a-zA-Z-]*(",$)/gm,
// Version in the readme file.
'./readme.txt': /(^\* Stable tag: )[0-9][0-9.a-zA-Z-]*($)/gm,
'./class-ghost-kit.php': [
// Version in the file header.
/(\* Version:\s\s+)[0-9][0-9.a-zA-Z-]*($)/gm,
// Version in the constant definition.
/(define\( 'GHOSTKIT_VERSION', ').*(' \);$)/gm,
],
};
const zipPluginName = 'ghostkit';
const zipDist = 'dist-zip';
const zipFiles = [
'assets/**/*',
'build/**/*',
'classes/**/*',
'composer-libraries/**/*',
'gutenberg/**/*',
'languages/**/*',
'settings/**/*',
'index.php',
'class-ghost-kit.php',
'LICENSE.txt',
'readme.txt',
'wpml-config.xml',
];
// Bump current version number.
// gulp bump --type major : bumps 1.0.0
// gulp bump --type minor : bumps 0.1.0
// gulp bump --type patch : bumps 0.0.2
// gulp bump --type prerelease : bumps 0.0.1-alpha.2
gulp.task('bump', (done) => {
let newVersion = '';
const { argv } = yargs(process.argv.slice(2));
const { major, minor, preReleaseType, preReleaseIncrement } =
currentVersionData;
let { patch } = currentVersionData;
switch (argv.type) {
case 'major':
newVersion = `${(major || 0) + 1}.0.0`;
break;
case 'minor':
newVersion = `${major || 0}.${(minor || 0) + 1}.0`;
break;
case 'prerelease':
if (!preReleaseIncrement) {
patch = (patch || 0) + 1;
}
newVersion = `${major || 0}.${minor || 0}.${patch || 0}-${
preReleaseType || 'alpha'
}.${(preReleaseIncrement || 0) + 1}`;
break;
// patch
default:
newVersion = `${major || 0}.${minor || 0}.${(patch || 0) + 1}`;
break;
}
Object.keys(bumpFiles).forEach((src) => {
gulp.src(src)
.pipe(
changeFileContent((content) => {
if (!Array.isArray(bumpFiles[src])) {
bumpFiles[src] = [bumpFiles[src]];
}
bumpFiles[src].forEach((reg) => {
content = content.replace(reg, `$1${newVersion}$2`);
});
return content;
})
)
.pipe(
gulp.dest((file) => {
return path.dirname(file.path);
})
);
});
// eslint-disable-next-line no-console
console.log(
`Bumped version from %cv${currentVersion}%c to %cv${newVersion}`,
'color: #f08d49',
'',
'color: #7ec699'
);
done();
});
gulp.task('zip-clean', () => {
return del(`${zipDist}/**`, { force: true });
});
gulp.task('zip-copy-files', () => {
return gulp
.src(zipFiles, { base: './' })
.pipe(gulp.dest(`dist-zip/${zipPluginName}`));
});
gulp.task('zip-pack', () => {
return gulp
.src(`${zipDist}/**/*`, {
nodir: true,
base: zipDist,
})
.pipe(zip(`${zipPluginName}.zip`))
.pipe(gulp.dest(zipDist));
});
gulp.task('zip', gulp.series('zip-clean', 'zip-copy-files', 'zip-pack'));