-
Notifications
You must be signed in to change notification settings - Fork 43
/
sync.js
55 lines (45 loc) · 1.14 KB
/
sync.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
import {
copyFileSync,
writeFileSync
} from 'node:fs'
import { getJson } from './src/utils/retrieve.js'
import { simplify } from './src/utils/provider.js'
const source = 'https://oembed.com/providers.json'
const latest = './src/utils/providers.latest.js'
const prev = './src/utils/providers.prev.js'
const orginal = './src/utils/providers.orginal.json'
const saveOriginal = (data, file) => {
writeFileSync(
file,
JSON.stringify(data, undefined, 2),
'utf8'
)
}
const sync = async () => {
try {
const result = await getJson(source)
saveOriginal(result, orginal)
const arr = simplify(result)
const data = JSON.stringify(arr, undefined, 2)
// backup previous version
copyFileSync(latest, prev)
const syncTime = (new Date()).toISOString()
writeFileSync(
latest,
[
`// provider data, synchronized at ${syncTime}`,
'',
'/* eslint-disable */ ',
'',
`export const providers = ${data}`,
'',
].join('\n'),
'utf8'
)
console.log('Providers list has been updated')
} catch (err) {
console.trace(err)
}
}
sync()