@haxtheweb/create
Version:
CLI for all things HAX the web
65 lines (63 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.commandString = commandString;
exports.consoleTransport = void 0;
exports.haxCliEnvOptions = haxCliEnvOptions;
exports.log = log;
exports.logger = exports.logFile = void 0;
var _nodeOs = require("node:os");
var path = _interopRequireWildcard(require("node:path"));
var winston = _interopRequireWildcard(require("winston"));
var _utils = require("./utils.js");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
// check for vercel running which is not allowed to write to home in logs
let baseLogPath = (0, _nodeOs.homedir)();
if (process.env.VERCEL_ENV) {
baseLogPath = "/tmp/";
}
const logFileName = path.join(baseLogPath, '.haxtheweb', 'create.log');
const consoleTransport = exports.consoleTransport = new winston.transports.Console({
format: winston.format.simple()
});
const logFile = exports.logFile = new winston.transports.File({
filename: logFileName,
level: 'info',
// so we don't store everything else
format: winston.format.combine(winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}), winston.format.errors({
stack: true
}), winston.format.splat(), winston.format.json()),
maxsize: 100000,
maxFiles: 10,
tailable: true
});
const logger = exports.logger = winston.createLogger({
transports: [consoleTransport, logFile]
});
function haxCliEnvOptions() {
return ['skip', 'npmClient', 'i', 'extras', 'root', 'path', 'org', 'author', 'y', 'auto', 'domain'];
}
// wrapper so we can silence all log messages at the same time
function log(msg, level = 'info', extra = null) {
logger.log(level, msg, extra);
}
function commandString(commandRun) {
let comStr = `hax ${commandRun.command} ${commandRun.arguments.action}`;
for (const key of Object.keys(commandRun.options)) {
// ignore environment centric calls
if (!haxCliEnvOptions().includes(key)) {
if (key === true) {
comStr += ` --${(0, _utils.camelToDash)(key)}`;
} else if (key === false) {
comStr += ` --no-${(0, _utils.camelToDash)(key)}`;
} else {
comStr += ` --${(0, _utils.camelToDash)(key)} "${commandRun.options[key]}"`;
}
}
}
return comStr;
}