diff --git a/app/prompts.json b/app/prompts.json index fe8371a1..a0371630 100644 --- a/app/prompts.json +++ b/app/prompts.json @@ -131,6 +131,13 @@ }, "name": "ngRoute, the official router" }, + { + "value": { + "key": "new-router", + "module": "ngNewRouter" + }, + "name": "Angular 2 new router which is compatible with Angular 1 (experimental)" + }, { "value": { "key": "none", diff --git a/app/src/bower.js b/app/src/bower.js index 87251ab1..e89c0dbe 100644 --- a/app/src/bower.js +++ b/app/src/bower.js @@ -58,6 +58,12 @@ module.exports = function(GulpAngularGenerator) { } } + if (this.props.router.key === 'new-router') { + bowerOverrides['angular-new-router'] = { + main: [ 'dist/router.es5.js' ] + }; + } + if (_.isEmpty(bowerOverrides)) { this.bowerOverrides = null; } else { diff --git a/app/src/router.js b/app/src/router.js index bd90f10c..63f42e59 100644 --- a/app/src/router.js +++ b/app/src/router.js @@ -9,20 +9,27 @@ module.exports = function(GulpAngularGenerator) { GulpAngularGenerator.prototype.computeRouter = function computeRouter() { var routerPartialSrc = 'src/app/main/__' + this.props.ui.key + '.html'; - if (this.props.router.module === 'ngRoute') { + if (this.props.router.key === 'angular-route') { this.routerHtml = '
'; this.files.push({ src: 'src/app/_ngroute/__ngroute.' + this.props.jsPreprocessor.srcExtension, dest: 'src/app/index.route.' + this.props.jsPreprocessor.extension, template: true }); - } else if (this.props.router.module === 'ui.router') { + } else if (this.props.router.key === 'ui-router') { this.routerHtml = '
'; this.files.push({ src: 'src/app/_uirouter/__uirouter.' + this.props.jsPreprocessor.srcExtension, dest: 'src/app/index.route.' + this.props.jsPreprocessor.extension, template: true }); + } else if (this.props.router.key === 'new-router') { + this.routerHtml = '
'; + this.files.push({ + src: 'src/app/_newrouter/__newrouter.' + this.props.jsPreprocessor.srcExtension, + dest: 'src/app/index.route.' + this.props.jsPreprocessor.extension, + template: true + }); } else { this.routerHtml = this.fs.read(this.templatePath(routerPartialSrc)); this.routerHtml = this.routerHtml.replace( diff --git a/app/templates/_bower.json b/app/templates/_bower.json index b3669c5f..31d6ee2d 100644 --- a/app/templates/_bower.json +++ b/app/templates/_bower.json @@ -26,6 +26,8 @@ "angular-route": "<%- props.angularVersion %>", <% } if (props.router.key === 'ui-router') { -%> "angular-ui-router": "~0.2.15", +<% } if (props.router.key === 'new-router') { -%> + "angular-new-router": "~0.5.3", <% } if(props.ui.key === 'bootstrap') { -%> <% if(props.cssPreprocessor.extension === 'scss') { -%> "bootstrap-sass": "~3.3.4", diff --git a/app/templates/src/app/_index.module.es6 b/app/templates/src/app/_index.module.es6 index adc56dd2..50512a06 100644 --- a/app/templates/src/app/_index.module.es6 +++ b/app/templates/src/app/_index.module.es6 @@ -1,8 +1,11 @@ /* global malarkey:false, moment:false */ + import config from './index.config'; -<% if (props.router.key !== 'none') { %> +<% if (props.router.key === 'new-router') { -%> +import { routerConfig, RouterController } from './index.route'; +<% } else if (props.router.key !== 'none') { -%> import routerConfig from './index.route'; -<% } %> +<% } -%> import runBlock from './index.run'; import MainController from './main/main.controller'; import GithubContributorService from '../app/components/githubContributor/githubContributor.service'; @@ -14,12 +17,15 @@ angular.module('<%- appName %>', [<%- modulesDependencies %>]) .constant('malarkey', malarkey) .constant('moment', moment) .config(config) -<% if (props.router.key !== 'none') { %> +<% if (props.router.key !== 'none') { -%> .config(routerConfig) -<% } %> +<% } -%> .run(runBlock) .service('githubContributor', GithubContributorService) .service('webDevTec', WebDevTecService) +<% if (props.router.key === 'new-router') { -%> + .controller('RouterController', RouterController) +<% } -%> .controller('MainController', MainController) .directive('acmeNavbar', () => new NavbarDirective()) .directive('acmeMalarkey', () => new MalarkeyDirective(malarkey)); diff --git a/app/templates/src/app/_index.module.ts b/app/templates/src/app/_index.module.ts index e838e30a..ba14ae15 100644 --- a/app/templates/src/app/_index.module.ts +++ b/app/templates/src/app/_index.module.ts @@ -1,7 +1,9 @@ /// import { config } from './index.config'; -<% if (props.router.key !== 'none') { -%> +<% if (props.router.key === 'new-router') { -%> +import { routerConfig, RouterController } from './index.route'; +<% } else if (props.router.key !== 'none') { -%> import { routerConfig } from './index.route'; <% } -%> import { runBlock } from './index.run'; @@ -14,16 +16,23 @@ import { acmeMalarkey } from '../app/components/malarkey/malarkey.directive'; declare var malarkey: any; declare var moment: moment.MomentStatic; -angular.module('<%- appName %>', [<%- modulesDependencies %>]) - .constant('malarkey', malarkey) - .constant('moment', moment) - .config(config) +module <%- appName %> { + 'use strict'; + + angular.module('<%- appName %>', [<%- modulesDependencies %>]) + .constant('malarkey', malarkey) + .constant('moment', moment) + .config(config) <% if (props.router.key !== 'none') { -%> - .config(routerConfig) + .config(routerConfig) +<% } -%> + .run(runBlock) + .service('githubContributor', GithubContributor) + .service('webDevTec', WebDevTecService) +<% if (props.router.key === 'new-router') { -%> + .controller('RouterController', RouterController) <% } -%> - .run(runBlock) - .service('githubContributor', GithubContributor) - .service('webDevTec', WebDevTecService) - .controller('MainController', MainController) - .directive('acmeNavbar', acmeNavbar) - .directive('acmeMalarkey', acmeMalarkey); + .controller('MainController', MainController) + .directive('acmeNavbar', acmeNavbar) + .directive('acmeMalarkey', acmeMalarkey); +} diff --git a/app/templates/src/app/_newrouter/__newrouter.coffee b/app/templates/src/app/_newrouter/__newrouter.coffee new file mode 100644 index 00000000..c45191d4 --- /dev/null +++ b/app/templates/src/app/_newrouter/__newrouter.coffee @@ -0,0 +1,12 @@ +angular.module '<%- appName %>' + .config ($componentLoaderProvider) -> + 'ngInject' + $componentLoaderProvider.setTemplateMapping (name) -> + "app/#{ name }/#{ name }.html" + + .controller 'RouterController', ($router) -> + 'ngInject' + $router.config [ + path: '/' + component: 'main' + ] diff --git a/app/templates/src/app/_newrouter/__newrouter.es6 b/app/templates/src/app/_newrouter/__newrouter.es6 new file mode 100644 index 00000000..85c32385 --- /dev/null +++ b/app/templates/src/app/_newrouter/__newrouter.es6 @@ -0,0 +1,15 @@ +export function routerConfig($componentLoaderProvider) { + 'ngInject'; + $componentLoaderProvider.setTemplateMapping(function(name) { + return `app/${ name }/${ name }.html`; + }); +} + +export class RouterController { + constructor($router) { + 'ngInject'; + $router.config([ + { path: '/', component: 'main' } + ]); + } +} diff --git a/app/templates/src/app/_newrouter/__newrouter.js b/app/templates/src/app/_newrouter/__newrouter.js new file mode 100644 index 00000000..b6162422 --- /dev/null +++ b/app/templates/src/app/_newrouter/__newrouter.js @@ -0,0 +1,23 @@ +(function() { + 'use strict'; + + angular + .module('<%- appName %>') + .config(routerConfig) + .controller('RouterController', RouterController); + + /** @ngInject */ + function routerConfig($componentLoaderProvider) { + $componentLoaderProvider.setTemplateMapping(function(name) { + return 'app/' + name + '/' + name + '.html'; + }); + } + + /** @ngInject */ + function RouterController($router) { + $router.config([ + { path: '/', component: 'main' } + ]); + } + +})(); diff --git a/app/templates/src/app/_newrouter/__newrouter.ts b/app/templates/src/app/_newrouter/__newrouter.ts new file mode 100644 index 00000000..c538ad13 --- /dev/null +++ b/app/templates/src/app/_newrouter/__newrouter.ts @@ -0,0 +1,13 @@ +export function routerConfig($componentLoaderProvider) { + $componentLoaderProvider.setTemplateMapping(function(name) { + return 'app/' + name + '/' + name + '.html'; + }); +} + +export class RouterController { + constructor($router) { + $router.config([ + { path: '/', component: 'main' } + ]); + } +} diff --git a/app/templates/src/app/_uirouter/__uirouter.js b/app/templates/src/app/_uirouter/__uirouter.js index 93994fd9..744313b3 100644 --- a/app/templates/src/app/_uirouter/__uirouter.js +++ b/app/templates/src/app/_uirouter/__uirouter.js @@ -3,10 +3,10 @@ angular .module('<%- appName %>') - .config(routeConfig); + .config(routerConfig); /** @ngInject */ - function routeConfig($stateProvider, $urlRouterProvider) { + function routerConfig($stateProvider, $urlRouterProvider) { $stateProvider .state('home', { url: '/', diff --git a/docs/assets/original/LESS-icon.png b/docs/assets/original/LESS-icon.png new file mode 100644 index 00000000..ff218d26 Binary files /dev/null and b/docs/assets/original/LESS-icon.png differ diff --git a/docs/assets/original/angular-icon.png b/docs/assets/original/angular-icon.png new file mode 100644 index 00000000..b680c3d2 Binary files /dev/null and b/docs/assets/original/angular-icon.png differ diff --git a/docs/assets/original/babel.png b/docs/assets/original/babel.png new file mode 100644 index 00000000..05edf67a Binary files /dev/null and b/docs/assets/original/babel.png differ diff --git a/docs/assets/original/bootstrap.png b/docs/assets/original/bootstrap.png new file mode 100644 index 00000000..aba6a587 Binary files /dev/null and b/docs/assets/original/bootstrap.png differ diff --git a/docs/assets/original/bower.png b/docs/assets/original/bower.png new file mode 100644 index 00000000..50828611 Binary files /dev/null and b/docs/assets/original/bower.png differ diff --git a/docs/assets/original/browsersync.png b/docs/assets/original/browsersync.png new file mode 100644 index 00000000..c96a7dc0 Binary files /dev/null and b/docs/assets/original/browsersync.png differ diff --git a/docs/assets/original/coffeescript.png b/docs/assets/original/coffeescript.png new file mode 100644 index 00000000..db79f96a Binary files /dev/null and b/docs/assets/original/coffeescript.png differ diff --git a/docs/assets/original/foundation.png b/docs/assets/original/foundation.png new file mode 100644 index 00000000..65792d88 Binary files /dev/null and b/docs/assets/original/foundation.png differ diff --git a/docs/assets/original/gulp.png b/docs/assets/original/gulp.png new file mode 100644 index 00000000..5c5e43a0 Binary files /dev/null and b/docs/assets/original/gulp.png differ diff --git a/docs/assets/original/haml.png b/docs/assets/original/haml.png new file mode 100644 index 00000000..195a6019 Binary files /dev/null and b/docs/assets/original/haml.png differ diff --git a/docs/assets/original/handlebars.png b/docs/assets/original/handlebars.png new file mode 100644 index 00000000..151678ce Binary files /dev/null and b/docs/assets/original/handlebars.png differ diff --git a/docs/assets/original/istanbul.png b/docs/assets/original/istanbul.png new file mode 100644 index 00000000..26fd39f4 Binary files /dev/null and b/docs/assets/original/istanbul.png differ diff --git a/docs/assets/original/jade.png b/docs/assets/original/jade.png new file mode 100644 index 00000000..c35e2977 Binary files /dev/null and b/docs/assets/original/jade.png differ diff --git a/docs/assets/original/jasmine.png b/docs/assets/original/jasmine.png new file mode 100644 index 00000000..2535d26c Binary files /dev/null and b/docs/assets/original/jasmine.png differ diff --git a/docs/assets/original/jshint.png b/docs/assets/original/jshint.png new file mode 100644 index 00000000..0c5ed430 Binary files /dev/null and b/docs/assets/original/jshint.png differ diff --git a/docs/assets/original/karma.png b/docs/assets/original/karma.png new file mode 100644 index 00000000..9863ce37 Binary files /dev/null and b/docs/assets/original/karma.png differ diff --git a/docs/assets/original/materialdesign.png b/docs/assets/original/materialdesign.png new file mode 100644 index 00000000..21cb58a6 Binary files /dev/null and b/docs/assets/original/materialdesign.png differ diff --git a/docs/assets/original/protractor.png b/docs/assets/original/protractor.png new file mode 100644 index 00000000..6b7642d5 Binary files /dev/null and b/docs/assets/original/protractor.png differ diff --git a/docs/assets/original/sass.png b/docs/assets/original/sass.png new file mode 100644 index 00000000..f4367267 Binary files /dev/null and b/docs/assets/original/sass.png differ diff --git a/docs/assets/original/sass.svg b/docs/assets/original/sass.svg new file mode 100644 index 00000000..194e860e --- /dev/null +++ b/docs/assets/original/sass.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/assets/original/stylus.png b/docs/assets/original/stylus.png new file mode 100644 index 00000000..1930937b Binary files /dev/null and b/docs/assets/original/stylus.png differ diff --git a/docs/assets/original/traceur.png b/docs/assets/original/traceur.png new file mode 100644 index 00000000..a7ed39fa Binary files /dev/null and b/docs/assets/original/traceur.png differ diff --git a/docs/assets/original/typescript.png b/docs/assets/original/typescript.png new file mode 100644 index 00000000..9415e85e Binary files /dev/null and b/docs/assets/original/typescript.png differ diff --git a/docs/assets/original/webpack.png b/docs/assets/original/webpack.png new file mode 100644 index 00000000..ead290b5 Binary files /dev/null and b/docs/assets/original/webpack.png differ diff --git a/test/inception/test-inception.js b/test/inception/test-inception.js index 4098deb1..cfbfd6c1 100644 --- a/test/inception/test-inception.js +++ b/test/inception/test-inception.js @@ -96,10 +96,11 @@ describe('gulp-angular generator inception tests', function () { }); }); - describe('with [jQuery 1, $http, ngMaterial, Stylus, TypeScript, handlebars]', function () { + describe('with [jQuery 1, $http, new router, ngMaterial, Stylus, TypeScript, handlebars]', function () { before(function() { return inception.prepare({}, { jQuery: prompts.jQuery.values['jquery 1'], + router: prompts.router.values['new-router'], ui: prompts.ui.values['angular-material'], cssPreprocessor: prompts.cssPreprocessor.values.stylus, jsPreprocessor: prompts.jsPreprocessor.values.typescript, diff --git a/test/node/test-bower.js b/test/node/test-bower.js index cda054ce..3735d8db 100644 --- a/test/node/test-bower.js +++ b/test/node/test-bower.js @@ -28,7 +28,8 @@ describe('gulp-angular generator bower script', function () { it('should return null if bootstrap is not selected', function() { generator.props = { - ui: { key: 'notbootstrap' } + ui: { key: 'notbootstrap' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); expect(generator.bowerOverrides).to.be.null; @@ -38,7 +39,8 @@ describe('gulp-angular generator bower script', function () { generator.props = { ui: { key: 'bootstrap' }, bootstrapComponents: { key: 'official' }, - cssPreprocessor: { key: 'something' } + cssPreprocessor: { key: 'something' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); var bootstrapMain = JSON.parse(generator.bowerOverrides).bootstrap.main; @@ -51,7 +53,8 @@ describe('gulp-angular generator bower script', function () { generator.props = { ui: { key: 'bootstrap' }, bootstrapComponents: { key: 'something' }, - cssPreprocessor: { key: 'none' } + cssPreprocessor: { key: 'none' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); var bootstrapMain = JSON.parse(generator.bowerOverrides).bootstrap.main; @@ -64,7 +67,8 @@ describe('gulp-angular generator bower script', function () { generator.props = { ui: { key: 'bootstrap' }, bootstrapComponents: { key: 'official' }, - cssPreprocessor: { key: 'notnone', extension: 'scss' } + cssPreprocessor: { key: 'notnone', extension: 'scss' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); var bootstrapMain = JSON.parse(generator.bowerOverrides)['bootstrap-sass'].main; @@ -80,7 +84,8 @@ describe('gulp-angular generator bower script', function () { generator.props = { ui: { key: 'bootstrap' }, bootstrapComponents: { key: 'something' }, - cssPreprocessor: { key: 'notnone', extension: 'scss' } + cssPreprocessor: { key: 'notnone', extension: 'scss' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); var bootstrapMain = JSON.parse(generator.bowerOverrides)['bootstrap-sass'].main; @@ -94,7 +99,8 @@ describe('gulp-angular generator bower script', function () { generator.props = { ui: { key: 'bootstrap' }, bootstrapComponents: { key: 'something' }, - cssPreprocessor: { key: 'less' } + cssPreprocessor: { key: 'less' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); var bootstrapMain = JSON.parse(generator.bowerOverrides).bootstrap.main; @@ -103,15 +109,28 @@ describe('gulp-angular generator bower script', function () { allFonts(bootstrapMain); }); + it('should add new router js file', function() { + generator.props = { + ui: { key: 'notbootstrap' }, + router: { key: 'new-router' } + }; + generator.prepareBowerOverrides(); + var routerMain = JSON.parse(generator.bowerOverrides)['angular-new-router'].main; + var first = routerMain.shift(); + first.should.match(/router\.es5\.js/); + }); + it('should keep indent in bower.json', function() { generator.props = { ui: { key: 'bootstrap' }, bootstrapComponents: { key: 'something' }, - cssPreprocessor: { key: 'something' } + cssPreprocessor: { key: 'something' }, + router: { key: 'notnewrouter' } }; generator.prepareBowerOverrides(); generator.bowerOverrides.should.match(/^{.*\n {4}/); }); + }); describe('select wiredep exclusions depending the choices', function () { diff --git a/test/node/test-router.js b/test/node/test-router.js index aa4e4a95..1d123174 100644 --- a/test/node/test-router.js +++ b/test/node/test-router.js @@ -11,7 +11,8 @@ var generator; var router = require('../../app/src/router.js'); -describe('gulp-angular generator techs script', function () { +describe('gulp-angular generator router script', function () { + var read; before(function() { router(Generator); @@ -19,13 +20,9 @@ describe('gulp-angular generator techs script', function () { beforeEach(function() { generator = new Generator(); - }); - - it('should prepare router files and html depending choices', function() { - var read = sinon.stub(generator.fs, 'read'); generator.props = { - router: { module: 'ngRoute' }, + router: { key: 'angular-route' }, ui: { key: 'testUi' }, jsPreprocessor: { srcExtension: 'testSrcExtension', @@ -33,23 +30,41 @@ describe('gulp-angular generator techs script', function () { } }; + read = sinon.stub(generator.fs, 'read'); + }); + + it('should prepare router files and html for angular route', function() { generator.files = []; generator.computeRouter(); generator.routerHtml.should.match(/ng-view/); generator.files[0].src.should.equal('src/app/_ngroute/__ngroute.testSrcExtension'); generator.files[0].dest.should.equal('src/app/index.route.testExtension'); + }); + it('should prepare router files and html for UI Router', function() { generator.files = []; - generator.props.router.module = 'ui.router'; + generator.props.router.key = 'ui-router'; generator.computeRouter(); generator.routerHtml.should.match(/ui-view/); generator.files[0].src.should.equal('src/app/_uirouter/__uirouter.testSrcExtension'); generator.files[0].dest.should.equal('src/app/index.route.testExtension'); + }); + + it('should prepare router files and html for angular new router', function() { + generator.files = []; + generator.props.router.key = 'new-router'; + generator.computeRouter(); + generator.routerHtml.should.match(/ng-viewport/); + generator.routerHtml.should.match(/RouterController/); + generator.files[0].src.should.equal('src/app/_newrouter/__newrouter.testSrcExtension'); + generator.files[0].dest.should.equal('src/app/index.route.testExtension'); + }); + it('should prepare router files and html for not router', function() { generator.files = []; read.withArgs('template/src/app/main/__testUi.html') .returns('
'); - generator.props.router.module = 'none'; + generator.props.router.key = 'none'; generator.computeRouter(); generator.routerHtml.should.match(/MainController/); generator.files.length.should.equal(0); diff --git a/test/template/test-bower.js b/test/template/test-bower.js index e08718d6..ce2e0450 100644 --- a/test/template/test-bower.js +++ b/test/template/test-bower.js @@ -105,16 +105,25 @@ describe('gulp-angular bower template', function () { var result = bower(model); result.should.not.match(/angular-route/); result.should.not.match(/angular-ui-router/); + result.should.not.match(/angular-new-router/); model.props.router.key = 'angular-route'; result = bower(model); - result.should.match(/angular-route/); result.should.not.match(/angular-ui-router/); + result.should.not.match(/angular-new-router/); + result.should.match(/angular-route/); model.props.router.key = 'ui-router'; result = bower(model); result.should.not.match(/angular-route/); + result.should.not.match(/angular-new-router/); result.should.match(/angular-ui-router/); + + model.props.router.key = 'new-router'; + result = bower(model); + result.should.not.match(/angular-route/); + result.should.not.match(/angular-ui-router/); + result.should.match(/angular-new-router/); }); it('should add the right ui lib', function() { diff --git a/test/template/test-index-module-js.js b/test/template/test-index-module-js.js index 3b09aceb..7dd34100 100644 --- a/test/template/test-index-module-js.js +++ b/test/template/test-index-module-js.js @@ -48,18 +48,32 @@ describe('gulp-angular index js template', function () { result.should.match(testTs); }); - it('should add the router config when necessary', function() { + it('should not add the router config for no router', function() { + model.props.router.key = 'none'; + var result = indexEs6(model); + result.should.not.match(/\.config\(routerConfig\)/); + result.should.not.match(/RouterController/); + result = indexTs(model); + result.should.not.match(/\.config\(routerConfig\)/); + result.should.not.match(/RouterController/); + }); + + it('should add the router config when a router is chosen', function() { model.props.router.key = 'not-none'; var result = indexEs6(model); - result.should.match(/.config\(routerConfig\)/); + result.should.match(/\.config\(routerConfig\)/); + result.should.not.match(/RouterController/); result = indexTs(model); - result.should.match(/.config\(routerConfig\)/); + result.should.match(/\.config\(routerConfig\)/); + result.should.not.match(/RouterController/); + }); - model.props.router.key = 'none'; - result = indexEs6(model); - result.should.not.match(/.config\(routerConfig\)/); + it('should add the router controller for the angular new router', function() { + model.props.router.key = 'new-router'; + var result = indexEs6(model); + result.should.match(/\.controller\('RouterController', RouterController\)/); result = indexTs(model); - result.should.not.match(/.config\(routerConfig\)/); + result.should.match(/\.controller\('RouterController', RouterController\)/); }); });