diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3d13255..db9ef066c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Changes since the last non-beta release. +### Added + +- **Added `SKIP=true` installer mode to preserve existing files**. [PR #893](https://github.com/shakacode/shakapacker/pull/893) by [justin808](https://github.com/justin808). Running `rails shakapacker:install SKIP=true` now skips conflicting files instead of overwriting them. This is useful for CI/CD pipelines and automated setups where you want to install only missing files without touching existing configuration. + ### Changed - **BREAKING: sass-loader now defaults to modern Sass API**. [PR #879](https://github.com/shakacode/shakapacker/pull/879) by [justin808](https://github.com/justin808). The sass-loader configuration now uses `api: "modern"` instead of the deprecated legacy API. This improves compatibility with plugins like sass-resources-loader that require the modern API. If you experience issues after upgrading, you can revert to the legacy API by customizing your webpack config: diff --git a/README.md b/README.md index d05d8ccb4..b18a5d092 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Then run the following to install Shakapacker: bundle exec rake shakapacker:install ``` -Before initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files or use the `FORCE=true` environment variable before the installation command to force the override without any prompt. +Before initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files, use `FORCE=true` to overwrite without prompting, or use `SKIP=true` to preserve existing files and only create missing ones. If both are set, `FORCE=true` takes precedence. Shakapacker uses the [`package_json`](https://github.com/shakacode/package_json) gem to handle updating the `package.json` and interacting with the underlying package manager of choice for managing dependencies and running commands; the package manager is managed using the [`packageManager`](https://nodejs.org/api/packages.html#packagemanager) property in the `package.json`, otherwise falling back to the value of `PACKAGE_JSON_FALLBACK_MANAGER` if set or otherwise `npm`. diff --git a/lib/install/binstubs.rb b/lib/install/binstubs.rb index c0aa31bbf..ba530a595 100644 --- a/lib/install/binstubs.rb +++ b/lib/install/binstubs.rb @@ -1,6 +1,12 @@ -force_option = ENV["FORCE"] ? { force: true } : {} +conflict_option = if ENV["FORCE"] + { force: true } +elsif ENV["SKIP"] + { skip: true } +else + {} +end say "Copying binstubs" -directory "#{__dir__}/bin", "bin", force_option +directory "#{__dir__}/bin", "bin", conflict_option chmod "bin", 0755 & ~File.umask, verbose: false diff --git a/lib/install/template.rb b/lib/install/template.rb index cde59d442..47d234d70 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -7,7 +7,13 @@ # Install Shakapacker -force_option = ENV["FORCE"] ? { force: true } : {} +conflict_option = if ENV["FORCE"] + { force: true } +elsif ENV["SKIP"] + { skip: true } +else + {} +end # Initialize variables for use throughout the template # Using instance variable to avoid method definition issues in Rails templates @@ -31,7 +37,7 @@ end # Copy config file -copy_file "#{install_dir}/config/shakapacker.yml", "config/shakapacker.yml", force_option +copy_file "#{install_dir}/config/shakapacker.yml", "config/shakapacker.yml", conflict_option # Update config if USE_BABEL_PACKAGES is set to ensure babel is used at runtime if @transpiler_to_install == "babel" && !ENV["JAVASCRIPT_TRANSPILER"] @@ -53,7 +59,7 @@ dest_config = "config/#{assets_bundler}/#{config_file}" empty_directory "config/#{assets_bundler}" -copy_file source_config, dest_config, force_option +copy_file source_config, dest_config, conflict_option if @use_typescript say " ✨ Using TypeScript config for enhanced type safety", :green