-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
332 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## @portone-io/remark-param-tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@portone-io/remark-param-tree", | ||
"version": "0.0.1", | ||
"repository": "https://github.com/portone-io/developers.portone.io", | ||
"type": "module", | ||
"private": true, | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"dependencies": { | ||
"mdast-util-from-markdown": "^2.0.1", | ||
"mdast-util-to-string": "^4.0.0", | ||
"remark": "^15.0.1", | ||
"remark-stringify": "^11.0.0", | ||
"ts-pattern": "^5.1.1", | ||
"unified": "^11.0.5", | ||
"unist-util-visit": "^5.0.0", | ||
"unist-util-visit-parents": "^6.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/mdast": "^4.0.4", | ||
"@types/node": "^20.12.7", | ||
"@types/unist": "^3.0.3", | ||
"@vitest/ui": "^1.5.3", | ||
"mdast-util-mdx-jsx": "^3.1.3", | ||
"vfile": "^6.0.3", | ||
"vite-tsconfig-paths": "^4.3.2", | ||
"vitest": "^1.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import "mdast-util-mdx-jsx"; | ||
|
||
import path from "node:path"; | ||
|
||
import type { BlockContent, DefinitionContent, Paragraph, Root } from "mdast"; | ||
import { fromMarkdown } from "mdast-util-from-markdown"; | ||
import { toString } from "mdast-util-to-string"; | ||
import { match, P } from "ts-pattern"; | ||
import { SKIP, visit } from "unist-util-visit"; | ||
import type { VFile } from "vfile"; | ||
|
||
const isParameter = (node: BlockContent | DefinitionContent) => {}; | ||
Check failure on line 12 in packages/remark-param-tree/scripts/migration.ts GitHub Actions / Lint code and MDX files
|
||
|
||
type TypeDefinition = { | ||
name: string; | ||
type: string; | ||
optional: boolean; | ||
}; | ||
|
||
export default function remarkParamTreePlugin() { | ||
return function (tree: Root, file: VFile) { | ||
const workingFile = path.resolve( | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument | ||
file.cwd, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access | ||
file.history[0] ?? "", | ||
); | ||
visit(tree, "mdxJsxFlowElement", (node) => { | ||
if (node.name === "ParamTree") { | ||
visit(node, "listItem", (listItem) => { | ||
if (listItem.children[0]?.type !== "paragraph") { | ||
return; | ||
} | ||
listItem.children[0].children = listItem.children[0].children.filter( | ||
(child) => | ||
match(child) | ||
.with( | ||
{ | ||
type: "text", | ||
value: P.when((value) => value.trim() === ""), | ||
}, | ||
() => false, | ||
) | ||
.otherwise(() => true), | ||
); | ||
const typeDefinition: TypeDefinition | null = match( | ||
listItem.children[0], | ||
) | ||
.with( | ||
{ | ||
children: [ | ||
{ type: P.not(P.union("inlineCode", "strong")) }, | ||
...P.array(), | ||
], | ||
}, | ||
() => null, | ||
) | ||
.with( | ||
{ | ||
children: [ | ||
{ type: P.union("inlineCode", "strong") }, | ||
{ | ||
type: "mdxJsxTextElement", | ||
name: "mark", | ||
}, | ||
], | ||
}, | ||
(typeDefinition) => { | ||
return { | ||
name: toString(typeDefinition.children[0]), | ||
type: toString(typeDefinition.children[1]), | ||
optional: true, | ||
} satisfies TypeDefinition; | ||
}, | ||
) | ||
.with( | ||
{ | ||
children: [ | ||
{ type: P.union("inlineCode", "strong") }, | ||
{ | ||
type: "mdxJsxTextElement", | ||
name: "mark", | ||
}, | ||
{ | ||
type: "mdxJsxTextElement", | ||
name: "mark", | ||
}, | ||
], | ||
}, | ||
(typeDefinition) => { | ||
return { | ||
name: toString(typeDefinition.children[0]), | ||
type: toString(typeDefinition.children[2]), | ||
optional: false, | ||
} satisfies TypeDefinition; | ||
}, | ||
) | ||
.otherwise(() => { | ||
// console.log(workingFile, toString(listItem.children[0])); | ||
return null; | ||
}); | ||
|
||
if (typeDefinition) { | ||
listItem.children[0] = fromMarkdown( | ||
`${typeDefinition.name}${typeDefinition.optional ? "" : "*"}: ${typeDefinition.type}`, | ||
"utf-8", | ||
).children[0] as Paragraph; | ||
console.log(workingFile, listItem.children[0]); | ||
} | ||
}); | ||
} | ||
return SKIP; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import "mdast-util-mdx-jsx"; | ||
|
||
import path from "node:path"; | ||
|
||
import type { BlockContent, DefinitionContent, Paragraph, Root } from "mdast"; | ||
import { fromMarkdown } from "mdast-util-from-markdown"; | ||
import { toString } from "mdast-util-to-string"; | ||
import { match, P } from "ts-pattern"; | ||
Check failure on line 8 in packages/remark-param-tree/src/index.ts GitHub Actions / Lint code and MDX files
|
||
import { SKIP, visit } from "unist-util-visit"; | ||
Check failure on line 9 in packages/remark-param-tree/src/index.ts GitHub Actions / Lint code and MDX files
|
||
import type { VFile } from "vfile"; | ||
|
||
const isParameter = (node: BlockContent | DefinitionContent) => {}; | ||
|
||
type TypeDefinition = { | ||
name: string; | ||
type: string; | ||
optional: boolean; | ||
}; | ||
|
||
export default function remarkParamTreePlugin() { | ||
return function (tree: Root, file: VFile) {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"types": ["vitest/globals"], | ||
"baseUrl": "./" | ||
} | ||
} |
Oops, something went wrong.