Skip to content

Commit 37ede8c

Browse files
authored
Merge pull request #285 from thunderstore-io/preconstruct-rework
Use Preconstruct to manage monorepo
2 parents 899536a + 7e2cd75 commit 37ede8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3611
-5971
lines changed

.eslintrc.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,14 @@
2828
"rules": {
2929
"react/react-in-jsx-scope": "off",
3030
"react/prop-types": "off"
31-
}
31+
},
32+
"overrides": [
33+
{
34+
"files": "*.js",
35+
// rule overrides for js config files (next.config.js, etc.)
36+
"rules": {
37+
"@typescript-eslint/no-var-requires": "off"
38+
}
39+
}
40+
]
3241
}

.github/actions/get-node-version/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image already pulled on runners
2-
FROM node:14-alpine
2+
FROM node:16-alpine
33
WORKDIR /src
44
COPY package.json yarn.lock ./
55
RUN yarn install --frozen-lockfile

.github/actions/get-node-version/package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
"directory": ".github/actions/get-node-version"
66
},
77
"engines": {
8-
"node": "^14.17.0"
8+
"node": "^16.6.0"
99
},
1010
"scripts": {
1111
"build": "tsc"
1212
},
1313
"dependencies": {
1414
"@actions/core": "^1.4.0",
15-
"semver": "^7.3.5"
16-
},
17-
"devDependencies": {
18-
"@types/node": "^14.17.6",
15+
"@types/node": "^16.6.2",
1916
"@types/semver": "^7.3.8",
20-
"typescript": "4.3.5"
17+
"semver": "^7.3.5",
18+
"typescript": "^4.4.2"
2119
}
2220
}

.github/actions/get-node-version/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {readFileSync} from "fs";
2020
}
2121

2222
const typesVersionRangeString = semver.validRange(
23-
packageJson.devDependencies["@types/node"]
23+
packageJson.dependencies["@types/node"]
2424
);
2525
if (!typesVersionRangeString) {
2626
setFailed(`Invalid types version range: ${typesVersionRangeString}`);

.github/actions/get-node-version/yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.4.0.tgz#cf2e6ee317e314b03886adfeb20e448d50d6e524"
88
integrity sha512-CGx2ilGq5i7zSLgiiGUtBCxhRRxibJYU6Fim0Q1Wg2aQL2LTnF27zbqZOrxfvFQ55eSBW0L8uVStgtKMpa0Qlg==
99

10-
"@types/node@^14.17.6":
11-
version "14.17.6"
12-
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.6.tgz#cc61c8361c89e70c468cda464d1fa3dd7e5ebd62"
13-
integrity sha512-iBxsxU7eswQDGhlr3AiamBxOssaYxbM+NKXVil8jg9yFXvrfEFbDumLD/2dMTB+zYyg7w+Xjt8yuxfdbUHAtcQ==
10+
"@types/node@^16.6.2":
11+
version "16.11.10"
12+
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.10.tgz#2e3ad0a680d96367103d3e670d41c2fed3da61ae"
13+
integrity sha512-3aRnHa1KlOEEhJ6+CvyHKK5vE9BcLGjtUpwvqYLRvYNQKMfabu3BwfJaA/SLW8dxe28LsNDjtHwePTuzn3gmOA==
1414

1515
"@types/semver@^7.3.8":
1616
version "7.3.8"
@@ -31,10 +31,10 @@ semver@^7.3.5:
3131
dependencies:
3232
lru-cache "^6.0.0"
3333

34-
typescript@4.3.5:
35-
version "4.3.5"
36-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
37-
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
34+
typescript@^4.4.2:
35+
version "4.5.2"
36+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998"
37+
integrity sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==
3838

3939
yallist@^4.0.0:
4040
version "4.0.0"

.github/workflows/static-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- name: Install yarn dependencies
5353
run: yarn install
5454
- name: Run ESLint
55-
run: yarn run eslint nextjs thunderstore-components -f node_modules/@microsoft/eslint-formatter-sarif/sarif.js -o results.sarif || ":"
55+
run: yarn run eslint apps packages -f node_modules/@microsoft/eslint-formatter-sarif/sarif.js -o results.sarif || ":"
5656
- name: Upload SARIF
5757
uses: github/codeql-action/upload-sarif@v1
5858
with:

.github/workflows/test.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ jobs:
4747
yarn-${{ runner.os }}-
4848
- name: Install Yarn dependencies
4949
run: yarn install --frozen-lockfile
50-
- name: Build thunderstore-components
51-
run: |
52-
cd thunderstore-components
53-
yarn build
54-
- name: Build nextjs
55-
run: |
56-
cd nextjs
57-
yarn build
50+
- name: Build @thunderstore/components
51+
run: yarn workspace @thunderstore/components build
52+
- name: Build @thunderstore/nextjs
53+
run: yarn workspace @thunderstore/nextjs build

README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Thunderstore UI
2+
3+
Monorepo containing Next.js frontend for [thunderstore.io](https://thunderstore.io)
4+
and reusable UI components.
5+
6+
## Monorepo Setup
7+
8+
- [`yarn` workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) manages
9+
the packages in the monorepo (see `packages` key in base `package.json` file)
10+
and handles dependency installation/deduplication.
11+
- [`preconstruct`](https://preconstruct.tools/) automates building and linking
12+
the packages within the monorepo. Instead of using relative paths, local
13+
packages can be imported as if they were installed via a package manager.
14+
- Packages can be linked locally by running `yarn preconstruct dev`, but this
15+
is handled automatically by `postinstall` hook, so developers don't need to
16+
worry about it.
17+
18+
```
19+
// first time setup
20+
git clone git@github.com:thunderstore-io/thunderstore-ui.git thunderstore-ui
21+
cd thunderstore-ui
22+
yarn install
23+
24+
// start Next.js dev server
25+
yarn workspace @thunderstore/nextjs dev
26+
```
27+
28+
That's it. Changes done to `apps/nextjs` and `packages/components` should both
29+
be automatically visible at [http://localhost:3000/].
30+
31+
### Adding dependencies
32+
33+
To add new dependencies to existing packages, simply run something like:
34+
35+
```
36+
yarn workspace @thunderstore/components add react-table @types/react-table
37+
```
38+
39+
### Adding a new package
40+
41+
To add a completely new package, start by creating the following file structure:
42+
43+
```
44+
// packages/greeter/package.json:
45+
{
46+
"name": "@thunderstore/greeter",
47+
"version": "1.0.0",
48+
"description": "Example package"
49+
}
50+
51+
// packages/greeter/src/index.tsx:
52+
import React from "react";
53+
54+
export const Greeter: React.FC = () => <p>Hello, world!</p>;
55+
```
56+
57+
To add some required fields to the new package's `package.json`, run
58+
`yarn preconstruct init` and allow modifying `package.json` when asked.
59+
60+
To install dependencies, if any, run e.g.
61+
`yarn workspace @thunderstore/greeter add react react-dom @types/react`.
62+
63+
To "install" the new package to Next.js app, update the `dependencies` section
64+
in `apps/nextjs/package.json` with `"@thunderstore/greeter": "^1.0.0",`.
65+
66+
Then run `yarn` one more time to let Preconstruct work its magic. After that the
67+
new package should be usable in the Next.js app by simply importing it:
68+
69+
```
70+
import { Greeter } from "@thunderstore/greeter";
71+
```
72+
73+
### About VS Code...
74+
75+
VS Code may have problem detecting installed packages in this monorepo/workspace
76+
setup. Installing
77+
[Monorepo Workspace extension](https://marketplace.visualstudio.com/items?itemName=folke.vscode-monorepo-workspace)
78+
may solve them.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/types/global" />
33
/// <reference types="next/image-types/global" />
4+
5+
// NOTE: This file should not be edited
6+
// see https://nextjs.org/docs/basic-features/typescript for more information.

apps/nextjs/next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const withPreconstruct = require("@preconstruct/next");
2+
3+
module.exports = withPreconstruct();

apps/nextjs/package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@thunderstore/nextjs",
3+
"version": "0.1.0",
4+
"repository": "https://github.com/thunderstore-io/thunderstore-ui/tree/master/apps/nextjs",
5+
"private": true,
6+
"scripts": {
7+
"dev": "next dev",
8+
"build": "next build",
9+
"start": "next start"
10+
},
11+
"dependencies": {
12+
"@chakra-ui/react": "^1.6.8",
13+
"@emotion/react": "^11.4.1",
14+
"@emotion/styled": "^11.3.0",
15+
"@thunderstore/components": "^0.1.0",
16+
"@types/react": "^17.0.19",
17+
"framer-motion": "^4.1.17",
18+
"next": "^11.1.0",
19+
"react": "^17.0.2",
20+
"react-dom": "^17.0.2"
21+
},
22+
"devDependencies": {
23+
"@preconstruct/next": "^3.0.1",
24+
"eslint-config-next": "^11.1.2"
25+
}
26+
}

nextjs/pages/_app.tsx renamed to apps/nextjs/pages/_app.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppProps } from "next/app";
2-
import { RootWrapper, theme } from "thunderstore-components";
2+
import { RootWrapper, theme } from "@thunderstore/components";
33

44
function MyApp({ Component, pageProps }: AppProps): JSX.Element {
55
return (
File renamed without changes.

nextjs/pages/community-picker.tsx renamed to apps/nextjs/pages/community-picker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Community, MultiCommunityPicker } from "thunderstore-components";
1+
import { Community, MultiCommunityPicker } from "@thunderstore/components";
22
import React, { useState } from "react";
33
import { Box, Button, List, ListItem } from "@chakra-ui/react";
44

File renamed without changes.

nextjs/pages/package-upload.tsx renamed to apps/nextjs/pages/package-upload.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PackageUpload } from "thunderstore-components";
1+
import { PackageUpload } from "@thunderstore/components";
22
import React from "react";
33

44
const PackageUploadPage: React.FC<Record<string, never>> = () => {

nextjs/pages/team-picker.tsx renamed to apps/nextjs/pages/team-picker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TeamPicker } from "thunderstore-components";
1+
import { TeamPicker } from "@thunderstore/components";
22
import React, { useState } from "react";
33
import { Box, Button, Text } from "@chakra-ui/react";
44

File renamed without changes.
File renamed without changes.

nextjs/tsconfig.json renamed to apps/nextjs/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
},
2929
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
3030
"exclude": ["node_modules"],
31-
"references": [{ "path": "../thunderstore-components" }]
31+
"references": [{ "path": "../../packages/components" }]
3232
}

babel.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
"@babel/preset-env",
5+
{
6+
modules: false,
7+
loose: true,
8+
},
9+
],
10+
"@babel/preset-react",
11+
"@babel/preset-typescript",
12+
],
13+
plugins: ["@babel/plugin-transform-runtime"],
14+
};

nextjs/README.md

-11
This file was deleted.

nextjs/package.json

-18
This file was deleted.

0 commit comments

Comments
 (0)