Skip to content

Commit 4114e56

Browse files
committed
Configuration file and modernization
1 parent 96f5e6f commit 4114e56

7 files changed

Lines changed: 51 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Path to a JSON configuration file. Default: `./typesharp.json` when that file ex
3838
`-s`, `--source` required unless set in config
3939
Folder containing `.cs` files. Subfolders are included.
4040

41-
`-f`, `--file-filter` required unless set in config
42-
Glob-style filter for source files, such as `*.cs` or `*Dto.cs`. Default: none.
41+
`-f`, `--file-filter` optional
42+
Glob-style filter for source files, such as `*.cs` or `*Dto.cs`. Default: `*.cs`.
4343

4444
`-t`, `--type-filter` optional
4545
Glob-style filter for parsed type names, such as `Person*`. Default: all parsed types.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Person } from "./Person";
22

33
export interface Dictionaries {
4-
personDictionary: { [key: string]: Person };
5-
personDictionaryDouble: { [key: number]: Person };
6-
personDictionaryInt: { [key: number]: Person };
4+
personDictionary: Record<string, Person>;
5+
personDictionaryDouble: Record<number, Person>;
6+
personDictionaryInt: Record<number, Person>;
77
}

samples/SampleModels/Typescript/Person.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ export interface Person {
3030
typeUnionDouble: 1.2 | 2.2;
3131
shouldBeAny: any;
3232
shouldBeUnknown?: unknown;
33-
pairs?: { [key: string]: any };
34-
subpersonPairs?: { [key: string]: SubPerson };
33+
pairs?: Record<string, any>;
34+
subpersonPairs?: Record<string, SubPerson>;
3535
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export { AccessLevel } from "./AccessLevel";
2-
export { ClassWithEvents } from "./ClassWithEvents";
3-
export { Dictionaries } from "./Dictionaries";
4-
export { GenericPerson } from "./GenericPerson";
5-
export { Person } from "./Person";
6-
export { PersonInput } from "./PersonInput";
7-
export { SubPerson } from "./SubPerson";
1+
export * from "./AccessLevel";
2+
export * from "./ClassWithEvents";
3+
export * from "./Dictionaries";
4+
export * from "./GenericPerson";
5+
export * from "./Person";
6+
export * from "./PersonInput";
7+
export * from "./SubPerson";

src/typesharp-ts/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ function resolveConfigPaths(options: ConfigFileOptions, base: string): ConfigFil
126126

127127
function finalizeOptions(options: ConfigFileOptions): CliOptions {
128128
if (typeof options.source !== "string") throw new Error("Missing required argument --source");
129-
if (typeof options.fileFilter !== "string") throw new Error("Missing required argument --file-filter");
130129
if (typeof options.destination !== "string") throw new Error("Missing required argument --destination");
131130
if (
132131
options.dictionaryStyle !== undefined && options.dictionaryStyle !== "index-signature" &&
@@ -139,7 +138,7 @@ function finalizeOptions(options: ConfigFileOptions): CliOptions {
139138
}
140139
return {
141140
source: options.source,
142-
fileFilter: options.fileFilter,
141+
fileFilter: options.fileFilter ?? "*.cs",
143142
destination: options.destination,
144143
typeFilter: options.typeFilter,
145144
watch: options.watch ?? false,

src/typesharp-ts/parser_test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,30 @@ Deno.test("loads typesharp.json and lets CLI override file values", async () =>
245245
}
246246
});
247247

248+
Deno.test("defaults fileFilter to C# source files", async () => {
249+
const temp = await Deno.makeTempDir();
250+
try {
251+
await Deno.writeTextFile(
252+
`${temp}/typesharp.json`,
253+
JSON.stringify({
254+
source: "models",
255+
destination: "generated",
256+
}),
257+
);
258+
259+
const options = await resolveOptions([], temp);
260+
assertEquals(options, {
261+
source: `${temp}/models`,
262+
fileFilter: "*.cs",
263+
destination: `${temp}/generated`,
264+
watch: false,
265+
exportModule: false,
266+
});
267+
} finally {
268+
await Deno.remove(temp, { recursive: true });
269+
}
270+
});
271+
248272
Deno.test("fails clearly on unsupported property bodies", async () => {
249273
await assertRejects(
250274
() => {

typesharp.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"source": "./samples/SampleModels",
3+
"fileFilter": "*.cs",
4+
"typeFilter": "*",
5+
"destination": "./samples/SampleModels/Typescript",
6+
"watch": false,
7+
"exportModule": true,
8+
"dictionaryStyle": "record",
9+
"readonlyProperties": false,
10+
"quoteStyle": "double",
11+
"semicolons": true
12+
}

0 commit comments

Comments
 (0)