UNPKG

@rnv/cli

Version:
702 lines 33.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.printBoxEnd = exports.printBoxStart = exports.printArrIntoBox = exports.printIntoBox = exports.logAppInfo = exports.logError = exports.logSuccess = exports.isInfoEnabled = exports.logDebug = exports.logInfo = exports.logWarning = exports.logHook = exports.logExitTask = exports.logInitTask = exports.logDefault = exports.logTask = exports.logSummary = exports.logRaw = exports.logToSummary = exports.getCurrentCommand = exports.logAndSave = exports.stripAnsi = exports.logWelcome = exports.logInitialize = exports.chalk = void 0; var tslib_1 = require("tslib"); /* eslint-disable no-console */ var chalk_1 = tslib_1.__importDefault(require("chalk")); var core_1 = require("@rnv/core"); var path_1 = tslib_1.__importDefault(require("path")); var ICN_ROCKET = core_1.isSystemWin ? 'RNV' : '🚀'; // const ICN_UNICORN = isSystemWin ? 'unicorn' : '🦄'; var _chalkCols = (0, core_1.generateDefaultChalk)(); var _chalkMono = tslib_1.__assign({}, _chalkCols); var colorBlue = { r: 10, g: 116, b: 230 }; // '#0a74e6' var currentChalk = chalk_1.default; var chalkBlue = chalk_1.default.rgb(colorBlue.r, colorBlue.g, colorBlue.b); // const RNV = 'ReNative'; var PRIVATE_PARAMS = ['-k', '--key']; var _isInfoEnabled = false; var _infoFilter = []; // let _c: RnvContext; var _isMono = false; var _defaultColor = _chalkCols.white; var _highlightColor = _chalkCols.white; // let _analytics: AnalyticsApi; var _jsonOnly; var chalk = function () { return currentChalk || chalk_1.default; }; exports.chalk = chalk; var logInitialize = function () { var _a, _b; // cnf(); var ctx = (0, core_1.getContext)(); _isInfoEnabled = !!ctx.program.opts().info; _jsonOnly = !!ctx.program.opts().json; _infoFilter = (_b = (_a = ctx.program.opts().info) === null || _a === void 0 ? void 0 : _a.split) === null || _b === void 0 ? void 0 : _b.call(_a, ','); // _analytics = analytics; if (ctx.program.opts().mono) { _isMono = true; currentChalk = _chalkMono; chalkBlue = _chalkMono.white; } _updateDefaultColors(); // RNV = getCurrentCommand(); if (!_jsonOnly) (0, exports.logWelcome)(); }; exports.logInitialize = logInitialize; var logWelcome = function () { var _a, _b, _c, _d, _e, _f, _g; var ctx = (0, core_1.getContext)(); if (((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) || ((_b = ctx.program) === null || _b === void 0 ? void 0 : _b.opts().noIntro)) return; var shortLen = 64; // prettier-ignore var str = _defaultColor("\n\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 ".concat(chalkBlue('██████╗'), " \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557").concat(chalkBlue('███╗ ██╗'), " \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557").concat(chalkBlue('██╗ ██╗'), "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2502\n\u2502 ").concat(chalkBlue('██╔══██╗'), "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D").concat(chalkBlue('████╗ ██║'), "\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2551").concat(chalkBlue('██║ ██║'), "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2502\n\u2502 ").concat(chalkBlue('██████╔╝'), "\u2588\u2588\u2588\u2588\u2588\u2557 ").concat(chalkBlue('██╔██╗ ██║'), "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551").concat(chalkBlue('██║ ██║'), "\u2588\u2588\u2588\u2588\u2588\u2557 \u2502\n\u2502 ").concat(chalkBlue('██╔══██╗'), "\u2588\u2588\u2554\u2550\u2550\u255D ").concat(chalkBlue('██║╚██╗██║'), "\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551").concat(chalkBlue('╚██╗ ██╔╝'), "\u2588\u2588\u2554\u2550\u2550\u255D \u2502\n\u2502 ").concat(chalkBlue('██║ ██║'), "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557").concat(chalkBlue('██║ ╚████║'), "\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551").concat(chalkBlue(' ╚████╔╝ '), "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2502\n\u2502 ").concat(chalkBlue('╚═╝ ╚═╝'), "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D").concat(chalkBlue('╚═╝ ╚═══╝'), "\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D").concat(chalkBlue(' ╚═══╝ '), "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u2502\n")); if ((_e = (_d = (_c = ctx.files) === null || _c === void 0 ? void 0 : _c.rnv) === null || _d === void 0 ? void 0 : _d.package) === null || _e === void 0 ? void 0 : _e.version) { ctx.rnvVersion = ctx.files.rnv.package.version; str += (0, exports.printIntoBox)(currentChalk.grey("".concat(!_isMono ? ICN_ROCKET : 'RNV', " v:").concat(ctx.rnvVersion, " | ").concat('renative.org', " | ").concat(ctx.timeStart.toLocaleString())), shortLen); if ((_g = (_f = ctx.rnvVersion) === null || _f === void 0 ? void 0 : _f.includes) === null || _g === void 0 ? void 0 : _g.call(_f, 'alpha')) { str += (0, exports.printIntoBox)("".concat(currentChalk.yellow('WARNING: this is a prerelease version.')), shortLen); } } // str += printIntoBox( // `${currentChalk.grey('https://renative.org')} | Start Time: ${currentChalk.grey( // ctx.timeStart.toLocaleString() // )}`, // shortLen // ); // str += printIntoBox(` ${ICN_ROCKET} ${currentChalk.yellow('Firing up!...')}`); str += (0, exports.printIntoBox)("$ ".concat(_highlightColor((0, exports.getCurrentCommand)(true))), shortLen); if (ctx.timeStart) { // str += printIntoBox(` Start Time: ${currentChalk.grey(ctx.timeStart.toLocaleString())}`); } // str += printIntoBox(''); // str += printBoxEnd(); str += _defaultColor('└─────────────────────────────────────────────────────────────────┘'); // str += '\n'; console.log(str); }; exports.logWelcome = logWelcome; function ansiRegex(_a) { var _b = _a === void 0 ? {} : _a, _c = _b.onlyFirst, onlyFirst = _c === void 0 ? false : _c; var pattern = [ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))', ].join('|'); return new RegExp(pattern, onlyFirst ? undefined : 'g'); } function stripAnsi(string) { if (typeof string !== 'string') { throw new TypeError("Expected a `string`, got `".concat(typeof string, "`")); } return string.replace(ansiRegex(), ''); } exports.stripAnsi = stripAnsi; // const cnf = () => { // if (!_c) { // _configureLogger(global.RNV_CONFIG, global.RNV_ANALYTICS); // } // return _c; // }; // const _configureLogger = (c: RnvContext, analytics: AnalyticsApi) => { // // ctx.logging.logMessages = []; // // _c = c; // // if (!ctx.timeStart) ctx.timeStart = new Date(); // _currentProcess = c.process; // _isInfoEnabled = !!c.program.opts().info; // _jsonOnly = !!c.program.opts().json; // _infoFilter = c.program.opts().info?.split?.(','); // // _isMono = c.program.opts().mono; // _analytics = analytics; // // if (_isMono) { // // currentChalk = _chalkMono; // // } // // _updateDefaultColors(); // // RNV = getCurrentCommand(); // }; var _updateDefaultColors = function () { _defaultColor = currentChalk.white; _highlightColor = currentChalk.bold.white; //currentChalk.bold; }; _updateDefaultColors(); var logAndSave = function (msg, skipLog) { var _a, _b, _c; var ctx = (0, core_1.getContext)(); if (((_a = ctx.logging) === null || _a === void 0 ? void 0 : _a.logMessages) && !((_b = ctx.logging) === null || _b === void 0 ? void 0 : _b.logMessages.includes(msg))) (_c = ctx.logging) === null || _c === void 0 ? void 0 : _c.logMessages.push(msg); if (!skipLog) console.log("".concat(msg)); }; exports.logAndSave = logAndSave; var _printJson = function (obj) { // sanitize if (obj.task) { obj.task = obj.task.trim().replace('[', '').replace(']', ''); } console.log(JSON.stringify(obj)); }; var getCurrentCommand = function (excludeDollar) { if (excludeDollar === void 0) { excludeDollar = false; } var ctx = (0, core_1.getContext)(); var argArr = ctx.process.argv.slice(2); var hideNext = false; var output = argArr .map(function (v) { if (hideNext) { hideNext = false; return '********'; } if (PRIVATE_PARAMS.includes(v)) { hideNext = true; } return v; }) .join(' '); var dollar = excludeDollar ? '' : '$ '; var npx = ctx.paths.IS_NPX_MODE ? 'npx ' : ''; return "".concat(dollar).concat(npx, "rnv ").concat(output); }; exports.getCurrentCommand = getCurrentCommand; var logToSummary = function (v) { var _a; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; var _v = _sanitizePaths(v); ctx.logging.logMessages.push("\n".concat(_v)); }; exports.logToSummary = logToSummary; var logRaw = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (_jsonOnly) { return _printJson({ type: 'rawLog', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(JSON.stringify(args))), }); } console.log.apply(null, args); }; exports.logRaw = logRaw; var logSummary = function (opts) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; if (_jsonOnly) { if (!ctx.logging.logMessages || !ctx.logging.logMessages.length) { return; } else { var cleanedMessages = ctx.logging.logMessages .map(stripAnsi) .map(function (msg) { var headerEndIndex = msg.indexOf(':') + 1; var header = msg.slice(0, headerEndIndex).trim(); var items = msg .slice(headerEndIndex) .split('\n') .map(function (line) { return line.trim(); }) .filter(function (line) { return line; }); return "".concat(header, " ").concat(items.join(', ')); }) .join(''); return _printJson({ type: 'summaryLog', task: stripAnsi(_getCurrentTask()), message: cleanedMessages, }); } } if ((_b = ctx.program) === null || _b === void 0 ? void 0 : _b.opts().noSummary) { if (!ctx.logging.logMessages || !ctx.logging.logMessages.length) { return; } else { console.log(ctx.logging.logMessages.join('').replace(/\n\s*\n\s*\n/g, '\n\n')); return; } } if (ctx.paths.project.configExists && !ctx.paths.IS_NPX_MODE && !ctx.paths.IS_LINKED) { (0, exports.logAndSave)((0, exports.chalk)().yellow('You are trying to run global rnv command in your current project.'), true); (0, exports.logAndSave)((0, exports.chalk)().yellow('This might lead to unexpected behaviour.'), true); (0, exports.logAndSave)((0, exports.chalk)().yellow('Run your rnv command with npx prefix:'), true); (0, exports.logAndSave)((0, exports.chalk)().bold('npx ' + (0, exports.getCurrentCommand)(true)), true); } var logContent = ''; //= printIntoBox(`All good as ${ICN_UNICORN} `); if (ctx.logging.logMessages && ctx.logging.logMessages.length) { logContent = ''; ctx.logging.logMessages.forEach(function (m) { logContent += "\u2502 ".concat(m, "\n"); }); } var timeString = ''; ctx.timeEnd = new Date(); timeString = "| ".concat(ctx.timeEnd.toLocaleString()); // let envString = ''; // if (ctx.process) { // envString = `${ctx.process.platform} | ${ctx.process.arch} | node v${ctx.process.versions?.node}`; // } var defaultHeaderStyle = ctx.logging.containsError ? 'error' : ctx.logging.containsWarning ? 'warning' : 'success'; var headerStyle = (opts === null || opts === void 0 ? void 0 : opts.headerStyle) || defaultHeaderStyle; var headerPrefix = headerStyle === 'success' ? '✔ ' : headerStyle === 'warning' ? '⚠ ' : headerStyle === 'error' ? '⨯ ' : ''; var headerTextPlain = "".concat(headerPrefix).concat((opts === null || opts === void 0 ? void 0 : opts.header) || 'SUMMARY'); var headerChalk; if (_isMono) { headerChalk = currentChalk.white; } else { headerChalk = headerStyle === 'success' ? currentChalk.green.bold : headerStyle === 'warning' ? currentChalk.yellow.bold : headerStyle === 'error' ? currentChalk.green.red : function (v) { return v; }; } var str = (0, exports.printBoxStart)("".concat(headerChalk(headerTextPlain), " ").concat(timeString, " | rnv@").concat(ctx.rnvVersion), (0, exports.getCurrentCommand)()); // str += printIntoBox(`ReNative Version: ${_highlightColor(ctx.rnvVersion)}`); if (((_e = (_d = (_c = ctx.files) === null || _c === void 0 ? void 0 : _c.project) === null || _d === void 0 ? void 0 : _d.package) === null || _e === void 0 ? void 0 : _e.name) && ((_h = (_g = (_f = ctx.files) === null || _f === void 0 ? void 0 : _f.project) === null || _g === void 0 ? void 0 : _g.package) === null || _h === void 0 ? void 0 : _h.version)) { str += (0, exports.printIntoBox)("Project: ".concat(currentChalk.gray("".concat(ctx.files.project.package.name, "@").concat(ctx.files.project.package.version)))); // str += printIntoBox(`Project Version: ${currentChalk.gray(ctx.files.project.package.version)}`); } if ((_j = ctx.buildConfig) === null || _j === void 0 ? void 0 : _j.workspaceID) { str += (0, exports.printIntoBox)("Workspace: ".concat(currentChalk.gray(ctx.buildConfig.workspaceID))); } if (ctx.platform) { str += (0, exports.printIntoBox)("Platform (-p): ".concat(_highlightColor(ctx.platform))); } if ((_k = ctx.runtime) === null || _k === void 0 ? void 0 : _k.engine) { // let addon = ''; // if (ctx.platform) { // addon = ` ($.platforms.${ctx.platform}.engine)`; // } str += (0, exports.printIntoBox)("Engine: ".concat(currentChalk.gray(((_m = (_l = ctx.runtime) === null || _l === void 0 ? void 0 : _l.engine) === null || _m === void 0 ? void 0 : _m.id) || ''))); } if ((_o = ctx.runtime) === null || _o === void 0 ? void 0 : _o.currentTemplate) { str += (0, exports.printIntoBox)("Template: ".concat(currentChalk.gray((_p = ctx.runtime) === null || _p === void 0 ? void 0 : _p.currentTemplate))); } if ((_r = (_q = ctx.buildConfig) === null || _q === void 0 ? void 0 : _q._meta) === null || _r === void 0 ? void 0 : _r.currentAppConfigId) { str += (0, exports.printIntoBox)("App Config (-c): ".concat(_highlightColor((_s = ctx.buildConfig._meta) === null || _s === void 0 ? void 0 : _s.currentAppConfigId))); } if ((_t = ctx.runtime) === null || _t === void 0 ? void 0 : _t.scheme) { str += (0, exports.printIntoBox)("Build Scheme (-s): ".concat(_highlightColor((_u = ctx.runtime) === null || _u === void 0 ? void 0 : _u.scheme))); } if ((_w = ctx.runtime) === null || _w === void 0 ? void 0 : _w.bundleAssets) { str += (0, exports.printIntoBox)("Bundle assets ($.platforms.".concat(ctx.platform, ".bundleAssets): ").concat(_highlightColor(!!((_x = ctx.runtime) === null || _x === void 0 ? void 0 : _x.bundleAssets)))); } if ((_y = ctx.runtime) === null || _y === void 0 ? void 0 : _y.target) { str += (0, exports.printIntoBox)("Target (-t): ".concat(_highlightColor((_z = ctx.runtime) === null || _z === void 0 ? void 0 : _z.target))); } if ((_1 = (_0 = ctx.program) === null || _0 === void 0 ? void 0 : _0.opts()) === null || _1 === void 0 ? void 0 : _1.reset) { str += (0, exports.printIntoBox)("Reset Project (-r): ".concat(_highlightColor(!!((_3 = (_2 = ctx.program) === null || _2 === void 0 ? void 0 : _2.opts()) === null || _3 === void 0 ? void 0 : _3.reset)))); } if ((_5 = (_4 = ctx.program) === null || _4 === void 0 ? void 0 : _4.opts()) === null || _5 === void 0 ? void 0 : _5.resetHard) { str += (0, exports.printIntoBox)("Reset Project and Assets (-R): ".concat(_highlightColor(!!((_7 = (_6 = ctx.program) === null || _6 === void 0 ? void 0 : _6.opts()) === null || _7 === void 0 ? void 0 : _7.resetHard)))); } if ((_9 = (_8 = ctx.runtime) === null || _8 === void 0 ? void 0 : _8.availablePlatforms) === null || _9 === void 0 ? void 0 : _9.length) { // const plats = ctx.runtime.availablePlatforms.map((v) => `${currentChalk.gray(v)}`); // str += printArrIntoBox(plats, 'Supported Platforms: '); str += (0, exports.printIntoBox)("Supported Platforms: ".concat(currentChalk.gray(ctx.runtime.availablePlatforms.join(', ')))); } if (ctx.process) { var envString = "".concat(ctx.process.platform, " | ").concat(ctx.process.arch, " | node v").concat((_10 = ctx.process.versions) === null || _10 === void 0 ? void 0 : _10.node); str += (0, exports.printIntoBox)("Env Info: ".concat(currentChalk.gray(envString))); } if (ctx.timeEnd) { str += (0, exports.printIntoBox)("Executed Time: ".concat(currentChalk.gray(_msToTime(ctx.timeEnd.getTime() - ctx.timeStart.getTime())))); } // str += printIntoBox(''); str += logContent.replace(/\n\s*\n\s*\n/g, '\n\n'); // str += printIntoBox(''); if ((_11 = ctx.runtime) === null || _11 === void 0 ? void 0 : _11.platformBuildsProjectPath) { str += (0, exports.printIntoBox)("Project location: ".concat(currentChalk.gray(_sanitizePaths(ctx.runtime.platformBuildsProjectPath || '')))); } str += (0, exports.printBoxEnd)(); console.log(str); }; exports.logSummary = logSummary; var _msToTime = function (seconds) { var s = seconds; var ms = s % 1000; s = (s - ms) / 1000; var secs = s % 60; s = (s - secs) / 60; var mins = s % 60; var hrs = (s - mins) / 60; return "".concat(hrs, "h:").concat(mins, "m:").concat(secs, "s:").concat(ms, "ms"); }; var _getCurrentTask = function () { var ctx = (0, core_1.getContext)(); return ctx._currentTask ? currentChalk.grey("\u25CB ".concat(ctx._currentTask, ":")) : ''; }; var CWD_ARR = []; var _generateRelativePaths = function () { var cwd = process.cwd(); var cwdArr = cwd.split(path_1.default.sep); var relativeUp = '.'; for (var i = 1; i < cwdArr.length; i++) { var absoluteUp = path_1.default.join(cwd, relativeUp).normalize(); CWD_ARR.push({ path: absoluteUp, relative: relativeUp }); relativeUp += i > 1 ? '/..' : '.'; } }; _generateRelativePaths(); var _sanitizePaths = function (msg) { // const ctx = getContext(); // let dir // const config = ctx.files?.project?.config; // if(config && config.isMonorepo) { // if() // } if (msg === null || msg === void 0 ? void 0 : msg.replace) { CWD_ARR.forEach(function (v) { msg = msg.replace(new RegExp(v.path, 'g'), v.relative); }); // return msg // .replace(new RegExp(CWD, 'g'), '.') // .replace(new RegExp(CWD_UP, 'g'), '..') // .replace(new RegExp(CWD_UP_UP, 'g'), '../..'); } return msg; }; var TASK_COUNTER = {}; var logTask = function (task, customChalk) { var _a; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; if (!TASK_COUNTER[task]) TASK_COUNTER[task] = 0; TASK_COUNTER[task] += 1; var taskCount = currentChalk.grey("[".concat(TASK_COUNTER[task], "]")); if (_jsonOnly) { return _printJson({ type: 'task', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(typeof customChalk === 'string' ? customChalk : task)), }); } var msg = ''; if (typeof customChalk === 'string') { msg = "".concat(currentChalk.green("[task]".concat(_getCurrentTask())), " ").concat(task).concat(taskCount, " ").concat(currentChalk.grey(customChalk)); } else if (customChalk) { msg = customChalk("[task]".concat(_getCurrentTask(), " ").concat(task).concat(taskCount)); } else { msg = "".concat(currentChalk.green("[task]".concat(_getCurrentTask())), " ").concat(task).concat(taskCount); } if (_isInfoEnabled) { // TODO: temporary. will be activated under different flag console.log(_sanitizePaths(msg)); } }; exports.logTask = logTask; var logDefault = function (task, customChalk) { var _a; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; var taskCount = getLogCounter(task); if (_jsonOnly) { return _printJson({ type: 'log', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(typeof customChalk === 'string' ? customChalk : task)), }); } var msg = ''; if (typeof customChalk === 'string') { msg = "[log]".concat(_getCurrentTask(), " ").concat(task).concat(taskCount, " ").concat(currentChalk.grey(customChalk)); } else if (customChalk) { msg = customChalk("[log]".concat(_getCurrentTask(), " ").concat(task, " ").concat(taskCount)); } else { msg = "[log]".concat(_getCurrentTask(), " ").concat(task, " ").concat(taskCount); } if (_isInfoEnabled) { // TODO: temporary. will be activated under different flag console.log(_sanitizePaths(msg)); } }; exports.logDefault = logDefault; var getLogCounter = function (task, skipAddition) { if (skipAddition === void 0) { skipAddition = false; } if (!TASK_COUNTER[task]) TASK_COUNTER[task] = 0; if (!skipAddition) { TASK_COUNTER[task] += 1; } var taskCount = currentChalk.grey("\u21BA".concat(TASK_COUNTER[task])); return taskCount; }; var logInitTask = function (task) { var _a; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; var taskCount = getLogCounter(task); if (_jsonOnly) { return _printJson({ type: 'taskInit', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(task)), }); } var msg = !_isMono ? "".concat(chalkBlue.bold('task:'), " \u25CB ").concat(task, " ").concat(taskCount) : "".concat(currentChalk.white('task:'), " \u25CB ").concat(task, " ").concat(taskCount); console.log(msg); }; exports.logInitTask = logInitTask; var logExitTask = function (task) { var _a; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; if (_jsonOnly) { return _printJson({ type: 'taskExit', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(task)), }); } // const taskCount = getLogCounter(task, true); var msg = "".concat(currentChalk.green('task:'), " ").concat(currentChalk.green('✔'), " ").concat(task); console.log(msg); }; exports.logExitTask = logExitTask; var logHook = function (hook, msg) { var _a; if (hook === void 0) { hook = ''; } if (msg === void 0) { msg = ''; } var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; if (_jsonOnly) { var payload = { type: 'hook', hook: hook, message: stripAnsi(_sanitizePaths(msg)) }; if (_getCurrentTask()) payload.task = stripAnsi(_getCurrentTask()); return _printJson(payload); } console.log("".concat("[hook]", " ").concat(_sanitizePaths(msg))); }; exports.logHook = logHook; var logWarning = function (msg, opts) { var _a; var ctx = (0, core_1.getContext)(); var skipSanitizePaths = (_a = opts === null || opts === void 0 ? void 0 : opts.skipSanitizePaths) !== null && _a !== void 0 ? _a : false; var msgSn = typeof msg === 'string' && !skipSanitizePaths ? _sanitizePaths(msg) : String(msg); if (_jsonOnly) { return _printJson({ type: 'log', level: 'warning', task: stripAnsi(_getCurrentTask()), message: stripAnsi(msgSn), }); } ctx.logging.containsWarning = true; (0, exports.logAndSave)(currentChalk.yellow("warn: ".concat(_getCurrentTask(), " ").concat(msgSn))); }; exports.logWarning = logWarning; var logInfo = function (msg) { var _a; var ctx = (0, core_1.getContext)(); if ((_a = ctx.program) === null || _a === void 0 ? void 0 : _a.opts().help) return; if (_jsonOnly) { return _printJson({ type: 'log', level: 'info', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(msg)), }); } console.log("".concat(_highlightColor('info:'), " ").concat(_sanitizePaths(msg))); }; exports.logInfo = logInfo; var logDebug = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (_isInfoEnabled) { if (_jsonOnly) { return _printJson({ type: 'log', level: 'debug', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(args.join(' '))), }); } if (_infoFilter) { var firstArg_1 = args[0]; if (_infoFilter.filter(function (v) { var _a; return (_a = firstArg_1 === null || firstArg_1 === void 0 ? void 0 : firstArg_1.includes) === null || _a === void 0 ? void 0 : _a.call(firstArg_1, v); }).length) { console.log.apply(null, args); } } else { console.log.apply(null, args); } } }; exports.logDebug = logDebug; var isInfoEnabled = function () { return _isInfoEnabled; }; exports.isInfoEnabled = isInfoEnabled; var logSuccess = function (msg) { if (_jsonOnly) { return _printJson({ type: 'success', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(msg)), }); } (0, exports.logAndSave)("".concat(currentChalk.magenta("info: \u2714"), " ").concat(_sanitizePaths(msg))); }; exports.logSuccess = logSuccess; var logError = function (e, opts) { var _a, _b, _c, _d, _e, _f, _g; var err = ''; if (typeof e === 'string') { err = e; } else if (e instanceof Error) { err = e.message; } var ctx = (0, core_1.getContext)(); var api = (0, core_1.getApi)(); if (!(opts === null || opts === void 0 ? void 0 : opts.skipAnalytics)) { var extra = { command: (0, exports.getCurrentCommand)(), version: ctx.rnvVersion, engine: (_b = (_a = ctx.runtime) === null || _a === void 0 ? void 0 : _a.engine) === null || _b === void 0 ? void 0 : _b.id, platform: ctx.platform, bundleAssets: !!((_c = ctx.runtime) === null || _c === void 0 ? void 0 : _c.bundleAssets), os: (_d = ctx.process) === null || _d === void 0 ? void 0 : _d.platform, arch: (_e = ctx.process) === null || _e === void 0 ? void 0 : _e.arch, node: (_g = (_f = ctx.process) === null || _f === void 0 ? void 0 : _f.versions) === null || _g === void 0 ? void 0 : _g.node, }; api.analytics.captureException(err, { extra: extra }); } if (ctx.logging) { ctx.logging.containsError = true; } if (_jsonOnly) { _printJson({ type: 'log', level: 'error', task: stripAnsi(_getCurrentTask()), message: stripAnsi(_sanitizePaths(err)), }); } else if (e && e instanceof Error) { (0, exports.logAndSave)(currentChalk.red("error: \u2A2F ".concat(_getCurrentTask(), " ").concat(e.stack || e, "\n"))); } else { (0, exports.logAndSave)(currentChalk.red("error: \u2A2F ".concat(_getCurrentTask(), " ").concat(e))); } }; exports.logError = logError; var logAppInfo = function (c) { if (!_jsonOnly) { (0, exports.logInfo)("Current app config: ".concat(_highlightColor(c.runtime.appId))); } }; exports.logAppInfo = logAppInfo; var printIntoBox = function (str, maxLen) { if (maxLen === void 0) { maxLen = 64; } var output = _defaultColor('│ '); var strLenDiff = str.length - stripAnsi(str).length; output += _defaultColor(str); var len = maxLen - (str.length - strLenDiff); if (len > 0) { for (var i = 0; i < len; i++) { output += ' '; } output += _defaultColor('│\n'); } else { output += _defaultColor('\n'); } return output; }; exports.printIntoBox = printIntoBox; var printArrIntoBox = function (arr, prefix) { if (prefix === void 0) { prefix = ''; } if (_jsonOnly) return arr.join(','); var output = ''; var stringArr = ''; var i = 0; arr.forEach(function (v) { var l = i === 0 ? 60 - _defaultColor(prefix).length : 60; if (stringArr.length > l) { if (i === 0 && prefix.length) { output += (0, exports.printIntoBox)("".concat(_defaultColor(prefix)).concat(_defaultColor(stringArr))); } else { output += (0, exports.printIntoBox)(_defaultColor(stringArr)); } stringArr = ''; i++; } stringArr += "".concat(v, ", "); // stringArr[i] += `${c.platformDefaults[v].icon} ${currentChalk.white(v)}, `; }); if (i === 0 && prefix.length) { output += (0, exports.printIntoBox)("".concat(_defaultColor(prefix)).concat(_defaultColor(stringArr.slice(0, -2)))); } else { output += (0, exports.printIntoBox)(_defaultColor(stringArr.slice(0, -2))); } return output; }; exports.printArrIntoBox = printArrIntoBox; var printBoxStart = function (str, str2) { var output = _defaultColor('┌─────────────────────────────────────────────────────────────────┐\n'); output += (0, exports.printIntoBox)(str); output += (0, exports.printIntoBox)(str2 || ''); output += _defaultColor('├─────────────────────────────────────────────────────────────────┤\n'); return output; }; exports.printBoxStart = printBoxStart; var printBoxEnd = function () { return _defaultColor('└─────────────────────────────────────────────────────────────────┘'); }; exports.printBoxEnd = printBoxEnd; var Logger = { logHook: exports.logHook, logInfo: exports.logInfo, logTask: exports.logTask, logError: exports.logError, logDebug: exports.logDebug, logAppInfo: exports.logAppInfo, logDefault: exports.logDefault, logWarning: exports.logWarning, logSuccess: exports.logSuccess, logWelcome: exports.logWelcome, logInitialize: exports.logInitialize, logAndSave: exports.logAndSave, getCurrentCommand: exports.getCurrentCommand, logExitTask: exports.logExitTask, logRaw: exports.logRaw, isInfoEnabled: exports.isInfoEnabled, logInitTask: exports.logInitTask, logSummary: exports.logSummary, logToSummary: exports.logToSummary, printArrIntoBox: exports.printArrIntoBox, printBoxEnd: exports.printBoxEnd, printBoxStart: exports.printBoxStart, printIntoBox: exports.printIntoBox, chalk: exports.chalk, }; exports.default = Logger; //# sourceMappingURL=index.js.map