-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathminify-and-add-emails.mjs
More file actions
27 lines (22 loc) · 991 Bytes
/
minify-and-add-emails.mjs
File metadata and controls
27 lines (22 loc) · 991 Bytes
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
import fs from 'fs';
import { minify } from 'html-minifier-terser';
const EMAIL_TEMPLATES_DIR = `${process.cwd()}/iac/quicksight-access/templates`;
const YAML_FILE = `${process.cwd()}/template.yaml`;
let yamlString = fs.readFileSync(YAML_FILE).toString('utf-8');
const emailMessages = [...yamlString.matchAll(/\s+EmailMessage: (<(.*-email)>.*).*/g)].map(
([line, placeholder, templateName]) => ({ line, placeholder, templateName }),
);
for (const { line, placeholder, templateName } of emailMessages) {
const filename = `${EMAIL_TEMPLATES_DIR}/${templateName}.html`;
const htmlString = fs.readFileSync(filename).toString('utf-8');
const minified = await minify(htmlString, {
collapseWhitespace: true,
html5: true,
minifyCSS: true,
quoteCharacter: "'",
removeComments: true,
useShortDoctype: true,
});
yamlString = yamlString.replace(line, line.replace(placeholder, `"${minified}"`));
}
fs.writeFileSync(YAML_FILE, yamlString, { encoding: 'utf-8' });