dato 0.1.12 → 0.1.13
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/dato/account/client.rb +11 -5
- data/lib/dato/dump/format/yaml.rb +3 -3
- data/lib/dato/dump/runner.rb +19 -7
- data/lib/dato/dump/ssg_detector.rb +99 -0
- data/lib/dato/site/client.rb +11 -5
- data/lib/dato/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce7d382f884eb6efae6931aa28679144d557aa7
|
4
|
+
data.tar.gz: 61a5d88910e3a6f9478a489e98f7cfa08467b37c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c76af4354a87d7c467d95628ea9d49a09769cd68d99a5099470c0c4bd924dd1f0b3f4f40d38d3e76d8c6635db789a8c73b362bc6e15ed1dd2311d33aa7743bea
|
7
|
+
data.tar.gz: 251ba83f8e43176dd94aebb694a669687390846d3618bb98d6c04c68458016dcae2ee7621b0659a268bcd147f29f6afc99043f5f8bb160d8115a7ecec7764ecf
|
data/lib/dato/account/client.rb
CHANGED
@@ -16,11 +16,16 @@ module Dato
|
|
16
16
|
sites: Repo::Site
|
17
17
|
}.freeze
|
18
18
|
|
19
|
-
attr_reader :token, :base_url, :schema
|
19
|
+
attr_reader :token, :base_url, :schema, :extra_headers
|
20
20
|
|
21
|
-
def initialize(
|
21
|
+
def initialize(
|
22
|
+
token,
|
23
|
+
base_url: 'https://account-api.datocms.com',
|
24
|
+
extra_headers: {}
|
25
|
+
)
|
22
26
|
@base_url = base_url
|
23
27
|
@token = token
|
28
|
+
@extra_headers = extra_headers
|
24
29
|
end
|
25
30
|
|
26
31
|
REPOS.each do |method_name, repo_klass|
|
@@ -44,11 +49,12 @@ module Dato
|
|
44
49
|
def connection
|
45
50
|
options = {
|
46
51
|
url: base_url,
|
47
|
-
headers:
|
52
|
+
headers: extra_headers.merge(
|
48
53
|
'Accept' => 'application/json',
|
49
54
|
'Content-Type' => 'application/json',
|
50
|
-
'Authorization' => "Bearer #{@token}"
|
51
|
-
|
55
|
+
'Authorization' => "Bearer #{@token}",
|
56
|
+
'User-Agent' => "ruby-client v#{Dato::VERSION}"
|
57
|
+
)
|
52
58
|
}
|
53
59
|
|
54
60
|
@connection ||= Faraday.new(options) do |c|
|
@@ -4,15 +4,15 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
class Array
|
6
6
|
def deep_stringify_keys
|
7
|
-
|
8
|
-
if
|
7
|
+
each_with_object([]) do |value, accum|
|
8
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
9
9
|
new_val = value.deep_stringify_keys
|
10
10
|
accum.push new_val
|
11
11
|
else
|
12
12
|
accum.push value
|
13
13
|
end
|
14
14
|
accum
|
15
|
-
|
15
|
+
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/dato/dump/runner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'dato/dump/dsl/root'
|
3
3
|
require 'dato/dump/operation/root'
|
4
|
+
require 'dato/dump/ssg_detector'
|
4
5
|
|
5
6
|
module Dato
|
6
7
|
module Dump
|
@@ -13,17 +14,18 @@ module Dato
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def run
|
16
|
-
site.load
|
17
|
-
|
18
|
-
root = Operation::Root.new(Dir.pwd)
|
19
|
-
|
20
17
|
Dsl::Root.new(
|
21
18
|
File.read(config_path),
|
22
19
|
site.items_repo,
|
23
|
-
|
20
|
+
operation
|
24
21
|
)
|
25
22
|
|
26
|
-
|
23
|
+
site.load
|
24
|
+
operation.perform
|
25
|
+
end
|
26
|
+
|
27
|
+
def operation
|
28
|
+
@operation ||= Operation::Root.new(Dir.pwd)
|
27
29
|
end
|
28
30
|
|
29
31
|
def site
|
@@ -31,7 +33,17 @@ module Dato
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def client
|
34
|
-
@client ||= Dato::Site::Client.new(
|
36
|
+
@client ||= Dato::Site::Client.new(
|
37
|
+
api_token,
|
38
|
+
extra_headers: {
|
39
|
+
'X-Reason' => 'dump',
|
40
|
+
'X-SSG' => generator
|
41
|
+
}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def generator
|
46
|
+
SsgDetector.new(Dir.pwd).detect
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'toml'
|
3
|
+
require 'json'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Dato
|
7
|
+
module Dump
|
8
|
+
class SsgDetector
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
RUBY = %w(middleman jekyll nanoc).freeze
|
12
|
+
|
13
|
+
NODE = %w(brunch assemble ember-cli hexo metalsmith react-scripts
|
14
|
+
roots docpad wintersmith gatsby harp grunt gulp).freeze
|
15
|
+
|
16
|
+
PYTHON = %w(mkdocs pelican cactus).freeze
|
17
|
+
|
18
|
+
HUGO = [
|
19
|
+
{
|
20
|
+
file: 'config.toml',
|
21
|
+
loader: ->(content) { TOML::Parser.new(content).parsed }
|
22
|
+
},
|
23
|
+
{
|
24
|
+
file: 'config.yaml',
|
25
|
+
loader: ->(content) { YAML.load(content) }
|
26
|
+
},
|
27
|
+
{
|
28
|
+
file: 'config.json',
|
29
|
+
loader: ->(content) { JSON.load(content) }
|
30
|
+
}
|
31
|
+
].freeze
|
32
|
+
|
33
|
+
def initialize(path)
|
34
|
+
@path = path
|
35
|
+
end
|
36
|
+
|
37
|
+
def detect
|
38
|
+
ruby_generator ||
|
39
|
+
node_generator ||
|
40
|
+
python_generator ||
|
41
|
+
hugo ||
|
42
|
+
'unknown'
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def ruby_generator
|
48
|
+
gemfile_path = File.join(path, 'Gemfile')
|
49
|
+
return unless File.exist?(gemfile_path)
|
50
|
+
|
51
|
+
gemfile = File.read(gemfile_path)
|
52
|
+
|
53
|
+
RUBY.find do |generator|
|
54
|
+
gemfile =~ /('#{generator}'|"#{generator}")/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def node_generator
|
59
|
+
package_path = File.join(path, 'package.json')
|
60
|
+
return unless File.exist?(package_path)
|
61
|
+
|
62
|
+
package = JSON.load(File.read(package_path))
|
63
|
+
|
64
|
+
deps = package.fetch('dependencies', {})
|
65
|
+
dev_deps = package.fetch('devDependencies', {})
|
66
|
+
all_deps = deps.merge(dev_deps)
|
67
|
+
|
68
|
+
NODE.find do |generator|
|
69
|
+
all_deps.key? generator
|
70
|
+
end
|
71
|
+
rescue JSON::ParserError
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
def python_generator
|
76
|
+
requirements_path = File.join(path, 'requirements.txt')
|
77
|
+
return unless File.exist?(requirements_path)
|
78
|
+
|
79
|
+
requirements = File.read(requirements_path)
|
80
|
+
|
81
|
+
PYTHON.find do |generator|
|
82
|
+
requirements =~ /^#{generator}(==)?/
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def hugo
|
87
|
+
HUGO.any? do |option|
|
88
|
+
path = File.join(path, option[:file])
|
89
|
+
config = option[:parser].call(File.read(path))
|
90
|
+
config.key? 'baseurl'
|
91
|
+
end && 'hugo'
|
92
|
+
rescue JSON::ParserError
|
93
|
+
nil
|
94
|
+
rescue Psych::SyntaxError
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/dato/site/client.rb
CHANGED
@@ -29,11 +29,16 @@ module Dato
|
|
29
29
|
items: Repo::Item
|
30
30
|
}.freeze
|
31
31
|
|
32
|
-
attr_reader :token, :base_url, :schema
|
32
|
+
attr_reader :token, :base_url, :schema, :extra_headers
|
33
33
|
|
34
|
-
def initialize(
|
34
|
+
def initialize(
|
35
|
+
token,
|
36
|
+
base_url: 'https://site-api.datocms.com',
|
37
|
+
extra_headers: {}
|
38
|
+
)
|
35
39
|
@base_url = base_url
|
36
40
|
@token = token
|
41
|
+
@extra_headers = extra_headers
|
37
42
|
end
|
38
43
|
|
39
44
|
def upload_file(path_or_url)
|
@@ -67,11 +72,12 @@ module Dato
|
|
67
72
|
def connection
|
68
73
|
options = {
|
69
74
|
url: base_url,
|
70
|
-
headers:
|
75
|
+
headers: extra_headers.merge(
|
71
76
|
'Accept' => 'application/json',
|
72
77
|
'Content-Type' => 'application/json',
|
73
|
-
'Authorization' => "Bearer #{@token}"
|
74
|
-
|
78
|
+
'Authorization' => "Bearer #{@token}",
|
79
|
+
'User-Agent' => "ruby-client v#{Dato::VERSION}"
|
80
|
+
)
|
75
81
|
}
|
76
82
|
|
77
83
|
@connection ||= Faraday.new(options) do |c|
|
data/lib/dato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -321,6 +321,7 @@ files:
|
|
321
321
|
- lib/dato/dump/operation/directory.rb
|
322
322
|
- lib/dato/dump/operation/root.rb
|
323
323
|
- lib/dato/dump/runner.rb
|
324
|
+
- lib/dato/dump/ssg_detector.rb
|
324
325
|
- lib/dato/json_api_deserializer.rb
|
325
326
|
- lib/dato/json_api_serializer.rb
|
326
327
|
- lib/dato/local/entities_repo.rb
|
@@ -379,4 +380,3 @@ signing_key:
|
|
379
380
|
specification_version: 4
|
380
381
|
summary: Ruby client for DatoCMS API
|
381
382
|
test_files: []
|
382
|
-
has_rdoc:
|