diff --git a/lib/foundationCLI.js b/lib/foundationCLI.js index a710a33..39d3f0b 100644 --- a/lib/foundationCLI.js +++ b/lib/foundationCLI.js @@ -1,11 +1,13 @@ -var fs = require('fs'); -var rimraf = require('rimraf'); -var exec = require('exec'); -var spawn = require('child_process').spawn; -var colors = require('colors'); -var open = require('open'); -var bower = require('bower'); -var pkg = require('../package.json'); +var fs = require('fs'); +var rimraf = require('rimraf'); +var exec = require('exec'); +var spawn = require('child_process').spawn; +var colors = require('colors'); +var open = require('open'); +var lineLog = require('single-line-log').stdout; +var yeti = require('./yeti'); +var bower = require('bower'); +var pkg = require('../package.json'); // HELP // List all available commands, or info for a specific command @@ -78,40 +80,60 @@ module.exports.new = function(args, options) { var gitClone = ['git', 'clone', 'https://github.com/zurb/foundation-apps-template.git', args[0]]; var npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'; var npmInstall = ['npm', 'install']; + var bowerInstall = ['bower', 'install']; + var bundleInstall = ['bundle']; // Show help screen if the user didn't enter a project name if (typeof projectName === 'undefined') { - this.help(); + this.help('new'); process.exit(); } + yeti([ + 'Thanks for using Foundation for Apps!', + 'Let\'s set up a new project.' + ]); + // Clone the template repo - process.stdout.write("Downloading the Foundation for Apps template...".cyan); + process.stdout.write("\nDownloading the Foundation for Apps template...".cyan); exec(gitClone, function(err, out, code) { if (err instanceof Error) throw err; process.stdout.write([ - " Done downloading!\n", - "\nInstalling dependencies...".cyan + " Done downloading!", + "\n\nInstalling dependencies...".cyan, + "\n" ].join('')); // Remove the Git folder rimraf('./'+projectName+'/.git/', function() {}); - // Install npm and Bower dependencies + lineLog("npm" + " => bower => bundler".gray); + + // Yes, this is callback hell, we'll get around to fixing it! exec(npmInstall, {cwd: './'+args[0]}, function(err, out, code) { if (err instanceof Error) throw err; - else { - process.stdout.write([ - " Done installing!\n", - "\nYou're all set! Now run ", - "npm start ".cyan, - "while inside the ", - args[0].cyan, - " folder.\n\n" - ].join('')); - } + lineLog("npm => ".green + "bower".white + " => bundler".gray); + exec(bowerInstall, {cwd: './'+args[0]}, function(err, out, code) { + if (err instanceof Error) throw err; + + lineLog("npm => bower".green + " => bundler"); + exec(bundleInstall, {cwd: './'+args[0]}, function(err, out, code) { + if (err instanceof Error) throw err; + + else { + lineLog("npm => bower => bundler".green); + process.stdout.write([ + "\n\nYou're all set! Now run ", + "foundation-apps watch ".cyan, + "while inside the ", + args[0].cyan, + " folder.\n\n" + ].join('')); + } + }); + }); }); }); } @@ -145,9 +167,6 @@ module.exports.watch = function(args, options, justBuild) { proc.stderr.on('data', function(data) { process.stdout.write(data.toString()); }); - proc.on('exit', function(code) { - console.log("Good Luck Have Batman".cyan); - }); } // BUILD diff --git a/lib/welcome.js b/lib/welcome.js index 0417213..3aef632 100755 --- a/lib/welcome.js +++ b/lib/welcome.js @@ -1,40 +1,15 @@ #!/usr/bin/env node -// /| -// | | /| . -// . /\| \/ |/| -// |\/ | -// ||\__/\____/|| -// ___|| ======== ||___ -// /___|| O O ||___\ -// || ______, || -// /| |\ -// /_/\\/\ /\//\_\ -// \/\\//\/ -// \/ - var colors = require('colors'); - -var yeti = [ - '\n /|' -, '\n | | /| .' -, '\n . /\\| \\/ |/|' -, '\n |\\/ |' -, '\n |'+'|\\__/\\____/|'.cyan+'|' -, '\n '+'___'.gray+'|'+'|'.cyan+' '+'========'.gray+' '+'|'.cyan+'|'+'___'.gray -, '\n '+'/___'.gray+'|'+'|'.cyan+' '+'O'.cyan+' '+'O'.cyan+' ||'+'___\\'.gray -, '\n |'+'|'.cyan+' '+'______,'.cyan+' '+'|'.cyan+'|' -, '\n /'+'|'.cyan+' '+'|'.cyan+'\\ ' -, '\n /_/\\'+'\\/\\'.cyan+' '+'/\\/'.cyan+'/\\_\\ ' -, '\n \\/\\'+'\\/'.cyan+'/\\/' -, '\n \\/' -, '\n' -]; - -yeti[3] = yeti[3] + ' '+'Thanks for installing Foundation for Apps!'; -yeti[4] = yeti[4] + ' ------------------------------------------'; -yeti[5] = yeti[5] + ' Type '+'foundation-apps new app'.cyan+' to create a new app,'; -yeti[6] = yeti[6] + ' or '+'foundation-apps help'.cyan+' to see every command.'; -yeti[8] = yeti[8] + ' '+'@zurbfoundation'.cyan+' on Twitter'; - -console.log(yeti.join('')); \ No newline at end of file +var yeti = require('./yeti'); + +var msg = [ + 'Thanks for installing Foundation for Apps!', + '------------------------------------------', + 'Type ' + 'foundation-apps new app'.cyan+' to create a new app,', + 'or '+'foundation-apps help'.cyan+' to see every command.', + '', + 'We\'re '+'@zurbfoundation'.cyan+' on Twitter.', +] + +yeti(msg); \ No newline at end of file diff --git a/lib/yeti.js b/lib/yeti.js new file mode 100644 index 0000000..f3b4927 --- /dev/null +++ b/lib/yeti.js @@ -0,0 +1,70 @@ +// /| +// | | /| . +// . /\| \/ |/| +// |\/ | +// ||\__/\____/|| +// ___|| ======== ||___ +// /___|| O O ||___\ +// || ______, || +// /| |\ +// /_/\\/\ /\//\_\ +// \/\\//\/ +// \/ + +var colors = require('colors') + , stringLength = require('string-length') +; + +var yeti = [ + '\n /|' +, '\n | | /| .' +, '\n . /\\| \\/ |/|' +, '\n |\\/ |' +, '\n |'+'|\\__/\\____/|'.cyan+'|' +, '\n '+'___'.gray+'|'+'|'.cyan+' '+'========'.gray+' '+'|'.cyan+'|'+'___'.gray +, '\n '+'/___'.gray+'|'+'|'.cyan+' '+'O'.cyan+' '+'O'.cyan+' ||'+'___\\'.gray +, '\n |'+'|'.cyan+' '+'______,'.cyan+' '+'|'.cyan+'|' +, '\n /'+'|'.cyan+' '+'|'.cyan+'\\ ' +, '\n /_/\\'+'\\/\\'.cyan+' '+'/\\/'.cyan+'/\\_\\ ' +, '\n \\/\\'+'\\/'.cyan+'/\\/' +, '\n \\/' +, '\n' +]; + +var baseTextOffset = 5 + , longestLine = (function() { + var highest = 0; + for (var i = 0; i < yeti.length; i++) { + var len = stringLength(yeti[i]); + if (len > highest) highest = len; + } + return highest; +})(); + +// Thank you: http://stackoverflow.com/a/5450113/492553 +var repeatChar = function(pattern, count) { + if (count < 1) return ''; + var result = ''; + while (count > 1) { + if (count & 1) result += pattern; + count >>= 1, pattern += pattern; + } + return result + pattern; +} + +// This function takes an array of text messages and places them next to the ASCII yeti +module.exports = function(text) { + var yetiHeight = yeti.length - 1 + , textHeight = text.length + , textOffset = Math.floor((yetiHeight - textHeight) / 2) + , yetiMsg = yeti + ; + + for (var i = 0; i < text.length; i++) { + var offset = textOffset + i; + var spaceCount = longestLine - stringLength(yetiMsg[offset]) + baseTextOffset; + yetiMsg[offset] = yetiMsg[offset] + repeatChar(' ', spaceCount) + text[i]; + } + + console.log(yetiMsg.join('')); +} \ No newline at end of file diff --git a/package.json b/package.json index 82f5a08..6bfa022 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,10 @@ "multiline": "^1.0.1", "nopt": "^3.0.1", "open": "0.0.5", + "q": "^1.1.2", "rimraf": "^2.2.8", + "single-line-log": "^0.4.1", + "string-length": "^1.0.0", "update-notifier": "^0.2.2" }, "scripts": {