diff --git a/README.md b/README.md index 072a5b6..2dfc0c5 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,18 @@ Create an Angular application using the HotTowel style (via a [Yeoman](http://ye 3. Run the generator ```bash - yo hottowel + yo hottowel helloWorld ``` + +## HotTowel Options + +### Application Name + - Pass in the app's name to avoid being prompted for it + + ```bash + yo hottowel [appName] + ``` + ## Running HotTowel ### Linting diff --git a/app/index.js b/app/index.js index 161d4b0..dd55886 100644 --- a/app/index.js +++ b/app/index.js @@ -2,72 +2,90 @@ var util = require('util'); var path = require('path'); var yeoman = require('yeoman-generator'); +var generators = yeoman.generators; var yosay = require('yosay'); var chalk = require('chalk'); -var HottowelGenerator = yeoman.generators.Base.extend({ - prompting: function () { - var done = this.async(); +var HottowelGenerator = generators.Base.extend({ - // Have Yeoman greet the user. + constructor: function() { + // arguments and options should be + // defined in the constructor. + generators.Base.apply(this, arguments); + + this.argument('appName', { type: String, required: false }); + this.appName = this._.camelize(this._.slugify(this._.humanize(this.appName))); + }, + + welcome: function() { this.log(yosay( 'Welcome to the HotTowel AngularJS generator!' )); + }, -// var prompts = [{ -// type: 'confirm', -// name: 'expressServer', -// message: 'Would you like to add an express server?', -// default: true -// }]; - - this.expressServer = true; + prompting: function () { + // If we passed in the app name, don't prompt the user for it + if(this.appName) { + return; + } -// this.prompt(prompts, function (props) { -// this.expressServer = props.expressServer; -// + var done = this.async(); + + var prompts = [{ + type: 'input', + name: 'appName', + message: 'What would you like to name the app?', + default: this.appName || path.basename(process.cwd()) + }]; + + this.prompt(prompts, function (answers) { + this.appName = answers.appName; + this.appName = this.appName || 'hottowel'; //path.basename(process.cwd()); done(); -// }.bind(this)); + }.bind(this)); }, + displayName: function() { + this.log('Creating ' + this.appName + ' app based on HotTowel.'); + }, + scaffoldFolders: function () { this.mkdir('src'); this.mkdir('src/client'); this.mkdir('src/client/app'); - if (this.expressServer) { - this.mkdir('src/server'); - } + this.mkdir('src/server'); }, - app: function () { - this.src.copy('_package.json', 'package.json'); - this.src.copy('_bower.json', 'bower.json'); - this.src.copy('_gulpfile.js', 'gulpfile.js'); - this.src.copy('_gulp.config.json', 'gulp.config.json'); - this.src.copy('_karma.conf.js', 'karma.conf.js'); - this.src.copy('_README.md', 'README.md'); + packageFiles: function () { + var context = { + appName: this.appName + }; + + this.copy('_package.json', 'package.json'); + this.template('_bower.json', 'bower.json'); + this.template('_gulpfile.js', 'gulpfile.js'); + this.template('_gulp.config.json', 'gulp.config.json'); + this.template('_karma.conf.js', 'karma.conf.js'); + this.template('_README.md', 'README.md'); + }, + + appFiles: function () { this.directory('src/client/app'); this.directory('src/client/content'); this.directory('src/client/test'); - var context = { - site_name: this.appName - }; + this.template('src/client/_index.html', 'src/client/index.html'); - this.template('src/client/_index.html', 'src/client/index.html', context); - - if (this.expressServer) { - this.template('src/server/_app.js', 'src/server/app.js', context); - this.copy('src/server/favicon.ico'); - } + this.template('src/server/_app.js', 'src/server/app.js'); + this.copy('src/server/favicon.ico'); }, projectfiles: function () { - this.src.copy('editorconfig', '.editorconfig'); - this.src.copy('jshintrc', '.jshintrc'); - this.src.copy('jscsrc', '.jscsrc'); - this.src.copy('bowerrc', '.bowerrc'); + this.copy('editorconfig', '.editorconfig'); + this.copy('jshintrc', '.jshintrc'); + this.copy('jscsrc', '.jscsrc'); + this.copy('bowerrc', '.bowerrc'); }, runNpm: function () { diff --git a/app/templates/_README.md b/app/templates/_README.md index 972f651..6f19892 100644 --- a/app/templates/_README.md +++ b/app/templates/_README.md @@ -1,4 +1,6 @@ -# HotTowel Angular +# <%= appName %> + +**Generated from HotTowel Angular** >*Opinionated AngularJS style guide for teams by [@john_papa](//twitter.com/john_papa)* diff --git a/app/templates/_bower.json b/app/templates/_bower.json index 7551b0a..bfc0c9d 100644 --- a/app/templates/_bower.json +++ b/app/templates/_bower.json @@ -1,12 +1,9 @@ { - "name": "hottowel-ng", - "version": "3.0.0", - "description": "HotTowel Angular", - "authors": [ - "John Papa" - ], + "name": "<%= appName %>", + "version": "0.0.1", + "description": "<%= appName %>", + "authors": [], "license": "MIT", - "homepage": "https://github.com/johnpapa/hottowel-ng", "ignore": [ "**/.*", "node_modules", @@ -15,18 +12,18 @@ "tests" ], "devDependencies": { - "angular-mocks": "~1.3.2" + "angular-mocks": "~1.3.4" }, "dependencies": { "jquery": "~2.1.0", - "angular": "~1.3.2", - "angular-sanitize": "~1.3.2", + "angular": "~1.3.4", + "angular-sanitize": "~1.3.4", "bootstrap": "~3.2.0", "extras.angular.plus": "~0.9.2", "font-awesome": "~4.2.0", "moment": "~2.6.0", "angular-ui-router": "~0.2.12", "toastr": "~2.1.0", - "angular-animate": "~1.3.2" + "angular-animate": "~1.3.4" } } \ No newline at end of file diff --git a/app/templates/_gulpfile.js b/app/templates/_gulpfile.js index b63f305..5512f9f 100644 --- a/app/templates/_gulpfile.js +++ b/app/templates/_gulpfile.js @@ -415,11 +415,11 @@ function formatPercent(num, precision) { function getHeader() { var pkg = require('./package.json'); var template = ['/**', - ' * <%= pkg.name %> - <%= pkg.description %>', - ' * @authors <%= pkg.authors %>', - ' * @version v<%= pkg.version %>', - ' * @link <%= pkg.homepage %>', - ' * @license <%= pkg.license %>', + ' * <%%= pkg.name %> - <%%= pkg.description %>', + ' * @authors <%%= pkg.authors %>', + ' * @version v<%%= pkg.version %>', + ' * @link <%%= pkg.homepage %>', + ' * @license <%%= pkg.license %>', ' */', ''].join('\n'); return plug.header(template, {pkg : pkg}); diff --git a/app/templates/_karma.conf.js b/app/templates/_karma.conf.js index b83d0f8..8e0644d 100644 --- a/app/templates/_karma.conf.js +++ b/app/templates/_karma.conf.js @@ -1,6 +1,4 @@ // Karma configuration -// Generated on Sun Jul 13 2014 09:06:13 GMT-0400 (EDT) - module.exports = function (config) { config.set({ @@ -13,7 +11,7 @@ module.exports = function (config) { // list of files / patterns to load in the browser files: [ - './src/client/test/bindPolyfill.js', + './src/client/test/bind-polyfill.js', './bower_components/jquery/dist/jquery.js', './bower_components/angular/angular.js', diff --git a/app/templates/_package.json b/app/templates/_package.json index 19899e0..42afffb 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -1,7 +1,6 @@ { - "name": "HotTowel", - "description": "Project Generated from HotTowel Angular", - "repository": "TBD", + "name": "<%= appName %>", + "description": "<%= appName %> Project Generated from HotTowel Angular", "version": "0.0.0", "scripts": { "init": "npm install", diff --git a/app/templates/editorconfig b/app/templates/editorconfig index 5760be5..2536d66 100644 --- a/app/templates/editorconfig +++ b/app/templates/editorconfig @@ -3,7 +3,7 @@ root = true [*] indent_style = space -indent_size = 2 +indent_size = 4 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true diff --git a/app/templates/src/client/_index.html b/app/templates/src/client/_index.html index 9b6a45e..bac2045 100644 --- a/app/templates/src/client/_index.html +++ b/app/templates/src/client/_index.html @@ -6,7 +6,7 @@ /* Since Angular has this but needs to load, this gives us the class early. */ .ng-hide { display: none!important; } - Hot Towel Angular + <%= appName %> @@ -30,7 +30,7 @@
- Hot Towel Angular + <%= appName %>
diff --git a/app/templates/src/client/app/app.module.js b/app/templates/src/client/app/app.module.js index 7678854..7950f07 100644 --- a/app/templates/src/client/app/app.module.js +++ b/app/templates/src/client/app/app.module.js @@ -1,18 +1,9 @@ -(function () { +(function () { 'use strict'; angular.module('app', [ - /* - * Order is not important. Angular makes a - * pass to register all of the modules listed - * and then when app.dashboard tries to use app.data, - * it's components are available. - */ 'app.core', 'app.widgets', - /* - * Feature areas - */ 'app.admin', 'app.dashboard', 'app.layout' diff --git a/app/templates/src/client/app/core/config.js b/app/templates/src/client/app/core/config.js index 4e79cfa..bb8c959 100644 --- a/app/templates/src/client/app/core/config.js +++ b/app/templates/src/client/app/core/config.js @@ -12,8 +12,8 @@ } var config = { - appErrorPrefix: '[HotTowel Error] ', - appTitle: 'HotTowel Angular Demo' + appErrorPrefix: '[<%= appName %> Error] ', + appTitle: '<%= appName %>' }; core.value('config', config); @@ -26,7 +26,7 @@ $logProvider.debugEnabled(true); } exceptionHandlerProvider.configure(config.appErrorPrefix); - routerHelperProvider.configure({docTitle: 'HotTowel: '}); + routerHelperProvider.configure({docTitle: config.appTitle + ': '}); } })(); \ No newline at end of file diff --git a/app/templates/src/client/app/dashboard/dashboard.controller.js b/app/templates/src/client/app/dashboard/dashboard.controller.js index 3239d7c..e9ffb66 100644 --- a/app/templates/src/client/app/dashboard/dashboard.controller.js +++ b/app/templates/src/client/app/dashboard/dashboard.controller.js @@ -1,4 +1,4 @@ -(function () { +(function () { 'use strict'; angular @@ -9,7 +9,7 @@ function DashboardController($q, dataservice, logger) { var vm = this; vm.news = { - title: 'Hot Towel Angular', + title: '<%= appName %>', description: 'Hot Towel Angular is a SPA template for Angular developers.' }; vm.messageCount = 0; diff --git a/app/templates/src/client/test/bindPolyfill.js b/app/templates/src/client/test/bind-polyfill.js similarity index 100% rename from app/templates/src/client/test/bindPolyfill.js rename to app/templates/src/client/test/bind-polyfill.js diff --git a/package.json b/package.json index d5337cc..d86cb0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-hottowel", - "version": "0.0.5", + "version": "0.0.6", "description": "Yeoman generator for HotTowel Angular", "license": "MIT", "main": "app/index.js", diff --git a/test/test-app.js b/test/test-app.js index 66ebaed..224c1b0 100644 --- a/test/test-app.js +++ b/test/test-app.js @@ -1,6 +1,8 @@ /*global describe, beforeEach, it*/ 'use strict'; +//TODO: create test suite + var path = require('path'); var assert = require('yeoman-generator').assert; var helpers = require('yeoman-generator').test;