Skip to content

Commit 368ef5e

Browse files
authored
Generate global types to .nuxt folder (#41)
1 parent 80c0b5e commit 368ef5e

File tree

2 files changed

+73
-25
lines changed

2 files changed

+73
-25
lines changed

modules/docs-toolkit-config.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2023 Exactpro (Exactpro Systems Limited)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { defineNuxtModule, createResolver, addTemplate } from '@nuxt/kit'
18+
19+
export default defineNuxtModule({
20+
setup(_, nuxt) {
21+
const { resolve } = createResolver(import.meta.url)
22+
const prefix = 'ExactproDocs'
23+
const typenamesWithoutPrefix = [
24+
'RobotsTxtOptions',
25+
'SocialLinkConfigOptions',
26+
'ContactConfigOptions'
27+
]
28+
29+
const typesPath = addTemplate({
30+
filename: 'types/docs-web-toolkit.d.ts',
31+
getContents: () =>
32+
[
33+
`import type { ${typenamesWithoutPrefix
34+
.map((type) => `${prefix}${type} as ${type}`)
35+
.join(', ')} } from '${resolve('../nuxt.schema.ts')}'`,
36+
'declare global {',
37+
...typenamesWithoutPrefix.map(
38+
(type) => ` interface ${prefix}${type} extends ${type} {}`
39+
),
40+
'}'
41+
].join('\n')
42+
}).dst
43+
44+
nuxt.hook('prepare:types', (options) => {
45+
options.references.push({
46+
path: typesPath
47+
})
48+
})
49+
}
50+
})

nuxt.schema.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,31 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type { RobotsTxtOptions } from './server/routes/robots.txt'
17+
// If new global type for config is required, add it to ./modules/docs-toolkit-config.ts
18+
export type { RobotsTxtOptions as ExactproDocsRobotsTxtOptions } from './server/routes/robots.txt'
1819

19-
declare global {
20-
interface ExactproDocsRobotsTxtOptions extends RobotsTxtOptions {}
21-
interface ExactproDocsSocialLinkConfigOptions {
22-
/**
23-
* Link to the social network
24-
*/
25-
url?: string
26-
/**
27-
* Name of the icon to override the default icon
28-
*
29-
* @see {@link https://icones.js.org/ | Icônes}
30-
*/
31-
customIcon?: string
32-
/**
33-
* Hide the link
34-
*
35-
* @default false
36-
*/
37-
disabled?: boolean
38-
}
20+
export interface ExactproDocsSocialLinkConfigOptions {
21+
/**
22+
* Link to the social network
23+
*/
24+
url?: string
25+
/**
26+
* Name of the icon to override the default icon
27+
*
28+
* @see {@link https://icones.js.org/ | Icônes}
29+
*/
30+
customIcon?: string
31+
/**
32+
* Hide the link
33+
*
34+
* @default false
35+
*/
36+
disabled?: boolean
37+
}
3938

40-
interface ExactproDocsContactConfigOptions {
41-
type: 'email' | 'phone'
42-
contact: string
43-
}
39+
export interface ExactproDocsContactConfigOptions {
40+
type: 'email' | 'phone'
41+
contact: string
4442
}
4543

4644
export default defineNuxtSchema({

0 commit comments

Comments
 (0)