Skip to content

Commit 2dba2bb

Browse files
committed
feat: add more tests and configurer
1 parent 1b5d001 commit 2dba2bb

13 files changed

Lines changed: 1436 additions & 211 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
STORAGE_DISK=fs
2+
AWS_REGION=sa-east-1
3+
AWS_S3_BUCKET_NAME=athenna-storage
4+
AWS_ACCESS_KEY_ID=
5+
AWS_SECRET_ACCESS_KEY=

configurer/index.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @athenna/storage
3+
*
4+
* (c) João Lenon <lenon@athenna.io>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
import { File, Path } from '@athenna/common'
11+
import { BaseConfigurer } from '@athenna/artisan'
12+
13+
export default class StorageConfigurer extends BaseConfigurer {
14+
public async configure() {
15+
await this.logger
16+
.task()
17+
.addPromise(`Create storage.${Path.ext()} config file`, () => {
18+
return new File('./storage').copy(Path.config(`storage.${Path.ext()}`))
19+
})
20+
.addPromise('Update providers of .athennarc.json', () => {
21+
return this.rc
22+
.pushTo('providers', '@athenna/storage/providers/StorageProvider')
23+
.save()
24+
})
25+
.addPromise('Update .env, .env.test and .env.example', () => {
26+
const envs =
27+
'\nSTORAGE_DISK=fs\n' +
28+
'AWS_REGION=us-east-1\n' +
29+
'AWS_S3_BUCKET_NAME=athenna-storage\n' +
30+
'AWS_ACCESS_KEY_ID=\n' +
31+
'AWS_SECRET_ACCESS_KEY=\n'
32+
33+
return new File(Path.pwd('.env'), '')
34+
.append(envs)
35+
.then(() => new File(Path.pwd('.env.test'), '').append(envs))
36+
.then(() => new File(Path.pwd('.env.example'), '').append(envs))
37+
})
38+
.run()
39+
}
40+
}

configurer/storage

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Env } from '@athenna/config'
2+
import { Path } from '@athenna/common'
3+
4+
export default {
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Default Storage Disk
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here you may specify the default storage disk that should be used
11+
| by the framework. The "fs" disk, as well as a variety of cloud
12+
| based disks are available to your application.
13+
|
14+
*/
15+
16+
default: Env('STORAGE_DISK', 'fs'),
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Storage Disks
21+
|--------------------------------------------------------------------------
22+
|
23+
| Here you may configure as many storage "disks" as you wish, and you
24+
| may even configure multiple disks of the same driver. Defaults have
25+
| been setup for each driver as an example of the required options.
26+
|
27+
*/
28+
29+
disks: {
30+
fs: {
31+
driver: 'fs',
32+
root: Path.storage()
33+
},
34+
fake: {
35+
driver: 'fake'
36+
},
37+
s3: {
38+
driver: 's3',
39+
key: Env('AWS_ACCESS_KEY_ID', ''),
40+
secret: Env('AWS_SECRET_ACCESS_KEY', ''),
41+
region: Env('AWS_REGION', ''),
42+
bucket: Env('AWS_S3_BUCKET_NAME', '')
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)