UNPKG

@beemo/driver-prettier

Version:

Prettier driver for Beemo.

69 lines (51 loc) 1.92 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const fs = require('fs'); const core = require('@beemo/core'); const event = require('@boost/event'); const _interopDefault = e => e && e.__esModule ? e : { default: e }; const fs__default = /*#__PURE__*/_interopDefault(fs); // Success: Writes formatted files to stdout // Failure: Writes to stderr for no files found and syntax errors class PrettierDriver extends core.Driver { constructor(...args) { super(...args); this.name = '@beemo/driver-prettier'; this.onCreateIgnoreFile = new event.Event('create-ignore-file'); this.handleCreateIgnoreFile = (context, configPath, config) => { if (!config.ignore) { return; } if (!Array.isArray(config.ignore)) { throw new TypeError(this.tool.msg('errors:prettierIgnoreInvalid')); } const ignorePath = configPath.parent().append('.prettierignore'); const _config$ignore = config.ignore, ignore = _config$ignore === void 0 ? [] : _config$ignore; this.onCreateIgnoreFile.emit([context, ignorePath, { ignore }]); fs__default.default.writeFileSync(ignorePath.path(), ignore.join('\n')); // Add to context so that it can be automatically cleaned up context.addConfigPath('prettier', ignorePath); // Delete the property // eslint-disable-next-line no-param-reassign delete config.ignore; }; } bootstrap() { this.setMetadata({ bin: 'prettier', configName: 'prettier.config.js', description: this.tool.msg('app:prettierDescription'), title: 'Prettier' }); this.onCreateConfigFile.listen(this.handleCreateIgnoreFile); } /** * If an "ignore" property exists in the Prettier config, create an ".prettierconfig" file. */ } exports.PrettierDriver = PrettierDriver; //# sourceMappingURL=PrettierDriver.js.map