@coat/cli
Version:
TODO: See #3
39 lines (36 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.textFileFunctions = void 0;
var _singleTrailingNewline = _interopRequireDefault(require("single-trailing-newline"));
var _getPrettier = require("../util/get-prettier");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function merge(_source, target) {
// The default "merge" for text files simply returns
// the target string, without looking at the source
// string.
return target;
}
function polish(source, filePath, context) {
const prettier = (0, _getPrettier.getPrettier)(context);
// Check whether prettier can infer a parser
// for the file. If it can, the file should
// be styled via prettier, otherwise only a
// new line at the end should be added
const fileInfo = prettier.getFileInfo.sync(filePath);
if (fileInfo.inferredParser) {
return prettier.format(source, {
filepath: filePath
});
}
// Only the end of a text file should be modified, by
// either adding or removing new lines to get a consistent
// single trailing new line at the end of the file.
return (0, _singleTrailingNewline.default)(source);
}
const textFileFunctions = {
merge,
polish
};
exports.textFileFunctions = textFileFunctions;