Skip to content

Commit

Permalink
Merge pull request #128 from Rick-Kirkham/update-React18-Fluent9-fixes
Browse files Browse the repository at this point in the history
Upgrade to React18, Fluent9, functional components, hooks
  • Loading branch information
millerds committed Oct 18, 2023
2 parents 5dfa4e0 + e372aed commit 45340f4
Show file tree
Hide file tree
Showing 43 changed files with 723 additions and 28,415 deletions.
48 changes: 24 additions & 24 deletions .azure-devops/full-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ jobs:
parameters:
webView: "edge-chromium"

- job: WebView_EdgeLegacy
pool:
name: OE-OfficeClientApps
steps:
- template: ./install.yml
- template: ./lint.yml
- template: ./build.yml
- template: ./devcerts.yml
- template: ./edgewebview.yml
- template: ./test.yml
parameters:
webView: "edge-legacy"
# - job: WebView_EdgeLegacy
# pool:
# name: OE-OfficeClientApps
# steps:
# - template: ./install.yml
# - template: ./lint.yml
# - template: ./build.yml
# - template: ./devcerts.yml
# - template: ./edgewebview.yml
# - template: ./test.yml
# parameters:
# webView: "edge-legacy"

- job: WebView_IE
pool:
name: OE-OfficeClientApps
steps:
- template: ./install.yml
- template: ./lint.yml
- template: ./build.yml
- template: ./devcerts.yml
- template: ./edgewebview.yml
- template: ./test.yml
parameters:
webView: "ie"
# - job: WebView_IE
# pool:
# name: OE-OfficeClientApps
# steps:
# - template: ./install.yml
# - template: ./lint.yml
# - template: ./build.yml
# - template: ./devcerts.yml
# - template: ./edgewebview.yml
# - template: ./test.yml
# parameters:
# webView: "ie"

- job: Mac
pool:
Expand Down
115 changes: 47 additions & 68 deletions convertToSingleHost.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global require, process, console */

const convertTest = process.argv[3] === "convert-test";
const fs = require("fs");
const host = process.argv[2];
const hosts = ["excel", "onenote", "outlook", "powerpoint", "project", "word"];
Expand All @@ -9,7 +8,6 @@ const util = require("util");
const testPackages = [
"@types/mocha",
"@types/node",
"current-processes",
"mocha",
"office-addin-mock",
"office-addin-test-helpers",
Expand All @@ -29,113 +27,94 @@ async function modifyProjectForSingleHost(host) {
}
await convertProjectToSingleHost(host);
await updatePackageJsonForSingleHost(host);
if (!convertTest) {
await updateLaunchJsonFile();
}
await updateLaunchJsonFile();
}

async function convertProjectToSingleHost(host) {
// copy host-specific manifest over manifest.xml
// Copy host-specific manifest over manifest.xml
const manifestContent = await readFileAsync(`./manifest.${host}.xml`, "utf8");
await writeFileAsync(`./manifest.xml`, manifestContent);

// copy host-specific App.tsx over src/taskpane/app/components/App.tsx
// Copy host-specific office-document.ts over src/office-document.ts
const hostName = getHostName(host);
const srcContent = await readFileAsync(`./src/taskpane/components/${hostName}.App.tsx`, 'utf8');
await writeFileAsync(`./src/taskpane/components/App.tsx`, srcContent);

// delete all test files by default for now - eventually we want to convert the tests by default
if (convertTest && (host === "excel" || host === "word")) {
// copy over host-specific taskpane test code to test-taskpane.ts
const testTaskpaneContent = await readFileAsync(`./test/src/test.${host}.app.tsx`, "utf8");
const updatedTestTaskpaneContent = testTaskpaneContent.replace(
`../../../src/taskpane/components/${host}.App`,
`../../../src/taskpane/components/App`
);
await writeFileAsync(`./test/src/test.app.tsx`, updatedTestTaskpaneContent);

// update ui-test.ts to only run against specified host
const testContent = await readFileAsync(`./test/ui-test.ts`, "utf8");
const updatedTestContent = testContent.replace(`const hosts = ["Excel", "Word"]`, `const hosts = ["${host}"]`);
await writeFileAsync(`./test/ui-test.ts`, updatedTestContent);

// delete all host-specific test files after converting to single host
hosts.forEach(async function (host) {
if (host == "excel" || host == "word") {
await unlinkFileAsync(`./test/src/test.${host}.app.tsx`);
}
});
} else {
deleteFolder(path.resolve(`./test`));
}

// delete all host-specific files
const srcContent = await readFileAsync(`./src/taskpane/${hostName}-office-document.ts`, 'utf8');
await writeFileAsync(`./src/taskpane/office-document.ts`, srcContent);

// Remove code from the TextInsertion component that is needed only for tests or
// that is host-specific.
const originalTextInsertionComponentContent = await readFileAsync(`./src/taskpane/components/TextInsertion.tsx`, "utf8");
let updatedTextInsertionComponentContent = originalTextInsertionComponentContent.replace(
`import { selectInsertionByHost } from "../../host-relative-text-insertion";`,
`import insertText from "../office-document";`
);
updatedTextInsertionComponentContent = updatedTextInsertionComponentContent.replace(
`const insertText = await selectInsertionByHost();`,
``
);
await writeFileAsync(`./src/taskpane/components/TextInsertion.tsx`, updatedTextInsertionComponentContent);

// Delete all host-specific files
hosts.forEach(async function (host) {
await unlinkFileAsync(`./manifest.${host}.xml`);
await unlinkFileAsync(`./src/taskpane/components/${getHostName(host)}.App.tsx`);
await unlinkFileAsync(`./src/taskpane/${getHostName(host)}-office-document.ts`);
});

await unlinkFileAsync(`./src/host-relative-text-insertion.ts`);

// delete the .github folder
deleteFolder(path.resolve(`./test`));

// Delete the .github folder
deleteFolder(path.resolve(`./.github`));

// delete CI/CD pipeline files
// Delete CI/CD pipeline files
deleteFolder(path.resolve(`./.azure-devops`));

// delete repo support files
// Delete repo support files
await deleteSupportFiles();
}

async function updatePackageJsonForSingleHost(host) {
// update package.json to reflect selected host
// Update package.json to reflect selected host
const packageJson = `./package.json`;
const data = await readFileAsync(packageJson, "utf8");
let content = JSON.parse(data);

// update 'config' section in package.json to use selected host
// Update 'config' section in package.json to use selected host
content.config["app_to_debug"] = host;

// remove 'engines' section
// Remove 'engines' section
delete content.engines;

// update sideload and unload scripts to use selected host.
["sideload", "unload"].forEach((key) => {
content.scripts[key] = content.scripts[`${key}:${host}`];
});

// remove scripts that are unrelated to the selected host
// Remove scripts that are unrelated to the selected host
Object.keys(content.scripts).forEach(function (key) {
if (
key.startsWith("sideload:") ||
key.startsWith("unload:") ||
key === "convert-to-single-host" ||
key === "start:desktop:outlook"
) {
delete content.scripts[key];
}
});

if (!convertTest) {
// remove test-related scripts
Object.keys(content.scripts).forEach(function (key) {
if (key.includes("test")) {
delete content.scripts[key];
}
});

// remove test-related packages
Object.keys(content.devDependencies).forEach(function (key) {
if (testPackages.includes(key)) {
delete content.devDependencies[key];
}
});
}
// Remove test-related scripts
Object.keys(content.scripts).forEach(function (key) {
if (key.includes("test")) {
delete content.scripts[key];
}
});

// Remove test-related packages
Object.keys(content.devDependencies).forEach(function (key) {
if (testPackages.includes(key)) {
delete content.devDependencies[key];
}
});

// write updated json to file
// Write updated json to file
await writeFileAsync(packageJson, JSON.stringify(content, null, 2));
}

async function updateLaunchJsonFile() {
// remove 'Debug Tests' configuration from launch.json
// Remove 'Debug Tests' configuration from launch.json
const launchJson = `.vscode/launch.json`;
const launchJsonContent = await readFileAsync(launchJson, "utf8");
const regex = /(.+{\r?\n.*"name": "Debug (?:UI|Unit) Tests",\r?\n(?:.*\r?\n)*?.*},.*\r?\n)/gm;
Expand Down
125 changes: 59 additions & 66 deletions manifest.outlook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
<Hosts>
<Host Name="Mailbox" />
</Hosts>
<!-- The <Requirements> element overridden by any <Requirements> element inside a <VersionOverrides> element. -->
<Requirements>
<Sets>
<Set Name="Mailbox" MinVersion="1.1" />
</Sets>
</Requirements>
<!-- The <FormSettins> element is required for validation, but is ignored when there is a <VersionOverrides> element. -->
<FormSettings>
<Form xsi:type="ItemRead">
<DesktopSettings>
Expand All @@ -32,79 +34,70 @@
</Form>
</FormSettings>
<Permissions>ReadWriteItem</Permissions>
<!-- The <Rule> element is required for validation, but is ignored when there is a <VersionOverrides> element. -->
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
</Rule>
<DisableEntityHighlighting>false</DisableEntityHighlighting>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<Requirements>
<bt:Sets DefaultMinVersion="1.3">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<!-- The <Hosts> element is required for validation, but it is ignored when there there is a child <VersionOverrides> element of type VersionOverridesV1_1 with its own <Hosts> element. -->
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Commands.Url" />
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="GroupLabel" />
<Control xsi:type="Button" id="msgReadOpenPaneButton">
<Label resid="TaskpaneButton.Label" />
<Supertip>
<Title resid="TaskpaneButton.Label" />
<Description resid="TaskpaneButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16" />
<bt:Image size="32" resid="Icon.32x32" />
<bt:Image size="80" resid="Icon.80x80" />
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Taskpane.Url" />
</Action>
</Control>
<Control xsi:type="Button" id="ActionButton">
<Label resid="ActionButton.Label"/>
<Supertip>
<Title resid="ActionButton.Label"/>
<Description resid="ActionButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>action</FunctionName>
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
</bt:Images>
<bt:Urls>
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="GroupLabel" DefaultValue="Contoso Add-in"/>
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
<bt:String id="ActionButton.Label" DefaultValue="Perform an action"/>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a pane displaying all available properties."/>
<bt:String id="ActionButton.Tooltip" DefaultValue="Perform an action when clicked."/>
</bt:LongStrings>
</Resources>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Requirements>
<bt:Sets DefaultMinVersion="1.3">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Commands.Url" />
<ExtensionPoint xsi:type="MessageComposeCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgComposeGroup">
<Label resid="GroupLabel" />
<Control xsi:type="Button" id="msgComposeOpenPaneButton">
<Label resid="TaskpaneButton.Label" />
<Supertip>
<Title resid="TaskpaneButton.Label" />
<Description resid="TaskpaneButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16" />
<bt:Image size="32" resid="Icon.32x32" />
<bt:Image size="80" resid="Icon.80x80" />
</Icon>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Taskpane.Url" />
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
</bt:Images>
<bt:Urls>
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="GroupLabel" DefaultValue="Contoso Add-in"/>
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a task pane."/>
<bt:String id="ActionButton.Tooltip" DefaultValue="Perform an action when clicked."/>
</bt:LongStrings>
</Resources>
</VersionOverrides>
</VersionOverrides>
</OfficeApp>
Loading

0 comments on commit 45340f4

Please sign in to comment.