rebuiltron 6.0.1 → 6.0.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.
@@ -13,7 +13,6 @@ const { srcAlias } = require(paths.appConfig);
13
13
 
14
14
 
15
15
  module.exports = {
16
- mode: isEnvProduction ? "production" : "development",
17
16
  stats: "errors-warnings",
18
17
  bail: isEnvProduction,
19
18
  output: {
@@ -69,9 +68,7 @@ module.exports = {
69
68
  strictExportPresence: true
70
69
  },
71
70
  plugins: [
72
- ...emptyOr(isEnvDevelopment, [
73
- new CaseSensitivePathsPlugin() // Detects case errors in import paths
74
- ]),
71
+ ...emptyOr(isEnvDevelopment, [new CaseSensitivePathsPlugin()]), // Detects case errors in import paths
75
72
  new ModuleNotFoundPlugin(paths.appPath) // Gives some necessary context to module not found errors
76
73
  ],
77
74
  performance: false // Performance processing is already handled via `FileSizeReporter`
@@ -9,6 +9,7 @@ const { main } = require(paths.appConfig);
9
9
 
10
10
  module.exports = {
11
11
  ...baseConfig,
12
+ mode: "production",
12
13
  target: "electron-main",
13
14
  entry: {
14
15
  [rebuiltronConfig.buildFileNames.main]: main
@@ -11,6 +11,7 @@ const { preloads } = require(paths.appConfig);
11
11
 
12
12
  module.exports = {
13
13
  ...baseConfig,
14
+ mode: "production",
14
15
  target: "electron-preload",
15
16
  entry: mapKeys(preloads, (_value, entryName) => (
16
17
  `${rebuiltronConfig.buildFileNames.preload}.${entryName}`
@@ -21,10 +22,8 @@ module.exports = {
21
22
  },
22
23
  module: {
23
24
  ...baseConfig.module,
24
- rules: [
25
- {
26
- oneOf: javascriptLoaders
27
- }
28
- ]
25
+ rules: [{
26
+ oneOf: javascriptLoaders
27
+ }]
29
28
  }
30
29
  };
@@ -23,6 +23,7 @@ const { renderers } = require(paths.appConfig);
23
23
 
24
24
  module.exports = {
25
25
  ...baseConfig,
26
+ mode: isEnvProduction ? "production" : "development",
26
27
  target: "browserslist",
27
28
  devtool: shouldUseSourceMap && (isEnvProduction ? "source-map" : "cheap-module-source-map"),
28
29
  entry: renderers,
@@ -0,0 +1,16 @@
1
+ const COMPILATION_ASSETS = Object.freeze({
2
+ PRELOAD: "Preload",
3
+ MAIN: "Main",
4
+ RENDERER: "Renderer"
5
+ });
6
+
7
+ const COMPILATION_STATES = Object.freeze({
8
+ PENDING: "pending",
9
+ FATAL_ERROR: "fatalError",
10
+ ERROR: "error",
11
+ WARNING: "warning",
12
+ SUCCESS: "success"
13
+ });
14
+
15
+
16
+ module.exports = { COMPILATION_ASSETS, COMPILATION_STATES };
package/helpers/utils.js CHANGED
@@ -1,14 +1,25 @@
1
+ /* eslint-disable jsdoc/valid-types, jsdoc/match-description */
2
+
1
3
  const path = require("path");
2
4
  const fs = require("fs");
3
5
 
4
6
  const { isArray } = require("lodash");
7
+ const { bold, red, green, yellow } = require("chalk");
5
8
 
6
- const log = require("./logger");
7
9
  const spinnies = require("./spinnies");
10
+ const { COMPILATION_STATES } = require("./constants");
8
11
 
9
12
 
10
- const _appDirectory = fs.realpathSync(process.cwd());
13
+ /**
14
+ * @import { Stats } from "webpack"
15
+ * @import { COMPILATION_ASSETS } from "./constants"
16
+ */
11
17
 
18
+ /**
19
+ * Path of the app directory.
20
+ */
21
+
22
+ const _appDirectory = fs.realpathSync(process.cwd());
12
23
 
13
24
  /**
14
25
  * Resolves a path relative to the app directory.
@@ -19,15 +30,15 @@ const _appDirectory = fs.realpathSync(process.cwd());
19
30
  const resolveApp = (relativePath) => path.resolve(_appDirectory, relativePath);
20
31
 
21
32
  /**
22
- * Logs error message and stack (if available) and exit the running process.
23
- * @param {(Error|import("./logger").LogMessage)} error - Error to log
33
+ * Logs error message (if provided) and exits the running process.
34
+ * @param {Error} [error] - Error to log
24
35
  */
25
36
 
26
37
  const exitProcessWithError = (error) => {
27
38
  spinnies.stopAll("fail");
28
39
 
29
- log.error(error?.message || error);
30
- if (error.stack) log.info(error.stack);
40
+ if (!error) return;
41
+ console.log(red(`\n${error?.message || error}\n`));
31
42
 
32
43
  process.exit(1);
33
44
  };
@@ -35,8 +46,8 @@ const exitProcessWithError = (error) => {
35
46
  /**
36
47
  * Returns the given value when the condition is truthy, otherwise an empty element of the same type.
37
48
  * @param {any} condition - Condition determining if the value should be returned
38
- * @param {(object|Array)} value - Value to return
39
- * @returns {(object|Array)} Value or empty element
49
+ * @param {(object | Array)} value - Value to return
50
+ * @returns {(object | Array)} Value or empty element
40
51
  */
41
52
 
42
53
  const emptyOr = (condition, value) => {
@@ -44,5 +55,70 @@ const emptyOr = (condition, value) => {
44
55
  return condition ? value : empty;
45
56
  };
46
57
 
58
+ /**
59
+ * Clears the console.
60
+ */
61
+
62
+ const clearConsole = () => {
63
+ process.stdout.write(
64
+ process.platform === "win32" ? "\x1B[2J\x1B[0f" : "\x1B[2J\x1B[3J\x1B[H"
65
+ );
66
+ };
67
+
68
+ /**
69
+ * Logs stats.
70
+ * @param {Stats} stats - Stats to log
71
+ */
72
+
73
+ const logStats = (stats) => {
74
+ console.log();
75
+
76
+ console.log(stats.toString({
77
+ colors: true,
78
+ all: false,
79
+ warnings: true,
80
+ errors: true,
81
+ errorDetails: false
82
+ }));
83
+ };
84
+
85
+ /**
86
+ * @typedef CompilationData
87
+ * @property {COMPILATION_ASSETS[keyof COMPILATION_ASSETS]} [asset] - Type of the compiled asset
88
+ * @property {COMPILATION_STATES[keyof COMPILATION_STATES]} state - Compilation state
89
+ * @property {Stats} [stats] - Compilation stats
90
+ */
91
+
92
+ /**
93
+ * Constructs the text to display for the given compilation state.
94
+ * @param {CompilationData} data - Compilation data
95
+ * @returns {string} Compilation text
96
+ */
97
+
98
+ const getCompilationText = ({ asset, state, stats }) => {
99
+ let prefix = asset ? bold(`${asset}: `) : "";
100
+
101
+ if (state === COMPILATION_STATES.PENDING) return prefix + `${asset ? "c" : "C"}ompiling...`;
102
+ if (state === COMPILATION_STATES.FATAL_ERROR) return prefix + bold(`${asset ? "f" : "F"}ailed`) + " to compile";
103
+
104
+ prefix += `${asset ? "c" : "C"}ompiled `;
105
+
106
+ if (state === COMPILATION_STATES.SUCCESS) return prefix + green(bold("successfully"));
107
+
108
+ const isError = state === COMPILATION_STATES.ERROR;
109
+
110
+ const count = stats.toJson()[isError ? "errorsCount" : "warningsCount"];
111
+ const color = isError ? red : yellow;
112
+
113
+ return prefix + "with " + bold(color(`${count} ${state}${count > 1 ? "s" : ""}`));
114
+ };
115
+
47
116
 
48
- module.exports = { resolveApp, exitProcessWithError, emptyOr };
117
+ module.exports = {
118
+ resolveApp,
119
+ exitProcessWithError,
120
+ emptyOr,
121
+ logStats,
122
+ clearConsole,
123
+ getCompilationText
124
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rebuiltron",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "author": "Arkellys",
5
5
  "license": "MIT",
6
6
  "bin": {
package/scripts/build.js CHANGED
@@ -2,6 +2,7 @@ process.env.BABEL_ENV = "production";
2
2
  process.env.NODE_ENV = "production";
3
3
 
4
4
 
5
+ const fsExtra = require("fs-extra");
5
6
  const { measureFileSizesBeforeBuild, printFileSizesAfterBuild } = require("react-dev-utils/FileSizeReporter");
6
7
 
7
8
  const buildApp = require("../tasks/buildApp");
@@ -16,8 +17,13 @@ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
16
17
  const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
17
18
 
18
19
  checkSetup
19
- .then(() => measureFileSizesBeforeBuild(paths.appBuild))
20
- .then((previousFileSizes) => buildApp(previousFileSizes))
20
+ .then(() => (
21
+ measureFileSizesBeforeBuild(paths.appBuild)
22
+ ))
23
+ .then((previousFileSizes) => {
24
+ fsExtra.emptyDirSync(paths.appBuild);
25
+ return buildApp(previousFileSizes);
26
+ })
21
27
  .then(({ stats, previousFileSizes }) => {
22
28
  console.log("\nFile sizes after gzip:\n");
23
29
 
package/scripts/start.js CHANGED
@@ -2,14 +2,12 @@ process.env.BABEL_ENV = "development";
2
2
  process.env.NODE_ENV = "development";
3
3
 
4
4
 
5
- const clearConsole = require("react-dev-utils/clearConsole");
6
-
7
5
  const checkSetup = require("../tasks/checkSetup");
8
6
  const startDevServer = require("../tasks/startDevServer");
9
7
  const compileMain = require("../tasks/compileMain");
10
8
  const watchPreloads = require("../tasks/watchPreloads");
11
9
  const startElectron = require("../tasks/startElectron");
12
- const { exitProcessWithError } = require("../helpers/utils");
10
+ const { exitProcessWithError, clearConsole } = require("../helpers/utils");
13
11
 
14
12
 
15
13
  process.on("unhandledRejection", exitProcessWithError);
package/tasks/buildApp.js CHANGED
@@ -1,13 +1,9 @@
1
- const fsExtra = require("fs-extra");
2
1
  const webpack = require("webpack");
3
- const clearConsole = require("react-dev-utils/clearConsole");
4
- const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
5
- const { bold, green, yellow } = require("chalk");
6
2
 
7
- const paths = require("../helpers/paths");
8
3
  const webpackConfig = require("../webpack.config");
9
4
  const spinnies = require("../helpers/spinnies");
10
- const log = require("../helpers/logger");
5
+ const { logStats, getCompilationText, clearConsole } = require("../helpers/utils");
6
+ const { COMPILATION_STATES } = require("../helpers/constants");
11
7
 
12
8
 
13
9
  /**
@@ -16,50 +12,50 @@ const log = require("../helpers/logger");
16
12
  * @returns {Promise<{ stats: webpack.Stats | undefined, previousFileSizes: any }>} Result of the build
17
13
  */
18
14
 
19
- module.exports = (previousFileSizes) => {
20
- fsExtra.emptyDirSync(paths.appBuild);
21
- const compiler = webpack(webpackConfig.production);
15
+ module.exports = (previousFileSizes) => new Promise((resolve, reject) => {
16
+ clearConsole();
17
+ spinnies.add("build", { text: "Creating the production build" });
22
18
 
23
- return new Promise((resolve, reject) => {
19
+ webpack(webpackConfig.production, (error, stats) => {
24
20
  clearConsole();
25
- spinnies.add("build", { text: "Creating the production build" });
26
-
27
- compiler.run((error, stats) => {
28
- if (!error) {
29
- return resolve({
30
- stats,
31
- previousFileSizes
32
- });
33
- }
34
21
 
22
+ if (error || stats.hasErrors()) {
35
23
  spinnies.fail("build", {
36
- text: "Failed to compile"
24
+ text: getCompilationText({
25
+ state: COMPILATION_STATES.FATAL_ERROR
26
+ })
37
27
  });
38
28
 
39
- reject(error);
40
- });
41
-
42
- compiler.hooks.done.tap("done", (stats) => {
43
- clearConsole();
44
-
45
- const statsData = stats.toJson({ all: false, warnings: true, errors: true });
46
- const { errors, warnings } = formatWebpackMessages(statsData);
29
+ if (stats) logStats(stats);
30
+ return reject(error);
31
+ }
32
+
33
+ if (stats.hasWarnings()) {
34
+ spinnies.update("build", {
35
+ text: getCompilationText({
36
+ state: COMPILATION_STATES.WARNING
37
+ }),
38
+ status: "stopped",
39
+ color: "white"
40
+ });
47
41
 
48
- if (stats.hasErrors()) throw new Error(errors);
42
+ logStats(stats);
49
43
 
50
- if (stats.hasWarnings()) {
51
- spinnies.update("build", {
52
- text: `Compiled ${yellow(bold("with warnings"))}`,
53
- status: "stopped",
54
- color: "white"
55
- });
44
+ return resolve({
45
+ stats,
46
+ previousFileSizes
47
+ });
48
+ }
56
49
 
57
- return log.warning(warnings.join("\n\n"));
58
- }
50
+ spinnies.succeed("build", {
51
+ text: getCompilationText({
52
+ state: COMPILATION_STATES.SUCCESS
53
+ })
54
+ });
59
55
 
60
- spinnies.succeed("build", {
61
- text: `Compiled ${green(bold("successfully"))}`
62
- });
56
+ return resolve({
57
+ stats,
58
+ previousFileSizes
63
59
  });
64
60
  });
65
- };
61
+ });
@@ -1,9 +1,9 @@
1
1
  const webpack = require("webpack");
2
- const { bold, green } = require("chalk");
3
- const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
4
2
 
5
3
  const webpackConfig = require("../webpack.config");
6
4
  const spinnies = require("../helpers/spinnies");
5
+ const { getCompilationText, logStats } = require("../helpers/utils");
6
+ const { COMPILATION_ASSETS, COMPILATION_STATES } = require("../helpers/constants");
7
7
 
8
8
 
9
9
  /**
@@ -11,31 +11,51 @@ const spinnies = require("../helpers/spinnies");
11
11
  * @returns {Promise<void>} Promise resolving when compilation is successful
12
12
  */
13
13
 
14
- module.exports = () => {
15
- const mainCompiler = webpack(webpackConfig.development.main);
14
+ module.exports = () => new Promise((resolve, reject) => {
15
+ const asset = COMPILATION_ASSETS.MAIN;
16
16
 
17
- return new Promise((resolve, reject) => {
18
- spinnies.add("compile-main", { text: "Compiling main file..." });
19
-
20
- mainCompiler.run((error) => {
21
- if (!error) return resolve();
17
+ spinnies.add("compile-main", {
18
+ text: getCompilationText({
19
+ asset,
20
+ state: COMPILATION_STATES.PENDING
21
+ })
22
+ });
22
23
 
24
+ webpack(webpackConfig.development.main, (error, stats) => {
25
+ if (error || stats.hasErrors()) {
23
26
  spinnies.fail("compile-main", {
24
- text: "Failed to compile main file"
27
+ text: getCompilationText({
28
+ asset,
29
+ state: COMPILATION_STATES.FATAL_ERROR
30
+ })
25
31
  });
26
32
 
27
- reject(error);
28
- });
29
-
30
- mainCompiler.hooks.done.tap("done", (stats) => {
31
- const statsData = stats.toJson({ all: false, warnings: true, errors: true });
32
- const { errors } = formatWebpackMessages(statsData);
33
+ if (stats) logStats(stats);
34
+ return reject(error);
35
+ }
36
+
37
+ if (stats.hasWarnings()) {
38
+ spinnies.update("compile-main", {
39
+ text: getCompilationText({
40
+ asset,
41
+ state: COMPILATION_STATES.WARNING,
42
+ stats
43
+ }),
44
+ status: "stopped",
45
+ color: "white"
46
+ });
33
47
 
34
- if (stats.hasErrors()) throw new Error(errors);
48
+ logStats(stats);
49
+ return resolve();
50
+ }
35
51
 
36
- spinnies.succeed("compile-main", {
37
- text: `Main file compiled ${green(bold("successfully"))}`
38
- });
52
+ spinnies.succeed("compile-main", {
53
+ text: getCompilationText({
54
+ asset,
55
+ state: COMPILATION_STATES.SUCCESS
56
+ })
39
57
  });
58
+
59
+ return resolve();
40
60
  });
41
- };
61
+ });
@@ -1,11 +1,12 @@
1
1
  const webpack = require("webpack");
2
2
  const WebpackDevServer = require("webpack-dev-server");
3
- const clearConsole = require("react-dev-utils/clearConsole");
4
3
  const { bold } = require("chalk");
5
4
 
6
5
  const webpackConfig = require("../webpack.config");
7
6
  const devServerConfig = require("../webpackDevServer.config");
8
7
  const spinnies = require("../helpers/spinnies");
8
+ const { getCompilationText, logStats, clearConsole } = require("../helpers/utils");
9
+ const { COMPILATION_ASSETS, COMPILATION_STATES } = require("../helpers/constants");
9
10
 
10
11
  /**
11
12
  * Starts the development server.
@@ -18,28 +19,66 @@ module.exports = (port) => (
18
19
  let devServer;
19
20
  let isFirstRun = true;
20
21
 
21
- const rendererCompiler = webpack(webpackConfig.development.renderers);
22
+ const asset = COMPILATION_ASSETS.RENDERER;
23
+ const compiler = webpack(webpackConfig.development.renderers);
22
24
 
23
25
  spinnies.add("devServer", { text: "Starting the development server" });
24
26
 
25
- rendererCompiler.hooks.invalid.tap("invalid", () => {
26
- clearConsole();
27
- spinnies.add("compile", { text: "Compiling..." });
27
+ compiler.hooks.compile.tap("compile", () => {
28
+ if (!isFirstRun) clearConsole();
29
+
30
+ spinnies.add("compile", {
31
+ text: getCompilationText({
32
+ asset,
33
+ state: COMPILATION_STATES.PENDING
34
+ })
35
+ });
28
36
  });
29
37
 
30
- rendererCompiler.hooks.done.tap("done", () => {
38
+ compiler.hooks.done.tap("done", (stats) => {
31
39
  if (isFirstRun) {
32
40
  isFirstRun = false;
33
41
 
34
42
  spinnies.succeed("devServer", { text: `Development server running on port ${bold(port)}` });
35
- return resolve(devServer);
43
+ resolve(devServer);
44
+ }
45
+
46
+ if (stats.hasErrors()) {
47
+ spinnies.fail("compile", {
48
+ text: getCompilationText({
49
+ asset,
50
+ state: COMPILATION_STATES.ERROR,
51
+ stats
52
+ }),
53
+ failColor: "white"
54
+ });
55
+
56
+ return logStats(stats);
57
+ }
58
+
59
+ if (stats.hasWarnings()) {
60
+ spinnies.update("compile", {
61
+ text: getCompilationText({
62
+ asset,
63
+ state: COMPILATION_STATES.WARNING,
64
+ stats
65
+ }),
66
+ status: "stopped",
67
+ color: "white"
68
+ });
69
+
70
+ return logStats(stats);
36
71
  }
37
72
 
38
- clearConsole();
39
- spinnies.remove("compile");
73
+ spinnies.succeed("compile", {
74
+ text: getCompilationText({
75
+ asset,
76
+ state: COMPILATION_STATES.SUCCESS
77
+ })
78
+ });
40
79
  });
41
80
 
42
- devServer = new WebpackDevServer({ ...devServerConfig, port }, rendererCompiler);
81
+ devServer = new WebpackDevServer({ ...devServerConfig, port }, compiler);
43
82
  await devServer.start();
44
83
  })
45
84
  );
@@ -2,17 +2,20 @@ const { spawn } = require("child_process");
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
4
 
5
+ const { bold } = require("chalk");
6
+
5
7
  const spinnies = require("../helpers/spinnies");
6
8
 
7
9
 
8
10
  /**
9
11
  * Starts Electron.
10
12
  * @param {number} port - Port on which the renderer is served
13
+ * @returns {Promise<void>} Promise resolving when compilation is successful
11
14
  */
12
15
 
13
16
  module.exports = (port) => (
14
17
  new Promise((resolve, reject) => {
15
- spinnies.add("electron", { text: "Starting Electron" });
18
+ spinnies.add("electron", { text: `Starting ${bold("Electron")}` });
16
19
 
17
20
  try {
18
21
  const electronPath = require.resolve("electron");
@@ -29,11 +32,11 @@ module.exports = (port) => (
29
32
  }
30
33
  }).on("close", process.exit);
31
34
 
32
- spinnies.succeed("electron", { text: "Electron started" });
35
+ spinnies.succeed("electron", { text: `${bold("Electron")} started` });
33
36
  resolve();
34
37
 
35
38
  } catch (error) {
36
- spinnies.fail("electron", { text: "Failed to start Electron" });
39
+ spinnies.fail("electron", { text: `${bold("Failed")} to start Electron` });
37
40
  reject(error);
38
41
  }
39
42
  })
@@ -1,11 +1,9 @@
1
1
  const webpack = require("webpack");
2
- const { red, bold, green, yellow } = require("chalk");
3
- const formatWebpackMessages = require("react-dev-utils/formatWebpackMessages");
4
- const clearConsole = require("react-dev-utils/clearConsole");
5
2
 
6
3
  const webpackConfig = require("../webpack.config");
7
4
  const spinnies = require("../helpers/spinnies");
8
- const log = require("../helpers/logger");
5
+ const { logStats, getCompilationText, clearConsole } = require("../helpers/utils");
6
+ const { COMPILATION_ASSETS, COMPILATION_STATES } = require("../helpers/constants");
9
7
 
10
8
 
11
9
  /**
@@ -13,61 +11,72 @@ const log = require("../helpers/logger");
13
11
  * @returns {Promise<void>} Promise resolving when compilation is successful
14
12
  */
15
13
 
16
- module.exports = () => {
17
- const preloadCompiler = webpack(webpackConfig.development.preloads);
14
+ module.exports = () => new Promise((resolve, reject) => {
15
+ let isFirstWatch = true;
18
16
 
19
- return new Promise((resolve, reject) => {
20
- let isFirstWatch = true;
17
+ const asset = COMPILATION_ASSETS.PRELOAD;
18
+ const compiler = webpack(webpackConfig.development.preloads);
21
19
 
22
- preloadCompiler.watch({}, (error) => {
23
- if (!isFirstWatch) return;
24
- isFirstWatch = false;
20
+ compiler.hooks.compile.tap("compile", () => {
21
+ if (!isFirstWatch) clearConsole();
25
22
 
26
- if (!error) return resolve();
23
+ spinnies.add("watch", {
24
+ text: getCompilationText({
25
+ asset,
26
+ state: COMPILATION_STATES.PENDING
27
+ })
28
+ });
29
+ });
27
30
 
31
+ compiler.watch({}, (error, stats) => {
32
+ if (error) {
28
33
  spinnies.fail("watch", {
29
- text: "Failed to compile preload file(s)"
34
+ text: getCompilationText({
35
+ asset,
36
+ state: COMPILATION_STATES.FATAL_ERROR
37
+ })
30
38
  });
31
39
 
32
- reject(error);
33
- });
40
+ return reject(error);
41
+ }
34
42
 
35
- preloadCompiler.hooks.compile.tap("compile", () => {
36
- if (!isFirstWatch) clearConsole();
43
+ if (isFirstWatch) {
44
+ isFirstWatch = false;
45
+ resolve();
46
+ }
37
47
 
38
- spinnies.add("watch", {
39
- text: "Compiling preload file(s)..."
48
+ if (stats.hasErrors()) {
49
+ spinnies.fail("watch", {
50
+ text: getCompilationText({
51
+ asset,
52
+ state: COMPILATION_STATES.ERROR,
53
+ stats
54
+ }),
55
+ failColor: "white"
40
56
  });
41
- });
42
57
 
43
- preloadCompiler.hooks.done.tap("done", (stats) => {
44
- const statsData = stats.toJson({ all: false, warnings: true, errors: true });
45
- const { errors, warnings } = formatWebpackMessages(statsData);
46
-
47
- if (stats.hasErrors()) {
48
- if (isFirstWatch) throw new Error(errors); // Stops the process
49
-
50
- spinnies.fail("watch", {
51
- text: `Preload file(s) compiled ${red(bold("with errors"))}`,
52
- failColor: "white"
53
- });
54
-
55
- return log.error(errors.join("\n\n"));
56
- }
57
-
58
- if (stats.hasWarnings()) {
59
- spinnies.update("watch", {
60
- text: `Preload file(s) compiled ${yellow(bold("with warnings"))}`,
61
- status: "stopped",
62
- color: "white"
63
- });
58
+ return logStats(stats);
59
+ }
60
+
61
+ if (stats.hasWarnings()) {
62
+ spinnies.update("watch", {
63
+ text: getCompilationText({
64
+ asset,
65
+ state: COMPILATION_STATES.WARNING,
66
+ stats
67
+ }),
68
+ status: "stopped",
69
+ color: "white"
70
+ });
64
71
 
65
- return log.warning(warnings.join("\n\n"));
66
- }
72
+ return logStats(stats);
73
+ }
67
74
 
68
- spinnies.succeed("watch", {
69
- text: `Preload file(s) compiled ${green(bold("successfully"))}`
70
- });
75
+ spinnies.succeed("watch", {
76
+ text: getCompilationText({
77
+ asset,
78
+ state: COMPILATION_STATES.SUCCESS
79
+ })
71
80
  });
72
81
  });
73
- };
82
+ });
@@ -15,11 +15,15 @@ module.exports = {
15
15
  }
16
16
  },
17
17
  client: {
18
+ progress: true,
18
19
  overlay: {
19
20
  errors: true,
20
21
  warnings: false
21
22
  }
22
23
  },
24
+ devMiddleware: {
25
+ stats: "none" // Already handled manually
26
+ },
23
27
  historyApiFallback: {
24
28
  disableDotRule: true, // Supports route with dots
25
29
  index: paths.basePath
package/helpers/logger.js DELETED
@@ -1,55 +0,0 @@
1
- const { red, green, yellow, black } = require("chalk");
2
- const { isString } = require("lodash");
3
-
4
-
5
- /**
6
- * @typedef {(string|string[])} LogMessage
7
- */
8
-
9
- /**
10
- * Formats a message into a single string.
11
- * @param {LogMessage} message - Message to format
12
- * @returns {string} Formatted message
13
- */
14
-
15
- const _formatMessage = (message) => {
16
- if (isString(message)) return message;
17
- return message.join("\n");
18
- };
19
-
20
-
21
- /**
22
- * Logs a message in red.
23
- * @param {LogMessage} message - Message to log
24
- */
25
-
26
- const logError = (message) => console.log(red(`\n${_formatMessage(message)}\n`));
27
-
28
- /**
29
- * Logs a message in green.
30
- * @param {LogMessage} message - Message to log
31
- */
32
-
33
- const logSuccess = (message) => console.log(green(`\n${_formatMessage(message)}\n`));
34
-
35
- /**
36
- * Logs a message in yellow.
37
- * @param {LogMessage} message - Message to log
38
- */
39
-
40
- const logWarning = (message) => console.log(yellow(`\n${_formatMessage(message)}\n`));
41
-
42
- /**
43
- * Logs a message in black.
44
- * @param {string} message - Message to log
45
- */
46
-
47
- const logInfo = (message) => console.log(black(`${message}\n`));
48
-
49
-
50
- module.exports = {
51
- error: logError,
52
- success: logSuccess,
53
- warning: logWarning,
54
- info: logInfo
55
- };