UNPKG

931 BJavaScriptView Raw
1/* eslint-env node */
2/* eslint-disable no-console */
3const findUp = require('find-up');
4const path = require('path');
5
6// Traverse up the folder tree, trying to find config files
7module.exports = function(cwd = process.cwd()) {
8 const creunaRcPath = findUp.sync('.creunarc.json', { cwd });
9 const eslintRcPath = findUp.sync('.eslintrc.json', { cwd });
10
11 const eslintConfig =
12 eslintRcPath && require(path.relative(__dirname, eslintRcPath));
13
14 if (!creunaRcPath) {
15 return { componentsPath: cwd, eslintConfig, mockupPath: cwd };
16 }
17
18 const projectRoot = path.dirname(creunaRcPath);
19 const {
20 componentsPath,
21 mockupPath,
22 dataFileExtension,
23 dataFileContent
24 } = require(path.relative(__dirname, creunaRcPath));
25
26 return {
27 componentsPath: path.join(projectRoot, componentsPath),
28 mockupPath: path.join(projectRoot, mockupPath),
29 dataFileContent,
30 dataFileExtension,
31 eslintConfig
32 };
33};