Skip to content

Commit 9d3c84f

Browse files
committed
formatting
1 parent d4bf466 commit 9d3c84f

10 files changed

+110
-13
lines changed

.dprint.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"lineWidth": 120,
3+
"useTabs": true,
4+
"markdown": {
5+
"textWrap": "always"
6+
},
7+
"excludes": [
8+
"**/node_modules",
9+
"**/*-lock.json"
10+
],
11+
"plugins": [
12+
"https://plugins.dprint.dev/typescript-0.89.0.wasm",
13+
"https://plugins.dprint.dev/json-0.19.1.wasm",
14+
"https://plugins.dprint.dev/markdown-0.16.3.wasm"
15+
]
16+
}

.editorconfig

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ root = true
55

66
[*]
77
indent_style = tab
8-
indent_size = 2
98
end_of_line = lf
109
charset = utf-8
1110
trim_trailing_whitespace = true

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
TreeType generates module definitions for object types.
44

55
## Install
6+
67
```sh
78
npm i tsup -D
89
# Or Yarn
@@ -12,11 +13,13 @@ pnpm add tsup -D
1213
```
1314

1415
## Usage
16+
1517
```
1618
treetype <definition file>
1719
```
1820

1921
The definition file specifies which modules to generate, the format is as follows:
22+
2023
```ini
2124
## These directives control some global options
2225
# `source` specifies which file should be used as the source of all source types
@@ -41,6 +44,7 @@ module from SourceType {
4144
}
4245
}
4346
```
47+
4448
Should any path or tree node need to contain whitespace, you can enclose it in quotes (`"`).
4549

4650
<!-- TODO: example plugins -->

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"devDependencies": {
2424
"@types/node": "^20.11.17",
25+
"dprint": "^0.45.0",
2526
"tsup": "^8.0.2"
2627
}
2728
}

pnpm-lock.yaml

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/env node
2-
import ts from "typescript";
3-
import * as path from "node:path";
42
import * as fs from "node:fs/promises";
5-
import { parseDefinition } from "./def.js";
3+
import * as path from "node:path";
4+
import ts from "typescript";
65
import { createModuleDeclarations } from "./core.js";
6+
import { parseDefinition } from "./def.js";
77

88
function getProjectProgram(filePath: string) {
99
const configPath = ts.findConfigFile(filePath, ts.sys.fileExists, "tsconfig.json");
@@ -34,7 +34,7 @@ async function main(argv: string[]) {
3434
const program = getProjectProgram(file);
3535
const definitions = parseDefinition(raw);
3636

37-
const nodes = createModuleDeclarations(program, definitions, path.dirname(file))
37+
const nodes = createModuleDeclarations(program, definitions, path.dirname(file));
3838
const result = ts.createSourceFile("output.ts", "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
3939
const printer = ts.createPrinter({
4040
newLine: ts.NewLineKind.LineFeed,

src/core.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function createImportNode(def: DefinitionEntry) {
2424
return factory.createTypeAliasDeclaration(undefined, rootIdent, undefined, importNode);
2525
}
2626

27-
const reserved = [
27+
const reserved = /* dprint-ignore */ [
2828
"break", "case", "catch", "class", "const", "continue", "debugger",
2929
"default", "delete", "do", "else", "enum", "export", "extends", "false",
3030
"finally", "for", "function", "if", "import", "in", "instanceof", "new",
@@ -54,7 +54,11 @@ function createExportNode(checker: ts.TypeChecker, type: ts.Type) {
5454
);
5555
}
5656

57-
export function createModuleDeclarations(program: ts.Program, definitions: Iterable<DefinitionEntry>, resolveDir: string) {
57+
export function createModuleDeclarations(
58+
program: ts.Program,
59+
definitions: Iterable<DefinitionEntry>,
60+
resolveDir: string,
61+
) {
5862
const checker = program.getTypeChecker();
5963
const nodes: ts.Node[] = [];
6064

src/def.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function* tokenize(input: string) {
2121
case "\r":
2222
case "\n":
2323
break;
24-
case '"':
24+
case "\"":
2525
state = TokenizerState.quote;
2626
break;
2727
case "#":
@@ -45,7 +45,7 @@ function* tokenize(input: string) {
4545
value = "";
4646
}
4747
break;
48-
case '"':
48+
case "\"":
4949
state = TokenizerState.quote;
5050
break;
5151
default:
@@ -59,7 +59,7 @@ function* tokenize(input: string) {
5959
break;
6060
case TokenizerState.quote:
6161
switch (char) {
62-
case '"':
62+
case "\"":
6363
state = TokenizerState.word;
6464
break;
6565
case "\\":
@@ -112,7 +112,7 @@ export function* parseDefinition(source: string) {
112112
function* parseNode(
113113
path: string[] = [],
114114
resolve: string[] = [],
115-
from: string | null = null
115+
from: string | null = null,
116116
): Generator<DefinitionEntry> {
117117
ensureNotEof();
118118
const name = read();

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./def.js";
21
export * from "./core.js";
2+
export * from "./def.js";

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"module": "Node16",
44
"target": "ES2022",
5-
"lib": ["ES2022"],
5+
"lib": ["ES2022"],
66

77
"strict": true,
88
"noFallthroughCasesInSwitch": true,

0 commit comments

Comments
 (0)