Skip to content

Commit

Permalink
Add plugin tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Electron committed May 6, 2023
1 parent 4983db2 commit dceacc4
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 333 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.reusable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Install dependencies
run: |
yarn
- name: Build plugins
run: |
yarn build:plugins
# Submodules cached per environment to save time
- name: Cache submodules
uses: actions/cache@v3
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ jobs:
publish:
strategy:
matrix:
package: [core, cli]
package: [core, cli, plugin-tutorial]
include:
- package: core
path: 'package.json'
workspace: '@iota-wiki/core'
- package: cli
path: 'cli/package.json'
workspace: '@iota-wiki/cli'
- package: plugin-tutorial
path: 'plugins/tutorial/package.json'
workspace: '@iota-wiki/plugin-tutorial'
uses: ./.github/workflows/publish.reusable.yaml
with:
path: ${{ matrix.path }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ jobs:
tag:
strategy:
matrix:
package: [core, cli]
package: [core, cli, plugin-tutorial]
include:
- package: core
path: 'package.json'
workspace: '@iota-wiki/core'
- package: cli
path: 'cli/package.json'
workspace: '@iota-wiki/cli'
- package: plugin-tutorial
path: 'plugins/tutorial/package.json'
workspace: '@iota-wiki/plugin-tutorial'
uses: ./.github/workflows/tag.reusable.yaml
with:
path: ${{ matrix.path }}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/tutorial/configure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
stringLiteral,
} from '@babel/types';
import generator from '@babel/generator';
import { UserOptions as TutorialOptions } from '@iota-wiki/plugin-tutorial';
import { type UserOptions as TutorialOptions } from '@iota-wiki/plugin-tutorial';
import prettier from 'prettier';

interface InputComponentProps {
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"start:shimmer": "(ENVIRONMENT=shimmer; yarn generate:api && yarn start)",
"start:next": "(ENVIRONMENT=next; yarn generate:api && yarn start)",
"start:all": "yarn build:all && yarn serve",
"build:plugins": "yarn ./plugins/tutorial build",
"build:iota": "(ENVIRONMENT=iota; yarn generate:api && yarn build --out-dir build)",
"build:shimmer": "(ENVIRONMENT=shimmer; yarn generate:api && yarn build --out-dir build/shimmer)",
"build:next": "(ENVIRONMENT=next; yarn generate:api && yarn build --out-dir build/next)",
"build:all": "yarn build:iota && yarn build:shimmer && yarn build:next",
"build:production:iota": "(MODE=\"production\" EXTERNAL=\"*,*/*,*/*/*\"; yarn checkout:remote:iota && yarn build:iota)",
"build:production:shimmer": "(MODE=\"production\" EXTERNAL=\"*,*/*,*/*/*\"; yarn checkout:remote:shimmer && yarn build:shimmer)",
"build:production:next": "(MODE=\"production\" EXTERNAL=\"*,*/*,*/*/*\"; yarn checkout:remote:next && yarn build:next)",
"build:all": "yarn build:plugins && yarn build:iota && yarn build:shimmer && yarn build:next",
"build:production:iota": "(MODE=\"production\" EXTERNAL=\"*,*/*,*/*/*\"; yarn checkout:remote:iota && yarn build:plugins && yarn build:iota)",
"build:production:shimmer": "(MODE=\"production\" EXTERNAL=\"*,*/*,*/*/*\"; yarn checkout:remote:shimmer && yarn build:plugins && yarn build:shimmer)",
"build:production:next": "(MODE=\"production\" EXTERNAL=\"*,*/*,*/*/*\"; yarn checkout:remote:next && yarn build:plugins && yarn build:next)",
"checkout": "git submodule update --init",
"checkout:iota": "yarn checkout iota/external/*",
"checkout:shimmer": "yarn checkout shimmer/external/*",
Expand Down Expand Up @@ -46,7 +47,7 @@
"@docusaurus/core": "2.2.0",
"@docusaurus/plugin-client-redirects": "2.2.0",
"@docusaurus/preset-classic": "2.2.0",
"@iota-wiki/plugin-tutorial": "^1.0.6",
"@iota-wiki/plugin-tutorial": "workspace:^",
"@mdx-js/react": "^1.6.21",
"@popperjs/core": "^2.11.5",
"@svgr/webpack": "^5.5.0",
Expand Down Expand Up @@ -114,6 +115,7 @@
"packageManager": "yarn@3.2.0",
"workspaces": [
"cli",
"plugins/**",
"theme"
],
"files": []
Expand Down
10 changes: 10 additions & 0 deletions plugins/tutorial/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
/dist

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.*
1 change: 1 addition & 0 deletions plugins/tutorial/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
29 changes: 29 additions & 0 deletions plugins/tutorial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Tutorial plugin

This is a small plugin to register tutorials to be listed on the tutorial page plugin.

## Usage

```
yarn add @iota-wiki/plugin-tutorial
```

Then register any tutorials to list on the tutorial page by providing information like the titles, routes and metadata of the tutorials:

```js
plugins: [
[
'@iota-wiki/plugin-tutorial',
{
title: "EVM Tutorial",
description:
"In this tutorial, you will learn how to use the EVM in IOTA.",
route: "evm-tutorial/intro",
tags: ["text"],
source: "https://github.com/dr-electron/tutorial-template", // Optional
preview: "evm-tutorial.png", // Optional
},
],
...
...
```
20 changes: 20 additions & 0 deletions plugins/tutorial/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@iota-wiki/plugin-tutorial",
"version": "1.0.6",
"main": "dist/index.js",
"types": "src/types.d.ts",
"scripts": {
"clean": "rm -rf ./lib",
"build": "tsc --build",
"prepack": "yarn build"
},
"packageManager": "yarn@3.2.2",
"devDependencies": {
"@docusaurus/types": "2.2.0",
"typescript": "^4.6.3"
},
"files": [
"dist",
"src/types.d.ts"
]
}
32 changes: 32 additions & 0 deletions plugins/tutorial/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type {
OptionValidationContext,
LoadContext,
Plugin,
} from '@docusaurus/types';

import type { NormalizedOptions, UserOptions } from './types';

export default async function pluginTutorial(
context: LoadContext,
options: NormalizedOptions,
): Promise<Plugin> {
return {
name: '@iota-wiki/plugin-tutorial',
async contentLoaded({ actions }) {
actions.setGlobalData(options);
},
};
}

export function validateOptions({
options: userOptions,
}: OptionValidationContext<UserOptions, NormalizedOptions>): NormalizedOptions {
const id = userOptions.title.normalize().toLowerCase().replace(/\W/, '-');

const defaultOptions = {
id,
route: id,
};

return Object.assign(defaultOptions, userOptions);
}
15 changes: 15 additions & 0 deletions plugins/tutorial/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface Options {
title: string;
description: string;
tags: string[];
source?: string;
preview?: string;
}

export interface DefaultOptions {
id: string;
route: string;
}

export type UserOptions = Options & Partial<DefaultOptions>;
export type NormalizedOptions = Options & DefaultOptions;
12 changes: 12 additions & 0 deletions plugins/tutorial/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2019",
"module": "NodeNext",
"moduleResolution": "node",
"esModuleInterop": true,
"rootDir": "src",
"outDir": "dist",
"declaration": true
},
"include": ["src"]
}

0 comments on commit dceacc4

Please sign in to comment.