From 80fd2bb11d30eaa2c6d779705f2790ee8bed8973 Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Sat, 25 Jul 2020 18:45:03 +0200 Subject: [PATCH 1/2] add initial TS types detection based on package.json content --- components/Filters.tsx | 7 ++++++ components/Icons/index.tsx | 12 ++++++++++ components/Library/MetaData.tsx | 9 +++++++- pages/api/libraries/index.ts | 1 + scripts/fetch-github-data.js | 39 +++++++++++++++++++-------------- types/index.ts | 8 +++++++ util/search.js | 5 +++++ 7 files changed, 64 insertions(+), 17 deletions(-) diff --git a/components/Filters.tsx b/components/Filters.tsx index 581c0cec..9eea9b4b 100644 --- a/components/Filters.tsx +++ b/components/Filters.tsx @@ -71,6 +71,7 @@ export const FilterButton = (props: FilterButtonProps) => { ...platforms.map(platform => platform.param), 'hasExample', 'hasImage', + 'hasTypes', 'isMaintained', 'isPopular', 'isRecommended', @@ -149,6 +150,12 @@ export const Filters = (props: FiltersProps) => { paramName="hasImage" title="Has image preview" /> + ); } + +export function TypeScript(props: Props) { + const { width = 16, height = 16, fill = colors.black } = props; + return ( + + + + ); +} diff --git a/components/Library/MetaData.tsx b/components/Library/MetaData.tsx index 541ec775..30a91dab 100644 --- a/components/Library/MetaData.tsx +++ b/components/Library/MetaData.tsx @@ -5,7 +5,7 @@ import { colors, A, P, Caption, darkColors } from '../../common/styleguide'; import CustomAppearanceContext from '../../context/CustomAppearanceContext'; import { Library as LibraryType } from '../../types'; import { getTimeSinceToday } from '../../util/datetime'; -import { Calendar, Star, Download, Issue, Web, License, Fork, Code } from '../Icons'; +import { Calendar, Star, Download, Issue, Web, License, Fork, Code, TypeScript } from '../Icons'; import { DirectoryScore } from './DirectoryScore'; type Props = { @@ -54,6 +54,13 @@ const generateData = (library, secondary, isDark) => { ), } : null, + github.hasTypes + ? { + id: 'types', + icon: , + content:

TypeScript Types

, + } + : null, library.examples && library.examples.length ? { id: 'examples', diff --git a/pages/api/libraries/index.ts b/pages/api/libraries/index.ts index fd8dc766..769ead43 100644 --- a/pages/api/libraries/index.ts +++ b/pages/api/libraries/index.ts @@ -53,6 +53,7 @@ function handler(req: NextApiRequest, res: NextApiResponse) { }, hasExample: req.query.hasExample, hasImage: req.query.hasImage, + hasTypes: req.query.hasTypes, isMaintained: req.query.isMaintained, isPopular: req.query.isPopular, isRecommended: req.query.isRecommended, diff --git a/scripts/fetch-github-data.js b/scripts/fetch-github-data.js index 1cccccad..9464608e 100644 --- a/scripts/fetch-github-data.js +++ b/scripts/fetch-github-data.js @@ -225,29 +225,35 @@ const getLicenseFromPackageJson = packageJson => { }; const createRepoDataWithResponse = (json, monorepo) => { - if (monorepo && json.packageJson) { + if (json.packageJson) { const packageJson = JSON.parse(json.packageJson.text); - json.homepageUrl = packageJson.homepage; - json.name = packageJson.name; - json.topics = packageJson.keywords; - json.description = packageJson.description; - json.licenseInfo = getLicenseFromPackageJson(packageJson); - } - - if (!monorepo && json.packageJson) { - const packageJson = JSON.parse(json.packageJson.text); - json.topics = json.repositoryTopics.nodes.map(({ topic }) => topic.name); - if (!json.description) { + if (monorepo) { + json.homepageUrl = packageJson.homepage; + json.name = packageJson.name; + json.topics = packageJson.keywords; json.description = packageJson.description; + json.licenseInfo = getLicenseFromPackageJson(packageJson); } - if (json.topics.length === 0) { - json.topics = packageJson.keywords; + if (!monorepo) { + json.topics = json.repositoryTopics.nodes.map(({ topic }) => topic.name); + + if (!json.description) { + json.description = packageJson.description; + } + + if (json.topics.length === 0) { + json.topics = packageJson.keywords; + } + + if (!json.licenseInfo || (json.licenseInfo && json.licenseInfo.key === 'other')) { + json.licenseInfo = getLicenseFromPackageJson(packageJson) || json.licenseInfo; + } } - if (!json.licenseInfo || (json.licenseInfo && json.licenseInfo.key === 'other')) { - json.licenseInfo = getLicenseFromPackageJson(packageJson) || json.licenseInfo; + if (packageJson.types || packageJson.typings) { + json.types = true; } } @@ -289,5 +295,6 @@ const createRepoDataWithResponse = (json, monorepo) => { topics, license: json.licenseInfo, lastRelease: json.lastRelease, + hasTypes: json.types, }; }; diff --git a/types/index.ts b/types/index.ts index 58dc1482..20e088f6 100644 --- a/types/index.ts +++ b/types/index.ts @@ -49,6 +49,14 @@ export type Library = { url: string; id: string; }; + lastRelease: { + name: string; + tagName: string; + createdAt: Date; + publishedAt: Date; + isPrerelease: boolean; + }; + hasTypes: boolean; }; images: string[]; npmPkg: string; diff --git a/util/search.js b/util/search.js index 9bc24a14..ab1a9ae8 100644 --- a/util/search.js +++ b/util/search.js @@ -7,6 +7,7 @@ export const handleFilterLibraries = ({ support, hasExample, hasImage, + hasTypes, isMaintained, isPopular, isRecommended, @@ -55,6 +56,10 @@ export const handleFilterLibraries = ({ return false; } + if (hasTypes && !library.github.hasTypes) { + return false; + } + if (isMaintained && library.unmaintained) { return false; } From 6da9446df782fac166fa281aa446f36ed98210b0 Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Sat, 25 Jul 2020 19:03:31 +0200 Subject: [PATCH 2/2] add missing Query TS types --- types/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/types/index.ts b/types/index.ts index 20e088f6..8dab5ed1 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,11 +1,20 @@ export type Query = { - ios?: string; - expo?: string; android?: string; + expo?: string; + ios?: string; + macos?: string; web?: string; + windows?: string; order?: 'quality' | 'recommended' | 'issues' | 'downloads' | 'stars'; search?: string; offset?: string; + hasExample?: string; + hasImage?: string; + hasTypes?: string; + isMaintained?: string; + isPopular?: string; + isRecommended?: string; + wasRecentlyUpdated?: string; }; export type Library = {