mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-04-20 04:18:05 +00:00
feat: 🎸 add demo-server
This commit is contained in:
parent
4f042c6e6d
commit
df35c6a0b4
@ -16,6 +16,7 @@
|
|||||||
"pub": "lerna publish --cd-version patch",
|
"pub": "lerna publish --cd-version patch",
|
||||||
"setup": "./scripts/setup.sh",
|
"setup": "./scripts/setup.sh",
|
||||||
"start": "./scripts/start.sh",
|
"start": "./scripts/start.sh",
|
||||||
|
"start:server": "./scripts/start-server.sh",
|
||||||
"test": "lerna run test --stream",
|
"test": "lerna run test --stream",
|
||||||
"test:snapshot": "lerna run test:snapshot"
|
"test:snapshot": "lerna run test:snapshot"
|
||||||
},
|
},
|
||||||
|
|||||||
24
packages/demo-server/.eslintrc.js
Normal file
24
packages/demo-server/.eslintrc.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module.exports = {
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
parserOptions: {
|
||||||
|
project: 'tsconfig.json',
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||||
|
extends: [
|
||||||
|
'plugin:@typescript-eslint/eslint-recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'prettier',
|
||||||
|
'prettier/@typescript-eslint',
|
||||||
|
],
|
||||||
|
root: true,
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
jest: true,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'@typescript-eslint/interface-name-prefix': 'off',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
},
|
||||||
|
};
|
||||||
4
packages/demo-server/.prettierrc
Normal file
4
packages/demo-server/.prettierrc
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
||||||
75
packages/demo-server/README.md
Normal file
75
packages/demo-server/README.md
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
|
||||||
|
[travis-url]: https://travis-ci.org/nestjs/nest
|
||||||
|
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
|
||||||
|
[linux-url]: https://travis-ci.org/nestjs/nest
|
||||||
|
|
||||||
|
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
|
||||||
|
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
|
||||||
|
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
|
||||||
|
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
|
||||||
|
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
|
||||||
|
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||||
|
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
|
||||||
|
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||||
|
</p>
|
||||||
|
<!--[](https://opencollective.com/nest#backer)
|
||||||
|
[](https://opencollective.com/nest#sponsor)-->
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# development
|
||||||
|
$ npm run start
|
||||||
|
|
||||||
|
# watch mode
|
||||||
|
$ npm run start:dev
|
||||||
|
|
||||||
|
# production mode
|
||||||
|
$ npm run start:prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# unit tests
|
||||||
|
$ npm run test
|
||||||
|
|
||||||
|
# e2e tests
|
||||||
|
$ npm run test:e2e
|
||||||
|
|
||||||
|
# test coverage
|
||||||
|
$ npm run test:cov
|
||||||
|
```
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||||
|
|
||||||
|
## Stay in touch
|
||||||
|
|
||||||
|
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||||
|
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||||
|
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Nest is [MIT licensed](LICENSE).
|
||||||
4
packages/demo-server/nest-cli.json
Normal file
4
packages/demo-server/nest-cli.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"collection": "@nestjs/schematics",
|
||||||
|
"sourceRoot": "src"
|
||||||
|
}
|
||||||
67
packages/demo-server/package.json
Normal file
67
packages/demo-server/package.json
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"name": "@ali/lowcode-demo-server",
|
||||||
|
"version": "0.8.37",
|
||||||
|
"private": true,
|
||||||
|
"description": "低代码引擎 DEMO Server 端",
|
||||||
|
"scripts": {
|
||||||
|
"prebuild": "rimraf dist",
|
||||||
|
"build": "nest build",
|
||||||
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
|
"start": "nest start",
|
||||||
|
"start:debug": "nest start --debug --watch",
|
||||||
|
"start:dev": "nest start --watch",
|
||||||
|
"start:prod": "node dist/main",
|
||||||
|
"test": "jest",
|
||||||
|
"test:cov": "jest --coverage",
|
||||||
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||||
|
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||||
|
"test:watch": "jest --watch"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"coverageDirectory": "../coverage",
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"js",
|
||||||
|
"json",
|
||||||
|
"ts"
|
||||||
|
],
|
||||||
|
"rootDir": "src",
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testRegex": ".spec.ts$",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ali/lowcode-code-generator": "0.8.8",
|
||||||
|
"@nestjs/common": "^7.0.0",
|
||||||
|
"@nestjs/core": "^7.0.0",
|
||||||
|
"@nestjs/platform-express": "^7.0.0",
|
||||||
|
"jszip": "^3.5.0",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"rxjs": "^6.5.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nestjs/cli": "^7.0.0",
|
||||||
|
"@nestjs/schematics": "^7.0.0",
|
||||||
|
"@nestjs/testing": "^7.0.0",
|
||||||
|
"@types/express": "^4.17.3",
|
||||||
|
"@types/jest": "25.2.3",
|
||||||
|
"@types/node": "^13.9.1",
|
||||||
|
"@types/supertest": "^2.0.8",
|
||||||
|
"@typescript-eslint/eslint-plugin": "3.0.2",
|
||||||
|
"@typescript-eslint/parser": "3.0.2",
|
||||||
|
"eslint": "7.1.0",
|
||||||
|
"eslint-config-prettier": "^6.10.0",
|
||||||
|
"eslint-plugin-import": "^2.20.1",
|
||||||
|
"jest": "26.0.1",
|
||||||
|
"prettier": "^1.19.1",
|
||||||
|
"supertest": "^4.0.2",
|
||||||
|
"ts-jest": "26.1.0",
|
||||||
|
"ts-loader": "^6.2.1",
|
||||||
|
"ts-node": "^8.6.2",
|
||||||
|
"tsconfig-paths": "^3.9.0",
|
||||||
|
"typescript": "^3.7.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
18
packages/demo-server/src/api/api.controller.spec.ts
Normal file
18
packages/demo-server/src/api/api.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ApiController } from './api.controller';
|
||||||
|
|
||||||
|
describe('Api Controller', () => {
|
||||||
|
let controller: ApiController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [ApiController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<ApiController>(ApiController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
21
packages/demo-server/src/api/api.controller.ts
Normal file
21
packages/demo-server/src/api/api.controller.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { Controller, Res, Get, Post, Body, Header } from '@nestjs/common';
|
||||||
|
import { Response } from 'express';
|
||||||
|
import { ApiService } from './api.service';
|
||||||
|
import { GenerateProjectDto } from '../dto/generate-project.dto';
|
||||||
|
|
||||||
|
@Controller('api')
|
||||||
|
export class ApiController {
|
||||||
|
constructor(private readonly apiService: ApiService) {}
|
||||||
|
|
||||||
|
@Get('generate/test')
|
||||||
|
generateTest() {
|
||||||
|
return 'generate test';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('generate/project')
|
||||||
|
@Header('Content-Type', 'application/zip')
|
||||||
|
async generateProject(@Res() res: Response, @Body() dto: GenerateProjectDto) {
|
||||||
|
const file = await this.apiService.generateProject(dto.schema);
|
||||||
|
file.pipe(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
packages/demo-server/src/api/api.service.spec.ts
Normal file
18
packages/demo-server/src/api/api.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ApiService } from './api.service';
|
||||||
|
|
||||||
|
describe('ApiService', () => {
|
||||||
|
let service: ApiService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [ApiService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<ApiService>(ApiService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
30
packages/demo-server/src/api/api.service.ts
Normal file
30
packages/demo-server/src/api/api.service.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import * as os from 'os';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import CodeGenerator from '@ali/lowcode-code-generator';
|
||||||
|
import { createZipPublisher } from '../publisher';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ApiService {
|
||||||
|
async generateProject(schema: string) {
|
||||||
|
const tmpDir = os.tmpdir();
|
||||||
|
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
|
||||||
|
const builder = createIceJsProjectBuilder();
|
||||||
|
const publisher = createZipPublisher({
|
||||||
|
outputPath: tmpDir,
|
||||||
|
projectSlug: 'demo-project',
|
||||||
|
});
|
||||||
|
const filePath = path.join(tmpDir, 'demo-project.zip');
|
||||||
|
|
||||||
|
const result = await builder.generateProject(schema);
|
||||||
|
publisher.setProject(result);
|
||||||
|
const response = await publisher.publish();
|
||||||
|
if (!response.success) {
|
||||||
|
throw new Error('generateProject failed');
|
||||||
|
}
|
||||||
|
return fs.createReadStream(filePath);
|
||||||
|
|
||||||
|
// return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
packages/demo-server/src/app.controller.spec.ts
Normal file
22
packages/demo-server/src/app.controller.spec.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
describe('AppController', () => {
|
||||||
|
let appController: AppController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const app: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
appController = app.get<AppController>(AppController);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('root', () => {
|
||||||
|
it('should return "Hello World!"', () => {
|
||||||
|
expect(appController.getHello()).toBe('Hello World!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
12
packages/demo-server/src/app.controller.ts
Normal file
12
packages/demo-server/src/app.controller.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class AppController {
|
||||||
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
getHello(): string {
|
||||||
|
return this.appService.getHello();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
packages/demo-server/src/app.module.ts
Normal file
12
packages/demo-server/src/app.module.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
import { ApiController } from './api/api.controller';
|
||||||
|
import { ApiService } from './api/api.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
controllers: [AppController, ApiController],
|
||||||
|
providers: [AppService, ApiService],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
8
packages/demo-server/src/app.service.ts
Normal file
8
packages/demo-server/src/app.service.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AppService {
|
||||||
|
getHello(): string {
|
||||||
|
return 'Hello World!';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
import { GenerateProjectDto } from './generate-project.dto';
|
||||||
|
|
||||||
|
describe('GenerateProjectDto', () => {
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(new GenerateProjectDto()).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
3
packages/demo-server/src/dto/generate-project.dto.ts
Normal file
3
packages/demo-server/src/dto/generate-project.dto.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export class GenerateProjectDto {
|
||||||
|
schema: string;
|
||||||
|
}
|
||||||
9
packages/demo-server/src/main.ts
Normal file
9
packages/demo-server/src/main.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
const app = await NestFactory.create(AppModule);
|
||||||
|
app.enableCors();
|
||||||
|
await app.listen(7002);
|
||||||
|
}
|
||||||
|
bootstrap();
|
||||||
76
packages/demo-server/src/publisher/index.ts
Normal file
76
packages/demo-server/src/publisher/index.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import { IResultDir } from '@ali/lowcode-code-generator';
|
||||||
|
import { isNodeProcess, writeZipToDisk, generateProjectZip } from './utils'
|
||||||
|
|
||||||
|
export type PublisherFactory<T, U> = (configuration?: Partial<T>) => U;
|
||||||
|
|
||||||
|
export interface IPublisher<T, U> {
|
||||||
|
publish: (options?: T) => Promise<IPublisherResponse<U>>;
|
||||||
|
getProject: () => IResultDir | void;
|
||||||
|
setProject: (project: IResultDir) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPublisherFactoryParams {
|
||||||
|
project?: IResultDir;
|
||||||
|
}
|
||||||
|
export interface IPublisherResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
payload?: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare type ZipPublisherResponse = string | Buffer | Blob
|
||||||
|
|
||||||
|
export interface ZipFactoryParams extends IPublisherFactoryParams {
|
||||||
|
outputPath?: string
|
||||||
|
projectSlug?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ZipPublisher extends IPublisher<ZipFactoryParams, ZipPublisherResponse> {
|
||||||
|
getOutputPath: () => string
|
||||||
|
setOutputPath: (path: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher> = (
|
||||||
|
params: ZipFactoryParams = {}
|
||||||
|
): ZipPublisher => {
|
||||||
|
let { project, outputPath } = params
|
||||||
|
|
||||||
|
const getProject = () => project
|
||||||
|
const setProject = (projectToSet: IResultDir) => {
|
||||||
|
project = projectToSet
|
||||||
|
}
|
||||||
|
|
||||||
|
const getOutputPath = () => outputPath
|
||||||
|
const setOutputPath = (path: string) => {
|
||||||
|
outputPath = path
|
||||||
|
}
|
||||||
|
|
||||||
|
const publish = async (options: ZipFactoryParams = {}) => {
|
||||||
|
const projectToPublish = options.project || project
|
||||||
|
if (!projectToPublish) {
|
||||||
|
throw new Error('MissingProject');
|
||||||
|
}
|
||||||
|
|
||||||
|
const zipName = options.projectSlug || params.projectSlug || projectToPublish.name
|
||||||
|
|
||||||
|
try {
|
||||||
|
const zipContent = await generateProjectZip(projectToPublish)
|
||||||
|
|
||||||
|
// If not output path is provided, zip is not written to disk
|
||||||
|
const projectOutputPath = options.outputPath || outputPath
|
||||||
|
if (projectOutputPath && isNodeProcess()) {
|
||||||
|
await writeZipToDisk(projectOutputPath, zipContent, zipName)
|
||||||
|
}
|
||||||
|
return { success: true, payload: zipContent }
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('ZipUnexpected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
publish,
|
||||||
|
getProject,
|
||||||
|
setProject,
|
||||||
|
getOutputPath,
|
||||||
|
setOutputPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
57
packages/demo-server/src/publisher/utils.ts
Normal file
57
packages/demo-server/src/publisher/utils.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import * as JSZip from 'jszip';
|
||||||
|
import { IResultFile, IResultDir } from '@ali/lowcode-code-generator';
|
||||||
|
|
||||||
|
export const isNodeProcess = (): boolean => {
|
||||||
|
return (
|
||||||
|
typeof process === 'object' &&
|
||||||
|
typeof process.versions === 'object' &&
|
||||||
|
typeof process.versions.node !== 'undefined'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const writeZipToDisk = (
|
||||||
|
zipFolderPath: string,
|
||||||
|
content: Buffer | Blob,
|
||||||
|
zipName: string
|
||||||
|
): void => {
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
if (!fs.existsSync(zipFolderPath)) {
|
||||||
|
fs.mkdirSync(zipFolderPath, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
const zipPath = path.join(zipFolderPath, `${zipName}.zip`)
|
||||||
|
|
||||||
|
const writeStream = fs.createWriteStream(zipPath)
|
||||||
|
writeStream.write(content)
|
||||||
|
writeStream.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateProjectZip = async (project: IResultDir): Promise<Buffer | Blob> => {
|
||||||
|
let zip = new JSZip()
|
||||||
|
zip = writeFolderToZip(project, zip, true)
|
||||||
|
const zipType = isNodeProcess() ? 'nodebuffer' : 'blob'
|
||||||
|
return zip.generateAsync({ type: zipType })
|
||||||
|
}
|
||||||
|
|
||||||
|
const writeFolderToZip = (
|
||||||
|
folder: IResultDir,
|
||||||
|
parentFolder: JSZip,
|
||||||
|
ignoreFolder: boolean = false
|
||||||
|
) => {
|
||||||
|
const zipFolder = ignoreFolder ? parentFolder : parentFolder.folder(folder.name)
|
||||||
|
|
||||||
|
folder.files.forEach((file: IResultFile) => {
|
||||||
|
// const options = file.contentEncoding === 'base64' ? { base64: true } : {}
|
||||||
|
const options = {};
|
||||||
|
const fileName = file.ext ? `${file.name}.${file.ext}` : file.name
|
||||||
|
zipFolder.file(fileName, file.content, options)
|
||||||
|
})
|
||||||
|
|
||||||
|
folder.dirs.forEach((subFolder: IResultDir) => {
|
||||||
|
writeFolderToZip(subFolder, zipFolder)
|
||||||
|
})
|
||||||
|
|
||||||
|
return parentFolder
|
||||||
|
}
|
||||||
24
packages/demo-server/test/app.e2e-spec.ts
Normal file
24
packages/demo-server/test/app.e2e-spec.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { INestApplication } from '@nestjs/common';
|
||||||
|
import * as request from 'supertest';
|
||||||
|
import { AppModule } from './../src/app.module';
|
||||||
|
|
||||||
|
describe('AppController (e2e)', () => {
|
||||||
|
let app: INestApplication;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||||
|
imports: [AppModule],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
app = moduleFixture.createNestApplication();
|
||||||
|
await app.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('/ (GET)', () => {
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.get('/')
|
||||||
|
.expect(200)
|
||||||
|
.expect('Hello World!');
|
||||||
|
});
|
||||||
|
});
|
||||||
9
packages/demo-server/test/jest-e2e.json
Normal file
9
packages/demo-server/test/jest-e2e.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"moduleFileExtensions": ["js", "json", "ts"],
|
||||||
|
"rootDir": ".",
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testRegex": ".e2e-spec.ts$",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
}
|
||||||
|
}
|
||||||
4
packages/demo-server/tsconfig.build.json
Normal file
4
packages/demo-server/tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||||
|
}
|
||||||
15
packages/demo-server/tsconfig.json
Normal file
15
packages/demo-server/tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"declaration": true,
|
||||||
|
"removeComments": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"target": "es2017",
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"baseUrl": "./",
|
||||||
|
"incremental": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@ interface BasicSection {
|
|||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CODEOUT_SERVICE_HOST = '30.13.88.126:3000';
|
const CODEOUT_SERVICE_HOST = 'localhost:7002';
|
||||||
|
|
||||||
const Codeout = ({ editor }: PluginProps) => {
|
const Codeout = ({ editor }: PluginProps) => {
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
|
|||||||
@ -53,5 +53,5 @@
|
|||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "http://registry.npm.alibaba-inc.com"
|
"registry": "http://registry.npm.alibaba-inc.com"
|
||||||
},
|
},
|
||||||
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.8.13/build/index.html"
|
"homepage": "https:/unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@0.8.13/build/index.html"
|
||||||
}
|
}
|
||||||
|
|||||||
5
scripts/start-server.sh
Executable file
5
scripts/start-server.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# FIXME! do not run build
|
||||||
|
lerna exec --scope @ali/lowcode-code-generator -- npm run build
|
||||||
|
lerna exec --scope @ali/lowcode-demo-server -- npm start
|
||||||
Loading…
x
Reference in New Issue
Block a user