1 | const chalk = require('chalk');
|
2 | const { logInfo } = require('./log');
|
3 | const path = require('path');
|
4 | const { getPackageJson, getPackageJsonAnuxSettings, shell, resolveFile, waitForAnyKeyToEnd } = require('./utils');
|
5 | const fs = require('fs');
|
6 | const rootPath = process.cwd();
|
7 |
|
8 | async function removeDistFolder() {
|
9 | await shell('rm -rf dist');
|
10 | }
|
11 |
|
12 | module.exports = async function anuxHarness() {
|
13 | const { name, version } = getPackageJson({ throwErrorIfNotFound: true });
|
14 | const { build: { clearBeforeCompile } } = getPackageJsonAnuxSettings({ build: { clearBeforeCompile: true } });
|
15 |
|
16 | if (!fs.existsSync(path.resolve(rootPath, './harnesses.ts'))) throw new Error('There is no harnesses.ts file in the root of the project.');
|
17 |
|
18 | logInfo(`Starting harness for ${name} v${version}...`);
|
19 | logInfo(chalk`{black.bgYellowBright Press any key to end.}`);
|
20 | if (clearBeforeCompile) {
|
21 | logInfo('Clearing dist folder...');
|
22 | await removeDistFolder();
|
23 | logInfo('Cleared, continuing harness creation...');
|
24 | }
|
25 | const configFile = await resolveFile('configs/harness.webpack.config.js');
|
26 | const buildCommand = `npx webpack-dev-server --config ${configFile} --mode development`;
|
27 | const buildProcess = shell(buildCommand);
|
28 | buildProcess.catch(({ exitCode, stdout, stderr }) => {
|
29 | exitCode = exitCode == null ? 0 : exitCode;
|
30 | if (exitCode !== 0) {
|
31 | stderr = stderr === '' ? stdout : stderr;
|
32 |
|
33 | console.error(stderr);
|
34 | }
|
35 | });
|
36 | await waitForAnyKeyToEnd(async () => {
|
37 | logInfo('Shutting down harness...');
|
38 | await buildProcess.kill();
|
39 | });
|
40 | };
|