From daa0f9417c305399eac626a559ac3df57754cf9d Mon Sep 17 00:00:00 2001 From: tyrro Date: Fri, 9 Sep 2022 16:13:46 +0700 Subject: [PATCH 01/19] [#348] feature: Add Makefile to build commands --- .gitignore | 1 + .gitignore.rb | 1 + .template/addons/docker/.env.tt | 1 + .template/variants/web/.gitignore.rb | 18 +++++++ Makefile.tt | 46 ++++++++++++++++ README.md.tt | 78 ++++++++++++---------------- bin/envteardown.sh | 3 ++ bin/template.rb | 2 + bin/wait-for-postgres.sh | 9 ++++ template.rb | 1 + 10 files changed, 114 insertions(+), 46 deletions(-) create mode 100644 Makefile.tt create mode 100644 bin/envteardown.sh create mode 100644 bin/wait-for-postgres.sh diff --git a/.gitignore b/.gitignore index b38118ad..13c6bef2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.iml out gen +.vscode diff --git a/.gitignore.rb b/.gitignore.rb index b5698e0a..ebc2edc6 100644 --- a/.gitignore.rb +++ b/.gitignore.rb @@ -6,6 +6,7 @@ # Ignore folder information and IDE-specific files .DS_Store .idea/* + .vscode/* # Ignore the test coverage results from SimpleCov /coverage diff --git a/.template/addons/docker/.env.tt b/.template/addons/docker/.env.tt index 7be3e1c5..ce002699 100644 --- a/.template/addons/docker/.env.tt +++ b/.template/addons/docker/.env.tt @@ -4,3 +4,4 @@ BRANCH_TAG=latest PORT=80 CI=false TEST_RETRY=0 +DATABASE_URL=postgres://postgres:postgres@0.0.0.0:5432/<%= APP_NAME %>_development?sslmode=disable diff --git a/.template/variants/web/.gitignore.rb b/.template/variants/web/.gitignore.rb index b4cc828c..b228508a 100644 --- a/.template/variants/web/.gitignore.rb +++ b/.template/variants/web/.gitignore.rb @@ -11,5 +11,23 @@ # Ignore Node dependencies /node_modules + + # debug + yarn-debug.log* + yarn-error.log* + .yarn-integrity + + # Ignore Byebug history. + .byebug_history + + # Ignore master keys for decrypting credentials and more. + /config/credentials/*.key + + # Ignore Gemfile.lock file in engines. + /engines/*/Gemfile.lock + + # Style guide + /styleguide/* + !/styleguide/README.md IGNORE end diff --git a/Makefile.tt b/Makefile.tt new file mode 100644 index 00000000..925fc400 --- /dev/null +++ b/Makefile.tt @@ -0,0 +1,46 @@ +include .env + +.PHONY: db/migrate db/rollback db/wait-for-postgres db/seed dev env/setup env/teardown test test/docker + +db/migrate: + make db/wait-for-postgres + rails db:migrate + +db/rollback: + make db/wait-for-postgres + rails db:rollback + +db/wait-for-postgres: + $(shell DATABASE_URL=$(DATABASE_URL) ./bin/wait-for-postgres.sh) + +db/seed: + rails db:seed + +dev: + make install-dependencies + make env/setup + ./bin/dev + +env/setup: + ./bin/envsetup.sh + rails db:prepare + +env/teardown: # this command will delete data + ./bin/envteardown.sh + +install-dependencies: + bundle install + yarn install + +test: + docker-compose -f docker-compose.test.yml --project-name ewa-payroll-web-test up -d db redis + bundle exec rspec $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + docker-compose -f docker-compose.test.yml --project-name ewa-payroll-web-test down + +test/docker: + ./bin/docker-prepare + docker-compose -f docker-compose.test.yml build + docker-compose -f docker-compose.test.yml run test make install-dependencies + docker-compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare + docker-compose -f docker-compose.test.yml run test + docker-compose -f docker-compose.test.yml down diff --git a/README.md.tt b/README.md.tt index 119bfc0e..6ed69f0c 100644 --- a/README.md.tt +++ b/README.md.tt @@ -17,28 +17,14 @@ - Install [Docker for Mac](https://docs.docker.com/docker-for-mac/install/) -- Setup and boot the Docker containers: - -```sh -./bin/envsetup.sh -``` - ### Development -- Setup the databases: - - - Postgres: +- Run the Rails app ```sh - rake db:setup + make dev ``` -- Run the Rails app - -```sh -./bin/dev -``` - ## Testing ### Docker-based tests on the CI server @@ -47,12 +33,12 @@ Add the following build settings to run the tests in the Docker environment via - Configure the environment variable `BRANCH_TAG` to tag Docker images per branch, e.g: -```sh -# a unique `BRANCH_TAG` value to tag the Docker image -# e.g $SEMAPHORE_BRANCH_ID or using the -# or using nimblehq/branch-tag-action@1 Github action -export BRANCH_TAG= # unique value for tagging Docker image -``` + ```sh + # a unique `BRANCH_TAG` value to tag the Docker image + # e.g $SEMAPHORE_BRANCH_ID or using the + # or using nimblehq/branch-tag-action@v1 Github action + export BRANCH_TAG= # unique value for tagging Docker image + ``` Each branch needs to have its own Docker image to avoid build settings disparities and leverage Docker image caching. @@ -61,54 +47,54 @@ An alternative is to use a unique identifier such as PR_ID or BRANCH_ID on the C - Pull the latest version the Docker image for the branch: -```sh -docker pull $DOCKER_IMAGE:$BRANCH_TAG || true -``` + ```sh + docker pull $DOCKER_IMAGE:$BRANCH_TAG || true + ``` On each build, the CI environment does not contain yet a cached version of the image. Therefore, it is required to pull it first to leverage the `cache_from` settings of Docker Compose which avoids rebuilding the whole Docker image on subsequent test builds. - Build the Docker image: -```sh -./bin/docker-prepare && docker compose -f docker-compose.test.yml build -``` + ```sh + ./bin/docker-prepare && docker compose -f docker-compose.test.yml build + ``` Upon the first build, the whole Docker image is built from the ground up and tagged using `$BRANCH_TAG`. - Push the latest version of the Docker image for this branch: -```sh -docker push $DOCKER_IMAGE:$BRANCH_TAG -``` + ```sh + docker push $DOCKER_IMAGE:$BRANCH_TAG + ``` - Setup the test database: -```sh -docker compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare -``` + ```sh + docker compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare + ``` ### Test - Run all tests: -```sh -# Docker way -docker compose -f docker-compose.test.yml run test + ```sh + # Docker way + make test/docker -# Non-Docker way -rspec -``` + # Non-Docker way + make test + ``` - Run a specific test: -```sh -# Docker way -docker compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params] + ```sh + # Docker way + docker-compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params] -# Non-Docker way -rspec [rspec-params] -``` + # Non-Docker way + make test [rspec-params] + ``` ### Automated Code Review Setup - Add a bot (i.e. `team-nimblehq`) to this repository or to the organization. The bot requires permission level “Write” to be able to set a PR’s status. diff --git a/bin/envteardown.sh b/bin/envteardown.sh new file mode 100644 index 00000000..b322a838 --- /dev/null +++ b/bin/envteardown.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker compose -f docker-compose.dev.yml down diff --git a/bin/template.rb b/bin/template.rb index 5750ea87..6c8480cb 100644 --- a/bin/template.rb +++ b/bin/template.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true copy_file 'bin/envsetup.sh', mode: :preserve +copy_file 'bin/envteardown.sh', mode: :preserve copy_file 'bin/start.sh', mode: :preserve copy_file 'bin/test.sh', mode: :preserve +copy_file 'bin/wait-for-postgres.sh', mode: :preserve copy_file 'bin/worker.sh', mode: :preserve copy_file 'bin/dev', mode: :preserve copy_file 'bin/docker-prepare', mode: :preserve diff --git a/bin/wait-for-postgres.sh b/bin/wait-for-postgres.sh new file mode 100644 index 00000000..19a9ae3f --- /dev/null +++ b/bin/wait-for-postgres.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +until psql $DATABASE_URL -c "\q" > /dev/null 2>&1; do + >&2 echo "$DATABASE_URL" + >&2 echo "Postgres is unavailable - sleeping" + sleep 1 +done diff --git a/template.rb b/template.rb index fd3ae51e..899537a1 100644 --- a/template.rb +++ b/template.rb @@ -43,6 +43,7 @@ def apply_template!(template_root) copy_file '.editorconfig' copy_file 'Procfile' copy_file 'Procfile.dev' + template 'Makefile.tt' template 'README.md.tt', force: true apply 'bin/template.rb' From dc93d0962d403b1d4d6bd85cf13a5a1d499dee4d Mon Sep 17 00:00:00 2001 From: tyrro Date: Thu, 30 Mar 2023 17:57:22 +0700 Subject: [PATCH 02/19] [#348] feat: Update template according to the addition of Makefile --- .gitignore.rb | 2 +- .../github/.github/workflows/test.yml.tt | 2 +- .template/variants/web/.gitignore.rb | 5 +--- .../variants/web/spec/support/capybara.rb | 1 + Makefile.tt | 13 +++++++++- README.md | 8 +++++- README.md.tt | 25 ++++++++++++++++--- spec/support/vcr.rb | 1 - 8 files changed, 45 insertions(+), 12 deletions(-) diff --git a/.gitignore.rb b/.gitignore.rb index ebc2edc6..5160ebf0 100644 --- a/.gitignore.rb +++ b/.gitignore.rb @@ -6,7 +6,7 @@ # Ignore folder information and IDE-specific files .DS_Store .idea/* - .vscode/* + .vscode # Ignore the test coverage results from SimpleCov /coverage diff --git a/.template/addons/github/.github/workflows/test.yml.tt b/.template/addons/github/.github/workflows/test.yml.tt index 9f13fbb4..910174cc 100644 --- a/.template/addons/github/.github/workflows/test.yml.tt +++ b/.template/addons/github/.github/workflows/test.yml.tt @@ -138,7 +138,7 @@ jobs: if: ${{ failure() }} with: name: system_tests_screenshots - path: tmp/screenshots/* + path: tmp/screenshots/ automated_code_review: name: Run Danger diff --git a/.template/variants/web/.gitignore.rb b/.template/variants/web/.gitignore.rb index b228508a..b235fdae 100644 --- a/.template/variants/web/.gitignore.rb +++ b/.template/variants/web/.gitignore.rb @@ -8,6 +8,7 @@ # Ignore asset builds /app/assets/builds/* + !/app/assets/builds/.keep # Ignore Node dependencies /node_modules @@ -25,9 +26,5 @@ # Ignore Gemfile.lock file in engines. /engines/*/Gemfile.lock - - # Style guide - /styleguide/* - !/styleguide/README.md IGNORE end diff --git a/.template/variants/web/spec/support/capybara.rb b/.template/variants/web/spec/support/capybara.rb index 39fbe29e..d8222fe3 100644 --- a/.template/variants/web/spec/support/capybara.rb +++ b/.template/variants/web/spec/support/capybara.rb @@ -37,3 +37,4 @@ Capybara.javascript_driver = :chrome Capybara.default_max_wait_time = CAPYBARA_TIMEOUT +Capybara.save_path = 'tmp/screenshots' diff --git a/Makefile.tt b/Makefile.tt index 925fc400..b7a90a22 100644 --- a/Makefile.tt +++ b/Makefile.tt @@ -1,6 +1,6 @@ include .env -.PHONY: db/migrate db/rollback db/wait-for-postgres db/seed dev env/setup env/teardown test test/docker +.PHONY: db/migrate db/rollback db/wait-for-postgres db/seed dev env/setup env/teardown test test/docker codebase codebase/fix db/migrate: make db/wait-for-postgres @@ -28,6 +28,9 @@ env/setup: env/teardown: # this command will delete data ./bin/envteardown.sh +generate-sprite: + ./bin/svg-sprite + install-dependencies: bundle install yarn install @@ -44,3 +47,11 @@ test/docker: docker-compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare docker-compose -f docker-compose.test.yml run test docker-compose -f docker-compose.test.yml down + +codebase: + rubocop + yarn codebase + +codebase/fix: + rubocop -a + yarn codebase:fix diff --git a/README.md b/README.md index 8302e4d4..dbb8efb6 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ Available Addons: - `slim` - `devise` +After the template finishes generating all the files, run the following command to start the rails server. + +```sh +make dev +``` + Read more about Rails Application Template in the [official Rails Guides](https://guides.rubyonrails.org/rails_application_templates.html). ## How to contribute @@ -101,7 +107,7 @@ There are 2 template file types: 1. **`.tt` files** This file is used for templating the whole new file. - In case if we want to create a new file that Rails does not generated. + In case if we want to create a new file that Rails has not generated. 2. **`.rb` files** diff --git a/README.md.tt b/README.md.tt index 6ed69f0c..202cbde8 100644 --- a/README.md.tt +++ b/README.md.tt @@ -19,11 +19,16 @@ ### Development -- Run the Rails app +- Run the Rails app: ```sh make dev ``` +- Run the seed: + + ```sh + make db/seed + ``` ## Testing @@ -80,7 +85,7 @@ Upon the first build, the whole Docker image is built from the ground up and tag ```sh # Docker way - make test/docker + docker compose -f docker-compose.test.yml run test # Non-Docker way make test @@ -90,12 +95,26 @@ Upon the first build, the whole Docker image is built from the ground up and tag ```sh # Docker way - docker-compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params] + docker compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params] # Non-Docker way make test [rspec-params] ``` +### Linting + +- Run all lint: + + ```sh + make codebase + ``` + +- Fix all lint: + + ```sh + make codebase/fix + ``` + ### Automated Code Review Setup - Add a bot (i.e. `team-nimblehq`) to this repository or to the organization. The bot requires permission level “Write” to be able to set a PR’s status. diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb index 3b21a09f..c40909c2 100644 --- a/spec/support/vcr.rb +++ b/spec/support/vcr.rb @@ -45,7 +45,6 @@ def configure_vcr_with_options(example, vcr_options) cassette_group = vcr_options[:group] vcr_cassettes.map! { |cassette| "#{cassette_group}/#{cassette}" } if cassette_group.present? vcr_cassettes.each do |cassette| - puts cassette VCR.use_cassette(cassette, cassette_options, &example) end end From dc3c575a530dc8889ca9b9dd0b85d177ea4fb34c Mon Sep 17 00:00:00 2001 From: tyrro Date: Tue, 4 Apr 2023 14:52:17 +0700 Subject: [PATCH 03/19] chore: Update MaxLineLength to comply with Compass convention --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 47d2d3f9..f2823ed9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,7 +22,7 @@ Style/Documentation: Enabled: false Layout/LineLength: - Max: 120 + Max: 130 Exclude: - 'spec/**/*' - 'config/**/*' From c4aeed2b779d192b298409e399e41a0d61de34d3 Mon Sep 17 00:00:00 2001 From: tyrro Date: Fri, 7 Apr 2023 17:11:36 +0700 Subject: [PATCH 04/19] [#348] chore: Remove DB related rake tasks from Makefile --- Makefile.tt | 23 +++-------------------- bin/template.rb | 1 - bin/wait-for-postgres.sh | 9 --------- 3 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 bin/wait-for-postgres.sh diff --git a/Makefile.tt b/Makefile.tt index b7a90a22..00bd1a60 100644 --- a/Makefile.tt +++ b/Makefile.tt @@ -1,20 +1,6 @@ include .env -.PHONY: db/migrate db/rollback db/wait-for-postgres db/seed dev env/setup env/teardown test test/docker codebase codebase/fix - -db/migrate: - make db/wait-for-postgres - rails db:migrate - -db/rollback: - make db/wait-for-postgres - rails db:rollback - -db/wait-for-postgres: - $(shell DATABASE_URL=$(DATABASE_URL) ./bin/wait-for-postgres.sh) - -db/seed: - rails db:seed +.PHONY: dev env/setup env/teardown test test/docker codebase codebase/fix dev: make install-dependencies @@ -28,17 +14,14 @@ env/setup: env/teardown: # this command will delete data ./bin/envteardown.sh -generate-sprite: - ./bin/svg-sprite - install-dependencies: bundle install yarn install test: - docker-compose -f docker-compose.test.yml --project-name ewa-payroll-web-test up -d db redis + docker-compose -f docker-compose.test.yml --project-name <%= APP_NAME %>_test up -d db redis bundle exec rspec $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) - docker-compose -f docker-compose.test.yml --project-name ewa-payroll-web-test down + docker-compose -f docker-compose.test.yml --project-name <%= APP_NAME %>_test down test/docker: ./bin/docker-prepare diff --git a/bin/template.rb b/bin/template.rb index 6c8480cb..eabab904 100644 --- a/bin/template.rb +++ b/bin/template.rb @@ -4,7 +4,6 @@ copy_file 'bin/envteardown.sh', mode: :preserve copy_file 'bin/start.sh', mode: :preserve copy_file 'bin/test.sh', mode: :preserve -copy_file 'bin/wait-for-postgres.sh', mode: :preserve copy_file 'bin/worker.sh', mode: :preserve copy_file 'bin/dev', mode: :preserve copy_file 'bin/docker-prepare', mode: :preserve diff --git a/bin/wait-for-postgres.sh b/bin/wait-for-postgres.sh deleted file mode 100644 index 19a9ae3f..00000000 --- a/bin/wait-for-postgres.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -set -e - -until psql $DATABASE_URL -c "\q" > /dev/null 2>&1; do - >&2 echo "$DATABASE_URL" - >&2 echo "Postgres is unavailable - sleeping" - sleep 1 -done From 7da2972fdb83938b24d3b3534e6c357167bd203e Mon Sep 17 00:00:00 2001 From: tyrro Date: Tue, 11 Apr 2023 16:30:15 +0700 Subject: [PATCH 05/19] [#348] chore: Remove test related make commands --- .template/addons/docker/.env.tt | 1 - Makefile.tt | 15 +-------------- README.md.tt | 6 +++--- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/.template/addons/docker/.env.tt b/.template/addons/docker/.env.tt index ce002699..7be3e1c5 100644 --- a/.template/addons/docker/.env.tt +++ b/.template/addons/docker/.env.tt @@ -4,4 +4,3 @@ BRANCH_TAG=latest PORT=80 CI=false TEST_RETRY=0 -DATABASE_URL=postgres://postgres:postgres@0.0.0.0:5432/<%= APP_NAME %>_development?sslmode=disable diff --git a/Makefile.tt b/Makefile.tt index 00bd1a60..0000e804 100644 --- a/Makefile.tt +++ b/Makefile.tt @@ -1,6 +1,6 @@ include .env -.PHONY: dev env/setup env/teardown test test/docker codebase codebase/fix +.PHONY: dev env/setup env/teardown codebase codebase/fix dev: make install-dependencies @@ -18,19 +18,6 @@ install-dependencies: bundle install yarn install -test: - docker-compose -f docker-compose.test.yml --project-name <%= APP_NAME %>_test up -d db redis - bundle exec rspec $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) - docker-compose -f docker-compose.test.yml --project-name <%= APP_NAME %>_test down - -test/docker: - ./bin/docker-prepare - docker-compose -f docker-compose.test.yml build - docker-compose -f docker-compose.test.yml run test make install-dependencies - docker-compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare - docker-compose -f docker-compose.test.yml run test - docker-compose -f docker-compose.test.yml down - codebase: rubocop yarn codebase diff --git a/README.md.tt b/README.md.tt index 202cbde8..bc318428 100644 --- a/README.md.tt +++ b/README.md.tt @@ -41,7 +41,7 @@ Add the following build settings to run the tests in the Docker environment via ```sh # a unique `BRANCH_TAG` value to tag the Docker image # e.g $SEMAPHORE_BRANCH_ID or using the - # or using nimblehq/branch-tag-action@v1 Github action + # or using nimblehq/branch-tag-action@1 Github action export BRANCH_TAG= # unique value for tagging Docker image ``` @@ -88,7 +88,7 @@ Upon the first build, the whole Docker image is built from the ground up and tag docker compose -f docker-compose.test.yml run test # Non-Docker way - make test + rspec ``` - Run a specific test: @@ -98,7 +98,7 @@ Upon the first build, the whole Docker image is built from the ground up and tag docker compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params] # Non-Docker way - make test [rspec-params] + rspec [rspec-params] ``` ### Linting From feb0cbc2979c8a26a7e0c200870b407e0445bae0 Mon Sep 17 00:00:00 2001 From: tyrro Date: Tue, 11 Apr 2023 16:51:06 +0700 Subject: [PATCH 06/19] [#348] chore: Update README.md.tt --- README.md.tt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md.tt b/README.md.tt index bc318428..91e719fc 100644 --- a/README.md.tt +++ b/README.md.tt @@ -19,16 +19,11 @@ ### Development -- Run the Rails app: +Run the Rails app: - ```sh - make dev - ``` -- Run the seed: - - ```sh - make db/seed - ``` +```sh +make dev +`` ## Testing From 7b92de7a8ce867d6c09b57242fd6147ad27d2737 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 19 May 2023 10:35:09 +0700 Subject: [PATCH 07/19] =?UTF-8?q?[#404]=20Fix=20the=20is=20does=20not=20?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.tt | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile.tt b/Gemfile.tt index a23b6179..8d603fe6 100644 --- a/Gemfile.tt +++ b/Gemfile.tt @@ -9,6 +9,7 @@ gem 'mini_magick' # A ruby wrapper for ImageMagick or GraphicsMagick command lin gem 'pagy' # A pagination gem that is very light and fast gem 'discard' # Soft deletes for ActiveRecord gem 'sidekiq' # background processing for Ruby +gem 'sassc' # bootsnap dependency gem 'bootsnap', require: false # Reduces boot times through caching; required in config/boot.rb gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] # Windows does not include zoneinfo files, so bundle the tzinfo-data gem # gem 'jbuilder' # Build JSON APIs with ease From 740b33ea0932e2cf3b22ea337e7630ac3d4681a6 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 28 Apr 2023 16:43:01 +0700 Subject: [PATCH 08/19] [#384] Implementation --- .template/variants/web/Procfile.dev.rb | 1 + .template/variants/web/package.json.rb | 18 +++++++++++++++++- bin/docker-assets-precompile | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.template/variants/web/Procfile.dev.rb b/.template/variants/web/Procfile.dev.rb index 1199488c..b72ad4ac 100644 --- a/.template/variants/web/Procfile.dev.rb +++ b/.template/variants/web/Procfile.dev.rb @@ -4,5 +4,6 @@ <<~PROCFILE js: yarn build --watch css: yarn build:css --watch + postcss: yarn build:postcss --watch PROCFILE end diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index 34dbf40d..d283ebc9 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -11,6 +11,17 @@ JSON end +unless File.exist?('postcss.config.js') + create_file 'postcss.config.js', + <<~POSTCSS + module.exports = { + plugins: [ + require('autoprefixer'), + ] + } + POSTCSS +end + # Install dependencies run 'yarn add i18n-js@3.8.0' run 'yarn add sass' @@ -21,7 +32,7 @@ run 'yarn add --dev @nimblehq/stylelint-config-nimble' # TODO: Check again after removing Webpacker, need to use version 8 # https://github.com/bjankord/stylelint-config-sass-guidelines/issues/203#issuecomment-955620774 -run 'yarn add --dev postcss@8.4.5' +run 'yarn add --dev postcss@8.4.5 postcss-cli autoprefixer' # Setup scripts run 'npm set-script eslint "eslint . --color"' @@ -43,3 +54,8 @@ npm set-script build:css \ "sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_options.join(' ')}" ) +run %(npm set-script postcss "postcss public/assets/*.css --dir public/assets --config ./") +run %( + npm set-script build:postcss \ + "postcss app/assets/builds/*.css --dir app/assets/builds --config ./", +) diff --git a/bin/docker-assets-precompile b/bin/docker-assets-precompile index 4a36fd90..a5b95c27 100755 --- a/bin/docker-assets-precompile +++ b/bin/docker-assets-precompile @@ -21,4 +21,4 @@ if rails_env == 'production' ENV['DATABASE_URL'] = 'postgres://postgres:postgres@postgres:5432/postgres' end -exit system('bin/rails i18n:js:export && bin/rails assets:precompile') +exit system('bin/rails i18n:js:export && bin/rails assets:precompile && yarn postcss') From b8e8f16b268a48164b421e6ae865177dcb09c41c Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 5 May 2023 09:39:43 +0700 Subject: [PATCH 09/19] [#384] Add tests for package.json --- .template/spec/variants/web/package_json_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.template/spec/variants/web/package_json_spec.rb b/.template/spec/variants/web/package_json_spec.rb index 1a7f04de..e1dc9c64 100644 --- a/.template/spec/variants/web/package_json_spec.rb +++ b/.template/spec/variants/web/package_json_spec.rb @@ -28,6 +28,11 @@ it 'adds the script for bundling css' do expect(subject['scripts']).to include('build:css') end + + it 'add the script for bundling postcss' do + expect(subject['scripts']).to include('postcss') + expect(subject['scripts']).to include('build:postcss') + end end describe 'Dependencies' do @@ -57,6 +62,8 @@ it 'adds postcss 8 dependencies' do expect(subject['devDependencies']).to include('postcss') expect(subject['devDependencies']['postcss']).to eq('8.4.5') + expect(subject['devDependencies']).to include('postcss-cli') + expect(subject['devDependencies']).to include('autoprefixer') end end end From de61f4881e1d81373d3a6f6389c7eca3a29bb4c1 Mon Sep 17 00:00:00 2001 From: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> Date: Fri, 26 May 2023 14:34:23 +0700 Subject: [PATCH 10/19] Update .template/spec/variants/web/package_json_spec.rb Co-authored-by: Xavier MALPARTY <77609814+malparty@users.noreply.github.com> --- .template/spec/variants/web/package_json_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.template/spec/variants/web/package_json_spec.rb b/.template/spec/variants/web/package_json_spec.rb index e1dc9c64..37e5f669 100644 --- a/.template/spec/variants/web/package_json_spec.rb +++ b/.template/spec/variants/web/package_json_spec.rb @@ -29,7 +29,7 @@ expect(subject['scripts']).to include('build:css') end - it 'add the script for bundling postcss' do + it 'adds the script for bundling postcss' do expect(subject['scripts']).to include('postcss') expect(subject['scripts']).to include('build:postcss') end From cbdf1ab9154285bd97f9ca357014ef5ae16e8cbb Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Tue, 30 May 2023 18:38:10 +0700 Subject: [PATCH 11/19] [#403] Install postcss-cli in all environments --- .template/variants/web/package.json.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index d283ebc9..e33f6feb 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -26,14 +26,11 @@ run 'yarn add i18n-js@3.8.0' run 'yarn add sass' run 'yarn add esbuild' +run 'yarn add postcss@8.4.5 postcss-cli autoprefixer' run 'yarn add --dev @nimblehq/eslint-config-nimble@2.2.1' run 'yarn add --dev stylelint' run 'yarn add --dev @nimblehq/stylelint-config-nimble' -# TODO: Check again after removing Webpacker, need to use version 8 -# https://github.com/bjankord/stylelint-config-sass-guidelines/issues/203#issuecomment-955620774 -run 'yarn add --dev postcss@8.4.5 postcss-cli autoprefixer' - # Setup scripts run 'npm set-script eslint "eslint . --color"' run 'npm set-script eslint:fix "eslint . --color --fix"' From 410cc9bcecd60fc5435e1cc4c23121b568fb2ee7 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Tue, 30 May 2023 19:02:24 +0700 Subject: [PATCH 12/19] [#403] Update package_json_spec.rb --- .template/spec/variants/web/package_json_spec.rb | 13 ++++++------- .template/variants/web/package.json.rb | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.template/spec/variants/web/package_json_spec.rb b/.template/spec/variants/web/package_json_spec.rb index 37e5f669..702fabef 100644 --- a/.template/spec/variants/web/package_json_spec.rb +++ b/.template/spec/variants/web/package_json_spec.rb @@ -47,6 +47,12 @@ it 'adds esbuild dependencies' do expect(subject['dependencies']).to include('esbuild') end + + it 'adds postcss dependencies' do + expect(subject['devDependencies']).to include('postcss') + expect(subject['devDependencies']).to include('postcss-cli') + expect(subject['devDependencies']).to include('autoprefixer') + end end describe 'Development Dependencies' do @@ -58,12 +64,5 @@ expect(subject['devDependencies']).to include('stylelint') expect(subject['devDependencies']).to include('@nimblehq/stylelint-config-nimble') end - - it 'adds postcss 8 dependencies' do - expect(subject['devDependencies']).to include('postcss') - expect(subject['devDependencies']['postcss']).to eq('8.4.5') - expect(subject['devDependencies']).to include('postcss-cli') - expect(subject['devDependencies']).to include('autoprefixer') - end end end diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index e33f6feb..8754d306 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -26,7 +26,7 @@ run 'yarn add i18n-js@3.8.0' run 'yarn add sass' run 'yarn add esbuild' -run 'yarn add postcss@8.4.5 postcss-cli autoprefixer' +run 'yarn add postcss postcss-cli autoprefixer' run 'yarn add --dev @nimblehq/eslint-config-nimble@2.2.1' run 'yarn add --dev stylelint' From 61b852f9d737741c93ebf6238b7c54904dc52bfa Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Tue, 30 May 2023 19:19:38 +0700 Subject: [PATCH 13/19] [#403] Update package_json_spec.rb --- .template/spec/variants/web/package_json_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.template/spec/variants/web/package_json_spec.rb b/.template/spec/variants/web/package_json_spec.rb index 702fabef..ace621f8 100644 --- a/.template/spec/variants/web/package_json_spec.rb +++ b/.template/spec/variants/web/package_json_spec.rb @@ -49,9 +49,9 @@ end it 'adds postcss dependencies' do - expect(subject['devDependencies']).to include('postcss') - expect(subject['devDependencies']).to include('postcss-cli') - expect(subject['devDependencies']).to include('autoprefixer') + expect(subject['dependencies']).to include('postcss') + expect(subject['dependencies']).to include('postcss-cli') + expect(subject['dependencies']).to include('autoprefixer') end end From 7b25b65320f291c68c7fe19082e6d32407dd9fcd Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 16 Jun 2023 10:05:42 +0700 Subject: [PATCH 14/19] [#409] Update Postgres version --- template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template.rb b/template.rb index f8bb4a87..73550b18 100644 --- a/template.rb +++ b/template.rb @@ -9,7 +9,7 @@ DOCKER_REGISTRY_HOST = 'docker.io' DOCKER_IMAGE = "nimblehq/#{APP_NAME}".freeze RUBY_VERSION = '3.0.1' -POSTGRES_VERSION = '14.4' +POSTGRES_VERSION = '15.2' REDIS_VERSION = '6.2.7' # Variants API_VARIANT = options[:api] || ENV['API'] == 'true' From 2d2532ffbc0aec813f923de22780b650a9081319 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 12 May 2023 14:55:36 +0700 Subject: [PATCH 15/19] [#385] Minify JS --- .template/variants/web/app/javascript/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.template/variants/web/app/javascript/build.js b/.template/variants/web/app/javascript/build.js index 420c38a6..9d9c585e 100644 --- a/.template/variants/web/app/javascript/build.js +++ b/.template/variants/web/app/javascript/build.js @@ -6,6 +6,7 @@ require('esbuild') inject: ['app/javascript/global.js'], bundle: true, sourcemap: true, + minify: !watch, outdir: 'app/assets/builds', }) .then((ctx) => { From dea4c8328d1718ee109bb6cf38a741536bc8eb94 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 12 May 2023 14:55:43 +0700 Subject: [PATCH 16/19] [#385] Minify CSS --- .template/variants/web/Procfile.dev.rb | 2 +- .template/variants/web/package.json.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.template/variants/web/Procfile.dev.rb b/.template/variants/web/Procfile.dev.rb index b72ad4ac..c617cbd0 100644 --- a/.template/variants/web/Procfile.dev.rb +++ b/.template/variants/web/Procfile.dev.rb @@ -3,7 +3,7 @@ append_to_file 'Procfile.dev' do <<~PROCFILE js: yarn build --watch - css: yarn build:css --watch + css: yarn build:css-dev --watch postcss: yarn build:postcss --watch PROCFILE end diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index 8754d306..8092c986 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -45,10 +45,17 @@ '--no-source-map', '--load-path=node_modules' ] +production_bundled_stylesheet_options = [ + '--style=compressed' +] run %(npm set-script build "node app/javascript/build.js") run %( npm set-script build:css \ + "sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_options.merge(production_bundled_stylesheet_options).join(' ')}" +) +run %( + npm set-script build:css-dev \ "sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_options.join(' ')}" ) run %(npm set-script postcss "postcss public/assets/*.css --dir public/assets --config ./") From 9cc72f7b97ca4a2c12017b9eba26bafd357f91d9 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 12 May 2023 16:37:21 +0700 Subject: [PATCH 17/19] [#385] Update merge array method --- .template/variants/web/package.json.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index 8092c986..897bc111 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -52,7 +52,7 @@ run %(npm set-script build "node app/javascript/build.js") run %( npm set-script build:css \ - "sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_options.merge(production_bundled_stylesheet_options).join(' ')}" + "sass #{source_stylesheet} #{bundled_stylesheet} #{(bundled_stylesheet_options + production_bundled_stylesheet_options).join(' ')}" ) run %( npm set-script build:css-dev \ From be10c45df3c06631a13ba11ab4c31e94d49fb910 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Thu, 18 May 2023 14:20:26 +0700 Subject: [PATCH 18/19] [#385] Update name for the base stylesheet options --- .template/variants/web/Procfile.dev.rb | 2 +- .template/variants/web/package.json.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.template/variants/web/Procfile.dev.rb b/.template/variants/web/Procfile.dev.rb index c617cbd0..b72ad4ac 100644 --- a/.template/variants/web/Procfile.dev.rb +++ b/.template/variants/web/Procfile.dev.rb @@ -3,7 +3,7 @@ append_to_file 'Procfile.dev' do <<~PROCFILE js: yarn build --watch - css: yarn build:css-dev --watch + css: yarn build:css --watch postcss: yarn build:postcss --watch PROCFILE end diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index 897bc111..0b1a4a7c 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -41,22 +41,22 @@ source_stylesheet = 'app/assets/stylesheets/application.scss' bundled_stylesheet = 'app/assets/builds/application.css' -bundled_stylesheet_options = [ +bundled_stylesheet_base_options = [ '--no-source-map', '--load-path=node_modules' ] -production_bundled_stylesheet_options = [ +production_bundled_stylesheet_options = bundled_stylesheet_base_options + [ '--style=compressed' ] run %(npm set-script build "node app/javascript/build.js") run %( - npm set-script build:css \ - "sass #{source_stylesheet} #{bundled_stylesheet} #{(bundled_stylesheet_options + production_bundled_stylesheet_options).join(' ')}" + npm set-script build:css-production \ + "sass #{source_stylesheet} #{bundled_stylesheet} #{(production_bundled_stylesheet_options).join(' ')}" ) run %( - npm set-script build:css-dev \ - "sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_options.join(' ')}" + npm set-script build:css \ + "sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_base_options.join(' ')}" ) run %(npm set-script postcss "postcss public/assets/*.css --dir public/assets --config ./") run %( From 4d587c1f477c36205cd66d1bd80a0c0a82aed1be Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Fri, 16 Jun 2023 14:41:48 +0700 Subject: [PATCH 19/19] [#385] Add tests for package_json --- .template/spec/variants/web/package_json_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.template/spec/variants/web/package_json_spec.rb b/.template/spec/variants/web/package_json_spec.rb index ace621f8..60cdb296 100644 --- a/.template/spec/variants/web/package_json_spec.rb +++ b/.template/spec/variants/web/package_json_spec.rb @@ -29,6 +29,10 @@ expect(subject['scripts']).to include('build:css') end + it 'adds the script for bundling css in production' do + expect(subject['scripts']).to include('build:css-production') + end + it 'adds the script for bundling postcss' do expect(subject['scripts']).to include('postcss') expect(subject['scripts']).to include('build:postcss')