kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Fix checking for non-empty folders in initcommand
rodzic
2698f08851
commit
51db48acc9
|
@ -26,7 +26,7 @@ Command.prototype.execute = function() {
|
||||||
var fs = require("fs"),
|
var fs = require("fs"),
|
||||||
path = require("path");
|
path = require("path");
|
||||||
// Check that we don't already have a valid wiki folder
|
// Check that we don't already have a valid wiki folder
|
||||||
if($tw.boot.wikiTiddlersPath) {
|
if($tw.boot.wikiTiddlersPath || ($tw.utils.isDirectory($tw.boot.wikiPath) && !$tw.utils.isDirectoryEmpty($tw.boot.wikiPath))) {
|
||||||
return "Wiki folder is not empty";
|
return "Wiki folder is not empty";
|
||||||
}
|
}
|
||||||
// Loop through each of the specified editions
|
// Loop through each of the specified editions
|
||||||
|
|
|
@ -139,4 +139,21 @@ exports.isDirectory = function(dirPath) {
|
||||||
return fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory();
|
return fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Check if a path identifies a directory that is empty
|
||||||
|
*/
|
||||||
|
exports.isDirectoryEmpty = function(dirPath) {
|
||||||
|
if(!$tw.utils.isDirectory(dirPath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var files = fs.readdirSync(dirPath),
|
||||||
|
empty = true;
|
||||||
|
$tw.utils.each(files,function(file,index) {
|
||||||
|
if(file.charAt(0) !== ".") {
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return empty;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
Ładowanie…
Reference in New Issue