aboutsummaryrefslogtreecommitdiff
path: root/src/files.ts
blob: 644d24e3421a4dc78f131a23514b78fe5a842cc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as fs from 'fs';

const CONTENT_BASE_DIRECTORY: string = './files';
const LOG_BASE_DIRECTORY: string = './logs';

const path: (filename: string, projectName: string) => string
	= (filename: string, projectName: string): string => {
	return `${CONTENT_BASE_DIRECTORY}/${projectName}/${filename}`;
};

const writableStream:
	(filename: string, projectName: string) => fs.WriteStream =
	(filename: string, projectName: string): fs.WriteStream => {
	return fs.createWriteStream(path(filename, projectName));
};

const logPath:
(type: string, projectName?: string) => string = (
	type: string, projectName?: string
): string => {
	return projectName
		? `${LOG_BASE_DIRECTORY}/projects/${projectName}/${type}`
		: `${LOG_BASE_DIRECTORY}/general/${type}`;
};

export const files: {
	path: (f: string, p: string) => string;
	writableStream: (f: string, p: string) => fs.WriteStream;
	logPath: (t: string, p?: string) => string;
} = {
	path,
	writableStream,
	logPath
};