UNPKG

1.07 kBtext/coffeescriptView Raw
1fs = require "fs"
2path = require "path"
3{logger} = require "./utils"
4log = logger()
5
6fs.existsSync ?= path.existsSync
7
8manifest =
9
10 lookup: (rootPath)->
11 for manifestName in [".manifest", "manifest.json"]
12 manifestPath = (path.join rootPath, manifestName)
13 break if fs.existsSync manifestPath
14 return manifestPath
15
16 fetch: (rootPath)->
17 manifestPath = @lookup rootPath
18 try
19 manifest = JSON.parse fs.readFileSync manifestPath
20 catch err
21 if err.errno is 34
22 log "Manifest file does not exist '#{manifestPath}'", "red"
23 process.exit 34
24 else
25 log "Manifest file seems corrupted '#{manifestPath}'", "red"
26 log err, "red"
27 process.exit 3
28
29 set: (rootPath, key, value)->
30 manifestPath = @lookup rootPath
31 manifest = @fetch rootPath
32 manifest.key = value
33 @write rootPath, manifest
34
35 write: (rootPath, manifest)->
36 manifestPath = @lookup rootPath
37 fs.writeFileSync manifestPath, (JSON.stringify manifest, null, 2)
38
39kite = {}
40
41module.exports = {manifest, kite}