UNPKG

1.75 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3var __importDefault = (this && this.__importDefault) || function (mod) {
4 return (mod && mod.__esModule) ? mod : { "default": mod };
5};
6Object.defineProperty(exports, "__esModule", { value: true });
7const path_1 = __importDefault(require("path"));
8const Errors_1 = require("../Errors");
9const Serialize_1 = require("../Serialize");
10'use strict';
11// Makes the script crash on unhandled rejections instead of silently
12// ignoring them. In the future, promise rejections that are not handled will
13// terminate the Node.js process with a non-zero exit code.
14process.on('unhandledRejection', err => {
15 throw err;
16});
17const { 3: configFileArg, 4: requestArg } = process.argv;
18let request = null;
19if (typeof requestArg === 'string') {
20 try {
21 request = JSON.parse(requestArg);
22 }
23 catch (_) { }
24}
25try {
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}
46catch (error) {
47 console.error(JSON.stringify(Errors_1.errorToJSON(error)));
48 process.exit(-1);
49}
50//# sourceMappingURL=read-config.js.map
\No newline at end of file