@@ -23,6 +23,12 @@ export interface ManifestFile {
23
23
cleanPath : string ;
24
24
}
25
25
26
+ export interface Redirect {
27
+ from : string ;
28
+ to : string ;
29
+ permanent ?: boolean ;
30
+ }
31
+
26
32
export interface PathToHash {
27
33
path ?: string ;
28
34
}
@@ -32,10 +38,12 @@ export class Manifest {
32
38
ref : string ;
33
39
branch ?: string ;
34
40
files : ManifestFile [ ] ;
41
+ redirects : Redirect [ ] ;
35
42
shortSha : string ;
36
43
37
44
constructor ( site : string , ref : string , branch ?: string ) {
38
45
this . files = [ ] ;
46
+ this . redirects = [ ] ;
39
47
this . site = site ;
40
48
this . ref = ref ;
41
49
this . shortSha = ref . slice ( 0 , 7 ) ;
@@ -49,6 +57,10 @@ export class Manifest {
49
57
} ) ;
50
58
}
51
59
60
+ setRedirects ( redirects : Redirect [ ] ) {
61
+ this . redirects = redirects ;
62
+ }
63
+
52
64
createHash ( path : string ) {
53
65
const contents = fs . readFileSync ( path ) ;
54
66
const hash = crypto . createHash ( 'sha1' ) ;
@@ -60,7 +72,9 @@ export class Manifest {
60
72
61
73
async addFile ( path : string , dir : string ) {
62
74
const hash = this . createHash ( path ) ;
63
- const cleanPath = path . replace ( dir . replace ( / ^ \\ + | \\ + $ / g, '' ) , '/' ) . replace ( '//' , '/' ) ;
75
+ const cleanPath = path
76
+ . replace ( dir . replace ( / ^ \\ + | \\ + $ / g, '' ) , '/' )
77
+ . replace ( '//' , '/' ) ;
64
78
const manifestFile : ManifestFile = {
65
79
cleanPath : cleanPath ,
66
80
hash : hash ,
@@ -70,7 +84,16 @@ export class Manifest {
70
84
this . files . push ( manifestFile ) ;
71
85
}
72
86
73
- toJSON ( ) {
87
+ async addRedirect ( from : string , to : string , permanent : boolean ) {
88
+ const redirect : Redirect = {
89
+ from : from ,
90
+ to : to ,
91
+ permanent : permanent ,
92
+ } ;
93
+ this . redirects . push ( redirect ) ;
94
+ }
95
+
96
+ pathsToJSON ( ) {
74
97
const pathsToHashes : any = { } ;
75
98
this . files . forEach ( file => {
76
99
pathsToHashes [ file . cleanPath ] = file . hash ;
0 commit comments