UNPKG

@haxtheweb/create

Version:

CLI for all things HAX the web

64 lines (62 loc) 2.77 kB
"use strict"; 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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } // 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; }