Skip to content

Commit

Permalink
feat: check for executable config and directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ronhippler committed Apr 11, 2020
1 parent ce46f68 commit 0005bc0
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions denon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ if (import.meta.main) {
if (!(await exists(file))) {
fail(`Could not start denon because file "${file}" does not exist`);
}
const filepath = resolve(file);
const fileInfo = await Deno.lstat(filepath);
if (fileInfo.isDirectory()) {
fail(`Could not start denon because "${file}" is a directory`);
}

config.files.push(resolve(file));
config.files.push(filepath);
}

// Remove duplicates
Expand All @@ -213,10 +218,7 @@ if (import.meta.main) {
config.watch = [...new Set(config.watch)];
debug(`Paths: ${config.watch}`);

const executors: {
[extension: string]: { [file: string]: () => void };
} = {};

const executors: (() => void)[] = [];
const execute = (...args: string[]) => {
let proc: Deno.Process | undefined;

Expand All @@ -232,26 +234,29 @@ if (import.meta.main) {
};
};

for (const extension in config.execute) {
executors[extension] = {};
const cmds = config.execute[extension];
const binary = cmds[0];

for (const file of config.files) {
if (extname(file) === extension) {
executors[extension][file] = execute(
...cmds,
...(binary === "deno" ? flags.deno_args : []),
file,
...flags.runnerFlags,
);

if (config.fullscreen) {
console.clear();
}

executors[extension][file]();
for (const file of config.files) {
const extension = extname(file);
const cmds = config.execute[extension] as string[] | undefined;

if (cmds) {
const binary = cmds[0];

const executor = execute(
...cmds,
...(binary === "deno" ? flags.deno_args : []),
file,
...flags.runnerFlags,
);

executors.push(executor);

if (config.fullscreen) {
console.clear();
}

executor();
} else {
fail(`Can not run ${file}. No config for "${extension}" found`);
}
}

Expand Down Expand Up @@ -287,12 +292,6 @@ if (import.meta.main) {
debug(`File "${change.path}" was ${change.event}`);
}

for (const extension in config.execute) {
for (const file of config.files) {
if (executors[extension][file]) {
executors[extension][file]();
}
}
}
executors.forEach((ex) => ex());
}
}

0 comments on commit 0005bc0

Please sign in to comment.