-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathphoneTemplates.ts
More file actions
52 lines (40 loc) · 1.68 KB
/
phoneTemplates.ts
File metadata and controls
52 lines (40 loc) · 1.68 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import path from 'path';
import fs from 'fs-extra';
import { constants } from '../../../tools';
import { existsMustBeDir, getFiles, dumpJSON, loadJSON } from '../../../utils';
import { DirectoryHandler } from '.';
import DirectoryContext from '..';
import { ParsedAsset } from '../../../types';
import { PhoneTemplate } from '../../../tools/auth0/handlers/phoneTemplates';
import { phoneTemplatesDefaults } from '../../defaults';
type ParsedPhoneTemplates = ParsedAsset<'phoneTemplates', PhoneTemplate[]>;
function parse(context: DirectoryContext): ParsedPhoneTemplates {
const phoneTemplatesFolder = path.join(context.filePath, constants.PHONE_TEMPLATES_DIRECTORY);
if (!existsMustBeDir(phoneTemplatesFolder)) return { phoneTemplates: null }; // Skip
const files = getFiles(phoneTemplatesFolder, ['.json']);
const phoneTemplates = files.map((f) =>
loadJSON(f, {
mappings: context.mappings,
disableKeywordReplacement: context.disableKeywordReplacement,
})
);
return { phoneTemplates };
}
async function dump(context: DirectoryContext): Promise<void> {
const { phoneTemplates } = context.assets;
if (!phoneTemplates) {
return;
} // Skip, nothing to dump
const phoneTemplatesFolder = path.join(context.filePath, constants.PHONE_TEMPLATES_DIRECTORY);
fs.ensureDirSync(phoneTemplatesFolder);
phoneTemplates.forEach((template) => {
const templateWithDefaults = phoneTemplatesDefaults(template);
const templateFile = path.join(phoneTemplatesFolder, `${template.type}.json`);
dumpJSON(templateFile, templateWithDefaults);
});
}
const phoneTemplatesHandler: DirectoryHandler<ParsedPhoneTemplates> = {
parse,
dump,
};
export default phoneTemplatesHandler;