refactor: move index.js and standalone.js to src (#5054)
There're always 2 files that they're source code but not in the `src` directory, which makes it hard to search. - move the content of `index.js` and `standalone.js` to `src`. - `/index.js` and `/standalone.js` are preserved as links to not break builds that's installed from git.master
parent
461e6035c1
commit
1965b74e61
69
index.js
69
index.js
|
@ -1,70 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
const version = require("./package.json").version;
|
||||
|
||||
const core = require("./src/main/core");
|
||||
const getSupportInfo = require("./src/main/support").getSupportInfo;
|
||||
const getFileInfo = require("./src/common/get-file-info");
|
||||
const sharedUtil = require("./src/common/util-shared");
|
||||
const loadPlugins = require("./src/common/load-plugins");
|
||||
|
||||
const config = require("./src/config/resolve-config");
|
||||
|
||||
const doc = require("./src/doc");
|
||||
|
||||
// Luckily `opts` is always the 2nd argument
|
||||
function _withPlugins(fn) {
|
||||
return function() {
|
||||
const args = Array.from(arguments);
|
||||
const opts = args[1] || {};
|
||||
args[1] = Object.assign({}, opts, {
|
||||
plugins: loadPlugins(opts.plugins, opts.pluginSearchDirs)
|
||||
});
|
||||
return fn.apply(null, args);
|
||||
};
|
||||
}
|
||||
|
||||
function withPlugins(fn) {
|
||||
const resultingFn = _withPlugins(fn);
|
||||
if (fn.sync) {
|
||||
resultingFn.sync = _withPlugins(fn.sync);
|
||||
}
|
||||
return resultingFn;
|
||||
}
|
||||
|
||||
const formatWithCursor = withPlugins(core.formatWithCursor);
|
||||
|
||||
module.exports = {
|
||||
formatWithCursor,
|
||||
|
||||
format(text, opts) {
|
||||
return formatWithCursor(text, opts).formatted;
|
||||
},
|
||||
|
||||
check: function(text, opts) {
|
||||
const formatted = formatWithCursor(text, opts).formatted;
|
||||
return formatted === text;
|
||||
},
|
||||
|
||||
doc,
|
||||
|
||||
resolveConfig: config.resolveConfig,
|
||||
resolveConfigFile: config.resolveConfigFile,
|
||||
clearConfigCache: config.clearCache,
|
||||
|
||||
getFileInfo: withPlugins(getFileInfo),
|
||||
getSupportInfo: withPlugins(getSupportInfo),
|
||||
|
||||
version,
|
||||
|
||||
util: sharedUtil,
|
||||
|
||||
/* istanbul ignore next */
|
||||
__debug: {
|
||||
parse: withPlugins(core.parse),
|
||||
formatAST: withPlugins(core.formatAST),
|
||||
formatDoc: withPlugins(core.formatDoc),
|
||||
printToDoc: withPlugins(core.printToDoc),
|
||||
printDocToString: withPlugins(core.printDocToString)
|
||||
}
|
||||
};
|
||||
module.exports = require("./src/index");
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
"use strict";
|
||||
|
||||
const version = require("../package.json").version;
|
||||
|
||||
const core = require("./main/core");
|
||||
const getSupportInfo = require("./main/support").getSupportInfo;
|
||||
const getFileInfo = require("./common/get-file-info");
|
||||
const sharedUtil = require("./common/util-shared");
|
||||
const loadPlugins = require("./common/load-plugins");
|
||||
|
||||
const config = require("./config/resolve-config");
|
||||
|
||||
const doc = require("./doc");
|
||||
|
||||
// Luckily `opts` is always the 2nd argument
|
||||
function _withPlugins(fn) {
|
||||
return function() {
|
||||
const args = Array.from(arguments);
|
||||
const opts = args[1] || {};
|
||||
args[1] = Object.assign({}, opts, {
|
||||
plugins: loadPlugins(opts.plugins, opts.pluginSearchDirs)
|
||||
});
|
||||
return fn.apply(null, args);
|
||||
};
|
||||
}
|
||||
|
||||
function withPlugins(fn) {
|
||||
const resultingFn = _withPlugins(fn);
|
||||
if (fn.sync) {
|
||||
resultingFn.sync = _withPlugins(fn.sync);
|
||||
}
|
||||
return resultingFn;
|
||||
}
|
||||
|
||||
const formatWithCursor = withPlugins(core.formatWithCursor);
|
||||
|
||||
module.exports = {
|
||||
formatWithCursor,
|
||||
|
||||
format(text, opts) {
|
||||
return formatWithCursor(text, opts).formatted;
|
||||
},
|
||||
|
||||
check: function(text, opts) {
|
||||
const formatted = formatWithCursor(text, opts).formatted;
|
||||
return formatted === text;
|
||||
},
|
||||
|
||||
doc,
|
||||
|
||||
resolveConfig: config.resolveConfig,
|
||||
resolveConfigFile: config.resolveConfigFile,
|
||||
clearConfigCache: config.clearCache,
|
||||
|
||||
getFileInfo: withPlugins(getFileInfo),
|
||||
getSupportInfo: withPlugins(getSupportInfo),
|
||||
|
||||
version,
|
||||
|
||||
util: sharedUtil,
|
||||
|
||||
/* istanbul ignore next */
|
||||
__debug: {
|
||||
parse: withPlugins(core.parse),
|
||||
formatAST: withPlugins(core.formatAST),
|
||||
formatDoc: withPlugins(core.formatDoc),
|
||||
printToDoc: withPlugins(core.printToDoc),
|
||||
printDocToString: withPlugins(core.printDocToString)
|
||||
}
|
||||
};
|
|
@ -0,0 +1,71 @@
|
|||
"use strict";
|
||||
|
||||
const version = require("../package.json").version;
|
||||
|
||||
const core = require("./main/core");
|
||||
const getSupportInfo = require("./main/support").getSupportInfo;
|
||||
const sharedUtil = require("./common/util-shared");
|
||||
|
||||
const doc = require("./doc");
|
||||
|
||||
const internalPlugins = [
|
||||
require("./language-js"),
|
||||
require("./language-css"),
|
||||
require("./language-graphql"),
|
||||
require("./language-handlebars"),
|
||||
require("./language-markdown"),
|
||||
require("./language-vue"),
|
||||
require("./language-yaml")
|
||||
];
|
||||
|
||||
const isArray =
|
||||
Array.isArray ||
|
||||
function(arr) {
|
||||
return Object.prototype.toString.call(arr) === "[object Array]";
|
||||
};
|
||||
|
||||
// Luckily `opts` is always the 2nd argument
|
||||
function withPlugins(fn) {
|
||||
return function() {
|
||||
const args = Array.from(arguments);
|
||||
let plugins = (args[1] && args[1].plugins) || [];
|
||||
if (!isArray(plugins)) {
|
||||
plugins = Object.values(plugins);
|
||||
}
|
||||
args[1] = Object.assign({}, args[1], {
|
||||
plugins: internalPlugins.concat(plugins)
|
||||
});
|
||||
return fn.apply(null, args);
|
||||
};
|
||||
}
|
||||
|
||||
const formatWithCursor = withPlugins(core.formatWithCursor);
|
||||
|
||||
module.exports = {
|
||||
formatWithCursor: formatWithCursor,
|
||||
|
||||
format(text, opts) {
|
||||
return formatWithCursor(text, opts).formatted;
|
||||
},
|
||||
|
||||
check(text, opts) {
|
||||
const formatted = formatWithCursor(text, opts).formatted;
|
||||
return formatted === text;
|
||||
},
|
||||
|
||||
doc,
|
||||
|
||||
getSupportInfo: withPlugins(getSupportInfo),
|
||||
|
||||
version,
|
||||
|
||||
util: sharedUtil,
|
||||
|
||||
__debug: {
|
||||
parse: withPlugins(core.parse),
|
||||
formatAST: withPlugins(core.formatAST),
|
||||
formatDoc: withPlugins(core.formatDoc),
|
||||
printToDoc: withPlugins(core.printToDoc),
|
||||
printDocToString: withPlugins(core.printDocToString)
|
||||
}
|
||||
};
|
|
@ -1,71 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
const version = require("./package.json").version;
|
||||
|
||||
const core = require("./src/main/core");
|
||||
const getSupportInfo = require("./src/main/support").getSupportInfo;
|
||||
const sharedUtil = require("./src/common/util-shared");
|
||||
|
||||
const doc = require("./src/doc");
|
||||
|
||||
const internalPlugins = [
|
||||
require("./src/language-js"),
|
||||
require("./src/language-css"),
|
||||
require("./src/language-graphql"),
|
||||
require("./src/language-handlebars"),
|
||||
require("./src/language-markdown"),
|
||||
require("./src/language-vue"),
|
||||
require("./src/language-yaml")
|
||||
];
|
||||
|
||||
const isArray =
|
||||
Array.isArray ||
|
||||
function(arr) {
|
||||
return Object.prototype.toString.call(arr) === "[object Array]";
|
||||
};
|
||||
|
||||
// Luckily `opts` is always the 2nd argument
|
||||
function withPlugins(fn) {
|
||||
return function() {
|
||||
const args = Array.from(arguments);
|
||||
let plugins = (args[1] && args[1].plugins) || [];
|
||||
if (!isArray(plugins)) {
|
||||
plugins = Object.values(plugins);
|
||||
}
|
||||
args[1] = Object.assign({}, args[1], {
|
||||
plugins: internalPlugins.concat(plugins)
|
||||
});
|
||||
return fn.apply(null, args);
|
||||
};
|
||||
}
|
||||
|
||||
const formatWithCursor = withPlugins(core.formatWithCursor);
|
||||
|
||||
module.exports = {
|
||||
formatWithCursor: formatWithCursor,
|
||||
|
||||
format(text, opts) {
|
||||
return formatWithCursor(text, opts).formatted;
|
||||
},
|
||||
|
||||
check(text, opts) {
|
||||
const formatted = formatWithCursor(text, opts).formatted;
|
||||
return formatted === text;
|
||||
},
|
||||
|
||||
doc,
|
||||
|
||||
getSupportInfo: withPlugins(getSupportInfo),
|
||||
|
||||
version,
|
||||
|
||||
util: sharedUtil,
|
||||
|
||||
__debug: {
|
||||
parse: withPlugins(core.parse),
|
||||
formatAST: withPlugins(core.formatAST),
|
||||
formatDoc: withPlugins(core.formatDoc),
|
||||
printToDoc: withPlugins(core.printToDoc),
|
||||
printDocToString: withPlugins(core.printDocToString)
|
||||
}
|
||||
};
|
||||
module.exports = require("./src/standalone");
|
||||
|
|
Loading…
Reference in New Issue