File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { readYaml , writeYaml } from "@oh /yaml" ;
1+ import { readYaml , writeYaml } from ". /yaml.ts " ;
22import type { ConfigProps } from "../types/config.types.ts" ;
33
44export const getConfig = async < ConfigTypes extends { } > ( {
@@ -8,6 +8,7 @@ export const getConfig = async <ConfigTypes extends {}>({
88} : ConfigProps < ConfigTypes > ) : Promise < ConfigTypes > => {
99 let config : ConfigTypes = { } as ConfigTypes ;
1010 try {
11+ //@ts -ignore
1112 config = await readYaml < ConfigTypes > ( `./${ fileName } ` ) ;
1213 } catch ( e ) { }
1314
Original file line number Diff line number Diff line change 11import { parse , stringify } from "@std/yaml" ;
22import { createDirectoryIfNotExists } from "../utils/directory.utils.ts" ;
3+ import { getModulePath } from "../utils/path.utils.ts" ;
34
45export type ReadProps = {
56 decode ?: boolean ;
@@ -16,7 +17,7 @@ export const readYaml = async <T extends unknown>(
1617 filePath : string ,
1718 { decode = false } : ReadProps = { decode : false } ,
1819) : Promise < T | unknown > => {
19- let content = await Deno . readTextFile ( filePath ) ;
20+ let content = await Deno . readTextFile ( getModulePath ( filePath ) ) ;
2021 if ( decode )
2122 content = decoder . decode ( new Uint8Array ( content . split ( "," ) . map ( Number ) ) ) ;
2223 return parse ( content ) ;
@@ -29,11 +30,12 @@ export const writeYaml = async <T extends any>(
2930 encode : false ,
3031 } ,
3132) : Promise < void > => {
32- await createDirectoryIfNotExists ( filePath ) ;
33+ await createDirectoryIfNotExists ( getModulePath ( filePath ) ) ;
3334
3435 let content = stringify ( data ) ;
3536 //@ts -ignore
3637 if ( encode ) content = encoder . encode ( content ) ;
3738
38- await Deno . writeTextFile ( filePath , content ) ;
39+ console . log ( getModulePath ( filePath ) , content ) ;
40+ await Deno . writeTextFile ( getModulePath ( filePath ) , content ) ;
3941} ;
Original file line number Diff line number Diff line change @@ -2,3 +2,15 @@ import * as path from "@std/path";
22
33export const getExecPath = ( ) : string => Deno . execPath ( ) ;
44export const getPath = ( ) : string => path . dirname ( getExecPath ( ) ) ;
5+
6+ const __dirname = path . dirname ( path . fromFileUrl ( import . meta. url ) ) ;
7+
8+ export const getLocalPath = ( filePath : string ) : string => {
9+ if ( filePath . startsWith ( "/" ) || / ^ [ A - Z a - z ] : \\ / . test ( filePath ) ) {
10+ return filePath ; // already absolute
11+ }
12+ return path . join ( __dirname , filePath ) ;
13+ } ;
14+
15+ export const getModulePath = ( filePath : string ) : string =>
16+ path . join ( path . dirname ( path . fromFileUrl ( Deno . mainModule ) ) , filePath ) ;
You can’t perform that action at this time.
0 commit comments