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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e5445d6dfa3c8e0663006ce933f45f6e0717ccb4be51c67da0901c9606a5c70c
|
4
|
+
data.tar.gz: 0ee188813bbc0bb274837b130231dd937f403484d1a26adccee36b8126d2ee3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78a345ff2396c29c7beeadda989780003b5cc63174e4b9bcfcd0344350d8160fbb403231208ba1c3ca0d4bb66083711e675f5aad7dff5d14b226d59f31be6554
|
7
|
+
data.tar.gz: 1dc8ab448b3674319f6a469439d7b8dd6657a9c85061358fee7c7280a1fe9bb5910e4bf5d69e3223511bfccbd77c9e09c666b1441619ec0489e25d9c934fc048
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Parts of this file were adapted from
|
2
|
+
# GitHub’s collection of .gitignore file templates
|
3
|
+
# which are Copyright (c) 2016 GitHub, Inc.
|
4
|
+
# and released under the MIT License.
|
5
|
+
# For more details, visit the project page:
|
6
|
+
# https://github.com/github/gitignore
|
7
|
+
|
8
|
+
*.gem
|
9
|
+
*.rbc
|
10
|
+
/.config
|
11
|
+
/coverage/
|
12
|
+
/InstalledFiles
|
13
|
+
/pkg/
|
14
|
+
/spec/reports/
|
15
|
+
/spec/examples.txt
|
16
|
+
/test/tmp/
|
17
|
+
/test/version_tmp/
|
18
|
+
/tmp/
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
|
25
|
+
## Documentation cache and generated files:
|
26
|
+
/.yardoc/
|
27
|
+
/_yardoc/
|
28
|
+
/doc/
|
29
|
+
/rdoc/
|
30
|
+
|
31
|
+
## Environment normalization:
|
32
|
+
/.bundle/
|
33
|
+
/vendor/bundle
|
34
|
+
/lib/bundler/man/
|
35
|
+
|
36
|
+
# for a library or gem, you might want to ignore these files since the code is
|
37
|
+
# intended to run in multiple environments; otherwise, check them in:
|
38
|
+
Gemfile.lock
|
39
|
+
.ruby-version
|
40
|
+
.ruby-gemset
|
41
|
+
|
42
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
43
|
+
.rvmrc
|
44
|
+
test
|
data/.irbrc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
IRB.conf[:AUTO_INDENT] = true
|
3
|
+
|
4
|
+
require "irb/completion"
|
5
|
+
require_relative "lib/planter"
|
6
|
+
|
7
|
+
# rubocop:disable Style/MixinUsage
|
8
|
+
include Planter # standard:disable all
|
9
|
+
# rubocop:enable Style/MixinUsage
|
10
|
+
|
11
|
+
require "awesome_print"
|
12
|
+
AwesomePrint.irb!
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
Style/RegexpLiteral:
|
2
|
+
Exclude:
|
3
|
+
- Guardfile
|
4
|
+
|
5
|
+
require:
|
6
|
+
- rubocop-rspec
|
7
|
+
- rubocop-rake
|
8
|
+
|
9
|
+
AllCops:
|
10
|
+
Include:
|
11
|
+
- Gemfile
|
12
|
+
- Guardfile
|
13
|
+
- Rakefile
|
14
|
+
- bin/planter
|
15
|
+
- lib/**/*.rb
|
16
|
+
Exclude:
|
17
|
+
- pkg/**/*.rb
|
18
|
+
- test/*
|
19
|
+
|
20
|
+
Style/MutableConstant:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/SpecialGlobalVars:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Security/YAMLLoad:
|
27
|
+
Exclude:
|
28
|
+
- 'lib/**/*.rb'
|
29
|
+
|
30
|
+
Style/StringLiterals:
|
31
|
+
Enabled: true
|
32
|
+
EnforcedStyle: single_quotes
|
33
|
+
|
34
|
+
Style/StringLiteralsInInterpolation:
|
35
|
+
Enabled: true
|
36
|
+
EnforcedStyle: single_quotes
|
37
|
+
|
38
|
+
Layout/LineLength:
|
39
|
+
Max: 120
|
40
|
+
|
41
|
+
Metrics/MethodLength:
|
42
|
+
Max: 45
|
43
|
+
|
44
|
+
Metrics/BlockLength:
|
45
|
+
Max: 45
|
46
|
+
Exclude:
|
47
|
+
- Rakefile
|
48
|
+
- bin/howzit
|
49
|
+
- lib/*.rb
|
50
|
+
|
51
|
+
Metrics/ClassLength:
|
52
|
+
Max: 300
|
53
|
+
|
54
|
+
Metrics/PerceivedComplexity:
|
55
|
+
Max: 30
|
56
|
+
|
57
|
+
# Metrics/AbcSize:
|
58
|
+
# Max: 45
|
59
|
+
|
60
|
+
Metrics/CyclomaticComplexity:
|
61
|
+
Max: 20
|
62
|
+
|
63
|
+
Metrics/AbcSize:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Metrics/ModuleLength:
|
67
|
+
Max: 174
|
68
|
+
|
69
|
+
Security/YAMLLoad:
|
70
|
+
Exclude:
|
71
|
+
- '**/*.rb'
|
72
|
+
|
73
|
+
Style/ModuleFunction:
|
74
|
+
Exclude:
|
75
|
+
- 'lib/planter/color.rb'
|
76
|
+
|
77
|
+
Style/RaiseArgs:
|
78
|
+
EnforcedStyle: compact
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
### 0.0.3
|
2
|
+
|
3
|
+
2024-08-28 09:46
|
4
|
+
|
5
|
+
#### CHANGED
|
6
|
+
|
7
|
+
- Change template config from _config.yml to _planter.yml
|
8
|
+
|
9
|
+
#### NEW
|
10
|
+
|
11
|
+
- Replacements key in config for a dictionary of regex patterns and replacements
|
12
|
+
- Add repo key to config, pull a git repo
|
13
|
+
- Allow `value:` to be specified for any key. If the value contains %%vars%% or matches regexes, it will be updated and included without prompting.
|
14
|
+
- Add multiline type allowing for paragraph(s)
|
15
|
+
|
16
|
+
#### IMPROVED
|
17
|
+
|
18
|
+
- Adding tests
|
19
|
+
- Better error reporting
|
20
|
+
- More custom error handling
|
21
|
+
- Rubocop warnings
|
22
|
+
- Better Docker config for testing
|
23
|
+
|
24
|
+
#### FIXED
|
25
|
+
|
26
|
+
- Merge wasn't populating template placeholders
|
27
|
+
- Remove flags from hashbang for wider compatibility
|
28
|
+
- Place main config in ~/.config/planter and not in planter/templates
|
29
|
+
|
30
|
+
### 0.0.2
|
31
|
+
|
32
|
+
2024-08-26 10:25
|
33
|
+
|
34
|
+
#### NEW:
|
35
|
+
|
36
|
+
- Add repo key to config, pull a git rep
|
37
|
+
- replacements key in config for a dictionary of regex patterns and replacements
|
38
|
+
|
39
|
+
#### IMPROVED
|
40
|
+
|
41
|
+
- Better error reporting
|
42
|
+
|
43
|
+
#### FIXED
|
44
|
+
|
45
|
+
- Merge wasn't populating template placeholders
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
scope groups: %i[doc lint unit]
|
4
|
+
|
5
|
+
group :doc do
|
6
|
+
guard :yard do
|
7
|
+
watch(%r{^lib/(.+)\.rb$})
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
group :lint do
|
12
|
+
guard :rubocop do
|
13
|
+
watch(%r{.+\.rb$})
|
14
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
group :unit do
|
19
|
+
guard :rspec, cmd: 'bundle exec rspec --color --format Fuubar' do
|
20
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
21
|
+
watch(%r{^lib/planter/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
22
|
+
watch(%r{^spec/.+_spec\.rb$})
|
23
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
24
|
+
end
|
25
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Brett Terpstra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
Plant a directory structure and files using templates.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install planter-cli
|
8
|
+
|
9
|
+
If you run into errors, try `gem install --user-install planter-cli`, or as a last ditch effort, `sudo gem install planter-cli`.
|
10
|
+
|
11
|
+
### Optional
|
12
|
+
|
13
|
+
If [Gum](https://github.com/charmbracelet/gum) is available it will be used for command line input.
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
|
17
|
+
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.
|
18
|
+
|
19
|
+
### Scripts.
|
20
|
+
|
21
|
+
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.
|
22
|
+
|
23
|
+
Scripts can be executable files in any language, and receive the template directory and the planted directory as arguments $1 and $2.
|
24
|
+
|
25
|
+
### Templates
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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/).
|
32
|
+
|
33
|
+
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:
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
variables:
|
37
|
+
- key: var_key
|
38
|
+
prompt: Prompt text
|
39
|
+
type: string # [string,multiline,float,integer,number,date] defaults to string
|
40
|
+
# value: (force value, string can include %%variables%% and regexes will be replaced. For date type can be today, time, now, etc.)
|
41
|
+
default: Untitled
|
42
|
+
min: 1
|
43
|
+
max: 5
|
44
|
+
script: # array of scripts, args passed as [script and args] TEMPLATE_DIR PWD
|
45
|
+
- process.py
|
46
|
+
git_init: false # if true, initialize a git repository in the newly-planted directory
|
47
|
+
files: # Dictionary for file handling (see [File-specific handling](#file-specific-handling))
|
48
|
+
replacements: # Dictionary of pattern/replacments for regex substitution, see [Regex replacements](#regex-replacements)
|
49
|
+
repo: # If a repository URL is provided, it will be pulled and duplicated instead of copying a file structure
|
50
|
+
```
|
51
|
+
|
52
|
+
### File-specific handling
|
53
|
+
|
54
|
+
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):
|
55
|
+
|
56
|
+
```yaml
|
57
|
+
files:
|
58
|
+
"*.py": merge
|
59
|
+
"%%title%%.md": overwrite
|
60
|
+
```
|
61
|
+
|
62
|
+
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:
|
63
|
+
|
64
|
+
```
|
65
|
+
// merge
|
66
|
+
Merged content
|
67
|
+
// /merge
|
68
|
+
```
|
69
|
+
|
70
|
+
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.
|
71
|
+
|
72
|
+
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.
|
73
|
+
|
74
|
+
### Regex replacements
|
75
|
+
|
76
|
+
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.
|
77
|
+
|
78
|
+
```yaml
|
79
|
+
replacements:
|
80
|
+
"Planter": "%%title:cap%%"
|
81
|
+
"(main|app)\.js": "%%script:lower%%.js"
|
82
|
+
```
|
83
|
+
|
84
|
+
Replacements are performed on both file/directory names and file contents.
|
85
|
+
|
86
|
+
## Usage
|
87
|
+
|
88
|
+
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.
|
89
|
+
|
90
|
+
```
|
91
|
+
Usage: planter [options] TEMPLATE
|
92
|
+
--defaults Accept default values for all variables
|
93
|
+
-i, --in TARGET Plant in TARGET instead of current directory
|
94
|
+
-o, --overwrite Overwrite existing files
|
95
|
+
-k, --var=KEY:VALUE,KEY:VALUE... Pass a variable on the command line as KEY:VALUE pairs. Can be used multiple times.
|
96
|
+
-d, --debug Display version number
|
97
|
+
-h, --help Display this screen, or list variables for template argument
|
98
|
+
-v, --version Display version number
|
99
|
+
```
|
100
|
+
|
101
|
+
Files will be copied, but existing files will not be overwritten unless otherwise noted in the `files` configuration for the template.
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
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.
|
106
|
+
|
107
|
+
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.
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
## Documentation
|
112
|
+
|
113
|
+
- [YARD documentation][RubyDoc] is hosted by RubyDoc.info.
|
114
|
+
- [Interactive documentation][Omniref] is hosted by Omniref.
|
115
|
+
|
116
|
+
[RubyDoc]: http://www.rubydoc.info/gems/planter-cli
|
117
|
+
|
118
|
+
## Development and Testing
|
119
|
+
|
120
|
+
### Source Code
|
121
|
+
|
122
|
+
The [planter-cli source] is hosted on GitHub.
|
123
|
+
|
124
|
+
Clone the project with
|
125
|
+
|
126
|
+
```
|
127
|
+
$ git clone https://github.com/ttscoff/planter-cli.git
|
128
|
+
```
|
129
|
+
|
130
|
+
[planter-cli source]: https://github.com/ttscoff/planter-cli
|
131
|
+
|
132
|
+
### Requirements
|
133
|
+
|
134
|
+
You will need [Ruby] with [Bundler].
|
135
|
+
|
136
|
+
Install the development dependencies with
|
137
|
+
|
138
|
+
```
|
139
|
+
$ bundle
|
140
|
+
```
|
141
|
+
|
142
|
+
[Bundler]: http://bundler.io/
|
143
|
+
[Ruby]: https://www.ruby-lang.org/
|
144
|
+
|
145
|
+
### Rake
|
146
|
+
|
147
|
+
Run `$ rake -T` to see all Rake tasks.
|
148
|
+
|
149
|
+
```
|
150
|
+
rake build # Build planter-cli-0.0.3.gem into the...
|
151
|
+
rake build:checksum # Generate SHA512 checksum of planter-...
|
152
|
+
rake bump:current[no_args] # Show current gem version
|
153
|
+
rake bump:file[no_args] # Show version file path
|
154
|
+
rake bump:major[no_args] # Bump major part of gem version
|
155
|
+
rake bump:minor[no_args] # Bump minor part of gem version
|
156
|
+
rake bump:patch[no_args] # Bump patch part of gem version
|
157
|
+
rake bump:pre[no_args] # Bump pre part of gem version
|
158
|
+
rake bump:set # Sets the version number using the VE...
|
159
|
+
rake bump:show-next[no_args] # Show next major|minor|patch|pre version
|
160
|
+
rake clean # Remove any temporary products
|
161
|
+
rake clobber # Remove any generated files / Clobber...
|
162
|
+
rake clobber_packages # Remove packages
|
163
|
+
rake cver # Changelog version check
|
164
|
+
rake dockertest[version,login,attempt] # Run tests in Docker
|
165
|
+
rake install # Build and install planter-cli-0.0.3....
|
166
|
+
rake install:local # Build and install planter-cli-0.0.3....
|
167
|
+
rake package # alias for build
|
168
|
+
rake release[remote] # Create tag v0.0.3 and build and push...
|
169
|
+
rake rubocop # Run RuboCop
|
170
|
+
rake rubocop:autocorrect # Autocorrect RuboCop offenses (only w...
|
171
|
+
rake rubocop:autocorrect_all # Autocorrect RuboCop offenses (safe a...
|
172
|
+
rake spec # Run RSpec code examples
|
173
|
+
rake test # Run test suite
|
174
|
+
rake ver # Development version check
|
175
|
+
rake yard # Generate YARD Documentation
|
176
|
+
```
|
177
|
+
|
178
|
+
### Guard
|
179
|
+
|
180
|
+
Guard tasks have been separated into the following groups:
|
181
|
+
`doc`, `lint`, and `unit`.
|
182
|
+
By default, `$ guard` will generate documentation, lint, and run unit tests.
|
183
|
+
|
184
|
+
## Contributing
|
185
|
+
|
186
|
+
Please submit and comment on bug reports and feature requests.
|
187
|
+
|
188
|
+
To submit a patch:
|
189
|
+
|
190
|
+
1. Fork it (https://github.com/ttscoff/planter-cli/fork).
|
191
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
192
|
+
3. Make changes. Write and run tests.
|
193
|
+
4. Commit your changes (`git commit -am 'Add some feature'`).
|
194
|
+
5. Push to the branch (`git push origin my-new-feature`).
|
195
|
+
6. Create a new Pull Request.
|
196
|
+
|
197
|
+
## License
|
198
|
+
|
199
|
+
This Ruby gem is licensed under the MIT license.
|
200
|
+
|
201
|
+
## Warranty
|
202
|
+
|
203
|
+
This software is provided "as is" and without any express or
|
204
|
+
implied warranties, including, without limitation, the implied
|
205
|
+
warranties of merchantibility and fitness for a particular
|
206
|
+
purpose.
|
207
|
+
|
208
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bump/tasks'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
require 'yard'
|
8
|
+
require 'tty-spinner'
|
9
|
+
|
10
|
+
## Docker error class
|
11
|
+
class DockerError < StandardError
|
12
|
+
def initialize(msg = nil)
|
13
|
+
msg = msg ? "Docker error: #{msg}" : 'Docker error'
|
14
|
+
super(msg)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: %i[test yard]
|
19
|
+
|
20
|
+
desc 'Run test suite'
|
21
|
+
task test: %i[rubocop spec]
|
22
|
+
|
23
|
+
RSpec::Core::RakeTask.new do |t|
|
24
|
+
t.rspec_opts = '--format documentation'
|
25
|
+
end
|
26
|
+
|
27
|
+
RuboCop::RakeTask.new do |t|
|
28
|
+
t.formatters = ['progress']
|
29
|
+
end
|
30
|
+
|
31
|
+
YARD::Rake::YardocTask.new
|
32
|
+
|
33
|
+
desc 'Remove packages'
|
34
|
+
task :clobber_packages do
|
35
|
+
FileUtils.rm_f 'pkg/*'
|
36
|
+
end
|
37
|
+
# Make a prerequisite of the preexisting clobber task
|
38
|
+
desc 'Clobber files'
|
39
|
+
task clobber: :clobber_packages
|
40
|
+
|
41
|
+
desc 'Development version check'
|
42
|
+
task :ver do
|
43
|
+
gver = `git ver`
|
44
|
+
cver = IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
|
45
|
+
res = `grep VERSION lib/planter/version.rb`
|
46
|
+
version = res.match(/VERSION *= *['"](\d+\.\d+\.\d+(\w+)?)/)[1]
|
47
|
+
puts "git tag: #{gver}"
|
48
|
+
puts "version.rb: #{version}"
|
49
|
+
puts "changelog: #{cver}"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Get Script Version'
|
53
|
+
task :sver do
|
54
|
+
res = `grep VERSION lib/planter/version.rb`
|
55
|
+
version = res.match(/VERSION *= *['"](\d+\.\d+\.\d+(\w+)?)/)[1]
|
56
|
+
print version
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Changelog version check'
|
60
|
+
task :cver do
|
61
|
+
puts IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Run tests in Docker'
|
65
|
+
task :dockertest, :version, :login, :attempt do |_, args|
|
66
|
+
args.with_defaults(version: 'all', login: false, attempt: 1)
|
67
|
+
`open -a Docker`
|
68
|
+
|
69
|
+
Rake::Task['clobber'].reenable
|
70
|
+
Rake::Task['clobber'].invoke
|
71
|
+
Rake::Task['build'].reenable
|
72
|
+
Rake::Task['build'].invoke
|
73
|
+
|
74
|
+
case args[:version]
|
75
|
+
when /^a/
|
76
|
+
%w[6 7 3].each do |v|
|
77
|
+
Rake::Task['dockertest'].reenable
|
78
|
+
Rake::Task['dockertest'].invoke(v, false)
|
79
|
+
end
|
80
|
+
Process.exit 0
|
81
|
+
when /^3/
|
82
|
+
version = '3.0'
|
83
|
+
img = 'plantertest3'
|
84
|
+
file = 'docker/Dockerfile-3.0'
|
85
|
+
when /6$/
|
86
|
+
version = '2.6'
|
87
|
+
img = 'plantertest26'
|
88
|
+
file = 'docker/Dockerfile-2.6'
|
89
|
+
when /(^2|7$)/
|
90
|
+
version = '2.7'
|
91
|
+
img = 'plantertest27'
|
92
|
+
file = 'docker/Dockerfile-2.7'
|
93
|
+
else
|
94
|
+
version = '3.0.1'
|
95
|
+
img = 'plantertest'
|
96
|
+
file = 'docker/Dockerfile'
|
97
|
+
end
|
98
|
+
|
99
|
+
puts `docker build . --file #{file} -t #{img}`
|
100
|
+
|
101
|
+
raise DockerError.new('Error building docker image') unless $?.success?
|
102
|
+
|
103
|
+
dirs = {
|
104
|
+
File.dirname(__FILE__) => '/planter',
|
105
|
+
File.expand_path('~/.config') => '/root/.config'
|
106
|
+
}
|
107
|
+
dir_args = dirs.map { |s, d| " -v '#{s}:#{d}'" }.join(' ')
|
108
|
+
exec "docker run #{dir_args} -it #{img} /bin/bash -l" if args[:login]
|
109
|
+
|
110
|
+
spinner = TTY::Spinner.new("[:spinner] Running tests (#{args[:version]})...", hide_cursor: true)
|
111
|
+
|
112
|
+
spinner.auto_spin
|
113
|
+
res = `docker run --rm #{dir_args} -it #{img}`
|
114
|
+
# raise DockerError.new('Error running docker image') unless $?.success?
|
115
|
+
|
116
|
+
# commit = puts `bash -c "docker commit $(docker ps -a|grep #{img}|awk '{print $1}'|head -n 1) #{img}"`.strip
|
117
|
+
$?.success? ? spinner.success : spinner.error
|
118
|
+
spinner.stop
|
119
|
+
|
120
|
+
# puts res
|
121
|
+
# puts commit&.empty? ? "Error commiting Docker tag #{img}" : "Committed Docker tag #{img}"
|
122
|
+
rescue DockerError
|
123
|
+
raise StandardError.new('Docker not responding') if args[:attempt] > 3
|
124
|
+
|
125
|
+
`open -a Docker`
|
126
|
+
sleep 3
|
127
|
+
Rake::Task['dockertest'].reenable
|
128
|
+
Rake::Task['dockertest'].invoke(args[:version], args[:login], args[:attempt] + 1)
|
129
|
+
end
|
130
|
+
|
131
|
+
desc 'alias for build'
|
132
|
+
task package: :build
|