From 9c4eefcdbf4058b65c8b88fe98387166acad127b Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 17 Dec 2018 17:34:32 +0100 Subject: [PATCH] Add prettier for examples directory (#5909) * Add prettier for examples directory * Fix files * Fix linting * Add prettier script in case it has to be ran again --- examples/active-class-name/components/Link.js | 4 +- examples/analyze-bundles/pages/about.js | 4 +- examples/analyze-bundles/pages/contact.js | 6 +- examples/analyze-bundles/pages/index.js | 4 +- examples/basic-export/pages/about.js | 4 +- examples/basic-export/pages/about2.js | 4 +- examples/basic-export/pages/day/index.js | 4 +- examples/basic-export/pages/index.js | 7 +- examples/custom-charset/server.js | 20 +- .../actions/render.js | 2 +- .../custom-server-actionhero/config/api.js | 32 +-- .../custom-server-actionhero/config/errors.js | 87 +++++--- .../custom-server-actionhero/config/i18n.js | 4 +- .../custom-server-actionhero/config/logger.js | 23 ++- .../config/plugins.js | 2 +- .../custom-server-actionhero/config/redis.js | 43 +++- .../custom-server-actionhero/config/routes.js | 6 +- .../config/servers/socket.js | 6 +- .../config/servers/web.js | 13 +- .../config/servers/websocket.js | 4 +- .../custom-server-actionhero/config/tasks.js | 4 +- .../initializers/next.js | 16 +- .../custom-server-actionhero/pages/index.js | 12 +- examples/custom-server-express/pages/index.js | 17 +- examples/custom-server-express/pages/posts.js | 16 +- examples/custom-server-express/server.js | 45 ++--- examples/custom-server-fastify/pages/index.js | 12 +- examples/custom-server-fastify/server.js | 42 ++-- examples/custom-server-hapi/next-wrapper.js | 8 +- examples/custom-server-hapi/pages/index.js | 12 +- examples/custom-server-hapi/server.js | 72 +++---- examples/custom-server-koa/pages/index.js | 12 +- examples/custom-server-koa/server.js | 55 +++-- examples/custom-server-micro/pages/index.js | 12 +- examples/custom-server-nodemon/pages/index.js | 12 +- .../custom-server-nodemon/server/index.js | 32 ++- examples/custom-server/pages/index.js | 12 +- examples/custom-server/server.js | 32 ++- examples/data-fetch/pages/index.js | 4 +- examples/data-fetch/pages/preact.js | 4 +- .../actions/formActionsCreators.js | 2 +- .../form-handler/components/DisplayForm.js | 4 +- examples/form-handler/components/Header.js | 2 +- examples/form-handler/components/UserForm.js | 7 +- examples/form-handler/components/index.js | 7 +- examples/form-handler/handlers/Input.js | 9 +- examples/form-handler/reducers/formReducer.js | 8 +- examples/form-handler/server.js | 7 +- examples/gh-pages/.babelrc.js | 8 +- examples/gh-pages/pages/about.js | 7 +- examples/gh-pages/pages/index.js | 7 +- examples/hello-world/pages/about.js | 4 +- examples/hello-world/pages/day/index.js | 4 +- examples/hello-world/pages/index.js | 7 +- .../layout-component/components/layout.js | 22 +- examples/nested-components/components/post.js | 4 +- examples/nested-components/pages/index.js | 2 +- .../components/BarChart.js | 3 +- .../components/LineChart.js | 3 +- .../pages/chart.js | 14 +- .../pages/index.js | 14 +- examples/parameterized-routing/pages/blog.js | 16 +- examples/parameterized-routing/pages/index.js | 18 +- examples/parameterized-routing/server.js | 34 ++-- examples/pass-server-data/pages/index.js | 6 +- examples/pass-server-data/pages/item.js | 16 +- examples/pass-server-data/server.js | 2 +- examples/progressive-render/pages/index.js | 4 +- examples/root-static-files/pages/index.js | 12 +- examples/root-static-files/server.js | 34 ++-- examples/shared-modules/components/Header.js | 4 +- examples/ssr-caching/pages/blog.js | 16 +- examples/ssr-caching/pages/index.js | 18 +- examples/ssr-caching/server.js | 41 ++-- examples/using-inferno/next.config.js | 2 +- examples/using-inferno/pages/about.js | 4 +- examples/using-inferno/pages/index.js | 7 +- examples/using-inferno/server.js | 18 +- examples/using-nerv/pages/about.js | 4 +- examples/using-nerv/pages/index.js | 7 +- examples/using-nerv/server.js | 18 +- examples/using-preact/pages/about.js | 4 +- examples/using-preact/pages/index.js | 7 +- examples/using-preact/server.js | 18 +- examples/using-router/components/Header.js | 2 +- examples/using-router/pages/error.js | 2 +- .../components/ActiveLink.js | 2 +- examples/using-with-router/pages/error.js | 2 +- .../components/app.js | 13 +- .../components/head.js | 3 +- .../pages/index.js | 4 +- examples/with-amp/components/Byline.js | 6 +- examples/with-amp/pages/_document.js | 10 +- examples/with-amp/pages/dog.js | 76 ++++++- examples/with-amp/pages/index.js | 190 +++++++++++++++++- examples/with-ant-design-less/next.config.js | 10 +- examples/with-ant-design-less/pages/index.js | 57 +++--- examples/with-ant-design/next.config.js | 2 +- examples/with-ant-design/pages/index.js | 57 +++--- .../with-antd-mobile/components/Layout.js | 4 +- examples/with-antd-mobile/next.config.js | 2 +- examples/with-antd-mobile/pages/_app.js | 8 +- examples/with-aphrodite/pages/_document.js | 5 +- .../components/App.js | 12 +- .../components/ErrorMessage.js | 2 +- .../components/PageCount.js | 2 +- .../components/Placeholder.js | 2 +- .../components/Post.js | 6 +- .../components/PostList.js | 2 +- .../components/PostVoteButton.js | 2 +- .../components/PostVoteCount.js | 2 +- .../lib/withApollo.js | 7 +- .../with-apollo-and-redux-saga/pages/about.js | 28 ++- .../pages/blog/index.js | 4 +- examples/with-apollo-and-redux-saga/routes.js | 2 +- examples/with-apollo-and-redux-saga/server.js | 13 +- .../components/AddCount.js | 13 +- .../with-apollo-and-redux/components/Clock.js | 7 +- examples/with-apollo-and-redux/lib/store.js | 21 +- examples/with-apollo-and-redux/pages/index.js | 4 +- .../components/RegisterBox.js | 104 ++++++---- .../with-apollo-auth/components/SigninBox.js | 83 +++++--- .../with-apollo-auth/lib/checkLoggedIn.js | 34 ++-- examples/with-apollo-auth/lib/withApollo.js | 20 +- examples/with-apollo-auth/pages/_app.js | 12 +- .../with-apollo-auth/pages/create-account.js | 7 +- examples/with-apollo-auth/pages/index.js | 2 +- examples/with-apollo-auth/pages/signin.js | 7 +- .../with-apollo/lib/with-apollo-client.js | 2 +- examples/with-apollo/pages/_app.js | 16 +- examples/with-apollo/pages/about.js | 22 +- examples/with-app-layout/pages/_app.js | 22 +- examples/with-asset-imports/pages/index.js | 3 +- examples/with-babel-macros/pages/_document.js | 4 +- examples/with-babel-macros/pages/index.js | 6 +- .../with-carbon-components/next.config.js | 34 ++-- .../with-carbon-components/pages/_document.js | 5 +- examples/with-cerebral/components/Clock.js | 9 +- examples/with-cerebral/components/Page.js | 51 ++--- .../with-cerebral/modules/clock/actions.js | 4 +- examples/with-cerebral/modules/clock/index.js | 3 +- .../with-cerebral/modules/clock/provider.js | 4 +- .../with-cerebral/modules/clock/signals.js | 11 +- examples/with-cerebral/pages/index.js | 13 +- examples/with-cerebral/pages/other.js | 13 +- .../with-configured-preset-env/pages/index.js | 2 +- .../with-custom-babel-config/pages/index.js | 8 +- .../with-custom-reverse-proxy/pages/index.js | 7 +- examples/with-custom-reverse-proxy/server.js | 2 +- examples/with-cxs/pages/_document.js | 5 +- .../with-data-prefetch/components/link.js | 18 +- examples/with-data-prefetch/pages/index.js | 4 +- examples/with-docker/next.config.js | 6 +- examples/with-docker/pages/index.js | 4 +- examples/with-dotenv/next.config.js | 2 +- examples/with-dotenv/pages/index.js | 4 +- examples/with-draft-js/pages/index.js | 179 ++++++++++++----- .../layouts/BlueLayout.js | 4 +- .../layouts/GreenLayout.js | 4 +- .../layouts/RedLayout.js | 4 +- .../with-dynamic-app-layout/pages/_app.js | 12 +- .../with-dynamic-app-layout/pages/green.js | 16 +- .../with-dynamic-app-layout/pages/index.js | 23 ++- examples/with-dynamic-app-layout/pages/red.js | 16 +- .../with-dynamic-import/components/Header.js | 4 +- .../with-dynamic-import/components/hello1.js | 4 +- .../with-dynamic-import/components/hello2.js | 4 +- .../with-dynamic-import/components/hello3.js | 4 +- .../with-dynamic-import/components/hello4.js | 4 +- .../with-dynamic-import/components/hello5.js | 4 +- .../with-dynamic-import/components/hello6.js | 4 +- .../with-dynamic-import/components/hello7.js | 4 +- examples/with-dynamic-import/pages/index.js | 6 +- .../with-electron/renderer/pages/start.js | 4 +- .../features/home.component.js | 2 +- .../hoc/withEmotion.component.js | 2 +- examples/with-emotion-fiber/shared/styles.js | 54 ++--- .../pages/index.js | 3 +- examples/with-fela/FelaProvider.js | 10 +- examples/with-fela/getFelaRenderer.js | 4 +- examples/with-fela/pages/_document.js | 4 +- .../pages/index.js | 98 +++++---- .../with-firebase-authentication/server.js | 88 ++++---- examples/with-flow/pages/_app.js | 24 ++- examples/with-freactal/components/app.js | 2 +- examples/with-freactal/githubApi.js | 5 +- examples/with-freactal/pages/index.js | 78 +++---- examples/with-freactal/provideState.js | 44 ++-- examples/with-glamorous/pages/index.js | 17 +- .../with-google-analytics/pages/_document.js | 3 +- .../components/AddCount.js | 19 +- .../components/Clock.js | 7 +- .../components/Page.js | 4 +- .../pages/index.js | 11 +- .../pages/other.js | 11 +- .../with-immutable-redux-wrapper/store.js | 16 +- .../__tests__/blog.page_with_provide.test.js | 4 +- .../endpoint.component_with_inject.test.js | 16 +- .../index.page_without_provide.test.js | 7 +- examples/with-ioc/components/component1.js | 4 +- examples/with-ioc/components/component2.js | 4 +- examples/with-ioc/components/endbutton.js | 14 +- examples/with-ioc/components/endpoint.js | 18 +- examples/with-ioc/pages/about.js | 4 +- examples/with-ioc/pages/blog.js | 4 +- examples/with-ioc/pages/index.js | 30 ++- examples/with-ioc/routes.js | 2 +- examples/with-ioc/server.js | 12 +- examples/with-jest-typescript/jest.config.js | 8 +- examples/with-jest-typescript/jest.setup.js | 2 +- examples/with-kea/pages/_app.js | 8 +- examples/with-kea/pages/index.js | 11 +- examples/with-kea/store.js | 5 +- examples/with-loading/pages/_app.js | 24 ++- examples/with-loading/pages/about.js | 2 +- examples/with-loading/pages/forever.js | 2 +- examples/with-markdown/next.config.js | 5 +- examples/with-markdown/pages/index.js | 10 +- examples/with-mdx/components/button.js | 18 +- .../with-mobx-state-tree/components/Clock.js | 9 +- .../components/SampleComponent.js | 9 +- examples/with-mobx-state-tree/pages/_app.js | 2 +- examples/with-mobx-state-tree/pages/index.js | 4 +- examples/with-mobx-state-tree/pages/other.js | 4 +- examples/with-mobx-state-tree/stores/store.js | 2 +- examples/with-mobx/components/Clock.js | 9 +- examples/with-mobx/components/Page.js | 18 +- examples/with-mobx/pages/_app.js | 58 +++--- examples/with-mobx/pages/index.js | 6 +- examples/with-mobx/pages/other.js | 6 +- examples/with-mobx/store.js | 8 +- examples/with-next-css/pages/index.js | 1 - examples/with-next-routes/pages/about.js | 2 +- examples/with-next-routes/pages/index.js | 30 ++- examples/with-next-routes/routes.js | 2 +- examples/with-next-routes/server.js | 12 +- examples/with-next-sass/pages/index.js | 5 +- examples/with-noscript/next.config.js | 4 +- examples/with-noscript/pages/index.js | 22 +- examples/with-pkg/pages/index.js | 3 +- examples/with-pkg/server.js | 14 +- examples/with-polyfills/next.config.js | 5 +- examples/with-polyfills/pages/index.js | 6 +- .../with-prefetching/components/Header.js | 17 +- examples/with-prefetching/pages/_app.js | 6 +- .../with-pretty-url-routing/pages/greeting.js | 18 +- examples/with-pretty-url-routing/routes.js | 8 +- examples/with-pretty-url-routing/server.js | 24 ++- examples/with-react-ga/pages/about.js | 4 +- examples/with-react-helmet/pages/_document.js | 40 ++-- examples/with-react-helmet/pages/index.js | 4 +- examples/with-react-intl/components/Layout.js | 5 +- examples/with-react-intl/components/Nav.js | 10 +- examples/with-react-intl/lib/withIntl.js | 2 +- examples/with-react-intl/pages/_app.js | 8 +- examples/with-react-intl/pages/_document.js | 10 +- examples/with-react-intl/pages/about.js | 8 +- .../with-react-intl/scripts/default-lang.js | 13 +- examples/with-react-intl/server.js | 18 +- examples/with-react-jss/pages/_document.js | 5 +- examples/with-react-md/pages/index.js | 32 ++- examples/with-react-native-web/next.config.js | 2 +- .../components/BlogPostPreview.js | 14 +- .../components/BlogPosts.js | 26 +-- .../lib/createEnvironment/server.js | 5 +- .../pages/_app.js | 11 +- .../pages/index.js | 2 +- examples/with-react-toolbox/pages/index.js | 4 +- examples/with-react-toolbox/static/theme.js | 87 +++++++- examples/with-react-useragent/pages/_app.js | 8 +- examples/with-react-useragent/pages/index.js | 4 +- .../with-react-uwp/components/ThemeWrapper.js | 5 +- examples/with-react-uwp/pages/_document.js | 14 +- examples/with-react-uwp/pages/index.js | 7 +- .../with-react-with-styles/pages/_document.js | 5 +- examples/with-rebass/pages/_document.js | 8 +- examples/with-rebass/pages/index.js | 10 +- examples/with-recompose/pages/index.js | 25 +-- .../with-redux-code-splitting/config/redux.js | 9 +- .../containers/about.js | 28 ++- .../containers/homepage.js | 28 ++- .../with-redux-code-splitting/pages/about.js | 2 +- .../with-redux-code-splitting/pages/index.js | 2 +- .../components/CharacterInfo.js | 46 +++-- examples/with-redux-observable/pages/index.js | 4 +- examples/with-redux-observable/redux/epics.js | 15 +- examples/with-redux-observable/redux/index.js | 2 +- .../with-redux-observable/redux/reducer.js | 6 +- .../actions/index.js | 6 +- .../components/addCount.js | 9 +- .../components/clock.js | 10 +- .../components/page.js | 7 +- .../containers/page.js | 15 +- .../selectors/index.js | 27 +-- .../with-redux-reselect-recompose/store.js | 6 +- examples/with-redux-saga/actions.js | 10 +- examples/with-redux-saga/components/clock.js | 4 +- .../with-redux-saga/components/counter.js | 10 +- examples/with-redux-saga/components/page.js | 30 +-- examples/with-redux-saga/pages/index.js | 4 +- examples/with-redux-saga/pages/other.js | 4 +- examples/with-redux-saga/reducer.js | 14 +- examples/with-redux-saga/saga.js | 6 +- examples/with-redux-saga/store.js | 6 +- .../with-redux-wrapper/components/AddCount.js | 17 +- .../with-redux-wrapper/components/Clock.js | 7 +- .../with-redux-wrapper/components/Page.js | 28 +-- examples/with-redux-wrapper/pages/_app.js | 40 ++-- examples/with-redux-wrapper/pages/index.js | 11 +- examples/with-redux-wrapper/pages/other.js | 11 +- examples/with-redux-wrapper/store.js | 21 +- examples/with-redux/components/clock.js | 7 +- examples/with-redux/components/counter.js | 16 +- examples/with-redux/components/examples.js | 2 +- examples/with-redux/lib/with-redux-store.js | 4 +- examples/with-redux/pages/_app.js | 4 +- examples/with-redux/pages/index.js | 10 +- examples/with-redux/store.js | 11 +- examples/with-reflux/actions/actions.js | 5 +- examples/with-reflux/store/counterStore.js | 6 +- examples/with-refnux/helpers/getStore.js | 2 +- examples/with-refnux/helpers/withRefnux.js | 14 +- examples/with-refnux/pages/page1.js | 21 +- examples/with-refnux/pages/page2.js | 21 +- .../with-refnux/store/counterIncrement.js | 3 +- examples/with-refnux/store/setTitle.js | 3 +- .../components/BlogPosts.js | 4 +- .../lib/createRelayEnvironment.js | 9 +- .../lib/withData.js | 5 +- .../next.config.js | 2 +- .../pages/index.js | 12 +- .../server/index.js | 26 +-- .../components/BlogPostPreview.js | 14 +- .../with-relay-modern/components/BlogPosts.js | 26 +-- .../lib/createRelayEnvironment.js | 9 +- examples/with-relay-modern/lib/withData.js | 5 +- examples/with-relay-modern/next.config.js | 2 +- examples/with-relay-modern/pages/index.js | 12 +- .../shared/components/counter-display.js | 5 +- .../components/Header.js | 18 +- examples/with-semantic-ui/pages/index.js | 7 +- examples/with-sentry/pages/_app.js | 2 +- examples/with-shallow-routing/pages/about.js | 4 +- .../server/app.js | 2 +- examples/with-socket.io/pages/_app.js | 4 +- examples/with-socket.io/pages/clone.js | 24 ++- examples/with-socket.io/pages/index.js | 24 ++- examples/with-socket.io/server.js | 6 +- .../with-static-export/components/post.js | 8 +- examples/with-static-export/next.config.js | 4 +- examples/with-static-export/pages/index.js | 8 +- examples/with-static-export/pages/post.js | 4 +- examples/with-static-export/server.js | 33 ++- .../with-strict-csp-hash/pages/_document.js | 6 +- examples/with-strict-csp-hash/pages/index.js | 4 +- examples/with-strict-csp/pages/_document.js | 6 +- examples/with-strict-csp/pages/index.js | 4 +- examples/with-strict-csp/server.js | 17 +- examples/with-style-sheet/pages/_document.js | 6 +- examples/with-style-sheet/pages/index.js | 7 +- .../with-styled-components/pages/_document.js | 12 +- examples/with-sw-precache/next.config.js | 2 +- examples/with-sw-precache/pages/index.js | 4 +- examples/with-sw-precache/server.js | 30 ++- examples/with-tailwindcss/components/nav.js | 28 +-- examples/with-typestyle/pages/_document.js | 6 +- examples/with-typestyle/pages/index.js | 8 +- .../next.config.js | 50 ++--- .../pages/index.js | 8 +- .../env-config.js | 4 +- .../pages/index.js | 4 +- examples/with-unstated/components/Clock.js | 13 +- examples/with-unstated/components/Counter.js | 4 +- .../containers/ClockContainer.js | 2 +- .../containers/CounterContainer.js | 4 +- examples/with-unstated/pages/_app.js | 4 +- examples/with-unstated/pages/about.js | 28 ++- examples/with-unstated/pages/index.js | 28 ++- examples/with-url-object-routing/server.js | 28 ++- examples/with-videojs/pages/index.js | 10 +- examples/with-webassembly/pages/index.js | 20 +- .../next.config.js | 8 +- .../pages/about.js | 4 +- .../pages/contact.js | 6 +- .../pages/index.js | 4 +- .../packages/bar/index.js | 6 +- examples/with-zones/blog/pages/blog.js | 6 +- examples/with-zones/home/pages/about.js | 6 +- examples/with-zones/home/pages/index.js | 12 +- package.json | 22 +- yarn.lock | 5 + 391 files changed, 3181 insertions(+), 2130 deletions(-) diff --git a/examples/active-class-name/components/Link.js b/examples/active-class-name/components/Link.js index eadf822e..fc555524 100644 --- a/examples/active-class-name/components/Link.js +++ b/examples/active-class-name/components/Link.js @@ -7,7 +7,9 @@ const ActiveLink = ({ router, children, ...props }) => { let className = child.props.className || null if (router.pathname === props.href && props.activeClassName) { - className = `${className !== null ? className : ''} ${props.activeClassName}`.trim() + className = `${className !== null ? className : ''} ${ + props.activeClassName + }`.trim() } delete props.activeClassName diff --git a/examples/analyze-bundles/pages/about.js b/examples/analyze-bundles/pages/about.js index e5db9621..5fd65c2b 100644 --- a/examples/analyze-bundles/pages/about.js +++ b/examples/analyze-bundles/pages/about.js @@ -1,3 +1 @@ -export default () => ( -
About us
-) +export default () =>
About us
diff --git a/examples/analyze-bundles/pages/contact.js b/examples/analyze-bundles/pages/contact.js index ad1b3696..b0fdbcd7 100644 --- a/examples/analyze-bundles/pages/contact.js +++ b/examples/analyze-bundles/pages/contact.js @@ -1,5 +1 @@ -export default () => ( -
- This is the contact page. -
-) +export default () =>
This is the contact page.
diff --git a/examples/analyze-bundles/pages/index.js b/examples/analyze-bundles/pages/index.js index 11df6e46..db9da9fc 100644 --- a/examples/analyze-bundles/pages/index.js +++ b/examples/analyze-bundles/pages/index.js @@ -21,7 +21,9 @@ export default class Index extends React.Component {

Home Page

Welcome, {name}

- About Page + + About Page +
) diff --git a/examples/basic-export/pages/about.js b/examples/basic-export/pages/about.js index e5db9621..5fd65c2b 100644 --- a/examples/basic-export/pages/about.js +++ b/examples/basic-export/pages/about.js @@ -1,3 +1 @@ -export default () => ( -
About us
-) +export default () =>
About us
diff --git a/examples/basic-export/pages/about2.js b/examples/basic-export/pages/about2.js index 44ce6571..fd84a738 100644 --- a/examples/basic-export/pages/about2.js +++ b/examples/basic-export/pages/about2.js @@ -1,3 +1 @@ -export default () => ( -
About 2
-) +export default () =>
About 2
diff --git a/examples/basic-export/pages/day/index.js b/examples/basic-export/pages/day/index.js index 5a581008..cc400491 100644 --- a/examples/basic-export/pages/day/index.js +++ b/examples/basic-export/pages/day/index.js @@ -1,3 +1 @@ -export default () => ( -
Hello Day
-) +export default () =>
Hello Day
diff --git a/examples/basic-export/pages/index.js b/examples/basic-export/pages/index.js index d120061e..c1af49f3 100644 --- a/examples/basic-export/pages/index.js +++ b/examples/basic-export/pages/index.js @@ -1,4 +1,9 @@ import Link from 'next/link' export default () => ( -
Hello World. About
+
+ Hello World.{' '} + + About + +
) diff --git a/examples/custom-charset/server.js b/examples/custom-charset/server.js index 5cc46fb4..a67e473a 100644 --- a/examples/custom-charset/server.js +++ b/examples/custom-charset/server.js @@ -7,15 +7,13 @@ const dev = process.env.NODE_ENV !== 'production' const app = next({ dev }) const handle = app.getRequestHandler() -app.prepare() - .then(() => { - createServer((req, res) => { - const parsedUrl = parse(req.url, true) - res.setHeader('Content-Type', 'text/html; charset=iso-8859-2') - handle(req, res, parsedUrl) - }) - .listen(port, (err) => { - if (err) throw err - console.log(`> Ready on http://localhost:${port}`) - }) +app.prepare().then(() => { + createServer((req, res) => { + const parsedUrl = parse(req.url, true) + res.setHeader('Content-Type', 'text/html; charset=iso-8859-2') + handle(req, res, parsedUrl) + }).listen(port, err => { + if (err) throw err + console.log(`> Ready on http://localhost:${port}`) }) +}) diff --git a/examples/custom-server-actionhero/actions/render.js b/examples/custom-server-actionhero/actions/render.js index 60bd2700..c5c964e9 100644 --- a/examples/custom-server-actionhero/actions/render.js +++ b/examples/custom-server-actionhero/actions/render.js @@ -1,5 +1,5 @@ 'use strict' -const {Action, api} = require('actionhero') +const { Action, api } = require('actionhero') module.exports = class CreateChatRoom extends Action { constructor () { diff --git a/examples/custom-server-actionhero/config/api.js b/examples/custom-server-actionhero/config/api.js index 3e85fc02..2c474507 100644 --- a/examples/custom-server-actionhero/config/api.js +++ b/examples/custom-server-actionhero/config/api.js @@ -3,7 +3,7 @@ const path = require('path') exports['default'] = { - general: (api) => { + general: api => { const packageJSON = require(api.projectRoot + path.sep + 'package.json') return { @@ -46,16 +46,16 @@ exports['default'] = { cliIncludeInternal: true, // configuration for your actionhero project structure paths: { - 'action': [path.join(__dirname, '/../actions')], - 'task': [path.join(__dirname, '/../tasks')], - 'public': [path.join(__dirname, '/../static')], - 'pid': [path.join(__dirname, '/../pids')], - 'log': [path.join(__dirname, '/../log')], - 'server': [path.join(__dirname, '/../servers')], - 'cli': [path.join(__dirname, '/../bin')], - 'initializer': [path.join(__dirname, '/../initializers')], - 'plugin': [path.join(__dirname, '/../node_modules')], - 'locale': [path.join(__dirname, '/../locales')] + action: [path.join(__dirname, '/../actions')], + task: [path.join(__dirname, '/../tasks')], + public: [path.join(__dirname, '/../static')], + pid: [path.join(__dirname, '/../pids')], + log: [path.join(__dirname, '/../log')], + server: [path.join(__dirname, '/../servers')], + cli: [path.join(__dirname, '/../bin')], + initializer: [path.join(__dirname, '/../initializers')], + plugin: [path.join(__dirname, '/../node_modules')], + locale: [path.join(__dirname, '/../locales')] }, // hash containing chat rooms you wish to be created at server boot startingChatRooms: { @@ -67,17 +67,17 @@ exports['default'] = { } exports.test = { - general: (api) => { + general: api => { return { id: 'test-server-' + process.pid, serverToken: 'serverToken-' + process.pid, developmentMode: true, startingChatRooms: { - 'defaultRoom': {}, - 'otherRoom': {} + defaultRoom: {}, + otherRoom: {} }, paths: { - 'locale': [ + locale: [ // require('os').tmpdir() + require('path').sep + 'locales', path.join(__dirname, '/../locales') ] @@ -88,7 +88,7 @@ exports.test = { } exports.production = { - general: (api) => { + general: api => { return { fileRequestLogLevel: 'debug', developmentMode: false diff --git a/examples/custom-server-actionhero/config/errors.js b/examples/custom-server-actionhero/config/errors.js index 458afb0f..fc9bcce4 100644 --- a/examples/custom-server-actionhero/config/errors.js +++ b/examples/custom-server-actionhero/config/errors.js @@ -2,9 +2,9 @@ // error messages can be strings of objects exports['default'] = { - errors: (api) => { + errors: api => { return { - '_toExpand': false, + _toExpand: false, // /////////////// // SERIALIZERS // @@ -12,28 +12,28 @@ exports['default'] = { serializers: { servers: { - web: (error) => { + web: error => { if (error.message) { return String(error.message) } else { return error } }, - websocket: (error) => { + websocket: error => { if (error.message) { return String(error.message) } else { return error } }, - socket: (error) => { + socket: error => { if (error.message) { return String(error.message) } else { return error } }, - specHelper: (error) => { + specHelper: error => { if (error.message) { return 'Error: ' + String(error.message) } else { @@ -49,38 +49,51 @@ exports['default'] = { // When a params for an action is invalid invalidParams: (data, validationErrors) => { - if (validationErrors.length >= 0) { return validationErrors[0] } + if (validationErrors.length >= 0) { + return validationErrors[0] + } return data.connection.localize('actionhero.errors.invalidParams') }, // When a required param for an action is not provided missingParams: (data, missingParams) => { - return data.connection.localize(['actionhero.errors.missingParams', {param: missingParams[0]}]) + return data.connection.localize([ + 'actionhero.errors.missingParams', + { param: missingParams[0] } + ]) }, // user requested an unknown action - unknownAction: (data) => { + unknownAction: data => { return data.connection.localize('actionhero.errors.unknownAction') }, // action not useable by this client/server type - unsupportedServerType: (data) => { - return data.connection.localize(['actionhero.errors.unsupportedServerType', {type: data.connection.type}]) + unsupportedServerType: data => { + return data.connection.localize([ + 'actionhero.errors.unsupportedServerType', + { type: data.connection.type } + ]) }, // action failed because server is mid-shutdown - serverShuttingDown: (data) => { + serverShuttingDown: data => { return data.connection.localize('actionhero.errors.serverShuttingDown') }, // action failed because this client already has too many pending acitons // limit defined in api.config.general.simultaneousActions - tooManyPendingActions: (data) => { - return data.connection.localize('actionhero.errors.tooManyPendingActions') + tooManyPendingActions: data => { + return data.connection.localize( + 'actionhero.errors.tooManyPendingActions' + ) }, dataLengthTooLarge: (maxLength, receivedLength) => { - return api.i18n.localize(['actionhero.errors.dataLengthTooLarge', {maxLength: maxLength, receivedLength: receivedLength}]) + return api.i18n.localize([ + 'actionhero.errors.dataLengthTooLarge', + { maxLength: maxLength, receivedLength: receivedLength } + ]) }, // /////////////// @@ -89,18 +102,21 @@ exports['default'] = { // The body message to accompany 404 (file not found) errors regarding flat files // You may want to load in the contnet of 404.html or similar - fileNotFound: (connection) => { + fileNotFound: connection => { return connection.localize(['actionhero.errors.fileNotFound']) }, // user didn't request a file - fileNotProvided: (connection) => { + fileNotProvided: connection => { return connection.localize('actionhero.errors.fileNotProvided') }, // something went wrong trying to read the file fileReadError: (connection, error) => { - return connection.localize(['actionhero.errors.fileReadError', {error: String(error)}]) + return connection.localize([ + 'actionhero.errors.fileReadError', + { error: String(error) } + ]) }, // /////////////// @@ -108,41 +124,54 @@ exports['default'] = { // /////////////// verbNotFound: (connection, verb) => { - return connection.localize(['actionhero.errors.verbNotFound', {verb: verb}]) + return connection.localize([ + 'actionhero.errors.verbNotFound', + { verb: verb } + ]) }, verbNotAllowed: (connection, verb) => { - return connection.localize(['actionhero.errors.verbNotAllowed', {verb: verb}]) + return connection.localize([ + 'actionhero.errors.verbNotAllowed', + { verb: verb } + ]) }, - connectionRoomAndMessage: (connection) => { + connectionRoomAndMessage: connection => { return connection.localize('actionhero.errors.connectionRoomAndMessage') }, connectionNotInRoom: (connection, room) => { - return connection.localize(['actionhero.errors.connectionNotInRoom', {room: room}]) + return connection.localize([ + 'actionhero.errors.connectionNotInRoom', + { room: room } + ]) }, connectionAlreadyInRoom: (connection, room) => { - return connection.localize(['actionhero.errors.connectionAlreadyInRoom', {room: room}]) + return connection.localize([ + 'actionhero.errors.connectionAlreadyInRoom', + { room: room } + ]) }, - connectionRoomHasBeenDeleted: (room) => { - return api.i18n.localize('actionhero.errors.connectionRoomHasBeenDeleted') + connectionRoomHasBeenDeleted: room => { + return api.i18n.localize( + 'actionhero.errors.connectionRoomHasBeenDeleted' + ) }, - connectionRoomNotExist: (room) => { + connectionRoomNotExist: room => { return api.i18n.localize('actionhero.errors.connectionRoomNotExist') }, - connectionRoomExists: (room) => { + connectionRoomExists: room => { return api.i18n.localize('actionhero.errors.connectionRoomExists') }, - connectionRoomRequired: (room) => { + connectionRoomRequired: room => { return api.i18n.localize('actionhero.errors.connectionRoomRequired') } - } } } diff --git a/examples/custom-server-actionhero/config/i18n.js b/examples/custom-server-actionhero/config/i18n.js index 979beef7..0c42799f 100644 --- a/examples/custom-server-actionhero/config/i18n.js +++ b/examples/custom-server-actionhero/config/i18n.js @@ -1,5 +1,5 @@ exports['default'] = { - i18n: (api) => { + i18n: api => { return { // visit https://github.com/mashpie/i18n-node to see all configuration options // locale path can be configired from within ./config/api.js @@ -28,7 +28,7 @@ exports['default'] = { } exports.test = { - i18n: (api) => { + i18n: api => { return { updateFiles: true } diff --git a/examples/custom-server-actionhero/config/logger.js b/examples/custom-server-actionhero/config/logger.js index a67e323c..8c447479 100644 --- a/examples/custom-server-actionhero/config/logger.js +++ b/examples/custom-server-actionhero/config/logger.js @@ -4,16 +4,18 @@ const fs = require('fs') const cluster = require('cluster') exports['default'] = { - logger: (api) => { - let logger = {transports: []} + logger: api => { + let logger = { transports: [] } // console logger if (cluster.isMaster) { logger.transports.push(function (api, winston) { - return new (winston.transports.Console)({ + return new winston.transports.Console({ colorize: true, level: 'info', - timestamp: function () { return api.id + ' @ ' + new Date().toISOString() } + timestamp: function () { + return api.id + ' @ ' + new Date().toISOString() + } }) }) } @@ -26,15 +28,18 @@ exports['default'] = { fs.mkdirSync(logDirectory) } catch (e) { if (e.code !== 'EEXIST') { - throw (new Error('Cannot create log directory @ ' + logDirectory)) + throw new Error('Cannot create log directory @ ' + logDirectory) } } } - return new (winston.transports.File)({ - filename: api.config.general.paths.log[0] + '/' + api.pids.title + '.log', + return new winston.transports.File({ + filename: + api.config.general.paths.log[0] + '/' + api.pids.title + '.log', level: 'info', - timestamp: function () { return api.id + ' @ ' + new Date().toISOString() } + timestamp: function () { + return api.id + ' @ ' + new Date().toISOString() + } }) }) @@ -52,7 +57,7 @@ exports['default'] = { } exports.test = { - logger: (api) => { + logger: api => { return { transports: null } diff --git a/examples/custom-server-actionhero/config/plugins.js b/examples/custom-server-actionhero/config/plugins.js index 01b01572..3ed9a464 100644 --- a/examples/custom-server-actionhero/config/plugins.js +++ b/examples/custom-server-actionhero/config/plugins.js @@ -1,5 +1,5 @@ exports['default'] = { - plugins: (api) => { + plugins: api => { /* If you want to use plugins in your application, include them here: diff --git a/examples/custom-server-actionhero/config/redis.js b/examples/custom-server-actionhero/config/redis.js index f392d929..67273b92 100644 --- a/examples/custom-server-actionhero/config/redis.js +++ b/examples/custom-server-actionhero/config/redis.js @@ -11,15 +11,20 @@ if (process.env.REDIS_URL) { } exports['default'] = { - redis: (api) => { + redis: api => { // konstructor: The redis client constructor method. All redis methods must be promises // args: The arguments to pass to the constructor // buildNew: is it `new konstructor()` or just `konstructor()`? function retryStrategy (times) { if (times === 1) { - const error = 'Unable to connect to Redis - please check your Redis config!' - if (process.env.NODE_ENV === 'test') { console.error(error) } else { api.log(error, 'error') } + const error = + 'Unable to connect to Redis - please check your Redis config!' + if (process.env.NODE_ENV === 'test') { + console.error(error) + } else { + api.log(error, 'error') + } return 5000 } return Math.min(times * 50, maxBackoff) @@ -28,20 +33,44 @@ exports['default'] = { return { enabled: true, - '_toExpand': false, + _toExpand: false, client: { konstructor: require('ioredis'), - args: [{ port: port, host: host, password: password, db: db, retryStrategy: retryStrategy }], + args: [ + { + port: port, + host: host, + password: password, + db: db, + retryStrategy: retryStrategy + } + ], buildNew: true }, subscriber: { konstructor: require('ioredis'), - args: [{ port: port, host: host, password: password, db: db, retryStrategy: retryStrategy }], + args: [ + { + port: port, + host: host, + password: password, + db: db, + retryStrategy: retryStrategy + } + ], buildNew: true }, tasks: { konstructor: require('ioredis'), - args: [{ port: port, host: host, password: password, db: db, retryStrategy: retryStrategy }], + args: [ + { + port: port, + host: host, + password: password, + db: db, + retryStrategy: retryStrategy + } + ], buildNew: true } } diff --git a/examples/custom-server-actionhero/config/routes.js b/examples/custom-server-actionhero/config/routes.js index c126f8e5..3d386ba2 100644 --- a/examples/custom-server-actionhero/config/routes.js +++ b/examples/custom-server-actionhero/config/routes.js @@ -1,9 +1,7 @@ exports['default'] = { - routes: (api) => { + routes: api => { return { - get: [ - { path: '/', matchTrailingPathParts: true, action: 'render' } - ] + get: [{ path: '/', matchTrailingPathParts: true, action: 'render' }] } } } diff --git a/examples/custom-server-actionhero/config/servers/socket.js b/examples/custom-server-actionhero/config/servers/socket.js index f4c918d2..cb541979 100644 --- a/examples/custom-server-actionhero/config/servers/socket.js +++ b/examples/custom-server-actionhero/config/servers/socket.js @@ -2,9 +2,9 @@ exports['default'] = { servers: { - socket: (api) => { + socket: api => { return { - enabled: (process.env.ENABLE_TCP_SERVER !== undefined), + enabled: process.env.ENABLE_TCP_SERVER !== undefined, // TCP or TLS? secure: false, // Passed to tls.createServer if secure=true. Should contain SSL certificates @@ -26,7 +26,7 @@ exports['default'] = { exports.test = { servers: { - socket: (api) => { + socket: api => { return { enabled: true, port: 1001 + (process.pid % 64535), diff --git a/examples/custom-server-actionhero/config/servers/web.js b/examples/custom-server-actionhero/config/servers/web.js index 6ad3dd09..ccb10bfe 100644 --- a/examples/custom-server-actionhero/config/servers/web.js +++ b/examples/custom-server-actionhero/config/servers/web.js @@ -4,7 +4,7 @@ const os = require('os') exports['default'] = { servers: { - web: (api) => { + web: api => { return { enabled: true, // HTTP or HTTPS? @@ -13,7 +13,9 @@ exports['default'] = { serverOptions: {}, // Should we redirect all traffic to the first host in this array if hte request header doesn't match? // i.e.: [ 'https://www.site.com' ] - allowedRequestHosts: process.env.ALLOWED_HOSTS ? process.env.ALLOWED_HOSTS.split(',') : [], + allowedRequestHosts: process.env.ALLOWED_HOSTS + ? process.env.ALLOWED_HOSTS.split(',') + : [], // Port or Socket Path port: process.env.PORT || 8080, // Which IP to listen on (use '0.0.0.0' for all; '::' for all on ipv4 and ipv6) @@ -23,7 +25,8 @@ exports['default'] = { httpHeaders: { 'X-Powered-By': api.config.general.serverName, 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE', + 'Access-Control-Allow-Methods': + 'HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE', 'Access-Control-Allow-Headers': 'Content-Type' }, // Route that actions will be served from; secondary route against this route will be treated as actions, @@ -92,7 +95,7 @@ exports['default'] = { exports.production = { servers: { - web: (api) => { + web: api => { return { padding: null, metadataOptions: { @@ -106,7 +109,7 @@ exports.production = { exports.test = { servers: { - web: (api) => { + web: api => { return { secure: false, port: process.env.PORT || 1000 + (process.pid % 64535), diff --git a/examples/custom-server-actionhero/config/servers/websocket.js b/examples/custom-server-actionhero/config/servers/websocket.js index f72c0975..1800290d 100644 --- a/examples/custom-server-actionhero/config/servers/websocket.js +++ b/examples/custom-server-actionhero/config/servers/websocket.js @@ -4,7 +4,7 @@ exports['default'] = { servers: { - websocket: (api) => { + websocket: api => { return { enabled: true, // you can pass a FQDN (string) here or 'window.location.origin' @@ -55,7 +55,7 @@ exports['default'] = { exports['test'] = { servers: { - websocket: (api) => { + websocket: api => { return { clientUrl: null } } } diff --git a/examples/custom-server-actionhero/config/tasks.js b/examples/custom-server-actionhero/config/tasks.js index b5652c2e..0febe8aa 100644 --- a/examples/custom-server-actionhero/config/tasks.js +++ b/examples/custom-server-actionhero/config/tasks.js @@ -1,5 +1,5 @@ exports['default'] = { - tasks: (api) => { + tasks: api => { return { // Should this node run a scheduler to promote delayed tasks? scheduler: false, @@ -52,7 +52,7 @@ exports['default'] = { } exports.test = { - tasks: (api) => { + tasks: api => { return { timeout: 100, checkTimeout: 50 diff --git a/examples/custom-server-actionhero/initializers/next.js b/examples/custom-server-actionhero/initializers/next.js index 2297e70c..0f650552 100644 --- a/examples/custom-server-actionhero/initializers/next.js +++ b/examples/custom-server-actionhero/initializers/next.js @@ -1,5 +1,5 @@ 'use strict' -const {Initializer, api} = require('actionhero') +const { Initializer, api } = require('actionhero') const next = require('next') module.exports = class NextInitializer extends Initializer { @@ -10,18 +10,22 @@ module.exports = class NextInitializer extends Initializer { async initialize () { api.next = { - render: async (connection) => { - if (connection.type !== 'web') { throw new Error('Connections for NEXT apps must be of type "web"') } + render: async connection => { + if (connection.type !== 'web') { + throw new Error('Connections for NEXT apps must be of type "web"') + } const req = connection.rawConnection.req const res = connection.rawConnection.res return api.next.handle(req, res) } } - api.next.dev = (api.env === 'development') - if (api.next.dev) { api.log('Running next in development mode...') } + api.next.dev = api.env === 'development' + if (api.next.dev) { + api.log('Running next in development mode...') + } - api.next.app = next({dev: api.next.dev}) + api.next.app = next({ dev: api.next.dev }) api.next.handle = api.next.app.getRequestHandler() await api.next.app.prepare() } diff --git a/examples/custom-server-actionhero/pages/index.js b/examples/custom-server-actionhero/pages/index.js index d044fc1e..fe5882e3 100644 --- a/examples/custom-server-actionhero/pages/index.js +++ b/examples/custom-server-actionhero/pages/index.js @@ -3,7 +3,15 @@ import Link from 'next/link' export default () => ( ) diff --git a/examples/custom-server-express/pages/index.js b/examples/custom-server-express/pages/index.js index 5a892506..a369054a 100644 --- a/examples/custom-server-express/pages/index.js +++ b/examples/custom-server-express/pages/index.js @@ -3,13 +3,18 @@ import Link from 'next/link' export default () => (