Convert backend code to ES modules

Bundling code now with Rollup for its flat bundling and tree shaking
support. Front end code still goes through Webpack for browser support.
This commit is contained in:
Zaid Abdulla committed 2019-02-04 23:47:54 -08:00
1 parent 824639976f
commit 1e41c72d60
62 files changed
+718 -898

No files matched your search

+9 -17
View File
@@ -18,8 +18,8 @@
*/
"use strict";
const path = require("path");
const fs = require("fs");
import { resolve } from "path";
import { readFileSync } from "fs";
const options = {
CONFIG_DIR: { type: "path", default: "config" },
@@ -133,7 +133,7 @@ function setConfig(name, value, commandLineArgument) {
return String(val);
case "path":
if (!val) return "";
return path.resolve(val);
return resolve(val);
default:
return null;
}
@@ -182,7 +182,7 @@ setConfig("CONFIG_DIR", options["CONFIG_DIR"]["default"]);
// Configuration file
const configFile = JSON.parse(
fs.readFileSync(path.resolve(allConfig.CONFIG_DIR, "config.json"))
readFileSync(resolve(allConfig.CONFIG_DIR, "config.json"))
);
for (const [k, v] of Object.entries(configFile)) {
if (!setConfig(k, v))
@@ -194,7 +194,7 @@ for (const [k, v] of Object.entries(configFile)) {
for (const [k, v] of Object.entries(options))
if (v["default"] != null) setConfig(k, v["default"]);
function get(optionName, deviceId) {
export function get(optionName, deviceId) {
if (!deviceId) return allConfig[optionName];
optionName = `${optionName}-${deviceId}`;
@@ -222,28 +222,20 @@ function get(optionName, deviceId) {
return null;
}
function getDefault(optionName) {
export function getDefault(optionName) {
const option = options[optionName];
if (!option) return null;
let val = option["default"];
if (val && option.type === "path") val = path.resolve(val);
if (val && option.type === "path") val = resolve(val);
return val;
}
export let auth;
// Load authentication scripts
try {
const authScript = fs.readFileSync(
path.resolve(allConfig.CONFIG_DIR, "auth.js")
);
exports.auth = (function(exports) {
eval(authScript.toString());
return exports;
})({});
auth = require(resolve(allConfig.CONFIG_DIR, "auth.js"));
} catch (error) {
// No auth.js exists
}
exports.get = get;
exports.getDefault = getDefault;