Skip to content

Commit

Permalink
Merge pull request #96 from dkamyshov/feat/skip-updates
Browse files Browse the repository at this point in the history
Do not overwrite files if content is the same
  • Loading branch information
Quramy authored Oct 22, 2020
2 parents 3b9f9e5 + 7dfa1af commit 01723c7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/dts-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as mkdirp from 'mkdirp';
import * as util from "util";

const writeFile = util.promisify(fs.writeFile);

const readFile = util.promisify(fs.readFile);

interface DtsContentOptions {
dropExtension: boolean;
Expand Down Expand Up @@ -76,7 +76,21 @@ export class DtsContent {
mkdirp.sync(outPathDir);
}

await writeFile(this.outputFilePath, finalOutput, 'utf8');
let isDirty = false;

if(!isThere(this.outputFilePath)) {
isDirty = true;
} else {
const content = (await readFile(this.outputFilePath)).toString();

if(content !== finalOutput) {
isDirty = true;
}
}

if(isDirty) {
await writeFile(this.outputFilePath, finalOutput, 'utf8');
}
}
}

Expand Down

0 comments on commit 01723c7

Please sign in to comment.