Skip to content

Commit

Permalink
feat: Add toContract to File and Folder class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Nov 30, 2021
1 parent 978bcab commit 3109420
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secjs/utils",
"version": "1.4.8",
"version": "1.4.9",
"description": "",
"license": "MIT",
"author": "João Lenon",
Expand All @@ -18,7 +18,7 @@
"nodejs"
],
"devDependencies": {
"@secjs/contracts": "1.1.7",
"@secjs/contracts": "1.1.8",
"@secjs/exceptions": "1.0.4",
"@secjs/logger": "1.2.2",
"@types/debug": "4.1.5",
Expand Down
8 changes: 8 additions & 0 deletions src/Classes/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { lookup } from 'mime-types'
import { randomBytes } from 'crypto'
import { parse, isAbsolute } from 'path'
import { InternalServerException } from '@secjs/exceptions'
import { FileContract } from '@secjs/contracts'

export interface FileJsonContract {
dir: string
Expand Down Expand Up @@ -98,6 +99,13 @@ export class File {
)
}

toContract(): FileContract {
return {
path: this.path,
value: this.getContentSync(),
}
}

toJSON(): FileJsonContract {
return JSON.parse(
JSON.stringify({
Expand Down
9 changes: 9 additions & 0 deletions src/Classes/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Parser } from './Parser'
import { randomBytes } from 'crypto'
import { isAbsolute, join, parse, resolve } from 'path'
import { InternalServerException } from '@secjs/exceptions'
import { DirectoryContract } from '@secjs/contracts'

export interface FolderJsonContract {
dir: string
Expand Down Expand Up @@ -75,6 +76,14 @@ export class Folder {
this.createFolderValues(mockedValues)
}

toContract(): DirectoryContract {
return {
path: this.path,
files: this.files.map(file => file.toContract()),
folders: this.folders.map(folder => folder.toContract()),
}
}

toJSON(): FolderJsonContract {
return JSON.parse(
JSON.stringify({
Expand Down
4 changes: 4 additions & 0 deletions src/utils/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { unset as unsetFn } from '../Functions/unset'
import { Path as PathInstance } from '../Classes/Path'
import { DirectoryContract, FileContract } from '@secjs/contracts'
import { File as FileInstance, FileJsonContract } from '../Classes/File'
import { Folder as FolderInstance, FolderJsonContract } from '../Classes/Folder'

Expand Down Expand Up @@ -69,6 +70,7 @@ declare global {
isCopy?: boolean,
)

toContract(): FileContract
toJSON(): FileJsonContract
createSync(): File
create(): Promise<File>
Expand Down Expand Up @@ -199,6 +201,8 @@ declare global {
* @param isCopy Default is false
*/
constructor(folderPath: string, mockedValues?: boolean, isCopy?: boolean)

toContract(): DirectoryContract
toJSON(): FolderJsonContract
createSync(): Folder
create(): Promise<Folder>
Expand Down

0 comments on commit 3109420

Please sign in to comment.