|
| 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 | +}) |
0 commit comments