Skip to content

Commit

Permalink
feat: improve generator
Browse files Browse the repository at this point in the history
- update some files
- add prompt for github
- add .gitignore an update scripts to template
- add grunt test to run the generator for development
- add commit message hook
  • Loading branch information
Andreas Krummsdorf committed Jun 13, 2014
1 parent 4fb68f2 commit f3aca58
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 90 deletions.
12 changes: 10 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# http://editorconfig.org
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 4
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
demo/
node_modules/
temp/
20 changes: 17 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
Expand All @@ -11,11 +11,25 @@
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true
"globals": {
"angular": false,
"after": false,
"afterEach": false,
"before": false,
"beforeEach": false,
"browser": false,
"describe": false,
"expect": false,
"inject": false,
"it": false,
"jasmine": false,
"spyOn": false,
"element": false,
"by": false
}
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- '0.8'
- '0.10'
before_install:
- currentfolder=${PWD##*/}
Expand Down
102 changes: 102 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict';

var fs = require('fs');

module.exports = function (grunt) {
// load npm tasks
require('load-grunt-tasks')(grunt);

// Project configuration.
grunt.initConfig({
jshintFiles: ['Gruntfile.js', 'app/**/*.js', '!app/**/_*.js', 'toplevel/**/*.js', '!toplevel/**/_*.js'],
pkg: grunt.file.readJSON('package.json'),
clean: {
reports: ['.reports'],
demo: ['demo']
},
jshint: {
options: {
jshintrc: true
},
test: '<%= jshintFiles %>',
jslint: {
options: {
reporter: 'jslint',
reporterOutput: '.reports/lint/jshint.xml'
},
files: {
src: '<%= jshintFiles %>'
}
},
checkstyle: {
options: {
reporter: 'checkstyle',
reporterOutput: '.reports/lint/jshint_checkstyle.xml'
},
files: {
src: '<%= jshintFiles %>'
}
}
},
bgShell: {
generator: {
cmd: 'cd demo && yo baboon'
},
link: {
cmd: 'npm link'
},
sudo_link: {
cmd: 'sudo npm link'
}
},
changelog: {
options: {
}
},
bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: ['pkg'],
commitFiles: ['-a'],
commitMessage: 'chore: release v%VERSION%',
push: false
}
}
});

// Register tasks.
grunt.registerTask('git:commitHook', 'Install git commit hook', function () {
grunt.file.copy('validate-commit-msg.js', '.git/hooks/commit-msg');
fs.chmodSync('.git/hooks/commit-msg', '0755');
grunt.log.ok('Registered git hook: commit-msg');
});

grunt.registerTask('mkdir:demo', 'Create test directory', function () {
grunt.file.mkdir(require('path').join(__dirname, 'demo'));
});

grunt.registerTask('link', 'Do npm link to test the generator', function () {
if (process.platform === 'win32') {
grunt.task.run(['bgShell:link']);
} else {
grunt.task.run(['bgShell:sudo_link']);
}
});

grunt.registerTask('test', 'Test the generator', function () {
grunt.task.run(['git:commitHook', 'jshint:test', 'clean:demo', 'mkdir:demo', 'link', 'bgShell:generator']);
});

grunt.registerTask('lint', ['jshint:test']);
grunt.registerTask('ci', ['clean', 'jshint:jslint', 'jshint:checkstyle']);
grunt.registerTask('release', 'Bump version, update changelog and tag version', function (version) {
grunt.task.run([
'bump:' + (version || 'patch') + ':bump-only',
'changelog',
'bump-commit'
]);
});

// Default task.
grunt.registerTask('default', 'lint');
};
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2014
Copyright 2014

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
42 changes: 36 additions & 6 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
Expand All @@ -19,7 +20,7 @@ var banner =
' ░ ░ \n' +
' by Litixsoft \n';

var BaboonGenerator = module.exports = function BaboonGenerator(args, options) {
var BaboonGenerator = module.exports = function BaboonGenerator (args, options) {
yeoman.generators.Base.apply(this, arguments);

this.argument('app_name', { type: String, required: false });
Expand Down Expand Up @@ -55,7 +56,7 @@ var BaboonGenerator = module.exports = function BaboonGenerator(args, options) {

this.on('exit', function () {
var help = [
' I\'m all done. Enter `' + chalk.yellow.bold('grunt serve') + '` to start your application. They will be serve on `' + chalk.yellow.bold(this.baboon.app_protocol + '://localhost:' + this.baboon.app_port) + '`.'
' I\'m all done. Enter `' + chalk.yellow.bold('grunt serve') + '` to start your application. They will be serve on `' + chalk.yellow.bold(this.baboon.app_protocol + '://localhost:' + this.baboon.app_port) + '`.'
];

if (this.baboon.app_rights_enabled) {
Expand All @@ -68,7 +69,7 @@ var BaboonGenerator = module.exports = function BaboonGenerator(args, options) {

util.inherits(BaboonGenerator, yeoman.generators.Base);

BaboonGenerator.prototype.askFor = function askFor() {
BaboonGenerator.prototype.askFor = function askFor () {
var done = this.async();

// Validators
Expand Down Expand Up @@ -111,6 +112,22 @@ BaboonGenerator.prototype.askFor = function askFor() {
message: 'Whats the name of your baboon application?',
default: this.app_name
},
// github?
{
type: 'confirm',
name: 'useGithub',
message: 'Would you like to use github?',
default: false
},
{
when: function (answer) {
return (answer && answer.useGithub === true);
},
type: 'input',
name: 'githubUsername',
message: 'Whats the Github username?',
default: ''
},
{
validate: validateIsPort,
type: 'input',
Expand Down Expand Up @@ -200,11 +217,17 @@ BaboonGenerator.prototype.askFor = function askFor() {
this.baboon.app_protocol = 'http';
this.baboon.app_session_secret = shasum.digest('hex');

if(props.githubUsername){
this.baboon.repoUrl = 'https://github.com/' + props.githubUsername + '/' + this._.slugify(props.app_name);
} else {
this.baboon.repoUrl = 'user/repo';
}

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

BaboonGenerator.prototype.app = function app() {
BaboonGenerator.prototype.app = function app () {
this.directory('client', 'client');
this.directory('scripts', 'scripts');
this.directory('server', 'server');
Expand All @@ -214,18 +237,25 @@ BaboonGenerator.prototype.app = function app() {
this.copy('Gruntfile.js', 'Gruntfile.js');
this.copy('client_settings.js', 'client_settings.js');
this.copy('server.js', 'server.js');
this.copy('update.bat', 'update.bat');
this.copy('update.sh', 'update.sh');

this.copy('.bowerrc', '.bowerrc');
this.copy('.editorconfig', '.editorconfig');
this.copy('.jshintrc', '.jshintrc');

if (this.baboon.useGithub) {
this.copy('_gitignore', '.gitignore');
this.copy('LICENSE', 'LICENSE');
}
};

BaboonGenerator.prototype.packageFiles = function packageFiles() {
BaboonGenerator.prototype.packageFiles = function packageFiles () {
this.template('_package.json', 'package.json');
this.template('_bower.json', 'bower.json');
this.template('_readme.md', 'README.md');
};

BaboonGenerator.prototype.configFiles = function configFiles() {
BaboonGenerator.prototype.configFiles = function configFiles () {
this.template('_config.js', 'config.js');
};
5 changes: 1 addition & 4 deletions app/templates/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
Expand All @@ -31,8 +30,6 @@
"jasmine": false,
"spyOn": false,
"element": false,
"by": false,
"runs": false,
"waitsFor": false
"by": false
}
}
3 changes: 1 addition & 2 deletions app/templates/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Release History
## v0.4.0

## v0.0.1 project initial
20 changes: 20 additions & 0 deletions app/templates/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright <year>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55 changes: 27 additions & 28 deletions app/templates/_bower.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"name": "<%= _.slugify(baboon.app_name) %>",
"version": "0.0.1",
"dependencies": {
"angular": "1.2.14",
"json3": "~3.2.6",
"es5-shim": "~2.1.0",
"bootstrap": "~3.0.3",
"angular-route": "1.2.14",
"angular-resource": "1.2.14",
"angular-cookies": "1.2.14",
"angular-sanitize": "1.2.14",
"angular-bootstrap": "~0.10.0",
"angular-highlightjs": "0.2.1",
"angular-translate": "~2.0.0",
"angular-translate-loader-static-files": "~2.1.0",
"angular-dynamic-locale": "0.1.1",
"angular-i18n": "1.2.14",
"baboon-client": "https://github.com/litixsoft/baboon-client.git#v0.4",
"checklist-model": "~0.1.3"
},
"devDependencies": {
"angular-mocks": "1.2.14",
"angular-scenario": "1.2.14"
},
"resolutions": {
"angular-translate-loader-static-files": "2.1.0",
"angular-translate": "~2.1.0"
}
"name": "<%= _.slugify(baboon.app_name) %>",
"version": "0.0.1",
"dependencies": {
"angular": "1.2.14",
"angular-bootstrap": "~0.10.0",
"angular-cookies": "1.2.14",
"angular-dynamic-locale": "0.1.1",
"angular-i18n": "1.2.14",
"angular-resource": "1.2.14",
"angular-route": "1.2.14",
"angular-sanitize": "1.2.14",
"angular-translate": "~2.0.0",
"angular-translate-loader-static-files": "~2.1.0",
"baboon-client": "https://github.com/litixsoft/baboon-client.git#v0.4",
"bootstrap": "~3.0.3",
"checklist-model": "~0.1.3",
"es5-shim": "~2.1.0",
"json3": "~3.2.6"
},
"devDependencies": {
"angular-mocks": "1.2.14",
"angular-scenario": "1.2.14"
},
"resolutions": {
"angular-translate": "~2.1.0",
"angular-translate-loader-static-files": "2.1.0"
}
}
9 changes: 9 additions & 0 deletions app/templates/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
.reports
.tmp
.dist
client/assets/bower_components
server/var/config
server/var/db
server/var/logs
node_modules
Loading

0 comments on commit f3aca58

Please sign in to comment.