weeblybundler 0.1.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +1 -0
- data/bin/weeblybundle +5 -0
- data/lib/weeblybundler/bundle.rb +90 -0
- data/lib/weeblybundler/cli.rb +58 -0
- data/lib/weeblybundler/version.rb +3 -0
- data/lib/weeblybundler/zip_file_generator.rb +49 -0
- data/lib/weeblybundler.rb +6 -0
- data/weeblybundler.gemspec +28 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 63ba5cddb9a5b6ff4671950d505d016cbc6b56b0
|
4
|
+
data.tar.gz: d2636ccc1e227364d4e776472000af8019d77d62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f954a8995f25582a1de864a7dd99e449a9d42bc1029f5acb881b4ea8159fa0a2d3d9257831e3eed067db97c51e6e85b771304f844126a4eb6a321f7a009a0ad1
|
7
|
+
data.tar.gz: 4fb11cf8218e5440b430347f6a979c207031e7e87655a75edbed937cfb60ddd36c2da1bcd4c9a231df01cf89fa55933c7c337ced759183fb5c0a22665d2de435
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Bryan Ashley
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# WeeblyBundler v0.1.0
|
2
|
+
|
3
|
+
WeeblyBundler is a CLI tool created to enable Weebly Platform Developers to rapidly deploy their apps and upload their themes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Please note, this process will be significantly easier once the gem is released on rubygems.
|
8
|
+
|
9
|
+
Download the source code
|
10
|
+
|
11
|
+
`git clone git@github.intern.weebly.net:weebly/weeblybundler.git`
|
12
|
+
|
13
|
+
Change to source directory and install dependencies (including bundler)
|
14
|
+
|
15
|
+
`cd weeblybundler`
|
16
|
+
|
17
|
+
`gem install bundler`
|
18
|
+
|
19
|
+
`bundle install`
|
20
|
+
|
21
|
+
Install the gem in your current gemset by running gem install with a path to the pkg/weeblybundler-0.1.0.gem in the gem's source directory.
|
22
|
+
|
23
|
+
`gem build pkg/weeblybundler.gemspec`
|
24
|
+
|
25
|
+
`gem install pkg/weeblybundler-0.1.0.gem`
|
26
|
+
|
27
|
+
Good to go!
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Uploading Apps
|
32
|
+
|
33
|
+
Before uploading apps, you must first set your client id and client secret as environment variables. You can find these values on your app's page in the developer-admin.
|
34
|
+
|
35
|
+
`export WEEBLY_CLIENT_ID=client_id && export WEEBLY_SECRET=secret`
|
36
|
+
|
37
|
+
Now you can use the app command to sync your local changes to your app.
|
38
|
+
|
39
|
+
`weeblybundle app /Path/To/Element/Directory`
|
40
|
+
|
41
|
+
Once you have installed your app to a site from the developer-admin, you can sync your app using weeblybundle and view your changes in the editor by refreshing the page.
|
42
|
+
|
43
|
+
### Uploading Themes
|
44
|
+
|
45
|
+
Before uploading themes, you must first set your email, site_id, and site_token. You can retrieve the site_id and site_token from your editor under Settings->General->Platform API Token.
|
46
|
+
|
47
|
+
`export WEEBLY_EMAIL=weebly@woobly.com && export WEEBLY_SITE_ID=site_id && export WEEBLY_TOKEN=token`
|
48
|
+
|
49
|
+
Then upload the theme by using:
|
50
|
+
|
51
|
+
`weeblybundle theme /Path/To/Theme`
|
52
|
+
|
53
|
+
You can then see your uploaded theme under Themes->Custom.
|
54
|
+
|
55
|
+
Happy Bundling!
|
56
|
+
|
57
|
+
For developer support and questions, contact us at developer@weebly.com.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/weeblybundle
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'weeblybundler/zip_file_generator'
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module Weeblybundler
|
6
|
+
|
7
|
+
class Bundle
|
8
|
+
|
9
|
+
# type = ['app', 'theme']
|
10
|
+
# path - path to the zip file.
|
11
|
+
# domain - host to upload to.
|
12
|
+
# params - Parameters Bundle object should be initialized with. Require parameters specified in the validateApp/validateTheme methods.
|
13
|
+
|
14
|
+
def initialize(type, path, domain, params)
|
15
|
+
@params = params
|
16
|
+
@path = path
|
17
|
+
@domain = domain
|
18
|
+
@zip_location = "#{path}/#{path.split('/').last}.zip"
|
19
|
+
@type = type
|
20
|
+
@errors = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def is_valid?()
|
24
|
+
unless File.directory?(@path)
|
25
|
+
@errors['filepath'] = "#{@path} is not a valid directory."
|
26
|
+
end
|
27
|
+
|
28
|
+
if (@type === 'app')
|
29
|
+
validateFields(['client_id', 'secret'])
|
30
|
+
end
|
31
|
+
if (@type === 'theme')
|
32
|
+
validateFields(['site_id', 'token', 'email'])
|
33
|
+
end
|
34
|
+
return @errors.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def validateFields(required)
|
38
|
+
for field in required
|
39
|
+
if @params[field].nil? || @params[field].strip.empty?
|
40
|
+
@errors[field] = "You must set WEEBLY_" + field.upcase + " in your environment variables to upload " + @type +" '. See the ReadMe for more information."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def errors
|
46
|
+
@errors
|
47
|
+
end
|
48
|
+
|
49
|
+
def sync(path, publish=false)
|
50
|
+
zip_bundle
|
51
|
+
if @type === 'app'
|
52
|
+
response = uploadApp(path, publish)
|
53
|
+
end
|
54
|
+
if @type === 'theme'
|
55
|
+
response = uploadTheme(path, publish)
|
56
|
+
end
|
57
|
+
cleanup
|
58
|
+
return response
|
59
|
+
end
|
60
|
+
|
61
|
+
def cleanup
|
62
|
+
File.delete(@zip_location) if File.exist?(@zip_location)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def zip_bundle
|
68
|
+
zfg = Weeblybundler::ZipFileGenerator.new(@path, @zip_location)
|
69
|
+
if (File.file?(@zip_location))
|
70
|
+
File.delete(@zip_location)
|
71
|
+
end
|
72
|
+
zfg.write()
|
73
|
+
end
|
74
|
+
|
75
|
+
def uploadApp(path, publish=false)
|
76
|
+
token = JWT.encode({:client_id => @params['client_id']}, @params['secret'], 'HS256')
|
77
|
+
RestClient.post("#{@domain}#{path}",
|
78
|
+
{ :client_id => @params['client_id'], :Filedata => File.new(@zip_location), :publish => publish },
|
79
|
+
{ :Authorization => token}
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def uploadTheme(path, publish=false)
|
84
|
+
RestClient.post("#{@domain}#{path}",
|
85
|
+
{ :site_id => @params['site_id'], :email => @params['email'], :Filedata => File.new(@zip_location), :publish => publish },
|
86
|
+
{ :Authorization => @params['token']}
|
87
|
+
)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'weeblybundler/bundle'
|
3
|
+
require "awesome_print"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Weeblybundler
|
7
|
+
class CLI < Thor
|
8
|
+
desc "app PATH", "Bundles and uploads your weebly platform app."
|
9
|
+
def app( path )
|
10
|
+
client_id = ENV['WEEBLY_CLIENT_ID']
|
11
|
+
secret = ENV['WEEBLY_SECRET']
|
12
|
+
domain = ENV['WEEBLY_DOMAIN'] || 'https://www.weebly.com'
|
13
|
+
|
14
|
+
ap client_id
|
15
|
+
ap secret
|
16
|
+
ap domain
|
17
|
+
|
18
|
+
bundle = Bundle.new('app', path, domain, {'client_id' => client_id, 'secret' => secret, 'domain' => domain})
|
19
|
+
|
20
|
+
if bundle.is_valid?
|
21
|
+
response = bundle.sync('/platform/app')
|
22
|
+
begin
|
23
|
+
ap JSON.parse(response.body)
|
24
|
+
rescue
|
25
|
+
ap "There was a problem uploading your element to #{domain}/platform/app"
|
26
|
+
ap response.body
|
27
|
+
bundle.cleanup
|
28
|
+
end
|
29
|
+
else
|
30
|
+
ap bundle.errors
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "theme PATH", "Bundles and uploads your weebly platform theme."
|
35
|
+
option :publish, :type => :boolean
|
36
|
+
def theme( path )
|
37
|
+
domain = ENV['WEEBLY_DOMAIN'] || 'https://www.weebly.com'
|
38
|
+
site_id = ENV['WEEBLY_SITE_ID']
|
39
|
+
token = ENV['WEEBLY_TOKEN']
|
40
|
+
email = ENV['WEEBLY_EMAIL']
|
41
|
+
|
42
|
+
bundle = Bundle.new('theme', path, domain, {'domain' => domain, 'site_id' => site_id, 'token' => token, 'email' => email})
|
43
|
+
|
44
|
+
if bundle.is_valid?
|
45
|
+
response = bundle.sync('/platform/theme', options[:publish])
|
46
|
+
begin
|
47
|
+
ap JSON.parse(response)
|
48
|
+
rescue
|
49
|
+
ap "There was a problem uploading your element to #{domain}/platform/theme"
|
50
|
+
ap response.body
|
51
|
+
bundle.cleanup
|
52
|
+
end
|
53
|
+
else
|
54
|
+
ap bundle.errors
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
# Recursively zips contents of a directory.
|
4
|
+
# https://github.com/rubyzip/rubyzip/blob/05916bf89181e1955118fd3ea059f18acac28cc8/samples/example_recursive.rb
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
# directoryToZip = "/tmp/input"
|
8
|
+
# outputFile = "/tmp/out.zip"
|
9
|
+
# zf = ZipFileGenerator.new(directoryToZip, outputFile)
|
10
|
+
# zf.write()
|
11
|
+
module Weeblybundler
|
12
|
+
class ZipFileGenerator
|
13
|
+
|
14
|
+
# Initialize with the directory to zip and the location of the output archive.
|
15
|
+
def initialize(inputDir, outputFile)
|
16
|
+
@inputDir = inputDir
|
17
|
+
@outputFile = outputFile
|
18
|
+
end
|
19
|
+
|
20
|
+
# Zip the input directory.
|
21
|
+
def write()
|
22
|
+
entries = Dir.entries(@inputDir)
|
23
|
+
entries.delete_if { |entry| entry.start_with? '.' }
|
24
|
+
io = Zip::File.open(@outputFile, Zip::File::CREATE);
|
25
|
+
|
26
|
+
writeEntries(entries, "", io)
|
27
|
+
io.close()
|
28
|
+
end
|
29
|
+
|
30
|
+
# A helper method to make the recursion work.
|
31
|
+
private
|
32
|
+
|
33
|
+
def writeEntries(entries, path, io)
|
34
|
+
entries.each { |e|
|
35
|
+
zipFilePath = path == "" ? e : File.join(path, e)
|
36
|
+
diskFilePath = File.join(@inputDir, zipFilePath)
|
37
|
+
if File.directory?(diskFilePath)
|
38
|
+
io.mkdir(zipFilePath)
|
39
|
+
subdir =Dir.entries(diskFilePath)
|
40
|
+
subdir.delete_if { |entry| entry.start_with? '.' }
|
41
|
+
writeEntries(subdir, zipFilePath, io)
|
42
|
+
else
|
43
|
+
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'weeblybundler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "weeblybundler"
|
8
|
+
spec.version = Weeblybundler::VERSION
|
9
|
+
spec.authors = ["Bryan Ashley"]
|
10
|
+
spec.email = ["bryan@weebly.com"]
|
11
|
+
spec.summary = %q{Used to for packaging and publishing Weebly platform App bundles}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = ['weeblybundle']
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'thor'
|
21
|
+
spec.add_dependency 'rubyzip'
|
22
|
+
spec.add_dependency 'rest-client'
|
23
|
+
spec.add_dependency 'awesome_print'
|
24
|
+
spec.add_dependency 'jwt'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weeblybundler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Ashley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubyzip
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
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: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jwt
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- bryan@weebly.com
|
114
|
+
executables:
|
115
|
+
- weeblybundle
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/weeblybundle
|
125
|
+
- lib/weeblybundler.rb
|
126
|
+
- lib/weeblybundler/bundle.rb
|
127
|
+
- lib/weeblybundler/cli.rb
|
128
|
+
- lib/weeblybundler/version.rb
|
129
|
+
- lib/weeblybundler/zip_file_generator.rb
|
130
|
+
- weeblybundler.gemspec
|
131
|
+
homepage: ''
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.6.6
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Used to for packaging and publishing Weebly platform App bundles
|
155
|
+
test_files: []
|