From dcd1b33d3bf8bdf5577dcc980608d9eac8d99372 Mon Sep 17 00:00:00 2001 From: gengyang Date: Sun, 16 Feb 2020 22:26:26 +0800 Subject: [PATCH] feat: remove useless codes & modify generator --- packages/material-parser/schemas/schema.yml | 42 +- packages/material-parser/scripts/transform.js | 27 +- packages/material-parser/src/Materialize.ts | 4 +- .../src/accesser/BaseAccesser.ts | 4 +- .../src/accesser/LocalAccesser.ts | 6 +- .../src/accesser/OnlineAccesser.ts | 4 +- .../src/extensions/MatBuildBundle.ts | 18 - .../src/extensions/MatConfigContainer.ts | 31 -- .../src/extensions/MatConfigManifest.ts | 18 +- .../src/extensions/MatGenerateBuildJS.ts | 27 -- .../src/extensions/MatLoadMaterials.ts | 16 - .../material-parser/src/extensions/index.ts | 6 - .../src/generator/Generator.ts | 55 +-- .../src/otter-core/schema/types.ts | 387 ++++++++---------- .../material-parser/src/otter-core/types.ts | 18 - .../src/types/ExtensionName.ts | 8 - .../material-parser/src/types/IAccesser.ts | 4 +- .../src/types/IExtensionBuildBundle.ts | 10 - .../src/types/IExtensionConfigContainer.ts | 13 - .../src/types/IExtensionConfigManifest.ts | 8 +- .../src/types/IExtensionGenerateBuildJS.ts | 13 - .../src/types/IExtensionLoadMaterials.ts | 12 - .../material-parser/src/types/IGenerator.ts | 4 +- .../src/types/IMaterialInOptions.ts | 23 -- .../src/types/IMaterializeOptions.ts | 6 - packages/material-parser/src/types/index.ts | 8 - .../material-parser/src/validate/schema.d.ts | 179 ++++++++ .../material-parser/src/validate/schema.json | 3 + 28 files changed, 440 insertions(+), 514 deletions(-) delete mode 100644 packages/material-parser/src/extensions/MatBuildBundle.ts delete mode 100644 packages/material-parser/src/extensions/MatConfigContainer.ts delete mode 100644 packages/material-parser/src/extensions/MatGenerateBuildJS.ts delete mode 100644 packages/material-parser/src/extensions/MatLoadMaterials.ts delete mode 100644 packages/material-parser/src/types/IExtensionBuildBundle.ts delete mode 100644 packages/material-parser/src/types/IExtensionConfigContainer.ts delete mode 100644 packages/material-parser/src/types/IExtensionGenerateBuildJS.ts delete mode 100644 packages/material-parser/src/types/IExtensionLoadMaterials.ts delete mode 100644 packages/material-parser/src/types/IMaterialInOptions.ts create mode 100644 packages/material-parser/src/validate/schema.d.ts diff --git a/packages/material-parser/schemas/schema.yml b/packages/material-parser/schemas/schema.yml index 7ddc5ad9d..471812e32 100644 --- a/packages/material-parser/schemas/schema.yml +++ b/packages/material-parser/schemas/schema.yml @@ -1,4 +1,4 @@ -$id: '@ali/low-code-component-protocol-schema' +$id: "@ali/low-code-component-protocol-schema" description: json schema for low code component protocol allOf: - $ref: "#/definitions/BasicSection" @@ -20,7 +20,7 @@ definitions: type: string icon: type: string - tags: + tags: type: array items: type: string @@ -38,12 +38,14 @@ definitions: - screenshot PropsSection: type: object + required: + - props properties: props: type: array items: properties: - name: + name: type: string propType: $ref: "#/definitions/PropType" @@ -74,17 +76,17 @@ definitions: Npm: type: object properties: - package: + package: type: string - exportName: + exportName: type: string - subName: + subName: type: string - main: + main: type: string - destructuring: + destructuring: type: boolean - version: + version: type: string required: - package @@ -98,7 +100,7 @@ definitions: - $ref: "#/definitions/BasicType" - $ref: "#/definitions/RequiredType" - $ref: "#/definitions/ComplexType" - BasicType: + BasicType: type: string enum: - array @@ -113,7 +115,7 @@ definitions: RequiredType: type: object properties: - type: + type: $ref: "#/definitions/BasicType" isRequired: type: boolean @@ -250,7 +252,7 @@ definitions: allOf: - type: object properties: - title: + title: type: string extraProps: type: object @@ -263,7 +265,7 @@ definitions: required: - type properties: - type: + type: type: string enum: - field @@ -306,7 +308,7 @@ definitions: - type - items properties: - type: + type: type: string enum: - group @@ -326,21 +328,21 @@ definitions: nestingRule: type: object properties: - childWhitelist: + childWhitelist: type: array - items: + items: type: string parentWhitelist: type: array - items: + items: type: string - descendantBlacklist: + descendantBlacklist: type: array - items: + items: type: string ancestorWhitelist: type: array - items: + items: type: string isNullNode: type: boolean diff --git a/packages/material-parser/scripts/transform.js b/packages/material-parser/scripts/transform.js index b64b88a14..b07f55aa1 100644 --- a/packages/material-parser/scripts/transform.js +++ b/packages/material-parser/scripts/transform.js @@ -2,19 +2,26 @@ 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/schema.json'); +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 -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'); -} catch (e) { - console.log(e); - process.exit(1); -} +(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); + } +})(); diff --git a/packages/material-parser/src/Materialize.ts b/packages/material-parser/src/Materialize.ts index b1d92094f..06928f804 100644 --- a/packages/material-parser/src/Materialize.ts +++ b/packages/material-parser/src/Materialize.ts @@ -1,6 +1,6 @@ import LocalAccesser from './accesser/LocalAccesser'; import OnlineAccesser from './accesser/OnlineAccesser'; -import { IMaterialinSchema } from './otter-core'; +import { IComponentMaterial } from './otter-core'; import { IAccesser, IMaterializeOptions } from './types'; /** @@ -34,7 +34,7 @@ class Materialize { * @returns {Promise} * @memberof Materialize */ - public async start(): Promise { + public async start(): Promise { // 分发请求到对应接入器 if (this.options.accesser === 'local') { this.accesser = new LocalAccesser(this.options); diff --git a/packages/material-parser/src/accesser/BaseAccesser.ts b/packages/material-parser/src/accesser/BaseAccesser.ts index f31ed3abb..40269a88d 100644 --- a/packages/material-parser/src/accesser/BaseAccesser.ts +++ b/packages/material-parser/src/accesser/BaseAccesser.ts @@ -1,4 +1,4 @@ -import { IMaterialinSchema } from '../otter-core'; +import { IComponentMaterial } from '../otter-core'; import { IAccesser, IMaterializeOptions } from '../types'; /** @@ -20,7 +20,7 @@ abstract class BaseAccesser implements IAccesser { this.options = options; } - public abstract access(): Promise; + public abstract access(): Promise; } export default BaseAccesser; diff --git a/packages/material-parser/src/accesser/LocalAccesser.ts b/packages/material-parser/src/accesser/LocalAccesser.ts index 45edaf40f..2f2b60564 100644 --- a/packages/material-parser/src/accesser/LocalAccesser.ts +++ b/packages/material-parser/src/accesser/LocalAccesser.ts @@ -1,5 +1,5 @@ import Generator from '../generator/Generator'; -import { debug, IMaterialinSchema } from '../otter-core'; +import { debug, IComponentMaterial } from '../otter-core'; import BaseParser from '../parser/BaseParser'; import ReactParser from '../parser/ReactParser'; import Scanner from '../scanner/Scanner'; @@ -38,7 +38,7 @@ class LocalAccesser extends BaseAccesser { */ private generator!: Generator; - public async access(): Promise { + public async access(): Promise { await this.init(); // 开始扫描 const matScanModel: IMaterialScanModel = await this.scanner.scan(); @@ -49,7 +49,7 @@ class LocalAccesser extends BaseAccesser { ); log('matParsedModels', matParsedModels); // 开始生产 - const material: IMaterialinSchema = await this.generator.generate( + const material: IComponentMaterial = await this.generator.generate( matScanModel, matParsedModels, ); diff --git a/packages/material-parser/src/accesser/OnlineAccesser.ts b/packages/material-parser/src/accesser/OnlineAccesser.ts index c06bc06bf..160f4d20b 100644 --- a/packages/material-parser/src/accesser/OnlineAccesser.ts +++ b/packages/material-parser/src/accesser/OnlineAccesser.ts @@ -3,7 +3,7 @@ import { ensureDir, ensureFile, writeFile } from 'fs-extra'; import { join } from 'path'; import semver from 'semver'; import uuid from 'short-uuid'; -import { debug, IMaterialinSchema, OtterError } from '../otter-core'; +import { debug, IComponentMaterial, OtterError } from '../otter-core'; import { IMaterializeOptions } from '../types'; import BaseAccesser from './BaseAccesser'; import LocalAccesser from './LocalAccesser'; @@ -25,7 +25,7 @@ class OnlineAccesser extends BaseAccesser { */ private tempDir: string = ''; - public async access(): Promise { + public async access(): Promise { // 创建临时目录 this.tempDir = await this.createTempDir(); // 创建组件包 diff --git a/packages/material-parser/src/extensions/MatBuildBundle.ts b/packages/material-parser/src/extensions/MatBuildBundle.ts deleted file mode 100644 index e9847d4e2..000000000 --- a/packages/material-parser/src/extensions/MatBuildBundle.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * 获取打包后的 bundle 文件(物料化场景下可以使用此扩展点) - * - 扩展点名称:mat:build:bundle - * - 对应 Studio 所处状态:进入 就绪态 前 - * - * @export - * @param {{ - * bundleJS: string, // bundle 文件内容 - * bundleObj: {[key: string]: any} // bundle 对象 - * }} params - * @returns {Promise} - */ -export default function matBuildBundle(params: { - bundleJS: string; // bundle 文件内容 - bundleObj: { [key: string]: any }; // bundle 对象 -}): Promise { - return Promise.resolve(); -} diff --git a/packages/material-parser/src/extensions/MatConfigContainer.ts b/packages/material-parser/src/extensions/MatConfigContainer.ts deleted file mode 100644 index 4b98c48a7..000000000 --- a/packages/material-parser/src/extensions/MatConfigContainer.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { writeFile } from 'fs-extra'; - -/** - * 处理 containerJS(物料化场景下可以使用此扩展点) - * - 扩展点名称:mat:config:container - * - 对应 Studio 所处状态:进入 就绪态 前 - * - * @export - * @param {{ - * filePath: string, - * fileContent: string, - * }} params - * @returns {Promise<{ - * filePath: string, - * fileContent: string, - * }>} - */ -export default async function matConfigContainer(params: { - filePath: string; - fileContent: string; -}): Promise<{ - filePath: string; - fileContent: string; -}> { - await writeFile(params.filePath, params.fileContent); - - return { - filePath: params.filePath, - fileContent: params.fileContent, - }; -} diff --git a/packages/material-parser/src/extensions/MatConfigManifest.ts b/packages/material-parser/src/extensions/MatConfigManifest.ts index 2b975d74d..491fdce8f 100644 --- a/packages/material-parser/src/extensions/MatConfigManifest.ts +++ b/packages/material-parser/src/extensions/MatConfigManifest.ts @@ -1,5 +1,5 @@ import { writeFile } from 'fs-extra'; -import { IMaterialinManifest } from '../otter-core'; +import { IComponentMaterial } from '../otter-core'; /** * 配置 manifest(物料化场景下可以使用此扩展点) @@ -8,29 +8,29 @@ import { IMaterialinManifest } from '../otter-core'; * * @export * @param {{ - * manifestObj: IMaterialinManifest, + * manifestObj: IComponentMaterial, * manifestFilePath: string, * }} params * @returns {Promise<{ * manifestJS: string, * manifestFilePath: string, - * manifestObj: IMaterialinManifest, + * manifestObj: IComponentMaterial, * }>} */ export default async function matConfigManifest(params: { - manifestObj: IMaterialinManifest; + manifestObj: IComponentMaterial; manifestFilePath: string; }): Promise<{ - manifestJS: string; + manifestJSON: string; manifestFilePath: string; - manifestObj: IMaterialinManifest; + manifestObj: IComponentMaterial; }> { - const manifestJS = `export default ${JSON.stringify(params.manifestObj)}`; + const manifestJSON = JSON.stringify(params.manifestObj); - await writeFile(params.manifestFilePath, manifestJS); + await writeFile(params.manifestFilePath, manifestJSON); return Promise.resolve({ - manifestJS, + manifestJSON, manifestObj: params.manifestObj, manifestFilePath: params.manifestFilePath, }); diff --git a/packages/material-parser/src/extensions/MatGenerateBuildJS.ts b/packages/material-parser/src/extensions/MatGenerateBuildJS.ts deleted file mode 100644 index dc643f0d1..000000000 --- a/packages/material-parser/src/extensions/MatGenerateBuildJS.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * 生成 build 文件,可用于多组件导出场景(物料化场景下可以使用此扩展点) - * - 扩展点名称:mat:generate:buildjs - * - 对应 Studio 所处状态:进入 就绪态 前 - * - * @export - * @param {{ - * buildFileContent: string; // build 文件内容 - * buildFilePath: string; // build 文件默认路径 - * }} params - * @returns {Promise<{ - * buildFileContent: string; - * buildFilePath: string; - * }>} - */ -export default function matGenerateBuildJS(params: { - buildFileContent: string; // build 文件内容 - buildFilePath: string; // build 文件默认路径 -}): Promise<{ - buildFileContent: string; - buildFilePath: string; -}> { - return Promise.resolve({ - buildFilePath: params.buildFilePath, - buildFileContent: params.buildFileContent, - }); -} diff --git a/packages/material-parser/src/extensions/MatLoadMaterials.ts b/packages/material-parser/src/extensions/MatLoadMaterials.ts deleted file mode 100644 index bd45066f5..000000000 --- a/packages/material-parser/src/extensions/MatLoadMaterials.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMaterialinSchema } from '../otter-core'; - -/** - * 加载物料(物料接入场景下可以使用此扩展点) - * - 扩展点名称:mat:config:load - * - 对应 Studio 所处状态:进入 就绪态 前 - * - * @export - * @param {string[]} pkgNameList - * @returns {Promise} - */ -export default function matLoadMaterials( - pkgNameList: string[], -): Promise { - return Promise.resolve([]); -} diff --git a/packages/material-parser/src/extensions/index.ts b/packages/material-parser/src/extensions/index.ts index 3ef404b24..d35c1b720 100644 --- a/packages/material-parser/src/extensions/index.ts +++ b/packages/material-parser/src/extensions/index.ts @@ -1,12 +1,6 @@ import { ExtensionName } from '../types'; -import MatBuildBundle from './MatBuildBundle'; -import MatConfigContainer from './MatConfigContainer'; import MatConfigManifest from './MatConfigManifest'; -import MatGenerateBuildJS from './MatGenerateBuildJS'; export default { [ExtensionName.CONFIGMANIFEST]: MatConfigManifest, - [ExtensionName.BUILDBUNDLE]: MatBuildBundle, - [ExtensionName.CONFIGCONTAINER]: MatConfigContainer, - [ExtensionName.GENERATEBUILDJS]: MatGenerateBuildJS, }; diff --git a/packages/material-parser/src/generator/Generator.ts b/packages/material-parser/src/generator/Generator.ts index e5b3fd2e9..e7634c304 100644 --- a/packages/material-parser/src/generator/Generator.ts +++ b/packages/material-parser/src/generator/Generator.ts @@ -1,8 +1,12 @@ import { dirname, join } from 'path'; import defaultExtension from '../extensions'; -import { debug, IMaterialinManifest, IMaterialinProp } from '../otter-core'; import { - ICompiler, + debug, + IComponentMaterial, + PropsSection, + PropType, +} from '../otter-core'; +import { IGenerator, IMaterializeOptions, IMaterialParsedModel, @@ -29,14 +33,6 @@ class Generator implements IGenerator { */ protected options!: IMaterializeOptions; - /** - * 编译器实例 - * @protected - * @type {ICompiler} - * @memberof BaseGenerator - */ - protected compiler!: ICompiler; - constructor(options: IMaterializeOptions) { this.options = options; } @@ -62,7 +58,10 @@ class Generator implements IGenerator { continue; } // 组装 manifest - const manifest: any = await this.genManifest(matParsedModel); + const manifest: any = await this.genManifest( + matScanModel, + matParsedModel, + ); containerList.push(manifest); } @@ -95,21 +94,25 @@ class Generator implements IGenerator { * @memberof LocalGenerator */ public async genManifest( + matScanModel: IMaterialScanModel, matParsedModel: IMaterialParsedModel, ): Promise<{ manifestFilePath: string; // manifest 文件路径 manifestJS: string; // manifest 文件内容 - manifestObj: IMaterialinManifest; // manifest 文件对象 + manifestObj: IComponentMaterial; // manifest 文件对象 }> { - const manifestObj: IMaterialinManifest = { - name: matParsedModel.defaultExportName, - settings: { - type: 'element_inline', - insertionModes: 'tbrl', - handles: ['cut', 'copy', 'duplicate', 'delete', 'paste'], - shouldActive: true, - shouldDrag: true, - props: [], + const manifestObj: Partial = { + componentName: matParsedModel.defaultExportName, + title: '', + docUrl: '', + screenshot: '', + npm: { + package: matScanModel.pkgName, + version: matScanModel.pkgVersion, + exportName: matParsedModel.defaultExportName, + main: matScanModel.mainEntry, + destructuring: false, + subName: '', }, }; @@ -119,7 +122,7 @@ class Generator implements IGenerator { ); // 填充 props - manifestObj.settings.props = this.populateProps(matParsedModel); + manifestObj.props = this.populateProps(matParsedModel); // 执行扩展点 const manifest: any = await this.executeExtensionPoint( 'mat:config:manifest', @@ -145,17 +148,17 @@ class Generator implements IGenerator { */ public populateProps( matParsedModel: IMaterialParsedModel, - ): IMaterialinProp[] { + ): PropsSection['props'] { // 填充 props - const props: IMaterialinProp[] = []; + const props: PropsSection['props'] = []; matParsedModel.propsTypes.forEach(item => { const defaultValueItem = matParsedModel.propsDefaults.find( inner => inner.name === item.name, ); props.push({ name: item.name, - label: item.name, - renderer: '', + propType: item.type as PropType, + description: '', defaultValue: defaultValueItem ? defaultValueItem.defaultValue : undefined, diff --git a/packages/material-parser/src/otter-core/schema/types.ts b/packages/material-parser/src/otter-core/schema/types.ts index 5e11373e9..1107ab720 100644 --- a/packages/material-parser/src/otter-core/schema/types.ts +++ b/packages/material-parser/src/otter-core/schema/types.ts @@ -1,238 +1,179 @@ -// 搭建基础协议、搭建入料协议的数据规范 +/* 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. + */ /** - * 搭建基础协议 - * - * @export - * @interface IBasicSchema + * json schema for low code component protocol */ -export interface IBasicSchema { - version: string; // 当前协议版本号 - componentsMap: IComponentsMapItem[]; // 组件映射关系(用于描述 componentName 到公域组件映射关系的规范) - componentsTree: IComponentsTreeItem[]; // 描述模版/页面/区块/低代码业务组件的组件树(用于描述搭建出来的组件树结构的规范) -} - -/** - * 搭建基础协议 - 单个组件描述 - * - * @export - * @interface IComponentsMapItem - */ -export interface IComponentsMapItem { - componentName: string; // 组件名称 - package: string; // 组件包的名称 - version: string; // 组件包的版本 - originalPackage: string; // 组件的原始包名称 - originalVersion: string; // 组件的原始包版本 - destructuring: boolean; // 组件是否是解构方式方式导出 - exportName: string; // 导出命名 - subName?: string; // 下标子组件名称 -} - -/** - * 搭建基础协议 - 单个组件树节点描述 - * - * @export - * @interface IComponentsTreeItem - */ -export interface IComponentsTreeItem { - id: string; // 节点的唯一标识 - componentName: string; // 组件名称 - pkg: string; // 组件所属的包 - props?: { - className?: string; // 组件样式类名 - style?: { [cssAttribute: string]: string | number }; // 组件内联样式 - [propName: string]: any; // 业务属性 - }; // 组件属性对象 - children?: IComponentsTreeItem[] | string; // 子节点 - dataSource?: IDataSource; // 数据源 - state?: { - // 初始数据状态 - [key: string]: any; +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; }; - methods?: { - // 自定事件绑定 - [methodName: string]: IJSExpression; - }; - lifeCycles?: { - // 组件生命周期 - didMount?: IJSExpression; - willMount?: IJSExpression; - }; -} + [k: string]: any; +} & (ConfigureFieldProp | ConfigureGroupProp); -/** - * 搭建基础协议 - 函数表达式 - * - * @export - * @interface IComponentLifeCycle - */ -export interface IJSExpression { - type: 'JSExpression'; - value: string; +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 IDataSource - */ -export interface IDataSource { - list: IDataSourceRequest[]; // 数据源配置列表 -} - -/** - * 搭建基础协议 - 数据源单个配置 - * - * @export - * @interface IDataSourceRequest - */ -export interface IDataSourceRequest { - id: string; // 数据请求 ID - isInit: boolean; // 表示在组件初始化渲染时是否自动发送当前数据请求 - type: 'fetch' | 'jsonp' | 'custom'; // 数据请求类型 - options?: IRequestOptions; // 请求参数配置 - dataHandler?: any; // 数据结果处理函数,形如:(data, err) => Object -} - -/** - * 搭建基础协议 - 请求参数配置 - * - * @export - * @interface IRequestOptions - */ -export interface IRequestOptions { - uri: string; // 请求地址 - params?: { - // 请求参数 - [key: string]: any; - }; - method: 'GET' | 'POST'; - isCors: boolean; // 是否支持跨域,对应credentials = 'include' - timeout: number; // 超时时长 - headers?: { - // 自定义请求头 - [key: string]: any; - }; -} - -/** - * 组件描述协议 - * - * @export - * @interface IMaterialinSchema - */ -export interface IMaterialinSchema { - version: string; // 当前协议版本号 - components: IMaterialinComponent[]; // 组件集合 - pkgInfo: IMaterialinPkgInfo; // 组件包信息描述 -} - -/** - * 组件描述协议 - 组件包信息描述(供出码引擎消费) - * - * @export - * @interface IMaterialinPkgInfo - */ -export interface IMaterialinPkgInfo { - // 包名 +export interface Npm { package: string; - // 版本号 + exportName: string; + subName: string; + main: string; + destructuring: boolean; version: string; - // 源版本号 - originalVersion: string; - // 源组件包 - originalPackage: string; - // 组件是否是 export 方式导出 - defaultExportedName: string; + [k: string]: any; } - -/** - * 组件描述协议 - 单个组件描述 - * - * @export - * @interface IMaterialinComponent - */ -export interface IMaterialinComponent { - componentName: string; // 组件名 - manifest: IMaterialinManifest; // 组件配置信息描述 - origin: any; // 组件源 +export interface PropsSection { + props: { + name: string; + propType: PropType; + description?: string; + defaultValue?: any; + [k: string]: any; + }[]; + [k: string]: any; } - -/** - * 组件描述协议 - 组件配置信息描述 - * - * @export - * @interface IMaterialinManifest - */ -export interface IMaterialinManifest { - name: string; // 组件名 - settings: IMaterialinSettings; // 定义组件的配置属性 - description?: string; // 组件的描述 - coverImage?: string; // 组件的封面图 URL - category?: string; // 组件的分类 - presets?: IMaterialinPreset[]; // 定义组件左侧预览信息 +export interface RequiredType { + type: BasicType; + isRequired?: boolean; } - -/** - * 组件描述协议 - 组件配置属性(直接影响组件在编排工作区中的行为表现) - * - * @export - * @interface IMaterialinSettings - */ -export interface IMaterialinSettings { - type: 'element_inline' | 'element_block' | 'container'; // 定义组件在编排画布上的渲染类型 - // 定义组件对于拖拽行为的响应,支持:t、b、r、l、v 组合;形如:tbrl - // t:允许元素在组件顶部插入 - // b:允许元素在组件底部插入 - // r:允许元素在组件右侧插入 - // l:允许元素在组件左侧插入 - // v:允许将元素拖放到组件内部 - insertionModes: string; // 定义组件在编排画布上的响应模式 - handles: Array<'cut' | 'copy' | 'paste' | 'delete' | 'duplicate'>; // 定义组件需要响应的右键菜单操作 - shouldActive: boolean; // 用于控制物料组件在画布区块中是否响应用户鼠标的 Click 操作 - shouldDrag: boolean; // 用于控制物料组件在画布区块中是否可以被用户拖拽 - props: IMaterialinProp[]; // 物料组件属性配置 - lifeCycle?: IMaterialinLifeCycle; // 组件生命周期 +export interface OneOf { + type: 'oneOf'; + value: string[]; + isRequired?: boolean; + [k: string]: any; } - -/** - * 组件描述协议 - 定义组件左侧预览信息 - * - * @export - * @interface IMaterialinPreset - */ -export interface IMaterialinPreset { - alias: string; // 组件的别名 - thumbnail: string; // 组件的预览缩略图 URL - colSpan?: number; // 代表组件所占栅格数 - customProps?: object; // 自定义属性值 +export interface OneOfType { + type: 'oneOfType'; + value: PropType[]; + isRequired?: boolean; + [k: string]: any; } - -/** - * 组件描述协议 - 组件属性的描述 - * - * @export - * @interface IMaterialinProp - */ -export interface IMaterialinProp { - name: string; // 属性名 - label: string; // 属性展示名称 - renderer: string; // 属性编辑器类型 - defaultValue?: any; // 属性默认值 - params?: any; // 属性编辑器的参数 - placeholder?: string; // 属性编辑器的 placeholder 信息 - hint?: string; // 属性编辑器的提示信息(类似于 tooltip 效果),用于帮助用户理解属性的使用方法 +export interface ArrayOf { + type: 'arrayOf'; + value: PropType; + isRequired?: boolean; + [k: string]: any; } - -/** - * 组件描述协议 - 组件生命周期描述 - * - * @export - * @interface IMaterialinLifeCycle - */ -export interface IMaterialinLifeCycle { - didMount?: any; // 组件渲染完成后的钩子 - didUpdate?: 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; } diff --git a/packages/material-parser/src/otter-core/types.ts b/packages/material-parser/src/otter-core/types.ts index de5a8621b..27a896671 100644 --- a/packages/material-parser/src/otter-core/types.ts +++ b/packages/material-parser/src/otter-core/types.ts @@ -1,5 +1,3 @@ -import { IBasicSchema } from './schema/types'; - /** * * @export @@ -22,19 +20,3 @@ export interface IComponents { [componentName: string]: any; // 组件 }; } - -/** - * 渲染引擎的输入 - * 编排引擎、渲染引擎使用 - * - * @export - * @interface IRenderInputData - */ -export interface IRenderInputData { - schema: IBasicSchema; - components: IComponents; - options?: { - domId?: string; - propsHooks?: { [propName: string]: any }; - }; -} diff --git a/packages/material-parser/src/types/ExtensionName.ts b/packages/material-parser/src/types/ExtensionName.ts index f5d9c3e88..e1d45afa5 100644 --- a/packages/material-parser/src/types/ExtensionName.ts +++ b/packages/material-parser/src/types/ExtensionName.ts @@ -2,16 +2,8 @@ * 扩展点名称 */ enum ExtensionName { - /** 加载物料 */ - LOADMATERIALS = 'mat:load:materials', /** 配置 manifest */ CONFIGMANIFEST = 'mat:config:manifest', - /** 获取打包后的 bundle */ - BUILDBUNDLE = 'mat:build:bundle', - /** 配置 containerJS */ - CONFIGCONTAINER = 'mat:config:container', - /** 生成 buildJS */ - GENERATEBUILDJS = 'mat:generate:buildjs', } export default ExtensionName; diff --git a/packages/material-parser/src/types/IAccesser.ts b/packages/material-parser/src/types/IAccesser.ts index dd3a673a2..45cfd2dd3 100644 --- a/packages/material-parser/src/types/IAccesser.ts +++ b/packages/material-parser/src/types/IAccesser.ts @@ -1,4 +1,4 @@ -import { IMaterialinSchema } from '../otter-core'; +import { IComponentMaterial } from '../otter-core'; /** * 接入器接口(用于定义物料化组件的接入渠道) @@ -10,7 +10,7 @@ interface IAccesser { * @returns {Promise} * @memberof IAccesser */ - access(): Promise; + access(): Promise; } export default IAccesser; diff --git a/packages/material-parser/src/types/IExtensionBuildBundle.ts b/packages/material-parser/src/types/IExtensionBuildBundle.ts deleted file mode 100644 index b063f5cf7..000000000 --- a/packages/material-parser/src/types/IExtensionBuildBundle.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * 扩展点:获取打包后的 bundle 文件 - * (物料化场景) - */ -type IExtensionBuildBundle = (params: { - bundleJS: string; // bundle 文件内容 - bundleObj: { [key: string]: any }; // bundle 对象 -}) => Promise; - -export default IExtensionBuildBundle; diff --git a/packages/material-parser/src/types/IExtensionConfigContainer.ts b/packages/material-parser/src/types/IExtensionConfigContainer.ts deleted file mode 100644 index 50b273efd..000000000 --- a/packages/material-parser/src/types/IExtensionConfigContainer.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * 扩展点:配置 container - * (物料化场景) - */ -type IExtensionConfigContainer = (params: { - filePath: string; // container 文件默认路径 - fileContent: string; // container 文件内容 -}) => Promise<{ - filePath: string; - fileContent: string; -}>; - -export default IExtensionConfigContainer; diff --git a/packages/material-parser/src/types/IExtensionConfigManifest.ts b/packages/material-parser/src/types/IExtensionConfigManifest.ts index 01ba0df08..5971341f3 100644 --- a/packages/material-parser/src/types/IExtensionConfigManifest.ts +++ b/packages/material-parser/src/types/IExtensionConfigManifest.ts @@ -1,15 +1,15 @@ -import { IMaterialinManifest } from '../otter-core'; +import { IComponentMaterial } from '../otter-core'; /** * 扩展点:配置 manifest * (物料化场景) */ type IExtensionConfigManifest = (params: { - manifestObj: IMaterialinManifest; // manifest 配置对象 + manifestObj: IComponentMaterial; // manifest 配置对象 manifestFilePath: string; // manifest 文件默认路径 }) => Promise<{ - manifestJS: string; // manifest 文件内容 + manifestJSON: string; // manifest 文件内容 manifestFilePath: string; // manifest 文件路径 - manifestObj: IMaterialinManifest; // manifest 文件对象 + manifestObj: IComponentMaterial; // manifest 文件对象 }>; export default IExtensionConfigManifest; diff --git a/packages/material-parser/src/types/IExtensionGenerateBuildJS.ts b/packages/material-parser/src/types/IExtensionGenerateBuildJS.ts deleted file mode 100644 index 3fc7f5704..000000000 --- a/packages/material-parser/src/types/IExtensionGenerateBuildJS.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * 扩展点:生成 build 文件 - * (物料化场景) - */ -type IExtensionGenerateBuildJS = (params: { - buildFilePath: string; // 文件默认路径 - buildFileContent: string; // 文件内容 -}) => Promise<{ - buildFilePath: string; - buildFileContent: string; -}>; - -export default IExtensionGenerateBuildJS; diff --git a/packages/material-parser/src/types/IExtensionLoadMaterials.ts b/packages/material-parser/src/types/IExtensionLoadMaterials.ts deleted file mode 100644 index ab6653d01..000000000 --- a/packages/material-parser/src/types/IExtensionLoadMaterials.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IMaterialinSchema } from '../otter-core'; - -/** - * 扩展点:加载物料(物料接入场景) - * - * @interface IExtensionLoadMaterials - */ -type IExtensionLoadMaterials = ( - pkgNameList: string[], -) => Promise; - -export default IExtensionLoadMaterials; diff --git a/packages/material-parser/src/types/IGenerator.ts b/packages/material-parser/src/types/IGenerator.ts index 641c0b1b6..ff37a8b8a 100644 --- a/packages/material-parser/src/types/IGenerator.ts +++ b/packages/material-parser/src/types/IGenerator.ts @@ -1,4 +1,4 @@ -import { IMaterialinSchema } from '../otter-core'; +import { IComponentMaterial } from '../otter-core'; import IMaterialParsedModel from './IMaterialParsedModel'; import IMaterialScanModel from './IMaterialScanModel'; @@ -16,5 +16,5 @@ export default interface IGenerator { generate( matScanModel: IMaterialScanModel, matParsedModels: IMaterialParsedModel[], - ): Promise; + ): Promise; } diff --git a/packages/material-parser/src/types/IMaterialInOptions.ts b/packages/material-parser/src/types/IMaterialInOptions.ts deleted file mode 100644 index cf6151b0e..000000000 --- a/packages/material-parser/src/types/IMaterialInOptions.ts +++ /dev/null @@ -1,23 +0,0 @@ -import ExtensionName from './ExtensionName'; -import IExtensionLoadMaterials from './IExtensionLoadMaterials'; - -interface IMaterialInOptions { - /** - * 配置从哪些 CDN 加载组件 - * (当 channel=online 时生效) - * 形如: - * https://unpkg.alibaba-inc.com/ - * https://unpkg.com/ - * https://cdn.jsdelivr.net/npm/ - */ - cdn?: string[]; - - /** - * 扩展点 - */ - extensions?: { - [ExtensionName.LOADMATERIALS]?: IExtensionLoadMaterials; - }; -} - -export default IMaterialInOptions; diff --git a/packages/material-parser/src/types/IMaterializeOptions.ts b/packages/material-parser/src/types/IMaterializeOptions.ts index 37790eeaf..9896f3916 100644 --- a/packages/material-parser/src/types/IMaterializeOptions.ts +++ b/packages/material-parser/src/types/IMaterializeOptions.ts @@ -1,8 +1,5 @@ import ExtensionName from './ExtensionName'; -import IExtensionBuildBundle from './IExtensionBuildBundle'; -import IExtensionConfigContainer from './IExtensionConfigContainer'; import IExtensionConfigManifest from './IExtensionConfigManifest'; -import IExtensionGenerateBuildJS from './IExtensionGenerateBuildJS'; /** * 物料化配置项 @@ -45,9 +42,6 @@ interface IMaterializeOptions { */ extensions?: { [ExtensionName.CONFIGMANIFEST]?: IExtensionConfigManifest; - [ExtensionName.CONFIGCONTAINER]?: IExtensionConfigContainer; - [ExtensionName.BUILDBUNDLE]?: IExtensionBuildBundle; - [ExtensionName.GENERATEBUILDJS]?: IExtensionGenerateBuildJS; }; /** diff --git a/packages/material-parser/src/types/index.ts b/packages/material-parser/src/types/index.ts index ae69c3834..22a743e76 100644 --- a/packages/material-parser/src/types/index.ts +++ b/packages/material-parser/src/types/index.ts @@ -3,12 +3,8 @@ import EcologyType from './EcologyType'; import ExtensionName from './ExtensionName'; import IAccesser from './IAccesser'; import ICompiler from './ICompiler'; -import IExtensionBuildBundle from './IExtensionBuildBundle'; -import IExtensionConfigContainer from './IExtensionConfigContainer'; import IExtensionConfigManifest from './IExtensionConfigManifest'; -import IExtensionLoadMaterials from './IExtensionLoadMaterials'; import IGenerator from './IGenerator'; -import IMaterialInOptions from './IMaterialInOptions'; import IMaterializeOptions from './IMaterializeOptions'; import IMaterialParsedModel from './IMaterialParsedModel'; import IMaterialScanModel from './IMaterialScanModel'; @@ -22,10 +18,6 @@ export { IScanner, ExtensionName, IExtensionConfigManifest, - IExtensionConfigContainer, - IExtensionLoadMaterials, - IExtensionBuildBundle, - IMaterialInOptions, IMaterializeOptions, IMaterialScanModel, IMaterialParsedModel, diff --git a/packages/material-parser/src/validate/schema.d.ts b/packages/material-parser/src/validate/schema.d.ts new file mode 100644 index 000000000..ed478418f --- /dev/null +++ b/packages/material-parser/src/validate/schema.d.ts @@ -0,0 +1,179 @@ +/* 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 ComponentMaterial = 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[]; + 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; +} diff --git a/packages/material-parser/src/validate/schema.json b/packages/material-parser/src/validate/schema.json index 7a5469a10..5aed3e9d0 100644 --- a/packages/material-parser/src/validate/schema.json +++ b/packages/material-parser/src/validate/schema.json @@ -60,6 +60,9 @@ }, "PropsSection": { "type": "object", + "required": [ + "props" + ], "properties": { "props": { "type": "array",