planter-cli 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +44 -0
- data/.irbrc +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +78 -0
- data/.travis.yml +7 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +45 -0
- data/Gemfile +6 -0
- data/Guardfile +25 -0
- data/LICENSE.txt +20 -0
- data/README.md +208 -0
- data/Rakefile +132 -0
- data/bin/plant +106 -0
- data/debug.log +0 -0
- data/docker/Dockerfile +12 -0
- data/docker/Dockerfile-2.6 +12 -0
- data/docker/Dockerfile-2.7 +12 -0
- data/docker/Dockerfile-3.0 +11 -0
- data/docker/bash_profile +15 -0
- data/docker/inputrc +57 -0
- data/lib/.rubocop.yml +1 -0
- data/lib/planter/array.rb +28 -0
- data/lib/planter/color.rb +370 -0
- data/lib/planter/errors.rb +59 -0
- data/lib/planter/file.rb +11 -0
- data/lib/planter/fileentry.rb +87 -0
- data/lib/planter/filelist.rb +144 -0
- data/lib/planter/hash.rb +103 -0
- data/lib/planter/plant.rb +228 -0
- data/lib/planter/prompt.rb +352 -0
- data/lib/planter/script.rb +59 -0
- data/lib/planter/string.rb +383 -0
- data/lib/planter/symbol.rb +28 -0
- data/lib/planter/version.rb +7 -0
- data/lib/planter.rb +222 -0
- data/planter-cli.gemspec +48 -0
- data/scripts/deploy.rb +97 -0
- data/scripts/runtests.sh +5 -0
- data/spec/.rubocop.yml +4 -0
- data/spec/planter/plant_spec.rb +14 -0
- data/spec/planter/string_spec.rb +20 -0
- data/spec/spec_helper.rb +20 -0
- data/src/_README.md +214 -0
- metadata +400 -0
data/scripts/deploy.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'tty-spinner'
|
3
|
+
require 'pastel'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
unless system('rake spec')
|
7
|
+
puts "Tests failed, exiting"
|
8
|
+
Process.exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
pastel = Pastel.new
|
12
|
+
format = "[#{pastel.yellow(':spinner')}] " + pastel.white("Release Gem")
|
13
|
+
spinners = TTY::Spinner::Multi.new(format, format: :dots, success_mark: pastel.green('✔'), error_mark: pastel.red('✖'))
|
14
|
+
sp_v = spinners.register "[#{pastel.cyan(':spinner')}] :msg"
|
15
|
+
sp_d = spinners.register "[#{pastel.cyan(':spinner')}] Generate docs"
|
16
|
+
spinners.auto_spin
|
17
|
+
|
18
|
+
$version = nil
|
19
|
+
sp_v.update(msg: 'Get version')
|
20
|
+
|
21
|
+
def get_version
|
22
|
+
versions = `rake ver`.strip
|
23
|
+
version = versions.match(/version\.rb: ([\d.]+(\w+\d*)?)/)[1]
|
24
|
+
changelog_version = versions.match(/changelog: ([\d.]+(\w+\d*)?)/)[1]
|
25
|
+
git_version = versions.match(/git tag: ([\d.]+(\w+\d*)?)/)[1]
|
26
|
+
[version, git_version, changelog_version]
|
27
|
+
end
|
28
|
+
|
29
|
+
sp_v.run do |spinner|
|
30
|
+
spinner.update(msg: 'Getting version')
|
31
|
+
version, git_version, changelog_version = get_version
|
32
|
+
|
33
|
+
if git_version == version
|
34
|
+
`rake bump:patch &> results.log`
|
35
|
+
end
|
36
|
+
|
37
|
+
version, git_version, changelog_version = get_version
|
38
|
+
|
39
|
+
unless version == changelog_version
|
40
|
+
`changelog -u &> results.log`
|
41
|
+
end
|
42
|
+
|
43
|
+
version, git_version, changelog_version = get_version
|
44
|
+
|
45
|
+
unless version == changelog_version
|
46
|
+
spinner.update(msg: "Version mismatch, please correct")
|
47
|
+
spinner.error
|
48
|
+
spinner.stop
|
49
|
+
Process.exit
|
50
|
+
end
|
51
|
+
|
52
|
+
$version = version
|
53
|
+
|
54
|
+
spinner.update(msg: "Version #{version}")
|
55
|
+
spinner.success
|
56
|
+
end
|
57
|
+
|
58
|
+
sp_d.auto_spin
|
59
|
+
`rake yard &> results.log`
|
60
|
+
sp_d.success
|
61
|
+
|
62
|
+
sp_r = spinners.register "[:spinner] Releasing gem :msg"
|
63
|
+
|
64
|
+
sp_r.run do |spinner|
|
65
|
+
spinner.update(msg: '- Preparing git release')
|
66
|
+
`git ar &> results.log`
|
67
|
+
`git commit -a -m "#{$version} release prep" &> results.log`
|
68
|
+
`git pull &> results.log`
|
69
|
+
`FORCE_PUSH=true git push &> results.log`
|
70
|
+
spinner.update(msg: '- Running rake release')
|
71
|
+
|
72
|
+
status = `changelog > current_changes.md; echo $?`
|
73
|
+
|
74
|
+
version, git_version, changelog_version = get_version
|
75
|
+
|
76
|
+
if status.to_i == 0
|
77
|
+
puts `gh release create #{version} -t "v#{version}" -F current_changes.md`
|
78
|
+
`git pull`
|
79
|
+
end
|
80
|
+
|
81
|
+
# Push a gem
|
82
|
+
`rake clobber build`
|
83
|
+
`gem push pkg/planter-#{version}.gem`
|
84
|
+
|
85
|
+
new_ver = `rake bump:patch`
|
86
|
+
puts `git commit -a -m "Version bump #{new_ver}"`
|
87
|
+
|
88
|
+
`git checkout main &> results.log`
|
89
|
+
`git merge develop &> results.log`
|
90
|
+
`rake release &> results.log`
|
91
|
+
spinner.update(msg: '- Cleaning up')
|
92
|
+
`git checkout develop &> results.log`
|
93
|
+
`git rebase main &> results.log`
|
94
|
+
sp_r.success
|
95
|
+
end
|
96
|
+
|
97
|
+
FileUtils.rm('results.log')
|
data/scripts/runtests.sh
ADDED
data/spec/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Planter::Plant do
|
6
|
+
Planter.accept_defaults = true
|
7
|
+
subject(:ruby_gem) { Planter::Plant.new('test', { project: 'Untitled', script: 'Script', title: 'Title' }) }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it 'makes a new instance' do
|
11
|
+
expect(ruby_gem).to be_a described_class
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::String do
|
4
|
+
describe '.to_var' do
|
5
|
+
it 'turns string into snake-cased symbol' do
|
6
|
+
expect('This is a test string'.to_var).to be :this_is_a_test_string
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.to_slug' do
|
11
|
+
it 'slugifies a string' do
|
12
|
+
expect('This is a test string'.to_slug).to match /this-is-a-test-string/
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'slugifies bad characters' do
|
16
|
+
expect('This: #is a test string!'.to_slug).to match /this-colon-hash-is-a-test-string-bang/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
if ENV['CI'] == 'true'
|
6
|
+
require 'codecov'
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
8
|
+
else
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'planter'
|
13
|
+
|
14
|
+
RSpec.configure do |c|
|
15
|
+
c.expect_with(:rspec) { |e| e.syntax = :expect }
|
16
|
+
c.before(:each) do
|
17
|
+
allow(FileUtils).to receive(:remove_entry_secure).with(anything)
|
18
|
+
end
|
19
|
+
c.add_formatter 'Fuubar'
|
20
|
+
end
|
data/src/_README.md
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
# Planter
|
2
|
+
|
3
|
+
[![Gem](https://img.shields.io/gem/v/planter-cli.svg)](https://rubygems.org/gems/planter-cli)
|
4
|
+
[![GitHub license](https://img.shields.io/github/license/ttscoff/planter-cli.svg)](./LICENSE.txt)
|
5
|
+
|
6
|
+
<!--README-->
|
7
|
+
|
8
|
+
Plant a directory structure and files using templates.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
gem install planter-cli
|
13
|
+
|
14
|
+
If you run into errors, try `gem install --user-install planter-cli`, or as a last ditch effort, `sudo gem install planter-cli`.
|
15
|
+
|
16
|
+
### Optional
|
17
|
+
|
18
|
+
If [Gum](https://github.com/charmbracelet/gum) is available it will be used for command line input.
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
Planter's base configuration is in `~/.config/planter/config.yml`. This file can contain any of the keys used in templates (see below) and will serve as a base configuration for all templates. Any key defined in this file will be overridden if it exists in a template.
|
23
|
+
|
24
|
+
### Scripts.
|
25
|
+
|
26
|
+
Scripts for execution after planting can be stored in `~/.config/planter/scripts` and referenced by filename only. Alternatively, scripts may be stored within a template in a `_scritps` subfolder.
|
27
|
+
|
28
|
+
Scripts can be executable files in any language, and receive the template directory and the planted directory as arguments $1 and $2.
|
29
|
+
|
30
|
+
### Templates
|
31
|
+
|
32
|
+
Templates are directories found in `~/.config/planter/templates/[TEMPLATE_NAME]`. All files and directories inside of these template directories are copied when that template is called. Filenames, directory names, and file contents can all use template placeholders.
|
33
|
+
|
34
|
+
Template placeholders are defined with `%%KEY%%`, where key is the key defined in the `variables` section of the configuration. %%KEY%% placeholders can be used in directory/file names, and in the file contents. These work in any plain text or RTF format document, including XML, so they can be used in things like Scrivener templates and MindNode files as well.
|
35
|
+
|
36
|
+
Each template contains a `_planter.yml` file that defines variables and other configuration options. The file format for all configuration files is [YAML](https://yaml.org/spec/1.2.2/).
|
37
|
+
|
38
|
+
First, there's a `variables` section that defines variables used in the template. It's an array of dictionaries, each dictionary defining one variable. The required fields are `key` (the key used to insert the variable) and `prompt` (the text provided on the command line when asking for the variable). The rest are optional:
|
39
|
+
|
40
|
+
```yaml
|
41
|
+
variables:
|
42
|
+
- key: var_key
|
43
|
+
prompt: Prompt text
|
44
|
+
type: string # [string,multiline,float,integer,number,date] defaults to string
|
45
|
+
# value: (force value, string can include %%variables%% and regexes will be replaced. For date type can be today, time, now, etc.)
|
46
|
+
default: Untitled
|
47
|
+
min: 1
|
48
|
+
max: 5
|
49
|
+
script: # array of scripts, args passed as [script and args] TEMPLATE_DIR PWD
|
50
|
+
- process.py
|
51
|
+
git_init: false # if true, initialize a git repository in the newly-planted directory
|
52
|
+
files: # Dictionary for file handling (see [File-specific handling](#file-specific-handling))
|
53
|
+
replacements: # Dictionary of pattern/replacments for regex substitution, see [Regex replacements](#regex-replacements)
|
54
|
+
repo: # If a repository URL is provided, it will be pulled and duplicated instead of copying a file structure
|
55
|
+
```
|
56
|
+
|
57
|
+
### File-specific handling
|
58
|
+
|
59
|
+
A `files` dictionary can specify how to handle specific files. Options are `copy`, `overwrite`, `merge`, or `ask`. The key for each entry is a filename or glob that matches the source filename (accounting for template variables if applicable):
|
60
|
+
|
61
|
+
```yaml
|
62
|
+
files:
|
63
|
+
"*.py": merge
|
64
|
+
"%%title%%.md": overwrite
|
65
|
+
```
|
66
|
+
|
67
|
+
If `merge` is specified, then the source file is scanned for merge comments and those are merged if they don't exist in the copied/existing file. If no merge comments are defined, then the entire contents of the source file are appended to the destination file (unless the file already matches the source). Merge comments start with `merge` and end with `/merge` and can have any comment syntax preceding them, for example:
|
68
|
+
|
69
|
+
```
|
70
|
+
// merge
|
71
|
+
Merged content
|
72
|
+
// /merge
|
73
|
+
```
|
74
|
+
|
75
|
+
By default files that already exist in the destination directory are not overwritten, and merging allows you to add missing parts to a Rakefile or Makefile, for example.
|
76
|
+
|
77
|
+
If `ask` is specified, a memu will be provided on the command line asking how to handle a file. If the file doesn't already exist, you will be asked only whether to copy the file or not. If it does exist, `overwrite` and `merge` options will be added.
|
78
|
+
|
79
|
+
### Regex replacements
|
80
|
+
|
81
|
+
In addition to manually-placed template variables, you can also specify regular expressions for replacement. The `replacements` dictionary is a set of key/value pairs with the regex pattern as the key, and the replacement as the value. Both should be quoted in almost all circumstances.
|
82
|
+
|
83
|
+
```yaml
|
84
|
+
replacements:
|
85
|
+
"Planter": "%%title:cap%%"
|
86
|
+
"(main|app)\.js": "%%script:lower%%.js"
|
87
|
+
```
|
88
|
+
|
89
|
+
Replacements are performed on both file/directory names and file contents.
|
90
|
+
|
91
|
+
## Usage
|
92
|
+
|
93
|
+
The executable for Planter is `plant`. You can run `plant TEMPLATE` in any directory and TEMPLATE will be planted in the current directory. You can also use `--in PATH` to plant in another directory.
|
94
|
+
|
95
|
+
```
|
96
|
+
Usage: planter [options] TEMPLATE
|
97
|
+
--defaults Accept default values for all variables
|
98
|
+
-i, --in TARGET Plant in TARGET instead of current directory
|
99
|
+
-o, --overwrite Overwrite existing files
|
100
|
+
-k, --var=KEY:VALUE,KEY:VALUE... Pass a variable on the command line as KEY:VALUE pairs. Can be used multiple times.
|
101
|
+
-d, --debug Display version number
|
102
|
+
-h, --help Display this screen, or list variables for template argument
|
103
|
+
-v, --version Display version number
|
104
|
+
```
|
105
|
+
|
106
|
+
Files will be copied, but existing files will not be overwritten unless otherwise noted in the `files` configuration for the template.
|
107
|
+
|
108
|
+
Some directories like `.git` and files like `_planter.yml` are automatically ignored. If you want to create a git repository, include the `git_init: true` key in config.
|
109
|
+
|
110
|
+
When `plant` is run, any defined variables will be requested on the command line using the defined prompt. If a `default` key is specified, hitting return at the prompt will accept the default value.
|
111
|
+
|
112
|
+
Variables can be passed on the command line with `--var KEY:VALUE`. This flag can contain a comma-separated list, e.g. `--var KEY:VALUE,KEY:VALUE` or used multiple times in the same command. Variables passed on the command line will not be prompted for when processing variables.
|
113
|
+
|
114
|
+
<!--GITHUB-->
|
115
|
+
|
116
|
+
## Documentation
|
117
|
+
|
118
|
+
- [YARD documentation][RubyDoc] is hosted by RubyDoc.info.
|
119
|
+
- [Interactive documentation][Omniref] is hosted by Omniref.
|
120
|
+
|
121
|
+
[RubyDoc]: http://www.rubydoc.info/gems/planter-cli
|
122
|
+
|
123
|
+
## Development and Testing
|
124
|
+
|
125
|
+
### Source Code
|
126
|
+
|
127
|
+
The [planter-cli source] is hosted on GitHub.
|
128
|
+
|
129
|
+
Clone the project with
|
130
|
+
|
131
|
+
```
|
132
|
+
$ git clone https://github.com/ttscoff/planter-cli.git
|
133
|
+
```
|
134
|
+
|
135
|
+
[planter-cli source]: https://github.com/ttscoff/planter-cli
|
136
|
+
|
137
|
+
### Requirements
|
138
|
+
|
139
|
+
You will need [Ruby] with [Bundler].
|
140
|
+
|
141
|
+
Install the development dependencies with
|
142
|
+
|
143
|
+
```
|
144
|
+
$ bundle
|
145
|
+
```
|
146
|
+
|
147
|
+
[Bundler]: http://bundler.io/
|
148
|
+
[Ruby]: https://www.ruby-lang.org/
|
149
|
+
|
150
|
+
### Rake
|
151
|
+
|
152
|
+
Run `$ rake -T` to see all Rake tasks.
|
153
|
+
|
154
|
+
```
|
155
|
+
rake build # Build planter-cli-0.0.3.gem into the...
|
156
|
+
rake build:checksum # Generate SHA512 checksum of planter-...
|
157
|
+
rake bump:current[no_args] # Show current gem version
|
158
|
+
rake bump:file[no_args] # Show version file path
|
159
|
+
rake bump:major[no_args] # Bump major part of gem version
|
160
|
+
rake bump:minor[no_args] # Bump minor part of gem version
|
161
|
+
rake bump:patch[no_args] # Bump patch part of gem version
|
162
|
+
rake bump:pre[no_args] # Bump pre part of gem version
|
163
|
+
rake bump:set # Sets the version number using the VE...
|
164
|
+
rake bump:show-next[no_args] # Show next major|minor|patch|pre version
|
165
|
+
rake clean # Remove any temporary products
|
166
|
+
rake clobber # Remove any generated files / Clobber...
|
167
|
+
rake clobber_packages # Remove packages
|
168
|
+
rake cver # Changelog version check
|
169
|
+
rake dockertest[version,login,attempt] # Run tests in Docker
|
170
|
+
rake install # Build and install planter-cli-0.0.3....
|
171
|
+
rake install:local # Build and install planter-cli-0.0.3....
|
172
|
+
rake package # alias for build
|
173
|
+
rake release[remote] # Create tag v0.0.3 and build and push...
|
174
|
+
rake rubocop # Run RuboCop
|
175
|
+
rake rubocop:autocorrect # Autocorrect RuboCop offenses (only w...
|
176
|
+
rake rubocop:autocorrect_all # Autocorrect RuboCop offenses (safe a...
|
177
|
+
rake spec # Run RSpec code examples
|
178
|
+
rake test # Run test suite
|
179
|
+
rake ver # Development version check
|
180
|
+
rake yard # Generate YARD Documentation
|
181
|
+
```
|
182
|
+
|
183
|
+
### Guard
|
184
|
+
|
185
|
+
Guard tasks have been separated into the following groups:
|
186
|
+
`doc`, `lint`, and `unit`.
|
187
|
+
By default, `$ guard` will generate documentation, lint, and run unit tests.
|
188
|
+
|
189
|
+
## Contributing
|
190
|
+
|
191
|
+
Please submit and comment on bug reports and feature requests.
|
192
|
+
|
193
|
+
To submit a patch:
|
194
|
+
|
195
|
+
1. Fork it (https://github.com/ttscoff/planter-cli/fork).
|
196
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
197
|
+
3. Make changes. Write and run tests.
|
198
|
+
4. Commit your changes (`git commit -am 'Add some feature'`).
|
199
|
+
5. Push to the branch (`git push origin my-new-feature`).
|
200
|
+
6. Create a new Pull Request.
|
201
|
+
|
202
|
+
## License
|
203
|
+
|
204
|
+
This Ruby gem is licensed under the MIT license.
|
205
|
+
|
206
|
+
## Warranty
|
207
|
+
|
208
|
+
This software is provided "as is" and without any express or
|
209
|
+
implied warranties, including, without limitation, the implied
|
210
|
+
warranties of merchantibility and fitness for a particular
|
211
|
+
purpose.
|
212
|
+
|
213
|
+
<!--END GITHUB-->
|
214
|
+
<!--END README-->
|