Skip to content

Commit 8fa9f22

Browse files
committed
[index] Create dist directory when it doesn't exist
1 parent 2c55f4f commit 8fa9f22

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import * as _credits from './credits.js'
66

77
import * as generate from './src/generate.ts'
88

9+
const exists = async (filename: string): Promise<boolean> => {
10+
try {
11+
await Deno.stat(filename);
12+
// successful, file or directory must exist
13+
return true;
14+
} catch (error) {
15+
if (error instanceof Deno.errors.NotFound) {
16+
// file or directory does not exist
17+
return false;
18+
} else {
19+
// unexpected error, maybe permissions, pass it along
20+
throw error;
21+
}
22+
}
23+
};
24+
925
let decoder = new TextDecoder('utf-8')
1026
export const config: IConfig = {
1127
imagePath: path.resolve('./img/'),
@@ -21,6 +37,10 @@ for (let item of Deno.readDirSync(path.resolve('./')))
2137
{
2238
console.log(`- ${item.name}` + (item.isDirectory ? ' (directory)' : ''))
2339
}
40+
if (!exists(config.distPath))
41+
{
42+
Deno.mkdirSync(config.distPath);
43+
}
2444
console.log(`Reading all files in ${config.distPath}`);
2545
for (let item of Deno.readDirSync(config.distPath))
2646
{

0 commit comments

Comments
 (0)