Skip to content

Commit

Permalink
[chore] cleanup, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-wyatt committed Jul 16, 2018
1 parent 2fd3f45 commit e6d7d64
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
3 changes: 2 additions & 1 deletion lib/TapestriesSpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ export class TapestriesSpool extends Spool {
const controllerTapestries = Util.getControllerTapestries(this.app) || []
const modelTapestries = this.modelTapestries ? Util.getModelTapestries(this.app) : []
const tapestryRoutes = union(controllerTapestries, modelTapestries) || []
const configRoutes = Object.values(this.app.config.get('routes') || [])

this.app.config.set('routes', [
...tapestryRoutes,
...(this.app.config.get('routes') || [])
...configRoutes
])
}
}
Expand Down
40 changes: 33 additions & 7 deletions lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
import { FabrixApp } from '@fabrix/fabrix'
import { join } from 'path'
import { get, map, flatten, omit } from 'lodash'
import { map, flatten, omit } from 'lodash'
import { Routes } from './routes'

export const Util = {
/**
* Get the controller method(s)
*/
getControllerMethods(app: FabrixApp) {
let configMethod = app.config.get('tapestries.controllers.method') || ['GET', 'POST']
if (configMethod instanceof Object) {
configMethod = Object.values(configMethod)
}
return configMethod
},

/**
* Get the Controllers to be Ignored by Tapestries
*/
getControllerIgnore(app: FabrixApp): string[] {
return Object.values(app.config.get('tapestries.controllers.ignore') || [])
},
/**
* Get either the configured spool-tapestries prefix, or use the one set by spool-router if any.
*/
getPrefix(app: FabrixApp) {
let prefix = app.config.get('tapestries.prefix')
if (!prefix) {
prefix = app.config.get('router.prefix') || ''
}
return prefix.toString()
},
/**
* Compile controller handlers into route objects
*/
getControllerTapestries (app: FabrixApp): {method: string, path: string, handler: string}[] {
if (app.config.get('tapestries.controllers')) {
// Returns an object of available Controllers for Tapestries
const controllers = omit(
app.controllers || {},
app.config.get('tapestries.controllers.ignore') || []
Util.getControllerIgnore(app)
)

const prefix = (app.config.get('tapestries.prefix') || '').toString()
const prefix = Util.getPrefix(app)

return flatten(map(controllers, (controller, controllerName: string) => {

return map(controller.methods, handlerName => {
return {
method: app.config.get('tapestries.controllers.method') || ['GET', 'POST'],
method: Util.getControllerMethods(app),
path: Util.getHandlerPath(app, prefix, controller.id, handlerName),
handler: Util.getControllerHandler(controllerName, handlerName)
}
Expand All @@ -37,8 +63,8 @@ export const Util = {
* Select the model tapestry routes that the configuration allows.
*/
getModelTapestries (app: FabrixApp): any[] {
const actionsConfig = app.config.get('tapestries.models.actions') || []
const prefix = (app.config.get('tapestries.prefix') || '').toString()
const actionsConfig = app.config.get('tapestries.models.actions') || {}
const prefix = Util.getPrefix(app)

return Routes
.filter(route => {
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-tapestries",
"version": "1.0.0",
"version": "1.0.1",
"description": "Spool - Tapestries, Easy RESTful Services",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down Expand Up @@ -49,8 +49,8 @@
"lodash": "^4.17.10"
},
"devDependencies": {
"@fabrix/fabrix": "^1.0.1",
"@fabrix/spool-router": "^1.0.0",
"@fabrix/fabrix": "^1.0.8",
"@fabrix/spool-router": "^1.0.1",
"@fabrix/lint": "^1.0.0-alpha.3",
"@types/lodash": "^4.14.109",
"@types/node": "~10.3.4",
Expand All @@ -64,7 +64,7 @@
"typescript": "~2.8.1"
},
"peerDependencies": {
"@fabrix/fabrix": "^1.0.1",
"@fabrix/fabrix": "^1.0.8",
"@fabrix/spool-router": "^1.0.0"
},
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Router Spool', () => {

describe('#configure', () => {
it('should have a prefix', () => {
console.log(global.app.config.entries())
// console.log(global.app.config.entries())
assert.equal(global.app.config.get('tapestries.prefix'), '/api/v1')
})
})
Expand Down Expand Up @@ -37,10 +37,6 @@ describe('Router Spool', () => {
r.method === 'GET'
)
})

// console.log('configRoute', configRoute)
// console.log('app.routes', global.app.routes)

assert(_.isFunction(configRoute.config.pre[0]))
})
})
Expand Down

0 comments on commit e6d7d64

Please sign in to comment.