From dacc34eaa27d00aac0146faab5bfd18c9e24d8d8 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 27 Feb 2024 19:26:45 +0000 Subject: [PATCH] Add support for dot and non-dot local files and look for localOnly opt. --- implementations/index.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/implementations/index.js b/implementations/index.js index d2be7e7..3548a26 100644 --- a/implementations/index.js +++ b/implementations/index.js @@ -8,13 +8,14 @@ import {join} from 'node:path'; const require = createRequire(import.meta.url); const requireDir = require('require-dir'); -const dir = requireDir('./'); +// get all the json files in this dir +const manifests = Object.values(requireDir('./')); // gets local implementations from an optional config file -const getLocalImplementations = () => { +const getLocalImplementations = fileName => { try { const path = join( - appRoot.toString(), '.localImplementationsConfig.cjs'); + appRoot.toString(), fileName); return require(path); } catch(e) { if(e?.code === 'MODULE_NOT_FOUND') { @@ -24,5 +25,14 @@ const getLocalImplementations = () => { } }; -export const implementerFiles = Object.values(dir) - .concat(getLocalImplementations()); +// open either list of local endpoints and merge into one list of endpoints. +const localImplementations = [ + getLocalImplementations('.localImplementationsConfig.cjs'), + getLocalImplementations('localImplementationsConfig.cjs') +].flatMap(a => a); + +// look for local only in a local settings file +const localOnly = localImplementations.some(i => i?.local === true); + +export const implementerFiles = localOnly ? localImplementations : + manifests.concat(localImplementations);