1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | const path_1 = __importDefault(require("path"));
|
6 | const findup_sync_1 = __importDefault(require("findup-sync"));
|
7 | const esmRequire = require('esm')(module);
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function requireBrocfile(brocfilePath) {
|
15 | let brocfile;
|
16 | if (brocfilePath.match(/\.ts$/)) {
|
17 | try {
|
18 | require.resolve('ts-node');
|
19 | }
|
20 | catch (e) {
|
21 | throw new Error(`Cannot find module 'ts-node', please install`);
|
22 | }
|
23 | try {
|
24 | require.resolve('typescript');
|
25 | }
|
26 | catch (e) {
|
27 | throw new Error(`Cannot find module 'typescript', please install`);
|
28 | }
|
29 |
|
30 | require('ts-node').register();
|
31 |
|
32 | brocfile = require(brocfilePath);
|
33 | }
|
34 | else {
|
35 |
|
36 | brocfile = esmRequire(brocfilePath);
|
37 | }
|
38 |
|
39 | if (brocfile !== null && typeof brocfile === 'object' && brocfile.hasOwnProperty('default')) {
|
40 | brocfile = brocfile.default;
|
41 | }
|
42 | return brocfile;
|
43 | }
|
44 | module.exports = function loadBrocfile(options = {}) {
|
45 | let brocfilePath;
|
46 | if (options.brocfilePath) {
|
47 | brocfilePath = path_1.default.resolve(options.brocfilePath);
|
48 | }
|
49 | else {
|
50 | brocfilePath = findup_sync_1.default('Brocfile.{ts,js}', {
|
51 | nocase: true,
|
52 | });
|
53 | }
|
54 | if (!brocfilePath) {
|
55 | throw new Error('Brocfile.[js|ts] not found');
|
56 | }
|
57 | const baseDir = options.cwd || path_1.default.dirname(brocfilePath);
|
58 |
|
59 |
|
60 | process.chdir(baseDir);
|
61 | const brocfile = requireBrocfile(brocfilePath);
|
62 |
|
63 | if (typeof brocfile === 'function') {
|
64 | return brocfile;
|
65 | }
|
66 |
|
67 | return () => brocfile;
|
68 | };
|
69 |
|
\ | No newline at end of file |