Skip to content

Commit c651be2

Browse files
committed
Merge branch 'master' into yo-office
2 parents 9a3ca73 + 12f2748 commit c651be2

File tree

8 files changed

+189
-48
lines changed

8 files changed

+189
-48
lines changed

convertToSingleHost.js

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
// NOTE: This script is generally in sync with other template repos (with minor differences) even though this template doesn't support different hosts.
2+
// It's easier to maintain the script in one place and copy it over to other repos than to maintain multiple versions of the script.
3+
14
/* global require, process, console */
25

36
const fs = require("fs");
47
const path = require("path");
58
const util = require("util");
69
const childProcess = require("child_process");
710

8-
const manifestType = process.argv[2];
9-
const projectName = process.argv[3];
10-
let appId = process.argv[4];
11+
const host = process.argv[2];
12+
const manifestType = process.argv[3];
13+
const projectName = process.argv[4];
14+
let appId = process.argv[5];
15+
const hosts = ["excel"];
1116
const testPackages = [
1217
"@types/mocha",
1318
"@types/node",
14-
"current-processes",
1519
"mocha",
1620
"office-addin-mock",
1721
"office-addin-test-helpers",
@@ -22,7 +26,35 @@ const readFileAsync = util.promisify(fs.readFile);
2226
const unlinkFileAsync = util.promisify(fs.unlink);
2327
const writeFileAsync = util.promisify(fs.writeFile);
2428

25-
async function removeTestInfraStructure() {
29+
async function modifyProjectForSingleHost(host) {
30+
if (!host) {
31+
throw new Error("The host was not provided.");
32+
}
33+
if (!hosts.includes(host)) {
34+
throw new Error(`'${host}' is not a supported host.`);
35+
}
36+
await convertProjectToSingleHost(host);
37+
await updatePackageJsonForSingleHost(host);
38+
await updateLaunchJsonFile(host);
39+
}
40+
41+
async function convertProjectToSingleHost(host) {
42+
// NOTE: This template only supports Excel, so we don't need to deal with host specific files.
43+
44+
// Copy host-specific manifest over manifest.xml
45+
// const manifestContent = await readFileAsync(`./manifest.${host}.xml`, "utf8");
46+
// await writeFileAsync(`./manifest.xml`, manifestContent);
47+
48+
// Copy over host-specific taskpane code to taskpane.ts
49+
// const srcContent = await readFileAsync(`./src/taskpane/${host}.ts`, "utf8");
50+
// await writeFileAsync(`./src/taskpane/taskpane.ts`, srcContent);
51+
52+
// Delete all host-specific files
53+
// hosts.forEach(async function (host) {
54+
// await unlinkFileAsync(`./manifest.${host}.xml`);
55+
// await unlinkFileAsync(`./src/taskpane/${host}.ts`);
56+
// });
57+
2658
// Delete test folder
2759
deleteFolder(path.resolve(`./test`));
2860

@@ -32,21 +64,33 @@ async function removeTestInfraStructure() {
3264
// Delete CI/CD pipeline files
3365
deleteFolder(path.resolve(`./.azure-devops`));
3466

35-
await updatePackageJsonFile();
36-
await updateLaunchJsonFile("excel");
37-
// delete this script
38-
await unlinkFileAsync("./convertToSingleHost.js");
67+
// Delete repo support files
3968
await deleteSupportFiles();
4069
}
4170

42-
async function updatePackageJsonFile() {
71+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
72+
async function updatePackageJsonForSingleHost(host) {
73+
// Update package.json to reflect selected host
4374
const packageJson = `./package.json`;
4475
const data = await readFileAsync(packageJson, "utf8");
4576
let content = JSON.parse(data);
4677

47-
// remove scripts that are unrelated to testing or this file
78+
// Update 'config' section in package.json to use selected host
79+
//content.config["app_to_debug"] = host;
80+
81+
// Remove 'engines' section
82+
delete content.engines;
83+
84+
// Remove scripts that are unrelated to the selected host
4885
Object.keys(content.scripts).forEach(function (key) {
49-
if (key === "convert-to-single-host" || key.includes("test")) {
86+
if (key === "convert-to-single-host") {
87+
delete content.scripts[key];
88+
}
89+
});
90+
91+
// Remove test-related scripts
92+
Object.keys(content.scripts).forEach(function (key) {
93+
if (key.includes("test")) {
5094
delete content.scripts[key];
5195
}
5296
});
@@ -116,6 +160,7 @@ async function deleteSupportFiles() {
116160
await unlinkFileAsync("LICENSE");
117161
await unlinkFileAsync("README.md");
118162
await unlinkFileAsync("SECURITY.md");
163+
await unlinkFileAsync("./convertToSingleHost.js");
119164
await unlinkFileAsync(".npmrc");
120165
await unlinkFileAsync("package-lock.json");
121166
}
@@ -211,12 +256,12 @@ async function modifyProjectForJSONManifest() {
211256
await deleteXMLManifestRelatedFiles();
212257
}
213258

214-
215259
/**
216-
* Remove test infrastructure and repo support files from project.
260+
* Modify the project so that it only supports a single host.
261+
* @param host The host to support.
217262
*/
218-
removeTestInfraStructure().catch((err) => {
219-
console.error(`Error: ${err instanceof Error ? err.message : err}`);
263+
modifyProjectForSingleHost(host).catch((err) => {
264+
console.error(`Error modifying for single host: ${err instanceof Error ? err.message : err}`);
220265
process.exitCode = 1;
221266
});
222267

@@ -241,7 +286,7 @@ if (projectName) {
241286
}
242287

243288
// Modify the manifest to include the name and id of the project
244-
const cmdLine = `npx office-addin-manifest modify ${manifestPath} -g ${appId} -d ${projectName}`;
289+
const cmdLine = `npx office-addin-manifest modify ${manifestPath} -g ${appId} -d "${projectName}"`;
245290
childProcess.exec(cmdLine, (error, stdout) => {
246291
if (error) {
247292
console.error(`Error updating the manifest: ${error}`);

manifest.xml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
55
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
6-
<Id>19791936-c8fa-48c9-a354-e347c71ae827</Id>
6+
<Id>ca968be6-628b-4f14-ba3c-3e614effa9bd</Id>
77
<Version>1.0.0.0</Version>
88
<ProviderName>Contoso</ProviderName>
99
<DefaultLocale>en-US</DefaultLocale>
10-
<DisplayName DefaultValue="Excel Custom Functions Shared Runtime" />
10+
<DisplayName DefaultValue="Excel Custom Functions" />
1111
<Description DefaultValue="Write your own Excel functions in TypeScript." />
1212
<IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
1313
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
@@ -20,7 +20,7 @@
2020
</Hosts>
2121
<Requirements>
2222
<Sets DefaultMinVersion="1.1">
23-
<Set Name="SharedRuntime" MinVersion="1.1"/>
23+
<Set Name="CustomFunctionsRuntime" MinVersion="1.1"/>
2424
</Sets>
2525
</Requirements>
2626
<DefaultSettings>
@@ -30,16 +30,13 @@
3030
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
3131
<Hosts>
3232
<Host xsi:type="Workbook">
33-
<Runtimes>
34-
<Runtime resid="Taskpane.Url" lifetime="long" />
35-
</Runtimes>
3633
<AllFormFactors>
3734
<ExtensionPoint xsi:type="CustomFunctions">
3835
<Script>
3936
<SourceLocation resid="Functions.Script.Url" />
4037
</Script>
4138
<Page>
42-
<SourceLocation resid="Taskpane.Url"/>
39+
<SourceLocation resid="Functions.Page.Url"/>
4340
</Page>
4441
<Metadata>
4542
<SourceLocation resid="Functions.Metadata.Url" />
@@ -53,7 +50,7 @@
5350
<Description resid="GetStarted.Description"/>
5451
<LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
5552
</GetStarted>
56-
<FunctionFile resid="Taskpane.Url"/>
53+
<FunctionFile resid="Commands.Url" />
5754
<ExtensionPoint xsi:type="PrimaryCommandSurface">
5855
<OfficeTab id="TabHome">
5956
<Group id="CommandsGroup">
@@ -92,10 +89,12 @@
9289
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
9390
</bt:Images>
9491
<bt:Urls>
95-
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3000/functions.js" />
96-
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3000/functions.json" />
92+
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3000/public/functions.js" />
93+
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3000/public/functions.json" />
94+
<bt:Url id="Functions.Page.Url" DefaultValue="https://localhost:3000/public/functions.html" />
9795
<bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812" />
98-
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
96+
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
97+
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html" />
9998
</bt:Urls>
10099
<bt:ShortStrings>
101100
<bt:String id="Functions.Namespace" DefaultValue="CONTOSO" />
@@ -109,4 +108,4 @@
109108
</bt:LongStrings>
110109
</Resources>
111110
</VersionOverrides>
112-
</OfficeApp>
111+
</OfficeApp>

src/commands/commands.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. -->
2+
3+
<!DOCTYPE html>
4+
<html>
5+
6+
<head>
7+
<meta charset="UTF-8" />
8+
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
9+
10+
<!-- Office JavaScript API -->
11+
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>
12+
</head>
13+
14+
<body>
15+
16+
</body>
17+
18+
</html>

src/functions/functions.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. -->
2+
3+
<!DOCTYPE html>
4+
<html>
5+
6+
<head>
7+
<meta charset="UTF-8" />
8+
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
9+
<meta http-equiv="Expires" content="0" />
10+
<title></title>
11+
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/custom-functions-runtime.js" type="text/javascript"></script>
12+
</head>
13+
14+
<body>
15+
16+
</body>
17+
18+
</html>

test/end-to-end/test-manifest-debugging.xml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Version>1.0.0.0</Version>
88
<ProviderName>Contoso</ProviderName>
99
<DefaultLocale>en-US</DefaultLocale>
10-
<DisplayName DefaultValue="Excel Custom Functions Shared Runtime"/>
10+
<DisplayName DefaultValue="Excel Custom Functions"/>
1111
<Description DefaultValue="Write your own Excel functions in TypeScript."/>
1212
<IconUrl DefaultValue="https://localhost:3001/assets/icon-32.png"/>
1313
<HighResolutionIconUrl DefaultValue="https://localhost:3001/assets/icon-64.png"/>
@@ -20,7 +20,7 @@
2020
</Hosts>
2121
<Requirements>
2222
<Sets DefaultMinVersion="1.1">
23-
<Set Name="SharedRuntime" MinVersion="1.1"/>
23+
<Set Name="CustomFunctionsRuntime" MinVersion="1.1"/>
2424
</Sets>
2525
</Requirements>
2626
<DefaultSettings>
@@ -30,9 +30,6 @@
3030
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
3131
<Hosts>
3232
<Host xsi:type="Workbook">
33-
<Runtimes>
34-
<Runtime resid="Taskpane.Url" lifetime="long" />
35-
</Runtimes>
3633
<AllFormFactors>
3734
<ExtensionPoint xsi:type="CustomFunctions">
3835
<Script>
@@ -47,6 +44,42 @@
4744
<Namespace resid="Functions.Namespace"/>
4845
</ExtensionPoint>
4946
</AllFormFactors>
47+
<DesktopFormFactor>
48+
<GetStarted>
49+
<Title resid="GetStarted.Title"/>
50+
<Description resid="GetStarted.Description"/>
51+
<LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
52+
</GetStarted>
53+
<FunctionFile resid="Commands.Url" />
54+
<ExtensionPoint xsi:type="PrimaryCommandSurface">
55+
<OfficeTab id="TabHome">
56+
<Group id="CommandsGroup">
57+
<Label resid="CommandsGroup.Label" />
58+
<Icon>
59+
<bt:Image size="16" resid="Icon.16x16" />
60+
<bt:Image size="32" resid="Icon.32x32" />
61+
<bt:Image size="80" resid="Icon.80x80" />
62+
</Icon>
63+
<Control xsi:type="Button" id="TaskpaneButton">
64+
<Label resid="TaskpaneButton.Label" />
65+
<Supertip>
66+
<Title resid="TaskpaneButton.Label" />
67+
<Description resid="TaskpaneButton.Tooltip" />
68+
</Supertip>
69+
<Icon>
70+
<bt:Image size="16" resid="Icon.16x16" />
71+
<bt:Image size="32" resid="Icon.32x32" />
72+
<bt:Image size="80" resid="Icon.80x80" />
73+
</Icon>
74+
<Action xsi:type="ShowTaskpane">
75+
<TaskpaneId>ButtonId1</TaskpaneId>
76+
<SourceLocation resid="Taskpane.Url" />
77+
</Action>
78+
</Control>
79+
</Group>
80+
</OfficeTab>
81+
</ExtensionPoint>
82+
</DesktopFormFactor>
5083
</Host>
5184
</Hosts>
5285
<Resources>
@@ -56,10 +89,11 @@
5689
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3001/assets/icon-80.png"/>
5790
</bt:Images>
5891
<bt:Urls>
59-
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3001/functions.js"/>
60-
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3001/functions.json"/>
61-
<bt:Url id="Functions.Page.Url" DefaultValue="https://localhost:3001/taskpane.html"/>
92+
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3001/public/functions.js"/>
93+
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3001/public/functions.json"/>
94+
<bt:Url id="Functions.Page.Url" DefaultValue="https://localhost:3001/public/functions.html"/>
6295
<bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
96+
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3001/commands.html"/>
6397
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3001/taskpane.html"/>
6498
</bt:Urls>
6599
<bt:ShortStrings>

test/end-to-end/test-manifest.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Version>1.0.0.0</Version>
88
<ProviderName>Contoso</ProviderName>
99
<DefaultLocale>en-US</DefaultLocale>
10-
<DisplayName DefaultValue="Excel Custom Functions Shared Runtime"/>
10+
<DisplayName DefaultValue="Excel Custom Functions"/>
1111
<Description DefaultValue="Write your own Excel functions in TypeScript."/>
1212
<IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
1313
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
@@ -20,7 +20,7 @@
2020
</Hosts>
2121
<Requirements>
2222
<Sets DefaultMinVersion="1.1">
23-
<Set Name="SharedRuntime" MinVersion="1.1"/>
23+
<Set Name="CustomFunctionsRuntime" MinVersion="1.1"/>
2424
</Sets>
2525
</Requirements>
2626
<DefaultSettings>
@@ -30,16 +30,13 @@
3030
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
3131
<Hosts>
3232
<Host xsi:type="Workbook">
33-
<Runtimes>
34-
<Runtime resid="Taskpane.Url" lifetime="long" />
35-
</Runtimes>
3633
<AllFormFactors>
3734
<ExtensionPoint xsi:type="CustomFunctions">
3835
<Script>
3936
<SourceLocation resid="Functions.Script.Url"/>
4037
</Script>
4138
<Page>
42-
<SourceLocation resid="Taskpane.Url"/>
39+
<SourceLocation resid="Functions.Page.Url"/>
4340
</Page>
4441
<Metadata>
4542
<SourceLocation resid="Functions.Metadata.Url"/>
@@ -56,9 +53,11 @@
5653
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
5754
</bt:Images>
5855
<bt:Urls>
59-
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3000/functions.js"/>
60-
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3000/functions.json"/>
56+
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3000/public/functions.js"/>
57+
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3000/public/functions.json"/>
58+
<bt:Url id="Functions.Page.Url" DefaultValue="https://localhost:3000/public/functions.html"/>
6159
<bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
60+
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
6261
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
6362
</bt:Urls>
6463
<bt:ShortStrings>

0 commit comments

Comments
 (0)