Skip to content

feat(playground): inline dependencies per framework example #2970

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

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/components/global/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ interface UsageTargetOptions {
files: {
[key: string]: MdxContent;
};
/**
* The list of dependencies to use in the Stackblitz example.
* The key is the package name and the value is the version.
* The version must be a valid semver range.
*
* For example:
* ```ts
* dependencies: {
* '@maskito/core': '^0.11.0',
* }
* ```
*/
dependencies?: {
[key: string]: string;
};
}

/**
Expand Down Expand Up @@ -326,6 +341,7 @@ export default function Playground({
.outerText,
}))
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
editorOptions.dependencies = (code[usageTarget] as UsageTargetOptions).dependencies;
}

switch (usageTarget) {
Expand Down
12 changes: 12 additions & 0 deletions src/components/global/Playground/stackblitz.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export interface EditorOptions {
[key: string]: string;
};

/**
* List of dependencies to add to the Stackblitz example.
* The key is the name of the dependency and the value is the version.
*/
dependencies?: {
[key: string]: string;
}

/**
* `true` if `ion-app` and `ion-content` should automatically be injected into the
* Stackblitz example.
Expand Down Expand Up @@ -79,6 +87,7 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => {
dependencies = {
...dependencies,
...JSON.parse(package_json).dependencies,
...options?.dependencies,
};
} catch (e) {
console.error('Failed to parse package.json contents', e);
Expand Down Expand Up @@ -130,6 +139,7 @@ const openAngularEditor = async (code: string, options?: EditorOptions) => {
'angular.json': defaultFiles[9],
'tsconfig.json': defaultFiles[10],
...options?.files,
...options?.dependencies,
};

const package_json = defaultFiles[11];
Expand All @@ -144,6 +154,7 @@ const openAngularEditor = async (code: string, options?: EditorOptions) => {
dependencies = {
...dependencies,
...JSON.parse(package_json).dependencies,
...options?.dependencies,
};
} catch (e) {
console.error('Failed to parse package.json contents', e);
Expand Down Expand Up @@ -183,6 +194,7 @@ const openReactEditor = async (code: string, options?: EditorOptions) => {
'package.json': defaultFiles[4],
'package-lock.json': defaultFiles[5],
...options?.files,
...options?.dependencies,
'.stackblitzrc': `{
"startCommand": "yarn run start"
}`,
Expand Down