-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(install): ignore dotfiles except for .ghost-cli in dir check
closes #868 - add dir-is-empty util that checks empty directories correctly
- Loading branch information
Showing
4 changed files
with
69 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fs = require('fs'); | ||
|
||
const debugLogRegex = /^ghost-cli-debug-.*\.log$/i; | ||
const importantDotfiles = ['.ghost-cli']; | ||
|
||
module.exports = function dirIsEmpty(dir) { | ||
const files = fs.readdirSync(dir); | ||
|
||
if (!files.length) { | ||
return true; | ||
} | ||
|
||
return files.every(file => file.match(debugLogRegex) || (file.startsWith('.') && !importantDotfiles.includes(file))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const proxyquire = require('proxyquire'); | ||
const {expect} = require('chai'); | ||
|
||
const proxy = files => proxyquire('../../../lib/utils/dir-is-empty', { | ||
fs: {readdirSync: () => files} | ||
}); | ||
|
||
describe('Unit: Utils > dirIsEmpty', function () { | ||
it('returns true if directory is empty', function () { | ||
const fn = proxy([]); | ||
expect(fn('dir')).to.be.true; | ||
}); | ||
|
||
it('returns true if directory contains ghost debug log files', function () { | ||
const fn = proxy(['ghost-cli-debug-1234.log']); | ||
expect(fn('dir')).to.be.true; | ||
}); | ||
|
||
it('returns true if directory contains dotfiles other than .ghost-cli', function () { | ||
const fn = proxy(['.npmrc', '.gitignore']); | ||
expect(fn('dir')).to.be.true; | ||
}); | ||
|
||
it('returns false if directory contains .ghost-cli file', function () { | ||
const fn = proxy(['.ghost-cli']); | ||
expect(fn('dir')).to.be.false; | ||
}); | ||
|
||
it('returns false if directory contains other files', function () { | ||
const fn = proxy(['file.txt', 'file2.txt']); | ||
expect(fn('dir')).to.be.false; | ||
}); | ||
}); |