lono 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 718e48960a1c3a862ff214236f1ca2a41e086074
4
- data.tar.gz: 3d88df2849d2d0c140e1484bfd441de14cf9c477
3
+ metadata.gz: 0cf2d662d15f91ab5a2be1fd65341349b343f8e5
4
+ data.tar.gz: ac0fb9f6cabba24f8d9c486100d2af4841131dc0
5
5
  SHA512:
6
- metadata.gz: 028ceea2ac8e288fe9fbd4c720edd7ab21852b368b3d4b27ce30d523c1aaaf08722ceae4e9d6161f15d7382e4044d739015be252663f5283b3315497da364783
7
- data.tar.gz: a726a5be3d63491b8af498a626b5e4322c9cb2c1453535f9511a90b6bba1fdc89e30a4bd14a52d28751510a407c9138a2502ea5f3416c030e189af816bcfb7fc
6
+ metadata.gz: 02479cb711b6b44348eb0d541cd1669dcc64166c329d67b969180baffba752a7aafd287c672843faa61462f867231edcc763d2be334eaaaeb6a4140f2b9ef700
7
+ data.tar.gz: a8c72b7ab907c2f5b9016a06037f9ef1644df59586fac5618708f2aa9ff91f3a524a4a61433dd9ef3f2de883c53df84da5aa52e3437762754066987352284394
data/README.md CHANGED
@@ -16,10 +16,7 @@ Lono is a Cloud Formation Template ruby generator. Lono generates Cloud Formati
16
16
  ## Usage
17
17
 
18
18
  <pre>
19
- $ gem install lono
20
- $ mkdir lono
21
- $ cd lono
22
- $ lono init
19
+ $ lono new lono
23
20
  </pre>
24
21
 
25
22
  This sets up a starter lono project with example templates.
@@ -1,11 +1,12 @@
1
1
  require 'json'
2
2
  require 'pp'
3
+ require 'colorize'
3
4
 
4
5
  $:.unshift File.dirname(__FILE__)
5
6
  require 'ext/hash'
6
7
  require 'lono/version'
7
8
  require 'lono/cli'
8
- require 'lono/task'
9
+ require 'lono/new'
9
10
  require 'lono/template'
10
11
  require 'lono/dsl'
11
12
  require 'lono/bashify'
@@ -1,36 +1,31 @@
1
1
  require 'thor'
2
+ require 'lono/cli/help'
2
3
 
3
4
  module Lono
4
5
  class CLI < Thor
5
6
 
6
- desc "init", "Setup lono starter project"
7
- long_desc "Sets up config/lono.rb"
8
- method_option :force, :type => :boolean, :aliases => "-f", :desc => "override existing starter files"
9
- method_option :project_root, :default => ".", :aliases => "-r", :desc => "project root"
10
- method_option :quiet, :type => :boolean, :aliases => "-q", :desc => "silence the output"
11
- def init
12
- Lono::Task.init(options.clone)
7
+ desc "new [NAME]", "Generates lono starter project"
8
+ Help.new_long_desc
9
+ option :force, :type => :boolean, :aliases => "-f", :desc => "override existing starter files"
10
+ option :quiet, :type => :boolean, :aliases => "-q", :desc => "silence the output"
11
+ def new(project_root)
12
+ Lono::New.new(options.clone.merge(:project_root => project_root)).run
13
13
  end
14
14
 
15
15
  desc "generate", "Generate the cloud formation templates"
16
- long_desc <<EOL
17
- Examples:
18
-
19
- 1. lono generate
20
- 2. lono g -c # shortcut
21
-
22
- Builds the cloud formation templates files based on config/lono.rb and writes them to the output folder on the filesystem.
23
- EOL
24
- method_option :clean, :type => :boolean, :aliases => "-c", :desc => "remove all output files before generating"
25
- method_option :project_root, :default => ".", :aliases => "-r", :desc => "project root"
26
- method_option :quiet, :type => :boolean, :aliases => "-q", :desc => "silence the output"
16
+ Help.generate
17
+ option :clean, :type => :boolean, :aliases => "-c", :desc => "remove all output files before generating"
18
+ option :project_root, :default => ".", :aliases => "-r", :desc => "project root"
19
+ option :quiet, :type => :boolean, :aliases => "-q", :desc => "silence the output"
20
+ option :pretty, :type => :boolean, :defautlt => true, :desc => "do not json prettier the output"
27
21
  def generate
28
- Lono::Task.generate(options.clone)
22
+ Lono::DSL.new(options.clone).run
29
23
  end
30
24
 
31
- desc "bashify [cloudformation-path]", "Convert the UserData section of an existing Cloud Formation Template to a starter bash script that is compatiable with lono"
25
+ desc "bashify [URL-OR-PATH]", "Convert the UserData section of an existing Cloud Formation Template to a starter bash script that is compatiable with lono"
26
+ Help.bashify
32
27
  def bashify(path)
33
- Lono::Task.bashify(path)
28
+ Lono::Bashify.new(:path => path).run
34
29
  end
35
30
 
36
31
  desc "version", "Prints version"
@@ -0,0 +1,37 @@
1
+ module Lono
2
+ module Help
3
+ def new_long_desc
4
+ <<-EOL
5
+ Examples:
6
+
7
+ $ lono new project
8
+
9
+ $ lono new lono
10
+ EOL
11
+ end
12
+
13
+ def generate
14
+ <<-EOL
15
+ Examples:
16
+
17
+ $ lono generate
18
+
19
+ $ lono g -c # shortcut
20
+
21
+ Builds the cloud formation templates files based on lono project and writes them to the output folder on the filesystem.
22
+ EOL
23
+ end
24
+
25
+ def bashify
26
+ <<-EOL
27
+ Examples:
28
+
29
+ $ lono bashify /path/to/cloudformation-template.json
30
+
31
+ $ lono bashify https://s3.amazonaws.com/cloudformation-templates-us-east-1/EC2WebSiteSample.template
32
+ EOL
33
+ end
34
+
35
+ extend self
36
+ end
37
+ end
@@ -38,11 +38,25 @@ module Lono
38
38
  @results.each do |name,json|
39
39
  path = "#{output_path}/#{name}"
40
40
  puts " #{path}" unless @options[:quiet]
41
- pretty_json = JSON.pretty_generate(JSON.parse(json))
42
- File.open(path, 'w') {|f| f.write(pretty_json) }
41
+ validate(json, path)
42
+ File.open(path, 'w') {|f| f.write(output_json(json)) }
43
43
  end
44
44
  end
45
45
 
46
+ def validate(json, path)
47
+ begin
48
+ JSON.parse(json)
49
+ rescue JSON::ParserError => e
50
+ puts "Invalid json. Output written to #{path} for debugging".colorize(:red)
51
+ File.open(path, 'w') {|f| f.write(json) }
52
+ exit 1
53
+ end
54
+ end
55
+
56
+ def output_json(json)
57
+ @options[:pretty] ? JSON.pretty_generate(JSON.parse(json)) : json
58
+ end
59
+
46
60
  def run(options={})
47
61
  evaluate
48
62
  build
@@ -1,14 +1,19 @@
1
1
  module Lono
2
- class Task
3
- def self.init(options={})
4
- project_root = options[:project_root] || '.'
2
+ class New
3
+ attr_reader :options
4
+ def initialize(options)
5
+ @options = options
6
+ @project_root = options[:project_root] || '.'
7
+ end
8
+
9
+ def run
5
10
  puts "Setting up lono project" unless options[:quiet]
6
11
  source_root = File.expand_path("../../starter_project", __FILE__)
7
12
  paths = Dir.glob("#{source_root}/**/*").
8
13
  select {|p| File.file?(p) }
9
14
  paths.each do |src|
10
15
  dest = src.gsub(%r{.*starter_project/},'')
11
- dest = "#{project_root}/#{dest}"
16
+ dest = "#{@project_root}/#{dest}"
12
17
 
13
18
  if File.exist?(dest) and !options[:force]
14
19
  puts "already exists: #{dest}" unless options[:quiet]
@@ -21,21 +26,5 @@ module Lono
21
26
  end
22
27
  puts "Starter lono project created"
23
28
  end
24
- def self.generate(options)
25
- new(options).generate
26
- end
27
-
28
- def initialize(options={})
29
- @options = options
30
- @dsl = options.empty? ? DSL.new : DSL.new(options)
31
- end
32
- def generate
33
- @dsl.run(@options)
34
- end
35
-
36
- def self.bashify(path)
37
- @bashify = Lono::Bashify.new(:path => path)
38
- @bashify.run
39
- end
40
29
  end
41
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Lono
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'lono'
@@ -1,10 +1,6 @@
1
1
  template "prod-api-app.json" do
2
- env,app,role = name.sub('.json','').split('-')
3
2
  source "app.json.erb"
4
3
  variables(
5
- :env => env,
6
- :app => app,
7
- :role => role,
8
4
  :ami => "ami-123",
9
5
  :instance_type => "m1.small",
10
6
  :port => "80",
@@ -21,12 +17,8 @@ template "prod-api-app.json" do
21
17
  end
22
18
 
23
19
  template "prod-api-worker.json" do
24
- env,app,role = name.sub('.json','').split('-')
25
20
  source "app.json.erb"
26
21
  variables(
27
- :env => env,
28
- :app => app,
29
- :role => role,
30
22
  :ami => "ami-123",
31
23
  :instance_type => "m1.small",
32
24
  :port => "80",
@@ -44,12 +36,8 @@ template "prod-api-worker.json" do
44
36
  end
45
37
 
46
38
  template "prod-api-redis.json" do
47
- env,app,role = name.sub('.json','').split('-')
48
39
  source "db.json.erb"
49
40
  variables(
50
- :env => env,
51
- :app => app,
52
- :role => role,
53
41
  :ami => "ami-456",
54
42
  :instance_type => "m1.small",
55
43
  :port => "80",
@@ -1,3 +1,4 @@
1
+ <% @env,@app,@role = name.sub('.json','').split('-') %>
1
2
  {
2
3
  "AWSTemplateFormatVersion": "2010-09-09",
3
4
  "Description": "<%= @app.capitalize %> Stack",
@@ -1,3 +1,4 @@
1
+ <% @env,@app,@role = name.sub('.json','').split('-') %>
1
2
  {
2
3
  "AWSTemplateFormatVersion": "2010-09-09",
3
4
  "Description": "<%= @app.capitalize %> <%= @role %>",
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "lono"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Lono::VERSION
17
+ gem.license = 'MIT'
17
18
 
18
19
  gem.add_dependency "rake"
19
20
  gem.add_dependency "json"
@@ -23,6 +24,7 @@ Gem::Specification.new do |gem|
23
24
  gem.add_dependency 'rb-fsevent'
24
25
  gem.add_dependency "guard-cloudformation"
25
26
  gem.add_dependency "guard-lono"
27
+ gem.add_dependency "colorize"
26
28
 
27
29
  gem.add_development_dependency 'rspec'
28
30
  gem.add_development_dependency 'guard-rspec'
@@ -2,13 +2,16 @@ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe Lono do
4
4
  before(:each) do
5
- @project = File.expand_path("../../project", __FILE__)
6
- FileUtils.mkdir(@project) unless File.exist?(@project)
7
- execute("./bin/lono init -f -q --project-root #{@project}")
5
+ lono_bin = File.expand_path("../../../bin/lono", __FILE__)
6
+ @project = File.expand_path("../../../tmp/lono_project", __FILE__)
7
+ dir = File.dirname(@project)
8
+ name = File.basename(@project)
9
+ FileUtils.mkdir(dir) unless File.exist?(dir)
10
+ execute("cd #{dir} && #{lono_bin} new #{name} -f -q ")
8
11
  end
9
12
 
10
13
  after(:each) do
11
- FileUtils.rm_rf(@project)
14
+ FileUtils.rm_rf(@project) unless ENV['LEAVE_TMP_PROJECT']
12
15
  end
13
16
 
14
17
  describe "bashify" do
@@ -174,10 +177,10 @@ describe Lono do
174
177
  end
175
178
 
176
179
  it "task should generate cloud formation templates" do
177
- Lono::Task.generate(
180
+ Lono::DSL.new(
178
181
  :project_root => @project,
179
182
  :quiet => true
180
- )
183
+ ).run
181
184
  raw = IO.read("#{@project}/output/prod-api-app.json")
182
185
  json = JSON.load(raw)
183
186
  json['Description'].should == "Api Stack"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: colorize
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -187,10 +201,12 @@ files:
187
201
  - lib/lono.rb
188
202
  - lib/lono/bashify.rb
189
203
  - lib/lono/cli.rb
204
+ - lib/lono/cli/help.rb
190
205
  - lib/lono/dsl.rb
191
- - lib/lono/task.rb
206
+ - lib/lono/new.rb
192
207
  - lib/lono/template.rb
193
208
  - lib/lono/version.rb
209
+ - lib/starter_project/Gemfile
194
210
  - lib/starter_project/Guardfile
195
211
  - lib/starter_project/config/lono.rb
196
212
  - lib/starter_project/config/lono/api.rb
@@ -207,7 +223,8 @@ files:
207
223
  - spec/lib/lono_spec.rb
208
224
  - spec/spec_helper.rb
209
225
  homepage: http://github.com/tongueroo/lono
210
- licenses: []
226
+ licenses:
227
+ - MIT
211
228
  metadata: {}
212
229
  post_install_message:
213
230
  rdoc_options: []