Last active
September 28, 2017 22:04
-
-
Save JPry/843e00c834e54b9b3f021856bfde1e0f to your computer and use it in GitHub Desktop.
Sample mustache files for Gulp scaffolding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require dependencies | |
const del = require( 'del' ); | |
const gulp = require( 'gulp' ); | |
const gutil = require( 'gulp-util' ); | |
const notify = require( 'gulp-notify' ); | |
const plumber = require( 'gulp-plumber' ); | |
const sort = require( 'gulp-sort' ); | |
const textdomain = require( 'gulp-checktextdomain' ); | |
const wpPot = require( 'gulp-wp-pot' ); | |
// Set assets paths. | |
const paths = { | |
'php': [ './*.php', './**/*.php' ] | |
}; | |
/** | |
* Handle errors and alert the user. | |
*/ | |
function handleErrors() { | |
const args = Array.prototype.slice.call( arguments ); | |
notify.onError({ | |
'title': 'Task Failed [<%= error.message %>', | |
'message': 'See console.', | |
'sound': 'Sosumi' // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults | |
}).apply( this, args ); | |
gutil.beep(); // Beep 'sosumi' again. | |
// Prevent the 'watch' task from stopping. | |
this.emit( 'end' ); | |
} | |
/** | |
* Check to ensure the textdomain is present where needed. | |
*/ | |
gulp.task( 'txtdomain', () => | |
gulp.src( paths.php ) | |
.pipe( sort() ) | |
.pipe( textdomain({ | |
text_domain: '{{plugin_slug}}', | |
keywords: [ | |
'__:1,2d', | |
'_e:1,2d', | |
'_x:1,2c,3d', | |
'esc_html__:1,2d', | |
'esc_html_e:1,2d', | |
'esc_html_x:1,2c,3d', | |
'esc_attr__:1,2d', | |
'esc_attr_e:1,2d', | |
'esc_attr_x:1,2c,3d', | |
'_ex:1,2c,3d', | |
'_n:1,2,4d', | |
'_nx:1,2,4c,5d', | |
'_n_noop:1,2,3d', | |
'_nx_noop:1,2,3c,4d' | |
] | |
}) ) | |
); | |
/** | |
* Delete the theme's .pot before we create a new one. | |
*/ | |
gulp.task( 'clean:pot', () => | |
del([ 'languages/{{plugin_slug}}.pot' ]) | |
); | |
/** | |
* Scan the theme and create a POT file. | |
* | |
* https://www.npmjs.com/package/gulp-wp-pot | |
*/ | |
gulp.task( 'wp-pot', [ 'clean:pot' ], () => | |
gulp.src( paths.php ) | |
.pipe( plumber({'errorHandler': handleErrors}) ) | |
.pipe( sort() ) | |
.pipe( wpPot({ | |
'domain': '{{plugin_slug}}', | |
'package': '{{plugin_slug}}' | |
}) ) | |
.pipe( gulp.dest( 'languages/{{plugin_slug}}.pot' ) ) | |
); | |
/** | |
* Create individual tasks. | |
*/ | |
gulp.task( 'i18n', [ 'wp-pot', 'txtdomain' ] ); | |
gulp.task( 'default', [ 'i18n' ] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "{{plugin_slug}}", | |
"version": "0.1.0", | |
"main": "Gulpfile.js", | |
"author": "{{plugin_author}}", | |
"devDependencies": { | |
"del": "~3", | |
"gulp": "~3", | |
"gulp-checktextdomain": "~2", | |
"gulp-notify": "~3", | |
"gulp-plumber": "~1", | |
"gulp-sort": "~2", | |
"gulp-util": "~3", | |
"gulp-wp-pot": "~2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment