@redhat-cloud-services/frontend-components-config 4.6.2 → 4.6.5

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.
package/README.md CHANGED
@@ -374,7 +374,7 @@ index f7513bb..d8c9008 100644
374
374
  "prod": "NODE_ENV=production webpack serve --config config/dev.webpack.config.js",
375
375
  "server:ctr": "node src/server/generateServerKey.js",
376
376
  "start": "NODE_ENV=development webpack serve --config config/dev.webpack.config.js",
377
- + "start:federated": "fec static --config config/dev.webpack.config.js",
377
+ + "start:federated": "fec static",
378
378
  "start:proxy": "PROXY=true NODE_ENV=development webpack serve --config config/dev.webpack.config.js",
379
379
  "travis:build": "NODE_ENV=production webpack --config config/prod.webpack.config.js",
380
380
  "travis:verify": "npm-run-all travis:build lint test",
package/bin/fec.js CHANGED
@@ -4,7 +4,8 @@ const static = require('@redhat-cloud-services/frontend-components-config-utilit
4
4
  const yargs = require('yargs');
5
5
 
6
6
  const devScript = require('../src/scripts/dev-script');
7
- const { logError } = require('../src/scripts/common')
7
+ const buildScript = require('../src/scripts/build-script');
8
+ const { logError } = require('../src/scripts/common');
8
9
 
9
10
  function patchHosts() {
10
11
  const command = `
@@ -48,13 +49,20 @@ const argv = yargs
48
49
  describe: 'Path to webpack config',
49
50
  })
50
51
  })
52
+ .command('build', 'Build production bundle', (yargs) => {
53
+ yargs.positional('webpack-config', {
54
+ type: 'string',
55
+ describe: 'Path to webpack config',
56
+ })
57
+ })
51
58
  .help()
52
59
  .argv;
53
60
 
54
61
  const scripts = {
55
62
  static,
56
63
  'patch-etc-hosts': patchHosts,
57
- dev: devScript
64
+ dev: devScript,
65
+ build: buildScript
58
66
  };
59
67
 
60
68
  const args = [ argv, cwd ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config",
3
- "version": "4.6.2",
3
+ "version": "4.6.5",
4
4
  "description": "Config plugins and settings for RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/RedHatInsights/frontend-components/tree/master/packages/config#readme",
22
22
  "dependencies": {
23
- "@redhat-cloud-services/frontend-components-config-utilities": "^1.5.11",
23
+ "@redhat-cloud-services/frontend-components-config-utilities": "^1.5.16",
24
24
  "assert": "^2.0.0",
25
25
  "axios": "^0.25.0",
26
26
  "babel-loader": "^8.2.2",
@@ -0,0 +1,27 @@
1
+ const { logError, getWebpackConfigPath } = require('./common');
2
+ const { resolve } = require('path');
3
+ const { spawn } = require('child_process');
4
+
5
+ function buildScript(argv, cwd) {
6
+ try {
7
+ const processArgs = [];
8
+ let configPath;
9
+ if (typeof argv.webpackConfig !== 'undefined') {
10
+ configPath = getWebpackConfigPath(argv.webpackConfig, cwd);
11
+ } else {
12
+ configPath = resolve(__dirname, './prod.webpack.config.js');
13
+ }
14
+ processArgs.push(`node_modules/.bin/webpack -c ${configPath}`);
15
+ process.env.NODE_ENV = 'production';
16
+ spawn('node', processArgs, {
17
+ stdio: [process.stdout, process.stdout, process.stdout],
18
+ cwd,
19
+ shell: true,
20
+ });
21
+ } catch (error) {
22
+ logError(error);
23
+ process.exit(1);
24
+ }
25
+ }
26
+
27
+ module.exports = buildScript;
@@ -1,7 +1,48 @@
1
1
  const chalk = require('chalk');
2
+ const { resolve } = require('path');
3
+ const { statSync } = require('fs');
2
4
 
3
5
  function logError(message) {
4
6
  console.log(chalk.blue('[fec]') + chalk.red(' ERROR: ') + message);
5
7
  }
6
8
 
9
+ function validateFECConfig(cwd) {
10
+ const configPath = resolve(cwd, './fec.config.js');
11
+ try {
12
+ statSync(configPath);
13
+ } catch (error) {
14
+ logError(`Unable to locate "fec.config.js" at ${configPath}`);
15
+ throw 'fec.config.js validation failed, file does not exist';
16
+ }
17
+
18
+ const config = require(configPath);
19
+ if (!config.appUrl) {
20
+ logError('Missing config "appUrl" in fec.config.js');
21
+ throw 'fec.config.js validation failed, missing "appUrl" config';
22
+ }
23
+ process.env.FEC_CONFIG_PATH = configPath;
24
+ }
25
+
26
+ function getWebpackConfigPath(path, cwd) {
27
+ let configPath;
28
+ try {
29
+ configPath = resolve(cwd, path);
30
+ statSync(configPath);
31
+ let config = require(configPath);
32
+ if (typeof config === 'function') {
33
+ config = config(process.env);
34
+ }
35
+ return configPath;
36
+ } catch (error) {
37
+ if (configPath) {
38
+ logError(`Unable to open webpack config at: "${configPath}"`);
39
+ } else {
40
+ logError(error);
41
+ throw 'FEC binary failed';
42
+ }
43
+ }
44
+ }
45
+
7
46
  module.exports.logError = logError;
47
+ module.exports.validateFECConfig = validateFECConfig;
48
+ module.exports.getWebpackConfigPath = getWebpackConfigPath;
@@ -1,9 +1,8 @@
1
1
  /* eslint-disable no-console */
2
2
  const inquirer = require('inquirer');
3
3
  const { resolve } = require('path');
4
- const { statSync } = require('fs');
5
4
  const { spawn } = require('child_process');
6
- const { logError } = require('./common');
5
+ const { validateFECConfig, getWebpackConfigPath } = require('./common');
7
6
 
8
7
  async function setEnv(cwd) {
9
8
  return inquirer
@@ -29,43 +28,6 @@ async function setEnv(cwd) {
29
28
  });
30
29
  }
31
30
 
32
- function getWebpackConfigPath(path, cwd) {
33
- let configPath;
34
- try {
35
- configPath = resolve(cwd, path);
36
- statSync(configPath);
37
- let config = require(configPath);
38
- if (typeof config === 'function') {
39
- config = config(process.env);
40
- }
41
- return configPath;
42
- } catch (error) {
43
- if (configPath) {
44
- logError(`Unable to open webpack config at: "${configPath}"`);
45
- } else {
46
- logError(error);
47
- throw 'FEC binary failed';
48
- }
49
- }
50
- }
51
-
52
- function validateFECConfig(cwd) {
53
- const configPath = resolve(cwd, './fec.config.js');
54
- try {
55
- statSync(configPath);
56
- } catch (error) {
57
- logError(`Unable to locate "fec.config.js" at ${configPath}`);
58
- throw 'fec.config.js validation failed, file does not exist';
59
- }
60
-
61
- const config = require(configPath);
62
- if (!config.appUrl) {
63
- logError('Missing config "appUrl" in fec.config.js');
64
- throw 'fec.config.js validation failed, missing "appUrl" config';
65
- }
66
- process.env.FEC_CONFIG_PATH = configPath;
67
- }
68
-
69
31
  async function devScript(argv, cwd) {
70
32
  try {
71
33
  validateFECConfig(cwd);