type-crafter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Type Crafter
2
+
3
+ TypeCrafter is a CLI tool for generating types from a YAML types specification for any language.
4
+ The tool is heavily inspired by [OpenAPI Generator](https://openapi-generator.tech/) and
5
+ aims to provide similar functionality for generating types with a simple YAML specification & more flexibility.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm i -g type-crafter
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ type-crafter generate <language> <types-specification-file> <output-directory>
17
+ ```
18
+
19
+ ### Example
20
+
21
+ ```bash
22
+ type-crafter generate typescript types.yaml ./types
23
+ ```
24
+
25
+ Example input specification file can be found [here](https://github.com/sinha-sahil/type-crafter/blob/release/examples/input.yaml#L1)
26
+
27
+ ## Input Specification
28
+
29
+ The input specification is a YAML file that contains the types specification.
30
+ Refer the following sample specification for the structure:
31
+
32
+ ```yaml
33
+ info:
34
+ version: 0.0.0
35
+ title: Title of your specification
36
+ types:
37
+ SampleType:
38
+ type: object
39
+ properties:
40
+ name:
41
+ type: string
42
+ groupedTypes:
43
+ SampleGroupedType:
44
+ type: object
45
+ properties:
46
+ name:
47
+ type: string
48
+ ```
49
+
50
+ The input specification yaml file must be of following syntax:
51
+
52
+ - `info` - The information about the specification. Specifying the version and title of your spec. **This is required.**
53
+ - `types` - These are types that will be generated in flat structure.
54
+ - `groupedTypes` - These are types that will be generated and grouped in a folder.
55
+
56
+ **Note: Passing types or groupedTypes is up to your expected results. A valid spec file can contain either types or groupedTypes or both.**
57
+
58
+ The syntax for writing different types can be referred from the [OpenAPI Data Types Guide](https://swagger.io/docs/specification/data-models/data-types/).
59
+
60
+ ## Supported languages
61
+
62
+ - [✔️] TypeScript
63
+ - More languages will be added soon.
64
+
65
+ ## Contributing & Extending
66
+
67
+ ### Adding support for a new language
68
+
69
+ TypeCrafter uses Handlebars to template syntax for different languages.
70
+
71
+ To add support for a new language, you need to create a new folder in `src/templates` directory.
72
+ The folder name will be the name of the language.
73
+ The folder must implement following files:
74
+
75
+ - `index.ts` - The main file that will be exporting the [generator config](https://github.com/sinha-sahil/type-crafter/blob/release/src/types/index.ts#L5).
76
+ - `object-syntax.hbs` - This Handlebars template file that will be used to generate the object syntax.
77
+ - `type-file-syntax.hbs` - This Handlebars template file that will be used to generate the syntax for file which contains the generated types & its imports.
78
+ - `exporter-module-syntax.hbs` - This Handlebars template file that will be used to generate the syntax for the module that exports the generated types.
79
+
80
+ ## Development
81
+
82
+ To start developing type-crafter, you need to run following commands:
83
+
84
+ ```bash
85
+ pnpm i
86
+ pnpm run dev
87
+ ```
@@ -0,0 +1,2 @@
1
+ import type { GenerationResult, SpecFileData } from '$types';
2
+ export declare function generator(specFileData: SpecFileData): GenerationResult;
@@ -0,0 +1,2 @@
1
+ import type { JSONObject } from 'type-decoder';
2
+ export declare function resolveReference(reference: string): JSONObject;
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { type Configuration } from '$types';
3
+ export declare function generate(config: Configuration): Promise<void>;