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