Skip to content

Commit

Permalink
feat: export JSON schemas as a pre-compiled module
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekyEggo committed Jun 3, 2024
1 parent 5cff8f7 commit 1511528
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@ npm install @elgato/schemas
Manifest JSON file responsible for defining a Stream Deck plugin.

```ts
// TypeScript type.
import { type Manifest } from "@elgato/schemas/streamdeck/plugins";
import manifestSchema from "@elgato/schemas/streamdeck/plugins/manifest.json";
```

```js
// Schema as an object.
import manifest from "@elgato/schemas/streamdeck/plugins/json";
```

```js
// Schema as an object, with experimental import attributes
import manifest from "@elgato/schemas/streamdeck/plugins/manifest.json" with { type: "json" };
```

```
Expand All @@ -39,8 +49,18 @@ https://schemas.elgato.com/streamdeck/plugins/manifest.json
Layout JSON file that defines the layout of an action on Stream Deck +.

```ts
// TypeScript type.
import { type Layout } from "@elgato/schemas/streamdeck/plugins";
import layoutSchema from "@elgato/schemas/streamdeck/plugins/layout.json";
```

```js
// Schema as an object.
import layout from "@elgato/schemas/streamdeck/plugins/json";
```

```js
// Schema as an object, with experimental import attributes
import layout from "@elgato/schemas/streamdeck/plugins/layout.json" with { type: "json" };
```

```
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"import": "./dist/streamdeck/plugins/index.mjs",
"types": "./dist/streamdeck/plugins/index.d.ts"
},
"./streamdeck/plugins/json": {
"default": "./dist/streamdeck/plugins/json.js",
"import": "./dist/streamdeck/plugins/json.mjs",
"types": "./dist/streamdeck/plugins/json.d.ts"
},
"./streamdeck/plugins/layout.json": {
"default": "./streamdeck/plugins/layout.json"
},
Expand Down
8 changes: 5 additions & 3 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import { dirname, join, parse } from "node:path";
Expand Down Expand Up @@ -40,7 +41,8 @@ function getConfig(input: string): RollupOptions[] {
typescript({
exclude: ["scripts/**/*.ts"]
}),
nodeResolve()
nodeResolve(),
json()
]
},
{
Expand All @@ -51,9 +53,9 @@ function getConfig(input: string): RollupOptions[] {
banner
}
],
plugins: [dts()]
plugins: [json(), dts()]
}
];
}

export default [...getConfig("index.ts"), ...getConfig("streamdeck/plugins/index.ts")] satisfies RollupOptions[];
export default [...getConfig("index.ts"), ...getConfig("streamdeck/plugins/index.ts"), ...getConfig("streamdeck/plugins/json.ts")] satisfies RollupOptions[];
2 changes: 2 additions & 0 deletions src/streamdeck/plugins/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as layout } from "../../../streamdeck/plugins/layout.json";
export { default as manifest } from "../../../streamdeck/plugins/manifest.json";

0 comments on commit 1511528

Please sign in to comment.