feat: 🎸 merge material-parser

This commit is contained in:
gengyang 2020-03-17 17:29:56 +08:00
commit b40c2869a0
312 changed files with 37154 additions and 17 deletions

View File

@ -1,2 +1,4 @@
**/test/**/*.ts **/test/**/*.ts
**/test/**/*.js **/test/**/*.js
**/template/**/*.template
**/template/**/*.tpl

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ava my-package",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/packages/material-parser/node_modules/.bin/ava",
"runtimeArgs": ["debug", "--break", "${file}"]
}
]
}

View File

@ -13,19 +13,21 @@
"commit": "git-cz" "commit": "git-cz"
}, },
"devDependencies": { "devDependencies": {
"@ice/spec": "^0.1.4",
"@types/node": "^10.12.18", "@types/node": "^10.12.18",
"ava": "^1.0.1", "ava": "^1.0.1",
"commitizen": "^3.0.5", "commitizen": "^3.0.5",
"cz-conventional-changelog": "^2.1.0", "cz-conventional-changelog": "^2.1.0",
"eslint": "^6.0.1",
"git-cz": "^4.3.1",
"husky": "^1.3.1", "husky": "^1.3.1",
"lerna": "^2.11.0", "lerna": "^2.11.0",
"lint-staged": "^8.1.0", "lint-staged": "^8.1.0",
"prettier": "^1.15.3", "prettier": "^1.15.3",
"rimraf": "^2.6.3", "rimraf": "^2.6.3",
"ts-node": "^7.0.1", "ts-node": "^7.0.1",
"tslint": "^5.12.0", "tslint": "^6.1.0",
"tslint-config-prettier": "^1.17.0", "tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.2.2" "typescript": "^3.2.2"
}, },
"engines": { "engines": {
@ -34,7 +36,7 @@
"lint-staged": { "lint-staged": {
"*.ts": [ "*.ts": [
"prettier --write", "prettier --write",
"tslint --fix -p tsconfig.json", "tslint --fix",
"git add" "git add"
] ]
}, },

9380
packages/designer/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

4097
packages/editor-framework/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

4179
packages/editor-skeleton/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

4386
packages/editor/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1 +1,4 @@
入料模块 # @ali/lowcode-engine-material-parser
> 入料模块

View File

@ -0,0 +1,57 @@
{
"name": "@ali/lowcode-engine-material-parser",
"version": "0.1.0",
"description": "material parser for Ali lowCode engine",
"main": "lib/index.js",
"files": [
"lib",
"schemas"
],
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/fs-extra": "^8.0.1",
"@types/js-yaml": "^3.12.2",
"@types/lodash": "^4.14.149",
"@types/semver": "^7.1.0",
"ajv": "^6.10.2",
"better-ajv-errors": "^0.6.4",
"globby": "^10.0.1",
"jest": "^24.8.0",
"jest-watch-typeahead": "^0.3.1",
"js-yaml": "^3.13.1",
"json-schema-to-typescript": "^8.2.0"
},
"scripts": {
"build": "tsc",
"prebuild": "npm run schema",
"test": "ava",
"test:snapshot": "ava --update-snapshots",
"schema": "node ./scripts/transform.js"
},
"ava": {
"snapshotDir": "test/fixtures/__snapshots__",
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"include": [
"test/generator/Generator.ts"
]
},
"license": "MIT",
"dependencies": {
"@babel/generator": "^7.8.4",
"@babel/parser": "^7.8.4",
"@babel/traverse": "^7.8.4",
"@babel/types": "^7.8.3",
"cross-spawn-promise": "^0.10.2",
"debug": "^4.1.1",
"fs-extra": "^8.1.0",
"lodash": "^4.17.15",
"react-docgen": "^5.3.0",
"semver": "^7.1.3",
"short-uuid": "^3.1.1"
}
}

View File

@ -0,0 +1,537 @@
{
"$id": "@ali/low-code-component-protocol-schema",
"description": "json schema for low code component protocol",
"allOf": [
{
"$ref": "#/definitions/BasicSection"
},
{
"$ref": "#/definitions/PropsSection"
},
{
"$ref": "#/definitions/ConfigureSection"
}
],
"definitions": {
"BasicSection": {
"type": "object",
"properties": {
"componentName": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"docUrl": {
"type": "string"
},
"screenshot": {
"type": "string"
},
"icon": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"devMode": {
"enum": [
"proCode",
"lowCode"
]
},
"npm": {
"$ref": "#/definitions/Npm"
}
},
"required": [
"componentName",
"title",
"npm",
"docUrl",
"screenshot"
]
},
"PropsSection": {
"type": "object",
"properties": {
"props": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
},
"description": {
"type": "string"
},
"defaultValue": {}
},
"required": [
"name",
"propType"
]
}
}
}
},
"ConfigureSection": {
"type": "object",
"properties": {
"configure": {
"type": "object",
"properties": {
"props": {
"type": "array",
"items": {
"$ref": "#/definitions/ConfigureProp"
}
},
"styles": {
"type": "object",
"properties": {}
},
"events": {
"type": "object",
"properties": {}
},
"component": {
"$ref": "#/definitions/ConfigureComponent"
}
}
}
}
},
"Npm": {
"type": "object",
"properties": {
"package": {
"type": "string"
},
"exportName": {
"type": "string"
},
"subName": {
"type": "string"
},
"main": {
"type": "string"
},
"destructuring": {
"type": "boolean"
},
"version": {
"type": "string"
}
},
"required": [
"package",
"exportName",
"subName",
"main",
"destructuring",
"version"
]
},
"PropType": {
"oneOf": [
{
"$ref": "#/definitions/BasicType"
},
{
"$ref": "#/definitions/RequiredType"
},
{
"$ref": "#/definitions/ComplexType"
}
]
},
"BasicType": {
"type": "string",
"enum": [
"array",
"bool",
"func",
"number",
"object",
"string",
"node",
"element",
"any"
]
},
"RequiredType": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/BasicType"
},
"isRequired": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": [
"type"
]
},
"ComplexType": {
"oneOf": [
{
"$ref": "#/definitions/OneOf"
},
{
"$ref": "#/definitions/OneOfType"
},
{
"$ref": "#/definitions/ArrayOf"
},
{
"$ref": "#/definitions/ObjectOf"
},
{
"$ref": "#/definitions/Shape"
},
{
"$ref": "#/definitions/Exact"
}
]
},
"OneOf": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"oneOf"
]
},
"value": {
"type": "array",
"items": {
"type": "string"
}
},
"isRequired": {
"type": "boolean"
}
}
},
"OneOfType": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"oneOfType"
]
},
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/PropType"
}
},
"isRequired": {
"type": "boolean"
}
}
},
"ArrayOf": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"arrayOf"
]
},
"value": {
"$ref": "#/definitions/PropType"
},
"isRequired": {
"type": "boolean"
}
}
},
"ObjectOf": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"objectOf"
]
},
"value": {
"$ref": "#/definitions/PropType"
},
"isRequired": {
"type": "boolean"
}
}
},
"Shape": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"shape"
]
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
}
},
"additionalProperties": false
}
},
"isRequired": {
"type": "boolean"
}
}
},
"ShapeItem": {
"type": "object",
"required": [
"name",
"propType"
],
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
},
"isRequired": {
"type": "boolean"
}
},
"additionalProperties": false
},
"Exact": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"exact"
]
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
}
},
"additionalProperties": false
}
},
"isRequired": {
"type": "boolean"
}
}
},
"ConfigureProp": {
"type": "object",
"allOf": [
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"extraProps": {
"type": "object",
"properties": {}
}
}
},
{
"oneOf": [
{
"$ref": "#/definitions/ConfigureFieldProp"
},
{
"$ref": "#/definitions/ConfigureGroupProp"
}
]
}
]
},
"ConfigureFieldProp": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"field"
]
},
"name": {
"type": "string"
},
"setter": {
"$ref": "#/definitions/ConfigureFieldSetter"
}
}
},
"ConfigureFieldSetter": {
"type": "object",
"required": [
"componentName"
],
"properties": {
"componentName": {
"type": "string",
"enum": [
"List",
"Object",
"Function",
"Node",
"Mixin",
"Expression",
"Switch",
"Number",
"Input",
"TextArea",
"Date",
"DateYear",
"DateMonth",
"DateRange",
"ColorPicker",
"CodeEditor",
"Select",
"RadioGroup"
]
},
"props": {
"type": "object",
"properties": {}
}
}
},
"ConfigureGroupProp": {
"type": "object",
"required": [
"type",
"items"
],
"properties": {
"type": {
"type": "string",
"enum": [
"group"
]
},
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/ConfigureProp"
}
}
}
},
"ConfigureComponent": {
"type": "object",
"properties": {
"isContainer": {
"type": "boolean"
},
"isModal": {
"type": "boolean"
},
"descriptor": {
"type": "string"
},
"nestingRule": {
"type": "object",
"properties": {
"childWhitelist": {
"type": "array",
"items": {
"type": "string"
}
},
"parentWhitelist": {
"type": "array",
"items": {
"type": "string"
}
},
"descendantBlacklist": {
"type": "array",
"items": {
"type": "string"
}
},
"ancestorWhitelist": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"isNullNode": {
"type": "boolean"
},
"isLayout": {
"type": "boolean"
}
}
}
}
}

View File

@ -0,0 +1,351 @@
$id: "@ali/low-code-component-protocol-schema"
description: json schema for low code component protocol
allOf:
- $ref: "#/definitions/BasicSection"
- $ref: "#/definitions/PropsSection"
- $ref: "#/definitions/ConfigureSection"
definitions:
BasicSection:
type: object
properties:
componentName:
type: string
title:
type: string
description:
type: string
docUrl:
type: string
screenshot:
type: string
icon:
type: string
tags:
type: array
items:
type: string
devMode:
enum:
- proCode
- lowCode
npm:
$ref: "#/definitions/Npm"
required:
- componentName
- title
- npm
PropsSection:
type: object
required:
- props
properties:
props:
type: array
items:
properties:
name:
type: string
propType:
$ref: "#/definitions/PropType"
description:
type: string
defaultValue: {}
required:
- name
- propType
ConfigureSection:
type: object
properties:
configure:
type: object
properties:
props:
type: array
items:
$ref: "#/definitions/ConfigureProp"
styles:
type: object
properties: {}
events:
type: object
properties: {}
component:
$ref: "#/definitions/ConfigureComponent"
Npm:
type: object
properties:
package:
type: string
exportName:
type: string
subName:
type: string
main:
type: string
destructuring:
type: boolean
version:
type: string
required:
- package
- exportName
- subName
- main
- destructuring
- version
PropType:
oneOf:
- $ref: "#/definitions/BasicType"
- $ref: "#/definitions/RequiredType"
- $ref: "#/definitions/ComplexType"
BasicType:
type: string
enum:
- array
- bool
- func
- number
- object
- string
- node
- element
- any
RequiredType:
type: object
properties:
type:
$ref: "#/definitions/BasicType"
isRequired:
type: boolean
additionalProperties: false
required:
- type
ComplexType:
oneOf:
- $ref: "#/definitions/OneOf"
- $ref: "#/definitions/OneOfType"
- $ref: "#/definitions/ArrayOf"
- $ref: "#/definitions/ObjectOf"
- $ref: "#/definitions/Shape"
- $ref: "#/definitions/Exact"
OneOf:
type: object
required:
- type
- value
properties:
type:
type: string
enum:
- oneOf
value:
type: array
items:
oneOf:
- type: string
- type: number
- type: boolean
isRequired:
type: boolean
OneOfType:
type: object
required:
- type
- value
properties:
type:
type: string
enum:
- oneOfType
value:
type: array
items:
$ref: "#/definitions/PropType"
isRequired:
type: boolean
ArrayOf:
type: object
required:
- type
- value
properties:
type:
type: string
enum:
- arrayOf
value:
$ref: "#/definitions/PropType"
isRequired:
type: boolean
ObjectOf:
type: object
required:
- type
- value
properties:
type:
type: string
enum:
- objectOf
value:
$ref: "#/definitions/PropType"
isRequired:
type: boolean
Shape:
type: object
required:
- type
- value
properties:
type:
type: string
enum:
- shape
value:
type: array
items:
type: object
properties:
name:
type: string
propType:
$ref: "#/definitions/PropType"
additionalProperties: false
isRequired:
type: boolean
ShapeItem:
type: object
required:
- name
- propType
properties:
name:
type: string
propType:
$ref: "#/definitions/PropType"
isRequired:
type: boolean
additionalProperties: false
Exact:
type: object
required:
- type
- value
properties:
type:
type: string
enum:
- exact
value:
type: array
items:
type: object
properties:
name:
type: string
propType:
$ref: "#/definitions/PropType"
additionalProperties: false
isRequired:
type: boolean
ConfigureProp:
type: object
allOf:
- type: object
properties:
title:
type: string
extraProps:
type: object
properties: {}
- oneOf:
- $ref: "#/definitions/ConfigureFieldProp"
- $ref: "#/definitions/ConfigureGroupProp"
ConfigureFieldProp:
type: object
required:
- type
properties:
type:
type: string
enum:
- field
name:
type: string
setter:
$ref: "#/definitions/ConfigureFieldSetter"
ConfigureFieldSetter:
type: object
required:
- componentName
properties:
componentName:
type: string
enum:
- List
- Object
- Function
- Node
- Mixin
- Expression
- Switch
- Number
- Input
- TextArea
- Date
- DateYear
- DateMonth
- DateRange
- ColorPicker
- CodeEditor
- Select
- RadioGroup
props:
type: object
properties: {} # 暂未校验每个控件的props待控件入料后获取真实属性
ConfigureGroupProp:
type: object
required:
- type
- items
properties:
type:
type: string
enum:
- group
items:
type: array
items:
$ref: "#/definitions/ConfigureProp"
ConfigureComponent:
type: object
properties:
isContainer:
type: boolean
isModal:
type: boolean
descriptor:
type: string
nestingRule:
type: object
properties:
childWhitelist:
type: array
items:
type: string
parentWhitelist:
type: array
items:
type: string
descendantBlacklist:
type: array
items:
type: string
ancestorWhitelist:
type: array
items:
type: string
isNullNode:
type: boolean
isLayout:
type: boolean

View File

@ -0,0 +1,27 @@
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
const Ajv = require('ajv');
const { compile } = require('json-schema-to-typescript');
const ajv = new Ajv();
const YamlPath = path.resolve(__dirname, '../schemas/schema.yml');
const JsonPath = path.resolve(__dirname, '../src/validate/schema.json');
const tsPath = path.resolve(__dirname, '../src/otter-core/schema/types.ts');
// Get document, or throw exception on error
(async function() {
try {
const schema = yaml.load(fs.readFileSync(YamlPath, 'utf8'));
ajv.compile(schema);
fs.writeFileSync(JsonPath, JSON.stringify(schema, null, 2), 'utf-8');
console.log('yaml file is successfully transformed into json');
const ts = await compile(schema, 'IComponentMaterial');
fs.writeFileSync(tsPath, ts);
console.log('schema.d.ts is successfully generated');
} catch (e) {
console.log(e);
process.exit(1);
}
})();

View File

@ -0,0 +1,48 @@
import LocalAccesser from './accesser/LocalAccesser';
import OnlineAccesser from './accesser/OnlineAccesser';
import { IComponentMaterial } from './otter-core';
import { IAccesser, IMaterializeOptions } from './types';
/**
* node
* @class Materialize
*/
class Materialize {
/**
*
* @private
* @type {IMaterializeOptions}
* @memberof Materialize
*/
private options: IMaterializeOptions;
/**
*
* @private
* @type {IAccesser}
* @memberof Materialize
*/
private accesser?: IAccesser;
constructor(options: IMaterializeOptions) {
this.options = options;
}
/**
*
*
* @returns {Promise<IMaterialinSchema>}
* @memberof Materialize
*/
public async start(): Promise<IComponentMaterial> {
// 分发请求到对应接入器
if (this.options.accesser === 'local') {
this.accesser = new LocalAccesser(this.options);
} else {
this.accesser = new OnlineAccesser(this.options);
}
return this.accesser.access();
}
}
export default Materialize;

View File

@ -0,0 +1,26 @@
import { IComponentMaterial } from '../otter-core';
import { IAccesser, IMaterializeOptions } from '../types';
/**
*
* @abstract
* @class BaseAccesser
* @implements {IAccesser}
*/
abstract class BaseAccesser implements IAccesser {
/**
*
* @protected
* @type {IMaterializeOptions}
* @memberof BaseAccesser
*/
protected options: IMaterializeOptions;
constructor(options: IMaterializeOptions) {
this.options = options;
}
public abstract access(): Promise<IComponentMaterial>;
}
export default BaseAccesser;

View File

@ -0,0 +1,78 @@
import Generator from '../generator/Generator';
import { debug, IComponentMaterial } from '../otter-core';
import BaseParser from '../parser/BaseParser';
import ReactParser from '../parser/ReactParser';
import Scanner from '../scanner/Scanner';
import { IMaterialParsedModel, IMaterialScanModel, IParser } from '../types';
import BaseAccesser from './BaseAccesser';
const log = debug.extend('mat');
/**
*
* @class LocalAccesser
* @extends {BaseAccesser}
*/
class LocalAccesser extends BaseAccesser {
/**
*
* @private
* @type {Scanner}
* @memberof LocalAccesser
*/
private scanner!: Scanner;
/**
*
* @private
* @type {IParser}
* @memberof LocalAccesser
*/
private parser!: IParser;
/**
*
* @private
* @type {Generator}
* @memberof LocalAccesser
*/
private generator!: Generator;
public async access(): Promise<IComponentMaterial> {
await this.init();
// 开始扫描
const matScanModel: IMaterialScanModel = await this.scanner.scan();
log('matScanModel', matScanModel);
// 开始解析
const matParsedModels: IMaterialParsedModel[] = await this.parser.parse(
matScanModel,
);
log('matParsedModels', matParsedModels);
// 开始生产
const material: IComponentMaterial = await this.generator.generate(
matScanModel,
matParsedModels,
);
log('material', material);
return material;
}
/**
*
* @private
* @returns {Promise<void>}
* @memberof LocalAccesser
*/
private async init(): Promise<void> {
const options = this.options;
this.scanner = new Scanner(options);
const ecology = await BaseParser.recognizeEcology(options);
if (ecology === 'react') {
// debugger;
this.parser = new ReactParser(options);
this.generator = new Generator(options);
}
}
}
export default LocalAccesser;

View File

@ -0,0 +1,121 @@
import spawn from 'cross-spawn-promise';
import { ensureDir, ensureFile, writeFile } from 'fs-extra';
import { join } from 'path';
import semver from 'semver';
import uuid from 'short-uuid';
import { debug, IComponentMaterial, OtterError } from '../otter-core';
import { IMaterializeOptions } from '../types';
import BaseAccesser from './BaseAccesser';
import LocalAccesser from './LocalAccesser';
const log = debug.extend('mat');
/**
* 线
* @class OnlineAccesser
* @extends {BaseAccesser}
*/
class OnlineAccesser extends BaseAccesser {
/**
*
*
* @private
* @type {string}
* @memberof OnlineAccesser
*/
private tempDir: string = '';
public async access(): Promise<IComponentMaterial> {
// 创建临时目录
this.tempDir = await this.createTempDir();
// 创建组件包
const { name, version } = this.getPkgNameAndVersion(this.options.entry);
await this.createFakePackage({
pkgName: name,
pkgVersion: version,
});
// 将问题转化为本地物料化场景
const options: IMaterializeOptions = {
cwd: this.tempDir,
entry: join(this.tempDir, 'node_modules', name),
accesser: 'local',
isExportedAsMultiple: this.options.isExportedAsMultiple,
};
const localAccesser = new LocalAccesser(options);
return localAccesser.access();
}
/**
*
*
* @private
* @param {{
* pkgName: string;
* pkgVersion: string;
* }} params
* @returns {Promise<void>}
* @memberof OnlineAccesser
*/
private async createFakePackage(params: {
pkgName: string;
pkgVersion: string;
}): Promise<void> {
// 创建临时组件包
const tempDir = this.tempDir;
const pkgJsonFilePath = join(tempDir, 'package.json');
await ensureFile(pkgJsonFilePath);
await writeFile(
pkgJsonFilePath,
JSON.stringify({
name: params.pkgName,
version: params.pkgVersion,
dependencies: {
[params.pkgName]: params.pkgVersion,
},
}),
);
// 安装依赖
const npmClient = this.options.npmClient || 'tnpm';
await spawn(npmClient, ['i'], { stdio: 'inherit', cwd: tempDir } as any);
}
/**
*
*
* @private
* @returns {Promise<string>}
* @memberof LocalGenerator
*/
private async createTempDir(): Promise<string> {
const tempDirName = uuid.generate();
const tempDir = join(__dirname, '../../node_modules/.temp/', tempDirName);
await ensureDir(tempDir);
log('create temp dir successfully', tempDir);
return tempDir;
}
/**
*
*
* @private
* @param {string} pkgNameWithVersion
* @returns {{ [key: string]: any }}
* @memberof OnlineAccesser
*/
private getPkgNameAndVersion(
pkgNameWithVersion: string,
): { [key: string]: any } {
const matches = pkgNameWithVersion.match(/(@\d+\.\d+\.\d+)$/);
if (!matches) {
throw new OtterError(`Illegal semver version: ${pkgNameWithVersion}`);
}
const semverObj = semver.coerce(matches[0]);
const name = pkgNameWithVersion.replace(matches[0], '');
return {
version: semverObj && semverObj.version,
name,
};
}
}
export default OnlineAccesser;

View File

@ -0,0 +1,37 @@
import { writeFile } from 'fs-extra';
import { IComponentMaterial } from '../otter-core';
/**
* manifest使
* - mat:config:manifest
* - Studio
*
* @export
* @param {{
* manifestObj: IComponentMaterial,
* manifestFilePath: string,
* }} params
* @returns {Promise<{
* manifestJS: string,
* manifestFilePath: string,
* manifestObj: IComponentMaterial,
* }>}
*/
export default async function matConfigManifest(params: {
manifestObj: IComponentMaterial;
manifestFilePath: string;
}): Promise<{
manifestJSON: string;
manifestFilePath: string;
manifestObj: IComponentMaterial;
}> {
const manifestJSON = JSON.stringify(params.manifestObj);
await writeFile(params.manifestFilePath, manifestJSON);
return Promise.resolve({
manifestJSON,
manifestObj: params.manifestObj,
manifestFilePath: params.manifestFilePath,
});
}

View File

@ -0,0 +1,6 @@
import { ExtensionName } from '../types';
import MatConfigManifest from './MatConfigManifest';
export default {
[ExtensionName.CONFIGMANIFEST]: MatConfigManifest,
};

View File

@ -0,0 +1,175 @@
import { dirname, join } from 'path';
import defaultExtension from '../extensions';
import { debug, IComponentMaterial, PropsSection } from '../otter-core';
import {
IGenerator,
IMaterializeOptions,
IMaterialParsedModel,
IMaterialScanModel,
} from '../types';
const log = debug.extend('mat');
/**
*
*/
class Generator implements IGenerator {
/**
*
* @protected
* @type {IMaterializeOptions}
* @memberof BaseGenerator
*/
/**
*
* @protected
* @type {IMaterializeOptions}
* @memberof BaseGenerator
*/
protected options!: IMaterializeOptions;
constructor(options: IMaterializeOptions) {
this.options = options;
}
public async generate(
matScanModel: IMaterialScanModel,
matParsedModels: IMaterialParsedModel[],
): Promise<any> {
// const model: IMaterialinSchema = {} as any;
// 标记协议版本号
// model.version = '1.0.0';
// 组装 pkgInfo
// model.pkgInfo = pkgInfo;
const containerList = [];
for (const matParsedModel of matParsedModels) {
// TODO 可以开放扩展点让上层使用者指定导出哪些组件或者不导出哪些组件
// 默认排除掉 defaultExportName 为空的组件
if (
!matParsedModel.defaultExportName ||
!matParsedModel.defaultExportName.length
) {
log('skip', matParsedModel.filePath);
continue;
}
// 组装 manifest
const manifest: any = await this.genManifest(
matScanModel,
matParsedModel,
);
containerList.push(manifest);
}
// const components: IMaterialinComponent[] = bundle.bundleObj.components;
// Object.keys(bundle.bundleObj.Modules).forEach(key => {
// const { origin, manifest } = bundle.bundleObj.Modules[key];
// const component: IMaterialinComponent = {
// componentName: key,
// origin,
// manifest,
// };
// components.push(component);
// });
// model.components = components;
// log('materialsModel', JSON.stringify(bundle.bundleObj));
return containerList;
}
/**
* manifest
*
* @param {IMaterialParsedModel} matParsedModel
* @returns {Promise<{
* manifestFilePath: string, // manifest 文件路径
* manifestJS: string, // manifest 文件内容
* manifestObj: IMaterialinManifest, // manifest 文件对象
* }>}
* @memberof LocalGenerator
*/
public async genManifest(
matScanModel: IMaterialScanModel,
matParsedModel: IMaterialParsedModel,
): Promise<{
manifestFilePath: string; // manifest 文件路径
manifestObj: IComponentMaterial; // manifest 文件对象
}> {
const manifestObj: Partial<IComponentMaterial> = {
// componentName: matParsedModel.defaultExportName,
title: matScanModel.pkgName,
docUrl: '',
screenshot: '',
npm: {
package: matScanModel.pkgName,
version: matScanModel.pkgVersion,
exportName: '', // matParsedModel.defaultExportName,
main: matScanModel.mainEntry,
destructuring: false,
subName: '',
},
};
const defaultManifestFilePath = join(
dirname(matParsedModel.filePath),
'./manifest.json',
);
// 填充 props
manifestObj.props = matParsedModel.props;
// 执行扩展点
const manifest: any = await this.executeExtensionPoint(
'mat:config:manifest',
{
manifestObj,
manifestFilePath: defaultManifestFilePath,
},
);
return {
manifestObj: manifest.manifestObj,
manifestFilePath: manifest.manifestFilePath,
};
}
/**
* props
*
* @public
* @param {IMaterialParsedModel} matParsedModel
* @returns {IMaterialinProp[]}
* @memberof BaseGenerator
*/
public populateProps(
matParsedModel: IMaterialParsedModel,
): PropsSection['props'] {
// @ts-ignore
return matParsedModel.props;
}
/**
*
* @param {string} extName
* @param {...any[]} args
* @returns {Promise<any>}
* @memberof BaseGenerator
*/
public async executeExtensionPoint(
extName: string,
...args: any[]
): Promise<any> {
const options = this.options;
const optionsExtensions: any = options.extensions;
const defaultExtensions: any = defaultExtension;
const ext: any =
optionsExtensions && optionsExtensions[extName]
? optionsExtensions[extName]
: defaultExtensions[extName];
if (!ext) {
throw new Error(`Unsupported extension point: ${extName}`);
}
return ext(...args);
}
}
export default Generator;

View File

@ -0,0 +1,8 @@
import Materialize from './Materialize';
export { default as validate } from './validate';
export { default as schema } from './validate/schema.json';
export * from './types';
export default Materialize;

View File

@ -0,0 +1,70 @@
import { _ } from './index';
import { IOtterErrorOptions } from './types';
/**
* Fix the prototype chain of the error
*
* Use Object.setPrototypeOf
* Support ES6 environments
*
* Fallback setting __proto__
* Support IE11+, see https://docs.microsoft.com/en-us/scripting/javascript/reference/javascript-version-information
*/
function fixPrototype(target: Error, prototype: {}) {
const setPrototypeOf: typeof Object.setPrototypeOf = (Object as any)
.setPrototypeOf;
setPrototypeOf
? setPrototypeOf(target, prototype)
: ((target as any).__proto__ = prototype);
}
/**
* Capture and fix the error stack when available
*
* Use Error.captureStackTrace
* Support v8 environments
*/
function fixStackTrace(target: Error, fn: any = target.constructor) {
const captureStackTrace: any = (Error as any).captureStackTrace;
if (captureStackTrace) {
captureStackTrace(target, fn);
}
}
class OtterError extends Error {
public name: string = '';
public urlRoot: string = 'https://docs.aimake.io/otter/';
private options: IOtterErrorOptions = {
url: '/',
version: '0.0.0',
};
constructor(message?: string, options?: IOtterErrorOptions) {
super(message);
// set error name as constructor name, make it not enumerable to keep native Error behavior
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target#new.target_in_constructors
Object.defineProperty(this, 'name', {
value: new.target.name,
enumerable: false,
});
// fix the extended error prototype chain
// because typescript __extends implementation can't
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
fixPrototype(this, new.target.prototype);
// try to remove constructor from stack trace
fixStackTrace(this);
_.extend(this.options, options || {});
}
public toString() {
const url = this.urlRoot + this.options.version + this.options.url;
return `${this.name}: ${this.message} See: ${url}`;
}
}
export default OtterError;

View File

@ -0,0 +1,21 @@
import _debug from 'debug';
import _lodash from 'lodash';
import _OtterError from './OtterError';
export * from './types';
export * from './schema/types';
/**
* Dev helper
*/
export const debug = _debug('otter');
export const enableDebug = () => _debug.enable('otter:*');
export const disableDebug = () => _debug.disable();
export const OtterError = _OtterError;
/**
* Dev utils
*/
export const _ = _lodash;

View File

@ -0,0 +1,164 @@
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
/**
* json schema for low code component protocol
*/
export type IComponentMaterial = BasicSection & PropsSection & ConfigureSection;
export type PropType = BasicType | RequiredType | ComplexType;
export type BasicType = "array" | "bool" | "func" | "number" | "object" | "string" | "node" | "element" | "any";
export type ComplexType = OneOf | OneOfType | ArrayOf | ObjectOf | Shape | Exact;
export type ConfigureProp = {
title?: string;
extraProps?: {
[k: string]: any;
};
[k: string]: any;
} & (ConfigureFieldProp | ConfigureGroupProp);
export interface BasicSection {
componentName: string;
title: string;
description?: string;
docUrl?: string;
screenshot?: string;
icon?: string;
tags?: string[];
devMode?: "proCode" | "lowCode";
npm: Npm;
[k: string]: any;
}
export interface Npm {
package: string;
exportName: string;
subName: string;
main: string;
destructuring: boolean;
version: string;
[k: string]: any;
}
export interface PropsSection {
props: {
name: string;
propType: PropType;
description?: string;
defaultValue?: any;
[k: string]: any;
}[];
[k: string]: any;
}
export interface RequiredType {
type: BasicType;
isRequired?: boolean;
}
export interface OneOf {
type: "oneOf";
value: (string | number | boolean)[];
isRequired?: boolean;
[k: string]: any;
}
export interface OneOfType {
type: "oneOfType";
value: PropType[];
isRequired?: boolean;
[k: string]: any;
}
export interface ArrayOf {
type: "arrayOf";
value: PropType;
isRequired?: boolean;
[k: string]: any;
}
export interface ObjectOf {
type: "objectOf";
value: PropType;
isRequired?: boolean;
[k: string]: any;
}
export interface Shape {
type: "shape";
value: {
name?: string;
propType?: PropType;
}[];
isRequired?: boolean;
[k: string]: any;
}
export interface Exact {
type: "exact";
value: {
name?: string;
propType?: PropType;
}[];
isRequired?: boolean;
[k: string]: any;
}
export interface ConfigureSection {
configure?: {
props?: ConfigureProp[];
styles?: {
[k: string]: any;
};
events?: {
[k: string]: any;
};
component?: ConfigureComponent;
[k: string]: any;
};
[k: string]: any;
}
export interface ConfigureFieldProp {
type: "field";
name?: string;
setter?: ConfigureFieldSetter;
[k: string]: any;
}
export interface ConfigureFieldSetter {
componentName:
| "List"
| "Object"
| "Function"
| "Node"
| "Mixin"
| "Expression"
| "Switch"
| "Number"
| "Input"
| "TextArea"
| "Date"
| "DateYear"
| "DateMonth"
| "DateRange"
| "ColorPicker"
| "CodeEditor"
| "Select"
| "RadioGroup";
props?: {
[k: string]: any;
};
[k: string]: any;
}
export interface ConfigureGroupProp {
type: "group";
items: ConfigureProp[];
[k: string]: any;
}
export interface ConfigureComponent {
isContainer?: boolean;
isModal?: boolean;
descriptor?: string;
nestingRule?: {
childWhitelist?: string[];
parentWhitelist?: string[];
descendantBlacklist?: string[];
ancestorWhitelist?: string[];
[k: string]: any;
};
isNullNode?: boolean;
isLayout?: boolean;
[k: string]: any;
}

View File

@ -0,0 +1,22 @@
/**
*
* @export
* @interface IOtterErrorOptions
*/
export interface IOtterErrorOptions {
url?: string;
version?: string;
}
/**
*
*
* @export
* @interface IComponents
*/
export interface IComponents {
[componentPackage: string]: {
// 组件包名称
[componentName: string]: any; // 组件
};
}

View File

@ -0,0 +1,76 @@
import { OtterError } from '../otter-core';
import {
EcologyType,
IMaterializeOptions,
IMaterialParsedModel,
IMaterialScanModel,
IParser,
SourceType,
} from '../types';
/**
*
* @abstract
* @class BaseParser
* @implements {IParser}
*/
abstract class BaseParser implements IParser {
/**
* reactvuerax
* @static
* @param {IMaterializeOptions} options
* @returns {Promise<EcologyType>}
* @memberof BaseParser
*/
public static recognizeEcology(
options: IMaterializeOptions,
): Promise<EcologyType> {
// TODO 识别物料组件生态
return Promise.resolve(EcologyType.REACT);
}
private options: IMaterializeOptions;
constructor(options: IMaterializeOptions) {
this.options = options;
}
public async parse(
model: IMaterialScanModel,
): Promise<IMaterialParsedModel[]> {
const results: IMaterialParsedModel[] = [];
switch (model.sourceType) {
case SourceType.MODULE: {
for (const item of model.modules) {
const parsedModel: IMaterialParsedModel = await this.parseES6({
model,
filePath: item.filePath,
fileContent: item.fileContent,
});
results.push(parsedModel);
}
break;
}
case SourceType.MAIN: {
this.parseES5(model);
break;
}
default: {
throw new OtterError(`Unsupported SourceType [${model.sourceType}]`);
}
}
return results;
}
public abstract parseES5(
model: IMaterialScanModel,
): Promise<IMaterialParsedModel>;
public abstract parseES6(params: {
model: IMaterialScanModel;
filePath: string;
fileContent: string;
}): Promise<IMaterialParsedModel>;
}
export default BaseParser;

View File

@ -0,0 +1,704 @@
import { CodeGenerator } from '@babel/generator';
// import { parse } from '@babel/parser';
const buildParser = require('react-docgen/dist/babelParser').default;
const reactDocs = require('react-docgen');
import traverse from '@babel/traverse';
import * as t from '@babel/types';
const { utils: ReactDocUtils } = require('react-docgen');
import { debug } from '../otter-core';
import {
IMaterialParsedModel,
IMaterialScanModel,
IPropType,
IPropTypes,
SourceType,
} from '../types';
import BaseParser from './BaseParser';
import resolver from './resolver';
import handlers from './handlers';
const log = debug.extend('mat');
const parser = buildParser();
function transformType(type: any): any {
const { name, value, computed, required } = type;
if (!value && !required) {
return name;
}
if (computed !== undefined && value) {
// tslint:disable-next-line:no-eval
return eval(value);
}
const result: any = {
type: name,
};
if (required) {
result.isRequired = required;
}
if (Array.isArray(value)) {
if (name === 'enum') {
result.type = 'oneOf';
} else if (name === 'union') {
result.type = 'oneOfType';
}
result.value = value.map(transformType);
} else if (typeof value === 'object') {
if (name === 'objectOf' || name === 'arrayOf' || name === 'instanceOf') {
result.value = transformType(value);
} else {
result.value = Object.keys(value).map((n: string) => {
// tslint:disable-next-line:variable-name
const { name: _name, ...others } = value[n];
return transformItem(n, {
...others,
type: {
name: _name,
},
});
});
}
} else if (value !== undefined) {
result.value = value;
}
return result;
}
function transformItem(name: string, item: any): any {
const { description, type, required, defaultValue } = item;
const result: any = {
name,
propType: transformType({
...type,
required: !!required,
}),
};
if (description) {
result.description = description;
}
if (defaultValue) {
try {
const value = eval(defaultValue.value);
result.defaultValue = value;
} catch (e) {}
}
return result;
}
/**
* react
*
* @class ReactParser
* @extends {BaseParser}
*/
class ReactParser extends BaseParser {
/**
* ExportStatement
* @static
* @returns {Promise<any>}
* @memberof ReactParser
*/
public static async parseExportedStatement(
fileContent: string,
sourceType: string,
): Promise<
Array<{
localName: string;
exportedName: string;
source: string;
}>
> {
const ast = parser.parse(fileContent);
// @ts-ignore
ast.__src = fileContent;
const specifiers: any = [];
// 组装 localName 和 exportedName
traverse(ast, {
enter(path) {
if (t.isExportNamedDeclaration(path.node)) {
path.node.specifiers.forEach(spec => {
if (t.isExportSpecifier(spec)) {
const source = (path.node as t.ExportNamedDeclaration).source;
specifiers.push({
localName: spec.local.name,
exportedName: spec.exported.name,
source: t.isLiteral(source) ? (source as any).value : '',
});
}
});
}
},
});
// 组装 source
traverse(ast, {
enter(path) {
if (t.isImportDeclaration(path.node)) {
const source = path.node.source;
path.node.specifiers.forEach(spec => {
if (t.isImportDefaultSpecifier(spec)) {
const target = specifiers.find(
(inner: any) => inner.localName === spec.local.name,
);
if (target) {
target.source = source.value;
}
}
});
}
},
});
debug('specifiers', specifiers);
return specifiers;
}
public static parseProperties(objectPath: any): IPropTypes {
const results: IPropTypes = objectPath
.get('properties')
.map((p: any) =>
transformItem(
p.get('key').node.name,
ReactDocUtils.getPropType(p.get('value')),
),
);
return results;
}
public async parseES5(
model: IMaterialScanModel,
): Promise<IMaterialParsedModel> {
const parsedModel: IMaterialParsedModel = {
filePath: '',
defaultExportName: '',
componentNames: [],
importModules: [],
exportModules: [],
subModules: [],
propsTypes: [],
propsDefaults: [],
};
const mainEntryItem: any = model.modules.find(
item => item.filePath === model.mainEntry,
);
const result = reactDocs.parse(
mainEntryItem.fileContent,
resolver,
handlers,
);
const props = Object.keys(result.props || {}).map(name => {
return transformItem(name, result.props[name]);
});
return {
filePath: mainEntryItem.filePath,
// defaultExportName,
// subModules,
// propsTypes,
props,
} as any;
// log('mainEntryItem', mainEntryItem);
// const ast = parser.parse(mainEntryItem.file);
// @ts-ignore
// ast.__src = mainEntryItem.file;
// // 获取 defaultExportName
// traverse(ast, {
// enter(path) {
// if (t.isExpressionStatement(path.node)) {
// if (
// t.isAssignmentExpression(path.node.expression) &&
// t.isMemberExpression(path.node.expression.left) &&
// t.isIdentifier(path.node.expression.left.object) &&
// t.isIdentifier(path.node.expression.right) &&
// path.node.expression.left.object.name === 'exports' &&
// (path.node.expression.left.property.name === 'default' ||
// path.node.expression.left.property.value === 'default')
// ) {
// // 支持 export default Demo 写法
// const tempVarName = path.node.expression.right.name;
// let defaultExportName = '';
// traverse(ast, {
// enter(innerPath) {
// if (
// t.isVariableDeclaration(innerPath.node) &&
// Array.isArray(innerPath.node.declarations) &&
// innerPath.node.declarations.length &&
// t.isVariableDeclarator(innerPath.node.declarations[0]) &&
// t.isIdentifier(innerPath.node.declarations[0].id) &&
// innerPath.node.declarations[0].id.name === tempVarName &&
// t.isIdentifier(innerPath.node.declarations[0].init)
// ) {
// defaultExportName = innerPath.node.declarations[0].init.name;
// }
// },
// });
// parsedModel.defaultExportName = defaultExportName;
// log('isIdentifier defaultExportName', defaultExportName);
// }
// }
// },
// });
// traverse(ast, {
// enter(path) {
// // 获取 componentNames
// if (t.isVariableDeclaration(path.node)) {
// if (
// t.isVariableDeclarator(path.node.declarations) &&
// t.isIdentifier(path.node.declarations.init) &&
// t.isIdentifier(path.node.declarations.id)
// ) {
// const exportedName = path.node.declarations.init.name;
// const localName = path.node.declarations.id.name;
// log('isIdentifier componentNames', exportedName);
// parsedModel.componentNames.push({
// exportedName,
// localName,
// });
// }
// }
// // 获取 exportModules
// if (t.isExpressionStatement(path.node)) {
// // 对应 export function DemoFunc() {} 或 export { DemoFunc } 写法
// if (
// t.isAssignmentExpression(path.node.expression) &&
// t.isMemberExpression(path.node.expression.left) &&
// t.isIdentifier(path.node.expression.left.object) &&
// t.isIdentifier(path.node.expression.left.property) &&
// t.isIdentifier(path.node.expression.right) &&
// path.node.expression.left.object.name === 'exports'
// ) {
// const exportedName = path.node.expression.left.property.name;
// const localName = path.node.expression.right.name;
// parsedModel.exportModules.push({
// exportedName:
// exportedName === 'default'
// ? parsedModel.defaultExportName
// : exportedName,
// localName:
// exportedName === 'default'
// ? parsedModel.defaultExportName
// : localName,
// });
// }
// // 支持 export { default as DemoFunc } from './DemoFunc' 写法
// if (
// t.isCallExpression(path.node.expression) &&
// t.isMemberExpression(path.node.expression.callee) &&
// t.isIdentifier(path.node.expression.callee.object) &&
// t.isIdentifier(path.node.expression.callee.property) &&
// path.node.expression.callee.object.name === 'Object' &&
// path.node.expression.callee.property.name === 'defineProperty' &&
// Array.isArray(path.node.expression.arguments) &&
// t.isIdentifier(path.node.expression.arguments[0]) &&
// (path.node.expression.arguments[0] as t.Identifier).name ===
// 'exports' &&
// t.isLiteral(path.node.expression.arguments[1])
// ) {
// // 对应 export function DemoFunc() {} 或 export { DemoFunc } 写法
// const args = path.node.expression.arguments as any;
// const funcName = args[1].value;
// if (funcName !== '__esModule') {
// parsedModel.exportModules.push({
// exportedName: funcName,
// localName: funcName,
// });
// }
// }
// }
// // 获取 importModules
// if (
// t.isVariableDeclaration(path.node) &&
// Array.isArray(path.node.declarations) &&
// path.node.declarations.length
// ) {
// path.node.declarations.forEach(dec => {
// // 支持 import Demo from './demo' 写法
// if (
// t.isVariableDeclarator(dec) &&
// t.isIdentifier(dec.id) &&
// t.isCallExpression(dec.init) &&
// t.isIdentifier(dec.init.callee) &&
// ['_interopRequireWildcard', '_interopRequireDefault'].includes(
// dec.init.callee.name,
// ) &&
// // dec.init.callee.name === '_interopRequireWildcard' &&
// Array.isArray(dec.init.arguments) &&
// t.isCallExpression(dec.init.arguments[0]) &&
// t.isIdentifier(
// (dec.init.arguments[0] as t.CallExpression).callee,
// ) &&
// ((dec.init.arguments[0] as t.CallExpression)
// .callee as t.Identifier).name === 'require'
// ) {
// const localName = dec.id.name;
// const args = (dec.init.arguments[0] as t.CallExpression)
// .arguments as any;
// const source = args[0].value;
// parsedModel.importModules.push({
// importDefaultName: localName,
// localName,
// source,
// });
// }
// // 支持 import { Demo as Demo2 } from './demo' 写法
// if (
// t.isVariableDeclarator(dec) &&
// t.isIdentifier(dec.id) &&
// t.isCallExpression(dec.init) &&
// t.isIdentifier(dec.init.callee) &&
// dec.init.callee.name === 'require' &&
// Array.isArray(dec.init.arguments) &&
// t.isLiteral(dec.init.arguments[0])
// ) {
// const args = dec.init.arguments as any;
// const source = args[0].value;
// const importName = dec.id.name;
// const localName = dec.id.name;
// // 遍历查找出 importName 和 localName
// // ES5 本身并不支持按需加载,故 import 都是全量导入
// // 但如果使用了诸如babel-plugin-import 等插件,会自动更改编译之后的 ES5 代码
// parsedModel.importModules.push({
// importName,
// localName,
// source,
// });
// }
// });
// }
// // 获取 subModules
// if (
// t.isExpressionStatement(path.node) &&
// t.isAssignmentExpression(path.node.expression) &&
// t.isMemberExpression(path.node.expression.left)
// ) {
// if (
// t.isIdentifier(path.node.expression.left.object) &&
// path.node.expression.left.object.name ===
// parsedModel.defaultExportName
// ) {
// // 支持 SFC.SubDemo1 = SubDemo1; 写法
// if (t.isIdentifier(path.node.expression.right)) {
// parsedModel.subModules.push({
// objectName: [path.node.expression.left.object.name],
// propertyName: path.node.expression.left.property.name,
// isValueAnonymousFunc: false,
// value: path.node.expression.right.name,
// });
// }
// // 支持 SFC.SubDemo2 = function() {}; 写法
// if (t.isFunctionExpression(path.node.expression.right)) {
// const rightID = path.node.expression.right.id as any;
// parsedModel.subModules.push({
// objectName: [path.node.expression.left.object.name],
// propertyName: path.node.expression.left.property.name,
// isValueAnonymousFunc: !rightID,
// value: rightID ? rightID.name : undefined,
// });
// }
// }
// if (t.isMemberExpression(path.node.expression.left.object)) {
// if (t.isIdentifier(path.node.expression.right)) {
// // 支持 DemoFunc4.Test.Obj2 = Obj3; 写法
// const tempLeftObject = path.node.expression.left.object as any;
// parsedModel.subModules.push({
// objectName: [
// tempLeftObject.object.name,
// tempLeftObject.property.name,
// ],
// propertyName: path.node.expression.left.property.name,
// isValueAnonymousFunc: false,
// value: path.node.expression.right.name,
// });
// }
// if (t.isFunctionExpression(path.node.expression.right)) {
// // 支持 DemoFunc4.Test.Obj2 = function() {}; 写法
// const rightID = path.node.expression.right.id as any;
// const tempLeftObject = path.node.expression.left.object as any;
// parsedModel.subModules.push({
// objectName: [
// tempLeftObject.object.name,
// tempLeftObject.property.name,
// ],
// propertyName: path.node.expression.left.property.name,
// isValueAnonymousFunc: !rightID,
// value: rightID ? rightID.name : undefined,
// });
// }
// }
// }
// // 获取 propsTypes 和 defaultProps
// if (
// t.isExpressionStatement(path.node) &&
// t.isAssignmentExpression(path.node.expression) &&
// t.isMemberExpression(path.node.expression.left) &&
// t.isObjectExpression(path.node.expression.right) &&
// t.isIdentifier(path.node.expression.left.object) &&
// t.isIdentifier(path.node.expression.left.property) &&
// path.node.expression.left.object.name ===
// parsedModel.defaultExportName &&
// ['propTypes', 'defaultProps'].includes(
// path.node.expression.left.property.name,
// )
// ) {
// // 处理 propTypes
// if (path.node.expression.left.property.name === 'propTypes') {
// path.node.expression.right.properties.forEach(prop => {
// if (t.isProperty(prop)) {
// if (t.isMemberExpression(prop.value)) {
// if (t.isIdentifier(prop.value.object)) {
// // 支持 optionalArray: PropTypes.array 写法
// parsedModel.propsTypes.push({
// name: prop.key.name,
// type: prop.value.property.name,
// required: false,
// });
// }
// if (t.isMemberExpression(prop.value.object)) {
// // 支持 optionalArray: PropTypes.array.isRequired 写法
// parsedModel.propsTypes.push({
// name: prop.key.name,
// type: prop.value.object.property.name,
// required:
// prop.value.object.property.name === 'isRequired',
// });
// }
// if (
// t.isCallExpression(prop.value.object) &&
// t.isMemberExpression(prop.value.object.callee)
// ) {
// // 支持 optionalArray: PropTypes.shape().isRequired 写法
// parsedModel.propsTypes.push({
// name: prop.key.name,
// type: prop.value.object.callee.property.name,
// required: prop.value.property.name === 'isRequired',
// });
// }
// }
// if (
// t.isCallExpression(prop.value) &&
// t.isMemberExpression(prop.value.callee)
// ) {
// // 支持 optionalArray: PropTypes.shape() 写法
// parsedModel.propsTypes.push({
// name: prop.key.name,
// type: prop.value.callee.property.name,
// required: false,
// });
// }
// }
// });
// }
// // 处理 defaultProps
// if (path.node.expression.left.property.name === 'defaultProps') {
// path.node.expression.right.properties.forEach(prop => {
// if (t.isProperty(prop)) {
// if (t.isObjectExpression(prop.value)) {
// const defaultValue = new CodeGenerator(
// t.objectExpression(prop.value.properties),
// ).generate().code;
// parsedModel.propsDefaults.push({
// name: prop.key.name,
// defaultValue,
// });
// }
// }
// });
// }
// }
// },
// });
// log('traverse done.');
// log('parsedModel.defaultExportName', parsedModel.defaultExportName);
// log('parsedModel.componentNames', parsedModel.componentNames);
// log('parsedModel.importModules', parsedModel.importModules);
// log('parsedModel.exportModules', parsedModel.exportModules);
// log('parsedModel.subModules', parsedModel.subModules);
// log('parsedModel.propsTypes', parsedModel.propsTypes);
// log('parsedModel.propsDefaults', parsedModel.propsDefaults);
// log('parsedModel', parsedModel);
// return parsedModel;
}
public async parseES6(params: {
model: IMaterialScanModel;
filePath: string;
fileContent: string;
}): Promise<IMaterialParsedModel> {
const ast = parser.parse(params.fileContent);
const result = reactDocs.parse(params.fileContent, resolver, handlers);
const props = Object.keys(result.props || {}).map(name => {
return transformItem(name, result.props[name]);
});
const defaultExportName = await this.parseDefaultExportNameES6(ast);
// const subModules = await this.parseSubModulesES6(ast);
return {
filePath: params.filePath,
defaultExportName,
// subModules,
props,
} as any;
}
/**
* AST defaultExportName
*
* - export default Demo
* - export default function Demo() {}
* - export default class Demo {}
*
* @private
* @param {*} ast
* @memberof ReactParser
*/
private async parseDefaultExportNameES6(ast: any): Promise<string> {
let defaultExportName = '';
traverse(ast, {
enter(path) {
// 获取 defaultExportName
if (t.isExportDefaultDeclaration(path.node)) {
if (t.isIdentifier(path.node.declaration)) {
// 支持 export default Demo 写法
defaultExportName = path.node.declaration.name;
log('isIdentifier defaultExportName', defaultExportName);
}
if (t.isFunctionDeclaration(path.node.declaration)) {
if (t.isIdentifier(path.node.declaration.id)) {
// 支持 export default function Demo() {} 写法
defaultExportName = path.node.declaration.id.name;
log('isFunctionDeclaration defaultExportName', defaultExportName);
}
}
if (t.isClassDeclaration(path.node.declaration)) {
if (t.isIdentifier(path.node.declaration.id)) {
// 支持 export default class Demo {} 写法
defaultExportName = path.node.declaration.id.name;
log('isClassDeclaration defaultExportName', defaultExportName);
}
}
if (t.isCallExpression(path.node.declaration)) {
const traverseCallExp: any = (args: any[]) => {
const arg = args[0];
if (t.isIdentifier(arg)) {
return arg.name;
}
return traverseCallExp(arg.arguments);
};
defaultExportName = traverseCallExp(
path.node.declaration.arguments,
);
}
}
},
});
return defaultExportName;
}
/**
* AST subModules
*
* - DemoFunc4.Test = Test;
* - DemoFunc4.Test = function() {};
* - DemoFunc4.Test.Obj2 = Obj3;
* - DemoFunc4.Test.Obj2 = function() {};
*
* @private
* @param {*} ast
* @returns {Promise<Array<{
* objectName: string[],
* propertyName: string,
* value?: string,
* isValueAnonymousFunc: boolean,
* }>>}
* @memberof ReactParser
*/
private async parseSubModulesES6(
ast: any,
): Promise<
Array<{
objectName: string[];
propertyName: string;
value?: string;
isValueAnonymousFunc: boolean;
}>
> {
const results: any[] = [];
traverse(ast, {
enter(path) {
if (t.isExpressionStatement(path.node)) {
if (t.isAssignmentExpression(path.node.expression)) {
if (t.isMemberExpression(path.node.expression.left)) {
if (t.isIdentifier(path.node.expression.left.object)) {
if (t.isIdentifier(path.node.expression.right)) {
// 支持 DemoFunc4.Test = Test; 写法
results.push({
objectName: [path.node.expression.left.object.name],
propertyName: path.node.expression.left.property.name,
isValueAnonymousFunc: false,
value: path.node.expression.right.name,
});
}
if (t.isFunctionExpression(path.node.expression.right)) {
// 支持 DemoFunc4.Test = function() {}; 写法
const rightID = !path.node.expression.right.id as any;
results.push({
objectName: [path.node.expression.left.object.name],
propertyName: path.node.expression.left.property.name,
isValueAnonymousFunc: !!rightID,
value: rightID ? rightID.name : undefined,
});
}
}
if (t.isMemberExpression(path.node.expression.left.object)) {
if (t.isIdentifier(path.node.expression.right)) {
// 支持 DemoFunc4.Test.Obj2 = Obj3; 写法
const tempLeftObject = path.node.expression.left
.object as any;
results.push({
objectName: [
tempLeftObject.object.name,
tempLeftObject.property.name,
],
propertyName: path.node.expression.left.property.name,
isValueAnonymousFunc: false,
value: path.node.expression.right.name,
});
}
if (t.isFunctionExpression(path.node.expression.right)) {
// 支持 DemoFunc4.Test.Obj2 = function() {}; 写法
const rightID = !path.node.expression.right.id as any;
const tempLeftObject = path.node.expression.left
.object as any;
results.push({
objectName: [
tempLeftObject.object.name,
tempLeftObject.property.name,
],
propertyName: path.node.expression.left.property.name,
isValueAnonymousFunc: !!rightID,
value: rightID ? rightID.name : undefined,
});
}
}
}
}
}
},
});
return results;
}
}
export default ReactParser;

View File

@ -0,0 +1,22 @@
const { handlers } = require('react-docgen');
import {
propTypeHandler,
contextTypeHandler,
childContextTypeHandler,
} from './propTypeHandler';
const defaultHandlers = [
propTypeHandler,
contextTypeHandler,
childContextTypeHandler,
handlers.propTypeCompositionHandler,
handlers.propDocBlockHandler,
handlers.flowTypeHandler,
handlers.defaultPropsHandler,
handlers.componentDocblockHandler,
handlers.displayNameHandler,
handlers.componentMethodsHandler,
handlers.componentMethodsJsDocHandler,
];
export default defaultHandlers;

View File

@ -0,0 +1,136 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import { namedTypes as t, visit } from 'ast-types';
import { throwStatement } from '@babel/types';
const {
resolveToValue,
getPropType,
getPropertyName,
getMemberValuePath,
isReactModuleName,
printValue,
resolveToModule,
} = require('react-docgen').utils;
const isRequiredPropType = require('react-docgen/dist/utils/isRequiredPropType')
.default;
function getRoot(node: any) {
let root = node.parent;
while (root.parent) {
root = root.parent;
}
return root;
}
// import type Documentation from '../Documentation';
function isPropTypesExpression(path: any) {
const moduleName = resolveToModule(path);
if (moduleName) {
return isReactModuleName(moduleName) || moduleName === 'ReactPropTypes';
}
return false;
}
function amendPropTypes(getDescriptor: any, path: any) {
if (!t.ObjectExpression.check(path.node)) {
return;
}
path.get('properties').each((propertyPath: any) => {
switch (propertyPath.node.type) {
// @ts-ignore
case t.Property.name: {
const propName = getPropertyName(propertyPath);
if (!propName) return;
const propDescriptor = getDescriptor(propName);
const valuePath = propertyPath.get('value');
const type = isPropTypesExpression(valuePath)
? getPropType(valuePath)
: { name: 'custom', raw: printValue(valuePath) };
if (type) {
propDescriptor.type = type;
propDescriptor.required =
type.name !== 'custom' && isRequiredPropType(valuePath);
}
break;
}
// @ts-ignore
case t.SpreadElement.name: {
const resolvedValuePath = resolveToValue(propertyPath.get('argument'));
switch (resolvedValuePath.node.type) {
// @ts-ignore
case t.ObjectExpression.name: // normal object literal
amendPropTypes(getDescriptor, resolvedValuePath);
break;
}
break;
}
}
});
}
function getDefinePropertyValuePath(nodePath: any, propName: string) {
const program = getRoot(nodePath);
const componentName = nodePath.node.id.name;
let resultPath = nodePath;
visit(program, {
visitCallExpression: function(path) {
const args = path.get('arguments');
const argsNodeList = args.value;
if (
argsNodeList.length === 3 &&
t.Identifier.check(argsNodeList[0]) &&
argsNodeList[0].name === componentName &&
t.Literal.check(argsNodeList[1]) &&
argsNodeList[1].value === propName
) {
resultPath = args.get(2);
}
return false;
},
});
return resultPath;
}
function getPropTypeHandler(propName: string) {
return function(documentation: any, path: any) {
let propTypesPath = getMemberValuePath(path, propName);
if (!propTypesPath) {
propTypesPath = getDefinePropertyValuePath(path, propName);
if (!propTypesPath) {
return;
}
}
propTypesPath = resolveToValue(propTypesPath);
if (!propTypesPath) {
return;
}
let getDescriptor;
switch (propName) {
case 'childContextTypes':
getDescriptor = documentation.getChildContextDescriptor;
break;
case 'contextTypes':
getDescriptor = documentation.getContextDescriptor;
break;
default:
getDescriptor = documentation.getPropDescriptor;
}
amendPropTypes(getDescriptor.bind(documentation), propTypesPath);
};
}
export const propTypeHandler = getPropTypeHandler('propTypes');
export const contextTypeHandler = getPropTypeHandler('contextTypes');
export const childContextTypeHandler = getPropTypeHandler('childContextTypes');

View File

@ -0,0 +1,7 @@
export default function checkIsIIFE(path: any) {
return (
path.value.callee &&
path.value.callee.type === 'FunctionExpression' &&
path.node.type === 'CallExpression'
);
}

View File

@ -0,0 +1,168 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { namedTypes as t, visit } from 'ast-types';
const {
isExportsOrModuleAssignment,
isReactComponentClass,
isReactCreateClassCall,
isReactForwardRefCall,
isStatelessComponent,
normalizeClassDefinition,
resolveExportDeclaration,
resolveToValue,
} = require('react-docgen').utils;
import checkIsIIFE from './checkIsIIFE';
import resolveHOC from './resolveHOC';
import resolveIIFE from './resolveIIFE';
import resolveTranspiledClass from './resolveTranspiledClass';
const ERROR_MULTIPLE_DEFINITIONS =
'Multiple exported component definitions found.';
function ignore() {
return false;
}
function isComponentDefinition(path: any) {
return (
isReactCreateClassCall(path) ||
isReactComponentClass(path) ||
isStatelessComponent(path) ||
isReactForwardRefCall(path)
);
}
function resolveDefinition(definition: any) {
if (isReactCreateClassCall(definition)) {
// return argument
const resolvedPath = resolveToValue(definition.get('arguments', 0));
if (t.ObjectExpression.check(resolvedPath.node)) {
return resolvedPath;
}
} else if (isReactComponentClass(definition)) {
normalizeClassDefinition(definition);
return definition;
} else if (
isStatelessComponent(definition) ||
isReactForwardRefCall(definition)
) {
return definition;
}
return null;
}
function getDefinition(definition: any) {
if (checkIsIIFE(definition)) {
definition = resolveToValue(resolveIIFE(definition));
if (!isComponentDefinition(definition)) {
definition = resolveTranspiledClass(definition);
}
} else {
definition = resolveToValue(resolveHOC(definition));
if (checkIsIIFE(definition)) {
definition = resolveToValue(resolveIIFE(definition));
if (!isComponentDefinition(definition)) {
definition = resolveTranspiledClass(definition);
}
}
}
// definition = resolveToValue(resolveIIFE(definition));
// if (!isComponentDefinition(definition)) {
// definition = resolveTranspiledClass(definition);
// }
// definition = resolveToValue(resolveHOC(definition));
return definition;
}
/**
* Given an AST, this function tries to find the exported component definition.
*
* The component definition is either the ObjectExpression passed to
* `React.createClass` or a `class` definition extending `React.Component` or
* having a `render()` method.
*
* If a definition is part of the following statements, it is considered to be
* exported:
*
* modules.exports = Definition;
* exports.foo = Definition;
* export default Definition;
* export var Definition = ...;
*/
export default function findExportedComponentDefinition(ast: any) {
let foundDefinition: any;
function exportDeclaration(path: any) {
const definitions = resolveExportDeclaration(path).reduce(
(acc: any, definition: any) => {
if (isComponentDefinition(definition)) {
acc.push(definition);
} else {
definition = getDefinition(definition);
if (isComponentDefinition(definition)) {
acc.push(definition);
}
}
return acc;
},
[],
);
if (definitions.length === 0) {
return false;
}
if (definitions.length > 1 || foundDefinition) {
// If a file exports multiple components, ... complain!
throw new Error(ERROR_MULTIPLE_DEFINITIONS);
}
foundDefinition = resolveDefinition(definitions[0]);
return false;
}
visit(ast, {
visitFunctionDeclaration: ignore,
visitFunctionExpression: ignore,
visitClassDeclaration: ignore,
visitClassExpression: ignore,
visitIfStatement: ignore,
visitWithStatement: ignore,
visitSwitchStatement: ignore,
visitWhileStatement: ignore,
visitDoWhileStatement: ignore,
visitForStatement: ignore,
visitForInStatement: ignore,
visitForOfStatement: ignore,
visitImportDeclaration: ignore,
visitExportNamedDeclaration: exportDeclaration,
visitExportDefaultDeclaration: exportDeclaration,
visitAssignmentExpression(path: any) {
// Ignore anything that is not `exports.X = ...;` or
// `module.exports = ...;`
if (!isExportsOrModuleAssignment(path)) {
return false;
}
// Resolve the value of the right hand side. It should resolve to a call
// expression, something like React.createClass
path = resolveToValue(path.get('right'));
if (!isComponentDefinition(path)) {
path = getDefinition(path);
}
if (foundDefinition) {
// If a file exports multiple components, ... complain!
throw new Error(ERROR_MULTIPLE_DEFINITIONS);
}
foundDefinition = resolveDefinition(path);
return false;
},
});
return foundDefinition;
}

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { namedTypes as t, visit } from 'ast-types';
const {
isReactCreateClassCall,
isReactForwardRefCall,
resolveToValue,
} = require('react-docgen').utils;
/**
* If the path is a call expression, it recursively resolves to the
* rightmost argument, stopping if it finds a React.createClass call expression
*
* Else the path itself is returned.
*/
export default function resolveHOC(path: any): any {
const node = path.node;
if (
t.CallExpression.check(node) &&
!isReactCreateClassCall(path) &&
!isReactForwardRefCall(path)
) {
if (node.arguments.length) {
const inner = path.get('arguments', 0);
// If the first argument is one of these types then the component might be the last argument
// If there are all identifiers then we cannot figure out exactly and have to assume it is the first
if (
node.arguments.length > 1 &&
(t.Literal.check(inner.node) ||
t.ObjectExpression.check(inner.node) ||
t.ArrayExpression.check(inner.node) ||
t.SpreadElement.check(inner.node))
) {
return resolveHOC(
// resolveToValue(path.get('arguments', node.arguments.length - 1)),
path.get('arguments', node.arguments.length - 1),
);
}
// return resolveHOC(resolveToValue(inner));
return resolveHOC(inner);
}
}
return path;
}

View File

@ -0,0 +1,33 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// const { namedTypes: t, visit } = require("ast-types");
const resolveFunctionDefinitionToReturnValue = require('react-docgen/dist/utils/resolveFunctionDefinitionToReturnValue')
.default;
// isReactCreateClassCall,
// isReactForwardRefCall,
// resolveToValue,
// resolveHOC
import checkIsIIFE from './checkIsIIFE';
/**
* If the path is a call expression, it recursively resolves to the
* rightmost argument, stopping if it finds a React.createClass call expression
*
* Else the path itself is returned.
*/
export default function resolveIIFE(path: any) {
if (!checkIsIIFE(path)) {
return path;
}
const returnValue = resolveFunctionDefinitionToReturnValue(
path.get('callee'),
);
return returnValue;
}

View File

@ -0,0 +1,42 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { builders, namedTypes as t, NodePath, visit } from 'ast-types';
/**
* If the path is a call expression, it recursively resolves to the
* rightmost argument, stopping if it finds a React.createClass call expression
*
* Else the path itself is returned.
*/
export default function resolveTranspiledClass(path: any) {
let classPath = path;
visit(path, {
visitFunctionDeclaration(arg) {
classPath = new NodePath(
builders.functionDeclaration(
arg.node.id,
[],
builders.blockStatement([
builders.returnStatement(
builders.jsxElement(
builders.jsxOpeningElement(
builders.jsxIdentifier('div'),
[],
true,
),
),
),
]),
),
path.parent,
);
return false;
},
});
return classPath;
}

View File

@ -0,0 +1,170 @@
import { pathExists, readFile, statSync } from 'fs-extra';
import { dirname, join } from 'path';
import { debug } from '../otter-core';
import BaseParser from '../parser/BaseParser';
import ReactParser from '../parser/ReactParser';
import {
IMaterializeOptions,
IMaterialScanModel,
IScanner,
SourceType,
} from '../types';
const log = debug.extend('mat');
/**
*
*
* @class Scanner
* @implements {IScanner}
*/
class Scanner implements IScanner {
public options: IMaterializeOptions;
constructor(options: IMaterializeOptions) {
this.options = options;
}
public async scan(): Promise<IMaterialScanModel> {
const model: IMaterialScanModel = {
pkgName: '',
pkgVersion: '',
mainEntry: '',
sourceType: SourceType.MODULE,
modules: [],
};
const options = this.options;
log('options', options);
// 入口文件路径
let entryFilePath = null;
const cwd = options.cwd ? options.cwd : '';
const entry = options.entry;
const isDepsMode = cwd !== entry;
const pkgJsonPath = join(cwd, 'package.json');
// 判断是否存在 package.json
// if (!(await pathExists(pkgJsonPath))) {
// throw new Error(`Cannot find package.json. ${pkgJsonPath}`);
// }
// 读取 package.json
let pkgJson = await this.resolvePkgJson(pkgJsonPath);
model.pkgName = pkgJson.name;
model.pkgVersion = pkgJson.version;
if (isDepsMode) {
pkgJson = await this.resolvePkgJson(join(entry, 'package.json'));
}
if (pkgJson.module) {
// 支持 es module
model.sourceType = SourceType.MODULE;
entryFilePath = pkgJson.module;
} else if (pkgJson.main) {
// 支持 commonjs
model.sourceType = SourceType.MAIN;
entryFilePath = pkgJson.main;
} else {
entryFilePath = './index.js';
}
entryFilePath = join(isDepsMode ? entry : cwd, entryFilePath);
log('entryFilePath', entryFilePath);
const entryFile = await this.loadFile(entryFilePath);
log('entryFile', entryFile);
model.mainEntry = entryFilePath;
// 记录入口文件
model.modules.push({
filePath: entryFilePath,
fileContent: entryFile,
});
log('model', model);
// debugger;
if (options.isExportedAsMultiple) {
// 解析 entryFile提取出 export 语句
const modules = await this.parseEntryFile({
entryFile,
entryFilePath,
sourceType: model.sourceType,
});
model.modules = [...modules];
}
log('model', model);
return model;
}
/**
*
* @param {string} filePath
* @returns {Promise<boolean>}
* @memberof LocalScanner
*/
public async isDirectory(filePath: string): Promise<boolean> {
log('materialIn', 'isDirectory - filePath', filePath);
const stats = statSync(filePath);
return stats.isDirectory();
}
public async loadFile(filePath: string): Promise<string> {
const content: string | Buffer = await readFile(filePath);
if (typeof content === 'string') {
return content;
}
return content.toString();
}
public async resolvePkgJson(
pkgJsonPath: string,
): Promise<{ [k: string]: any }> {
const content = await this.loadFile(pkgJsonPath);
const json = JSON.parse(content);
return json;
}
/**
*
* @private
* @param {{
* entryFile: string;
* entryFilePath: string;
* sourceType: string;
* }} params
* @returns {Promise<any>}
* @memberof LocalScanner
*/
private async parseEntryFile(params: {
entryFile: string;
entryFilePath: string;
sourceType: string;
}): Promise<any> {
const modules: any = [];
const entryFileDirName = dirname(params.entryFilePath);
const ecology = await BaseParser.recognizeEcology(this.options);
if (ecology === 'react') {
const exportedList = await ReactParser.parseExportedStatement(
params.entryFile,
params.sourceType,
);
if (Array.isArray(exportedList)) {
for (const item of exportedList) {
if (item.source && item.source.length) {
try {
let filePath = join(entryFileDirName, item.source);
if (await this.isDirectory(filePath)) {
filePath = join(filePath, 'index.js');
} else {
filePath = join(filePath, '.js');
}
debug('filePath', filePath);
modules.push({
filePath,
fileContent: await this.loadFile(filePath),
});
} catch (e) {
debug('error', 'parseEntryFile', e.message);
}
}
}
}
}
debug('modules', modules);
return modules;
}
}
export default Scanner;

View File

@ -0,0 +1,11 @@
/**
*
*/
enum ChannelType {
/** 本地 */
LOCAL = 'local',
/** 在线 */
ONLINE = 'online',
}
export default ChannelType;

View File

@ -0,0 +1,15 @@
/**
*
*/
enum EcologyType {
/** react 生态 */
REACT = 'react',
/** vue 生态 */
VUE = 'vue',
/** rax 生态 */
RAX = 'rax',
/** angular 生态 */
ANGULAR = 'angular',
}
export default EcologyType;

View File

@ -0,0 +1,9 @@
/**
*
*/
enum ExtensionName {
/** 配置 manifest */
CONFIGMANIFEST = 'mat:config:manifest',
}
export default ExtensionName;

View File

@ -0,0 +1,16 @@
import { IComponentMaterial } from '../otter-core';
/**
*
* @interface IAccesser
*/
interface IAccesser {
/**
*
* @returns {Promise<IMaterialinSchema>}
* @memberof IAccesser
*/
access(): Promise<IComponentMaterial>;
}
export default IAccesser;

View File

@ -0,0 +1,15 @@
/**
* - 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;

View File

@ -0,0 +1,15 @@
import { IComponentMaterial } from '../otter-core';
/**
* manifest
*
*/
type IExtensionConfigManifest = (params: {
manifestObj: IComponentMaterial; // manifest 配置对象
manifestFilePath: string; // manifest 文件默认路径
}) => Promise<{
manifestJSON: string; // manifest 文件内容
manifestFilePath: string; // manifest 文件路径
manifestObj: IComponentMaterial; // manifest 文件对象
}>;
export default IExtensionConfigManifest;

View File

@ -0,0 +1,20 @@
import { IComponentMaterial } from '../otter-core';
import { IMaterialParsedModel } from './IMaterialParsedModel';
import IMaterialScanModel from './IMaterialScanModel';
/**
*
*/
export default interface IGenerator {
/**
*
* @param {IMaterialScanModel} matScanModel
* @param {IMaterialParsedModel[]} matParsedModels
* @returns {Promise<IMaterialinSchema>}
* @memberof IGenerator
*/
generate(
matScanModel: IMaterialScanModel,
matParsedModels: IMaterialParsedModel[],
): Promise<IComponentMaterial>;
}

View File

@ -0,0 +1,49 @@
import { PropsSection } from '../otter-core';
/**
*
*/
export interface IPropType {
name: string;
type: string;
value?: IPropTypes;
required: boolean;
}
export type IPropTypes = IPropType[];
export interface IMaterialParsedModel {
filePath: string;
defaultExportName: string;
props?: PropsSection['props'];
componentNames: Array<{
exportedName: string;
localName: string;
source?: string;
}>;
importModules: Array<{
importDefaultName?: string;
importName?: string;
localName?: string;
source: string;
}>;
exportModules: Array<{
exportedName: string;
localName: string;
source?: string;
}>;
/**
* Demo.SubModule = value; Demo.SubModule.Sub = subValue;
*/
subModules: Array<{
objectName: string[];
propertyName: string;
value?: string;
// value 是否对应匿名函数
isValueAnonymousFunc: boolean;
}>;
propsTypes: IPropTypes;
propsDefaults: Array<{
name: string;
defaultValue: any;
}>;
}

View File

@ -0,0 +1,20 @@
/**
*
*/
interface IMaterialScanModel {
/** 入口文件地址 */
mainEntry: string;
/** 标记物料组件包所使用的模块规范 */
sourceType: 'module' | 'main';
/** 每个文件对应的文件内容 */
modules: Array<{
filePath: string;
fileContent: string;
}>;
/** 当前包名 */
pkgName: string;
/** 当前包版本 */
pkgVersion: string;
}
export default IMaterialScanModel;

View File

@ -0,0 +1,53 @@
import ExtensionName from './ExtensionName';
import IExtensionConfigManifest from './IExtensionConfigManifest';
/**
*
* @interface IMaterializeOptions
*/
interface IMaterializeOptions {
/**
*
*
* /usr/project/src/container/DemoMaterial
* @ali/demo-material@0.0.1
*/
entry: string;
/**
*
* localonline线 npm
* @type {('local' | 'online')}
* @memberof IMaterializeOptions
*/
accesser: 'local' | 'online';
/**
*
* truefalse
* @type {boolean}
* @memberof IMaterializeOptions
*/
isExportedAsMultiple: boolean;
/**
* accesser=local /usr/.../demo-project
* @type {string}
* @memberof IMaterializeOptions
*/
cwd?: string;
/**
*
*/
extensions?: {
[ExtensionName.CONFIGMANIFEST]?: IExtensionConfigManifest;
};
/**
* accesser=online 使 npm clienttnpmcnpmyarnnpm
*/
npmClient?: string;
}
export default IMaterializeOptions;

View File

@ -0,0 +1,42 @@
import { IMaterialParsedModel } from './IMaterialParsedModel';
import IMaterialScanModel from './IMaterialScanModel';
/**
*
* @interface IParser
*/
interface IParser {
/**
* IScanner AST
* @param {IMaterialScanModel} model IScanner
* @returns {Promise<IMaterialParsedModel[]>}
* @memberof IParser
*/
parse(model: IMaterialScanModel): Promise<IMaterialParsedModel[]>;
/**
* ES5
* @param {IMaterialScanModel} model
* @returns {Promise<IMaterialParsedModel>}
* @memberof IParser
*/
parseES5(model: IMaterialScanModel): Promise<IMaterialParsedModel>;
/**
* ESM
* @param {{
* model: IMaterialScanModel,
* filePath: string, // 要解析的文件路径
* fileContent: string // 要解析的文件内容
* }} params
* @returns {Promise<IMaterialParsedModel>}
* @memberof IParser
*/
parseES6(params: {
model: IMaterialScanModel;
filePath: string;
fileContent: string;
}): Promise<IMaterialParsedModel>;
}
export default IParser;

View File

@ -0,0 +1,32 @@
import IMaterialScanModel from './IMaterialScanModel';
/**
*
* @interface IScanner
*/
interface IScanner {
/**
*
* @returns {Promise<IMaterialScanModel>}
* @memberof IScanner
*/
scan(): Promise<IMaterialScanModel>;
/**
*
* @param {string} filePath
* @returns {Promise<string>}
* @memberof IScanner
*/
loadFile(filePath: string): Promise<string>;
/**
* package.json
* @param {string} pkgJsonPath
* @returns {Promise<{ [k: string]: any }>} package
* @memberof IScanner
*/
resolvePkgJson(pkgJsonPath: string): Promise<{ [k: string]: any }>;
}
export default IScanner;

View File

@ -0,0 +1,11 @@
/**
*
*/
enum SourceType {
/** ES6 规范 */
MODULE = 'module',
/** CommonJS 规范 */
MAIN = 'main',
}
export default SourceType;

View File

@ -0,0 +1,28 @@
import ChannelType from './ChannelType';
import EcologyType from './EcologyType';
import ExtensionName from './ExtensionName';
import IAccesser from './IAccesser';
import ICompiler from './ICompiler';
import IExtensionConfigManifest from './IExtensionConfigManifest';
import IGenerator from './IGenerator';
import IMaterializeOptions from './IMaterializeOptions';
export * from './IMaterialParsedModel';
import IMaterialScanModel from './IMaterialScanModel';
import IParser from './IParser';
import IScanner from './IScanner';
import SourceType from './SourceType';
export {
IGenerator,
IParser,
IScanner,
ExtensionName,
IExtensionConfigManifest,
IMaterializeOptions,
IMaterialScanModel,
SourceType,
ChannelType,
EcologyType,
IAccesser,
ICompiler,
};

View File

@ -0,0 +1,13 @@
import Ajv from 'ajv';
import schema from './schema.json';
const ajv = new Ajv({ jsonPointers: true });
const validate = ajv.compile(schema);
export default function validateSchema(json: object) {
if (validate(json) === false) {
throw new Error(JSON.stringify(validate.errors, null, 2));
}
return true;
}

View File

@ -0,0 +1,548 @@
{
"$id": "@ali/low-code-component-protocol-schema",
"description": "json schema for low code component protocol",
"allOf": [
{
"$ref": "#/definitions/BasicSection"
},
{
"$ref": "#/definitions/PropsSection"
},
{
"$ref": "#/definitions/ConfigureSection"
}
],
"definitions": {
"BasicSection": {
"type": "object",
"properties": {
"componentName": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"docUrl": {
"type": "string"
},
"screenshot": {
"type": "string"
},
"icon": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"devMode": {
"enum": [
"proCode",
"lowCode"
]
},
"npm": {
"$ref": "#/definitions/Npm"
}
},
"required": [
"componentName",
"title",
"npm"
]
},
"PropsSection": {
"type": "object",
"required": [
"props"
],
"properties": {
"props": {
"type": "array",
"items": {
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
},
"description": {
"type": "string"
},
"defaultValue": {}
},
"required": [
"name",
"propType"
]
}
}
}
},
"ConfigureSection": {
"type": "object",
"properties": {
"configure": {
"type": "object",
"properties": {
"props": {
"type": "array",
"items": {
"$ref": "#/definitions/ConfigureProp"
}
},
"styles": {
"type": "object",
"properties": {}
},
"events": {
"type": "object",
"properties": {}
},
"component": {
"$ref": "#/definitions/ConfigureComponent"
}
}
}
}
},
"Npm": {
"type": "object",
"properties": {
"package": {
"type": "string"
},
"exportName": {
"type": "string"
},
"subName": {
"type": "string"
},
"main": {
"type": "string"
},
"destructuring": {
"type": "boolean"
},
"version": {
"type": "string"
}
},
"required": [
"package",
"exportName",
"subName",
"main",
"destructuring",
"version"
]
},
"PropType": {
"oneOf": [
{
"$ref": "#/definitions/BasicType"
},
{
"$ref": "#/definitions/RequiredType"
},
{
"$ref": "#/definitions/ComplexType"
}
]
},
"BasicType": {
"type": "string",
"enum": [
"array",
"bool",
"func",
"number",
"object",
"string",
"node",
"element",
"any"
]
},
"RequiredType": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/BasicType"
},
"isRequired": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": [
"type"
]
},
"ComplexType": {
"oneOf": [
{
"$ref": "#/definitions/OneOf"
},
{
"$ref": "#/definitions/OneOfType"
},
{
"$ref": "#/definitions/ArrayOf"
},
{
"$ref": "#/definitions/ObjectOf"
},
{
"$ref": "#/definitions/Shape"
},
{
"$ref": "#/definitions/Exact"
}
]
},
"OneOf": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"oneOf"
]
},
"value": {
"type": "array",
"items": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
},
{
"type": "boolean"
}
]
}
},
"isRequired": {
"type": "boolean"
}
}
},
"OneOfType": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"oneOfType"
]
},
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/PropType"
}
},
"isRequired": {
"type": "boolean"
}
}
},
"ArrayOf": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"arrayOf"
]
},
"value": {
"$ref": "#/definitions/PropType"
},
"isRequired": {
"type": "boolean"
}
}
},
"ObjectOf": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"objectOf"
]
},
"value": {
"$ref": "#/definitions/PropType"
},
"isRequired": {
"type": "boolean"
}
}
},
"Shape": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"shape"
]
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
}
},
"additionalProperties": false
}
},
"isRequired": {
"type": "boolean"
}
}
},
"ShapeItem": {
"type": "object",
"required": [
"name",
"propType"
],
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
},
"isRequired": {
"type": "boolean"
}
},
"additionalProperties": false
},
"Exact": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"exact"
]
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"propType": {
"$ref": "#/definitions/PropType"
}
},
"additionalProperties": false
}
},
"isRequired": {
"type": "boolean"
}
}
},
"ConfigureProp": {
"type": "object",
"allOf": [
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"extraProps": {
"type": "object",
"properties": {}
}
}
},
{
"oneOf": [
{
"$ref": "#/definitions/ConfigureFieldProp"
},
{
"$ref": "#/definitions/ConfigureGroupProp"
}
]
}
]
},
"ConfigureFieldProp": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"field"
]
},
"name": {
"type": "string"
},
"setter": {
"$ref": "#/definitions/ConfigureFieldSetter"
}
}
},
"ConfigureFieldSetter": {
"type": "object",
"required": [
"componentName"
],
"properties": {
"componentName": {
"type": "string",
"enum": [
"List",
"Object",
"Function",
"Node",
"Mixin",
"Expression",
"Switch",
"Number",
"Input",
"TextArea",
"Date",
"DateYear",
"DateMonth",
"DateRange",
"ColorPicker",
"CodeEditor",
"Select",
"RadioGroup"
]
},
"props": {
"type": "object",
"properties": {}
}
}
},
"ConfigureGroupProp": {
"type": "object",
"required": [
"type",
"items"
],
"properties": {
"type": {
"type": "string",
"enum": [
"group"
]
},
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/ConfigureProp"
}
}
}
},
"ConfigureComponent": {
"type": "object",
"properties": {
"isContainer": {
"type": "boolean"
},
"isModal": {
"type": "boolean"
},
"descriptor": {
"type": "string"
},
"nestingRule": {
"type": "object",
"properties": {
"childWhitelist": {
"type": "array",
"items": {
"type": "string"
}
},
"parentWhitelist": {
"type": "array",
"items": {
"type": "string"
}
},
"descendantBlacklist": {
"type": "array",
"items": {
"type": "string"
}
},
"ancestorWhitelist": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"isNullNode": {
"type": "boolean"
},
"isLayout": {
"type": "boolean"
}
}
}
}
}

View File

@ -0,0 +1,63 @@
import test from 'ava';
import Materialize from '../src/Materialize';
import { IMaterializeOptions } from '../src/types';
import { getFromFixtures } from './helpers';
const multiExportedComptPath = getFromFixtures('multiple-exported-component');
const singleExportedComptPath = getFromFixtures('single-exported-component');
const singleExportedComponent = '@ali/demo-biz-test090702@0.0.2';
const multipleExportedComponent = '@ali/aimake-basic@0.1.0';
test('materialize single exported component by local', async t => {
const options: IMaterializeOptions = {
cwd: singleExportedComptPath,
entry: singleExportedComptPath,
accesser: 'local',
isExportedAsMultiple: false,
};
const instance = new Materialize(options);
const actual = await instance.start();
t.snapshot(actual);
});
// test('materialize multiple exported component by local', async t => {
// const options: IMaterializeOptions = {
// cwd: multiExportedComptPath,
// entry: multiExportedComptPath,
// accesser: 'local',
// isExportedAsMultiple: true,
// };
// const instance = new Materialize(options);
// const actual = await instance.start();
// t.snapshot(actual);
// });
// test('materialize single exported component by online', async t => {
// const options: IMaterializeOptions = {
// entry: singleExportedComponent,
// accesser: 'online',
// isExportedAsMultiple: false,
// };
// const instance = new Materialize(options);
// const actual = await instance.start();
// t.snapshot(actual);
// });
// test('materialize multiple exported component by online', async t => {
// const options: IMaterializeOptions = {
// entry: multipleExportedComponent,
// accesser: 'online',
// isExportedAsMultiple: false,
// };
// const instance = new Materialize(options);
// const actual = await instance.start();
// t.snapshot(actual);
// });

View File

@ -0,0 +1,29 @@
import test from 'ava';
import LocalAccesser from '../../src/accesser/LocalAccesser';
import { IMaterializeOptions } from '../../src/types';
import { getFromFixtures } from '../helpers';
const multiExportedComptPath = getFromFixtures('multiple-exported-component');
const singleExportedComptPath = getFromFixtures('single-exported-component');
test.serial('access single exported component by local', async t => {
const options: IMaterializeOptions = {
entry: singleExportedComptPath,
accesser: 'local',
isExportedAsMultiple: false,
};
const accesser = new LocalAccesser(options);
const actual = await accesser.access();
t.snapshot(actual);
});
// test.serial('access multiple exported component by local', async t => {
// const options: IMaterializeOptions = {
// entry: multiExportedComptPath,
// accesser: 'local',
// isExportedAsMultiple: true,
// };
// const accesser = new LocalAccesser(options);
// const actual = await accesser.access();
// t.snapshot(actual);
// });

View File

@ -0,0 +1,42 @@
import test from 'ava';
import OnlineAccesser from '../../src/accesser/OnlineAccesser';
import { IMaterializeOptions } from '../../src/types';
const singleExportedComponent = '@ali/demo-biz-test090702@0.0.2';
const multipleExportedComponent = '@ali/aimake-basic@0.1.0';
test.serial('online accesser', t => {
t.pass();
})
// test.serial('access single exported component by online', async t => {
// const options: IMaterializeOptions = {
// entry: singleExportedComponent,
// accesser: 'online',
// isExportedAsMultiple: false,
// };
// const accesser = new OnlineAccesser(options);
// const actual = await accesser.access();
// t.snapshot(actual);
// });
// test.serial('access multiple exported component by online', async t => {
// const options: IMaterializeOptions = {
// entry: multipleExportedComponent,
// accesser: 'online',
// isExportedAsMultiple: true,
// };
// const accesser = new OnlineAccesser(options);
// const actual = await accesser.access();
// t.snapshot(actual);
// });
// test.serial('access @alifd/next@1.17.12 by online', async t => {
// const options: IMaterializeOptions = {
// entry: '@alifd/next@1.17.12',
// accesser: 'online',
// isExportedAsMultiple: true,
// };
// const accesser = new OnlineAccesser(options);
// const actual = await accesser.access();
// t.snapshot(actual);
// });

View File

@ -0,0 +1,529 @@
# Snapshot report for `test/accesser/LocalAccesser.ts`
The actual snapshot is saved in `LocalAccesser.ts.snap`.
Generated by [AVA](https://ava.li).
## access multiple exported component by local
> Snapshot 1
[
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/manifest.js',
manifestJS: 'export default {"name":"AIMakeBlank","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"styleFlexLayout","label":"styleFlexLayout","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"},{"name":"id","label":"id","renderer":""}]}}',
manifestObj: {
name: 'AIMakeBlank',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleFlexLayout',
name: 'styleFlexLayout',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
{
defaultValue: undefined,
label: 'id',
name: 'id',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/manifest.js',
manifestJS: 'export default {"name":"AIMakeIcon","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"className","label":"className","renderer":""},{"name":"iconClassName","label":"iconClassName","renderer":""},{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleText","label":"styleText","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeIcon',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'className',
name: 'className',
renderer: '',
},
{
defaultValue: undefined,
label: 'iconClassName',
name: 'iconClassName',
renderer: '',
},
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleText',
name: 'styleText',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/manifest.js',
manifestJS: 'export default {"name":"AIMakeImage","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeImage',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/manifest.js',
manifestJS: 'export default {"name":"AIMakeLink","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleText","label":"styleText","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeLink',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleText',
name: 'styleText',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/manifest.js',
manifestJS: 'export default {"name":"AIMakePlaceholder","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakePlaceholder',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/manifest.js',
manifestJS: 'export default {"name":"AIMakeText","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"type","label":"type","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleText","label":"styleText","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeText',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'type',
name: 'type',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleText',
name: 'styleText',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/manifest.js',
manifestJS: 'export default {"name":"Root","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"style","label":"style","renderer":"","defaultValue":"{\\n padding: 0,\\n backgroundColor: \'#f0f2f5\',\\n minHeight: \'100%\'\\n}"},{"name":"children","label":"children","renderer":""}]}}',
manifestObj: {
name: 'Root',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: `{␊
padding: 0,␊
backgroundColor: '#f0f2f5',␊
minHeight: '100%'␊
}`,
label: 'style',
name: 'style',
renderer: '',
},
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
]
## access single exported component by local
> Snapshot 1
[
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/manifest.js',
manifestJS: 'export default {"name":"Demo","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"optionalArray","label":"optionalArray","renderer":""},{"name":"optionalBool","label":"optionalBool","renderer":""},{"name":"optionalFunc","label":"optionalFunc","renderer":""},{"name":"optionalNumber","label":"optionalNumber","renderer":""},{"name":"optionalObject","label":"optionalObject","renderer":""},{"name":"optionalString","label":"optionalString","renderer":""},{"name":"optionalSymbol","label":"optionalSymbol","renderer":""},{"name":"optionalNode","label":"optionalNode","renderer":""},{"name":"optionalElement","label":"optionalElement","renderer":""},{"name":"optionalElementType","label":"optionalElementType","renderer":""},{"name":"optionalMessage","label":"optionalMessage","renderer":""},{"name":"optionalEnum","label":"optionalEnum","renderer":""},{"name":"optionalUnion","label":"optionalUnion","renderer":""},{"name":"optionalArrayOf","label":"optionalArrayOf","renderer":""},{"name":"optionalObjectOf","label":"optionalObjectOf","renderer":""},{"name":"optionalObjectWithShape","label":"optionalObjectWithShape","renderer":""},{"name":"optionalObjectWithShape2","label":"optionalObjectWithShape2","renderer":""},{"name":"optionalObjectWithStrictShape","label":"optionalObjectWithStrictShape","renderer":""},{"name":"requiredFunc","label":"requiredFunc","renderer":""},{"name":"requiredAny","label":"requiredAny","renderer":""}]}}',
manifestObj: {
name: 'Demo',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'optionalArray',
name: 'optionalArray',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalBool',
name: 'optionalBool',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalFunc',
name: 'optionalFunc',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalNumber',
name: 'optionalNumber',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalObject',
name: 'optionalObject',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalString',
name: 'optionalString',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalSymbol',
name: 'optionalSymbol',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalNode',
name: 'optionalNode',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalElement',
name: 'optionalElement',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalElementType',
name: 'optionalElementType',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalMessage',
name: 'optionalMessage',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalEnum',
name: 'optionalEnum',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalUnion',
name: 'optionalUnion',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalArrayOf',
name: 'optionalArrayOf',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalObjectOf',
name: 'optionalObjectOf',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalObjectWithShape',
name: 'optionalObjectWithShape',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalObjectWithShape2',
name: 'optionalObjectWithShape2',
renderer: '',
},
{
defaultValue: undefined,
label: 'optionalObjectWithStrictShape',
name: 'optionalObjectWithStrictShape',
renderer: '',
},
{
defaultValue: undefined,
label: 'requiredFunc',
name: 'requiredFunc',
renderer: '',
},
{
defaultValue: undefined,
label: 'requiredAny',
name: 'requiredAny',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
]

View File

@ -0,0 +1,408 @@
# Snapshot report for `test/accesser/OnlineAccesser.ts`
The actual snapshot is saved in `OnlineAccesser.ts.snap`.
Generated by [AVA](https://ava.li).
## access multiple exported component by online
> Snapshot 1
[
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/AIMakeBlank/manifest.js',
manifestJS: 'export default {"name":"AIMakeBlank","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"styleFlexLayout","label":"styleFlexLayout","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"},{"name":"id","label":"id","renderer":""}]}}',
manifestObj: {
name: 'AIMakeBlank',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleFlexLayout',
name: 'styleFlexLayout',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
{
defaultValue: undefined,
label: 'id',
name: 'id',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/AIMakeIcon/manifest.js',
manifestJS: 'export default {"name":"AIMakeIcon","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"className","label":"className","renderer":""},{"name":"iconClassName","label":"iconClassName","renderer":""},{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleText","label":"styleText","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeIcon',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'className',
name: 'className',
renderer: '',
},
{
defaultValue: undefined,
label: 'iconClassName',
name: 'iconClassName',
renderer: '',
},
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleText',
name: 'styleText',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/AIMakeImage/manifest.js',
manifestJS: 'export default {"name":"AIMakeImage","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeImage',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/AIMakeLink/manifest.js',
manifestJS: 'export default {"name":"AIMakeLink","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleText","label":"styleText","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeLink',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleText',
name: 'styleText',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/AIMakePlaceholder/manifest.js',
manifestJS: 'export default {"name":"AIMakePlaceholder","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakePlaceholder',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/AIMakeText/manifest.js',
manifestJS: 'export default {"name":"AIMakeText","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"children","label":"children","renderer":""},{"name":"type","label":"type","renderer":""},{"name":"styleBoxModel","label":"styleBoxModel","renderer":""},{"name":"styleText","label":"styleText","renderer":""},{"name":"styleLayout","label":"styleLayout","renderer":""},{"name":"styleBackground","label":"styleBackground","renderer":""},{"name":"style","label":"style","renderer":"","defaultValue":"{}"}]}}',
manifestObj: {
name: 'AIMakeText',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
{
defaultValue: undefined,
label: 'type',
name: 'type',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBoxModel',
name: 'styleBoxModel',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleText',
name: 'styleText',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleLayout',
name: 'styleLayout',
renderer: '',
},
{
defaultValue: undefined,
label: 'styleBackground',
name: 'styleBackground',
renderer: '',
},
{
defaultValue: '{}',
label: 'style',
name: 'style',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/kDKCQ3wGKzpHh6KU5ExdE1/node_modules/@ali/aimake-basic/es/basic/Root/manifest.js',
manifestJS: 'export default {"name":"Root","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[{"name":"style","label":"style","renderer":"","defaultValue":"{\\n padding: 0,\\n backgroundColor: \'#f0f2f5\',\\n minHeight: \'100%\'\\n}"},{"name":"children","label":"children","renderer":""}]}}',
manifestObj: {
name: 'Root',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [
{
defaultValue: `{␊
padding: 0,␊
backgroundColor: '#f0f2f5',␊
minHeight: '100%'␊
}`,
label: 'style',
name: 'style',
renderer: '',
},
{
defaultValue: undefined,
label: 'children',
name: 'children',
renderer: '',
},
],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
]
## access single exported component by online
> Snapshot 1
[
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/node_modules/.temp/todtaTTK9KxDGepu5Kbb9G/node_modules/@ali/demo-biz-test090702/es/manifest.js',
manifestJS: 'export default {"name":"Demo","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}',
manifestObj: {
name: 'Demo',
settings: {
handles: [
'cut',
'copy',
'duplicate',
'delete',
'paste',
],
insertionModes: 'tbrl',
props: [],
shouldActive: true,
shouldDrag: true,
type: 'element_inline',
},
},
},
]

View File

@ -0,0 +1,188 @@
# Snapshot report for `test/Materialize.ts`
The actual snapshot is saved in `Materialize.ts.snap`.
Generated by [AVA](https://avajs.dev).
## materialize single exported component by local
> Snapshot 1
[
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json',
manifestObj: {
docUrl: '',
npm: {
destructuring: false,
exportName: '',
main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js',
package: 'single-exported-component',
subName: '',
version: '1.0.0',
},
props: [
{
name: 'optionalArray',
propType: 'array',
},
{
name: 'optionalBool',
propType: 'bool',
},
{
name: 'optionalFunc',
propType: 'func',
},
{
defaultValue: 123,
name: 'optionalNumber',
propType: 'number',
},
{
name: 'optionalObject',
propType: 'object',
},
{
name: 'optionalString',
propType: 'string',
},
{
name: 'optionalSymbol',
propType: 'symbol',
},
{
name: 'optionalNode',
propType: 'node',
},
{
name: 'optionalElement',
propType: 'element',
},
{
name: 'optionalElementType',
propType: 'elementType',
},
{
name: 'optionalMessage',
propType: {
type: 'instanceOf',
value: 'Demo',
},
},
{
name: 'optionalEnum',
propType: {
type: 'oneOf',
value: [
'News',
'Photos',
],
},
},
{
name: 'optionalUnion',
propType: {
type: 'oneOfType',
value: [
'string',
'number',
{
type: 'instanceOf',
value: 'Demo',
},
],
},
},
{
name: 'optionalArrayOf',
propType: {
type: 'arrayOf',
value: 'number',
},
},
{
name: 'optionalObjectOf',
propType: {
type: 'objectOf',
value: 'number',
},
},
{
name: 'optionalObjectWithShape',
propType: {
type: 'shape',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'optionalObjectWithShape2',
propType: {
isRequired: true,
type: 'shape',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'optionalObjectWithStrictShape',
propType: {
type: 'exact',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'requiredFunc',
propType: {
isRequired: true,
type: 'func',
},
},
{
name: 'requiredAny',
propType: {
isRequired: true,
type: 'any',
},
},
],
screenshot: '',
title: 'single-exported-component',
},
},
]

View File

@ -0,0 +1,188 @@
# Snapshot report for `test/accesser/LocalAccesser.ts`
The actual snapshot is saved in `LocalAccesser.ts.snap`.
Generated by [AVA](https://avajs.dev).
## access single exported component by local
> Snapshot 1
[
{
manifestFilePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/manifest.json',
manifestObj: {
docUrl: '',
npm: {
destructuring: false,
exportName: '',
main: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js',
package: '@ali/lowcode-engine-material-parser',
subName: '',
version: '0.1.0',
},
props: [
{
name: 'optionalArray',
propType: 'array',
},
{
name: 'optionalBool',
propType: 'bool',
},
{
name: 'optionalFunc',
propType: 'func',
},
{
defaultValue: 123,
name: 'optionalNumber',
propType: 'number',
},
{
name: 'optionalObject',
propType: 'object',
},
{
name: 'optionalString',
propType: 'string',
},
{
name: 'optionalSymbol',
propType: 'symbol',
},
{
name: 'optionalNode',
propType: 'node',
},
{
name: 'optionalElement',
propType: 'element',
},
{
name: 'optionalElementType',
propType: 'elementType',
},
{
name: 'optionalMessage',
propType: {
type: 'instanceOf',
value: 'Demo',
},
},
{
name: 'optionalEnum',
propType: {
type: 'oneOf',
value: [
'News',
'Photos',
],
},
},
{
name: 'optionalUnion',
propType: {
type: 'oneOfType',
value: [
'string',
'number',
{
type: 'instanceOf',
value: 'Demo',
},
],
},
},
{
name: 'optionalArrayOf',
propType: {
type: 'arrayOf',
value: 'number',
},
},
{
name: 'optionalObjectOf',
propType: {
type: 'objectOf',
value: 'number',
},
},
{
name: 'optionalObjectWithShape',
propType: {
type: 'shape',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'optionalObjectWithShape2',
propType: {
isRequired: true,
type: 'shape',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'optionalObjectWithStrictShape',
propType: {
type: 'exact',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'requiredFunc',
propType: {
isRequired: true,
type: 'func',
},
},
{
name: 'requiredAny',
propType: {
isRequired: true,
type: 'any',
},
},
],
screenshot: '',
title: '@ali/lowcode-engine-material-parser',
},
},
]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,474 @@
# Snapshot report for `test/parser/ReactParser.ts`
The actual snapshot is saved in `ReactParser.ts.snap`.
Generated by [AVA](https://avajs.dev).
## parse es6 multiple exported component by local
> Snapshot 1
[
{
defaultExportName: 'AIMakeBlank',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/index.js',
props: [
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
{
type: 'arrayOf',
value: 'node',
},
'node',
],
},
},
{
name: 'styleBoxModel',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleLayout',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleBackground',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleFlexLayout',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'style',
propType: 'object',
},
{
name: 'id',
propType: 'string',
},
],
},
{
defaultExportName: 'AIMakeIcon',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/index.js',
props: [
{
name: 'className',
propType: 'string',
},
{
name: 'iconClassName',
propType: 'string',
},
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
{
type: 'arrayOf',
value: 'node',
},
'node',
],
},
},
{
name: 'styleBoxModel',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleText',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleBackground',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'style',
propType: 'object',
},
],
},
{
defaultExportName: 'AIMakeImage',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/index.js',
props: [
{
name: 'styleBoxModel',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'style',
propType: 'object',
},
],
},
{
defaultExportName: 'AIMakeLink',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/index.js',
props: [
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
{
type: 'arrayOf',
value: 'node',
},
'node',
],
},
},
{
name: 'styleBoxModel',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleText',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleLayout',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleBackground',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'style',
propType: 'object',
},
],
},
{
defaultExportName: 'AIMakePlaceholder',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/index.js',
props: [
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
{
type: 'arrayOf',
value: 'node',
},
'node',
],
},
},
{
name: 'styleBoxModel',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleLayout',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'style',
propType: 'object',
},
],
},
{
defaultExportName: 'AIMakeText',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/index.js',
props: [
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
{
type: 'arrayOf',
value: 'node',
},
'node',
'string',
],
},
},
{
name: 'type',
propType: 'string',
},
{
name: 'styleBoxModel',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleText',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleLayout',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'styleBackground',
propType: {
isRequired: true,
type: 'object',
},
},
{
name: 'style',
propType: 'object',
},
],
},
{
defaultExportName: 'Root',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/index.js',
props: [
{
name: 'style',
propType: 'object',
},
{
name: 'children',
propType: {
type: 'oneOfType',
value: [
'element',
{
type: 'arrayOf',
value: 'element',
},
],
},
},
],
},
]
## parse es6 single exported component by local
> Snapshot 1
[
{
defaultExportName: 'Demo',
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js',
props: [
{
name: 'optionalArray',
propType: 'array',
},
{
name: 'optionalBool',
propType: 'bool',
},
{
name: 'optionalFunc',
propType: 'func',
},
{
defaultValue: 123,
name: 'optionalNumber',
propType: 'number',
},
{
name: 'optionalObject',
propType: 'object',
},
{
name: 'optionalString',
propType: 'string',
},
{
name: 'optionalSymbol',
propType: 'symbol',
},
{
name: 'optionalNode',
propType: 'node',
},
{
name: 'optionalElement',
propType: 'element',
},
{
name: 'optionalElementType',
propType: 'elementType',
},
{
name: 'optionalMessage',
propType: {
type: 'instanceOf',
value: 'Demo',
},
},
{
name: 'optionalEnum',
propType: {
type: 'oneOf',
value: [
'News',
'Photos',
],
},
},
{
name: 'optionalUnion',
propType: {
type: 'oneOfType',
value: [
'string',
'number',
{
type: 'instanceOf',
value: 'Demo',
},
],
},
},
{
name: 'optionalArrayOf',
propType: {
type: 'arrayOf',
value: 'number',
},
},
{
name: 'optionalObjectOf',
propType: {
type: 'objectOf',
value: 'number',
},
},
{
name: 'optionalObjectWithShape',
propType: {
type: 'shape',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'optionalObjectWithShape2',
propType: {
isRequired: true,
type: 'shape',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'optionalObjectWithStrictShape',
propType: {
type: 'exact',
value: [
{
name: 'optionalProperty',
propType: 'string',
},
{
name: 'requiredProperty',
propType: {
isRequired: true,
type: 'number',
},
},
],
},
},
{
name: 'requiredFunc',
propType: {
isRequired: true,
type: 'func',
},
},
{
name: 'requiredAny',
propType: {
isRequired: true,
type: 'any',
},
},
],
},
]

View File

@ -0,0 +1,623 @@
# Snapshot report for `test/scanner/Scanner.ts`
The actual snapshot is saved in `Scanner.ts.snap`.
Generated by [AVA](https://avajs.dev).
## scan multiple exported component
> Snapshot 1
{
mainEntry: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/index.js',
modules: [
{
fileContent: `import _extends from "@babel/runtime/helpers/extends";␊
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React, { Component } from 'react';␊
import PropTypes from 'prop-types';␊
import HOCBoxModelProps from '../utils/HOCBoxModelProps';␊
import HOCLayoutProps from '../utils/HOCLayoutProps';␊
import HOCBackgroundProps from '../utils/HOCBackgroundProps';␊
import HOCFlexLayoutProps from '../utils/HOCFlexLayoutProps';␊
var AIMakeBlank =␊
/*#__PURE__*/␊
function (_Component) {␊
_inherits(AIMakeBlank, _Component);␊
function AIMakeBlank() {␊
_classCallCheck(this, AIMakeBlank);␊
return _possibleConstructorReturn(this, _getPrototypeOf(AIMakeBlank).apply(this, arguments));␊
}␊
_createClass(AIMakeBlank, [{␊
key: "render",␊
value: function render() {␊
var merged = {};␊
var _this$props = this.props,␊
children = _this$props.children,␊
styleBoxModel = _this$props.styleBoxModel,␊
styleLayout = _this$props.styleLayout,␊
styleBackground = _this$props.styleBackground,␊
styleFlexLayout = _this$props.styleFlexLayout,␊
style = _this$props.style,␊
id = _this$props.id;␊
var styles = { ...styleBoxModel,␊
...styleLayout,␊
...styleBackground,␊
...styleFlexLayout,␊
...style␊
};␊
if (id) {␊
merged.id = id;␊
}␊
return React.createElement("div", _extends({␊
style: styles␊
}, merged), children);␊
}␊
}]);␊
return AIMakeBlank;␊
}(Component);␊
_defineProperty(AIMakeBlank, "propTypes", {␊
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),␊
styleBoxModel: PropTypes.object.isRequired,␊
styleLayout: PropTypes.object.isRequired,␊
styleBackground: PropTypes.object.isRequired,␊
styleFlexLayout: PropTypes.object.isRequired,␊
style: PropTypes.object,␊
id: PropTypes.string␊
});␊
_defineProperty(AIMakeBlank, "defaultProps", {␊
children: [],␊
style: {},␊
id: ''␊
});␊
export default HOCBoxModelProps(HOCLayoutProps(HOCBackgroundProps(HOCFlexLayoutProps(AIMakeBlank))));`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeBlank/index.js',
},
{
fileContent: `import _extends from "@babel/runtime/helpers/extends";␊
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";␊
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React, { Component } from 'react';␊
import PropTypes from 'prop-types';␊
import classNames from 'classnames';␊
import createFromIconfont from './IconFont';␊
var AIMakeIcon =␊
/*#__PURE__*/␊
function (_Component) {␊
_inherits(AIMakeIcon, _Component);␊
function AIMakeIcon() {␊
_classCallCheck(this, AIMakeIcon);␊
return _possibleConstructorReturn(this, _getPrototypeOf(AIMakeIcon).apply(this, arguments));␊
}␊
_createClass(AIMakeIcon, [{␊
key: "render",␊
value: function render() {␊
var _this$props = this.props,␊
className = _this$props.className,␊
iconClassName = _this$props.iconClassName,␊
children = _this$props.children,␊
styleBoxModel = _this$props.styleBoxModel,␊
styleText = _this$props.styleText,␊
styleBackground = _this$props.styleBackground,␊
style = _this$props.style,␊
otherProps = _objectWithoutProperties(_this$props, ["className", "iconClassName", "children", "styleBoxModel", "styleText", "styleBackground", "style"]);␊
var styles = { ...styleBoxModel,␊
...styleText,␊
...styleBackground,␊
...style␊
};␊
return React.createElement("i", _extends({}, otherProps, {␊
className: classNames(className, iconClassName),␊
style: styles␊
}), children);␊
}␊
}]);␊
return AIMakeIcon;␊
}(Component);␊
_defineProperty(AIMakeIcon, "propTypes", {␊
className: PropTypes.string,␊
iconClassName: PropTypes.string,␊
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),␊
styleBoxModel: PropTypes.object.isRequired,␊
styleText: PropTypes.object.isRequired,␊
styleBackground: PropTypes.object.isRequired,␊
style: PropTypes.object␊
});␊
_defineProperty(AIMakeIcon, "defaultProps", {␊
className: '',␊
iconClassName: 'iconfont',␊
children: '',␊
style: {}␊
});␊
AIMakeIcon.createFromIconfont = createFromIconfont;␊
export default AIMakeIcon;`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeIcon/index.js',
},
{
fileContent: `import _extends from "@babel/runtime/helpers/extends";␊
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";␊
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React, { Component } from 'react';␊
import PropTypes from 'prop-types';␊
import HOCBoxModelProps from '../utils/HOCBoxModelProps';␊
var AIMakeImage =␊
/*#__PURE__*/␊
function (_Component) {␊
_inherits(AIMakeImage, _Component);␊
function AIMakeImage() {␊
_classCallCheck(this, AIMakeImage);␊
return _possibleConstructorReturn(this, _getPrototypeOf(AIMakeImage).apply(this, arguments));␊
}␊
_createClass(AIMakeImage, [{␊
key: "render",␊
value: function render() {␊
var _this$props = this.props,␊
styleBoxModel = _this$props.styleBoxModel,␊
style = _this$props.style,␊
otherProps = _objectWithoutProperties(_this$props, ["styleBoxModel", "style"]);␊
var styles = { ...styleBoxModel,␊
...style␊
};␊
return React.createElement("img", _extends({}, otherProps, {␊
style: styles,␊
alt: "AIMakeImage"␊
}));␊
}␊
}]);␊
return AIMakeImage;␊
}(Component);␊
_defineProperty(AIMakeImage, "propTypes", {␊
styleBoxModel: PropTypes.object.isRequired,␊
style: PropTypes.object␊
});␊
_defineProperty(AIMakeImage, "defaultProps", {␊
style: {}␊
});␊
export default HOCBoxModelProps(AIMakeImage);`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeImage/index.js',
},
{
fileContent: `import _extends from "@babel/runtime/helpers/extends";␊
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";␊
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React, { Component } from 'react';␊
import PropTypes from 'prop-types';␊
import HOCBoxModelProps from '../utils/HOCBoxModelProps';␊
import HOCTextProps from '../utils/HOCTextProps';␊
import HOCLayoutProps from '../utils/HOCLayoutProps';␊
import HOCBackgroundProps from '../utils/HOCBackgroundProps';␊
var AIMakeLink =␊
/*#__PURE__*/␊
function (_Component) {␊
_inherits(AIMakeLink, _Component);␊
function AIMakeLink() {␊
_classCallCheck(this, AIMakeLink);␊
return _possibleConstructorReturn(this, _getPrototypeOf(AIMakeLink).apply(this, arguments));␊
}␊
_createClass(AIMakeLink, [{␊
key: "render",␊
value: function render() {␊
var _this$props = this.props,␊
children = _this$props.children,␊
styleBoxModel = _this$props.styleBoxModel,␊
styleText = _this$props.styleText,␊
styleLayout = _this$props.styleLayout,␊
styleBackground = _this$props.styleBackground,␊
style = _this$props.style,␊
otherProps = _objectWithoutProperties(_this$props, ["children", "styleBoxModel", "styleText", "styleLayout", "styleBackground", "style"]);␊
var styles = { ...styleBoxModel,␊
...styleText,␊
...styleLayout,␊
...styleBackground,␊
...style␊
};␊
if (typeof children !== 'string') {␊
styles.display = 'inline-block';␊
}␊
return React.createElement("a", _extends({}, otherProps, {␊
style: styles␊
}), [children]);␊
}␊
}]);␊
return AIMakeLink;␊
}(Component);␊
_defineProperty(AIMakeLink, "propTypes", {␊
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),␊
styleBoxModel: PropTypes.object.isRequired,␊
styleText: PropTypes.object.isRequired,␊
styleLayout: PropTypes.object.isRequired,␊
styleBackground: PropTypes.object.isRequired,␊
style: PropTypes.object␊
});␊
_defineProperty(AIMakeLink, "defaultProps", {␊
children: '',␊
style: {}␊
});␊
export default HOCBoxModelProps(HOCTextProps(HOCLayoutProps(HOCBackgroundProps(AIMakeLink))));`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeLink/index.js',
},
{
fileContent: `import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React, { Component } from 'react';␊
import PropTypes from 'prop-types';␊
import HOCBoxModelProps from '../utils/HOCBoxModelProps';␊
import HOCLayoutProps from '../utils/HOCLayoutProps';␊
var AIMakePlaceholder =␊
/*#__PURE__*/␊
function (_Component) {␊
_inherits(AIMakePlaceholder, _Component);␊
function AIMakePlaceholder() {␊
_classCallCheck(this, AIMakePlaceholder);␊
return _possibleConstructorReturn(this, _getPrototypeOf(AIMakePlaceholder).apply(this, arguments));␊
}␊
_createClass(AIMakePlaceholder, [{␊
key: "render",␊
value: function render() {␊
var _this$props = this.props,␊
children = _this$props.children,␊
styleBoxModel = _this$props.styleBoxModel,␊
styleLayout = _this$props.styleLayout,␊
style = _this$props.style;␊
var styles = { ...styleBoxModel,␊
...styleLayout,␊
...style␊
};␊
var placeholderStyle = {␊
display: 'inline-block',␊
border: '1px dashed #aaa',␊
lineHeight: styles.height,␊
backgroundColor: '#F5E075',␊
overflow: 'hidden',␊
textAlign: 'center',␊
...styles␊
};␊
return React.createElement("div", {␊
style: placeholderStyle␊
}, children);␊
}␊
}]);␊
return AIMakePlaceholder;␊
}(Component);␊
_defineProperty(AIMakePlaceholder, "propTypes", {␊
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),␊
styleBoxModel: PropTypes.object.isRequired,␊
styleLayout: PropTypes.object.isRequired,␊
style: PropTypes.object␊
});␊
_defineProperty(AIMakePlaceholder, "defaultProps", {␊
children: '',␊
style: {}␊
});␊
export default HOCBoxModelProps(HOCLayoutProps(AIMakePlaceholder));`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakePlaceholder/index.js',
},
{
fileContent: `import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React, { Component } from 'react';␊
import PropTypes from 'prop-types';␊
import HOCBoxModelProps from '../utils/HOCBoxModelProps';␊
import HOCTextProps from '../utils/HOCTextProps';␊
import HOCLayoutProps from '../utils/HOCLayoutProps';␊
import HOCBackgroundProps from '../utils/HOCBackgroundProps';␊
var AIMakeText =␊
/*#__PURE__*/␊
function (_Component) {␊
_inherits(AIMakeText, _Component);␊
function AIMakeText() {␊
var _this;␊
_classCallCheck(this, AIMakeText);␊
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];␊
}␊
_this = _possibleConstructorReturn(this, _getPrototypeOf(AIMakeText).call(this, ...args));␊
_defineProperty(_assertThisInitialized(_this), "generateComponentType", function (componentType) {␊
var componentNameMap = {␊
h1: 'h1',␊
h2: 'h2',␊
h3: 'h3',␊
h4: 'h4',␊
h5: 'h5',␊
paragraph: 'p',␊
label: 'label'␊
};␊
return componentNameMap[componentType] || 'div';␊
});␊
return _this;␊
}␊
_createClass(AIMakeText, [{␊
key: "render",␊
value: function render() {␊
var _this$props = this.props,␊
children = _this$props.children,␊
type = _this$props.type,␊
styleBoxModel = _this$props.styleBoxModel,␊
styleText = _this$props.styleText,␊
styleLayout = _this$props.styleLayout,␊
styleBackground = _this$props.styleBackground,␊
style = _this$props.style;␊
var styles = { ...styleBoxModel,␊
...styleText,␊
...styleLayout,␊
...styleBackground,␊
...style␊
};␊
var Comp = this.generateComponentType(type);␊
var labelStyle = Comp === 'label' ? {␊
display: 'inline-block'␊
} : {};␊
return React.createElement(Comp, {␊
className: "AIMakeText",␊
style: Object.assign(labelStyle, styles)␊
}, [children]);␊
}␊
}]);␊
return AIMakeText;␊
}(Component);␊
_defineProperty(AIMakeText, "propTypes", {␊
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node, PropTypes.string]),␊
type: PropTypes.string,␊
styleBoxModel: PropTypes.object.isRequired,␊
styleText: PropTypes.object.isRequired,␊
styleLayout: PropTypes.object.isRequired,␊
styleBackground: PropTypes.object.isRequired,␊
style: PropTypes.object␊
});␊
_defineProperty(AIMakeText, "defaultProps", {␊
children: '',␊
type: '',␊
// paragraph || label␊
style: {}␊
});␊
export default HOCBoxModelProps(HOCTextProps(HOCLayoutProps(HOCBackgroundProps(AIMakeText))));`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/AIMakeText/index.js',
},
{
fileContent: `import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
import _defineProperty from "@babel/runtime/helpers/defineProperty";␊
import React from 'react';␊
import PropTypes from 'prop-types';␊
var Root =␊
/*#__PURE__*/␊
function (_React$Component) {␊
_inherits(Root, _React$Component);␊
function Root() {␊
_classCallCheck(this, Root);␊
return _possibleConstructorReturn(this, _getPrototypeOf(Root).apply(this, arguments));␊
}␊
_createClass(Root, [{␊
key: "render",␊
value: function render() {␊
var _this$props = this.props,␊
style = _this$props.style,␊
children = _this$props.children;␊
var newStyle = Object.assign({}, Root.defaultProps.style, style);␊
return React.createElement("div", {␊
style: newStyle␊
}, children);␊
}␊
}]);␊
return Root;␊
}(React.Component);␊
_defineProperty(Root, "propTypes", {␊
style: PropTypes.object,␊
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)])␊
});␊
_defineProperty(Root, "defaultProps", {␊
style: {␊
padding: 0,␊
backgroundColor: '#f0f2f5',␊
minHeight: '100%'␊
},␊
children: null␊
});␊
export default Root;`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/multiple-exported-component/es/basic/Root/index.js',
},
],
pkgName: 'multiple-exported-component',
pkgVersion: '1.0.0',
sourceType: 'module',
}
## scan single exported component
> Snapshot 1
{
mainEntry: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js',
modules: [
{
fileContent: `import _classCallCheck from "@babel/runtime/helpers/classCallCheck";␊
import _createClass from "@babel/runtime/helpers/createClass";␊
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";␊
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";␊
import _inherits from "@babel/runtime/helpers/inherits";␊
/* eslint-disable react/no-unused-prop-types */␊
/* eslint-disable react/require-default-props */␊
import React from 'react';␊
import PropTypes from 'prop-types';␊
import "./main.css";␊
var Demo =␊
/*#__PURE__*/␊
function (_React$Component) {␊
_inherits(Demo, _React$Component);␊
function Demo() {␊
_classCallCheck(this, Demo);␊
return _possibleConstructorReturn(this, _getPrototypeOf(Demo).apply(this, arguments));␊
}␊
_createClass(Demo, [{␊
key: "render",␊
value: function render() {␊
return React.createElement("div", null, " Test ");␊
}␊
}]);␊
return Demo;␊
}(React.Component);␊
Demo.propTypes = {␊
optionalArray: PropTypes.array,␊
optionalBool: PropTypes.bool,␊
optionalFunc: PropTypes.func,␊
optionalNumber: PropTypes.number,␊
optionalObject: PropTypes.object,␊
optionalString: PropTypes.string,␊
optionalSymbol: PropTypes.symbol,␊
// Anything that can be rendered: numbers, strings, elements or an array␊
// (or fragment) containing these types.␊
optionalNode: PropTypes.node,␊
// A React element (ie. <MyComponent />).␊
optionalElement: PropTypes.element,␊
// A React element type (ie. MyComponent).␊
optionalElementType: PropTypes.elementType,␊
// You can also declare that a prop is an instance of a class. This uses␊
// JS's instanceof operator.␊
optionalMessage: PropTypes.instanceOf(Demo),␊
// You can ensure that your prop is limited to specific values by treating␊
// it as an enum.␊
optionalEnum: PropTypes.oneOf(['News', 'Photos']),␊
// An object that could be one of many types␊
optionalUnion: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.instanceOf(Demo)]),␊
// An array of a certain type␊
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),␊
// An object with property values of a certain type␊
optionalObjectOf: PropTypes.objectOf(PropTypes.number),␊
// You can chain any of the above with `isRequired` to make sure a warning␊
// is shown if the prop isn't provided.␊
// An object taking on a particular shape␊
optionalObjectWithShape: PropTypes.shape({␊
optionalProperty: PropTypes.string,␊
requiredProperty: PropTypes.number.isRequired␊
}),␊
optionalObjectWithShape2: PropTypes.shape({␊
optionalProperty: PropTypes.string,␊
requiredProperty: PropTypes.number.isRequired␊
}).isRequired,␊
// An object with warnings on extra properties␊
optionalObjectWithStrictShape: PropTypes.exact({␊
optionalProperty: PropTypes.string,␊
requiredProperty: PropTypes.number.isRequired␊
}),␊
requiredFunc: PropTypes.func.isRequired,␊
// A value of any data type␊
requiredAny: PropTypes.any.isRequired␊
};␊
Demo.defaultProps = {␊
optionalNumber: 123␊
};␊
export default Demo;`,
filePath: '/Users/gengyang/code/frontend/low-code/ali-lowcode-engine/packages/material-parser/test/fixtures/single-exported-component/es/index.js',
},
],
pkgName: 'single-exported-component',
pkgVersion: '1.0.0',
sourceType: 'module',
}

View File

@ -0,0 +1,56 @@
# Snapshot report for `test/validate/index.ts`
The actual snapshot is saved in `index.ts.snap`.
Generated by [AVA](https://avajs.dev).
## should be right in dir basic-error
> Snapshot 1
{
errors: [
{
dataPath: '',
keyword: 'required',
message: 'should have required property \'props\'',
params: {
missingProperty: 'props',
},
schemaPath: '#/required',
},
],
success: false,
}
## should be right in dir basic-success
> Snapshot 1
{
success: true,
}
## should be right in dir configure
> Snapshot 1
{
success: true,
}
## should be right in dir props-basic-type
> Snapshot 1
{
success: true,
}
## should be right in dir props-complex-type
> Snapshot 1
{
success: true,
}

View File

@ -0,0 +1,14 @@
{
"name": "fusion-next-component",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@alife/next": "^1.17.12"
}
}

View File

@ -0,0 +1,5 @@
import Affix from './../../../../node_modules/@alife/next/es/affix/index.js';
import manifest from './manifest.js';
export default { origin: Affix, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Affix","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Animate from './../../../../node_modules/@alife/next/es/animate/index.js';
import manifest from './manifest.js';
export default { origin: Animate, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Animate","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Badge from './../../../../node_modules/@alife/next/es/badge/index.js';
import manifest from './manifest.js';
export default { origin: Badge, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Badge","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Balloon from './../../../../node_modules/@alife/next/es/balloon/index.js';
import manifest from './manifest.js';
export default { origin: Balloon, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Balloon","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Breadcrumb from './../../../../node_modules/@alife/next/es/breadcrumb/index.js';
import manifest from './manifest.js';
export default { origin: Breadcrumb, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Breadcrumb","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Button from './../../../../node_modules/@alife/next/es/button/index.js';
import manifest from './manifest.js';
export default { origin: Button, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Button","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Calendar from './../../../../node_modules/@alife/next/es/calendar/index.js';
import manifest from './manifest.js';
export default { origin: Calendar, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Calendar","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Card from './../../../../node_modules/@alife/next/es/card/index.js';
import manifest from './manifest.js';
export default { origin: Card, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Card","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import CascaderSelect from './../../../../node_modules/@alife/next/es/cascader-select/index.js';
import manifest from './manifest.js';
export default { origin: CascaderSelect, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"CascaderSelect","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Cascader from './../../../../node_modules/@alife/next/es/cascader/index.js';
import manifest from './manifest.js';
export default { origin: Cascader, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Cascader","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Checkbox from './../../../../node_modules/@alife/next/es/checkbox/index.js';
import manifest from './manifest.js';
export default { origin: Checkbox, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Checkbox","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Collapse from './../../../../node_modules/@alife/next/es/collapse/index.js';
import manifest from './manifest.js';
export default { origin: Collapse, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Collapse","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import ConfigProvider from './../../../../node_modules/@alife/next/es/config-provider/index.js';
import manifest from './manifest.js';
export default { origin: ConfigProvider, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"ConfigProvider","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import DatePicker from './../../../../node_modules/@alife/next/es/date-picker/index.js';
import manifest from './manifest.js';
export default { origin: DatePicker, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"DatePicker","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

View File

@ -0,0 +1,5 @@
import Dialog from './../../../../node_modules/@alife/next/es/dialog/index.js';
import manifest from './manifest.js';
export default { origin: Dialog, manifest };

View File

@ -0,0 +1 @@
const manifest = {"name":"Dialog","settings":{"type":"element_inline","insertionModes":"tbrl","handles":["cut","copy","duplicate","delete","paste"],"shouldActive":true,"shouldDrag":true,"props":[]}}; export default manifest;

Some files were not shown because too many files have changed in this diff Show More