Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soderlind/664147138c58a44e7eaa to your computer and use it in GitHub Desktop.
Save soderlind/664147138c58a44e7eaa to your computer and use it in GitHub Desktop.
Automating WordPress plugin updates and releases with Grunt
/*
* Based on http://torquemag.io/automating-wordpress-plugin-updates-releases-grunt/
*
* added:
* copy:svn_assets task
* makepot, creates read-offline.pot
*/
module.exports = function (grunt) {
//setup file list for copying/ not copying for SVN
files_list = [
'**',
'!assets/**', // will be copied in copy:svn_assets below
'!node_modules/**',
'!release/**',
'!.git/**',
'!.sass-cache/**',
'!Gruntfile.js',
'!package.json',
'!.gitignore',
'!.gitmodules',
'!bin/**',
'!tests/**',
'!.gitattributes',
'!.travis.yml',
'!composer.lock',
'!composer.json',
'!CONTRIBUTING.md',
'!git-workflow.md',
'!phpunit.xml.dist'
];
// Project configuration.
grunt.initConfig({
pkg : grunt.file.readJSON( 'package.json' ),
/*
glotpress_download : {
core : {
options : {
domainPath : 'languages',
url : 'http://wp-translate.org',
slug : 'read-offline',
textdomain : 'read-offline'
}
}
},
*/
clean: {
post_build: [
'build'
],
shortcake: [
'tmp'
]
},
copy: {
svn_assets: {
options : {
mode :true
},
expand: true,
cwd: 'assets/',
src: '**',
dest: 'build/<%= pkg.name %>/assets/',
flatten: true,
filter: 'isFile'
},
svn_trunk: {
options : {
mode :true
},
src: files_list,
dest: 'build/<%= pkg.name %>/trunk/'
},
svn_tag: {
options : {
mode :true
},
src: files_list,
dest: 'build/<%= pkg.name %>/tags/<%= pkg.version %>/'
},
shortcake: {
options : {
mode :true
},
expand: true,
cwd: 'tmp/shortcake',
src: [
'inc/**',
'js/**',
'css/**'
],
dest: ''
}
},
gittag: {
addtag: {
options: {
tag: '2.x/<%= pkg.version %>',
message: 'Version <%= pkg.version %>'
}
}
},
gitcommit: {
commit: {
options: {
message: 'Version <%= pkg.version %>',
noVerify: true,
noStatus: false,
allowEmpty: true
},
files: {
src: [ 'README.md', 'readme.txt', 'read-offline.php', 'package.json', 'Gruntfile.js','assets/**', 'inc/**', 'languages/**', 'lib/**', 'templates/**' ]
}
}
},
gitpush: {
push: {
options: {
tags: true,
remote: 'origin',
branch: 'master'
}
}
},
gitclone: {
shortcake: {
options: {
repository: 'https://github.com/fusioneng/Shortcake.git',
directory: 'tmp/shortcake'
}
}
},
replace: {
reamde_md: {
src: [ 'README.md' ],
overwrite: true,
replacements: [{
from: /~Current Version:\s*(.*)~/,
to: "~Current Version: <%= pkg.version %>~"
}, {
from: /Latest Stable Release:\s*\[(.*)\]\s*\(https:\/\/github.com\/soderlind\/read-offline\/releases\/tag\/(.*)\s*\)/,
to: "Latest Stable Release: [<%= pkg.git_tag %>](https://github.com/soderlind/read-offline/releases/tag/<%= pkg.git_tag %>)"
}]
},
reamde_txt: {
src: [ 'readme.txt' ],
overwrite: true,
replacements: [{
from: /Stable tag: (.*)/,
to: "Stable tag: <%= pkg.version %>"
}]
},
plugin_php: {
src: [ 'read-offline.php' ],
overwrite: true,
replacements: [{
from: /Version:\s*(.*)/,
to: "Version: <%= pkg.version %>"
}, {
from: /define\(\s*'READOFFLINE_VERSION',\s*'(.*)'\s*\);/,
to: "define( 'READOFFLINE_VERSION', '<%= pkg.version %>' );"
}]
}
},
svn_checkout: {
make_local: {
repos: [
{
path: [ 'release' ],
repo: 'http://plugins.svn.wordpress.org/read-offline'
}
]
}
},
push_svn: {
options: {
remove: true
},
main: {
src: 'release/<%= pkg.name %>',
dest: 'http://plugins.svn.wordpress.org/read-offline',
tmp: 'build/make_svn'
}
},
makepot: {
target: {
options: {
domainPath: '/languages',
mainFile: 'read-offline.php',
potFilename: 'read-offline.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
},
processPot: function( pot, options ) {
pot.headers['report-msgid-bugs-to'] = 'https://github.com/soderlind/read-offline/issues';
/*pot.headers['language-team'] = 'Team Name <team@example.com>';*/
return pot;
},
type: 'wp-plugin',
updateTimestamp: true,
exclude: [
'lib/.*',
'node_modules/.*'
],
}
}
}, //makepot
});
//load modules
// grunt.loadNpmTasks( 'grunt-glotpress' );
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.loadNpmTasks( 'grunt-git' );
grunt.loadNpmTasks( 'grunt-text-replace' );
grunt.loadNpmTasks( 'grunt-svn-checkout' );
grunt.loadNpmTasks( 'grunt-push-svn' );
grunt.loadNpmTasks( 'grunt-remove' );
grunt.loadNpmTasks( 'grunt-wp-i18n' )
grunt.registerTask('syntax', 'default task description', function(){
console.log('Syntax:\n\tgrunt release');
});
//register default task
// grunt.registerTask( 'default', [ 'glotpress_download' ]);
grunt.registerTask( 'default', ['syntax']);
// get the latest version of Shortcake
grunt.registerTask( 'shortcake', ['gitclone:shortcake', 'copy:shortcake', 'clean:shortcake']);
// makepot
grunt.registerTask('l10n', ['makepot']);
//release tasks
grunt.registerTask( 'version_number', [ 'replace:reamde_md', 'replace:reamde_txt', 'replace:plugin_php' ] );
// grunt.registerTask( 'pre_vcs', [ 'version_number', 'glotpress_download' ] );
grunt.registerTask( 'pre_vcs', [ 'version_number', 'l10n'] );
grunt.registerTask( 'do_svn', [ 'svn_checkout', 'copy:svn_assets', 'copy:svn_trunk', 'copy:svn_tag', 'push_svn' ] );
grunt.registerTask( 'do_git', [ 'gitcommit', 'gittag', 'gitpush' ] );
grunt.registerTask( 'release', [ 'pre_vcs', 'do_svn', 'do_git', 'clean:post_build' ] );
};
@soderlind
Copy link
Author

Here's the package.json loaded in line 36

{
  "name": "read-offline",
  "title": "Read Offline",
  "version": "0.2.8",
  "git_tag": "0.2.8",
  "description": "Read Offline allows you to download or print posts and pages. You can download the posts as PDF, ePub or mobi",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "repository": {
    "type": "git",
    "url": "git://github.com/soderlind/read-offline.git"
  },
  "license": "GPL",
  "bugs": {
    "url": "https://github.com/soderlind/read-offline/issues"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-cli": "~0.1.13",
    "grunt-composer": "^0.4.4",
    "grunt-contrib-clean": "^0.6.0",
    "grunt-contrib-copy": "^0.7.0",
    "grunt-git": "^0.3.4",
    "grunt-push-svn": "^0.2.1",
    "grunt-remove": "^0.1.0",
    "grunt-svn-checkout": "^0.1.1",
    "grunt-text-replace": "^0.4.0",
    "grunt-wp-i18n": "^0.5.0"
  }
}

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