diff --git a/src/index.ts b/src/index.ts index dc79c52..e6778e6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,9 @@ const dummyHook: Required = { overrideEmitData(_rootDir, emitData) { return Promise.resolve(emitData); }, + cleanup(_rootDir) { + return Promise.resolve(); + }, }; async function main(options: OptionValues) { @@ -95,15 +98,16 @@ async function main(options: OptionValues) { preCodeEmitData ); - emit(rootDir, resourceJson.codeEmit, codeEmitData).then( - (codeEmitFilesToWrite) => { - filesToWrite.push(...codeEmitFilesToWrite); - writeFiles(filesToWrite); - } + const codeEmitFilesToWrite = await emit( + rootDir, + resourceJson.codeEmit, + codeEmitData ); - } else { - writeFiles(filesToWrite); + filesToWrite.push(...codeEmitFilesToWrite); } + writeFiles(filesToWrite); + + await hookModule.cleanup(rootDir); } const packageJson = require('../package.json'); diff --git a/src/types.ts b/src/types.ts index 5eb54c8..91b1a1e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -244,4 +244,5 @@ export type HookModule = { resourceRootDir: string, emitData: CodeEmitData ) => Promise; + cleanup?: (resourceRootDir: string) => Promise; }; diff --git a/testData/testHook.js b/testData/testHook.js index dd36b19..91a05fc 100644 --- a/testData/testHook.js +++ b/testData/testHook.js @@ -13,6 +13,10 @@ const hook = { console.log(emitData); return Promise.resolve(emitData); }, + cleanup(rootDir) { + console.log('test hook cleanup', rootDir); + return Promise.resolve(); + }, }; module.exports = hook;