Files
portfolio2023/node_modules/@poppinss/cliui/build/api.js
T
2023-11-24 22:35:41 +01:00

109 lines
4.1 KiB
JavaScript

"use strict";
/*
* @poppinss/cliui
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.instantiate = void 0;
const color_support_1 = __importDefault(require("color-support"));
const Icons_1 = require("./src/Icons");
const Table_1 = require("./src/Table");
const Logger_1 = require("./src/Logger");
const Manager_1 = require("./src/Task/Manager");
const Instructions_1 = require("./src/Instructions");
const Memory_1 = require("./src/Renderer/Memory");
const Console_1 = require("./src/Renderer/Console");
function instantiate(testing) {
/**
* Is terminal interactive or not. The code is copied from
* https://github.com/sindresorhus/is-interactive/blob/master/index.js.
*
* Yes, we can install it as a dependency, but decided to copy/paste 4
* lines. NO STRONG REASONS BEHIND IT
*/
const isInteractive = Boolean(process.stdout && process.stdout.isTTY && process.env.TERM !== 'dumb' && !('CI' in process.env));
/**
* Whether or not colors are enabled. They are enabled by default,
* unless the terminal doesn't support color. Also "FORCE_COLOR"
* env variable enables them forcefully.
*/
const supportsColors = !!process.env.FORCE_COLOR || color_support_1.default.level > 0;
/**
* The renderer used in the testing mode. One can access it to listen
* for the log messages. Also, the memory renderer only works when
* the "CLI_UI_IS_TESTING" flag is set
*/
const testingRenderer = new Memory_1.MemoryRenderer();
/**
* Console renderer outputs to the console. We do not export it, since one
* cannot do much by having an access to it.
*/
const consoleRenderer = new Console_1.ConsoleRenderer();
/**
* Logger
*/
const logger = new Logger_1.Logger({ colors: supportsColors, interactive: isInteractive }, testing);
logger.useRenderer(testing ? testingRenderer : consoleRenderer);
/**
* Reference to the instructions block to render a set of lines inside
* a box.
*/
const instructions = () => {
const instructionsInstance = new Instructions_1.Instructions({ colors: supportsColors, icons: true }, testing);
instructionsInstance.useRenderer(testing ? testingRenderer : consoleRenderer);
return instructionsInstance;
};
/**
* Similar to instructions. But the lines are not prefix with a pointer `>`
*/
const sticker = () => {
const stickerInstance = new Instructions_1.Instructions({ colors: supportsColors, icons: false }, testing);
stickerInstance.useRenderer(testing ? testingRenderer : consoleRenderer);
return stickerInstance;
};
/**
* Initiates a group of tasks
*/
const tasks = () => {
const manager = new Manager_1.TaskManager({ colors: supportsColors, interactive: isInteractive }, testing);
manager.useRenderer(testing ? testingRenderer : consoleRenderer);
return manager;
};
/**
* Initiate tasks in verbose mode
*/
tasks.verbose = () => {
const manager = new Manager_1.TaskManager({ colors: supportsColors, interactive: isInteractive, verbose: true }, testing);
manager.useRenderer(testing ? testingRenderer : consoleRenderer);
return manager;
};
/**
* Instantiate a new table
*/
const table = () => {
const tableInstance = new Table_1.Table({ colors: supportsColors }, testing);
tableInstance.useRenderer(testing ? testingRenderer : consoleRenderer);
return tableInstance;
};
return {
table,
tasks,
icons: Icons_1.icons,
logger,
sticker,
instructions,
isInteractive,
supportsColors,
consoleRenderer,
testingRenderer,
};
}
exports.instantiate = instantiate;