Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#966 nextjs example template #1009

Draft
wants to merge 30 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42d20d0
Switch to tsup for package builds + enable noImplicitAny #1018
Polleps Dec 2, 2024
41471d8
Enable noImplicitAny For @tomic/react #1018
Polleps Dec 2, 2024
3a43928
Upgrade @tomic/react to be compatible with react 19
Polleps Dec 9, 2024
c543d9d
Upgrade Databrowser to React 19 #1026
Polleps Dec 10, 2024
3ec32c8
feat: initial commit for atomic Next.js template #966
RoelLeijser Oct 21, 2024
774a3b2
Add webpack extension alias for .js extentions in Next.js config
RoelLeijser Oct 21, 2024
36768c0
Refactor MenuItem component
RoelLeijser Oct 21, 2024
e746d8b
Add blog page
RoelLeijser Oct 21, 2024
588141c
Add CurrentSubjectContext with errors
RoelLeijser Oct 21, 2024
f05e805
Start migrating to server components (breaking)
RoelLeijser Oct 22, 2024
0f6de05
Upgrade next to v15
RoelLeijser Oct 23, 2024
22eab73
Update template to server components
RoelLeijser Oct 23, 2024
4c0da26
Migrate to ESLint v9
RoelLeijser Oct 24, 2024
c99c472
Modified the Search functionality to server components with streaming
RoelLeijser Oct 24, 2024
25f7aaa
Refactor for client side
RoelLeijser Oct 31, 2024
064769a
Implement feedback
RoelLeijser Nov 5, 2024
1df794a
Update README.md
RoelLeijser Nov 6, 2024
c07c027
Move store
RoelLeijser Nov 6, 2024
fcda0f5
Enhance Next.js template
RoelLeijser Nov 7, 2024
09c1e21
Implement feedback and fixes
RoelLeijser Nov 11, 2024
53e7c6e
Add dynamic file extension handling in ontology index generation when…
RoelLeijser Nov 12, 2024
bd95072
Add cli support for Next.js template
RoelLeijser Nov 12, 2024
b8f01ed
Small fixes
RoelLeijser Nov 12, 2024
9124705
Refactor CSS styles and update navbar
RoelLeijser Nov 14, 2024
0815c3d
Refactor MenuItem components
RoelLeijser Nov 14, 2024
9bad3ca
Add deployment instructions for Netlify in README
RoelLeijser Nov 18, 2024
8595ab2
Refactor layout and context management
RoelLeijser Nov 18, 2024
8fe34f8
Refactor MenuItem components and update dependencies
RoelLeijser Dec 9, 2024
813e4db
Add deployment instructions for Netlify and Vercel to README, remove …
RoelLeijser Dec 9, 2024
53eed8f
Add nextjs-site template to documentation
RoelLeijser Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions browser/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ publish
.husky
.nohup
.swc
.tsup
*/lib
*/dist
*/dev-dist
Expand All @@ -26,3 +27,9 @@ data-browser/coverage
!.yarn/versions
.DS_Store
**/.trunk/*

**/tomic-lib-**.tgz
**/tomic-react-**.tgz
**/tomic-svelte-**.tgz
**/tomic-cli-**.tgz
**/tomic-create-template-**.tgz
5 changes: 5 additions & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ This changelog covers all five packages, as they are (for now) updated as a whol
- Added `store.preloadResourceTree()` method, see docs for more info.
- Fix generated ontologies not working in a Next.js server context.
- SEMI BREAKING CHANGE: When using generated types by cli, @tomic/lib now requires them to be generated by @tomic/cli v0.41.0 or above.
- Fix types masquerading as esm module in cjs build.

### @tomic/react

- Add cjs build.

### @tomic/cli

Expand Down
6 changes: 6 additions & 0 deletions browser/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ all:
BUILD +build
BUILD +test
BUILD +lint
BUILD +lint-package
BUILD +typedoc

deps:
Expand All @@ -18,6 +19,7 @@ deps:
COPY react/package.json react/.
COPY svelte/package.json svelte/.
COPY cli/package.json cli/.
COPY create-template/package.json create-template/.
RUN pnpm install --frozen-lockfile --shamefully-hoist
COPY . .

Expand All @@ -30,6 +32,10 @@ lint:
FROM +deps
RUN pnpm run lint

lint-package:
FROM +deps
RUN pnpm run lint-package

build:
FROM +deps
RUN pnpm run build
Expand Down
14 changes: 12 additions & 2 deletions browser/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
{
"version": "0.40.0",
"author": "Polle Pas",
"homepage": "https://docs.atomicdata.dev/js-cli",
"repository": {
"type": "git",
"url": "git+https://github.com/atomicdata-dev/atomic-server.git"
},
"bugs": {
"url": "https://github.com/atomicdata-dev/atomic-server/issues"
},
"dependencies": {
"@tomic/lib": "workspace:*",
"chalk": "^5.3.0",
"get-tsconfig": "^4.8.1",
"prettier": "3.0.3"
},
"devDependencies": {
"typescript": "^5.6.3"
},
"description": "",
"description": "Generate types from Atomic Data ontologies",
"license": "MIT",
"name": "@tomic/cli",
"publishConfig": {
Expand All @@ -19,7 +28,8 @@
"build": "tsc",
"lint": "eslint ./src --ext .js,.ts",
"lint-fix": "eslint ./src --ext .js,.ts --fix",
"prepublishOnly": "pnpm run build && pnpm run lint-fix",
"prepublishOnly": "pnpm run build && pnpm run lint && pnpm run lint-package",
"lint-package": "pnpm dlx publint",
"watch": "tsc --build --watch",
"start": "pnpm watch",
"tsc": "pnpm exec tsc --build",
Expand Down
6 changes: 3 additions & 3 deletions browser/cli/src/generateIndex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { store } from './store.js';
import { camelCaseify } from './utils.js';
import { camelCaseify, getExtension } from './utils.js';
import { atomicConfig } from './config.js';

enum Inserts {
Expand All @@ -16,7 +16,7 @@ const TEMPLATE = `

import { registerOntologies } from '${
// Prevents a circular dependency
atomicConfig._ISLIB_ ? '../ontology.js' : Inserts.MODULE_ALIAS
atomicConfig._ISLIB_ ? `../ontology${getExtension()}` : Inserts.MODULE_ALIAS
}';

${Inserts.IMPORTS}
Expand Down Expand Up @@ -57,4 +57,4 @@ export const generateIndex = (
};

const createImportLine = (name: string) =>
`import { ${name} } from './${name}.js';`;
`import { ${name} } from './${name}${getExtension()}';`;
7 changes: 7 additions & 0 deletions browser/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getTsconfig } from 'get-tsconfig';

export const camelCaseify = (str: string) =>
str.replace(/-([a-z])/g, g => {
return g[1].toUpperCase();
Expand All @@ -6,3 +8,8 @@ export const camelCaseify = (str: string) =>
export const dedupe = <T>(array: T[]): T[] => {
return Array.from(new Set(array));
};

export const getExtension = () =>
getTsconfig()?.config.compilerOptions?.moduleResolution === 'Bundler'
? ''
: '.js';
11 changes: 10 additions & 1 deletion browser/create-template/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"version": "0.40.0",
"author": "Polle Pas",
"homepage": "https://docs.atomicdata.dev/create-template/atomic-template",
"repository": {
"type": "git",
"url": "git+https://github.com/atomicdata-dev/atomic-server.git"
},
"bugs": {
"url": "https://github.com/atomicdata-dev/atomic-server/issues"
},
"dependencies": {
"@tomic/lib": "workspace:*",
"chalk": "^5.3.0",
Expand All @@ -20,7 +28,8 @@
"build": "tsc",
"lint": "eslint ./src --ext .js,.ts",
"lint-fix": "eslint ./src --ext .js,.ts --fix",
"prepublishOnly": "pnpm run build && pnpm run lint-fix",
"prepublishOnly": "pnpm run build && pnpm run lint && pnpm run lint-package",
"lint-package": "pnpm dlx publint",
"watch": "tsc --build --watch",
"start": "pnpm exec tsc --build --watch",
"tsc": "pnpm exec tsc --build",
Expand Down
8 changes: 8 additions & 0 deletions browser/create-template/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const baseTemplates = {

export const templates = {
'sveltekit-site': baseTemplates.website,
'nextjs-site': {
...baseTemplates.website,
generateEnv: ({ serverUrl }) => {
const siteSubject = `${serverUrl}/01j5zrevq917dp0wm4p2vnd7nr`;

return `NEXT_PUBLIC_ATOMIC_SERVER_URL=${serverUrl}\nNEXT_PUBLIC_WEBSITE_RESOURCE=${siteSubject}`;
},
},
} satisfies Record<string, BaseTemplate>;

export const isTemplate = (value: string): value is TemplateKey =>
Expand Down
36 changes: 36 additions & 0 deletions browser/create-template/templates/nextjs-site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
97 changes: 97 additions & 0 deletions browser/create-template/templates/nextjs-site/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Atomic Next.js Template

This repository is a [Next.js](https://nextjs.org/) 15 website starter template to be used with [AtomicServer](https://github.com/atomicdata-dev/atomic-server). For specific steps on how to deploy this template, see [DEPLOYING](./README/deploying.md).

## Getting started

This guide assumes you have AtomicServer running on your local machine. If you don't, you can follow the [AtomicServer installation guide](https://docs.atomicdata.dev/atomicserver/installation).

### 1. Create a new project

```bash
$ npm create @tomic/template my-project -- --template nextjs-site --server-url http://localhost:9883
$ pnpm create @tomic/template my-project --template nextjs-site --server-url http://localhost:9883
$ yarn create @tomic/template my-project --template nextjs-site --server-url http://localhost:9883
```

### 2. Generate ontologies

```bash
$ cd my-project
```

```bash
$ npx ad-generate ontologies
$ pnpm exec ad-generate ontologies
$ yarn ad-generate ontologies
```

After making changes to an ontology you need to re-generate them in your code.

### 3. Start the development server

```bash
$ npm run dev
$ pnpm dev
$ yarn dev
```

## Structure

Atomic Data resources are rendered by views.
These views are components that accept a resource as prop and render the data in a certain way.
For example the `BlogPostFullPage` view renders a `blog-post` resource as a full page.

Oftentimes these views also come with a kind of view selector component that determines what component to render based on the resources class.
An example of this would be `FullPageView`.

These selector components are great for when a resource can reference another resource without a classtype, meaning it can be any kind of resource.
For example, the `page` class has a `blocks` property that can reference any type of resource.
The FullPage view for the `page` class (`PageFullPage`) therefore renders a `BlockView` component that selects the appropriate component to render, i.e. a `TextBlock` or an `ImageGalleryBlock`.

## Deploying

### Deploying to Netlify

#### Prerequisites

- A [Netlify](https://www.netlify.com/) account
- A Git repository with your template project

#### UI

1. Click on the "Add new site" button and select "Import an existing project".
2. Choose your Git provider and select the repository where your project is located.
3. Add the environment variables required by your project

#### CLI

1. Install the Netlify CLI by running `npm install -g netlify-cli`.
2. Run `netlify login` and log in.
3. Run `netlify init` and select the repository you want to deploy.
4. Run `netlify deploy` to deploy the site.

### Deploying to Vercel

#### Prerequisites

- A [Vercel](https://vercel.com/) account
- A Git repository with your template project

#### UI

1. Click on the "Import Project" button and select the repository where your project is located.
2. Add the environment variables required by your project.

#### CLI

1. Install the Vercel CLI by running `npm install -g vercel`.
2. Run `vercel login` and log in.
3. Run `vercel` and select the repository you want to deploy.
4. Run `vercel --prod` to deploy the site to production.

## Resources

- [AtomicServer Docs](https://docs.atomicdata.dev/)
- [Next.js Docs](https://nextjs.org/docs)
- [Discord](https://discord.gg/a72Rv2P)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"outputFolder": "./src/ontologies",
"ontologies": ["<ONTOLOGY>"]
}
10 changes: 10 additions & 0 deletions browser/create-template/templates/nextjs-site/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat();

/** @type {import('eslint').ESLint.ConfigData} */
const eslintConfig = [
...compat.extends('next/core-web-vitals', 'next/typescript'),
];

export default eslintConfig;
12 changes: 12 additions & 0 deletions browser/create-template/templates/nextjs-site/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: config => {
config.resolve.extensionAlias = {
'.js': ['.ts', '.tsx', '.js'],
};

return config;
},
};

export default nextConfig;
35 changes: 35 additions & 0 deletions browser/create-template/templates/nextjs-site/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "nextjs-site",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"generate-ontologies": "ad-generate ontologies"
},
"dependencies": {
"@t3-oss/env-nextjs": "^0.11.1",
"@tomic/lib": "^0.40.0",
"@tomic/react": "^0.40.0",
"clsx": "^2.1.1",
"gray-matter": "^4.0.3",
RoelLeijser marked this conversation as resolved.
Show resolved Hide resolved
"modern-css-reset": "^1.4.0",
"next": "15.0.4",
"react": "19.0.0",
"react-dom": "19.0.0",
"remark": "^15.0.1",
RoelLeijser marked this conversation as resolved.
Show resolved Hide resolved
"remark-html": "^16.0.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@tomic/cli": "^0.40.0",
"@types/node": "^20",
"@types/react": "19.0.1",
"@types/react-dom": "19.0.1",
"eslint": "^9.13.0",
"eslint-config-next": "15.0.2",
"typescript": "^5"
}
}
Loading
Loading