Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark playground and bundler for release and change versions to -alpha #2455

Merged
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/bundler",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/bundler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/internal-build-utils",
"comment": "Handle bumping version of prerelease packages",
"type": "none"
}
],
"packageName": "@typespec/internal-build-utils"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/playground",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/playground"
}
4,106 changes: 2,372 additions & 1,734 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion common/config/rush/version-policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
{
"definitionName": "lockStepVersion",
"policyName": "typespec",
"version": "0.48.0",
"version": "0.49.0",
"nextBump": "minor"
},
{
"definitionName": "lockStepVersion",
"policyName": "playground",
"version": "0.1.0-alpha.1",
"nextBump": "prerelease"
}
// {
// /**
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typespec/bundler",
"version": "0.1.0",
"version": "0.1.0-alpha.0",
"author": "Microsoft Corporation",
"description": "Package to bundle a typespec library.",
"homepage": "https://microsoft.github.io/typespec",
Expand Down
4 changes: 3 additions & 1 deletion packages/internal-build-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
"dependencies": {
"yargs": "~17.7.2",
"strip-json-comments": "~5.0.0",
"cspell": "~6.31.1"
"cspell": "~6.31.1",
"semver": "^7.5.4"
},
"devDependencies": {
"@types/mocha": "~10.0.1",
"@types/node": "~18.11.9",
"@types/yargs": "~17.0.24",
"@typespec/eslint-config-typespec": "workspace:~0.48.0",
"@types/semver": "^7.5.2",
"eslint": "^8.49.0",
"mocha": "~10.2.0",
"mocha-junit-reporter": "~2.2.1",
Expand Down
16 changes: 14 additions & 2 deletions packages/internal-build-utils/src/prerelease.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import { lstat, readdir, readFile, stat, writeFile } from "fs/promises";
import { join } from "path";
import { parse } from "semver";
import stripJsonComments from "strip-json-comments";

interface RushChangeFile {
Expand Down Expand Up @@ -133,8 +134,19 @@ function getDevVersion(version: string, changeCount: number) {
}

function getNextVersion(version: string) {
const [major, minor] = version.split(".").map((x) => parseInt(x, 10));
return `${major}.${minor + 1}.0`;
const parsed = parse(version);
if (parsed === null) {
throw new Error(`Invalid semver version ${version}`);
}
if (parsed.prerelease.length > 0) {
const [preName, preVersion] = parsed.prerelease;
if (typeof preVersion !== "number") {
throw new Error(`Invalid expected prerelease version ${preVersion} to be a number.`);
}
return `${parsed.major}.${parsed.minor}.${parsed.patch}-${preName}.${preVersion + 1}`;
} else {
return `${parsed.major}.${parsed.minor + 1}.0`;
}
}

async function addPrereleaseNumber(
Expand Down
3 changes: 1 addition & 2 deletions packages/playground-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"!dist/test/**"
],
"dependencies": {
"@typespec/playground": "workspace:~0.44.0",
"@typespec/playground": "workspace:~0.1.0-alpha.0",
"@typespec/versioning": "workspace:~0.48.0",
"@typespec/compiler": "workspace:~0.48.1",
"@typespec/http": "workspace:~0.48.0",
Expand All @@ -65,7 +65,6 @@
"@types/react": "~18.2.22",
"@types/swagger-ui-react": "^4.18.0",
"@types/swagger-ui": "~3.52.0",
"@typespec/bundler": "workspace:~0.1.0",
"@typespec/eslint-config-typespec": "workspace:~0.48.0",
"@vitejs/plugin-react": "~4.0.4",
"c8": "~8.0.1",
Expand Down
63 changes: 62 additions & 1 deletion packages/playground/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# TypeSpec Playground

A web app to play with TypeSpec in the browser.
Contains react components for the TypeSpec playground.

It can be used as a standalone custom playground with your own libraries or components can be used individually to customize the UI as you see fit.

## Usage

### Standalone

The stanalone playground provides some vite helpers to make it easy to get started.

In `vite.config.ts`:

```ts
import { definePlaygroundViteConfig } from "@typespec/playground/vite";

const config = definePlaygroundViteConfig({
defaultEmitter: "@typespec/openapi3",
libraries: [
"@typespec/compiler",
"@typespec/http",
"@typespec/openapi3",

// Add any other libraries here. Make sure those libraries are also dependencies of that package.
],
samples: {
"My sample": {
filename: "samples/my.tsp",
preferredEmitter: "@typespec/openapi3",
},
},
links: {
githubIssueUrl: `<link to your website>`,
documentationUrl: "<link to your website>",
},
});

export default config;
```

In `src/main.tsx`:

```tsx
import { PlaygroundManifest } from "@typespec/playground/manifest";
import { renderReactPlayground } from "@typespec/playground/react";
import { SwaggerUIViewer } from "@typespec/playground/react/viewers";
import "./style.css";

await renderReactPlayground({
...PlaygroundManifest,
emitterViewers: {
"@typespec/openapi3": [SwaggerUIViewer],
},
});
```

### Individual components

Playground react components can be used individually. The things to watch out for is for the TypeSpec compiler to be working correctly it needs:

- The libraries to be loaded and registered
- The libraries **MUST** be importable by their name this means an import map must be setup. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
- The libraries **MUST** have been bundled using `@typespec/bundler`
5 changes: 2 additions & 3 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@typespec/playground",
"private": true,
"version": "0.44.0",
"version": "0.1.0-alpha.0",
"author": "Microsoft Corporation",
"description": "TypeSpec playground UI components.",
"homepage": "https://microsoft.github.io/typespec",
Expand Down Expand Up @@ -80,7 +79,7 @@
"@types/react": "~18.2.22",
"@types/swagger-ui-react": "^4.18.0",
"@types/swagger-ui": "~3.52.0",
"@typespec/bundler": "workspace:~0.1.0",
"@typespec/bundler": "workspace:~0.1.0-alpha.0",
"@typespec/eslint-config-typespec": "workspace:~0.48.0",
"@vitejs/plugin-react": "~4.0.4",
"c8": "~8.0.1",
Expand Down
4 changes: 2 additions & 2 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"packageName": "@typespec/playground",
"projectFolder": "packages/playground",
"reviewCategory": "production",
"shouldPublish": false
"versionPolicyName": "playground"
},
{
"packageName": "@typespec/playground-website",
Expand All @@ -184,7 +184,7 @@
"packageName": "@typespec/bundler",
"projectFolder": "packages/bundler",
"reviewCategory": "production",
"shouldPublish": false
"versionPolicyName": "playground"
},
{
"packageName": "@typespec/protobuf",
Expand Down
Loading