Skip to content

Commit

Permalink
refactor: update all instances
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Aug 19, 2020
1 parent 04f5090 commit 66e085b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 22 deletions.
5 changes: 3 additions & 2 deletions packages/generators/src/init-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { blue, green, bold } from 'colorette';
import logger from 'webpack-cli/lib/utils/logger';
import logSymbols from 'log-symbols';
import path from 'path';
import { getPackageManager } from '@webpack-cli/package-utils';
Expand Down Expand Up @@ -74,12 +75,12 @@ export default class InitGenerator extends CustomGenerator {

this.usingDefaults = true;

process.stdout.write(
logger.rawLog(
`\n${logSymbols.info}${blue(' INFO ')} ` +
'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'))}\n`,
);
process.stdout.write(`${logSymbols.info}${blue(' INFO ')} ` + 'Alternatively, run "webpack(-cli) --help" for usage info\n\n');
logger.rawLog(`${logSymbols.info}${blue(' INFO ')} ` + 'Alternatively, run "webpack(-cli) --help" for usage info\n\n');

const { multiEntries } = await Confirm(
self,
Expand Down
2 changes: 1 addition & 1 deletion packages/info/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export default async function info(...args): Promise<string[]> {
output = output.replace(/npmGlobalPackages/g, 'Global Packages');

const finalOutput = output;
process.stdout.write(finalOutput + '\n');
logger.rawLog(finalOutput + '\n');
return finalOutput;
}
4 changes: 2 additions & 2 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) {
console.log(green(`+ ${diffLine.value}`));
logger.rawLog(green(`+ ${diffLine.value}`));
} else if (diffLine.removed) {
console.log(red(`- ${diffLine.value}`));
logger.rawLog(red(`- ${diffLine.value}`));
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { red, underline } from 'colorette';
import logger from 'webpack-cli/lib/utils/logger';

import { findPluginsByName, isType, safeTraverse } from '@webpack-cli/utils';

Expand Down Expand Up @@ -34,7 +35,7 @@ export default function (j: JSCodeshift, ast: Node): Node {
j(path).remove();
}
} else {
process.stderr.write(`
logger.rawLog(`
${red('Please remove deprecated plugins manually. ')}
See ${underline('https://webpack.js.org/guides/migrating/')} for more information.`);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/modify-config-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { red, green } from 'colorette';
import fs from 'fs';
import logger from 'webpack-cli/lib/utils/logger';
import path from 'path';
import yeoman from 'yeoman-environment';
import Generator from 'yeoman-generator';
Expand Down Expand Up @@ -140,7 +141,7 @@ export function modifyHelperUtil(
const runCommand = getPackageManager() === 'yarn' ? 'yarn build' : 'npm run build';

const successMessage = `\nYou can now run ${green(runCommand)} to bundle your application!\n\n`;
process.stdout.write(`\n${successMessage}`);
logger.rawLog(`\n${successMessage}`);
}

// scaffold webpack config file from using .yo-rc.json
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/scaffold.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { green } from 'colorette';
import logger from 'webpack-cli/lib/utils/logger';
import j from 'jscodeshift';
import pEachSeries = require('p-each-series');
import path from 'path';
Expand Down Expand Up @@ -102,5 +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`);
}
process.stdout.write(`\n${successMessage}`);
logger.rawLog(`\n${successMessage}`);
}
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function runCLI(cliArgs) {
cliArgs = newArgKeys;
args = argParser('', core, cliArgs);
await cli.run(args.opts, core);
process.stdout.write('\n');
logger.rawLog('\n');
logger.warn('Duplicate flags found, defaulting to last set value');
} else {
logger.error(err);
Expand Down
22 changes: 11 additions & 11 deletions packages/webpack-cli/lib/groups/HelpGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ class HelpGroup {
const description = options.description;
const link = options.link;

logger.help(`${header('Usage')}: ${usage}`);
logger.help(`${header('Description')}: ${description}`);
logger.rawLog(`${header('Usage')}: ${usage}`);
logger.rawLog(`${header('Description')}: ${description}`);

if (link) {
logger.help(`${header('Documentation')}: ${link}`);
logger.rawLog(`${header('Documentation')}: ${link}`);
}

if (options.flags) {
const flags = commandLineUsage({
header: 'Options',
optionList: options.flags,
});
logger.help(flags);
logger.rawLog(flags);
}
} else if (invalidArgs.length > 0) {
const argType = invalidArgs[0].startsWith('-') ? 'option' : 'command';
logger.warn(`You provided an invalid ${argType} '${invalidArgs[0]}'.`);
logger.help(this.run().outputOptions.help);
logger.rawLog(this.run().outputOptions.help);
} else {
logger.help(this.run().outputOptions.help);
logger.rawLog(this.run().outputOptions.help);
}
logger.help('\n Made with ♥️ by the webpack team');
logger.rawLog('\n Made with ♥️ by the webpack team');
}

outputVersion(externalPkg, commandsUsed, invalidArgs) {
if (externalPkg && commandsUsed.length === 1 && invalidArgs.length === 0) {
try {
if ([externalPkg.alias, externalPkg.name].some((pkg) => commandsUsed.includes(pkg))) {
const { name, version } = require(`@webpack-cli/${defaultCommands[externalPkg.name]}/package.json`);
logger.help(`\n${name} ${version}`);
logger.rawLog(`\n${name} ${version}`);
} else {
const { name, version } = require(`${externalPkg.name}/package.json`);
logger.help(`\n${name} ${version}`);
logger.rawLog(`\n${name} ${version}`);
}
} catch (e) {
logger.error('Error: External package not found.');
Expand All @@ -76,8 +76,8 @@ class HelpGroup {

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

run() {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/utils/cli-executer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function prompter() {
async function run() {
try {
const args = await prompter();
process.stdout.write('\n');
logger.rawLog('\n');
logger.info('Executing CLI\n');
await runner([], args);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = {
info: (val) => console.info(`[webpack-cli] ${cyan(val)}`),
success: (val) => console.log(`[webpack-cli] ${green(val)}`),
log: (val) => console.log(`[webpack-cli] ${val}`),
help: (val) => console.log(val),
rawLog: (val) => console.log(val),
};

0 comments on commit 66e085b

Please sign in to comment.