Skip to content

Commit ecbe447

Browse files
committed
[DEVTOOLS-574] Cleanup. Refactor storybook config and example.
1 parent 36dc43b commit ecbe447

33 files changed

+2631
-3284
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# dependencies
22
/node_modules
33

4-
# Adding IDE folders to be ignored
5-
/.idea
4+
# misc
5+
.DS_Store
6+
*.pem
7+
.idea

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4+
# Run test command in the app service.
5+
cd services/app
46
npm test

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.12

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ git remote add origin git@github.com:forumone/[project-name].git
4242
##### No
4343

4444
Please remove:
45-
* `./services/app/stories`
4645
* `./services/app/.storybook`
4746
* In the `./services/app/package.json`, remove
4847
```
@@ -51,6 +50,7 @@ Please remove:
5150
"build-storybook": "build-storybook"
5251
...
5352
```
53+
* Uninstall the storybook related packages as well in `services/app/package.json`
5454
* Run `npm i --package-lock-only`
5555

5656
#### Do you need github action linting?

README.project.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,30 @@ Note that Next v11 comes with the following installed already:
1515
## Initial Setup
1616

1717

18-
1. Within `services/app`, copy `.env.local.example` to `.env.local` and define the following variables: `API_URL`, `SPACE_ID`, and `ACCESS_TOKEN` from the Contentful instance.
18+
1. Go to the `services/app` directory.
19+
```bash
20+
cd services/app
21+
```
22+
23+
1. Ensure that you are using the proper Node version for this app. We currently use v16. Assuming you have [nvm](https://github.com/nvm-sh/nvm) installed locally, you can simply run:
24+
```bash
25+
nvm use
26+
```
27+
This will set your Node version to match the `.nvmrc` file.
28+
29+
1. Next, install packages for local development:
30+
```bash
31+
npm ci
32+
```
33+
34+
1. Next, copy `.env.local.example` to `.env.local` and define any local environment variables you need for local development.
1935
```bash
2036
cp .env.local.example .env.local
2137
```
2238

23-
2. Then, go to the `services/app` directory and install packages for local use there:
39+
1. Now you are ready to start up the app. To do that, run `ddev start` from within the `services/app` directory:
2440
```bash
25-
cd services/app && ddev start
41+
ddev start
2642
```
2743

2844
## Starting and stopping the project

services/app/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ yarn-error.log*
3636

3737
# TypeScript
3838
tsconfig.tsbuildinfo
39+
40+
# Storybook build files
41+
storybook-static/

services/app/.storybook/main.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module.exports = {
2-
"stories": [
3-
"../stories/**/*.stories.mdx",
4-
"../stories/**/*.stories.@(js|jsx|ts|tsx)"
2+
staticDirs: ['../public/'],
3+
stories: ['../source/**/*.stories.@(js|jsx|ts|tsx)'],
4+
addons: [
5+
'@storybook/addon-links',
6+
'@storybook/addon-essentials',
7+
'@storybook/addon-interactions',
58
],
6-
"addons": [
7-
"@storybook/addon-links",
8-
"@storybook/addon-essentials",
9-
"@storybook/addon-interactions"
10-
],
11-
"framework": "@storybook/react",
12-
"core": {
13-
"builder": "@storybook/builder-webpack5"
14-
}
15-
}
9+
framework: '@storybook/react',
10+
core: {
11+
builder: '@storybook/builder-webpack5',
12+
},
13+
};

services/app/.storybook/preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export const parameters = {
2-
actions: { argTypesRegex: "^on[A-Z].*" },
2+
actions: { argTypesRegex: '^on[A-Z].*' },
33
controls: {
44
matchers: {
55
color: /(background|color)$/i,
66
date: /Date$/,
77
},
88
},
9-
}
9+
};

services/app/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Forum One Next.js Starter App
2+
3+
This is a starter app for [Next.js](https://nextjs.org/) (bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app)) that includes the following features:
4+
* [TypeScript](https://www.typescriptlang.org/)
5+
* [Emotion](https://emotion.sh/docs/introduction)
6+
* [ESLint](https://eslint.org/)
7+
* [Prettier](https://prettier.io/)
8+
9+
Note that Next v11 comes with the following installed already:
10+
* [Webpack v5](https://webpack.js.org/concepts/)
11+
* [Babel v7](https://babeljs.io/docs/en/)
12+
13+
## Getting Started
14+
15+
Ensure that you are using the proper Node version for this app. We currently use v16. Assuming you have [nvm](https://github.com/nvm-sh/nvm) installed locally, you can simply run:
16+
17+
```bash
18+
nvm use
19+
```
20+
21+
This will set your Node version to match the `.nvmrc` file.
22+
23+
Next, install packages:
24+
```bash
25+
npm ci
26+
```
27+
28+
To run the [development server](https://nextjs.org/docs/api-reference/cli#development):
29+
30+
```bash
31+
npm run dev
32+
```
33+
34+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
35+
36+
## Other Commands
37+
38+
### Build production application
39+
40+
```bash
41+
npm run build
42+
```
43+
Runs `next build`, which builds the production application in the `.next` folder. For more information, see the [Next.js CLI documentation](https://nextjs.org/docs/api-reference/cli#build).
44+
45+
### Start application in production mode
46+
47+
```bash
48+
npm run start
49+
```
50+
51+
Runs `next start`, which starts a Node.js server that supports [hybrid pages](https://nextjs.org/docs/basic-features/pages), serving both statically generated and server-side rendered pages. Note that `npm run build` should be ran first. For more information, see the [Next.js CLI documentation](https://nextjs.org/docs/api-reference/cli#production).
52+
53+
### Export application to static HTML
54+
55+
```bash
56+
npm run export
57+
```
58+
59+
Runs `next build && next export`. This allows you to export your app to static HTML (exported in the `out` folder), which can be run standalone without the need of a Node.js server. For more information, see the [Next.js Static HTML Export documentation](https://nextjs.org/docs/advanced-features/static-html-export).
60+
61+
### Run linter
62+
63+
```bash
64+
npm run lint
65+
```
66+
67+
Runs `next lint`, which runs the ESLint command. This is useful to catch lint errors that you might miss during development. For more information, see the [Next.js ESLint documentation](https://nextjs.org/docs/basic-features/eslint).
68+
69+
### Run prettier
70+
71+
#### Prettier check
72+
73+
```bash
74+
npm run prettier
75+
```
76+
77+
Runs `prettier --check`, which will check that all files within the `pages` and `source` directories use the Prettier code style from `.prettierrc`. This might be redundant with the `lint` script above, since it extends whatever Prettier rules we have set.
78+
79+
#### Prettier write
80+
81+
```bash
82+
npm run prettier:write
83+
```
84+
85+
Runs `prettier --write`, which will find and fix all prettier issues found within the `pages` and `source` directories. Note that this will automatically overwrite your files.
86+
87+
### Run TypeScript compiler (tsc)
88+
89+
```bash
90+
npm run tsc
91+
```
92+
93+
Runs `tsc --noEmit`, which will compile the TypeScript code without emitting files. This acts as a TS error check in your CLI. This is useful to catch TS errors that you might miss during development. For more information, see the [TypeScript Compiler (tsc) documentation](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
94+
95+
### Scaffold new component
96+
97+
```bash
98+
npm run component
99+
```
100+
Runs the `lib/component.js` script, which will scaffold a new React or Emotion component,
101+
with the option to include a Storybook story file as well.
102+
103+
## Husky
104+
105+
This project uses [Husky](https://typicode.github.io/husky/#/) to check code on git commits. By default, it is setup to use the `npm test` script which runs `lint` and `tsc` (TypeScript) checks against the codebase. This check occurs on `git commit` attempts. This helps developers catch errors _before_ pushing branches and creating PRs, quickening the overall dev worklow.
106+
107+
To bypass this check, you can use the `--no-verify` flag with your commit:
108+
109+
```bash
110+
git commit -m "This will not get checked by Husky." --no-verify
111+
```
112+
113+
Note that bypassing the Husky check is frowned upon.
114+
115+
## Notes
116+
117+
* Code for the app is currently configured to go into the `pages` directory (for [Next.js pages](https://nextjs.org/docs/basic-features/pages)) and `source` for theming, components, providers, helpers, etc.
118+
* Starting in Next.js v9.4, TypeScript errors do not show up in your browser when running the dev server (i.e. `npm run dev`). However, TS errors will prevent `next build` (i.e. `npm run build`) from running successfully. Be sure to run `npm run lint` and `npm run tsc` before committing and pushing code. This will give you lint and TS errors that will most likely cause your builds to fail.
119+
* For discussion: should we include a [TS checker in the config](https://github.com/vercel/next.js/issues/12735#issuecomment-629404102)? Note that a Next.js dev warns that [this will greatly slow development](https://github.com/vercel/next.js/issues/12735#issuecomment-629404842).
120+
* The current favicon implementation will probably not display correctly locally in Chrome (v94), but does display correctly in Firefox and Safari. Note that the favicon _does_ display correctly once deployed. Not sure why.

services/app/next.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/** @type {import('next').NextConfig} */
2-
31
const basePath = '';
42

3+
/** @type {import('next').NextConfig} */
54
module.exports = {
65
reactStrictMode: true,
76
basePath,

0 commit comments

Comments
 (0)