twokeys-server
Version:
Server for 2Keys
73 lines (69 loc) • 2.52 kB
JavaScript
;
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 Generates files, such as keyboard roots and index.ahks
*/
const mkdirp_1 = __importDefault(require("mkdirp"));
const fs_1 = require("fs");
const path_1 = require("path");
const constants_1 = require("../util/constants");
const logger_1 = __importDefault(require("../util/logger"));
const logger = new logger_1.default({
name: "generate"
});
/**
* Generates files, such as keyboard root folder and index.ahks
* @param config Config written to config.yml
*/
function gen_files(config) {
return new Promise((resolve, reject) => {
// Get dirs & root
const dirs = [];
const roots = []; // index.ahks
for (let keyboard in config.keyboards) {
if (config.keyboards.hasOwnProperty(keyboard)) {
dirs.push(config.keyboards[keyboard].dir);
roots.push(path_1.join(config.keyboards[keyboard].dir, config.keyboards[keyboard].root));
}
}
// CREATE
for (let dir of dirs) {
try {
mkdirp_1.default.sync(dir);
logger.debug(`Made dir ${dir}.`);
}
catch (err) {
reject(err);
}
}
for (let root of roots) {
try {
fs_1.writeFileSync(root, constants_1.DEFAULT_AHK_ROOT_CONTENTS);
logger.debug(`Made root ${root}.`);
}
catch (err) {
reject(err);
}
}
resolve();
});
}
exports.default = gen_files;
//# sourceMappingURL=gen-files.js.map