Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Sep 2, 2020
1 parent a34667f commit 814033c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 40 deletions.
3 changes: 1 addition & 2 deletions packages/generators/src/init-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export default class InitGenerator extends CustomGenerator {
'For more information and a detailed description of each question, have a look at: ' +
`${bold(green('https://github.com/webpack/webpack-cli/blob/master/INIT.md'))}`,
);
logger.log(`${logSymbols.info}${blue(' INFO ')} ` + 'Alternatively, run "webpack(-cli) --help" for usage info');
logger.raw();
logger.log(`${logSymbols.info}${blue(' INFO ')} ` + 'Alternatively, run "webpack(-cli) --help" for usage info\n');

const { multiEntries } = await Confirm(
self,
Expand Down
12 changes: 5 additions & 7 deletions packages/migrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ function runMigration(currentConfigPath: string, outputConfigPath: string): Prom

diffOutput.forEach((diffLine: Change): void => {
if (diffLine.added) {
logger.raw(green(`+ ${diffLine.value}`));
process.stdout.write(green(`+ ${diffLine.value}`));
} else if (diffLine.removed) {
logger.raw(red(`- ${diffLine.value}`));
process.stdout.write(red(`- ${diffLine.value}`));
}
});

Expand Down Expand Up @@ -139,7 +139,7 @@ function runMigration(currentConfigPath: string, outputConfigPath: string): Prom
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const webpackOptionsValidationErrors: any = validate(outputConfig);
if (webpackOptionsValidationErrors.length) {
logger.error("\n✖ Your configuration validation wasn't successful");
logger.error("\n✖ Your configuration validation wasn't successful\n");
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
logger.error(new WebpackOptionsValidationError(webpackOptionsValidationErrors));
Expand All @@ -154,8 +154,7 @@ function runMigration(currentConfigPath: string, outputConfigPath: string): Prom
);
})
.catch((err: object): void => {
const errMsg = '\n ✖ ︎Migration aborted due to some errors:';
logger.error(errMsg);
logger.error('\n ✖ ︎Migration aborted due to some errors:\n');
logger.error(err);
process.exitCode = 1;
});
Expand All @@ -175,8 +174,7 @@ function runMigration(currentConfigPath: string, outputConfigPath: string): Prom
export default function migrate(...args: string[]): void | Promise<void> {
const filePaths = args;
if (!filePaths.length) {
const errMsg = '\n ✖ Please specify a path to your webpack config';
logger.error(errMsg);
logger.error('\n ✖ Please specify a path to your webpack config\n');
return;
}

Expand Down
18 changes: 6 additions & 12 deletions packages/utils/src/modify-config-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export function modifyHelperUtil(
}
}
} catch (err) {
logger.raw();
logger.error('Your package.json was incorrectly formatted.');
logger.error('\nYour package.json was incorrectly formatted.\n');
Error.stackTraceLimit = 0;
process.exitCode = 2;
}
Expand All @@ -105,11 +104,9 @@ export function modifyHelperUtil(
const confPath = path.resolve(process.cwd(), '.yo-rc.json');
configModule = require(confPath);
} catch (err) {
logger.raw();
logger.error('Could not find a yeoman configuration file (.yo-rc.json).');
logger.raw();
logger.error('\nCould not find a yeoman configuration file (.yo-rc.json).\n');
logger.error(
"Please make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.",
"\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n",
);
Error.stackTraceLimit = 0;
process.exitCode = 2;
Expand All @@ -125,9 +122,8 @@ export function modifyHelperUtil(
}
} catch (err) {
logger.error(err);
logger.error(err.stack);
logger.raw();
logger.error('Your yeoman configuration file (.yo-rc.json) was incorrectly formatted. Deleting it may fix the problem.');
logger.error(`${err.stack}\n`);
logger.error('Your yeoman configuration file (.yo-rc.json) was incorrectly formatted. Deleting it may fix the problem.\n');
Error.stackTraceLimit = 0;
process.exitCode = 2;
}
Expand All @@ -142,9 +138,7 @@ export function modifyHelperUtil(
if (finalConfig.usingDefaults && finalConfig.usingDefaults === true) {
const runCommand = getPackageManager() === 'yarn' ? 'yarn build' : 'npm run build';

const successMessage = `You can now run ${green(runCommand)} to bundle your application!\n`;
logger.raw();
logger.log(successMessage);
logger.log(`\nYou can now run ${green(runCommand)} to bundle your application!\n`);
}

// scaffold webpack config file from using .yo-rc.json
Expand Down
12 changes: 6 additions & 6 deletions packages/utils/src/resolve-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function resolvePackages(pkg: string[]): Function | void {
require.resolve(absolutePath);
packageLocations.push(absolutePath);
} catch (err) {
logger.error(`Cannot find a generator at ${absolutePath}.`);
logger.error('Reason:');
logger.error(`Cannot find a generator at ${absolutePath}.\n`);
logger.error('Reason:\n');
logger.error(bold(err));
process.exitCode = 1;
}
Expand All @@ -76,15 +76,15 @@ export function resolvePackages(pkg: string[]): Function | void {
packageLocations.push(path.resolve(globalPath, scaffold));
} catch (err) {
logger.error("Package wasn't validated correctly...");
logger.error('Submit an issue for', pkg, 'if this persists');
logger.error('Reason:');
logger.error(`Submit an issue for ${pkg} if this persists\n`);
logger.error('Reason:\n');
logger.error(bold(err));
process.exitCode = 1;
}
})
.catch((err: string): void => {
logger.error("Package couldn't be installed, aborting...");
logger.error('Reason:');
logger.error("Package couldn't be installed, aborting...\n");
logger.error('Reason:\n');
logger.error(bold(err));
process.exitCode = 1;
})
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/run-prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function runPrettier(outputPath: string, source: string): void {
useTabs: true,
});
} catch (err) {
logger.warn(`WARNING: Could not apply prettier to ${outputPath} due to validation error, but the file has been created`);
logger.warn(`\nWARNING: Could not apply prettier to ${outputPath} due to validation error, but the file has been created`);
prettySource = source;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/utils/src/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function runTransform(transformConfig: TransformConfig, action: string, g
runPrettier(outputPath, source);
})
.catch((err: Error): void => {
logger.error(err.message ? err.message : err);
logger.error(err);
});
},
);
Expand All @@ -103,6 +103,5 @@ export function runTransform(transformConfig: TransformConfig, action: string, g
if (initActionNotDefined && transformConfig.config.item) {
successMessage = green(`Congratulations! ${transformConfig.config.item} has been ${action}ed!\n`);
}
logger.raw();
logger.log(successMessage);
logger.log(`\n${successMessage}`);
}
3 changes: 1 addition & 2 deletions packages/webpack-cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ async function runCLI(cliArgs) {
cliArgs = newArgKeys;
args = argParser('', core, cliArgs);
await cli.run(args.opts, core);
logger.raw();
logger.warn('Duplicate flags found, defaulting to last set value');
logger.warn('\nDuplicate flags found, defaulting to last set value');
} else {
logger.error(err);
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/groups/BasicGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BasicGroup extends GroupHelper {
if (arg === 'entry') {
options[arg] = this.resolveFilePath(args[arg], 'index.js');
if (options[arg].length === 0) {
logger.error('Error: you provided an invalid entry point.');
logger.error('\nError: you provided an invalid entry point.');
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/webpack-cli/lib/groups/HelpGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ class HelpGroup {
}

if (commandsUsed.length > 1) {
logger.error('You provided multiple commands. Please use only one command at a time.');
logger.error('You provided multiple commands. Please use only one command at a time.\n');
process.exit(2);
}

if (invalidArgs.length > 0) {
const argType = invalidArgs[0].startsWith('-') ? 'option' : 'command';
logger.error(red(`Error: Invalid ${argType} '${invalidArgs[0]}'.`));
logger.info(cyan('Run webpack --help to see available commands and arguments.'));
logger.info(cyan('Run webpack --help to see available commands and arguments.\n'));
process.exit(2);
}

const pkgJSON = require('../../package.json');
const webpack = require('webpack');
logger.raw(`\nwebpack-cli ${pkgJSON.version}`);
logger.raw(`\nwebpack ${webpack.version}`);
logger.raw(`\nwebpack ${webpack.version}\n`);
}

run() {
Expand Down
3 changes: 1 addition & 2 deletions packages/webpack-cli/lib/utils/cli-executer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ async function prompter() {
async function run() {
try {
const args = await prompter();
logger.raw();
logger.info('Executing CLI\n');
logger.info('\nExecuting CLI\n');
await runCLI(args);
} catch (err) {
logger.error(`Action Interrupted, use ${cyan('webpack-cli help')} to see possible options.`);
Expand Down
2 changes: 1 addition & 1 deletion test/migrate/config/migrate-config.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const { red } = require('colorette');
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const { red } = require('colorette');
const { run, runAndGetWatchProc, runPromptWithAnswers } = require('../../utils/test-utils');

const ENTER = '\x0D';
Expand Down

0 comments on commit 814033c

Please sign in to comment.