Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b50e3fa

Browse files
committedMar 27, 2024
Added Current-Working-Directory support and integrated interactive config file prompt.
1 parent 72f9a1b commit b50e3fa

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed
 

‎app.meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const getGHRawURL = (branch: string, resource: string) =>
22
`https://raw.githubusercontent.com/Techzy-Programmer/dxpm/${branch}${resource}`;
3-
const VERSION = "v0.2.5-us";
3+
const VERSION = "v0.2.6-us";
44

55
export {
66
getGHRawURL,

‎deps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * as jsonc from "https://deno.land/std@0.220.1/jsonc/mod.ts";
77
export { z, ZodError } from "https://deno.land/x/zod@v3.22.4/mod.ts";
88
export { isPortAvailable } from "https://deno.land/x/port@1.0.0/mod.ts"
99
export { EventEmitter } from "https://deno.land/x/eventemitter@1.2.4/mod.ts";
10+
export { Input } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/input.ts";
1011
export { colors } from "https://deno.land/x/cliffy@v1.0.0-rc.3/ansi/colors.ts";
1112
export { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts";
1213
export { Select } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/select.ts";

‎lib/helper/parser.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { ZodError, isAbsolute, jsonc, dirname, Input } from "../../deps.ts";
12
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";
45

56
export async function parseConfig(path: string | undefined): Promise<DXPMConfig> {
67
let configObject: DXPMConfig | undefined;
@@ -15,7 +16,30 @@ export async function parseConfig(path: string | undefined): Promise<DXPMConfig>
1516
const config = jsonc.parse(configTxt);
1617

1718
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+
1943
const idsSet = new Set(ids);
2044

2145
if (idsSet.size !== ids.length) {
@@ -33,6 +57,14 @@ export async function parseConfig(path: string | undefined): Promise<DXPMConfig>
3357
}
3458

3559
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+
3668
elog("Config file not found. Exiting...");
3769
Deno.exit(1);
3870
}

0 commit comments

Comments
 (0)
Please sign in to comment.