1
+ import { Link } from 'react-router-dom' ;
1
2
import * as React from 'react' ;
2
3
import * as Registration from './Registration' ;
3
4
5
+ import './Dependencies.css' ;
6
+
4
7
interface IDependenciesProps {
5
8
dependencyGroups : Registration . IDependencyGroup [ ] ;
6
9
}
@@ -11,14 +14,60 @@ interface IPackageDependenciesProps {
11
14
12
15
class Dependencies extends React . Component < IDependenciesProps > {
13
16
14
- constructor ( props : IDependenciesProps ) {
15
- props . dependencyGroups . forEach ( group => {
16
- if ( ! group . dependencies ) {
17
- group . dependencies = [ ] ;
18
- }
19
- } ) ;
17
+ static readonly netFrameworkRegex : RegExp = / n e t [ 0 - 9 ] { 2 , 3 } $ / ;
18
+ static readonly netCoreRegex : RegExp = / n e t c o r e a p p [ 0 - 9 ] .[ 0 - 9 ] $ / ;
19
+ static readonly netStandardRegex : RegExp = / n e t s t a n d a r d [ 0 - 9 ] .[ 0 - 9 ] $ / ;
20
+ static readonly versionRangeRegex : RegExp = / \[ [ 0 - 9 ] ( .[ 0 - 9 ] ) * , \) $ / ;
20
21
22
+ constructor ( props : IDependenciesProps ) {
21
23
super ( props ) ;
24
+
25
+ props . dependencyGroups . forEach ( Dependencies . prettifyDependencyGroup ) ;
26
+ }
27
+
28
+ private static prettifyDependencyGroup ( group : Registration . IDependencyGroup ) {
29
+ if ( ! group . dependencies ) {
30
+ group . dependencies = [ ] ;
31
+ }
32
+
33
+ Dependencies . prettifyTargetFramework ( group ) ;
34
+
35
+ if ( group . dependencies !== undefined ) {
36
+ group . dependencies . forEach ( Dependencies . prettifyDepency ) ;
37
+ }
38
+ }
39
+
40
+ private static prettifyTargetFramework ( group : Registration . IDependencyGroup ) {
41
+ // This uses heuristics and may produce incorrect results.
42
+ // This ignores portable class libraries.
43
+ if ( Dependencies . netFrameworkRegex . test ( group . targetFramework ) ) {
44
+ const version = group . targetFramework . substring ( "net" . length ) ;
45
+ const prettyVersion = version . length == 2
46
+ ? `${ version [ 0 ] } .${ version [ 1 ] } `
47
+ : `${ version [ 0 ] } .${ version [ 1 ] } .${ version [ 2 ] } ` ;
48
+
49
+ group . targetFramework = `.NET Framework ${ prettyVersion } ` ;
50
+ return ;
51
+ }
52
+
53
+ if ( Dependencies . netCoreRegex . test ( group . targetFramework ) ) {
54
+ const version = group . targetFramework . substring ( "netcoreapp" . length ) ;
55
+ group . targetFramework = `.NET Core ${ version } ` ;
56
+ return ;
57
+ }
58
+
59
+ if ( Dependencies . netStandardRegex . test ( group . targetFramework ) ) {
60
+ const version = group . targetFramework . substring ( "netstandard" . length ) ;
61
+ group . targetFramework = `.NET Standard ${ version } ` ;
62
+ return ;
63
+ }
64
+ }
65
+
66
+ private static prettifyDepency ( dependency : Registration . IDependency ) {
67
+ // This uses heuristics and may produce incorrect results.
68
+ if ( Dependencies . versionRangeRegex . test ( dependency . range ) ) {
69
+ dependency . range = `(>= ${ dependency . range . slice ( 1 , - 3 ) } )` ;
70
+ }
22
71
}
23
72
24
73
public render ( ) {
@@ -36,10 +85,12 @@ class Dependencies extends React.Component<IDependenciesProps> {
36
85
< div >
37
86
< h3 > Dependencies</ h3 >
38
87
39
- < div >
88
+ < div className = "dependency-groups" >
40
89
{ this . props . dependencyGroups . map ( group => (
41
90
< div key = { group . targetFramework } >
42
- < h4 > { group . targetFramework } </ h4 >
91
+ < h4 >
92
+ < span > { group . targetFramework } </ span >
93
+ </ h4 >
43
94
44
95
< PackageDependencies dependencies = { group . dependencies } />
45
96
</ div >
@@ -59,10 +110,12 @@ class PackageDependencies extends React.Component<IPackageDependenciesProps> {
59
110
}
60
111
61
112
return (
62
- < ul >
113
+ < ul className = "list-unstyled dependency-group" >
63
114
{ this . props . dependencies . map ( dependency => (
64
115
< li key = { dependency . id } >
65
- { dependency . id } { dependency . range }
116
+ < Link to = { `/packages/${ dependency . id } ` } > { dependency . id } </ Link >
117
+
118
+ < span > { dependency . range } </ span >
66
119
</ li >
67
120
) ) }
68
121
</ ul >
0 commit comments