diff --git a/lib/generators/inertia/install/frameworks.yml b/lib/generators/inertia/install/frameworks.yml index 7fdde8c..20957bf 100644 --- a/lib/generators/inertia/install/frameworks.yml +++ b/lib/generators/inertia/install/frameworks.yml @@ -13,12 +13,6 @@ react: vite_plugin_call: "react()" copy_files_ts: "InertiaExample.tsx": "%{js_destination_path}/pages/inertia_example/index.tsx" - "tsconfig.json": "tsconfig.json" - "tsconfig.app.json": "tsconfig.app.json" - "tsconfig.node.json": "tsconfig.node.json" - "types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts" - "types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts" - "types/index.ts": "%{js_destination_path}/types/index.ts" copy_files_js: "InertiaExample.jsx": "%{js_destination_path}/pages/inertia_example/index.jsx" copy_files: @@ -44,12 +38,6 @@ vue: "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg" copy_files_ts: "InertiaExample.ts.vue": "%{js_destination_path}/pages/inertia_example/index.vue" - "tsconfig.json": "tsconfig.json" - "tsconfig.app.json": "tsconfig.app.json" - "tsconfig.node.json": "tsconfig.node.json" - "types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts" - "types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts" - "types/index.ts": "%{js_destination_path}/types/index.ts" copy_files_js: "InertiaExample.vue": "%{js_destination_path}/pages/inertia_example/index.vue" @@ -68,11 +56,6 @@ svelte: vite_plugin_call: "svelte()" copy_files_ts: "InertiaExample.ts.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte" - "tsconfig.json": "tsconfig.json" - "tsconfig.node.json": "tsconfig.node.json" - "types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts" - "types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts" - "types/index.ts": "%{js_destination_path}/types/index.ts" copy_files_js: "InertiaExample.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte" copy_files: diff --git a/lib/generators/inertia/install/install_generator.rb b/lib/generators/inertia/install/install_generator.rb index 1ef7d2b..8459651 100644 --- a/lib/generators/inertia/install/install_generator.rb +++ b/lib/generators/inertia/install/install_generator.rb @@ -118,7 +118,7 @@ def install_inertia ERB insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n" - if framework == 'react' && !application_layout.read.include?('vite_react_refresh_tag') + if react? && !application_layout.read.include?('vite_react_refresh_tag') say 'Adding Vite React Refresh tag to the application layout' insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ", before: '<%= vite_client_tag %>' @@ -130,7 +130,7 @@ def install_inertia say_error '- ...' say_error '+ ...' say_error '+ <%= inertia_ssr_head %>' - say_error '+ <%= vite_react_refresh_tag %>' if framework == 'react' + say_error '+ <%= vite_react_refresh_tag %>' if react? say_error "+ <%= #{vite_tag} %>" end end @@ -148,14 +148,30 @@ def install_typescript add_dependencies(*FRAMEWORKS[framework]['packages_ts']) - say 'Copying adding scripts to package.json' + say 'Copying tsconfig and types' + + # Copy tsconfig files + tsconfig_files = %w[tsconfig.json tsconfig.node.json] + tsconfig_files << 'tsconfig.app.json' unless svelte? + + tsconfig_files.each do |file| + template "#{framework}/#{file}", file_path(file) + end + + # Copy type definition files + types_files = %w[types/vite-env.d.ts types/globals.d.ts types/index.ts] + types_files.each do |file| + template "#{framework}/#{file}", file_path("#{js_destination_path}/#{file}") + end + + say 'Adding TypeScript check scripts to package.json' if svelte? run 'npm pkg set scripts.check="svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"' - end - if framework == 'vue' + elsif react? + run 'npm pkg set scripts.check="tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' + elsif vue? run 'npm pkg set scripts.check="vue-tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' end - run 'npm pkg set scripts.check="tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' if framework == 'react' end def install_example_page @@ -327,6 +343,10 @@ def react? framework.start_with? 'react' end + def vue? + framework.start_with? 'vue' + end + def inertia_package "#{FRAMEWORKS[framework]['inertia_package']}@#{options[:inertia_version]}" end