1- import { existsSync , readFileSync , writeFileSync } from 'fs' ;
1+ import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'fs' ;
22import path from 'path' ;
33import { Task , TaskOutput } from './Task' ;
4+ import { createHash } from 'crypto' ;
45
56export interface ManifestTaskOutput extends TaskOutput {
67 taskName : 'ConvertManifest' ;
@@ -10,11 +11,12 @@ export interface ManifestTaskOutput extends TaskOutput {
1011 */
1112export function convertManifest ( dataDir : string , verbose : number ) {
1213 const srcFile = path . join ( dataDir , 'manifest.json' ) ;
13- const dstFile = path . join ( 'static' , 'manifest.json' ) ;
14- if ( existsSync ( srcFile ) ) {
14+ let contents = '' ;
15+ const existing = existsSync ( srcFile ) ;
16+ if ( existing ) {
1517 const fileContents = readFileSync ( srcFile ) . toString ( ) ;
1618 const lines = fileContents . split ( '\n' ) ;
17- const updatedFileContents = lines
19+ contents = lines
1820 . map ( ( line ) => {
1921 if ( line . includes ( 'start_url' ) ) {
2022 const path = process . env . BUILD_BASE_PATH ? process . env . BUILD_BASE_PATH : '.' ;
@@ -27,8 +29,6 @@ export function convertManifest(dataDir: string, verbose: number) {
2729 return line ;
2830 } )
2931 . join ( '\n' ) ;
30- writeFileSync ( dstFile , updatedFileContents ) ;
31- if ( verbose ) console . log ( `converted ${ srcFile } to ${ dstFile } ` ) ;
3232 } else {
3333 // If no manifest exists, we need to at least have a minimum manifest to build.
3434 const manifest = {
@@ -38,8 +38,22 @@ export function convertManifest(dataDir: string, verbose: number) {
3838 background_color : '#000000' ,
3939 theme_color : '#000000'
4040 } ;
41- writeFileSync ( dstFile , JSON . stringify ( manifest ) ) ;
41+ contents = JSON . stringify ( manifest ) ;
4242 }
43+
44+ const hash = createHash ( 'md5' ) ;
45+ hash . update ( contents ) ;
46+ const digest = hash . digest ( 'base64url' ) ;
47+
48+ const name = `manifest.${ digest } .json` ;
49+
50+ const dstFile = path . join ( 'static' , name ) ;
51+
52+ writeFileSync ( dstFile , contents ) ;
53+ if ( verbose && existing ) console . log ( `converted ${ srcFile } to ${ dstFile } ` ) ;
54+
55+ mkdirSync ( path . join ( 'src' , 'generatedAssets' ) , { recursive : true } ) ;
56+ writeFileSync ( path . join ( 'src/generatedAssets' , 'manifestUrl.json' ) , JSON . stringify ( { url : name } ) ) ;
4357}
4458export class ConvertManifest extends Task {
4559 public triggerFiles : string [ ] = [ 'manifest.json' ] ;
0 commit comments