|
1 | 1 | const path = require('node:path'); |
2 | 2 |
|
3 | 3 | const ZOD2MD_CONFIG_FILE = 'zod2md.config.ts'; |
| 4 | +const TS_PATCH_TARGET_NAME = 'ts-patch'; |
| 5 | +const GENERATE_DOCS_TARGET_NAME = 'generate-docs'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Creates the ts-patch target configuration |
| 9 | + * @returns {object} ts-patch target configuration |
| 10 | + */ |
| 11 | +const createTsPatchTargetConfig = { |
| 12 | + command: 'ts-patch install', |
| 13 | + cache: true, |
| 14 | + inputs: ['sharedGlobals', { runtime: 'ts-patch check' }], |
| 15 | +}; |
| 16 | + |
| 17 | +/** |
| 18 | + * Creates the docs generation target configuration |
| 19 | + * @param {object} params - Configuration parameters |
| 20 | + * @param {string} params.config - Path to the zod2md config file |
| 21 | + * @param {string} params.output - Path to the output markdown file |
| 22 | + * @returns {object} Docs target configuration |
| 23 | + */ |
| 24 | +function createDocsTargetConfig({ config, output }) { |
| 25 | + return { |
| 26 | + executor: 'nx:run-commands', |
| 27 | + options: { |
| 28 | + commands: [ |
| 29 | + `zod2md --config ${config} --output ${output}`, |
| 30 | + `prettier --write ${output}`, |
| 31 | + ], |
| 32 | + parallel: false, |
| 33 | + }, |
| 34 | + cache: true, |
| 35 | + inputs: ['production', '^production', config], |
| 36 | + outputs: [output], |
| 37 | + }; |
| 38 | +} |
4 | 39 |
|
5 | 40 | const createNodesV2 = [ |
6 | 41 | `**/${ZOD2MD_CONFIG_FILE}`, |
7 | 42 | async (zod2MdConfigurationFiles, createNodesOptions) => { |
8 | | - const options = createNodesOptions ?? {}; |
9 | | - const targetName = options.targetName ?? 'generate-docs'; |
| 43 | + const { |
| 44 | + docsTargetName = GENERATE_DOCS_TARGET_NAME, |
| 45 | + jsDocsTypesAugmentation = true, |
| 46 | + } = createNodesOptions ?? {}; |
10 | 47 |
|
11 | 48 | return Promise.all( |
12 | 49 | zod2MdConfigurationFiles.map(async zod2MdConfigurationFile => { |
13 | 50 | const projectRoot = path.dirname(zod2MdConfigurationFile); |
14 | 51 | const normalizedProjectRoot = projectRoot === '.' ? '' : projectRoot; |
15 | 52 | const output = '{projectRoot}/docs/{projectName}-reference.md'; |
16 | 53 | const config = `{projectRoot}/${ZOD2MD_CONFIG_FILE}`; |
| 54 | + |
17 | 55 | const result = { |
18 | 56 | projects: { |
19 | 57 | [normalizedProjectRoot]: { |
20 | 58 | targets: { |
21 | | - [targetName]: { |
22 | | - executor: 'nx:run-commands', |
23 | | - options: { |
24 | | - commands: [ |
25 | | - `zod2md --config ${config} --output ${output}`, |
26 | | - `prettier --write ${output}`, |
27 | | - ], |
28 | | - parallel: false, |
29 | | - }, |
30 | | - cache: true, |
31 | | - inputs: ['production', '^production', config], |
32 | | - outputs: [output], |
33 | | - }, |
| 59 | + ...(jsDocsTypesAugmentation |
| 60 | + ? { [TS_PATCH_TARGET_NAME]: createTsPatchTargetConfig } |
| 61 | + : {}), |
| 62 | + [docsTargetName]: createDocsTargetConfig({ |
| 63 | + config, |
| 64 | + output, |
| 65 | + }), |
34 | 66 | }, |
35 | 67 | }, |
36 | 68 | }, |
|
0 commit comments