rigit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9225e47cd4053ff2b58617293897271b9336f625e705de83b00c27bd0ee62035
4
+ data.tar.gz: 378721971c76ee5acc9e2bb0d056112e09b131d2bff464fa63b84c5f6b8c2278
5
+ SHA512:
6
+ metadata.gz: bcdf50376677c22d94ba59b73a85ef87c378fac414fe4469faa55cd2fee44b1ac5644179c0be4913a1f205d6c79cb5ec2cc0426d6cd55e90144c4d112a462b6f
7
+ data.tar.gz: bdb7363fc79e942b5b8299d94da698e1af724420363cef5b76bef4068887f1ccc16b58d8ca124f9219c95111e337db7de7da0f8a87e163c9fdf512dd7c917346
data/bin/rig ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rigit'
3
+
4
+ begin
5
+ Rigit::CommandLine.execute ARGV
6
+ rescue Rigit::Exit => e
7
+ puts e.message
8
+ exit 1
9
+ rescue Rigit::ConfigError => e
10
+ puts "#{e.class} - #{e.message}"
11
+ exit 1
12
+ rescue TTY::Reader::InputInterrupt
13
+ puts "\nGoodbye"
14
+ exit 1
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'super_docopt'
2
+ require 'rigit/version'
3
+
4
+ module Rigit
5
+ class CommandLine < SuperDocopt::Base
6
+ version VERSION
7
+ docopt File.expand_path 'docopt.txt', __dir__
8
+ subcommands [:build]
9
+
10
+ include Commands::Build
11
+ end
12
+ end
@@ -0,0 +1,83 @@
1
+ require 'super_docopt'
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
12
+
13
+ def initialize(args)
14
+ @args = args
15
+ end
16
+
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
24
+
25
+ private
26
+
27
+ def config
28
+ @config ||= config_for source
29
+ end
30
+
31
+ def source
32
+ args['RIG']
33
+ end
34
+
35
+ def target_dir
36
+ '.'
37
+ end
38
+
39
+ def source_dir
40
+ "#{ENV['RIG_HOME']}/#{source}"
41
+ end
42
+
43
+ def params
44
+ @params ||= params!
45
+ end
46
+
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
55
+ end
56
+
57
+ def prompt
58
+ @prompt ||= Rigit::Prompt.new config.params
59
+ end
60
+
61
+ def tty_prompt
62
+ @tty_prompt ||= TTY::Prompt.new
63
+ end
64
+
65
+ def config_for(source)
66
+ Rigit::Config.load("#{ENV['RIG_HOME']}/#{source}/config.yml")
67
+ end
68
+
69
+ def verify_folders
70
+ if !Dir.exist? source_dir
71
+ raise Rigit::Exit, "No such rig: #{source}"
72
+ end
73
+
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
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,26 @@
1
+ require 'configatron/core'
2
+ require 'yaml'
3
+
4
+ module Rigit
5
+ class Config
6
+ attr_reader :path
7
+
8
+ def self.load(path)
9
+ new(path).settings
10
+ end
11
+
12
+ def initialize(path)
13
+ @path = path
14
+ end
15
+
16
+ def settings
17
+ @settings ||= settings!
18
+ end
19
+
20
+ def settings!
21
+ settings = Configatron::RootStore.new
22
+ settings.configure_from_hash YAML.load_file(path)
23
+ settings
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ Rigit
2
+
3
+ Usage:
4
+ rig build RIG [PARAMS...]
5
+
6
+ Parameters:
7
+ RIG
8
+ The name of the source folder (installed rig).
9
+
10
+ Examples:
11
+ rig build gem name=mygem
@@ -0,0 +1,4 @@
1
+ module Rigit
2
+ class Exit < StandardError; end
3
+ class ConfigError < ArgumentError; end
4
+ end
@@ -0,0 +1,10 @@
1
+ require 'fileutils'
2
+
3
+ class File
4
+ def self.deep_write(filename, content)
5
+ dirname = File.dirname filename
6
+ FileUtils.mkdir_p dirname unless File.directory? dirname
7
+ File.write filename, content
8
+ end
9
+ end
10
+
@@ -0,0 +1,41 @@
1
+ require 'tty-prompt'
2
+
3
+ module Rigit
4
+ class Prompt
5
+ attr_reader :params
6
+
7
+ def initialize(params)
8
+ @params = params
9
+ end
10
+
11
+ def get_input(prefill={})
12
+ result = {}
13
+ params.each do |key, spec|
14
+ result[key] = prefill.has_key?(key) ? prefill[key] : ask(spec)
15
+ end
16
+ result
17
+ end
18
+
19
+ private
20
+
21
+ def ask(param)
22
+ text = param.prompt
23
+ default = param.default
24
+
25
+ case param[:type]
26
+ when 'yesno'
27
+ prompt.yes?(text, default: default) ? 'yes' : 'no'
28
+ when 'text'
29
+ prompt.ask text, default: default
30
+ when 'select'
31
+ prompt.select text, param.list, marker: '>'
32
+ else
33
+ raise ConfigError, "Unknown type '#{param[:type]}'"
34
+ end
35
+ end
36
+
37
+ def prompt
38
+ @prompt ||= TTY::Prompt.new
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,3 @@
1
+ module Rigit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rigit.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rigit/extensions/file_extension.rb'
2
+
3
+ require 'rigit/commands/build'
4
+
5
+ require 'rigit/command_line'
6
+ require 'rigit/config'
7
+ require 'rigit/errors'
8
+ require 'rigit/prompt'
9
+ require 'rigit/rigger'
10
+
11
+ ENV['RIG_HOME'] ||= File.expand_path('.rigs', Dir.home)
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rigit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: super_docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: configatron
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-prompt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.15'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_fixtures
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: runfile
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: runfile-tasks
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.4'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.15'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.15'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.9'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.9'
167
+ description: Build project templates with ease
168
+ email: db@dannyben.com
169
+ executables:
170
+ - rig
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - bin/rig
175
+ - lib/rigit.rb
176
+ - lib/rigit/command_line.rb
177
+ - lib/rigit/commands/build.rb
178
+ - lib/rigit/config.rb
179
+ - lib/rigit/docopt.txt
180
+ - lib/rigit/errors.rb
181
+ - lib/rigit/extensions/file_extension.rb
182
+ - lib/rigit/prompt.rb
183
+ - lib/rigit/rigger.rb
184
+ - lib/rigit/version.rb
185
+ homepage: https://github.com/DannyBen/rigit
186
+ licenses:
187
+ - MIT
188
+ metadata: {}
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: 2.4.0
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 2.7.3
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: Zero-coding project scaffolding
209
+ test_files: []