-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathnx-plugin.ts
More file actions
64 lines (58 loc) · 1.65 KB
/
nx-plugin.ts
File metadata and controls
64 lines (58 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { CreateNodesV2, NxPlugin, TargetConfiguration } from '@nx/devkit';
import * as path from 'node:path';
// this would break without setting node loader in .env.local
import { GENERATE_DOCS_TARGET_NAME, ZOD2MD_CONFIG_FILE } from './constants.js';
type DocsTargetConfigParams = {
config: string;
output: string;
};
function createDocsTargetConfig({
config,
output,
}: DocsTargetConfigParams): TargetConfiguration {
return {
executor: 'nx:run-commands',
options: {
commands: [
`zod2md --config ${config} --output ${output}`,
`prettier --write ${output}`,
],
parallel: false,
},
cache: true,
inputs: ['production', '^production', config],
outputs: [output],
};
}
const createNodesV2: CreateNodesV2 = [
`**/${ZOD2MD_CONFIG_FILE}`,
async configFilePaths =>
Promise.all(
configFilePaths.map(async configFilePath => {
const projectRoot = path.dirname(configFilePath);
const normalizedProjectRoot = projectRoot === '.' ? '' : projectRoot;
const output = '{projectRoot}/docs/{projectName}-reference.md';
const config = `{projectRoot}/${ZOD2MD_CONFIG_FILE}`;
return [
configFilePath,
{
projects: {
[normalizedProjectRoot]: {
targets: {
[GENERATE_DOCS_TARGET_NAME]: createDocsTargetConfig({
config,
output,
}),
},
},
},
},
] as const;
}),
),
];
const nxPlugin: NxPlugin = {
name: 'zod2md-jsdocs-nx-plugin',
createNodesV2,
};
export default nxPlugin;