-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit-repositories
executable file
·52 lines (41 loc) · 1.04 KB
/
edit-repositories
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
#!/usr/bin/env node
const { writeFileSync: writeFile } = require('fs')
const { join } = require('path')
const args = process.argv.slice(2)
const repositories = require('./products/repositories.json')
switch (args[0]) {
case undefined:
console.log(Object.keys(repositories))
break
case 'add': {
const id = args[1]
if (!id) {
console.error('Error: You must specify a repository ID')
break
}
if (repositories[id]) {
console.error('Error: Already exists')
break
}
repositories[id] = { loaded: false, stargazers: [] }
writeFile(join(__dirname, 'products/repositories.json'), JSON.stringify(repositories))
break
}
case 'remove': {
const id = args[1]
if (!id) {
console.error('Error: You must specify a repository ID')
break
}
if (!repositories[id]) {
console.error('Error: Does not exist')
break
}
delete repositories[id]
writeFile(join(__dirname, 'products/repositories.json'), JSON.stringify(repositories))
break
}
default:
console.error(`Unkown option ${args[0]}`)
break
}