UNPKG

884 BJavaScriptView Raw
1
2/**
3 * @license MIT
4 * Copyright (c) 2016 Craig Monro (cmroanirgo)
5 **/
6
7
8"use strict";
9
10var fs = require('fs');
11var path = require('path');
12var _ = require('ergo-utils')._;
13var l = require('ergo-utils').log.module('ergo-core-api-index');
14
15/*
16Each file in this dir is expected to be part of the 'public' api.
17*/
18
19module.exports = buildApi();
20
21function buildApi() {
22 var api = {};
23 fs.readdirSync(__dirname).forEach(function(file) {
24 if (file!='index.js' && path.extname(file)=='.js') { // ignore this file, but include all other js
25 file = path.basename(file, '.js'); // chop off the .js
26 try {
27 api[file] = require('./'+file); // export the included file
28 }
29 catch(e) {
30 l.loge("Failed to load api for '"+file+"': \n" + _.niceStackTrace(e));
31 throw e; // deliberately propogate this. This is a DEV fault & need be discovered early
32 }
33 }
34 });
35 return api;
36}
37
38
39
40