# ts-creator
A code generator to generate TypeScript code generator from TypeScript code
👉 Try It! 👈
How to use it:
npm install ts-creator
1. generate from code
2. transform source file
declare
3. transform node
declare
How does it work?
If you want to write a TypeScript codegen.
You got TypeScript code:
ts-creator generate TypeScript factory from given code to:
ts.createFunctionDeclaration undefined, undefined, undefined, ts.createIdentifier'foo', undefined, , ts.createKeywordTypeNodets.SyntaxKind.NumberKeyword, ts.createBlock , true
Result after run the generated factory code:
Cli usage
Use ts-creator
cli to generate code:
ts-creator <input> [options]
Simple usage:
# print generate code ts-creator foo.ts # or read data from pipeline echo 42 | ts-creatorcat foo.ts | ts-creatorts-creator < foo.ts # write to file ts-creator foo.ts -o foo.jsts-creator foo.ts > foo.js
Installation
You can install ts-creator
globally.
npm i -g ts-creator# or yarn yarn global add ts-creator
If you install locally, may prepend npx
or yarn
you need.
# use npm npm i ts-creatornpx ts-creator -h # use yarn yarn add ts-creatoryarn ts-creator -h
Cli options
option | description | type | default |
---|---|---|---|
--target, -t | generate targets | Enum { expression , runnable , esmodule , commonjs } |
expression |
--output, -o | output to filepath | String | undefined |
--tsx | tsx support | Boolean | false |
--color | colorful print | Boolean | true |
--semi | print semicolons at the ends of statements | Boolean | false |
--single-quote | use single quotes instead of double quotes | Boolean | true |
--jsx-single-quote | use single quotes in JSX | Boolean | false |
--bracket-spacing | print spaces between brackets in object literals | Boolean | true |
--tab-width | pecify the number of spaces per indentation-level | Number | 2 |
--use-tabs | indent lines with tabs instead of spaces | Boolean | false |
--trailing-comma | print trailing commas wherever possible | Enum { none , es5 , all } |
none |
--prose-wrap | how to wrap output | Enum { always , never , preserve } |
preserve |
--version, -v | show ts-creator versions | Boolean | false |
--help, -h | show helper | Boolean | false |
TODO:
- JSDoc