Skip to content

Commit

Permalink
Add support for dot and non-dot local files and look for localOnly opt.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Feb 27, 2024
1 parent 7dc0fd0 commit dacc34e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions implementations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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);

0 comments on commit dacc34e

Please sign in to comment.