UNPKG

925 BJavaScriptView Raw
1/**
2 * @file: getPath
3 * @author: Cuttle Cong
4 * @date: 2017/11/9
5 * @description:
6 */
7
8var nps = require('path');
9var fs = require('../../lib/lib/utils/fs');
10var find = require('../../lib/lib/utils/find-parent-dir');
11var console = require('../../lib/lib/utils/console').default;
12
13module.exports = function (path) {
14 var configPath, cwd = process.cwd()
15 if (path) {
16 configPath = nps.resolve(path)
17 if(!fs.isFile(configPath)) {
18 throw new Error('Not found `' + path + '`')
19 } else {
20 cwd = nps.dirname(configPath)
21 }
22 } else {
23 cwd = find('picidae.config.js')
24 if (!cwd) {
25 throw new Error('Not found `picidae.config.js`')
26 }
27 configPath = nps.join(cwd, 'picidae.config.js')
28 }
29
30 console.log('config in:', configPath)
31 console.log('cwd is:', cwd)
32
33 return {
34 configPath: configPath,
35 cwd: cwd
36 }
37}