rigit 0.0.1 → 0.0.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
  SHA256:
3
- metadata.gz: 9225e47cd4053ff2b58617293897271b9336f625e705de83b00c27bd0ee62035
4
- data.tar.gz: 378721971c76ee5acc9e2bb0d056112e09b131d2bff464fa63b84c5f6b8c2278
3
+ metadata.gz: 55f146cc6a111bbb185a681203d87a7cf5092ce5f461e3e1aac4aec11bd121aa
4
+ data.tar.gz: 46990712e2b86bd1b1c8785084d6e1b02e18f05de2248030a41e21ec8b7049b8
5
5
  SHA512:
6
- metadata.gz: bcdf50376677c22d94ba59b73a85ef87c378fac414fe4469faa55cd2fee44b1ac5644179c0be4913a1f205d6c79cb5ec2cc0426d6cd55e90144c4d112a462b6f
7
- data.tar.gz: bdb7363fc79e942b5b8299d94da698e1af724420363cef5b76bef4068887f1ccc16b58d8ca124f9219c95111e337db7de7da0f8a87e163c9fdf512dd7c917346
6
+ metadata.gz: 8f33dbd202c77428e16e05bf42441b6359b49132ef78a977608d13029414327441c163e44e390957fb5182fc7554948e86ef359b4598daa4d794d8726280c5e2
7
+ data.tar.gz: 84f92225b7b0edeba9a5a4583a097ccac9047dc5e2b1fe837bd19be45ecf4f08c5be5d96e93530d3bf21be282613eb97d8117e49d01ba7552eed537a1ab670db
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ Rigit
2
+ ==================================================
3
+
4
+ [![Gem](https://img.shields.io/gem/v/rigit.svg?style=flat-square)](https://rubygems.org/gems/rigit)
5
+ [![Build](https://img.shields.io/travis/DannyBen/rigit.svg?style=flat-square)](https://travis-ci.org/DannyBen/rigit)
6
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/DannyBen/rigit.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/rigit)
7
+ [![Issues](https://img.shields.io/codeclimate/issues/github/DannyBen/rigit.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/rigit)
8
+
9
+ ---
10
+
11
+ ![Rigit](rigit-header.png)
12
+
13
+ ---
14
+
15
+ Table of Contents
16
+ --------------------------------------------------
17
+
18
+ * [Installation](#installation)
19
+ * [Quick Start](#quick-start)
20
+ * [Installing Rigs](#installing-rigs)
21
+ * [Using Rigs (Scaffolding)](#using-rigs-scaffolding)
22
+ * [Creating Rigs](#creating-rigs)
23
+ * [Directory Structure](#directory-structure)
24
+ * [Config File](#config-file)
25
+
26
+
27
+ Installation
28
+ --------------------------------------------------
29
+
30
+
31
+ Quick Start
32
+ --------------------------------------------------
33
+
34
+
35
+ Installing Rigs
36
+ --------------------------------------------------
37
+
38
+
39
+ Using Rigs (Scaffolding)
40
+ --------------------------------------------------
41
+
42
+
43
+ Creating Rigs
44
+ --------------------------------------------------
45
+
46
+ ### Directory Structure
47
+
48
+ ### Config File
49
+
data/bin/rig CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rigit'
3
+ require 'colsole'
4
+ include Colsole
3
5
 
4
6
  begin
5
7
  Rigit::CommandLine.execute ARGV
6
8
  rescue Rigit::Exit => e
7
- puts e.message
9
+ message = e.message
10
+ say message unless message == 'Rigit::Exit'
8
11
  exit 1
9
12
  rescue Rigit::ConfigError => e
10
- puts "#{e.class} - #{e.message}"
13
+ say "#{e.class} - #{e.message}"
11
14
  exit 1
12
15
  rescue TTY::Reader::InputInterrupt
13
- puts "\nGoodbye"
16
+ say "\nGoodbye"
14
17
  exit 1
15
18
  end
@@ -5,8 +5,9 @@ module Rigit
5
5
  class CommandLine < SuperDocopt::Base
6
6
  version VERSION
7
7
  docopt File.expand_path 'docopt.txt', __dir__
8
- subcommands [:build]
8
+ subcommands [:build, :install]
9
9
 
10
10
  include Commands::Build
11
+ include Commands::Install
11
12
  end
12
13
  end
@@ -1,81 +1,77 @@
1
- require 'super_docopt'
1
+ require 'colsole'
2
2
 
3
- module Rigit
4
- module Commands
5
- module Build
6
- def build
7
- Builder.new(args).execute
8
- end
9
-
10
- class Builder
11
- attr_reader :args
3
+ module Rigit::Commands
4
+ module Build
5
+ def build
6
+ Builder.new(args).execute
7
+ end
12
8
 
13
- def initialize(args)
14
- @args = args
15
- end
9
+ class Builder
10
+ attr_reader :args, :rig_name, :target_dir
16
11
 
17
- def execute
18
- puts "#{config.intro}\n\n" if config.intro
19
- verify_folders
20
- arguments = prompt.get_input params
21
- rigger = Rigit::Rigger.new source, arguments
22
- rigger.scaffold
23
- end
12
+ include Colsole
24
13
 
25
- private
14
+ def initialize(args)
15
+ @args = args
16
+ @rig_name = args['RIG']
17
+ @target_dir = '.'
18
+ end
26
19
 
27
- def config
28
- @config ||= config_for source
29
- end
20
+ def execute
21
+ say "Building !txtgrn!#{rig_name}"
22
+ say "!txtblu!#{config.intro}" if config.has_key? :intro
23
+ verify_dirs
24
+ arguments = prompt.get_input params
25
+ rig.scaffold arguments:arguments, target_dir: target_dir
26
+ say "Done"
27
+ end
30
28
 
31
- def source
32
- args['RIG']
33
- end
29
+ private
34
30
 
35
- def target_dir
36
- '.'
37
- end
31
+ def rig
32
+ @rig ||= Rigit::Rig.new rig_name
33
+ end
38
34
 
39
- def source_dir
40
- "#{ENV['RIG_HOME']}/#{source}"
41
- end
35
+ def config
36
+ @config ||= rig.config
37
+ end
42
38
 
43
- def params
44
- @params ||= params!
45
- end
39
+ def params
40
+ @params ||= params!
41
+ end
46
42
 
47
- def params!
48
- output = {}
49
- input = args['PARAMS']
50
- input.each do |param|
51
- key, value = param.split '='
52
- output[key.to_sym] = value
53
- end
54
- output
43
+ def params!
44
+ output = {}
45
+ input = args['PARAMS']
46
+ input.each do |param|
47
+ key, value = param.split '='
48
+ output[key.to_sym] = value
55
49
  end
50
+ output
51
+ end
56
52
 
57
- def prompt
58
- @prompt ||= Rigit::Prompt.new config.params
59
- end
53
+ def prompt
54
+ @prompt ||= Rigit::Prompt.new config.params
55
+ end
60
56
 
61
- def tty_prompt
62
- @tty_prompt ||= TTY::Prompt.new
63
- end
57
+ def tty_prompt
58
+ @tty_prompt ||= TTY::Prompt.new
59
+ end
64
60
 
65
- def config_for(source)
66
- Rigit::Config.load("#{ENV['RIG_HOME']}/#{source}/config.yml")
67
- end
61
+ def verify_dirs
62
+ verify_source_dir
63
+ verify_target_dir
64
+ end
68
65
 
69
- def verify_folders
70
- if !Dir.exist? source_dir
71
- raise Rigit::Exit, "No such rig: #{source}"
72
- end
66
+ def verify_source_dir
67
+ raise Rigit::Exit, "No such rig: #{rig_name}" unless rig.exist?
68
+ end
73
69
 
74
- if !Dir.empty? target_dir
75
- dirstring = target_dir == '.' ? 'Current directory' : "Directory '#{target_dir}'"
76
- continue = tty_prompt.yes? "#{dirstring} is not empty. Continue anyway?", default: false
77
- raise Rigit::Exit, "Goodbye" unless continue
78
- end
70
+ def verify_target_dir
71
+ if !Dir.empty? target_dir
72
+ dirstring = target_dir == '.' ? 'Current directory' : "Directory '#{target_dir}'"
73
+ continue = tty_prompt.yes? "#{dirstring} is not empty. Continue anyway?", default: false
74
+ raise Rigit::Exit, "Goodbye" unless continue
79
75
  end
80
76
  end
81
77
  end
@@ -0,0 +1,58 @@
1
+ require 'fileutils'
2
+ require 'colsole'
3
+
4
+ module Rigit::Commands
5
+ module Install
6
+ def install
7
+ Installer.new(args).execute
8
+ end
9
+
10
+ class Installer
11
+ include Colsole
12
+
13
+ attr_reader :args, :rig_name, :repo
14
+
15
+ def initialize(args)
16
+ @args = args
17
+ @rig_name = args['RIG']
18
+ @repo = args['REPO']
19
+ end
20
+
21
+ def execute
22
+ verify_dirs
23
+ install
24
+ end
25
+
26
+ private
27
+
28
+ def install
29
+ say "Installing !txtgrn!#{repo}\n"
30
+ FileUtils.mkdir_p target_path unless Dir.exist? target_path
31
+ success = Git.clone repo, target_path
32
+
33
+ if success
34
+ say "\nRig installed !txtgrn!successfully!txtrst! in !txtgrn!#{target_path}"
35
+ say "To build a new project with this rig, run this in any empty directory:\n"
36
+ say " !txtpur!rig build #{rig_name}\n"
37
+ end
38
+ end
39
+
40
+ def rig
41
+ @rig ||= Rigit::Rig.new rig_name
42
+ end
43
+
44
+ def target_path
45
+ @target_path ||= rig.path
46
+ end
47
+
48
+ def verify_dirs
49
+ if Dir.exist? target_path
50
+ say "Rig !txtgrn!#{rig_name}!txtrst! is already installed."
51
+ say "In order to update it from the source repository, run:\n"
52
+ say " !txtpur!rig update #{rig_name}\n"
53
+ raise Rigit::Exit
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/rigit/config.rb CHANGED
@@ -19,7 +19,7 @@ module Rigit
19
19
 
20
20
  def settings!
21
21
  settings = Configatron::RootStore.new
22
- settings.configure_from_hash YAML.load_file(path)
22
+ settings.configure_from_hash YAML.load_file(path) if File.exist? path
23
23
  settings
24
24
  end
25
25
  end
data/lib/rigit/docopt.txt CHANGED
@@ -2,10 +2,28 @@ Rigit
2
2
 
3
3
  Usage:
4
4
  rig build RIG [PARAMS...]
5
+ rig install RIG REPO
6
+
7
+ Commands:
8
+ build
9
+ Create a new project based on one of the installed rig templates.
10
+ This command should be executed in an empty directory.
11
+ In case the rig has arguments, you will be prompted to input them.
12
+ If you wish to execute this command without interactivity, you may
13
+ use specify all parameters in the PARAMS parameter (see below).
5
14
 
6
15
  Parameters:
7
16
  RIG
8
17
  The name of the source folder (installed rig).
9
18
 
19
+ REPO
20
+ A git repository containing rig configuration.
21
+ Use the 'clone URL' for the repository.
22
+
23
+ PARAMS
24
+ Specify any of the rig's parameters in the format 'param=value'.
25
+ For boolean parameters, use 'param=y' or 'param=n'.
26
+
10
27
  Examples:
11
- rig build gem name=mygem
28
+ rig build gem name=mygem spec=y
29
+ rig install example https://github.com/DannyBen/example-rig.git
@@ -2,9 +2,12 @@ require 'fileutils'
2
2
 
3
3
  class File
4
4
  def self.deep_write(filename, content)
5
+ # :nocov: only due to the fact that the rspec_fixtures gem brings
6
+ # this method as well
5
7
  dirname = File.dirname filename
6
8
  FileUtils.mkdir_p dirname unless File.directory? dirname
7
9
  File.write filename, content
10
+ # :nocov:
8
11
  end
9
12
  end
10
13
 
data/lib/rigit/git.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Rigit
2
+ class Git
3
+ def self.clone(repo, target_path)
4
+ execute %Q[git clone #{repo} "#{target_path}"]
5
+ end
6
+
7
+ private
8
+
9
+ def self.execute(command)
10
+ if ENV['SIMULATE_GIT']
11
+ puts "Simulated Execute: #{command}"
12
+ true
13
+ else
14
+ system command
15
+ $?&.exitstatus == 0
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/rigit/rig.rb ADDED
@@ -0,0 +1,56 @@
1
+ module Rigit
2
+ class Rig
3
+ attr_reader :name
4
+
5
+ def self.home
6
+ ENV['RIG_HOME'] ||= File.expand_path('.rigs', Dir.home)
7
+ end
8
+
9
+ def self.home=(path)
10
+ ENV['RIG_HOME'] = path
11
+ end
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+
17
+ def scaffold(arguments: {}, target_dir:'.')
18
+ scaffold_dir "#{path}/base", arguments, target_dir
19
+
20
+ arguments.each do |key, value|
21
+ additive_dir = "#{path}/#{key}=#{value}"
22
+ if Dir.exist? additive_dir
23
+ scaffold_dir additive_dir, arguments, target_dir
24
+ end
25
+ end
26
+ end
27
+
28
+ def path
29
+ "#{Rig.home}/#{name}"
30
+ end
31
+
32
+ def exist?
33
+ Dir.exist? path
34
+ end
35
+
36
+ def config_file
37
+ "#{path}/config.yml"
38
+ end
39
+
40
+ def config
41
+ @config ||= Config.load(config_file)
42
+ end
43
+
44
+ private
45
+
46
+ def scaffold_dir(dir, arguments, target_dir)
47
+ files = Dir["#{dir}/**/*"].reject { |file| File.directory? file }
48
+
49
+ files.each do |file|
50
+ target_file = (file % arguments).sub dir, target_dir
51
+ content = File.read(file) % arguments
52
+ File.deep_write target_file, content
53
+ end
54
+ end
55
+ end
56
+ end
data/lib/rigit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rigit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/rigit.rb CHANGED
@@ -1,11 +1,16 @@
1
1
  require 'rigit/extensions/file_extension.rb'
2
2
 
3
- require 'rigit/commands/build'
4
-
5
- require 'rigit/command_line'
6
3
  require 'rigit/config'
7
4
  require 'rigit/errors'
8
5
  require 'rigit/prompt'
9
- require 'rigit/rigger'
6
+ require 'rigit/rig'
7
+ require 'rigit/git'
8
+
9
+ require 'rigit/commands/build'
10
+ require 'rigit/commands/install'
11
+ require 'rigit/command_line'
10
12
 
11
- ENV['RIG_HOME'] ||= File.expand_path('.rigs', Dir.home)
13
+ module Rigit
14
+ module Commands
15
+ end
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colsole
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: byebug
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -171,16 +185,19 @@ executables:
171
185
  extensions: []
172
186
  extra_rdoc_files: []
173
187
  files:
188
+ - README.md
174
189
  - bin/rig
175
190
  - lib/rigit.rb
176
191
  - lib/rigit/command_line.rb
177
192
  - lib/rigit/commands/build.rb
193
+ - lib/rigit/commands/install.rb
178
194
  - lib/rigit/config.rb
179
195
  - lib/rigit/docopt.txt
180
196
  - lib/rigit/errors.rb
181
197
  - lib/rigit/extensions/file_extension.rb
198
+ - lib/rigit/git.rb
182
199
  - lib/rigit/prompt.rb
183
- - lib/rigit/rigger.rb
200
+ - lib/rigit/rig.rb
184
201
  - lib/rigit/version.rb
185
202
  homepage: https://github.com/DannyBen/rigit
186
203
  licenses:
data/lib/rigit/rigger.rb DELETED
@@ -1,38 +0,0 @@
1
- module Rigit
2
- class Rigger
3
- attr_reader :rig, :arguments, :target_dir
4
-
5
- def initialize(rig, arguments={}, target_dir='.')
6
- @rig = rig
7
- @target_dir = target_dir
8
- @arguments = arguments
9
- end
10
-
11
- def scaffold
12
- scaffold_dir "#{source_dir}/base"
13
-
14
- arguments.each do |key, value|
15
- additive_dir = "#{source_dir}/#{key}=#{value}"
16
- if Dir.exist? additive_dir
17
- scaffold_dir additive_dir
18
- end
19
- end
20
- end
21
-
22
- private
23
-
24
- def source_dir
25
- "#{ENV['RIG_HOME']}/#{rig}"
26
- end
27
-
28
- def scaffold_dir(dir)
29
- files = Dir["#{dir}/**/*"].reject { |file| File.directory? file }
30
-
31
- files.each do |file|
32
- target_file = (file % arguments).sub dir, target_dir
33
- content = File.read(file) % arguments
34
- File.deep_write target_file, content
35
- end
36
- end
37
- end
38
- end