UNPKG

1.38 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.runHook = exports.setupEnvironment = void 0;
4const path_1 = require("path");
5function setupEnvironment(options) {
6 var _a, _b, _c, _d, _e, _f, _g;
7 // eslint-disable-next-line @typescript-eslint/no-var-requires
8 const packageInfo = require(path_1.resolve(process.cwd(), './package.json'));
9 const environment = options.environment;
10 return {
11 environment,
12 version: options.version,
13 serviceWorkerEnabled: (_b = (_a = options === null || options === void 0 ? void 0 : options.serviceWorker) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : options.environment === 'production',
14 ...((_d = (_c = packageInfo.site) === null || _c === void 0 ? void 0 : _c.common) !== null && _d !== void 0 ? _d : {}),
15 ...((_f = (_e = packageInfo.site) === null || _e === void 0 ? void 0 : _e[environment]) !== null && _f !== void 0 ? _f : {}),
16 ...((_g = options.additionalEnvironment) !== null && _g !== void 0 ? _g : {})
17 };
18}
19exports.setupEnvironment = setupEnvironment;
20async function runHook(input, hook) {
21 var _a;
22 if (typeof hook !== 'function') {
23 return input;
24 }
25 const output = await hook(input);
26 return (_a = output) !== null && _a !== void 0 ? _a : input;
27}
28exports.runHook = runHook;