Skip to content

Commit

Permalink
feat: add configure command
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 5, 2023
1 parent 5eff877 commit ed989c2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
36 changes: 36 additions & 0 deletions configure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* @adonisjs/bouncer
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import type Configure from '@adonisjs/core/commands/configure'

/**
* Configures the package
*/
export async function configure(command: Configure) {
const codemods = await command.createCodemods()

/**
* Register provider
*/
await codemods.updateRcFile((rcFile) => {
rcFile.addProvider('@adonisjs/bouncer/bouncer_provider')
})

/**
* Publish and register middleware
*/
await command.publishStub('initialize_bouncer_middleware.stub', {
entity: command.app.generators.createEntity('initialize_bouncer'),
})
await codemods.registerMiddleware('router', [
{
path: '#middleware/initialize_bouncer_middleware',
},
])
}
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

export * as errors from './src/errors.js'
export { Bouncer } from './src/bouncer.js'
export { configure } from './configure.js'
export { stubsRoot } from './stubs/main.js'
export { BasePolicy } from './src/base_policy.js'
export { AuthorizationResponse } from './src/response.js'
export { action, allowGuest } from './src/decorators/action.js'
27 changes: 20 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"files": [
"build",
"!build/bin",
"!build/tests",
"!build/tests_helpers"
"!build/tests"
],
"exports": {
".": "./build/index.js",
Expand Down Expand Up @@ -52,6 +51,7 @@
"adonisjs"
],
"devDependencies": {
"@adonisjs/assembler": "^6.1.3-29",
"@adonisjs/core": "^6.1.5-33",
"@adonisjs/eslint-config": "^1.2.0",
"@adonisjs/i18n": "^2.0.0-8",
Expand All @@ -77,6 +77,21 @@
"tsup": "^8.0.1",
"typescript": "5.2.2"
},
"dependencies": {
"@poppinss/utils": "^6.6.0"
},
"peerDependencies": {
"@adonisjs/core": "^6.1.5-33",
"@adonisjs/i18n": "^2.0.0-8"
},
"peerDependenciesMeta": {
"@adonisjs/core": {
"optional": true
},
"@adonisjs/i18n": {
"optional": true
}
},
"eslintConfig": {
"extends": "@adonisjs/eslint-config/package"
},
Expand Down Expand Up @@ -107,17 +122,15 @@
},
"tsup": {
"entry": [
"./index.ts"
"./index.ts",
"./providers/bouncer_provider.ts",
"./src/plugins/edge.ts"
],
"outDir": "./build",
"clean": true,
"format": "esm",
"dts": false,
"sourcemap": true,
"target": "esnext"
},
"dependencies": {
"@poppinss/hooks": "^7.2.1",
"@poppinss/utils": "^6.6.0"
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions stubs/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* @adonisjs/bouncer
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { getDirname } from '@poppinss/utils'

export const stubsRoot = getDirname(import.meta.url)

0 comments on commit ed989c2

Please sign in to comment.