forked from bdevos/rss-to-email
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.js
39 lines (28 loc) · 961 Bytes
/
email.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
import { existsSync, mkdirSync, writeFileSync } from 'fs'
import { createServer as createViteServer } from 'vite'
const outputDir = './dist'
const getFromArgv = (key) => process.argv.find((arg) => arg.startsWith(`${key}=`))?.replaceAll(`${key}=`, '')
async function createEmail() {
const vite = await createViteServer({
appType: 'custom',
})
const actionUrl = getFromArgv('actionUrl')
const lastSuccess = getFromArgv('lastSuccess')
try {
const { renderEmail } = await vite.ssrLoadModule('/src/renderEmail.tsx')
const { html, itemCount } = await renderEmail({ actionUrl, lastSuccess })
if (itemCount === 0) {
console.log('No new items in feed, skipping email')
process.exit(0)
}
if (!existsSync(outputDir)) {
mkdirSync(outputDir)
}
writeFileSync(`${outputDir}/email.html`, html, { flag: 'w' })
process.exit(0)
} catch (e) {
console.error(e)
process.exit(1)
}
}
createEmail()