mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-16 15:01:15 +00:00
feat: project builder fix & publish demo to disk
This commit is contained in:
parent
a5ee6bd558
commit
26983b38c2
@ -8,6 +8,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rimraf lib && tsc",
|
"build": "rimraf lib && tsc",
|
||||||
|
"demo": "ts-node -r tsconfig-paths/register ./src/demo/main.ts",
|
||||||
"test": "ava"
|
"test": "ava"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -18,7 +19,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^1.0.1",
|
"ava": "^1.0.1",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"ts-node": "^7.0.1"
|
"ts-node": "^7.0.1",
|
||||||
|
"tsconfig-paths": "^3.9.0"
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"compileEnhancements": false,
|
"compileEnhancements": false,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { IResultDir, IResultFile } from '@/types';
|
import { IResultDir, IResultFile } from '@/types';
|
||||||
|
|
||||||
import CodeGenerator from '@/index';
|
import CodeGenerator from '@/index';
|
||||||
|
import { createDiskPublisher } from '@/publisher/disk';
|
||||||
import demoSchema from './simpleDemo';
|
import demoSchema from './simpleDemo';
|
||||||
|
|
||||||
function flatFiles(rootName: string | null, dir: IResultDir): IResultFile[] {
|
function flatFiles(rootName: string | null, dir: IResultDir): IResultFile[] {
|
||||||
@ -16,16 +17,34 @@ function flatFiles(rootName: string | null, dir: IResultDir): IResultFile[] {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function displayResultInConsole(root: IResultDir): void {
|
||||||
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
const files = flatFiles('.', root);
|
||||||
const builder = createIceJsProjectBuilder();
|
|
||||||
builder.generateProject(demoSchema).then(result => {
|
|
||||||
const files = flatFiles('.', result);
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
console.log(`========== ${file.name} Start ==========`);
|
console.log(`========== ${file.name} Start ==========`);
|
||||||
console.log(file.content);
|
console.log(file.content);
|
||||||
console.log(`========== ${file.name} End ==========`);
|
console.log(`========== ${file.name} End ==========`);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeResultToDisk(root: IResultDir, path: string): Promise<any> {
|
||||||
|
const publisher = createDiskPublisher();
|
||||||
|
|
||||||
|
return publisher.publish({
|
||||||
|
project: root,
|
||||||
|
outputPath: path,
|
||||||
|
projectSlug: 'demo-project',
|
||||||
|
createProjectFolder: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
||||||
|
const builder = createIceJsProjectBuilder();
|
||||||
|
builder.generateProject(demoSchema).then(result => {
|
||||||
|
// displayResultInConsole(result);
|
||||||
|
writeResultToDisk(result, '/Users/armslave/lowcodeDemo').then(response =>
|
||||||
|
console.log('Write to disk: ', JSON.stringify(response)),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import { IProjectSchema } from '@/types';
|
import { IProjectSchema } from '@/types';
|
||||||
|
|
||||||
|
// meta: {
|
||||||
|
// title: '测试',
|
||||||
|
// router: '/',
|
||||||
|
// },
|
||||||
|
|
||||||
const demoData: IProjectSchema = {
|
const demoData: IProjectSchema = {
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
componentsMap: [
|
componentsMap: [
|
||||||
@ -59,6 +64,10 @@ const demoData: IProjectSchema = {
|
|||||||
{
|
{
|
||||||
componentName: 'Page',
|
componentName: 'Page',
|
||||||
id: 'node$1',
|
id: 'node$1',
|
||||||
|
meta: {
|
||||||
|
title: '测试',
|
||||||
|
router: '/',
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
ref: 'outterView',
|
ref: 'outterView',
|
||||||
autoLoading: true,
|
autoLoading: true,
|
||||||
|
|||||||
@ -68,6 +68,8 @@ export class ProjectBuilder implements IProjectBuilder {
|
|||||||
let buildResult: IModuleInfo[] = [];
|
let buildResult: IModuleInfo[] = [];
|
||||||
|
|
||||||
// Generator Code module
|
// Generator Code module
|
||||||
|
// components
|
||||||
|
// pages
|
||||||
const containerBuildResult: IModuleInfo[] = await Promise.all<IModuleInfo>(
|
const containerBuildResult: IModuleInfo[] = await Promise.all<IModuleInfo>(
|
||||||
parseResult.containers.map(async containerInfo => {
|
parseResult.containers.map(async containerInfo => {
|
||||||
let builder: IModuleBuilder;
|
let builder: IModuleBuilder;
|
||||||
@ -91,6 +93,7 @@ export class ProjectBuilder implements IProjectBuilder {
|
|||||||
);
|
);
|
||||||
buildResult = buildResult.concat(containerBuildResult);
|
buildResult = buildResult.concat(containerBuildResult);
|
||||||
|
|
||||||
|
// router
|
||||||
if (parseResult.globalRouter && builders.router) {
|
if (parseResult.globalRouter && builders.router) {
|
||||||
const { files } = await builders.router.generateModule(
|
const { files } = await builders.router.generateModule(
|
||||||
parseResult.globalRouter,
|
parseResult.globalRouter,
|
||||||
@ -102,6 +105,92 @@ export class ProjectBuilder implements IProjectBuilder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// entry
|
||||||
|
if (parseResult.project && builders.entry) {
|
||||||
|
const { files } = await builders.entry.generateModule(
|
||||||
|
parseResult.project,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.entry.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// constants?
|
||||||
|
if (
|
||||||
|
parseResult.project &&
|
||||||
|
builders.constants &&
|
||||||
|
this.template.slots.constants
|
||||||
|
) {
|
||||||
|
const { files } = await builders.constants.generateModule(
|
||||||
|
parseResult.project,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.constants.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// utils?
|
||||||
|
if (
|
||||||
|
parseResult.globalUtils &&
|
||||||
|
builders.utils &&
|
||||||
|
this.template.slots.utils
|
||||||
|
) {
|
||||||
|
const { files } = await builders.utils.generateModule(
|
||||||
|
parseResult.globalUtils,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.utils.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// i18n?
|
||||||
|
if (parseResult.globalI18n && builders.i18n && this.template.slots.i18n) {
|
||||||
|
const { files } = await builders.i18n.generateModule(
|
||||||
|
parseResult.globalI18n,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.i18n.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// globalStyle
|
||||||
|
if (parseResult.project && builders.globalStyle) {
|
||||||
|
const { files } = await builders.globalStyle.generateModule(
|
||||||
|
parseResult.project,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.globalStyle.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// htmlEntry
|
||||||
|
if (parseResult.project && builders.htmlEntry) {
|
||||||
|
const { files } = await builders.htmlEntry.generateModule(
|
||||||
|
parseResult.project,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.htmlEntry.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// packageJSON
|
||||||
|
if (parseResult.project && builders.packageJSON) {
|
||||||
|
const { files } = await builders.packageJSON.generateModule(
|
||||||
|
parseResult.project,
|
||||||
|
);
|
||||||
|
|
||||||
|
buildResult.push({
|
||||||
|
path: this.template.slots.packageJSON.path,
|
||||||
|
files,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Post Process
|
// Post Process
|
||||||
|
|
||||||
// Combine Modules
|
// Combine Modules
|
||||||
|
|||||||
@ -33,7 +33,6 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
|
|||||||
version: '0.1.5',
|
version: '0.1.5',
|
||||||
description: '轻量级模板,使用 JavaScript,仅包含基础的 Layout。',
|
description: '轻量级模板,使用 JavaScript,仅包含基础的 Layout。',
|
||||||
dependencies: {
|
dependencies: {
|
||||||
'@alifd/next': '^1.19.4',
|
|
||||||
moment: '^2.24.0',
|
moment: '^2.24.0',
|
||||||
react: '^16.4.1',
|
react: '^16.4.1',
|
||||||
'react-dom': '^16.4.1',
|
'react-dom': '^16.4.1',
|
||||||
|
|||||||
@ -217,7 +217,7 @@ export interface IBasicMeta {
|
|||||||
|
|
||||||
export interface IPageMeta extends IBasicMeta {
|
export interface IPageMeta extends IBasicMeta {
|
||||||
router: string; // 页面路由
|
router: string; // 页面路由
|
||||||
spmb: string; // spm
|
spmb?: string; // spm
|
||||||
}
|
}
|
||||||
|
|
||||||
// "theme": {
|
// "theme": {
|
||||||
@ -250,6 +250,6 @@ export interface IAppMeta {
|
|||||||
git_group?: string; // 应用对应git分组名
|
git_group?: string; // 应用对应git分组名
|
||||||
project_name?: string; // 应用对应git的project名称
|
project_name?: string; // 应用对应git的project名称
|
||||||
description?: string; // 应用描述
|
description?: string; // 应用描述
|
||||||
spma: string; // 应用spma A位信息
|
spma?: string; // 应用spma A位信息
|
||||||
creator?: string; // author
|
creator?: string; // author
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user