mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
chore: add tsx demo and update readme
This commit is contained in:
parent
bffa5be420
commit
e2be399df2
@ -1,16 +1,22 @@
|
|||||||
# @ali/lowcode-material-parser
|
# @alilc/lowcode-material-parser
|
||||||
|
|
||||||
> 入料模块
|
> 入料模块
|
||||||
|
|
||||||
本模块负责物料接入,能自动扫描、解析源码组件,并最终产出一份符合《中后台搭建组件描述协议》的 **JSON Schema**。
|
本模块负责物料接入,能自动扫描、解析源码组件,并最终产出一份符合《中后台搭建组件描述协议》的 **JSON Schema**。
|
||||||
|
|
||||||
详见[文档](https://yuque.antfin-inc.com/ali-lowcode/docs/tyktrt)。
|
详见[文档](https://lowcode-engine.cn/docV2/yhgcqb)。
|
||||||
|
|
||||||
## demo
|
## demo
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
cd demo
|
cd demo
|
||||||
node index.js
|
|
||||||
|
// parse jsx
|
||||||
|
node parse-jsx.js
|
||||||
|
|
||||||
|
// parse tsx
|
||||||
|
node parse-tsx.js
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|||||||
54
modules/material-parser/demo/component.tsx
Normal file
54
modules/material-parser/demo/component.tsx
Normal 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;
|
||||||
11
modules/material-parser/demo/parse-tsx.js
Normal file
11
modules/material-parser/demo/parse-tsx.js
Normal 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));
|
||||||
|
})();
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-material-parser",
|
"name": "@alilc/lowcode-material-parser",
|
||||||
"version": "1.0.1-beta.3",
|
"version": "1.0.3",
|
||||||
"description": "material parser for Ali lowCode engine",
|
"description": "material parser for Ali lowCode engine",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@ -282,23 +282,21 @@ export function transformItem(name: string, item: any) {
|
|||||||
if (!isNil(defaultValue) && typeof defaultValue === 'object' && isEvaluable(defaultValue)) {
|
if (!isNil(defaultValue) && typeof defaultValue === 'object' && isEvaluable(defaultValue)) {
|
||||||
if (defaultValue === null) {
|
if (defaultValue === null) {
|
||||||
result.defaultValue = defaultValue;
|
result.defaultValue = defaultValue;
|
||||||
} else {
|
} else if ('computed' in defaultValue) {
|
||||||
// if ('computed' in defaultValue) {
|
// parsed data from react-docgen
|
||||||
// val = val.value;
|
|
||||||
try {
|
try {
|
||||||
if (isEvaluable(defaultValue.value)) {
|
if (isEvaluable(defaultValue.value)) {
|
||||||
const value = safeEval(`'${defaultValue.value}'`);
|
result.defaultValue = safeEval(defaultValue.value);
|
||||||
result.defaultValue = value;
|
|
||||||
} else {
|
} else {
|
||||||
result.defaultValue = defaultValue.value;
|
result.defaultValue = defaultValue.value;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// parsed data from react-docgen-typescript
|
||||||
|
result.defaultValue = defaultValue.value;
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// result.defaultValue = defaultValue.value;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
if (result.propType === undefined) {
|
if (result.propType === undefined) {
|
||||||
delete result.propType;
|
delete result.propType;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user