UNPKG

barrelbot

Version:

a small utility to maintain barrel files

34 lines (33 loc) 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../types"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); /** checks for exact match to comment string in index file */ function checkIndexFile(pathToIndexFile) { // validate if (!isIndexFile(pathToIndexFile)) throw new Error(`expected index file, but given ${pathToIndexFile}`); // parse // console.log('hcecking', pathToIndexFile); // TODO: try https://stackoverflow.com/questions/28747719/what-is-the-most-efficient-way-to-read-only-the-first-line-of-a-file-in-node-js const strArr = fs_1.default .readFileSync(pathToIndexFile) .toString() .split('\n'); if (strArr.length > 0 && strArr[0] === types_1.COMMENTSTRING) { return true; } else { return false; } } exports.checkIndexFile = checkIndexFile; /** is this file an index file or not? */ function isIndexFile(filepath) { return types_1.INDEXFILES.includes(path_1.default.basename(filepath)); } exports.isIndexFile = isIndexFile;