Skip to content

Commit

Permalink
feat(import): add shouldIgnore config callback
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stropitek committed Feb 13, 2017
1 parent ee4704b commit ef25e39
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/import/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ef25e39

Please sign in to comment.