-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.ts
22 lines (18 loc) · 793 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { join } from 'path'
import { readdirSync } from 'fs'
export function getDirectoriesNames(directory: string) {
return readdirSync(directory, { withFileTypes: true })
.filter(dir => dir.isDirectory()).map(({ name }) => name)
}
export function getFilePathByType(directory: string, type: string) {
const file = readdirSync(directory, { withFileTypes: true }).filter(file => {
return file.isFile() && file.name.endsWith(type)
}).map(({ name }) => name)
return `${directory}/${file}`
}
export function getEmailJSON(category: string, template: string) {
return require(getFilePathByType(join(__dirname, 'templates', category, template), '.json'));
}
export function getAllTemplatesAsJSON() {
return require(getFilePathByType(join(__dirname, 'templates'), '.json'));
}