From ef25e394905096128e7e346ef8334da778a387bd Mon Sep 17 00:00:00 2001 From: Daniel Kostro Date: Mon, 13 Feb 2017 18:06:11 +0100 Subject: [PATCH] feat(import): add shouldIgnore config callback shouldIgnore callback is called before the file is read and gives an opportunity to stop the import process Useful in an environment where files cannot be moved around in the importation directory --- src/import/import.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/import/import.js b/src/import/import.js index 481baf75..956e9b37 100644 --- a/src/import/import.js +++ b/src/import/import.js @@ -17,17 +17,25 @@ exports.import = async function (database, importName, file, options) { const parsedFilename = path.parse(file); const filedir = parsedFilename.dir; const filename = parsedFilename.base; + let config = getConfig(database); + const couch = Couch.get(database); + const shouldIgnore = verifyConfig(config, 'shouldIgnore', null, true); + // Give an opportunity to ignore before even reading the file + if(shouldIgnore) { + const ignore = await shouldIgnore(filename, couch, filedir); + if(ignore) { + debug.debug(`Ignore file ${file}`); + return; + } + } let contents = fs.readFileSync(file); - let config = getConfig(database); if (!config.import || !config.import[importName]) { throw new Error(`no import config for ${database}/${importName}`); } config = config.import[importName]; - const couch = Couch.get(database); - const info = {}; let isParse = false;