Skip to content

Commit b71d9c1

Browse files
committed
Server
1 parent 8534508 commit b71d9c1

File tree

88 files changed

+649
-463
lines changed

Some content is hidden

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

88 files changed

+649
-463
lines changed

src/cli.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ const config = {
7373
message: 'Enable synchronization?',
7474
initial: true,
7575
},
76+
{
77+
type: (prev: unknown, answers: Record<string, unknown>) =>
78+
answers.sync ? ('confirm' as const) : null,
79+
name: 'server',
80+
message: 'Add code for server?',
81+
initial: false,
82+
},
83+
{
84+
type: (prev: unknown, answers: Record<string, unknown>) =>
85+
answers.server ? ('select' as const) : null,
86+
name: 'serverType',
87+
message: 'Server type:',
88+
choices: [
89+
{title: 'Node', value: 'node'},
90+
{title: 'Durable Objects', value: 'durable-objects'},
91+
],
92+
initial: 0,
93+
},
7694
{
7795
type: 'confirm' as const,
7896
name: 'prettier',
@@ -97,6 +115,8 @@ const config = {
97115
eslint,
98116
schemas,
99117
sync,
118+
server,
119+
serverType,
100120
} = answers;
101121
const typescript = language === 'typescript';
102122
const javascript = !typescript;
@@ -112,33 +132,52 @@ const config = {
112132
eslint,
113133
schemas: typescript && (schemas === true || schemas === 'true'),
114134
sync: sync === true || sync === 'true',
135+
server: server === true || server === 'true',
136+
serverType: serverType || 'node',
115137
typescript,
116138
javascript,
117139
react,
118140
ext,
119141
};
120142
},
121143

122-
createDirectories: async (targetDir: string) => {
144+
createDirectories: async (targetDir: string, context: Record<string, unknown>) => {
123145
const {mkdir} = await import('fs/promises');
124146
const {join} = await import('path');
125-
await mkdir(join(targetDir, 'src'), {recursive: true});
126-
await mkdir(join(targetDir, 'public'), {recursive: true});
147+
const server = context.server as boolean;
148+
149+
await mkdir(join(targetDir, 'client/src'), {recursive: true});
150+
await mkdir(join(targetDir, 'client/public'), {recursive: true});
151+
152+
if (server) {
153+
await mkdir(join(targetDir, 'server'), {recursive: true});
154+
}
127155
},
128156

129-
getFiles: () => {
130-
return [
157+
getFiles: (context: TemplateContext) => {
158+
const server = context.server as boolean;
159+
const files = [
131160
{
132-
template: 'package.json.hbs',
133-
output: 'package.json',
161+
template: 'README.md.hbs',
162+
output: 'README.md',
134163
prettier: true,
135164
},
136165
{
137-
template: 'README.md.hbs',
138-
output: 'README.md',
166+
template: 'client/package.json.hbs',
167+
output: 'client/package.json',
139168
prettier: true,
140169
},
141170
];
171+
172+
if (server) {
173+
files.push({
174+
template: 'package.json.hbs',
175+
output: 'package.json',
176+
prettier: true,
177+
});
178+
}
179+
180+
return files;
142181
},
143182

144183
processIncludedFile: (file: FileConfig, context: TemplateContext) => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="preconnect" href="https://fonts.googleapis.com" />
88
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
99
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap" />
10-
{{includeFile template="public/favicon.svg" output="public/favicon.svg"}}
10+
{{includeFile template="client/public/favicon.svg" output="client/public/favicon.svg"}}
1111
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
1212
<title>
1313
TinyBase {{#if (eq appType "chat")}}Chat{{else if (eq appType "drawing")}}Drawing{{else if (eq appType "game")}}Game{{else}}Todos{{/if}}
@@ -173,7 +173,7 @@
173173
</div>
174174
<div id="app"></div>
175175
</div>
176-
{{includeFile template="src/index.tsx.hbs" output="src/index.{{ext}}"}}
176+
{{includeFile template="client/src/index.tsx.hbs" output="client/src/index.{{ext}}"}}
177177
<script type="module" src="/src/index.{{ext}}"></script>
178178
</body>
179179

templates/client/package.json.hbs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "{{projectName}}{{#if server}}-client{{/if}}",
3+
"version": "1.0.0",
4+
"scripts": {
5+
{{#list}}
6+
{{includeFile template="client/index.html.hbs" output="client/index.html"}}
7+
"dev": "vite"
8+
{{#if typescript}}
9+
"build": "tsc && vite build"
10+
{{else}}
11+
"build": "vite build"
12+
{{/if}}
13+
"preview": "vite preview"
14+
{{#if prettier}}
15+
"format": "prettier --write ."
16+
"format:check": "prettier --check ."
17+
{{/if}}
18+
{{#if eslint}}
19+
"lint": "eslint ."
20+
{{/if}}
21+
{{/list}}
22+
},
23+
"devDependencies": {
24+
{{#list}}
25+
"vite": "^7.1.3"
26+
{{#if typescript}}
27+
"typescript": "^5.9.3"
28+
"@types/node": "^25.0.3"
29+
{{#if react}}
30+
"@types/react": "^19.2.7"
31+
"@types/react-dom": "^19.2.3"
32+
{{/if}}
33+
{{/if}}
34+
{{#if react}}
35+
"@vitejs/plugin-react": "^4.3.4"
36+
{{/if}}
37+
{{#if prettier}}
38+
"prettier": "^3.7.4"
39+
{{/if}}
40+
{{#if eslint}}
41+
"eslint": "^9.39.2"
42+
{{#if typescript}}
43+
"typescript-eslint": "^8.51.0"
44+
{{/if}}
45+
{{#if react}}
46+
"eslint-plugin-react": "7.37.5"
47+
"eslint-plugin-react-hooks": "^7.0.1"
48+
{{/if}}
49+
{{/if}}
50+
{{/list}}
51+
},
52+
"dependencies": {
53+
{{#list}}
54+
"tinybase": "^7.3.1"
55+
{{#if react}}
56+
"react": "^19.2.3"
57+
"react-dom": "^19.2.3"
58+
{{/if}}
59+
{{#if sync}}
60+
"reconnecting-websocket": "^4.4.0"
61+
{{/if}}
62+
{{/list}}
63+
}
64+
}
65+
{{#if prettier}}
66+
{{includeFile template="client/.prettierrc.hbs" output="client/.prettierrc"}}
67+
{{/if}}
68+
{{#if eslint}}
69+
{{includeFile template="client/eslint.config.js.hbs" output="client/eslint.config.js"}}
70+
{{/if}}
71+
{{#if react}}
72+
{{includeFile template="client/vite.config.js.hbs" output="client/vite.config.js"}}
73+
{{/if}}
74+
{{#if typescript}}
75+
{{includeFile template="client/tsconfig.json.hbs" output="client/tsconfig.json"}}
76+
{{/if}}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import {StrictMode} from 'react';
55
import {Provider} from 'tinybase/ui-react';
66
{{/if}}
77
import {Inspector} from 'tinybase/ui-react-inspector';
8-
{{includeFile template="src/chat/SettingsStore.tsx.hbs" output="src/SettingsStore.{{ext}}"}}
8+
{{includeFile template="client/src/chat/SettingsStore.tsx.hbs" output="client/src/SettingsStore.{{ext}}"}}
99
import {SettingsStore} from './SettingsStore';
10-
{{includeFile template="src/chat/ChatStore.tsx.hbs" output="src/ChatStore.{{ext}}"}}
10+
{{includeFile template="client/src/chat/ChatStore.tsx.hbs" output="client/src/ChatStore.{{ext}}"}}
1111
import {ChatStore} from './ChatStore';
12-
{{includeFile template="src/chat/UsernameInput.tsx.hbs" output="src/UsernameInput.{{ext}}"}}
12+
{{includeFile template="client/src/chat/UsernameInput.tsx.hbs" output="client/src/UsernameInput.{{ext}}"}}
1313
import {UsernameInput} from './UsernameInput';
14-
{{includeFile template="src/chat/Messages.tsx.hbs" output="src/Messages.{{ext}}"}}
14+
{{includeFile template="client/src/chat/Messages.tsx.hbs" output="client/src/Messages.{{ext}}"}}
1515
import {Messages} from './Messages';
16-
{{includeFile template="src/chat/MessageInput.tsx.hbs" output="src/MessageInput.{{ext}}"}}
16+
{{includeFile template="client/src/chat/MessageInput.tsx.hbs" output="client/src/MessageInput.{{ext}}"}}
1717
import {MessageInput} from './MessageInput';
1818

1919
const App = () => {
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {useRow, STORE_ID} from './ChatStore';
2-
{{includeFile template="src/chat/message.css.hbs" output="src/message.css"}}
2+
{{includeFile template="client/src/chat/message.css.hbs" output="client/src/message.css"}}
33
import './message.css';
44

55
interface MessageProps {

templates/src/chat/MessageInput.tsx.hbs renamed to templates/client/src/chat/MessageInput.tsx.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
{{includeFile template="src/chat/messageInput.css.hbs" output="src/messageInput.css"}}
1+
{{includeFile template="client/src/chat/messageInput.css.hbs" output="client/src/messageInput.css"}}
22
import {useState} from 'react';
33
import {useAddRowCallback, STORE_ID as CHAT_STORE_ID} from './ChatStore';
44
import {useValue, STORE_ID as SETTINGS_STORE_ID} from './SettingsStore';
55
import './messageInput.css';
6-
{{includeFile template="src/shared/Button.tsx.hbs" output="src/Button.{{ext}}"}}
6+
{{includeFile template="client/src/shared/Button.tsx.hbs" output="client/src/Button.{{ext}}"}}
77
import {Button} from './Button';
8-
{{includeFile template="src/shared/Input.tsx.hbs" output="src/Input.{{ext}}"}}
8+
{{includeFile template="client/src/shared/Input.tsx.hbs" output="client/src/Input.{{ext}}"}}
99
import {Input} from './Input';
1010

1111
export const MessageInput = () => {

0 commit comments

Comments
 (0)