Skip to content

Commit

Permalink
Fixes #192
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Aug 10, 2012
1 parent 4377003 commit 8530cb8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 55 deletions.
5 changes: 3 additions & 2 deletions cli/bin/yeoman
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ async.series([function(cb) {
// Are we dealing with yeoman in a test environment? If so, skip the // Are we dealing with yeoman in a test environment? If so, skip the
// insight prompt. This is specifically put into the environment by // insight prompt. This is specifically put into the environment by
// our test spawn helper. // our test spawn helper.
if(process.env.yeoman_test) return cb(); if(process.env.yeoman_test) {
return cb();
}


insight.init({ insight.init({
pkgname : pkg.name, pkgname : pkg.name,
Expand All @@ -85,7 +87,6 @@ async.series([function(cb) {
cb : cb cb : cb
}); });



}, function(cb) { }, function(cb) {


// if the route is empty // if the route is empty
Expand Down
9 changes: 4 additions & 5 deletions metrics/yeomaninsight.py → cli/bin/yeomaninsight.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import urllib import urllib
import urllib2 import urllib2


#import settings

NO_STATS = 'NO_STATS' NO_STATS = 'NO_STATS'
CLI_NAME = 'yeoman' #settings.APP['cli_name'] CLI_NAME = 'yeoman'


# TODO(ericbidelman): Verify expanduser('~') works on other platforms. # TODO(ericbidelman): Verify expanduser('~') works on other platforms.
INSIGHT_DIR = os.path.join(os.path.expanduser('~'), '.yeoman', 'insight') # ~/.yeoman/insight
LOG_FILE = os.path.join(INSIGHT_DIR, '.log') #os.path.join(os.path.dirname(__file__), '.log') INSIGHT_DIR = os.path.join(os.path.expanduser('~'), '.' + CLI_NAME, 'insight')
LOG_FILE = os.path.join(INSIGHT_DIR, '.log') # ~/.yeoman/insight/.log


NUM_SUB_CMDS = 2 # Subcommand depth. TODO: This assumes only "cmd subcmd" format. NUM_SUB_CMDS = 2 # Subcommand depth. TODO: This assumes only "cmd subcmd" format.
NUM_SECONDS_TO_STASH_DATA = 0 # Send data as it happens. NUM_SECONDS_TO_STASH_DATA = 0 # Send data as it happens.
Expand Down
80 changes: 41 additions & 39 deletions cli/lib/plugins/insight.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ var fs = require('fs'),
colors = require('colors'), colors = require('colors'),
prompt = require('prompt'); prompt = require('prompt');



module.exports = { module.exports = {
init : function(opts){ init: function(opts) {

// Store global state used throughout the project in the user's home dir.
// e.g. /Users/username/.yeoman
var YEOMAN_DIR = join(opts.getUserHome(), '.' + opts.pkgname);


// Store global state used throughout the project in the user's home dir. // This should correspond to whatever name is used in package.json.
// e.g. /Users/username/.yeoman var INSIGHT_SCRIPT = '_' + opts.pkgname + 'insight'
var YEOMAN_DIR = join(opts.getUserHome(), '.' + opts.pkgname);


var insightFolder = join(YEOMAN_DIR, 'insight'); var insightFolder = join(YEOMAN_DIR, 'insight');


// Assume yeomaninsight.py is installed in the user's home dir. // Assume yeomaninsight.py is installed globally (/usr/local/bin/)
var insightRecordCmd = [join(insightFolder, 'yeomaninsight.py'), 'record']; var insightRecordCmd = ['record'];


// Record this action in Insight (e.g. python yeomaninsight.py record cmd cmd2). // Record this action in Insight (e.g. python yeomaninsight.py record cmd cmd2).
spawn('python', insightRecordCmd.concat(opts.cmds)); spawn(INSIGHT_SCRIPT, insightRecordCmd.concat(opts.cmds));
//insight.stdout.pipe(process.stdout); //insight.stdout.pipe(process.stdout);


fs.stat(join(insightFolder, '.log'), function(err, stats) { fs.stat(join(insightFolder, '.log'), function(err, stats) {
// Error means file doesn't exist and this is the first run. // Error means file doesn't exist and this is the first run.
// Go through stat opt-in flow. // Go through stat opt-in flow.
if ( !err ) { if ( !err ) {
return opts.cb(); return opts.cb();
} }


/*jshint multistr:true */ /*jshint multistr:true */
var msg = "\ var msg = "\
Expand All @@ -36,31 +38,31 @@ May we anonymously report usage statistics to improve the tool over time? \n\
More info: http://goo.gl/GPtU9 & http://yeoman.io".yellow + "\n\ More info: http://goo.gl/GPtU9 & http://yeoman.io".yellow + "\n\
==========================================================================".grey; ==========================================================================".grey;


prompt.message = '[' + '?'.green + ']'; prompt.message = '[' + '?'.green + ']';
prompt.delimiter = ' '; prompt.delimiter = ' ';


var properties = [{ var properties = [{
name: 'optin', name: 'optin',
message: '[Y/n]: ', message: '[Y/n]: ',
"default": 'Y', "default": 'Y',
validator: /^[yntf]{1}/i, validator: /^[yntf]{1}/i,
empty: false empty: false
}]; }];


prompt.start(); prompt.start();
console.log(msg); console.log(msg);
prompt.get(properties, function(err, result) { prompt.get(properties, function(err, result) {
if (err) { if (err) {
return opts.cb(err); return opts.cb(err);
} }


if (/n/i.test(result.optin)) { if (/n/i.test(result.optin)) {
spawn('python', insightRecordCmd.concat(['NO_STATS'])); spawn(INSIGHT_SCRIPT, insightRecordCmd.concat(['NO_STATS']));
} }
opts.cb(); opts.cb();
}); });




}); });
} }
}; };
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"homepage": "http://yeoman.io", "homepage": "http://yeoman.io",
"main": "./yeoman", "main": "./yeoman",
"bin": { "bin": {
"yeoman": "./bin/yeoman" "yeoman": "./bin/yeoman",
"_yeomaninsight": "./bin/yeomaninsight.py"
}, },
"directories": { "directories": {
"man": "./man" "man": "./man"
Expand Down
17 changes: 9 additions & 8 deletions setup/install.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -192,16 +192,17 @@ echo "Okay here we go..."
sudo npm install . -g sudo npm install . -g


echo "" echo ""
echo "Yah Hoo! Yeoman global is in place, now for some housekeeping.." echo "Yah Hoo! Yeoman global is in place."

# let's ask the user if she is okay with reporting anonymous stats so we can build a better tool
echo "" echo ""
cd ../metrics
# TODO: creating a path like this probably doesn't work on Windows.
python setup.py install --quiet --force --user --install-scripts=~/.yeoman/insight


echo "Alright now, that bit is done now, too." # # let's ask the user if she is okay with reporting anonymous stats so we can build a better tool
echo "" # echo ""
# cd ../metrics
# # TODO: creating a path like this probably doesn't work on Windows.
# python setup.py install --quiet --force --user --install-scripts=~/.yeoman/insight

# echo "Alright now, that bit is done now, too."
# echo ""


# hop back to start and kill our temp folder off # hop back to start and kill our temp folder off
cd "$BACK" && rm -rf "$TMP" cd "$BACK" && rm -rf "$TMP"
Expand Down

0 comments on commit 8530cb8

Please sign in to comment.