@vyriy/create 0.5.3 → 0.5.5
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/README.md +6 -2
- package/bin/index.js +3 -0
- package/cli.d.ts +5 -0
- package/cli.js +62 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -18
- package/plan/plan.d.ts +0 -1
- package/plan/plan.js +1 -3
- package/plan/types.d.ts +0 -1
- package/preset/api.js +118 -5
- package/preset/base.js +109 -2
- package/preset/fullstack.js +393 -12
- package/preset/gql.js +198 -34
- package/preset/library.js +346 -180
- package/preset/mfe.js +450 -15
- package/preset/rest.js +182 -6
- package/preset/spa.js +236 -7
- package/preset/ssg.js +266 -13
- package/preset/ssr.js +256 -10
- package/prompt/index.d.ts +0 -1
- package/prompt/index.js +0 -1
- package/prompt/preset.js +3 -2
- package/types.d.ts +8 -0
- package/bin/vyriy-create.js +0 -17
- package/prompt/scope.d.ts +0 -2
- package/prompt/scope.js +0 -2
package/preset/fullstack.js
CHANGED
|
@@ -17,28 +17,263 @@ const projectFiles = {
|
|
|
17
17
|
'packages/env/env.test.ts': "import { afterEach, describe, expect, it } from '@jest/globals';\n\nimport { getApi, getCdn, getUi } from './env.js';\n\ndescribe('env getters', () => {\n afterEach(() => {\n delete process.env.API;\n delete process.env.CDN;\n delete process.env.UI;\n });\n\n it('reads required environment values', () => {\n process.env.API = 'http://localhost:3000';\n process.env.CDN = 'http://localhost:3001';\n process.env.UI = 'http://localhost:3002';\n\n expect(getApi()).toBe('http://localhost:3000');\n expect(getCdn()).toBe('http://localhost:3001');\n expect(getUi()).toBe('http://localhost:3002');\n });\n\n it('throws when a required environment value is missing', () => {\n expect(() => getUi()).toThrow('Environment variable UI is not defined!');\n });\n});\n",
|
|
18
18
|
'packages/env/env.ts': "import { getEnv } from '@vyriy/env';\n\n/** Reads the API origin used for server endpoints. */\nexport const getApi = () => getEnv('API');\n\n/** Reads the CDN origin used for static assets. */\nexport const getCdn = () => getEnv('CDN');\n\n/** Reads the UI origin used for browser assets. */\nexport const getUi = () => getEnv('UI');\n",
|
|
19
19
|
'packages/env/index.test.ts': "import { afterEach, describe, expect, it } from '@jest/globals';\n\nimport * as publicApi from './index.js';\n\nconst ENV_NAMES = [\n 'API',\n 'CDN',\n 'UI',\n] as const;\n\nconst clearEnv = () => {\n for (const name of ENV_NAMES) {\n delete process.env[name];\n }\n};\n\ndescribe('env public API', () => {\n afterEach(() => {\n clearEnv();\n });\n\n it('exports env getters', () => {\n expect(publicApi.getApi).toBeDefined();\n expect(publicApi.getCdn).toBeDefined();\n expect(publicApi.getUi).toBeDefined();\n });\n\n it('reads environment variables by public getter name', () => {\n process.env.API = 'http://localhost:3000';\n process.env.CDN = 'http://localhost:3001';\n process.env.UI = 'http://localhost:3002';\n\n expect(publicApi.getApi()).toBe('http://localhost:3000');\n expect(publicApi.getCdn()).toBe('http://localhost:3001');\n expect(publicApi.getUi()).toBe('http://localhost:3002');\n });\n\n it('throws when a required environment variable is missing', () => {\n clearEnv();\n\n expect(() => publicApi.getApi()).toThrow('Environment variable API is not defined!');\n });\n});\n",
|
|
20
|
-
'packages/env/README.md':
|
|
20
|
+
'packages/env/README.md': `# Env
|
|
21
|
+
|
|
22
|
+
Required environment readers shared by the API and UI workspaces.
|
|
23
|
+
|
|
24
|
+
## Exports
|
|
25
|
+
|
|
26
|
+
- \`getApi()\` reads \`API\`.
|
|
27
|
+
- \`getCdn()\` reads \`CDN\`.
|
|
28
|
+
- \`getUi()\` reads \`UI\`.
|
|
29
|
+
|
|
30
|
+
Each getter throws when its environment variable is missing.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
\`\`\`ts
|
|
35
|
+
import { getApi, getCdn, getUi } from '@p/env';
|
|
36
|
+
|
|
37
|
+
const apiOrigin = getApi();
|
|
38
|
+
const cdnOrigin = getCdn();
|
|
39
|
+
const uiOrigin = getUi();
|
|
40
|
+
\`\`\`
|
|
41
|
+
|
|
42
|
+
## Local Defaults
|
|
43
|
+
|
|
44
|
+
Workspace scripts source \`workspaces/env.sh\`, which provides local defaults:
|
|
45
|
+
|
|
46
|
+
- \`API_PORT=3000\`
|
|
47
|
+
- \`CDN_PORT=3001\`
|
|
48
|
+
- \`UI_PORT=3002\`
|
|
49
|
+
- \`API=http://localhost:$API_PORT\`
|
|
50
|
+
- \`CDN=http://localhost:$CDN_PORT\`
|
|
51
|
+
- \`UI=http://localhost:$UI_PORT\`
|
|
52
|
+
|
|
53
|
+
Override these variables before running a workspace script when a different origin or port is needed.
|
|
54
|
+
|
|
55
|
+
## Notes
|
|
56
|
+
|
|
57
|
+
- The package is private to this repository.
|
|
58
|
+
- The public entry point re-exports from \`env.ts\`.
|
|
59
|
+
- The getters are thin wrappers around \`@vyriy/env\` and keep environment access explicit at call sites.
|
|
60
|
+
`,
|
|
21
61
|
'stylelint.config.ts': "export { default } from '@vyriy/stylelint-config';\n",
|
|
22
62
|
'workspaces/api/bin/build.sh': '#!/usr/bin/env sh\n\nset -e\n\nscriptdir="$PWD/workspaces/api";\n\n. "$PWD/workspaces/env.sh"\n\nNODE_ENV=production \\\nnpx webpack --config $scriptdir/webpack.config.ts\n\ncp $scriptdir/package.json dist/api/package.json\nnpm pkg delete "type" --prefix dist/api\nnpm pkg delete "private" --prefix dist/api\n',
|
|
23
|
-
'workspaces/api/bin/start.sh':
|
|
63
|
+
'workspaces/api/bin/start.sh': `#!/usr/bin/env sh
|
|
64
|
+
|
|
65
|
+
set -e
|
|
66
|
+
|
|
67
|
+
scriptdir="$PWD/workspaces/api";
|
|
68
|
+
|
|
69
|
+
. "$PWD/workspaces/env.sh"
|
|
70
|
+
|
|
71
|
+
echo "Demo:\n$API/\n"
|
|
72
|
+
echo "Prerender:\n$API/prerender?name=Developer&title=Senior%20IT%20Professional&avatarUrl=http://localhost:3001/avatar.svg\n"
|
|
73
|
+
echo "Semantic:\n$API/semantic?name=Developer&title=Senior%20IT%20Professional&avatarUrl=http://localhost:3001/avatar.svg\n"
|
|
74
|
+
echo "Manifest:\n$API/manifest.yml\n"
|
|
75
|
+
|
|
76
|
+
NODE_ENV=production \
|
|
77
|
+
LOG_LEVEL=info \
|
|
78
|
+
PORT=$API_PORT \
|
|
79
|
+
tsx watch $scriptdir/index.tsx
|
|
80
|
+
`,
|
|
24
81
|
'workspaces/api/doc.mdx': "import { Meta, Markdown } from '@storybook/addon-docs/blocks';\nimport ReadMe from './README.md?raw';\n\n<Meta title=\"Workspaces/API\" />\n\n<Markdown>{ReadMe}</Markdown>\n",
|
|
25
82
|
'workspaces/api/package.json': '{\n "name": "@w/api",\n "type": "module",\n "private": true\n}\n',
|
|
26
|
-
'workspaces/api/README.md':
|
|
83
|
+
'workspaces/api/README.md': `# API
|
|
84
|
+
|
|
85
|
+
Server-rendered demo workspace for the profile-card application.
|
|
86
|
+
|
|
87
|
+
## Behavior
|
|
88
|
+
|
|
89
|
+
The API starts an \`@vyriy/server\` handler and serves the root route:
|
|
90
|
+
|
|
91
|
+
- \`GET /\` returns an HTML document with a server-rendered \`ProfileCard\`.
|
|
92
|
+
- Unknown routes return the router \`404\` response.
|
|
93
|
+
|
|
94
|
+
The HTML includes:
|
|
95
|
+
|
|
96
|
+
- \`http://localhost:3002/main.css\` by default
|
|
97
|
+
- \`http://localhost:3002/index.js\` by default
|
|
98
|
+
- the demo avatar at \`http://localhost:3001/avatar.svg\`
|
|
99
|
+
|
|
100
|
+
The UI origin is read through \`getUi()\` from \`@p/env\`.
|
|
101
|
+
|
|
102
|
+
## Local Development
|
|
103
|
+
|
|
104
|
+
From the repository root:
|
|
105
|
+
|
|
106
|
+
\`\`\`bash
|
|
107
|
+
yarn start:api
|
|
108
|
+
\`\`\`
|
|
109
|
+
|
|
110
|
+
The script sources \`workspaces/env.sh\` and starts \`workspaces/api/index.tsx\` with \`tsx watch\`.
|
|
111
|
+
|
|
112
|
+
Default local values:
|
|
113
|
+
|
|
114
|
+
- \`API_PORT=3000\`
|
|
115
|
+
- \`API=http://localhost:3000\`
|
|
116
|
+
- \`UI=http://localhost:3002\`
|
|
117
|
+
|
|
118
|
+
Run the static and UI workspaces alongside the API when loading the full page:
|
|
119
|
+
|
|
120
|
+
\`\`\`bash
|
|
121
|
+
yarn start
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
## Build
|
|
125
|
+
|
|
126
|
+
\`\`\`bash
|
|
127
|
+
yarn build:api
|
|
128
|
+
\`\`\`
|
|
129
|
+
|
|
130
|
+
The build emits the server bundle to \`dist/api/index.js\` and copies the workspace \`package.json\` into \`dist/api\`.
|
|
131
|
+
|
|
132
|
+
## Validation
|
|
133
|
+
|
|
134
|
+
\`\`\`bash
|
|
135
|
+
yarn test:jest workspaces/api
|
|
136
|
+
\`\`\`
|
|
137
|
+
|
|
138
|
+
The tests verify server registration, the rendered root response, response headers, linked UI assets, and the \`404\` path.
|
|
139
|
+
`,
|
|
27
140
|
'workspaces/api/index.test.tsx': "import { describe, expect, it, jest } from '@jest/globals';\nimport type { APIGatewayProxyEvent } from '@vyriy/router';\n\nconst apiMock = jest.fn((handler) => ({ handler }));\nconst serverMock = jest.fn();\n\njest.mock('@vyriy/handler', () => ({\n api: apiMock,\n}));\n\njest.mock('@vyriy/server', () => ({\n server: serverMock,\n}));\n\njest.mock('@p/env', () => ({\n getUi: () => 'http://localhost:3002',\n}));\n\ndescribe('workspaces/api/index.tsx', () => {\n type ApiHandler = (event: APIGatewayProxyEvent) => Promise<{\n body: string;\n headers?: Record<string, string>;\n statusCode: number;\n }>;\n\n const getEvent = (path: string): APIGatewayProxyEvent =>\n ({\n body: null,\n headers: {},\n httpMethod: 'GET',\n path,\n pathParameters: null,\n queryStringParameters: null,\n }) as APIGatewayProxyEvent;\n\n const loadHandler = async (): Promise<ApiHandler> => {\n await jest.isolateModulesAsync(async () => {\n await import('./index.js');\n });\n\n expect(apiMock).toHaveBeenCalledTimes(1);\n expect(serverMock).toHaveBeenCalledTimes(1);\n expect(serverMock).toHaveBeenCalledWith(apiMock.mock.results[0]?.value);\n\n return apiMock.mock.calls[0]?.[0] as ApiHandler;\n };\n\n it('starts the server with the API handler', async () => {\n await loadHandler();\n\n expect(apiMock).toHaveBeenCalledTimes(1);\n });\n\n it('renders the demo page for the root route', async () => {\n const handler = await loadHandler();\n const response = await handler(getEvent('/'));\n\n expect(response).toEqual({\n body: expect.any(String),\n headers: {\n 'access-control-allow-origin': '*',\n 'cache-control': 'public, max-age=300, s-maxage=3600, stale-while-revalidate=86400',\n 'content-type': 'text/html; charset=utf-8',\n 'x-content-type-options': 'nosniff',\n },\n isBase64Encoded: undefined,\n multiValueHeaders: undefined,\n statusCode: 200,\n });\n expect(response.body).toContain('<title>Demo</title>');\n expect(response.body).toContain('href=\"http://localhost:3002/main.css\"');\n expect(response.body).toContain('<div id=\"root\" rendered>');\n expect(response.body).toContain('Developer');\n expect(response.body).toContain('Senior IT Professional');\n expect(response.body).toContain('http://localhost:3001/avatar.svg');\n expect(response.body).toContain('src=\"http://localhost:3002/index.js\"');\n });\n\n it('returns not found for unknown routes', async () => {\n const handler = await loadHandler();\n\n await expect(handler(getEvent('/missing'))).resolves.toEqual({\n body: JSON.stringify({\n message: 'Not Found',\n }),\n statusCode: 404,\n });\n });\n});\n",
|
|
28
141
|
'workspaces/api/index.tsx': "import { server } from '@vyriy/server';\nimport { api } from '@vyriy/handler';\nimport { createRouter } from '@vyriy/router';\nimport { minify, html } from '@vyriy/html';\nimport { html as react } from '@vyriy/render';\n\nimport { ProfileCard } from '@p/components/profile-card';\nimport { getUi } from '@p/env';\n\nserver(\n api(async (event) =>\n createRouter()\n .get('/', () => ({\n body: minify(\n html({\n htmlAttributes: 'lang=\"en\"',\n title: '<title>Demo</title>',\n meta: '<meta charset=\"utf-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />',\n link: `<link rel=\"stylesheet\" type=\"text/css\" href=\"${getUi()}/main.css\" />`,\n body: `<div id=\"root\" rendered>${react(\n <ProfileCard\n name=\"Developer\"\n title=\"Senior IT Professional\"\n avatarUrl=\"http://localhost:3001/avatar.svg\"\n />,\n )}</div>`,\n script: `<script defer=\"defer\" src=\"${getUi()}/index.js\"></script>`,\n }),\n ),\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n 'cache-control': 'public, max-age=300, s-maxage=3600, stale-while-revalidate=86400',\n 'access-control-allow-origin': '*',\n 'x-content-type-options': 'nosniff',\n },\n }))\n .route(event),\n ),\n);\n",
|
|
29
142
|
'workspaces/api/webpack.config.ts': "import { EnvironmentPlugin } from 'webpack';\nimport { path } from '@vyriy/path';\nimport { ssr, external } from '@vyriy/webpack-config';\n\nexport default ssr(\n '@w/api',\n {\n path: path('dist', 'api'),\n filename: 'index.js',\n library: { type: 'commonjs2' },\n },\n (config) => ({\n ...config,\n externals: [external({ allowlist: [/^@p/, /^@w/, /^@vyriy/] })],\n plugins: [\n ...(config.plugins ?? []),\n new EnvironmentPlugin([\n 'API',\n 'CDN',\n 'UI',\n ]),\n ],\n }),\n);\n",
|
|
30
143
|
'workspaces/env.sh': '#!/usr/bin/env sh\n\n: "${API_PORT:=3000}"\n: "${CDN_PORT:=3001}"\n: "${UI_PORT:=3002}"\n: "${API:=http://localhost:$API_PORT}"\n: "${CDN:=http://localhost:$CDN_PORT}"\n: "${UI:=http://localhost:$UI_PORT}"\n\nexport API_PORT\nexport CDN_PORT\nexport UI_PORT\nexport API\nexport CDN\nexport UI\n',
|
|
31
144
|
'workspaces/static/bin/build.sh': '#!/usr/bin/env sh\n\nset -e\n\nscriptdir="$PWD/workspaces/static";\ndistdir="$PWD/dist/cdn";\n\ncp -R $scriptdir/public/* $distdir/\n',
|
|
32
|
-
'workspaces/static/bin/start.sh':
|
|
145
|
+
'workspaces/static/bin/start.sh': `#!/usr/bin/env sh
|
|
146
|
+
|
|
147
|
+
set -e
|
|
148
|
+
|
|
149
|
+
scriptdir="$PWD/workspaces/static";
|
|
150
|
+
|
|
151
|
+
. "$PWD/workspaces/env.sh"
|
|
152
|
+
|
|
153
|
+
npx vs -p $CDN_PORT $scriptdir/public
|
|
154
|
+
`,
|
|
33
155
|
'workspaces/static/doc.mdx': "import { Meta, Markdown } from '@storybook/addon-docs/blocks';\nimport ReadMe from './README.md?raw';\n\n<Meta title=\"Workspaces/Static\" />\n\n<Markdown>{ReadMe}</Markdown>\n",
|
|
34
156
|
'workspaces/static/package.json': '{\n "name": "@w/static",\n "type": "module",\n "private": true\n}\n',
|
|
35
157
|
'workspaces/static/public/avatar.svg': '<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800">\r\n<rect width="1200" height="800" fill="#0057B7"/>\r\n<rect width="1200" height="400" y="400" fill="#FFD700"/>\r\n</svg>',
|
|
36
|
-
'workspaces/static/README.md':
|
|
158
|
+
'workspaces/static/README.md': `# Static
|
|
159
|
+
|
|
160
|
+
Static asset workspace for the profile-card UI. It is served with \`vs\`, the CLI provided by \`@vyriy/static\`.
|
|
161
|
+
|
|
162
|
+
## Assets
|
|
163
|
+
|
|
164
|
+
- \`avatar.svg\` is the default demo avatar.
|
|
165
|
+
|
|
166
|
+
## Local Development
|
|
167
|
+
|
|
168
|
+
From the repository root:
|
|
169
|
+
|
|
170
|
+
\`\`\`bash
|
|
171
|
+
yarn start:static
|
|
172
|
+
\`\`\`
|
|
173
|
+
|
|
174
|
+
The script sources \`workspaces/env.sh\` and runs:
|
|
175
|
+
|
|
176
|
+
\`\`\`bash
|
|
177
|
+
npx vs -p $CDN_PORT workspaces/static/public
|
|
178
|
+
\`\`\`
|
|
179
|
+
|
|
180
|
+
This serves every file in \`workspaces/static/public\` as a directly addressable static asset for the project.
|
|
181
|
+
|
|
182
|
+
Default local values:
|
|
183
|
+
|
|
184
|
+
- \`CDN_PORT=3001\`
|
|
185
|
+
- \`CDN=http://localhost:3001\`
|
|
186
|
+
|
|
187
|
+
The API and UI demo use the avatar at:
|
|
188
|
+
|
|
189
|
+
\`\`\`text
|
|
190
|
+
http://localhost:3001/avatar.svg
|
|
191
|
+
\`\`\`
|
|
192
|
+
|
|
193
|
+
## Global CLI
|
|
194
|
+
|
|
195
|
+
\`@vyriy/static\` can be installed globally when you want the \`vs\` command available without \`npx\` or project scripts:
|
|
196
|
+
|
|
197
|
+
\`\`\`bash
|
|
198
|
+
npm install --global @vyriy/static
|
|
199
|
+
vs -p 3001 workspaces/static/public
|
|
200
|
+
\`\`\`
|
|
201
|
+
|
|
202
|
+
Use the same command shape for any static directory:
|
|
203
|
+
|
|
204
|
+
\`\`\`bash
|
|
205
|
+
vs -p <port> <static-directory>
|
|
206
|
+
\`\`\`
|
|
207
|
+
|
|
208
|
+
## Build
|
|
209
|
+
|
|
210
|
+
\`\`\`bash
|
|
211
|
+
yarn build:static
|
|
212
|
+
\`\`\`
|
|
213
|
+
|
|
214
|
+
The build copies files from \`workspaces/static/public\` into \`dist/cdn\`.
|
|
215
|
+
|
|
216
|
+
## Notes
|
|
217
|
+
|
|
218
|
+
- Keep files in \`public\` directly addressable by URL.
|
|
219
|
+
- Add shared static demo assets here rather than coupling them to the API or UI workspace.
|
|
220
|
+
`,
|
|
37
221
|
'workspaces/ui/bin/build.sh': '#!/usr/bin/env sh\n\nset -e\n\nscriptdir="$PWD/workspaces/ui";\n\n. "$PWD/workspaces/env.sh"\n\nNODE_ENV=production \\\nnpx webpack \\\n--config $scriptdir/webpack.config.ts\n',
|
|
38
222
|
'workspaces/ui/bin/start.sh': '#!/usr/bin/env sh\n\nset -e\n\nscriptdir="$PWD/workspaces/ui";\n\n. "$PWD/workspaces/env.sh"\n\nnpx webpack serve \\\n--open \\\n--config $scriptdir/webpack.config.ts \\\n--port $UI_PORT\n',
|
|
39
223
|
'workspaces/ui/doc.mdx': "import { Meta, Markdown } from '@storybook/addon-docs/blocks';\nimport ReadMe from './README.md?raw';\n\n<Meta title=\"Workspaces/UI\" />\n\n<Markdown>{ReadMe}</Markdown>\n",
|
|
40
224
|
'workspaces/ui/package.json': '{\n "name": "@w/ui",\n "type": "module",\n "private": true\n}\n',
|
|
41
|
-
'workspaces/ui/README.md':
|
|
225
|
+
'workspaces/ui/README.md': `# UI
|
|
226
|
+
|
|
227
|
+
Client-rendered demo workspace for the profile-card application.
|
|
228
|
+
|
|
229
|
+
## Behavior
|
|
230
|
+
|
|
231
|
+
The UI entry point mounts a \`ProfileCard\` into \`#root\` with the same demo data used by the API-rendered page.
|
|
232
|
+
|
|
233
|
+
It imports shared component styles from:
|
|
234
|
+
|
|
235
|
+
\`\`\`ts
|
|
236
|
+
import '@p/components/styles.scss';
|
|
237
|
+
\`\`\`
|
|
238
|
+
|
|
239
|
+
## Local Development
|
|
240
|
+
|
|
241
|
+
From the repository root:
|
|
242
|
+
|
|
243
|
+
\`\`\`bash
|
|
244
|
+
yarn start:ui
|
|
245
|
+
\`\`\`
|
|
246
|
+
|
|
247
|
+
The script sources \`workspaces/env.sh\` and starts webpack dev server for \`workspaces/ui/index.tsx\`.
|
|
248
|
+
|
|
249
|
+
Default local values:
|
|
250
|
+
|
|
251
|
+
- \`UI_PORT=3002\`
|
|
252
|
+
- \`UI=http://localhost:3002\`
|
|
253
|
+
- \`CDN=http://localhost:3001\`
|
|
254
|
+
|
|
255
|
+
Run the full local application when the API, CDN assets, and UI bundle should all be available:
|
|
256
|
+
|
|
257
|
+
\`\`\`bash
|
|
258
|
+
yarn start
|
|
259
|
+
\`\`\`
|
|
260
|
+
|
|
261
|
+
## Build
|
|
262
|
+
|
|
263
|
+
\`\`\`bash
|
|
264
|
+
yarn build:ui
|
|
265
|
+
\`\`\`
|
|
266
|
+
|
|
267
|
+
The build emits the browser bundle and generated HTML into \`dist/cdn\`.
|
|
268
|
+
|
|
269
|
+
## Validation
|
|
270
|
+
|
|
271
|
+
\`\`\`bash
|
|
272
|
+
yarn test:jest workspaces/ui
|
|
273
|
+
\`\`\`
|
|
274
|
+
|
|
275
|
+
The tests verify that the entry point mounts into \`#root\` and renders the demo \`ProfileCard\` props.
|
|
276
|
+
`,
|
|
42
277
|
'workspaces/ui/index.test.tsx': "import { describe, expect, it, jest } from '@jest/globals';\nimport { isValidElement } from 'react';\nimport type { ReactElement } from 'react';\n\nconst elementMock = jest.fn();\n\njest.mock('@vyriy/render/element', () => ({\n element: elementMock,\n}));\n\ntype ProfileCardProps = {\n avatarUrl: string;\n name: string;\n title: string;\n};\n\ndescribe('workspaces/ui/index.tsx', () => {\n const loadEntry = async () => {\n const root = document.createElement('div');\n root.id = 'root';\n document.body.replaceChildren();\n document.body.append(root);\n\n await jest.isolateModulesAsync(async () => {\n await import('./index.js');\n });\n\n const [{ component }] = elementMock.mock.calls[0] as [{ component: ReactElement<ProfileCardProps> }];\n\n return {\n root,\n component,\n };\n };\n\n it('mounts the UI into the root element', async () => {\n const { root, component } = await loadEntry();\n\n expect(elementMock).toHaveBeenCalledTimes(1);\n expect(elementMock).toHaveBeenCalledWith({\n root,\n component,\n });\n });\n\n it('renders the profile card demo component', async () => {\n const { component } = await loadEntry();\n\n expect(isValidElement(component)).toBe(true);\n expect(typeof component.type).toBe('function');\n expect((component.type as { name?: string }).name).toBe('ProfileCard');\n expect(component.props).toEqual({\n avatarUrl: 'http://localhost:3001/avatar.svg',\n name: 'Developer',\n title: 'Senior IT Professional',\n });\n });\n});\n",
|
|
43
278
|
'workspaces/ui/index.tsx': "import { element } from '@vyriy/render/element';\n\nimport { ProfileCard } from '@p/components/profile-card';\nimport '@p/components/styles.scss';\n\nelement({\n root: document.getElementById('root'),\n component: (\n <ProfileCard name=\"Developer\" title=\"Senior IT Professional\" avatarUrl=\"http://localhost:3001/avatar.svg\" />\n ),\n});\n",
|
|
44
279
|
'workspaces/ui/webpack.config.ts': "import { EnvironmentPlugin } from 'webpack';\n\nimport { csr, html } from '@vyriy/webpack-config';\nimport { path } from '@vyriy/path';\n\nexport default csr(\n '@w/ui',\n {\n path: path('dist', 'cdn'),\n filename: 'index.js',\n },\n (config) => ({\n ...config,\n plugins: [\n ...(config.plugins ?? []),\n new EnvironmentPlugin(['API', 'CDN', 'UI']),\n html({\n htmlAttributes: 'lang=\"en\"',\n title: '<title>Demo</title>',\n meta: '<meta charset=\"utf-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />',\n body: '<div id=\"root\"></div>',\n }),\n ],\n }),\n);\n",
|
|
@@ -241,7 +476,70 @@ export default {
|
|
|
241
476
|
'packages/components/profile-tags/README.md': "# ProfileTags\n\n`ProfileTags` renders a list of profile tags using `Badge`.\n\n## Usage\n\n```tsx\nimport { ProfileTags } from './profile-tags.js';\n\nexport const Example = () => <ProfileTags tags={['React', 'TypeScript']} />;\n```\n\n## Props\n\n```ts\nexport type ProfileTagsProps = {\n tags: string[];\n tone?: BadgeProps['tone'];\n} & ComponentProps<'ul'>;\n```\n\n## Accessibility\n\nTags are rendered as a semantic `<ul>` with one `<li>` per tag.\n\n## Notes\n\n- Empty tag arrays render `null`.\n- SSR/SSG-safe.\n- Shared SCSS styles.\n",
|
|
242
477
|
'packages/components/profile-tags/styles.scss': '.profile-tags {\n display: flex;\n flex-wrap: wrap;\n gap: 0.4rem;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.profile-tags__item {\n display: inline-flex;\n}\n',
|
|
243
478
|
'packages/components/profile-tags/types.ts': "import type { ComponentProps, FC } from 'react';\n\nimport type { BadgeProps } from '../badge/index.js';\n\n/** Props for the ProfileTags component. */\nexport type ProfileTagsProps = {\n tags: string[];\n tone?: BadgeProps['tone'];\n} & ComponentProps<'ul'>;\n\n/** ProfileTags component type. */\nexport type ProfileTagsType = FC<ProfileTagsProps>;\n",
|
|
244
|
-
'packages/components/README.md':
|
|
479
|
+
'packages/components/README.md': `# Components
|
|
480
|
+
|
|
481
|
+
Reusable React components for the profile-card demo. The package is private to
|
|
482
|
+
this repository and is consumed by the API and UI workspaces.
|
|
483
|
+
|
|
484
|
+
## Exports
|
|
485
|
+
|
|
486
|
+
Import the full public surface from \`@p/components\`:
|
|
487
|
+
|
|
488
|
+
- \`Avatar\`
|
|
489
|
+
- \`Badge\`
|
|
490
|
+
- \`ButtonLink\`
|
|
491
|
+
- \`Card\`
|
|
492
|
+
- \`IconLink\`
|
|
493
|
+
- \`ProfileCard\`
|
|
494
|
+
- \`ProfileDetails\`
|
|
495
|
+
- \`ProfileHeader\`
|
|
496
|
+
- \`ProfileLinks\`
|
|
497
|
+
- \`ProfileMeta\`
|
|
498
|
+
- \`ProfileTags\`
|
|
499
|
+
|
|
500
|
+
Focused component entry points are also available:
|
|
501
|
+
|
|
502
|
+
\`\`\`tsx
|
|
503
|
+
import { ProfileCard } from '@p/components/profile-card';
|
|
504
|
+
\`\`\`
|
|
505
|
+
|
|
506
|
+
## Usage
|
|
507
|
+
|
|
508
|
+
\`\`\`tsx
|
|
509
|
+
import { ProfileCard } from '@p/components/profile-card';
|
|
510
|
+
import '@p/components/styles.scss';
|
|
511
|
+
|
|
512
|
+
export const Example = () => (
|
|
513
|
+
<ProfileCard
|
|
514
|
+
name="Developer"
|
|
515
|
+
title="Senior IT Professional"
|
|
516
|
+
description="Building calm architecture for cloud-ready applications."
|
|
517
|
+
avatarUrl="http://localhost:3001/avatar.svg"
|
|
518
|
+
tags={['React', 'TypeScript', 'Vyriy']}
|
|
519
|
+
meta={[{ label: 'Project', value: 'Fullstack preset' }]}
|
|
520
|
+
links={[{ href: 'https://vyriy.dev', label: 'Website', external: true }]}
|
|
521
|
+
/>
|
|
522
|
+
);
|
|
523
|
+
\`\`\`
|
|
524
|
+
|
|
525
|
+
## Structure
|
|
526
|
+
|
|
527
|
+
Each public component lives in its own folder with:
|
|
528
|
+
|
|
529
|
+
- a focused \`README.md\`
|
|
530
|
+
- Storybook docs in \`doc.mdx\`
|
|
531
|
+
- stories for visual states
|
|
532
|
+
- behavior tests and public entry-point tests
|
|
533
|
+
- component-local SCSS
|
|
534
|
+
|
|
535
|
+
The package-level \`index.ts\` is a re-export surface only.
|
|
536
|
+
|
|
537
|
+
## Notes
|
|
538
|
+
|
|
539
|
+
- Components are SSR/SSG-friendly and avoid browser globals during render.
|
|
540
|
+
- Shared styles are exposed through \`@p/components/styles.scss\`.
|
|
541
|
+
- Public imports use ESM \`.js\` relative specifiers in TypeScript source.
|
|
542
|
+
`,
|
|
245
543
|
'packages/components/styles.d.ts': "declare module '*.scss';\ndeclare module '*.scss?inline' {\n const css: string;\n export default css;\n}\ndeclare module '*.svg' {\n const src: string;\n export default src;\n}\n",
|
|
246
544
|
'packages/components/styles.scss': "@use './avatar/styles' as avatar;\n@use './badge/styles' as badge;\n@use './button-link/styles' as button-link;\n@use './card/styles' as card;\n@use './icon-link/styles' as icon-link;\n@use './profile-card/styles' as profile-card;\n@use './profile-details/styles' as profile-details;\n@use './profile-header/styles' as profile-header;\n@use './profile-links/styles' as profile-links;\n@use './profile-meta/styles' as profile-meta;\n@use './profile-tags/styles' as profile-tags;\n",
|
|
247
545
|
'packages/components/package.json': JSON.stringify({
|
|
@@ -318,18 +616,22 @@ export default {
|
|
|
318
616
|
'npm-run-all2': packageJson.peerDependencies['npm-run-all2'],
|
|
319
617
|
prettier: packageJson.peerDependencies.prettier,
|
|
320
618
|
rimraf: packageJson.peerDependencies.rimraf,
|
|
321
|
-
serve: packageJson.peerDependencies.serve,
|
|
322
619
|
storybook: packageJson.peerDependencies.storybook,
|
|
323
620
|
stylelint: packageJson.peerDependencies.stylelint,
|
|
324
621
|
tsx: packageJson.peerDependencies.tsx,
|
|
325
622
|
typescript: packageJson.peerDependencies.typescript,
|
|
326
623
|
webpack: packageJson.peerDependencies.webpack,
|
|
327
624
|
'webpack-cli': packageJson.peerDependencies['webpack-cli'],
|
|
625
|
+
'@vyriy/static': `^${packageJson.version}`,
|
|
328
626
|
},
|
|
329
627
|
}, null, 2) + '\n',
|
|
330
|
-
'README.md': `#
|
|
628
|
+
'README.md': `# Fullstack
|
|
629
|
+
|
|
630
|
+
Calm cloud-ready profile-card application.
|
|
331
631
|
|
|
332
|
-
|
|
632
|
+
This repository contains a small fullstack demo with shared React components,
|
|
633
|
+
required environment readers, a server-rendered API page, a static asset origin,
|
|
634
|
+
and a client-rendered UI bundle.
|
|
333
635
|
|
|
334
636
|
## Setup
|
|
335
637
|
|
|
@@ -337,6 +639,8 @@ ${options.description}
|
|
|
337
639
|
yarn install
|
|
338
640
|
\`\`\`
|
|
339
641
|
|
|
642
|
+
The project uses Yarn workspaces and Node \`>=24.0.0\`.
|
|
643
|
+
|
|
340
644
|
## Start
|
|
341
645
|
|
|
342
646
|
Start the API, static asset server, and UI dev server together:
|
|
@@ -353,14 +657,79 @@ yarn start:static
|
|
|
353
657
|
yarn start:ui
|
|
354
658
|
\`\`\`
|
|
355
659
|
|
|
660
|
+
\`yarn start:static\` uses the \`vs\` CLI from \`@vyriy/static\` to serve project
|
|
661
|
+
static files from \`workspaces/static/public\`.
|
|
662
|
+
|
|
356
663
|
## Local URLs
|
|
357
664
|
|
|
358
|
-
Default ports are defined in \`workspaces/env.sh\`:
|
|
665
|
+
Default ports and origins are defined in \`workspaces/env.sh\`:
|
|
359
666
|
|
|
360
667
|
- API: \`http://localhost:3000\`
|
|
361
668
|
- Static/CDN assets: \`http://localhost:3001\`
|
|
362
669
|
- UI dev server: \`http://localhost:3002\`
|
|
363
670
|
|
|
671
|
+
Override \`API_PORT\`, \`CDN_PORT\`, \`UI_PORT\`, \`API\`, \`CDN\`, or \`UI\` before
|
|
672
|
+
running a script when local services need different addresses.
|
|
673
|
+
|
|
674
|
+
## Workspaces
|
|
675
|
+
|
|
676
|
+
- \`packages/components\` provides the shared profile-card React component set.
|
|
677
|
+
- \`packages/env\` provides required environment readers for \`API\`, \`CDN\`, and
|
|
678
|
+
\`UI\`.
|
|
679
|
+
- \`workspaces/api\` serves the SSR demo page at \`GET /\`.
|
|
680
|
+
- \`workspaces/static\` serves public static assets such as \`avatar.svg\` through
|
|
681
|
+
\`vs\` from \`@vyriy/static\`.
|
|
682
|
+
- \`workspaces/ui\` builds and serves the browser entry point.
|
|
683
|
+
|
|
684
|
+
Each package or workspace has its own README with focused usage notes.
|
|
685
|
+
|
|
686
|
+
## Static Server
|
|
687
|
+
|
|
688
|
+
\`@vyriy/static\` provides the \`vs\` command for serving static files. The project
|
|
689
|
+
uses it through \`npx\` in \`workspaces/static/bin/start.sh\`:
|
|
690
|
+
|
|
691
|
+
\`\`\`bash
|
|
692
|
+
npx vs -p 3001 workspaces/static/public
|
|
693
|
+
\`\`\`
|
|
694
|
+
|
|
695
|
+
It can also be installed globally when the same static server is useful outside
|
|
696
|
+
the workspace scripts:
|
|
697
|
+
|
|
698
|
+
\`\`\`bash
|
|
699
|
+
npm install --global @vyriy/static
|
|
700
|
+
vs -p 3001 workspaces/static/public
|
|
701
|
+
\`\`\`
|
|
702
|
+
|
|
703
|
+
## Storybook
|
|
704
|
+
|
|
705
|
+
Run Storybook docs and component stories:
|
|
706
|
+
|
|
707
|
+
\`\`\`bash
|
|
708
|
+
yarn storybook
|
|
709
|
+
\`\`\`
|
|
710
|
+
|
|
711
|
+
Storybook loads package and workspace \`doc.mdx\` files and shared component
|
|
712
|
+
styles from \`packages/components/styles.scss\`.
|
|
713
|
+
|
|
714
|
+
## Build
|
|
715
|
+
|
|
716
|
+
Build all production outputs:
|
|
717
|
+
|
|
718
|
+
\`\`\`bash
|
|
719
|
+
yarn build
|
|
720
|
+
\`\`\`
|
|
721
|
+
|
|
722
|
+
Focused builds are also available:
|
|
723
|
+
|
|
724
|
+
\`\`\`bash
|
|
725
|
+
yarn build:api
|
|
726
|
+
yarn build:static
|
|
727
|
+
yarn build:ui
|
|
728
|
+
yarn build:storybook
|
|
729
|
+
\`\`\`
|
|
730
|
+
|
|
731
|
+
The API bundle is emitted to \`dist/api\`; UI and static assets are emitted to \`dist/cdn\`.
|
|
732
|
+
|
|
364
733
|
## Validation
|
|
365
734
|
|
|
366
735
|
\`\`\`bash
|
|
@@ -368,11 +737,23 @@ yarn lint
|
|
|
368
737
|
yarn test
|
|
369
738
|
yarn build
|
|
370
739
|
\`\`\`
|
|
740
|
+
|
|
741
|
+
Use \`yarn check\` to run linting, build, and tests in one command.
|
|
742
|
+
|
|
743
|
+
## Project Guidance
|
|
744
|
+
|
|
745
|
+
These articles describe the development approach behind this preset and provide practical guidance for evolving a project on top of it:
|
|
746
|
+
|
|
747
|
+
- [Calm Development Environment: Node.js, Corepack, Yarn and Static Preview](https://vyriy.dev/blog/calm-development-setup/) - how to keep the local development environment predictable and easy to reproduce.
|
|
748
|
+
- [Calm App Structure for the Vyriy Ecosystem](https://vyriy.dev/blog/vyriy-calm-app-structure/) - a practical project structure for Vyriy applications: shared configs, small packages, thin workspaces, Storybook docs, tests, and deployable entry points.
|
|
749
|
+
- [One Handler, Many Runtimes](https://vyriy.dev/examples/one-handler-many-runtimes/) - how @vyriy/handler, @vyriy/router, and @vyriy/server compose a calm Lambda-compatible API that can run locally, in Docker, Fargate-style HTTP runtimes, and AWS Lambda.
|
|
750
|
+
- [Calm Component Structure](https://vyriy.dev/blog/calm-component-structure/) - how to organize component code, tests, stories, and public exports.
|
|
751
|
+
- [Storybook as Project Documentation](https://vyriy.dev/blog/storybook-as-project-documentation/) - how to use Storybook as living project documentation and a component playground.
|
|
371
752
|
`,
|
|
372
753
|
'doc.mdx': `import { Meta, Markdown } from '@storybook/addon-docs/blocks';
|
|
373
754
|
import ReadMe from './README.md?raw';
|
|
374
755
|
|
|
375
|
-
<Meta title="
|
|
756
|
+
<Meta title="Fullstack" />
|
|
376
757
|
|
|
377
758
|
<Markdown>{ReadMe}</Markdown>
|
|
378
759
|
`,
|