UNPKG

pushoo-cli

Version:

A command line tool with Pushoo.js pushes multiple platform messages.

48 lines 1.68 kB
import CmdExists from 'command-exists'; import fs, { lstatSync } from 'fs'; import YAML, { parse as yamlParse } from 'yaml'; import { resolve } from './promise'; export async function commandExists(commandString) { const [commandError] = await resolve(CmdExists(commandString)); return commandError === undefined; } // write yaml file from json object export async function writeYamlFile(filePath, data) { const yaml = YAML.stringify(data); await fs.writeFileSync(filePath, yaml, 'utf8'); return yaml; } // read yaml file to json object export async function readYamlFile(filePath) { if ((await fs.existsSync(filePath)) && (await lstatSync(filePath).isFile())) { return yamlParse(await fs.readFileSync(filePath, 'utf8')); } return undefined; } // Check the object attributes required export function checkRequiredAttributes(object, attributes) { const checkResult = []; for (const attribute of attributes) { if (!object[attribute] || object[attribute] === null || object[attribute] === '') { checkResult.push(attribute); } } if (checkResult.length > 0) { throw new Error(`Missing required attributes: ${checkResult.join(', ')}`); } } // Check whether the length of multiple array is the same export function checkArrayLength(array) { const checkResult = []; for (const item of array) { if (item.length !== array[0].length) { checkResult.push(item); } } if (checkResult.length > 0) { throw new Error(`The length of the array is not the same: ${checkResult.join(', ')}`); } } //# sourceMappingURL=index.js.map