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