diff --git a/.editorconfig b/.editorconfig index c308ed0..c2cdfb8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore index 9a42fb0..b73183a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea +demo/ node_modules/ temp/ diff --git a/.jshintrc b/.jshintrc index fa51fc3..bd5e132 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,8 +1,8 @@ { "node": true, + "browser": true, "esnext": true, "bitwise": true, - "camelcase": true, "curly": true, "eqeqeq": true, "immed": true, @@ -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 + } } diff --git a/.travis.yml b/.travis.yml index 56ac8e3..6b1b52f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - - '0.8' - '0.10' before_install: - currentfolder=${PWD##*/} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..933dd1b --- /dev/null +++ b/Gruntfile.js @@ -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'); +}; \ No newline at end of file diff --git a/LICENSE b/LICENSE index e7895de..35bffb8 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/app/index.js b/app/index.js index 3143ada..b312927 100644 --- a/app/index.js +++ b/app/index.js @@ -1,4 +1,5 @@ 'use strict'; + var util = require('util'); var path = require('path'); var yeoman = require('yeoman-generator'); @@ -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 }); @@ -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) { @@ -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 @@ -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', @@ -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'); @@ -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'); }; \ No newline at end of file diff --git a/app/templates/.jshintrc b/app/templates/.jshintrc index 59fa0d6..bd5e132 100644 --- a/app/templates/.jshintrc +++ b/app/templates/.jshintrc @@ -11,7 +11,6 @@ "newcap": true, "noarg": true, "quotmark": "single", - "regexp": true, "undef": true, "unused": true, "strict": true, @@ -31,8 +30,6 @@ "jasmine": false, "spyOn": false, "element": false, - "by": false, - "runs": false, - "waitsFor": false + "by": false } } diff --git a/app/templates/CHANGELOG.md b/app/templates/CHANGELOG.md index d6a9c74..58179c5 100644 --- a/app/templates/CHANGELOG.md +++ b/app/templates/CHANGELOG.md @@ -1,3 +1,2 @@ # Release History -## v0.4.0 - +## v0.0.1 project initial \ No newline at end of file diff --git a/app/templates/LICENSE b/app/templates/LICENSE new file mode 100644 index 0000000..8c534d1 --- /dev/null +++ b/app/templates/LICENSE @@ -0,0 +1,20 @@ +Copyright + +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. diff --git a/app/templates/_bower.json b/app/templates/_bower.json index 387ae18..a4273e2 100644 --- a/app/templates/_bower.json +++ b/app/templates/_bower.json @@ -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" + } } \ No newline at end of file diff --git a/app/templates/_gitignore b/app/templates/_gitignore new file mode 100644 index 0000000..d5841f8 --- /dev/null +++ b/app/templates/_gitignore @@ -0,0 +1,9 @@ +.idea +.reports +.tmp +.dist +client/assets/bower_components +server/var/config +server/var/db +server/var/logs +node_modules \ No newline at end of file diff --git a/app/templates/_package.json b/app/templates/_package.json index 28db44f..0fbe1e3 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -4,15 +4,15 @@ "version": "0.0.1", "homepage": "your homepage", "author": { - "name": "your company", + "name": "your name", "email": "info@company.com" }, "repository": { "type": "git", - "url": "your git project url" + "url": "<%= baboon.repoUrl %>.git" }, "bugs": { - "url": "your bugtracker url" + "url": "<%= baboon.repoUrl %>/issues" }, "keywords": [ "your keywords" @@ -21,10 +21,9 @@ "licenses": [ { "type": "MIT", - "url": "your licence url" + "url": "<%= baboon.repoUrl %>/blob/master/LICENSE" } ], - "readmeFilename": "README.md", "dependencies": { "async": "^0.7.0", "baboon": "^0.4.0", @@ -36,45 +35,45 @@ "connect-livereload": "^0.4.0", "grunt": "~0.4.3", "grunt-autoprefixer": "~0.4.0", + "grunt-bg-shell": "~2.3.0", "grunt-concurrent": "~0.4.1", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-cssmin": "~0.7.0", "grunt-contrib-htmlmin": "~0.1.3", - "jpegtran-bin": "0.2.0", "grunt-contrib-imagemin": "~0.3.0", "grunt-contrib-jshint": "~0.7.1", + "grunt-contrib-less": "~0.9.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-watch": "~0.5.2", + "grunt-express-server": "~0.4.5", + "grunt-jasmine-node": "~0.1.0", + "grunt-karma": "~0.8.0", "grunt-newer": "~0.5.4", "grunt-ngmin": "~0.0.2", + "grunt-open": "~0.2.0", "grunt-rev": "~0.1.0", + "grunt-shell": "~0.6.1", "grunt-svgmin": "~0.2.0", "grunt-usemin": "~2.0.0", + "istanbul": "~0.1.45", + "jpegtran-bin": "0.2.0", "jshint-stylish": "~0.1.3", - "load-grunt-tasks": "~0.2.0", - "time-grunt": "~0.2.1", - "grunt-express-server": "~0.4.5", - "grunt-open": "~0.2.0", - "karma-ng-scenario": "~0.1.0", - "karma-script-launcher": "~0.1.0", + "karma-coverage": "~0.2.0", + "karma-detect-browsers": "~0.1.2", "karma-html2js-preprocessor": "~0.1.0", "karma-jasmine": "~0.2.1", - "requirejs": "~2.1.10", - "karma-requirejs": "~0.2.1", - "karma-ng-html2js-preprocessor": "~0.1.0", - "grunt-karma": "~0.8.0", - "karma-mocha-reporter": "~0.2.2", - "karma-detect-browsers": "~0.1.2", "karma-junit-reporter": "~0.2.1", - "grunt-shell": "~0.6.1", - "karma-coverage": "~0.2.0", - "grunt-jasmine-node": "~0.1.0", - "grunt-bg-shell": "~2.3.0", - "istanbul": "~0.1.45", - "grunt-contrib-less": "~0.9.0", - "protractor": "~0.17.0" + "karma-mocha-reporter": "~0.2.2", + "karma-ng-html2js-preprocessor": "~0.1.0", + "karma-ng-scenario": "~0.1.0", + "karma-requirejs": "~0.2.1", + "karma-script-launcher": "~0.1.0", + "load-grunt-tasks": "~0.2.0", + "protractor": "~0.17.0", + "requirejs": "~2.1.10", + "time-grunt": "~0.2.1" }, "engines": { "node": ">=0.10.0" diff --git a/app/templates/_readme.md b/app/templates/_readme.md index 1cc66a4..5d086c4 100644 --- a/app/templates/_readme.md +++ b/app/templates/_readme.md @@ -5,7 +5,7 @@ # Author - + # License Copyright (C) diff --git a/app/templates/client/app/main/index.html b/app/templates/client/app/main/index.html index 5ca4335..f712750 100644 --- a/app/templates/client/app/main/index.html +++ b/app/templates/client/app/main/index.html @@ -14,7 +14,6 @@ - @@ -91,8 +90,6 @@

{{ 'APP_HEADER' | translate }}

- - diff --git a/app/templates/update.bat b/app/templates/update.bat new file mode 100644 index 0000000..ccf22ad --- /dev/null +++ b/app/templates/update.bat @@ -0,0 +1,7 @@ +@echo off +if exist "node_modules" rd /s /q "node_modules" +if exist "client\assets\bower_components" rd /s /q "client\assets\bower_components" + +call npm install +call bower cache clean +call bower install diff --git a/app/templates/update.sh b/app/templates/update.sh new file mode 100755 index 0000000..bb27d1a --- /dev/null +++ b/app/templates/update.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ -d "node_modules" ]; then + rm -R node_modules +fi + +if [ -d "client/assets/bower_components" ]; then + rm -R client/assets/bower_components +fi + +npm install +bower cache clean +bower install \ No newline at end of file diff --git a/package.json b/package.json index 6f89c8c..b0a294b 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,27 @@ "name": "generator-baboon", "version": "0.4.2", "description": "Yeoman generator for Baboon", + "homepage": "https://github.com/litixsoft/generator-baboon", + "author": "Litixsoft GmbH (http://www.litixsoft.de)", + "maintainers": [ + "Thomas Scheibe ", + "Timo Liebetrau ", + "Andreas Krummsdorf " + ], + "repository": { + "type": "git", + "url": "https://github.com/litixsoft/generator-baboon.git" + }, + "bugs": { + "url": "https://github.com/litixsoft/generator-baboon/issues" + }, + "license": "The MIT License (MIT)", + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/litixsoft/generator-baboon/blob/master/LICENSE" + } + ], "keywords": [ "yeoman-generator", "scaffold", @@ -13,28 +34,27 @@ "baboon" ], "dependencies": { - "yeoman-generator": "~0.16.0", + "yeoman-generator": "^0.16.0", "chalk": "^0.4.0" }, "peerDependencies": { "yo": ">=1.0.0" }, "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.8.0", - "grunt-conventional-changelog": "~1.1.0", - "grunt-release": "~0.6.0", - "load-grunt-tasks": "~0.3.0", - "underscore.string": "~2.3.1" + "grunt": "^0.4.5", + "grunt-bg-shell": "^2.3.1", + "grunt-contrib-clean": "^0.5.0", + "grunt-contrib-jshint": "^0.10.0", + "grunt-conventional-changelog": "^1.1.0", + "grunt-release": "^0.7.0", + "load-grunt-tasks": "^0.5.0", + "underscore.string": "^2.3.3" }, "engines": { "node": ">=0.10.0", "npm": ">=1.2.10" }, - "licenses": [ - { - "type": "MIT" - } - ] - + "scripts": { + "test": "grunt lint" + } } diff --git a/toplevel/templates/index/index.js b/toplevel/templates/index/index.js index 7af6dc2..10ac4ab 100644 --- a/toplevel/templates/index/index.js +++ b/toplevel/templates/index/index.js @@ -1,4 +1,3 @@ - 'use strict'; angular.module('<%= TopLevelName %>.<%= TopLevelPageName %>', []) diff --git a/validate-commit-msg.js b/validate-commit-msg.js new file mode 100644 index 0000000..e0046b1 --- /dev/null +++ b/validate-commit-msg.js @@ -0,0 +1,105 @@ +#!/usr/bin/env node + +/** + * Git COMMIT-MSG hook for validating commit message + * See https://docs.google.com/document/d/1rk04jEuGfk9kYzfqCuOlPTSJw3hEDZJTBN5E5f1SALo/edit + * + * Installation: + * >> cd lx-helpers + * >> ln -s validate-commit-msg.js .git/hooks/commit-msg + */ +var fs = require('fs'); +var util = require('util'); + + +var MAX_LENGTH = 200; +var PATTERN = /^(?:fixup!\s*)?(\w*)(\(([\w\$\.\-\*/]*)\))?\: (.*)$/; +var IGNORED = /^WIP\:/; +var TYPES = { + feat: true, + fix: true, + docs: true, + style: true, + refactor: true, + test: true, + chore: true, + revert: true +}; + + +var error = function() { + // gitx does not display it + // http://gitx.lighthouseapp.com/projects/17830/tickets/294-feature-display-hook-error-message-when-hook-fails + // https://groups.google.com/group/gitx/browse_thread/thread/a03bcab60844b812 + console.error('INVALID COMMIT MSG: ' + util.format.apply(null, arguments)); +}; + + +var validateMessage = function(message) { + var isValid = true; + + if (IGNORED.test(message)) { + console.log('Commit message validation ignored.'); + return true; + } + + if (message.length > MAX_LENGTH) { + error('is longer than %d characters !', MAX_LENGTH); + isValid = false; + } + + var match = PATTERN.exec(message); + + if (!match) { + error('does not match "(): " ! was: ' + message); + return false; + } + + var type = match[1]; + var scope = match[3]; + var subject = match[4]; + + if (!TYPES.hasOwnProperty(type)) { + error('"%s" is not allowed type !', type); + return false; + } + + // Some more ideas, do want anything like this ? + // - allow only specific scopes (eg. fix(docs) should not be allowed ? + // - auto correct the type to lower case ? + // - auto correct first letter of the subject to lower case ? + // - auto add empty line after subject ? + // - auto remove empty () ? + // - auto correct typos in type ? + // - store incorrect messages, so that we can learn + + return isValid; +}; + + +var firstLineFromBuffer = function(buffer) { + return buffer.toString().split('\n').shift(); +}; + + + +// publish for testing +exports.validateMessage = validateMessage; + +// hacky start if not run by jasmine :-D +if (process.argv.join('').indexOf('jasmine-node') === -1) { + var commitMsgFile = process.argv[2]; + var incorrectLogFile = commitMsgFile.replace('COMMIT_EDITMSG', 'logs/incorrect-commit-msgs'); + + fs.readFile(commitMsgFile, function(err, buffer) { + var msg = firstLineFromBuffer(buffer); + + if (!validateMessage(msg)) { + fs.appendFile(incorrectLogFile, msg + '\n', function() { + process.exit(1); + }); + } else { + process.exit(0); + } + }); +} \ No newline at end of file