Skip to content

Commit

Permalink
Initial build structure and config are functional.
Browse files Browse the repository at this point in the history
Still to complete: login page, account page, chat example, and test units
  • Loading branch information
katowulf committed Aug 15, 2014
1 parent ae53202 commit 1a3efd6
Show file tree
Hide file tree
Showing 22 changed files with 838 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
test/tmp
.idea
16 changes: 16 additions & 0 deletions angularfire-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"bower": {
"firebase": "1.0.x",
"angularfire": "0.8.x",
"mockfirebase": "0.3.x",
"simplelogin": "1.6.x"
},

"simpleLoginProviders": [
{ "name": "Email/Password", "value": "password", "checked": true },
{ "name": "Anonymous", "value": "anonymous" },
{ "name": "Facebook", "value": "facebook" },
{ "name": "Google", "value": "google" },
{ "name": "Twitter", "value": "twitter" }
]
}
151 changes: 144 additions & 7 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,51 @@ var yosay = require('yosay');
var wiredep = require('wiredep');
var chalk = require('chalk');

//angularfire
var afconfig = require('../angularfire-config.json');
var colors = require('../util/colors.js');
var FIREBASE_PROMPTS = [
{
name: 'firebaseName',
message: colors('Name of your Firebase instance ' +
'(https//%yellow<your instance>%/yellow.firebaseio.com)'),
required: true,
validate: function (input) {
if (!input || !input.match(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/)) {
return chalk.red('Your Firebase name may only contain [a-z], [0-9], and hyphen (-). ' +
'It may not start or end with a hyphen.');
}
return true;
}
}, {
name: 'loginModule',
message: 'Would you like to use FirebaseSimpleLogin for authentication?',
type: 'confirm'
}, {
type: 'checkbox',
name: 'simpleLoginProviders',
message: 'Which providers shall I install?',
choices: afconfig.simpleLoginProviders,
when: function(answers) {
return answers.loginModule;
},
validate: function(picks) {
return picks.length > 0? true : 'Must pick at least one provider';
},
default: ['password']
}
];

var Generator = module.exports = function Generator(args, options) {
yeoman.generators.Base.apply(this, arguments);
this.argument('appname', { type: String, required: false });
this.appname = this.appname || path.basename(process.cwd());
this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname)));

//angularfire
this.afconfig = afconfig;
this.angularFireSourceFiles = [];

this.option('app-suffix', {
desc: 'Allow a custom suffix to be added to the module name',
type: String,
Expand Down Expand Up @@ -57,15 +96,15 @@ var Generator = module.exports = function Generator(args, options) {
this.env.options.coffee = this.options.coffee;
}

this.hookFor('angular:common', {
this.hookFor('angularfire:common', {
args: args
});

this.hookFor('angular:main', {
this.hookFor('angularfire:main', {
args: args
});

this.hookFor('angular:controller', {
this.hookFor('angularfire:controller', {
args: args
});

Expand Down Expand Up @@ -96,9 +135,17 @@ var Generator = module.exports = function Generator(args, options) {
enabledComponents.push('angular-touch/angular-touch.js');
}

//angularfire
if (this.loginModule) {
enabledComponents.push('firebase-simple-login/firebase-simple-login.js');
}

enabledComponents = [
'angular/angular.js',
'angular-mocks/angular-mocks.js'
'angular-mocks/angular-mocks.js',
//angularfire
'firebase/firebase.js',
'angularfire/dist/angularfire.js'
].concat(enabledComponents).join(',');

var jsExt = this.options.coffee ? 'coffee' : 'js';
Expand Down Expand Up @@ -126,10 +173,28 @@ var Generator = module.exports = function Generator(args, options) {
});

if (this.env.options.ngRoute) {
this.invoke('angular:route', {
args: ['about']
this.invoke('angularfire:route', {
//angularfire
args: ['chat']
});
}

//angularfire
if(this.env.options.loginModule) {
if( this.env.options.ngRoute ) {
this.invoke('angularfire:route', {
args: ['login', true]
});
}
else {
this.invoke('angularfire:controller', {
args: ['login', true]
});
this.invoke('angularfire.view', {
args: ['login', true]
});
}
}
});

this.pkg = require('../package.json');
Expand Down Expand Up @@ -158,9 +223,26 @@ Generator.prototype.welcome = function welcome() {
}
};

//angularfire
Generator.prototype.askFirebaseQuestions = function askForCompass() {
this.firebaseName = null;
this.loginModule = false;
this.simpleLoginProviders = [];

var cb = this.async();
this.prompt(FIREBASE_PROMPTS, function (props) {
FIREBASE_PROMPTS.forEach(function(prompt) {
this[prompt.name] = props[prompt.name];
}, this);
cb();
}.bind(this));
};

Generator.prototype.askForCompass = function askForCompass() {
var cb = this.async();

console.log('stuff', this.firebaseName, this.loginModule, this.simpleLoginProviders);

this.prompt([{
type: 'confirm',
name: 'compass',
Expand Down Expand Up @@ -270,6 +352,14 @@ Generator.prototype.askForModules = function askForModules() {
angMods.push("'ngTouch'");
}

//angularfire
angMods.push("'firebase'");
angMods.push("'firebase.utils'");
if( this.loginModule ) {
this.env.options.simpleLogin = true;
angMods.push("'simpleLogin'");
}

if (angMods.length) {
this.env.options.angularDeps = '\n ' + angMods.join(',\n ') + '\n ';
}
Expand All @@ -291,12 +381,32 @@ Generator.prototype.bootstrapFiles = function bootstrapFiles() {
);
};

//todo make this its own subgenerator separate from Angular.js gen
//angularfire
Generator.prototype.copyAngularFireFiles = function() {
this._common('scripts/angularfire/config.js');
this._common('scripts/angularfire/firebase.utils.js');

if( this.loginModule ) {
this._common('scripts/angularfire/simpleLogin.js');
this._tpl('controllers/login');
this._htmlTpl('views/login.html');
}

if( this.routeModule ) {
var withOrWithout = this.loginModule? 'with' : 'without';
this._tpl('routes.' + withOrWithout + '.login', 'routes');
}
};

Generator.prototype.appJs = function appJs() {
this.indexFile = this.appendFiles({
html: this.indexFile,
fileType: 'js',
optimizedPath: 'scripts/scripts.js',
sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js'],
sourceFileList: ['scripts/app.js', 'scripts/controllers/main.js']
//angularfire
.concat(this.angularFireSourceFiles),
searchPath: ['.tmp', this.appPath]
});
};
Expand Down Expand Up @@ -338,3 +448,30 @@ Generator.prototype._injectDependencies = function _injectDependencies() {
});
}
};

//angularfire
Generator.prototype._common = function(dest) {
this.angularFireSourceFiles.push(dest);
var appPath = this.options.appPath;
this.template(path.join('app', dest), path.join(appPath, dest));
};

//angularfire
Generator.prototype._htmlTpl = function(dest) {
var join = path.join;
var appPath = this.options.appPath;
this.copy(join('app', dest), join(appPath, dest));
};

//angularfire
Generator.prototype._tpl = function(src, dest) {
if( !dest ) { dest = src; }
var suff = this.options.coffee? '.coffee' : '.js';
var destFileName = path.join('scripts', dest+suff);
this.angularFireSourceFiles.push(destFileName);
this.template(
// haaaaaack
path.join('..', this.options.coffee? 'coffee' : 'javascript', src+suff),
path.join(this.appPath, destFileName)
);
};
1 change: 1 addition & 0 deletions common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ Generator.prototype.setupEnv = function setupEnv() {
copy('favicon.ico');
copy('robots.txt');
copy('views/main.html');

this.directory(join('app', 'images'), join(appPath, 'images'));
};
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "generator-angular",
"version": "0.9.5",
"description": "Yeoman generator for AngularJS",
"name": "generator-angularfire",
"version": "0.8.1",
"description": "Yeoman generator for Angular+Firebase",
"keywords": [
"yeoman-generator",
"scaffold",
"framework",
"component",
"front-end",
"app",
"angular"
"angular",
"firebase"
],
"author": "The Yeoman Team",
"author": "Kato (with thanks to Yeoman team)",
"main": "app/index.js",
"files": [
"app",
Expand All @@ -32,7 +33,7 @@
"script-base.js",
"util.js"
],
"repository": "yeoman/generator-angular",
"repository": "yeoman/generator-angularfire",
"scripts": {
"test": "mocha"
},
Expand Down
13 changes: 8 additions & 5 deletions route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Generator = module.exports = function Generator() {
var bower = require(path.join(process.cwd(), 'bower.json'));
var match = require('fs').readFileSync(path.join(
this.env.options.appPath,
'scripts/app.' + (this.env.options.coffee ? 'coffee' : 'js')
'scripts/routes.' + (this.env.options.coffee ? 'coffee' : 'js')
), 'utf-8').match(/\.when/);

if (
Expand All @@ -29,14 +29,15 @@ var Generator = module.exports = function Generator() {

util.inherits(Generator, ScriptBase);

//angularFire
Generator.prototype.rewriteAppJs = function () {
var coffee = this.env.options.coffee;

if (!this.foundWhenForRoute) {
this.on('end', function () {
this.log(chalk.yellow(
'\nangular-route is not installed. Skipping adding the route to ' +
'scripts/app.' + (coffee ? 'coffee' : 'js')
'scripts/routes.' + (coffee ? 'coffee' : 'js')
));
});
return;
Expand All @@ -50,7 +51,7 @@ Generator.prototype.rewriteAppJs = function () {
var config = {
file: path.join(
this.env.options.appPath,
'scripts/app.' + (coffee ? 'coffee' : 'js')
'scripts/routes.' + (coffee ? 'coffee' : 'js')
),
needle: '.otherwise',
splicable: [
Expand All @@ -59,11 +60,13 @@ Generator.prototype.rewriteAppJs = function () {
]
};

var whenMethod = this.env.options.authRequired? 'whenAuthenticated' : 'when';

if (coffee) {
config.splicable.unshift(".when '/" + this.uri + "',");
config.splicable.unshift("." + whenMethod + " '/" + this.uri + "',");
}
else {
config.splicable.unshift(".when('/" + this.uri + "', {");
config.splicable.unshift("." + whenMethod + "('/" + this.uri + "', {");
config.splicable.push("})");
}

Expand Down
22 changes: 18 additions & 4 deletions templates/common/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="#">Home</a></li>
<li><a ng-href="<% if (ngRoute) { %>#/about<% } else { %>#<% } %>">About</a></li>
<li><a ng-href="#">Contact</a></li>
</ul>
<!-- //angularfire -->
<%
if (ngRoute) {
%><li><a ng-href="#/chat">chat</a></li>
<%
if (loginModule) {
%><li>
<a ng-hide-auth ng-href="#/login">log in</a>
<a ng-show-auth ng-href="#/account">account</a>
</li>
<%
}
} else {
%><li><a ng-href="#">link</a></li>
<% }
%></ul>
<h3 class="text-muted"><%= appname %></h3>
</div>

<% if (ngRoute) {
%><div ng-view></div><%
} else {
%><div ng-include="'views/main.html'" ng-controller="MainCtrl"></div><%
<!-- //angularfire -->
%><div ng-include="'views/chat.html'" ng-controller="ChatCtrl"></div><%
} %>

<div class="footer">
Expand Down
8 changes: 8 additions & 0 deletions templates/common/app/scripts/angularfire/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
angular.module('firebase.config', [])
.constant('FBURL', 'https://<%= firebaseName %>.firebaseio.com')<%
if( loginModule ) {
%>
.constant('SIMPLE_LOGIN_PROVIDERS', ['<%= simpleLoginProviders.join("','") %>'])

.constant('loginRedirectPath', '/login')<% }
%>;
Loading

0 comments on commit 1a3efd6

Please sign in to comment.