import * as vscode from 'vscode' ; import * as path from 'path' ; import { readFileSync } from 'fs' ; import { PackageInfo } from './packageinfo' ; import { Version } from './version' ; import { GlobalStorage } from '../globalstorage' ; export class WhatsNewView { protected vscodePanel : vscode . WebviewPanel ; param context return public static updateVersion ( context ) { const versionId = 'version' ; const previousVersion = GlobalStorage . Get < string > ( versionId ) ! ; const currentVersion = PackageInfo . extension . packageJSON . version ; if ( currentVersion != previousVersion ) GlobalStorage . Set ( versionId , currentVersion ) ; const isNewer = Version . isNewVersion ( currentVersion , previousVersion ) ; return isNewer ; } param title param text constructor ( ) { this . vscodePanel = vscode . window . createWebviewPanel ( '' , '' , { preserveFocus : true , viewColumn : vscode . ViewColumn . Nine } ) ; this . vscodePanel . title = "Whats New" ; this . setHtml ( ) ; } /**
     * Returns the html code to display the whats web html.
     */ public setHtml ( ) { if ( ! this . vscodePanel . webview ) return ; const extPath = PackageInfo . extension . extensionPath ; const mainHtmlFile = path . join ( extPath , 'html/whatsnew.html' ) ; let html = readFileSync ( mainHtmlFile ) . toString ( ) ; const resourcePath = vscode . Uri . file ( extPath ) ; const vscodeResPath = this . vscodePanel . webview . asWebviewUri ( resourcePath ) . toString ( ) ; html = html . replace ( '${vscodeResPath}' , vscodeResPath ) ; html = html . replace ( /\${extensionName}/g , PackageInfo . extension . packageJSON . id ) ; const versArray = PackageInfo . extension . packageJSON . version . split ( '.' ) ; let mainVersion = versArray . shift ( ) || '' ; const vPart2 = versArray . shift ( ) ; if ( vPart2 ) mainVersion += '.' + vPart2 ; html = html . replace ( /\${extensionMainVersion}/g , mainVersion ) ; html = html . replace ( /\${extensionDisplayName}/g , PackageInfo . extension . packageJSON . displayName ) ; html = html . replace ( /\${repositoryUrl}/g , PackageInfo . extension . packageJSON . repository . url ) ; html = html . replace ( /\${repositoryIssues}/g , PackageInfo . extension . packageJSON . bugs . url ) ; html = html . replace ( /\${repositoryHomepage}/g , PackageInfo . extension . packageJSON . repository . url ) ; const changeLogFile = path . join ( extPath , 'html/whatsnew_changelog.html' ) ; const changeLogHtml = readFileSync ( changeLogFile ) . toString ( ) ; html = html . replace ( '${changeLog}' , changeLogHtml ) ; this . vscodePanel . webview . html = html ; } }