Son CV dans un terminal web en Javascript! https://terminal-cv.gregandev.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

270 lines
7.9 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._report = _report;
exports.default = void 0;
function _plugin() {
const data = require("@parcel/plugin");
_plugin = function () {
return data;
};
return data;
}
function _utils() {
const data = require("@parcel/utils");
_utils = function () {
return data;
};
return data;
}
function _chalk() {
const data = _interopRequireDefault(require("chalk"));
_chalk = function () {
return data;
};
return data;
}
var _utils2 = require("./utils");
var _logLevels = _interopRequireDefault(require("./logLevels"));
var _bundleReport = _interopRequireDefault(require("./bundleReport"));
var _render = require("./render");
var emoji = _interopRequireWildcard(require("./emoji"));
function _wrapAnsi() {
const data = _interopRequireDefault(require("wrap-ansi"));
_wrapAnsi = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const THROTTLE_DELAY = 100;
const seenWarnings = new Set();
const seenPhases = new Set();
let statusThrottle = (0, _utils().throttle)(message => {
(0, _render.updateSpinner)(message);
}, THROTTLE_DELAY); // Exported only for test
async function _report(event, options) {
let logLevelFilter = _logLevels.default[options.logLevel || 'info'];
switch (event.type) {
case 'buildStart':
{
seenWarnings.clear();
seenPhases.clear();
if (logLevelFilter < _logLevels.default.info) {
break;
} // Clear any previous output
(0, _render.resetWindow)();
if (options.serveOptions) {
var _options$serveOptions;
(0, _render.persistMessage)(_chalk().default.blue.bold(`Server running at ${options.serveOptions.https ? 'https' : 'http'}://${(_options$serveOptions = options.serveOptions.host) !== null && _options$serveOptions !== void 0 ? _options$serveOptions : 'localhost'}:${options.serveOptions.port}`));
}
break;
}
case 'buildProgress':
{
if (logLevelFilter < _logLevels.default.info) {
break;
}
if (!_render.isTTY && logLevelFilter != _logLevels.default.verbose) {
if (event.phase == 'transforming' && !seenPhases.has('transforming')) {
(0, _render.updateSpinner)('Building...');
} else if (event.phase == 'bundling' && !seenPhases.has('bundling')) {
(0, _render.updateSpinner)('Bundling...');
} else if ((event.phase == 'packaging' || event.phase == 'optimizing') && !seenPhases.has('packaging') && !seenPhases.has('optimizing')) {
(0, _render.updateSpinner)('Packaging & Optimizing...');
}
seenPhases.add(event.phase);
break;
}
let message = (0, _utils2.getProgressMessage)(event);
if (message != null) {
if (_render.isTTY) {
statusThrottle(_chalk().default.gray.bold(message));
} else {
(0, _render.updateSpinner)(message);
}
}
break;
}
case 'buildSuccess':
if (logLevelFilter < _logLevels.default.info) {
break;
}
(0, _render.persistSpinner)('buildProgress', 'success', _chalk().default.green.bold(`Built in ${(0, _utils().prettifyTime)(event.buildTime)}`));
if (options.mode === 'production') {
var _options$detailedRepo;
await (0, _bundleReport.default)(event.bundleGraph, options.outputFS, options.projectRoot, (_options$detailedRepo = options.detailedReport) === null || _options$detailedRepo === void 0 ? void 0 : _options$detailedRepo.assetsPerBundle);
}
break;
case 'buildFailure':
if (logLevelFilter < _logLevels.default.error) {
break;
}
(0, _render.resetWindow)();
(0, _render.persistSpinner)('buildProgress', 'error', _chalk().default.red.bold('Build failed.'));
await writeDiagnostic(options, event.diagnostics, 'red', true);
break;
case 'log':
{
if (logLevelFilter < _logLevels.default[event.level]) {
break;
}
switch (event.level) {
case 'success':
(0, _render.writeOut)(_chalk().default.green(event.message));
break;
case 'progress':
(0, _render.writeOut)(event.message);
break;
case 'verbose':
case 'info':
await writeDiagnostic(options, event.diagnostics, 'blue');
break;
case 'warn':
if (event.diagnostics.some(diagnostic => !seenWarnings.has(diagnostic.message))) {
await writeDiagnostic(options, event.diagnostics, 'yellow', true);
for (let diagnostic of event.diagnostics) {
seenWarnings.add(diagnostic.message);
}
}
break;
case 'error':
await writeDiagnostic(options, event.diagnostics, 'red', true);
break;
default:
throw new Error('Unknown log level ' + event.level);
}
}
}
}
async function writeDiagnostic(options, diagnostics, color, isError = false) {
let columns = (0, _utils2.getTerminalWidth)().columns;
let indent = 2;
for (let diagnostic of diagnostics) {
let {
message,
stack,
codeframe,
hints,
documentation
} = await (0, _utils().prettyDiagnostic)(diagnostic, options, columns - indent);
message = _chalk().default[color](message);
if (isError) {
(0, _render.writeOut)('');
}
if (message) {
(0, _render.writeOut)(wrapWithIndent(message), isError);
}
if (stack || codeframe) {
(0, _render.writeOut)('');
}
if (stack) {
(0, _render.writeOut)(_chalk().default.gray(wrapWithIndent(stack, indent)), isError);
}
if (codeframe) {
(0, _render.writeOut)(indentString(codeframe, indent), isError);
}
if ((stack || codeframe) && (hints.length > 0 || documentation)) {
(0, _render.writeOut)('');
} // Write hints
let hintIndent = stack || codeframe ? indent : 0;
for (let hint of hints) {
(0, _render.writeOut)(wrapWithIndent(`${emoji.hint} ${_chalk().default.blue.bold(hint)}`, hintIndent + 3, hintIndent));
}
if (documentation) {
(0, _render.writeOut)(wrapWithIndent(`${emoji.docs} ${_chalk().default.magenta.bold(documentation)}`, hintIndent + 3, hintIndent));
}
}
if (isError) {
(0, _render.writeOut)('');
}
}
function wrapWithIndent(string, indent = 0, initialIndent = indent) {
let width = (0, _utils2.getTerminalWidth)().columns;
return indentString((0, _wrapAnsi().default)(string, width - indent), indent, initialIndent);
}
function indentString(string, indent = 0, initialIndent = indent) {
return ' '.repeat(initialIndent) + string.replace(/\n/g, '\n' + ' '.repeat(indent));
}
var _default = new (_plugin().Reporter)({
report({
event,
options
}) {
return _report(event, options);
}
});
exports.default = _default;