mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +00:00
chore: 🤖 add local test case
This commit is contained in:
parent
16f8cf2afe
commit
e0eacbf318
13065
packages/code-generator/demo/assets.json
Normal file
13065
packages/code-generator/demo/assets.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,20 +4,20 @@ const CodeGenerator = require('../lib').default;
|
||||
|
||||
function flatFiles(rootName, dir) {
|
||||
const dirRoot = rootName ? `${rootName}/${dir.name}` : dir.name;
|
||||
const files = dir.files.map(file => ({
|
||||
const files = dir.files.map((file) => ({
|
||||
name: `${dirRoot}/${file.name}.${file.ext}`,
|
||||
content: file.content,
|
||||
ext: '',
|
||||
}));
|
||||
const filesInSub = dir.dirs.map(subDir => flatFiles(`${dirRoot}`, subDir));
|
||||
const result = files.concat.apply(files, filesInSub);
|
||||
const filesInSub = dir.dirs.map((subDir) => flatFiles(`${dirRoot}`, subDir));
|
||||
const result = files.concat(...filesInSub);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function displayResultInConsole(root, fileName) {
|
||||
const files = flatFiles('.', root);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (!fileName || fileName === file.name) {
|
||||
console.log(`========== ${file.name} Start ==========`);
|
||||
console.log(file.content);
|
||||
@ -37,20 +37,62 @@ async function writeResultToDisk(root, path) {
|
||||
});
|
||||
}
|
||||
|
||||
function getComponentsMap() {
|
||||
const assetJson = fs.readFileSync('./demo/assets.json', { encoding: 'utf8' });
|
||||
const assets = JSON.parse(assetJson);
|
||||
const { components } = assets;
|
||||
|
||||
const componentsMap = components
|
||||
.filter((c) => !!c.npm)
|
||||
.map((c) => ({
|
||||
componentName: c.componentName,
|
||||
...(c.npm || {}),
|
||||
}));
|
||||
|
||||
return componentsMap;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
||||
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
||||
const builder = createIceJsProjectBuilder();
|
||||
|
||||
builder.generateProject(schemaJson).then(result => {
|
||||
builder.generateProject(schemaJson).then((result) => {
|
||||
displayResultInConsole(result);
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then(response =>
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then((response) =>
|
||||
console.log('Write to disk: ', JSON.stringify(response)),
|
||||
);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
function demo() {
|
||||
const schemaJson = fs.readFileSync('./demo/schema.json', { encoding: 'utf8' });
|
||||
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
||||
const builder = createIceJsProjectBuilder();
|
||||
|
||||
const componentsMap = getComponentsMap();
|
||||
const root = JSON.parse(schemaJson);
|
||||
|
||||
const fullSchema = {
|
||||
version: '1.0.0',
|
||||
config: {
|
||||
historyMode: 'hash',
|
||||
targetRootID: 'J_Container',
|
||||
},
|
||||
meta: {
|
||||
name: 'demoproject',
|
||||
},
|
||||
componentsTree: [root],
|
||||
componentsMap,
|
||||
};
|
||||
|
||||
builder.generateProject(fullSchema).then((result) => {
|
||||
displayResultInConsole(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
function exportModule() {
|
||||
const schemaJson = fs.readFileSync('./demo/shenmaSample.json', { encoding: 'utf8' });
|
||||
const moduleBuilder = CodeGenerator.createModuleBuilder({
|
||||
@ -66,13 +108,11 @@ function exportModule() {
|
||||
CodeGenerator.plugins.react.jsx(),
|
||||
CodeGenerator.plugins.style.css(),
|
||||
],
|
||||
postProcessors: [
|
||||
CodeGenerator.postprocessor.prettier(),
|
||||
],
|
||||
postProcessors: [CodeGenerator.postprocessor.prettier()],
|
||||
mainFileName: 'index',
|
||||
});
|
||||
|
||||
moduleBuilder.generateModuleCode(schemaJson).then(result => {
|
||||
moduleBuilder.generateModuleCode(schemaJson).then((result) => {
|
||||
displayResultInConsole(result);
|
||||
return result;
|
||||
});
|
||||
@ -81,7 +121,7 @@ function exportModule() {
|
||||
function exportProject() {
|
||||
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
||||
|
||||
const builder = CodeGenerator.createProjectBuilder({
|
||||
const builder = CodeGenerator.createProjectBuilder({
|
||||
template: CodeGenerator.solutionParts.icejs.template,
|
||||
plugins: {
|
||||
components: [
|
||||
@ -108,41 +148,21 @@ function exportProject() {
|
||||
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(),
|
||||
],
|
||||
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(),
|
||||
],
|
||||
postProcessors: [CodeGenerator.postprocessor.prettier()],
|
||||
});
|
||||
|
||||
builder.generateProject(schemaJson).then(result => {
|
||||
builder.generateProject(schemaJson).then((result) => {
|
||||
displayResultInConsole(result);
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then(response =>
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then((response) =>
|
||||
console.log('Write to disk: ', JSON.stringify(response)),
|
||||
);
|
||||
return result;
|
||||
@ -151,4 +171,5 @@ function exportProject() {
|
||||
|
||||
// main();
|
||||
// exportModule();
|
||||
exportProject();
|
||||
// exportProject();
|
||||
demo();
|
||||
|
||||
138
packages/code-generator/demo/schema.json
Normal file
138
packages/code-generator/demo/schema.json
Normal file
@ -0,0 +1,138 @@
|
||||
{
|
||||
"componentName": "Page",
|
||||
"fileName": "test",
|
||||
"dataSource": {
|
||||
"list": []
|
||||
},
|
||||
"state": {
|
||||
"text": "outter"
|
||||
},
|
||||
|
||||
"css": "body {font-size: 12px;} .botton{width:100px;color:#ff00ff}",
|
||||
"lifeCycles": {
|
||||
"componentDidMount": {
|
||||
"type": "JSExpression",
|
||||
"value": "function() {\n \t\tconsole.log('did mount');\n\t}"
|
||||
},
|
||||
"componentWillUnmount": {
|
||||
"type": "JSExpression",
|
||||
"value": "function() {\n \t\tconsole.log('will umount');\n\t}"
|
||||
}
|
||||
},
|
||||
|
||||
"methods": {
|
||||
"testFunc": {
|
||||
"type": "JSFunction",
|
||||
"value": "function() {console.log('test func');}"
|
||||
}
|
||||
},
|
||||
|
||||
"props": {
|
||||
"ref": "outterView",
|
||||
"autoLoading": true,
|
||||
"style": {
|
||||
"padding": 20
|
||||
}
|
||||
},
|
||||
"children": [{
|
||||
"componentName": "Form",
|
||||
"props": {
|
||||
"labelCol": 3,
|
||||
"style": {},
|
||||
"ref": "testForm"
|
||||
},
|
||||
"children": [{
|
||||
"componentName": "Form.Item",
|
||||
"props": {
|
||||
"label": "姓名:",
|
||||
"name": "name",
|
||||
"initValue": "李雷"
|
||||
},
|
||||
"children": [{
|
||||
"componentName": "Input",
|
||||
"props": {
|
||||
"placeholder": "请输入",
|
||||
"size": "medium",
|
||||
"style": {
|
||||
"width": 320
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
"componentName": "Form.Item",
|
||||
"props": {
|
||||
"label": "年龄:",
|
||||
"name": "age",
|
||||
"initValue": "22"
|
||||
},
|
||||
"children": [{
|
||||
"componentName": "NumberPicker",
|
||||
"props": {
|
||||
"size": "medium",
|
||||
"type": "normal"
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
"componentName": "Form.Item",
|
||||
"props": {
|
||||
"label": "职业:",
|
||||
"name": "profession"
|
||||
},
|
||||
"children": [{
|
||||
"componentName": "Select",
|
||||
"props": {
|
||||
"dataSource": [{
|
||||
"label": "教师",
|
||||
"value": "t"
|
||||
}, {
|
||||
"label": "医生",
|
||||
"value": "d"
|
||||
}, {
|
||||
"label": "歌手",
|
||||
"value": "s"
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
"componentName": "Form.Item",
|
||||
"props": {
|
||||
"style": {
|
||||
"textAlign": "center"
|
||||
}
|
||||
},
|
||||
"children": [{
|
||||
"componentName": "Button.Group",
|
||||
"props": {},
|
||||
"children": [{
|
||||
"componentName": "Button",
|
||||
"props": {
|
||||
"type": "primary",
|
||||
"style": {
|
||||
"margin": "0 5px 0 5px"
|
||||
},
|
||||
"htmlType": "submit"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"componentName": "Icon",
|
||||
"props": {
|
||||
"type": "success"
|
||||
}
|
||||
},
|
||||
"提交"
|
||||
]
|
||||
}, {
|
||||
"componentName": "Button",
|
||||
"props": {
|
||||
"type": "normal",
|
||||
"style": {
|
||||
"margin": "0 5px 0 5px"
|
||||
},
|
||||
"htmlType": "reset"
|
||||
},
|
||||
"children": "重置"
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user