1- import { GenerateConfig , ProjectType , Resource } from '../types' ;
1+ import { GenerateConfig , Resource } from '../types' ;
22
33const defaultScriptTemplate = `
44<script>
@@ -7,11 +7,17 @@ const defaultScriptTemplate = `
77</script>
88` ;
99
10- const tsSv5ScriptTemplate = `
11- <script lang="ts">
12- import type { PageData } from './$types';
10+ const jsSv5ScriptTemplate = `
11+ <script>
12+ /** @type {{ data: import('./$types').PageData }} */
13+ let { data } = $props();
14+ </script>
15+ ` ;
1316
14- let { data }: { data: PageData } = $props();
17+ const jsSv5ScriptTemplateProps = `
18+ <script>
19+ /** @type {import('./$types').PageProps} */
20+ let { data } = $props();
1521</script>
1622` ;
1723
@@ -23,22 +29,39 @@ const tsScriptTemplate = `
2329</script>
2430` ;
2531
26- const jsSv5ScriptTemplate = `
27- <script>
28- /** @type {{ data: import('./$types').PageData }} */
29- let { data } = $props();
32+ const tsSv5ScriptTemplate = `
33+ <script lang="ts">
34+ import type { PageData } from './$types';
35+
36+ let { data }: { data: PageData } = $props();
3037</script>
3138` ;
3239
33- const scriptTemplate : ReadonlyMap < ProjectType , string > = new Map ( [
34- [ ProjectType . TS_SV5 , tsSv5ScriptTemplate ] ,
35- [ ProjectType . TS_SATISFIES_SV5 , tsSv5ScriptTemplate ] ,
36- [ ProjectType . JS_SV5 , jsSv5ScriptTemplate ] ,
37- [ ProjectType . TS , tsScriptTemplate ] ,
38- [ ProjectType . TS_SATISFIES , tsScriptTemplate ] ,
39- [ ProjectType . JS , defaultScriptTemplate ]
40- ] ) ;
40+ const tsSv5ScriptTemplateProps = `
41+ <script lang="ts">
42+ import type { PageProps } from './$types';
43+
44+ let { data }: PageProps = $props();
45+ </script>
46+ ` ;
4147
4248export default async function ( config : GenerateConfig ) : ReturnType < Resource [ 'generate' ] > {
43- return ( scriptTemplate . get ( config . type ) ?? defaultScriptTemplate ) . trim ( ) ;
49+ const { withProps, withRunes, withTs } = config . kind ;
50+ let template = defaultScriptTemplate ;
51+
52+ if ( withRunes && withTs && withProps ) {
53+ template = tsSv5ScriptTemplateProps ;
54+ } else if ( withRunes && withTs && ! withProps ) {
55+ template = tsSv5ScriptTemplate ;
56+ } else if ( withRunes && ! withTs && withProps ) {
57+ template = jsSv5ScriptTemplateProps ;
58+ } else if ( withRunes && ! withTs && ! withProps ) {
59+ template = jsSv5ScriptTemplate ;
60+ } else if ( ! withRunes && withTs ) {
61+ template = tsScriptTemplate ;
62+ } else if ( ! withRunes && ! withTs ) {
63+ template = defaultScriptTemplate ;
64+ }
65+
66+ return template . trim ( ) ;
4467}
0 commit comments