-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-certificate.js
42 lines (36 loc) · 1.14 KB
/
generate-certificate.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
const fs = require('fs')
const moment = require('moment')
const args = require('yargs').argv;
const csv = require('csv-parser');
const toCase = require('change-case')
const template = fs.readFileSync('./templates/devCSP.ejs').toString()
const { createBaseDirectory, createFile, renderTemplate } = require('./common')
moment.locale('pt');
const file = args.file
const baseDir = args.baseDir
async function createCertificate (row) {
const data = {
event: {
name: toCase.titleCase(row.eventName),
date: row.date,
hours: row.hours,
id: row.eventId
},
user: {
name: toCase.titleCase(row.userName),
email: row.email
}
}
data.event.date = moment(data.event.date).format('DD [de] MMMM [de] YYYY')
data.event.date = toCase.titleCase(data.event.date)
createFile(`${data.user.email}`, renderTemplate(template, data), baseDir).then(() => console.log(`File ${data.event.name} created`))
}
createBaseDirectory(baseDir)
fs.createReadStream(file)
.pipe(csv())
.on('data', async (row) => {
await createCertificate(row)
})
.on('end', () => {
console.log('CSV file successfully processed');
});