From ed989c2ee87512c8bea2b199b8cad50bac29df0b Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 5 Dec 2023 15:02:42 +0530 Subject: [PATCH] feat: add configure command --- configure.ts | 36 +++++++++++++++++++ index.ts | 2 ++ package.json | 27 ++++++++++---- ...tub => initialize_bouncer_middleware.stub} | 0 stubs/main.ts | 12 +++++++ 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 configure.ts rename stubs/{init_bouncer_middleware.stub => initialize_bouncer_middleware.stub} (100%) create mode 100644 stubs/main.ts diff --git a/configure.ts b/configure.ts new file mode 100644 index 0000000..311bec2 --- /dev/null +++ b/configure.ts @@ -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', + }, + ]) +} diff --git a/index.ts b/index.ts index 07ad703..8d36c16 100644 --- a/index.ts +++ b/index.ts @@ -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' diff --git a/package.json b/package.json index 4dfdb04..6040443 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "files": [ "build", "!build/bin", - "!build/tests", - "!build/tests_helpers" + "!build/tests" ], "exports": { ".": "./build/index.js", @@ -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", @@ -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" }, @@ -107,7 +122,9 @@ }, "tsup": { "entry": [ - "./index.ts" + "./index.ts", + "./providers/bouncer_provider.ts", + "./src/plugins/edge.ts" ], "outDir": "./build", "clean": true, @@ -115,9 +132,5 @@ "dts": false, "sourcemap": true, "target": "esnext" - }, - "dependencies": { - "@poppinss/hooks": "^7.2.1", - "@poppinss/utils": "^6.6.0" } } diff --git a/stubs/init_bouncer_middleware.stub b/stubs/initialize_bouncer_middleware.stub similarity index 100% rename from stubs/init_bouncer_middleware.stub rename to stubs/initialize_bouncer_middleware.stub diff --git a/stubs/main.ts b/stubs/main.ts new file mode 100644 index 0000000..0c7a922 --- /dev/null +++ b/stubs/main.ts @@ -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)