-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
410 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"singleQuote": true | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"useTabs": false, | ||
"tabWidth": 4, | ||
"printWidth": 120, | ||
"importOrderSeparation": true, | ||
"importOrder": ["<THIRD_PARTY_MODULES>", "^[./]"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
|
||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch mail merge cli", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/packages/email/docsoc-mail-merge/src/cli.ts", | ||
"cwd": "${workspaceFolder}/packages/email/docsoc-mail-merge", | ||
"outFiles": [ | ||
"${workspaceFolder}/packages/email/docsoc-mail-merge/dist/**/*.js", | ||
"${workspaceFolder}/packages/email/docsoc-mail-merge/dist/**/*.js.map" | ||
], | ||
"preLaunchTask": "nx: nx run docsoc-mail-merge:build", | ||
"sourceMaps": true, | ||
"sourceMapPathOverrides": { | ||
"../../../../../packages/email/docsoc-mail-merge/**/*": "${workspaceFolder}/dist/packages/email/docsoc-mail-merge/**/*", | ||
}, | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "nx", | ||
"project": "", | ||
"command": "run", | ||
"positional": "docsoc-mail-merge:build", | ||
"flags": [], | ||
"problemMatcher": [], | ||
"label": "nx: nx run docsoc-mail-merge:build" | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Mailer from "./mailer/mailer"; | ||
import createLogger from "./util/logger"; | ||
|
||
import { promises as fs } from "fs"; | ||
import nunjucks from "nunjucks"; | ||
import markdownit from "markdown-it"; | ||
|
||
import "dotenv/config"; // load .env | ||
import { join } from "path"; | ||
import { renderMarkdownTemplate, renderMarkdownToHtml } from "./markdown/template"; | ||
import { parse } from "csv-parse"; | ||
import { defaultMailer, getDefaultMailer } from "./mailer/defaultMailer"; | ||
|
||
const logger = createLogger("docsoc"); | ||
|
||
async function main() { | ||
logger.info("Starting DoCSoc Mail Merge"); | ||
logger.info("Loading template..."); | ||
|
||
const template = await fs.readFile(join(__dirname, "../templates/TEMPLATE.md.njk"), "utf-8"); | ||
const csv = await fs.readFile(join(__dirname, "../data/names.csv"), "utf-8"); | ||
const templateCompiled = nunjucks.compile( | ||
template, | ||
nunjucks.configure({ | ||
throwOnUndefined: true, | ||
}), | ||
); | ||
const htmlWrapper = await fs.readFile(join(__dirname, "../templates/wrapper.html.njk"), "utf-8"); | ||
const htmlWrapperCompiled = nunjucks.compile(htmlWrapper, nunjucks.configure({ autoescape: false })); | ||
const mailer = getDefaultMailer(); | ||
// read the params from the nunjucks template | ||
|
||
const csvData = parse(csv, { columns: true }); | ||
for await (const record of csvData) { | ||
const expanded = renderMarkdownTemplate(templateCompiled, { | ||
name: record["name"], | ||
}); | ||
const html = renderMarkdownToHtml(expanded); | ||
|
||
// wrap the html in the wrapper | ||
const wrapped = htmlWrapperCompiled.render({ content: html }); | ||
|
||
console.log(wrapped); | ||
|
||
await defaultMailer([record["email"]], "DoCSoc Mail Merge Test", wrapped, mailer); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,44 @@ | ||
import Mailer from './mailer/mailer'; | ||
import createLogger from './util/logger'; | ||
|
||
import { promises as fs } from 'fs'; | ||
import nunjucks from 'nunjucks'; | ||
import markdownit from 'markdown-it'; | ||
|
||
import 'dotenv/config'; // load .env | ||
import { join } from "path"; | ||
import { renderMarkdownTemplate, renderMarkdownToHtml } from "./markdown/template"; | ||
import { parse } from "csv-parse"; | ||
import { defaultMailer, getDefaultMailer } from "./mailer/defaultMailer"; | ||
|
||
const logger = createLogger('docsoc'); | ||
|
||
|
||
async function main() { | ||
logger.info('Starting DoCSoc Mail Merge'); | ||
logger.info("Loading template...") | ||
|
||
const template = await fs.readFile(join(__dirname, '../templates/TEMPLATE.md.njk'), 'utf-8'); | ||
const csv = await fs.readFile(join(__dirname, '../data/names.csv'), 'utf-8'); | ||
const templateCompiled = nunjucks.compile(template, nunjucks.configure({ | ||
throwOnUndefined: true, | ||
})); | ||
const htmlWrapper = await fs.readFile(join(__dirname, '../templates/wrapper.html.njk'), 'utf-8'); | ||
const htmlWrapperCompiled = nunjucks.compile(htmlWrapper, nunjucks.configure({autoescape: false})); | ||
const mailer = getDefaultMailer(); | ||
// read the params from the nunjucks template | ||
|
||
const csvData = parse(csv, {columns: true}); | ||
for await (const record of csvData) { | ||
|
||
const expanded = renderMarkdownTemplate(templateCompiled, { | ||
name: record["name"] | ||
}) | ||
const html = renderMarkdownToHtml(expanded); | ||
|
||
// wrap the html in the wrapper | ||
const wrapped = htmlWrapperCompiled.render({content: html}); | ||
|
||
console.log(wrapped) | ||
|
||
await defaultMailer([record["email"]], "DoCSoc Mail Merge Test", wrapped, mailer); | ||
} | ||
import "dotenv/config"; | ||
import { promises as fs } from "fs"; | ||
import markdownit from "markdown-it"; | ||
import nunjucks from "nunjucks"; | ||
// load .env | ||
import { join } from "path"; | ||
|
||
import packageJSON from "../package.json"; | ||
import createLogger from "./util/logger"; | ||
import { CliOptions } from "./util/types"; | ||
import { stopIfCriticalFsError } from "./util/files"; | ||
|
||
const logger = createLogger("docsoc"); | ||
|
||
const opts: CliOptions = { | ||
csvFile: "./data/names.csv", | ||
}; | ||
|
||
async function main(opts: CliOptions) { | ||
logger.info("DoCSoc Mail Merge"); | ||
logger.info(`v${packageJSON.version}`); | ||
|
||
// 1: Load the CSV | ||
logger.info("Loading CSV..."); | ||
const csvRaw = await stopIfCriticalFsError(fs.readFile(join(__dirname, "../data/names.csv"), "utf-8")); | ||
logger.debug("Parsing & loading CSV..."); | ||
const csvParsed = parse(csvRaw, { columns: true }); | ||
const records = []; | ||
for await (const record of csvParsed) { | ||
records.push(record); | ||
} | ||
logger.info(`Loaded ${records.length} records`); | ||
|
||
// 3: Grab fields | ||
if (records.length === 0) { | ||
logger.error("No records found in CSV"); | ||
throw new Error("No records found in CSV"); | ||
} | ||
const fields = Object.keys(records[0]); | ||
logger.info(`Fields: ${fields.join(", ")}`); | ||
} | ||
|
||
main(); | ||
main(opts); |
Oops, something went wrong.