import * as fs from "fs" ; import { ChangeLogItem , ChangeLogKind , Header , Sponsor } from "./ContentProvider" ; export class WhatsNewPageBuilder { public static newBuilder ( htmlFile ) { return new WhatsNewPageBuilder ( htmlFile ) ; } private htmlFile : string ; constructor ( htmlFile ) { this . htmlFile = fs . readFileSync ( htmlFile ) . toString ( ) ; } public updateExtensionDisplayName ( extensionDisplayName ) { this . htmlFile = this . htmlFile . replace ( /\$\{extensionDisplayName\}/g , extensionDisplayName ) ; return this ; } public updateExtensionName ( extensionName ) { this . htmlFile = this . htmlFile . replace ( /\$\{extensionName\}/g , extensionName ) ; return this ; } public updateExtensionVersion ( extensionVersion ) { this . htmlFile = this . htmlFile . replace ( "${extensionVersion}" , extensionVersion ) ; return this ; } public updateRepositoryUrl ( repositoryUrl ) { this . htmlFile = this . htmlFile . replace ( /\$\{repositoryUrl\}/g , repositoryUrl ) ; return this ; } public updateRepositoryIssues ( repositoryIssues ) { this . htmlFile = this . htmlFile . replace ( "${repositoryIssues}" , repositoryIssues ) ; return this ; } public updateRepositoryHomepage ( repositoryHomepage ) { this . htmlFile = this . htmlFile . replace ( "${repositoryHomepage}" , repositoryHomepage ) ; return this ; } public updateCSS ( cssUrl ) { this . htmlFile = this . htmlFile . replace ( "${cssUrl}" , cssUrl ) ; return this ; } public updateHeader ( header ) { this . htmlFile = this . htmlFile . replace ( "${headerLogo}" , header . logo . src ) ; this . htmlFile = this . htmlFile . replace ( "${headerWidth}" , header . logo . width . toString ( ) ) ; this . htmlFile = this . htmlFile . replace ( "${headerHeight}" , header . logo . height . toString ( ) ) ; this . htmlFile = this . htmlFile . replace ( "${headerMessage}" , header . message ) ; this . htmlFile = this . htmlFile . replace ( "${noticeMessage}" , header . notice ) ; return this ; } public updateChangeLog ( changeLog ) { let changeLogString = "" ; for ( const cl of changeLog ) { const badge = this . getBadgeFromChangeLogKind ( cl . kind ) ; changeLogString = changeLogString . concat ( `<li><span class="changelog__badge changelog__badge--${ badge }">${ cl . kind }</span>
                    ${ cl . message }
                </li>` ) ; } this . htmlFile = this . htmlFile . replace ( "${changeLog}" , changeLogString ) ; return this ; } public updateSponsors ( sponsors ) { if ( sponsors . length === 0 ) { this . htmlFile = this . htmlFile . replace ( "${sponsors}" , "" ) ; return this ; } let sponsorsString = `<p>
          <h2>Sponsors</h2>` ; for ( const sp of sponsors ) { sponsorsString = sponsorsString . concat ( `<a title="${ sp . title }" href="${ sp . link }">
                    <img src="${ sp . image }" width="${ sp . width }%"/>
                </a>
                ${ sp . message } 
                ${ sp . extra }` ) ; } sponsorsString = sponsorsString . concat ( "</p>" ) ; this . htmlFile = this . htmlFile . replace ( "${sponsors}" , sponsorsString ) ; return this ; } public build ( ) { return this . htmlFile . toString ( ) ; } private getBadgeFromChangeLogKind ( kind ) { switch ( kind ) { case ChangeLogKind . NEW : return "added" ; case ChangeLogKind . CHANGED : return "changed" ; case ChangeLogKind . FIXED : return "fixed" ; default : break ; } } }