node-talisman
Version:
A npm package for running Thoughtwork's Talisman tool
20 lines (16 loc) • 659 B
JavaScript
import os from 'os';
import messages from "../messages.js";
import { PLATFORMS, ARCHITECTURES } from "../constants.js";
const getMatchedName = (key, list) => {
const listItemMatched = Object.keys(list).find(listItem => key.includes(list[listItem].key));
if (!listItemMatched) {
throw new ReferenceError(messages.keyNotPresentInList({
KEY: key,
LIST: JSON.stringify(list)
}));
}
return list[listItemMatched].name;
};
export const getPlatform = () => getMatchedName(os.platform(), PLATFORMS);
export const getArchitecture = () => getMatchedName(os.arch(), ARCHITECTURES);
export const isWindows = () => os.platform() === 'win32';