Skip to content

Instantly share code, notes, and snippets.

@jayj
Last active March 13, 2022 16:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayj/93884eb56105dd5f7567 to your computer and use it in GitHub Desktop.
Save jayj/93884eb56105dd5f7567 to your computer and use it in GitHub Desktop.
Using Grunt to automate theme releases
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
// Bump version numbers
version: {
css: {
options: {
prefix: 'Version\\:\\s'
},
src: [ 'style.scss' ],
},
php: {
options: {
prefix: '\@version\\s+'
},
src: [ 'functions.php' ],
}
},
// Commit and tag the new version
gitcommit: {
version: {
options: {
message: 'New version: <%= pkg.version %>'
},
files: {
src: ['style.css', 'package.json', 'functions.php']
}
}
},
gittag: {
version: {
options: {
tag: '<%= pkg.version %>',
message: 'Tagging version <%= pkg.version %>'
}
}
},
gitpush: {
version: {},
tag: {
options: {
tags: true
}
}
},
// Clean the build folder
clean: {
build: {
src: ['build/']
}
},
// Copy to build folder
copy: {
build: {
src: ['**', '!node_modules/**', '!Gruntfile.js', '!package.json'],
dest: 'build/',
},
},
// Minify CSS files into NAME-OF-FILE.min.css
cssmin: {
build: {
expand: true,
src: ['*.css', '!*.min.css'],
dest: 'build/',
ext: '.min.css'
}
},
// Compress the build folder into an upload-ready zip file
compress: {
build: {
options: {
archive: 'build/<%= pkg.name %>.zip'
},
cwd: 'build/',
src: ['**/*'],
dest: '<%= pkg.name %>/'
}
}
});
// Load all grunt plugins here
grunt.loadNpmTasks('grunt-version');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-cssmin');
// Release task
grunt.registerTask( 'release', [ 'version', 'gitcommit:version', 'gittag:version', 'gitpush:version', 'gitpush:tag' ]);
// Build task
grunt.registerTask( 'build', [ 'clean:build', 'copy:build', 'cssmin:build', 'compress:build' ]);
};
@vburlak
Copy link

vburlak commented May 22, 2015

Beautiful gist. Thx a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment