Skip to content

Instantly share code, notes, and snippets.

@nathanieltubb
Forked from yosukehasumi/rare.sh
Created July 13, 2017 17:29
Show Gist options
  • Save nathanieltubb/43b86d3f056bf2b8148e21c7756bfece to your computer and use it in GitHub Desktop.
Save nathanieltubb/43b86d3f056bf2b8148e21c7756bfece to your computer and use it in GitHub Desktop.
Create a new wordpress boilerplate theme
#!/usr/bin/env bash
VERSION=2.0.13;
# Download this file, rename it to "rare", and place it in your bin directory (for mac it'll be something like usr/local/bin/rare).
# For OSX you could try this CURL command to install it:
# curl https://gist.githubusercontent.com/yosukehasumi/d0c905da78229122e7c1bb34a0fc92a7/raw/rare.sh > /usr/local/bin/rare;
# sudo chmod 755 /usr/local/bin/rare;
#
# To use this script, cd into your project directory and in command line type:
# rare install wp [theme_name] => downloads wp, boiler-plate theme, and installs precompilers, including gulp and dploy
# rare install compilers [path] => downloads and installs scss and coffeescript boilerplate and installs gulp with its node_modules
# rare server => starts gulp
# rare deploy => deploys a project to your server
# https://github.com/yosukehasumi/boiler-theme
# https://gist.github.com/yosukehasumi/d21f3ed89171ea5fc234
#
# This should work in OSX, not tested anywhere else.
#=======================================================================================
installwp() {
THEMENAME="$1";
THEMEDIR="wordpress/wp-content/themes/$THEMENAME";
# download the latest wordpress and unpackage it
curl -L "http://wordpress.org/latest.tar.gz" | tar xz;
# clone my boiler-theme repo
git clone https://github.com/yosukehasumi/boiler-theme.git;
# remove any git references
rm -rf boiler-theme/.git boiler-theme/.gitignore;
# move the boiler-theme to it's new location
mv boiler-theme $THEMEDIR;
# add the theme name to style.scss and save it as tmpfile.scss
sed "s/boiler-theme/$THEMENAME/g" "$THEMEDIR/scss/style.scss" > "$THEMEDIR/scss/tmpfile.scss";
# remove the old style.scss
rm "$THEMEDIR/scss/style.scss";
# move tmpfile.scss to style.scss
mv "$THEMEDIR/scss/tmpfile.scss" "$THEMEDIR/scss/style.scss";
# move the sample.gitignore to .gitignore in the root of the site
mv "$THEMEDIR/sample.gitignore" "wordpress/.gitignore";
# unzip acf
unzip "$THEMEDIR/advanced-custom-fields-pro.zip" -d "wordpress/wp-content/plugins/";
#remove acf package
rm "$THEMEDIR/advanced-custom-fields-pro.zip";
# remove hello plugin
rm "wordpress/wp-content/plugins/hello.php";
# grab sample gulpfile from boiler theme
mv "$THEMEDIR/sample.gulpfile.js" "wordpress/gulpfile.js";
# cd into the root of the site and link node_modules
cd wordpress;
npm install gulp gulp-util gulp-sass gulp-autoprefixer gulp-coffee gulp-clean-css gulp-uglify gulp-babel gulp-concat merge2 babel-preset-es2015 --save-dev
# add the stylesheet_dir variable in the gulpfile
echo "var stylesheet_dir = \"wp-content/themes/$THEMENAME\"" | cat - gulpfile.js > temp && mv temp gulpfile.js;
}
#=======================================================================================
installtheme() {
THEMENAME="$1";
THEMEDIR="wp-content/themes/$THEMENAME";
# clone my boiler-theme repo
git clone https://github.com/yosukehasumi/boiler-theme.git;
# remove any git references
rm -rf boiler-theme/.git boiler-theme/.gitignore;
# move the boiler-theme to it's new location
mv boiler-theme $THEMEDIR;
# add the theme name to style.scss and save it as tmpfile.scss
sed "s/YourCustomThemeName/$THEMENAME/g" "$THEMEDIR/scss/style.scss" > "$THEMEDIR/scss/tmpfile.scss";
# remove the old style.scss
rm "$THEMEDIR/scss/style.scss";
# move tmpfile.scss to style.scss
mv "$THEMEDIR/scss/tmpfile.scss" "$THEMEDIR/scss/style.scss";
# unzip acf
unzip "$THEMEDIR/advanced-custom-fields-pro.zip" -d "wp-content/plugins/";
# grab sample gulpfile from boiler theme
mv "$THEMEDIR/sample.gulpfile.js" "wordpress/gulpfile.js";
# install node_modules
npm install gulp gulp-util gulp-sass gulp-autoprefixer gulp-coffee gulp-clean-css gulp-uglify gulp-babel gulp-concat merge2 babel-preset-es2015 --save-dev
# add the stylesheet_dir variable in the gulpfile
echo "var stylesheet_dir = \"wp-content/themes/$THEMENAME\"" | cat - gulpfile.js > temp && mv temp gulpfile.js;
}
#=======================================================================================
# installcompilers() {
# THEMEDIR="$1";
# # clone my boiler-theme repo
# git clone https://github.com/yosukehasumi/boiler-theme.git;
# # move just the boiler-theme js and scss to it's new location
# mv boiler-theme/js $THEMEDIR;
# mv boiler-theme/scss $THEMEDIR;
# # remove boiler-theme
# rm -rf boiler-theme
# # grab my gulpfile
# if [ ! -f "gulpfile.js" ]; then
# curl "https://gist.githubusercontent.com/nathanieltubb/43b86d3f056bf2b8148e21c7756bfece/raw/gulpfile.js" -o "gulpfile.js";
# fi
# # install node_modules
# npm install gulp gulp-util gulp-sass gulp-autoprefixer gulp-coffee gulp-clean-css gulp-uglify gulp-babel gulp-concat merge2 babel-preset-es2015 --save-dev
# # add the stylesheet_dir variable in the gulpfile
# echo "var stylesheet_dir = \"$THEMEDIR\"" | cat - gulpfile.js > temp && mv temp gulpfile.js;
# }
#=======================================================================================
server() {
#run gulp
gulp
}
#=======================================================================================
# deploysetup() {
# echo "--------"
# echo "protocol: [ftp sftp]"
# read protocol
# echo "--------"
# echo "host: (example.com)"
# read host
# echo "--------"
# echo "port: (commonly 21 or 22)"
# read port
# echo "--------"
# echo "path: (relative path please)"
# read path
# echo "--------"
# echo "user: [ftp_username]"
# read user
# echo "--------"
# echo "password: [ftp_password]"
# read password
# echo "--------"
# echo "key: [ssh_private_key_name]"
# read key
# echo "--------"
# echo "pubkey: [ssh_public_key_name]"
# read pubkey
# echo "--------"
# echo "You entered"
# echo " protocol: $protocol"
# echo " host: $host"
# echo " port: $port"
# echo " path: $path"
# echo " user: $user"
# echo " password: $password"
# echo " key: $key"
# echo " pubkey: $pubkey"
# echo "is this information correct? [Y/N]"
# read confirm
# if [ "$confirm" == "Y" ] || [ "$confirm" == "y" ]; then
# echo "-------- adding"
# echo " git config git-ftp.$1.url $protocol://$host:$port/$path"
# git config git-ftp."$1".url "$protocol"://"$host":"$port"/"$path"
# echo " git config git-ftp.$1.user $user"
# git config git-ftp."$1".user "$user"
# echo " git config git-ftp.$1.password $password"
# git config git-ftp."$1".password "$password"
# echo " git config git-ftp.$1.key $key"
# git config git-ftp."$1".key "$key"
# echo " git config git-ftp.$1.pubkey $pubkey"
# git config git-ftp."$1".pubkey "$pubkey"
# echo " git config git-ftp.$1.insecure 1"
# git config git-ftp."$1".insecure 1
# echo "--------"
# echo "You can now deploy using this scope:"
# echo " rare deploy $1"
# fi
# }
#=======================================================================================
# deployinit() {
# echo "initializing first deployment to $1"
# git ftp init -s "$1" -v
# }
#=======================================================================================
# deploy() {
# echo "deploying to $1"
# git ftp push -s "$1" -v
# }
#=======================================================================================
update() {
echo 'updating rare...';
echo " location: `which rare`";
echo " version: `rare -v`";
touch $TMPDIR/rare-self-update
sudo chmod 777 $TMPDIR/rare-self-update
echo "#!/usr/bin/env bash
LOCATION=\`which rare\`;
curl https://gist.githubusercontent.com/yosukehasumi/d0c905da78229122e7c1bb34a0fc92a7/raw/rare.sh > \$TMPDIR/rare;
sudo chmod 755 \$TMPDIR/rare;
sudo mv \$TMPDIR/rare \$LOCATION;
echo \" rare has updated to version: \`rare -v\`\";
" > $TMPDIR/rare-self-update
exec $TMPDIR/rare-self-update
}
#=======================================================================================
echohelp() {
echo "------";
echo " rare install wp [theme_name]";
echo " -- run from your web root, will install to ./wordpress";
# echo " rare install compilers [path]";
echo " rare install theme [theme_name]";
echo " -- run from your site root, will install to ./wp-content/themes";
# echo " rare install deployment [scope/environment]";
echo " rare server";
echo " -- runs GULP";
echo " rare update";
echo " -- updates to the latest version of this script";
# echo " rare deploy [scope/environment]";
echo "------";
# echo "For git-ftp deployment information/installation see https://github.com/git-ftp/git-ftp.";
}
#=======================================================================================
if [ "$1" == "install" ]; then
if [ "$2" == "wp" ]; then
if [ -n "$3" ]; then
installwp "$3";
fi
elif [ "$2" == "theme" ]; then
if [ -n "$3" ]; then
installtheme "$3";
fi
elif [ "$2" == "compilers" ]; then
if [ -n "$3" ]; then
installcompilers "$3";
fi
elif [ "$2" == "deployment" ]; then
if [ -n "$3" ]; then
deploysetup "$3";
fi
fi
elif [ "$1" == "server" ] || [ "$1" == "s" ]; then
server;
elif [ "$1" == "deploy" ]; then
if [ "$2" == "init" ]; then
deployinit "$3";
elif [ -n "$2" ]; then
deploy "$2";
fi
elif [ "$1" == "-v" ]; then
echo $VERSION;
elif [ "$1" == "update" ]; then
update;
else
echohelp;
fi
#=======================================================================================
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment