Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
jobs:
linux:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- '6382:6379'
strategy:
matrix:
node-version:
Expand All @@ -32,25 +37,3 @@ jobs:

- name: Test code compilation
run: npm run build

windows:
runs-on: windows-latest
strategy:
matrix:
node-version:
- 21.x
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test:coverage

- name: Test code compilation
run: npm run build
8 changes: 8 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

services:
redis:
container_name: athenna_db_redis
image: redis:6.2-alpine
ports:
- '6382:6379'
42 changes: 42 additions & 0 deletions configurer/cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Env } from '@athenna/config'

export default {
/*
|--------------------------------------------------------------------------
| Default Cache Store Name
|--------------------------------------------------------------------------
|
| Athenna's cache API supports an assortment of back-ends via a single
| API, giving you convenient access to each back-end using the same
| syntax for every one. Here you may define a default store.
|
*/

default: Env('CACHE_STORE', 'memory'),

/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may configure the store connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Athenna. You are free to add more.
|
| Drivers: "redis", "memory"
|
*/

stores: {
memory: {
driver: 'memory'
},

redis: {
driver: 'redis',

url: Env('REDIS_URL', 'redis://localhost:6379?database=0')
}
}
}

8 changes: 8 additions & 0 deletions configurer/docker/redis/file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

services:
redis:
container_name: athenna_redis
image: redis
ports:
- '6379:6379'
14 changes: 14 additions & 0 deletions configurer/docker/redis/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @athenna/cache
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

export default {
container_name: 'athenna_redis',
image: 'redis',
ports: ['6379:6379']
}
58 changes: 57 additions & 1 deletion configurer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
* file that was distributed with this source code.
*/

import { File, Path } from '@athenna/common'
import { BaseConfigurer } from '@athenna/artisan'
import { File, Path, Parser, Module } from '@athenna/common'

export default class CacheConfigurer extends BaseConfigurer {
public async configure() {
const stores = await this.prompt.checkbox(
'Which cache stores do you plan to use?',
['redis', 'memory']
)

const task = this.logger.task()
const hasSelectedRedis = stores.find(store => store === 'redis')

task.addPromise(`Create cache.${Path.ext()} config file`, () => {
return new File('./cache').copy(Path.config(`cache.${Path.ext()}`))
Expand All @@ -24,6 +30,56 @@ export default class CacheConfigurer extends BaseConfigurer {
.save()
})

task.addPromise('Update .env, .env.test and .env.example', () => {
let envs = '\nCACHE_STORE=memory\n'

if (hasSelectedRedis) {
envs += 'REDIS_URL=redis://localhost:6379?database=0\n'
}

return new File(Path.pwd('.env'), '')
.append(envs)
.then(() => new File(Path.pwd('.env.test'), '').append(envs))
.then(() => new File(Path.pwd('.env.example'), '').append(envs))
})

if (hasSelectedRedis) {
task.addPromise('Add service to docker-compose.yml file', async () => {
const hasDockerCompose = await File.exists(
Path.pwd('docker-compose.yml')
)

if (hasDockerCompose) {
const docker = await new File(
Path.pwd('docker-compose.yml')
).getContentAsYaml()

docker.services.redis = await Module.get(
import('./docker/redis/service.js')
)

return new File(Path.pwd('docker-compose.yml')).setContent(
Parser.objectToYamlString(docker)
)
}

return new File(`./docker/redis/file.yml`).copy(
Path.pwd('docker-compose.yml')
)
})
}

const libraries = {
redis: ['redis'],
memory: ['lru-cache']
}

task.addPromise(`Install ${stores.join(', ')} libraries`, () => {
return stores.athenna.concurrently(store => {
return this.npm.install(libraries[store])
})
})

await task.run()

console.log()
Expand Down
104 changes: 98 additions & 6 deletions package-lock.json

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

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/cache",
"version": "5.1.0",
"version": "5.2.0",
"description": "The cache handler for Athenna Framework.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down Expand Up @@ -70,7 +70,9 @@
"eslint-plugin-promise": "^6.6.0",
"husky": "^3.1.0",
"lint-staged": "^12.5.0",
"prettier": "^2.8.8"
"lru-cache": "^11.1.0",
"prettier": "^2.8.8",
"redis": "^5.8.1"
},
"c8": {
"all": true,
Expand Down Expand Up @@ -164,8 +166,5 @@
}
]
}
},
"dependencies": {
"lru-cache": "^11.1.0"
}
}
Loading