From da5474da0ee6f22bbd039031cf0e4853f49cef0e Mon Sep 17 00:00:00 2001 From: TeoDev1611 Date: Sat, 20 Aug 2022 20:38:58 -0500 Subject: [PATCH] release(v0.1.0): first release docs and some info --- .vscode/settings.json | 3 ++ 2 | 120 ------------------------------------------ README.md | 44 ++++++++++++++-- deno.json | 2 +- dpm.json | 5 +- eggs.json | 13 ++--- examples.ts | 15 ------ examples/basic.ts | 26 +++++++++ 8 files changed, 81 insertions(+), 147 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 2 delete mode 100644 examples.ts create mode 100644 examples/basic.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cbac569 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} diff --git a/2 b/2 deleted file mode 100644 index a84a6d2..0000000 --- a/2 +++ /dev/null @@ -1,120 +0,0 @@ -import { basename, extname, join } from 'path/mod.ts'; -import { BenoSetTypes, BenoTypes } from './src/parsers/types.d.ts'; -import { benoMagicReader, benoOneFile } from './src/parsers/reader.ts'; -import { Validate } from './src/validator.ts'; - -// Methods for Parsers -interface BenoCfgFunctions { - config(path?: string, env?: string): void; - get(key: string): unknown | undefined; - content(): Record[] | undefined; - set(filename: string, object: BenoSetTypes): boolean; - has(filename: string, key:string): boolean; -} - -export class Beno implements BenoCfgFunctions { - version = '0.1.0'; - - constructor(private props: BenoTypes) { - this.props.path = join(Deno.cwd(), 'config'); - this.props.envPath = join(Deno.cwd(), '.env'); - } - - config(path?: string | undefined, env?: string | undefined): void { - /** Make a validation */ - - // Helpers for the Params - let cfg, envPath; - - // Add the - if (path == undefined) { - cfg = join(Deno.cwd(), 'config'); - } else { - cfg = path; - } - - if (env == undefined) { - envPath = join(Deno.cwd(), '.env'); - } else { - envPath = env; - } - - this.props.path = cfg!; - this.props.envPath = envPath!; - } - - content(): Record[] | undefined { - const path: string[] = []; - for (const e of Deno.readDirSync(this.props.path!)) { - if (e.isFile && extname(e.name).substring(1) == this.props.encoder) { - path.push(join(this.props.path!, e.name)); - } - } - return benoMagicReader(path, this.props.encoder); - } - - get(key: string): Validate { - const content = this.content(); - - if (content == undefined) { - throw new Error( - 'Beno ERROR: Not defined the content not found a valid file in the directory or not found the directory', - ); - } - const target = content.find((i) => key in i); - return new Validate((target ?? {})[key]); - } - - set(filename: string, object: BenoSetTypes): boolean { - const content = this.content(); - - if (content == undefined) { - throw new Error( - 'Beno ERROR: Not defined the content not found a valid file in the directory or not found the directory', - ); - } - - content.map((e) => { - if (extname(filename) != '') { - filename = filename.replace(`.${this.props.encoder}`, ''); - } - if (typeof e.BENO_INTERNALS_FILEPATH == 'string') { - if ( - filename == - basename(e.BENO_INTERNALS_FILEPATH).replace( - `.${this.props.encoder}`, - '', - ) - ) { - const obj = benoOneFile( - e.BENO_INTERNALS_FILEPATH, - this.props.encoder, - ); - - obj[object.key] = object.val; - - try { - Deno.writeTextFileSync( - e.BENO_INTERNALS_FILEPATH, - JSON.stringify(obj, null, 2), - ); - } catch (e) { - throw new Error( - `Beno ERROR: Is not possible write the file error.\n${e}`, - ); - } - return true; - } - } else { - throw new Error( - `Beno ERROR: Not valid internal path please report this on github maybe a Bug`, - ); - } - }); - - return false; - } - - has(filename: string, key: string): boolean { -} -} diff --git a/README.md b/README.md index 8edbc33..56234dd 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,50 @@ --- -Dont make your config experience bad only disfrute with this +Do you want to manage the settings of your apps? Make it easy with the help of +Beno + +## What is this? + +Well I need manage some config files for DPM and for make this a easy experience +and make more `type-safe` i wrote this is a way for read files from a dir using +an many encoders :sunglasses: + +## Usage: + +```ts +import { Beno } from 'https://deno.land/x/beno/mod.ts'; + +// Exists many options for this for example the json encoder or can create the encoder with jsonc prop +const beno = new Beno({ encoder: 'json' }); + +// Set a new key on the file +beno.set('filename.json', { key: 'beno', val: 'is awesome' }); + +// Get the value from a key in a filename +// This value can return string, boolean, or number +console.log(beno.get('beno').string()); + +// Check if a key exists: +beno.has('beno'); // -> Returns true +beno.has('notExists'); // Returns false + +// Advanced functions + +// Get the content in a Record[] +console.log(beno.content()); + +// For configure some values you can use this function bellow the beno instance +beno.config( + `${Deno.cwd()}/newPath/forFolderConfig`, + `${Deno.cwd()}/custom-path/to/.envFile`, // Working in the implementation for this +); +``` ## Why this name? :notes: -Simple I dont know a name for this project but I am listening Bad Bunny and why -not call this **Beno** +I didn't have a name for this project but I was listening to Bad Bunny and I'm +thinking why not call this project **Beno**. ## Information :book: diff --git a/deno.json b/deno.json index f036941..9b51868 100644 --- a/deno.json +++ b/deno.json @@ -11,7 +11,7 @@ "tasks": { "test": "deno test -A --unstable", "fmt": "deno fmt -c deno.json", - "fmt:check": "deno fmt -c deno.json --check && deno lint -c deno.json", + "fmt:check": "deno fmt -c deno.jsonc --check && deno lint -c deno.json", "lint": "deno lint -c deno.json" } } diff --git a/dpm.json b/dpm.json index a531465..bb4a0bc 100644 --- a/dpm.json +++ b/dpm.json @@ -2,14 +2,15 @@ "$schema": "https://dpmland.deno.dev/schema", "name": "bad-cfg", "version": "0.1.0", - "description": "Dont make your config experience bad only disfrute with this", + "description": "Do you want to manage the settings of your apps? Make it easy with the help of Beno", "author": "The DPM Authors Team", "license": "MIT", "main": "mod.ts", "scripts": { "test": "deno test -A --unstable", "fmt": "deno fmt -c deno.json", - "lint": "deno lint -c deno.json" + "lint": "deno lint -c deno.json", + "fmt:check": "deno fmt -c deno.jsonc --check && deno lint -c deno.json" }, "dependencies": { "path/": "0.152.0", diff --git a/eggs.json b/eggs.json index eee8522..370b733 100644 --- a/eggs.json +++ b/eggs.json @@ -1,11 +1,12 @@ { - "name": "bad-cfg", + "$schema": "https://x.nest.land/eggs@0.3.10/src/schema.json", + "name": "beno", "entry": "mod.ts", - "description": "Dont make your config experience bad only disfrute with this", - "homepage": "https://github.com/the_name/bad-cfg", - "unstable": true, + "description": "Do you want to manage the settings of your apps? Make it easy with the help of Beno", + "homepage": "https://github.com/dpmland/beno", + "unstable": false, "unlisted": false, - "releaseType": "patch", + "releaseType": "major", "files": [ "./mod.ts", "./src/**/*", @@ -15,6 +16,6 @@ ".git" ], "checkFormat": "deno task fmt:check", - "checkInstallation": "deno test", + "checkInstallation": true, "check": false } diff --git a/examples.ts b/examples.ts deleted file mode 100644 index e787f67..0000000 --- a/examples.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Beno } from './mod.ts'; - -const beno = new Beno({ encoder: 'json' }); -/* console.log(beno.get('example').string()); -console.log(beno.get('to').number()); -console.log(beno.get('yes').boolean()); */ -// beno.set('other', { key: 'helloo', val: 'benooooooooo' }); -// beno.set('hello.json', { key: 'bye', val: 'chauuuuuuuu' }); - -console.log(beno.has('helloo')); -console.log(beno.has('notexistidkmaybeyes')); - -/* const JSONC = new Beno({encoder: 'jsonc'}) -console.log(JSONC.content()) -console.log(JSONC.get('hello').string()) */ diff --git a/examples/basic.ts b/examples/basic.ts new file mode 100644 index 0000000..3ab63fa --- /dev/null +++ b/examples/basic.ts @@ -0,0 +1,26 @@ +import { Beno } from '../mod.ts'; + +// Exists many options for this for example the json encoder or can create the encoder with jsonc prop +const beno = new Beno({ encoder: 'json' }); + +// Set a new key on the file +beno.set('filename.json', { key: 'beno', val: 'is awesome' }); + +// Get the value from a key in a filename +// This value can return string, boolean, or number +console.log(beno.get('beno').string()); + +// Check if a key exists: +beno.has('beno'); // -> Returns true +beno.has('notExists'); // Returns false + +// Advanced functions + +// Get the content in a Record[] +console.log(beno.content()); + +// For configure some values you can use this function bellow the beno instance +beno.config( + `${Deno.cwd()}/newPath/forFolderConfig`, + `${Deno.cwd()}/custom-path/to/.envFile`, +);