added script to generate exports
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
// export * from "./core/component-event"
|
||||
// export * from "./core/components/action-row"
|
||||
// export * from "./core/components/button"
|
||||
// export * from "./core/components/button-shared-props"
|
||||
// export * from "./core/components/embed"
|
||||
// export * from "./core/components/embed-author"
|
||||
// export * from "./core/components/embed-field"
|
||||
// export * from "./core/components/embed-footer"
|
||||
// export * from "./core/components/embed-image"
|
||||
// export * from "./core/components/embed-thumbnail"
|
||||
// export * from "./core/components/embed-title"
|
||||
// export * from "./core/components/link"
|
||||
// export * from "./core/components/option"
|
||||
// export * from "./core/components/select"
|
||||
// export * from "./core/instance"
|
||||
// export { useInstance } from "./core/instance-context"
|
||||
// export * from "./core/reacord"
|
||||
// export * from "./djs/reacord-discord-js"
|
||||
export {}
|
||||
export { type ReacordConfig, ReacordClient } from "./reacord-client.js"
|
||||
export { type ReacordInstance } from "./reacord-instance.js"
|
||||
export { ActionRow, type ActionRowProps } from "./react/action-row.js"
|
||||
export { type ButtonSharedProps } from "./react/button-shared-props.js"
|
||||
export {
|
||||
Button,
|
||||
type ButtonProps,
|
||||
type ButtonClickEvent,
|
||||
} from "./react/button.js"
|
||||
export { type ComponentEvent } from "./react/component-event.js"
|
||||
export { EmbedAuthor, type EmbedAuthorProps } from "./react/embed-author.js"
|
||||
export { EmbedField, type EmbedFieldProps } from "./react/embed-field.js"
|
||||
export { EmbedFooter, type EmbedFooterProps } from "./react/embed-footer.js"
|
||||
export { EmbedImage, type EmbedImageProps } from "./react/embed-image.js"
|
||||
export {
|
||||
EmbedThumbnail,
|
||||
type EmbedThumbnailProps,
|
||||
} from "./react/embed-thumbnail.js"
|
||||
export { EmbedTitle, type EmbedTitleProps } from "./react/embed-title.js"
|
||||
export { Embed, type EmbedProps } from "./react/embed.js"
|
||||
export { useInstance } from "./react/instance-context.js"
|
||||
export { Link, type LinkProps } from "./react/link.js"
|
||||
export { Option, type OptionProps } from "./react/option.js"
|
||||
export {
|
||||
Select,
|
||||
type SelectProps,
|
||||
type SelectChangeEvent,
|
||||
} from "./react/select.js"
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
"devDependencies": {
|
||||
"@reacord/helpers": "workspace:*",
|
||||
"@types/lodash-es": "^4.17.6",
|
||||
"@types/prettier": "^2.6.4",
|
||||
"discord.js": "^14.1.2",
|
||||
"dotenv": "^16.0.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
@@ -70,6 +71,7 @@
|
||||
"pretty-ms": "^8.0.0",
|
||||
"react": "^18.2.0",
|
||||
"release-it": "^15.2.0",
|
||||
"ts-morph": "^15.1.0",
|
||||
"tsup": "^6.2.1",
|
||||
"tsx": "^3.8.0",
|
||||
"type-fest": "^2.18.0",
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { writeFile } from "node:fs/promises"
|
||||
import { join, relative } from "node:path/posix"
|
||||
import prettier from "prettier"
|
||||
import { Node, Project, SyntaxKind } from "ts-morph"
|
||||
|
||||
function isDeclarationPublic(declaration: Node) {
|
||||
if (!Node.isJSDocable(declaration)) return false
|
||||
|
||||
const jsDocTags = new Set(
|
||||
declaration
|
||||
.getJsDocs()
|
||||
.flatMap((doc) => doc.getTags())
|
||||
.map((tag) => tag.getTagName()),
|
||||
)
|
||||
|
||||
return jsDocTags.has("category") && !jsDocTags.has("private")
|
||||
}
|
||||
|
||||
const project = new Project()
|
||||
|
||||
project.addSourceFilesAtPaths(["library/**/*.{ts,tsx}", "!library/main.ts"])
|
||||
|
||||
const exportLines = project
|
||||
.getSourceFiles()
|
||||
.map((file) => {
|
||||
const importPath = relative(
|
||||
"library",
|
||||
join(file.getDirectoryPath(), file.getBaseNameWithoutExtension() + ".js"),
|
||||
)
|
||||
const exports = file.getExportedDeclarations()
|
||||
|
||||
const exportNames = [...exports].flatMap(([name, [declaration]]) => {
|
||||
if (!declaration) return []
|
||||
if (!isDeclarationPublic(declaration)) return []
|
||||
if (
|
||||
declaration.isKind(SyntaxKind.TypeAliasDeclaration) ||
|
||||
declaration.isKind(SyntaxKind.InterfaceDeclaration)
|
||||
) {
|
||||
return `type ${name}`
|
||||
}
|
||||
return name
|
||||
})
|
||||
|
||||
return { importPath, exportNames }
|
||||
})
|
||||
.filter(({ exportNames }) => exportNames.length > 0)
|
||||
.map(({ importPath, exportNames }) => {
|
||||
return `export { ${exportNames.join(", ")} } from "./${importPath}"`
|
||||
})
|
||||
|
||||
const resolvedConfig = await prettier.resolveConfig("library/main.ts")
|
||||
if (!resolvedConfig) {
|
||||
throw new Error("Could not find prettier config")
|
||||
}
|
||||
|
||||
await writeFile(
|
||||
"library/main.ts",
|
||||
prettier.format(exportLines.join(";"), {
|
||||
...resolvedConfig,
|
||||
parser: "typescript",
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user