@@ -3,6 +3,8 @@ import * as fs from 'fs';
3
3
import * as fsPath from 'path' ;
4
4
import * as mimeTypes from 'mime-types' ;
5
5
6
+ import { branchToHostnameToken } from './server' ;
7
+
6
8
const walk = function ( path : string , newFiles ?: string [ ] ) {
7
9
let files = newFiles || [ ] ;
8
10
fs . readdirSync ( path ) . forEach ( file => {
@@ -34,13 +36,20 @@ export interface Redirect {
34
36
interface GitAuthor {
35
37
email : string ;
36
38
name : string ;
39
+ timestamp : number ;
37
40
}
38
41
39
42
export interface Commit {
40
43
message : string ;
41
44
author : GitAuthor ;
42
45
}
43
46
47
+ export interface ManifestUrls {
48
+ stagingBranch : string ;
49
+ stagingSha : string ;
50
+ ui : string ;
51
+ }
52
+
44
53
export interface SerializedManifest {
45
54
site : string ;
46
55
ref : string ;
@@ -66,8 +75,15 @@ export class Manifest {
66
75
localizationPathFormat : string ;
67
76
headers : Record < string , Record < string , string > > ;
68
77
commit : Commit ;
69
-
70
- constructor ( site : string , ref : string , branch : string , commit : Commit ) {
78
+ googleCloudProject : string ;
79
+
80
+ constructor (
81
+ site : string ,
82
+ ref : string ,
83
+ branch : string ,
84
+ commit : Commit ,
85
+ googleCloudProject : string
86
+ ) {
71
87
this . files = [ ] ;
72
88
this . redirects = [ ] ;
73
89
this . site = site ;
@@ -78,6 +94,7 @@ export class Manifest {
78
94
this . localizationPathFormat = DEFAULT_LOCALIZATION_PATH_FORMAT ;
79
95
this . headers = { } ;
80
96
this . commit = commit ;
97
+ this . googleCloudProject = googleCloudProject ;
81
98
}
82
99
83
100
async createFromDirectory ( path : string ) {
@@ -136,4 +153,32 @@ export class Manifest {
136
153
} ) ;
137
154
return pathsToHashes ;
138
155
}
156
+
157
+ toOutputJSON ( ) {
158
+ return {
159
+ urls : this . urls ,
160
+ files : this . files ,
161
+ commit : this . commit ,
162
+ } ;
163
+ }
164
+
165
+ get urls ( ) : ManifestUrls {
166
+ // TODO: Allow customizing the staging URL using `fileset.yaml` configuration.
167
+ const hostnameSuffix = `fileset-dot-${ this . googleCloudProject } .appspot.com` ;
168
+ const stagingShaUrl =
169
+ this . site === 'default'
170
+ ? `https://${ this . shortSha } -dot-${ hostnameSuffix } `
171
+ : `https://${ this . site } -${ this . shortSha } -dot-${ hostnameSuffix } ` ;
172
+ const branchToken = branchToHostnameToken ( this . branch ) ;
173
+ const stagingBranchUrl =
174
+ this . site === 'default'
175
+ ? `https://${ branchToken } -dot-${ hostnameSuffix } `
176
+ : `https://${ this . site } -${ branchToken } -dot-${ hostnameSuffix } ` ;
177
+ const uiUrl = `https://${ hostnameSuffix } /fileset/sites/${ this . site } /${ this . shortSha } ` ;
178
+ return {
179
+ stagingBranch : stagingBranchUrl ,
180
+ stagingSha : stagingShaUrl ,
181
+ ui : uiUrl ,
182
+ } ;
183
+ }
139
184
}
0 commit comments