Skip to content

Commit d0910c9

Browse files
authored
feat(create-rstack): add Nx template (#575)
1 parent 89a3f96 commit d0910c9

28 files changed

Lines changed: 425 additions & 33 deletions

‎packages/create-rstack/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ npx create-rstack --dir my-project --template app-vanilla-ts --no-git
5151
- `doc` - Basic documentation site
5252
- `doc-i18n` - Multilingual documentation site
5353
- `turborepo` - Turborepo
54+
- `nx` - Nx
5455

5556
## Documentation
5657

‎packages/create-rstack/src/index.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const templateNames = [
4444
'doc',
4545
'doc-i18n',
4646
'turborepo',
47+
'nx',
4748
];
4849

4950
const resolveTemplateName = (template: string): string => {
@@ -56,7 +57,7 @@ const resolveTemplateName = (template: string): string => {
5657

5758
const getTemplateName = async ({ template }: Argv): Promise<string> => {
5859
if (typeof template === 'string') {
59-
if (/^(?:app|lib|doc|turborepo)(?:-|$)/u.test(template)) {
60+
if (/^(?:app|lib|doc|turborepo|nx)(?:-|$)/u.test(template)) {
6061
return resolveTemplateName(template);
6162
}
6263

@@ -79,7 +80,10 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
7980
const monorepoType = checkCancel<string>(
8081
await select({
8182
message: 'Select monorepo tool',
82-
options: [{ value: 'turborepo', label: 'Turborepo', hint: 'pnpm' }],
83+
options: [
84+
{ value: 'turborepo', label: 'Turborepo', hint: 'pnpm' },
85+
{ value: 'nx', label: 'Nx', hint: 'pnpm' },
86+
],
8387
}),
8488
);
8589

@@ -235,6 +239,6 @@ await create({
235239
builtinTools: [],
236240
getTemplateName,
237241
getPackageManager: ({ templateName }) =>
238-
templateName === 'turborepo' ? 'pnpm' : undefined,
242+
['turborepo', 'nx'].includes(templateName) ? 'pnpm' : undefined,
239243
onGitResolved: injectStagedSetup,
240244
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Nx + Rstack
2+
3+
## Setup
4+
5+
```bash
6+
pnpm install
7+
```
8+
9+
## Structure
10+
11+
- `apps/web`: React application.
12+
- `packages/ui`: Shared UI components.
13+
- `tsconfig.base.json`: Shared TypeScript configuration.
14+
15+
## Scripts
16+
17+
Run from the repository root:
18+
19+
- `pnpm run build`: Build all packages.
20+
- `pnpm run dev`: Start the web app and watch the shared UI package.
21+
- `pnpm run test`: Run tests.
22+
- `pnpm run check`: Run lint, formatting, and TypeScript checks.
23+
- `pnpm run lint`: Lint the workspace.
24+
- `pnpm run format`: Format the workspace.
25+
26+
Nx discovers projects and tasks from workspace package manifests. Build and test tasks are cached, and dependencies are built first.
27+
28+
Run `pnpm run build` before `pnpm run check`.
29+
30+
Use `pnpm exec nx graph` to explore the project graph.
31+
32+
## Learn more
33+
34+
- [Rstack CLI monorepo guide](https://rstack.rs/guide/monorepo)
35+
- [Nx documentation](https://nx.dev/docs/getting-started/intro)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "web",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "rs build",
8+
"dev": "rs dev",
9+
"preview": "rs preview",
10+
"test": "rs test"
11+
},
12+
"dependencies": {
13+
"@repo/ui": "workspace:^",
14+
"react": "^19.3.0",
15+
"react-dom": "^19.3.0"
16+
},
17+
"devDependencies": {
18+
"@rsbuild/plugin-react": "^2.1.1",
19+
"@testing-library/dom": "^10.4.2",
20+
"@testing-library/jest-dom": "^7.0.1",
21+
"@testing-library/react": "^16.3.3",
22+
"@types/react": "^19.3.0",
23+
"@types/react-dom": "^19.3.0",
24+
"happy-dom": "^21.0.1"
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Configuration guide: https://rstack.rs/config
2+
import { define } from 'rstack';
3+
4+
define.app(async () => {
5+
const { pluginReact } = await import('@rsbuild/plugin-react');
6+
return {
7+
plugins: [pluginReact()],
8+
};
9+
});
10+
11+
define.test({
12+
setupFiles: ['./tests/rstest.setup.ts'],
13+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Button } from '@repo/ui/button';
2+
3+
export function App() {
4+
return (
5+
<main>
6+
<h1>Web</h1>
7+
<p>Nx + Rstack CLI</p>
8+
<p>Edit apps/web/src/App.tsx to get started.</p>
9+
<Button onClick={() => window.alert('Hello from @repo/ui!')}>
10+
Shared button
11+
</Button>
12+
<nav>
13+
<a href="https://rstack.rs">Rstack documentation</a>
14+
</nav>
15+
</main>
16+
);
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
body {
2+
margin: 0;
3+
font-family: system-ui, sans-serif;
4+
color: #202124;
5+
background: #f8f9fa;
6+
}
7+
8+
main {
9+
max-width: 640px;
10+
margin: 15vh auto;
11+
padding: 24px;
12+
}
13+
14+
button {
15+
padding: 10px 16px;
16+
border: 0;
17+
border-radius: 8px;
18+
color: white;
19+
background: #5755d9;
20+
cursor: pointer;
21+
}
22+
23+
nav {
24+
display: flex;
25+
gap: 20px;
26+
margin-top: 24px;
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { StrictMode } from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { App } from './App';
4+
import './index.css';
5+
6+
const root = document.getElementById('root');
7+
if (root) {
8+
createRoot(root).render(
9+
<StrictMode>
10+
<App />
11+
</StrictMode>,
12+
);
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from 'rstack/test';
2+
import { render, screen } from '@testing-library/react';
3+
import { App } from '../src/App';
4+
5+
test('renders the web app with the shared UI package', () => {
6+
render(<App />);
7+
expect(screen.getByRole('heading', { name: 'Web' })).toBeInTheDocument();
8+
expect(
9+
screen.getByRole('button', { name: 'Shared button' }),
10+
).toBeInTheDocument();
11+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { expect } from 'rstack/test';
2+
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';
3+
4+
expect.extend(jestDomMatchers);

0 commit comments

Comments
 (0)