@oss-ma/tpl 1.0.31 → 1.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/resources/templates/react-next/files/env.example +10 -0
- package/resources/templates/react-next/files/gitignore +19 -0
- package/resources/templates/react-next/files/jest.config.ts +15 -0
- package/resources/templates/react-next/files/next.config.mjs +0 -0
- package/resources/templates/react-next/files/package.json +50 -0
- package/resources/templates/react-next/files/src/app/globals.css +18 -0
- package/resources/templates/react-next/files/src/app/layout.tsx +32 -0
- package/resources/templates/react-next/files/src/app/loading.tsx +7 -0
- package/resources/templates/react-next/files/src/app/not-found.tsx +13 -0
- package/resources/templates/react-next/files/src/app/page.tsx +13 -0
- package/resources/templates/react-next/files/src/features/example/ExampleFeature.tsx +74 -0
- package/resources/templates/react-next/files/src/features/example/store.ts +15 -0
- package/resources/templates/react-next/files/src/lib/QueryProvider.tsx +26 -0
- package/resources/templates/react-next/files/src/shared/ui/Button.test.tsx +21 -0
- package/resources/templates/react-next/files/src/shared/ui/Button.tsx +34 -0
- package/resources/templates/react-next/files/src/tests/setup.ts +1 -0
- package/resources/templates/react-next/files/tsconfig.json +24 -0
- package/resources/templates/react-next/template.yaml +37 -0
- package/resources/templates/react-ts/files/src/features/example/ExampleFeature.tsx +0 -6
- package/resources/templates/react-ts/files/src/pages/HomePage.tsx +0 -6
package/package.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Application
|
|
2
|
+
NEXT_PUBLIC_APP_NAME={{appName}}
|
|
3
|
+
NEXT_PUBLIC_APP_VERSION=0.1.0
|
|
4
|
+
|
|
5
|
+
# API
|
|
6
|
+
NEXT_PUBLIC_API_BASE_URL=https://api.example.com
|
|
7
|
+
|
|
8
|
+
# Server-side only (never exposed to browser)
|
|
9
|
+
# DATABASE_URL=postgresql://user:password@localhost:5432/mydb
|
|
10
|
+
# SECRET_KEY=your-secret-key
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Config } from "jest";
|
|
2
|
+
import nextJest from "next/jest.js";
|
|
3
|
+
|
|
4
|
+
const createJestConfig = nextJest({ dir: "./" });
|
|
5
|
+
|
|
6
|
+
const config: Config = {
|
|
7
|
+
coverageProvider: "v8",
|
|
8
|
+
testEnvironment: "jsdom",
|
|
9
|
+
setupFilesAfterFramework: ["<rootDir>/src/tests/setup.ts"],
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
"^@/(.*)$": "<rootDir>/src/$1",
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default createJestConfig(config);
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{appName}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start",
|
|
9
|
+
"lint": "next lint",
|
|
10
|
+
"format": "prettier -w .",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"test": "jest --passWithNoTests",
|
|
13
|
+
"test:watch": "jest --watch",
|
|
14
|
+
"test:coverage": "jest --coverage",
|
|
15
|
+
"prepare": "husky",
|
|
16
|
+
"audit": "npm audit --audit-level=high"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"next": "^15.1.0",
|
|
20
|
+
"react": "^19.0.0",
|
|
21
|
+
"react-dom": "^19.0.0"{{#if state}},
|
|
22
|
+
"zustand": "^5.0.0"{{/if}}{{#if fetching}},
|
|
23
|
+
"@tanstack/react-query": "^5.56.0"{{/if}}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@commitlint/cli": "^19.3.0",
|
|
27
|
+
"@commitlint/config-conventional": "^19.2.0",{{#if fetching}}
|
|
28
|
+
"@tanstack/react-query-devtools": "^5.56.0",{{/if}}
|
|
29
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
30
|
+
"@testing-library/react": "^16.0.0",
|
|
31
|
+
"@testing-library/user-event": "^14.5.0",
|
|
32
|
+
"@types/jest": "^29.5.0",
|
|
33
|
+
"@types/node": "^20.0.0",
|
|
34
|
+
"@types/react": "^19.0.0",
|
|
35
|
+
"@types/react-dom": "^19.0.0",
|
|
36
|
+
"eslint": "^8.57.0",
|
|
37
|
+
"eslint-config-next": "^15.1.0",
|
|
38
|
+
"husky": "^9.0.0",
|
|
39
|
+
"jest": "^29.7.0",
|
|
40
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
41
|
+
"lint-staged": "^15.2.0",
|
|
42
|
+
"prettier": "^3.3.0",
|
|
43
|
+
"ts-jest": "^29.2.0",
|
|
44
|
+
"typescript": "^5.5.0"
|
|
45
|
+
},
|
|
46
|
+
"lint-staged": {
|
|
47
|
+
"*.{ts,tsx,js,jsx,json,md,yml,yaml}": ["prettier -w"],
|
|
48
|
+
"*.{ts,tsx,js,jsx}": ["eslint --fix"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
*,
|
|
2
|
+
*::before,
|
|
3
|
+
*::after {
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:root {
|
|
10
|
+
font-family: Inter, system-ui, sans-serif;
|
|
11
|
+
line-height: 1.5;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
min-height: 100vh;
|
|
16
|
+
background: #0a0a0a;
|
|
17
|
+
color: #ededed;
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Metadata } from "next";
|
|
2
|
+
import { Inter } from "next/font/google";
|
|
3
|
+
{{#if fetching}}
|
|
4
|
+
import { QueryProvider } from "@/lib/QueryProvider";
|
|
5
|
+
{{/if}}
|
|
6
|
+
import "./globals.css";
|
|
7
|
+
|
|
8
|
+
const inter = Inter({ subsets: ["latin"] });
|
|
9
|
+
|
|
10
|
+
export const metadata: Metadata = {
|
|
11
|
+
title: "{{appName}}",
|
|
12
|
+
description: "Generated by @oss-ma/tpl",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function RootLayout({
|
|
16
|
+
children,
|
|
17
|
+
}: {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
}) {
|
|
20
|
+
return (
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<body className={inter.className}>
|
|
23
|
+
{{#if fetching}}
|
|
24
|
+
<QueryProvider>{children}</QueryProvider>
|
|
25
|
+
{{/if}}
|
|
26
|
+
{{#unless fetching}}
|
|
27
|
+
{children}
|
|
28
|
+
{{/unless}}
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Link from "next/link";
|
|
2
|
+
|
|
3
|
+
export default function NotFound() {
|
|
4
|
+
return (
|
|
5
|
+
<main style={{ padding: "2rem", textAlign: "center" }}>
|
|
6
|
+
<h1>404</h1>
|
|
7
|
+
<p>Page not found.</p>
|
|
8
|
+
<Link href="/" style={{ marginTop: "1rem", display: "inline-block" }}>
|
|
9
|
+
Go home
|
|
10
|
+
</Link>
|
|
11
|
+
</main>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExampleFeature } from "@/features/example/ExampleFeature";
|
|
2
|
+
|
|
3
|
+
export default function HomePage() {
|
|
4
|
+
return (
|
|
5
|
+
<main style={{ padding: "2rem", maxWidth: 800, margin: "0 auto" }}>
|
|
6
|
+
<h1>{{appName}}</h1>
|
|
7
|
+
<p style={{ marginTop: "0.5rem", opacity: 0.7 }}>
|
|
8
|
+
Next.js 14 · App Router · TypeScript
|
|
9
|
+
</p>
|
|
10
|
+
<ExampleFeature />
|
|
11
|
+
</main>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
{{#if fetching}}
|
|
4
|
+
import { useQuery } from "@tanstack/react-query";
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if state}}
|
|
7
|
+
import { useCounterStore } from "./store";
|
|
8
|
+
{{/if}}
|
|
9
|
+
import { Button } from "@/shared/ui/Button";
|
|
10
|
+
{{#if fetching}}
|
|
11
|
+
|
|
12
|
+
interface Post {
|
|
13
|
+
id: number;
|
|
14
|
+
title: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function fetchPosts(): Promise<Post[]> {
|
|
18
|
+
const res = await fetch(
|
|
19
|
+
"https://jsonplaceholder.typicode.com/posts?_limit=3",
|
|
20
|
+
{ cache: "no-store" }
|
|
21
|
+
);
|
|
22
|
+
if (!res.ok) throw new Error("Failed to fetch posts");
|
|
23
|
+
return res.json();
|
|
24
|
+
}
|
|
25
|
+
{{/if}}
|
|
26
|
+
|
|
27
|
+
export function ExampleFeature() {
|
|
28
|
+
{{#if state}}
|
|
29
|
+
const { count, increment, decrement, reset } = useCounterStore();
|
|
30
|
+
{{/if}}
|
|
31
|
+
{{#if fetching}}
|
|
32
|
+
const { data: posts, isLoading, isError } = useQuery({
|
|
33
|
+
queryKey: ["posts"],
|
|
34
|
+
queryFn: fetchPosts,
|
|
35
|
+
});
|
|
36
|
+
{{/if}}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<section style={{ marginTop: "2rem" }}>
|
|
40
|
+
{{#if state}}
|
|
41
|
+
<div style={{ marginBottom: "2rem" }}>
|
|
42
|
+
<h2>Counter (Zustand)</h2>
|
|
43
|
+
<p style={{ fontSize: "2rem", margin: "0.5rem 0" }}>{count}</p>
|
|
44
|
+
<div style={{ display: "flex", gap: "0.5rem" }}>
|
|
45
|
+
<Button onClick={decrement}>−</Button>
|
|
46
|
+
<Button onClick={increment}>+</Button>
|
|
47
|
+
<Button onClick={reset} variant="secondary">Reset</Button>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
{{/if}}
|
|
51
|
+
{{#if fetching}}
|
|
52
|
+
<div>
|
|
53
|
+
<h2>Posts (TanStack Query)</h2>
|
|
54
|
+
{isLoading && <p>Loading...</p>}
|
|
55
|
+
{isError && <p>Error loading posts.</p>}
|
|
56
|
+
{posts && (
|
|
57
|
+
<ul style={{ marginTop: "0.5rem", paddingLeft: "1.2rem" }}>
|
|
58
|
+
{posts.map((post) => (
|
|
59
|
+
<li key={post.id} style={{ marginBottom: "0.25rem" }}>
|
|
60
|
+
{post.title}
|
|
61
|
+
</li>
|
|
62
|
+
))}
|
|
63
|
+
</ul>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
{{/if}}
|
|
67
|
+
{{#unless state}}
|
|
68
|
+
{{#unless fetching}}
|
|
69
|
+
<p>Feature module — add your components here.</p>
|
|
70
|
+
{{/unless}}
|
|
71
|
+
{{/unless}}
|
|
72
|
+
</section>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
interface CounterState {
|
|
4
|
+
count: number;
|
|
5
|
+
increment: () => void;
|
|
6
|
+
decrement: () => void;
|
|
7
|
+
reset: () => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useCounterStore = create<CounterState>((set) => ({
|
|
11
|
+
count: 0,
|
|
12
|
+
increment: () => set((state) => ({ count: state.count + 1 })),
|
|
13
|
+
decrement: () => set((state) => ({ count: state.count - 1 })),
|
|
14
|
+
reset: () => set({ count: 0 }),
|
|
15
|
+
}));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
|
+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
|
|
7
|
+
export function QueryProvider({ children }: { children: React.ReactNode }) {
|
|
8
|
+
const [queryClient] = useState(
|
|
9
|
+
() =>
|
|
10
|
+
new QueryClient({
|
|
11
|
+
defaultOptions: {
|
|
12
|
+
queries: {
|
|
13
|
+
staleTime: 1000 * 60 * 5,
|
|
14
|
+
retry: 1,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<QueryClientProvider client={queryClient}>
|
|
22
|
+
{children}
|
|
23
|
+
<ReactQueryDevtools initialIsOpen={false} />
|
|
24
|
+
</QueryClientProvider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
2
|
+
import { Button } from "@/shared/ui/Button";
|
|
3
|
+
|
|
4
|
+
describe("Button", () => {
|
|
5
|
+
it("renders children", () => {
|
|
6
|
+
render(<Button>Click me</Button>);
|
|
7
|
+
expect(screen.getByRole("button", { name: /click me/i })).toBeInTheDocument();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("calls onClick when clicked", () => {
|
|
11
|
+
const handler = jest.fn();
|
|
12
|
+
render(<Button onClick={handler}>Click</Button>);
|
|
13
|
+
fireEvent.click(screen.getByRole("button"));
|
|
14
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("is disabled when disabled prop is set", () => {
|
|
18
|
+
render(<Button disabled>Disabled</Button>);
|
|
19
|
+
expect(screen.getByRole("button")).toBeDisabled();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ButtonHTMLAttributes } from "react";
|
|
4
|
+
|
|
5
|
+
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
6
|
+
variant?: "primary" | "secondary";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Button({
|
|
10
|
+
variant = "primary",
|
|
11
|
+
children,
|
|
12
|
+
style,
|
|
13
|
+
...props
|
|
14
|
+
}: ButtonProps) {
|
|
15
|
+
const base: React.CSSProperties = {
|
|
16
|
+
padding: "0.4rem 1rem",
|
|
17
|
+
borderRadius: 6,
|
|
18
|
+
border: "none",
|
|
19
|
+
cursor: "pointer",
|
|
20
|
+
fontWeight: 500,
|
|
21
|
+
fontSize: "0.9rem",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const variants: Record<string, React.CSSProperties> = {
|
|
25
|
+
primary: { background: "#646cff", color: "#fff" },
|
|
26
|
+
secondary: { background: "#3a3a3a", color: "#fff" },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<button style={{ ...base, ...variants[variant], ...style }} {...props}>
|
|
31
|
+
{children}
|
|
32
|
+
</button>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2017",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"jsx": "preserve",
|
|
15
|
+
"incremental": true,
|
|
16
|
+
"plugins": [{ "name": "next" }],
|
|
17
|
+
"baseUrl": ".",
|
|
18
|
+
"paths": {
|
|
19
|
+
"@/*": ["./src/*"]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
23
|
+
"exclude": ["node_modules"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: react-next
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
description: "Next.js 14 App Router + TypeScript with optional state and fetching"
|
|
4
|
+
engine: "v1"
|
|
5
|
+
|
|
6
|
+
questions:
|
|
7
|
+
- name: appName
|
|
8
|
+
message: "Nom du projet ?"
|
|
9
|
+
default: "my-next-app"
|
|
10
|
+
|
|
11
|
+
- name: packageManager
|
|
12
|
+
message: "Package manager ?"
|
|
13
|
+
choices: ["npm", "pnpm", "yarn"]
|
|
14
|
+
default: "npm"
|
|
15
|
+
|
|
16
|
+
- name: state
|
|
17
|
+
message: "State management ?"
|
|
18
|
+
choices: ["zustand", "none"]
|
|
19
|
+
default: "zustand"
|
|
20
|
+
|
|
21
|
+
- name: fetching
|
|
22
|
+
message: "Data fetching ?"
|
|
23
|
+
choices: ["tanstack-query", "none"]
|
|
24
|
+
default: "tanstack-query"
|
|
25
|
+
|
|
26
|
+
hooks:
|
|
27
|
+
postGenerate:
|
|
28
|
+
- run: "git init"
|
|
29
|
+
|
|
30
|
+
- run: "npm install --ignore-scripts"
|
|
31
|
+
when: "{{packageManager}} == npm"
|
|
32
|
+
|
|
33
|
+
- run: "pnpm install --ignore-scripts"
|
|
34
|
+
when: "{{packageManager}} == pnpm"
|
|
35
|
+
|
|
36
|
+
- run: "yarn install --ignore-scripts"
|
|
37
|
+
when: "{{packageManager}} == yarn"
|
|
@@ -24,7 +24,6 @@ export function ExampleFeature() {
|
|
|
24
24
|
const { count, increment, decrement, reset } = useCounterStore();
|
|
25
25
|
{{/if}}
|
|
26
26
|
{{#if fetching}}
|
|
27
|
-
|
|
28
27
|
const { data: posts, isLoading, isError } = useQuery({
|
|
29
28
|
queryKey: ["posts"],
|
|
30
29
|
queryFn: fetchPosts,
|
|
@@ -60,11 +59,6 @@ export function ExampleFeature() {
|
|
|
60
59
|
)}
|
|
61
60
|
</div>
|
|
62
61
|
{{/if}}
|
|
63
|
-
{{#unless state}}
|
|
64
|
-
{{#unless fetching}}
|
|
65
|
-
<p>Feature module — add your components here.</p>
|
|
66
|
-
{{/unless}}
|
|
67
|
-
{{/unless}}
|
|
68
62
|
</section>
|
|
69
63
|
);
|
|
70
64
|
}
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
import { ExampleFeature } from "@/features/example/ExampleFeature";
|
|
3
3
|
{{/if}}
|
|
4
4
|
{{#unless state}}
|
|
5
|
-
{{#unless fetching}}
|
|
6
5
|
import { Button } from "@/shared/ui/Button";
|
|
7
6
|
import { useState } from "react";
|
|
8
7
|
{{/unless}}
|
|
9
|
-
{{/unless}}
|
|
10
8
|
|
|
11
9
|
export function HomePage() {
|
|
12
10
|
{{#unless state}}
|
|
13
|
-
{{#unless fetching}}
|
|
14
11
|
const [msg, setMsg] = useState<string | null>(null);
|
|
15
12
|
{{/unless}}
|
|
16
|
-
{{/unless}}
|
|
17
13
|
|
|
18
14
|
return (
|
|
19
15
|
<main style={{ padding: "2rem", maxWidth: 800, margin: "0 auto" }}>
|
|
@@ -25,13 +21,11 @@ export function HomePage() {
|
|
|
25
21
|
<ExampleFeature />
|
|
26
22
|
{{/if}}
|
|
27
23
|
{{#unless state}}
|
|
28
|
-
{{#unless fetching}}
|
|
29
24
|
<section style={{ marginTop: "2rem" }}>
|
|
30
25
|
<Button onClick={() => setMsg("Hello!")}>Click me</Button>
|
|
31
26
|
{msg && <p style={{ marginTop: "0.5rem" }}>{msg}</p>}
|
|
32
27
|
</section>
|
|
33
28
|
{{/unless}}
|
|
34
|
-
{{/unless}}
|
|
35
29
|
</main>
|
|
36
30
|
);
|
|
37
31
|
}
|