rebuiltron 6.0.2 → 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.
- package/helpers/constants.js +16 -0
- package/helpers/utils.js +85 -9
- package/package.json +1 -1
- package/scripts/build.js +8 -2
- package/scripts/start.js +1 -3
- package/tasks/buildApp.js +37 -41
- package/tasks/compileMain.js +41 -21
- package/tasks/startDevServer.js +49 -10
- package/tasks/startElectron.js +5 -3
- package/tasks/watchPreloads.js +56 -47
- package/webpackDevServer.config.js +4 -0
- package/helpers/logger.js +0 -55
|
@@ -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
|
-
|
|
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
|
|
23
|
-
* @param {
|
|
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
|
-
|
|
30
|
-
|
|
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 = {
|
|
117
|
+
module.exports = {
|
|
118
|
+
resolveApp,
|
|
119
|
+
exitProcessWithError,
|
|
120
|
+
emptyOr,
|
|
121
|
+
logStats,
|
|
122
|
+
clearConsole,
|
|
123
|
+
getCompilationText
|
|
124
|
+
};
|
package/package.json
CHANGED
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(() =>
|
|
20
|
-
|
|
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
|
|
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
|
-
|
|
21
|
-
|
|
15
|
+
module.exports = (previousFileSizes) => new Promise((resolve, reject) => {
|
|
16
|
+
clearConsole();
|
|
17
|
+
spinnies.add("build", { text: "Creating the production build" });
|
|
22
18
|
|
|
23
|
-
|
|
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:
|
|
24
|
+
text: getCompilationText({
|
|
25
|
+
state: COMPILATION_STATES.FATAL_ERROR
|
|
26
|
+
})
|
|
37
27
|
});
|
|
38
28
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
42
|
+
logStats(stats);
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
44
|
+
return resolve({
|
|
45
|
+
stats,
|
|
46
|
+
previousFileSizes
|
|
47
|
+
});
|
|
48
|
+
}
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
spinnies.succeed("build", {
|
|
51
|
+
text: getCompilationText({
|
|
52
|
+
state: COMPILATION_STATES.SUCCESS
|
|
53
|
+
})
|
|
54
|
+
});
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
return resolve({
|
|
57
|
+
stats,
|
|
58
|
+
previousFileSizes
|
|
63
59
|
});
|
|
64
60
|
});
|
|
65
|
-
};
|
|
61
|
+
});
|
package/tasks/compileMain.js
CHANGED
|
@@ -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
|
|
14
|
+
module.exports = () => new Promise((resolve, reject) => {
|
|
15
|
+
const asset = COMPILATION_ASSETS.MAIN;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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:
|
|
27
|
+
text: getCompilationText({
|
|
28
|
+
asset,
|
|
29
|
+
state: COMPILATION_STATES.FATAL_ERROR
|
|
30
|
+
})
|
|
25
31
|
});
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
48
|
+
logStats(stats);
|
|
49
|
+
return resolve();
|
|
50
|
+
}
|
|
35
51
|
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
});
|
package/tasks/startDevServer.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
26
|
-
clearConsole();
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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 },
|
|
81
|
+
devServer = new WebpackDevServer({ ...devServerConfig, port }, compiler);
|
|
43
82
|
await devServer.start();
|
|
44
83
|
})
|
|
45
84
|
);
|
package/tasks/startElectron.js
CHANGED
|
@@ -2,6 +2,8 @@ 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
|
|
|
@@ -13,7 +15,7 @@ const spinnies = require("../helpers/spinnies");
|
|
|
13
15
|
|
|
14
16
|
module.exports = (port) => (
|
|
15
17
|
new Promise((resolve, reject) => {
|
|
16
|
-
spinnies.add("electron", { text:
|
|
18
|
+
spinnies.add("electron", { text: `Starting ${bold("Electron")}` });
|
|
17
19
|
|
|
18
20
|
try {
|
|
19
21
|
const electronPath = require.resolve("electron");
|
|
@@ -30,11 +32,11 @@ module.exports = (port) => (
|
|
|
30
32
|
}
|
|
31
33
|
}).on("close", process.exit);
|
|
32
34
|
|
|
33
|
-
spinnies.succeed("electron", { text: "Electron started
|
|
35
|
+
spinnies.succeed("electron", { text: `${bold("Electron")} started` });
|
|
34
36
|
resolve();
|
|
35
37
|
|
|
36
38
|
} catch (error) {
|
|
37
|
-
spinnies.fail("electron", { text: "Failed to start Electron
|
|
39
|
+
spinnies.fail("electron", { text: `${bold("Failed")} to start Electron` });
|
|
38
40
|
reject(error);
|
|
39
41
|
}
|
|
40
42
|
})
|
package/tasks/watchPreloads.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
14
|
+
module.exports = () => new Promise((resolve, reject) => {
|
|
15
|
+
let isFirstWatch = true;
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const asset = COMPILATION_ASSETS.PRELOAD;
|
|
18
|
+
const compiler = webpack(webpackConfig.development.preloads);
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
isFirstWatch = false;
|
|
20
|
+
compiler.hooks.compile.tap("compile", () => {
|
|
21
|
+
if (!isFirstWatch) clearConsole();
|
|
25
22
|
|
|
26
|
-
|
|
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:
|
|
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
|
-
|
|
36
|
-
|
|
43
|
+
if (isFirstWatch) {
|
|
44
|
+
isFirstWatch = false;
|
|
45
|
+
resolve();
|
|
46
|
+
}
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
66
|
-
|
|
72
|
+
return logStats(stats);
|
|
73
|
+
}
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
};
|