chore: add tsx demo and update readme

This commit is contained in:
mark 2022-03-30 15:44:47 +08:00
parent bffa5be420
commit e2be399df2
6 changed files with 81 additions and 12 deletions

View File

@ -1,16 +1,22 @@
# @ali/lowcode-material-parser
# @alilc/lowcode-material-parser
> 入料模块
本模块负责物料接入,能自动扫描、解析源码组件,并最终产出一份符合《中后台搭建组件描述协议》的 **JSON Schema**
详见[文档](https://yuque.antfin-inc.com/ali-lowcode/docs/tyktrt)。
详见[文档](https://lowcode-engine.cn/docV2/yhgcqb)。
## demo
```shell
cd demo
node index.js
// parse jsx
node parse-jsx.js
// parse tsx
node parse-tsx.js
```
## API

View File

@ -0,0 +1,54 @@
/* eslint-disable react/forbid-prop-types,react/no-unused-prop-types */
import React from 'react';
import './main.scss';
interface DemoProps {
optionalArray?: [],
optionalBool: boolean,
optionalFunc: Function,
optionalNumber: number,
optionalObject: object,
optionalString: string,
optionalSymbol: symbol,
// Anything that can be rendered: numbers, strings, elements or an array
// (or fragment) containing these types.
optionalNode: React.ReactNode,
// A React element (ie. <MyComponent />).
optionalElement: React.ReactElement,
// A React element type (ie. MyComponent).
optionalElementType: React.ElementType,
// You can also declare that a prop is an instance of a class. This uses
// JS's instanceof operator.
optionalMessage: React.ReactInstance,
// You can ensure that your prop is limited to specific values by treating
// it as an enum.
optionalEnum: 'News'|'Photos',
// An object that could be one of many types
optionalUnion: string|number|React.ReactInstance,
// An array of a certain type
optionalArrayOf: number[],
// An object with property values of a certain type
optionalObjectOf: Record<number, any>,
// You can chain any of the above with `isRequired` to make sure a warning
// is shown if the prop isn't provided.
}
const Demo = (props: DemoProps) => {
return <div> Test </div>;
}
Demo.defaultProps = {
optionalString: 'optionalString'
};
export default Demo;

View File

@ -0,0 +1,11 @@
const parse = require('../lib').default;
(async () => {
const options = {
entry: './component.tsx',
accesser: 'local',
};
const actual = await parse(options);
console.log(JSON.stringify(actual, null, 2));
})();

View File

@ -1,6 +1,6 @@
{
"name": "@alilc/lowcode-material-parser",
"version": "1.0.1-beta.3",
"version": "1.0.3",
"description": "material parser for Ali lowCode engine",
"main": "lib/index.js",
"files": [

View File

@ -282,23 +282,21 @@ export function transformItem(name: string, item: any) {
if (!isNil(defaultValue) && typeof defaultValue === 'object' && isEvaluable(defaultValue)) {
if (defaultValue === null) {
result.defaultValue = defaultValue;
} else {
// if ('computed' in defaultValue) {
// val = val.value;
} else if ('computed' in defaultValue) {
// parsed data from react-docgen
try {
if (isEvaluable(defaultValue.value)) {
const value = safeEval(`'${defaultValue.value}'`);
result.defaultValue = value;
result.defaultValue = safeEval(defaultValue.value);
} else {
result.defaultValue = defaultValue.value;
}
} catch (e) {
log(e);
}
} else {
// parsed data from react-docgen-typescript
result.defaultValue = defaultValue.value;
}
// else {
// result.defaultValue = defaultValue.value;
// }
}
if (result.propType === undefined) {
delete result.propType;