Skip to content

Commit

Permalink
fix(cleanfile): add file check and log for non-existent file (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwyneplaine authored and dbanksdesign committed May 28, 2019
1 parent 9a40407 commit 6375133
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jspm_packages
# Optional npm cache directory
.npm

# yarn
yarn.lock

# Optional REPL history
.node_repl_history

Expand Down
6 changes: 6 additions & 0 deletions __tests__/cleanFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ describe('cleanFile', () => {
expect(helpers.fileDoesNotExist('./__tests__/__output/test.txt')).toBeTruthy();
});

describe('if a file does not exist', () => {
it('should not throw', () => {
expect(() => cleanFile('non-existent.txt', format, { buildPath: '__tests__/__output/' }, {})).not.toThrow();
})
})

});
5 changes: 5 additions & 0 deletions lib/cleanFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ function cleanFile(destination, format, platform, dictionary, filter) {

var dirname = path.dirname(destination);

if (!fs.existsSync(destination)) {
console.log(chalk.bold.red('!') + ' ' + destination + ', does not exist');
return;
}

fs.unlinkSync(destination);
console.log(chalk.bold.red('-') + ' ' + destination);
}
Expand Down

0 comments on commit 6375133

Please sign in to comment.