Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Better talking yeti, more verbose install process
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Kimball committed Dec 3, 2014
1 parent 2966400 commit 4e4ea59
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 63 deletions.
71 changes: 45 additions & 26 deletions lib/foundationCLI.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(''));
}
});
});
});
});
}
Expand Down Expand Up @@ -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
Expand Down
49 changes: 12 additions & 37 deletions lib/welcome.js
Original file line number Diff line number Diff line change
@@ -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(''));
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);
70 changes: 70 additions & 0 deletions lib/yeti.js
Original file line number Diff line number Diff line change
@@ -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(''));
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 4e4ea59

Please sign in to comment.