Make script for adding types to index (#118)

* Make script for adding types to index

* Add semicolons to export lines
This commit is contained in:
SleeplessOne1917 2023-05-11 17:10:28 +00:00 committed by GitHub
parent 82ac85785d
commit 40dfb4c3ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 295 additions and 8 deletions

View file

@ -3,14 +3,10 @@
"env": { "env": {
"browser": true "browser": true
}, },
"plugins": [ "plugins": ["@typescript-eslint"],
"@typescript-eslint" "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"ignorePatterns": ["putTypesInIndex.js"],
"parserOptions": { "parserOptions": {
"project": "./tsconfig.json", "project": "./tsconfig.json",
"warnOnUnsupportedTypeScriptVersion": false "warnOnUnsupportedTypeScriptVersion": false

View file

@ -11,4 +11,6 @@ cp api_common/bindings/* ../../lemmy-js-client/src/types/
cp db_schema/bindings/* ../../lemmy-js-client/src/types/ cp db_schema/bindings/* ../../lemmy-js-client/src/types/
cp db_views/bindings/* ../../lemmy-js-client/src/types/ cp db_views/bindings/* ../../lemmy-js-client/src/types/
cp db_views_actor/bindings/* ../../lemmy-js-client/src/types/ cp db_views_actor/bindings/* ../../lemmy-js-client/src/types/
cp db_views_moderator/bindings/* ../../lemmy-js-client/src/types/ cp db_views_moderator/bindings/* ../../lemmy-js-client/src/types/
node ../../lemmy-js-client/putTypesInIndex.js

36
putTypesInIndex.js Normal file
View file

@ -0,0 +1,36 @@
const fs = require("fs/promises");
const path = require("path");
const exportRegex = /export\s+(?:enum|interface|type)\s+([A-Za-z0-9_]+)/g;
const baseExports = ['export * from "./http";', 'export * from "./websocket";'];
async function putTypesInIndex() {
const typeFiles = await fs.readdir(path.resolve("./src/types"));
const exports = [...baseExports];
for (const filename of typeFiles) {
const localExports = [];
const fileText = await fs.readFile(path.resolve(`./src/types/${filename}`));
for (
let match = exportRegex.exec(fileText);
match;
match = exportRegex.exec(fileText)
) {
localExports.push(match[1]);
}
const spacer = localExports.length > 1 ? "\n" : " ";
exports.push(
`export {${spacer}${localExports.join(
",\n"
)}${spacer}} from "./types/${filename.replace(/\..+/, "")}";`
);
}
fs.writeFile(path.resolve("./src/index.ts"), exports.join("\n"), {
flag: "w",
});
}
putTypesInIndex();

View file

@ -1,2 +1,255 @@
export * from "./http"; export * from "./http";
export { AddAdmin } from "./types/AddAdmin";
export { AddAdminResponse } from "./types/AddAdminResponse";
export { AddModToCommunity } from "./types/AddModToCommunity";
export { AddModToCommunityResponse } from "./types/AddModToCommunityResponse";
export { AdminPurgeComment } from "./types/AdminPurgeComment";
export { AdminPurgeCommentView } from "./types/AdminPurgeCommentView";
export { AdminPurgeCommunity } from "./types/AdminPurgeCommunity";
export { AdminPurgeCommunityView } from "./types/AdminPurgeCommunityView";
export { AdminPurgePerson } from "./types/AdminPurgePerson";
export { AdminPurgePersonView } from "./types/AdminPurgePersonView";
export { AdminPurgePost } from "./types/AdminPurgePost";
export { AdminPurgePostView } from "./types/AdminPurgePostView";
export { ApproveRegistrationApplication } from "./types/ApproveRegistrationApplication";
export { BanFromCommunity } from "./types/BanFromCommunity";
export { BanFromCommunityResponse } from "./types/BanFromCommunityResponse";
export { BanPerson } from "./types/BanPerson";
export { BanPersonResponse } from "./types/BanPersonResponse";
export { BannedPersonsResponse } from "./types/BannedPersonsResponse";
export { BlockCommunity } from "./types/BlockCommunity";
export { BlockCommunityResponse } from "./types/BlockCommunityResponse";
export { BlockPerson } from "./types/BlockPerson";
export { BlockPersonResponse } from "./types/BlockPersonResponse";
export { CaptchaResponse } from "./types/CaptchaResponse";
export { ChangePassword } from "./types/ChangePassword";
export { Comment } from "./types/Comment";
export { CommentAggregates } from "./types/CommentAggregates";
export { CommentId } from "./types/CommentId";
export { CommentReply } from "./types/CommentReply";
export { CommentReplyId } from "./types/CommentReplyId";
export { CommentReplyResponse } from "./types/CommentReplyResponse";
export { CommentReplyView } from "./types/CommentReplyView";
export { CommentReport } from "./types/CommentReport";
export { CommentReportId } from "./types/CommentReportId";
export { CommentReportResponse } from "./types/CommentReportResponse";
export { CommentReportView } from "./types/CommentReportView";
export { CommentResponse } from "./types/CommentResponse";
export { CommentSortType } from "./types/CommentSortType";
export { CommentView } from "./types/CommentView";
export { Community } from "./types/Community";
export { CommunityAggregates } from "./types/CommunityAggregates";
export { CommunityBlockId } from "./types/CommunityBlockId";
export { CommunityBlockView } from "./types/CommunityBlockView";
export { CommunityFollowerView } from "./types/CommunityFollowerView";
export { CommunityId } from "./types/CommunityId";
export { CommunityJoin } from "./types/CommunityJoin";
export { CommunityJoinResponse } from "./types/CommunityJoinResponse";
export { CommunityModeratorView } from "./types/CommunityModeratorView";
export { CommunityResponse } from "./types/CommunityResponse";
export { CommunityView } from "./types/CommunityView";
export { CreateComment } from "./types/CreateComment";
export { CreateCommentLike } from "./types/CreateCommentLike";
export { CreateCommentReport } from "./types/CreateCommentReport";
export { CreateCommunity } from "./types/CreateCommunity";
export { CreateCustomEmoji } from "./types/CreateCustomEmoji";
export { CreatePost } from "./types/CreatePost";
export { CreatePostLike } from "./types/CreatePostLike";
export { CreatePostReport } from "./types/CreatePostReport";
export { CreatePrivateMessage } from "./types/CreatePrivateMessage";
export { CreatePrivateMessageReport } from "./types/CreatePrivateMessageReport";
export { CreateSite } from "./types/CreateSite";
export { CustomEmoji } from "./types/CustomEmoji";
export { CustomEmojiId } from "./types/CustomEmojiId";
export { CustomEmojiKeyword } from "./types/CustomEmojiKeyword";
export { CustomEmojiResponse } from "./types/CustomEmojiResponse";
export { CustomEmojiView } from "./types/CustomEmojiView";
export { DeleteAccount } from "./types/DeleteAccount";
export { DeleteAccountResponse } from "./types/DeleteAccountResponse";
export { DeleteComment } from "./types/DeleteComment";
export { DeleteCommunity } from "./types/DeleteCommunity";
export { DeleteCustomEmoji } from "./types/DeleteCustomEmoji";
export { DeleteCustomEmojiResponse } from "./types/DeleteCustomEmojiResponse";
export { DeletePost } from "./types/DeletePost";
export { DeletePrivateMessage } from "./types/DeletePrivateMessage";
export { DistinguishComment } from "./types/DistinguishComment";
export { EditComment } from "./types/EditComment";
export { EditCommunity } from "./types/EditCommunity";
export { EditCustomEmoji } from "./types/EditCustomEmoji";
export { EditPost } from "./types/EditPost";
export { EditPrivateMessage } from "./types/EditPrivateMessage";
export { EditSite } from "./types/EditSite";
export { FeaturePost } from "./types/FeaturePost";
export { FederatedInstances } from "./types/FederatedInstances";
export { FollowCommunity } from "./types/FollowCommunity";
export { GetBannedPersons } from "./types/GetBannedPersons";
export { GetCaptcha } from "./types/GetCaptcha";
export { GetCaptchaResponse } from "./types/GetCaptchaResponse";
export { GetComment } from "./types/GetComment";
export { GetComments } from "./types/GetComments";
export { GetCommentsResponse } from "./types/GetCommentsResponse";
export { GetCommunity } from "./types/GetCommunity";
export { GetCommunityResponse } from "./types/GetCommunityResponse";
export { GetFederatedInstances } from "./types/GetFederatedInstances";
export { GetFederatedInstancesResponse } from "./types/GetFederatedInstancesResponse";
export { GetModlog } from "./types/GetModlog";
export { GetModlogResponse } from "./types/GetModlogResponse";
export { GetPersonDetails } from "./types/GetPersonDetails";
export { GetPersonDetailsResponse } from "./types/GetPersonDetailsResponse";
export { GetPersonMentions } from "./types/GetPersonMentions";
export { GetPersonMentionsResponse } from "./types/GetPersonMentionsResponse";
export { GetPost } from "./types/GetPost";
export { GetPostResponse } from "./types/GetPostResponse";
export { GetPosts } from "./types/GetPosts";
export { GetPostsResponse } from "./types/GetPostsResponse";
export { GetPrivateMessages } from "./types/GetPrivateMessages";
export { GetReplies } from "./types/GetReplies";
export { GetRepliesResponse } from "./types/GetRepliesResponse";
export { GetReportCount } from "./types/GetReportCount";
export { GetReportCountResponse } from "./types/GetReportCountResponse";
export { GetSite } from "./types/GetSite";
export { GetSiteMetadata } from "./types/GetSiteMetadata";
export { GetSiteMetadataResponse } from "./types/GetSiteMetadataResponse";
export { GetSiteResponse } from "./types/GetSiteResponse";
export { GetUnreadCount } from "./types/GetUnreadCount";
export { GetUnreadCountResponse } from "./types/GetUnreadCountResponse";
export { GetUnreadRegistrationApplicationCount } from "./types/GetUnreadRegistrationApplicationCount";
export { GetUnreadRegistrationApplicationCountResponse } from "./types/GetUnreadRegistrationApplicationCountResponse";
export { HideCommunity } from "./types/HideCommunity";
export { Instance } from "./types/Instance";
export { InstanceId } from "./types/InstanceId";
export { Language } from "./types/Language";
export { LanguageId } from "./types/LanguageId";
export { LeaveAdmin } from "./types/LeaveAdmin";
export { ListCommentReports } from "./types/ListCommentReports";
export { ListCommentReportsResponse } from "./types/ListCommentReportsResponse";
export { ListCommunities } from "./types/ListCommunities";
export { ListCommunitiesResponse } from "./types/ListCommunitiesResponse";
export { ListPostReports } from "./types/ListPostReports";
export { ListPostReportsResponse } from "./types/ListPostReportsResponse";
export { ListPrivateMessageReports } from "./types/ListPrivateMessageReports";
export { ListPrivateMessageReportsResponse } from "./types/ListPrivateMessageReportsResponse";
export { ListRegistrationApplications } from "./types/ListRegistrationApplications";
export { ListRegistrationApplicationsResponse } from "./types/ListRegistrationApplicationsResponse";
export { ListingType } from "./types/ListingType";
export { LocalSite } from "./types/LocalSite";
export { LocalSiteId } from "./types/LocalSiteId";
export { LocalSiteRateLimit } from "./types/LocalSiteRateLimit";
export { LocalUser } from "./types/LocalUser";
export { LocalUserId } from "./types/LocalUserId";
export { LocalUserView } from "./types/LocalUserView";
export { LockPost } from "./types/LockPost";
export { Login } from "./types/Login";
export { LoginResponse } from "./types/LoginResponse";
export { MarkAllAsRead } from "./types/MarkAllAsRead";
export { MarkCommentReplyAsRead } from "./types/MarkCommentReplyAsRead";
export { MarkPersonMentionAsRead } from "./types/MarkPersonMentionAsRead";
export { MarkPostAsRead } from "./types/MarkPostAsRead";
export { MarkPrivateMessageAsRead } from "./types/MarkPrivateMessageAsRead";
export { ModAdd } from "./types/ModAdd";
export { ModAddCommunity } from "./types/ModAddCommunity";
export { ModAddCommunityView } from "./types/ModAddCommunityView";
export { ModAddView } from "./types/ModAddView";
export { ModBan } from "./types/ModBan";
export { ModBanFromCommunity } from "./types/ModBanFromCommunity";
export { ModBanFromCommunityView } from "./types/ModBanFromCommunityView";
export { ModBanView } from "./types/ModBanView";
export { ModFeaturePost } from "./types/ModFeaturePost";
export { ModFeaturePostView } from "./types/ModFeaturePostView";
export { ModHideCommunity } from "./types/ModHideCommunity";
export { ModHideCommunityView } from "./types/ModHideCommunityView";
export { ModJoin } from "./types/ModJoin";
export { ModJoinResponse } from "./types/ModJoinResponse";
export { ModLockPost } from "./types/ModLockPost";
export { ModLockPostView } from "./types/ModLockPostView";
export { ModRemoveComment } from "./types/ModRemoveComment";
export { ModRemoveCommentView } from "./types/ModRemoveCommentView";
export { ModRemoveCommunity } from "./types/ModRemoveCommunity";
export { ModRemoveCommunityView } from "./types/ModRemoveCommunityView";
export { ModRemovePost } from "./types/ModRemovePost";
export { ModRemovePostView } from "./types/ModRemovePostView";
export { ModTransferCommunity } from "./types/ModTransferCommunity";
export { ModTransferCommunityView } from "./types/ModTransferCommunityView";
export { ModlogActionType } from "./types/ModlogActionType";
export { ModlogListParams } from "./types/ModlogListParams";
export { MyUserInfo } from "./types/MyUserInfo";
export { PasswordChangeAfterReset } from "./types/PasswordChangeAfterReset";
export { PasswordReset } from "./types/PasswordReset";
export { PasswordResetResponse } from "./types/PasswordResetResponse";
export { Person } from "./types/Person";
export { PersonAggregates } from "./types/PersonAggregates";
export { PersonBlockId } from "./types/PersonBlockId";
export { PersonBlockView } from "./types/PersonBlockView";
export { PersonId } from "./types/PersonId";
export { PersonMention } from "./types/PersonMention";
export { PersonMentionId } from "./types/PersonMentionId";
export { PersonMentionResponse } from "./types/PersonMentionResponse";
export { PersonMentionView } from "./types/PersonMentionView";
export { PersonView } from "./types/PersonView";
export { Post } from "./types/Post";
export { PostAggregates } from "./types/PostAggregates";
export { PostFeatureType } from "./types/PostFeatureType";
export { PostId } from "./types/PostId";
export { PostJoin } from "./types/PostJoin";
export { PostJoinResponse } from "./types/PostJoinResponse";
export { PostOrCommentId } from "./types/PostOrCommentId";
export { PostReport } from "./types/PostReport";
export { PostReportId } from "./types/PostReportId";
export { PostReportResponse } from "./types/PostReportResponse";
export { PostReportView } from "./types/PostReportView";
export { PostResponse } from "./types/PostResponse";
export { PostView } from "./types/PostView";
export { PrivateMessage } from "./types/PrivateMessage";
export { PrivateMessageId } from "./types/PrivateMessageId";
export { PrivateMessageReport } from "./types/PrivateMessageReport";
export { PrivateMessageReportId } from "./types/PrivateMessageReportId";
export { PrivateMessageReportResponse } from "./types/PrivateMessageReportResponse";
export { PrivateMessageReportView } from "./types/PrivateMessageReportView";
export { PrivateMessageResponse } from "./types/PrivateMessageResponse";
export { PrivateMessageView } from "./types/PrivateMessageView";
export { PrivateMessagesResponse } from "./types/PrivateMessagesResponse";
export { PurgeComment } from "./types/PurgeComment";
export { PurgeCommunity } from "./types/PurgeCommunity";
export { PurgeItemResponse } from "./types/PurgeItemResponse";
export { PurgePerson } from "./types/PurgePerson";
export { PurgePost } from "./types/PurgePost";
export { Register } from "./types/Register";
export { RegistrationApplication } from "./types/RegistrationApplication";
export { RegistrationApplicationResponse } from "./types/RegistrationApplicationResponse";
export { RegistrationApplicationView } from "./types/RegistrationApplicationView";
export { RegistrationMode } from "./types/RegistrationMode";
export { RemoveComment } from "./types/RemoveComment";
export { RemoveCommunity } from "./types/RemoveCommunity";
export { RemovePost } from "./types/RemovePost";
export { ResolveCommentReport } from "./types/ResolveCommentReport";
export { ResolveObject } from "./types/ResolveObject";
export { ResolveObjectResponse } from "./types/ResolveObjectResponse";
export { ResolvePostReport } from "./types/ResolvePostReport";
export { ResolvePrivateMessageReport } from "./types/ResolvePrivateMessageReport";
export { SaveComment } from "./types/SaveComment";
export { SavePost } from "./types/SavePost";
export { SaveUserSettings } from "./types/SaveUserSettings";
export { Search } from "./types/Search";
export { SearchResponse } from "./types/SearchResponse";
export { SearchType } from "./types/SearchType";
export { Site } from "./types/Site";
export { SiteAggregates } from "./types/SiteAggregates";
export { SiteId } from "./types/SiteId";
export { SiteMetadata } from "./types/SiteMetadata";
export { SiteResponse } from "./types/SiteResponse";
export { SiteView } from "./types/SiteView";
export { SortType } from "./types/SortType";
export { SubscribedType } from "./types/SubscribedType";
export { Tagline } from "./types/Tagline";
export { TransferCommunity } from "./types/TransferCommunity";
export { UserJoin } from "./types/UserJoin";
export { UserJoinResponse } from "./types/UserJoinResponse";
export { VerifyEmail } from "./types/VerifyEmail";
export { VerifyEmailResponse } from "./types/VerifyEmailResponse";
export {
ImageFile,
UploadImage,
UploadImageResponse,
UserOperation,
} from "./types/others";
export * from "./websocket"; export * from "./websocket";