Skip to content

Commit 71a0b11

Browse files
authored
Merge pull request #298 from alec-c4/add-tsconfig-non-interactive
refactor: improve TypeScript setup for non-interactive installs
2 parents d06b45e + 6a06f51 commit 71a0b11

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

lib/generators/inertia/install/frameworks.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ react:
1313
vite_plugin_call: "react()"
1414
copy_files_ts:
1515
"InertiaExample.tsx": "%{js_destination_path}/pages/inertia_example/index.tsx"
16-
"tsconfig.json": "tsconfig.json"
17-
"tsconfig.app.json": "tsconfig.app.json"
18-
"tsconfig.node.json": "tsconfig.node.json"
19-
"types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts"
20-
"types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts"
21-
"types/index.ts": "%{js_destination_path}/types/index.ts"
2216
copy_files_js:
2317
"InertiaExample.jsx": "%{js_destination_path}/pages/inertia_example/index.jsx"
2418
copy_files:
@@ -44,12 +38,6 @@ vue:
4438
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
4539
copy_files_ts:
4640
"InertiaExample.ts.vue": "%{js_destination_path}/pages/inertia_example/index.vue"
47-
"tsconfig.json": "tsconfig.json"
48-
"tsconfig.app.json": "tsconfig.app.json"
49-
"tsconfig.node.json": "tsconfig.node.json"
50-
"types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts"
51-
"types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts"
52-
"types/index.ts": "%{js_destination_path}/types/index.ts"
5341
copy_files_js:
5442
"InertiaExample.vue": "%{js_destination_path}/pages/inertia_example/index.vue"
5543

@@ -68,11 +56,6 @@ svelte:
6856
vite_plugin_call: "svelte()"
6957
copy_files_ts:
7058
"InertiaExample.ts.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte"
71-
"tsconfig.json": "tsconfig.json"
72-
"tsconfig.node.json": "tsconfig.node.json"
73-
"types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts"
74-
"types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts"
75-
"types/index.ts": "%{js_destination_path}/types/index.ts"
7659
copy_files_js:
7760
"InertiaExample.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte"
7861
copy_files:

lib/generators/inertia/install/install_generator.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def install_inertia
118118
ERB
119119
insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n"
120120

121-
if framework == 'react' && !application_layout.read.include?('vite_react_refresh_tag')
121+
if react? && !application_layout.read.include?('vite_react_refresh_tag')
122122
say 'Adding Vite React Refresh tag to the application layout'
123123
insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ",
124124
before: '<%= vite_client_tag %>'
@@ -130,7 +130,7 @@ def install_inertia
130130
say_error '- <title>...</title>'
131131
say_error '+ <title data-inertia>...</title>'
132132
say_error '+ <%= inertia_ssr_head %>'
133-
say_error '+ <%= vite_react_refresh_tag %>' if framework == 'react'
133+
say_error '+ <%= vite_react_refresh_tag %>' if react?
134134
say_error "+ <%= #{vite_tag} %>"
135135
end
136136
end
@@ -148,14 +148,30 @@ def install_typescript
148148

149149
add_dependencies(*FRAMEWORKS[framework]['packages_ts'])
150150

151-
say 'Copying adding scripts to package.json'
151+
say 'Copying tsconfig and types'
152+
153+
# Copy tsconfig files
154+
tsconfig_files = %w[tsconfig.json tsconfig.node.json]
155+
tsconfig_files << 'tsconfig.app.json' unless svelte?
156+
157+
tsconfig_files.each do |file|
158+
template "#{framework}/#{file}", file_path(file)
159+
end
160+
161+
# Copy type definition files
162+
types_files = %w[types/vite-env.d.ts types/globals.d.ts types/index.ts]
163+
types_files.each do |file|
164+
template "#{framework}/#{file}", file_path("#{js_destination_path}/#{file}")
165+
end
166+
167+
say 'Adding TypeScript check scripts to package.json'
152168
if svelte?
153169
run 'npm pkg set scripts.check="svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"'
154-
end
155-
if framework == 'vue'
170+
elsif react?
171+
run 'npm pkg set scripts.check="tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"'
172+
elsif vue?
156173
run 'npm pkg set scripts.check="vue-tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"'
157174
end
158-
run 'npm pkg set scripts.check="tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' if framework == 'react'
159175
end
160176

161177
def install_example_page
@@ -327,6 +343,10 @@ def react?
327343
framework.start_with? 'react'
328344
end
329345

346+
def vue?
347+
framework.start_with? 'vue'
348+
end
349+
330350
def inertia_package
331351
"#{FRAMEWORKS[framework]['inertia_package']}@#{options[:inertia_version]}"
332352
end

0 commit comments

Comments
 (0)