UNPKG

1.6 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.resolvePath = resolvePath;
7exports.isPathExist = isPathExist;
8exports.findPathThatExist = findPathThatExist;
9exports.getWebpackConfigByPath = getWebpackConfigByPath;
10
11var _path = require('path');
12
13var _path2 = _interopRequireDefault(_path);
14
15var _fs = require('fs');
16
17var _fs2 = _interopRequireDefault(_fs);
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21function resolvePath() {
22 var currentPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
23
24 if (typeof currentPath !== 'string') {
25 throw new Error('currentPath is not string');
26 }
27
28 return _path2.default.resolve(process.cwd(), currentPath);
29}
30
31function isPathExist(targetPath) {
32 try {
33 _fs2.default.statSync(targetPath);
34 } catch (err) {
35 return err.code !== 'ENOENT';
36 }
37
38 return true;
39}
40
41function findPathThatExist() {
42 for (var _len = arguments.length, paths = Array(_len), _key = 0; _key < _len; _key++) {
43 paths[_key] = arguments[_key];
44 }
45
46 return paths.find(function (currectPath) {
47 return isPathExist(currectPath);
48 });
49}
50
51function getWebpackConfigByPath() {
52 var currentPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
53
54 if (typeof currentPath !== 'string') {
55 throw new Error('currentPath is not string');
56 }
57
58 /* eslint-disable global-require, import/no-dynamic-require */
59 require('babel-register');
60
61 return require(currentPath).default;
62 /* eslint-enable */
63}
64//# sourceMappingURL=utils.js.map
\No newline at end of file