@redhat-cloud-services/frontend-components-config 6.0.0-beta.1 → 6.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/bin/build-script.d.ts +4 -0
  2. package/bin/build-script.js +42 -0
  3. package/bin/build-script.js.map +1 -1
  4. package/bin/common.d.ts +2 -0
  5. package/bin/common.js +48 -0
  6. package/bin/common.js.map +1 -1
  7. package/bin/csc-interceptor-server.d.ts +1 -0
  8. package/bin/csc-interceptor-server.js +121 -0
  9. package/bin/dev-script.d.ts +2 -0
  10. package/bin/dev-script.js +128 -0
  11. package/bin/dev.webpack.config.d.ts +2 -0
  12. package/bin/dev.webpack.config.js +78 -0
  13. package/bin/empty.d.ts +1 -0
  14. package/bin/empty.js +3 -0
  15. package/bin/fec.d.ts +2 -0
  16. package/bin/fec.js +82 -59
  17. package/bin/fec.js.map +1 -1
  18. package/bin/prod.webpack.config.d.ts +2 -0
  19. package/bin/prod.webpack.config.js +46 -0
  20. package/bin/webpack.plugins.d.ts +2 -0
  21. package/bin/webpack.plugins.js +25 -0
  22. package/lib/createConfig.d.ts +47 -0
  23. package/lib/createConfig.js +172 -0
  24. package/lib/createConfig.js.map +1 -1
  25. package/lib/createPlugins.d.ts +13 -0
  26. package/lib/createPlugins.js +69 -0
  27. package/lib/createPlugins.js.map +1 -1
  28. package/lib/index.d.ts +18 -0
  29. package/lib/index.js +98 -0
  30. package/package.json +9 -3
  31. package/extensions-plugin.js +0 -3
  32. package/federated-modules.js +0 -3
  33. package/index.js +0 -86
  34. package/src/chrome-render-loader.js +0 -3
  35. package/src/config.js +0 -246
  36. package/src/config.test.js +0 -123
  37. package/src/cookieTransform.js +0 -4
  38. package/src/plugins.js +0 -45
  39. package/src/plugins.test.js +0 -42
  40. package/src/proxy.js +0 -4
  41. package/src/scripts/build-script.js +0 -34
  42. package/src/scripts/common.js +0 -48
  43. package/src/scripts/csc-interceptor-server.js +0 -67
  44. package/src/scripts/dev-script.js +0 -84
  45. package/src/scripts/dev.webpack.config.js +0 -65
  46. package/src/scripts/empty.js +0 -2
  47. package/src/scripts/prod.webpack.config.js +0 -25
  48. package/src/scripts/webpack.plugins.js +0 -23
  49. package/src/serveLocalFile.js +0 -4
@@ -0,0 +1,4 @@
1
+ export declare function buildScript(argv: {
2
+ [name: string]: string;
3
+ }, cwd: string): void;
4
+ export default buildScript;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildScript = void 0;
4
+ var frontend_components_config_utilities_1 = require("@redhat-cloud-services/frontend-components-config-utilities");
5
+ var _a = require('./common'), getWebpackConfigPath = _a.getWebpackConfigPath, validateFECConfig = _a.validateFECConfig;
6
+ var resolve = require('path').resolve;
7
+ var spawn = require('child_process').spawn;
8
+ function buildScript(argv, cwd) {
9
+ validateFECConfig(cwd);
10
+ var configPath;
11
+ if (typeof argv.webpackConfig !== 'undefined') {
12
+ configPath = getWebpackConfigPath(argv.webpackConfig, cwd);
13
+ }
14
+ else {
15
+ configPath = resolve(__dirname, './prod.webpack.config.js');
16
+ }
17
+ process.env.NODE_ENV = 'production';
18
+ var subprocess = spawn("npm exec -- webpack -c ".concat(configPath), [], {
19
+ stdio: [process.stdout, process.stdout, process.stdout],
20
+ cwd: cwd,
21
+ shell: true,
22
+ });
23
+ subprocess.on('error', function (err) {
24
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, err);
25
+ process.exit(1);
26
+ });
27
+ subprocess.on('exit', function (code, signal) {
28
+ if (code) {
29
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, 'Exited with code', code);
30
+ }
31
+ else if (signal) {
32
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, 'Exited with signal', signal);
33
+ }
34
+ else {
35
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.info, 'Exited Okay');
36
+ }
37
+ });
38
+ }
39
+ exports.buildScript = buildScript;
40
+ exports.default = buildScript;
41
+ module.exports = buildScript;
42
+ //# sourceMappingURL=build-script.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-script.js","sourceRoot":"","sources":["../src/bin/build-script.js"],"names":[],"mappings":";AAAM,IAAA,KAAwD,OAAO,CAAC,UAAU,CAAC,EAAzE,QAAQ,cAAA,EAAE,oBAAoB,0BAAA,EAAE,iBAAiB,uBAAwB,CAAC;AAC1E,IAAA,OAAO,GAAK,OAAO,CAAC,MAAM,CAAC,QAApB,CAAqB;AAC5B,IAAA,KAAK,GAAK,OAAO,CAAC,eAAe,CAAC,MAA7B,CAA8B;AAE3C,SAAS,WAAW,CAAC,IAAI,EAAE,GAAG;IAC5B,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACvB,IAAI,UAAU,CAAC;IACf,IAAI,OAAO,IAAI,CAAC,aAAa,KAAK,WAAW,EAAE;QAC7C,UAAU,GAAG,oBAAoB,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;KAC5D;SAAM;QACL,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,0BAA0B,CAAC,CAAC;KAC7D;IACD,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC;IACpC,IAAM,UAAU,GAAG,KAAK,CAAC,iCAA0B,UAAU,CAAE,EAAE,EAAE,EAAE;QACnE,KAAK,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;QACvD,GAAG,KAAA;QACH,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;QAClC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,UAAU,CAAC,EAAE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AI;KACZ,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAQ;QACvC,IAAA,gDAAS,EAAC,8CAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,IAAmB,EAAE,MAAc;QACxD,IAAI,IAAI,EAAE;YACR,IAAA,gDAAS,EAAC,8CAAO,CAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;SACpD;aAAM,IAAI,MAAM,EAAE;YACjB,IAAA,gDAAS,EAAC,8CAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE,MAAM,CAAC,CAAC;SACxD;aAAM;YACL,IAAA,gDAAS,EAAC,8CAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;SACxC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AA3BD,kCA2BC;AAED,kBAAe,WAAW,CAAC;AAC3B,MAAM,CAAC,OAAO,GAAG,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function validateFECConfig(cwd: string): void;
2
+ export declare function getWebpackConfigPath(path: string, cwd: string): any;
package/bin/common.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebpackConfigPath = exports.validateFECConfig = void 0;
4
+ var frontend_components_config_utilities_1 = require("@redhat-cloud-services/frontend-components-config-utilities");
5
+ var resolve = require('path').resolve;
6
+ var statSync = require('fs').statSync;
7
+ function validateFECConfig(cwd) {
8
+ var configPath = resolve(cwd, './fec.config.js');
9
+ try {
10
+ statSync(configPath);
11
+ }
12
+ catch (error) {
13
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, "Unable to locate \"fec.config.js\" at ".concat(configPath));
14
+ throw 'fec.config.js validation failed, file does not exist';
15
+ }
16
+ var config = require(configPath);
17
+ if (!config.appUrl) {
18
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, 'Missing config "appUrl" in fec.config.js');
19
+ throw 'fec.config.js validation failed, missing "appUrl" config';
20
+ }
21
+ process.env.FEC_CONFIG_PATH = configPath;
22
+ }
23
+ exports.validateFECConfig = validateFECConfig;
24
+ function getWebpackConfigPath(path, cwd) {
25
+ var configPath;
26
+ try {
27
+ configPath = resolve(cwd, path);
28
+ statSync(configPath);
29
+ var config = require(configPath);
30
+ if (typeof config === 'function') {
31
+ config = config(process.env);
32
+ }
33
+ return configPath;
34
+ }
35
+ catch (error) {
36
+ if (configPath) {
37
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, "Unable to open webpack config at: \"".concat(configPath, "\""));
38
+ }
39
+ else {
40
+ (0, frontend_components_config_utilities_1.fecLogger)(frontend_components_config_utilities_1.LogType.error, error);
41
+ throw 'FEC binary failed';
42
+ }
43
+ }
44
+ }
45
+ exports.getWebpackConfigPath = getWebpackConfigPath;
46
+ module.exports.validateFECConfig = validateFECConfig;
47
+ module.exports.getWebpackConfigPath = getWebpackConfigPath;
48
+ //# sourceMappingURL=common.js.map
package/bin/common.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/bin/common.js"],"names":[],"mappings":";AAAA,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACvB,IAAA,OAAO,GAAK,OAAO,CAAC,MAAM,CAAC,QAApB,CAAqB;AAC5B,IAAA,QAAQ,GAAK,OAAO,CAAC,IAAI,CAAC,SAAlB,CAAmB;AAEnC,SAAS,QAAQ,CAAC,OAAO;IACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,CAAC;AACrE,CAAC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C,8CAAO,CAAC,KAAK,EAAE,8CAAsC,UAAU,OAAG,CAAC,CAAC;SAC/E;aAAM;YACL,IAAA,gDAAS,EAAC,8CAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAChC,MAAM,mBAAmB,CAAC;SAC3B;KACF;AACH,CAAC;AAlBD,oDAkBC;AAED,MAAM,CAAC,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;AACrD,MAAM,CAAC,OAAO,CAAC,oBAAoB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var path = require('path');
48
+ var express = require('express');
49
+ var axios = require('axios');
50
+ var jsVarName = require('@redhat-cloud-services/frontend-components-config-utilities/jsVarName');
51
+ var fs = require('fs');
52
+ var jsyaml = require('js-yaml');
53
+ var cwd = process.cwd();
54
+ var pgk = require(path.resolve(cwd, './package.json'));
55
+ var appname = jsVarName(pgk.insights.appname);
56
+ var moduleName = jsVarName(appname);
57
+ var frontendDeployConfig = jsyaml.load(fs.readFileSync(path.resolve(cwd, './deploy/frontend.yaml')));
58
+ var frontendSpec = frontendDeployConfig.objects[0];
59
+ var navItems = frontendSpec.spec.navItems;
60
+ var fecModules = frontendSpec.spec.module;
61
+ var bundles = Array.from(new Set(fecModules.modules
62
+ .map(function (_a) {
63
+ var routes = _a.routes;
64
+ return routes;
65
+ })
66
+ .flat()
67
+ .map(function (_a) {
68
+ var pathname = _a.pathname;
69
+ return pathname.split('/')[1];
70
+ })));
71
+ var app = express();
72
+ var port = 9999;
73
+ var BASE_URL = 'https://raw.githubusercontent.com/RedHatInsights/chrome-service-backend/main';
74
+ function getRequestBundle(requestUrl) {
75
+ var bundle = requestUrl.split('/').pop().split('-').shift();
76
+ return bundle === 'rhel' ? 'insights' : bundle;
77
+ }
78
+ app.get('*', function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
79
+ var reqUrl, schema, requestBundle_1, payload, payload, error_1;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ _a.trys.push([0, 2, , 3]);
84
+ reqUrl = BASE_URL + req.url.replace('/api/chrome-service/v1', '');
85
+ return [4, axios.get(reqUrl)];
86
+ case 1:
87
+ schema = _a.sent();
88
+ if (req.url.includes('-navigation.json') && bundles.some(function (bundle) { return req.url.includes(bundle); })) {
89
+ requestBundle_1 = getRequestBundle(req.url);
90
+ payload = schema.data;
91
+ payload.navItems = __spreadArray(__spreadArray([], payload.navItems, true), navItems.filter(function (_a) {
92
+ var href = _a.href;
93
+ return href.includes(requestBundle_1);
94
+ }), true);
95
+ res.json(payload);
96
+ res.end();
97
+ return [2];
98
+ }
99
+ else if (req.url.includes('fed-modules.json')) {
100
+ payload = schema.data;
101
+ payload[moduleName] = fecModules;
102
+ res.json(payload);
103
+ res.end();
104
+ return [2];
105
+ }
106
+ res.json(schema.data);
107
+ res.end();
108
+ return [3, 3];
109
+ case 2:
110
+ error_1 = _a.sent();
111
+ console.log(error_1);
112
+ next(error_1);
113
+ return [3, 3];
114
+ case 3: return [2];
115
+ }
116
+ });
117
+ }); });
118
+ app.listen(port, function () {
119
+ console.log('csc-intercept-server is running on port ' + port);
120
+ });
121
+ //# sourceMappingURL=csc-interceptor-server.js.map
@@ -0,0 +1,2 @@
1
+ export = devScript;
2
+ declare function devScript(argv: any, cwd: any): Promise<void>;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var inquirer = require('inquirer');
39
+ var resolve = require('path').resolve;
40
+ var spawn = require('child_process').spawn;
41
+ var _a = require('./common'), validateFECConfig = _a.validateFECConfig, getWebpackConfigPath = _a.getWebpackConfigPath;
42
+ function setEnv(cwd) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ return __generator(this, function (_a) {
45
+ return [2, inquirer
46
+ .prompt([
47
+ {
48
+ type: 'list',
49
+ name: 'clouddotEnv',
50
+ message: 'Which platform environment you want to use?',
51
+ choices: ['stage', 'prod', { value: 'qa', name: 'qa (deprecated)' }, { value: 'ci', name: 'ci (deprecated)' }],
52
+ },
53
+ {
54
+ type: 'list',
55
+ name: 'uiEnv',
56
+ message: 'Which Chrome environment you want to use?',
57
+ choices: ['beta', 'stable'],
58
+ },
59
+ ])
60
+ .then(function (answers) {
61
+ var uiEnv = answers.uiEnv, clouddotEnv = answers.clouddotEnv;
62
+ process.env.BETA = uiEnv === 'beta' ? 'true' : 'false';
63
+ process.env.CLOUDOT_ENV = clouddotEnv ? clouddotEnv : 'stage';
64
+ process.env.FEC_ROOT_DIR = cwd;
65
+ })];
66
+ });
67
+ });
68
+ }
69
+ function devScript(argv, cwd) {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var fecConfig, configPath, clouddotEnvOptions, uiEnvOptions, interceptorServerPath, interceptorServerArgs, error_1;
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0:
75
+ _a.trys.push([0, 4, , 5]);
76
+ validateFECConfig(cwd);
77
+ fecConfig = require(process.env.FEC_CONFIG_PATH);
78
+ configPath = void 0;
79
+ if (typeof argv.webpackConfig !== 'undefined') {
80
+ configPath = getWebpackConfigPath(argv.webpackConfig, cwd);
81
+ }
82
+ else {
83
+ configPath = resolve(__dirname, './dev.webpack.config.js');
84
+ }
85
+ clouddotEnvOptions = ['stage', 'prod', 'qa', 'ci'];
86
+ uiEnvOptions = ['beta', 'stable'];
87
+ if (!((argv === null || argv === void 0 ? void 0 : argv.clouddotEnv) && (argv === null || argv === void 0 ? void 0 : argv.uiEnv))) return [3, 1];
88
+ if (clouddotEnvOptions.includes(argv.clouddotEnv) && uiEnvOptions.includes(argv.uiEnv)) {
89
+ process.env.BETA = argv.uiEnv === 'beta' ? 'true' : 'false';
90
+ process.env.CLOUDOT_ENV = argv.clouddotEnv;
91
+ process.env.FEC_ROOT_DIR = cwd;
92
+ }
93
+ else {
94
+ console.error('Incorrect argument value:\n--clouddotEnv must be one of: [', clouddotEnvOptions.toString(), ']\n--uiEnv must be one of: [', uiEnvOptions.toString(), ']\nRun fec --help for more information.');
95
+ process.exit(1);
96
+ }
97
+ return [3, 3];
98
+ case 1: return [4, setEnv(cwd)];
99
+ case 2:
100
+ _a.sent();
101
+ _a.label = 3;
102
+ case 3:
103
+ spawn("npm exec -- webpack serve -c ".concat(configPath), [], {
104
+ stdio: [process.stdout, process.stdout, process.stdout],
105
+ cwd: cwd,
106
+ shell: true,
107
+ });
108
+ if (fecConfig.interceptChromeConfig === true) {
109
+ interceptorServerPath = resolve(__dirname, './csc-interceptor-server.js');
110
+ interceptorServerArgs = [interceptorServerPath];
111
+ spawn('NODE_OPTIONS=--dns-result-order=ipv4first node', interceptorServerArgs, {
112
+ stdio: [process.stdout, process.stdout, process.stdout],
113
+ cwd: cwd,
114
+ shell: true,
115
+ });
116
+ }
117
+ return [3, 5];
118
+ case 4:
119
+ error_1 = _a.sent();
120
+ process.exit(1);
121
+ return [3, 5];
122
+ case 5: return [2];
123
+ }
124
+ });
125
+ });
126
+ }
127
+ module.exports = devScript;
128
+ //# sourceMappingURL=dev-script.js.map
@@ -0,0 +1,2 @@
1
+ declare const _exports: any;
2
+ export = _exports;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
26
+ if (ar || !(i in from)) {
27
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
28
+ ar[i] = from[i];
29
+ }
30
+ }
31
+ return to.concat(ar || Array.prototype.slice.call(from));
32
+ };
33
+ var config = require('../lib/index.js');
34
+ var commonPlugins = require('../lib/webpack.plugins.js');
35
+ var fecConfig = require(process.env.FEC_CONFIG_PATH);
36
+ var isBeta = process.env.BETA === 'true';
37
+ function parseRegexpURL(url) {
38
+ return isBeta ? [new RegExp("/beta".concat(url.toString())), new RegExp("/preview".concat(url.toString()))] : new RegExp(url.toString());
39
+ }
40
+ function createAppUrl(appUrl) {
41
+ if (Array.isArray(appUrl)) {
42
+ return appUrl
43
+ .map(function (url) {
44
+ if (typeof url === 'object') {
45
+ return parseRegexpURL(url);
46
+ }
47
+ else if (typeof url === 'string') {
48
+ return isBeta ? ["/beta".concat(url), "/preview".concat(url)] : url;
49
+ }
50
+ else {
51
+ throw "Invalid appURL format! Expected string or regexp, got ".concat(typeof url, ". Check your fec.config.js:appUrl.");
52
+ }
53
+ })
54
+ .flat();
55
+ }
56
+ else if (typeof appUrl === 'object') {
57
+ return parseRegexpURL(appUrl);
58
+ }
59
+ else if (typeof appUrl === 'string') {
60
+ return "".concat(isBeta ? '/beta' : '').concat(appUrl);
61
+ }
62
+ else {
63
+ throw "Invalid appURL format! Expected string or regexp, got ".concat(typeof appUrl, ". Check your fec.config.js:appUrl.");
64
+ }
65
+ }
66
+ var appUrl = createAppUrl(fecConfig.appUrl);
67
+ var externalPlugins = fecConfig.plugins, interceptChromeConfig = fecConfig.interceptChromeConfig, routes = fecConfig.routes, externalConfig = __rest(fecConfig, ["plugins", "interceptChromeConfig", "routes"]);
68
+ var internalProxyRoutes = __assign(__assign({}, routes), (interceptChromeConfig === true
69
+ ? {
70
+ '/api/chrome-service/v1/static': {
71
+ host: 'http://localhost:9999',
72
+ },
73
+ }
74
+ : {}));
75
+ var _a = config(__assign(__assign({ useFileHash: false, useCache: true }, externalConfig), { routes: internalProxyRoutes, appUrl: appUrl, deployment: isBeta ? 'beta/apps' : 'apps', env: "".concat(process.env.CLOUDOT_ENV, "-").concat(isBeta === true ? 'beta' : 'stable'), rootFolder: process.env.FEC_ROOT_DIR || process.cwd() })), webpackConfig = _a.config, plugins = _a.plugins;
76
+ plugins.push.apply(plugins, __spreadArray(__spreadArray([], commonPlugins, false), externalPlugins, false));
77
+ module.exports = __assign(__assign({}, webpackConfig), { plugins: plugins });
78
+ //# sourceMappingURL=dev.webpack.config.js.map
package/bin/empty.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/bin/empty.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ module.exports = {};
3
+ //# sourceMappingURL=empty.js.map
package/bin/fec.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/fec.js CHANGED
@@ -1,96 +1,119 @@
1
1
  #!/usr/bin/env node
2
- const { execSync } = require('child_process');
3
- const static = require('@redhat-cloud-services/frontend-components-config-utilities/serve-federated');
4
- const yargs = require('yargs');
5
-
6
- const devScript = require('../src/scripts/dev-script');
7
- const buildScript = require('../src/scripts/build-script');
8
- const { logError, validateFECConfig } = require('../src/scripts/common');
9
-
2
+ "use strict";
3
+ var execSync = require('child_process').execSync;
4
+ var serveStatic = require('@redhat-cloud-services/frontend-components-config-utilities/serve-federated');
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var yargs = require('yargs');
8
+ var devScript = require('../src/scripts/dev-script');
9
+ var buildScript = require('../src/scripts/build-script');
10
+ var validateFECConfig = require('../src/scripts/common').validateFECConfig;
11
+ var _a = require('@redhat-cloud-services/frontend-components-config-utilities'), fecLogger = _a.fecLogger, LogType = _a.LogType;
10
12
  function patchHosts() {
11
- const command = `
12
- for host in prod.foo.redhat.com stage.foo.redhat.com qa.foo.redhat.com ci.foo.redhat.com
13
- do
14
- grep -q $host /etc/hosts 2>/dev/null
15
- if [ $? -ne 0 ]
16
- then
17
- echo "Adding $host to /etc/hosts"
18
- echo "127.0.0.1 $host" >>/etc/hosts
19
- echo "::1 $host" >>/etc/hosts
20
- fi
21
- done
22
- `
13
+ var command = "\n for host in prod.foo.redhat.com stage.foo.redhat.com qa.foo.redhat.com ci.foo.redhat.com\ndo\n grep -q $host /etc/hosts 2>/dev/null\n if [ $? -ne 0 ]\n then\n echo \"Adding $host to /etc/hosts\"\n echo \"127.0.0.1 $host\" >>/etc/hosts\n echo \"::1 $host\" >>/etc/hosts\n fi\ndone\n";
23
14
  try {
24
- execSync(command)
25
- } catch (error) {
26
- logError('Unable to patch /etc/hosts! Please to run the script as sudo.')
15
+ execSync(command);
27
16
  }
17
+ catch (error) {
18
+ fecLogger(LogType.error, 'Unable to patch /etc/hosts! Please to run the script as sudo.');
19
+ }
20
+ }
21
+ var cwd = process.cwd();
22
+ function checkDependencies() {
23
+ var requiredDependencies = ['typescript', 'ts-patch', '@redhat-cloud-services/tsc-transform-imports'];
24
+ var missingDependencies = [];
25
+ var dependencies = JSON.parse(fs.readFileSync(path.resolve(cwd, 'package.json'))).dependencies;
26
+ requiredDependencies.forEach(function (dep) {
27
+ if (dependencies[dep]) {
28
+ missingDependencies.push(dep);
29
+ }
30
+ });
31
+ return missingDependencies;
28
32
  }
29
-
30
- const cwd = process.cwd();
31
-
32
- const argv = yargs
33
- .usage('Usage: $0 <command> [options]')
34
- .command('static', 'Serve webpack output without the webpack server', (yargs) => {
35
- yargs.positional('config', {
33
+ function patchTs(dependencies) {
34
+ fecLogger(LogType.info, 'postinstall');
35
+ var usesYarn = fs.existsSync(path.resolve(cwd, 'yarn.lock'));
36
+ if (dependencies.length > 0) {
37
+ var command = void 0;
38
+ if (usesYarn) {
39
+ command = "yarn add -D ".concat(dependencies);
40
+ }
41
+ else {
42
+ command = "npm i --save-dev ".concat(dependencies);
43
+ }
44
+ fecLogger(LogType.info, 'Installing missing build dependencies: ', command);
45
+ execSync(command, { stdio: 'inherit', cwd: cwd });
46
+ }
47
+ fecLogger(LogType.info, 'Patching TS');
48
+ execSync('npx ts-patch install', { stdio: 'inherit', cwd: cwd });
49
+ if (!fs.existsSync(path.resolve(cwd, 'tsconfig.json'))) {
50
+ fecLogger(LogType.info, 'Creating base tsconfig.json');
51
+ fs.copyFileSync(path.resolve(__dirname, './tsconfig.template.json'), path.resolve(cwd, 'tsconfig.json'));
52
+ }
53
+ }
54
+ var argv = yargs
55
+ .usage('Usage: $0 <command> [options]')
56
+ .command('static', 'Serve webpack output without the webpack server', function (yargs) {
57
+ yargs
58
+ .positional('config', {
36
59
  type: 'string',
37
60
  alias: 'c',
38
- describe: 'Path to webpack config'
39
- }).positional('port', {
61
+ describe: 'Path to webpack config',
62
+ })
63
+ .positional('port', {
40
64
  type: 'number',
41
65
  alias: 'p',
42
66
  describe: 'Asset server port',
43
- default: 8003
67
+ default: 8003,
44
68
  });
45
69
  })
46
- .command('patch-etc-hosts', 'You may have to run this as \'sudo\'. Setup your etc/hosts allow development hosts in your browser')
47
- .command('dev', 'Start development server', (yargs) => {
70
+ .command('patch-etc-hosts', "You may have to run this as 'sudo'. Setup your etc/hosts allow development hosts in your browser")
71
+ .command('dev', 'Start development server', function (yargs) {
48
72
  yargs.positional('webpack-config', {
49
73
  type: 'string',
50
74
  describe: 'Path to webpack config',
51
- })
75
+ });
52
76
  })
53
- .command('build', 'Build production bundle', (yargs) => {
77
+ .command('build', 'Build production bundle', function (yargs) {
54
78
  yargs.positional('webpack-config', {
55
79
  type: 'string',
56
80
  describe: 'Path to webpack config',
57
- })
81
+ });
58
82
  })
59
- .option('clouddotEnv', {
83
+ .option('clouddotEnv', {
60
84
  describe: "Set platform environment ['stage', 'prod', 'qa', 'ci']",
61
85
  type: 'string',
62
86
  })
63
- .option('uiEnv', {
87
+ .option('uiEnv', {
64
88
  describe: "Set Chrome environment ['beta', 'stable']",
65
89
  type: 'string',
66
90
  })
67
- .example('$0 dev --clouddotEnv=stage --uiEnv=stable', 'Example of usage in non-interactive environments')
68
- .help()
69
- .argv;
70
-
71
- const scripts = {
72
- static: (argv, cwd) => {
73
- // set fec config
74
- validateFECConfig(cwd)
75
- static(argv, cwd)
91
+ .example('$0 dev --clouddotEnv=stage --uiEnv=stable', 'Example of usage in non-interactive environments')
92
+ .help().argv;
93
+ var scripts = {
94
+ static: function (argv, cwd) {
95
+ validateFECConfig(cwd);
96
+ serveStatic(argv, cwd);
76
97
  },
77
98
  'patch-etc-hosts': patchHosts,
78
- dev: (argv, cwd) => {
79
- validateFECConfig(cwd)
80
- devScript(argv, cwd)
99
+ dev: function (argv, cwd) {
100
+ validateFECConfig(cwd);
101
+ devScript(argv, cwd);
81
102
  },
82
- build: buildScript
103
+ build: buildScript,
104
+ 'patch-ts': function () { return patchTs(checkDependencies().join(' ')); },
83
105
  };
84
-
85
- const args = [ argv, cwd ];
86
-
106
+ var args = [argv, cwd];
87
107
  function run() {
108
+ var missingDependencies = checkDependencies();
109
+ if (missingDependencies.length > 0) {
110
+ patchTs(missingDependencies.join(' '));
111
+ }
88
112
  if (!argv._.length || argv._.length === 0) {
89
113
  console.error('Script name must be specified. Run fec --help for more information.');
90
114
  process.exit(1);
91
115
  }
92
-
93
- scripts[argv._[0]](...args);
116
+ scripts[argv._[0]].apply(scripts, args);
94
117
  }
95
-
96
118
  run();
119
+ //# sourceMappingURL=fec.js.map