yassh 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/yassh +135 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11af146bac5df12226fe31a4783677c84c3ef2a2
|
4
|
+
data.tar.gz: cd3d4fe214af8229cd803052f251d7a7248b33ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d76fcb15656deb2cd4ecaf37d3ae5d7dd0413e624a5c27053669e0ba956f5872fbc67cc9d9ac3e0abbadf23356809b550bb720b5ba53a1206eea79decd93c298
|
7
|
+
data.tar.gz: 899ff9f60ef7475e5ff0085dcdb277612c011acd5e32eaf2ce4d8e6be5c481e92f2dad4dd4e1e86b4441fcf55ad08f7fe8f1634d8d6618a4a020cc66976df1da
|
data/bin/yassh
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'json'
|
6
|
+
require 'net/http'
|
7
|
+
|
8
|
+
require 'commander/import'
|
9
|
+
require "mimemagic"
|
10
|
+
require 'rest-client'
|
11
|
+
|
12
|
+
program :description, 'CLI for publishing websites to yas.sh'
|
13
|
+
program :version, "1.0.0"
|
14
|
+
|
15
|
+
class RestClient::Response
|
16
|
+
def json
|
17
|
+
JSON.parse(body)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
$api = RestClient::Resource.new("https://api.yas.sh", headers: {content_type: 'application/json; charset=utf-8', accept: 'application/json'})
|
22
|
+
|
23
|
+
def load_default_domain
|
24
|
+
File.read("CNAME").strip.split.first
|
25
|
+
rescue
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_default_token
|
30
|
+
dir_path = File.join(ENV["HOME"], ".config/yassh/")
|
31
|
+
path = File.join(dir_path, "access_token")
|
32
|
+
File.read(path).strip.split.first
|
33
|
+
rescue
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_site(domain, token)
|
38
|
+
$api['/sites'].post({ domain: domain }.to_json, {Authorization: "Bearer #{token}"}).json
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_revision(domain, token)
|
42
|
+
$api["/sites/#{domain}/revisions"].post("", {Authorization: "Bearer #{token}"}).json["revision"]["number"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def post_file(domain, revision, metadata, token)
|
46
|
+
$api["/sites/#{domain}/revisions/#{revision}/files"].post(metadata.to_json, {Authorization: "Bearer #{token}"}).json
|
47
|
+
end
|
48
|
+
|
49
|
+
def commit_revision(domain, revision, token)
|
50
|
+
$api["/sites/#{domain}/revisions/#{revision}/commit"].post("", {Authorization: "Bearer #{token}"}).json
|
51
|
+
end
|
52
|
+
|
53
|
+
def authenticate(email, password)
|
54
|
+
$api["/auth"].post({username: email, password: password}.to_json).json
|
55
|
+
end
|
56
|
+
|
57
|
+
command :auth do |c|
|
58
|
+
c.syntax = "yassh auth"
|
59
|
+
c.description = "Authenticate your user account and store API key in ~/.config/yassh/"
|
60
|
+
c.action do |args, opts|
|
61
|
+
email = ask("Email: ")
|
62
|
+
pass = password
|
63
|
+
|
64
|
+
begin
|
65
|
+
result = authenticate(email, pass)
|
66
|
+
dir_path = File.join(ENV["HOME"], ".config/yassh/")
|
67
|
+
FileUtils.mkdir_p(dir_path)
|
68
|
+
path = File.join(dir_path, "access_token")
|
69
|
+
File.write(path, result["access_token"] + "\n")
|
70
|
+
puts "Access token written to: #{path}"
|
71
|
+
rescue RestClient::RequestFailed
|
72
|
+
puts "Incorrect email or password"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
command :push do |c|
|
78
|
+
c.syntax = "yassh push [options]"
|
79
|
+
c.description = "Create a new revision and recursively upload files"
|
80
|
+
c.option '-d', '--domain DOMAIN', String, 'Domain to push site to (default loaded from CNAME)'
|
81
|
+
c.option '--root PATH', String, 'Root directory for the website (default .)'
|
82
|
+
c.option '--token TOKEN', String, 'Yassh access token'
|
83
|
+
c.action do |args, opts|
|
84
|
+
opts.default domain: load_default_domain, root: Dir.pwd, token: load_default_token
|
85
|
+
|
86
|
+
create_site(opts.domain, opts.token)
|
87
|
+
|
88
|
+
print "Creating revision ... "
|
89
|
+
revision_number = create_revision(opts.domain, opts.token)
|
90
|
+
puts "#{opts.domain} v#{revision_number}"
|
91
|
+
|
92
|
+
failure_encountered = false
|
93
|
+
|
94
|
+
|
95
|
+
Dir.chdir opts.root
|
96
|
+
Dir.glob("**/*") do |path|
|
97
|
+
payload = File.open(path) do |f|
|
98
|
+
metadata = {
|
99
|
+
domain: opts.domain,
|
100
|
+
size: f.size,
|
101
|
+
md5: Digest::MD5.file(f).hexdigest,
|
102
|
+
path: path,
|
103
|
+
content_type: (MimeMagic.by_path(path) || MimeMagic.by_magic(f) || 'application/octet-stream').to_s
|
104
|
+
}
|
105
|
+
|
106
|
+
print "Uploading #{path} ... "
|
107
|
+
|
108
|
+
begin
|
109
|
+
response = post_file(opts.domain, revision_number, metadata, opts.token)
|
110
|
+
if response["file"]["new_file"]
|
111
|
+
RestClient.put response["file"]["upload_url"], f, content_type: metadata[:content_type]
|
112
|
+
puts "SUCCESS"
|
113
|
+
else
|
114
|
+
puts "EXISTS"
|
115
|
+
end
|
116
|
+
rescue RestClient::RequestFailed
|
117
|
+
failure_encountered = true
|
118
|
+
puts "FAILED"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
force_commit = false
|
124
|
+
if failure_encountered
|
125
|
+
force_commit = agree("Failed to succesfuly upload all files. Would you still like to commit this version?")
|
126
|
+
end
|
127
|
+
|
128
|
+
if force_commit || !failure_encountered
|
129
|
+
print "Committing #{opts.domain} v#{revision_number} ... "
|
130
|
+
|
131
|
+
commit_revision(opts.domain, revision_number, opts.token)
|
132
|
+
puts "SUCCESS"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yassh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hamon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mimemagic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description: Publish a folder instantly to yas.sh
|
56
|
+
email: andrew@hamon.cc
|
57
|
+
executables:
|
58
|
+
- yassh
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/yassh
|
63
|
+
homepage: http://rubygems.org/gems/yassh
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.5.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: yassh push .
|
87
|
+
test_files: []
|