barrelbot
Version:
a small utility to maintain barrel files
39 lines (38 loc) • 1.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const checkIndexFile_1 = require("./checkIndexFile");
/** checks for exact match to comment string in index file */
function checkDir(pathToDir, extension) {
// parse
const strArr = fs_1.default.readdirSync(pathToDir).filter(p => {
const stat = fs_1.default.statSync(path_1.default.join(pathToDir, p));
return !stat.isDirectory();
});
let indexFilePath = null;
let allFilesExceptIndex = [];
strArr.forEach(_x => {
const x = path_1.default.join(pathToDir, _x);
if (checkIndexFile_1.isIndexFile(x)) {
if (!checkIndexFile_1.checkIndexFile(x))
throw new Error(`detected index file that isnt generated by barrelbot: ${x}`);
indexFilePath = x;
}
else {
allFilesExceptIndex.push(x);
}
});
const hasIndexFile = !!indexFilePath;
if (!indexFilePath)
indexFilePath = path_1.default.join(pathToDir, `index.${extension}`);
return {
hasIndexFile,
indexFilePath,
allFilesExceptIndex
};
}
exports.checkDir = checkDir;