Skip to content

Commit

Permalink
Merge pull request #82 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Add helpers descriptions and fix code links
  • Loading branch information
jlenon7 authored Aug 16, 2023
2 parents b34c961 + 121351e commit 5f96186
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 15 deletions.
6 changes: 3 additions & 3 deletions docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ await Config.loadAll(Path.stubs('config'))

If you are using the [slim](https://athenna.io/docs/getting-started/installation#project-structure)
project structure, or you are building your own project
structure, you are not going to have the config directory
structure, you are not going to have the `config` directory
in your project root path.

You will have two options now:
Expand All @@ -493,7 +493,7 @@ The [slim](https://athenna.io/docs/getting-started/installation#project-structur
project structure is using the second option above to
specify to Athenna that the configuration files will
be inside of `src/config` directory. Check the examples
above how this implementation works.
bellow to see how this implementation works.

:::

Expand All @@ -505,7 +505,7 @@ defined.

The `directories` property is an object that maps the directory
base path that the [`Path`](https://athenna.io/docs/digging-deeper/helpers#path)
class will use to resolve your application paths:
helper will use to resolve your application paths:

```typescript
import { Path } from '@athenna/common'
Expand Down
2 changes: 1 addition & 1 deletion docs/rest-api-application/rate-limiting.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Rate Limiting
sidebar_position: 7
sidebar_position: 6
description: See how to create rate limiting rules for Athenna REST API application.
tags:
- REST API Application
Expand Down
2 changes: 1 addition & 1 deletion docs/rest-api-application/security-with-helmet.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Security with Helmet
sidebar_position: 9
sidebar_position: 8
description: See how to improve the security of your REST API with Helmet in Athenna.
tags:
- REST API Application
Expand Down
2 changes: 1 addition & 1 deletion docs/rest-api-application/swagger-documentation.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Swagger Documentation
sidebar_position: 6
sidebar_position: 9
description: See how to create the Swagger documentation for Athenna REST API application.
tags:
- REST API Application
Expand Down
2 changes: 1 addition & 1 deletion docs/rest-api-application/tracing-requests.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Tracing Requests
sidebar_position: 8
sidebar_position: 7
description: Understand how to trace requests in your REST API application of Athenna.
tags:
- REST API Application
Expand Down
208 changes: 205 additions & 3 deletions docs/the-basics/helpers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,36 @@ them in your own applications if you find them convenient.

## Available helpers

- [`Clean`](/docs/the-basics/helpers#clean) - Remove falsy values
from different data structures.
- [`Color`](/docs/the-basics/helpers#color) - The UI Kit of Athenna
command line applications.
- [`Exec`](/docs/the-basics/helpers#exec) - Simple helpers that executes
some operation, like executing a command in a child process.
- [`FakeApi`](/docs/the-basics/helpers#fakeapi) - Create a fake REST API
using `json` files to map the routes and their returns (similiar to [WireMock](https://wiremock.org/)).
- [`File`](/docs/the-basics/helpers#file) - Create, copy, move,
delete and get information about files.
- [`Folder`](/docs/the-basics/helpers#folder) - Create, copy, move,
delete and get information about folders.

### `File`
### `Clean`

Coming soon

### `Color`

Coming soon

### `Exec`

Coming soon

### `FakeApi`

Coming soon

Use the `File` class to create an instance of a file, it existing or not.
### `File`

#### `File.load()` & `File.loadSync()`

Expand Down Expand Up @@ -339,4 +361,184 @@ const file = await File.createFileOfSize('fake.js', 1024 * 1024 * 100) 👈

### `Folder`

Coming soon
#### `Folder.load()` & `Folder.loadSync()`

Creates the folder if it does not exist and also load the folder information:

```typescript
import { Folder } from '@athenna/common'

const existent = new Folder(Path.storage('existent'))
const nonExistent = new Folder('./nonExistent')

// Load the folder info with sub folders and with file contents.
await existent.load({ withSub: true, withContent: true }) 👈

// Create and load the folder info without the
// content (be careful when loading big files).
nonExistent.loadSync() 👈
```

After loading process, the folder will contain new informations:

- createdAt - The date when the folder was created.
- accessedAt - The date when the folder was last accessed.
- modifiedAt - The date when the folder was last modified.
- folderSize - The size of the folder in MB.

#### `Folder.copy()` & `Folder.copySync()`

Create a copy of the folder in other location or with other name:

```typescript
import { Folder } from '@athenna/common'

const copiedFolder = folder.copySync('./copy-of-folder')
const copiedFolder = await folder.copy(Path.storage('copy-of-folder'))
```

To copy the folder and load the sub folders and the content of the
copy set the `withSub` and `withContent` as `true`:

```typescript
import { Folder } from '@athenna/common'

const copiedFolder = await folder.copy(Path.storage('copy-of-folder'), {
withSub: true, 👈
withContent: true 👈
})
```

When copying the folder you can set the `mockedValues` to `true` to copy the
files with fake names:

```typescript
import { Folder } from '@athenna/common'

const copiedFolder = await folder.copy(Path.storage('copy-of-file'), {
mockedValues: true 👈
})
```

#### `Folder.move()` & `Folder.moveSync()`

Move the folder to other location:

```typescript
import { Folder } from '@athenna/common'

const movedFolder = folder.moveSync('./move-of-folder') 👈
const movedFolder = await folder.move(Path.storage('move-of-folder')) 👈
```

To move the folder and load the sub folders and the content of the
move set the `withSub` and `withContent` as `true`:

```typescript
import { Folder } from '@athenna/common'

const movedFolder = await folder.move(Path.storage('move-of-folder'), {
withSub: true, 👈
withContent: true 👈
})
```

When moving the folder you can set the `mockedValues` to `true` to move the
files with fake names:

```typescript
import { Folder } from '@athenna/common'

const movedFolder = await folder.move(Path.storage('file-path'), {
mockedValues: true 👈
})
```

#### `Folder.remove()` & `Folder.removeSync()`

Delete a folder from the folder system:

```typescript
import { Folder } from '@athenna/common'

folder.removeSync() 👈
await folder.remove() 👈
```

#### `Folder.toJSON()`

Get the informations of the folder as JSON:

```typescript
const infos = folder.toJSON() 👈
```

#### `Folder.getFilesByPattern()`

Get all the files of a folder using a glob pattern:

```typescript
const files = folder.getFilesByPattern('**/*.js') 👈
```

#### `Folder.getFoldersByPattern()`

Get all the folders of a folder using a glob pattern:

```typescript
const folders = folder.getFoldersByPattern('**/*') 👈
```

#### `Folder::safeRemove()`

Call for a delete operation without worrying about exceptions because the folder
does not exist:

```typescript
import { Folder } from '@athenna/common'

await Folder.safeRemove(Path.storage('folder')) 👈
await Folder.safeRemove(Path.storage('not-found')) 👈 // Will not throw
```

#### `Folder::exists()` & `Folder::existsSync()`

Verify if a folder exists or not:

```typescript
if (Folder.existsSync('app')) {
// do something
}

if (await Folder.exists('app')) {
// do something
}
```

#### `Folder::isFolder()` & `Folder::isFolderSync()`

Verify if a folder is a valid folder or not:

```typescript
if (Folder.isFolderSync('app')) {
// do something
}

if (await Folder.isFolder('app')) {
// do something
}
```

#### `Folder::size()` & `Folder::sizeSync()`

Get the size of the folder in MB:

```typescript
if (Folder.sizeSync('app') === 100) {
// do something
}

if (await Folder.size('app') === 100) {
// do something
}
```
16 changes: 11 additions & 5 deletions static/css/markdown.css
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
.markdown code {
color: #ff80bf !important;
color: #ff80bf;
}

.markdown a {
color: #939300 !important;
}

a code {
color: #939300 !important;
}

.markdown a:hover {
color: #ff80bf !important;
color: #ff80bf;
}

[data-theme='dark'] .markdown a {
color: #ffff80 !important;
}

[data-theme='dark'] a code {
color: #ffff80 !important;
}

[data-theme='dark'] .markdown a:hover {
color: #ff80bf !important;
color: #ff80bf;
}

.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 {
font-weight: 800 !important;
}


0 comments on commit 5f96186

Please sign in to comment.