rigit 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +64 -17
- data/lib/rigit/command_line.rb +3 -1
- data/lib/rigit/commands/build.rb +15 -1
- data/lib/rigit/commands/new_rig.rb +43 -0
- data/lib/rigit/docopt.txt +8 -0
- data/lib/rigit/rig.rb +9 -0
- data/lib/rigit/template_config.yml +21 -0
- data/lib/rigit/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c64487a87ae7122b0d47a53d3843b374beb6d3ae12ccf0cf171d83d0f68075e8
|
4
|
+
data.tar.gz: ca486b20b6ba0ba9af18c1d10c3254b352a2598226995d6decdb785f86ff7ae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3bff17c87022e3742de0fddc5e9616e63f5fc1c443751104db0c292fba7c3f4ff86b2c4793a8795c544a0660178144c0fa18ce96cfe95ac7f6fffef790874da
|
7
|
+
data.tar.gz: a976e1b1ae23a1c207964957725e05d2d00622f0b2d4407858d1d8e8fec92c048d3401b96001fec503da3f46fc238a4a052415f854f8becd294d2f8430b050b1
|
data/README.md
CHANGED
@@ -28,9 +28,10 @@ Table of Contents
|
|
28
28
|
* [Directory Structure](#directory-structure)
|
29
29
|
* [Dynamic Tokens](#dynamic-tokens)
|
30
30
|
* [Config File](#config-file)
|
31
|
-
* [
|
32
|
-
* [
|
33
|
-
* [
|
31
|
+
* [Example Config](#example-config)
|
32
|
+
* [Showing messages before/after scaffolding](#showing-messages-beforeafter-scaffolding)
|
33
|
+
* [Executing commands before/after scaffolding](#executing-commands-beforeafter-scaffolding)
|
34
|
+
* [Scaffolding parameters](#scaffolding-parameters)
|
34
35
|
|
35
36
|
|
36
37
|
Installation
|
@@ -61,6 +62,7 @@ Usage
|
|
61
62
|
```
|
62
63
|
$ rig
|
63
64
|
Usage:
|
65
|
+
rig new NAME
|
64
66
|
rig build RIG [--force] [PARAMS...]
|
65
67
|
rig install RIG REPO
|
66
68
|
rig uninstall RIG
|
@@ -129,7 +131,7 @@ Most rigs will have parameters, you will be prompted to input them as needed.
|
|
129
131
|
You can also provide some (or all) of the parameters in the command line,
|
130
132
|
if you need to avoid interactivity.
|
131
133
|
|
132
|
-
$ rig build example name=myapp spec=
|
134
|
+
$ rig build example name=myapp spec=yes console=irb license=MIT
|
133
135
|
|
134
136
|
To learn about the parameters of a rig:
|
135
137
|
|
@@ -159,6 +161,10 @@ The steps in creating a rig are:
|
|
159
161
|
a folder with s special `parameter=value` folder.
|
160
162
|
5. Create a config file to specify the needed parameters.
|
161
163
|
|
164
|
+
In order to quickly get started with creating a new rig, you can also run
|
165
|
+
`rig new your_new_rig_name`. This will create the initial folder structure
|
166
|
+
and an initial `config.yml` for you to build on.
|
167
|
+
|
162
168
|
|
163
169
|
### Directory Structure
|
164
170
|
|
@@ -192,19 +198,36 @@ Tokens are specified using this syntax:
|
|
192
198
|
|
193
199
|
%{name}
|
194
200
|
|
201
|
+
If you are using the
|
202
|
+
[`before` and `after`](#showing-messages-beforeafter-scaffolding)
|
203
|
+
definitions in your config file, you can use dynamic tokens in both the
|
204
|
+
label and the command of each definition.
|
205
|
+
|
195
206
|
|
196
207
|
### Config File
|
197
208
|
|
198
209
|
Place a `config.yml` file at the root of your rig template. A config file
|
199
210
|
is optional for rigs that do not have any variables.
|
200
211
|
|
201
|
-
|
212
|
+
|
213
|
+
#### Example Config
|
214
|
+
|
215
|
+
The below config file example contains all the available options:
|
202
216
|
|
203
217
|
```yaml
|
218
|
+
# Optional messages to show before/after scaffolding
|
204
219
|
intro: A sample generator
|
205
|
-
|
206
220
|
outro: Something to say after scaffolding is done
|
207
221
|
|
222
|
+
# Optional commands to execute before/after scaffolding
|
223
|
+
before:
|
224
|
+
"Create empty .env file": "touch .env"
|
225
|
+
|
226
|
+
after:
|
227
|
+
"Install Dependencies": "bundle install"
|
228
|
+
"Initialize git repo": "git init"
|
229
|
+
|
230
|
+
# Parameters to collect on scaffolding
|
208
231
|
params:
|
209
232
|
name:
|
210
233
|
prompt: "Name your project:"
|
@@ -222,29 +245,43 @@ params:
|
|
222
245
|
list: [irb, pry]
|
223
246
|
```
|
224
247
|
|
225
|
-
####
|
248
|
+
#### Showing messages before/after scaffolding
|
226
249
|
|
227
|
-
|
250
|
+
Use the `intro` and `outro` options to show short message that will be
|
251
|
+
displayed before or after building. Both are optional.
|
228
252
|
|
229
|
-
|
253
|
+
The message is displayed using the [Colsole][colsole] gem, so
|
230
254
|
you can use [color markers][colsole-colors]
|
231
255
|
|
232
|
-
Example:
|
256
|
+
Example:
|
233
257
|
|
258
|
+
```yaml
|
259
|
+
intro: Welcome to my blue !txtblu!rig!txtrst!`
|
260
|
+
outro: Installation completed successfully
|
261
|
+
```
|
234
262
|
|
235
|
-
####
|
263
|
+
#### Executing commands before/after scaffolding
|
236
264
|
|
237
|
-
|
265
|
+
Use the `before` and `after` options to specify one or more commands to
|
266
|
+
run before or after building. Each command has a label and an action, and
|
267
|
+
both support [dynamic tokens](#dynamic-tokens), so you can use the input the user provided in
|
268
|
+
your commands.
|
238
269
|
|
239
|
-
|
240
|
-
you can use [color markers][colsole-colors]
|
270
|
+
Example:
|
241
271
|
|
242
|
-
|
272
|
+
```yaml
|
273
|
+
before:
|
274
|
+
"Create empty .env file": "touch .env"
|
243
275
|
|
276
|
+
after:
|
277
|
+
"Install Dependencies": "bundle install"
|
278
|
+
"Initialize git repo": "git init"
|
279
|
+
"Run setup script": "myscript %{name}"
|
280
|
+
```
|
244
281
|
|
245
|
-
####
|
282
|
+
#### Scaffolding parameters
|
246
283
|
|
247
|
-
|
284
|
+
The `params` option contains a list of parameters required by the rig.
|
248
285
|
|
249
286
|
Each definition in the `params` key should start with the name of the
|
250
287
|
variable (`name`, `spec` and `console` in the above example), and contain
|
@@ -257,6 +294,16 @@ the below specifications:
|
|
257
294
|
| `default` | The default value. When using `yesno`, use `yes` or `no` |
|
258
295
|
| `list` | An array of allowed options (only used in `select` type) |
|
259
296
|
|
297
|
+
Example:
|
298
|
+
|
299
|
+
```yaml
|
300
|
+
params:
|
301
|
+
name:
|
302
|
+
prompt: "Name your project:"
|
303
|
+
type: text
|
304
|
+
default: project
|
305
|
+
```
|
306
|
+
|
260
307
|
---
|
261
308
|
|
262
309
|
[example-rig]: https://github.com/DannyBen/example-rig
|
data/lib/rigit/command_line.rb
CHANGED
@@ -10,13 +10,14 @@ require 'rigit/commands/install'
|
|
10
10
|
require 'rigit/commands/list'
|
11
11
|
require 'rigit/commands/uninstall'
|
12
12
|
require 'rigit/commands/update'
|
13
|
+
require 'rigit/commands/new_rig'
|
13
14
|
|
14
15
|
module Rigit
|
15
16
|
# Handles command line execution using docopt.
|
16
17
|
class CommandLine < SuperDocopt::Base
|
17
18
|
version VERSION
|
18
19
|
docopt File.expand_path 'docopt.txt', __dir__
|
19
|
-
subcommands [:build, :install, :uninstall, :update, :info, :list]
|
20
|
+
subcommands [:build, :install, :uninstall, :update, :info, :list, new: :new_rig]
|
20
21
|
|
21
22
|
include Commands::Build
|
22
23
|
include Commands::Install
|
@@ -24,5 +25,6 @@ module Rigit
|
|
24
25
|
include Commands::Update
|
25
26
|
include Commands::Info
|
26
27
|
include Commands::List
|
28
|
+
include Commands::NewRig
|
27
29
|
end
|
28
30
|
end
|
data/lib/rigit/commands/build.rb
CHANGED
@@ -38,9 +38,23 @@ module Rigit::Commands
|
|
38
38
|
# Call Rig#scaffold while checking each file to see if it should be
|
39
39
|
# overwritten or not.
|
40
40
|
def scaffold(arguments)
|
41
|
+
execute_actions config.before, arguments if config.has_key? :before
|
42
|
+
|
41
43
|
rig.scaffold arguments: arguments, target_dir: target_dir do |file|
|
42
44
|
overwrite_file? file
|
43
45
|
end
|
46
|
+
|
47
|
+
execute_actions config.after, arguments if config.has_key? :after
|
48
|
+
end
|
49
|
+
|
50
|
+
# Execute user-defined system commands.
|
51
|
+
# Actions are expected to be provided as a hash (label=command) and
|
52
|
+
# both labels and commands accept string interpolation +%{tokens}+
|
53
|
+
def execute_actions(actions, arguments)
|
54
|
+
actions.each do |label, command|
|
55
|
+
say "!txtgrn!#{label}" % arguments
|
56
|
+
system command % arguments
|
57
|
+
end
|
44
58
|
end
|
45
59
|
|
46
60
|
# Check various scenarios to decide if the file should be overwritten
|
@@ -69,7 +83,7 @@ module Rigit::Commands
|
|
69
83
|
|
70
84
|
def prompt_user_to_overwrite(file)
|
71
85
|
say "File !txtgrn!#{file}!txtrst! already exists."
|
72
|
-
tty_prompt.expand "Overwrite?" do |menu|
|
86
|
+
tty_prompt.expand " Overwrite?" do |menu|
|
73
87
|
menu.choice key: 'y', name: 'overwrite', value: true
|
74
88
|
menu.choice key: 'n', name: 'skip', value: false
|
75
89
|
menu.choice key: 'a', name: 'overwrite all' do @overwrite_all = true; true end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rigit::Commands
|
2
|
+
# The {NewRIg} module provides the {#new_rig} command for the {CommandLine}
|
3
|
+
# module.
|
4
|
+
module NewRig
|
5
|
+
|
6
|
+
# The command line +new+ command.
|
7
|
+
def new_rig
|
8
|
+
NewRigHandler.new(args).execute
|
9
|
+
end
|
10
|
+
|
11
|
+
# Internal class to handle the creation of a new rig template for the
|
12
|
+
# {CommandLine} class.
|
13
|
+
class NewRigHandler
|
14
|
+
include Colsole
|
15
|
+
|
16
|
+
attr_reader :args, :name
|
17
|
+
|
18
|
+
def initialize(args)
|
19
|
+
@args = args
|
20
|
+
@name = args['NAME']
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute
|
24
|
+
verify_presence
|
25
|
+
Rigit::Rig.create name
|
26
|
+
say "Rig template created in !txtgrn!#{rig.path}"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def rig
|
32
|
+
@rig ||= Rigit::Rig.new name
|
33
|
+
end
|
34
|
+
|
35
|
+
def verify_presence
|
36
|
+
if rig.exist?
|
37
|
+
say "Rig !txtgrn!#{name}!txtrst! already exists, choose a different name"
|
38
|
+
raise Rigit::Exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/rigit/docopt.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Rigit
|
2
2
|
|
3
3
|
Usage:
|
4
|
+
rig new NAME
|
4
5
|
rig build RIG [--force] [PARAMS...]
|
5
6
|
rig install RIG REPO
|
6
7
|
rig uninstall RIG
|
@@ -10,6 +11,9 @@ Usage:
|
|
10
11
|
rig (-h|--help|--version)
|
11
12
|
|
12
13
|
Commands:
|
14
|
+
new
|
15
|
+
Create a new rig template.
|
16
|
+
|
13
17
|
build
|
14
18
|
Create a new project based on one of the installed rig templates.
|
15
19
|
This command should be executed in an empty directory.
|
@@ -34,6 +38,9 @@ Commands:
|
|
34
38
|
of subfolders (possibly rigs) inside it.
|
35
39
|
|
36
40
|
Parameters:
|
41
|
+
NAME
|
42
|
+
The name of the new rig template.
|
43
|
+
|
37
44
|
RIG
|
38
45
|
The name of the source folder (installed rig).
|
39
46
|
|
@@ -69,4 +76,5 @@ Examples:
|
|
69
76
|
rig update example
|
70
77
|
rig info example
|
71
78
|
rig list
|
79
|
+
rig new myrig
|
72
80
|
|
data/lib/rigit/rig.rb
CHANGED
@@ -15,6 +15,15 @@ module Rigit
|
|
15
15
|
ENV['RIG_HOME'] = path
|
16
16
|
end
|
17
17
|
|
18
|
+
# Create a new empty rig with a basic config file as a starting point.
|
19
|
+
def self.create(name)
|
20
|
+
target_dir = "#{home}/#{name}"
|
21
|
+
template_file = File.expand_path 'template_config.yml', __dir__
|
22
|
+
|
23
|
+
FileUtils.mkdir_p "#{target_dir}/base"
|
24
|
+
FileUtils.cp template_file, "#{target_dir}/config.yml"
|
25
|
+
end
|
26
|
+
|
18
27
|
# Returns a new instance of Rig. The +name+ argument should be the name
|
19
28
|
# of an existing (installed) rig.
|
20
29
|
def initialize(name)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
intro: Optional intro message
|
2
|
+
|
3
|
+
outro: Optional outro message
|
4
|
+
|
5
|
+
params:
|
6
|
+
name:
|
7
|
+
prompt: "Name your project:"
|
8
|
+
type: text
|
9
|
+
default: project
|
10
|
+
|
11
|
+
# More parameter examples
|
12
|
+
|
13
|
+
# spec:
|
14
|
+
# prompt: Include RSpec files?
|
15
|
+
# type: yesno
|
16
|
+
# default: yes
|
17
|
+
|
18
|
+
# console:
|
19
|
+
# prompt: "Select console:"
|
20
|
+
# type: select
|
21
|
+
# list: [irb, pry]
|
data/lib/rigit/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.5
|
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-03-
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: super_docopt
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/rigit/commands/info.rb
|
208
208
|
- lib/rigit/commands/install.rb
|
209
209
|
- lib/rigit/commands/list.rb
|
210
|
+
- lib/rigit/commands/new_rig.rb
|
210
211
|
- lib/rigit/commands/uninstall.rb
|
211
212
|
- lib/rigit/commands/update.rb
|
212
213
|
- lib/rigit/config.rb
|
@@ -216,6 +217,7 @@ files:
|
|
216
217
|
- lib/rigit/git.rb
|
217
218
|
- lib/rigit/prompt.rb
|
218
219
|
- lib/rigit/rig.rb
|
220
|
+
- lib/rigit/template_config.yml
|
219
221
|
- lib/rigit/version.rb
|
220
222
|
homepage: https://dannyben.github.io/rigit/
|
221
223
|
licenses:
|