├── BabyHippoGram.png
├── public
├── favicon.ico
├── manifest.json
└── index.html
├── src
├── Components
│ ├── Layout.js
│ ├── Container.js
│ ├── Card.js
│ └── Header.js
├── App.test.js
├── index.css
├── index.js
├── App.css
├── App.js
├── logo.svg
└── serviceWorker.js
├── .gitignore
├── config2.yml
├── LICENSE
├── package.json
├── .circleci
└── config.yml
└── README.md
/BabyHippoGram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CircleCI-Public/circleci-demo-javascript-react-app/HEAD/BabyHippoGram.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CircleCI-Public/circleci-demo-javascript-react-app/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/Components/Layout.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default class Layout extends React.Component {
4 | render() {
5 |
6 | return (
7 |
8 | { this.props.children }
9 |
10 | );
11 | }
12 | }
--------------------------------------------------------------------------------
/src/Components/Container.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default class Container extends React.Component {
4 | render() {
5 | return (
6 |
7 | { this.props.children }
8 |
9 | );
10 | }
11 | }
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 | // import the React Test Renderer
5 | import { create } from "react-test-renderer";
6 | // test card state renders
7 |
8 | it('renders without crashing', () => {
9 | const div = document.createElement('div');
10 | ReactDOM.render(, div);
11 | ReactDOM.unmountComponentAtNode(div);
12 | });
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 | /test-results
11 |
12 | # production
13 | /build
14 |
15 | # misc
16 | .DS_Store
17 | .env.local
18 | .env.development.local
19 | .env.test.local
20 | .env.production.local
21 |
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
6 | sans-serif;
7 | -webkit-font-smoothing: antialiased;
8 | -moz-osx-font-smoothing: grayscale;
9 | }
10 |
11 | code {
12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
13 | monospace;
14 | }
15 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(, document.getElementById('root'));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
11 | // Learn more about service workers: https://bit.ly/CRA-PWA
12 | serviceWorker.unregister();
13 |
--------------------------------------------------------------------------------
/src/Components/Card.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const Cards = ({ cards }) => {
4 | console.log({cards})
5 |
6 | return (
7 |
8 | {cards.map((card) => (
9 |
10 | { card.data.crosspost_parent == null && card.data.media == null ?
11 |
12 |

13 |
14 | : ""
15 | }
16 |
17 | ))}
18 |
19 | )
20 | }
21 |
22 | export default Cards
--------------------------------------------------------------------------------
/config2.yml:
--------------------------------------------------------------------------------
1 | orbs:
2 | circle-node: circleci/node@4.7.0
3 | docker: circleci/docker@2.0.1
4 | continuation: circleci/continuation@0.2.0
5 |
6 | default-executor: &default-executor
7 | executor:
8 | name: 'circle-node/default'
9 |
10 | runner-executor: &runner-executor
11 | machine: true
12 | resource_class: jkg-runner/jkg-resource-class
13 |
14 | version: 2.1
15 |
16 | setup: true
17 |
18 | jobs:
19 | checking-branch:
20 | <<: *default-executor
21 | steps:
22 | - checkout
23 | - run:
24 | command: |
25 | if [ << pipeline.git.branch >> != "main" ]; then
26 | exit 1
27 | fi
28 | - continuation/continue:
29 | configuration_path: config2.yml
30 | workflows:
31 | run-if-main:
32 | jobs:
33 | - checking-branch
34 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | animation: App-logo-spin infinite 20s linear;
7 | height: 40vmin;
8 | pointer-events: none;
9 | }
10 |
11 | .App-header {
12 | background-color: #282c34;
13 | min-height: 100vh;
14 | display: flex;
15 | flex-direction: column;
16 | align-items: center;
17 | justify-content: center;
18 | font-size: calc(10px + 2vmin);
19 | color: white;
20 | }
21 |
22 | .App-link {
23 | color: #61dafb;
24 | }
25 |
26 | @keyframes App-logo-spin {
27 | from {
28 | transform: rotate(0deg);
29 | }
30 | to {
31 | transform: rotate(360deg);
32 | }
33 | }
34 |
35 | li {
36 | list-style-type: none;
37 | margin: 0;
38 | padding: 0;
39 | }
40 |
41 | .container {
42 | margin-top: 75px;
43 | }
44 |
45 | .card {
46 | padding-right: 20px;
47 | border: none;
48 | }
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import './App.css';
3 |
4 | import Layout from './Components/Layout';
5 | import Header from './Components/Header';
6 | import Container from './Components/Container';
7 | import Card from './Components/Card';
8 |
9 |
10 | class App extends Component {
11 | render() {
12 | return (
13 |
14 |
15 |
16 |
17 |
18 |
19 | );
20 | }
21 |
22 | state = {
23 | cards: []
24 | };
25 |
26 | componentDidMount() {
27 | fetch('https://www.reddit.com/r/babyhippos/hot/.json?count=20')
28 | .then(res => res.json())
29 | .then((data) => {
30 | console.log(data.data.children);
31 | this.setState({ cards: data.data.children })
32 | })
33 | .catch(console.log)
34 | }
35 | }
36 |
37 | export default App;
38 |
--------------------------------------------------------------------------------
/src/Components/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default class Header extends React.Component {
4 | render() {
5 | return (
6 |
20 | );
21 | }
22 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Circle Internet Services, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "circleci-demo-javascript-create-react-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "react": "^16.13.1",
7 | "react-dom": "^16.13.1",
8 | "react-scripts": "^5.0.0"
9 | },
10 | "scripts": {
11 | "start": "react-scripts start",
12 | "build": "export NODE_OPTIONS=--openssl-legacy-provider; react-scripts build",
13 | "test": "react-scripts test --maxWorkers=2 --ci --coverage --reporters=default --reporters=jest-junit",
14 | "eject": "react-scripts eject"
15 | },
16 | "eslintConfig": {
17 | "extends": "react-app"
18 | },
19 | "browserslist": {
20 | "production": [
21 | ">0.2%",
22 | "not dead",
23 | "not op_mini all"
24 | ],
25 | "development": [
26 | "last 1 chrome version",
27 | "last 1 firefox version",
28 | "last 1 safari version"
29 | ]
30 | },
31 | "devDependencies": {
32 | "jest-junit": "^10.0.0",
33 | "react-test-renderer": "^17.0.1"
34 | },
35 | "jest-junit": {
36 | "suiteName": "jest tests",
37 | "outputDirectory": ".",
38 | "outputName": "test-results/junit.xml",
39 | "classNameTemplate": "{classname}-{title}",
40 | "titleTemplate": "{classname}-{title}",
41 | "ancestorSeparator": " › ",
42 | "usePathForSuiteName": "true"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 | orbs:
3 | node: circleci/node@4.7.0
4 | heroku: circleci/heroku@1.2.6
5 |
6 | jobs:
7 | build_and_test:
8 | docker:
9 | - image: cimg/node:17.2.0
10 | steps:
11 | - checkout
12 | - node/install-packages:
13 | pkg-manager: yarn
14 | - run:
15 | command: yarn test
16 | name: Run tests
17 | - run:
18 | command: yarn build
19 | name: Build app
20 | - persist_to_workspace:
21 | root: ~/project
22 | paths:
23 | - .
24 | deploy: # this can be any name you choose
25 | docker:
26 | - image: cimg/node:17.2.0
27 | steps:
28 | - attach_workspace:
29 | at: ~/project
30 | - heroku/deploy-via-git:
31 | force: true # force push when pushing to the heroku remote, see: https://devcenter.heroku.com/articles/git
32 |
33 | workflows:
34 | on_commit:
35 | jobs:
36 | - build_and_test
37 | # Follow instructions here to authenticate git for Heroku: https://devcenter.heroku.com/articles/git#http-git-authentication
38 | # The following code may be uncommented, onnce HEROKU_API_KEY & HEROKU_APP_NAME environemnt variables are present
39 | # Read more: https://circleci.com/docs/2.0/env-vars/
40 | # - deploy:
41 | # requires:
42 | # - build_and_test # only deploy if the build_and_test job has completed
43 | # filters:
44 | # branches:
45 | # only: master # only deploy when on main/master
46 | nightly:
47 | triggers:
48 | - schedule:
49 | cron: "0 0 * * *"
50 | filters:
51 | branches:
52 | only:
53 | - master
54 | jobs:
55 | - build_and_test
56 | # Follow instructions here to authenticate git for Heroku: https://devcenter.heroku.com/articles/git#http-git-authentication
57 | # The following code may be uncommented, onnce HEROKU_API_KEY & HEROKU_APP_NAME environemnt variables are present
58 | # Read more: https://circleci.com/docs/2.0/env-vars/
59 | # - deploy:
60 | # requires:
61 | # - build_and_test # only deploy if the build_and_test job has completed
62 | # filters:
63 | # branches:
64 | # only: master # only deploy when on main/master
65 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
22 | React App
23 |
24 |
25 |
26 |
27 |
28 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Quickstart: Demo JavaScript Node.js Reference Project
2 | We maintain a reference JavaScript Node.js project to show how to build an Express.js app on CircleCI with version: 2.1 configuration:
3 | [Demo JavaScript Node Project on GitHub](https://github.com/CircleCI-Public/circleci-demo-javascript-react-app)
4 | [Demo JavaScript Node Project building on CircleCI](https://app.circleci.com/pipelines/github/CircleCI-Public/circleci-demo-javascript-react-app)
5 |
6 | In the project you will find a CircleCI configuration file .circleci/config.yml. This file shows best practice for using version 2.1 config with Node projects.
7 | Build the Demo JavaScript Node Project Yourself
8 | A good way to start using CircleCI is to build a project yourself. Here’s how to build the demo project with your own account:
9 | Fork the project on GitHub to your own account.
10 | Go to the Add Projects page in the CircleCI application and click the Set Up Project button next to the project you just forked.
11 | To make changes you can edit the .circleci/config.yml file and make a commit. When you push a commit to GitHub, CircleCI will build and test the project.
12 |
13 | # Sample Configuration
14 | Below is the .circleci/config.yml file in the demo project.
15 |
16 | ```
17 | version: 2.1
18 | orbs:
19 | node: circleci/node@4.7.0
20 | heroku: circleci/heroku@1.2.6
21 |
22 | jobs:
23 | build_and_test:
24 | docker:
25 | - image: cimg/node:17.2.0
26 | steps:
27 | - checkout
28 | - node/install-packages:
29 | pkg-manager: yarn
30 | - run:
31 | command: yarn test
32 | name: Run tests
33 | - run:
34 | command: yarn build
35 | name: Build app
36 | - persist_to_workspace:
37 | root: ~/project
38 | paths:
39 | - .
40 | deploy: # this can be any name you choose
41 | docker:
42 | - image: cimg/node:17.2.0
43 | steps:
44 | - attach_workspace:
45 | at: ~/project
46 | - heroku/deploy-via-git:
47 | force: true # force push when pushing to the heroku remote, see: https://devcenter.heroku.com/articles/git
48 |
49 | workflows:
50 | on_commit:
51 | jobs:
52 | - build_and_test
53 | - deploy:
54 | requires:
55 | - build_and_test # only deploy if the build_and_test job has completed
56 | filters:
57 | branches:
58 | only: master # only deploy when on main/master
59 | nightly:
60 | triggers:
61 | - schedule:
62 | cron: "0 0 * * *"
63 | filters:
64 | branches:
65 | only:
66 | - master
67 | - docs-node-js-language-guide
68 | jobs:
69 | - build_and_test
70 | - deploy:
71 | requires:
72 | - build_and_test # only deploy if the build_and_test job has completed
73 | filters:
74 | branches:
75 | only: master # only deploy when on main/master
76 | ```
77 |
78 | # Config Walkthrough
79 | By using the [Node orb](https://circleci.com/orbs/registry/orb/circleci/node#jobs-test), it sets an executor from CircleCI's highly cached convenience images built for CI and allows you to set the version of NodeJS to use. Any available tag from this list can be used: https://hub.docker.com/r/cimg/node/tags.
80 |
81 | The Node Orb test command will test your code with a one-line command, with optional parameters.
82 |
83 | Matrix jobs are a simple way to test your Node app on various node environments. For a more in depth example of how the Node orb utilizes matrix jobs, see our blog on [matrix jobs](https://circleci.com/blog/circleci-matrix-jobs/). See [documentation on pipeline parameters](https://circleci.com/docs/2.0/pipeline-variables/#pipeline-parameters-in-configuration) to learn how to set a node version via Pipeline parameters.
84 |
85 | Success! You just set up a Node.js app to build on CircleCI with version: 2.1 configuration. Check out our project’s Job page to see how this looks when building on CircleCI.
86 |
87 |
88 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------