UNPKG

twokeys-server

Version:

Server for 2Keys

89 lines (85 loc) 3.23 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /** Copyright 2018 Kishan Sambhi This file is part of 2Keys. 2Keys is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 2Keys is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with 2Keys. If not, see <https://www.gnu.org/licenses/>. */ /** * @overview Index file for initialising a 2Keys project/config */ const fs = __importStar(require("fs")); const yaml_1 = __importDefault(require("yaml")); const logger_1 = __importDefault(require("../util/logger")); const constants_1 = require("../util/constants"); const get_config_1 = __importDefault(require("./get-config")); const oobe_1 = __importDefault(require("../oobe")); const gen_files_1 = __importDefault(require("./gen-files")); const daemon_1 = __importDefault(require("./daemon")); const logger = new logger_1.default({ name: "init" }); // Util /** * Function to initalise 2Keys config * @param argv Arguments from yargs */ async function run_init(argv) { logger.info("Starting to initalise a new 2Keys config..."); let config; // Create a write stream const writeStream = fs.createWriteStream(constants_1.CONFIG_FILE, { flags: argv.force ? "w" : "wx" }); writeStream.on("error", (err) => { if (argv.force && err.code === "EEXIST") { return; } if (err.code === "EEXIST") { logger.throw(new Error("Config file already exists! Exiting as a result.")); } else { logger.err("Error accessing config file!"); logger.throw(err); } }); try { config = await get_config_1.default(argv); const yaml_config = yaml_1.default.stringify(config); logger.debug("Config:"); console.log(yaml_config); logger.info("Writing config..."); writeStream.write(yaml_config); writeStream.close(); logger.info("Generating files..."); await gen_files_1.default(config); logger.info("Adding 2Keys server daemon to startup folder..."); daemon_1.default(config.name, argv); logger.debug("Running OOBE..."); await oobe_1.default(argv); } catch (err) { logger.throw(err); } } exports.default = run_init; //# sourceMappingURL=index.js.map