Skip to content

Commit 679b042

Browse files
committed
Noved 'rename' from script to Gulp task
1 parent 7abdca0 commit 679b042

4 files changed

Lines changed: 59 additions & 16 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ config.rb
3939

4040
# Composer #
4141
############
42-
!assets/js/vendor/
42+
!src/js/vendor/
4343
wpcs/
4444
composer.lock
4545

@@ -63,6 +63,9 @@ node_modules
6363

6464
# Development - Remove if you want them included in your own plugin repo #
6565
##########################################################################
66+
languages/*.pot
67+
languages/*.po
68+
languages/*.mo
6669
vendor/
6770
assets/css/**/*.css
6871
assets/css/**/*.map

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ It may also be used as the means of [separating custom code](http://www.billeric
2121
* Configuration registry ([docs](https://github.com/dmhendricks/wordpress-toolkit/wiki/ConfigRegistry)) and optional `wp-config.php` [Constants](https://github.com/dmhendricks/wordpress-base-plugin/wiki/Configuration-&-Constants)
2222
* [More to come...](#planned-features)
2323

24+
**Note:** Gulp and Bower are optional, but handy. If you do not wish to use them, you can delete the references.
25+
26+
2427
## Requirements
2528

2629
* WordPress 4.0 or higher
@@ -57,10 +60,9 @@ This plugin loads many of its defaults & settings from `plugin.json`. See [Confi
5760

5861
## Planned Features & TODO
5962

60-
#### Before 0.3.0 Pre-Release
63+
#### 0.3.0 Pre-Release
6164

6265
* Add gulp task to package plugin as ZIP file
63-
* Move NPM scripts to gulp tasks
6466

6567
#### Future Releases
6668

@@ -75,6 +77,7 @@ Release changes are noted on the [Releases](https://github.com/dmhendricks/wordp
7577

7678
* Bumped minimum PHP version check to 5.6
7779
* Added [Gulp](https://gulpjs.com/) for task automation (SASS, JS processing)
80+
* Added `gulp rename` task ([notes](https://github.com/dmhendricks/wordpress-base-plugin/wiki#rename-files-and-strings))
7881
* Added [Bower](https://bower.io/) to (optionally) load third-party scripts
7982
* Drastically refactored configuration management
8083
* Split out settings pages, shortcodes, CPT & widgets into separate files/classes (thanks [obstschale](https://github.com/obstschale/wordpress-base-plugin))

gulpfile.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
* @version 1.0.3
1212
*/
1313

14+
var pkg = require('./package.json');
15+
1416
/**
1517
* Configuration
1618
*
1719
* In paths you can add <<glob or array of globs>>. Edit the variables as per your project requirements.
1820
*/
19-
var project = 'wordpress-base-plugin'; // Project slug
21+
var project = pkg.name; // Project slug
2022
var cssOutputStyle = 'expanded'; // Values: compact, compressed, nested, expanded
2123
var cssOutputCoumments = false; // Output SASS source/line numbers in compiled CSS files
2224

@@ -57,9 +59,15 @@ var jsTasks = [
5759
}
5860
];
5961

60-
// Arrays to hold created task info
61-
var tasks_css = [];
62-
var tasks_js = [];
62+
63+
/* Define strings to replace using 'gelp rename', defined in the config section of package.json */
64+
var renameStrings = [
65+
[ 'dmhendricks\/wordpress-base-plugin', pkg.config.username + '/' + pkg.name ], // Git/Composer identifier
66+
[ 'wordpress-base-plugin', pkg.name ], // Plugin slug
67+
[ 'VendorName\\PluginName', pkg.config.php_namespace ], // PHP namespace for your plugin
68+
[ 'VendorName\\\\PluginName', pkg.config.php_namespace.replace(/\\/g, '\\\\') ], // Rename Composer namespace
69+
[ 'WPBP_NS', pkg.config.javascript_object ] // Unique JavaScript object for your plugin
70+
];
6371

6472
/**
6573
* Browsers for which you want to enable autoprefixing.
@@ -84,6 +92,7 @@ const AUTOPREFIXER_BROWSERS = [
8492
* Load gulp plugins and pass them semantic names.
8593
*/
8694
var gulp = require('gulp');
95+
var pkg = require('./package.json');
8796

8897
// CSS-related plugins
8998
var sass = require('gulp-sass'); // Gulp pluign for Sass compilation.
@@ -96,11 +105,19 @@ var concat = require('gulp-concat'); // Concatenates JS files
96105
var uglify = require('gulp-uglify'); // Minifies JS files
97106

98107
// Utility related plugins.
99-
var rename = require('gulp-rename'); // Renames files E.g. style.css -> style.min.css
108+
var rename = require('gulp-rename'); // Renames files (ex: style.css -> style.min.css)
109+
var replace = require('gulp-batch-replace'); // Replace strings inside files
100110
var lineec = require('gulp-line-ending-corrector'); // Consistent Line Endings for non UNIX systems. Gulp Plugin for Line Ending Corrector (A utility that makes sure your files have consistent line endings)
101111
var filter = require('gulp-filter'); // Enables you to work on a subset of the original files by filtering them using globbing.
102112
var sourcemaps = require('gulp-sourcemaps'); // Maps code in a compressed file (E.g. style.css) back to it’s original position in a source file (E.g. structure.scss, which was later combined with other css files to generate style.css)
103-
var notify = require('gulp-notify'); // Sends message notification to you
113+
var notify = require('gulp-notify'); // Displays notification message
114+
var batchRename = require('gulp-simple-rename'); // Rename files with wildcard
115+
var vinylPaths = require('vinyl-paths');
116+
var del = require('del'); // Delete files that are renamed
117+
118+
/* Arrays to hold created task info */
119+
var tasks_css = [];
120+
var tasks_js = [];
104121

105122
/**
106123
* Style tasks
@@ -210,6 +227,22 @@ gulp.task( 'default', object_property_to_array( tasks_js, 'id', tasks_css ), fun
210227

211228
});
212229

230+
/**
231+
* Task to rename files and variables
232+
*/
233+
gulp.task( 'rename', function () {
234+
235+
return gulp.src( [ './**/*.php', './*.json', './**/*.js', './**/*.scss', './*.txt', '!./node_modules/**', '!./vendor/**', '!./.git/**', '!./languages/**', '!./*lock*', '!./gulpfile.js' ] )
236+
.pipe( replace( renameStrings ) )
237+
.pipe( vinylPaths( del ) )
238+
.pipe( batchRename( function (path) {
239+
return path.replace( /wordpress-base-plugin/, pkg.name );
240+
} ) )
241+
.pipe( gulp.dest( './' ) )
242+
.pipe( notify( { message: 'TASK: "rename" completed.', onLast: true } ) );
243+
244+
});
245+
213246
/**
214247
* Helper functions
215248
*/

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
"author": "Daniel M. Hendricks",
44
"license": "GPL-2.0",
55
"config": {
6-
"slug": "wordpress-base-plugin",
7-
"namespace": "VendorName\\PluginName",
6+
"username": "dmhendricks",
7+
"php_namespace": "VendorName\\PluginName",
88
"javascript_object": "WPBP_NS"
99
},
1010
"scripts": {
11-
"translate": "wp-pot -s 'app/**/*.php' -o ./languages/$npm_package_config_slug.pot -p $npm_package_config_slug",
12-
"rename": "replace $npm_package_name $npm_package_config_slug . -r --exclude='node_modules,vendor,package.json'; replace 'VendorName\\\\PluginName' $npm_package_config_namespace . -r --exclude='node_modules,vendor,package.json'; replace 'WPBP_NS' $npm_package_config_javascript_object . -r --include='assets,src'; renamer -v --find $npm_package_name --replace $npm_package_config_slug *.*; renamer -v --find $npm_package_name --replace $npm_package_config_slug ./assets/js/**;"
11+
"translate": "wp-pot -s 'app/**/*.php' -o ./languages/$npm_package_name.pot -p $npm_package_config_slug"
1312
},
1413
"devDependencies": {
1514
"gulp": "^3.9.1",
@@ -24,9 +23,14 @@
2423
"gulp-sourcemaps": "^1.5.2",
2524
"gulp-uglify": "^1.5.3",
2625
"gulp-uglifycss": "^1.0.6",
27-
"gulp-sort": "^2.0.0",
26+
"gulp-batch-replace": "*",
27+
"gulp-simple-rename": "^0.1.3",
28+
"vinyl-paths": "^2.1.0",
2829
"wp-pot-cli": "^1.0",
29-
"replace": "^0.3.0",
30-
"renamer": "^0.6.0"
30+
"del": "^3.0"
31+
},
32+
"repository": {
33+
"type": "git",
34+
"url": "git://github.com/dmhendricks/my-plugin.git"
3135
}
3236
}

0 commit comments

Comments
 (0)