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");
|
2018-04-25 13:29:35 -03:00
|
|
|
const getSupportInfo = require("./src/main/support").getSupportInfo;
|
2018-05-09 17:53:44 +01:00
|
|
|
const getFileInfo = require("./src/common/get-file-info");
|
2018-04-26 13:38:57 -03:00
|
|
|
const sharedUtil = require("./src/common/util-shared");
|
2018-04-25 13:29:35 -03:00
|
|
|
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
|
2018-05-09 17:53:44 +01:00
|
|
|
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, {
|
2018-05-09 12:17:12 +01:00
|
|
|
plugins: loadPlugins(opts.plugins, opts.pluginSearchDirs)
|
2018-04-26 13:38:57 -03:00
|
|
|
});
|
|
|
|
|
return fn.apply(null, args);
|
2017-05-23 10:43:58 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 17:53:44 +01:00
|
|
|
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);
|
2017-05-21 13:14:13 -04:00
|
|
|
|
2016-11-29 15:23:00 -05:00
|
|
|
module.exports = {
|
2018-04-26 13:38:57 -03:00
|
|
|
formatWithCursor,
|
2017-07-10 22:26:36 +10:00
|
|
|
|
2018-04-26 13:38:57 -03:00
|
|
|
format(text, opts) {
|
|
|
|
|
return formatWithCursor(text, opts).formatted;
|
2017-01-18 12:45:44 -08:00
|
|
|
},
|
2017-07-10 22:26:36 +10:00
|
|
|
|
2017-04-03 09:54:10 -07:00
|
|
|
check: function(text, opts) {
|
|
|
|
|
try {
|
2018-04-26 13:38:57 -03:00
|
|
|
const formatted = formatWithCursor(text, opts).formatted;
|
2017-04-03 09:54:10 -07:00
|
|
|
return formatted === text;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-07-10 22:26:36 +10:00
|
|
|
|
2017-12-26 12:23:50 +11:00
|
|
|
doc,
|
|
|
|
|
|
2017-07-11 20:40:51 +10:00
|
|
|
resolveConfig: config.resolveConfig,
|
2018-04-25 13:29:35 -03:00
|
|
|
resolveConfigFile: config.resolveConfigFile,
|
2017-07-11 20:40:51 +10:00
|
|
|
clearConfigCache: config.clearCache,
|
2017-07-10 22:26:36 +10:00
|
|
|
|
2018-05-09 17:53:44 +01:00
|
|
|
getFileInfo: withPlugins(getFileInfo),
|
2018-04-26 13:38:57 -03:00
|
|
|
getSupportInfo: withPlugins(getSupportInfo),
|
2017-11-03 18:06:25 +11:00
|
|
|
|
2017-07-10 22:26:36 +10:00
|
|
|
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
|
|
|
};
|