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

50 lines (49 loc) 2.16 kB
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()); }); }; import fs from 'fs-extra'; import { logger } from '../logger'; export function addScript(filePath, name, command) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield fs.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.writeFile(filePath, jsonString, 'utf8'); } catch (error) { logger.error(`Could not write script '${command}' in file '${filePath}'`); logger.error(error.message); } }); } export function removeScript(filePath, name) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield fs.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.writeFile(filePath, jsonString, 'utf8'); } catch (error) { logger.error(`Could not remove script '${name}' in file '${filePath}'`); logger.error(error.message); } }); }