This is something that I needed to do in a recent AngularJS project. I had scaffolded the project with my favorite yeoman generator, Gulp-Angular, and I would build my project with the simple gulp command. However, in order to actually deploy it I had to hand off the files to some one else. The company was using a small time CMS that only allowed for manual upload of files, and I wasn't even given access being that I was just a contractor at the time.
Seizing the Automation Opportunity!
I found myself over and over doing the same bit of manual work- something that annoys the heck out of me. But what annoyed the heck out of me even more is that I knew I should automate this step I was wasting my own damn precious time and energy. To review, here's what the manual work entailed:
I should be noted that I could have done this by adding a gulp task at the end of everything it does to zip up the proper files so that everything would happen from the gulp command. However, I didn't want to have to keep opening up the gulp files in order to change the version number. I was also already in the terminal window to run gulp so I figured I'd just do it with normal linux commands.
It's a bit scary, but I'll just throw it out there and then explain it:
The first thing to realize is that we can chain commands one after another by separating them with a semicolon. We can see the first part of this command is the good old gulp command as usual. Then we have another straightforward command, cd dist, which drills down into the dist folder creates by gulp (so that we don't include the dist folder in the zip we're about to do). Next we're going to zip up everything in the current folder. We use the zip command with the recursive -r flag, point to the exact path and name of the zip we're creating (you should change this to reflect the place on your computer where'd you'd like to save the zip file), and finally tell it to zip everything in this folder with the * character. I then cd out of the dist folder, bringing back where I started. If I then check in my "latent builds" folder, I'll see the zip there smiling at me!
I can always run this code above wherever I would run the gulp command, and it doesn't this extra bit of manual work for me. Some people would say this is overkill; that's is unnecessary. I say posh to them! I save a lot of time and agony with this script, and on top of that I feel like a real badass when I run it. So while they're right clicking around on compress /rename /move, I'm laughing all the way to the office game room.
The posts on this site are written and maintained by Jim Lynch. About Jim...