-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateMessages.js
43 lines (35 loc) · 1.14 KB
/
generateMessages.js
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
import fs from "fs";
import Handlebars from "handlebars";
import { readJSON, writePlainText } from "./io.js";
const template = Handlebars.compile(
fs.readFileSync("./input/message.hbs", "utf8")
);
async function generateMessages() {
const secretSanta = readJSON({
path: "./output/secretSanta.json",
shouldDecrypt: true,
});
const messages = [];
const timestamp = new Date().toISOString();
if (!fs.existsSync(`./output/messages_${timestamp}`)) {
fs.mkdirSync(`./output/messages_${timestamp}`);
}
// Send a text message to each participant with their secret santa
for (const participant of secretSanta) {
const { name, number, buyingFor } = participant;
const message = template({ name, buyingFor });
writePlainText({
folder: `messages_${timestamp}`,
fileName: `${name}`,
data: `${name}\n${number}\n\n${message}`,
});
}
}
try {
generateMessages();
} catch (error) {
console.log(error);
console.error(
`🚨 FAILED TO GENERATE MESSAGES 🚨\nMake sure you have generated your secret santas and tested them using \`yarn generate && yarn test\` before generating your messages.`
);
}