@@ -32,10 +32,29 @@ function parseManifest(xml: Xml): ManifestInfo {
3232 return manifest ;
3333}
3434
35- async function readXmlFromManifestFile ( manifestPath : string ) : Promise < Xml > {
36- const fileData : string = await readFileAsync ( manifestPath , { encoding : "utf8" } ) ;
37- const xml = await parseXmlAsync ( fileData , manifestPath ) ;
38- return xml ;
35+ export async function modifyManifestFile ( manifestPath : string , guid ?: string , displayName ?: string ) : Promise < ManifestInfo > {
36+ let manifestData : ManifestInfo = { } ;
37+ if ( manifestPath ) {
38+ if ( ! guid && ! displayName ) {
39+ throw new Error ( "You need to specify something to change in the manifest." ) ;
40+ } else {
41+ manifestData = await modifyManifestXml ( manifestPath , guid , displayName ) ;
42+ await writeManifestData ( manifestPath , manifestData ) ;
43+ return await readManifestFile ( manifestPath ) ;
44+ }
45+ } else {
46+ throw new Error ( `Please provide the path to the manifest file.` ) ;
47+ }
48+ }
49+
50+ async function modifyManifestXml ( manifestPath : string , guid ?: string , displayName ?: string ) : Promise < Xml > {
51+ try {
52+ const manifestXml : Xml = await readXmlFromManifestFile ( manifestPath ) ;
53+ setModifiedXmlData ( manifestXml . OfficeApp , guid , displayName ) ;
54+ return manifestXml ;
55+ } catch ( err ) {
56+ throw new Error ( `Unable to modify xml data for manifest file: ${ manifestPath } . \n${ err } ` ) ;
57+ }
3958}
4059
4160async function parseXmlAsync ( xmlString : string , manifestPath : string ) : Promise < Xml > {
@@ -60,28 +79,22 @@ export async function readManifestFile(manifestPath: string): Promise<ManifestIn
6079 }
6180}
6281
63- export async function modifyManifestFile ( manifestPath : string , guid ?: string , displayName ?: string ) : Promise < ManifestInfo > {
64- let manifestData : ManifestInfo = { } ;
65- if ( manifestPath ) {
66- if ( ! guid && ! displayName ) {
67- throw new Error ( "You need to specify something to change in the manifest." ) ;
68- } else {
69- manifestData = await modifyManifestXml ( manifestPath , guid , displayName ) ;
70- await writeManifestData ( manifestPath , manifestData ) ;
71- return await readManifestFile ( manifestPath ) ;
82+ async function readXmlFromManifestFile ( manifestPath : string ) : Promise < Xml > {
83+ const fileData : string = await readFileAsync ( manifestPath , { encoding : "utf8" } ) ;
84+ const xml = await parseXmlAsync ( fileData , manifestPath ) ;
85+ return xml ;
86+ }
87+
88+ function setModifiedXmlData ( xml : any , guid : string | undefined , displayName : string | undefined ) {
89+ if ( guid ) {
90+ if ( guid === "random" ) {
91+ guid = uuid ( ) ;
7292 }
73- } else {
74- throw new Error ( `Please provide the path to the manifest file.` ) ;
93+ xmlMethods . setXmlElementValue ( xml , "Id" , guid ) ;
7594 }
76- }
7795
78- async function modifyManifestXml ( manifestPath : string , guid ?: string , displayName ?: string ) : Promise < Xml > {
79- try {
80- const manifestXml : Xml = await readXmlFromManifestFile ( manifestPath ) ;
81- setModifiedXmlData ( manifestXml . OfficeApp , guid , displayName ) ;
82- return manifestXml ;
83- } catch ( err ) {
84- throw new Error ( `Unable to modify xml data for manifest file: ${ manifestPath } . \n${ err } ` ) ;
96+ if ( displayName ) {
97+ xmlMethods . setXmlElementAttributeValue ( xml , "DisplayName" , displayName ) ;
8598 }
8699}
87100
@@ -103,16 +116,3 @@ async function writeManifestData(manifestPath: string, manifestData: any): Promi
103116 throw new Error ( `Unable to write to file. ${ manifestPath } \n${ err } ` ) ;
104117 }
105118}
106-
107- function setModifiedXmlData ( xml : any , guid : string | undefined , displayName : string | undefined ) {
108- if ( guid ) {
109- if ( guid === "random" ) {
110- guid = uuid ( ) ;
111- }
112- xmlMethods . setXmlElementValue ( xml , "Id" , guid ) ;
113- }
114-
115- if ( displayName ) {
116- xmlMethods . setElementAttributeValue ( xml , "DisplayName" , displayName ) ;
117- }
118- }
0 commit comments