-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from UndeadBaneGitHub/angular-config
Angular config subgenerator and test added
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// ... | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |