.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / prettier-stylelint / src / utils.js
1 'use strict';
2
3 const fs = require('fs');
4 const path = require('path');
5 const debug = require('debug')('prettier-stylelint:utils');
6 const ignore = require('ignore');
7
8 exports.arrify = function(val) {
9     if (val === null || val === undefined) {
10         return [];
11     }
12
13     return Array.isArray(val) ? val : [val];
14 };
15
16 exports.ignore = function(paths, options) {
17     const ignorer = ignore();
18     const gitignore = path.resolve(options.cwd, '.gitignore');
19     const prettierignore = path.resolve(options.cwd, '.prettierignore');
20
21     try {
22         ignorer.add(fs.readFileSync(gitignore, 'utf8').toString());
23     } catch (err) {
24         debug('.gitignore error', err.message);
25     }
26
27     try {
28         ignorer.add(fs.readFileSync(prettierignore, 'utf8').toString());
29     } catch (err) {
30         debug('.prettierignore error', err.message);
31     }
32
33     paths = ignorer.filter(paths);
34
35     // Filter out unwanted file extensions
36     // For silly users that don't specify an extension in the glob pattern
37     if (paths.length > 0) {
38         paths = paths.filter((filePath) => {
39             const ext = path.extname(filePath).replace('.', '');
40
41             return options.extensions.indexOf(ext) !== -1;
42         });
43     }
44
45     return paths;
46 };