Skip to content

Commit 36a762b

Browse files
committed
feat: prisma db connector (#47)
* style: layout and github link button * feat: prisma * chore(release): 1.4.0 * docs: roadmap * fix: cache hash key * ci(caches): remove unused conf
1 parent 174c754 commit 36a762b

31 files changed

+451
-221
lines changed

.env

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HOSTNAME=localhost
2+
PORT=3000
3+
# https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser
4+
NEXT_PUBLIC_HOST=http://$HOSTNAME:$PORT
5+
# You can start with this url, but you may need to configure your own database as this is only an example with a read only user !
6+
DATABASE_URL=postgresql://baby_kirby:1234@kirby.cgqxnhhl7oal.eu-west-3.rds.amazonaws.com:5432/kirby?schema=public

.github/workflows/tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
.next
4949
node_modules
5050
~/.cache/Cypress
51-
key: ${{ runner.os }}-build-
51+
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
5252
restore-keys: |
5353
${{ runner.os }}-node_modules-
5454
@@ -86,7 +86,7 @@ jobs:
8686
.next
8787
node_modules
8888
~/.cache/Cypress
89-
key: ${{ runner.os }}-build-
89+
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
9090
restore-keys: |
9191
${{ runner.os }}-build-
9292
@@ -121,7 +121,7 @@ jobs:
121121
.next
122122
node_modules
123123
~/.cache/Cypress
124-
key: ${{ runner.os }}-build-
124+
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
125125
restore-keys: |
126126
${{ runner.os }}-build-
127127

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,8 @@ yarn-error.log*
6868
# apollo
6969
graphql-schema.json
7070

71+
# prisma
72+
prisma/migrations
73+
7174
# lhci
7275
.lighthouseci

CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## 1.4.0 (2021-05-03)
6+
7+
### Features
8+
9+
- prisma ([1961a6b](https://github.com/FabienGreard/kirby-boilerplate/commit/1961a6b5f1b49941ffbde81ea737c8abdd8602f1))
10+
511
## 1.3.0 (2021-04-10)
612

713
### Features
814

9-
- graphQL ([#36](https://github.com/FabienGreard/kirby-boilerplate/issues/36)) ([3083241](https://github.com/FabienGreard/kirby-boilerplate/commit/c9078cb88cd34e617dd3e2564515f351dfdf4223))
15+
- graphQL ([#36](https://github.com/FabienGreard/kirby-boilerplate/issues/36)) ([5381151](https://github.com/FabienGreard/kirby-boilerplate/commit/538115108802804256f16b6ed2ed0ec74efbe4f2))
1016

1117
## 1.2.0 (2021-03-22)
1218

1319
### Features
1420

15-
- design-system ([#7](https://github.com/FabienGreard/kirby-boilerplate/issues/7)) ([cc4c825](https://github.com/FabienGreard/kirby-boilerplate/commit/cc4c8259c1afff4b60350a1a4b7eb7dec43cfdda))
21+
- design-system ([#7](https://github.com/FabienGreard/kirby-boilerplate/issues/7)) ([bf61341](https://github.com/FabienGreard/kirby-boilerplate/commit/bf613412bcaa781a7b65f342b053ecc0dbe13ff9)), closes [#16](https://github.com/FabienGreard/kirby-boilerplate/issues/16) [#15](https://github.com/FabienGreard/kirby-boilerplate/issues/15) [#11](https://github.com/FabienGreard/kirby-boilerplate/issues/11) [#12](https://github.com/FabienGreard/kirby-boilerplate/issues/12) [#14](https://github.com/FabienGreard/kirby-boilerplate/issues/14) [#17](https://github.com/FabienGreard/kirby-boilerplate/issues/17) [#21](https://github.com/FabienGreard/kirby-boilerplate/issues/21) [#22](https://github.com/FabienGreard/kirby-boilerplate/issues/22) [#20](https://github.com/FabienGreard/kirby-boilerplate/issues/20) [#18](https://github.com/FabienGreard/kirby-boilerplate/issues/18) [#26](https://github.com/FabienGreard/kirby-boilerplate/issues/26) [#25](https://github.com/FabienGreard/kirby-boilerplate/issues/25) [#23](https://github.com/FabienGreard/kirby-boilerplate/issues/23) [#19](https://github.com/FabienGreard/kirby-boilerplate/issues/19) [#24](https://github.com/FabienGreard/kirby-boilerplate/issues/24) [#31](https://github.com/FabienGreard/kirby-boilerplate/issues/31) [#30](https://github.com/FabienGreard/kirby-boilerplate/issues/30) [#29](https://github.com/FabienGreard/kirby-boilerplate/issues/29) [#27](https://github.com/FabienGreard/kirby-boilerplate/issues/27) [#28](https://github.com/FabienGreard/kirby-boilerplate/issues/28) [#32](https://github.com/FabienGreard/kirby-boilerplate/issues/32) [#33](https://github.com/FabienGreard/kirby-boilerplate/issues/33) [#34](https://github.com/FabienGreard/kirby-boilerplate/issues/34) [#35](https://github.com/FabienGreard/kirby-boilerplate/issues/35)
1622

1723
## 1.1.0 (2021-03-21)
1824

README.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Start by cloning this repository, then use either `yarn install` or `npm install
2121

2222
## Getting Started
2323

24-
First, run the development server:
24+
First look at the `.env` file. (you can start with the default)
25+
26+
Then, run the development server:
2527

2628
```bash
2729
npm run dev
@@ -52,6 +54,10 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the
5254
| bump:major | standard-version --release-as major --no-verify | v.0.0.0 => v.1.0.0 |
5355
| apollo:download | npx apollo service:download --endpoint=http://localhost:3000/api/graphql graphql-schema.json | download a graphql schema from an endpoint |
5456
| apollo:generate | npx apollo codegen:generate types --localSchemaFile=graphql-schema.json --target=typescript --tagName=gql --outputFlat --tsFileExtension=d.ts | use for generating typing files from a graphql schema |
57+
| ts-node | ts-node --compiler-options '{\"module\":\"CommonJS\"}' | use by prisma:seed |
58+
| prisma:migrate | prisma migrate dev | prisma database schema migration tool |
59+
| prisma:seed | prisma db seed --preview-feature | prisma database seed tool |
60+
| prisma:generate | prisma generate | generate prisma client |
5561
| clear | node scripts/clear.js | clear node_modules and \*lock |
5662
| prepare | husky install | This is needed from husky to set up the project |
5763

@@ -61,6 +67,7 @@ This project is build with :
6167

6268
- [NextJs](https://nextjs.org/)
6369
- [Apollo](https://www.apollographql.com/)
70+
- [prisma](https://www.prisma.io/)
6471
- [Tailwindcss](https://tailwindcss.com/)
6572
- [Typescript](https://www.typescriptlang.org/)
6673
- [react-intl](https://formatjs.io/)
@@ -110,12 +117,39 @@ Given the [conventionalcommits](https://www.conventionalcommits.org/en/v1.0.0/):
110117
[optional footer(s)]
111118
```
112119

120+
## Setting up your own database (e.g. PostgreSQL, MySQL, SQL Server)
121+
122+
If you want to use another database than PostgreSQL, you can adjust the database connection in [`prisma/schema.prisma`](hhttps://github.com/FabienGreard/kirby-boilerplate/tree/main/prisma/schema.prisma) by reconfiguring the datasource block.
123+
124+
Learn more about the different connection configurations in the [docs](https://www.prisma.io/docs/reference/database-reference/connection-urls).
125+
126+
At this point your should be able to execute `yarn prisma:migrate` or `npm run prisma:migrate` to initialise your database with the base schema.
127+
128+
You could also seed your database with `yarn prisma:seed` or `npm run prisma:seed`.
129+
113130
## Generate typing from graphql schema
114131

115132
You may need to look at [apollo-tooling](https://github.com/apollographql/apollo-tooling)
116133

117134
With the graphql endpoint running launch `yarn apollo:download` follow by `yarn apollo:generate`, this will create under `types` a typing file for each query under `apollo/operations`.
118135

136+
## Hosting
137+
138+
Kirby use [vercel](https://vercel.com/docs) however you can use any other hosting service.
139+
140+
## Roadmap:
141+
142+
(Would love Pull requests that build towards these objectives)
143+
144+
- [ ] Add a CLI installer like cra / cna
145+
- [ ] Multiple install with opt-out feature e.f without apollo, with monorepo etc...
146+
- [ ] Monorepo
147+
- [ ] Without server / api (remove apollo)
148+
- [ ] More installer ??
149+
- [ ] Better doc ?
150+
- [ ] Feature projects build with Kirby
151+
- [ ] Feature contributors
152+
119153
## Contributing
120154

121155
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

apollo/resolvers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import prisma from 'prisma/index';
2+
13
export default {
24
Query: {
35
viewer() {
4-
return { id: 1, name: 'Kirby Doe' };
6+
return prisma.user.findFirst();
57
},
68
},
79
};

components/Head.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import NextHead from 'next/head';
22

3-
import { SEO } from 'utils/constant';
3+
import { SEO, HOST } from 'utils/constant';
44

55
interface Props {
66
title?: string;
@@ -12,6 +12,9 @@ export default function Head({ title = SEO.title, description = SEO.description
1212
<NextHead>
1313
<title>{title}</title>
1414
<meta name="description" content={description} />
15+
<meta property="og:title" content={title} />
16+
<meta property="og:description" content={description} />
17+
<meta property="og:image" content={`${HOST}/images/og-image.png`} />
1518
<link rel="icon" href="/favicon.ico" />
1619
<link rel="manifest" href="/manifest.json" />
1720
<meta name="theme-color" content="#fff" />

components/Icons/Github.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
interface Props extends React.SVGProps<SVGSVGElement> {
2+
size?: number;
3+
color?: string;
4+
}
5+
6+
export default function SvgGithub({ size = 64, color, ...props }: Props) {
7+
return (
8+
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 496 512" {...props}>
9+
<path
10+
className={`fill-current ${color ?? 'text-white'}`}
11+
d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"
12+
/>
13+
</svg>
14+
);
15+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render } from '@testing-library/react';
2+
3+
import GithubSVG from 'components/Icons/Github';
4+
5+
describe('ReactSVG', () => {
6+
it('Should match snapshots', () => {
7+
const { container } = render(<GithubSVG />);
8+
9+
expect(container).toMatchSnapshot();
10+
});
11+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ReactSVG Should match snapshots 1`] = `
4+
<div>
5+
<svg
6+
height="64"
7+
viewBox="0 0 496 512"
8+
width="64"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
11+
<path
12+
class="fill-current text-white"
13+
d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"
14+
/>
15+
</svg>
16+
</div>
17+
`;

components/Layout.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useIntl } from 'react-intl';
2+
3+
import Head from 'components/Head';
4+
import GithubSVG from 'components/Icons/Github';
5+
import { withLink } from 'components/Link';
6+
7+
import Button from 'design-system/Button';
8+
9+
import { VERSION, GITHUB_URL } from 'utils/constant';
10+
11+
import * as langs from 'langs';
12+
13+
const ButtonWithLink = withLink(Button);
14+
15+
const Header = () => {
16+
const { formatMessage } = useIntl();
17+
18+
return (
19+
<header>
20+
<a href={GITHUB_URL} target="_blank" rel="noreferrer">
21+
<Button
22+
label={formatMessage({ id: 'githubLinkMessage' })}
23+
icon={<GithubSVG size={24} />}
24+
size="small"
25+
className="space-x-2"
26+
primary
27+
/>
28+
</a>
29+
</header>
30+
);
31+
};
32+
33+
const Footer = () => {
34+
const { formatDate } = useIntl();
35+
36+
const Langs = () => (
37+
<div className="flex justify-center space-x-1">
38+
{Object.keys(langs).map(lang => (
39+
<ButtonWithLink key={lang} locale={lang} href="/" label={lang} size="small" />
40+
))}
41+
</div>
42+
);
43+
44+
return (
45+
<footer className="text-xs md:text-sm space-y-1">
46+
<Langs />
47+
<p>{`v.${VERSION} - ${formatDate(Date.now())}`}</p>
48+
</footer>
49+
);
50+
};
51+
52+
export default function Layout({ children }) {
53+
return (
54+
<div className="flex flex-col h-screen items-center justify-between p-1 md:p-2">
55+
<Head />
56+
<Header />
57+
<main>{children}</main>
58+
<Footer />
59+
</div>
60+
);
61+
}

components/__tests__/Layout.test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { render } from 'utils/customTestRender';
2+
import Layout from 'components/Layout';
3+
4+
describe('Layout', () => {
5+
test('Should render a Layout element', () => {
6+
const { getByText, getByTestId } = render(
7+
<Layout>
8+
<h1 data-testid="title">Title</h1>
9+
</Layout>,
10+
);
11+
12+
expect(getByText('Title')).toBeInTheDocument();
13+
expect(getByTestId('title')).toBeInTheDocument();
14+
});
15+
});

design-system/Button.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export interface ButtonProps {
2323
* Optional className overidel
2424
*/
2525
className?: string;
26+
/**
27+
* Optional icon component
28+
*/
29+
icon?: JSX.Element;
2630
}
2731

2832
/**
@@ -33,12 +37,13 @@ export const Button: React.FC<ButtonProps> = ({
3337
size = 'medium',
3438
backgroundColor,
3539
className,
40+
icon = null,
3641
label,
3742
...props
3843
}) => {
39-
const BASE_BUTTON = 'uppercase tracking-wider box-border';
44+
const BASE_BUTTON = 'flex items-center uppercase tracking-wider box-border';
4045
const PRIMARY_BUTTON = `${BASE_BUTTON} bg-primary-600 border border-primary-600 text-white focus:outline-none focus:bg-primary-900 focus:border-primary-900 hover:bg-primary-900 hover:border-primary-900`;
41-
const SECONDARY_BUTTON = `${BASE_BUTTON} border bg-white text-primary-600 border-primary-600 text-black focus:outline-none focus:text-primary-900 focus:border-primary-900 hover:border-primary-900 hover:text-primary-900`;
46+
const SECONDARY_BUTTON = `${BASE_BUTTON} bg-white border border-primary-600 text-primary-600 focus:outline-none focus:text-primary-900 focus:border-primary-900 hover:border-primary-900 hover:text-primary-900`;
4247

4348
const SIZE_BUTTON = {
4449
small: 'rounded-sm text-sm px-2 py-1',
@@ -53,7 +58,8 @@ export const Button: React.FC<ButtonProps> = ({
5358
style={{ backgroundColor }}
5459
{...props}
5560
>
56-
{label}
61+
{icon}
62+
<p>{label}</p>
5763
</button>
5864
);
5965
};

0 commit comments

Comments
 (0)