Skip to content

Commit c319d40

Browse files
committed
Feat: Name flag for runs
1 parent c39eea7 commit c319d40

10 files changed

Lines changed: 160 additions & 28 deletions

File tree

email/libmailmerge/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"@azure/identity": "^4.4.1",
66
"@docsoc/util": "^0.1.0",
77
"@microsoft/microsoft-graph-client": "^3.0.7",
8+
"chalk": "^5.3.0",
89
"cli-progress": "^3.12.0",
910
"email-validator": "^2.0.4",
1011
"html-to-text": "^9.0.5",
1112
"markdown-it": "^14.1.0",
1213
"nodemailer": "^6.9.14",
1314
"nunjucks": "^3.2.4",
15+
"readline-sync": "^1.4.10",
1416
"tslib": "^2.3.0"
1517
},
1618
"scripts": {

email/mailmerge-cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ I recommend placing attachments in an `attachments` folder.
4141

4242
This library was generated with [Nx](https://nx.dev).
4343

44+
### Uploading to drafts
45+
46+
You can also upload the emails to drafts instead of sending them. To do this, run `docsoc-mailmerge upload-drafts ./output/<runname> `. This will upload the emails to drafts instead of sending them.
47+
4448
## Building
4549

4650
Run `nx build mailmerge-cli` to build the library.

email/mailmerge-cli/src/commands/generate/nunjucks.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export default class GenerateNunjucks extends Command {
5252
description:
5353
"Enable BCC mapping from CSV - column values must be a space separate list",
5454
}),
55+
name: Flags.string({
56+
char: "n",
57+
description: "Name of the run, created as a subdirectory in the output directory",
58+
}),
5559
};
5660

5761
public async run(): Promise<void> {
@@ -73,6 +77,7 @@ export default class GenerateNunjucks extends Command {
7377
enableBCC: flags.bcc,
7478
enableCC: flags.cc,
7579
},
80+
name: flags.name,
7681
};
7782
await generatePreviews(options);
7883
}

email/mailmerge-cli/src/common/generate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ export interface CliOptions {
4242
enableCC?: boolean;
4343
enableBCC?: boolean;
4444
};
45+
/** Run name, created as subdir under output */
46+
name?: string;
4547
}
4648

4749
// TODO: Put somewhere nice
4850
const ADDITIONAL_FIELDS = [CSV_DEFAULT_FIELD_NAMES.to, CSV_DEFAULT_FIELD_NAMES.subject];
4951

5052
export default async function generatePreviews(opts: CliOptions) {
5153
// 0: What to call this run?
52-
const runName = await getRunNameInteractively();
54+
const runName = opts.name ?? (await getRunNameInteractively());
5355

5456
// Workspace root
5557
const workspaceRoot = process.cwd();

email/mailmerge-cli/src/common/upload-drafts.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { EmailUploader, ENGINES_MAP } from "@docsoc/libmailmerge";
22
import { loadPreviewsFromSidecar, loadSidecars, EmailString } from "@docsoc/libmailmerge";
33
import { createLogger } from "@docsoc/util";
4+
import chalk from "chalk";
45
// Load dotenv
56
import "dotenv/config";
67
import { join } from "path";
8+
import readlineSync from "readline-sync";
79

810
const logger = createLogger("docsoc");
911

@@ -58,33 +60,32 @@ export async function uploadDrafts(directory: string) {
5860
}
5961

6062
// Print the warning
61-
// TODO: Move sent emails elsewhere
62-
// console.log(
63-
// chalk.yellow(`⚠️ --- WARNING --- ⚠️
64-
// You are about to upload ${pendingEmails.length} emails.
65-
// This action is IRREVERSIBLE.
66-
67-
// If the system crashes, you will need to manually upload the emails.
68-
// Re-running this after a partial upload will end up uploading duplicate emails.
69-
// Unlike with send, emails will not be moved to a different folder after upload.
70-
71-
// Check that:
72-
// 1. The template was correct
73-
// 1. You are satisfied with ALL previews, including the HTML previews
74-
// 3. You have tested the system beforehand
75-
// 4. All indications this is a test have been removed
76-
77-
// You are about to upload ${pendingEmails.length} emails. The esitmated time for this is ${
78-
// (20 * pendingEmails.length) / 60 / 60
79-
// } hours.
80-
81-
// If you are happy to proceed, please type "Yes, upload emails" below.`),
82-
// );
83-
84-
// const input = readlineSync.question("");
85-
// if (input !== "Yes, upload emails") {
86-
// process.exit(0);
87-
// }
63+
console.log(
64+
chalk.yellow(`⚠️ --- WARNING --- ⚠️
65+
You are about to upload ${pendingEmails.length} emails.
66+
This action is IRREVERSIBLE.
67+
68+
If the system crashes, you will need to manually upload the emails.
69+
Re-running this after a partial upload will end up uploading duplicate emails.
70+
Unlike with send, emails will not be moved to a different folder after upload.
71+
72+
Check that:
73+
1. The template was correct
74+
1. You are satisfied with ALL previews, including the HTML previews
75+
3. You have tested the system beforehand
76+
4. All indications this is a test have been removed
77+
78+
You are about to upload ${pendingEmails.length} emails. The esitmated time for this is ${
79+
(20 * pendingEmails.length) / 60 / 60
80+
} hours.
81+
82+
If you are happy to proceed, please type "Yes, upload emails" below.`),
83+
);
84+
85+
const input = readlineSync.question("");
86+
if (input !== "Yes, upload emails") {
87+
process.exit(0);
88+
}
8889

8990
// Send the emails
9091
logger.info("Uploading emails...");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "Kishan",
3+
"record": {
4+
"name": "Kishan",
5+
"email": "kss22@ic.ac.uk kishansambhi@hotmail.co.uk",
6+
"subject": "DoCSoc x Kishan",
7+
"attachment1": "./attachments/DoCSoc Sponsorship Proposal 24-25.pdf",
8+
"attachment2": "./attachments/munch.jpg",
9+
"bcc": "kishansambhi@hotmail.co.uk",
10+
"cc": "jaskishansaran@gmail.com kishansambhi@outlook.com"
11+
},
12+
"engine": "nunjucks",
13+
"engineOptions": {
14+
"templatePath": "templates/template.md.njk",
15+
"rootHtmlTemplate": "templates/wrapper.html.njk"
16+
},
17+
"files": [
18+
{
19+
"filename": "Kishan__nunjucks__Preview-Markdown.md",
20+
"engineData": {
21+
"name": "Preview-Markdown.md",
22+
"metadata": {
23+
"type": "markdown"
24+
}
25+
}
26+
},
27+
{
28+
"filename": "Kishan__nunjucks__Preview-HTML.html",
29+
"engineData": {
30+
"name": "Preview-HTML.html",
31+
"metadata": {
32+
"type": "html"
33+
}
34+
}
35+
}
36+
],
37+
"email": {
38+
"to": [
39+
"kss22@ic.ac.uk",
40+
"kishansambhi@hotmail.co.uk"
41+
],
42+
"cc": [
43+
"jaskishansaran@gmail.com",
44+
"kishansambhi@outlook.com"
45+
],
46+
"bcc": [
47+
"kishansambhi@hotmail.co.uk"
48+
],
49+
"subject": "DoCSoc x Kishan"
50+
},
51+
"attachments": [
52+
"./attachments/DoCSoc Sponsorship Proposal 24-25.pdf",
53+
"./attachments/munch.jpg"
54+
],
55+
"$originalFilepath": "output/test/Kishan-metadata.json"
56+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- DoCSoc Mail Merge Wrapper - used to wrap results rendered from Markdown -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
</head>
8+
<body>
9+
<p>Dear Kishan,</p>
10+
<p>I hope you are well.</p>
11+
<p>If you are seeing this email, it means that the new mail merge tool is working as expected.</p>
12+
<p>For it was this email you see, that was sent by complete mail merge pipeline.</p>
13+
<p>Of course, some things are still missing, namely:</p>
14+
<ul>
15+
<li>Attachments</li>
16+
<li>Crash-proofing so you don't double send emails</li>
17+
<li>A nice CLI</li>
18+
<li>Docs</li>
19+
</ul>
20+
<p>But it does work!</p>
21+
<p>Kind regards,<br>
22+
Some TypeScript code on behalf of Kishan Sambhi (he/him)<br>
23+
DoCSoc Vice President</p>
24+
25+
</body>
26+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Dear Kishan,
2+
3+
I hope you are well.
4+
5+
If you are seeing this email, it means that the new mail merge tool is working as expected.
6+
7+
For it was this email you see, that was sent by complete mail merge pipeline.
8+
9+
Of course, some things are still missing, namely:
10+
- Attachments
11+
- Crash-proofing so you don't double send emails
12+
- A nice CLI
13+
- Docs
14+
15+
But it does work!
16+
17+
Kind regards,
18+
Some TypeScript code on behalf of Kishan Sambhi (he/him)
19+
DoCSoc Vice President

email/workspace/quick-run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docsoc-mailmerge generate nunjucks ./data/names.csv -o ./output -n test -b -c
2+
docsoc-mailmerge regenerate ./output/test
3+
docsoc-mailmerge upload-drafts ./output/test
4+
docsoc-mailmerge send ./output/test

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)