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 +87 -0
- package/dist/generators/generic.d.ts +2 -0
- package/dist/generators/helpers.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19801 -0
- package/dist/runtime.d.ts +24 -0
- package/dist/templates/index.d.ts +1 -0
- package/dist/templates/typescript/exporter-module-syntax.hbs +3 -0
- package/dist/templates/typescript/index.d.ts +2 -0
- package/dist/templates/typescript/object-syntax.hbs +5 -0
- package/dist/templates/typescript/types-file-syntax.hbs +5 -0
- package/dist/types/decoders.d.ts +5 -0
- package/dist/types/index.d.ts +100 -0
- package/dist/utils/error-handler.d.ts +16 -0
- package/dist/utils/file-system.d.ts +8 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/writer/helpers.d.ts +3 -0
- package/dist/writer/index.d.ts +2 -0
- package/package.json +75 -0
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
|
+
```
|
package/dist/index.d.ts
ADDED