Skip to content

Commit e66ad24

Browse files
committed
Alphabetize methods
1 parent 90330f7 commit e66ad24

2 files changed

Lines changed: 42 additions & 42 deletions

File tree

packages/office-addin-manifest/src/manifestInfo.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4160
async 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-
}

packages/office-addin-manifest/src/xml.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function getXmlAttributeValue(xml: any, name: string): string | undefined
55
// reading xml values is resilient to errors but you can uncomment the next line for debugging if attributes are missing
66
// console.error(`Unable to get xml attribute value "${name}". ${err}`);
77
}
8-
}
8+
}
99

1010
export function getXmlElementAttributeValue(xml: any, elementName: string, attributeName: string = "DefaultValue"): string | undefined {
1111
const element = getXmlElementValue(xml, elementName);
@@ -25,12 +25,12 @@ export function getXmlElementValue(xml: any, name: string): string | undefined {
2525
// reading xml values is resilient to errors but you can uncomment the next line for debugging if elements are missing
2626
// console.error(`Unable to get xml element value "${name}". ${err}`);
2727
}
28-
}
29-
30-
export function setXmlElementValue(xml: any, elementName: string, input: any) {
31-
xml[elementName] = input;
3228
}
3329

34-
export function setElementAttributeValue(xml: any, elementName: string, input: string | undefined, attributeName: string = "DefaultValue") {
30+
export function setXmlElementAttributeValue(xml: any, elementName: string, input: string | undefined, attributeName: string = "DefaultValue") {
3531
xml[elementName][0].$[attributeName] = input;
3632
}
33+
34+
export function setXmlElementValue(xml: any, elementName: string, input: any) {
35+
xml[elementName] = input;
36+
}

0 commit comments

Comments
 (0)