UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

57 lines (56 loc) 2.57 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addScript = addScript; exports.removeScript = removeScript; const fs_extra_1 = __importDefault(require("fs-extra")); const logger_1 = require("../logger"); function addScript(filePath, name, command) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield fs_extra_1.default.readFile(filePath, 'utf8'); const jsonData = JSON.parse(data); if (jsonData.scripts === undefined) { jsonData.scripts = { [name]: `${command}` }; } else { jsonData.scripts[name] = command; } const jsonString = JSON.stringify(jsonData, null, 2); yield fs_extra_1.default.writeFile(filePath, jsonString, 'utf8'); } catch (error) { logger_1.logger.error(`Could not write script '${command}' in file '${filePath}'`); logger_1.logger.error(error.message); } }); } function removeScript(filePath, name) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield fs_extra_1.default.readFile(filePath, 'utf8'); const jsonData = JSON.parse(data); if (jsonData.scripts === undefined) { return; } delete jsonData.scripts[name]; const jsonString = JSON.stringify(jsonData, null, 2); yield fs_extra_1.default.writeFile(filePath, jsonString, 'utf8'); } catch (error) { logger_1.logger.error(`Could not remove script '${name}' in file '${filePath}'`); logger_1.logger.error(error.message); } }); }