mesmerize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mesmerize (0.0.1)
5
+ commander (~> 4.1.2)
6
+ faraday (~> 0.8.0)
7
+ faraday_middleware (~> 0.8.7)
8
+ netrc (~> 0.7.2)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ commander (4.1.2)
14
+ highline (~> 1.6.11)
15
+ faraday (0.8.1)
16
+ multipart-post (~> 1.1)
17
+ faraday_middleware (0.8.7)
18
+ faraday (>= 0.7.4, < 0.9)
19
+ highline (1.6.12)
20
+ multipart-post (1.1.5)
21
+ netrc (0.7.2)
22
+ rake (0.9.2.2)
23
+ rspec (0.6.4)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ mesmerize!
30
+ rake (~> 0.9.2)
31
+ rspec (~> 0.6.1)
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ ## Commands
2
+
3
+ ``` bash
4
+ mesmerize signup
5
+ mesmerize login
6
+ mesmerize logout
7
+
8
+ mesmerize create
9
+ mesmerize [push, bump, release]
10
+ # mesmerize apps:destroy
11
+ # mesmerize apps
12
+
13
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ gemspec = eval(File.read("mesmerize.gemspec"))
5
+
6
+ task :build => "#{gemspec.full_name}.gem"
7
+
8
+ file "#{gemspec.full_name}.gem" => gemspec.files + ["mesmerize.gemspec"] do
9
+ system "gem build mesmerize.gemspec"
10
+ system "gem install mesmerize-#{Mesmerize::VERSION}.gem"
11
+ end
data/bin/mesmerize ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander/import'
4
+
5
+ $:.push File.expand_path("../../lib", __FILE__)
6
+ require 'mesmerize'
7
+ require 'mesmerize/commands'
8
+
9
+ program :version, Mesmerize::VERSION
10
+ program :description, 'A command-line interface for Mesmerize'
11
+
12
+ program :help, 'Author', 'Mattt Thompson <m@mattt.me>'
13
+ program :help, 'Website', 'http://mesmerizeapp.com'
14
+ program :help_formatter, :compact
15
+
16
+ global_option '--verbose'
17
+ default_command :help
data/lib/mesmerize.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Mesmerize
2
+ VERSION = '0.0.1'
3
+ end
4
+
5
+ require_relative 'mesmerize/authentication'
6
+ require_relative 'mesmerize/client'
7
+ require_relative 'mesmerize/agvtool'
8
+ require_relative 'mesmerize/xcodebuildinfo'
@@ -0,0 +1,17 @@
1
+ module Mesmerize::Agvtool
2
+ class << self
3
+ def what_version
4
+ output = `agvtool what-version -terse`
5
+ output.length > 0 ? output : nil
6
+ end
7
+
8
+ alias :vers :what_version
9
+
10
+ def what_marketing_version
11
+ output = `agvtool what-marketing-version -terse`
12
+ output.scan(/\=(.+)$/).flatten.first
13
+ end
14
+
15
+ alias :mvers :what_marketing_version
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ require 'netrc'
2
+
3
+ module Mesmerize
4
+ module Authentication
5
+ def credentials
6
+ Netrc.read[Mesmerize::Client::HOSTNAME]
7
+ end
8
+
9
+ def login!(user, pass)
10
+ raise unless user and pass
11
+ netrc = Netrc.read
12
+ netrc[Mesmerize::Client::HOSTNAME] = user, pass
13
+ netrc.save
14
+ end
15
+
16
+ def logout!
17
+ p netrc = Netrc.read
18
+ p netrc.delete(Mesmerize::Client::HOSTNAME)
19
+ netrc.save
20
+ end
21
+
22
+ def client
23
+ username, password = credentials
24
+ @client ||= Mesmerize::Client.new(password)
25
+ end
26
+
27
+ def authenticated?
28
+ !!credentials
29
+ end
30
+
31
+ def warn_if_currently_authenticated!
32
+ if authenticated?
33
+ say_warning "You are already authenticated."
34
+ end
35
+ end
36
+
37
+ def require_authorization!
38
+ abort "Authentication required. Please do `mesmerize login` first" unless authenticated?
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,89 @@
1
+ require 'openssl'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Mesmerize
6
+ class Client
7
+ HOSTNAME = 'mesmerizeapp.com'
8
+ # HOSTNAME = 'localhost:5000'
9
+
10
+
11
+ def initialize(api_key = nil)
12
+ @connection = Faraday.new(:url => "http://#{HOSTNAME}") do |builder|
13
+ builder.request :multipart
14
+ builder.request :url_encoded
15
+ builder.use FaradayMiddleware::FollowRedirects
16
+
17
+ builder.response :json, :content_type => /\bjson$/
18
+
19
+ builder.adapter :net_http
20
+ end
21
+
22
+ @connection.headers['X-Mesmerize-API-Key'] = api_key if api_key
23
+ end
24
+
25
+ def post_session(email, password)
26
+ params = {
27
+ email: email,
28
+ password: password
29
+ }
30
+
31
+ @connection.post("/api/sessions", params).on_complete do |env|
32
+ yield env[:status], env[:body] if block_given?
33
+ end
34
+ end
35
+
36
+ def post_account(name, email, password)
37
+ params = {
38
+ name: name,
39
+ email: email,
40
+ password: password
41
+ }
42
+
43
+ @connection.post("/api/accounts", params).on_complete do |env|
44
+ yield env[:status], env[:body] if block_given?
45
+ end
46
+ end
47
+
48
+ def get_apps
49
+ @connection.get("/api/accounts").on_complete do |env|
50
+ yield env[:status], env[:body] if block_given?
51
+ end
52
+ end
53
+
54
+ def get_app(app)
55
+ @connection.get("/api/apps/#{app}").on_complete do |env|
56
+ yield env[:status], env[:body] if block_given?
57
+ end
58
+ end
59
+
60
+ def post_app(app)
61
+ params = {
62
+ name: app
63
+ }
64
+
65
+ @connection.post("/api/apps", params).on_complete do |env|
66
+ yield env[:status], env[:body] if block_given?
67
+ end
68
+ end
69
+
70
+ def post_release(app, release, file)
71
+ params = {
72
+ version: release.to_s
73
+ }
74
+
75
+ @connection.post("/api/apps/#{app}/releases", params).on_complete do |env|
76
+ if (200...300).include? env[:status]
77
+ params = env[:body]["params"]
78
+ params[:file] = Faraday::UploadIO.new(file, 'application/octet-stream')
79
+
80
+ response = @connection.post(env[:body]["url"], params)
81
+
82
+ yield response[:status], response[:body] if block_given?
83
+ else
84
+ yield env[:status], env[:body] if block_given?
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ include Mesmerize::Authentication
2
+
3
+ require_relative 'commands/signup'
4
+ require_relative 'commands/login'
5
+ require_relative 'commands/logout'
6
+ require_relative 'commands/create'
7
+ require_relative 'commands/release'
@@ -0,0 +1,19 @@
1
+ command :create do |c|
2
+ c.syntax = 'mesmerize create APP_NAME [options]'
3
+ c.summary = 'Create a new app'
4
+ c.description = ''
5
+
6
+ c.action do |args, options|
7
+ if @app = args[0]
8
+ client.post_app(@app) do |status, body|
9
+ if (200...300).include?(status)
10
+ say_ok "Successfully created app, #{@app}"
11
+ else
12
+ say_error "Unable to create app: #{body}"
13
+ end
14
+ end
15
+ else
16
+ say_error "Missing argument: App Name"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ command :login do |c|
2
+ c.syntax = 'mesmerize login'
3
+ c.summary = 'Get account credentials'
4
+ c.description = ''
5
+
6
+ c.action do |args, options|
7
+ warn_if_currently_authenticated!
8
+
9
+ say "Enter your Mesmerize Credentials"
10
+ @email = ask "Email:"
11
+ @password = password "Password (typing will be hidden):"
12
+
13
+ client.post_session(@email, @password) do |status, body|
14
+ if (200...300).include?(status)
15
+ say_ok "Successfully logged in"
16
+ login!(body["email"], body["api_key"])
17
+ else
18
+ say_error "Could not log you in. Please check that you are entering the correct e-mail and password."
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # [:signin, :'sign-in', :'authenticate'].each do |command|
25
+ # alias_command command, :login
26
+ # end
@@ -0,0 +1,18 @@
1
+ command :logout do |c|
2
+ c.syntax = 'mesmerize logout'
3
+ c.summary = 'Clear your account credentials'
4
+ c.description = ''
5
+
6
+ c.action do |args, options|
7
+ if current_user
8
+ logout!
9
+ say_ok "You have logged out successfully"
10
+ else
11
+ say_warning "You are not current logged in"
12
+ end
13
+ end
14
+ end
15
+
16
+ # [:signout, :'sign-out'].each do |command|
17
+ # alias_command command, :logout
18
+ # end
@@ -0,0 +1,131 @@
1
+ command :release do |c|
2
+ c.syntax = 'mesmerize release [VERSION] [options]'
3
+ c.summary = 'Release a new build of your app'
4
+ c.description = ''
5
+
6
+ c.example 'description', 'mesmerize release 478 --tag 3.7.2 --scheme MyApp+Sparkle'
7
+ c.option '-a', '--app APP', 'Name of App'
8
+ c.option '-t', '--tag TAG', 'Marketing Version Number (e.g. 3.7.2)'
9
+ c.option '-w', '--workspace WORKSPACE', 'Workspace (.xcworkspace) file to use to build app (automatically detected in current directory)'
10
+ c.option '-p', '--project PROJECT', 'Project (.xcodeproj) file to use to build app (automatically detected in current directory, overridden by --workspace option, if passed)'
11
+ c.option '-s', '--scheme SCHEME', 'Scheme used to build app'
12
+
13
+ c.action do |args, options|
14
+ require_authorization!
15
+
16
+ begin
17
+ @info = Mesmerize::XcodeBuildInfo.info
18
+
19
+ @appName = options.app || @info.project
20
+ @version = args.shift.to_i
21
+ @tag = options.tag
22
+ @workspace = options.workspace
23
+ @project = options.project
24
+ @scheme = options.scheme
25
+
26
+ @appSlug = @appName.strip.gsub(/\s+/, '-')
27
+
28
+ say "Found project \"#{@appName}\"."
29
+ say "Looking up current release information..."
30
+
31
+ response = client.get_app(@appSlug)
32
+ if response.status == 404
33
+ say_error "Could not find listing for #{@appName}." and say_error "Do `mesmerize create #{@appName}` first." and abort
34
+ end
35
+
36
+ @app = response.body
37
+ if @version.nonzero?
38
+ if @version <= @app["version"].to_i
39
+ say_error "Specified release (#{@version}) must be greater than current release (#{@app["version"]})" and abort
40
+ end
41
+ else
42
+ if @app["version"]
43
+ @version = @app["version"] + 1
44
+ say_warning "Bumping release to version #{@version}"
45
+ elsif Mesmerize::Agvtool.vers
46
+ @version = Mesmerize::Agvtool.vers + 1
47
+ say_warning "Bumping release to version #{@version}"
48
+ else
49
+ say_error "Specify a release version" and abort
50
+ end
51
+ end
52
+
53
+ unless @workspace || @project
54
+ workspaces, projects = Dir["*.xcworkspace"], Dir["*.xcodeproj"]
55
+ abort "No Xcode projects or workspaces found in current directory" if workspaces.empty? && projects.empty?
56
+
57
+ case workspaces.length
58
+ when 0
59
+ case projects.length
60
+ when 0
61
+ abort "No Xcode projects or workspaces found in current directory"
62
+ when 1
63
+ @project = projects.first
64
+ else
65
+ @project = choose "Select a project:", *projects
66
+ end
67
+ when 1
68
+ @workspace = workspaces.first
69
+ else
70
+ @workspace = choose "Select a workspace:", *workspaces
71
+ end
72
+ end
73
+
74
+ if @scheme and not @info.schemes.include?(@scheme)
75
+ abort "Scheme #{@scheme} not found"
76
+ end
77
+
78
+ if @scheme.nil?
79
+ @scheme = choose "Select a scheme:", *@info.schemes
80
+ end
81
+
82
+ ENV['CC'] = nil # Fix for rvm
83
+
84
+ puts
85
+ say "Building \"#{@workspace || @project}\" version #{@version} with scheme \"#{@scheme}\"\n"
86
+
87
+ log "agvtool", "new-version"
88
+ `agvtool -noscm new-version -all #{@version}`
89
+
90
+ if @tag
91
+ log "agvtool", "new-marketing-version"
92
+ `agvtool -noscm new-marketing-version #{@tag}`
93
+ end
94
+
95
+ [:clean, :build, :archive, :install].each do |action|
96
+ log "xcodebuild", action
97
+
98
+ options = []
99
+ options << "-workspace '#{@workspace}'" if @workspace
100
+ options << "-project '#{@project}'" if @project
101
+ options << "-scheme '#{@scheme}'" if @scheme
102
+
103
+ `xcodebuild #{options.join(" ")} -sdk macosx DSTROOT='./.mesmerize' #{action}`# 1> /dev/null 2> /dev/null`
104
+ end
105
+
106
+
107
+ @filename = "#{@app['name']}-#{@version}.zip"
108
+ `pushd .mesmerize/Applications; zip -r #{@filename} #{@app['name']}.app; popd`
109
+
110
+ @file = ".mesmerize/Applications/" + @filename
111
+
112
+ log "upload", @filename
113
+
114
+ client.post_release(@appSlug, @version, @file) do |status, body|
115
+ if (200...300).include?(status) || status.nil?
116
+ say_ok "Successfully created release, #{@app['name']} r#{@version}"
117
+ else
118
+ abort "Unable to create release"
119
+ end
120
+ end
121
+ rescue Mesmerize::XcodeBuildInfo::NilOutputError
122
+ say_error "Current directory does not seem to contain valid project or workspace" and abort
123
+ rescue Mesmerize::XcodeBuildInfo::Error => e
124
+ say_error "Xcode Build Error: #{e}" and abort
125
+ rescue => e
126
+ say_error "Error: #{e}" and abort
127
+ ensure
128
+ `rm -rf .mesmerize`
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,25 @@
1
+ command :signup do |c|
2
+ c.syntax = 'mesmerize signup'
3
+ c.summary = 'Create a new account'
4
+ c.description = ''
5
+ c.example 'description', 'command example'
6
+
7
+ c.action do |args, options|
8
+ warn_if_currently_authenticated!
9
+
10
+ say "Enter your Mesmerize Credentials"
11
+ @name = ask "Name:"
12
+ @email = ask "Email:"
13
+ @password = password "Password (typing will be hidden):"
14
+
15
+ client.post_account(@name, @email, @password) do |status, body|
16
+ if (200...300).include?(status)
17
+ say_ok "Successfully logged in"
18
+ config.reset!
19
+ config.update(body)
20
+ else
21
+ say_error "Could not create an account. Please contact support@mesmerizeapp.com if this problem continues."
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'ostruct'
2
+
3
+ module Mesmerize::XcodeBuildInfo
4
+ class Info < OpenStruct; end
5
+
6
+ class Error < StandardError; end
7
+ class NilOutputError < Error; end
8
+
9
+ class << self
10
+ def info
11
+ output = `xcodebuild -list 2> /dev/null`
12
+ raise Error.new $1 if /^xcodebuild\: error\: (.+)$/ === output
13
+ raise NilOutputError unless /\S/ === output
14
+
15
+ lines = output.split(/\n/)
16
+ hash = {project: lines.shift.match(/\"(.+)\"\:/)[1]}
17
+ group = nil
18
+
19
+ lines.each do |line|
20
+ if /\:$/ === line
21
+ group = line.strip[0...-1].downcase.gsub(/\s+/, '-')
22
+ hash[group] = []
23
+ next
24
+ end
25
+
26
+ unless group.nil? or /\.$/ === line
27
+ hash[group] << line.strip
28
+ end
29
+ end
30
+
31
+ Info.new(hash)
32
+ end
33
+ end
34
+ end
data/mesmerize.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mesmerize"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mesmerize"
7
+ s.authors = ["Mattt Thompson"]
8
+ s.email = "m@mattt.me"
9
+ s.homepage = "http://mesmerizeapp.com"
10
+ s.version = Mesmerize::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.summary = "Mesmerize CLI"
13
+ s.description = "Command-Line Interface for Mesmerize"
14
+
15
+ s.add_development_dependency "rspec", "~> 0.6.1"
16
+ s.add_development_dependency "rake", "~> 0.9.2"
17
+
18
+ s.add_dependency "commander", "~> 4.1.2"
19
+ s.add_dependency "faraday", "~> 0.8.0"
20
+ s.add_dependency "faraday_middleware", "~> 0.8.7"
21
+ s.add_dependency "netrc", "~> 0.7.2"
22
+
23
+ s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mesmerize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mattt Thompson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70309173732500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.6.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70309173732500
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70309173718220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70309173718220
36
+ - !ruby/object:Gem::Dependency
37
+ name: commander
38
+ requirement: &70309173717180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 4.1.2
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70309173717180
47
+ - !ruby/object:Gem::Dependency
48
+ name: faraday
49
+ requirement: &70309173715980 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70309173715980
58
+ - !ruby/object:Gem::Dependency
59
+ name: faraday_middleware
60
+ requirement: &70309173714900 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.8.7
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70309173714900
69
+ - !ruby/object:Gem::Dependency
70
+ name: netrc
71
+ requirement: &70309173713820 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.7.2
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70309173713820
80
+ description: Command-Line Interface for Mesmerize
81
+ email: m@mattt.me
82
+ executables:
83
+ - mesmerize
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - ./Gemfile
88
+ - ./Gemfile.lock
89
+ - ./lib/mesmerize/agvtool.rb
90
+ - ./lib/mesmerize/authentication.rb
91
+ - ./lib/mesmerize/client.rb
92
+ - ./lib/mesmerize/commands/create.rb
93
+ - ./lib/mesmerize/commands/login.rb
94
+ - ./lib/mesmerize/commands/logout.rb
95
+ - ./lib/mesmerize/commands/release.rb
96
+ - ./lib/mesmerize/commands/signup.rb
97
+ - ./lib/mesmerize/commands.rb
98
+ - ./lib/mesmerize/xcodebuildinfo.rb
99
+ - ./lib/mesmerize.rb
100
+ - ./mesmerize.gemspec
101
+ - ./Rakefile
102
+ - ./README.md
103
+ - bin/mesmerize
104
+ homepage: http://mesmerizeapp.com
105
+ licenses: []
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ segments:
117
+ - 0
118
+ hash: -2006340050113562150
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ segments:
126
+ - 0
127
+ hash: -2006340050113562150
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.15
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Mesmerize CLI
134
+ test_files: []