Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Feb 14, 2021
1 parent 091083e commit f42cce2
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 213 deletions.
4 changes: 2 additions & 2 deletions commands/GenerateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { BaseCommand } from '@adonisjs/ace'
import { randomString } from '@poppinss/utils'
import { string } from '@poppinss/utils/build/helpers'

/**
* A command to generate a secure app key
Expand All @@ -18,7 +18,7 @@ export default class GenerateKey extends BaseCommand {
public static description = 'Generate a new APP_KEY secret'

public async run() {
const secret = randomString(32)
const secret = string.generateRandom(32)
console.log(this.colors.green(secret))

console.log(
Expand Down
99 changes: 49 additions & 50 deletions commands/ListRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { BaseCommand, flags } from '@adonisjs/ace'
import type { RouterContract, RouteNode } from '@ioc:Adonis/Core/Route'
import type { RouterContract } from '@ioc:Adonis/Core/Route'

/**
* A command to display a list of routes
Expand All @@ -27,36 +27,28 @@ export default class ListRoutes extends BaseCommand {
loadApp: true,
}

/**
* Find route from the routes store. We expect it to always return a route
*/
private findRoute(
router: any,
domain: string,
methods: string[],
pattern: string
): RouteNode | undefined {
return router['store']['tree'].domains[domain][methods[0]].routes[pattern]
}

/**
* Returns an array of routes as JSON
*/
private outputJSON(router: RouterContract) {
return router.toJSON().map((lookupRoute) => {
const route = this.findRoute(
router,
lookupRoute.domain,
lookupRoute.methods,
lookupRoute.pattern
)

let handler: string = 'Closure'
const middleware = route
? route.middleware.map((one) => (typeof one === 'function' ? 'Closure' : one))
: []

if (route) {
const routes = router.toJSON()

return Object.keys(routes).reduce<{
[domain: string]: {
methods: string[]
name: string
pattern: string
handler: string
middleware: string[]
}[]
}>((result, domain) => {
result[domain] = routes[domain].map((route) => {
let handler: string = 'Closure'

const middleware = route
? route.middleware.map((one) => (typeof one === 'function' ? 'Closure' : one))
: []

if (route.meta.resolvedHandler!.type !== 'function' && route.meta.namespace) {
handler = `${route.meta.resolvedHandler!['namespace']}.${
route.meta.resolvedHandler!['method']
Expand All @@ -66,36 +58,43 @@ export default class ListRoutes extends BaseCommand {
const routeHandler = route.handler as string
handler = `${routeHandler.replace(new RegExp(`.${method}$`), '')}.${method}`
}
} else if (typeof lookupRoute.handler === 'string') {
handler = lookupRoute.handler
}

return {
methods: lookupRoute.methods,
name: lookupRoute.name || '',
pattern: lookupRoute.pattern,
handler: handler,
domain: lookupRoute.domain === 'root' ? '' : lookupRoute.domain,
middleware: middleware,
}
})
return {
methods: route.methods,
name: route.name || '',
pattern: route.pattern,
handler: handler,
middleware: middleware,
}
})

return result
}, {})
}

/**
* Output routes a table string
*/
private outputTable(router: RouterContract) {
const table = this.ui.table().head(['Route', 'Handler', 'Middleware', 'Name', 'Domain'])

this.outputJSON(router).forEach((route) => {
const row = [
`${this.colors.dim(route.methods.join(','))} ${route.pattern}`,
typeof route.handler === 'function' ? 'Closure' : route.handler,
route.middleware.join(','),
route.name,
route.domain,
]
table.row(row)
const routes = this.outputJSON(router)
const domains = Object.keys(routes)
const showDomainHeadline = domains.length > 1 || domains[0] !== 'root'
const table = this.ui.table().head(['Method', 'Route', 'Handler', 'Middleware', 'Name'])

domains.forEach((domain) => {
if (showDomainHeadline) {
table.row([{ colSpan: 5, content: `Domain ${this.colors.cyan(domain)}` }])
}

routes[domain].forEach((route) => {
table.row([
this.colors.dim(route.methods.join(', ')),
route.pattern,
typeof route.handler === 'function' ? 'Closure' : route.handler,
route.middleware.join(','),
route.name,
])
})
})

table.render()
Expand Down
4 changes: 2 additions & 2 deletions instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { join } from 'path'
import { randomString } from '@poppinss/utils'
import * as sinkStatic from '@adonisjs/sink'
import { string } from '@poppinss/utils/build/helpers'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'

const ENV_VALIDATIONS_TEMPLATE_STUB = join(__dirname, './templates', 'env.txt')
Expand Down Expand Up @@ -73,7 +73,7 @@ export default async function instructions(
env.set('PORT', 3333)
env.set('HOST', '0.0.0.0')
env.set('NODE_ENV', 'development')
env.set('APP_KEY', randomString(32))
env.set('APP_KEY', string.generateRandom(32))
env.commit()
logger.action(env.exists() ? 'update' : 'create').succeeded('.env,.env.example')

Expand Down
56 changes: 28 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@
"homepage": "https://github.com/adonisjs/core#readme",
"devDependencies": {
"@adonisjs/assembler": "^3.0.6",
"@adonisjs/mrm-preset": "^2.4.0",
"@adonisjs/repl": "^1.1.5",
"@adonisjs/require-ts": "^1.1.0",
"@adonisjs/sink": "^4.2.0",
"@poppinss/dev-utils": "^1.0.11",
"@types/node": "^14.14.10",
"@adonisjs/mrm-preset": "^3.0.0",
"@adonisjs/repl": "^1.1.6",
"@adonisjs/require-ts": "^2.0.2",
"@adonisjs/sink": "^5.0.0",
"@poppinss/dev-utils": "^1.1.0",
"@types/node": "^14.14.27",
"@types/supertest": "^2.0.10",
"clear-module": "^4.1.1",
"commitizen": "^4.2.2",
"copyfiles": "^2.4.0",
"commitizen": "^4.2.3",
"copyfiles": "^2.4.1",
"cz-conventional-changelog": "^3.3.0",
"del-cli": "^3.0.1",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-adonis": "^1.0.15",
"eslint-plugin-prettier": "^3.1.4",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-adonis": "^1.2.0",
"eslint-plugin-prettier": "^3.3.1",
"github-label-sync": "^2.0.0",
"husky": "^4.3.0",
"husky": "^5.0.9",
"japa": "^3.1.1",
"mrm": "^2.5.13",
"np": "^7.0.0",
"mrm": "^2.5.18",
"np": "^7.4.0",
"npm-audit-html": "^1.5.0",
"prettier": "^2.2.0",
"prettier": "^2.2.1",
"reflect-metadata": "^0.1.13",
"strip-ansi": "^6.0.0",
"supertest": "^6.0.1",
"supertest": "^6.1.3",
"test-console": "^1.1.0",
"typescript": "^4.1.2",
"typescript": "^4.1.5",
"youch": "^2.1.1",
"youch-terminal": "^1.0.1"
},
Expand All @@ -97,16 +97,16 @@
}
},
"dependencies": {
"@adonisjs/ace": "^8.0.0",
"@adonisjs/application": "^3.0.21",
"@adonisjs/bodyparser": "^5.0.7",
"@adonisjs/encryption": "^3.0.7",
"@adonisjs/events": "^5.0.6",
"@adonisjs/hash": "^6.0.7",
"@adonisjs/http-server": "^4.0.9",
"@adonisjs/validator": "^8.2.0",
"@poppinss/cliui": "^2.0.2",
"@poppinss/utils": "^2.5.9",
"@adonisjs/ace": "^9.0.2",
"@adonisjs/application": "^4.0.4",
"@adonisjs/bodyparser": "^6.0.0",
"@adonisjs/encryption": "^4.0.0",
"@adonisjs/events": "^6.0.0",
"@adonisjs/hash": "^7.0.0",
"@adonisjs/http-server": "^5.1.0",
"@adonisjs/validator": "^9.0.0",
"@poppinss/cliui": "^2.2.0",
"@poppinss/utils": "^3.0.3",
"serve-static": "^1.14.1"
},
"np": {
Expand Down
27 changes: 15 additions & 12 deletions providers/AppProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ export default class AppProvider {
/**
* Register the cors before hook with the server
*/
this.app.container.with(['Adonis/Core/Config', 'Adonis/Core/Server'], (Config, Server) => {
const config = Config.get('cors', {})
if (!config.enabled) {
return
}
this.app.container.withBindings(
['Adonis/Core/Config', 'Adonis/Core/Server'],
(Config, Server) => {
const config = Config.get('cors', {})
if (!config.enabled) {
return
}

const Cors = require('../src/Hooks/Cors').Cors
const cors = new Cors(config)
Server.hooks.before(cors.handle.bind(cors))
})
const Cors = require('../src/Hooks/Cors').Cors
const cors = new Cors(config)
Server.hooks.before(cors.handle.bind(cors))
}
)
}

/**
Expand All @@ -96,7 +99,7 @@ export default class AppProvider {
/**
* Register the cors before hook with the server
*/
this.app.container.with(
this.app.container.withBindings(
['Adonis/Core/Config', 'Adonis/Core/Server', 'Adonis/Core/Application'],
(Config, Server, Application) => {
const config = Config.get('static', {})
Expand All @@ -123,7 +126,7 @@ export default class AppProvider {
return
}

this.app.container.with(['Adonis/Core/HealthCheck'], (healthCheck) => {
this.app.container.withBindings(['Adonis/Core/HealthCheck'], (healthCheck) => {
require('../src/HealthCheck/Checkers/Env').default(healthCheck)
require('../src/HealthCheck/Checkers/AppKey').default(healthCheck)
})
Expand All @@ -144,7 +147,7 @@ export default class AppProvider {
/**
* Define REPL bindings
*/
this.app.container.with(['Adonis/Addons/Repl'], (Repl) => {
this.app.container.withBindings(['Adonis/Addons/Repl'], (Repl) => {
const { defineReplBindings } = require('../src/Bindings/Repl')
defineReplBindings(this.app, Repl)
})
Expand Down
8 changes: 4 additions & 4 deletions src/Ignitor/Ace/App/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/

import { join } from 'path'
import { resolveFrom } from '@poppinss/utils'
import { sticker, logger } from '@poppinss/cliui'
import { Application } from '@adonisjs/application'
import { Kernel, ManifestLoader } from '@adonisjs/ace'
import { resolveFrom } from '@poppinss/utils/build/helpers'

import { ErrorHandler } from '../ErrorHandler'
import { registerTsHook } from '../../../utils'
Expand Down Expand Up @@ -212,10 +212,10 @@ export class App {
/**
* Do not change sequence
*/
this.application.setup()
this.application.registerProviders()
await this.application.setup()
await this.application.registerProviders()
await this.application.bootProviders()
this.application.requirePreloads()
await this.application.requirePreloads()
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Ignitor/HttpServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export class HttpServer {
/**
* Setting up the application.
*/
this.application.setup()
await this.application.setup()

/**
* Registering providers
*/
this.application.registerProviders()
await this.application.registerProviders()

/**
* Booting providers
Expand All @@ -73,7 +73,7 @@ export class HttpServer {
/**
* Importing preloaded files
*/
this.application.requirePreloads()
await this.application.requirePreloads()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/

import { resolveFrom } from '@poppinss/utils'
import { resolveFrom } from '@poppinss/utils/build/helpers'

/**
* Helper to know if error belongs to a missing module
Expand Down
4 changes: 2 additions & 2 deletions test-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export async function setupApp(additionalProviders?: string[]) {
await setupApplicationFiles(additionalProviders)
const app = new Application(fs.basePath, 'web')

app.setup()
app.registerProviders()
await app.setup()
await app.registerProviders()
await app.bootProviders()

return app
Expand Down
18 changes: 11 additions & 7 deletions test/ignitor-ace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ test.group('Ignitor | Ace | Generate Manifest', (group) => {

const aceManifest = await fs.fsExtra.readJson(join(fs.basePath, './ace-manifest.json'))
assert.deepEqual(aceManifest, {
foo: {
settings: {},
commandPath: './FooCommand',
commandName: 'foo',
description: '',
args: [],
flags: [],
commands: {
foo: {
settings: {},
aliases: [],
commandPath: './FooCommand',
commandName: 'foo',
description: '',
args: [],
flags: [],
},
},
aliases: {},
})

assert.equal(stripAnsi(output[0]).split('CREATE:')[1].trim(), 'ace-manifest.json file')
Expand Down

0 comments on commit f42cce2

Please sign in to comment.