@redhat-cloud-services/frontend-components-config 4.6.0 → 4.6.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.
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.0",
3
+ "version": "4.6.3",
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.9",
23
+ "@redhat-cloud-services/frontend-components-config-utilities": "^1.5.11",
24
24
  "assert": "^2.0.0",
25
25
  "axios": "^0.25.0",
26
26
  "babel-loader": "^8.2.2",
@@ -29,7 +29,7 @@
29
29
  "clean-webpack-plugin": "^3.0.0",
30
30
  "css-loader": "^5.2.6",
31
31
  "concurrently": "^6.3.0",
32
- "chalk": "^5.0.0",
32
+ "chalk": "^4.0.0",
33
33
  "express": "^4.17.2",
34
34
  "git-revision-webpack-plugin": "^3.0.6",
35
35
  "glob": "^7.0.0",
@@ -0,0 +1,20 @@
1
+ const { logError, getWebpackConfigPath } = require('./common');
2
+ const { resolve } = require('path');
3
+
4
+ function buildScript(argv, cwd) {
5
+ try {
6
+ const processArgs = [];
7
+ let configPath;
8
+ if (typeof argv.webpackConfig !== 'undefined') {
9
+ configPath = getWebpackConfigPath(argv.webpackConfig, cwd);
10
+ } else {
11
+ configPath = resolve(__dirname, './prod.webpack.config.js');
12
+ }
13
+ processArgs.push(`node_modules/.bin/webpack -c ${configPath}`);
14
+ } catch (error) {
15
+ logError(error);
16
+ process.exit(1);
17
+ }
18
+ }
19
+
20
+ 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);