forked from adamlaska/circleci-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (51 loc) · 1.83 KB
/
index.js
File metadata and controls
63 lines (51 loc) · 1.83 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import ObjectsToCsv from 'objects-to-csv'
import fs from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { snippetTracking } from './runSnippetTracking.js'
import { articleTracking } from './runArticleTracking.js'
export const log = (message) => {
// eslint-disable-next-line no-console
console.log('=>', message);
};
const runSnippetTracking = async () => {
// first we remove the ouput file to clear it
if (fs.existsSync(`${__dirname}/snippetsTracking.csv`)) {
fs.unlinkSync(`${__dirname}/snippetsTracking.csv`);
}
// get the data
const data = await snippetTracking();
log(`Found ${data.length} snippets`);
// write the data to the output CSV file in chuncks of 500
// this is done to prevent writing to much data which can cause issues
// with the CSV library
while (data.length > 0) {
const csv = new ObjectsToCsv(data.splice(0, 500));
csv.toDisk('./snippetsTracking.csv', { append: true });
}
}
const runArticleTracking = async () => {
// first we remove the ouput file to clear it
if (fs.existsSync(`${__dirname}/articleTracking.csv`)) {
fs.unlinkSync(`${__dirname}/articleTracking.csv`);
}
// get the data
const data = await articleTracking();
log(`Found ${data.length} snippets`);
// write the data to the output CSV file in chuncks of 500
// this is done to prevent writing to much data which can cause issues
// with the CSV library
while (data.length > 0) {
const csv = new ObjectsToCsv(data.splice(0, 500));
csv.toDisk('./articleTracking.csv', { append: true });
}
}
const start = async () => {
// commented out to save on runtime
// await runSnippetTracking();
await runArticleTracking();
log('Done');
};
start();