setup_script_generator 0.2.3 → 0.2.4

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: c829d0750e6fccda26bffda6ec50825da73518a8c93064848a8c9c46071d4e47
4
- data.tar.gz: 7c02754e0c5f48330263ffa97a3ce1734a1806f36a66b81556189dcd2a7f9421
3
+ metadata.gz: 7abbab871c8809934382abcaded81af412afe8a30837dbbb9337d48e8eb0fb02
4
+ data.tar.gz: 9b220d798bac841e9436822710fc55f131b284b660cbbad30cd03f3ffb5ca71b
5
5
  SHA512:
6
- metadata.gz: 3f7d03380b393dc293bd61ceb27399ffc374abbfcb672a1d588b3b33325827958d817eb13a4afbbc2ddfa5031d581cd549721088228e184230f9d7bd4021d402
7
- data.tar.gz: aff1f842639f2acbe98238cc8f6ae9f68900bd90752dfdba934988c7b5d60d1f7c8e96318ce1e0cd4233fa0b59d404aa91f400c5296c79788829bfa57e47a828
6
+ metadata.gz: b04ff789fdf36f3914d30a3bb1dd37881d637b4566d850a3c5aa681cbdd4570f6f9b11146f4d12b6bf415a026ea93bde4d6ff16e57108c71f3ac25da3ef57385
7
+ data.tar.gz: 314df7615aa78a2cb4e9881c876e0b1669658bc92f2d9ad5d20c5fbf99ae1fd459688f4daf2a1b8e203c4ce3402d0c5c132c1e39155815abbc34fd1abd14a67e
@@ -0,0 +1,2 @@
1
+ [README.md]
2
+ max_line_length = unset
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
+ Gemfile.lock
2
3
  pkg
@@ -0,0 +1 @@
1
+ ruby 2.7.1
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in setup_script_generator.gemspec
6
6
  gemspec
7
+
8
+ gem "rake"
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Elliot Winkler
3
+ Copyright (c) 2019-2020 Elliot Winkler
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,81 +1,96 @@
1
1
  # Setup Script Generator
2
2
 
3
- Every project needs a [setup script][setup-script]. This is an executable that a
4
- new contributor to the project can run in order to quickly prepare his or her
5
- machine for development.
3
+ Every project needs a [setup script][setup-script]
4
+ to quickly ready new developers for contributing to the project.
5
+ However, a good setup script is time-consuming to write:
6
6
 
7
7
  [setup-script]: https://thoughtbot.com/blog/shell-script-suggestions-for-speedy-setups
8
8
 
9
- The problem is that a good setup script is time-consuming to write:
9
+ * The script must make sure that the proper version of your project's language is installed,
10
+ taking into account the usage of version managers.
11
+ * The script must be idempotent,
12
+ installing new requirements while skipping over existing ones.
13
+ * The script must provide friendly messages (successful or otherwise).
14
+ * The script must be quick to run.
15
+ * The script must be usable on multiple platforms.
16
+ * The script must be easy to read and maintain.
10
17
 
11
- * The script must be portable, which means handling installation of software
12
- using package managers on different platforms.
13
- * The script must be snappy, which (along with the previous point) dictates the
14
- use of Bash.
15
- * The script must make sure that the proper version of your project's
16
- implementation language is installed, and if said language has version
17
- managers (such as for Ruby or Node), the script must take them into account
18
- as well.
19
- * The script must provide friendly errors if any checks fail.
20
- (Bonus points for colors and/or emoji.)
21
- * The script must be idempotent, so that if changes to the development are
22
- made, the script can be run again, and any requirements that are already
23
- satisfied will be skipped, while new requirements will be installed.
24
- * The script must be easy to read and maintain in the future.
18
+ Given these constraints,
19
+ this project generates a setup script that you can place in your own project.
20
+ This script is implemented in Bash
21
+ so that it is is performant, portable, and maintainable.
25
22
 
26
- Given this, this project provides a way to generate a setup script for your own
27
- project, so that you can keep all of your teammates on the same page and offer
28
- them a nice experience going forward.
29
-
30
- ## Installation
31
-
32
- Currently, the generator is available through a Ruby gem. You can install this
33
- gem by first installing Ruby, then running:
23
+ ## Usage
34
24
 
35
- gem install setup_script_generator
25
+ Currently, the generator is available through a Ruby gem.
26
+ You can install this gem by first installing Ruby, then by running:
36
27
 
37
- ## Usage
28
+ ```
29
+ gem install setup_script_generator
30
+ ```
38
31
 
39
- After installing the gem, navigate to your project. Generally, setup scripts are
40
- kept in `bin`, so to generate a script, run:
32
+ After installing the gem, navigate to your project.
33
+ You now have the `generate-setup` command
34
+ which will allow you to generate a setup script where you like.
35
+ A common location is `bin/setup`, so you could say:
41
36
 
42
37
  generate-setup bin/setup
43
38
 
44
- Now, by default, this won't do a whole lot. That's because a setup script is
45
- much more useful with *provisions*, which add checks and steps for a particular
46
- language, framework, or service. For instance, if your project requires Ruby,
47
- then you'd want to say:
39
+ Now open up this file in your editor.
40
+ By default, this script is fairly empty,
41
+ although it does offer a section at the top
42
+ to which you can add custom code:
48
43
 
49
- generate-setup bin/setup --provision ruby
44
+ ``` bash
45
+ provision-project() {
46
+ # ...
47
+ }
48
+ ```
50
49
 
51
- You can add more than one provision if that's what you need:
50
+ While it is perfectly fine to update this function,
51
+ you will probably find it more useful to run `generate-setup` with a set of *provisions*.
52
+ These extend your script with checks and installation steps
53
+ for languages, frameworks, or services on which your project relies.
54
+ For instance, if your project requires Ruby,
55
+ then you'd want to run:
52
56
 
53
- generate-setup bin/setup --provision ruby --provision node
57
+ ```
58
+ generate-setup bin/setup --provision ruby
59
+ ```
54
60
 
55
- You can get a list of available provisions by running:
61
+ (Don't worry, if you've already run `generate-setup`,
62
+ you can re-run it at any point in the future
63
+ to add or remove provisions.)
56
64
 
57
- generate-setup --list-provisions
65
+ You can also use more than one provision if that's what you need:
58
66
 
59
- And if you want to view the setup script before you generate it, you can tack
60
- `--dry-run` to the end of the command. For instance:
67
+ ```
68
+ generate-setup bin/setup --provision ruby --provision node
69
+ ```
61
70
 
62
- generate-setup bin/setup --provision ruby --dry-run
71
+ And you can get a list of available provisions by running:
72
+
73
+ ```
74
+ generate-setup --list-provisions
75
+ ```
63
76
 
64
77
  Finally, to see the full list of options, run:
65
78
 
66
- generate-setup --help
79
+ ```
80
+ generate-setup --help
81
+ ```
67
82
 
68
83
  ## Development
69
84
 
70
- Naturally, this gem comes with its own setup script you can use to get started.
71
- Just run:
72
-
73
- bin/setup
85
+ Naturally, this project comes with its own setup script.
86
+ Simply run this command to get started:
74
87
 
75
- To release a new version, update `version.rb`, then run `rake release`.
88
+ ```
89
+ bin/setup
90
+ ```
76
91
 
77
92
  ## Author/License
78
93
 
79
- (c) 2019 Elliot Winkler (<elliot.winkler@gmail.com>).
80
-
81
- Available under the [MIT license](LICENSE.txt).
94
+ Setup Script Generator is copyright © 2019-2020 Elliot Winkler
95
+ (<elliot.winkler@gmail.com>)
96
+ and is released under the [MIT license](LICENSE.txt).
data/bin/setup CHANGED
@@ -17,12 +17,12 @@ provision-project() {
17
17
 
18
18
  ### DON'T MODIFY ANYTHING BELOW THIS LINE! #####################################
19
19
 
20
- # This setup script was generated with setup_script_generator 0.2.1,
20
+ # This setup script was generated with setup_script_generator 0.2.3,
21
21
  # available on RubyGems.
22
22
  #
23
23
  # To regenerate this section, install the gem and run:
24
24
  #
25
- # generate-setup
25
+ # generate-setup -p ruby
26
26
  #
27
27
 
28
28
  # --- SETUP --------------------------------------------------------------------
@@ -177,10 +177,106 @@ setup() {
177
177
  cd "$(dirname "$(dirname "$0")")"
178
178
  check-for-package-manager
179
179
  install-development-libraries
180
- provision-project
180
+ run-provisions
181
+ if type provision-project &>/dev/null; then
182
+ provision-project
183
+ fi
181
184
  success "Setup complete!"
182
185
  }
183
186
 
187
+ # --- RUBY ---------------------------------------------------------------------
188
+
189
+ provision-ruby() {
190
+ USE_BUNDLER_1=0
191
+
192
+ if [[ -f .tool-versions ]]; then
193
+ REQUIRED_RUBY_VERSION=$(cat .tool-versions | grep '^ruby ' | sed -Ee 's/^ruby (.+)$/\1/')
194
+ elif [[ -f .ruby-version ]]; then
195
+ REQUIRED_RUBY_VERSION=$(cat .ruby-version)
196
+ else
197
+ error "You don't seem to have a Ruby version set in your project."
198
+ print-wrapped "\
199
+ You'll need to create either a .tool-versions file or .ruby-version file in your
200
+ project before you can run this script."
201
+ exit 1
202
+ fi
203
+
204
+ ensure-ruby-development-libraries-installed
205
+ ensure-ruby-installed
206
+ ensure-project-ruby-dependencies-installed
207
+ }
208
+
209
+ ensure-ruby-development-libraries-installed() {
210
+ local platform=$(determine-platform)
211
+
212
+ if [[ $platform == "linux" ]]; then
213
+ banner "Installing Ruby development libraries"
214
+ install apt=ruby-dev rpm=ruby-devel
215
+ fi
216
+ }
217
+
218
+ ensure-ruby-installed() {
219
+ if has-executable asdf; then
220
+ if ! (asdf current ruby | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
221
+ banner "Installing Ruby $REQUIRED_RUBY_VERSION with asdf"
222
+ asdf install ruby $REQUIRED_RUBY_VERSION
223
+ fi
224
+ elif has-executable rbenv; then
225
+ if ! (rbenv versions | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
226
+ banner "Installing Ruby $REQUIRED_RUBY_VERSION with rbenv"
227
+ rbenv install --skip-existing "$REQUIRED_RUBY_VERSION"
228
+ fi
229
+ elif has-executable chruby-exec; then
230
+ PREFIX='' source /usr/local/share/chruby/chruby.sh
231
+ if ! (chruby '' | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
232
+ if has-executable install-ruby; then
233
+ banner "Installing Ruby $REQUIRED_RUBY_VERSION with install-ruby"
234
+ install-ruby "$REQUIRED_RUBY_VERSION"
235
+ else
236
+ error "Please use chruby to install Ruby $REQUIRED_RUBY_VERSION!"
237
+ fi
238
+ fi
239
+ elif has-executable rvm; then
240
+ if ! (rvm list | grep $required_ruby_version'\>' &>/dev/null); then
241
+ banner "Installing Ruby $required_ruby_version with rvm"
242
+ rvm install $required_ruby_version
243
+ rvm use $required_ruby_version
244
+ fi
245
+ else
246
+ error "You don't seem to have a Ruby manager installed."
247
+ print-wrapped "\
248
+ We recommend using asdf. You can find instructions to install it here:
249
+
250
+ https://asdf-vm.com
251
+
252
+ When you're done, close and re-open this terminal tab and re-run this script."
253
+ exit 1
254
+ fi
255
+ }
256
+
257
+ has-bundler() {
258
+ has-executable bundle && bundle -v &>/dev/null
259
+ }
260
+
261
+ ensure-project-ruby-dependencies-installed() {
262
+ banner 'Installing Ruby dependencies'
263
+
264
+ if [[ $USE_BUNDLER_1 -eq 1 ]] && (! has-bundler || [[ $(bundle -v) =~ '^1\.' ]]); then
265
+ gem install bundler -v '~> 1.0'
266
+ elif ! has-bundler; then
267
+ gem install bundler
268
+ fi
269
+
270
+ bundle check || bundle install
271
+ }
272
+
273
+ run-provisions() {
274
+ provision-ruby
275
+
276
+ if type provision-project &>/dev/null; then
277
+ provision-project
278
+ fi
279
+ }
184
280
 
185
281
  # --- FIN ----------------------------------------------------------------------
186
282
 
@@ -1,4 +1,6 @@
1
1
  provision-ruby() {
2
+ USE_BUNDLER_1=0
3
+
2
4
  if [[ -f .tool-versions ]]; then
3
5
  REQUIRED_RUBY_VERSION=$(cat .tool-versions | grep '^ruby ' | sed -Ee 's/^ruby (.+)$/\1/')
4
6
  elif [[ -f .ruby-version ]]; then
@@ -1,3 +1,3 @@
1
1
  module SetupScriptGenerator
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
@@ -30,8 +30,4 @@ Gem::Specification.new do |spec|
30
30
  spec.bindir = "exe"
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
-
34
- spec.add_development_dependency "bundler", "~> 1.17"
35
- spec.add_development_dependency "rake", "~> 10.0"
36
- # spec.add_development_dependency "rspec", "~> 3.0"
37
33
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setup_script_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Winkler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-14 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.17'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.17'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description:
42
14
  email:
43
15
  - elliot.winkler@gmail.com
@@ -46,10 +18,10 @@ executables:
46
18
  extensions: []
47
19
  extra_rdoc_files: []
48
20
  files:
21
+ - ".editorconfig"
49
22
  - ".gitignore"
50
- - ".ruby-version"
23
+ - ".tool-versions"
51
24
  - Gemfile
52
- - Gemfile.lock
53
25
  - LICENSE.txt
54
26
  - README.md
55
27
  - Rakefile
@@ -1 +0,0 @@
1
- 2.6.3
@@ -1,20 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- setup_script_generator (0.2.3)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- rake (10.5.0)
10
-
11
- PLATFORMS
12
- ruby
13
-
14
- DEPENDENCIES
15
- bundler (~> 1.17)
16
- rake (~> 10.0)
17
- setup_script_generator!
18
-
19
- BUNDLED WITH
20
- 1.17.3