Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor on filenames #34

Merged
merged 3 commits into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions generators/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,21 @@ module.exports = yeoman.Base.extend({

writing: function () {
var props = this.props;
var routesFile = path.join(props.srcDir, 'routes.js');
var routesFile = path.join(props.dir, 'index.js');
var copyTpl = this.fs.copyTpl.bind(this.fs);
var tPath = this.templatePath.bind(this);
var dPath = this.destinationPath.bind(this);
var filepath = function (filename) {
return path.join(props.dir, props.kebab, filename.replace('api', props.kebab));
return path.join(props.dir, props.kebab, filename);
};

copyTpl(tPath('api.controller.js'), dPath(filepath('api.controller.js')), props);
copyTpl(tPath('api.router.js'), dPath(filepath('api.router.js')), props);
copyTpl(tPath('api.router.test.js'), dPath(filepath('api.router.test.js')), props);
copyTpl(tPath('package.json'), dPath(filepath('package.json')), props);
copyTpl(tPath('controller.js'), dPath(filepath('controller.js')), props);
copyTpl(tPath('index.js'), dPath(filepath('index.js')), props);
copyTpl(tPath('index.test.js'), dPath(filepath('index.test.js')), props);

if (props.generateModel) {
copyTpl(tPath('api.model.js'), dPath(filepath('api.model.js')), props);
copyTpl(tPath('api.model.test.js'), dPath(filepath('api.model.test.js')), props);
copyTpl(tPath('model.js'), dPath(filepath('model.js')), props);
copyTpl(tPath('model.test.js'), dPath(filepath('model.test.js')), props);
}

if (this.fs.exists(routesFile)) {
Expand All @@ -184,9 +183,7 @@ module.exports = yeoman.Base.extend({
return statement.type === 'ImportDeclaration';
});
var actualImportCode = recast.print(body[lastImportIndex]).code;
var importString = [
'import ', props.camel, ' from \'./', props.apiDir, '/', props.kebab, '\''
].join('');
var importString = ['import ', props.camel, ' from \'./', props.kebab, '\''].join('');
body.splice(lastImportIndex, 1, importString);
body.splice(lastImportIndex, 0, actualImportCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ import { middleware as body } from 'bodymen'
import { <%= authMiddlewares.join(', ') %> } from '../../services/passport'
<%_ } _%>
<%_ if (methods.length) { _%>
import { <%= methods.map(function (method) { return method.controller }).join(', ') %> } from './<%= kebab %>.controller'
import { <%= methods.map(function (method) { return method.controller }).join(', ') %> } from './controller'
<%_ } _%>
<%_ if (generateModel) { _%>
<%_ if (hasBody) { _%>
import { schema } from './<%= kebab %>.model'
import { schema } from './model'
<%_ } _%>
export <%= pascal %>, { schema } from './<%= kebab %>.model'
export <%= pascal %>, { schema } from './model'
<%_ } _%>

const router = new Router()
Expand Down
6 changes: 0 additions & 6 deletions generators/api/templates/package.json

This file was deleted.

1 change: 1 addition & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = yeoman.Base.extend({
copyTpl(tPath('src'), dPath(props.srcDir), props);
copyTpl(tPath('test'), dPath('test'), props);
copyTpl(tPath('services/response'), dPath(props.srcDir + '/services/response'), props);
copyTpl(tPath('api/index.js'), dPath(props.srcDir + '/' + props.apiDir + '/index.js'), props);

if (props.generateAuthApi) {
copyTpl(tPath('services/passport'), dPath(props.srcDir + '/services/passport'), props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (authServices.length) {
}
_%>
import { Router } from 'express'
import { login } from './auth.controller'
import { login } from './controller'
<%_ if (passport.length) { _%>
import { <%= passport.join(', ') %> } from '../../services/passport'
<%_ } _%>
Expand Down
6 changes: 0 additions & 6 deletions generators/app/templates/api/auth/package.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Router } from 'express'
<%_ if (generateAuthApi) { _%>
import user from './<%= apiDir %>/user'
import auth from './<%= apiDir %>/auth'
import user from './user'
import auth from './auth'
<%_ } _%>
<%_ if (typeof passwordReset !== 'undefined' && passwordReset) { _%>
import passwordReset from './<%= apiDir %>/password-reset'
import passwordReset from './password-reset'
<%_ } _%>

const router = new Router()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Router } from 'express'
import { middleware as body } from 'bodymen'
import { master } from '../../services/passport'
import { create, show, update } from './password-reset.controller'
import { create, show, update } from './controller'
import { schema } from '../user'
export PasswordReset, { schema } from './password-reset.model'
export PasswordReset, { schema } from './model'

const router = new Router()
const { email, password } = schema.tree
Expand Down
6 changes: 0 additions & 6 deletions generators/app/templates/api/password-reset/package.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Router } from 'express'
import { middleware as query } from 'querymen'
import { middleware as body } from 'bodymen'
import {<% if (passwordSignup) { %> password as passwordAuth,<% } %> master, token } from '../../services/passport'
import { index, showMe, show, create, update<% if (passwordSignup) { %>, updatePassword<% } %>, destroy } from './user.controller'
import { schema } from './user.model'
export User, { schema } from './user.model'
import { index, showMe, show, create, update<% if (passwordSignup) { %>, updatePassword<% } %>, destroy } from './controller'
import { schema } from './model'
export User, { schema } from './model'

const router = new Router()
const { email<% if (passwordSignup) { %>, password<% } %>, name, picture, role } = schema.tree
Expand Down
6 changes: 0 additions & 6 deletions generators/app/templates/api/user/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion generators/app/templates/services/passport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { jwtSecret, masterKey } from '../../config'
<%_ authServices.forEach(function (service) { _%>
import * as <%= service %>Service from '../<%= service %>'
<%_ }) _%>
import User<% if (passwordSignup) { %>, { schema }<% } %> from '../../<%= apiDir %>/user/user.model'
import User<% if (passwordSignup) { %>, { schema }<% } %> from '../../<%= apiDir %>/user/model'

<%_ if (passwordSignup) { _%>
export const password = () => (req, res, next) =>
Expand Down
4 changes: 2 additions & 2 deletions generators/app/templates/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import http from 'http'
import { env, mongo, port, ip } from './config'
import mongoose from './config/mongoose'
import express from './config/express'
import routes from './routes'
import api from './api'

const app = express(routes)
const app = express(api)
const server = http.createServer(app)

mongoose.connect(mongo.uri)
Expand Down