@vyriy/create 0.5.4 → 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/package.json +2 -16
- 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/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/scope.d.ts +0 -2
- package/prompt/scope.js +0 -2
package/preset/mfe.js
CHANGED
|
@@ -21,7 +21,52 @@ const projectFiles = {
|
|
|
21
21
|
'packages/api/package.json': '{\n "name": "@p/api",\n "type": "module",\n "private": true\n}\n',
|
|
22
22
|
'packages/api/prerender.test.tsx': "import { afterEach, describe, expect, it } from '@jest/globals';\n\nimport { prerender } from './prerender.js';\n\ndescribe('prerender', () => {\n afterEach(() => {\n delete process.env.MODE;\n delete process.env.TAG;\n delete process.env.UI;\n });\n\n it('renders profile card props as custom element attributes', () => {\n process.env.MODE = 'open';\n process.env.TAG = 'vyriy-profile-card';\n process.env.UI = 'http://localhost:3002';\n\n expect(\n prerender({\n avatarUrl: 'https://example.com/avatar.png',\n description: 'A \"quoted\" <description>',\n name: 'Name',\n tags: ['one', 'two'],\n title: 'Title',\n }),\n ).toContain(\n '<vyriy-profile-card name=\"Name\" title=\"Title\" description=\"A "quoted" <description>\" avatarUrl=\"https://example.com/avatar.png\" tags=\"["one","two"]\" rendered>',\n );\n expect(\n prerender({\n name: 'Name',\n }),\n ).toContain('<div data-vyriy-root>');\n });\n\n it('removes React generated resource hints from the hydration root', () => {\n process.env.MODE = 'open';\n process.env.TAG = 'vyriy-profile-card';\n process.env.UI = 'http://localhost:3002';\n\n expect(\n prerender({\n avatarUrl: 'https://example.com/avatar.png',\n name: 'Name',\n }),\n ).not.toContain('rel=\"preload\"');\n });\n});\n",
|
|
23
23
|
'packages/api/prerender.tsx': "import { html } from '@vyriy/render';\n\nimport { ProfileCard } from '@p/components/profile-card';\n\nimport { getTag, getMode, getUi } from '@p/env';\n\nimport type { Prerender } from './types.js';\n\ntype AttributeValue = string | string[] | undefined;\n\nconst escapeAttribute = (value: string): string => {\n return value.replaceAll('&', '&').replaceAll('\"', '"').replaceAll('<', '<').replaceAll('>', '>');\n};\n\nconst getAttributeValue = (value: AttributeValue): string | undefined => {\n if (value === undefined) {\n return undefined;\n }\n\n return Array.isArray(value) ? JSON.stringify(value) : value;\n};\n\nconst getAttribute = (name: string, value: AttributeValue): string => {\n const attributeValue = getAttributeValue(value);\n\n if (attributeValue === undefined) {\n return '';\n }\n\n return ` ${name}=\"${escapeAttribute(attributeValue)}\"`;\n};\n\nconst getProfileCardAttributes = (props: Parameters<Prerender>[0]): string => {\n return [\n getAttribute('name', props.name),\n getAttribute('title', props.title),\n getAttribute('description', props.description),\n getAttribute('avatarUrl', props.avatarUrl),\n getAttribute('tags', props.tags),\n ].join('');\n};\n\nconst removeReactResourceHints = (value: string): string => {\n return value.replaceAll(/<link\\b(?=[^>]*\\brel=\"preload\")[^>]*>/g, '');\n};\n\n/** Renders a profile card custom element with declarative shadow DOM for hydration. */\nexport const prerender: Prerender = (props) => {\n const tag = getTag();\n const mode = getMode();\n const body = removeReactResourceHints(html(<ProfileCard {...props} />));\n\n return [\n `<${tag}${getProfileCardAttributes(props)} rendered>`,\n `<template shadowrootmode=\"${mode}\">`,\n `<link rel=\"stylesheet\" href=\"${getUi()}/main.css\" />`,\n `<div data-vyriy-root>${body}</div>`,\n `</template>`,\n `</${tag}>`,\n ].join('');\n};\n",
|
|
24
|
-
'packages/api/README.md':
|
|
24
|
+
'packages/api/README.md': `# API
|
|
25
|
+
|
|
26
|
+
Server-side document builders for the profile-card microfrontend.
|
|
27
|
+
|
|
28
|
+
## Exports
|
|
29
|
+
|
|
30
|
+
- \`demo()\` returns a standalone HTML demo document.
|
|
31
|
+
- \`prerender(props)\` returns SSR custom element markup with declarative shadow DOM.
|
|
32
|
+
- \`semantic(props)\` returns Schema.org Person JSON-LD.
|
|
33
|
+
- \`manifest()\` returns the OpenMFE manifest YAML.
|
|
34
|
+
- \`Demo\`, \`Prerender\`, \`Semantic\`, and \`Manifest\` describe the public builder signatures.
|
|
35
|
+
|
|
36
|
+
## Props
|
|
37
|
+
|
|
38
|
+
The renderers accept the shared profile-card data model from \`@p/components\`:
|
|
39
|
+
|
|
40
|
+
- \`name\` is required.
|
|
41
|
+
- \`title\`, \`description\`, \`avatarUrl\`, and \`tags\` are optional.
|
|
42
|
+
|
|
43
|
+
\`prerender(props)\` serializes those values onto the configured custom element tag and includes the UI stylesheet inside the declarative shadow root.
|
|
44
|
+
|
|
45
|
+
## Environment
|
|
46
|
+
|
|
47
|
+
The builders read required runtime configuration through \`@p/env\`:
|
|
48
|
+
|
|
49
|
+
- \`TAG\` custom element tag name.
|
|
50
|
+
- \`MODE\` shadow root mode.
|
|
51
|
+
- \`API\` API origin used in the manifest.
|
|
52
|
+
- \`CDN\` static asset origin used in the manifest.
|
|
53
|
+
- \`UI\` UI asset origin used by demo and prerender output.
|
|
54
|
+
|
|
55
|
+
## Example
|
|
56
|
+
|
|
57
|
+
\`\`\`ts
|
|
58
|
+
import { prerender, semantic } from '@p/api';
|
|
59
|
+
|
|
60
|
+
const props = {
|
|
61
|
+
name: 'Ada Lovelace',
|
|
62
|
+
title: 'Mathematician',
|
|
63
|
+
tags: ['math', 'computing'],
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const html = prerender(props);
|
|
67
|
+
const jsonLd = semantic(props);
|
|
68
|
+
\`\`\`
|
|
69
|
+
`,
|
|
25
70
|
'packages/api/semantic.test.ts': "import { describe, expect, it } from '@jest/globals';\n\nimport { semantic } from './semantic.js';\n\ndescribe('semantic', () => {\n it('serializes profile-card props as Schema.org JSON-LD', () => {\n expect(\n JSON.parse(\n semantic({\n avatarUrl: 'https://example.com/avatar.png',\n name: 'Ada Lovelace',\n title: 'Mathematician',\n }),\n ),\n ).toEqual({\n '@context': 'https://schema.org',\n '@type': 'Person',\n image: 'https://example.com/avatar.png',\n jobTitle: 'Mathematician',\n name: 'Ada Lovelace',\n });\n });\n});\n",
|
|
26
71
|
'packages/api/semantic.ts': "import type { Semantic } from './types.js';\n\n/** Serializes profile-card props as Schema.org Person JSON-LD. */\nexport const semantic: Semantic = (params) =>\n JSON.stringify({\n '@context': 'https://schema.org',\n '@type': 'Person',\n name: params.name,\n jobTitle: params.title,\n image: params.avatarUrl,\n });\n",
|
|
27
72
|
'packages/api/types.ts': "import type { ProfileCard } from '@p/components/profile-card/types.js';\n\n/** Builds the standalone HTML demo document. */\nexport type Demo = () => string;\n\n/** Builds server-rendered custom element markup from profile-card props. */\nexport type Prerender = (props: ProfileCard) => string;\n\n/** Builds semantic JSON-LD from profile-card props. */\nexport type Semantic = (props: ProfileCard) => string;\n\n/** Builds the OpenMFE manifest YAML document. */\nexport type Manifest = () => string;\n",
|
|
@@ -31,7 +76,39 @@ const projectFiles = {
|
|
|
31
76
|
'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 'TAG',\n 'MODE',\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.getTag).toBeDefined();\n expect(publicApi.getMode).toBeDefined();\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.TAG = 'vyriy-profile-card';\n process.env.MODE = 'open';\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.getTag()).toBe('vyriy-profile-card');\n expect(publicApi.getMode()).toBe('open');\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",
|
|
32
77
|
'packages/env/index.ts': "export * from './env.js';\n",
|
|
33
78
|
'packages/env/package.json': '{\n "name": "@p/env",\n "type": "module",\n "private": true\n}\n',
|
|
34
|
-
'packages/env/README.md':
|
|
79
|
+
'packages/env/README.md': `# Env
|
|
80
|
+
|
|
81
|
+
Required environment readers shared by API and UI workspaces.
|
|
82
|
+
|
|
83
|
+
## Exports
|
|
84
|
+
|
|
85
|
+
- \`getTag()\` reads \`TAG\`.
|
|
86
|
+
- \`getMode()\` reads \`MODE\`.
|
|
87
|
+
- \`getApi()\` reads \`API\`.
|
|
88
|
+
- \`getCdn()\` reads \`CDN\`.
|
|
89
|
+
- \`getUi()\` reads \`UI\`.
|
|
90
|
+
|
|
91
|
+
Each getter delegates to \`@vyriy/env\` and throws when its environment variable is missing.
|
|
92
|
+
|
|
93
|
+
## Local Defaults
|
|
94
|
+
|
|
95
|
+
\`workspaces/env.sh\` provides the local development defaults:
|
|
96
|
+
|
|
97
|
+
- \`API=http://localhost:3000\`
|
|
98
|
+
- \`CDN=http://localhost:3001\`
|
|
99
|
+
- \`UI=http://localhost:3002\`
|
|
100
|
+
- \`TAG=vyriy-profile-card\`
|
|
101
|
+
- \`MODE=open\`
|
|
102
|
+
|
|
103
|
+
## Example
|
|
104
|
+
|
|
105
|
+
\`\`\`ts
|
|
106
|
+
import { getCdn, getUi } from '@p/env';
|
|
107
|
+
|
|
108
|
+
const stylesheet = \`\${getUi()}/main.css\`;
|
|
109
|
+
const avatar = \`\${getCdn()}/avatar.svg\`;
|
|
110
|
+
\`\`\`
|
|
111
|
+
`,
|
|
35
112
|
'packages/event/constants.test.ts': "import { describe, expect, it } from '@jest/globals';\n\nimport { PROFILE_CARD_ANALYTICS_EVENT_NAME, PROFILE_CARD_SELECT_EVENT_NAME } from './constants.js';\n\ndescribe('event constants', () => {\n it('matches the manifest event names', () => {\n expect(PROFILE_CARD_ANALYTICS_EVENT_NAME).toBe('openmfe.analytics');\n expect(PROFILE_CARD_SELECT_EVENT_NAME).toBe('vyriy-profile-card.select');\n });\n});\n",
|
|
36
113
|
'packages/event/constants.ts': "/** Custom event emitted when the profile card is selected. */\nexport const PROFILE_CARD_SELECT_EVENT_NAME = 'vyriy-profile-card.select';\n\n/** Standard OpenMFE analytics event emitted for profile-card interactions. */\nexport const PROFILE_CARD_ANALYTICS_EVENT_NAME = 'openmfe.analytics';\n",
|
|
37
114
|
'packages/event/doc.mdx': "import { Meta, Markdown } from '@storybook/addon-docs/blocks';\nimport ReadMe from './README.md?raw';\n\n<Meta title=\"Packages/Event\" />\n\n<Markdown>{ReadMe}</Markdown>\n",
|
|
@@ -41,7 +118,45 @@ const projectFiles = {
|
|
|
41
118
|
'packages/event/profile-card-analytics.ts': "import { dispatchAnalyticsEvent } from '@vyriy/event';\n\nimport type { ProfileCardAnalyticsData } from './types.js';\n\n/** Dispatches the standard OpenMFE analytics event for a profile-card selection. */\nexport const dispatchProfileCardAnalyticsEvent = (target: HTMLElement, data: ProfileCardAnalyticsData): CustomEvent => {\n return dispatchAnalyticsEvent(\n target,\n {\n action: 'select',\n category: 'profile-card',\n data,\n name: 'profile_card_select',\n },\n {\n bubbles: true,\n composed: true,\n },\n );\n};\n",
|
|
42
119
|
'packages/event/profile-card-select.test.ts': "import { describe, expect, it, jest } from '@jest/globals';\n\nimport { PROFILE_CARD_SELECT_EVENT_NAME } from './constants.js';\nimport { dispatchProfileCardSelectEvent } from './profile-card-select.js';\n\ndescribe('dispatchProfileCardSelectEvent', () => {\n it('dispatches the profile card select event from the custom element', () => {\n const target = document.createElement('vyriy-profile-card');\n const listener = jest.fn();\n\n target.addEventListener(PROFILE_CARD_SELECT_EVENT_NAME, listener);\n\n const event = dispatchProfileCardSelectEvent(target, {\n avatarUrl: 'https://example.com/avatar.png',\n name: 'Ada Lovelace',\n role: 'Mathematician',\n });\n\n expect(event.type).toBe(PROFILE_CARD_SELECT_EVENT_NAME);\n expect(event.bubbles).toBe(true);\n expect(event.composed).toBe(true);\n expect(event.detail).toEqual({\n avatarUrl: 'https://example.com/avatar.png',\n name: 'Ada Lovelace',\n role: 'Mathematician',\n });\n expect(listener).toHaveBeenCalledWith(event);\n });\n});\n",
|
|
43
120
|
'packages/event/profile-card-select.ts': "import { dispatchCustomEvent } from '@vyriy/event';\n\nimport { PROFILE_CARD_SELECT_EVENT_NAME } from './constants.js';\nimport type { ProfileCardSelectDetail } from './types.js';\n\n/** Dispatches the profile-card select custom event from the web component host. */\nexport const dispatchProfileCardSelectEvent = (\n target: HTMLElement,\n detail: ProfileCardSelectDetail,\n): CustomEvent<ProfileCardSelectDetail> => {\n return dispatchCustomEvent(target, PROFILE_CARD_SELECT_EVENT_NAME, detail, {\n bubbles: true,\n composed: true,\n });\n};\n",
|
|
44
|
-
'packages/event/README.md':
|
|
121
|
+
'packages/event/README.md': `# Event
|
|
122
|
+
|
|
123
|
+
Typed profile-card event helpers.
|
|
124
|
+
|
|
125
|
+
## Exports
|
|
126
|
+
|
|
127
|
+
- \`PROFILE_CARD_SELECT_EVENT_NAME\` is \`vyriy-profile-card.select\`.
|
|
128
|
+
- \`PROFILE_CARD_ANALYTICS_EVENT_NAME\` is \`openmfe.analytics\`.
|
|
129
|
+
- \`dispatchProfileCardSelectEvent(target, detail)\` dispatches the profile-card selection event.
|
|
130
|
+
- \`dispatchProfileCardAnalyticsEvent(target, data)\` dispatches the standard OpenMFE analytics event for the same selection.
|
|
131
|
+
- \`ProfileCardSelectDetail\` and \`ProfileCardAnalyticsData\` describe the event payloads.
|
|
132
|
+
|
|
133
|
+
Both dispatch helpers emit bubbling, composed custom events so consumers outside the custom element shadow root can observe them.
|
|
134
|
+
|
|
135
|
+
## Usage
|
|
136
|
+
|
|
137
|
+
\`\`\`ts
|
|
138
|
+
import { dispatchProfileCardAnalyticsEvent, dispatchProfileCardSelectEvent } from '@p/event';
|
|
139
|
+
|
|
140
|
+
const target = document.querySelector('vyriy-profile-card');
|
|
141
|
+
|
|
142
|
+
if (target instanceof HTMLElement) {
|
|
143
|
+
const detail = {
|
|
144
|
+
name: 'Ada Lovelace',
|
|
145
|
+
role: 'Mathematician',
|
|
146
|
+
avatarUrl: '/avatar.svg',
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
dispatchProfileCardSelectEvent(target, detail);
|
|
150
|
+
dispatchProfileCardAnalyticsEvent(target, detail);
|
|
151
|
+
}
|
|
152
|
+
\`\`\`
|
|
153
|
+
|
|
154
|
+
## Payload
|
|
155
|
+
|
|
156
|
+
\`ProfileCardSelectDetail\` requires \`name\` and accepts optional \`role\` and \`avatarUrl\`.
|
|
157
|
+
|
|
158
|
+
The analytics helper wraps the same data in the standard OpenMFE analytics event with \`action: 'select'\` and \`category: 'profile-card'\`.
|
|
159
|
+
`,
|
|
45
160
|
'packages/event/types.ts': '/** Detail payload for the profile-card select custom event. */\nexport type ProfileCardSelectDetail = {\n name: string;\n role?: string;\n avatarUrl?: string | null;\n};\n\n/** Analytics data payload emitted for profile-card selections. */\nexport type ProfileCardAnalyticsData = ProfileCardSelectDetail;\n',
|
|
46
161
|
'packages/query/doc.mdx': "import { Meta, Markdown } from '@storybook/addon-docs/blocks';\nimport ReadMe from './README.md?raw';\n\n<Meta title=\"Packages/Query\" />\n\n<Markdown>{ReadMe}</Markdown>\n",
|
|
47
162
|
'packages/query/index.test.ts': "import { describe, expect, it } from '@jest/globals';\n\nimport * as publicApi from './index.js';\n\ndescribe('query public API', () => {\n it('exports query parsers', () => {\n expect(publicApi.parseProfileCardQuery).toBeDefined();\n });\n});\n",
|
|
@@ -49,7 +164,42 @@ const projectFiles = {
|
|
|
49
164
|
'packages/query/package.json': '{\n "name": "@p/query",\n "type": "module",\n "private": true\n}\n',
|
|
50
165
|
'packages/query/profile-card.test.ts': "import { describe, expect, it } from '@jest/globals';\n\nimport { parseProfileCardQuery } from './profile-card.js';\n\ndescribe('parseProfileCardQuery', () => {\n it('returns undefined when name is missing', () => {\n expect(parseProfileCardQuery(undefined)).toBeUndefined();\n expect(parseProfileCardQuery({})).toBeUndefined();\n expect(parseProfileCardQuery({ name: '' })).toBeUndefined();\n });\n\n it('parses supported profile card fields', () => {\n expect(\n parseProfileCardQuery({\n avatarUrl: 'https://example.com/avatar.png',\n description: 'Profile description',\n name: 'Name',\n tags: 'one, two,, three ',\n title: 'Title',\n }),\n ).toEqual({\n avatarUrl: 'https://example.com/avatar.png',\n description: 'Profile description',\n name: 'Name',\n tags: ['one', 'two', 'three'],\n title: 'Title',\n });\n });\n\n it('omits tags when the query list is empty after trimming', () => {\n expect(\n parseProfileCardQuery({\n name: 'Name',\n tags: ', , ',\n }),\n ).toEqual({\n name: 'Name',\n tags: undefined,\n });\n });\n});\n",
|
|
51
166
|
'packages/query/profile-card.ts': "import type { ParseProfileCardQuery, Query } from './types.js';\n\nconst getQueryValue = (query: Query, name: string): string | undefined => {\n const value = query?.[name];\n\n return value === '' ? undefined : value;\n};\n\nconst getQueryList = (query: Query, name: string): string[] | undefined => {\n const value = getQueryValue(query, name);\n\n if (!value) {\n return undefined;\n }\n\n const list = value\n .split(',')\n .map((item) => item.trim())\n .filter(Boolean);\n\n return list.length > 0 ? list : undefined;\n};\n\n/** Parses request query parameters into profile-card props. */\nexport const parseProfileCardQuery: ParseProfileCardQuery = (query) => {\n const name = getQueryValue(query, 'name');\n\n if (!name) {\n return undefined;\n }\n\n return {\n name,\n title: getQueryValue(query, 'title'),\n description: getQueryValue(query, 'description'),\n avatarUrl: getQueryValue(query, 'avatarUrl'),\n tags: getQueryList(query, 'tags'),\n };\n};\n",
|
|
52
|
-
'packages/query/README.md':
|
|
167
|
+
'packages/query/README.md': `# Query
|
|
168
|
+
|
|
169
|
+
Query-string parsers for profile-card API endpoints.
|
|
170
|
+
|
|
171
|
+
## Exports
|
|
172
|
+
|
|
173
|
+
- \`parseProfileCardQuery(query)\` converts router query parameters into profile-card props.
|
|
174
|
+
- \`Query\` describes the router query input shape.
|
|
175
|
+
- \`ParseProfileCardQuery\` describes the parser signature.
|
|
176
|
+
|
|
177
|
+
## Parameters
|
|
178
|
+
|
|
179
|
+
\`name\` is required. When \`name\` is missing or empty, the parser returns \`undefined\`.
|
|
180
|
+
|
|
181
|
+
Supported optional parameters:
|
|
182
|
+
|
|
183
|
+
- \`title\`
|
|
184
|
+
- \`description\`
|
|
185
|
+
- \`avatarUrl\`
|
|
186
|
+
- \`tags\`, as a comma-separated list
|
|
187
|
+
|
|
188
|
+
Empty string values are treated as missing. \`tags\` are split on commas, trimmed, and empty items are removed.
|
|
189
|
+
|
|
190
|
+
## Example
|
|
191
|
+
|
|
192
|
+
\`\`\`ts
|
|
193
|
+
import { parseProfileCardQuery } from '@p/query';
|
|
194
|
+
|
|
195
|
+
const props = parseProfileCardQuery({
|
|
196
|
+
name: 'Ada Lovelace',
|
|
197
|
+
title: 'Mathematician',
|
|
198
|
+
description: 'First computer programmer.',
|
|
199
|
+
tags: 'math, computing',
|
|
200
|
+
});
|
|
201
|
+
\`\`\`
|
|
202
|
+
`,
|
|
53
203
|
'packages/query/types.ts': "import type { ProfileCard } from '@p/components/profile-card/types.js';\n\n/** Query string values provided by the API router. */\nexport type Query = Record<string, string | undefined> | undefined;\n\n/** Converts query string values into profile-card props or rejects incomplete input. */\nexport type ParseProfileCardQuery = (query: Query) => ProfileCard | undefined;\n",
|
|
54
204
|
'stylelint.config.ts': "export { default } from '@vyriy/stylelint-config';\n",
|
|
55
205
|
'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',
|
|
@@ -58,25 +208,213 @@ const projectFiles = {
|
|
|
58
208
|
'workspaces/api/index.test.ts': "import { describe, expect, it, jest } from '@jest/globals';\nimport type { APIGatewayProxyEvent } from '@vyriy/router';\n\nconst apiMock = jest.fn((handler) => ({\n handler,\n}));\nconst serverMock = jest.fn();\n\njest.mock('@vyriy/handler', () => ({\n api: apiMock,\n}));\n\njest.mock('@vyriy/server', () => ({\n server: serverMock,\n}));\n\ndescribe('workspaces/api/index.ts', () => {\n const getEvent = (\n path: string,\n queryStringParameters: APIGatewayProxyEvent['queryStringParameters'] = null,\n ): APIGatewayProxyEvent =>\n ({\n body: null,\n headers: {},\n httpMethod: 'GET',\n path,\n pathParameters: null,\n queryStringParameters,\n }) as APIGatewayProxyEvent;\n\n it('starts the server with the API router handler', async () => {\n process.env.MODE = 'open';\n process.env.TAG = 'vyriy-profile-card';\n process.env.API = 'http://localhost:3000';\n process.env.CDN = 'http://localhost:3001';\n process.env.UI = 'http://localhost:3002';\n\n await import('./index.js');\n\n expect(apiMock).toHaveBeenCalledTimes(1);\n expect(serverMock).toHaveBeenCalledTimes(1);\n expect(serverMock).toHaveBeenCalledWith(apiMock.mock.results[0]?.value);\n\n const handler = apiMock.mock.calls[0]?.[0] as (event: APIGatewayProxyEvent) => Promise<{\n body: string;\n headers?: Record<string, string>;\n statusCode: number;\n }>;\n\n await expect(handler(getEvent('/'))).resolves.toEqual({\n body: expect.stringContaining('<vyriy-profile-card'),\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\n await expect(handler(getEvent('/prerender'))).resolves.toEqual({\n body: JSON.stringify({\n message: 'Query parameter \"name\" is required.',\n }),\n headers: undefined,\n isBase64Encoded: undefined,\n multiValueHeaders: undefined,\n statusCode: 400,\n });\n\n const prerenderResponse = await handler(\n getEvent('/prerender', {\n description: 'Profile description',\n name: 'Name',\n tags: 'one, two',\n title: 'Title',\n }),\n );\n\n expect(prerenderResponse).toEqual({\n body: expect.stringContaining('Name'),\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(prerenderResponse.body).toContain('shadowrootmode=\"open\"');\n expect(prerenderResponse.body).toContain('http://localhost:3002/main.css');\n\n await expect(handler(getEvent('/semantic', { name: 'Name' }))).resolves.toEqual({\n body: JSON.stringify({\n '@context': 'https://schema.org',\n '@type': 'Person',\n name: 'Name',\n }),\n headers: {\n 'access-control-allow-origin': '*',\n 'cache-control': 'public, max-age=300, s-maxage=3600, stale-while-revalidate=86400',\n 'content-type': 'application/ld+json; charset=utf-8',\n 'x-content-type-options': 'nosniff',\n },\n isBase64Encoded: undefined,\n multiValueHeaders: undefined,\n statusCode: 200,\n });\n\n await expect(handler(getEvent('/semantic'))).resolves.toEqual({\n body: JSON.stringify({\n message: 'Query parameter \"name\" is required.',\n }),\n headers: undefined,\n isBase64Encoded: undefined,\n multiValueHeaders: undefined,\n statusCode: 400,\n });\n\n await expect(handler(getEvent('/manifest.yml'))).resolves.toEqual({\n body: expect.stringContaining(\"name: 'Vyriy Profile Card'\"),\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/yaml; charset=utf-8',\n 'x-content-type-options': 'nosniff',\n },\n isBase64Encoded: undefined,\n multiValueHeaders: undefined,\n statusCode: 200,\n });\n\n await expect(handler(getEvent('/healthcheck'))).resolves.toEqual({\n body: JSON.stringify({\n message: 'Not Found',\n }),\n statusCode: 404,\n });\n });\n});\n",
|
|
59
209
|
'workspaces/api/index.ts': "import { server } from '@vyriy/server';\nimport { api } from '@vyriy/handler';\nimport { createRouter } from '@vyriy/router';\nimport { minify } from '@vyriy/html';\n\nimport { demo, manifest, prerender, semantic } from '@p/api';\nimport { parseProfileCardQuery } from '@p/query';\n\nserver(\n api(async (event) =>\n createRouter()\n .get('/', () => ({\n body: minify(demo()),\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 .get('/prerender', ({ query }) => {\n const profileCard = parseProfileCardQuery(query);\n\n if (!profileCard) {\n return {\n statusCode: 400,\n body: JSON.stringify({ message: 'Query parameter \"name\" is required.' }),\n };\n }\n\n return {\n body: minify(prerender(profileCard)),\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 })\n .get('/semantic', ({ query }) => {\n const profileCard = parseProfileCardQuery(query);\n\n if (!profileCard) {\n return {\n statusCode: 400,\n body: JSON.stringify({ message: 'Query parameter \"name\" is required.' }),\n };\n }\n\n return {\n body: semantic(profileCard),\n headers: {\n 'content-type': 'application/ld+json; 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 })\n .get('/manifest.yml', () => ({\n body: manifest(),\n headers: {\n 'content-type': 'text/yaml; 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",
|
|
60
210
|
'workspaces/api/package.json': '{\n "name": "@w/api",\n "type": "module",\n "private": true\n}\n',
|
|
61
|
-
'workspaces/api/README.md':
|
|
211
|
+
'workspaces/api/README.md': `# Api
|
|
212
|
+
|
|
213
|
+
Server workspace for the profile-card microfrontend.
|
|
214
|
+
|
|
215
|
+
## Routes
|
|
216
|
+
|
|
217
|
+
- \`GET /\` returns a standalone HTML demo page.
|
|
218
|
+
- \`GET /prerender\` returns server-rendered custom element HTML.
|
|
219
|
+
- \`GET /semantic\` returns Schema.org Person JSON-LD.
|
|
220
|
+
- \`GET /manifest.yml\` returns the OpenMFE manifest YAML.
|
|
221
|
+
|
|
222
|
+
\`/prerender\` and \`/semantic\` require the \`name\` query parameter. They also accept \`title\`, \`description\`, \`avatarUrl\`, and comma-separated \`tags\`.
|
|
223
|
+
|
|
224
|
+
## Local Development
|
|
225
|
+
|
|
226
|
+
\`\`\`bash
|
|
227
|
+
yarn start:api
|
|
228
|
+
\`\`\`
|
|
229
|
+
|
|
230
|
+
The start script loads \`workspaces/env.sh\`, listens on \`API_PORT\`, and prints example URLs for the demo, prerender, semantic, and manifest endpoints.
|
|
231
|
+
|
|
232
|
+
Default local URL:
|
|
233
|
+
|
|
234
|
+
\`\`\`text
|
|
235
|
+
http://localhost:3000
|
|
236
|
+
\`\`\`
|
|
237
|
+
|
|
238
|
+
## Build
|
|
239
|
+
|
|
240
|
+
\`\`\`bash
|
|
241
|
+
yarn build:api
|
|
242
|
+
\`\`\`
|
|
243
|
+
|
|
244
|
+
The build writes the server bundle to \`dist/api\`.
|
|
245
|
+
`,
|
|
62
246
|
'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 'MODE',\n 'TAG',\n 'UI',\n ]),\n ],\n }),\n);\n",
|
|
63
247
|
'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: "${TAG:=vyriy-profile-card}"\n: "${MODE:=open}"\n\nexport API_PORT\nexport CDN_PORT\nexport UI_PORT\nexport API\nexport CDN\nexport UI\nexport TAG\nexport MODE\n',
|
|
64
248
|
'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',
|
|
65
|
-
'workspaces/static/bin/start.sh':
|
|
249
|
+
'workspaces/static/bin/start.sh': `#!/usr/bin/env sh
|
|
250
|
+
|
|
251
|
+
set -e
|
|
252
|
+
|
|
253
|
+
scriptdir="$PWD/workspaces/static";
|
|
254
|
+
|
|
255
|
+
. "$PWD/workspaces/env.sh"
|
|
256
|
+
|
|
257
|
+
npx vs -p $CDN_PORT $scriptdir/public
|
|
258
|
+
`,
|
|
66
259
|
'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",
|
|
67
260
|
'workspaces/static/package.json': '{\n "name": "@w/static",\n "type": "module",\n "private": true\n}\n',
|
|
68
261
|
'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>',
|
|
69
262
|
'workspaces/static/public/icon.svg': '<svg\n width="256"\n height="256"\n viewBox="0 0 256 256"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n role="img"\n aria-labelledby="title description"\n>\n <title id="title">Vyriy Profile Card icon</title>\n <desc id="description">A calm rounded square icon with a profile card symbol.</desc>\n\n <rect width="256" height="256" rx="56" fill="#111827" />\n <rect x="56" y="48" width="144" height="160" rx="24" fill="#F9FAFB" />\n <circle cx="128" cy="104" r="36" fill="#9CA3AF" />\n <rect x="84" y="156" width="88" height="14" rx="7" fill="#111827" />\n <rect x="96" y="180" width="64" height="10" rx="5" fill="#6B7280" />\n <circle cx="184" cy="184" r="20" fill="#10B981" />\n <path\n d="M175 184L181 190L194 176"\n stroke="white"\n stroke-width="6"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n</svg>\n',
|
|
70
263
|
'workspaces/static/public/screenshots/compact.svg': '<svg\n width="1280"\n height="720"\n viewBox="0 0 1280 720"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n role="img"\n aria-labelledby="title description"\n>\n <title id="title">Default profile card screenshot</title>\n <desc id="description">A profile card microfrontend rendered in a desktop host page.</desc>\n\n <rect width="1280" height="720" fill="#F3F4F6" />\n <rect x="80" y="72" width="1120" height="576" rx="32" fill="white" />\n\n <rect x="128" y="120" width="360" height="480" rx="28" fill="#F9FAFB" stroke="#E5E7EB" />\n <circle cx="308" cy="244" r="72" fill="#9CA3AF" />\n <rect x="188" y="368" width="240" height="28" rx="14" fill="#111827" />\n <rect x="224" y="420" width="168" height="18" rx="9" fill="#6B7280" />\n <rect x="232" y="492" width="152" height="44" rx="22" fill="#10B981" />\n\n <rect x="560" y="152" width="420" height="40" rx="20" fill="#111827" />\n <rect x="560" y="232" width="520" height="20" rx="10" fill="#6B7280" />\n <rect x="560" y="272" width="460" height="20" rx="10" fill="#9CA3AF" />\n <rect x="560" y="312" width="360" height="20" rx="10" fill="#D1D5DB" />\n <rect x="560" y="420" width="520" height="96" rx="24" fill="#F9FAFB" stroke="#E5E7EB" />\n</svg>\n',
|
|
71
264
|
'workspaces/static/public/screenshots/default.svg': '<svg\n width="1280"\n height="720"\n viewBox="0 0 1280 720"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n role="img"\n aria-labelledby="title description"\n>\n <title id="title">Default profile card screenshot</title>\n <desc id="description">A profile card microfrontend rendered in a desktop host page.</desc>\n\n <rect width="1280" height="720" fill="#F3F4F6" />\n <rect x="80" y="72" width="1120" height="576" rx="32" fill="white" />\n\n <rect x="128" y="120" width="360" height="480" rx="28" fill="#F9FAFB" stroke="#E5E7EB" />\n <circle cx="308" cy="244" r="72" fill="#9CA3AF" />\n <rect x="188" y="368" width="240" height="28" rx="14" fill="#111827" />\n <rect x="224" y="420" width="168" height="18" rx="9" fill="#6B7280" />\n <rect x="232" y="492" width="152" height="44" rx="22" fill="#10B981" />\n\n <rect x="560" y="152" width="420" height="40" rx="20" fill="#111827" />\n <rect x="560" y="232" width="520" height="20" rx="10" fill="#6B7280" />\n <rect x="560" y="272" width="460" height="20" rx="10" fill="#9CA3AF" />\n <rect x="560" y="312" width="360" height="20" rx="10" fill="#D1D5DB" />\n <rect x="560" y="420" width="520" height="96" rx="24" fill="#F9FAFB" stroke="#E5E7EB" />\n</svg>\n',
|
|
72
|
-
'workspaces/static/README.md':
|
|
265
|
+
'workspaces/static/README.md': `# Static
|
|
266
|
+
|
|
267
|
+
Static asset workspace for the profile-card microfrontend.
|
|
268
|
+
|
|
269
|
+
This workspace uses \`@vyriy/static\` to serve files during local development. The package exposes the \`vs\` command, which can also be installed globally to serve static data from any directory with a simple command.
|
|
270
|
+
|
|
271
|
+
## Assets
|
|
272
|
+
|
|
273
|
+
- \`avatar.svg\` is the default demo avatar.
|
|
274
|
+
- \`icon.svg\` is the manifest icon.
|
|
275
|
+
- \`screenshots/default.svg\` documents the default profile-card state.
|
|
276
|
+
- \`screenshots/compact.svg\` documents the compact profile-card state.
|
|
277
|
+
|
|
278
|
+
The workspace is served as the CDN origin during local development and copied into \`dist/cdn\` for production builds.
|
|
279
|
+
|
|
280
|
+
## Local Development
|
|
281
|
+
|
|
282
|
+
\`\`\`bash
|
|
283
|
+
yarn start:static
|
|
284
|
+
\`\`\`
|
|
285
|
+
|
|
286
|
+
The start script loads \`workspaces/env.sh\` and serves \`workspaces/static/public\` on \`CDN_PORT\`.
|
|
287
|
+
|
|
288
|
+
Internally it runs:
|
|
289
|
+
|
|
290
|
+
\`\`\`bash
|
|
291
|
+
npx vs -p $CDN_PORT workspaces/static/public
|
|
292
|
+
\`\`\`
|
|
293
|
+
|
|
294
|
+
With \`@vyriy/static\` installed globally, the same kind of static preview can be started directly:
|
|
295
|
+
|
|
296
|
+
\`\`\`bash
|
|
297
|
+
vs -p 3001 workspaces/static/public
|
|
298
|
+
\`\`\`
|
|
299
|
+
|
|
300
|
+
Default local URL:
|
|
301
|
+
|
|
302
|
+
\`\`\`text
|
|
303
|
+
http://localhost:3001
|
|
304
|
+
\`\`\`
|
|
305
|
+
|
|
306
|
+
## Build
|
|
307
|
+
|
|
308
|
+
\`\`\`bash
|
|
309
|
+
yarn build:static
|
|
310
|
+
\`\`\`
|
|
311
|
+
`,
|
|
73
312
|
'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',
|
|
74
313
|
'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',
|
|
75
314
|
'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",
|
|
76
315
|
'workspaces/ui/index.test.tsx': "import { beforeAll, describe, expect, it, jest } from '@jest/globals';\nimport type { ReactElement } from 'react';\n\ntype CustomElementOptions = {\n tag: string;\n elements: () => {\n elements: HTMLElement[];\n root: HTMLElement;\n };\n render: (el: HTMLElement) => ReactElement<{\n onClick: () => void;\n tags?: string[];\n }>;\n};\n\nconst customElementMock = jest.fn();\nconst dispatchProfileCardAnalyticsEventMock = jest.fn();\nconst dispatchProfileCardSelectEventMock = jest.fn();\nlet options: CustomElementOptions;\n\njest.mock('@vyriy/render/custom-element', () => ({\n customElement: customElementMock,\n}));\n\njest.mock('@p/env', () => ({\n getUi: () => 'http://localhost:3002',\n}));\n\njest.mock('@p/event', () => ({\n dispatchProfileCardAnalyticsEvent: dispatchProfileCardAnalyticsEventMock,\n dispatchProfileCardSelectEvent: dispatchProfileCardSelectEventMock,\n}));\n\ndescribe('workspaces/ui/index.tsx', () => {\n beforeAll(async () => {\n await import('./index.js');\n\n [options] = (customElementMock.mock.calls[0] ?? []) as [CustomElementOptions];\n });\n\n it('registers the profile-card custom element with event dispatching', () => {\n const renderElements = options.elements();\n const host = document.createElement('vyriy-profile-card');\n\n host.setAttribute('avatarUrl', 'https://example.com/avatar.png');\n host.setAttribute('description', 'Profile description');\n host.setAttribute('name', 'Ada Lovelace');\n host.setAttribute('tags', '[\"math\",\"computing\"]');\n host.setAttribute('title', 'Mathematician');\n\n const element = options.render(host);\n\n element.props.onClick();\n\n expect(options.tag).toBe('vyriy-profile-card');\n expect(renderElements.root).toBeInstanceOf(HTMLDivElement);\n expect(renderElements.elements[0]).toBeInstanceOf(HTMLLinkElement);\n expect((renderElements.elements[0] as HTMLLinkElement).href).toBe('http://localhost:3002/main.css');\n expect(element.props.tags).toEqual(['math', 'computing']);\n expect(dispatchProfileCardSelectEventMock).toHaveBeenCalledWith(host, {\n avatarUrl: 'https://example.com/avatar.png',\n name: 'Ada Lovelace',\n role: 'Mathematician',\n });\n expect(dispatchProfileCardAnalyticsEventMock).toHaveBeenCalledWith(host, {\n avatarUrl: 'https://example.com/avatar.png',\n name: 'Ada Lovelace',\n role: 'Mathematician',\n });\n });\n\n it('ignores missing and invalid tags attributes', () => {\n const host = document.createElement('vyriy-profile-card');\n\n expect(options.render(host).props.tags).toBeUndefined();\n\n host.setAttribute('tags', 'not json');\n\n expect(options.render(host).props.tags).toBeUndefined();\n\n host.setAttribute('tags', '{\"tag\":\"math\"}');\n\n expect(options.render(host).props.tags).toBeUndefined();\n });\n\n it('falls back to empty profile values when attributes are missing', () => {\n const host = document.createElement('vyriy-profile-card');\n const element = options.render(host);\n\n element.props.onClick();\n\n expect(dispatchProfileCardSelectEventMock).toHaveBeenLastCalledWith(host, {\n avatarUrl: null,\n name: '',\n role: undefined,\n });\n });\n});\n",
|
|
77
|
-
'workspaces/ui/index.tsx':
|
|
316
|
+
'workspaces/ui/index.tsx': `import { customElement } from '@vyriy/render/custom-element';
|
|
317
|
+
|
|
318
|
+
import { dispatchProfileCardAnalyticsEvent, dispatchProfileCardSelectEvent } from '@p/event';
|
|
319
|
+
import { getUi } from '@p/env';
|
|
320
|
+
|
|
321
|
+
import { ProfileCard } from '@p/components/profile-card';
|
|
322
|
+
import '@p/components/styles.scss';
|
|
323
|
+
|
|
324
|
+
const parseJsonAttribute = (value: string | null): string[] | undefined => {
|
|
325
|
+
if (!value) {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const parsedValue: unknown = JSON.parse(value);
|
|
331
|
+
|
|
332
|
+
if (Array.isArray(parsedValue) && parsedValue.every((item) => typeof item === 'string')) {
|
|
333
|
+
return parsedValue;
|
|
334
|
+
}
|
|
335
|
+
} catch {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return undefined;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const getProfileCardSelectDetail = (el: HTMLElement) => ({
|
|
343
|
+
avatarUrl: el.getAttribute('avatarUrl'),
|
|
344
|
+
name: el.getAttribute('name') ?? '',
|
|
345
|
+
role: el.getAttribute('title') ?? undefined,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
customElement({
|
|
349
|
+
tag: 'vyriy-profile-card',
|
|
350
|
+
elements: () => {
|
|
351
|
+
const link = document.createElement('link');
|
|
352
|
+
const container = document.createElement('div');
|
|
353
|
+
|
|
354
|
+
link.rel = 'stylesheet';
|
|
355
|
+
link.href = \`\${getUi()}/main.css\`;
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
elements: [link, container],
|
|
359
|
+
root: container,
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
render: (el) => (
|
|
363
|
+
<ProfileCard
|
|
364
|
+
avatarUrl={el.getAttribute('avatarUrl') ?? ''}
|
|
365
|
+
description={el.getAttribute('description') ?? ''}
|
|
366
|
+
name={el.getAttribute('name') ?? ''}
|
|
367
|
+
onClick={() => {
|
|
368
|
+
const detail = getProfileCardSelectDetail(el);
|
|
369
|
+
|
|
370
|
+
dispatchProfileCardSelectEvent(el, detail);
|
|
371
|
+
dispatchProfileCardAnalyticsEvent(el, detail);
|
|
372
|
+
}}
|
|
373
|
+
tags={parseJsonAttribute(el.getAttribute('tags'))}
|
|
374
|
+
title={el.getAttribute('title') ?? ''}
|
|
375
|
+
/>
|
|
376
|
+
),
|
|
377
|
+
});
|
|
378
|
+
`,
|
|
78
379
|
'workspaces/ui/package.json': '{\n "name": "@w/ui",\n "type": "module",\n "private": true\n}\n',
|
|
79
|
-
'workspaces/ui/README.md':
|
|
380
|
+
'workspaces/ui/README.md': `# UI
|
|
381
|
+
|
|
382
|
+
Browser workspace for the \`vyriy-profile-card\` custom element.
|
|
383
|
+
|
|
384
|
+
## Runtime
|
|
385
|
+
|
|
386
|
+
The entry point registers the custom element and renders \`ProfileCard\` inside its shadow root. The element reads these attributes:
|
|
387
|
+
|
|
388
|
+
- \`name\`
|
|
389
|
+
- \`title\`
|
|
390
|
+
- \`description\`
|
|
391
|
+
- \`avatarUrl\`
|
|
392
|
+
- \`tags\`, as a JSON string array
|
|
393
|
+
|
|
394
|
+
Clicking the rendered profile card dispatches \`vyriy-profile-card.select\` and \`openmfe.analytics\`.
|
|
395
|
+
|
|
396
|
+
## Local Development
|
|
397
|
+
|
|
398
|
+
\`\`\`bash
|
|
399
|
+
yarn start:ui
|
|
400
|
+
\`\`\`
|
|
401
|
+
|
|
402
|
+
The start script loads \`workspaces/env.sh\`, starts webpack dev server on \`UI_PORT\`, and opens the generated demo page.
|
|
403
|
+
|
|
404
|
+
Default local URL:
|
|
405
|
+
|
|
406
|
+
\`\`\`text
|
|
407
|
+
http://localhost:3002
|
|
408
|
+
\`\`\`
|
|
409
|
+
|
|
410
|
+
## Build
|
|
411
|
+
|
|
412
|
+
\`\`\`bash
|
|
413
|
+
yarn build:ui
|
|
414
|
+
\`\`\`
|
|
415
|
+
|
|
416
|
+
The build writes \`index.js\`, \`main.css\`, and the generated demo HTML into \`dist/cdn\`.
|
|
417
|
+
`,
|
|
80
418
|
'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 {\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: '<vyriy-profile-card name=\"Developer\" title=\"Senior IT Professional\" avatarUrl=\"http://localhost:3001/avatar.svg\"></vyriy-profile-card>',\n script: [\n '<script defer=\"defer\" src=\"/index.js\"></script>',\n [\n '<script type=\"module\">',\n \"const card = document.querySelector('vyriy-profile-card');\",\n \"card.addEventListener('vyriy-profile-card.select', (event) => {\",\n \" console.log('UI demo event:', event.detail);\",\n '});',\n '</scr' + 'ipt>',\n ].join(''),\n ].join(''),\n },\n { inject: false },\n ),\n ],\n }),\n);\n",
|
|
81
419
|
};
|
|
82
420
|
export const mfe = (options) => ({
|
|
@@ -276,7 +614,49 @@ export default {
|
|
|
276
614
|
'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",
|
|
277
615
|
'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',
|
|
278
616
|
'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",
|
|
279
|
-
'packages/components/README.md':
|
|
617
|
+
'packages/components/README.md': `# Components
|
|
618
|
+
|
|
619
|
+
Reusable React primitives for the profile-card microfrontend.
|
|
620
|
+
|
|
621
|
+
## Exports
|
|
622
|
+
|
|
623
|
+
The package exports the public profile-card component set:
|
|
624
|
+
|
|
625
|
+
- \`Avatar\`
|
|
626
|
+
- \`Badge\`
|
|
627
|
+
- \`ButtonLink\`
|
|
628
|
+
- \`Card\`
|
|
629
|
+
- \`IconLink\`
|
|
630
|
+
- \`ProfileCard\`
|
|
631
|
+
- \`ProfileDetails\`
|
|
632
|
+
- \`ProfileHeader\`
|
|
633
|
+
- \`ProfileLinks\`
|
|
634
|
+
- \`ProfileMeta\`
|
|
635
|
+
- \`ProfileTags\`
|
|
636
|
+
|
|
637
|
+
Each component also exports its public prop and component types from its folder entry point.
|
|
638
|
+
|
|
639
|
+
## Usage
|
|
640
|
+
|
|
641
|
+
\`\`\`tsx
|
|
642
|
+
import { ProfileCard } from '@p/components';
|
|
643
|
+
import '@p/components/styles.scss';
|
|
644
|
+
|
|
645
|
+
export const Example = () => (
|
|
646
|
+
<ProfileCard
|
|
647
|
+
avatarUrl="/avatar.svg"
|
|
648
|
+
description="First computer programmer."
|
|
649
|
+
name="Ada Lovelace"
|
|
650
|
+
tags={['math', 'computing']}
|
|
651
|
+
title="Mathematician"
|
|
652
|
+
/>
|
|
653
|
+
);
|
|
654
|
+
\`\`\`
|
|
655
|
+
|
|
656
|
+
## Component Docs
|
|
657
|
+
|
|
658
|
+
Each component has a focused README, Storybook docs, stories, and unit tests in its own folder. Use those folder READMEs for prop-level details and supported visual states.
|
|
659
|
+
`,
|
|
280
660
|
'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",
|
|
281
661
|
'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",
|
|
282
662
|
'packages/components/package.json': JSON.stringify({
|
|
@@ -354,18 +734,21 @@ export default {
|
|
|
354
734
|
'npm-run-all2': packageJson.peerDependencies['npm-run-all2'],
|
|
355
735
|
prettier: packageJson.peerDependencies['prettier'],
|
|
356
736
|
rimraf: packageJson.peerDependencies['rimraf'],
|
|
357
|
-
serve: packageJson.peerDependencies['serve'],
|
|
358
737
|
storybook: packageJson.peerDependencies['storybook'],
|
|
359
738
|
stylelint: packageJson.peerDependencies['stylelint'],
|
|
360
739
|
tsx: packageJson.peerDependencies['tsx'],
|
|
361
740
|
typescript: packageJson.peerDependencies['typescript'],
|
|
362
741
|
webpack: packageJson.peerDependencies['webpack'],
|
|
363
742
|
'webpack-cli': packageJson.peerDependencies['webpack-cli'],
|
|
743
|
+
'@vyriy/static': `^${packageJson.version}`,
|
|
364
744
|
},
|
|
365
745
|
}, null, 2) + '\n',
|
|
366
|
-
'README.md': `#
|
|
746
|
+
'README.md': `# MFE
|
|
747
|
+
|
|
748
|
+
Profile-card microfrontend starter for Vyriy and OpenMFE-oriented development.
|
|
367
749
|
|
|
368
|
-
|
|
750
|
+
The repository is split into reusable packages and runnable workspaces. Packages own typed component, API, event, query, and environment behavior.
|
|
751
|
+
Workspaces compose those packages into the local API server, static asset origin, and browser custom element build.
|
|
369
752
|
|
|
370
753
|
## Setup
|
|
371
754
|
|
|
@@ -373,6 +756,17 @@ ${options.description}
|
|
|
373
756
|
yarn install
|
|
374
757
|
\`\`\`
|
|
375
758
|
|
|
759
|
+
## Project Structure
|
|
760
|
+
|
|
761
|
+
- \`packages/api\` builds demo HTML, prerendered custom element markup, JSON-LD, and the OpenMFE manifest.
|
|
762
|
+
- \`packages/components\` provides the React profile-card component set.
|
|
763
|
+
- \`packages/env\` reads required runtime environment values.
|
|
764
|
+
- \`packages/event\` dispatches typed profile-card selection and analytics events.
|
|
765
|
+
- \`packages/query\` parses API query strings into profile-card props.
|
|
766
|
+
- \`workspaces/api\` serves the demo, prerender, semantic, and manifest endpoints.
|
|
767
|
+
- \`workspaces/static\` serves CDN assets such as the avatar, manifest icon, and screenshots with \`@vyriy/static\`.
|
|
768
|
+
- \`workspaces/ui\` registers the \`vyriy-profile-card\` custom element and builds browser assets.
|
|
769
|
+
|
|
376
770
|
## Start
|
|
377
771
|
|
|
378
772
|
Start the API, static asset server, and UI dev server together:
|
|
@@ -391,12 +785,17 @@ yarn start:ui
|
|
|
391
785
|
|
|
392
786
|
## Local URLs
|
|
393
787
|
|
|
394
|
-
Default ports are defined in \`workspaces/env.sh\`:
|
|
788
|
+
Default ports and origins are defined in \`workspaces/env.sh\`:
|
|
395
789
|
|
|
396
790
|
- API: \`http://localhost:3000\`
|
|
397
791
|
- Static/CDN assets: \`http://localhost:3001\`
|
|
398
792
|
- UI dev server: \`http://localhost:3002\`
|
|
399
793
|
|
|
794
|
+
Default runtime values:
|
|
795
|
+
|
|
796
|
+
- \`TAG=vyriy-profile-card\`
|
|
797
|
+
- \`MODE=open\`
|
|
798
|
+
|
|
400
799
|
Useful API URLs:
|
|
401
800
|
|
|
402
801
|
- Demo HTML: \`http://localhost:3000/\`
|
|
@@ -404,18 +803,54 @@ Useful API URLs:
|
|
|
404
803
|
- Semantic JSON-LD: \`http://localhost:3000/semantic?name=Developer&title=Senior%20IT%20Professional&avatarUrl=http://localhost:3001/avatar.svg\`
|
|
405
804
|
- Manifest: \`http://localhost:3000/manifest.yml\`
|
|
406
805
|
|
|
806
|
+
\`/prerender\` and \`/semantic\` require \`name\` and accept optional \`title\`, \`description\`, \`avatarUrl\`, and comma-separated \`tags\`.
|
|
807
|
+
|
|
808
|
+
## Static Assets
|
|
809
|
+
|
|
810
|
+
Static files are served with \`@vyriy/static\`. The package exposes the \`vs\` command, so a globally installed copy can serve any static directory with a small command:
|
|
811
|
+
|
|
812
|
+
\`\`\`bash
|
|
813
|
+
vs -p 3001 workspaces/static/public
|
|
814
|
+
\`\`\`
|
|
815
|
+
|
|
816
|
+
In this project, \`yarn start:static\` runs the same static server through \`npx vs\` and the \`CDN_PORT\` value from \`workspaces/env.sh\`.
|
|
817
|
+
|
|
818
|
+
## Build
|
|
819
|
+
|
|
820
|
+
\`\`\`bash
|
|
821
|
+
yarn build
|
|
822
|
+
\`\`\`
|
|
823
|
+
|
|
824
|
+
The build writes server output to \`dist/api\` and browser/static CDN output to \`dist/cdn\`.
|
|
825
|
+
|
|
407
826
|
## Validation
|
|
408
827
|
|
|
828
|
+
\`\`\`bash
|
|
829
|
+
yarn check
|
|
830
|
+
\`\`\`
|
|
831
|
+
|
|
832
|
+
Focused validation commands:
|
|
833
|
+
|
|
409
834
|
\`\`\`bash
|
|
410
835
|
yarn lint
|
|
411
836
|
yarn test
|
|
412
837
|
yarn build
|
|
413
838
|
\`\`\`
|
|
839
|
+
|
|
840
|
+
## Project Guidance
|
|
841
|
+
|
|
842
|
+
These articles describe the development approach behind this preset and provide practical guidance for evolving a project on top of it:
|
|
843
|
+
|
|
844
|
+
- [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.
|
|
845
|
+
- [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.
|
|
846
|
+
- [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.
|
|
847
|
+
- [Calm Component Structure](https://vyriy.dev/blog/calm-component-structure/) - how to organize component code, tests, stories, and public exports.
|
|
848
|
+
- [Storybook as Project Documentation](https://vyriy.dev/blog/storybook-as-project-documentation/) - how to use Storybook as living project documentation and a component playground.
|
|
414
849
|
`,
|
|
415
850
|
'doc.mdx': `import { Meta, Markdown } from '@storybook/addon-docs/blocks';
|
|
416
851
|
import ReadMe from './README.md?raw';
|
|
417
852
|
|
|
418
|
-
<Meta title="
|
|
853
|
+
<Meta title="MFE" />
|
|
419
854
|
|
|
420
855
|
<Markdown>{ReadMe}</Markdown>
|
|
421
856
|
`,
|