Some scripts for automating plugin creation in WordPress.
Last active
May 22, 2020 07:20
-
-
Save davilera/b6c2cbf29439443b4ab738a5ec23bf45 to your computer and use it in GitHub Desktop.
Automation Scripts
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
var gulp = require( 'gulp' ), | |
rename = require( 'gulp-rename' ), | |
uglify = require( 'gulp-uglify' ); | |
gulp.task( 'process-js', function() { | |
gulp.src( [ 'admin/js/src/*.js' ] ) | |
.pipe( uglify() ) | |
.pipe( rename( { suffix:'.min' } ) ) | |
.pipe( gulp.dest( 'admin/js/' ) ); | |
}); |
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
( function() { | |
//=include lib/script1.js | |
//=include lib/script2.js | |
// TODO... | |
})(); |
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
var gulp = require( 'gulp' ), | |
include = require( 'gulp-include' ), | |
rename = require( 'gulp-rename' ), | |
uglify = require( 'gulp-uglify' ); | |
gulp.task( 'process-js', function() { | |
gulp.src( [ 'admin/js/src/*.js' ] ) | |
.pipe( include() ) | |
.pipe( uglify() ) | |
.pipe( rename( { suffix:'.min' } ) ) | |
.pipe( gulp.dest( 'admin/js/' ) ); | |
}); |
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
var gulp = require( 'gulp' ), | |
include = require( 'gulp-include' ), | |
cssnano = require( 'cssnano' ), | |
cssnext = require( 'postcss-cssnext' ), | |
rename = require( 'gulp-rename' ), | |
postcss = require( 'gulp-postcss' ), | |
uglify = require( 'gulp-uglify' ); | |
gulp.task( 'process-css', function() { | |
gulp.src( [ 'admin/css/src/*.css' ] ) | |
.pipe( include() ) | |
.pipe( postcss( [ cssnext(), cssnano({ zindex:false }) ] ) ) | |
.pipe( rename( { suffix:'.min' } ) ) | |
.pipe( gulp.dest( 'admin/css/' ) ); | |
} ); |
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
gulp.task( 'watch', function() { | |
// Minify JS and CSS right after run "watch" | |
gulp.start([ | |
'process-js', | |
'process-css' | |
]); | |
// Listen to CSS file changes and minify if there are any | |
gulp.watch([ | |
'admin/css/src/*.css', | |
'admin/css/src/**/*.css' | |
], [ | |
'process-css', | |
]); | |
// Listen to CSS file changes and minify if there are any | |
gulp.watch([ | |
'admin/js/src/*.js', | |
'admin/js/src/**/*.js' | |
], [ | |
'process-js' | |
]); | |
}); |
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
var gulp = require( 'gulp' ), | |
qunit = require( 'gulp-qunit' ), | |
phpunit = require( 'gulp-phpunit' ); | |
gulp.task( 'test:qunit', function() { | |
return gulp.src( './tests/qunit/essential/index.html' ) | |
.pipe( qunit() ); | |
}); | |
gulp.task( 'test:phpunit', function() { | |
var options = { | |
statusLine: false, | |
debug: false | |
}; | |
return gulp.src( '' ) | |
.pipe( phpunit( 'phpunit' ), options ); | |
}); | |
gulp.task( 'test', function() { | |
return gulp.start([ | |
'minify', | |
'test:phpunit', | |
'test:qunit' | |
]); | |
}); |
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
var gulp = require( 'gulp' ), | |
pot = require( 'gulp-wp-pot' ); | |
gulp.task( 'pot', function () { | |
return gulp.src( [ 'admin/**/*.php', 'public/**/*.php', 'includes/**/*.php', '*.php' ] ) | |
.pipe( pot({ | |
domain: 'nelio-content', | |
package: 'Nelio Content' | |
}) ) | |
.pipe( gulp.dest( 'languages/nelio-content.pot' ) ); | |
}); |
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
var gulp = require( 'gulp' ), | |
cssnano = require( 'cssnano' ), | |
cssnext = require( 'postcss-cssnext' ), | |
gulpif = require( 'gulp-if' ), | |
include = require( 'gulp-include' ), | |
qunit = require( 'gulp-qunit' ), | |
rename = require( 'gulp-rename' ), | |
uglify = require( 'gulp-uglify' ), | |
phpunit = require( 'gulp-phpunit' ), | |
postcss = require( 'gulp-postcss' ), | |
wrap = require( 'gulp-wrap' ); | |
var applyMinification = false; | |
// Process and minimize other CSS files | |
// -------------------------------------------------------- | |
gulp.task( 'process-css', function() { | |
gulp.src( [ 'admin/css/src/*.css' ] ) | |
.pipe( include() ) | |
.pipe( include() ) | |
.pipe( gulpif( | |
applyMinification, | |
postcss( [ cssnext(), cssnano({ zindex:false }) ] ) | |
) ) | |
.pipe( gulpif( | |
! applyMinification, | |
postcss( [ cssnext() ] ) | |
) ) | |
.pipe( rename( { suffix:'.min' } ) ) | |
.pipe( gulp.dest( 'admin/css/' ) ); | |
} ); | |
// Process and minimize JS files | |
// -------------------------------------------------------- | |
gulp.task( 'process-js', function() { | |
gulp.src( [ 'admin/js/src/*.js' ] ) | |
.pipe( uglify() ) | |
.pipe( rename( { suffix:'.min' } ) ) | |
.pipe( gulp.dest( 'admin/js/' ) ); | |
}); | |
// Testing | |
// -------------------------------------------------------- | |
gulp.task( 'test:qunit', function() { | |
return gulp.src( './tests/qunit/essential/index.html' ) | |
.pipe( qunit() ); | |
}); | |
gulp.task( 'test:phpunit', function() { | |
var options = { | |
statusLine: false, | |
debug: false | |
}; | |
return gulp.src( '' ) | |
.pipe( phpunit( 'phpunit' ), options ); | |
}); | |
gulp.task( 'test', function() { | |
return gulp.start([ | |
'minify', | |
'test:phpunit', | |
'test:qunit' | |
]); | |
}); | |
// Watch and start | |
// -------------------------------------------------------- | |
gulp.task( 'watch', function() { | |
gulp.start([ | |
'process-js', | |
'process-css' | |
]); | |
gulp.watch([ | |
'admin/css/src/*.css', | |
'admin/css/src/**/*.css' | |
], [ | |
'process-css', | |
]); | |
gulp.watch([ | |
'admin/js/src/*.js', | |
'admin/js/src/**/*.js' | |
], [ | |
'process-js' | |
]); | |
}); | |
gulp.task( 'minify', function() { | |
applyMinification = true; | |
gulp.start([ | |
'process-js', | |
'process-css' | |
]); | |
}); | |
gulp.task( 'default', function() { | |
gulp.start([ | |
'process-js', | |
'process-css' | |
]); | |
}); |
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
#/bin/bash | |
function print_help { | |
cat <<EOT | |
Usage: $0 VERSION SVNDIR | |
EOT | |
} | |
function info { | |
echo -e "\033[0;32mINFO\033[0;0m $1" >&2 | |
} | |
function error { | |
echo -e "\033[0;31mERROR\033[0;0m $1" >&2 | |
} | |
function question { | |
echo -en "\033[0;1m$1\033[0;0m " >&2 | |
} | |
if [ $# -eq 2 ]; | |
then | |
version=$1 | |
svndir=$2 | |
else | |
print_help | |
exit 1 | |
fi | |
if [ $1 == "-h" ] || [ $1 == "--help" ]; | |
then | |
print_help | |
exit | |
fi |
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
# Example: | |
# == Changelog == | |
# = 1.4.2 (November 15, 2017) = | |
# * First change. | |
# * Second change. | |
# ... | |
# | |
# == Upgrade Notice == | |
# Some notice here. | |
# Check if there's a valid Change Log | |
if [ `grep "^= $version" README.txt | wc -l` -eq 0 ]; | |
then | |
error "README doesn't contain a changelog for version \`$version'." | |
exit 4 | |
fi | |
# Ask for the upgrade notice | |
question "Please, specify the Upgrade Notice of version \`$version':" | |
read description | |
# ============================================================================= | |
info "Updating README..." | |
# ============================================================================= | |
# Remove old upgrade notice from README.txt | |
head README.txt -n `grep -n "== Upgrade Notice ==" README.txt | cut -d: -f1` > /tmp/readme.txt | |
# Update release date in change log | |
release_date=`LC_TIME=en_US date "+%B %-d, %Y"` | |
sed /tmp/readme.txt -e "s/^= $version.*=$/= $version ($release_date) =/" > README.txt | |
# Append new upgrade notice | |
cat <<EOT >> README.txt | |
$description | |
EOT |
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
# ============================================================================= | |
info "Minifying CSS and JavaScript files..." | |
# ============================================================================= | |
./node_modules/.bin/gulp minify | |
# ============================================================================= | |
info "Regenerating PO files..." | |
# ============================================================================= | |
php $HOME/vagrant/wordpress/tools/i18n/makepot.php wp-plugin . | |
mv $main_file.pot languages/. | |
# ============================================================================= | |
info "Updating version number in plugin files..." | |
# ============================================================================= | |
sed $main_file -e "s/^ \* Version: .*$/ * Version: $version/" > /tmp/$main_file | |
mv /tmp/$main_file $main_file |
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
# ============================================================================= | |
info "Moving all files to SVN trunk dir..." | |
# ============================================================================= | |
rm -rf $svndir/trunk/* >/dev/null 2>&1 | |
for file in `ls -d * .[a-zA-Z]* | grep -v "node_modules\|mkver\|.git\|.config\|.jscs.json"`; | |
do | |
cp -r $file $svndir/trunk/$file | |
done |
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
# ============================================================================= | |
info "Tagging version \`$version'..." | |
# ============================================================================= | |
rm -rf $svndir/tags/$version >/dev/null 2>&1 | |
pushd $svndir >/dev/null 2>&1 | |
cp -r trunk tags/$version | |
cd tags/$version | |
rm -rf admin/js/src admin/css/src | |
rm -rf bin tests phpunit.xml | |
rm -f .travis.yml gulpfile.js package.json | |
cd ../.. | |
sed tags/$version/README.txt -e "s/^Stable tag:.*$/Stable tag: $version/" > /tmp/readme.txt | |
mv /tmp/readme.txt tags/$version/README.txt | |
popd >/dev/null 2>&1 |
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
# ============================================================================= | |
info "Updating SVN references..." | |
# ============================================================================= | |
pushd $svndir/trunk >/dev/null 2>&1 | |
# Remove empty directories | |
for dir in `find . -type d | sort -r`; | |
do | |
rmdir $dir >/dev/null 2>&1 | |
done | |
# Add new files in SVN | |
for file in `svn st | grep "^?" | sed -e "s/\s\+/:/" | cut -d: -f2`; | |
do | |
svn add $file | |
done | |
# Delete old files from SVN | |
for file in `svn st | grep "^!" | sed -e "s/\s\+/:/" | cut -d: -f2`; | |
do | |
svn delete $file | |
done | |
# Add the new tag to SVN | |
cd .. | |
svn add tags/$version >/dev/null 2>&1 | |
popd >/dev/null 2>&1 |
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
#!/bin/bash | |
function print_help { | |
cat <<EOT | |
Usage: $0 VERSION SVNDIR | |
EOT | |
} | |
function info { | |
echo -e "\033[0;32mINFO\033[0;0m $1" >&2 | |
} | |
function error { | |
echo -e "\033[0;31mERROR\033[0;0m $1" >&2 | |
} | |
function question { | |
echo -en "\033[0;1m$1\033[0;0m " >&2 | |
} | |
if [ $# -eq 2 ]; | |
then | |
version=$1 | |
svndir=$2 | |
else | |
print_help | |
exit 1 | |
fi | |
if [ $1 == "-h" ] || [ $1 == "--help" ]; | |
then | |
print_help | |
exit | |
fi | |
# ============================================================================= | |
# Locating SVN Directory (if any) | |
# ============================================================================= | |
if [ ! -d "$svndir" ]; | |
then | |
error "Target directory \`$svndir' not found." >&2 | |
exit 3 | |
fi | |
# Check if there's a valid Change Log | |
if [ `grep "^= $version" README.txt | wc -l` -eq 0 ]; | |
then | |
error "README doesn't contain a changelog for version \`$version'." | |
exit 4 | |
fi | |
# Ask for the upgrade notice | |
question "Please, specify the Upgrade Notice of version \`$version':" | |
read description | |
# ============================================================================= | |
info "Updating README..." | |
# ============================================================================= | |
# Remove old upgrade notice from README.txt | |
head README.txt -n `grep -n "== Upgrade Notice ==" README.txt | cut -d: -f1` > /tmp/readme.txt | |
# Update release date in change log | |
release_date=`LC_TIME=en_US date "+%B %-d, %Y"` | |
sed /tmp/readme.txt -e "s/^= $version.*=$/= $version ($release_date) =/" > README.txt | |
# Append new upgrade notice | |
cat <<EOT >> README.txt | |
$description | |
EOT | |
# ============================================================================= | |
info "Minifying CSS and JavaScript files..." | |
# ============================================================================= | |
./node_modules/.bin/gulp minify | |
# ============================================================================= | |
info "Regenerating PO files..." | |
# ============================================================================= | |
php $HOME/vagrant/wordpress/tools/i18n/makepot.php wp-plugin . | |
mv $main_file.pot languages/. | |
# ============================================================================= | |
info "Updating version number in plugin files..." | |
# ============================================================================= | |
sed $main_file -e "s/^ \* Version: .*$/ * Version: $version/" > /tmp/$main_file | |
mv /tmp/$main_file $main_file | |
# ============================================================================= | |
info "Moving all files to SVN trunk dir..." | |
# ============================================================================= | |
rm -rf $svndir/trunk/* >/dev/null 2>&1 | |
for file in `ls -d * .[a-zA-Z]* | grep -v "node_modules\|mkver\|.git\|.config\|.jscs.json"`; | |
do | |
cp -r $file $svndir/trunk/$file | |
done | |
# ============================================================================= | |
info "Tagging version \`$version'..." | |
# ============================================================================= | |
rm -rf $svndir/tags/$version >/dev/null 2>&1 | |
pushd $svndir >/dev/null 2>&1 | |
cp -r trunk tags/$version | |
cd tags/$version | |
rm -rf admin/js/src admin/css/src | |
rm -rf bin tests phpunit.xml | |
rm -f .travis.yml gulpfile.js package.json | |
cd ../.. | |
sed tags/$version/README.txt -e "s/^Stable tag:.*$/Stable tag: $version/" > /tmp/readme.txt | |
mv /tmp/readme.txt tags/$version/README.txt | |
popd >/dev/null 2>&1 | |
# ============================================================================= | |
info "Updating SVN references..." | |
# ============================================================================= | |
pushd $svndir/trunk >/dev/null 2>&1 | |
# Remove empty directories | |
for dir in `find . -type d | sort -r`; | |
do | |
rmdir $dir >/dev/null 2>&1 | |
done | |
# Add new files in SVN | |
for file in `svn st | grep "^?" | sed -e "s/\s\+/:/" | cut -d: -f2`; | |
do | |
svn add $file | |
done | |
# Delete old files from SVN | |
for file in `svn st | grep "^!" | sed -e "s/\s\+/:/" | cut -d: -f2`; | |
do | |
svn delete $file | |
done | |
# Add the new tag to SVN | |
cd .. | |
svn add tags/$version >/dev/null 2>&1 | |
popd >/dev/null 2>&1 | |
# ============================================================================= | |
echo "PROCESS COMPLETED!" | |
echo "Don't forget to tag version \`$version' as stable." | |
# ============================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment