Table of Contents
- Project Kit is a ruby project starter kit that makes bootstrapping and syncing common development items easy.
- It aims to speed up ruby projects by hosting these development templates in a centralised directory as a single source of truth and propagate changes to multiple projects all from a single point.
- Project Kit is built using
Thor, a toolkit for building CLI interfaces. AThorclass exposes an executable with a number of subcommands where public methods defined become task commands.
~ gem install thor-
Run
thor listorthor -Tto see a list of available commands for a thor task -
Run
thor help <command>to see the description and options for a particular command
Within some projects you may find the following directory:
├── bin
└── command
└── lib
├── command.rb
└── subcommand.rb
- To call lib, we need to change the permissions of our bin script so that it can be executed
~ chmod a+x <file>
or
~ chmod a+x bin/command- Now, we are able to call it by running
./<file>orbin/command
- Install missing gem executables
~ bundle install- Change the permissions so that the script can be executed
~ chmod +x exe/project_kit- Call lib by executing
exe/project_kitin the current context of bundle
~ bundle exec exe/project_kit
Commands:
project_kit help [COMMAND] # Describe available commands or one specific command
project_kit setup # initial ruby project setup
project_kit sync # compares project templates with an existing target app directory
~ bundle exec exe/project_kit setup gem
name of your new project: hello
setting up hello...
create ../hello/.gitignore
create ../hello/.ruby-version
create ../hello/Gemfile
create ../hello/LICENSE.txt
hello gem project successfully setup
~ bundle exec exe/project_kit sync gem -t ../hello
finding ../hello
identical ../hello/.gitignore
identical ../hello/.ruby-version
identical ../hello/Gemfile
identical ../hello/LICENSE.txt
+--------------+----------------+
| Synced Files | Unsynced Files |
+--------------+----------------+
|.gitignore | |
|.ruby-version | |
|Gemfile | |
|LICENSE.txt | |
+--------------+----------------+- Package and install the gem
~ gem build project_kit.gemspec
~ gem install project_kit-1.0.0.gem --local- Run the gem
~ project_kitRun rspec spec/project_kit_spec.rb to test the behavior of the CLI
ProjectKit
#setup
name of your new project: test
setting up test...
create project-kit-cli/test/.gitignore
create project-kit-cli/test/.ruby-version
create project-kit-cli/test/Gemfile
create project-kit-cli/test/LICENSE.txt
test gem project successfully setup
initial setup of a gem project
#sync
finding ../test
identical project-kit-cli/test/.gitignore
identical project-kit-cli/test/.ruby-version
identical project-kit-cli/test/Gemfile
identical project-kit-cli/test/LICENSE.txt
+--------------+----------------+
| Synced Files | Unsynced Files |
+--------------+----------------+
|.gitignore | |
|.ruby-version | |
|Gemfile | |
|LICENSE.txt | |
+--------------+----------------+
sync gem templates to ../test directory
Finished in 1.18 seconds (files took 0.36764 seconds to load)
2 examples, 0 failures- Unlike Thor files,
.start(ARGV)would need to be added at the end of a Ruby script to instantiate the class and invoke the task - Ruby relies on absolute paths while Thor relies on relative paths, hence the need to resolve the path difference when accessing templates
- In Project Kit, a
File.file?check was performed to ensure that the current iterable is a file and not a directory, as by defaulttemplate()creates a copy of a file which might lead to subsequent file clashes- eg. a file clash between
.githuband.github/PULL_REQUEST_TEMPLATE.md
- eg. a file clash between
- Open3#popen3 allows you to interact with the external command while it is running and consolidates all 3 of the std pipes into a single stream
- As each pipe has a limited buffer size, it is important to ensure the stdout streams are continuously read else
stdin.writewill be blocked
