Skip to content

Commit

Permalink
fix: fix __ask-if-exists on readme files
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed May 27, 2019
1 parent 8ce8db0 commit e9095f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/write-project/when-file-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ module.exports = function(targetFolder, unattended, _mockAsk) {
if (file.relative.match(/readme(\.(md|txt|markdown))?$/i)) {
// Special treatment for readme file, use append by default
if (!file.writePolicy) file.writePolicy = 'append';
} else if (file.relative === 'package.json') {
}

if (file.relative === 'package.json') {
// Special treatment for package.json file
if (file.writePolicy) file.writePolicy = null;
// Merge dependencies to existing package.json
Expand Down Expand Up @@ -71,7 +73,7 @@ async function askQuestion(relativePath) {
hint: `Keeps your existing file. New file will be created as '${relativePath}__makes'. You may need to update existing contents to work.`
}, {
value: 'replace',
title: 'Replace the existing file ',
title: 'Replace the existing file',
hint: 'Replaces the existing file with a new one designed.'
}]
});
Expand Down
8 changes: 4 additions & 4 deletions test/write-project/when-file-exists.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test.serial.cb('whenFileExists marks readme file with append write policy, when
});
});

test.serial.cb('whenFileExists keeps existing readme file write policy mark, when target file exists', t => {
test.serial.cb('whenFileExists honours existing readme file write policy mark, when target file exists', t => {
mockfs({
'here/folder/some-readme.md': 'lorem'
});
Expand All @@ -45,14 +45,14 @@ test.serial.cb('whenFileExists keeps existing readme file write policy mark, whe
writePolicy: 'ask'
});

const ts = whenFileExists('here');
const ts = whenFileExists('here', true);

ts.write(file);
ts.end();
ts.once('data', file => {
t.truthy(file.isBuffer());
t.is(file.relative.replace(/\\/g, '/'), 'folder/some-readme.md');
t.is(file.writePolicy, 'ask');
t.is(file.relative.replace(/\\/g, '/'), 'folder/some-readme.md__makes');
t.is(file.writePolicy, null);
t.is(file.contents.toString(), 'abc');
t.end();
});
Expand Down

0 comments on commit e9095f4

Please sign in to comment.