rigit 0.0.2 → 0.0.3

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: 55f146cc6a111bbb185a681203d87a7cf5092ce5f461e3e1aac4aec11bd121aa
4
- data.tar.gz: 46990712e2b86bd1b1c8785084d6e1b02e18f05de2248030a41e21ec8b7049b8
3
+ metadata.gz: d0e095455913e67ecceddde67453c5e1b80198c8a1e8b1cc73bd3729b6aaa745
4
+ data.tar.gz: a34322fc5be2a3e94bc585a4232cedb8f0bf4975203b14c993b13ffd0a548a5b
5
5
  SHA512:
6
- metadata.gz: 8f33dbd202c77428e16e05bf42441b6359b49132ef78a977608d13029414327441c163e44e390957fb5182fc7554948e86ef359b4598daa4d794d8726280c5e2
7
- data.tar.gz: 84f92225b7b0edeba9a5a4583a097ccac9047dc5e2b1fe837bd19be45ecf4f08c5be5d96e93530d3bf21be282613eb97d8117e49d01ba7552eed537a1ab670db
6
+ metadata.gz: 49ef20ec39ea53e8f3ceaa8ea3407fc7ef687c46f6d23f8b6449685e08d8aab3630c7093e480e3125c76a7f975210a828a90126b5abf077433f8672febb96de0
7
+ data.tar.gz: 00d2d1c8c2323004c704235ea3f7b2400c2e7ef37713597982ca63c01849aa062801b0647ba54f56ab7020f07c2e456e60e455afd1a693df5b3e5e751314e380
data/README.md CHANGED
@@ -8,6 +8,8 @@ Rigit
8
8
 
9
9
  ---
10
10
 
11
+ Build project templates easily, and without the need to write code.
12
+
11
13
  ![Rigit](rigit-header.png)
12
14
 
13
15
  ---
@@ -16,34 +18,208 @@ Table of Contents
16
18
  --------------------------------------------------
17
19
 
18
20
  * [Installation](#installation)
21
+ * [Key Features](#key-features)
22
+ * [Usage](#usage)
19
23
  * [Quick Start](#quick-start)
20
24
  * [Installing Rigs](#installing-rigs)
21
25
  * [Using Rigs (Scaffolding)](#using-rigs-scaffolding)
26
+ * [Non-Interactive Execution](#non-interactive-execution)
22
27
  * [Creating Rigs](#creating-rigs)
23
- * [Directory Structure](#directory-structure)
24
- * [Config File](#config-file)
28
+ * [Directory Structure](#directory-structure)
29
+ * [Dynamic Tokens](#dynamic-tokens)
30
+ * [Config File](#config-file)
31
+
25
32
 
26
33
 
27
34
  Installation
28
35
  --------------------------------------------------
29
36
 
37
+ $ gem install rigit
38
+
39
+
40
+
41
+ Key Features
42
+ --------------------------------------------------
43
+
44
+ Rigit was designed to allow the rapid building of reusable project templates.
45
+ In Rigit, we call these templates "rigs".
46
+
47
+ - No coding required.
48
+ - Conventions-based [folder structure](#directory-structure).
49
+ - A minimalistic [configuration file](#config-file) to allow specifying
50
+ needed parameters.
51
+ - [String replacement](#dynamic-tokens) in file names and file contents.
52
+ - [Install rigs](#installing-rigs) from any remote git repository.
53
+
54
+
55
+
56
+ Usage
57
+ --------------------------------------------------
58
+
59
+ ```
60
+ $ rig
61
+ Usage:
62
+ rig build RIG [PARAMS...]
63
+ rig install RIG REPO
64
+ rig update RIG
65
+ rig info RIG
66
+ rig (-h|--help|--version)
67
+ ```
68
+
69
+
30
70
 
31
71
  Quick Start
32
72
  --------------------------------------------------
33
73
 
74
+ After installing Rigit, you can follow these steps to quickly understand how
75
+ it works, and how you can create your own rigs.
76
+
77
+ First, create an empty folder:
78
+
79
+ $ mkdir myapp
80
+ $ cd muapp
81
+
82
+ Install your first rig. You can use this [example rig][example-rig].
83
+
84
+ $ rig install example https://github.com/DannyBen/example-rig.git
85
+
86
+ Now that your rig is installed (in `~/.rigs`), you can use it.
87
+
88
+ $ rig build example
89
+
90
+ Input all the answers, and you are done. Your project has been rigged.
91
+
92
+
34
93
 
35
94
  Installing Rigs
36
95
  --------------------------------------------------
37
96
 
97
+ Rigs are installed in `~/.rigs` by default. You can change the installation
98
+ directory by setting the `RIG_HOME` environment variable to your desired
99
+ path.
100
+
101
+ To install a rig, simply use the `rig install` command, and supply a name
102
+ (which will be the name of the rig in your local system) and a git URL (use
103
+ the same url as you would use in "git clone").
104
+
105
+ $ rig install example https://github.com/DannyBen/example-rig.git
106
+
107
+
38
108
 
39
109
  Using Rigs (Scaffolding)
40
110
  --------------------------------------------------
41
111
 
112
+ After you have one or more installed rigs, you can use them to create a new
113
+ project. Note that rigit works in the *current* directory, and will not
114
+ create the project root directory for you.
115
+
116
+ $ mkdir myapp
117
+ $ cd myapp
118
+ $ rig build example
119
+
120
+ Most rigs will have parameters, you will be prompted to input them as needed.
121
+
122
+
123
+ ### Non-Interactive Execution
124
+
125
+ You can also provide some (or all) of the parameters in the command line,
126
+ if you need to avoid interactivity.
127
+
128
+ $ rig build example name=myapp spec=y console=irb license=MIT
129
+
130
+ To learn about the parameters of a rig:
131
+
132
+ $ rig info example
133
+
134
+
42
135
 
43
136
  Creating Rigs
44
137
  --------------------------------------------------
45
138
 
139
+ > **Tip**: Take a look at the [example rig][example-rig] while reading
140
+ > this section.
141
+
142
+ Rigit's main design goal was to allow rapid and easy creation of new
143
+ templates. There is no coding involved in creating a rig, and instead we
144
+ are using folders with specific names, to allow for a sort of "additive"
145
+ project building.
146
+
147
+ The steps in creating a rig are:
148
+
149
+ 1. Start in a new, empty folder.
150
+ 2. Create a folder named `base`. Put all the files and folders of your
151
+ project inside.
152
+ 3. Rename files and folders, and files as needed to include dynamic tokens.
153
+ 4. If you want to add some of the files only in specific cases (for example
154
+ only include a license file if the user wants to), you move the files to
155
+ a folder with s special `parameter=value` folder.
156
+ 5. Create a config file to specify the needed parameters.
157
+
158
+
46
159
  ### Directory Structure
47
160
 
161
+ There are two types of folders in a rig template.
162
+
163
+ 1. Base folder (`base`) - files and folders here will be copied always
164
+ 2. Conditional folders (`parameter=value`) - contents in these folders will
165
+ only be copied if the user answerd `value` to the question `parameter`.
166
+
167
+
168
+ ### Dynamic Tokens
169
+
170
+ You can use variable replacements (tokens) in file names, folder names and in
171
+ file contents.
172
+
173
+ Each token that you use, must also be declared in the config file.
174
+
175
+ Tokens are specified using this syntax:
176
+
177
+ %{name}
178
+
179
+
48
180
  ### Config File
49
181
 
182
+ Place a `config.yml` file at the root of your rig template. A config file
183
+ is optional for rigs that do not have any variables.
184
+
185
+ A typical config file looks like this:
186
+
187
+ ```yaml
188
+ intro: A sample generator
189
+
190
+ params:
191
+ name:
192
+ prompt: "Name your project:"
193
+ type: text
194
+ default: project
195
+
196
+ spec:
197
+ prompt: Include RSpec files?
198
+ type: yesno
199
+ default: y
200
+
201
+ console:
202
+ prompt: "Select console:"
203
+ type: select
204
+ list: [irb, pry]
205
+ ```
206
+
207
+ | Key | Purpose |
208
+ |----------|---------------------------------------------------------|
209
+ | `intro` | A short message to display when building (Optional) |
210
+ | `params` | A list of parameters required by the rig |
211
+
212
+ The `params` key should start with the name of the variable (`name`,
213
+ `spec` and `console` in the above example), and contain the below
214
+ specifications:
215
+
216
+ | Key | Purpose |
217
+ |-----------|----------------------------------------------------------|
218
+ | `prompt` | The text to display when asking for user input |
219
+ | `type` | The variable tyoe. Can be `yesno`, `text` or `select` |
220
+ | `default` | The default value. When using `yesno`, use `y` and `n` |
221
+ | `list` | An array of allowed options (only used in `select` type) |
222
+
223
+ ---
224
+
225
+ [example-rig]: https://github.com/DannyBen/example-rig
@@ -1,13 +1,20 @@
1
1
  require 'super_docopt'
2
2
  require 'rigit/version'
3
3
 
4
+ require 'rigit/commands/build'
5
+ require 'rigit/commands/install'
6
+ require 'rigit/commands/update'
7
+ require 'rigit/commands/info'
8
+
4
9
  module Rigit
5
10
  class CommandLine < SuperDocopt::Base
6
11
  version VERSION
7
12
  docopt File.expand_path 'docopt.txt', __dir__
8
- subcommands [:build, :install]
13
+ subcommands [:build, :install, :update, :info]
9
14
 
10
15
  include Commands::Build
11
16
  include Commands::Install
17
+ include Commands::Update
18
+ include Commands::Info
12
19
  end
13
20
  end
@@ -3,10 +3,10 @@ require 'colsole'
3
3
  module Rigit::Commands
4
4
  module Build
5
5
  def build
6
- Builder.new(args).execute
6
+ BuildHandler.new(args).execute
7
7
  end
8
8
 
9
- class Builder
9
+ class BuildHandler
10
10
  attr_reader :args, :rig_name, :target_dir
11
11
 
12
12
  include Colsole
@@ -22,7 +22,13 @@ module Rigit::Commands
22
22
  say "!txtblu!#{config.intro}" if config.has_key? :intro
23
23
  verify_dirs
24
24
  arguments = prompt.get_input params
25
- rig.scaffold arguments:arguments, target_dir: target_dir
25
+ rig.scaffold arguments:arguments, target_dir: target_dir do |file|
26
+ if File.exist? file
27
+ tty_prompt.yes? "Overwrite #{file}?", default: false
28
+ else
29
+ true
30
+ end
31
+ end
26
32
  say "Done"
27
33
  end
28
34
 
@@ -0,0 +1,46 @@
1
+ require 'colsole'
2
+
3
+ module Rigit::Commands
4
+ module Info
5
+ def info
6
+ InfoHandler.new(args).execute
7
+ end
8
+
9
+ class InfoHandler
10
+ include Colsole
11
+
12
+ attr_reader :args, :rig_name
13
+
14
+ def initialize(args)
15
+ @args = args
16
+ @rig_name = args['RIG']
17
+ end
18
+
19
+ def execute
20
+ verify_presence
21
+ info
22
+ end
23
+
24
+ private
25
+
26
+ def info
27
+ rig.info.each do |key, value|
28
+ say "!txtgrn!#{key}!txtrst!:"
29
+ say word_wrap " #{value}"
30
+ say ""
31
+ end
32
+ end
33
+
34
+ def rig
35
+ @rig ||= Rigit::Rig.new rig_name
36
+ end
37
+
38
+ def verify_presence
39
+ if !rig.exist?
40
+ say "Cannot find rig !txtgrn!#{rig_name}"
41
+ raise Rigit::Exit
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -4,10 +4,10 @@ require 'colsole'
4
4
  module Rigit::Commands
5
5
  module Install
6
6
  def install
7
- Installer.new(args).execute
7
+ InstallHandler.new(args).execute
8
8
  end
9
9
 
10
- class Installer
10
+ class InstallHandler
11
11
  include Colsole
12
12
 
13
13
  attr_reader :args, :rig_name, :repo
@@ -26,15 +26,20 @@ module Rigit::Commands
26
26
  private
27
27
 
28
28
  def install
29
- say "Installing !txtgrn!#{repo}\n"
29
+ say "Installing !txtgrn!#{repo}"
30
30
  FileUtils.mkdir_p target_path unless Dir.exist? target_path
31
- success = Git.clone repo, target_path
31
+ success = Rigit::Git.clone repo, target_path
32
32
 
33
33
  if success
34
- say "\nRig installed !txtgrn!successfully!txtrst! in !txtgrn!#{target_path}"
34
+ say "Rig installed !txtgrn!successfully!txtrst! in !txtgrn!#{target_path}"
35
35
  say "To build a new project with this rig, run this in any empty directory:\n"
36
36
  say " !txtpur!rig build #{rig_name}\n"
37
+ else
38
+ # :nocov:
39
+ say "!txtred!Installation failed"
40
+ # :nocov:
37
41
  end
42
+
38
43
  end
39
44
 
40
45
  def rig
@@ -46,8 +51,8 @@ module Rigit::Commands
46
51
  end
47
52
 
48
53
  def verify_dirs
49
- if Dir.exist? target_path
50
- say "Rig !txtgrn!#{rig_name}!txtrst! is already installed."
54
+ if rig.exist?
55
+ say "Rig !txtgrn!#{rig_name}!txtrst! is already installed"
51
56
  say "In order to update it from the source repository, run:\n"
52
57
  say " !txtpur!rig update #{rig_name}\n"
53
58
  raise Rigit::Exit
@@ -0,0 +1,54 @@
1
+ require 'colsole'
2
+
3
+ module Rigit::Commands
4
+ module Update
5
+ def update
6
+ UpdateHandler.new(args).execute
7
+ end
8
+
9
+ class UpdateHandler
10
+ include Colsole
11
+
12
+ attr_reader :args, :rig_name
13
+
14
+ def initialize(args)
15
+ @args = args
16
+ @rig_name = args['RIG']
17
+ end
18
+
19
+ def execute
20
+ verify_dirs
21
+ update
22
+ end
23
+
24
+ private
25
+
26
+ def update
27
+ say "Updating !txtgrn!#{rig_name}"
28
+ success = Rigit::Git.pull target_path
29
+ if success
30
+ say "Rig updated !txtgrn!successfully!txtrst!"
31
+ else
32
+ # :nocov:
33
+ say "!txtred!Update failed"
34
+ # :nocov:
35
+ end
36
+ end
37
+
38
+ def rig
39
+ @rig ||= Rigit::Rig.new rig_name
40
+ end
41
+
42
+ def target_path
43
+ @target_path ||= rig.path
44
+ end
45
+
46
+ def verify_dirs
47
+ if !rig.exist?
48
+ say "Rig !txtgrn!#{rig_name}!txtrst! is not installed"
49
+ raise Rigit::Exit
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/rigit/docopt.txt CHANGED
@@ -3,6 +3,9 @@ Rigit
3
3
  Usage:
4
4
  rig build RIG [PARAMS...]
5
5
  rig install RIG REPO
6
+ rig update RIG
7
+ rig info RIG
8
+ rig (-h|--help|--version)
6
9
 
7
10
  Commands:
8
11
  build
@@ -12,6 +15,15 @@ Commands:
12
15
  If you wish to execute this command without interactivity, you may
13
16
  use specify all parameters in the PARAMS parameter (see below).
14
17
 
18
+ install
19
+ Clone a remote rig git repository and install it locally.
20
+
21
+ update
22
+ Update an installed rig to its latest version.
23
+
24
+ info
25
+ Show some meta information about an installed rig.
26
+
15
27
  Parameters:
16
28
  RIG
17
29
  The name of the source folder (installed rig).
@@ -24,6 +36,13 @@ Parameters:
24
36
  Specify any of the rig's parameters in the format 'param=value'.
25
37
  For boolean parameters, use 'param=y' or 'param=n'.
26
38
 
39
+ Environment Variables:
40
+ RIG_HOME
41
+ The path where your local rigs are installed (default: ~/.rigs)
42
+
27
43
  Examples:
28
44
  rig build gem name=mygem spec=y
29
- rig install example https://github.com/DannyBen/example-rig.git
45
+ rig install example https://github.com/DannyBen/example-rig.git
46
+ rig update example
47
+ rig info example
48
+
data/lib/rigit/git.rb CHANGED
@@ -4,6 +4,12 @@ module Rigit
4
4
  execute %Q[git clone #{repo} "#{target_path}"]
5
5
  end
6
6
 
7
+ def self.pull(target_path)
8
+ Dir.chdir target_path do
9
+ execute %Q[git pull]
10
+ end
11
+ end
12
+
7
13
  private
8
14
 
9
15
  def self.execute(command)
data/lib/rigit/rig.rb CHANGED
@@ -14,13 +14,15 @@ module Rigit
14
14
  @name = name
15
15
  end
16
16
 
17
- def scaffold(arguments: {}, target_dir:'.')
18
- scaffold_dir "#{path}/base", arguments, target_dir
17
+ def scaffold(arguments: {}, target_dir:'.', &block)
18
+ scaffold_dir dir: "#{path}/base", arguments: arguments,
19
+ target_dir: target_dir, &block
19
20
 
20
21
  arguments.each do |key, value|
21
22
  additive_dir = "#{path}/#{key}=#{value}"
22
23
  if Dir.exist? additive_dir
23
- scaffold_dir additive_dir, arguments, target_dir
24
+ scaffold_dir dir: additive_dir, arguments: arguments,
25
+ target_dir: target_dir, &block
24
26
  end
25
27
  end
26
28
  end
@@ -33,6 +35,10 @@ module Rigit
33
35
  Dir.exist? path
34
36
  end
35
37
 
38
+ def has_config?
39
+ File.exist? config_file
40
+ end
41
+
36
42
  def config_file
37
43
  "#{path}/config.yml"
38
44
  end
@@ -41,13 +47,24 @@ module Rigit
41
47
  @config ||= Config.load(config_file)
42
48
  end
43
49
 
50
+ def info
51
+ {
52
+ name: name,
53
+ path: path,
54
+ config: (has_config? ? File.read(config_file) : '<empty>')
55
+ }
56
+ end
57
+
44
58
  private
45
59
 
46
- def scaffold_dir(dir, arguments, target_dir)
60
+ def scaffold_dir(dir:, arguments:, target_dir:)
47
61
  files = Dir["#{dir}/**/*"].reject { |file| File.directory? file }
48
62
 
49
63
  files.each do |file|
50
64
  target_file = (file % arguments).sub dir, target_dir
65
+
66
+ next if block_given? and !yield target_file
67
+
51
68
  content = File.read(file) % arguments
52
69
  File.deep_write target_file, content
53
70
  end
data/lib/rigit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rigit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/rigit.rb CHANGED
@@ -5,9 +5,6 @@ require 'rigit/errors'
5
5
  require 'rigit/prompt'
6
6
  require 'rigit/rig'
7
7
  require 'rigit/git'
8
-
9
- require 'rigit/commands/build'
10
- require 'rigit/commands/install'
11
8
  require 'rigit/command_line'
12
9
 
13
10
  module Rigit
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt
@@ -190,7 +190,9 @@ files:
190
190
  - lib/rigit.rb
191
191
  - lib/rigit/command_line.rb
192
192
  - lib/rigit/commands/build.rb
193
+ - lib/rigit/commands/info.rb
193
194
  - lib/rigit/commands/install.rb
195
+ - lib/rigit/commands/update.rb
194
196
  - lib/rigit/config.rb
195
197
  - lib/rigit/docopt.txt
196
198
  - lib/rigit/errors.rb