Skip to content

feat(gen): add Insight stat tracker #1704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions app/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import chalk from 'chalk';
import {Base} from 'yeoman-generator';
import {genBase} from '../generator-base';
import insight from '../insight-init';

export default class Generator extends Base {

Expand All @@ -28,13 +29,30 @@ export default class Generator extends Base {

get initializing() {
return {

init: function () {
var cb = this.async();

this.config.set('generatorVersion', this.rootGeneratorVersion());
this.filters = {};

// init shared generator properies and methods
genBase(this);

if(insight.optOut === undefined) {
insight.askPermission(null, (err, optIn) => {
if(err || !optIn) return cb();
insight.track('generatorVersion', this.rootGeneratorVersion());
insight.track('node', process.version);
exec('npm --version', (err, stdin, stderr) => {
if(err || stderr.length > 0) return insight.track('npm', 'error');
else return insight.track('npm', stdin.toString().trim());
});
insight.track('platform', process.platform);
return cb();
});
} else {
return cb();
}
},

info: function () {
Expand All @@ -55,7 +73,8 @@ export default class Generator extends Base {
}], function (answers) {
this.skipConfig = answers.skipConfig;

if (this.skipConfig) {
if(this.skipConfig) {
insight.track('skipConfig', 'true');
this.filters = existingFilters;

this.scriptExt = this.filters.ts ? 'ts' : 'js';
Expand All @@ -65,6 +84,7 @@ export default class Generator extends Base {
this.filters.stylus ? 'styl' :
'css';
} else {
insight.track('skipConfig', 'false');
this.filters = {};
this.forceConfig = true;
this.config.set('filters', this.filters);
Expand All @@ -77,7 +97,6 @@ export default class Generator extends Base {
cb();
}
}

};
}

Expand Down Expand Up @@ -133,14 +152,24 @@ export default class Generator extends Base {
return answers.bootstrap;
}
}], function (answers) {

this.filters.js = true;
this.filters[answers.transpiler] = true;
insight.track('transpiler', answers.transpiler);

this.filters[answers.markup] = true;
insight.track('markup', answers.markup);

this.filters[answers.stylesheet] = true;
insight.track('stylesheet', answers.stylesheet);

this.filters[answers.router] = true;
insight.track('router', answers.router);

this.filters.bootstrap = !!answers.bootstrap;
insight.track('bootstrap', !!answers.bootstrap);

this.filters.uibootstrap = !!answers.uibootstrap;
insight.track('uibootstrap', !!answers.uibootstrap);

this.scriptExt = answers.transpiler === 'ts' ? 'ts' : 'js';
this.templateExt = answers.markup;
Expand Down Expand Up @@ -228,7 +257,11 @@ export default class Generator extends Base {
default: true
}], function (answers) {
if(answers.socketio) this.filters.socketio = true;
insight.track('socketio', !!answers.socketio);

if(answers.auth) this.filters.auth = true;
insight.track('auth', !!answers.auth);

if(answers.odms && answers.odms.length > 0) {
var models;
if(!answers.models) {
Expand All @@ -241,15 +274,26 @@ export default class Generator extends Base {
answers.odms.forEach(function(odm) {
this.filters[odm] = true;
}.bind(this));
insight.track('oauth', !!answers.oauth);
} else {
this.filters.noModels = true;
}
insight.track('odms', answers.odms && answers.odms.length > 0);
insight.track('mongoose', !!this.filters.mongoose);
insight.track('mongooseModels', !!this.filters.mongooseModels);
insight.track('sequelize', !!this.filters.sequelize);
insight.track('sequelizeModels', !!this.filters.sequelizeModels);

if(answers.oauth) {
if(answers.oauth.length) this.filters.oauth = true;
answers.oauth.forEach(function(oauthStrategy) {
this.filters[oauthStrategy] = true;
}.bind(this));
}
insight.track('oauth', !!this.filters.oauth);
insight.track('google-oauth', !!this.filters['googleAuth']);
insight.track('facebook-oauth', !!this.filters['facebookAuth']);
insight.track('twitter-oauth', !!this.filters['twitterAuth']);

cb();
}.bind(this));
Expand Down Expand Up @@ -295,13 +339,16 @@ export default class Generator extends Base {
}
}], function (answers) {
this.filters[answers.buildtool] = true;
insight.track('buildtool', answers.buildtool);

this.filters[answers.testing] = true;
insight.track('testing', answers.testing);
if (answers.testing === 'mocha') {
this.filters.jasmine = false;
this.filters.should = false;
this.filters.expect = false;
this.filters[answers.chai] = true;
insight.track('chai-assertions', answers.chai);
}
if (answers.testing === 'jasmine') {
this.filters.mocha = false;
Expand Down
21 changes: 21 additions & 0 deletions insight-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
var Insight = require('insight');
var pkg = require('./package.json');

var insight = new Insight({
// Google Analytics tracking code
trackingCode: 'UA-48443700-4',
pkg: pkg
});

if(process.stdout.isTTY === undefined) insight.optOut = false;

// ask for permission the first time
// if(insight.optOut === undefined) {
// insight.askPermission();
// }

// insight.track('foo', 'bar');
// recorded in Analytics as `/foo/bar`

module.exports = insight;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"chalk": "^1.1.0",
"generator-ng-component": "~0.2.1",
"glob": "^7.0.3",
"insight": "~0.7.0",
"lodash": "^4.6.1",
"underscore.string": "^3.1.1",
"yeoman-generator": "^0.22.5",
Expand Down