-
Notifications
You must be signed in to change notification settings - Fork 2
/
plistInfo.coffee
64 lines (58 loc) · 1.57 KB
/
plistInfo.coffee
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
###*
* @fileoverview info.plistの読み込み
###
fs = require "fs-extra"
path = require "path"
plist = require "plist"
denodeify = require "denodeify"
semver = require "semver"
request = require "./request"
cache = require "./cache"
config = require "./config"
util = require "./util"
readFile = denodeify(fs.readFile)
###*
* データ
###
data = {}
###*
* エラー出力
* @private
###
_outputError = (err) ->
console.error("Error: #{err}") if err?
return
###*
* plistを取得してパースしたものを返します
* @param {"remote"|"local"} repoType
* @param {string} repoName
* @param {boolean} force キャッシュを無視して元ファイルを取得するか 既定値は"false"
* @return {Object} plistのオブジェクト
###
get = ({type: repoType, name: repoName}, force = false) ->
return new Promise( (resolve, reject) ->
if data[repoName]? and !force
resolve(data[repoName])
return
isCatched = false
cache.getStringFile(repoName, "info.plist", force).catch( ->
isCatched = true
if repoType is "remote"
return request.getFromRemote(repoName, "info.plist").then( (content) ->
return content.toString()
)
else if repoType is "local"
return readFile(path.join(repoName, "info.plist"), "utf8")
return Promise.reject()
).then( (res) ->
cache.setStringFile(repoName, "info.plist", res) if isCatched
data[repoName] = plist.parse(res)
resolve(data[repoName])
return
).catch( (err) ->
reject(err)
return
)
)
module.exports =
get: get