44 *--------------------------------------------------------------------------------------------*/
55
66import * as fse from 'fs-extra' ;
7- import * as path from 'path' ;
8- import { l10n } from 'vscode' ;
9- import * as xml2js from 'xml2js' ;
10- import { getNetCoreProjectInfo } from '../../utils/netCoreUtils' ;
7+ import * as vscode from 'vscode' ;
8+ import { getBlazorManifestInfo } from '../../utils/netCoreUtils' ;
119import { pathNormalize } from '../../utils/pathNormalize' ;
1210import { PlatformOS } from '../../utils/platform' ;
1311import { DockerContainerVolume } from '../DockerRunTaskDefinitionBase' ;
1412import { DockerRunTaskDefinition } from "../DockerRunTaskProvider" ;
1513import { DockerRunTaskContext } from "../TaskHelper" ;
1614
17- interface ContentRootAttributes {
18- BasePath : string ;
19- Path : string ;
20- }
21-
22- interface ContentRoot {
23- $ : ContentRootAttributes ;
24- }
25-
26- interface StaticWebAssets {
27- ContentRoot : ContentRoot [ ] ;
28- }
29-
30- interface XmlManifest {
31- StaticWebAssets : StaticWebAssets ;
32- }
33-
3415interface JsonManifest {
3516 ContentRoots : string [ ] ;
3617}
3718
3819export async function updateBlazorManifest ( context : DockerRunTaskContext , runDefinition : DockerRunTaskDefinition ) : Promise < void > {
39- const contents = await getNetCoreProjectInfo ( 'GetBlazorManifestLocations' , runDefinition . netCore . appProject ) ;
40-
41- if ( contents . length < 2 ) {
42- throw new Error ( l10n . t ( 'Unable to determine Blazor manifest locations from output file.' ) ) ;
43- }
44-
45- await transformBlazorManifest ( context , contents [ 0 ] . trim ( ) , contents [ 1 ] . trim ( ) , runDefinition . dockerRun . volumes , runDefinition . dockerRun . os ) ;
20+ const blazorInfo = await getBlazorManifestInfo ( runDefinition . netCore . appProject ) ;
21+ await transformBlazorManifest ( context , blazorInfo . inputManifestPath , blazorInfo . outputManifestPath , runDefinition . dockerRun . volumes , runDefinition . dockerRun . os ) ;
4622}
4723
4824async function transformBlazorManifest ( context : DockerRunTaskContext , inputManifest : string , outputManifest : string , volumes : DockerContainerVolume [ ] , os : PlatformOS ) : Promise < void > {
@@ -58,20 +34,16 @@ async function transformBlazorManifest(context: DockerRunTaskContext, inputManif
5834
5935 os = os || 'Linux' ;
6036
61- context . terminal . writeOutputLine ( l10n . t ( 'Attempting to containerize Blazor static web assets manifest...' ) ) ;
37+ context . terminal . writeOutputLine ( vscode . l10n . t ( 'Attempting to containerize Blazor static web assets manifest...' ) ) ;
6238
63- if ( path . extname ( inputManifest ) === '.json' ) {
64- await transformJsonBlazorManifest ( inputManifest , outputManifest , volumes , os ) ;
65- } else {
66- await transformXmlBlazorManifest ( inputManifest , outputManifest , volumes , os ) ;
67- }
39+ await transformJsonBlazorManifest ( inputManifest , outputManifest , volumes , os ) ;
6840}
6941
7042async function transformJsonBlazorManifest ( inputManifest : string , outputManifest : string , volumes : DockerContainerVolume [ ] , os : PlatformOS ) : Promise < void > {
7143 const manifest = < JsonManifest > await fse . readJson ( inputManifest ) ;
7244
7345 if ( ! manifest ?. ContentRoots ) {
74- throw new Error ( l10n . t ( 'Failed to parse Blazor static web assets manifest.' ) ) ;
46+ throw new Error ( vscode . l10n . t ( 'Failed to parse Blazor static web assets manifest.' ) ) ;
7547 }
7648
7749 if ( ! Array . isArray ( manifest . ContentRoots ) ) {
@@ -87,33 +59,6 @@ async function transformJsonBlazorManifest(inputManifest: string, outputManifest
8759 await fse . utimes ( outputManifest , 0 , 0 ) ;
8860}
8961
90- async function transformXmlBlazorManifest ( inputManifest : string , outputManifest : string , volumes : DockerContainerVolume [ ] , os : PlatformOS ) : Promise < void > {
91- const contents = ( await fse . readFile ( inputManifest ) ) . toString ( ) ;
92- const manifest = < XmlManifest > await xml2js . parseStringPromise ( contents ) ;
93-
94- if ( ! manifest ?. StaticWebAssets ) {
95- throw new Error ( l10n . t ( 'Failed to parse Blazor static web assets manifest.' ) ) ;
96- }
97-
98- if ( ! Array . isArray ( manifest . StaticWebAssets . ContentRoot ) ) {
99- return ;
100- }
101-
102- for ( const contentRoot of manifest . StaticWebAssets . ContentRoot ) {
103- if ( contentRoot && contentRoot . $ ) {
104- contentRoot . $ . Path = tryContainerizePath ( contentRoot . $ . Path , volumes , os ) ;
105- }
106- }
107-
108- const outputContents = ( new xml2js . Builder ( ) ) . buildObject ( manifest ) ;
109-
110- // Write out a new manifest
111- await fse . writeFile ( outputManifest , outputContents ) ;
112-
113- // Set the mtime to 1970 so that next time .NET builds, it will overwrite the output file
114- await fse . utimes ( outputManifest , 0 , 0 ) ;
115- }
116-
11762function tryContainerizePath ( oldPath : string , volumes : DockerContainerVolume [ ] , os : PlatformOS ) : string {
11863 const matchingVolume : DockerContainerVolume = volumes . find ( v => oldPath . toLowerCase ( ) . startsWith ( v . localPath . toLowerCase ( ) ) ) ;
11964
0 commit comments