Skip to content

Commit 35ef0a1

Browse files
authored
Merge pull request #128 from OfficeDev/merge-shared-changes
Merge shared changes
2 parents bcc4013 + 8e161df commit 35ef0a1

File tree

8 files changed

+70
-49
lines changed

8 files changed

+70
-49
lines changed

.vscode/launch.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@
3939
"internalConsoleOptions": "openOnSessionStart",
4040
"runtimeArgs": ["--preserve-symlinks"]
4141
},
42-
{
43-
"name": "Excel Desktop (Custom Functions)",
44-
"type": "node",
45-
"request": "attach",
46-
"port": 9223,
47-
"timeout": 600000,
48-
"preLaunchTask": "Debug: Excel Desktop",
49-
"postDebugTask": "Stop Debug",
50-
"resolveSourceMapLocations": null
51-
},
5242
{
5343
"name": "Excel Desktop (Edge Chromium)",
5444
"type": "msedge",

convertToSingleHost.js

Lines changed: 61 additions & 16 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

manifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<Host Name="Workbook"/>
2020
</Hosts>
2121
<Requirements>
22-
<Sets DefaultMinVersion="1.1">
23-
<Set Name="CustomFunctionsRuntime" MinVersion="1.1"/>
24-
</Sets>
22+
<Sets DefaultMinVersion="1.1">
23+
<Set Name="CustomFunctionsRuntime" MinVersion="1.1"/>
24+
</Sets>
2525
</Requirements>
2626
<DefaultSettings>
2727
<SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"start:web": "office-addin-debugging start manifest.xml web",
2727
"stop": "office-addin-debugging stop manifest.xml",
2828
"test": "npm run test:unit && npm run test:e2e",
29-
"test:e2e": "mocha -r ts-node/register test/end-to-end/*.ts",
29+
"test:e2e": "mocha -r ts-node/register test/end-to-end/tests.ts",
3030
"test:unit": "mocha -r ts-node/register test/unit/*.test.ts",
3131
"validate": "office-addin-manifest validate manifest.xml",
3232
"watch": "webpack --mode development --watch"

src/commands/commands.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</head>
1313

1414
<body>
15-
15+
1616
</body>
1717

18-
</html>
18+
</html>

src/functions/functions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</head>
1313

1414
<body>
15-
15+
1616
</body>
1717

1818
</html>

test/end-to-end/src/debugger-websocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export async function connectToWebsocket(reconnectTry: number = 1): Promise<WebS
2424
let jsonUrl = reconnectTry % 2 == 0 ? "http://127.0.0.1:9223/json" : "http://127.0.0.1:9229/json";
2525

2626
while (!wsUrl && reconnectTry < limitOfReconnectTries) {
27-
console.log("Attaching debugger...");
27+
console.log(`Attaching debugger to '${jsonUrl}'...`);
2828
findUrl(jsonUrl);
2929
reconnectTry++;
3030
await sleep(1000);
3131
}
3232

3333
return new Promise((resolve) => {
34-
console.log("Connecting to websocket...");
34+
console.log(`Connecting to websocket '${wsUrl}'...`);
3535
const ws = new WebSocket(wsUrl);
3636

3737
ws.onopen = () => {

0 commit comments

Comments
 (0)