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.
 
 
 
 

38 lines
1.4 KiB

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runPrettier = void 0;
const fs_1 = __importDefault(require("fs"));
const webpack_cli_1 = require("webpack-cli");
const { logger } = webpack_cli_1.utils;
/**
*
* Runs prettier and later prints the output configuration
*
* @param {string} outputPath - Path to write the config to
* @param {string} source - AST to write at the given path
* @returns {void} Writes a file at given location
*/
function runPrettier(outputPath, source) {
let prettySource = source;
let prettier;
try {
// eslint-disable-next-line node/no-extraneous-require
prettier = require('prettier');
}
catch (err) {
logger.warn("File is not properly formatted because you don't have prettier installed, you can either install it or format it manually");
return fs_1.default.writeFileSync(outputPath, source, 'utf8');
}
try {
prettySource = prettier.format(source, { filepath: outputPath, parser: 'babel' });
}
catch (error) {
logger.warn(`\nWARNING: Could not apply prettier to ${outputPath} due to validation error, but the file has been created`);
prettySource = source;
}
fs_1.default.writeFileSync(outputPath, prettySource, 'utf8');
}
exports.runPrettier = runPrettier;