diff --git a/packages/demo-server/src/api/api.controller.ts b/packages/demo-server/src/api/api.controller.ts index c7a23ec5c..f061019c7 100644 --- a/packages/demo-server/src/api/api.controller.ts +++ b/packages/demo-server/src/api/api.controller.ts @@ -5,7 +5,7 @@ import { GenerateProjectDto } from '../dto/generate-project.dto'; @Controller('api') export class ApiController { - constructor(private readonly apiService: ApiService) {} + private readonly apiService: ApiService; @Get('generate/test') generateTest() { diff --git a/packages/demo-server/src/app.controller.ts b/packages/demo-server/src/app.controller.ts index cce879ee6..1fa9180c3 100644 --- a/packages/demo-server/src/app.controller.ts +++ b/packages/demo-server/src/app.controller.ts @@ -3,7 +3,7 @@ import { AppService } from './app.service'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + private readonly appService: AppService; @Get() getHello(): string { diff --git a/packages/demo-server/src/publisher/index.ts b/packages/demo-server/src/publisher/index.ts index 3bd62d4eb..c3d9777c3 100644 --- a/packages/demo-server/src/publisher/index.ts +++ b/packages/demo-server/src/publisher/index.ts @@ -1,5 +1,5 @@ import { IResultDir } from '@ali/lowcode-code-generator'; -import { isNodeProcess, writeZipToDisk, generateProjectZip } from './utils' +import { isNodeProcess, writeZipToDisk, generateProjectZip } from './utils'; export type PublisherFactory = (configuration?: Partial) => U; @@ -17,7 +17,7 @@ export interface IPublisherResponse { payload?: T; } -declare type ZipPublisherResponse = string | Buffer | Blob +declare type ZipPublisherResponse = string | Buffer | Blob; export interface ZipFactoryParams extends IPublisherFactoryParams { outputPath?: string @@ -32,39 +32,39 @@ export interface ZipPublisher extends IPublisher = ( params: ZipFactoryParams = {} ): ZipPublisher => { - let { project, outputPath } = params + let { project, outputPath } = params; - const getProject = () => project + const getProject = () => project; const setProject = (projectToSet: IResultDir) => { - project = projectToSet - } + project = projectToSet; + }; - const getOutputPath = () => outputPath + const getOutputPath = () => outputPath; const setOutputPath = (path: string) => { - outputPath = path - } + outputPath = path; + }; const publish = async (options: ZipFactoryParams = {}) => { - const projectToPublish = options.project || project + const projectToPublish = options.project || project; if (!projectToPublish) { throw new Error('MissingProject'); } - const zipName = options.projectSlug || params.projectSlug || projectToPublish.name + const zipName = options.projectSlug || params.projectSlug || projectToPublish.name; try { - const zipContent = await generateProjectZip(projectToPublish) + const zipContent = await generateProjectZip(projectToPublish); // If not output path is provided, zip is not written to disk - const projectOutputPath = options.outputPath || outputPath + const projectOutputPath = options.outputPath || outputPath; if (projectOutputPath && isNodeProcess()) { - await writeZipToDisk(projectOutputPath, zipContent, zipName) + await writeZipToDisk(projectOutputPath, zipContent, zipName); } - return { success: true, payload: zipContent } + return { success: true, payload: zipContent }; } catch (error) { throw new Error('ZipUnexpected'); } - } + }; return { publish, @@ -72,5 +72,5 @@ export const createZipPublisher: PublisherFactory { 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') + const fs = require('fs'); + const path = require('path'); if (!fs.existsSync(zipFolderPath)) { - fs.mkdirSync(zipFolderPath, { recursive: true }) + fs.mkdirSync(zipFolderPath, { recursive: true }); } - const zipPath = path.join(zipFolderPath, `${zipName}.zip`) + const zipPath = path.join(zipFolderPath, `${zipName}.zip`); - const writeStream = fs.createWriteStream(zipPath) - writeStream.write(content) - writeStream.end() -} + const writeStream = fs.createWriteStream(zipPath); + writeStream.write(content); + writeStream.end(); +}; export const generateProjectZip = async (project: IResultDir): Promise => { - let zip = new JSZip() - zip = writeFolderToZip(project, zip, true) - const zipType = isNodeProcess() ? 'nodebuffer' : 'blob' - return zip.generateAsync({ type: zipType }) -} + 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 = false ) => { - const zipFolder = ignoreFolder ? parentFolder : parentFolder.folder(folder.name) + 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) - }) + const fileName = file.ext ? `${file.name}.${file.ext}` : file.name; + zipFolder.file(fileName, file.content, options); + }); folder.dirs.forEach((subFolder: IResultDir) => { - writeFolderToZip(subFolder, zipFolder) - }) + writeFolderToZip(subFolder, zipFolder); + }); - return parentFolder -} + return parentFolder; +};