From acb09d13a54691cc0d9282136ff57fbfb2a8ba19 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:30:35 -0400 Subject: [PATCH 01/11] refactor(app): fix some ESLint issues --- src/test/get-expected-files.js | 1 + templates/app/.eslintignore | 1 + templates/app/client/.eslintrc(babel) | 6 +++ .../app/account(auth)/account.module.js | 4 -- .../app/account(auth)/account.routes.js | 42 ------------------- .../client/app/admin(auth)/admin.routes.js | 9 ---- templates/app/client/app/app.module.js | 38 ++++++----------- .../components/auth(auth)/auth.service.js | 2 - .../components/navbar/navbar.component.js | 8 ++-- .../components/socket(ws)/socket.mock.js | 1 - .../user(auth)/user.model(mongooseModels).js | 12 +++--- .../user(auth)/user.model(sequelizeModels).js | 12 +++--- .../app/server/config/environment/shared.js | 1 + templates/app/server/config/express.js | 2 +- templates/app/server/index.js | 1 + templates/endpoint/basename.controller.js | 4 +- 16 files changed, 43 insertions(+), 101 deletions(-) create mode 100644 templates/app/.eslintignore delete mode 100644 templates/app/client/app/account(auth)/account.routes.js delete mode 100644 templates/app/client/app/admin(auth)/admin.routes.js diff --git a/src/test/get-expected-files.js b/src/test/get-expected-files.js index edbbf0a0d..056f0bfee 100644 --- a/src/test/get-expected-files.js +++ b/src/test/get-expected-files.js @@ -90,6 +90,7 @@ export function app(options) { '.babelrc', '.buildignore', '.editorconfig', + '.eslintignore', '.eslintrc', '.gitattributes', '.gitignore', diff --git a/templates/app/.eslintignore b/templates/app/.eslintignore new file mode 100644 index 000000000..55181f991 --- /dev/null +++ b/templates/app/.eslintignore @@ -0,0 +1 @@ +client/components/socket/primus.js diff --git a/templates/app/client/.eslintrc(babel) b/templates/app/client/.eslintrc(babel) index b12322f67..adfc49054 100644 --- a/templates/app/client/.eslintrc(babel) +++ b/templates/app/client/.eslintrc(babel) @@ -3,5 +3,11 @@ "env": { "browser": true, "commonjs": true + }, + "globals": { + "process": true + }, + "rules": { + "no-process-env": 0 } } diff --git a/templates/app/client/app/account(auth)/account.module.js b/templates/app/client/app/account(auth)/account.module.js index b303eb7eb..84db4ccfe 100644 --- a/templates/app/client/app/account(auth)/account.module.js +++ b/templates/app/client/app/account(auth)/account.module.js @@ -8,9 +8,6 @@ import { RouterModule, Routes } from '@angular/router';<% } %> <%_ if(filters.oauth) { -%> import { DirectivesModule } from '../../components/directives.module';<% } %> -<%_ if(filters.uirouter) { -%> -import { STATES } from './account.routes';<% } %> - import { LoginComponent } from './login/login.component'; import { SettingsComponent } from './settings/settings.component'; import { SignupComponent } from './signup/signup.component'; @@ -19,7 +16,6 @@ import { SignupComponent } from './signup/signup.component'; const accountRoutes: Routes = [{ path: 'login', component: LoginComponent, - //data: { title: 'Home' } }, { path: 'settings', component: SettingsComponent, diff --git a/templates/app/client/app/account(auth)/account.routes.js b/templates/app/client/app/account(auth)/account.routes.js deleted file mode 100644 index eedab2494..000000000 --- a/templates/app/client/app/account(auth)/account.routes.js +++ /dev/null @@ -1,42 +0,0 @@ -import { LoginComponent } from './login/login.component'; -import { SignupComponent } from './signup/signup.component'; -import { SettingsComponent } from './settings/settings.component'; -import { AuthService } from '../../components/auth/auth.service'; - -<%_ if(filters.uirouter) { -%> -export const STATES = [{ - name: 'login', - url: '/login', - component: LoginComponent, -}, { - name: 'signup', - url: '/signup', - component: SignupComponent, -}, { - name: 'settings', - url: '/settings', - component: SettingsComponent, - data: { - authenticate: true, - }, -}, { - name: 'logout', - url: '/logout?referrer', - onEnter(trans, state) { - console.log('enter'); - // var referrer = $state.params.referrer - // || $state.current.referrer - // || 'main'; - // Auth.logout(); - // $state.go(referrer); - }, - resolve: [{ - provide: 'isLoggedIn', - useFactory: (AuthService) => { - console.log('resolve'); - return AuthService.isLoggedIn(); - }, - deps: [AuthService], - }], -}];<% } %> -<%_ if(filters.ngroute) { -%><% } %> diff --git a/templates/app/client/app/admin(auth)/admin.routes.js b/templates/app/client/app/admin(auth)/admin.routes.js deleted file mode 100644 index d87f23563..000000000 --- a/templates/app/client/app/admin(auth)/admin.routes.js +++ /dev/null @@ -1,9 +0,0 @@ -import { AdminComponent } from './admin.component'; - -<%_ if(filters.uirouter) { -%> -export const STATES = [{ - name: 'admin', - url: '/admin', - component: AdminComponent, -}];<% } %> -<%_ if(filters.ngroute) { -%><% } %> diff --git a/templates/app/client/app/app.module.js b/templates/app/client/app/app.module.js index 3bde844db..482e37cff 100644 --- a/templates/app/client/app/app.module.js +++ b/templates/app/client/app/app.module.js @@ -1,17 +1,16 @@ import { NgModule, - ErrorHandler, Injectable, - ApplicationRef, - Provider, + ApplicationRef,<% if(filters.ts || filters.flow) { %> + Provider,<% } %> } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { Http, HttpModule, - BaseRequestOptions, + BaseRequestOptions,<% if(filters.ts || filters.flow) { %> RequestOptions, - RequestOptionsArgs, + RequestOptionsArgs,<% } %> } from '@angular/http'; import { removeNgStyles, @@ -22,11 +21,10 @@ import { import { UIRouterModule } from 'ui-router-ng2';<% } %> <%_ if (filters.ngroute) { -%> import { RouterModule, Routes } from '@angular/router';<% } %> -import { provideAuth, AuthHttp, AuthConfig } from 'angular2-jwt'; +import { AuthHttp, AuthConfig } from 'angular2-jwt'; import { AppComponent } from './app.component'; import { MainModule } from './main/main.module'; -// import { MainComponent } from './main/main.component'; import { DirectivesModule } from '../components/directives.module'; import { AccountModule } from './account/account.module'; import { AdminModule } from './admin/admin.module'; @@ -50,7 +48,7 @@ let providers: Provider[] = [{ if(constants.env === 'development') { @Injectable() class HttpOptions extends BaseRequestOptions { - merge(options/*:RequestOptionsArgs*/)/*:RequestOptions*/ { + merge(options: RequestOptionsArgs):RequestOptions { options.url = `http://localhost:9000${options.url}`; return super.merge(options); } @@ -59,20 +57,10 @@ if(constants.env === 'development') { providers.push({ provide: RequestOptions, useClass: HttpOptions }); } -const appRoutes: Routes = [ - //{ path: 'crisis-center', component: CrisisListComponent }, - //{ path: 'hero/:id', component: HeroDetailComponent }, - // { - // path: 'home', - // component: MainComponent, - // data: { title: 'Home' } - // }, - { path: '', - redirectTo: '/home', - pathMatch: 'full' - }, - //{ path: '**', component: PageNotFoundComponent } -]; +const appRoutes: Routes = [{ path: '', + redirectTo: '/home', + pathMatch: 'full' +}]; @NgModule({ providers, @@ -110,8 +98,8 @@ export class AppModule { } // change detection this.appRef.tick(); - delete store.state; - delete store.restoreInputValues; + Reflect.deleteProperty(store, 'state'); + Reflect.deleteProperty(store, 'restoreInputValues'); } hmrOnDestroy(store) { @@ -131,7 +119,7 @@ export class AppModule { hmrAfterDestroy(store) { // display new elements store.disposeOldHosts() - delete store.disposeOldHosts; + Reflect.deleteProperty(store, 'disposeOldHosts'); // anything you need done the component is removed } } diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index 92f2e8e24..9010a4566 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -1,9 +1,7 @@ import { Injectable, EventEmitter, Output } from '@angular/core'; -import { Response } from '@angular/http'; import { AuthHttp } from 'angular2-jwt'; import { UserService } from './user.service'; import { Http } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/toPromise'; import { safeCb, extractData } from '../util'; import constants from '../../app/app.constants'; diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index bfeed3314..1630098a8 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -53,11 +53,9 @@ export class NavbarComponent { } logout() { - let promise = this.AuthService.logout(); - <%_ if(filters.uirouter) { -%> - this.StateService.go('login');<% } -%> - <%_ if(filters.ngroute) { -%> - this.Router.navigateByUrl('/home');<% } -%> + let promise = this.AuthService.logout();<% if(filters.uirouter) { %> + this.StateService.go('login');<% } %><% if(filters.ngroute) { %> + this.Router.navigateByUrl('/home');<% } %> return promise; }<% } -%> } diff --git a/templates/app/client/components/socket(ws)/socket.mock.js b/templates/app/client/components/socket(ws)/socket.mock.js index 7b5921e1a..fd858e605 100644 --- a/templates/app/client/components/socket(ws)/socket.mock.js +++ b/templates/app/client/components/socket(ws)/socket.mock.js @@ -1,7 +1,6 @@ 'use strict'; export class SocketServiceStub { - constructor() {} syncUpdates() {} unsyncUpdates() {} } diff --git a/templates/app/server/api/user(auth)/user.model(mongooseModels).js b/templates/app/server/api/user(auth)/user.model(mongooseModels).js index ee4da3097..c9b6593c4 100644 --- a/templates/app/server/api/user(auth)/user.model(mongooseModels).js +++ b/templates/app/server/api/user(auth)/user.model(mongooseModels).js @@ -197,14 +197,16 @@ UserSchema.methods = { * @return {String} * @api public */ - makeSalt(byteSize, callback) { + makeSalt(...args) { var defaultByteSize = 16; + let byteSize; + let callback; - if(typeof arguments[0] === 'function') { - callback = arguments[0]; + if(typeof args[0] === 'function') { + callback = args[0]; byteSize = defaultByteSize; - } else if(typeof arguments[1] === 'function') { - callback = arguments[1]; + } else if(typeof args[1] === 'function') { + callback = args[1]; } else { throw new Error('Missing Callback'); } diff --git a/templates/app/server/api/user(auth)/user.model(sequelizeModels).js b/templates/app/server/api/user(auth)/user.model(sequelizeModels).js index 94147e1ef..ae6204603 100644 --- a/templates/app/server/api/user(auth)/user.model(sequelizeModels).js +++ b/templates/app/server/api/user(auth)/user.model(sequelizeModels).js @@ -135,14 +135,16 @@ export default function(sequelize, DataTypes) { * @return {String} * @api public */ - makeSalt(byteSize, callback) { + makeSalt(...args) { var defaultByteSize = 16; + let byteSize; + let callback; - if(typeof arguments[0] === 'function') { - callback = arguments[0]; + if(typeof args[0] === 'function') { + callback = args[0]; byteSize = defaultByteSize; - } else if(typeof arguments[1] === 'function') { - callback = arguments[1]; + } else if(typeof args[1] === 'function') { + callback = args[1]; } else { throw new Error('Missing Callback'); } diff --git a/templates/app/server/config/environment/shared.js b/templates/app/server/config/environment/shared.js index 1f000515d..9c418c5fe 100644 --- a/templates/app/server/config/environment/shared.js +++ b/templates/app/server/config/environment/shared.js @@ -1,4 +1,5 @@ 'use strict'; +/*eslint no-process-env:0*/ module.exports.default = { env: process.env.NODE_ENV, diff --git a/templates/app/server/config/express.js b/templates/app/server/config/express.js index 23de6a1de..1b5655e00 100644 --- a/templates/app/server/config/express.js +++ b/templates/app/server/config/express.js @@ -72,7 +72,7 @@ export default function(app) { * Lusca - express server security * https://github.com/krakenjs/lusca */ - if(env !== 'test' && env !== 'development' && !process.env.SAUCE_USERNAME) { + if(env !== 'test' && env !== 'development' && !process.env.SAUCE_USERNAME) { // eslint-disable-line no-process-env app.use(lusca({ csrf: true, xframe: 'SAMEORIGIN', diff --git a/templates/app/server/index.js b/templates/app/server/index.js index c3ee5245d..28bfb44a8 100644 --- a/templates/app/server/index.js +++ b/templates/app/server/index.js @@ -1,4 +1,5 @@ 'use strict'; +/*eslint no-process-env:0*/ // Set default node environment to development var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development'; diff --git a/templates/endpoint/basename.controller.js b/templates/endpoint/basename.controller.js index a97d38bd6..85bf549ac 100644 --- a/templates/endpoint/basename.controller.js +++ b/templates/endpoint/basename.controller.js @@ -96,7 +96,7 @@ export function create(req, res) { // Upserts the given <%= classedName %> in the DB at the specified ID export function upsert(req, res) { if(req.body._id) { - delete req.body._id; + Reflect.deleteProperty(req.body, '_id'); } <%_ if(filters.mongooseModels) { -%> return <%= classedName %>.findOneAndUpdate({_id: req.params.id}, req.body, {new: true, upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()<% } %> @@ -113,7 +113,7 @@ export function upsert(req, res) { // Updates an existing <%= classedName %> in the DB export function patch(req, res) { if(req.body._id) { - delete req.body._id; + Reflect.deleteProperty(req.body, '_id'); } <% if(filters.mongooseModels) { %>return <%= classedName %>.findById(req.params.id).exec()<% } if(filters.sequelizeModels) { %>return <%= classedName %>.find({ From d967554d249460d1d527d7b81940a780365f2082 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:30:50 -0400 Subject: [PATCH 02/11] feat(client:auth): don't submit forms if invalid --- .../app/client/app/account(auth)/settings/settings.component.js | 2 ++ .../app/client/app/account(auth)/signup/signup.component.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/templates/app/client/app/account(auth)/settings/settings.component.js b/templates/app/client/app/account(auth)/settings/settings.component.js index c19ee87aa..af7be779b 100644 --- a/templates/app/client/app/account(auth)/settings/settings.component.js +++ b/templates/app/client/app/account(auth)/settings/settings.component.js @@ -38,6 +38,8 @@ export class SettingsComponent { } changePassword(form) { + if(form.invalid) return; + this.submitted = true; return this.AuthService.changePassword(this.user.oldPassword, this.user.newPassword) diff --git a/templates/app/client/app/account(auth)/signup/signup.component.js b/templates/app/client/app/account(auth)/signup/signup.component.js index 74fe2eb8d..a3a995599 100644 --- a/templates/app/client/app/account(auth)/signup/signup.component.js +++ b/templates/app/client/app/account(auth)/signup/signup.component.js @@ -47,6 +47,8 @@ export class SignupComponent { } register(form) { + if(form.invalid) return; + this.submitted = true; return this.AuthService.createUser({ From 804a91782069ddbfe5c2279b832b41b865682b62 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:31:06 -0400 Subject: [PATCH 03/11] feat(gen): default Flow on --- src/generators/app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/app/index.js b/src/generators/app/index.js index 6b54cd535..9982f9f2c 100644 --- a/src/generators/app/index.js +++ b/src/generators/app/index.js @@ -158,7 +158,7 @@ export class Generator extends Base { }, { type: 'confirm', name: 'flow', - default: false, + default: true, message: 'Would you like to use Flow types with Babel?', when: answers => answers.transpiler === 'babel' }, { From a401b8de8b005b8bd80662cdd0211b06719e4b0b Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:31:25 -0400 Subject: [PATCH 04/11] docs(gen): Angular name --- src/generators/app/USAGE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/app/USAGE b/src/generators/app/USAGE index 22bfcb18d..265445411 100644 --- a/src/generators/app/USAGE +++ b/src/generators/app/USAGE @@ -1,5 +1,5 @@ Description: - Creates a Full-Stack AngularJS + Node app + Creates a Full-Stack Angular + Node app Example: yo angular-fullstack From 4f9618ab277d6859625124272dca89c684678b11 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:31:43 -0400 Subject: [PATCH 05/11] fix(gen): fix gen issue with flow on --- src/generators/app/index.js | 60 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/generators/app/index.js b/src/generators/app/index.js index 9982f9f2c..2609b3c80 100644 --- a/src/generators/app/index.js +++ b/src/generators/app/index.js @@ -466,35 +466,37 @@ export class Generator extends Base { const codeshiftStream = tap(function(file, t) { var contents = file.contents.toString(); - // remove `implements Foo` from class declarations - contents = jscodeshift(contents) - .find(jscodeshift.ClassDeclaration) - .forEach(path => { - path.value.implements = null; - }) - .toSource(); - - // remove any type annotations - contents = jscodeshift(contents) - .find(jscodeshift.TypeAnnotation) - .remove() - .toSource(); - contents = jscodeshift(contents) - .find(jscodeshift.GenericTypeAnnotation) - .remove() - .toSource(); - - // remove any `type Foo = { .. }` declarations - contents = jscodeshift(contents) - .find(jscodeshift.TypeAlias) - .remove() - .toSource(); - - // remove any flow directive comments - contents = jscodeshift(contents) - .find(jscodeshift.Comment, path => path.type === 'CommentLine' && path.value.includes('@flow')) - .forEach(path => path.prune()) - .toSource(); + if(!flow) { + // remove `implements Foo` from class declarations + contents = jscodeshift(contents) + .find(jscodeshift.ClassDeclaration) + .forEach(path => { + path.value.implements = null; + }) + .toSource(); + + // remove any type annotations + contents = jscodeshift(contents) + .find(jscodeshift.TypeAnnotation) + .remove() + .toSource(); + contents = jscodeshift(contents) + .find(jscodeshift.GenericTypeAnnotation) + .remove() + .toSource(); + + // remove any `type Foo = { .. }` declarations + contents = jscodeshift(contents) + .find(jscodeshift.TypeAlias) + .remove() + .toSource(); + + // remove any flow directive comments + contents = jscodeshift(contents) + .find(jscodeshift.Comment, path => path.type === 'CommentLine' && path.value.includes('@flow')) + .forEach(path => path.prune()) + .toSource(); + } file.contents = new Buffer(contents); }); From e225a67534b007c369b5cf474444c045d2aa0b1d Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:32:04 -0400 Subject: [PATCH 06/11] fix(server): swap shrink-ray back out for compression --- templates/app/_package.json | 4 ++-- templates/app/server/config/express.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/app/_package.json b/templates/app/_package.json index 3ebee1c51..6caa157ea 100644 --- a/templates/app/_package.json +++ b/templates/app/_package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "main": "server/index.js", "dependencies": { + "compression": "^1.7.1", "core-js": "^2.4.1", "cors": "^2.8.1", "express": "^4.13.3", @@ -45,8 +46,7 @@ "primus": "^7.0.1", "primus-emit": "^1.0.0", "uws": "^8.14.1",<% } %> - "serve-favicon": "^2.3.0", - "shrink-ray": "^0.1.3" + "serve-favicon": "^2.3.0" }, "devDependencies": { <%# CLIENT %> diff --git a/templates/app/server/config/express.js b/templates/app/server/config/express.js index 1b5655e00..25af62393 100644 --- a/templates/app/server/config/express.js +++ b/templates/app/server/config/express.js @@ -7,7 +7,7 @@ import express from 'express'; import favicon from 'serve-favicon'; import morgan from 'morgan'; -import shrinkRay from 'shrink-ray'; +import compression from 'compression'; import bodyParser from 'body-parser'; import methodOverride from 'method-override'; import cookieParser from 'cookie-parser'; @@ -46,7 +46,7 @@ export default function(app) { app.engine('html', require('ejs').renderFile); app.set('view engine', 'html');<% } %><% if(filters.pug) { %> app.set('view engine', 'pug');<% } %> - app.use(shrinkRay()); + app.use(compression()); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(methodOverride()); From 8cfe32e44c8e59ceb0d02c0e9c2b64a27343c147 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:32:25 -0400 Subject: [PATCH 07/11] feat(package): add linting scripts --- templates/app/_package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/app/_package.json b/templates/app/_package.json index 6caa157ea..262645481 100644 --- a/templates/app/_package.json +++ b/templates/app/_package.json @@ -213,6 +213,9 @@ "npm": "^3.9.5" }, "scripts": { + "lint": "npm run lint:client && npm run lint:server", + "lint:client": "eslint ./client/**/*.<%= scriptExt %> -c ./client/.eslintrc --ignore-pattern *.spec.<%= scriptExt %>", + "lint:server": "eslint ./server/**/*.js -c ./server/.eslintrc --ignore-pattern *.spec.js --ignore-pattern *.integration.js", "test": "gulp test", "test:client": "karma start ./karma.conf.js --single-run", <%_ if(filters.flow) { -%> From bd658ed595d0f861709f2687803f8123ba897b44 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:32:47 -0400 Subject: [PATCH 08/11] chore(webpack): fix dev server redirects --- templates/app/webpack.make.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/templates/app/webpack.make.js b/templates/app/webpack.make.js index ab6ecd1fd..bd1886f72 100644 --- a/templates/app/webpack.make.js +++ b/templates/app/webpack.make.js @@ -350,9 +350,19 @@ module.exports = function makeWebpackConfig(options) { contentBase: './client/', hot: true, proxy: { - '/api': 'http://localhost:<%= devPort %>', - '/auth': 'http://localhost:<%= devPort %>', - '/socket.io': 'http://localhost:<%= devPort %>', + '/api': { + target: 'http://localhost:<%= devPort %>', + secure: false, + }, + '/auth': { + target: 'http://localhost:<%= devPort %>', + secure: false, + },<% if(filters.ws) { %> + '/primus': { + target: 'http://localhost:<%= devPort %>', + secure: false, + ws: true, + },<% } %> }, stats: { modules: false, From 8e5b44784aab862da3e0e414c3d4928ada60894c Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:33:01 -0400 Subject: [PATCH 09/11] style(server): fix routes.js styling --- templates/app/server/routes.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/templates/app/server/routes.js b/templates/app/server/routes.js index dcef9c275..62d4b248d 100644 --- a/templates/app/server/routes.js +++ b/templates/app/server/routes.js @@ -8,18 +8,17 @@ import errors from './components/errors'; import path from 'path'; export default function(app) { - // Insert routes below<% if (filters.auth) { %> - app.use('/api/users', require('./api/user')); + // Insert routes below<% if(filters.auth) { %> + app.use('/api/users', require('./api/user')); + app.use('/auth', require('./auth').default);<% } %> - app.use('/auth', require('./auth').default); -<% } %> - // All undefined asset or api routes should return a 404 - app.route('/:url(api|auth|components|app|bower_components|assets)/*') - .get(errors[404]); + // All undefined asset or api routes should return a 404 + app.route('/:url(api|auth|components|app|bower_components|assets)/*') + .get(errors[404]); - // All other routes should redirect to the index.html - app.route('/*') - .get((req, res) => { - res.sendFile(path.resolve(app.get('appPath') + '/index.html')); - }); + // All other routes should redirect to the index.html + app.route('/*') + .get((req, res) => { + res.sendFile(path.resolve(app.get('appPath') + '/index.html')); + }); } From 220097f50045777e29ae3f3e21668fb5a922e744 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:39:05 -0400 Subject: [PATCH 10/11] test(gen): fix expected files --- src/test/get-expected-files.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/get-expected-files.js b/src/test/get-expected-files.js index 056f0bfee..5b326f03e 100644 --- a/src/test/get-expected-files.js +++ b/src/test/get-expected-files.js @@ -157,7 +157,6 @@ export function app(options) { if (options.auth) { files = files.concat([ 'client/app/account/account.module.' + script, - 'client/app/account/account.routes.' + script, 'client/app/account/login/login.' + markup, 'client/app/account/login/login.component.' + script, 'client/app/account/settings/settings.' + markup, @@ -168,7 +167,6 @@ export function app(options) { 'client/app/admin/admin.' + stylesheet, 'client/app/admin/admin.component.' + script, 'client/app/admin/admin.module.' + script, - 'client/app/admin/admin.routes.' + script, 'client/components/auth/auth.module.' + script, 'client/components/auth/auth.service.' + script, 'client/components/auth/interceptor.service.' + script, From ad585d3224e20a11ebe0d6b3a6cf34cba3339028 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 12 Oct 2017 18:52:37 -0400 Subject: [PATCH 11/11] fix test failures --- src/test/fixtures/.yo-rc.json | 2 +- src/test/main.test.js | 2 ++ .../app/client/app/admin(auth)/admin.module.js | 9 ++++----- templates/app/client/app/app.module.js | 8 ++++---- .../app/client/app/main/main.component.js | 5 +++-- .../app/client/app/main/main.component.spec.js | 18 +++++++++--------- .../app/client/components/directives.module.js | 10 +++++----- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/test/fixtures/.yo-rc.json b/src/test/fixtures/.yo-rc.json index e0d83dd8d..b369cde2f 100644 --- a/src/test/fixtures/.yo-rc.json +++ b/src/test/fixtures/.yo-rc.json @@ -15,7 +15,7 @@ "filters": { "js": true, "babel": true, - "flow": false, + "flow": true, "html": true, "sass": true, "ngroute": true, diff --git a/src/test/main.test.js b/src/test/main.test.js index d688b2e17..700d98b42 100644 --- a/src/test/main.test.js +++ b/src/test/main.test.js @@ -17,6 +17,7 @@ import { const defaultOptions = { buildtool: 'gulp', transpiler: 'babel', + flow: true, markup: 'html', stylesheet: 'sass', router: 'ngroute', @@ -263,6 +264,7 @@ describe('angular-fullstack:app', function() { var testOptions = { buildtool: 'gulp', transpiler: 'babel', + flow: true, markup: 'pug', stylesheet: 'css', router: 'ngroute', diff --git a/templates/app/client/app/admin(auth)/admin.module.js b/templates/app/client/app/admin(auth)/admin.module.js index b9142d7c4..f8bcf9c75 100644 --- a/templates/app/client/app/admin(auth)/admin.module.js +++ b/templates/app/client/app/admin(auth)/admin.module.js @@ -1,10 +1,8 @@ import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -<%_ if(filters.uirouter) { %> -import { UIRouterModule } from 'ui-router-ng2';<% } %> -<%_ if(filters.ngroute) { %> +import { BrowserModule } from '@angular/platform-browser';<% if(filters.uirouter) { %> +import { UIRouterModule } from 'ui-router-ng2';<% } %><% if(filters.ngroute) { %> import { RouterModule, Routes } from '@angular/router';<% } %> - +import { AuthGuard } from '../../components/auth/auth-guard.service'; import { AdminComponent } from './admin.component'; <%_ if(filters.uirouter) { -%> @@ -13,6 +11,7 @@ import { STATES } from './admin.routes';<% } %> const adminRoutes: Routes = [{ path: 'admin', component: AdminComponent, + canActivate: [AuthGuard], }];<% } %> @NgModule({ diff --git a/templates/app/client/app/app.module.js b/templates/app/client/app/app.module.js index 482e37cff..7db4bfe3b 100644 --- a/templates/app/client/app/app.module.js +++ b/templates/app/client/app/app.module.js @@ -25,9 +25,9 @@ import { AuthHttp, AuthConfig } from 'angular2-jwt'; import { AppComponent } from './app.component'; import { MainModule } from './main/main.module'; -import { DirectivesModule } from '../components/directives.module'; +import { DirectivesModule } from '../components/directives.module';<% if(filters.auth) { %> import { AccountModule } from './account/account.module'; -import { AdminModule } from './admin/admin.module'; +import { AdminModule } from './admin/admin.module';<% } %> import constants from './app.constants'; @@ -72,9 +72,9 @@ const appRoutes: Routes = [{ path: '', <%_ if (filters.ngroute) { -%> RouterModule.forRoot(appRoutes, { enableTracing: process.env.NODE_ENV === 'development' }),<% } %> MainModule, - DirectivesModule, + DirectivesModule,<% if(filters.auth) { %> AccountModule, - AdminModule, + AdminModule,<% } %> ], declarations: [ AppComponent, diff --git a/templates/app/client/app/main/main.component.js b/templates/app/client/app/main/main.component.js index 1bc692373..e6195cac3 100644 --- a/templates/app/client/app/main/main.component.js +++ b/templates/app/client/app/main/main.component.js @@ -1,7 +1,8 @@ import { Component, OnInit<% if(filters.ws) { %>, OnDestroy<% } %> } from '@angular/core'; import { Http } from '@angular/http'; import { Observable } from 'rxjs/Observable'; -import { SocketService } from '../../components/socket/socket.service'; +import 'rxjs/add/operator/map';<% if(filters.ws) { %> +import { SocketService } from '../../components/socket/socket.service';<% } %> @Component({ selector: 'main', @@ -16,7 +17,7 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<% <%_ if(filters.models) { -%> newThing = '';<% } %> - static parameters = [Http, SocketService]; + static parameters = [Http<% if(filters.ws) { %>, SocketService<% } %>]; constructor(<%= private() %>http: Http<% if(filters.ws) { %>, <%= private() %>socketService: SocketService<% } %>) { this.Http = http; <%_ if(filters.ws) { -%> diff --git a/templates/app/client/app/main/main.component.spec.js b/templates/app/client/app/main/main.component.spec.js index 5af50bf0c..db8ca4f2c 100644 --- a/templates/app/client/app/main/main.component.spec.js +++ b/templates/app/client/app/main/main.component.spec.js @@ -17,9 +17,9 @@ import { MockBackend } from '@angular/http/testing'; <%_ if(filters.mocha && filters.expect) { -%> import { expect } from 'chai';<% } %><% if(filters.uibootstrap) { %> import { TooltipModule } from 'ngx-bootstrap';<% } %> -import { FormsModule } from '@angular/forms'; +import { FormsModule } from '@angular/forms';<% if(filters.ws) { %> import { SocketService } from '../../components/socket/socket.service'; -import { SocketServiceStub } from '../../components/socket/socket.mock'; +import { SocketServiceStub } from '../../components/socket/socket.mock';<% } %> import { MainComponent } from './main.component'; describe('Component: MainComponent', function() { @@ -41,21 +41,21 @@ describe('Component: MainComponent', function() { provide: Http, useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => { return new Http(backend, defaultOptions); - },<%_ if(filters.ws) { %> - deps: [MockBackend, BaseRequestOptions]<% } %> - }, - { provide: SocketService, useClass: SocketServiceStub }, + }, + deps: [MockBackend, BaseRequestOptions] + },<% if(filters.ws) { %> + { provide: SocketService, useClass: SocketServiceStub },<% } %> ], }).compileComponents(); })); - <%_ if(filters.ws) { %> + beforeEach(async(inject([MockBackend], (mockBackend) => { mockBackend.connections.subscribe(conn => { conn.mockRespond(new Response(new ResponseOptions({ body: JSON.stringify(['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express']) }))); }); - })));<% } %> + }))); beforeEach(async(() => { fixture = TestBed.createComponent(MainComponent); @@ -69,7 +69,7 @@ describe('Component: MainComponent', function() { })); it('should attach a list of things to the controller', () => {<% if(filters.jasmine) { %> - expect(comp.awesomeThings.length).toEqual(4);<% } else if(filters.mocha) { -%> + expect(comp.awesomeThings.length).toEqual(4);<% } else if(filters.mocha) { %> <%= expect() %>comp.awesomeThings.length<%= to() %>.equal(4);<% } %> }); }); diff --git a/templates/app/client/components/directives.module.js b/templates/app/client/components/directives.module.js index ca86bfdd7..6c0c4885a 100644 --- a/templates/app/client/components/directives.module.js +++ b/templates/app/client/components/directives.module.js @@ -7,8 +7,8 @@ import { CollapseModule } from 'ngx-bootstrap';<% } %> import { UIRouterModule } from 'ui-router-ng2';<% } %> <%_ if (filters.ngroute) { -%> import { RouterModule } from '@angular/router';<% } %> - -import { AuthModule } from './auth/auth.module'; +<% if(filters.auth) { %> +import { AuthModule } from './auth/auth.module';<% } %> import { NavbarComponent } from './navbar/navbar.component'; import { FooterComponent } from './footer/footer.component'; @@ -17,9 +17,9 @@ import { OauthButtonsComponent } from './oauth-buttons/oauth-buttons.component'; @NgModule({ imports: [ - CommonModule, - <% if(filters.uibootstrap) { %>CollapseModule,<% } %> - AuthModule, + CommonModule,<% if(filters.uibootstrap) { %> + CollapseModule,<% } %><% if(filters.auth) { %> + AuthModule,<% } %> <%_ if (filters.uirouter) { -%> UIRouterModule,<% } %> <%_ if (filters.ngroute) { -%>