{"id":531,"date":"2016-04-05T22:23:11","date_gmt":"2016-04-06T02:23:11","guid":{"rendered":"http:\/\/www.bemdesign.com\/wordpress\/?p=531"},"modified":"2016-04-05T22:23:11","modified_gmt":"2016-04-06T02:23:11","slug":"shell-scripts-for-easier-website-scaffolding-part-2","status":"publish","type":"post","link":"https:\/\/www.bemdesign.com\/wordpress\/2016\/04\/05\/shell-scripts-for-easier-website-scaffolding-part-2\/","title":{"rendered":"Shell scripts for easier website scaffolding part 2"},"content":{"rendered":"<p>Another bit of Bash script fun for prepping a directory or file for deployment.<br \/>\n<code>deploy()<br \/>\n{<br \/>\necho \"Which directory or file do you want to deploy?\"<br \/>\nread sourcedirectory<br \/>\necho \"ZIP'ing up directory\/file\"<br \/>\nzip -r --exclude=\\.git --exclude=\\node_modules --exclude=\\bower_components --exclude=\\.npm --exclude=\\.idea --exclude=\\.hg $sourcedirectory $sourcedirectory<br \/>\necho \"Syncing ZIP'ed folder\/file to Deploy directory\"<br \/>\nrsync -r --progress $sourcedirectory.zip ~\/Deploy<br \/>\necho \"Done! You can find your deployment package $sourcedirectory.zip here: ~\/Deploy (type cd ~\/Deploy to go there)<br \/>\n}<\/code><\/p>\n<p>So some explanations for those not too familiar with shell scripts &#8211; this function goes in your bash profile (.bash_profile in your user account, if it doesn&#8217;t exist you can create it). <code>read<\/code> is a command that asks for user input &#8211; we&#8217;re asking the user to tell us which file or directory they want us to run on. Then we zip up the file\/directory making sure to exclude things we don&#8217;t want deployed to production and save the ZIP&#8217;ed file name the same as the directory we&#8217;re &#8220;deploying&#8221;. And then we use rsync to copy the ZIP archive to our deploy folder.<\/p>\n<p>You can totally tweak this so that instead of zipping the directory or files up, it could just rsync the directory or files to a remote directory &#8211; the skies the limit (or really your user privileges).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Another bit of Bash script fun for prepping a directory or file for deployment. deploy() { echo &#8220;Which directory or file do you want to deploy?&#8221; read sourcedirectory echo &#8220;ZIP&#8217;ing up directory\/file&#8221; zip -r &#8211;exclude=\\.git &#8211;exclude=\\node_modules &#8211;exclude=\\bower_components &#8211;exclude=\\.npm &#8211;exclude=\\.idea &#8211;exclude=\\.hg $sourcedirectory $sourcedirectory echo &#8220;Syncing ZIP&#8217;ed folder\/file to Deploy directory&#8221; rsync -r &#8211;progress $sourcedirectory.zip ~\/Deploy echo [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4],"tags":[49,48],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry","category-technology","category-work","tag-shell-script","tag-tools"],"_links":{"self":[{"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/posts\/531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":1,"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":532,"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/posts\/531\/revisions\/532"}],"wp:attachment":[{"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bemdesign.com\/wordpress\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}