mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-19 05:48:17 +00:00
refactor: material parser code style
1. 修复eslint问题 2. instanceOf => any 3. 修复node类型解析失败问题 Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3716330 * refactor: material parser code style
This commit is contained in:
parent
0a29c80928
commit
430d522353
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -9,7 +9,7 @@
|
|||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"runtimeExecutable": "${workspaceFolder}/packages/material-parser/node_modules/.bin/ava",
|
"runtimeExecutable": "${workspaceFolder}/packages/material-parser/node_modules/.bin/ava",
|
||||||
"runtimeArgs": ["debug", "--break", "${file}"]
|
"runtimeArgs": ["debug", "--break", "${workspaceFolder}/packages/material-parser/test/antd.ts"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./scripts/build.sh",
|
"build": "./scripts/build.sh",
|
||||||
"clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build",
|
"clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build",
|
||||||
|
"lint": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet",
|
||||||
|
"lint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet --fix",
|
||||||
"pub": "lerna publish --force-publish --cd-version prepatch",
|
"pub": "lerna publish --force-publish --cd-version prepatch",
|
||||||
"setup": "./scripts/setup.sh",
|
"setup": "./scripts/setup.sh",
|
||||||
"start": "./scripts/start.sh",
|
"start": "./scripts/start.sh",
|
||||||
@ -19,9 +21,7 @@
|
|||||||
"test": "lerna run test --stream",
|
"test": "lerna run test --stream",
|
||||||
"test:snapshot": "lerna run test:snapshot",
|
"test:snapshot": "lerna run test:snapshot",
|
||||||
"xima:fix": "xima fix",
|
"xima:fix": "xima fix",
|
||||||
"xima:scan": "xima scan",
|
"xima:scan": "xima scan"
|
||||||
"lint": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet",
|
|
||||||
"lint:fix": "eslint --ext .ts,.tsx,.js,.jsx ./ --quiet --fix"
|
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
|
|||||||
2
packages/material-parser/.eslintignore
Normal file
2
packages/material-parser/.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
test/fixtures/**
|
||||||
|
lib/**
|
||||||
3
packages/material-parser/.eslintrc.js
Normal file
3
packages/material-parser/.eslintrc.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: 'eslint-config-ali/typescript/react',
|
||||||
|
};
|
||||||
@ -12,3 +12,5 @@
|
|||||||
cd demo
|
cd demo
|
||||||
node index.js
|
node index.js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable react/forbid-prop-types,react/no-unused-prop-types */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
@ -37,7 +38,11 @@ Demo.propTypes = {
|
|||||||
optionalEnum: PropTypes.oneOf(['News', 'Photos']),
|
optionalEnum: PropTypes.oneOf(['News', 'Photos']),
|
||||||
|
|
||||||
// An object that could be one of many types
|
// An object that could be one of many types
|
||||||
optionalUnion: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Demo)]),
|
optionalUnion: PropTypes.oneOfType([
|
||||||
|
PropTypes.string,
|
||||||
|
PropTypes.number,
|
||||||
|
PropTypes.instanceOf(Demo),
|
||||||
|
]),
|
||||||
|
|
||||||
// An array of a certain type
|
// An array of a certain type
|
||||||
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
|
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
|
||||||
|
|||||||
@ -63,6 +63,7 @@
|
|||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react-docgen": "^5.3.0",
|
"react-docgen": "^5.3.0",
|
||||||
"react-docgen-typescript": "^1.16.5",
|
"react-docgen-typescript": "^1.16.5",
|
||||||
|
"safe-eval": "^0.4.1",
|
||||||
"semver": "^7.1.3",
|
"semver": "^7.1.3",
|
||||||
"short-uuid": "^3.1.1",
|
"short-uuid": "^3.1.1",
|
||||||
"typescript": "^3.9.5",
|
"typescript": "^3.9.5",
|
||||||
|
|||||||
@ -5,6 +5,6 @@ export * from './schema/types';
|
|||||||
/**
|
/**
|
||||||
* Dev helper
|
* Dev helper
|
||||||
*/
|
*/
|
||||||
export const debug = _debug('lowcode');
|
export const debug = _debug('lowcode:mat');
|
||||||
export const enableDebug = () => _debug.enable('lowcode:*');
|
export const enableDebug = () => _debug.enable('lowcode:*');
|
||||||
export const disableDebug = () => _debug.disable();
|
export const disableDebug = () => _debug.disable();
|
||||||
|
|||||||
@ -42,13 +42,13 @@ export interface Npm {
|
|||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
export interface PropsSection {
|
export interface PropsSection {
|
||||||
props: Array<{
|
props: {
|
||||||
name: string;
|
name: string;
|
||||||
propType: PropType;
|
propType: PropType;
|
||||||
description?: string;
|
description?: string;
|
||||||
defaultValue?: any;
|
defaultValue?: any;
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}>;
|
}[];
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
export interface RequiredType {
|
export interface RequiredType {
|
||||||
@ -57,7 +57,7 @@ export interface RequiredType {
|
|||||||
}
|
}
|
||||||
export interface OneOf {
|
export interface OneOf {
|
||||||
type: 'oneOf';
|
type: 'oneOf';
|
||||||
value: Array<string | number | boolean>;
|
value: (string | number | boolean)[];
|
||||||
isRequired?: boolean;
|
isRequired?: boolean;
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
@ -81,19 +81,19 @@ export interface ObjectOf {
|
|||||||
}
|
}
|
||||||
export interface Shape {
|
export interface Shape {
|
||||||
type: 'shape';
|
type: 'shape';
|
||||||
value: Array<{
|
value: {
|
||||||
name?: string;
|
name?: string;
|
||||||
propType?: PropType;
|
propType?: PropType;
|
||||||
}>;
|
}[];
|
||||||
isRequired?: boolean;
|
isRequired?: boolean;
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
export interface Exact {
|
export interface Exact {
|
||||||
type: 'exact';
|
type: 'exact';
|
||||||
value: Array<{
|
value: {
|
||||||
name?: string;
|
name?: string;
|
||||||
propType?: PropType;
|
propType?: PropType;
|
||||||
}>;
|
}[];
|
||||||
isRequired?: boolean;
|
isRequired?: boolean;
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { debug, ComponentMeta } from './core';
|
import { debug, ComponentMeta } from './core';
|
||||||
import { IMaterialParsedModel, IMaterialScanModel } from './types';
|
import { IMaterialParsedModel, IMaterialScanModel } from './types';
|
||||||
|
|
||||||
const log = debug.extend('mat');
|
const log = debug.extend('gen');
|
||||||
|
|
||||||
export default async function (
|
export default async function (
|
||||||
matScanModel: IMaterialScanModel,
|
matScanModel: IMaterialScanModel,
|
||||||
@ -41,6 +41,7 @@ export async function genManifest(
|
|||||||
title: matScanModel.pkgName,
|
title: matScanModel.pkgName,
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
screenshot: '',
|
screenshot: '',
|
||||||
|
devMode: 'proCode', // 需要入料的组件都是源码模式,低代码组件在平台上即可直接生成描述
|
||||||
npm: {
|
npm: {
|
||||||
package: matScanModel.pkgName,
|
package: matScanModel.pkgName,
|
||||||
version: matScanModel.pkgVersion,
|
version: matScanModel.pkgVersion,
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
import spawn from 'cross-spawn-promise';
|
import spawn from 'cross-spawn-promise';
|
||||||
import { ensureDir, ensureFile, writeFile } from 'fs-extra';
|
import { ensureDir, ensureFile, writeFile } from 'fs-extra';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import semver from 'semver';
|
|
||||||
import uuid from 'short-uuid';
|
import uuid from 'short-uuid';
|
||||||
import { debug } from './core';
|
import { debug } from './core';
|
||||||
import { IMaterializeOptions } from './types';
|
import { IMaterializeOptions } from './types';
|
||||||
|
|
||||||
const log = debug.extend('mat');
|
const log = debug.extend('localize');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建组件包
|
* 创建组件包
|
||||||
|
|||||||
@ -3,6 +3,9 @@ import parseJS from './js';
|
|||||||
import parseTS from './ts';
|
import parseTS from './ts';
|
||||||
import { install, installPeerDeps, installTypeModules } from '../utils';
|
import { install, installPeerDeps, installTypeModules } from '../utils';
|
||||||
import { IMaterialScanModel } from '../types';
|
import { IMaterialScanModel } from '../types';
|
||||||
|
import { debug } from '../core';
|
||||||
|
|
||||||
|
const log = debug.extend('parse');
|
||||||
|
|
||||||
export interface IParseArgs extends IMaterialScanModel {
|
export interface IParseArgs extends IMaterialScanModel {
|
||||||
accesser?: 'online' | 'local';
|
accesser?: 'online' | 'local';
|
||||||
@ -15,7 +18,11 @@ export interface IParseArgs extends IMaterialScanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async (args: IParseArgs) => {
|
export default async (args: IParseArgs) => {
|
||||||
const { typingsFileAbsolutePath, mainFileAbsolutePath, moduleFileAbsolutePath = mainFileAbsolutePath } = args;
|
const {
|
||||||
|
typingsFileAbsolutePath,
|
||||||
|
mainFileAbsolutePath,
|
||||||
|
moduleFileAbsolutePath = mainFileAbsolutePath,
|
||||||
|
} = args;
|
||||||
if (args.accesser === 'local') {
|
if (args.accesser === 'local') {
|
||||||
if (moduleFileAbsolutePath.endsWith('ts') || moduleFileAbsolutePath.endsWith('tsx')) {
|
if (moduleFileAbsolutePath.endsWith('ts') || moduleFileAbsolutePath.endsWith('tsx')) {
|
||||||
await install(args);
|
await install(args);
|
||||||
@ -48,7 +55,7 @@ export default async (args: IParseArgs) => {
|
|||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log(e);
|
||||||
// if error, use static js parsing instead
|
// if error, use static js parsing instead
|
||||||
return parseJS(moduleFileAbsolutePath);
|
return parseJS(moduleFileAbsolutePath);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
|
// import { debug } from '../../../core';
|
||||||
const { namedTypes: t, NodePath } = require('ast-types');
|
const { namedTypes: t, NodePath } = require('ast-types');
|
||||||
|
|
||||||
|
// const log = debug.extend('parse:js');
|
||||||
|
|
||||||
type NodePathType = typeof NodePath;
|
type NodePathType = typeof NodePath;
|
||||||
const {
|
const {
|
||||||
getPropertyName,
|
getPropertyName,
|
||||||
@ -7,7 +10,6 @@ const {
|
|||||||
getMemberValuePath,
|
getMemberValuePath,
|
||||||
isReactForwardRefCall,
|
isReactForwardRefCall,
|
||||||
printValue,
|
printValue,
|
||||||
resolveExportDeclaration,
|
|
||||||
resolveToValue,
|
resolveToValue,
|
||||||
} = require('react-docgen').utils;
|
} = require('react-docgen').utils;
|
||||||
const resolveFunctionDefinitionToReturnValue = require('react-docgen/dist/utils/resolveFunctionDefinitionToReturnValue');
|
const resolveFunctionDefinitionToReturnValue = require('react-docgen/dist/utils/resolveFunctionDefinitionToReturnValue');
|
||||||
@ -29,16 +31,17 @@ function getDefaultValue(path: NodePathType) {
|
|||||||
node = path.node;
|
node = path.node;
|
||||||
try {
|
try {
|
||||||
defaultValue = printValue(path);
|
defaultValue = printValue(path);
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
// log(e);
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof defaultValue !== 'undefined') {
|
if (typeof defaultValue !== 'undefined') {
|
||||||
return {
|
return {
|
||||||
value: defaultValue,
|
value: defaultValue,
|
||||||
computed:
|
computed:
|
||||||
t.CallExpression.check(node) ||
|
t.CallExpression.check(node) || t.MemberExpression.check(node) || t.Identifier.check(node),
|
||||||
t.MemberExpression.check(node) ||
|
|
||||||
t.Identifier.check(node),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,10 +58,7 @@ function getStatelessPropsPath(componentDefinition: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultPropsPath(componentDefinition: any) {
|
function getDefaultPropsPath(componentDefinition: any) {
|
||||||
let defaultPropsPath = getMemberValuePath(
|
let defaultPropsPath = getMemberValuePath(componentDefinition, 'defaultProps');
|
||||||
componentDefinition,
|
|
||||||
'defaultProps',
|
|
||||||
);
|
|
||||||
if (!defaultPropsPath) {
|
if (!defaultPropsPath) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -71,9 +71,7 @@ function getDefaultPropsPath(componentDefinition: any) {
|
|||||||
if (t.FunctionExpression.check(defaultPropsPath.node)) {
|
if (t.FunctionExpression.check(defaultPropsPath.node)) {
|
||||||
// Find the value that is returned from the function and process it if it is
|
// Find the value that is returned from the function and process it if it is
|
||||||
// an object literal.
|
// an object literal.
|
||||||
const returnValue = resolveFunctionDefinitionToReturnValue(
|
const returnValue = resolveFunctionDefinitionToReturnValue(defaultPropsPath);
|
||||||
defaultPropsPath,
|
|
||||||
);
|
|
||||||
if (returnValue && t.ObjectExpression.check(returnValue.node)) {
|
if (returnValue && t.ObjectExpression.check(returnValue.node)) {
|
||||||
defaultPropsPath = returnValue;
|
defaultPropsPath = returnValue;
|
||||||
}
|
}
|
||||||
@ -81,16 +79,11 @@ function getDefaultPropsPath(componentDefinition: any) {
|
|||||||
return defaultPropsPath;
|
return defaultPropsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultValuesFromProps(
|
function getDefaultValuesFromProps(properties: any[], documentation: any, isStateless: boolean) {
|
||||||
properties: any[],
|
|
||||||
documentation: any,
|
|
||||||
isStateless: boolean,
|
|
||||||
) {
|
|
||||||
properties
|
properties
|
||||||
// Don't evaluate property if component is functional and the node is not an AssignmentPattern
|
// Don't evaluate property if component is functional and the node is not an AssignmentPattern
|
||||||
.filter(
|
.filter(
|
||||||
propertyPath => !isStateless ||
|
propertyPath => !isStateless || t.AssignmentPattern.check(propertyPath.get('value').node),
|
||||||
t.AssignmentPattern.check(propertyPath.get('value').node),
|
|
||||||
)
|
)
|
||||||
.forEach(propertyPath => {
|
.forEach(propertyPath => {
|
||||||
if (t.Property.check(propertyPath.node)) {
|
if (t.Property.check(propertyPath.node)) {
|
||||||
@ -99,9 +92,7 @@ function getDefaultValuesFromProps(
|
|||||||
|
|
||||||
const propDescriptor = documentation.getPropDescriptor(propName);
|
const propDescriptor = documentation.getPropDescriptor(propName);
|
||||||
const defaultValue = getDefaultValue(
|
const defaultValue = getDefaultValue(
|
||||||
isStateless
|
isStateless ? propertyPath.get('value', 'right') : propertyPath.get('value'),
|
||||||
? propertyPath.get('value', 'right')
|
|
||||||
: propertyPath.get('value'),
|
|
||||||
);
|
);
|
||||||
if (defaultValue) {
|
if (defaultValue) {
|
||||||
propDescriptor.defaultValue = defaultValue;
|
propDescriptor.defaultValue = defaultValue;
|
||||||
@ -119,10 +110,7 @@ function getDefaultValuesFromProps(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function defaultPropsHandler(
|
export default function defaultPropsHandler(documentation: any, componentDefinition: any) {
|
||||||
documentation: any,
|
|
||||||
componentDefinition: any,
|
|
||||||
) {
|
|
||||||
let statelessProps = null;
|
let statelessProps = null;
|
||||||
const defaultPropsPath = getDefaultPropsPath(componentDefinition);
|
const defaultPropsPath = getDefaultPropsPath(componentDefinition);
|
||||||
/**
|
/**
|
||||||
@ -134,17 +122,9 @@ export default function defaultPropsHandler(
|
|||||||
|
|
||||||
// Do both statelessProps and defaultProps if both are available so defaultProps can override
|
// Do both statelessProps and defaultProps if both are available so defaultProps can override
|
||||||
if (statelessProps && t.ObjectPattern.check(statelessProps.node)) {
|
if (statelessProps && t.ObjectPattern.check(statelessProps.node)) {
|
||||||
getDefaultValuesFromProps(
|
getDefaultValuesFromProps(statelessProps.get('properties'), documentation, true);
|
||||||
statelessProps.get('properties'),
|
|
||||||
documentation,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (defaultPropsPath && t.ObjectExpression.check(defaultPropsPath.node)) {
|
if (defaultPropsPath && t.ObjectExpression.check(defaultPropsPath.node)) {
|
||||||
getDefaultValuesFromProps(
|
getDefaultValuesFromProps(defaultPropsPath.get('properties'), documentation, false);
|
||||||
defaultPropsPath.get('properties'),
|
|
||||||
documentation,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
import { namedTypes as t } from 'ast-types';
|
import { namedTypes as t } from 'ast-types';
|
||||||
import getTSType from '../utils/getTSType';
|
import getTSType from '../utils/getTSType';
|
||||||
import getRoot from '../utils/getRoot';
|
import getFlowTypeFromReactComponent, {
|
||||||
import parseTS from '../../ts';
|
applyToFlowTypeProperties,
|
||||||
import getFlowTypeFromReactComponent, { applyToFlowTypeProperties } from '../utils/getFlowTypeFromReactComponent';
|
} from '../utils/getFlowTypeFromReactComponent';
|
||||||
|
|
||||||
const { unwrapUtilityType } = require('react-docgen/dist/utils/flowUtilityTypes');
|
const { unwrapUtilityType } = require('react-docgen/dist/utils/flowUtilityTypes');
|
||||||
const { getFlowType, getPropertyName, resolveToValue } = require('react-docgen').utils;
|
const { getFlowType, getPropertyName, resolveToValue } = require('react-docgen').utils;
|
||||||
|
|||||||
@ -26,9 +26,9 @@ export default function parse(filePath: string): IMaterialParsedModel[] {
|
|||||||
const item: any = transformItem(name, info.props[name]);
|
const item: any = transformItem(name, info.props[name]);
|
||||||
acc.push(item);
|
acc.push(item);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
// TODO
|
||||||
return acc;
|
|
||||||
}
|
}
|
||||||
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
res.push({
|
res.push({
|
||||||
componentName: info.displayName,
|
componentName: info.displayName,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { uniqBy } from 'lodash';
|
|||||||
import checkIsIIFE from './checkIsIIFE';
|
import checkIsIIFE from './checkIsIIFE';
|
||||||
import resolveHOC from './resolveHOC';
|
import resolveHOC from './resolveHOC';
|
||||||
import resolveIIFE from './resolveIIFE';
|
import resolveIIFE from './resolveIIFE';
|
||||||
import resolveImport, { isImportLike } from './resolveImport';
|
import resolveImport from './resolveImport';
|
||||||
import resolveTranspiledClass from './resolveTranspiledClass';
|
import resolveTranspiledClass from './resolveTranspiledClass';
|
||||||
import isStaticMethod from './isStaticMethod';
|
import isStaticMethod from './isStaticMethod';
|
||||||
import findAssignedMethods from './findAssignedMethods';
|
import findAssignedMethods from './findAssignedMethods';
|
||||||
@ -253,14 +253,16 @@ function getSubComponents(path: any, scope: any, cache: ICache) {
|
|||||||
value: def.flatMap((x: any) => x).filter((x: any) => isComponentDefinition(x)),
|
value: def.flatMap((x: any) => x).filter((x: any) => isComponentDefinition(x)),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.map(({ subName, localName, value }: IMethodsPath) => value.map((x: any) => ({
|
.map(({ subName, localName, value }: IMethodsPath) => {
|
||||||
|
return value.map((x: any) => ({
|
||||||
subName,
|
subName,
|
||||||
localName,
|
localName,
|
||||||
value: x,
|
value: x,
|
||||||
})))
|
}));
|
||||||
|
})
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.flatMap((x: any) => x)
|
.flatMap((x: any) => x)
|
||||||
.map(({ subName, localName, value }: IMethodsPath) => {
|
.map(({ subName, value }: IMethodsPath) => {
|
||||||
const __meta = {
|
const __meta = {
|
||||||
subName,
|
subName,
|
||||||
exportName: path.__meta && path.__meta.exportName,
|
exportName: path.__meta && path.__meta.exportName,
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
import { namedTypes as t, visit } from 'ast-types';
|
import { namedTypes as t } from 'ast-types';
|
||||||
|
|
||||||
const {
|
const { isReactCreateClassCall, isReactForwardRefCall } = require('react-docgen').utils;
|
||||||
isReactCreateClassCall,
|
|
||||||
isReactForwardRefCall,
|
|
||||||
resolveToValue,
|
|
||||||
} = require('react-docgen').utils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the path is a call expression, it recursively resolves to the
|
* If the path is a call expression, it recursively resolves to the
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { builders, namedTypes as t, NodePath, visit } from 'ast-types';
|
import { builders, NodePath, visit } from 'ast-types';
|
||||||
/**
|
/**
|
||||||
* If the path is a call expression, it recursively resolves to the
|
* If the path is a call expression, it recursively resolves to the
|
||||||
* rightmost argument, stopping if it finds a React.createClass call expression
|
* rightmost argument, stopping if it finds a React.createClass call expression
|
||||||
@ -17,11 +17,7 @@ export default function resolveTranspiledClass(path: any) {
|
|||||||
builders.blockStatement([
|
builders.blockStatement([
|
||||||
builders.returnStatement(
|
builders.returnStatement(
|
||||||
builders.jsxElement(
|
builders.jsxElement(
|
||||||
builders.jsxOpeningElement(
|
builders.jsxOpeningElement(builders.jsxIdentifier('div'), [], true),
|
||||||
builders.jsxIdentifier('div'),
|
|
||||||
[],
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
|||||||
@ -14,5 +14,5 @@ export function get(scope: string, name: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function has(scope: string, name: string) {
|
export function has(scope: string, name: string) {
|
||||||
return cache[scope] && cache[scope].hasOwnProperty(name);
|
return cache[scope] && Object.prototype.hasOwnProperty.call(cache[scope], name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,15 @@ function makeProxy(target: { [name: string]: any }, meta: any = {}): any {
|
|||||||
if (prop === '__isProxy') return true;
|
if (prop === '__isProxy') return true;
|
||||||
if (prop === '__getRaw') return () => target;
|
if (prop === '__getRaw') return () => target;
|
||||||
if (prop === '__getMeta') return () => meta;
|
if (prop === '__getMeta') return () => meta;
|
||||||
return meta.hasOwnProperty(prop) ? meta[prop] : obj[prop];
|
return Object.prototype.hasOwnProperty.call(meta, prop) ? meta[prop] : obj[prop];
|
||||||
// return obj[prop];
|
// return obj[prop];
|
||||||
},
|
},
|
||||||
has: (obj, prop) => obj.hasOwnProperty(prop) || meta.hasOwnProperty(prop),
|
has: (obj, prop) => {
|
||||||
|
return (
|
||||||
|
Object.prototype.hasOwnProperty.call(obj, prop) ||
|
||||||
|
Object.prototype.hasOwnProperty.call(meta, prop)
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { isEmpty } from 'lodash';
|
|||||||
import parsePropTypes from 'parse-prop-types';
|
import parsePropTypes from 'parse-prop-types';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { transformItem } from '../transform';
|
import { transformItem } from '../transform';
|
||||||
import { IParseArgs } from '../index';
|
|
||||||
import requireInSandbox from './requireInSandbox';
|
import requireInSandbox from './requireInSandbox';
|
||||||
|
|
||||||
export interface IComponentInfo {
|
export interface IComponentInfo {
|
||||||
@ -29,7 +28,7 @@ const reservedKeys = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function getKeys(com: any) {
|
function getKeys(com: any) {
|
||||||
const keys = Object.keys(com).filter((x) => {
|
const keys = Object.keys(com).filter(x => {
|
||||||
return !reservedKeys.includes(x) && !x.startsWith('_');
|
return !reservedKeys.includes(x) && !x.startsWith('_');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -37,7 +36,11 @@ function getKeys(com: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isComponent(obj: any) {
|
function isComponent(obj: any) {
|
||||||
return typeof obj === 'function' && (obj.hasOwnProperty('propTypes') || obj.hasOwnProperty('defaultProps'));
|
return (
|
||||||
|
typeof obj === 'function' &&
|
||||||
|
(Object.prototype.hasOwnProperty.call(obj, 'propTypes') ||
|
||||||
|
Object.prototype.hasOwnProperty.call(obj, 'defaultProps'))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (filePath: string) {
|
export default function (filePath: string) {
|
||||||
@ -50,7 +53,7 @@ export default function (filePath: string) {
|
|||||||
|
|
||||||
if (Com.__esModule) {
|
if (Com.__esModule) {
|
||||||
const keys = getKeys(Com);
|
const keys = getKeys(Com);
|
||||||
keys.forEach((k) => {
|
keys.forEach(k => {
|
||||||
if (isComponent(Com[k])) {
|
if (isComponent(Com[k])) {
|
||||||
components.push({
|
components.push({
|
||||||
component: Com[k],
|
component: Com[k],
|
||||||
@ -75,8 +78,8 @@ export default function (filePath: string) {
|
|||||||
|
|
||||||
const keys = getKeys(item.component);
|
const keys = getKeys(item.component);
|
||||||
const subs = keys
|
const subs = keys
|
||||||
.filter((k) => isComponent(item.component[k]))
|
.filter(k => isComponent(item.component[k]))
|
||||||
.map((k) => ({
|
.map(k => ({
|
||||||
component: item.component[k],
|
component: item.component[k],
|
||||||
meta: {
|
meta: {
|
||||||
...item.meta,
|
...item.meta,
|
||||||
@ -91,14 +94,14 @@ export default function (filePath: string) {
|
|||||||
const result = components.reduce((acc: any, { meta, component }) => {
|
const result = components.reduce((acc: any, { meta, component }) => {
|
||||||
const componentInfo = parsePropTypes(component);
|
const componentInfo = parsePropTypes(component);
|
||||||
if (!isEmpty(componentInfo)) {
|
if (!isEmpty(componentInfo)) {
|
||||||
const props = Object.keys(componentInfo).reduce((acc: any[], name) => {
|
const props = Object.keys(componentInfo).reduce((acc2: any[], name) => {
|
||||||
try {
|
try {
|
||||||
const item: any = transformItem(name, componentInfo[name]);
|
const item: any = transformItem(name, componentInfo[name]);
|
||||||
acc.push(item);
|
acc2.push(item);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
// TODO
|
||||||
return acc;
|
|
||||||
}
|
}
|
||||||
|
return acc2;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import { omit, pick } from 'lodash';
|
import { omit, pick, isNil } from 'lodash';
|
||||||
|
import { safeEval, isEvaluable } from '../utils';
|
||||||
|
import { debug } from '../core';
|
||||||
|
|
||||||
|
const log = debug.extend('parse:transform');
|
||||||
|
|
||||||
export function transformType(itemType: any) {
|
export function transformType(itemType: any) {
|
||||||
if (typeof itemType === 'string') return itemType;
|
if (typeof itemType === 'string') return itemType;
|
||||||
@ -7,7 +11,7 @@ export function transformType(itemType: any) {
|
|||||||
// return name;
|
// return name;
|
||||||
// }
|
// }
|
||||||
if (computed !== undefined && value) {
|
if (computed !== undefined && value) {
|
||||||
return eval(value);
|
return safeEval(value);
|
||||||
}
|
}
|
||||||
const result: any = {
|
const result: any = {
|
||||||
type: name,
|
type: name,
|
||||||
@ -24,16 +28,31 @@ export function transformType(itemType: any) {
|
|||||||
case 'symbol':
|
case 'symbol':
|
||||||
case 'object':
|
case 'object':
|
||||||
case 'null':
|
case 'null':
|
||||||
|
case 'array':
|
||||||
|
case 'element':
|
||||||
|
case 'node':
|
||||||
break;
|
break;
|
||||||
case 'literal':
|
case 'literal':
|
||||||
return eval(value);
|
return safeEval(value);
|
||||||
case 'enum':
|
case 'enum':
|
||||||
case 'tuple':
|
case 'tuple':
|
||||||
case 'oneOf':
|
case 'oneOf':
|
||||||
result.type = 'oneOf';
|
result.type = 'oneOf';
|
||||||
result.value = value.map(transformType);
|
result.value = value.map(transformType);
|
||||||
break;
|
break;
|
||||||
case 'union':
|
case 'union': {
|
||||||
|
const { raw } = itemType;
|
||||||
|
if (raw) {
|
||||||
|
if (raw.match(/ReactNode$/)) {
|
||||||
|
result.type = 'node';
|
||||||
|
break;
|
||||||
|
} else if (raw.match(/Element$/)) {
|
||||||
|
result.type = 'element';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line no-fallthrough
|
||||||
case 'oneOfType':
|
case 'oneOfType':
|
||||||
result.type = 'oneOfType';
|
result.type = 'oneOfType';
|
||||||
result.value = value.map(transformType);
|
result.value = value.map(transformType);
|
||||||
@ -77,12 +96,9 @@ export function transformType(itemType: any) {
|
|||||||
result.value = properties
|
result.value = properties
|
||||||
.filter((item: any) => typeof item.key !== 'object')
|
.filter((item: any) => typeof item.key !== 'object')
|
||||||
.map((prop: any) => {
|
.map((prop: any) => {
|
||||||
const {
|
const { key } = prop;
|
||||||
key,
|
|
||||||
value: { name, ...others },
|
|
||||||
} = prop;
|
|
||||||
return transformItem(key, {
|
return transformItem(key, {
|
||||||
...others,
|
...omit(prop.value, 'name'),
|
||||||
type: pick(prop.value, ['name', 'value']),
|
type: pick(prop.value, ['name', 'value']),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -90,7 +106,6 @@ export function transformType(itemType: any) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'objectOf':
|
case 'objectOf':
|
||||||
case 'arrayOf':
|
|
||||||
case 'instanceOf':
|
case 'instanceOf':
|
||||||
result.value = transformType(value);
|
result.value = transformType(value);
|
||||||
break;
|
break;
|
||||||
@ -107,18 +122,19 @@ export function transformType(itemType: any) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case (name.match('ReactNode$') || {}).input:
|
case (name.match(/ReactNode$/) || {}).input:
|
||||||
result.type = 'node';
|
result.type = 'node';
|
||||||
break;
|
break;
|
||||||
case (name.match('Element$') || {}).input:
|
case (name.match(/Element$/) || {}).input:
|
||||||
result.type = 'element';
|
result.type = 'element';
|
||||||
break;
|
break;
|
||||||
case (name.match('ElementType$') || {}).input:
|
// case (name.match(/ElementType$/) || {}).input:
|
||||||
result.type = 'elementType';
|
// result.type = 'elementType';
|
||||||
break;
|
// break;
|
||||||
default:
|
default:
|
||||||
result.type = 'instanceOf';
|
// result.type = 'instanceOf';
|
||||||
result.value = name;
|
// result.value = name;
|
||||||
|
result.type = 'any';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Object.keys(result).length === 1) {
|
if (Object.keys(result).length === 1) {
|
||||||
@ -128,7 +144,15 @@ export function transformType(itemType: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function transformItem(name: string, item: any) {
|
export function transformItem(name: string, item: any) {
|
||||||
const { description, flowType, tsType, type = tsType || flowType, required, defaultValue, ...others } = item;
|
const {
|
||||||
|
description,
|
||||||
|
flowType,
|
||||||
|
tsType,
|
||||||
|
type = tsType || flowType,
|
||||||
|
required,
|
||||||
|
defaultValue,
|
||||||
|
...others
|
||||||
|
} = item;
|
||||||
const result: any = {
|
const result: any = {
|
||||||
name,
|
name,
|
||||||
};
|
};
|
||||||
@ -147,11 +171,19 @@ export function transformItem(name: string, item: any) {
|
|||||||
result.description = description;
|
result.description = description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (defaultValue !== undefined) {
|
if (!isNil(defaultValue) && typeof defaultValue === 'object' && isEvaluable(defaultValue)) {
|
||||||
|
if (defaultValue === null) {
|
||||||
|
result.defaultValue = defaultValue;
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
const value = eval(defaultValue.value);
|
const value = safeEval(defaultValue.value);
|
||||||
|
if (isEvaluable(value)) {
|
||||||
result.defaultValue = value;
|
result.defaultValue = value;
|
||||||
} catch (e) {}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result.propType === undefined) {
|
if (result.propType === undefined) {
|
||||||
delete result.propType;
|
delete result.propType;
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
import { Parser, ComponentDoc } from 'react-docgen-typescript';
|
import { Parser, ComponentDoc } from 'react-docgen-typescript';
|
||||||
import ts, { SymbolFlags, TypeFlags } from 'typescript';
|
import ts, { SymbolFlags, TypeFlags } from 'typescript';
|
||||||
import { isEmpty, isEqual } from 'lodash';
|
import { isEmpty, isEqual } from 'lodash';
|
||||||
|
import { debug } from '../../core';
|
||||||
|
import { Json } from '../../types';
|
||||||
import { transformItem } from '../transform';
|
import { transformItem } from '../transform';
|
||||||
|
|
||||||
|
const log = debug.extend('parse:ts');
|
||||||
|
|
||||||
|
type ExtendedType = ts.Type & {
|
||||||
|
id: string;
|
||||||
|
typeArguments: any[];
|
||||||
|
};
|
||||||
|
|
||||||
function getSymbolName(symbol: ts.Symbol) {
|
function getSymbolName(symbol: ts.Symbol) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const prefix: string = symbol.parent && getSymbolName(symbol.parent);
|
const prefix: string = symbol.parent && getSymbolName(symbol.parent);
|
||||||
@ -32,13 +41,10 @@ function getDocgenTypeHelper(
|
|||||||
parentIds: number[] = [],
|
parentIds: number[] = [],
|
||||||
isRequired = false,
|
isRequired = false,
|
||||||
): any {
|
): any {
|
||||||
function isTuple(type: ts.Type) {
|
function isTuple(_type: ts.Type) {
|
||||||
// @ts-ignore use internal methods
|
// @ts-ignore use internal methods
|
||||||
return checker.isArrayLikeType(type) && !checker.isArrayType(type);
|
return checker.isArrayLikeType(_type) && !checker.isArrayType(_type);
|
||||||
}
|
}
|
||||||
// if (type.aliasSymbol && type.aliasSymbol.getName() === 'ReactNode') {
|
|
||||||
// return 'children';
|
|
||||||
// }
|
|
||||||
let required: boolean;
|
let required: boolean;
|
||||||
if (isRequired !== undefined) {
|
if (isRequired !== undefined) {
|
||||||
required = isRequired;
|
required = isRequired;
|
||||||
@ -46,7 +52,7 @@ function getDocgenTypeHelper(
|
|||||||
required = !(type.flags & SymbolFlags.Optional) || isRequired;
|
required = !(type.flags & SymbolFlags.Optional) || isRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeResult(typeInfo: object) {
|
function makeResult(typeInfo: Json) {
|
||||||
if (skipRequired) {
|
if (skipRequired) {
|
||||||
return {
|
return {
|
||||||
raw: checker.typeToString(type),
|
raw: checker.typeToString(type),
|
||||||
@ -61,7 +67,7 @@ function getDocgenTypeHelper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getShapeFromArray(symbolArr: ts.Symbol[], type: ts.Type) {
|
function getShapeFromArray(symbolArr: ts.Symbol[], _type: ts.Type) {
|
||||||
const shape: Array<{
|
const shape: Array<{
|
||||||
key:
|
key:
|
||||||
| {
|
| {
|
||||||
@ -69,7 +75,7 @@ function getDocgenTypeHelper(
|
|||||||
}
|
}
|
||||||
| string;
|
| string;
|
||||||
value: any;
|
value: any;
|
||||||
}> = symbolArr.map((prop) => {
|
}> = symbolArr.map(prop => {
|
||||||
const propType = checker.getTypeOfSymbolAtLocation(
|
const propType = checker.getTypeOfSymbolAtLocation(
|
||||||
prop,
|
prop,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -83,19 +89,19 @@ function getDocgenTypeHelper(
|
|||||||
propType,
|
propType,
|
||||||
false,
|
false,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
[...parentIds, type.id],
|
[...parentIds, _type.id],
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
prop?.valueDeclaration?.questionToken ? false : undefined,
|
prop?.valueDeclaration?.questionToken ? false : undefined,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
// @ts-ignore use internal methods
|
// @ts-ignore use internal methods
|
||||||
if (checker.isArrayLikeType(type)) {
|
if (checker.isArrayLikeType(_type)) {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
if (type.getStringIndexType()) {
|
if (_type.getStringIndexType()) {
|
||||||
// @ts-ignore use internal methods
|
// @ts-ignore use internal methods
|
||||||
if (!type.stringIndexInfo) {
|
if (!_type.stringIndexInfo) {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
shape.push({
|
shape.push({
|
||||||
@ -103,11 +109,14 @@ function getDocgenTypeHelper(
|
|||||||
name: 'string',
|
name: 'string',
|
||||||
},
|
},
|
||||||
// @ts-ignore use internal methods
|
// @ts-ignore use internal methods
|
||||||
value: getDocgenTypeHelper(checker, type.stringIndexInfo.type, false, [...parentIds, type.id]),
|
value: getDocgenTypeHelper(checker, _type.stringIndexInfo.type, false, [
|
||||||
|
...parentIds,
|
||||||
|
(_type as ExtendedType).id,
|
||||||
|
]),
|
||||||
});
|
});
|
||||||
} else if (type.getNumberIndexType()) {
|
} else if (_type.getNumberIndexType()) {
|
||||||
// @ts-ignore use internal methods
|
// @ts-ignore use internal methods
|
||||||
if (!type.numberIndexInfo) {
|
if (!_type.numberIndexInfo) {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
shape.push({
|
shape.push({
|
||||||
@ -116,32 +125,34 @@ function getDocgenTypeHelper(
|
|||||||
},
|
},
|
||||||
|
|
||||||
// @ts-ignore use internal methods
|
// @ts-ignore use internal methods
|
||||||
value: getDocgenTypeHelper(checker, type.numberIndexInfo.type, false, [...parentIds, type.id]),
|
value: getDocgenTypeHelper(checker, _type.numberIndexInfo.type, false, [
|
||||||
|
...parentIds,
|
||||||
|
(_type as ExtendedType).id,
|
||||||
|
]),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getShape(type: ts.Type) {
|
function getShape(_type: ts.Type) {
|
||||||
const { symbol } = type;
|
const { symbol } = _type;
|
||||||
if (symbol && symbol.members) {
|
if (symbol && symbol.members) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const props: ts.Symbol[] = Array.from(symbol.members.values());
|
const props: ts.Symbol[] = Array.from(symbol.members.values());
|
||||||
return getShapeFromArray(
|
return getShapeFromArray(
|
||||||
props.filter((prop) => prop.getName() !== '__index'),
|
props.filter(prop => prop.getName() !== '__index'),
|
||||||
type,
|
_type,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const args = type.resolvedTypeArguments || [];
|
const args = _type.resolvedTypeArguments || [];
|
||||||
const props = checker.getPropertiesOfType(type);
|
const props = checker.getPropertiesOfType(_type);
|
||||||
const shape = getShapeFromArray(props.slice(0, args.length), type);
|
const shape = getShapeFromArray(props.slice(0, args.length), _type);
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pattern = /^__global\.(.+)$/;
|
const pattern = /^__global\.(.+)$/;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (parentIds.includes(type.id)) {
|
if (parentIds.includes(type.id)) {
|
||||||
return makeResult({
|
return makeResult({
|
||||||
@ -191,21 +202,26 @@ function getDocgenTypeHelper(
|
|||||||
return makeResult({
|
return makeResult({
|
||||||
name: 'union',
|
name: 'union',
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
value: type.types.map((t) => getDocgenTypeHelper(checker, t, true, [...parentIds, type.id])),
|
value: type.types.map(t => getDocgenTypeHelper(checker, t, true, [...parentIds, type.id])),
|
||||||
});
|
});
|
||||||
} else if (type.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
|
} else if (type.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
|
||||||
if (isTuple(type)) {
|
if (isTuple(type)) {
|
||||||
const props = getShape(type);
|
const props = getShape(type);
|
||||||
return makeResult({
|
return makeResult({
|
||||||
name: 'union',
|
name: 'union',
|
||||||
value: props.map((p) => p.value),
|
value: props.map(p => p.value),
|
||||||
});
|
});
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} else if (checker.isArrayType(type)) {
|
} else if (checker.isArrayType(type)) {
|
||||||
return makeResult({
|
return makeResult({
|
||||||
name: 'Array',
|
name: 'Array',
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
elements: [getDocgenTypeHelper(checker, type.typeArguments[0], false, [...parentIds, type.id])],
|
elements: [
|
||||||
|
getDocgenTypeHelper(checker, (type as ExtendedType).typeArguments[0], false, [
|
||||||
|
...parentIds,
|
||||||
|
(type as any).id,
|
||||||
|
]),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
} else if (type.aliasSymbol) {
|
} else if (type.aliasSymbol) {
|
||||||
return makeResult({
|
return makeResult({
|
||||||
@ -254,7 +270,10 @@ interface SymbolWithMeta extends ts.Symbol {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function parseTS(filePathOrPaths: string | string[], parserOpts: any = {}): ComponentDoc[] {
|
export default function parseTS(
|
||||||
|
filePathOrPaths: string | string[],
|
||||||
|
parserOpts: any = {},
|
||||||
|
): ComponentDoc[] {
|
||||||
const filePaths = Array.isArray(filePathOrPaths) ? filePathOrPaths : [filePathOrPaths];
|
const filePaths = Array.isArray(filePathOrPaths) ? filePathOrPaths : [filePathOrPaths];
|
||||||
|
|
||||||
const program = ts.createProgram(filePaths, compilerOptions);
|
const program = ts.createProgram(filePaths, compilerOptions);
|
||||||
@ -264,8 +283,8 @@ export default function parseTS(filePathOrPaths: string | string[], parserOpts:
|
|||||||
const checker = program.getTypeChecker();
|
const checker = program.getTypeChecker();
|
||||||
|
|
||||||
const result = filePaths
|
const result = filePaths
|
||||||
.map((filePath) => program.getSourceFile(filePath))
|
.map(filePath => program.getSourceFile(filePath))
|
||||||
.filter((sourceFile) => typeof sourceFile !== 'undefined')
|
.filter(sourceFile => typeof sourceFile !== 'undefined')
|
||||||
.reduce((docs: any[], sourceFile) => {
|
.reduce((docs: any[], sourceFile) => {
|
||||||
const moduleSymbol = checker.getSymbolAtLocation(sourceFile as ts.Node);
|
const moduleSymbol = checker.getSymbolAtLocation(sourceFile as ts.Node);
|
||||||
|
|
||||||
@ -291,7 +310,7 @@ export default function parseTS(filePathOrPaths: string | string[], parserOpts:
|
|||||||
subName: exportName ? name : '',
|
subName: exportName ? name : '',
|
||||||
exportName: exportName || name,
|
exportName: exportName || name,
|
||||||
};
|
};
|
||||||
if (docs.find((x) => isEqual(x.meta, meta))) {
|
if (docs.find(x => isEqual(x.meta, meta))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
docs.push({
|
docs.push({
|
||||||
@ -303,7 +322,10 @@ export default function parseTS(filePathOrPaths: string | string[], parserOpts:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const type = checker.getTypeOfSymbolAtLocation(sym, sym.valueDeclaration || sym.declarations[0]);
|
const type = checker.getTypeOfSymbolAtLocation(
|
||||||
|
sym,
|
||||||
|
sym.valueDeclaration || sym.declarations[0],
|
||||||
|
);
|
||||||
|
|
||||||
Array.prototype.push.apply(
|
Array.prototype.push.apply(
|
||||||
exportSymbols,
|
exportSymbols,
|
||||||
@ -323,10 +345,9 @@ export default function parseTS(filePathOrPaths: string | string[], parserOpts:
|
|||||||
const item: any = transformItem(name, info.props[name]);
|
const item: any = transformItem(name, info.props[name]);
|
||||||
acc.push(item);
|
acc.push(item);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('error', e);
|
log(e);
|
||||||
} finally {
|
|
||||||
return acc;
|
|
||||||
}
|
}
|
||||||
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
res.push({
|
res.push({
|
||||||
componentName: info?.meta?.exportName || info.displayName,
|
componentName: info?.meta?.exportName || info.displayName,
|
||||||
|
|||||||
4
packages/material-parser/src/types/Basic.ts
Normal file
4
packages/material-parser/src/types/Basic.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface Json {
|
||||||
|
[x: string]: string | number | boolean | Date | Json | JsonArray;
|
||||||
|
}
|
||||||
|
export type JsonArray = Array<string | number | boolean | Date | Json | JsonArray>;
|
||||||
@ -1,11 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* 物料接入渠道
|
* 物料接入渠道
|
||||||
*/
|
*/
|
||||||
enum ChannelType {
|
export enum ChannelType {
|
||||||
/** 本地 */
|
/** 本地 */
|
||||||
LOCAL = 'local',
|
LOCAL = 'local',
|
||||||
/** 在线 */
|
/** 在线 */
|
||||||
ONLINE = 'online',
|
ONLINE = 'online',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ChannelType;
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* 语法生态
|
* 语法生态
|
||||||
*/
|
*/
|
||||||
enum EcologyType {
|
export enum EcologyType {
|
||||||
/** react 生态 */
|
/** react 生态 */
|
||||||
REACT = 'react',
|
REACT = 'react',
|
||||||
/** vue 生态 */
|
/** vue 生态 */
|
||||||
@ -11,5 +11,3 @@ enum EcologyType {
|
|||||||
/** angular 生态 */
|
/** angular 生态 */
|
||||||
ANGULAR = 'angular',
|
ANGULAR = 'angular',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default EcologyType;
|
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* 扩展点名称
|
|
||||||
*/
|
|
||||||
enum ExtensionName {
|
|
||||||
/** 配置 manifest */
|
|
||||||
CONFIGMANIFEST = 'mat:config:manifest',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ExtensionName;
|
|
||||||
@ -4,7 +4,7 @@ import { ComponentMeta } from '../core';
|
|||||||
* 接入器接口(用于定义物料化组件的接入渠道)
|
* 接入器接口(用于定义物料化组件的接入渠道)
|
||||||
* @interface IAccesser
|
* @interface IAccesser
|
||||||
*/
|
*/
|
||||||
interface IAccesser {
|
export interface IAccesser {
|
||||||
/**
|
/**
|
||||||
* 接入
|
* 接入
|
||||||
* @returns {Promise<IMaterialinSchema>}
|
* @returns {Promise<IMaterialinSchema>}
|
||||||
@ -12,5 +12,3 @@ interface IAccesser {
|
|||||||
*/
|
*/
|
||||||
access(): Promise<ComponentMeta[]>;
|
access(): Promise<ComponentMeta[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default IAccesser;
|
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
/**
|
|
||||||
* 编译器 - 用于编译并打包生成 bundle.js
|
|
||||||
* @interface ICompiler
|
|
||||||
*/
|
|
||||||
interface ICompiler {
|
|
||||||
/**
|
|
||||||
* 编译
|
|
||||||
* @param {{ [key: string]: any }} config webpack 配置文件
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
* @memberof ICompiler
|
|
||||||
*/
|
|
||||||
compile(config: { [key: string]: any }): Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ICompiler;
|
|
||||||
@ -3,7 +3,7 @@ import { ComponentMeta } from '../core';
|
|||||||
* 扩展点:配置 manifest
|
* 扩展点:配置 manifest
|
||||||
* (物料化场景)
|
* (物料化场景)
|
||||||
*/
|
*/
|
||||||
type IExtensionConfigManifest = (params: {
|
export type IExtensionConfigManifest = (params: {
|
||||||
manifestObj: ComponentMeta; // manifest 配置对象
|
manifestObj: ComponentMeta; // manifest 配置对象
|
||||||
manifestFilePath: string; // manifest 文件默认路径
|
manifestFilePath: string; // manifest 文件默认路径
|
||||||
}) => Promise<{
|
}) => Promise<{
|
||||||
@ -11,5 +11,3 @@ type IExtensionConfigManifest = (params: {
|
|||||||
manifestFilePath: string; // manifest 文件路径
|
manifestFilePath: string; // manifest 文件路径
|
||||||
manifestObj: ComponentMeta; // manifest 文件对象
|
manifestObj: ComponentMeta; // manifest 文件对象
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export default IExtensionConfigManifest;
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* 对应扫描阶段的产物
|
* 对应扫描阶段的产物
|
||||||
*/
|
*/
|
||||||
interface IMaterialScanModel {
|
export interface IMaterialScanModel {
|
||||||
/** 当前包名 */
|
/** 当前包名 */
|
||||||
pkgName: string;
|
pkgName: string;
|
||||||
/** 当前包版本 */
|
/** 当前包版本 */
|
||||||
@ -19,5 +19,3 @@ interface IMaterialScanModel {
|
|||||||
/** typings文件绝对路径 */
|
/** typings文件绝对路径 */
|
||||||
typingsFileAbsolutePath?: string;
|
typingsFileAbsolutePath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default IMaterialScanModel;
|
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
import ExtensionName from './ExtensionName';
|
|
||||||
import IExtensionConfigManifest from './IExtensionConfigManifest';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 物料化配置项
|
* 物料化配置项
|
||||||
* @interface IMaterializeOptions
|
* @interface IMaterializeOptions
|
||||||
*/
|
*/
|
||||||
interface IMaterializeOptions {
|
export interface IMaterializeOptions {
|
||||||
/**
|
/**
|
||||||
* 组件文件(夹)路径或包名
|
* 组件文件(夹)路径或包名
|
||||||
* 形如:
|
* 形如:
|
||||||
@ -35,5 +32,3 @@ interface IMaterializeOptions {
|
|||||||
*/
|
*/
|
||||||
npmClient?: string;
|
npmClient?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default IMaterializeOptions;
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { NodePath, Path } from 'ast-types';
|
import { Path } from 'ast-types';
|
||||||
|
|
||||||
export interface IFileMeta {
|
export interface IFileMeta {
|
||||||
src: string;
|
src: string;
|
||||||
|
|||||||
@ -1,21 +1,8 @@
|
|||||||
import ChannelType from './ChannelType';
|
export * from './ChannelType';
|
||||||
import EcologyType from './EcologyType';
|
export * from './EcologyType';
|
||||||
import ExtensionName from './ExtensionName';
|
export * from './IAccesser';
|
||||||
import IAccesser from './IAccesser';
|
export * from './IExtensionConfigManifest';
|
||||||
import ICompiler from './ICompiler';
|
export * from './IMaterializeOptions';
|
||||||
import IExtensionConfigManifest from './IExtensionConfigManifest';
|
export * from './IMaterialScanModel';
|
||||||
import IMaterializeOptions from './IMaterializeOptions';
|
export * from './IMaterialParsedModel';
|
||||||
import IMaterialScanModel from './IMaterialScanModel';
|
export * from './Basic';
|
||||||
import { IMaterialParsedModel } from './IMaterialParsedModel';
|
|
||||||
|
|
||||||
export {
|
|
||||||
ExtensionName,
|
|
||||||
IExtensionConfigManifest,
|
|
||||||
IMaterialParsedModel,
|
|
||||||
IMaterializeOptions,
|
|
||||||
IMaterialScanModel,
|
|
||||||
ChannelType,
|
|
||||||
EcologyType,
|
|
||||||
IAccesser,
|
|
||||||
ICompiler,
|
|
||||||
};
|
|
||||||
|
|||||||
@ -1,27 +1,42 @@
|
|||||||
import { pathExists, readFileSync, writeFile } from 'fs-extra';
|
import { pathExists, readFileSync, writeFile } from 'fs-extra';
|
||||||
|
import { isPlainObject } from 'lodash';
|
||||||
|
import safeEval from 'safe-eval';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import spawn from 'cross-spawn-promise';
|
import spawn from 'cross-spawn-promise';
|
||||||
|
|
||||||
export async function isNPMInstalled(args: { workDir: string; moduleDir: string; npmClient?: string }) {
|
export async function isNPMInstalled(args: {
|
||||||
return await pathExists(path.join(args.workDir, 'node_modules'));
|
workDir: string;
|
||||||
|
moduleDir: string;
|
||||||
|
npmClient?: string;
|
||||||
|
}) {
|
||||||
|
return pathExists(path.join(args.workDir, 'node_modules'));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function install(args: { workDir: string; moduleDir: string; npmClient?: string }) {
|
export async function install(args: { workDir: string; moduleDir: string; npmClient?: string }) {
|
||||||
if (await isNPMInstalled(args)) return;
|
if (await isNPMInstalled(args)) return;
|
||||||
const { workDir, moduleDir, npmClient = 'tnpm' } = args;
|
const { workDir, npmClient = 'tnpm' } = args;
|
||||||
try {
|
try {
|
||||||
await spawn(npmClient, ['i'], { stdio: 'inherit', cwd: workDir } as any);
|
await spawn(npmClient, ['i'], { stdio: 'inherit', cwd: workDir } as any);
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installTypeScript(args: { workDir: string; moduleDir: string; npmClient?: string }) {
|
export async function installTypeScript(args: {
|
||||||
|
workDir: string;
|
||||||
|
moduleDir: string;
|
||||||
|
npmClient?: string;
|
||||||
|
}) {
|
||||||
if (await isNPMInstalled(args)) return;
|
if (await isNPMInstalled(args)) return;
|
||||||
const { workDir, moduleDir, npmClient = 'tnpm' } = args;
|
const { workDir, npmClient = 'tnpm' } = args;
|
||||||
await spawn(npmClient, ['i', 'typescript'], { stdio: 'inherit', cwd: workDir } as any);
|
await spawn(npmClient, ['i', 'typescript'], { stdio: 'inherit', cwd: workDir } as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installPeerDeps(args: { workDir: string; moduleDir: string; npmClient?: string }) {
|
export async function installPeerDeps(args: {
|
||||||
|
workDir: string;
|
||||||
|
moduleDir: string;
|
||||||
|
npmClient?: string;
|
||||||
|
}) {
|
||||||
const { workDir, moduleDir, npmClient = 'tnpm' } = args;
|
const { workDir, moduleDir, npmClient = 'tnpm' } = args;
|
||||||
const modulePkgJsonPath = path.resolve(moduleDir, 'package.json');
|
const modulePkgJsonPath = path.resolve(moduleDir, 'package.json');
|
||||||
if (!(await pathExists(modulePkgJsonPath))) {
|
if (!(await pathExists(modulePkgJsonPath))) {
|
||||||
@ -43,7 +58,11 @@ export async function installPeerDeps(args: { workDir: string; moduleDir: string
|
|||||||
await spawn(npmClient, ['i'], { stdio: 'inherit', cwd: workDir } as any);
|
await spawn(npmClient, ['i'], { stdio: 'inherit', cwd: workDir } as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installTypeModules(args: { workDir: string; moduleDir: string; npmClient?: string }) {
|
export async function installTypeModules(args: {
|
||||||
|
workDir: string;
|
||||||
|
moduleDir: string;
|
||||||
|
npmClient?: string;
|
||||||
|
}) {
|
||||||
const { workDir, moduleDir, npmClient = 'tnpm' } = args;
|
const { workDir, moduleDir, npmClient = 'tnpm' } = args;
|
||||||
const pkgJsonPath = path.resolve(moduleDir, 'package.json');
|
const pkgJsonPath = path.resolve(moduleDir, 'package.json');
|
||||||
if (!(await pathExists(pkgJsonPath))) {
|
if (!(await pathExists(pkgJsonPath))) {
|
||||||
@ -65,3 +84,19 @@ export function loadFile(filePath: string): string {
|
|||||||
}
|
}
|
||||||
return content.toString();
|
return content.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPrimitive(val) {
|
||||||
|
return !['object', 'function'].includes(typeof val) || val === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isEvaluable(value) {
|
||||||
|
if (isPrimitive(value)) return true;
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.every(isEvaluable);
|
||||||
|
} else if (isPlainObject(value)) {
|
||||||
|
return Object.keys(value).every(key => isEvaluable(value[key]));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { safeEval };
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import Ajv from 'ajv';
|
import Ajv from 'ajv';
|
||||||
|
import { Json } from '../types/Basic';
|
||||||
import schema from './schema.json';
|
import schema from './schema.json';
|
||||||
|
|
||||||
const ajv = new Ajv({ jsonPointers: true });
|
const ajv = new Ajv({ jsonPointers: true });
|
||||||
const validate = ajv.compile(schema);
|
const validate = ajv.compile(schema);
|
||||||
|
|
||||||
export default function validateSchema(json: object) {
|
export default function validateSchema(json: Json) {
|
||||||
if (validate(json) === false) {
|
if (validate(json) === false) {
|
||||||
throw new Error(JSON.stringify(validate.errors, null, 2));
|
throw new Error(JSON.stringify(validate.errors, null, 2));
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -11,6 +11,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
componentName: 'AIMakeBlank',
|
componentName: 'AIMakeBlank',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -63,6 +64,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'AIMakeIcon',
|
componentName: 'AIMakeIcon',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -112,6 +114,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'AIMakeImage',
|
componentName: 'AIMakeImage',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -139,6 +142,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'AIMakeLink',
|
componentName: 'AIMakeLink',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -187,6 +191,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'AIMakePlaceholder',
|
componentName: 'AIMakePlaceholder',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -221,6 +226,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'AIMakeText',
|
componentName: 'AIMakeText',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -273,6 +279,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'Root',
|
componentName: 'Root',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -300,6 +307,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
componentName: 'Demo',
|
componentName: 'Demo',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: false,
|
destructuring: false,
|
||||||
@ -312,10 +320,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
props: [
|
props: [
|
||||||
{
|
{
|
||||||
name: 'optionalArray',
|
name: 'optionalArray',
|
||||||
propType: {
|
propType: 'array',
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'array',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'optionalBool',
|
name: 'optionalBool',
|
||||||
@ -344,24 +349,15 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'optionalNode',
|
name: 'optionalNode',
|
||||||
propType: {
|
propType: 'node',
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'node',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'optionalElement',
|
name: 'optionalElement',
|
||||||
propType: {
|
propType: 'element',
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'element',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'optionalElementType',
|
name: 'optionalElementType',
|
||||||
propType: {
|
propType: 'any',
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'elementType',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'optionalMessage',
|
name: 'optionalMessage',
|
||||||
@ -486,6 +482,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
componentName: 'default',
|
componentName: 'default',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: false,
|
destructuring: false,
|
||||||
@ -498,77 +495,15 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
props: [
|
props: [
|
||||||
{
|
{
|
||||||
name: 'node',
|
name: 'node',
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'string',
|
|
||||||
'number',
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
'object',
|
|
||||||
{
|
|
||||||
type: 'shape',
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
name: 'P',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'T',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'type',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'props',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'key',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'string',
|
|
||||||
'number',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'shape',
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
name: 'key',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'string',
|
|
||||||
'number',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'children',
|
|
||||||
propType: 'node',
|
propType: 'node',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
screenshot: '',
|
screenshot: '',
|
||||||
title: 'ts-component',
|
title: 'ts-component',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'default',
|
componentName: 'default',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: false,
|
destructuring: false,
|
||||||
|
|||||||
Binary file not shown.
@ -4,199 +4,54 @@ The actual snapshot is saved in `online.ts.snap`.
|
|||||||
|
|
||||||
Generated by [AVA](https://avajs.dev).
|
Generated by [AVA](https://avajs.dev).
|
||||||
|
|
||||||
## materialize custom breadcrumb by online
|
## materialize mc-hello by online
|
||||||
|
|
||||||
> Snapshot 1
|
> Snapshot 1
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
componentName: 'default',
|
componentName: 'default',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: false,
|
destructuring: false,
|
||||||
exportName: 'default',
|
exportName: 'default',
|
||||||
main: 'lib/index.js',
|
main: 'lib/index.js',
|
||||||
package: 'mc-breadcrumb',
|
package: 'mc-hello',
|
||||||
subName: '',
|
subName: '',
|
||||||
version: '1.0.1',
|
version: '1.0.1',
|
||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
{
|
{
|
||||||
name: 'prefix',
|
name: 'color',
|
||||||
propType: 'string',
|
propType: 'string',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'rtl',
|
name: 'background',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultValue: false,
|
||||||
|
name: 'round',
|
||||||
propType: 'bool',
|
propType: 'bool',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
defaultValue: 200,
|
||||||
|
name: 'width',
|
||||||
|
propType: 'number',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultValue: 40,
|
||||||
|
name: 'height',
|
||||||
|
propType: 'number',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'children',
|
name: 'children',
|
||||||
propType: {
|
propType: 'node',
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'custom',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'maxNode',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'number',
|
|
||||||
{
|
|
||||||
type: 'oneOf',
|
|
||||||
value: [
|
|
||||||
'auto',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'separator',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'node',
|
|
||||||
},
|
|
||||||
'string',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'component',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'string',
|
|
||||||
'func',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'className',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'locale',
|
|
||||||
propType: 'object',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'pure',
|
|
||||||
propType: 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'device',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOf',
|
|
||||||
value: [
|
|
||||||
'tablet',
|
|
||||||
'desktop',
|
|
||||||
'phone',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'popupContainer',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'errorBoundary',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'bool',
|
|
||||||
'object',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
screenshot: '',
|
screenshot: '',
|
||||||
title: 'mc-breadcrumb',
|
title: 'mc-hello',
|
||||||
},
|
|
||||||
{
|
|
||||||
componentName: 'Item',
|
|
||||||
docUrl: '',
|
|
||||||
npm: {
|
|
||||||
destructuring: false,
|
|
||||||
exportName: 'default',
|
|
||||||
main: 'lib/index.js',
|
|
||||||
package: 'mc-breadcrumb',
|
|
||||||
subName: 'Item',
|
|
||||||
version: '1.0.1',
|
|
||||||
},
|
|
||||||
props: [
|
|
||||||
{
|
|
||||||
name: 'prefix',
|
|
||||||
propType: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'rtl',
|
|
||||||
propType: 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'link',
|
|
||||||
propType: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'activated',
|
|
||||||
propType: 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'separator',
|
|
||||||
propType: {
|
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'node',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'className',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'children',
|
|
||||||
propType: {
|
|
||||||
type: 'instanceOf',
|
|
||||||
value: 'node',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'locale',
|
|
||||||
propType: 'object',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'pure',
|
|
||||||
propType: 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'device',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOf',
|
|
||||||
value: [
|
|
||||||
'tablet',
|
|
||||||
'desktop',
|
|
||||||
'phone',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'popupContainer',
|
|
||||||
propType: 'any',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'errorBoundary',
|
|
||||||
propType: {
|
|
||||||
type: 'oneOfType',
|
|
||||||
value: [
|
|
||||||
'bool',
|
|
||||||
'object',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
screenshot: '',
|
|
||||||
title: 'mc-breadcrumb',
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -207,6 +62,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
componentName: 'BlockPicker',
|
componentName: 'BlockPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -239,7 +95,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -249,6 +104,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'CirclePicker',
|
componentName: 'CirclePicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -281,7 +137,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
propType: 'number',
|
propType: 'number',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -291,6 +146,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'default',
|
componentName: 'default',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: false,
|
destructuring: false,
|
||||||
@ -318,7 +174,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
propType: 'bool',
|
propType: 'bool',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -339,6 +194,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'ChromePicker',
|
componentName: 'ChromePicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -366,7 +222,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
propType: 'bool',
|
propType: 'bool',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -387,6 +242,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'CompactPicker',
|
componentName: 'CompactPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -398,7 +254,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -408,6 +263,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'GithubPicker',
|
componentName: 'GithubPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -443,7 +299,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -453,6 +308,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'HuePicker',
|
componentName: 'HuePicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -464,7 +320,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -474,6 +329,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'PhotoshopPicker',
|
componentName: 'PhotoshopPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -489,7 +345,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
propType: 'string',
|
propType: 'string',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -499,6 +354,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'SketchPicker',
|
componentName: 'SketchPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -526,7 +382,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -536,6 +391,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'SliderPicker',
|
componentName: 'SliderPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -547,7 +403,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -557,6 +412,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'SwatchesPicker',
|
componentName: 'SwatchesPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -590,7 +446,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
@ -600,6 +455,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
componentName: 'TwitterPicker',
|
componentName: 'TwitterPicker',
|
||||||
|
devMode: 'proCode',
|
||||||
docUrl: '',
|
docUrl: '',
|
||||||
npm: {
|
npm: {
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -633,7 +489,6 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultValue: {},
|
|
||||||
name: 'styles',
|
name: 'styles',
|
||||||
propType: 'object',
|
propType: 'object',
|
||||||
},
|
},
|
||||||
|
|||||||
Binary file not shown.
@ -29,7 +29,6 @@ interface Props {
|
|||||||
node?: React.ReactNode;
|
node?: React.ReactNode;
|
||||||
// element?: JSX.Element;
|
// element?: JSX.Element;
|
||||||
// elementType?: React.ElementType;
|
// elementType?: React.ElementType;
|
||||||
// instance: Props;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const App = (props: Props) => {
|
const App = (props: Props) => {
|
||||||
|
|||||||
@ -39,4 +39,3 @@ test('ts component by local', async t => {
|
|||||||
|
|
||||||
t.snapshot(actual);
|
t.snapshot(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import parse from '../src';
|
|||||||
import { IMaterializeOptions } from '../src/types';
|
import { IMaterializeOptions } from '../src/types';
|
||||||
|
|
||||||
const reactColorComponent = 'react-color';
|
const reactColorComponent = 'react-color';
|
||||||
const customComponent = 'mc-breadcrumb';
|
const customComponent = 'mc-hello@1.0.1';
|
||||||
|
|
||||||
test('materialize react-color by online', async t => {
|
test('materialize react-color by online', async t => {
|
||||||
const options: IMaterializeOptions = {
|
const options: IMaterializeOptions = {
|
||||||
@ -15,7 +15,7 @@ test('materialize react-color by online', async t => {
|
|||||||
t.snapshot(actual);
|
t.snapshot(actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('materialize custom breadcrumb by online', async t => {
|
test('materialize mc-hello by online', async t => {
|
||||||
const options: IMaterializeOptions = {
|
const options: IMaterializeOptions = {
|
||||||
entry: customComponent,
|
entry: customComponent,
|
||||||
accesser: 'online',
|
accesser: 'online',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user