Skip to content

Commit

Permalink
feat: Clean up all essages
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkr00t committed Jun 14, 2017
1 parent 9c215da commit b6fc441
Show file tree
Hide file tree
Showing 17 changed files with 880 additions and 171 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"browser": false
},

"parserOptions": {
"sourceType": "module"
},

"plugins": [
"flowtype"
],
Expand Down
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
},
"pre-commit": [
"lint:flow",
"lint:staged"
"lint:staged",
"test"
],
"lint-staged": {
"*.js": [
Expand Down Expand Up @@ -102,14 +103,14 @@
"babel-plugin-syntax-flow": "6.18.0",
"babel-plugin-transform-async-to-generator": "6.24.1",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"babel-polyfill": "^6.23.0",
"babel-polyfill": "6.23.0",
"conventional-github-releaser": "1.1.11",
"coveralls": "^2.13.1",
"coveralls": "2.13.1",
"cz-conventional-changelog": "2.0.0",
"eslint-plugin-flowtype": "2.34.0",
"flow-bin": "0.48.0",
"jest": "^20.0.4",
"lint-staged": "^3.4.0",
"jest": "20.0.4",
"lint-staged": "3.4.0",
"pmm": "1.3.1",
"pre-commit": "1.2.2",
"prettier": "1.4.4",
Expand All @@ -119,5 +120,13 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"jest": {
"roots": [
"./src"
],
"collectCoverageFrom": [
"src/**/*.js"
]
}
}
25 changes: 19 additions & 6 deletions src/commands/build/webpack-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import webpack from "webpack";
import gzipSize from "gzip-size";
import webpackConfigBuilder from "./../../webpack/config-builder";
import {
print,
addTopSpace,
builderBanner,
builderRemovingDistMsg,
builderRunningBuildMsg,
Expand All @@ -32,26 +34,31 @@ export default async function runWebpackBuilder(
try {
fs.statSync(filename);
} catch (error) {
fileDoesNotExistMsg(filename);
print(fileDoesNotExistMsg(filename), /* clear console */ true);
return;
}

const config = webpackConfigBuilder(filename, flags, params);
const compiler = webpack(config);

builderBanner(filename, flags, params);
builderRemovingDistMsg(params.dist.path);
print(builderBanner(filename, flags, params), /* clear console */ true);
print(addTopSpace(builderRemovingDistMsg(params.dist.path)));

await removeDist(params.dist.path);

builderRunningBuildMsg();
print(builderRunningBuildMsg());

return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
const json = stats.toJson({}, true);

if (err || stats.hasErrors()) {
builderErrorMsg(err || json.errors);
print(
builderErrorMsg(err || json.errors),
/* clear console */ true,
/* add sep */ true
);

return reject();
}

Expand All @@ -67,7 +74,13 @@ export default async function runWebpackBuilder(
sizeGz: gzipSize.sync(content) / 1024
};
});
builderSuccessMsg(params.dist.short, { buildDuration, assets });

print(
builderSuccessMsg(params.dist.short, { buildDuration, assets }),
/* clear console */ true,
/* add sep */ true
);

resolve(compiler);
});
});
Expand Down
13 changes: 9 additions & 4 deletions src/commands/dev-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import createWebpackDevServer from "./webpack-dev-server";
import createNgrokTunnel from "./ngrok";
import createParams from "./../../utils/params";
import {
print,
addBottomSpace,
devServerFileDoesNotExistMsg,
devServerInvalidBuildMsg,
fileDoesNotExistMsg,
Expand All @@ -33,7 +35,7 @@ export function requestCreatingAnEntryPoint(
return resolve(true);
}

fileDoesNotExistMsg(filename);
print(fileDoesNotExistMsg(filename), /* clear console */ true);

reject();
});
Expand All @@ -55,7 +57,10 @@ async function prepareEntryPoint(filename: string) {
try {
fs.statSync(filename);
} catch (error) {
devServerFileDoesNotExistMsg(filename);
print(
addBottomSpace(devServerFileDoesNotExistMsg(filename)),
/* clear console */ true
);

const shouldCreateAnEntryPoint = await requestCreatingAnEntryPoint(
filename
Expand All @@ -72,7 +77,7 @@ function prepareForReact() {
const needReactDom = !isModuleInstalled("react-dom");

if (needReact || needReactDom) {
devServerReactRequired();
print(devServerReactRequired());
}

needReact && installModule("react");
Expand All @@ -90,7 +95,7 @@ export default async function aikDevServer(

await prepareEntryPoint(filename);

devServerInvalidBuildMsg();
print(devServerInvalidBuildMsg(), /* clear console */ true);
installAllModules(process.cwd());

if (flags.react) {
Expand Down
84 changes: 53 additions & 31 deletions src/commands/dev-server/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import WebpackDevServer from "webpack-dev-server";
import webpackConfigBuilder from "./../../webpack/config-builder";
import detectPort from "./../../utils/detect-port";
import testUtils from "./../../utils/test-utils";
import { formatMessages } from "./../../utils/error-helpers";
import {
isLikelyASyntaxError,
formatMessage
} from "./../../utils/error-helpers";
import {
print,
addTopSpace,
joinWithSpace,
joinWithSeparator,
separator,
clearConsole,
eslintExtraWarningMsg,
devServerInvalidBuildMsg,
Expand Down Expand Up @@ -41,18 +43,16 @@ export function onDone(
clearConsole(true);

if (!hasErrors && !hasWarnings) {
devServerCompiledSuccessfullyMsg(filename, flags, params, buildDuration);
print(
devServerCompiledSuccessfullyMsg(filename, flags, params, buildDuration)
);
testUtils();
return;
}

const json = stats.toJson({}, true);
const formattedWarnings = json.warnings.map(
message => "Warning in " + formatMessage(message)
);
let formattedErrors = json.errors.map(
message => "Error in " + formatMessage(message)
);
const formattedWarnings = formatMessages(json.warnings);
const formattedErrors = formatMessages(json.errors);

if (hasErrors) {
if (
Expand All @@ -63,25 +63,39 @@ export function onDone(
return;
}

devServerFailedToCompileMsg();

// If there are any syntax errors, show just them.
// This prevents a confusing ESLint parsing error
// preceding a much more useful Babel syntax error.
if (formattedErrors.some(isLikelyASyntaxError)) {
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
}
print(
devServerFailedToCompileMsg(),
/* clear console */ true,
/* add sep */ true
);

// If errors exist, ignore warnings.
formattedErrors.forEach(message => console.log("\n", message)); // eslint-disable-line
testUtils();
return;
if (formattedErrors.length) {
print(
addTopSpace(
joinWithSeparator(`\n\n${separator()}\n\n`, formattedErrors)
)
);
testUtils();
return;
}
}

if (hasWarnings) {
devServerCompiledWithWarningsMsg(filename, flags, params, buildDuration);
formattedWarnings.forEach(message => console.log("\n", message)); // eslint-disable-line
eslintExtraWarningMsg();
if (hasWarnings && formattedWarnings.length) {
print(
joinWithSeparator(`\n${separator()}\n`, [
joinWithSpace([
devServerCompiledWithWarningsMsg(
filename,
flags,
params,
buildDuration
),
formattedWarnings.join(`\n\n${separator()}\n\n`)
]),
eslintExtraWarningMsg()
])
);
}

testUtils();
Expand All @@ -97,9 +111,10 @@ export function createWebpackCompiler(
config: Object,
invalidate: Function
) {
// eslint-disable-line
const compiler = webpack(config);
compiler.plugin("invalid", devServerInvalidBuildMsg);
compiler.plugin("invalid", () =>
print(devServerInvalidBuildMsg(), /* clear console */ true)
);
compiler.plugin(
"done",
onDone.bind(null, filename, flags, params, compiler, invalidate)
Expand Down Expand Up @@ -138,12 +153,19 @@ export default async function createWebpackDevServer(

try {
resolveModule.sync(moduleName, { basedir: process.cwd() });
devServerRestartMsg(moduleName);
print(
devServerRestartMsg(moduleName),
/* clear console */ true,
/* add sep */ true
);
server.close();
createWebpackDevServer(filename, flags, params);
} catch (e) {
// eslint-disable-line
devServerModuleDoesntExists(moduleName, fileWithError);
print(
devServerModuleDoesntExists(moduleName, fileWithError),
/* clear console */ true,
/* add sep */ true
);
}
};

Expand Down
39 changes: 39 additions & 0 deletions src/utils/__test__/__snapshots__/error-helpers.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`#formatMessages Format ESLint Warnings 1`] = `
" 5:16 warning React.createClass is deprecated since React 15.5.0, use the npm module create-react-class instead react/no-deprecated
40:11 warning No duplicate props allowed react/jsx-no-duplicate-props
Where: ./thinking-in-react/src/components/filtered-product-table/filtered-product-table.js
16:11 warning No duplicate props allowed react/jsx-no-duplicate-props
Where: ./thinking-in-react/src/components/product-table/product-table.js"
`;

exports[`#formatMessages Format Syntax Error 1`] = `
"Error:
| Syntax Error: Unexpected token (20:7)
Where: ./thinking-in-react/src/components/product-table/product-table.js
  18 |  return (
 19 |  <div className=\\"productTable\\">
> 20 |  <<table>
 |  ^
 21 |  <thead>
 22 |  <tr>
 23 |  <th>Name</th>"
`;

exports[`#formatMessages Format Webpack Warnings 1`] = `""`;

exports[`#formatMessages Unknown messages 1`] = `
Array [
"some",
"custom",
"messages",
]
`;

0 comments on commit b6fc441

Please sign in to comment.