-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (20 loc) · 856 Bytes
/
Copy pathindex.js
File metadata and controls
28 lines (20 loc) · 856 Bytes
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
import * as dotenv from 'dotenv';
import RequestManager from "./src/RequestManager.js";
import fs from "fs";
dotenv.config();
const cachePath = './cache.json'
let projectsWithTasks = []
if (process.argv.includes('--use-cache') && fs.existsSync(cachePath)) {
console.log('load data projects from cache')
projectsWithTasks = JSON.parse(fs.readFileSync(cachePath).toString())
} else {
console.log('load projects from api')
const requestManager = new RequestManager()
const projects = await requestManager.request('/open/v1/project')
for (const p of projects) {
console.log(`load project data for: ${p.name}`)
projectsWithTasks.push(await requestManager.request(`/open/v1/project/${p.id}/data`))
}
fs.writeFileSync(cachePath, JSON.stringify(projectsWithTasks))
}
fs.writeFileSync('data.json', JSON.stringify(projectsWithTasks))