1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
4 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
5 | };
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | const path_1 = __importDefault(require("path"));
|
8 | const Errors_1 = require("../Errors");
|
9 | const Serialize_1 = require("../Serialize");
|
10 | 'use strict';
|
11 |
|
12 |
|
13 |
|
14 | process.on('unhandledRejection', err => {
|
15 | throw err;
|
16 | });
|
17 | const { 3: configFileArg, 4: requestArg } = process.argv;
|
18 | let request = null;
|
19 | if (typeof requestArg === 'string') {
|
20 | try {
|
21 | request = JSON.parse(requestArg);
|
22 | }
|
23 | catch (_) { }
|
24 | }
|
25 | try {
|
26 | const configFile = path_1.default.resolve(configFileArg);
|
27 | require('@babel/register')({
|
28 | only: [configFile],
|
29 | extensions: ['.ts', '.js'],
|
30 | presets: [require.resolve('@expo/babel-preset-cli')],
|
31 | });
|
32 | let result = require(configFile);
|
33 | if (result.default != null) {
|
34 | result = result.default;
|
35 | }
|
36 | const exportedObjectType = typeof result;
|
37 | if (typeof result === 'function') {
|
38 | result = result(request);
|
39 | }
|
40 | if (result instanceof Promise) {
|
41 | throw new Errors_1.ConfigError(`Config file ${configFile} cannot return a Promise.`, 'INVALID_CONFIG');
|
42 | }
|
43 | console.log(JSON.stringify({ config: Serialize_1.serializeAndEvaluate(result), exportedObjectType }));
|
44 | process.exit(0);
|
45 | }
|
46 | catch (error) {
|
47 | console.error(JSON.stringify(Errors_1.errorToJSON(error)));
|
48 | process.exit(-1);
|
49 | }
|
50 |
|
\ | No newline at end of file |