1
+ import { ZodError , isAbsolute , jsonc , dirname , Input } from "../../deps.ts" ;
1
2
import { DXPMConfig , DXPMConfigSchema } from "./struct.ts" ;
2
- import { ZodError , jsonc } from "../../deps .ts" ;
3
- import { elog } from "./logs .ts" ;
3
+ import { elog , wlog } from "./logs .ts" ;
4
+ import { exists } from "../../deps .ts" ;
4
5
5
6
export async function parseConfig ( path : string | undefined ) : Promise < DXPMConfig > {
6
7
let configObject : DXPMConfig | undefined ;
@@ -15,7 +16,30 @@ export async function parseConfig(path: string | undefined): Promise<DXPMConfig>
15
16
const config = jsonc . parse ( configTxt ) ;
16
17
17
18
configObject = DXPMConfigSchema . parse ( config ) ;
18
- const ids = configObject . apps . map ( ( conf ) => conf . id ) ;
19
+ const ids : string [ ] = [ ] ;
20
+
21
+ for ( const appConf of configObject . apps ) {
22
+ if ( ! appConf . cwd ) appConf . cwd = dirname ( filePath ) ;
23
+
24
+ if ( ! appConf . cwd . endsWith ( "/" ) && appConf . cwd . endsWith ( "\\" ) ) {
25
+ appConf . cwd = appConf . cwd + "/" ;
26
+ }
27
+
28
+ if ( ! isAbsolute ( appConf . script ) ) {
29
+ try {
30
+ appConf . script = await Deno
31
+ . realPath ( appConf . cwd + appConf . script ) ;
32
+ } catch { /* Ignore as it will be handled below */ }
33
+ }
34
+
35
+ if ( ! ( await exists ( appConf . script ) ) ) {
36
+ elog ( `Script file not found at '${ appConf . script } ', exiting...` ) ;
37
+ Deno . exit ( 1 ) ;
38
+ }
39
+
40
+ ids . push ( appConf . id ) ;
41
+ }
42
+
19
43
const idsSet = new Set ( ids ) ;
20
44
21
45
if ( idsSet . size !== ids . length ) {
@@ -33,6 +57,14 @@ export async function parseConfig(path: string | undefined): Promise<DXPMConfig>
33
57
}
34
58
35
59
if ( ! configObject ) {
60
+ if ( ! path ) {
61
+ const promptedPath = await Input . prompt ( "Enter path to the config file: " ) ;
62
+ if ( promptedPath ) return parseConfig ( promptedPath ) ;
63
+
64
+ wlog ( "Config file not provided." ) ;
65
+ Deno . exit ( 1 ) ;
66
+ }
67
+
36
68
elog ( "Config file not found. Exiting..." ) ;
37
69
Deno . exit ( 1 ) ;
38
70
}
0 commit comments