Skip to content

Commit e58c1fc

Browse files
committed
refactor: wip
1 parent 06f526a commit e58c1fc

File tree

17 files changed

+283
-193
lines changed

17 files changed

+283
-193
lines changed

packages/models/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"implicitDependencies": ["zod2md-jsdocs"],
77
"targets": {
88
"build": {
9-
"dependsOn": ["^build", "generate-docs"]
9+
"dependsOn": ["^build", "generate-docs", "ts-patch"]
1010
},
1111
"lint": {},
1212
"unit-test": {},

tools/zod2md-jsdocs/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ export {
44
annotateTypeDefinitions,
55
generateJSDocComment,
66
} from './lib/transformers/transformers.js';
7-
87
export default annotateTypeDefinitions;
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { Config } from 'zod2md';
2-
3-
// see: https://github.com/matejchalk/zod2md?tab=readme-ov-file#configuration-file-reference
42
export default {
5-
entry: 'libs/test-app/src/index.ts',
6-
format: 'esm',
7-
title: 'test-app reference',
8-
output: 'libs/test-app/docs/test-app-reference.md',
9-
tsconfig: 'libs/test-app/tsconfig.lib.json',
3+
entry: 'libs/test-app/src/index.ts',
4+
format: 'esm',
5+
title: 'test-app reference',
6+
output: 'libs/test-app/docs/test-app-reference.md',
7+
tsconfig: 'libs/test-app/tsconfig.lib.json',
108
} satisfies Config;

tools/zod2md-jsdocs/src/lib/generators/configuration/generator.int.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ describe('configurationGenerator', () => {
1313
let tree: Tree;
1414
const testProjectName = 'test-app';
1515
const loggerInfoSpy = vi.spyOn(logger, 'info');
16-
1716
beforeEach(() => {
1817
tree = createTreeWithEmptyWorkspace();
1918
addProjectConfiguration(tree, 'test-app', {
2019
root: 'test-app',
2120
});
2221
});
23-
2422
afterEach(() => {
2523
tree.delete(testProjectName);
2624
});
27-
2825
it('should skip config creation if skipConfig is used', async () => {
2926
await configurationGenerator(tree, {
3027
project: testProjectName,
@@ -33,17 +30,14 @@ describe('configurationGenerator', () => {
3330
output: 'docs/test-app-reference.md',
3431
title: 'Test App Reference',
3532
});
36-
3733
readProjectConfiguration(tree, testProjectName);
38-
3934
expect(
4035
tree.read(
4136
path.join('libs', testProjectName, DEFAULT_ZOD2MD_CONFIG_FILE_NAME),
4237
),
4338
).toBeNull();
4439
expect(loggerInfoSpy).toHaveBeenCalledWith('Skip config file creation');
4540
});
46-
4741
it('should skip formatting', async () => {
4842
await configurationGenerator(tree, {
4943
project: testProjectName,

tools/zod2md-jsdocs/src/lib/generators/configuration/generator.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@ export async function configurationGenerator(
1212
options: ConfigurationGeneratorOptions,
1313
) {
1414
const projectConfiguration = readProjectConfiguration(tree, options.project);
15-
1615
const { skipConfig, skipFormat } = options;
17-
1816
if (skipConfig === true) {
1917
logger.info('Skip config file creation');
2018
} else {
2119
generateZod2MdConfig(tree, projectConfiguration.root);
2220
}
23-
2421
if (skipFormat === true) {
2522
logger.info('Skip formatting files');
2623
} else {
2724
await formatFiles(tree);
2825
}
2926
}
30-
3127
export default configurationGenerator;

tools/zod2md-jsdocs/src/lib/generators/configuration/tsconfig.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export function getFirstExistingTsConfig(
3333
)
3434
: undefined;
3535
}
36-
3736
export type PluginDefinition = {
3837
transform: string;
3938
afterDeclarations: boolean;
@@ -44,7 +43,6 @@ export type TsConfig = {
4443
plugins: PluginDefinition[];
4544
};
4645
};
47-
4846
export function addZod2MdTransformToTsConfig(
4947
tree: Tree,
5048
root: string,
@@ -61,15 +59,12 @@ export function addZod2MdTransformToTsConfig(
6159
if (!firstExistingTsc) {
6260
throw new Error(`No config tsconfig.json file exists.`);
6361
}
64-
6562
const tscJson = JSON.parse(tree.read(firstExistingTsc)?.toString() ?? `{}`);
6663
const compilerOptions = tscJson.compilerOptions ?? {};
6764
const plugins = (compilerOptions.plugins ?? []) as PluginDefinition[];
68-
6965
const hasTransformPlugin = plugins.some(
7066
plugin => plugin.transform === './tools/zod2md-jsdocs/dist',
7167
);
72-
7368
if (!hasTransformPlugin) {
7469
tree.write(
7570
firstExistingTsc,

tools/zod2md-jsdocs/src/lib/generators/configuration/tsconfig.unit.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe('addZod2MdTransformToTsConfig', () => {
1212
testProjectName,
1313
DEFAULT_ZOD2MD_CONFIG_FILE_NAME,
1414
);
15-
1615
beforeEach(() => {
1716
tree = createTreeWithEmptyWorkspace();
1817
tree.write(
@@ -40,7 +39,6 @@ describe('addZod2MdTransformToTsConfig', () => {
4039
`,
4140
);
4241
});
43-
4442
it('should fail on missing tsconfig.json', () => {
4543
tree.delete(tsconfigLibPath);
4644
expect(() =>
@@ -50,7 +48,6 @@ describe('addZod2MdTransformToTsConfig', () => {
5048
}),
5149
).toThrow('No config tsconfig.json file exists.');
5250
});
53-
5451
it('should update tsconfig.lib.json with transform', () => {
5552
tree.write(
5653
tsconfigLibPath,
@@ -60,7 +57,6 @@ describe('addZod2MdTransformToTsConfig', () => {
6057
projectName: testProjectName,
6158
baseUrl: 'http://example.com',
6259
});
63-
6460
expect(
6561
JSON.parse(tree.read(tsconfigLibPath)?.toString() ?? '{}'),
6662
).toStrictEqual(
@@ -77,7 +73,6 @@ describe('addZod2MdTransformToTsConfig', () => {
7773
}),
7874
);
7975
});
80-
8176
it('should skip creation if config already configured', () => {
8277
expect(() =>
8378
addZod2MdTransformToTsConfig(tree, testProjectName, {
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
export type ItemOrArray<T> = T | T[];
2-
32
export type ExtractArray<T> = T extends unknown[] ? T : never;
4-
53
export type ExecutableCode = {
64
fileImports: ItemOrArray<string>;
75
codeStrings: ItemOrArray<string>;
86
};
9-
107
export type ExtractArrays<T extends Record<string, unknown>> = {
118
[K in keyof T]: ExtractArray<T[K]>;
129
};

tools/zod2md-jsdocs/src/lib/generators/configuration/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export function normalizeItemOrArray<T>(
1010
}
1111
return [itemOrArray];
1212
}
13-
14-
// Return a formatted JSON in TS object with the same keys as the input object but remove the " for the properties
1513
export function formatObjectToFormattedJsString(
1614
jsonObj?:
1715
| {
@@ -22,13 +20,9 @@ export function formatObjectToFormattedJsString(
2220
if (!jsonObj) {
2321
return;
2422
}
25-
// Convert JSON object to a string with indentation
2623
const jsonString = JSON.stringify(jsonObj, null, 2);
27-
28-
// Remove double quotes around property names
2924
return jsonString.replace(/"(\w+)":/g, '$1:');
3025
}
31-
3226
export function formatArrayToLinesOfJsString(
3327
lines?: string[],
3428
separator = '\n',
@@ -38,12 +32,10 @@ export function formatArrayToLinesOfJsString(
3832
}
3933
return lines.join(separator).replace(/'/g, '"');
4034
}
41-
4235
export function formatArrayToJSArray(lines?: string[]) {
4336
if (!Array.isArray(lines)) {
4437
return;
4538
}
46-
4739
return `[${formatArrayToLinesOfJsString(lines, ',\n') ?? ''}]`.replace(
4840
/"/g,
4941
'',

tools/zod2md-jsdocs/src/lib/generators/configuration/utils.unit.test.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,48 @@ import {
66

77
describe('formatArrayToJSArray', () => {
88
it('should return array as JS', () => {
9-
expect(
10-
formatArrayToJSArray(['plugin1()', 'plugin2()']),
11-
).toMatchInlineSnapshot(
12-
`
9+
expect(formatArrayToJSArray(['plugin1()', 'plugin2()']))
10+
.toMatchInlineSnapshot(`
1311
"[plugin1(),
1412
plugin2()]"
15-
`,
16-
);
13+
`);
1714
});
18-
1915
it('should return empty array as JS for empty items', () => {
2016
expect(formatArrayToJSArray([])).toMatchInlineSnapshot('"[]"');
2117
});
22-
2318
it('should return undefined for undefined values', () => {
2419
expect(formatArrayToJSArray(undefined)).toBeUndefined();
2520
});
2621
});
27-
2822
describe('formatArrayToLinesOfJsString', () => {
2923
it('should return lines as JS', () => {
30-
expect(
31-
formatArrayToLinesOfJsString([`import plugin from "../nx-plugin";`]),
32-
).toMatchInlineSnapshot(
33-
`
24+
expect(formatArrayToLinesOfJsString([`import plugin from "../nx-plugin";`]))
25+
.toMatchInlineSnapshot(`
3426
"import plugin from "../nx-plugin";"
35-
`,
36-
);
27+
`);
3728
});
38-
3929
it('should return lines as JS with normalized quotes', () => {
4030
expect(
4131
formatArrayToLinesOfJsString([
4232
`import { CoreConfig } from '@zod2md/models';`,
4333
`import plugin from "../mx-plugin";`,
4434
]),
45-
).toMatchInlineSnapshot(
46-
`
35+
).toMatchInlineSnapshot(`
4736
"import { CoreConfig } from "@zod2md/models";
4837
import plugin from "../mx-plugin";"
49-
`,
50-
);
38+
`);
5139
});
52-
5340
it('should return undefined for empty items', () => {
5441
expect(formatArrayToLinesOfJsString([])).toBeUndefined();
5542
});
56-
5743
it('should return undefined for nullish values', () => {
5844
expect(formatArrayToLinesOfJsString()).toBeUndefined();
5945
});
6046
});
61-
6247
describe('normalizeItemOrArray', () => {
6348
it('should turn string into string array', () => {
6449
expect(normalizeItemOrArray('myPlugin()')).toStrictEqual(['myPlugin()']);
6550
});
66-
6751
it('should keep string array', () => {
6852
expect(normalizeItemOrArray('myPlugin()')).toStrictEqual(['myPlugin()']);
6953
});

0 commit comments

Comments
 (0)