Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/artifact-project/tx-reflector
TypeScript transformer for code generation.
https://github.com/artifact-project/tx-reflector
artifact-project interfaces react reflection typescript-transformer
Last synced: 12 days ago
JSON representation
TypeScript transformer for code generation.
- Host: GitHub
- URL: https://github.com/artifact-project/tx-reflector
- Owner: artifact-project
- Created: 2017-06-21T10:57:05.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-28T10:07:45.000Z (over 6 years ago)
- Last Synced: 2024-06-20T00:17:21.139Z (22 days ago)
- Topics: artifact-project, interfaces, react, reflection, typescript-transformer
- Language: TypeScript
- Size: 18.6 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Lists
- awesome-stars - tx-reflector - TypeScript transformer for code generation. (TypeScript)
- awesome-stars - tx-reflector - TypeScript transformer for code generation. (TypeScript)
README
TX Reflector
------------
TypeScript transformer for code generation.
See also [Interface-based instructions](https://github.com/artifact-project/ibi).### Install
```
npm i --save-dev tx-reflector
```### API
- `getInterfaces(target: Function | object): string[]`
- `getInterfaces(target: T): string[]`
- `getRawInterfaces(target: T): Interface[]`
- `getComponentInterfaces(XClass: Function): string[]`### Usage
```ts
import {getInterfaces, getRawInterfaces, Interface} from 'tx-reflector';const data: IData = {value: 'foo'};
const interfaces: string[] = getInterfaces(data); // OR getInterfaces(anything);
const rawInterfaces: Interface[] = getRawInterfaces(data);;// After compilation:
// var interfaces = ["IData", "IAbstractData"];
// var rawInterfaces = [
// {
// name: "IData",
// entries: [{name: "value", type: "string", optional: false}],
// }, {
// name: "IAbstractData",
// entries: [{name: "source", type: "string", optional: false}],
// },
// ];
```### React and like
```ts
import {getComponentInterfaces} from 'tx-reflector';interface IBtnProps extends IComponent, IClickable {
value: string;
}class Btn extends React.Component {
}const interfaces = getComponentInterfaces(Btn);
// After compilation:
// var interfaces = ["IBtnProps", "IComponent", "IClickable"];
```### Webpack
Use [awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader) or [ts-loader 2.3+](https://github.com/TypeStrong/ts-loader/).```js
// webpack.config.js
const {default:txReflector} = require('tx-reflector/src/transformer/transformer');module.exports = {
// ...
module: {
// ...
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader', // or ts-loader
options: {
getCustomTransformers() {
return {
before: [txReflector],
after: [],
};
}
}
},
},
// ...
};
```### Jest (only with TS 2.4+)
```js
// .jest/tsPreprocessor.js
const tsc = require('typescript');
const tsConfig = require('../tsconfig.json');
const {default:txReflector} = require('tx-reflector/src/transformer/transformer');module.exports = {
process(src, path) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
const result = tsc.transpileModule(src, {
compilerOptions: tsConfig.compilerOptions,
fileName: path,
transformers: {
before: [txReflector],
after: [],
},
});return result.outputText;
}return src;
},
};
```### Development
- `npm i`
- `npm test`, [code coverage](./coverage/lcov-report/index.html)