Skip to content

Commit 2241e3d

Browse files
author
reflector-six
committed
allow file postprocessors
1 parent 9bb5cbe commit 2241e3d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/dts-content.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ export class DtsContent {
6868
return path.join(this.rootDir, this.searchDir, this.rInputPath);
6969
}
7070

71-
public async writeFile(): Promise<void> {
71+
public async writeFile(postprocessor = (formatted: string) => formatted): Promise<void> {
72+
const finalOutput = postprocessor(this.formatted);
73+
7274
const outPathDir = path.dirname(this.outputFilePath);
7375
if(!isThere(outPathDir)) {
7476
mkdirp.sync(outPathDir);
7577
}
7678

77-
await writeFile(this.outputFilePath, this.formatted, 'utf8');
79+
await writeFile(this.outputFilePath, finalOutput, 'utf8');
7880
}
7981
}
8082

test/dts-creator.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ export = styles;
180180
});
181181

182182
describe('#writeFile', () => {
183+
it('accepts a postprocessor function', done => {
184+
new DtsCreator()
185+
.create('test/testStyle.css')
186+
.then(content => {
187+
return content.writeFile(
188+
formatted => `// this banner was added to the .d.ts file automatically.\n${formatted}`
189+
);
190+
})
191+
.then(() => {
192+
done();
193+
});
194+
});
195+
183196
it('writes a file', done => {
184197
new DtsCreator()
185198
.create('test/testStyle.css')

0 commit comments

Comments
 (0)