/
printConfig.js
55 lines (45 loc) · 1.44 KB
/
printConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* @flow */
"use strict";
const _ = require("lodash");
const createStylelint = require("./createStylelint");
const globby /*: Function*/ = require("globby");
const path = require("path");
module.exports = function(
options /*: stylelint$standaloneOptions */
) /*: Promise<stylelint$config>*/ {
const code = options.code;
const config = options.config;
const configBasedir = options.configBasedir;
const configFile = options.configFile;
const configOverrides = options.configOverrides;
const globbyOptions = options.globbyOptions;
const files = options.files;
const isCodeNotFile = code !== undefined;
if (!files || files.length !== 1 || isCodeNotFile) {
return Promise.reject(
new Error(
"The --print-config option must be used with exactly one file path."
)
);
}
const filePath = files[0];
if (globby.hasMagic(filePath.replace(/\\/g, "/"))) {
return Promise.reject(
new Error("The --print-config option does not support globs.")
);
}
const stylelint = createStylelint({
config,
configFile,
configBasedir,
configOverrides
});
const cwd = _.get(globbyOptions, "cwd", process.cwd());
const absoluteFilePath = !path.isAbsolute(filePath)
? path.join(cwd, filePath)
: path.normalize(filePath);
const configSearchPath = stylelint._options.configFile || absoluteFilePath;
return stylelint
.getConfigForFile(configSearchPath)
.then(result => result.config);
};