bibliothecary 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bibliothecary/parsers/elm.rb +76 -3
- data/lib/bibliothecary/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec3cbad7997b779286b5fbe64cef309126f1850b
|
4
|
+
data.tar.gz: fbded52f25368308e345f61896bac20171a0213f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ec15897f011e54553f272408f97c51bb65ce37c9014bc4d9c8aced87a07dee60fca06e60a9453e03d489377f8b129ef4946dabcb8172c440aa699bd9710517c
|
7
|
+
data.tar.gz: acc374351eb5315f14062a5712bdd8dde3a4642d4e14c9bbef8b4984d09369ef99b5511cffcb4b49a3f7d9067ded7267c1904bbc23d0b239c923a1ca57a7a91b
|
@@ -1,3 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Bibliothecary
|
4
|
+
module Parsers
|
5
|
+
class Elm
|
6
|
+
PLATFORM_NAME = 'elm'
|
7
|
+
|
8
|
+
def self.parse(filename, file_contents)
|
9
|
+
if filename.match(/^elm-package\.json$|^elm_dependencies\.json$/)
|
10
|
+
json = JSON.parse file_contents
|
11
|
+
parse_json_manifest(json)
|
12
|
+
elsif filename.match(/^elm-stuff\/exact-dependencies\.json$/)
|
13
|
+
json = JSON.parse file_contents
|
14
|
+
parse_json_lock(json)
|
15
|
+
else
|
16
|
+
[]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.analyse(folder_path, file_list)
|
21
|
+
[analyse_json(folder_path, file_list),
|
22
|
+
analyse_json_lock(folder_path, file_list)]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.analyse_json(folder_path, file_list)
|
26
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^elm-package\.json$|^elm_dependencies\.json$/) }
|
27
|
+
return unless path
|
28
|
+
|
29
|
+
manifest = JSON.parse File.open(path).read
|
30
|
+
|
31
|
+
{
|
32
|
+
platform: PLATFORM_NAME,
|
33
|
+
path: path,
|
34
|
+
dependencies: parse_json_manifest(manifest)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.analyse_json_lock(folder_path, file_list)
|
39
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^elm-stuff\/exact-dependencies\.json$/) }
|
40
|
+
return unless path
|
41
|
+
|
42
|
+
manifest = JSON.parse File.open(path).read
|
43
|
+
|
44
|
+
{
|
45
|
+
platform: PLATFORM_NAME,
|
46
|
+
path: path,
|
47
|
+
dependencies: parse_json_lock(manifest)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.parse_json_manifest(manifest)
|
52
|
+
map_dependencies(manifest, 'dependencies', 'runtime')
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.parse_json_lock(manifest)
|
56
|
+
manifest.map do |name, requirement|
|
57
|
+
{
|
58
|
+
name: name,
|
59
|
+
requirement: requirement,
|
60
|
+
type: 'runtime'
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.map_dependencies(hash, key, type)
|
66
|
+
hash.fetch(key,[]).map do |name, requirement|
|
67
|
+
{
|
68
|
+
name: name,
|
69
|
+
requirement: requirement,
|
70
|
+
type: type
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|