diff --git a/lib/generators/suspenders/lint_generator.rb b/lib/generators/suspenders/lint_generator.rb index 96aa0533f..21c95e4ff 100644 --- a/lib/generators/suspenders/lint_generator.rb +++ b/lib/generators/suspenders/lint_generator.rb @@ -6,6 +6,12 @@ class LintGenerator < Rails::Generators::Base source_root File.expand_path("../../templates/lint", __FILE__) desc "Creates a holistic linting solution that covers JavaScript, CSS, Ruby and ERB." + def check_package_json + unless File.exist? Rails.root.join("package.json") + copy_file "package.json", "package.json" + end + end + def install_dependencies run "yarn add stylelint eslint @thoughtbot/stylelint-config @thoughtbot/eslint-config npm-run-all prettier --dev" end diff --git a/lib/generators/templates/lint/package.json b/lib/generators/templates/lint/package.json new file mode 100644 index 000000000..dcd25e6e3 --- /dev/null +++ b/lib/generators/templates/lint/package.json @@ -0,0 +1,4 @@ +{ + "name": "app", + "private": "true" +} diff --git a/test/generators/suspenders/lint_generator_test.rb b/test/generators/suspenders/lint_generator_test.rb index 30520f7c4..6a3681014 100644 --- a/test/generators/suspenders/lint_generator_test.rb +++ b/test/generators/suspenders/lint_generator_test.rb @@ -248,6 +248,14 @@ class LintGeneratorTest < Rails::Generators::TestCase assert_equal desc, generator_class.desc end + test "created package.json if one does not exist" do + remove_file_if_exists "package.json" + + run_generator + + assert_file app_root("package.json") + end + private def prepare_destination