forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.iced
executable file
·65 lines (54 loc) · 1.28 KB
/
tool.iced
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
64
65
#!/usr/bin/env iced
fs = require 'fs'
stringify = require 'json-stable-stringify'
CSON = require 'cson'
{docopt} = require 'docopt'
doc = """
Convert pvl cson docs to a json pvl_kit.
Example:
./tool.iced
Usage:
tool.iced
tool.iced --help
"""
options = docopt doc
die = (msg) ->
console.log msg
process.exit 1
parse_cson = (filepath) ->
# read the cson file
pvl_obj = CSON.parseCSONFile filepath
if 'filename' of pvl_obj
console.log "error decoding"
die pvl_obj.toString()
return pvl_obj
unix_time = ->
parseInt( (new Date()).getTime() / 1000 )
main = ->
# collect cson files into tab
tab = {}
await fs.readdir "./tab", defer err, files
die err if err?
re = /^(\w*)\.(cson)$/
for file in files
groups = file.match(re)
if groups?
key = parseInt(groups[1])
die "nan key: #{groups[1]}" if isNaN(key)
obj = parse_cson "./tab/#{file}"
tab[key] = obj
console.log "added: tab[#{key}] <- #{file}"
else
console.log "IGNORE: #{file}"
# build kit
kit = {}
kit.kit_version = 1
kit.ctime = unix_time()
kit.tab = tab
# write to file
kit_json = JSON.stringify kit
kit_path = "./kit.json"
await fs.writeFile kit_path, (kit_json + "\n"), defer err
die err if err?
console.log "WROTE #{kit_path}"
do main