diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a78f0a0f9..826faf07e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -228,9 +228,9 @@ yalc add react-on-rails ### Testing the Generator -The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator_testing_script.md](generator_testing_script.md) for a script on how to run the generator on a fresh project. +The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator-testing.md](docs/contributor-info/generator-testing.md) for a script on how to run the generator on a fresh project. -`rake run_rspec:example_basic` is a great way to run tests on one generator. Once that works, you should run `rake run_rspec:examples`. Be aware that this will create a hug number of files under a `/gen-examples` directory. You should be sure to exclude this directory from your IDE and delete it once your testing is done. +`rake run_rspec:shakapacker_examples_basic` is a great way to run tests on one generator. Once that works, you should run `rake run_rspec:shakapacker_examples`. Be aware that this will create a huge number of files under a `/gen-examples` directory. You should be sure to exclude this directory from your IDE and delete it once your testing is done. ### Linting diff --git a/lib/generators/react_on_rails/dev_tests_generator.rb b/lib/generators/react_on_rails/dev_tests_generator.rb index 68cd97fab7..3a20a2b72e 100644 --- a/lib/generators/react_on_rails/dev_tests_generator.rb +++ b/lib/generators/react_on_rails/dev_tests_generator.rb @@ -47,14 +47,10 @@ def replace_prerender_if_server_rendering def add_yarn_relative_install_script_in_package_json package_json = File.join(destination_root, "package.json") - contents = File.read(package_json) - replacement_value = <<-STRING - "scripts": { - "postinstall": "yalc link react-on-rails", - STRING - new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/, - replacement_value) - File.open(package_json, "w+") { |f| f.puts new_client_package_json_contents } + contents = JSON.parse(File.read(package_json)) + contents["scripts"] ||= {} + contents["scripts"]["postinstall"] = "yalc link react-on-rails" + File.open(package_json, "w+") { |f| f.puts JSON.pretty_generate(contents) } end end end diff --git a/script/convert b/script/convert index bfb4be0640..93629e2ae3 100755 --- a/script/convert +++ b/script/convert @@ -13,7 +13,7 @@ new_config = File.expand_path("../spec/dummy/config/webpacker.yml", __dir__) File.rename(old_config, new_config) -gsub_file_content("../Gemfile.development_dependencies", 'gem "shakapacker", "8.0.0"', 'gem "shakapacker", "6.6.0"') +gsub_file_content("../Gemfile.development_dependencies", /gem "shakapacker", "[^"]*"/, 'gem "shakapacker", "6.6.0"') # The below packages don't work on the oldest supported Node version and aren't needed there anyway gsub_file_content("../package.json", /"knip": "[^"]*",/, "") @@ -21,7 +21,7 @@ gsub_file_content("../package.json", %r{"@arethetypeswrong/cli": "[^"]*",}, "") gsub_file_content("../package.json", %r{"@testing-library/dom": "[^"]*",}, "") gsub_file_content("../package.json", %r{"@testing-library/react": "[^"]*",}, "") -gsub_file_content("../spec/dummy/package.json", '"shakapacker": "8.0.0",', '"shakapacker": "6.6.0",') +gsub_file_content("../spec/dummy/package.json", /"shakapacker": "[^"]*",/, '"shakapacker": "6.6.0",') gsub_file_content("../spec/dummy/config/webpack/commonWebpackConfig.js", /generateWebpackConfig(\(\))?/, "webpackConfig")