Skip to content

Commit

Permalink
HookModule#cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
city41 committed Jul 26, 2024
1 parent 32cd5fc commit df1131c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const dummyHook: Required<HookModule> = {
overrideEmitData(_rootDir, emitData) {
return Promise.resolve(emitData);
},
cleanup(_rootDir) {
return Promise.resolve();
},
};

async function main(options: OptionValues) {
Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,5 @@ export type HookModule = {
resourceRootDir: string,
emitData: CodeEmitData
) => Promise<CodeEmitData & any>;
cleanup?: (resourceRootDir: string) => Promise<void>;
};
4 changes: 4 additions & 0 deletions testData/testHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit df1131c

Please sign in to comment.