-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48cb1c2
commit c8dce18
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* @adonisjs/redis | ||
* | ||
* (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) { | ||
/** | ||
* Publish config file | ||
*/ | ||
await command.publishStub('config/redis.stub') | ||
|
||
/** | ||
* Publish typings file | ||
*/ | ||
await command.publishStub('types/redis.stub') | ||
|
||
/** | ||
* Add environment variables | ||
*/ | ||
await command.defineEnvVariables({ | ||
REDIS_CONNECTION: 'local', | ||
REDIS_HOST: '127.0.0.1', | ||
REDIS_PORT: '6379', | ||
REDIS_PASSWORD: '', | ||
}) | ||
|
||
/** | ||
* Add provider to rc file | ||
*/ | ||
await command.updateRcFile((rcFile) => { | ||
rcFile.addProvider('@adonisjs/redis/providers/redis_provider') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
to: {{ app.configPath('redis.ts') }} | ||
--- | ||
|
||
import env from '#start/env' | ||
import { defineConfig } from '@adonisjs/redis' | ||
|
||
export default defineConfig({ | ||
connection: env.get('REDIS_CONNECTION'), | ||
|
||
connections: { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| The default connection | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The main connection you want to use to execute redis commands. The same | ||
| connection will be used by the session provider, if you rely on the | ||
| redis driver. | ||
| | ||
*/ | ||
local: { | ||
host: env.get('REDIS_HOST'), | ||
port: env.get('REDIS_PORT'), | ||
password: env.get('REDIS_PASSWORD', ''), | ||
db: 0, | ||
keyPrefix: '', | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* @adonisjs/redis | ||
* | ||
* (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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
to: {{ app.makePath('types/redis.ts') }} | ||
--- | ||
import redis from '#config/redis' | ||
|
||
declare module '@adonisjs/redis/types' { | ||
export interface RedisConnections extends InferConnections<typeof redis> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* @adonisjs/mail | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { fileURLToPath } from 'node:url' | ||
import { test } from '@japa/runner' | ||
import { IgnitorFactory } from '@adonisjs/core/factories' | ||
import Configure from '@adonisjs/core/commands/configure' | ||
|
||
export const BASE_URL = new URL('./tmp/', import.meta.url) | ||
|
||
async function setupConfigureCommand() { | ||
const ignitor = new IgnitorFactory() | ||
.withCoreProviders() | ||
.withCoreConfig() | ||
.create(BASE_URL, { | ||
importer: (filePath) => { | ||
if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
return import(new URL(filePath, BASE_URL).href) | ||
} | ||
|
||
return import(filePath) | ||
}, | ||
}) | ||
|
||
const app = ignitor.createApp('web') | ||
await app.init() | ||
await app.boot() | ||
|
||
const ace = await app.container.make('ace') | ||
const command = await ace.create(Configure, ['../../index.js']) | ||
|
||
command.ui.switchMode('raw') | ||
|
||
return { command } | ||
} | ||
|
||
test.group('Configure', (group) => { | ||
group.each.setup(({ context }) => { | ||
context.fs.baseUrl = BASE_URL | ||
context.fs.basePath = fileURLToPath(BASE_URL) | ||
}) | ||
|
||
test('publish config and types files', async ({ assert }) => { | ||
const { command } = await setupConfigureCommand() | ||
|
||
await command.exec() | ||
|
||
await assert.fileExists('config/redis.ts') | ||
await assert.fileContains('config/redis.ts', 'export default defineConfig({') | ||
await assert.fileExists('types/redis.ts') | ||
}) | ||
|
||
test('add redis_provider to the rc file', async ({ assert }) => { | ||
const { command } = await setupConfigureCommand() | ||
|
||
await command.exec() | ||
|
||
await assert.fileExists('.adonisrc.json') | ||
await assert.fileContains('.adonisrc.json', '"@adonisjs/redis/providers/redis_provider"') | ||
}) | ||
|
||
test('add env variables for the selected drivers', async ({ assert, fs }) => { | ||
const { command } = await setupConfigureCommand() | ||
|
||
await fs.create('.env', '') | ||
await command.exec() | ||
|
||
await assert.fileContains('.env', 'REDIS_CONNECTION=local') | ||
await assert.fileContains('.env', 'REDIS_HOST=127.0.0.1') | ||
|
||
await assert.fileContains('.env', 'REDIS_PORT=6379') | ||
await assert.fileContains('.env', 'REDIS_PASSWORD=') | ||
}) | ||
}) |