mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-25 11:28:18 +00:00
fix: 新增自定义模式 demo & 导出自定义需要的信息
This commit is contained in:
parent
57b30cf785
commit
07e27592a6
@ -1,4 +1,5 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
// ../lib 可以替换成 @ali/lowcode-code-generator
|
||||||
const CodeGenerator = require('../lib').default;
|
const CodeGenerator = require('../lib').default;
|
||||||
|
|
||||||
function flatFiles(rootName, dir) {
|
function flatFiles(rootName, dir) {
|
||||||
@ -50,4 +51,104 @@ function main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
function exportModule() {
|
||||||
|
const schemaJson = fs.readFileSync('./demo/shenmaSample.json', { encoding: 'utf8' });
|
||||||
|
const moduleBuilder = CodeGenerator.createModuleBuilder({
|
||||||
|
plugins: [
|
||||||
|
CodeGenerator.plugins.react.reactCommonDeps(),
|
||||||
|
CodeGenerator.plugins.common.esmodule({
|
||||||
|
fileType: 'jsx',
|
||||||
|
}),
|
||||||
|
CodeGenerator.plugins.react.containerClass(),
|
||||||
|
CodeGenerator.plugins.react.containerInitState(),
|
||||||
|
CodeGenerator.plugins.react.containerLifeCycle(),
|
||||||
|
CodeGenerator.plugins.react.containerMethod(),
|
||||||
|
CodeGenerator.plugins.react.jsx(),
|
||||||
|
CodeGenerator.plugins.style.css(),
|
||||||
|
],
|
||||||
|
postProcessors: [
|
||||||
|
CodeGenerator.postprocessor.prettier(),
|
||||||
|
],
|
||||||
|
mainFileName: 'index',
|
||||||
|
});
|
||||||
|
|
||||||
|
moduleBuilder.generateModuleCode(schemaJson).then(result => {
|
||||||
|
displayResultInConsole(result);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportProject() {
|
||||||
|
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
||||||
|
|
||||||
|
const builder = CodeGenerator.createProjectBuilder({
|
||||||
|
template: CodeGenerator.solutionParts.icejs.template,
|
||||||
|
plugins: {
|
||||||
|
components: [
|
||||||
|
CodeGenerator.plugins.react.reactCommonDeps(),
|
||||||
|
CodeGenerator.plugins.common.esmodule({
|
||||||
|
fileType: 'jsx',
|
||||||
|
}),
|
||||||
|
CodeGenerator.plugins.react.containerClass(),
|
||||||
|
CodeGenerator.plugins.react.containerInitState(),
|
||||||
|
CodeGenerator.plugins.react.containerLifeCycle(),
|
||||||
|
CodeGenerator.plugins.react.containerMethod(),
|
||||||
|
CodeGenerator.plugins.react.jsx(),
|
||||||
|
CodeGenerator.plugins.style.css(),
|
||||||
|
],
|
||||||
|
pages: [
|
||||||
|
CodeGenerator.plugins.react.reactCommonDeps(),
|
||||||
|
CodeGenerator.plugins.common.esmodule({
|
||||||
|
fileType: 'jsx',
|
||||||
|
}),
|
||||||
|
CodeGenerator.plugins.react.containerClass(),
|
||||||
|
CodeGenerator.plugins.react.containerInitState(),
|
||||||
|
CodeGenerator.plugins.react.containerLifeCycle(),
|
||||||
|
CodeGenerator.plugins.react.containerMethod(),
|
||||||
|
CodeGenerator.plugins.react.jsx(),
|
||||||
|
CodeGenerator.plugins.style.css(),
|
||||||
|
],
|
||||||
|
router: [
|
||||||
|
CodeGenerator.plugins.common.esmodule(),
|
||||||
|
CodeGenerator.solutionParts.icejs.plugins.router(),
|
||||||
|
],
|
||||||
|
entry: [
|
||||||
|
CodeGenerator.solutionParts.icejs.plugins.entry(),
|
||||||
|
],
|
||||||
|
constants: [
|
||||||
|
CodeGenerator.plugins.project.constants(),
|
||||||
|
],
|
||||||
|
utils: [
|
||||||
|
CodeGenerator.plugins.common.esmodule(),
|
||||||
|
CodeGenerator.plugins.project.utils(),
|
||||||
|
],
|
||||||
|
i18n: [
|
||||||
|
CodeGenerator.plugins.project.i18n(),
|
||||||
|
],
|
||||||
|
globalStyle: [
|
||||||
|
CodeGenerator.solutionParts.icejs.plugins.globalStyle(),
|
||||||
|
],
|
||||||
|
htmlEntry: [
|
||||||
|
CodeGenerator.solutionParts.icejs.plugins.entryHtml(),
|
||||||
|
],
|
||||||
|
packageJSON: [
|
||||||
|
CodeGenerator.solutionParts.icejs.plugins.packageJSON(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
postProcessors: [
|
||||||
|
CodeGenerator.postprocessor.prettier(),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.generateProject(schemaJson).then(result => {
|
||||||
|
displayResultInConsole(result);
|
||||||
|
writeResultToDisk(result, 'output/lowcodeDemo').then(response =>
|
||||||
|
console.log('Write to disk: ', JSON.stringify(response)),
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// main();
|
||||||
|
// exportModule();
|
||||||
|
exportProject();
|
||||||
|
|||||||
36
packages/code-generator/demo/shenmaSample.json
Normal file
36
packages/code-generator/demo/shenmaSample.json
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"componentsMap": [
|
||||||
|
{
|
||||||
|
"componentName": "Demo",
|
||||||
|
"package": "@ali/demo",
|
||||||
|
"version": "1.19.18",
|
||||||
|
"destructuring": true,
|
||||||
|
"exportName": "Demo"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "page_kc326r8m",
|
||||||
|
"componentsTree": [{
|
||||||
|
"componentName": "Page",
|
||||||
|
"id": "node_kc326r8h",
|
||||||
|
"props": {},
|
||||||
|
"condition": true,
|
||||||
|
"loopArgs": ["item", "index"],
|
||||||
|
"children": [{
|
||||||
|
"componentName": "Demo",
|
||||||
|
"id": "node_kc326r8i",
|
||||||
|
"props": {
|
||||||
|
"value": "文本内容",
|
||||||
|
"color": "#ffffff",
|
||||||
|
"ui_maxLine": 2,
|
||||||
|
"url": "",
|
||||||
|
"ui_type": "xs",
|
||||||
|
"style": {},
|
||||||
|
"className": ""
|
||||||
|
},
|
||||||
|
"condition": true,
|
||||||
|
"loopArgs": ["item", "index"]
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"params": {}
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ali/lowcode-code-generator",
|
"name": "@ali/lowcode-code-generator",
|
||||||
"version": "0.8.7",
|
"version": "0.8.8",
|
||||||
"description": "出码引擎 for LowCode Engine",
|
"description": "出码引擎 for LowCode Engine",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@ -10,6 +10,11 @@ import createRecoreProjectBuilder from './solutions/recore';
|
|||||||
|
|
||||||
// 引入说明
|
// 引入说明
|
||||||
import { REACT_CHUNK_NAME } from './plugins/component/react/const';
|
import { REACT_CHUNK_NAME } from './plugins/component/react/const';
|
||||||
|
import {
|
||||||
|
COMMON_CHUNK_NAME,
|
||||||
|
CLASS_DEFINE_CHUNK_NAME,
|
||||||
|
DEFAULT_LINK_AFTER,
|
||||||
|
} from './const/generator';
|
||||||
|
|
||||||
// 引入通用插件组
|
// 引入通用插件组
|
||||||
import esmodule from './plugins/common/esmodule';
|
import esmodule from './plugins/common/esmodule';
|
||||||
@ -26,6 +31,7 @@ import css from './plugins/component/style/css';
|
|||||||
import constants from './plugins/project/constants';
|
import constants from './plugins/project/constants';
|
||||||
import i18n from './plugins/project/i18n';
|
import i18n from './plugins/project/i18n';
|
||||||
import utils from './plugins/project/utils';
|
import utils from './plugins/project/utils';
|
||||||
|
import prettier from './postprocessor/prettier';
|
||||||
|
|
||||||
// 引入常用工具
|
// 引入常用工具
|
||||||
import * as utilsCommon from './utils/common';
|
import * as utilsCommon from './utils/common';
|
||||||
@ -34,6 +40,9 @@ import * as utilsJsExpression from './utils/jsExpression';
|
|||||||
import * as utilsNodeToJSX from './utils/nodeToJSX';
|
import * as utilsNodeToJSX from './utils/nodeToJSX';
|
||||||
import * as utilsTemplateHelper from './utils/templateHelper';
|
import * as utilsTemplateHelper from './utils/templateHelper';
|
||||||
|
|
||||||
|
// 引入内置解决方案模块
|
||||||
|
import icejs from './plugins/project/framework/icejs';
|
||||||
|
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -43,6 +52,9 @@ export default {
|
|||||||
icejs: createIceJsProjectBuilder,
|
icejs: createIceJsProjectBuilder,
|
||||||
recore: createRecoreProjectBuilder,
|
recore: createRecoreProjectBuilder,
|
||||||
},
|
},
|
||||||
|
solutionParts: {
|
||||||
|
icejs,
|
||||||
|
},
|
||||||
publishers: {
|
publishers: {
|
||||||
disk: createDiskPublisher,
|
disk: createDiskPublisher,
|
||||||
},
|
},
|
||||||
@ -70,6 +82,9 @@ export default {
|
|||||||
utils,
|
utils,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
postprocessor: {
|
||||||
|
prettier,
|
||||||
|
},
|
||||||
utils: {
|
utils: {
|
||||||
common: utilsCommon,
|
common: utilsCommon,
|
||||||
compositeType: utilsCompositeType,
|
compositeType: utilsCompositeType,
|
||||||
@ -77,4 +92,12 @@ export default {
|
|||||||
nodeToJSX: utilsNodeToJSX,
|
nodeToJSX: utilsNodeToJSX,
|
||||||
templateHelper: utilsTemplateHelper,
|
templateHelper: utilsTemplateHelper,
|
||||||
},
|
},
|
||||||
|
chunkNames: {
|
||||||
|
COMMON_CHUNK_NAME,
|
||||||
|
CLASS_DEFINE_CHUNK_NAME,
|
||||||
|
REACT_CHUNK_NAME,
|
||||||
|
},
|
||||||
|
defaultLinkAfter: {
|
||||||
|
COMMON_DEFAULT_LINK_AFTER: DEFAULT_LINK_AFTER,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
import template from './template';
|
||||||
|
import entry from './plugins/entry';
|
||||||
|
import entryHtml from './plugins/entryHtml';
|
||||||
|
import globalStyle from './plugins/globalStyle';
|
||||||
|
import packageJSON from './plugins/packageJSON';
|
||||||
|
import router from './plugins/router';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
template,
|
||||||
|
plugins: {
|
||||||
|
entry,
|
||||||
|
entryHtml,
|
||||||
|
globalStyle,
|
||||||
|
packageJSON,
|
||||||
|
router,
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -5,7 +5,7 @@ import { PostProcessor, PostProcessorFactory } from '../../types';
|
|||||||
|
|
||||||
const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];
|
const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];
|
||||||
|
|
||||||
interface ProcessorConfig {
|
type ProcessorConfig = {
|
||||||
customFileTypeParser: Record<string, string>;
|
customFileTypeParser: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,20 +12,16 @@ import jsx from '../plugins/component/react/jsx';
|
|||||||
import reactCommonDeps from '../plugins/component/react/reactCommonDeps';
|
import reactCommonDeps from '../plugins/component/react/reactCommonDeps';
|
||||||
import css from '../plugins/component/style/css';
|
import css from '../plugins/component/style/css';
|
||||||
import constants from '../plugins/project/constants';
|
import constants from '../plugins/project/constants';
|
||||||
import iceJsEntry from '../plugins/project/framework/icejs/plugins/entry';
|
|
||||||
import iceJsEntryHtml from '../plugins/project/framework/icejs/plugins/entryHtml';
|
|
||||||
import iceJsGlobalStyle from '../plugins/project/framework/icejs/plugins/globalStyle';
|
|
||||||
import iceJsPackageJSON from '../plugins/project/framework/icejs/plugins/packageJSON';
|
|
||||||
import iceJsRouter from '../plugins/project/framework/icejs/plugins/router';
|
|
||||||
import template from '../plugins/project/framework/icejs/template';
|
|
||||||
import i18n from '../plugins/project/i18n';
|
import i18n from '../plugins/project/i18n';
|
||||||
import utils from '../plugins/project/utils';
|
import utils from '../plugins/project/utils';
|
||||||
|
|
||||||
|
import icejs from '../plugins/project/framework/icejs';
|
||||||
|
|
||||||
import { prettier } from '../postprocessor';
|
import { prettier } from '../postprocessor';
|
||||||
|
|
||||||
export default function createIceJsProjectBuilder(): IProjectBuilder {
|
export default function createIceJsProjectBuilder(): IProjectBuilder {
|
||||||
return createProjectBuilder({
|
return createProjectBuilder({
|
||||||
template,
|
template: icejs.template,
|
||||||
plugins: {
|
plugins: {
|
||||||
components: [
|
components: [
|
||||||
reactCommonDeps(),
|
reactCommonDeps(),
|
||||||
@ -53,14 +49,14 @@ export default function createIceJsProjectBuilder(): IProjectBuilder {
|
|||||||
jsx(),
|
jsx(),
|
||||||
css(),
|
css(),
|
||||||
],
|
],
|
||||||
router: [esmodule(), iceJsRouter()],
|
router: [esmodule(), icejs.plugins.router()],
|
||||||
entry: [iceJsEntry()],
|
entry: [icejs.plugins.entry()],
|
||||||
constants: [constants()],
|
constants: [constants()],
|
||||||
utils: [esmodule(), utils()],
|
utils: [esmodule(), utils()],
|
||||||
i18n: [i18n()],
|
i18n: [i18n()],
|
||||||
globalStyle: [iceJsGlobalStyle()],
|
globalStyle: [icejs.plugins.globalStyle()],
|
||||||
htmlEntry: [iceJsEntryHtml()],
|
htmlEntry: [icejs.plugins.entryHtml()],
|
||||||
packageJSON: [iceJsPackageJSON()],
|
packageJSON: [icejs.plugins.packageJSON()],
|
||||||
},
|
},
|
||||||
postProcessors: [prettier()],
|
postProcessors: [prettier()],
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user