Skip to content

Commit 5a5ab3d

Browse files
committed
Initial commit
1 parent 949aa00 commit 5a5ab3d

34 files changed

+8640
-0
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
"next/babel"
4+
],
5+
"plugins": [
6+
]
7+
}

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
out
2+
3+
.DS_Store
4+
*.swp
5+
*.swo
6+
7+
node_modules/
8+
.next/
9+
10+
yarn-error.log
11+
12+
.bsb.lock
13+
.merlin
14+
lib/

.nowignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.next/
2+
node_modules/

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Reason NextJS Workshop
2+
3+
This repo will be the starting point for building some Reason app.
4+
5+
## Setup
6+
7+
```
8+
git clone https://github.com/ryyppy/reason-workshop-nextjs
9+
cd reason-workshop-nextjs
10+
yarn
11+
12+
# Initial build
13+
yarn bs:build
14+
15+
yarn dev
16+
17+
# Open localhost:3000
18+
```
19+
20+
In case you want to run BuckleScript in watchmode:
21+
22+
```
23+
yarn run bs:start
24+
```
25+
26+
## Useful commands
27+
28+
Build CSS seperately via `postcss` (useful for debugging)
29+
30+
```
31+
# Devmode
32+
postcss styles/main.css -o test.css
33+
34+
# Production
35+
NODE_ENV=production postcss styles/main.css -o test.css
36+
```

bindings/Next.bs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
3+
import * as Block from "bs-platform/lib/es6/block.js";
4+
5+
var Link = /* module */Block.localModule([], []);
6+
7+
var Router = /* module */Block.localModule([], []);
8+
9+
var Head = /* module */Block.localModule([], []);
10+
11+
var $$Error = /* module */Block.localModule([], []);
12+
13+
export {
14+
Link ,
15+
Router ,
16+
Head ,
17+
$$Error ,
18+
19+
}
20+
/* No side effect */

bindings/Next.re

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
type getInitialPropsFn('a) =
2+
{
3+
.
4+
"query": Js.Dict.t(string),
5+
"req": Js.Nullable.t(Js.t('a)),
6+
} =>
7+
Js.Promise.t(Js.t('a));
8+
9+
module Link = {
10+
[@bs.module "next/link"] [@react.component]
11+
external make:
12+
(
13+
~href: string=?,
14+
~_as: string=?,
15+
~prefetch: bool=?,
16+
~replace: option(bool)=?,
17+
~shallow: option(bool)=?,
18+
~passHref: option(bool)=?,
19+
~children: React.element
20+
) =>
21+
React.element =
22+
"default";
23+
};
24+
25+
module Router = {
26+
type props = {. "router": {. "query": Js.Dict.t(string)}};
27+
28+
[@bs.module "next/router"]
29+
external withRouter: (props => React.element) => React.element = "";
30+
};
31+
32+
module Head = {
33+
[@bs.module "next/head"] [@react.component]
34+
external make: (~children: React.element) => React.element = "default";
35+
};
36+
37+
module Error = {
38+
[@bs.module "next/head"] [@react.component]
39+
external make: (~statusCode: int, ~children: React.element) => React.element =
40+
"default";
41+
};

bsconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "reason-workshop-nextjs",
3+
"namespace": false,
4+
"reason": { "react-jsx": 3 },
5+
"refmt": 3,
6+
"bs-dependencies": ["reason-react", "bs-fetch", "@glennsl/bs-json"],
7+
"ppx-flags": ["graphql_ppx/ppx"],
8+
"sources": [
9+
{ "dir": "common" },
10+
{ "dir": "bindings" },
11+
{ "dir": "pages", "subdirs": true },
12+
{ "dir": "components", "subdirs": true },
13+
"layouts"
14+
],
15+
"package-specs": {
16+
"module": "es6",
17+
"in-source": true
18+
},
19+
"suffix": ".bs.js",
20+
"bsc-flags": ["-bs-no-version-header", "-bs-super-errors", "-bs-g"],
21+
"gentypeconfig": {
22+
"language": "typescript",
23+
"shims": [],
24+
"module": "es6"
25+
}
26+
}

common/Mdx.bs.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
3+
import * as $$Text from "../components/Text.bs.js";
4+
import * as Block from "bs-platform/lib/es6/block.js";
5+
6+
var $$default = {
7+
p: $$Text.Md[/* P */3][/* make */0],
8+
li: $$Text.Md[/* Li */7][/* make */3],
9+
h1: $$Text.H1[/* make */0],
10+
h2: $$Text.H2[/* make */0],
11+
h3: $$Text.H3[/* make */0],
12+
h4: $$Text.H4[/* make */0],
13+
h5: $$Text.H5[/* make */0],
14+
ul: $$Text.Md[/* Ul */5][/* make */0],
15+
ol: $$Text.Md[/* Ol */6][/* make */0],
16+
inlineCode: $$Text.Md[/* InlineCode */2][/* make */0],
17+
code: $$Text.Md[/* Code */1][/* make */0],
18+
pre: $$Text.Md[/* Pre */0][/* make */0],
19+
a: $$Text.Md[/* A */4][/* make */2]
20+
};
21+
22+
var Components = /* module */Block.localModule(["default"], [$$default]);
23+
24+
var Provider = /* module */Block.localModule([], []);
25+
26+
export {
27+
Components ,
28+
Provider ,
29+
30+
}
31+
/* Text Not a pure module */

common/Mdx.re

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module Components = {
2+
open Text;
3+
type props = {. "children": ReasonReact.reactElement};
4+
5+
[@bs.deriving abstract]
6+
type t = {
7+
[@bs.optional]
8+
p: React.component(props),
9+
[@bs.optional]
10+
li: React.component(props),
11+
[@bs.optional]
12+
h1: React.component(props),
13+
[@bs.optional]
14+
h2: React.component(props),
15+
[@bs.optional]
16+
h3: React.component(props),
17+
[@bs.optional]
18+
h4: React.component(props),
19+
[@bs.optional]
20+
h5: React.component(props),
21+
[@bs.optional]
22+
ul: React.component(props),
23+
[@bs.optional]
24+
ol: React.component(props),
25+
[@bs.optional]
26+
inlineCode: React.component(props),
27+
[@bs.optional]
28+
code:
29+
React.component({
30+
.
31+
"className": option(string),
32+
"metastring": string,
33+
"children": array(ReasonReact.reactElement),
34+
}),
35+
[@bs.optional]
36+
pre: React.component(props),
37+
[@bs.optional]
38+
a:
39+
React.component({
40+
.
41+
"children": ReasonReact.reactElement,
42+
"href": string,
43+
}),
44+
};
45+
46+
/* Sets our preferred branded styles
47+
We most likely will never need a different ~components
48+
option on our website. */
49+
let default =
50+
t(
51+
~p=Md.P.make,
52+
~li=Md.Li.make,
53+
~h1=H1.make,
54+
~h2=H2.make,
55+
~h3=H3.make,
56+
~h4=H4.make,
57+
~h5=H5.make,
58+
~ul=Md.Ul.make,
59+
~ol=Md.Ol.make,
60+
~a=Md.A.make,
61+
~pre=Md.Pre.make,
62+
~inlineCode=Md.InlineCode.make,
63+
~code=Md.Code.make,
64+
(),
65+
);
66+
};
67+
68+
module Provider = {
69+
[@bs.module "@mdx-js/react"] [@react.component]
70+
external make:
71+
(~components: Components.t, ~children: ReasonReact.reactElement=?) =>
72+
React.element =
73+
"MDXProvider";
74+
};

common/Util.bs.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
import * as Block from "bs-platform/lib/es6/block.js";
4+
5+
function s(prim) {
6+
return prim;
7+
}
8+
9+
function ate(prim) {
10+
return prim;
11+
}
12+
13+
var ReactStuff = /* module */Block.localModule([
14+
"s",
15+
"ate"
16+
], [
17+
s,
18+
ate
19+
]);
20+
21+
export {
22+
ReactStuff ,
23+
24+
}
25+
/* No side effect */

common/Util.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ReactStuff = {
2+
let s = ReasonReact.string;
3+
let ate = ReasonReact.array;
4+
};

common/highlight.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from "react";
2+
import Highlight, { defaultProps } from "prism-react-renderer";
3+
4+
export const jsExample = `
5+
const a = "test";
6+
7+
function foo(a){
8+
console.log("hello world: " + a);
9+
}
10+
11+
foo(a)
12+
}
13+
`;
14+
15+
export const reasonExample = `let foo = 1;
16+
17+
let add = (a, b) => a + b;
18+
19+
let add1 = add(foo);`;
20+
21+
export default ({code, language}) => {
22+
return (
23+
<Highlight {...defaultProps} code={code} language={language}>
24+
{({ className, style, tokens, getLineProps, getTokenProps }) => (
25+
<pre className={className + " py-4 px-4"} style={style}>
26+
{tokens.map((line, i) => (
27+
<div {...getLineProps({ line, key: i })}>
28+
{line.map((token, key) => (
29+
<span {...getTokenProps({ token, key })} />
30+
))}
31+
</div>
32+
))}
33+
</pre>
34+
)}
35+
</Highlight>
36+
);
37+
};

0 commit comments

Comments
 (0)