From ac45a5e33b221d0db2df5d2fa3b0a6dc2e3e596a Mon Sep 17 00:00:00 2001 From: Martin Karkowski Date: Mon, 24 Aug 2020 23:16:09 +0200 Subject: [PATCH] enable Refactoring code. --- lib/helpers/generateTemplate.ts | 35 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/helpers/generateTemplate.ts b/lib/helpers/generateTemplate.ts index 2b80bc0..2c4a397 100644 --- a/lib/helpers/generateTemplate.ts +++ b/lib/helpers/generateTemplate.ts @@ -1,8 +1,8 @@ +import { copyFile, readFile } from "fs/promises"; +import * as handlebars from 'handlebars'; +import { join } from 'path'; import { Project } from "ts-morph"; import { analyzeFiles } from "./analyzeTypescriptFiles"; -import * as handlebars from 'handlebars'; -import { readFile, copyFile } from "fs/promises"; -import { join } from 'path'; import { createFile, createPath } from "./fileHelpers"; /** @@ -21,8 +21,8 @@ export async function generateClientTemplate(options: { // Firstly copy the nopeDispatcher await copyFile( - join(__dirname,'..','..','..','lib','dispatcher','nopeDispatcher.ts'), - join(options.outputDir,'nopeDispatcher.ts') + join(__dirname, '..', '..', '..', 'lib', 'dispatcher', 'nopeDispatcher.ts'), + join(options.outputDir, 'nopeDispatcher.ts') ); // Function to Determine new project files. @@ -61,14 +61,31 @@ export async function generateClientTemplate(options: { } }); - for (const file of files){ + for (const file of files) { + const fileName = join(options.outputDir, 'clients', file.name); await createFile( // Generate the Path. - join(options.outputDir,'clients',file.name), + join(options.outputDir, 'clients', file.name), file.content - ) + ); + + // Function to Determine new project files. + const project = new Project({ + tsConfigFilePath: options.tsConfigFilePath, + addFilesFromTsConfig: false, + }); + + project.addSourceFileAtPath(fileName); + + // Readin the Source-Files. + const sourceFiles = project.getSourceFiles(); + + for (const file of sourceFiles) { + file.formatText(); + await file.save(); + } } // Compile the Template and parse the Code. - return true; + return true; } \ No newline at end of file