mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-25 03:08:11 +00:00
fix: 新增自定义模式 demo & 导出自定义需要的信息
This commit is contained in:
parent
57b30cf785
commit
07e27592a6
@ -1,4 +1,5 @@
|
||||
const fs = require('fs');
|
||||
// ../lib 可以替换成 @ali/lowcode-code-generator
|
||||
const CodeGenerator = require('../lib').default;
|
||||
|
||||
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",
|
||||
"version": "0.8.7",
|
||||
"version": "0.8.8",
|
||||
"description": "出码引擎 for LowCode Engine",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
|
||||
@ -10,6 +10,11 @@ import createRecoreProjectBuilder from './solutions/recore';
|
||||
|
||||
// 引入说明
|
||||
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';
|
||||
@ -26,6 +31,7 @@ import css from './plugins/component/style/css';
|
||||
import constants from './plugins/project/constants';
|
||||
import i18n from './plugins/project/i18n';
|
||||
import utils from './plugins/project/utils';
|
||||
import prettier from './postprocessor/prettier';
|
||||
|
||||
// 引入常用工具
|
||||
import * as utilsCommon from './utils/common';
|
||||
@ -34,6 +40,9 @@ import * as utilsJsExpression from './utils/jsExpression';
|
||||
import * as utilsNodeToJSX from './utils/nodeToJSX';
|
||||
import * as utilsTemplateHelper from './utils/templateHelper';
|
||||
|
||||
// 引入内置解决方案模块
|
||||
import icejs from './plugins/project/framework/icejs';
|
||||
|
||||
export * from './types';
|
||||
|
||||
export default {
|
||||
@ -43,6 +52,9 @@ export default {
|
||||
icejs: createIceJsProjectBuilder,
|
||||
recore: createRecoreProjectBuilder,
|
||||
},
|
||||
solutionParts: {
|
||||
icejs,
|
||||
},
|
||||
publishers: {
|
||||
disk: createDiskPublisher,
|
||||
},
|
||||
@ -70,6 +82,9 @@ export default {
|
||||
utils,
|
||||
},
|
||||
},
|
||||
postprocessor: {
|
||||
prettier,
|
||||
},
|
||||
utils: {
|
||||
common: utilsCommon,
|
||||
compositeType: utilsCompositeType,
|
||||
@ -77,4 +92,12 @@ export default {
|
||||
nodeToJSX: utilsNodeToJSX,
|
||||
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'];
|
||||
|
||||
interface ProcessorConfig {
|
||||
type ProcessorConfig = {
|
||||
customFileTypeParser: Record<string, string>;
|
||||
}
|
||||
|
||||
|
||||
@ -12,20 +12,16 @@ import jsx from '../plugins/component/react/jsx';
|
||||
import reactCommonDeps from '../plugins/component/react/reactCommonDeps';
|
||||
import css from '../plugins/component/style/css';
|
||||
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 utils from '../plugins/project/utils';
|
||||
|
||||
import icejs from '../plugins/project/framework/icejs';
|
||||
|
||||
import { prettier } from '../postprocessor';
|
||||
|
||||
export default function createIceJsProjectBuilder(): IProjectBuilder {
|
||||
return createProjectBuilder({
|
||||
template,
|
||||
template: icejs.template,
|
||||
plugins: {
|
||||
components: [
|
||||
reactCommonDeps(),
|
||||
@ -53,14 +49,14 @@ export default function createIceJsProjectBuilder(): IProjectBuilder {
|
||||
jsx(),
|
||||
css(),
|
||||
],
|
||||
router: [esmodule(), iceJsRouter()],
|
||||
entry: [iceJsEntry()],
|
||||
router: [esmodule(), icejs.plugins.router()],
|
||||
entry: [icejs.plugins.entry()],
|
||||
constants: [constants()],
|
||||
utils: [esmodule(), utils()],
|
||||
i18n: [i18n()],
|
||||
globalStyle: [iceJsGlobalStyle()],
|
||||
htmlEntry: [iceJsEntryHtml()],
|
||||
packageJSON: [iceJsPackageJSON()],
|
||||
globalStyle: [icejs.plugins.globalStyle()],
|
||||
htmlEntry: [icejs.plugins.entryHtml()],
|
||||
packageJSON: [icejs.plugins.packageJSON()],
|
||||
},
|
||||
postProcessors: [prettier()],
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user