Skip to content

Commit

Permalink
Merge pull request #158 from UndeadBaneGitHub/angular-config
Browse files Browse the repository at this point in the history
Angular config subgenerator and test added
  • Loading branch information
codydaig committed Jan 11, 2016
2 parents 77835fb + 738c340 commit b651438
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
56 changes: 56 additions & 0 deletions angular-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

var fs = require('fs'),
s = require('underscore.string'),
yeoman = require('yeoman-generator');

var ConfigGenerator = yeoman.generators.Base.extend({
askForModuleName: function () {
var modulesFolder = process.cwd() + '/modules/';
var done = this.async();

var prompts = [{
type: 'list',
name: 'moduleName',
default: 'core',
message: 'Which module does this configuration file belongs to?',
choices: []
},{
type: 'input',
name: 'name',
default: '',
message: 'What is the name of the config (leave it blank to inherit it from module)?'
}];

if (fs.existsSync(modulesFolder)) {
fs.readdirSync(modulesFolder).forEach(function (folder) {
var stat = fs.statSync(modulesFolder + '/' + folder);

if (stat.isDirectory()) {
prompts[0].choices.push({
value: folder,
name: folder
});
}
});
}

this.prompt(prompts, function (props) {
this.moduleName = props.moduleName;
this.name = props.name || this.moduleName;

this.slugifiedModuleName = s(this.moduleName).humanize().slugify().value();
this.humanizedModuleName = s(this.moduleName).humanize().value();

this.slugifiedName = s(this.name).slugify().value();

done();
}.bind(this));
},

renderConfigFile: function () {
this.template('_.client.config.js', 'modules/' + this.slugifiedModuleName + '/client/config/' + this.slugifiedName + '.client.config.js')
}
});

module.exports = ConfigGenerator;
9 changes: 9 additions & 0 deletions angular-config/templates/_.client.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

// <%= humanizedModuleName %> module config
angular.module('<%= slugifiedModuleName %>').run(['Menus',
function (Menus) {
// Config logic
// ...
}
]);
70 changes: 70 additions & 0 deletions test/angular-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

var path = require('path'),
helpers = require('yeoman-generator').test,
assert = require('yeoman-generator').assert,
temp = require('temp').track();

describe('AngularJS Sub Generators Tests', function () {
this.timeout(0);
/**
* Setup the temp directory
*/
before(function (done) {
helpers.testDirectory(path.join(__dirname, 'temp'), done);
});

/**
* Clean up temp directory
*/
after(function () {
temp.cleanup();
});

describe('Generate an AngularJS config file through the sub-generator', function () {
beforeEach(function (done) {
helpers.run(path.join(__dirname, '../angular-config'))
.withOptions({
'skip-install': true
})
.withPrompts({
'moduleName': 'core',
'name': 'foo'
})
.on('ready', function (generator) {
// this is called right before `generator.run()` is called
})
.on('end', function () {
done();
});
});

it('should generate an angular config file', function (done) {
assert.file('modules/core/client/config/foo.client.config.js');
done();
});
});

describe('Generate an AngularJS config file through the sub-generator (no name specified)', function () {
beforeEach(function (done) {
helpers.run(path.join(__dirname, '../angular-config'))
.withOptions({
'skip-install': true
})
.withPrompts({
'moduleName': 'core'
})
.on('ready', function (generator) {
// this is called right before `generator.run()` is called
})
.on('end', function () {
done();
});
});

it('should generate an angular config file', function (done) {
assert.file('modules/core/client/config/core.client.config.js');
done();
});
});
});

0 comments on commit b651438

Please sign in to comment.