How to Automate Local App Setup Process Using Bin/Setup

Recently, I have done some research on creating an interactive bin/setup script that can lead a developer who joined a new project through app's local setup process.
The new bin/setup script was supposed to create a sec_config.yml file from a sample while asking a developer to provide necessary missing values and saving them to the new file.
The script I created is a sample one with a possibility to change it when needed. I created support for standard sec_config/secrets files in yaml format and for standard .env file format.
The script is divided into a few sections.
Section #1
[code]
Here you'd want to add commands that install/update gems, install required ruby version, npm/bower dependencies, etc.
Section #2
[code]
This section is responsible for all config files logic.
In the first block, you can create database.yml from the sample file. If the database.yml.sample file has two keys: username and password, you can replace them as shown above.
You can also replace the code with gsub_file method:
[code]
[code]
In this block, you can create a new config file from the sample or edit the existing one (if it's present). You need to set the config path in CONFIG_FILE constant. Script will ask the user to provide required values (keys are present in the sample file, but they have no value).
[code]
For this sec_config.yml.sample file, the script will work like this:
[code]
...which results in the following sec_config.yml:
[code]
[code]
The block above is for creating a standard .env file from this sample:
[code]
This will ask the user for values that are missing. You need to get value for each key that is present and has no value in the sample file.
Section #3
[code]
This section is taking care of the database setup. You can just use bin/rake db:setup here or add additional commands like bin/rake db:test:prepare. Of course, you can add beautiful and colourful messages as shown in the example.
Section #4
[code]
Section #5
[code]
Here you can add messages for developers.
Feel free to use and customise this script in your projects. I hope this will help developers set up projects faster and easier.