@@ -23,6 +23,9 @@ type npmPackage = {
2323 description : string ,
2424 repositoryHref : Js .Null .t <string >,
2525 npmHref : string ,
26+ searchScore : float ,
27+ maintenanceScore : float ,
28+ score : {"final" : float , "detail" : {"quality" : float , "popularity" : float , "maintenance" : float }},
2629}
2730
2831module Resource = {
@@ -94,7 +97,20 @@ module Resource = {
9497
9598 let fuser = Fuse .make (packages , fuseOpts )
9699
97- fuser -> Fuse .search (pattern )
100+ let t =
101+ fuser
102+ -> Fuse .search (pattern )
103+ -> Js .Array2 .map (t => {
104+ if t ["item" ].name === "reson" || t ["item" ].name === "rescript-json-schema" {
105+ Js .Console .log (t )
106+ t
107+ } else {
108+ t
109+ }
110+ })
111+ -> Js .Array2 .sortInPlaceWith ((a , b ) => a ["item" ].searchScore < b ["item" ].searchScore ? - 1 : 1 )
112+
113+ t
98114 }
99115
100116 let applyUrlResourceSearch = (urls : array <urlResource >, pattern : string ): array <
@@ -505,6 +521,11 @@ let default = (props: props) => {
505521
506522type npmData = {
507523 "objects" : array <{
524+ "searchScore" : float ,
525+ "score" : {
526+ "final" : float ,
527+ "detail" : {"quality" : float , "popularity" : float , "maintenance" : float },
528+ },
508529 "package" : {
509530 "name" : string ,
510531 "keywords" : array <string >,
@@ -522,14 +543,8 @@ module Response = {
522543
523544@val external fetchNpmPackages : string => promise <Response .t > = "fetch"
524545
525- let getStaticProps : Next .GetStaticProps .revalidate <props , unit > = async _ctx => {
526- let response = await fetchNpmPackages (
527- "https://registry.npmjs.org/-/v1/search?text=keywords:rescript&size=250" ,
528- )
529-
530- let data = await response -> Response .json
531-
532- let pkges = Belt .Array .map (data ["objects" ], item => {
546+ let parsePkgs = data =>
547+ Belt .Array .map (data ["objects" ], item => {
533548 let pkg = item ["package" ]
534549 {
535550 name : pkg ["name" ],
@@ -538,9 +553,48 @@ let getStaticProps: Next.GetStaticProps.revalidate<props, unit> = async _ctx =>
538553 description : Belt .Option .getWithDefault (pkg ["description" ], "" ),
539554 repositoryHref : Js .Null .fromOption (pkg ["links" ]["repository" ]),
540555 npmHref : pkg ["links" ]["npm" ],
556+ searchScore : item ["searchScore" ],
557+ maintenanceScore : item ["score" ]["detail" ]["maintenance" ],
558+ score : item ["score" ],
541559 }
542560 })
543561
562+ let getStaticProps : Next .GetStaticProps .revalidate <props , unit > = async _ctx => {
563+ let (one , two , three ) = await Js .Promise2 .all3 ((
564+ fetchNpmPackages (
565+ "https://registry.npmjs.org/-/v1/search?text=keywords:rescript&size=250&maintenance=1.0&popularity=0.7&quality=0.1" ,
566+ ),
567+ fetchNpmPackages (
568+ "https://registry.npmjs.org/-/v1/search?text=keywords:rescript&size=250&maintenance=1.0&popularity=0.7&quality=0.1&from=250" ,
569+ ),
570+ fetchNpmPackages (
571+ "https://registry.npmjs.org/-/v1/search?text=keywords:rescript&size=250&maintenance=1.0&popularity=0.7&quality=0.1&from=500" ,
572+ ),
573+ ))
574+
575+ let (data1 , data2 , data3 ) = await Js .Promise2 .all3 ((
576+ one -> Response .json ,
577+ two -> Response .json ,
578+ three -> Response .json ,
579+ ))
580+
581+ let unmaintained = []
582+
583+ let pkges =
584+ parsePkgs (data1 )
585+ -> Js .Array2 .concat (parsePkgs (data2 ))
586+ -> Js .Array2 .concat (parsePkgs (data3 ))
587+ -> Js .Array2 .filter (pkg => {
588+ if pkg .maintenanceScore < 0.03 {
589+ false
590+ } else {
591+ true
592+ }
593+ })
594+
595+ Js .Console .log2 ("Number of packages" , pkges -> Js .Array2 .length )
596+ Js .Console .log2 ("Number of unmaintained" , unmaintained -> Js .Array2 .length )
597+
544598 let index_data_dir = Node .Path .join2 (Node .Process .cwd (), "./data" )
545599 let urlResources =
546600 Node .Path .join2 (index_data_dir , "packages_url_resources.json" )
0 commit comments