UNPKG

wicked-cli

Version:
46 lines (38 loc) 1.21 kB
'use strict'; /* global __dirname */ const fs = require('fs'); const path = require('path'); const axios = require('axios'); const utils = function () {}; utils.getUtc = function () { return Math.floor((new Date()).getTime() / 1000); }; utils.getJson = function (ob) { if (ob instanceof String || typeof ob === "string") return JSON.parse(ob); return ob; }; utils.getText = function (ob) { if (ob instanceof String || typeof ob === "string") return ob; return JSON.stringify(ob, null, 2); }; utils._packageVersion = null; utils.getVersion = function () { if (!utils._packageVersion) { const packageFile = path.join(__dirname, '..', 'package.json'); if (fs.existsSync(packageFile)) { try { const packageInfo = JSON.parse(fs.readFileSync(packageFile, 'utf8')); if (packageInfo.version) utils._packageVersion = packageInfo.version; } catch (ex) { console.error(ex); } } if (!utils._packageVersion) // something went wrong utils._packageVersion = "0.0.0"; } return utils._packageVersion; }; module.exports = utils;