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

Migrate docusaurus-plugin-moonwave to ESM #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion docusaurus-plugin-moonwave/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"url": "https://github.com/evaera/moonwave/issues"
},
"homepage": "https://github.com/evaera/moonwave/tree/master/docusaurus-plugin-moonwave",
"type": "module",
"dependencies": {
"@mapbox/rehype-prism": "^0.9.0",
"hast-util-sanitize": "^5.0.1",
Expand All @@ -33,4 +34,4 @@
"hast-util-from-html": "^2.0.3",
"micromark-util-symbol": "^2.0.0"
}
}
}
8 changes: 4 additions & 4 deletions docusaurus-plugin-moonwave/src/components/ClassMember.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Heading from "@theme/Heading"
import React from "react"
import Admonition from "./Admonition"
import Badge from "./Badge"
import SourceLink from "./SourceLink"
import Admonition from "./Admonition.js"
import Badge from "./Badge.js"
import SourceLink from "./SourceLink.js"
import styles from "./styles.module.css"
import Tag from "./Tag"
import Tag from "./Tag.js"

export default function ClassMember({
name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import Markdown from "./Markdown"
import Markdown from "./Markdown.js"
import styles from "./styles.module.css"

export default function InlineDescription({ content }) {
Expand Down
16 changes: 8 additions & 8 deletions docusaurus-plugin-moonwave/src/components/LuaClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
useEffect,
useState,
} from "react"
import Admonition from "./Admonition"
import Badge from "./Badge"
import ClassMember from "./ClassMember"
import LuaFunction from "./LuaFunction"
import LuaProp from "./LuaProp"
import LuaTypeDef from "./LuaTypeDef"
import Markdown from "./Markdown"
import Admonition from "./Admonition.js"
import Badge from "./Badge.js"
import ClassMember from "./ClassMember.js"
import LuaFunction from "./LuaFunction.js"
import LuaProp from "./LuaProp.js"
import LuaTypeDef from "./LuaTypeDef.js"
import Markdown from "./Markdown.js"
import styles from "./styles.module.css"
import Tag from "./Tag"
import Tag from "./Tag.js"

const SECTIONS = [
{
Expand Down
10 changes: 5 additions & 5 deletions docusaurus-plugin-moonwave/src/components/LuaFunction.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Heading from "@theme/Heading"
import clsx from "clsx"
import React from "react"
import InlineDescription from "./InlineDescription"
import LuaType from "./LuaType"
import LuaTypeDef from "./LuaTypeDef"
import Markdown from "./Markdown"
import InlineDescription from "./InlineDescription.js"
import LuaType from "./LuaType.js"
import LuaTypeDef from "./LuaTypeDef.js"
import Markdown from "./Markdown.js"
import styles from "./styles.module.css"
import { PrOp } from "./Syntax"
import { PrOp } from "./Syntax.js"

const Param = ({ name, lua_type }) => (
<>
Expand Down
4 changes: 2 additions & 2 deletions docusaurus-plugin-moonwave/src/components/LuaProp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"
import LuaType from "./LuaType"
import Markdown from "./Markdown"
import LuaType from "./LuaType.js"
import Markdown from "./Markdown.js"
import styles from "./styles.module.css"

export default function LuaProp({
Expand Down
6 changes: 3 additions & 3 deletions docusaurus-plugin-moonwave/src/components/LuaType.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useContext } from "react"
import GenericLink from "./GenericLink"
import { TypeLinksContext } from "./LuaClass"
import GenericLink from "./GenericLink.js"
import { TypeLinksContext } from "./LuaClass.js"
import styles from "./styles.module.css"
import { Op, PrOp } from "./Syntax"
import { Op, PrOp } from "./Syntax.js"

const isPunc = (char) => !!char.match(/[\{\}<>\-\|&]/)
const isWhitespace = (char) => !!char.match(/\s/)
Expand Down
6 changes: 3 additions & 3 deletions docusaurus-plugin-moonwave/src/components/LuaTypeDef.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import InlineDescription from "./InlineDescription"
import LuaType from "./LuaType"
import Markdown from "./Markdown"
import InlineDescription from "./InlineDescription.js"
import LuaType from "./LuaType.js"
import Markdown from "./Markdown.js"
import styles from "./styles.module.css"

const TypeAlias = ({ name, luaType }) => (
Expand Down
6 changes: 3 additions & 3 deletions docusaurus-plugin-moonwave/src/components/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import sanitize from "rehype-sanitize"
import html from "rehype-stringify"
import directives from "remark-directive"
import remarkGfm from "remark-gfm"
import remarkRehypeAdmonitions from "../remark/remarkRehypeAdmonitions"
import remarkExtendedLinkReferences from "../remark/remarkExtendedLinkReferences"
import remarkRehypeAdmonitions from "../remark/remarkRehypeAdmonitions.js"
import remarkExtendedLinkReferences from "../remark/remarkExtendedLinkReferences.js"
import parse from "remark-parse"
import remark2rehype from "remark-rehype"
import { unified } from "unified"
import { TypeLinksContext } from "./LuaClass"
import { TypeLinksContext } from "./LuaClass.js"

const schema = {
...defaultSchema,
Expand Down
4 changes: 2 additions & 2 deletions docusaurus-plugin-moonwave/src/generateRobloxTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright © 2018 Eryn L. K.
*****/

const fetch = require("node-fetch")
import fetch from "node-fetch"

const dataTypes = [
"Axes",
Expand Down Expand Up @@ -42,7 +42,7 @@ const dataTypes = [
"Vector3int16",
]

module.exports.generateRobloxTypes = async function generateRobloxTypes() {
export async function generateRobloxTypes() {
const req = await fetch(
"https://raw.githubusercontent.com/CloneTrooper1019/Roblox-Client-Watch/roblox/API-Dump.json"
)
Expand Down
24 changes: 12 additions & 12 deletions docusaurus-plugin-moonwave/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require("path")
const fs = require("fs")
const { promisify } = require("util")
import { resolve } from "path"
import { existsSync } from "fs"
import { promisify } from "util"
const exec = promisify(require("child_process").exec)
const { generateRobloxTypes } = require("./generateRobloxTypes")
import { generateRobloxTypes } from "./generateRobloxTypes.js"

const capitalize = (text) => text[0].toUpperCase() + text.substring(1)

Expand Down Expand Up @@ -259,19 +259,19 @@ async function generateTypeLinks(nameSet, luaClasses, baseUrl) {
return typeLinks
}

module.exports = (context, options) => ({
export default (context, options) => ({
name: "docusaurus-plugin-moonwave",

getThemePath() {
return path.resolve(__dirname, "./theme")
return resolve(__dirname, "./theme")
},

getPathsToWatch() {
return options.code.map((filePath) => `${filePath}/**/*.{lua,luau}`)
},

async loadContent() {
const basePath = options.projectDir || path.resolve(process.cwd(), "..")
const basePath = options.projectDir || resolve(process.cwd(), "..")

const binaryPath = options.binaryPath ?? "moonwave-extractor"

Expand Down Expand Up @@ -402,7 +402,7 @@ module.exports = (context, options) => ({
addRoute({
path: baseUrl + "api/",
exact: true,
component: path.resolve(__dirname, "components/Redirect.js"),
component: resolve(__dirname, "components/Redirect.js"),
modules: {
sidebarClassNames,
pluginOptions,
Expand All @@ -428,7 +428,7 @@ module.exports = (context, options) => ({

addRoute({
path: `${baseUrl}api/${luaClass.name}`,
component: path.resolve(__dirname, "components/LuaClass.js"),
component: resolve(__dirname, "components/LuaClass.js"),
modules: {
luaClass: apiDataPath,
sidebarClassNames,
Expand All @@ -442,7 +442,7 @@ module.exports = (context, options) => ({
},
})

module.exports.validateOptions = ({ options }) => {
export function validateOptions({ options }) {
if (!options.code) {
throw new Error(
"Moonwave plugin: expected option `code` to point to your source code."
Expand Down Expand Up @@ -472,9 +472,9 @@ module.exports.validateOptions = ({ options }) => {
)
}

const resolvedPath = path.resolve(process.cwd(), codePath)
const resolvedPath = resolve(process.cwd(), codePath)

if (!fs.existsSync(resolvedPath)) {
if (!existsSync(resolvedPath)) {
throw new Error(
`Moonwave plugin: code path ${resolvedPath} does not actually exist.`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { visit, EXIT } from "unist-util-visit"
import { fromHtml } from "hast-util-from-html"
import { renderToString } from "react-dom/server"

import Admonition from "../components/Admonition"
import Admonition from "../components/Admonition.js"

/// remark-rehype handlers
const handlers = {
Expand Down
Loading