Files
test-repo/index.js
T

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-01-10 12:18:22 -05:00
"use strict";
2017-01-28 07:50:22 -08:00
2017-01-18 15:31:46 -08:00
const version = require("./package.json").version;
2017-12-27 00:04:09 +11:00
2018-04-26 13:38:57 -03:00
const core = require("./src/main/core");
const getSupportInfo = require("./src/main/support").getSupportInfo;
const getFileInfo = require("./src/common/get-file-info");
2018-04-26 13:38:57 -03:00
const sharedUtil = require("./src/common/util-shared");
const loadPlugins = require("./src/common/load-plugins");
2017-12-27 00:04:09 +11:00
const config = require("./src/config/resolve-config");
2017-12-26 12:23:50 +11:00
const doc = require("./src/doc");
2016-11-29 15:23:00 -05:00
2018-04-26 13:38:57 -03:00
// Luckily `opts` is always the 2nd argument
function _withPlugins(fn) {
2018-04-26 13:38:57 -03:00
return function() {
const args = Array.from(arguments);
const opts = args[1] || {};
args[1] = Object.assign({}, opts, {
plugins: loadPlugins(opts.plugins, opts.pluginSearchDirs)
2018-04-26 13:38:57 -03:00
});
return fn.apply(null, args);
};
}
function withPlugins(fn) {
const resultingFn = _withPlugins(fn);
if (fn.sync) {
resultingFn.sync = _withPlugins(fn.sync);
}
return resultingFn;
}
2018-04-26 13:38:57 -03:00
const formatWithCursor = withPlugins(core.formatWithCursor);
2016-11-29 15:23:00 -05:00
module.exports = {
2018-04-26 13:38:57 -03:00
formatWithCursor,
2018-04-26 13:38:57 -03:00
format(text, opts) {
return formatWithCursor(text, opts).formatted;
2017-01-18 12:45:44 -08:00
},
check: function(text, opts) {
try {
2018-04-26 13:38:57 -03:00
const formatted = formatWithCursor(text, opts).formatted;
return formatted === text;
} catch (e) {
return false;
}
},
2017-12-26 12:23:50 +11:00
doc,
2017-07-11 20:40:51 +10:00
resolveConfig: config.resolveConfig,
resolveConfigFile: config.resolveConfigFile,
2017-07-11 20:40:51 +10:00
clearConfigCache: config.clearCache,
getFileInfo: withPlugins(getFileInfo),
2018-04-26 13:38:57 -03:00
getSupportInfo: withPlugins(getSupportInfo),
version,
2018-02-10 03:01:19 +01:00
util: sharedUtil,
2017-07-16 21:49:37 +10:00
/* istanbul ignore next */
2017-01-20 09:54:32 -08:00
__debug: {
2018-04-26 13:38:57 -03:00
parse: withPlugins(core.parse),
formatAST: withPlugins(core.formatAST),
formatDoc: withPlugins(core.formatDoc),
printToDoc: withPlugins(core.printToDoc),
printDocToString: withPlugins(core.printDocToString)
2017-01-20 09:54:32 -08:00
}
2016-11-29 15:23:00 -05:00
};