mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-10 01:48:18 +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) {
|
function flatFiles(rootName, dir) {
|
||||||
const dirRoot = rootName ? `${rootName}/${dir.name}` : dir.name;
|
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}`,
|
name: `${dirRoot}/${file.name}.${file.ext}`,
|
||||||
content: file.content,
|
content: file.content,
|
||||||
ext: '',
|
ext: '',
|
||||||
}));
|
}));
|
||||||
const filesInSub = dir.dirs.map(subDir => flatFiles(`${dirRoot}`, subDir));
|
const filesInSub = dir.dirs.map((subDir) => flatFiles(`${dirRoot}`, subDir));
|
||||||
const result = files.concat.apply(files, filesInSub);
|
const result = files.concat(...filesInSub);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayResultInConsole(root, fileName) {
|
function displayResultInConsole(root, fileName) {
|
||||||
const files = flatFiles('.', root);
|
const files = flatFiles('.', root);
|
||||||
files.forEach(file => {
|
files.forEach((file) => {
|
||||||
if (!fileName || fileName === file.name) {
|
if (!fileName || fileName === file.name) {
|
||||||
console.log(`========== ${file.name} Start ==========`);
|
console.log(`========== ${file.name} Start ==========`);
|
||||||
console.log(file.content);
|
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() {
|
function main() {
|
||||||
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
||||||
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
||||||
const builder = createIceJsProjectBuilder();
|
const builder = createIceJsProjectBuilder();
|
||||||
|
|
||||||
builder.generateProject(schemaJson).then(result => {
|
builder.generateProject(schemaJson).then((result) => {
|
||||||
displayResultInConsole(result);
|
displayResultInConsole(result);
|
||||||
writeResultToDisk(result, 'output/lowcodeDemo').then(response =>
|
writeResultToDisk(result, 'output/lowcodeDemo').then((response) =>
|
||||||
console.log('Write to disk: ', JSON.stringify(response)),
|
console.log('Write to disk: ', JSON.stringify(response)),
|
||||||
);
|
);
|
||||||
return result;
|
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() {
|
function exportModule() {
|
||||||
const schemaJson = fs.readFileSync('./demo/shenmaSample.json', { encoding: 'utf8' });
|
const schemaJson = fs.readFileSync('./demo/shenmaSample.json', { encoding: 'utf8' });
|
||||||
const moduleBuilder = CodeGenerator.createModuleBuilder({
|
const moduleBuilder = CodeGenerator.createModuleBuilder({
|
||||||
@ -66,13 +108,11 @@ function exportModule() {
|
|||||||
CodeGenerator.plugins.react.jsx(),
|
CodeGenerator.plugins.react.jsx(),
|
||||||
CodeGenerator.plugins.style.css(),
|
CodeGenerator.plugins.style.css(),
|
||||||
],
|
],
|
||||||
postProcessors: [
|
postProcessors: [CodeGenerator.postprocessor.prettier()],
|
||||||
CodeGenerator.postprocessor.prettier(),
|
|
||||||
],
|
|
||||||
mainFileName: 'index',
|
mainFileName: 'index',
|
||||||
});
|
});
|
||||||
|
|
||||||
moduleBuilder.generateModuleCode(schemaJson).then(result => {
|
moduleBuilder.generateModuleCode(schemaJson).then((result) => {
|
||||||
displayResultInConsole(result);
|
displayResultInConsole(result);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
@ -81,7 +121,7 @@ function exportModule() {
|
|||||||
function exportProject() {
|
function exportProject() {
|
||||||
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
|
||||||
|
|
||||||
const builder = CodeGenerator.createProjectBuilder({
|
const builder = CodeGenerator.createProjectBuilder({
|
||||||
template: CodeGenerator.solutionParts.icejs.template,
|
template: CodeGenerator.solutionParts.icejs.template,
|
||||||
plugins: {
|
plugins: {
|
||||||
components: [
|
components: [
|
||||||
@ -108,41 +148,21 @@ function exportProject() {
|
|||||||
CodeGenerator.plugins.react.jsx(),
|
CodeGenerator.plugins.react.jsx(),
|
||||||
CodeGenerator.plugins.style.css(),
|
CodeGenerator.plugins.style.css(),
|
||||||
],
|
],
|
||||||
router: [
|
router: [CodeGenerator.plugins.common.esmodule(), CodeGenerator.solutionParts.icejs.plugins.router()],
|
||||||
CodeGenerator.plugins.common.esmodule(),
|
entry: [CodeGenerator.solutionParts.icejs.plugins.entry()],
|
||||||
CodeGenerator.solutionParts.icejs.plugins.router(),
|
constants: [CodeGenerator.plugins.project.constants()],
|
||||||
],
|
utils: [CodeGenerator.plugins.common.esmodule(), CodeGenerator.plugins.project.utils()],
|
||||||
entry: [
|
i18n: [CodeGenerator.plugins.project.i18n()],
|
||||||
CodeGenerator.solutionParts.icejs.plugins.entry(),
|
globalStyle: [CodeGenerator.solutionParts.icejs.plugins.globalStyle()],
|
||||||
],
|
htmlEntry: [CodeGenerator.solutionParts.icejs.plugins.entryHtml()],
|
||||||
constants: [
|
packageJSON: [CodeGenerator.solutionParts.icejs.plugins.packageJSON()],
|
||||||
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: [
|
postProcessors: [CodeGenerator.postprocessor.prettier()],
|
||||||
CodeGenerator.postprocessor.prettier(),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.generateProject(schemaJson).then(result => {
|
builder.generateProject(schemaJson).then((result) => {
|
||||||
displayResultInConsole(result);
|
displayResultInConsole(result);
|
||||||
writeResultToDisk(result, 'output/lowcodeDemo').then(response =>
|
writeResultToDisk(result, 'output/lowcodeDemo').then((response) =>
|
||||||
console.log('Write to disk: ', JSON.stringify(response)),
|
console.log('Write to disk: ', JSON.stringify(response)),
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
@ -151,4 +171,5 @@ function exportProject() {
|
|||||||
|
|
||||||
// main();
|
// main();
|
||||||
// exportModule();
|
// 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