monk-shake 1.0.0.pre1 → 1.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ v1.0.0.pre2
2
+ -----------
3
+
4
+ * `monk install` shows what gemset it's being installed to.
5
+
6
+ * `monk add` now will stop you if you try to update the default skeleton.
7
+
8
+ * `monk init` will use the same RVM Ruby version patch level if RVM is installed.
9
+
10
+ * `monk lock` will back up your old .gems file if needed.
11
+
12
+ v1.0.0.pre1
13
+ -----------
14
+
15
+ * Initial.
data/README.md CHANGED
@@ -1,29 +1,49 @@
1
- Monk
2
- ====
1
+ Monk-shake
2
+ ==========
3
3
 
4
- A feature-complete rewrite of Monk that uses Shake instead of Thor.
5
- It is modeled after Monk 1.0 beta.
4
+ #### Monk lets you build Sinatra applications quickly and painlessly by letting it set up the directory structure for you.
6
5
 
7
- See more info in [monkrb.com](http://www.morkrb.com).
6
+ ----
8
7
 
9
- **NOTE:** This is NOT an official replacement for Monk, nor is it
10
- supported or endorsed by Citrusbyte.
8
+ Monk-shake is an UNOFFICIAL feature-complete rewrite of Monk that uses the
9
+ lightweight and superfast [Shake](http://github.com/rstacruz/shake)
10
+ instead of Thor. It is modeled after Monk 1.0 beta. See more info
11
+ at [monkrb.com](http://www.morkrb.com).
11
12
 
12
- ### What is it?
13
+ **NOTE:** *This is NOT an official replacement for Monk, nor is it
14
+ supported or endorsed by Citrusbyte.*
13
15
 
14
- * Monk lets you start a Sinatra project painlessly with everything set
15
- up for you.
16
+ ## Get started
16
17
 
17
- ### Get started
18
+ You may need to uninstall the original monk gem. \*
18
19
 
19
- You may need to uninstall the original monk gem.
20
+ $ rvm @global # TIP: Recommended for RVM users
21
+ $ gem uninstall monk
20
22
 
21
- $ rvm @global # TIP: Recommended for RVM users
22
- $ gem uninstall monk
23
- $ gem install monk-shake --pre
24
- $ monk
23
+ Install it:
25
24
 
26
- ### Differences from the real Monk in general
25
+ $ gem install monk-shake --pre
26
+
27
+ Try it out! This should help you get started:
28
+
29
+ $ monk
30
+
31
+ Now create your first project:
32
+
33
+ $ monk init myproject
34
+
35
+ You'll get a new directory called `myproject/`. Start hacking!
36
+ Monk-shake provides the following commands while in your
37
+ project folder:
38
+
39
+ $ cd myproject/
40
+ $ monk install # Install needed gems
41
+ $ monk start # Starts the server
42
+ $ monk irb # Starts a console session
43
+
44
+ *(\* = Alternatively, you can install monk-shake in a new RVM gemset instead. This means you will need to install it in your Monk-shake projects's gemsets too, however!)*
45
+
46
+ ## Differences from the official Monk
27
47
 
28
48
  * *No more Thor!* The new Monkfile has deprecated the old Thorfile.
29
49
  This version uses Shake instead.
@@ -57,3 +77,16 @@ You may need to uninstall the original monk gem.
57
77
  * `monk install` will first check if a gem is installed. It will not
58
78
  try to reinstall gems you already have.
59
79
 
80
+ Authors
81
+ =======
82
+
83
+ Monk-shake is a derivative work by [Rico Sta. Cruz](http://www.ricostacruz.com),
84
+ heavily based on the original implementations of [Monk](http://www.monkrb.com).
85
+
86
+ Released under the MIT license.
87
+
88
+ Monk (the original [1.0 beta](http://github.com/monk/monk) and
89
+ [0.x](https://github.com/monkrb/monk) implementations) is
90
+ copyright (c) 2009 Michel Martens and Damian Janowski. All credit
91
+ goes out to their (and contributors) hard work for the original idea,
92
+ the API and the Monk skeletons.
@@ -4,15 +4,19 @@ require 'fileutils'
4
4
  require 'shake'
5
5
 
6
6
  class Monk < Shake
7
- VERSION = "1.0.0.pre1"
7
+ VERSION = "1.0.0.pre2"
8
8
  PREFIX = File.expand_path('../monk', __FILE__)
9
9
 
10
10
  autoload :Helpers, "#{PREFIX}/helpers"
11
11
  autoload :InitHelpers, "#{PREFIX}/init_helpers"
12
+ autoload :RvmHelpers, "#{PREFIX}/rvm_helpers"
13
+ autoload :FileHelpers, "#{PREFIX}/file_helpers"
12
14
  autoload :Config, "#{PREFIX}/config"
13
15
 
14
16
  extend Helpers
15
17
  extend InitHelpers
18
+ extend FileHelpers
19
+ extend RvmHelpers
16
20
 
17
21
  task(:init) do
18
22
  name = params.extract('-s') || 'default'
@@ -36,8 +40,13 @@ class Monk < Shake
36
40
  in_path (target) {
37
41
  rm_rf '.git'
38
42
  touch 'Monkfile'
39
- system_q "rvm #{RUBY_VERSION}@#{target} --rvmrc --create" if rvm?
40
- system_q "rvm rvmrc trust" if rvm?
43
+ if rvm?
44
+ rvm "#{rvm_ruby_version}@#{target} --rvmrc --create", :output => true
45
+ rvm "rvmrc trust", :output => true
46
+ else
47
+ puts
48
+ puts "RVM not installed, skipping creating .rvmrc."
49
+ end
41
50
  }
42
51
 
43
52
  puts
@@ -49,25 +58,23 @@ class Monk < Shake
49
58
  puts
50
59
 
51
60
  if rvm?
52
- puts "An RVM gemset @#{target} has been created for you."
61
+ puts "The RVM gemset #{rvm_ruby_version}@#{target} has been created for you."
53
62
  puts
54
63
  end
55
64
  end
56
65
 
57
66
  task(:install) do
58
- manifest = '.gems'
59
-
60
- pass "This project does not have a .gems manifest." unless File.exists?(manifest)
61
-
62
- gems = File.read(manifest).split("\n")
67
+ pass "This project does not have a .gems manifest." unless File.exists?('.gems')
63
68
 
64
- gems.reject! { |name| name =~ /^\s*(#|$)/ }
69
+ gems = gems_from_manifest
65
70
  pass "The .gems manifest is empty." unless gems.any?
66
71
 
67
72
  gems.reject! { |name| has_gem? name }
68
73
  pass "All good! You have all needed gems installed." unless gems.any?
69
74
 
70
- unless rvm?
75
+ if rvm?
76
+ say_status :info, "Installing to RVM gemset #{rvm_gemset}."
77
+ else
71
78
  err "Tip: RVM is a great way to manage gems across multiple projects."
72
79
  err "See http://rvm.beginrescueend.com for more info."
73
80
  err
@@ -78,20 +85,23 @@ class Monk < Shake
78
85
 
79
86
  task(:unpack) do
80
87
  ensure_rvm or pass
81
- system "rvm rvmrc load"
82
- system "rvm gemset unpack vendor"
88
+ rvm "rvmrc load"
89
+ rvm "gemset unpack vendor"
83
90
  end
84
91
 
85
92
  task(:lock) do
86
93
  ensure_rvm or pass
87
- system "rvm rvmrc load"
88
- system "rvm gemset export .gems"
94
+ backup_gems_file if File.exists?('.gems')
95
+ rvm "rvmrc load"
96
+ rvm "gemset export .gems"
89
97
  end
90
98
 
91
99
  task(:add) do
92
100
  wrong_usage unless params.size == 2
93
101
  name, repo = params
94
102
 
103
+ pass "You can't update the default skeleton." if name == 'default'
104
+
95
105
  existed = !!config.skeletons[name]
96
106
 
97
107
  config.skeletons[name] = repo
@@ -0,0 +1,28 @@
1
+ module Monk::FileHelpers
2
+ # File helpers
3
+ def touch(target)
4
+ say_status :touch, target
5
+ FileUtils.touch target
6
+ end
7
+
8
+ def mkdir_p(target)
9
+ return if File.directory?(target)
10
+ say_status :mkdir, target
11
+ FileUtils.mkdir_p target
12
+ end
13
+
14
+ def cp_r(from, target)
15
+ say_status :copy, "#{from} -> #{target}"
16
+ FileUtils.cp_r from, target
17
+ end
18
+
19
+ def mv(from, target)
20
+ say_status :move, "#{from} -> #{target}"
21
+ FileUtils.mv from, target
22
+ end
23
+
24
+ def rm_rf(target)
25
+ say_status :delete, target
26
+ FileUtils.rm_rf target
27
+ end
28
+ end
@@ -1,6 +1,3 @@
1
- # All these functions are available as Monk.xxxx.
2
- # (eg, Monk.tasks_for)
3
- #
4
1
  module Monk::Helpers
5
2
  def config
6
3
  @config ||= Monk::Config.load
@@ -14,15 +11,10 @@ module Monk::Helpers
14
11
  tasks.select { |name, t| t.category.nil? }
15
12
  end
16
13
 
17
- def rvm?
18
- @has_rvm = (!! `rvm` rescue false) if @has_rvm.nil?
19
- @has_rvm
20
- end
21
-
22
- def ensure_rvm
23
- return true if rvm?
24
- err "You need RVM installed for this command."
25
- err "See http://rvm.beginrescueend.com for more info."
14
+ # Reads the gems manifest file and returns the gems to be installed.
15
+ def gems_from_manifest(manifest='.gems')
16
+ gems = File.read(manifest).split("\n")
17
+ gems.reject { |name| name =~ /^\s*(#|$)/ }
26
18
  end
27
19
 
28
20
  # Checks if a certain gem is installed.
@@ -99,31 +91,13 @@ module Monk::Helpers
99
91
  `#{cmd}`
100
92
  end
101
93
 
102
- def say_status(what, cmd)
103
- c1 = "\033[0;33m"
104
- c0 = "\033[0;m"
105
- puts "#{c1}%10s#{c0} %s" % [ what, cmd ]
106
- end
107
-
108
- # File helpers
109
- def touch(target)
110
- say_status :touch, target
111
- FileUtils.touch target
94
+ def say_info(str)
95
+ say_status '*', str, 30
112
96
  end
113
97
 
114
- def mkdir_p(target)
115
- return if File.directory?(target)
116
- say_status :mkdir, target
117
- FileUtils.mkdir_p target
118
- end
119
-
120
- def cp_r(from, target)
121
- say_status :copy, "#{from} -> #{target}"
122
- FileUtils.cp_r from, target
123
- end
124
-
125
- def rm_rf(target)
126
- say_status :delete, target
127
- FileUtils.rm_rf target
98
+ def say_status(what, cmd, color=32)
99
+ c1 = "\033[0;#{color}m"
100
+ c0 = "\033[0;m"
101
+ puts "#{c1}%10s#{c0} %s" % [ what, cmd ]
128
102
  end
129
103
  end
@@ -31,4 +31,12 @@ module Monk::InitHelpers
31
31
  def git_clone(repo, path)
32
32
  system "git clone --depth 1 #{repo} #{path}"
33
33
  end
34
+
35
+ def backup_gems_file(manifest='.gems')
36
+ if File.exists?(manifest)
37
+ time = File.mtime(manifest).strftime('%Y%m%d')
38
+ say_info "#{manifest} file exists; moving aside to preserve."
39
+ mv manifest, "#{manifest}.#{time}"
40
+ end
41
+ end
34
42
  end
@@ -0,0 +1,26 @@
1
+ module Monk::RvmHelpers
2
+ def rvm?
3
+ @has_rvm = (!! `rvm` rescue false) if @has_rvm.nil?
4
+ @has_rvm
5
+ end
6
+
7
+ # Returns the name of the current RVM gemset.
8
+ def rvm_gemset
9
+ File.basename(`rvm current`.strip)
10
+ end
11
+
12
+ def rvm_ruby_version
13
+ rvm_gemset.split('@').first
14
+ end
15
+
16
+ def rvm(cmd, options={})
17
+ return `rvm #{cmd}` if options[:output]
18
+ system "rvm #{cmd}"
19
+ end
20
+
21
+ def ensure_rvm
22
+ return true if rvm?
23
+ err "You need RVM installed for this command."
24
+ err "See http://rvm.beginrescueend.com for more info."
25
+ end
26
+ end
@@ -59,5 +59,19 @@ scope do
59
59
  assert cerr.include?('No such skeleton')
60
60
  end
61
61
 
62
+ test 'no rvm' do
63
+ monk 'init x'
64
+ assert cout.include?("skipping creating .rvmrc")
65
+ assert rvm_commands.empty?
66
+ end
67
+
68
+ test 'with rvm' do
69
+ $has_rvm = true
70
+ monk 'init x'
71
+ assert !cout.include?("skipping creating .rvmrc")
72
+ assert rvm_commands.to_s.include?('--rvmrc')
73
+ assert rvm_commands.to_s.include?('rvmrc trust')
74
+ end
75
+
62
76
  # TODO: git fail test
63
77
  end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ scope do
4
+ test 'lock' do
5
+ monk 'lock'
6
+ assert cerr.include?('You need RVM')
7
+ end
8
+
9
+ scope do
10
+ prepare do
11
+ $has_rvm = true
12
+ end
13
+
14
+ test 'lock rvm' do
15
+ monk 'lock'
16
+ assert rvm_commands.include?('gemset export .gems')
17
+ end
18
+
19
+ test 'backup gems' do
20
+ FileUtils.touch '.gems'
21
+ monk 'lock'
22
+ assert cout.include?('moving aside to preserve')
23
+ assert Dir['.gems.*'].any?
24
+ assert rvm_commands.include?('gemset export .gems')
25
+ end
26
+ end
27
+ end
@@ -25,6 +25,16 @@ module Monk::InitHelpers
25
25
  end
26
26
  end
27
27
 
28
+ module Monk::RvmHelpers
29
+ def rvm?
30
+ $has_rvm
31
+ end
32
+
33
+ def rvm(cmd, options={})
34
+ $rvm << cmd
35
+ end
36
+ end
37
+
28
38
  # Config will never load the config file
29
39
  class Monk::Config
30
40
  def self.load
@@ -10,6 +10,7 @@ require File.expand_path('../mock', __FILE__)
10
10
  def monk(cmd)
11
11
  $out = ''
12
12
  $err = ''
13
+ $rvm = Array.new
13
14
 
14
15
  Monk.load_monkfile
15
16
  Monk.run *Shellwords.shellsplit(cmd)
@@ -23,6 +24,10 @@ def cerr
23
24
  $err
24
25
  end
25
26
 
27
+ def rvm_commands
28
+ $rvm
29
+ end
30
+
26
31
  def assert_invalid
27
32
  assert cout.empty?
28
33
  assert cerr.include?('Invalid usage')
@@ -45,4 +50,5 @@ prepare do
45
50
  Dir.chdir tmp_path
46
51
  Monk.instance_variable_set :@config, nil
47
52
  FileUtils.rm_rf 'Monkfile'
53
+ $has_rvm = false
48
54
  end
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: monk-shake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.0.0.pre1
5
+ version: 1.0.0.pre2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-15 00:00:00 +08:00
13
+ date: 2011-02-16 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,15 +36,23 @@ extra_rdoc_files: []
36
36
  files:
37
37
  - bin/monk
38
38
  - lib/monk/config.rb
39
+ - lib/monk/file_helpers.rb
39
40
  - lib/monk/helpers.rb
40
41
  - lib/monk/init_helpers.rb
42
+ - lib/monk/rvm_helpers.rb
41
43
  - lib/monk.rb
42
44
  - test/add_test.rb
43
45
  - test/help_test.rb
44
46
  - test/init_test.rb
47
+ - test/lock_test.rb
45
48
  - test/mock.rb
46
49
  - test/test_helper.rb
50
+ - test/tmp/default/init.rb
51
+ - test/tmp/default/Monkfile
52
+ - test/tmp/x/init.rb
53
+ - test/tmp/x/Monkfile
47
54
  - README.md
55
+ - CHANGELOG
48
56
  has_rdoc: true
49
57
  homepage: http://www.github.com/rstacruz/monk-shake
50
58
  licenses: []