1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.resolvePath = resolvePath;
|
7 | exports.isPathExist = isPathExist;
|
8 | exports.findPathThatExist = findPathThatExist;
|
9 | exports.getWebpackConfigByPath = getWebpackConfigByPath;
|
10 |
|
11 | var _path = require('path');
|
12 |
|
13 | var _path2 = _interopRequireDefault(_path);
|
14 |
|
15 | var _fs = require('fs');
|
16 |
|
17 | var _fs2 = _interopRequireDefault(_fs);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | function 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 |
|
31 | function isPathExist(targetPath) {
|
32 | try {
|
33 | _fs2.default.statSync(targetPath);
|
34 | } catch (err) {
|
35 | return err.code !== 'ENOENT';
|
36 | }
|
37 |
|
38 | return true;
|
39 | }
|
40 |
|
41 | function 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 |
|
51 | function 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 |
|
59 | require('babel-register');
|
60 |
|
61 | return require(currentPath).default;
|
62 |
|
63 | }
|
64 |
|
\ | No newline at end of file |