@happyvertical/smrt-playground 0.30.0
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/AGENTS.md +46 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +46 -0
- package/dist/chunks/discovery-C0r-nDQB.js +177 -0
- package/dist/chunks/discovery-C0r-nDQB.js.map +1 -0
- package/dist/chunks/runtime-BtfwY7PF.js +104 -0
- package/dist/chunks/runtime-BtfwY7PF.js.map +1 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.js.map +1 -0
- package/dist/svelte/PlaygroundHost.svelte +563 -0
- package/dist/svelte/PlaygroundHost.svelte.d.ts +11 -0
- package/dist/svelte/PlaygroundHost.svelte.d.ts.map +1 -0
- package/dist/svelte/index.d.ts +2 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +1 -0
- package/dist/svelte/runtime.d.ts +2 -0
- package/dist/svelte/runtime.d.ts.map +1 -0
- package/dist/svelte/runtime.js +1 -0
- package/dist/svelte/types.d.ts +2 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +1 -0
- package/dist/templates.d.ts +4 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/vite.d.ts +6 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +115 -0
- package/dist/vite.js.map +1 -0
- package/package.json +76 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# smrt-playground
|
|
2
|
+
|
|
3
|
+
Shared playground discovery, runtime helpers, and host components for SMRT UI packages.
|
|
4
|
+
|
|
5
|
+
## Core pieces
|
|
6
|
+
|
|
7
|
+
- `discovery.ts` — finds package-owned `./playground` modules across the workspace and installed `node_modules`
|
|
8
|
+
- `runtime.ts` — coerces and merges discovered modules into a unified registry consumed by the host
|
|
9
|
+
- `templates.ts` — generates Svelte route templates for app-level and package-level playground hosts
|
|
10
|
+
- `svelte/PlaygroundHost.svelte` — the host component that renders discovered playground entries
|
|
11
|
+
- `vite.ts` — vite plugin used by the SvelteKit playground host to wire everything together
|
|
12
|
+
|
|
13
|
+
## Surface contract
|
|
14
|
+
|
|
15
|
+
Each UI-shipping package opts in by exporting a `./playground` subpath that resolves to a module shaped like `SmrtPlaygroundModule`:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// packages/<name>/src/svelte/playground.ts
|
|
19
|
+
export const playground: SmrtPlaygroundModule = {
|
|
20
|
+
packageName: '@happyvertical/smrt-<name>',
|
|
21
|
+
entries: [
|
|
22
|
+
{
|
|
23
|
+
id: '<name>:component-id',
|
|
24
|
+
label: 'Human-readable label',
|
|
25
|
+
load: () => import('./components/MyComponent.svelte'),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## CLI integration
|
|
32
|
+
|
|
33
|
+
The `smrt playground` commands (`init`, `dev`, `list`) consume this package. The CLI commands live in `@happyvertical/smrt-cli`; the runtime they delegate to is here.
|
|
34
|
+
|
|
35
|
+
## Relationship to `smrt-svelte`
|
|
36
|
+
|
|
37
|
+
`smrt-playground` does not own component code or theming — it only discovers and renders. UI components themselves come from individual packages (`smrt-content/svelte`, `smrt-jobs/svelte`, etc.), from `smrt-ui` for shared domain-agnostic primitives, or from `smrt-svelte` for the top-level integration components.
|
|
38
|
+
|
|
39
|
+
## Internal `host/` directory
|
|
40
|
+
|
|
41
|
+
The `host/` directory is a private SvelteKit app used for Playwright e2e testing of `PlaygroundHost.svelte`. It is registered as `smrt-playground-host` in the workspace but is not published.
|
|
42
|
+
|
|
43
|
+
## Docs
|
|
44
|
+
|
|
45
|
+
- See [`docs/ui-surfaces.md`](../../docs/ui-surfaces.md) for the full UI surface contract
|
|
46
|
+
- See [`docs/standards.md`](../../docs/standards.md) for monorepo conventions
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @happyvertical/smrt-playground
|
|
2
|
+
|
|
3
|
+
Shared playground discovery, runtime helpers, and host components for SMRT UI packages.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
`@happyvertical/smrt-playground` powers the shared `smrt playground` experience. It discovers package-owned playground modules and renders them in a common host without forcing those packages to share a single route tree.
|
|
8
|
+
|
|
9
|
+
This package is about previews, not app routing.
|
|
10
|
+
|
|
11
|
+
## Surface Model
|
|
12
|
+
|
|
13
|
+
SMRT UI packages can expose three different surfaces:
|
|
14
|
+
|
|
15
|
+
- `./svelte` for reusable components
|
|
16
|
+
- `./playground` for preview metadata
|
|
17
|
+
- package-local page shells under `src/svelte/routes` and `src/routes` when needed
|
|
18
|
+
|
|
19
|
+
`@happyvertical/smrt-playground` consumes `./playground`, not package route trees.
|
|
20
|
+
|
|
21
|
+
For this release, most UI packages should stop at `./svelte` and `./playground`. Route/page shells can stay package-local until there is a concrete downstream need to standardize a public route contract.
|
|
22
|
+
|
|
23
|
+
For the full convention, see [docs/ui-surfaces.md](../../docs/ui-surfaces.md).
|
|
24
|
+
|
|
25
|
+
## Package-Owned Playground Modules
|
|
26
|
+
|
|
27
|
+
Packages opt in by defining `src/svelte/playground.ts`.
|
|
28
|
+
|
|
29
|
+
That module should:
|
|
30
|
+
|
|
31
|
+
- export stable preview entry IDs
|
|
32
|
+
- point at real package components
|
|
33
|
+
- provide mock fixtures or live configuration
|
|
34
|
+
- stay importable from workspace source for `smrt playground list`
|
|
35
|
+
|
|
36
|
+
The shared host discovers these modules and renders them. Package pages do not need to be mounted into the shared playground.
|
|
37
|
+
|
|
38
|
+
## Relationship To `smrt playground`
|
|
39
|
+
|
|
40
|
+
The `smrt playground` CLI commands are the public entry point.
|
|
41
|
+
|
|
42
|
+
- `smrt playground init`
|
|
43
|
+
- `smrt playground dev`
|
|
44
|
+
- `smrt playground list`
|
|
45
|
+
|
|
46
|
+
This package provides the runtime and host implementation behind those commands.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { relative, join, resolve, dirname, isAbsolute, extname } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import fg from "fast-glob";
|
|
6
|
+
import { c as coercePlaygroundModules } from "./runtime-BtfwY7PF.js";
|
|
7
|
+
const require$1 = createRequire(import.meta.url);
|
|
8
|
+
const TS_SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".mts", ".cts"]);
|
|
9
|
+
function findWorkspaceRoot(startDir = process.cwd()) {
|
|
10
|
+
let current = resolve(startDir);
|
|
11
|
+
while (true) {
|
|
12
|
+
if (existsSync(join(current, "pnpm-workspace.yaml"))) {
|
|
13
|
+
return current;
|
|
14
|
+
}
|
|
15
|
+
const parent = dirname(current);
|
|
16
|
+
if (parent === current) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
current = parent;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function findSmrtWorkspaceRoot(startDir = process.cwd()) {
|
|
23
|
+
const workspaceRoot = findWorkspaceRoot(startDir);
|
|
24
|
+
if (!workspaceRoot) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const hostPackageJsonPath = join(
|
|
28
|
+
workspaceRoot,
|
|
29
|
+
"packages",
|
|
30
|
+
"smrt-playground",
|
|
31
|
+
"host",
|
|
32
|
+
"package.json"
|
|
33
|
+
);
|
|
34
|
+
return existsSync(hostPackageJsonPath) ? workspaceRoot : null;
|
|
35
|
+
}
|
|
36
|
+
function detectPlaygroundMode(projectRoot = process.cwd()) {
|
|
37
|
+
return findSmrtWorkspaceRoot(projectRoot) ? "workspace" : "consumer";
|
|
38
|
+
}
|
|
39
|
+
function readJson(path) {
|
|
40
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
41
|
+
}
|
|
42
|
+
function resolveNodeModulePackageDir(projectRoot, packageName) {
|
|
43
|
+
const packageJsonPath = join(
|
|
44
|
+
projectRoot,
|
|
45
|
+
"node_modules",
|
|
46
|
+
packageName,
|
|
47
|
+
"package.json"
|
|
48
|
+
);
|
|
49
|
+
return existsSync(packageJsonPath) ? dirname(packageJsonPath) : null;
|
|
50
|
+
}
|
|
51
|
+
async function discoverWorkspacePlaygrounds(workspaceRoot, packagesPattern = "packages/*/src/svelte/playground.ts") {
|
|
52
|
+
const matches = await fg(packagesPattern, {
|
|
53
|
+
cwd: workspaceRoot,
|
|
54
|
+
absolute: true
|
|
55
|
+
});
|
|
56
|
+
const discovered = [];
|
|
57
|
+
for (const sourcePath of matches.sort()) {
|
|
58
|
+
const packageDir = dirname(dirname(dirname(sourcePath)));
|
|
59
|
+
const packageJsonPath = join(packageDir, "package.json");
|
|
60
|
+
if (!existsSync(packageJsonPath)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const packageJson = readJson(packageJsonPath);
|
|
64
|
+
const runtimePath = join(packageDir, "dist", "playground.js");
|
|
65
|
+
discovered.push({
|
|
66
|
+
packageName: packageJson.name,
|
|
67
|
+
packageDir,
|
|
68
|
+
sourcePath,
|
|
69
|
+
runtimePath: existsSync(runtimePath) ? runtimePath : null
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return discovered;
|
|
73
|
+
}
|
|
74
|
+
async function discoverInstalledPlaygrounds(projectRoot = process.cwd()) {
|
|
75
|
+
const packageJsonPath = join(projectRoot, "package.json");
|
|
76
|
+
if (!existsSync(packageJsonPath)) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const packageJson = readJson(packageJsonPath);
|
|
80
|
+
const dependencies = {
|
|
81
|
+
...packageJson.dependencies,
|
|
82
|
+
...packageJson.devDependencies,
|
|
83
|
+
...packageJson.peerDependencies
|
|
84
|
+
};
|
|
85
|
+
const discovered = [];
|
|
86
|
+
for (const dependencyName of Object.keys(dependencies).sort()) {
|
|
87
|
+
if (!dependencyName.startsWith("@happyvertical/smrt-") || dependencyName === "@happyvertical/smrt-playground") {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const packageDir = resolveNodeModulePackageDir(projectRoot, dependencyName);
|
|
91
|
+
if (!packageDir) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const dependencyPackageJson = readJson(join(packageDir, "package.json"));
|
|
95
|
+
if (dependencyPackageJson.exports?.["./playground"]) {
|
|
96
|
+
discovered.push({
|
|
97
|
+
packageName: dependencyName,
|
|
98
|
+
importSpecifier: `${dependencyName}/playground`
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return discovered;
|
|
103
|
+
}
|
|
104
|
+
async function discoverPlaygroundTargets(projectRoot = process.cwd(), mode = "auto", localPlaygroundPath = "src/playground.ts") {
|
|
105
|
+
const effectiveMode = mode === "auto" ? detectPlaygroundMode(projectRoot) : mode;
|
|
106
|
+
if (effectiveMode === "workspace") {
|
|
107
|
+
const workspaceRoot = mode === "workspace" ? findWorkspaceRoot(projectRoot) : findSmrtWorkspaceRoot(projectRoot);
|
|
108
|
+
if (!workspaceRoot) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const packages = await discoverWorkspacePlaygrounds(workspaceRoot);
|
|
112
|
+
return packages.map((item) => ({
|
|
113
|
+
packageName: item.packageName,
|
|
114
|
+
source: "workspace",
|
|
115
|
+
sourcePath: item.sourcePath,
|
|
116
|
+
runtimePath: item.runtimePath ?? void 0
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
const targets = [];
|
|
120
|
+
const installed = await discoverInstalledPlaygrounds(projectRoot);
|
|
121
|
+
for (const item of installed) {
|
|
122
|
+
targets.push({
|
|
123
|
+
packageName: item.packageName,
|
|
124
|
+
source: "package",
|
|
125
|
+
importSpecifier: item.importSpecifier
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const localPath = resolve(projectRoot, localPlaygroundPath);
|
|
129
|
+
if (existsSync(localPath)) {
|
|
130
|
+
targets.push({
|
|
131
|
+
source: "app",
|
|
132
|
+
sourcePath: localPath
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return targets;
|
|
136
|
+
}
|
|
137
|
+
async function importPlaygroundModule(input) {
|
|
138
|
+
const imported = isAbsolute(input) || input.startsWith(".") ? await importPathModule(resolve(input)) : await import(input);
|
|
139
|
+
const module = imported.default ?? imported.playground ?? imported;
|
|
140
|
+
return module && typeof module === "object" ? coercePlaygroundModules(module) : [];
|
|
141
|
+
}
|
|
142
|
+
async function importPathModule(inputPath) {
|
|
143
|
+
if (!TS_SOURCE_EXTENSIONS.has(extname(inputPath))) {
|
|
144
|
+
return import(pathToFileURL(inputPath).href);
|
|
145
|
+
}
|
|
146
|
+
let tsxApiPath;
|
|
147
|
+
try {
|
|
148
|
+
tsxApiPath = require$1.resolve("tsx/esm/api");
|
|
149
|
+
} catch (tsxError) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Failed to load playground module from ${inputPath}: source playground discovery requires the "tsx" package.`,
|
|
152
|
+
{ cause: tsxError }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const { tsImport } = await import(pathToFileURL(tsxApiPath).href);
|
|
156
|
+
return tsImport(pathToFileURL(inputPath).href, {
|
|
157
|
+
parentURL: import.meta.url
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function describePlaygroundSource(target, cwd = process.cwd()) {
|
|
161
|
+
if (target.source === "package") {
|
|
162
|
+
return target.importSpecifier || target.packageName || "installed package";
|
|
163
|
+
}
|
|
164
|
+
const path = target.sourcePath || target.runtimePath;
|
|
165
|
+
return path ? relative(cwd, path) || "." : target.source;
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
detectPlaygroundMode as a,
|
|
169
|
+
discoverInstalledPlaygrounds as b,
|
|
170
|
+
discoverPlaygroundTargets as c,
|
|
171
|
+
describePlaygroundSource as d,
|
|
172
|
+
discoverWorkspacePlaygrounds as e,
|
|
173
|
+
findSmrtWorkspaceRoot as f,
|
|
174
|
+
findWorkspaceRoot as g,
|
|
175
|
+
importPlaygroundModule as i
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=discovery-C0r-nDQB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery-C0r-nDQB.js","sources":["../../src/discovery.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport {\n dirname,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n} from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport fg from 'fast-glob';\nimport { coercePlaygroundModules } from './runtime.js';\nimport type {\n DiscoveredInstalledPlayground,\n DiscoveredPlaygroundTarget,\n DiscoveredWorkspacePlayground,\n SmrtPlaygroundModule,\n} from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst TS_SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);\n\nexport function findWorkspaceRoot(startDir = process.cwd()): string | null {\n let current = resolve(startDir);\n\n while (true) {\n if (existsSync(join(current, 'pnpm-workspace.yaml'))) {\n return current;\n }\n\n const parent = dirname(current);\n if (parent === current) {\n return null;\n }\n current = parent;\n }\n}\n\nexport function findSmrtWorkspaceRoot(startDir = process.cwd()): string | null {\n const workspaceRoot = findWorkspaceRoot(startDir);\n if (!workspaceRoot) {\n return null;\n }\n\n const hostPackageJsonPath = join(\n workspaceRoot,\n 'packages',\n 'smrt-playground',\n 'host',\n 'package.json',\n );\n\n return existsSync(hostPackageJsonPath) ? workspaceRoot : null;\n}\n\nexport function detectPlaygroundMode(\n projectRoot = process.cwd(),\n): 'workspace' | 'consumer' {\n return findSmrtWorkspaceRoot(projectRoot) ? 'workspace' : 'consumer';\n}\n\nfunction readJson(path: string): any {\n return JSON.parse(readFileSync(path, 'utf-8'));\n}\n\nfunction resolveNodeModulePackageDir(\n projectRoot: string,\n packageName: string,\n): string | null {\n const packageJsonPath = join(\n projectRoot,\n 'node_modules',\n packageName,\n 'package.json',\n );\n return existsSync(packageJsonPath) ? dirname(packageJsonPath) : null;\n}\n\nexport async function discoverWorkspacePlaygrounds(\n workspaceRoot: string,\n packagesPattern = 'packages/*/src/svelte/playground.ts',\n): Promise<DiscoveredWorkspacePlayground[]> {\n const matches = await fg(packagesPattern, {\n cwd: workspaceRoot,\n absolute: true,\n });\n\n const discovered: DiscoveredWorkspacePlayground[] = [];\n\n for (const sourcePath of matches.sort()) {\n const packageDir = dirname(dirname(dirname(sourcePath)));\n const packageJsonPath = join(packageDir, 'package.json');\n\n if (!existsSync(packageJsonPath)) {\n continue;\n }\n\n const packageJson = readJson(packageJsonPath);\n const runtimePath = join(packageDir, 'dist', 'playground.js');\n\n discovered.push({\n packageName: packageJson.name,\n packageDir,\n sourcePath,\n runtimePath: existsSync(runtimePath) ? runtimePath : null,\n });\n }\n\n return discovered;\n}\n\nexport async function discoverInstalledPlaygrounds(\n projectRoot = process.cwd(),\n): Promise<DiscoveredInstalledPlayground[]> {\n const packageJsonPath = join(projectRoot, 'package.json');\n if (!existsSync(packageJsonPath)) {\n return [];\n }\n\n const packageJson = readJson(packageJsonPath);\n const dependencies = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n ...packageJson.peerDependencies,\n };\n\n const discovered: DiscoveredInstalledPlayground[] = [];\n\n for (const dependencyName of Object.keys(dependencies).sort()) {\n if (\n !dependencyName.startsWith('@happyvertical/smrt-') ||\n dependencyName === '@happyvertical/smrt-playground'\n ) {\n continue;\n }\n\n const packageDir = resolveNodeModulePackageDir(projectRoot, dependencyName);\n if (!packageDir) {\n continue;\n }\n\n const dependencyPackageJson = readJson(join(packageDir, 'package.json'));\n if (dependencyPackageJson.exports?.['./playground']) {\n discovered.push({\n packageName: dependencyName,\n importSpecifier: `${dependencyName}/playground`,\n });\n }\n }\n\n return discovered;\n}\n\nexport async function discoverPlaygroundTargets(\n projectRoot = process.cwd(),\n mode: 'auto' | 'workspace' | 'consumer' = 'auto',\n localPlaygroundPath = 'src/playground.ts',\n): Promise<DiscoveredPlaygroundTarget[]> {\n const effectiveMode =\n mode === 'auto' ? detectPlaygroundMode(projectRoot) : mode;\n\n if (effectiveMode === 'workspace') {\n const workspaceRoot =\n mode === 'workspace'\n ? findWorkspaceRoot(projectRoot)\n : findSmrtWorkspaceRoot(projectRoot);\n if (!workspaceRoot) {\n return [];\n }\n\n const packages = await discoverWorkspacePlaygrounds(workspaceRoot);\n return packages.map((item) => ({\n packageName: item.packageName,\n source: 'workspace' as const,\n sourcePath: item.sourcePath,\n runtimePath: item.runtimePath ?? undefined,\n }));\n }\n\n const targets: DiscoveredPlaygroundTarget[] = [];\n const installed = await discoverInstalledPlaygrounds(projectRoot);\n\n for (const item of installed) {\n targets.push({\n packageName: item.packageName,\n source: 'package',\n importSpecifier: item.importSpecifier,\n });\n }\n\n const localPath = resolve(projectRoot, localPlaygroundPath);\n if (existsSync(localPath)) {\n targets.push({\n source: 'app',\n sourcePath: localPath,\n });\n }\n\n return targets;\n}\n\nexport async function importPlaygroundModule(\n input: string,\n): Promise<SmrtPlaygroundModule[]> {\n const imported =\n isAbsolute(input) || input.startsWith('.')\n ? await importPathModule(resolve(input))\n : await import(input);\n\n const module = imported.default ?? imported.playground ?? imported;\n return module && typeof module === 'object'\n ? coercePlaygroundModules(module as SmrtPlaygroundModule)\n : [];\n}\n\nasync function importPathModule(inputPath: string): Promise<unknown> {\n if (!TS_SOURCE_EXTENSIONS.has(extname(inputPath))) {\n return import(pathToFileURL(inputPath).href);\n }\n\n let tsxApiPath: string;\n try {\n tsxApiPath = require.resolve('tsx/esm/api');\n } catch (tsxError) {\n throw new Error(\n `Failed to load playground module from ${inputPath}: source playground discovery requires the \"tsx\" package.`,\n { cause: tsxError },\n );\n }\n\n const { tsImport } = await import(pathToFileURL(tsxApiPath).href);\n return tsImport(pathToFileURL(inputPath).href, {\n parentURL: import.meta.url,\n });\n}\n\nexport function describePlaygroundSource(\n target: DiscoveredPlaygroundTarget,\n cwd = process.cwd(),\n): string {\n if (target.source === 'package') {\n return target.importSpecifier || target.packageName || 'installed package';\n }\n\n const path = target.sourcePath || target.runtimePath;\n return path ? relative(cwd, path) || '.' : target.source;\n}\n"],"names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A,QAAM,EAAE,SAAA,IAAa,MAAM,OAAO,cAAc,UAAU,EAAE;AAC5D,SAAO,SAAS,cAAc,SAAS,EAAE,MAAM;AAAA,IAC7C,WAAW,YAAY;AAAA,EAAA,CACxB;AACH;AAEO,SAAS,yBACd,QACA,MAAM,QAAQ,OACN;AACR,MAAI,OAAO,WAAW,WAAW;AAC/B,WAAO,OAAO,mBAAmB,OAAO,eAAe;AAAA,EACzD;AAEA,QAAM,OAAO,OAAO,cAAc,OAAO;AACzC,SAAO,OAAO,SAAS,KAAK,IAAI,KAAK,MAAM,OAAO;AACpD;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function titleCase(value) {
|
|
2
|
+
return value.split(/[-_/]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join(" ");
|
|
3
|
+
}
|
|
4
|
+
function displayNameForSmrtPackage(packageName) {
|
|
5
|
+
return titleCase(packageName.replace(/^@happyvertical\/smrt-/, ""));
|
|
6
|
+
}
|
|
7
|
+
function displayNameForScopedPackage(packageName) {
|
|
8
|
+
return titleCase(packageName.replace(/^@/, "").replace(/\//g, " "));
|
|
9
|
+
}
|
|
10
|
+
function normalizeModeConfig(value) {
|
|
11
|
+
if (!value) {
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
return value === true ? {} : value;
|
|
15
|
+
}
|
|
16
|
+
function qualifyPlaygroundEntryId(packageName, entryId) {
|
|
17
|
+
return `${packageName}:${entryId}`;
|
|
18
|
+
}
|
|
19
|
+
function coercePlaygroundModules(input) {
|
|
20
|
+
if (!input) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(input)) {
|
|
24
|
+
return input.filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
if ("modules" in input && Array.isArray(input.modules)) {
|
|
27
|
+
return input.modules.filter(Boolean);
|
|
28
|
+
}
|
|
29
|
+
return [input];
|
|
30
|
+
}
|
|
31
|
+
function normalizePlaygroundModule(module) {
|
|
32
|
+
const displayName = module.displayName || module.moduleMeta?.displayName || displayNameForSmrtPackage(module.packageName);
|
|
33
|
+
const entries = [...module.entries || []].map((entry) => {
|
|
34
|
+
const modes = {
|
|
35
|
+
mock: normalizeModeConfig(entry.modes?.mock),
|
|
36
|
+
live: normalizeModeConfig(entry.modes?.live)
|
|
37
|
+
};
|
|
38
|
+
const availableModes = ["mock", "live"].filter(
|
|
39
|
+
(mode) => Boolean(modes[mode])
|
|
40
|
+
);
|
|
41
|
+
if (availableModes.length === 0) {
|
|
42
|
+
modes.mock = {};
|
|
43
|
+
availableModes.push("mock");
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...entry,
|
|
47
|
+
displayName,
|
|
48
|
+
packageName: module.packageName,
|
|
49
|
+
qualifiedId: qualifyPlaygroundEntryId(module.packageName, entry.id),
|
|
50
|
+
availableModes,
|
|
51
|
+
modes
|
|
52
|
+
};
|
|
53
|
+
}).sort((left, right) => {
|
|
54
|
+
const orderDiff = (left.order ?? 999) - (right.order ?? 999);
|
|
55
|
+
return orderDiff !== 0 ? orderDiff : left.title.localeCompare(right.title);
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
...module,
|
|
59
|
+
displayName,
|
|
60
|
+
entries
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function mergePlaygroundModules(modules) {
|
|
64
|
+
const mergedByPackage = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const inputModule of modules) {
|
|
66
|
+
const module = normalizePlaygroundModule(inputModule);
|
|
67
|
+
const existing = mergedByPackage.get(module.packageName);
|
|
68
|
+
if (!existing) {
|
|
69
|
+
mergedByPackage.set(module.packageName, {
|
|
70
|
+
module: { ...module, entries: [] },
|
|
71
|
+
entries: new Map(
|
|
72
|
+
module.entries.map((entry) => [entry.qualifiedId, entry])
|
|
73
|
+
)
|
|
74
|
+
});
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
existing.module = {
|
|
78
|
+
...existing.module,
|
|
79
|
+
...module,
|
|
80
|
+
entries: [],
|
|
81
|
+
displayName: module.displayName || existing.module.displayName,
|
|
82
|
+
moduleMeta: module.moduleMeta || existing.module.moduleMeta
|
|
83
|
+
};
|
|
84
|
+
for (const entry of module.entries) {
|
|
85
|
+
existing.entries.set(entry.qualifiedId, entry);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return [...mergedByPackage.values()].map(({ module, entries }) => ({
|
|
89
|
+
...module,
|
|
90
|
+
entries: [...entries.values()].sort((left, right) => {
|
|
91
|
+
const orderDiff = (left.order ?? 999) - (right.order ?? 999);
|
|
92
|
+
return orderDiff !== 0 ? orderDiff : left.title.localeCompare(right.title);
|
|
93
|
+
})
|
|
94
|
+
})).sort((left, right) => left.displayName.localeCompare(right.displayName));
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
displayNameForSmrtPackage as a,
|
|
98
|
+
coercePlaygroundModules as c,
|
|
99
|
+
displayNameForScopedPackage as d,
|
|
100
|
+
mergePlaygroundModules as m,
|
|
101
|
+
normalizePlaygroundModule as n,
|
|
102
|
+
qualifyPlaygroundEntryId as q
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=runtime-BtfwY7PF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-BtfwY7PF.js","sources":["../../src/utils.ts","../../src/runtime.ts"],"sourcesContent":["export function titleCase(value: string): string {\n return value\n .split(/[-_/]/)\n .filter(Boolean)\n .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))\n .join(' ');\n}\n\nexport function displayNameForSmrtPackage(packageName: string): string {\n return titleCase(packageName.replace(/^@happyvertical\\/smrt-/, ''));\n}\n\nexport function displayNameForScopedPackage(packageName: string): string {\n return titleCase(packageName.replace(/^@/, '').replace(/\\//g, ' '));\n}\n","import type {\n ResolvedSmrtPlaygroundEntry,\n ResolvedSmrtPlaygroundModule,\n SmrtPlaygroundMode,\n SmrtPlaygroundModeConfig,\n SmrtPlaygroundModule,\n SmrtPlaygroundModuleExport,\n} from './types.js';\nimport { displayNameForSmrtPackage } from './utils.js';\n\nfunction normalizeModeConfig(\n value: SmrtPlaygroundModeConfig | true | undefined,\n): SmrtPlaygroundModeConfig | undefined {\n if (!value) {\n return undefined;\n }\n return value === true ? {} : value;\n}\n\nexport function qualifyPlaygroundEntryId(\n packageName: string,\n entryId: string,\n): string {\n return `${packageName}:${entryId}`;\n}\n\nexport function coercePlaygroundModules(\n input: SmrtPlaygroundModuleExport | null | undefined,\n): SmrtPlaygroundModule[] {\n if (!input) {\n return [];\n }\n\n if (Array.isArray(input)) {\n return input.filter(Boolean);\n }\n\n if ('modules' in input && Array.isArray(input.modules)) {\n return input.modules.filter(Boolean);\n }\n\n return [input as SmrtPlaygroundModule];\n}\n\nexport function normalizePlaygroundModule(\n module: SmrtPlaygroundModule,\n): ResolvedSmrtPlaygroundModule {\n const displayName =\n module.displayName ||\n module.moduleMeta?.displayName ||\n displayNameForSmrtPackage(module.packageName);\n\n const entries: ResolvedSmrtPlaygroundEntry[] = [...(module.entries || [])]\n .map((entry) => {\n const modes = {\n mock: normalizeModeConfig(entry.modes?.mock),\n live: normalizeModeConfig(entry.modes?.live),\n };\n const availableModes = (['mock', 'live'] as SmrtPlaygroundMode[]).filter(\n (mode) => Boolean(modes[mode]),\n );\n\n if (availableModes.length === 0) {\n modes.mock = {};\n availableModes.push('mock');\n }\n\n return {\n ...entry,\n displayName,\n packageName: module.packageName,\n qualifiedId: qualifyPlaygroundEntryId(module.packageName, entry.id),\n availableModes,\n modes,\n };\n })\n .sort((left, right) => {\n const orderDiff = (left.order ?? 999) - (right.order ?? 999);\n return orderDiff !== 0\n ? orderDiff\n : left.title.localeCompare(right.title);\n });\n\n return {\n ...module,\n displayName,\n entries,\n };\n}\n\nexport function mergePlaygroundModules(\n modules: SmrtPlaygroundModule[],\n): ResolvedSmrtPlaygroundModule[] {\n // Later modules intentionally override earlier ones so app-local entries can\n // replace installed package previews by packageName + entry id.\n const mergedByPackage = new Map<\n string,\n {\n module: ResolvedSmrtPlaygroundModule;\n entries: Map<string, ResolvedSmrtPlaygroundEntry>;\n }\n >();\n\n for (const inputModule of modules) {\n const module = normalizePlaygroundModule(inputModule);\n const existing = mergedByPackage.get(module.packageName);\n\n if (!existing) {\n mergedByPackage.set(module.packageName, {\n module: { ...module, entries: [] },\n entries: new Map(\n module.entries.map((entry) => [entry.qualifiedId, entry]),\n ),\n });\n continue;\n }\n\n existing.module = {\n ...existing.module,\n ...module,\n entries: [],\n displayName: module.displayName || existing.module.displayName,\n moduleMeta: module.moduleMeta || existing.module.moduleMeta,\n };\n\n for (const entry of module.entries) {\n existing.entries.set(entry.qualifiedId, entry);\n }\n }\n\n return [...mergedByPackage.values()]\n .map(({ module, entries }) => ({\n ...module,\n entries: [...entries.values()].sort((left, right) => {\n const orderDiff = (left.order ?? 999) - (right.order ?? 999);\n return orderDiff !== 0\n ? orderDiff\n : left.title.localeCompare(right.title);\n }),\n }))\n .sort((left, right) => left.displayName.localeCompare(right.displayName));\n}\n"],"names":[],"mappings":"AAAO,SAAS,UAAU,OAAuB;AAC/C,SAAO,MACJ,MAAM,OAAO,EACb,OAAO,OAAO,EACd,IAAI,CAAC,YAAY,QAAQ,OAAO,CAAC,EAAE,gBAAgB,QAAQ,MAAM,CAAC,CAAC,EACnE,KAAK,GAAG;AACb;AAEO,SAAS,0BAA0B,aAA6B;AACrE,SAAO,UAAU,YAAY,QAAQ,0BAA0B,EAAE,CAAC;AACpE;AAEO,SAAS,4BAA4B,aAA6B;AACvE,SAAO,UAAU,YAAY,QAAQ,MAAM,EAAE,EAAE,QAAQ,OAAO,GAAG,CAAC;AACpE;ACJA,SAAS,oBACP,OACsC;AACtC,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,SAAO,UAAU,OAAO,CAAA,IAAK;AAC/B;AAEO,SAAS,yBACd,aACA,SACQ;AACR,SAAO,GAAG,WAAW,IAAI,OAAO;AAClC;AAEO,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Q5B,aAAW,eAAe,SAAS;AACjC,UAAM,SAAS,0BAA0B,WAAW;AACpD,UAAM,WAAW,gBAAgB,IAAI,OAAO,WAAW;AAEvD,QAAI,CAAC,UAAU;AACb,sBAAgB,IAAI,OAAO,aAAa;AAAA,QACtC,QAAQ,EAAE,GAAG,QAAQ,SAAS,CAAA,EAAC;AAAA,QAC/B,SAAS,IAAI;AAAA,UACX,OAAO,QAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,aAAa,KAAK,CAAC;AAAA,QAAA;AAAA,MAC1D,CACD;AACD;AAAA,IACF;AAEA,aAAS,SAAS;AAAA,MAChB,GAAG,SAAS;AAAA,MACZ,GAAG;AAAA,MACH,SAAS,CAAA;AAAA,MACT,aAAa,OAAO,eAAe,SAAS,OAAO;AAAA,MACnD,YAAY,OAAO,cAAc,SAAS,OAAO;AAAA,IAAA;AAGnD,eAAW,SAAS,OAAO,SAAS;AAClC,eAAS,QAAQ,IAAI,MAAM,aAAa,KAAK;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO,CAAC,GAAG,gBAAgB,OAAA,CAAQ,EAChC,IAAI,CAAC,EAAE,QAAQ,eAAe;AAAA,IAC7B,GAAG;AAAA,IACH,SAAS,CAAC,GAAG,QAAQ,OAAA,CAAQ,EAAE,KAAK,CAAC,MAAM,UAAU;AACnD,YAAM,aAAa,KAAK,SAAS,QAAQ,MAAM,SAAS;AACxD,aAAO,cAAc,IACjB,YACA,KAAK,MAAM,cAAc,MAAM,KAAK;AAAA,IAC1C,CAAC;AAAA,EAAA,EACD,EACD,KAAK,CAAC,MAAM,UAAU,KAAK,YAAY,cAAc,MAAM,WAAW,CAAC;AAC5E;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DiscoveredInstalledPlayground, DiscoveredPlaygroundTarget, DiscoveredWorkspacePlayground, SmrtPlaygroundModule } from './types.js';
|
|
2
|
+
export declare function findWorkspaceRoot(startDir?: string): string | null;
|
|
3
|
+
export declare function findSmrtWorkspaceRoot(startDir?: string): string | null;
|
|
4
|
+
export declare function detectPlaygroundMode(projectRoot?: string): 'workspace' | 'consumer';
|
|
5
|
+
export declare function discoverWorkspacePlaygrounds(workspaceRoot: string, packagesPattern?: string): Promise<DiscoveredWorkspacePlayground[]>;
|
|
6
|
+
export declare function discoverInstalledPlaygrounds(projectRoot?: string): Promise<DiscoveredInstalledPlayground[]>;
|
|
7
|
+
export declare function discoverPlaygroundTargets(projectRoot?: string, mode?: 'auto' | 'workspace' | 'consumer', localPlaygroundPath?: string): Promise<DiscoveredPlaygroundTarget[]>;
|
|
8
|
+
export declare function importPlaygroundModule(input: string): Promise<SmrtPlaygroundModule[]>;
|
|
9
|
+
export declare function describePlaygroundSource(target: DiscoveredPlaygroundTarget, cwd?: string): string;
|
|
10
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,EAC7B,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,iBAAiB,CAAC,QAAQ,SAAgB,GAAG,MAAM,GAAG,IAAI,CAczE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,SAAgB,GAAG,MAAM,GAAG,IAAI,CAe7E;AAED,wBAAgB,oBAAoB,CAClC,WAAW,SAAgB,GAC1B,WAAW,GAAG,UAAU,CAE1B;AAmBD,wBAAsB,4BAA4B,CAChD,aAAa,EAAE,MAAM,EACrB,eAAe,SAAwC,GACtD,OAAO,CAAC,6BAA6B,EAAE,CAAC,CA4B1C;AAED,wBAAsB,4BAA4B,CAChD,WAAW,SAAgB,GAC1B,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAsC1C;AAED,wBAAsB,yBAAyB,CAC7C,WAAW,SAAgB,EAC3B,IAAI,GAAE,MAAM,GAAG,WAAW,GAAG,UAAmB,EAChD,mBAAmB,SAAsB,GACxC,OAAO,CAAC,0BAA0B,EAAE,CAAC,CA0CvC;AAED,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAUjC;AAuBD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,0BAA0B,EAClC,GAAG,SAAgB,GAClB,MAAM,CAOR"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { describePlaygroundSource, detectPlaygroundMode, discoverInstalledPlaygrounds, discoverPlaygroundTargets, discoverWorkspacePlaygrounds, findSmrtWorkspaceRoot, findWorkspaceRoot, importPlaygroundModule, } from './discovery.js';
|
|
2
|
+
export { coercePlaygroundModules, mergePlaygroundModules, normalizePlaygroundModule, qualifyPlaygroundEntryId, } from './runtime.js';
|
|
3
|
+
export { createAppPlaygroundRouteTemplate, createAppPlaygroundTemplate, createPackagePlaygroundTemplate, } from './templates.js';
|
|
4
|
+
export type { DiscoveredInstalledPlayground, DiscoveredPlaygroundTarget, DiscoveredWorkspacePlayground, PlaygroundComponentLoader, PlaygroundComponentModule, PlaygroundComponentType, ResolvedSmrtPlaygroundEntry, ResolvedSmrtPlaygroundModule, SmrtPlaygroundEntry, SmrtPlaygroundMode, SmrtPlaygroundModeConfig, SmrtPlaygroundModule, SmrtPlaygroundModuleExport, SmrtPlaygroundVitePluginOptions, } from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,4BAA4B,EAC5B,yBAAyB,EACzB,4BAA4B,EAC5B,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gCAAgC,EAChC,2BAA2B,EAC3B,+BAA+B,GAChC,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,EAC7B,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { d, a, b, c, e, f, g, i } from "./chunks/discovery-C0r-nDQB.js";
|
|
2
|
+
import { d as displayNameForScopedPackage, a as displayNameForSmrtPackage } from "./chunks/runtime-BtfwY7PF.js";
|
|
3
|
+
import { c as c2, m, n, q } from "./chunks/runtime-BtfwY7PF.js";
|
|
4
|
+
function createPackagePlaygroundTemplate(packageName) {
|
|
5
|
+
const displayName = displayNameForSmrtPackage(packageName);
|
|
6
|
+
return `/**
|
|
7
|
+
* ${displayName} playground definitions
|
|
8
|
+
*
|
|
9
|
+
* Export preview entries for the shared SMRT playground host here.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
packageName: '${packageName}',
|
|
14
|
+
displayName: '${displayName}',
|
|
15
|
+
entries: [],
|
|
16
|
+
};
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
19
|
+
function createAppPlaygroundTemplate(packageName) {
|
|
20
|
+
const displayName = displayNameForScopedPackage(packageName);
|
|
21
|
+
return `/**
|
|
22
|
+
* Local app playground overrides
|
|
23
|
+
*
|
|
24
|
+
* Add app-specific previews here, or override installed package entries by
|
|
25
|
+
* exporting an additional module with the same packageName + entry id.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export default [
|
|
29
|
+
{
|
|
30
|
+
packageName: '${packageName}',
|
|
31
|
+
displayName: '${displayName}',
|
|
32
|
+
entries: [],
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
function createAppPlaygroundRouteTemplate() {
|
|
38
|
+
return `<script lang="ts">
|
|
39
|
+
import { PlaygroundHost } from '@happyvertical/smrt-playground/svelte';
|
|
40
|
+
import { playgroundModules } from 'virtual:smrt-playground/modules';
|
|
41
|
+
<\/script>
|
|
42
|
+
|
|
43
|
+
<PlaygroundHost
|
|
44
|
+
title="SMRT Playground"
|
|
45
|
+
subtitle="Package previews and local app overrides"
|
|
46
|
+
modules={playgroundModules}
|
|
47
|
+
/>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
c2 as coercePlaygroundModules,
|
|
52
|
+
createAppPlaygroundRouteTemplate,
|
|
53
|
+
createAppPlaygroundTemplate,
|
|
54
|
+
createPackagePlaygroundTemplate,
|
|
55
|
+
d as describePlaygroundSource,
|
|
56
|
+
a as detectPlaygroundMode,
|
|
57
|
+
b as discoverInstalledPlaygrounds,
|
|
58
|
+
c as discoverPlaygroundTargets,
|
|
59
|
+
e as discoverWorkspacePlaygrounds,
|
|
60
|
+
f as findSmrtWorkspaceRoot,
|
|
61
|
+
g as findWorkspaceRoot,
|
|
62
|
+
i as importPlaygroundModule,
|
|
63
|
+
m as mergePlaygroundModules,
|
|
64
|
+
n as normalizePlaygroundModule,
|
|
65
|
+
q as qualifyPlaygroundEntryId
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/templates.ts"],"sourcesContent":["import {\n displayNameForScopedPackage,\n displayNameForSmrtPackage,\n} from './utils.js';\n\nexport function createPackagePlaygroundTemplate(packageName: string): string {\n const displayName = displayNameForSmrtPackage(packageName);\n\n return `/**\n * ${displayName} playground definitions\n *\n * Export preview entries for the shared SMRT playground host here.\n */\n\nexport default {\n packageName: '${packageName}',\n displayName: '${displayName}',\n entries: [],\n};\n`;\n}\n\nexport function createAppPlaygroundTemplate(packageName: string): string {\n const displayName = displayNameForScopedPackage(packageName);\n\n return `/**\n * Local app playground overrides\n *\n * Add app-specific previews here, or override installed package entries by\n * exporting an additional module with the same packageName + entry id.\n */\n\nexport default [\n {\n packageName: '${packageName}',\n displayName: '${displayName}',\n entries: [],\n },\n];\n`;\n}\n\nexport function createAppPlaygroundRouteTemplate(): string {\n return `<script lang=\"ts\">\nimport { PlaygroundHost } from '@happyvertical/smrt-playground/svelte';\nimport { playgroundModules } from 'virtual:smrt-playground/modules';\n</script>\n\n<PlaygroundHost\n title=\"SMRT Playground\"\n subtitle=\"Package previews and local app overrides\"\n modules={playgroundModules}\n/>\n`;\n}\n"],"names":[],"mappings":";;;AAKO,SAAS,gCAAgC,aAA6B;AAC3E,QAAM,cAAc,0BAA0B,WAAW;AAEzD,SAAO;AAAA,KACJ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAME,WAAW;AAAA,kBACX,WAAW;AAAA;AAAA;AAAA;AAI7B;AAEO,SAAS,4BAA4B,aAA6B;AACvE,QAAM,cAAc,4BAA4B,WAAW;AAE3D,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBASW,WAAW;AAAA,oBACX,WAAW;AAAA;AAAA;AAAA;AAAA;AAK/B;AAEO,SAAS,mCAA2C;AACzD,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWT;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ResolvedSmrtPlaygroundModule, SmrtPlaygroundModule, SmrtPlaygroundModuleExport } from './types.js';
|
|
2
|
+
export declare function qualifyPlaygroundEntryId(packageName: string, entryId: string): string;
|
|
3
|
+
export declare function coercePlaygroundModules(input: SmrtPlaygroundModuleExport | null | undefined): SmrtPlaygroundModule[];
|
|
4
|
+
export declare function normalizePlaygroundModule(module: SmrtPlaygroundModule): ResolvedSmrtPlaygroundModule;
|
|
5
|
+
export declare function mergePlaygroundModules(modules: SmrtPlaygroundModule[]): ResolvedSmrtPlaygroundModule[];
|
|
6
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,4BAA4B,EAG5B,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAYpB,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,CAER;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,0BAA0B,GAAG,IAAI,GAAG,SAAS,GACnD,oBAAoB,EAAE,CAcxB;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,oBAAoB,GAC3B,4BAA4B,CA0C9B;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,oBAAoB,EAAE,GAC9B,4BAA4B,EAAE,CAiDhC"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|