@@ -23,6 +23,9 @@ type npmPackage = {
23
23
description : string ,
24
24
repositoryHref : Js .Null .t <string >,
25
25
npmHref : string ,
26
+ searchScore : float ,
27
+ maintenanceScore : float ,
28
+ score : {"final" : float , "detail" : {"quality" : float , "popularity" : float , "maintenance" : float }},
26
29
}
27
30
28
31
module Resource = {
@@ -94,7 +97,20 @@ module Resource = {
94
97
95
98
let fuser = Fuse .make (packages , fuseOpts )
96
99
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
98
114
}
99
115
100
116
let applyUrlResourceSearch = (urls : array <urlResource >, pattern : string ): array <
@@ -505,6 +521,11 @@ let default = (props: props) => {
505
521
506
522
type npmData = {
507
523
"objects" : array <{
524
+ "searchScore" : float ,
525
+ "score" : {
526
+ "final" : float ,
527
+ "detail" : {"quality" : float , "popularity" : float , "maintenance" : float },
528
+ },
508
529
"package" : {
509
530
"name" : string ,
510
531
"keywords" : array <string >,
@@ -522,14 +543,8 @@ module Response = {
522
543
523
544
@val external fetchNpmPackages : string => promise <Response .t > = "fetch"
524
545
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 => {
533
548
let pkg = item ["package" ]
534
549
{
535
550
name : pkg ["name" ],
@@ -538,9 +553,48 @@ let getStaticProps: Next.GetStaticProps.revalidate<props, unit> = async _ctx =>
538
553
description : Belt .Option .getWithDefault (pkg ["description" ], "" ),
539
554
repositoryHref : Js .Null .fromOption (pkg ["links" ]["repository" ]),
540
555
npmHref : pkg ["links" ]["npm" ],
556
+ searchScore : item ["searchScore" ],
557
+ maintenanceScore : item ["score" ]["detail" ]["maintenance" ],
558
+ score : item ["score" ],
541
559
}
542
560
})
543
561
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
+
544
598
let index_data_dir = Node .Path .join2 (Node .Process .cwd (), "./data" )
545
599
let urlResources =
546
600
Node .Path .join2 (index_data_dir , "packages_url_resources.json" )
0 commit comments