Skip to content

Instantly share code, notes, and snippets.

@mariojankovic
Forked from mackensen/gulpfile.js
Created July 3, 2018 21:11
Show Gist options
  • Save mariojankovic/2a259cdb92863f95e393e561c9f3d622 to your computer and use it in GitHub Desktop.
Save mariojankovic/2a259cdb92863f95e393e561c9f3d622 to your computer and use it in GitHub Desktop.
This is an example gulpfile for managing a WordPress theme with a custom (non-LESS) CSS stylesheet. It includes tools for bumping the version and updating the version references.
// List of modules used.
var gulp = require('gulp'),
bump = require('gulp-bump'), // Generates new version.
argv = require('yargs')
.default('release', 'patch')
.argv, // CLI parser.
fs = require('fs'), // Used by bump.
semver = require('semver'), // Used by bump.
git = require('gulp-git'), // Git wrapper.
jshint = require('gulp-jshint'), // Lints JS.
phplint = require('phplint'), // Lints PHP.
replace = require('gulp-replace'); // Text replacer.
// Parses the package.json file. We use this because its values
// change during execution.
var getPackageJSON = function() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
};
// Lint associated PHP files.
gulp.task('phplint', function() {
return phplint(['*.php', './functions/**/*.php']);
});
// Lint associated Javascripts.
gulp.task('scripts', function() {
gulp.src('./gulpfile.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest('./'));
gulp.src('./javascripts/global.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest('./javascripts'));
});
// Integration task. Bumps version and commits.
// Tagging is separate.
gulp.task('integrate', function() {
var pkg = getPackageJSON();
var newversion = semver.inc(pkg.version, argv.release);
var banner = ['/*',
'Theme Name: ' + pkg.description,
'Theme URI: '+ pkg.uri,
'Author: '+ pkg.author,
'Version: '+ newversion,
'License: '+ pkg.license,
'License URI: '+ pkg.licenseuri,
'*/',
''].join('\n');
gulp.src('./package.json')
.pipe(bump({version: newversion}))
.pipe(gulp.dest('./'));
gulp.src(['./functions.php'])
.pipe(replace(pkg.version, newversion))
.pipe(gulp.dest('./'));
fs.writeFile('./style.css', banner);
gulp.src(['package.json','style.css','functions.php'])
.pipe(git.commit(pkg.description + ' v' + newversion, {cwd: './'}));
});
// Tags. Run this after integrating.
gulp.task('tag', function() {
var pkg = getPackageJSON();
git.tag('v'+pkg.version, pkg.description + ' v' + pkg.version, function(err) {
});
});
// Watch tasks.
gulp.task('watch', function() {
gulp.watch(['*.php', './functions/**/*.php'],['phplint']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment