Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR: react-js template for wxp on Toolkit #110

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

41 changes: 1 addition & 40 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug UI Tests",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"bdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/end-to-end",
"-r",
"ts-node/register",
"${workspaceFolder}/test/end-to-end/*.ts"
],
"internalConsoleOptions": "openOnSessionStart",
"runtimeArgs": ["--preserve-symlinks"]
},
{
"name": "Debug Unit Tests",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"bdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/unit",
"-r",
"ts-node/register",
"${workspaceFolder}/test/unit/*.test.ts"
],
"internalConsoleOptions": "openOnSessionStart",
"runtimeArgs": ["--preserve-symlinks"]
},
{
"name": "Excel Desktop (Edge Chromium)",
"type": "msedge",
Expand All @@ -67,7 +29,6 @@
"name": "Outlook Desktop (Edge Chromium)",
"type": "msedge",
"request": "attach",
"useWebView": true,
"port": 9229,
"timeout": 600000,
"webRoot": "${workspaceRoot}",
Expand Down Expand Up @@ -128,4 +89,4 @@
"postDebugTask": "Stop Debug"
}
]
}
}
50 changes: 41 additions & 9 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,53 @@
{
"label": "Debug: Excel Desktop",
"type": "npm",
"script": "start:desktop -- --app excel",
"script": "start -- --app excel",
"dependsOn": [
"Check OS",
"Link"
],
"presentation": {
"clear": true,
"panel": "dedicated",
},
"problemMatcher": []
},
{
"label": "Debug: PowerPoint Desktop",
"label": "Debug: Outlook Desktop",
"type": "npm",
"script": "start:desktop -- --app powerpoint",
"script": "start -- --app outlook",
"dependsOn": [
"Check OS",
"Install"
],
"presentation": {
"clear": true,
"panel": "dedicated",
},
"problemMatcher": []
},
{
"label": "Debug: Word Desktop",
"label": "Debug: PowerPoint Desktop",
"type": "npm",
"script": "start:desktop -- --app word",
"script": "start -- --app powerpoint",
"dependsOn": [
"Check OS",
"Install"
],
"presentation": {
"clear": true,
"panel": "dedicated",
},
"problemMatcher": []
},

{
"label": "Debug: Outlook Desktop",
"label": "Debug: Word Desktop",
"type": "npm",
"script": "start:desktop -- --app outlook",
"script": "start -- --app word",
"dependsOn": [
"Check OS",
"Install"
],
"presentation": {
"clear": true,
"panel": "dedicated",
Expand Down Expand Up @@ -127,5 +142,22 @@
},
"problemMatcher": []
},
]
{
"label": "Check OS",
"type": "shell",
"windows": {
"command": "echo 'Sideloading on Windows is supported'"
},
"linux": {
"command": "echo 'Sideloading on Linux is not supported' && exit 1"
},
"osx": {
"command": "echo 'Sideloading on Mac is not supported' && exit 1"
},
"presentation": {
"clear": true,
"panel": "dedicated",
},
}
],
}
Binary file added assets/color.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/outline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 28 additions & 68 deletions convertToSingleHost.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* 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"];
const host = "outlook";
const hosts = ["outlook", "word", "excel", "powerpoint"];
const path = require("path");
const util = require("util");
const testPackages = [
"@types/mocha",
"@types/node",
"current-processes",
"mocha",
"office-addin-mock",
"office-addin-test-helpers",
Expand All @@ -25,122 +27,80 @@ async function modifyProjectForSingleHost(host) {
if (!hosts.includes(host)) {
throw new Error(`'${host}' is not a supported host.`);
}
await convertProjectToSingleHost(host);
await convertProjectToSingleHost();
await updatePackageJsonForSingleHost(host);
await updateLaunchJsonFile();
if (!convertTest) {
await updateLaunchJsonFile();
}
}

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

// Copy host-specific office-document.js over src/office-document.js
const hostName = getHostName(host);
const srcContent = await readFileAsync(`./src/taskpane/${hostName}-office-document.js`, 'utf8');
await writeFileAsync(`./src/taskpane/office-document.js`, 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.jsx`, "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.jsx`, updatedTextInsertionComponentContent);

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

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

async function convertProjectToSingleHost() {
// Delete the test folder
deleteFolder(path.resolve(`./test`));
// Delete the .github folder

// 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
content.config["app_to_debug"] = host;

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

// Remove scripts that are unrelated to the selected host
// 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
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];
}
});

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

// Remove test-related packages
// 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;
const updatedContent = launchJsonContent.replace(regex, "");
await writeFileAsync(launchJson, updatedContent);
}

function getHostName(host) {
switch (host) {
case "excel":
return "Excel";
case "onenote":
return "OneNote";
case "outlook":
return "Outlook"
case "powerpoint":
return "PowerPoint";
case "project":
return "Project";
case "word":
return "Word";
default:
throw new Error(`'${host}' is not a supported host.`);
}
}

function deleteFolder(folder) {
try {
if (fs.existsSync(folder)) {
Expand Down