UNPKG

@spotify/web-scripts

Version:

Build, lint, test, format, and release your JS/TS library.

39 lines (38 loc) 1.41 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { default as Debug } from 'debug'; import { default as spawn } from 'cross-spawn'; import { hasConfig } from '@spotify/web-scripts-utils'; import { PRETTIER_CONFIG, CONSUMING_ROOT } from '../../Paths'; var dbg = Debug('web-scripts:format'); export function getPrettierConfig() { if (!hasConfig([ { type: 'file', pattern: '.prettierrc' }, { type: 'file', pattern: 'prettier.config.js' }, { type: 'package.json', property: 'prettierrc' }, ])) { return PRETTIER_CONFIG; } return null; } export function formatTask(task) { var cmd = 'npx'; var config = task.config || getPrettierConfig(); var path = task.path || "".concat(CONSUMING_ROOT, "/**/src"); var args = __spreadArray(__spreadArray([ '--no-install', 'prettier' ], (config ? ['--config', config] : []), true), [ '--write', "".concat(path, "/**/*.{ts,tsx,js,jsx}"), ], false); dbg('npx args %o', args); return spawn.sync(cmd, args, { stdio: 'inherit' }); }