diff --git a/app/generator.js b/app/generator.js
index 591984d98..22b46dfe8 100644
--- a/app/generator.js
+++ b/app/generator.js
@@ -33,7 +33,7 @@ export default class Generator extends Base {
},
info: function () {
- this.log(this.welcome);
+ this.log(this.yoWelcome);
this.log('Out of the box I create an AngularJS app with an Express server.\n');
},
@@ -49,7 +49,7 @@ export default class Generator extends Base {
}], function (answers) {
this.skipConfig = answers.skipConfig;
- this.filters = this._.defaults(this.config.get('filters'), {
+ this.filters = this.lodash.defaults(this.config.get('filters'), {
bootstrap: true,
uibootstrap: true,
jasmine: true
diff --git a/app/templates/README.md b/app/templates/README.md
index 958834120..e5ec70428 100644
--- a/app/templates/README.md
+++ b/app/templates/README.md
@@ -1,4 +1,4 @@
-# <%= _.slugify(_.humanize(appname)) %>
+# <%= lodash.slugify(lodash.humanize(appname)) %>
This project was generated with the [Angular Full-Stack Generator](https://github.com/DaftMonk/generator-angular-fullstack) version <%= pkg.version %>.
diff --git a/app/templates/_bower.json b/app/templates/_bower.json
index 1d41b39d1..85e8835ed 100644
--- a/app/templates/_bower.json
+++ b/app/templates/_bower.json
@@ -1,5 +1,5 @@
{
- "name": "<%= _.slugify(_.humanize(appname)) %>",
+ "name": "<%= lodash.slugify(lodash.humanize(appname)) %>",
"version": "0.0.0",
"dependencies": {
"angular": "~1.4.0",
diff --git a/app/templates/_package.json b/app/templates/_package.json
index 67760246d..3187a8ae1 100644
--- a/app/templates/_package.json
+++ b/app/templates/_package.json
@@ -1,5 +1,5 @@
{
- "name": "<%= _.slugify(_.humanize(appname)) %>",
+ "name": "<%= lodash.slugify(lodash.humanize(appname)) %>",
"version": "0.0.0",
"main": "server/app.js",
"dependencies": {
diff --git a/app/templates/client/components/navbar/navbar(html).html b/app/templates/client/components/navbar/navbar(html).html
index ec9e4682d..eda46b07a 100644
--- a/app/templates/client/components/navbar/navbar(html).html
+++ b/app/templates/client/components/navbar/navbar(html).html
@@ -7,7 +7,7 @@
- <%= _.slugify(_.humanize(appname)) %>
+ <%= lodash.slugify(lodash.humanize(appname)) %>
diff --git a/app/templates/client/components/navbar/navbar(jade).jade b/app/templates/client/components/navbar/navbar(jade).jade
index e20a8fffa..a6f5fe919 100644
--- a/app/templates/client/components/navbar/navbar(jade).jade
+++ b/app/templates/client/components/navbar/navbar(jade).jade
@@ -6,7 +6,7 @@ div.navbar.navbar-default.navbar-static-top(ng-controller='NavbarCtrl')
span.icon-bar
span.icon-bar
span.icon-bar
- a.navbar-brand(href='/') <%= _.slugify(_.humanize(appname)) %>
+ a.navbar-brand(href='/') <%= lodash.slugify(lodash.humanize(appname)) %>
div#navbar-main.navbar-collapse.collapse(collapse='isCollapsed')
ul.nav.navbar-nav
diff --git a/app/templates/server/config/_local.env.js b/app/templates/server/config/_local.env.js
index 12b78192e..82195c471 100644
--- a/app/templates/server/config/_local.env.js
+++ b/app/templates/server/config/_local.env.js
@@ -7,7 +7,7 @@
module.exports = {
DOMAIN: 'http://localhost:9000',
- SESSION_SECRET: '<%= _.slugify(appname) + "-secret" %>',<% if (filters.facebookAuth) { %>
+ SESSION_SECRET: '<%= lodash.slugify(appname) + "-secret" %>',<% if (filters.facebookAuth) { %>
FACEBOOK_ID: 'app-id',
FACEBOOK_SECRET: 'secret',<% } if (filters.twitterAuth) { %>
diff --git a/app/templates/server/config/_local.env.sample.js b/app/templates/server/config/_local.env.sample.js
index ac5a52a2e..8106cf731 100644
--- a/app/templates/server/config/_local.env.sample.js
+++ b/app/templates/server/config/_local.env.sample.js
@@ -7,7 +7,7 @@
module.exports = {
DOMAIN: 'http://localhost:9000',
- SESSION_SECRET: '<%= _.slugify(appname) + "-secret" %>',<% if (filters.facebookAuth) { %>
+ SESSION_SECRET: '<%= lodash.slugify(appname) + "-secret" %>',<% if (filters.facebookAuth) { %>
FACEBOOK_ID: 'app-id',
FACEBOOK_SECRET: 'secret',<% } if (filters.twitterAuth) { %>
diff --git a/app/templates/server/config/environment/development.js b/app/templates/server/config/environment/development.js
index 20656595b..d79b250b3 100644
--- a/app/templates/server/config/environment/development.js
+++ b/app/templates/server/config/environment/development.js
@@ -5,7 +5,7 @@
module.exports = {
// MongoDB connection options
mongo: {
- uri: 'mongodb://localhost/<%= _.slugify(appname) %>-dev'
+ uri: 'mongodb://localhost/<%= lodash.slugify(appname) %>-dev'
},
sequelize: {
uri: 'sqlite://',
diff --git a/app/templates/server/config/environment/index.js b/app/templates/server/config/environment/index.js
index 547f6bbac..98c892d32 100644
--- a/app/templates/server/config/environment/index.js
+++ b/app/templates/server/config/environment/index.js
@@ -29,7 +29,7 @@ var all = {
// Secret for session, you will want to change this and make it an environment variable
secrets: {
- session: '<%= _.slugify(_.humanize(appname)) + '-secret' %>'
+ session: '<%= lodash.slugify(lodash.humanize(appname)) + '-secret' %>'
},
// List of user roles
diff --git a/app/templates/server/config/environment/production.js b/app/templates/server/config/environment/production.js
index e0b77bf97..abdda30a3 100644
--- a/app/templates/server/config/environment/production.js
+++ b/app/templates/server/config/environment/production.js
@@ -19,6 +19,6 @@ module.exports = {
process.env.MONGOHQ_URL ||
process.env.OPENSHIFT_MONGODB_DB_URL +
process.env.OPENSHIFT_APP_NAME ||
- 'mongodb://localhost/<%= _.slugify(appname) %>'
+ 'mongodb://localhost/<%= lodash.slugify(appname) %>'
}
};
diff --git a/app/templates/server/config/environment/test.js b/app/templates/server/config/environment/test.js
index 021938424..ea7d65096 100644
--- a/app/templates/server/config/environment/test.js
+++ b/app/templates/server/config/environment/test.js
@@ -5,7 +5,7 @@
module.exports = {
// MongoDB connection options
mongo: {
- uri: 'mongodb://localhost/<%= _.slugify(appname) %>-test'
+ uri: 'mongodb://localhost/<%= lodash.slugify(appname) %>-test'
},
sequelize: {
uri: 'sqlite://',
diff --git a/app/templates/server/config/express.js b/app/templates/server/config/express.js
index e8748499b..7ecf10888 100644
--- a/app/templates/server/config/express.js
+++ b/app/templates/server/config/express.js
@@ -46,7 +46,7 @@ module.exports = function(app) {
saveUninitialized: true<% if (filters.mongoose) { %>,
store: new mongoStore({
mongooseConnection: mongoose.connection,
- db: '<%= _.slugify(_.humanize(appname)) %>'
+ db: '<%= lodash.slugify(lodash.humanize(appname)) %>'
})<% } else if(filters.sequelize) { %>,
store: new Store(sqldb.sequelize)<% } %>
}));
diff --git a/generator-base.js b/generator-base.js
index fbe4be437..2abbaa0f7 100644
--- a/generator-base.js
+++ b/generator-base.js
@@ -2,17 +2,26 @@
import util from 'util';
import path from 'path';
+import lodash from 'lodash';
+import s from 'underscore.string';
+import yoWelcome from 'yeoman-welcome';
import * as genUtils from './util';
+// extend lodash with underscore.string
+lodash.mixin(s.exports());
+
export function genBase(self) {
self = self || this;
+ self.lodash = lodash;
+ self.yoWelcome = yoWelcome;
+
try {
self.appname = require(path.join(process.cwd(), 'bower.json')).name;
} catch (e) {
self.appname = self.name || path.basename(process.cwd());
}
- self.appname = self._.camelize(self._.slugify(self._.humanize(self.appname)));
+ self.appname = lodash.camelize(lodash.slugify(lodash.humanize(self.appname)));
self.scriptAppName = self.appname + genUtils.appSuffix(self);
self.filters = self.filters || self.config.get('filters');
@@ -41,8 +50,8 @@ export function genNamedBase(self) {
var name = self.name.replace(/\//g, '-');
- self.cameledName = self._.camelize(name);
- self.classedName = self._.classify(name);
+ self.cameledName = lodash.camelize(name);
+ self.classedName = lodash.classify(name);
self.basename = path.basename(self.name);
self.dirname = (self.name.indexOf('/') >= 0) ? path.dirname(self.name) : self.name;
diff --git a/heroku/index.js b/heroku/index.js
index 689833d26..dd3670473 100644
--- a/heroku/index.js
+++ b/heroku/index.js
@@ -4,6 +4,7 @@ var yeoman = require('yeoman-generator');
var exec = require('child_process').exec;
var chalk = require('chalk');
var path = require('path');
+var s = require('underscore.string');
var Generator = module.exports = function Generator() {
yeoman.generators.Base.apply(this, arguments);
@@ -14,7 +15,7 @@ var Generator = module.exports = function Generator() {
} catch (e) {
this.appname = path.basename(process.cwd());
}
- this.appname = this._.slugify(this.appname);
+ this.appname = s.slugify(this.appname);
this.filters = this.config.get('filters') || {};
};
@@ -29,7 +30,7 @@ Generator.prototype.askForName = function askForName() {
}];
this.prompt(prompts, function (props) {
- this.deployedName = this._.slugify(props.deployedName);
+ this.deployedName = s.slugify(props.deployedName);
done();
}.bind(this));
};
diff --git a/openshift/index.js b/openshift/index.js
index 7929c0e09..c0f8f171f 100644
--- a/openshift/index.js
+++ b/openshift/index.js
@@ -4,6 +4,7 @@ var yeoman = require('yeoman-generator');
var childProcess = require('child_process');
var chalk = require('chalk');
var path = require('path');
+var s = require('underscore.string');
var exec = childProcess.exec;
var spawn = childProcess.spawn;
@@ -16,7 +17,7 @@ var Generator = module.exports = function Generator() {
} catch (e) {
this.appname = path.basename(process.cwd());
}
- this.appname = this._.slugify(this.appname).split('-').join('');
+ this.appname = s.slugify(this.appname).split('-').join('');
this.filters = this.config.get('filters') || {};
};
@@ -32,7 +33,7 @@ Generator.prototype.askForName = function askForName() {
}];
this.prompt(prompts, function (props) {
- this.deployedName = this._.slugify(props.deployedName).split('-').join('');
+ this.deployedName = s.slugify(props.deployedName).split('-').join('');
done();
}.bind(this));
};
diff --git a/package.json b/package.json
index c36bf2d50..45c91f865 100644
--- a/package.json
+++ b/package.json
@@ -37,7 +37,11 @@
"babel-core": "^5.8.23",
"chalk": "^1.1.0",
"generator-ng-component": "~0.1.0",
- "yeoman-generator": "~0.18.10"
+ "glob": "^5.0.14",
+ "lodash": "^3.10.1",
+ "underscore.string": "^3.1.1",
+ "yeoman-generator": "~0.19.2",
+ "yeoman-welcome": "^1.0.1"
},
"devDependencies": {
"chai": "^3.2.0",
@@ -55,7 +59,7 @@
"q": "^1.0.1",
"recursive-readdir": "^1.2.0",
"shelljs": "^0.5.3",
- "underscore.string": "^3.1.1"
+ "yeoman-assert": "^2.0.0"
},
"engines": {
"node": ">=0.12.0",
diff --git a/test/test-file-creation.js b/test/test-file-creation.js
index 7850fc9e4..1f2162142 100644
--- a/test/test-file-creation.js
+++ b/test/test-file-creation.js
@@ -4,6 +4,7 @@ var path = require('path');
var fs = require('fs');
var exec = require('child_process').exec;
var helpers = require('yeoman-generator').test;
+var assert = require('yeoman-assert');
var chai = require('chai');
var expect = chai.expect;
var recursiveReadDir = require('recursive-readdir');
@@ -31,7 +32,9 @@ describe('angular-fullstack generator', function () {
gen.run(function () {
var afGenerator;
var deps = [path.join('../..', generatorType)];
- afGenerator = helpers.createGenerator('angular-fullstack:' + generatorType, deps, [name]);
+ afGenerator = helpers.createGenerator('angular-fullstack:' + generatorType, deps, [name], {
+ skipInstall: true
+ });
helpers.mockPrompt(afGenerator, mockPrompt);
afGenerator.run(function () {
@@ -328,8 +331,9 @@ describe('angular-fullstack generator', function () {
return done(err);
}
- gen = helpers.createGenerator('angular-fullstack:app', deps);
- gen.options['skip-install'] = true;
+ gen = helpers.createGenerator('angular-fullstack:app', deps, [], {
+ skipInstall: true
+ });
done();
}.bind(this));
});
@@ -337,13 +341,13 @@ describe('angular-fullstack generator', function () {
describe('making sure test fixtures are present', function() {
it('should have package.json in fixtures', function() {
- helpers.assertFile([
+ assert.file([
path.join(__dirname, 'fixtures', 'package.json')
]);
});
it('should have bower.json in fixtures', function() {
- helpers.assertFile([
+ assert.file([
path.join(__dirname, 'fixtures', 'bower.json')
]);
});
@@ -355,7 +359,7 @@ describe('angular-fullstack generator', function () {
deps = deps.map(function(dep) {
return path.join(__dirname, 'fixtures', 'node_modules', dep);
});
- helpers.assertFile(deps);
+ assert.file(deps);
});
it('should have all bower packages in fixtures/bower_components', function() {
@@ -365,7 +369,7 @@ describe('angular-fullstack generator', function () {
deps = deps.map(function(dep) {
return path.join(__dirname, 'fixtures', 'bower_components', dep);
});
- helpers.assertFile(deps);
+ assert.file(deps);
});
});
@@ -429,7 +433,7 @@ describe('angular-fullstack generator', function () {
it('should generate expected files with path name endpoint', function(done) {
runTest('(exit 0)', this, function() {
- helpers.assertFile([
+ assert.file([
'server/api/foo/bar/index.js',
'server/api/foo/bar/index.spec.js',
'server/api/foo/bar/bar.controller.js',
@@ -452,13 +456,14 @@ describe('angular-fullstack generator', function () {
helpers.createDummyGenerator(),
'ng-component:app'
]
- ]);
- gen.options['skip-install'] = true;
+ ], [], {
+ skipInstall: true
+ });
helpers.mockPrompt(gen, {
skipConfig: true
});
gen.run(function () {
- helpers.assertFile([
+ assert.file([
'client/app/main/main.less',
'client/app/main/main.coffee',
'server/auth/google/passport.js'
@@ -469,7 +474,7 @@ describe('angular-fullstack generator', function () {
it('should generate expected files', function (done) {
gen.run(function () {
- helpers.assertFile(genFiles(defaultOptions));
+ assert.file(genFiles(defaultOptions));
done();
});
});
@@ -540,7 +545,7 @@ describe('angular-fullstack generator', function () {
it('should generate expected files', function (done) {
gen.run(function () {
- helpers.assertFile(genFiles(testOptions));
+ assert.file(genFiles(testOptions));
done();
});
});
@@ -612,7 +617,7 @@ describe('angular-fullstack generator', function () {
it('should generate expected files', function (done) {
gen.run(function () {
- helpers.assertFile(genFiles(testOptions));
+ assert.file(genFiles(testOptions));
done();
});
});
@@ -686,7 +691,7 @@ describe('angular-fullstack generator', function () {
it('should generate expected files', function (done) {
gen.run(function () {
- helpers.assertFile(genFiles(testOptions));
+ assert.file(genFiles(testOptions));
done();
});
});
@@ -747,7 +752,7 @@ describe('angular-fullstack generator', function () {
it('should generate expected files', function (done) {
gen.run(function () {
- helpers.assertFile(genFiles(testOptions));
+ assert.file(genFiles(testOptions));
done();
});
});
diff --git a/util.js b/util.js
index d23e7f693..ce7b7733b 100644
--- a/util.js
+++ b/util.js
@@ -2,6 +2,15 @@
import path from 'path';
import fs from 'fs';
+import glob from 'glob';
+
+function expandFiles(pattern, options) {
+ options = options || {};
+ var cwd = options.cwd || process.cwd();
+ return glob.sync(pattern, options).filter(function (filepath) {
+ return fs.statSync(path.join(cwd, filepath)).isFile();
+ });
+}
export function rewriteFile(args) {
args.path = args.path || process.cwd();
@@ -56,7 +65,7 @@ export function rewrite(args) {
export function appSuffix(self) {
var suffix = self.options['app-suffix'];
- return (typeof suffix === 'string') ? self._.classify(suffix) : '';
+ return (typeof suffix === 'string') ? self.lodash.classify(suffix) : '';
}
function destinationPath(self, filepath) {
@@ -98,7 +107,7 @@ function templateIsUsable(self, filteredFile) {
for(var key in filters) {
if(filters[key]) enabledFilters.push(key);
}
- var matchedFilters = self._.intersection(filteredFile.filters, enabledFilters);
+ var matchedFilters = self.lodash.intersection(filteredFile.filters, enabledFilters);
// check that all filters on file are matched
if(filteredFile.filters.length && matchedFilters.length !== filteredFile.filters.length) {
return false;
@@ -108,8 +117,8 @@ function templateIsUsable(self, filteredFile) {
export function processDirectory(source, destination) {
var self = this;
- var root = self.isPathAbsolute(source) ? source : path.join(self.sourceRoot(), source);
- var files = self.expandFiles('**', { dot: true, cwd: root });
+ var root = path.isAbsolute(source) ? source : path.join(self.sourceRoot(), source);
+ var files = expandFiles('**', { dot: true, cwd: root });
var dest, src;
files.forEach(function(f) {