-
Notifications
You must be signed in to change notification settings - Fork 25
/
generate-mock.ts
48 lines (41 loc) · 1.01 KB
/
generate-mock.ts
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
44
45
46
47
48
const faker = require('faker');
const rimraf = require('rimraf');
const fs = require('fs');
const sections = [
'primary',
'promotions',
'social',
'starred',
'important',
'sent',
'drafts',
'trash'
];
const directory = __dirname + '/src/app/mocks/json';
const createEmail = () => {
return {
id: faker.random.uuid(),
from: {
email: faker.internet.email(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
},
title: faker.lorem.sentence(),
body: faker.lorem.paragraphs(),
date: faker.date.recent(),
read: faker.random.boolean()
};
};
const createEmails = (count) => {
const emails = [];
while (count > 0) {
emails.push(createEmail());
count--;
}
return JSON.stringify(emails.sort((a,b) => b.date - a.date));
}
const createSections = (section) => {
fs.writeFileSync(`${directory}/${section}.json`, createEmails(20), { flag: 'w' });
};
// delete all mock data
rimraf(`${directory}/*`, [], () => sections.forEach(createSections));