UNPKG

@lcap/builder

Version:
45 lines (44 loc) 2.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatCode = formatCode; const path_1 = __importDefault(require("path")); const fs_extra_1 = __importDefault(require("fs-extra")); const prettier_1 = __importDefault(require("prettier")); function formatCode(code_1) { return __awaiter(this, arguments, void 0, function* (code, parser = 'babel') { let options = { printWidth: 120, tabWidth: 2, useTabs: false, singleQuote: true, vueIndentScriptAndStyle: false, trailingComma: 'all', bracketSpacing: true, bracketSameLine: true, arrowParens: 'always', semi: true, }; const configFilePath = path_1.default.resolve(process.cwd(), '.prettierrc'); if (fs_extra_1.default.existsSync(configFilePath)) { const customOptions = yield prettier_1.default.resolveConfig(configFilePath, { editorconfig: fs_extra_1.default.existsSync('.editorconfig'), }); if (customOptions) { options = customOptions; } } return prettier_1.default.format(code, Object.assign(Object.assign({}, options), { parser })); }); }