Skip to content

Commit 83fa42b

Browse files
committed
Fix merge conflicts
1 parent 0507b17 commit 83fa42b

File tree

6 files changed

+256
-6
lines changed

6 files changed

+256
-6
lines changed

packages/office-addin-dev-settings/README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Provides the ability to configure developer settings for Office Add-ins.
1313
* [source-bundle-url](#source-bundle-url)
1414
* [unregister](#unregister)
1515
* [webview](#webview)
16+
* [configure-disk-manifests](#configure-disk-manifests)
1617

1718
#
1819

@@ -256,4 +257,27 @@ Disable overriding the source bundle of an add-in.
256257

257258
Enable overriding the source bundle of an add-in.
258259

259-
#
260+
#
261+
262+
### disk-manifests
263+
Configures loading manifests from disk.
264+
265+
> This switch currently supports the following clients: classic Windows Outlook.
266+
267+
Syntax:
268+
269+
`office-addin-dev-settings configure-disk-manifests [options]`
270+
271+
Without options, displays whether loading manifests from disk is enabled.
272+
273+
Options:
274+
275+
`--disable`
276+
277+
Disable loading manifests from disk.
278+
279+
`--enable`
280+
281+
Enable loading manifests from disk.
282+
283+
#

packages/office-addin-dev-settings/src/cli.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ commander
108108
.description("Configures overriding of the source bundle.")
109109
.action(commands.sourceBundleOverrideFile);
110110

111+
commander
112+
.command("disk-manifests")
113+
.option("--enable [path]", `Enable loading manifests from disk.`)
114+
.option("--disable", "Disable loading manifests from disk.")
115+
.description("Configures loading manifests from disk.")
116+
.action(commands.diskManifests);
117+
111118
// if the command is not known, display an error
112119
commander.on("command:*", function () {
113120
logErrorMessage(`The command syntax is not valid.\n`);

packages/office-addin-dev-settings/src/commands.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,40 @@ export async function isSourceBundleOverriden(addInId: string) {
545545
usageDataObject.reportException("isSourceBundleOverriden", err);
546546
logErrorMessage(err);
547547
}
548-
}
548+
}
549+
550+
export async function diskManifests(options: OptionValues) {
551+
try {
552+
if (options.enable) {
553+
const path: string | undefined =
554+
typeof options.enable === "string" ? options.enable : undefined;
555+
await enableDiskManifests(path);
556+
} else if (options.disable) {
557+
await disableDiskManifests();
558+
} else {
559+
await areDiskManifestsEnabled();
560+
}
561+
usageDataObject.reportSuccess("diskManifests");
562+
} catch (err: any) {
563+
usageDataObject.reportException("diskManifests", err);
564+
logErrorMessage(err);
565+
}
566+
}
567+
568+
export async function enableDiskManifests(path?: string) {
569+
const diskManifestsPath = await devSettings.enableDiskManifests(path);
570+
console.log(`Disk manifests have been enabled. Path: ${diskManifestsPath}`);
571+
usageDataObject.reportSuccess("enableDiskManifests()");
572+
}
573+
574+
export async function disableDiskManifests() {
575+
await devSettings.disableDiskManifests();
576+
console.log("Disk manifests have been disabled.");
577+
usageDataObject.reportSuccess("disableDiskManifests()");
578+
}
579+
580+
export async function areDiskManifestsEnabled() {
581+
const res = await devSettings.areDiskManifestsEnabled();
582+
console.log(res);
583+
usageDataObject.reportSuccess("areDiskManifestsEnabled()");
584+
}

packages/office-addin-dev-settings/src/dev-settings-windows.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import fspath from "path";
2525
/* global process */
2626

2727
const DeveloperSettingsRegistryKey: string = `HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Office\\16.0\\Wef\\Developer`;
28+
const ProvidersRegistryKey: string = `HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\16.0\\WEF\\Providers`;
2829

2930
const OpenDevTools: string = "OpenDevTools";
3031
export const OutlookSideloadManifestPath: string = "OutlookSideloadManifestPath";
@@ -40,6 +41,9 @@ const UseLiveReload: string = "UseLiveReload";
4041
const UseProxyDebugger: string = "UseWebDebugger";
4142
const WebViewSelection: string = "WebViewSelection";
4243
const JsBundle: string = "JsBundle";
44+
const Outlook: string = "Outlook";
45+
const EnableDebugging: string = "EnableDebugging";
46+
const OutlookDiskProvider: string = "OutlookDiskProvider";
4347

4448
export async function clearDevSettings(addinId: string): Promise<void> {
4549
return deleteDeveloperSettingsRegistryKey(addinId);
@@ -97,6 +101,10 @@ export function getDeveloperSettingsRegistryKey(addinId: string): registry.Regis
97101
return new registry.RegistryKey(`${DeveloperSettingsRegistryKey}\\${addinId}`);
98102
}
99103

104+
export function getProvidersRegistryKey(): registry.RegistryKey {
105+
return new registry.RegistryKey(`${ProvidersRegistryKey}`);
106+
}
107+
100108
export async function getEnabledDebuggingMethods(addinId: string): Promise<DebuggingMethod[]> {
101109
const key: registry.RegistryKey = getDeveloperSettingsRegistryKey(addinId);
102110
const methods: DebuggingMethod[] = [];
@@ -376,4 +384,43 @@ export async function getSourceBundleOverrideFilePath(addInId: string): Promise<
376384
const developerSettingsRegKey = getDeveloperSettingsRegistryKey(addInId);
377385
const sourceBundleOverridePath = await registry.getStringValue(developerSettingsRegKey, JsBundle);
378386
return sourceBundleOverridePath;
379-
}
387+
}
388+
389+
export async function enableDiskManifests(path: string) {
390+
const providersRegKey = getProvidersRegistryKey();
391+
await registry.addStringValue(providersRegKey, OutlookDiskProvider, path);
392+
393+
const outlookDeveloperRegKey = getDeveloperSettingsRegistryKey(Outlook);
394+
await registry.addNumberValue(outlookDeveloperRegKey, EnableDebugging, 1);
395+
}
396+
397+
export async function disableDiskManifests() {
398+
const providersRegKey = getProvidersRegistryKey();
399+
await registry.deleteValue(providersRegKey, OutlookDiskProvider);
400+
401+
const outlookDeveloperRegKey = getDeveloperSettingsRegistryKey(Outlook);
402+
await registry.deleteKey(outlookDeveloperRegKey);
403+
}
404+
405+
export async function areDiskManifestsEnabled(): Promise<string> {
406+
const diskManifestsPath = await getDiskManifestsPath();
407+
const enableDebugging = await getOutlookEnableDebugging();
408+
409+
if (diskManifestsPath && enableDebugging && enableDebugging > 0) {
410+
return "Disk manifests are enabled. Path = " + diskManifestsPath;
411+
}
412+
413+
return "Disk manifests are disabled";
414+
}
415+
416+
export async function getDiskManifestsPath(): Promise<string | undefined> {
417+
const providersRegKey = getProvidersRegistryKey();
418+
const diskManifestsPath = await registry.getStringValue(providersRegKey, OutlookDiskProvider);
419+
return diskManifestsPath;
420+
}
421+
422+
export async function getOutlookEnableDebugging(): Promise<number | undefined> {
423+
const outlookDeveloperRegKey = getDeveloperSettingsRegistryKey(Outlook);
424+
const enableDebugging = await registry.getNumberValue(outlookDeveloperRegKey, EnableDebugging);
425+
return enableDebugging;
426+
}

packages/office-addin-dev-settings/src/dev-settings.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,57 @@ export async function isSourceBundleOverriden(addInId: string) : Promise<string>
336336

337337
export async function getSourceBundleOverrideFilePath(addInId: string): Promise<string | undefined> {
338338
return devSettingsWindows.getSourceBundleOverrideFilePath(addInId);
339-
}
339+
}
340+
341+
export async function enableDiskManifests(path?: string) : Promise<string> {
342+
switch (process.platform) {
343+
case "win32": {
344+
const isValidPath = isValidDiskManifestsPath(path);
345+
if (path && isValidPath) {
346+
await devSettingsWindows.enableDiskManifests(path);
347+
return path;
348+
}
349+
throw new ExpectedError("The disk manifests path is not specified or is invalid. Ensure that it is an existing directory path.");
350+
}
351+
default:
352+
throw new ExpectedError(`Platform not supported: ${process.platform}.`);
353+
}
354+
}
355+
356+
function isValidDiskManifestsPath(path?: string) {
357+
let isValid: boolean = false;
358+
try {
359+
if (path) {
360+
const pathExists: boolean = fs.existsSync(path);
361+
if (pathExists) {
362+
const stat = fs.statSync(path);
363+
isValid = stat.isDirectory();
364+
}
365+
}
366+
} catch (err: any) {
367+
console.log(err);
368+
}
369+
return isValid;
370+
}
371+
372+
export async function disableDiskManifests() : Promise<void> {
373+
switch (process.platform) {
374+
case "win32":
375+
return devSettingsWindows.disableDiskManifests();
376+
default:
377+
throw new ExpectedError(`Platform not supported: ${process.platform}.`);
378+
}
379+
}
380+
381+
export async function areDiskManifestsEnabled() : Promise<string> {
382+
switch (process.platform) {
383+
case "win32":
384+
return devSettingsWindows.areDiskManifestsEnabled();
385+
default:
386+
throw new ExpectedError(`Platform not supported: ${process.platform}.`);
387+
}
388+
}
389+
390+
export async function getDiskManifestsPath(): Promise<string | undefined> {
391+
return devSettingsWindows.getDiskManifestsPath();
392+
}

packages/office-addin-dev-settings/test/unit-tests/test.ts

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ describe("Sideload to web", function () {
641641

642642
describe("Source bundle override file", function() {
643643
if (isWindows) {
644-
let sourceBundleOverridePathBeforeTests: string | undefined;
645644
const baseDirPath = process.cwd();
646645
const jsBundleFileName = "bundle.js";
647646
const testBundleOverrideFilePath = fspath.normalize(`${baseDirPath}/${jsBundleFileName}`);
@@ -706,4 +705,88 @@ describe("Source bundle override file", function() {
706705
});
707706
});
708707
}
709-
});
708+
});
709+
710+
describe("Disk Manifests", function() {
711+
if (isWindows) {
712+
let diskManifestsPathBeforeTests: string | undefined;
713+
const diskManifestsDisableStr = "Disk manifests are disabled";
714+
const testExecDirName = "testExec";
715+
const baseDirPath = process.cwd();
716+
const testExecDirPath = fspath.normalize(`${baseDirPath}/${testExecDirName}`);
717+
const enableDiskManifestsError = "The disk manifests path is not specified or is invalid. Ensure that it is an existing directory path.";
718+
const diskManifestsEnabledPrefix = "Disk manifests are enabled. Path = ";
719+
720+
this.beforeAll(async function() {
721+
await fsextra.remove(testExecDirPath);
722+
await fsextra.mkdir(testExecDirPath);
723+
diskManifestsPathBeforeTests = await devSettings.getDiskManifestsPath();
724+
await devSettings.disableDiskManifests();
725+
});
726+
727+
this.afterAll(async function() {
728+
await fsextra.remove(testExecDirPath);
729+
if (diskManifestsPathBeforeTests) {
730+
await devSettings.enableDiskManifests(diskManifestsPathBeforeTests);
731+
} else {
732+
await devSettings.disableDiskManifests();
733+
}
734+
});
735+
736+
describe("validate before enabling disk manifests", function() {
737+
it("disk manifests should NOT be enabled", async function() {
738+
assert.strictEqual(await devSettings.areDiskManifestsEnabled(), diskManifestsDisableStr);
739+
});
740+
});
741+
742+
describe("validate enabling disk manifests", function() {
743+
it("enable disk manifests with NO path", async function() {
744+
assert.strictEqual(await devSettings.areDiskManifestsEnabled(), diskManifestsDisableStr);
745+
746+
let error;
747+
try {
748+
await devSettings.enableDiskManifests(undefined);
749+
} catch (err: any) {
750+
error = err;
751+
}
752+
assert.ok(error instanceof Error, "error expected");
753+
assert.strictEqual(error.message, enableDiskManifestsError);
754+
});
755+
756+
it("enable disk manifests with INVALID path", async function() {
757+
assert.strictEqual(await devSettings.areDiskManifestsEnabled(), diskManifestsDisableStr);
758+
759+
const diskManifestsPath = fspath.join(testExecDirPath, "doesNotExist");
760+
761+
let error;
762+
try {
763+
await devSettings.enableDiskManifests(diskManifestsPath);
764+
} catch (err: any) {
765+
error = err;
766+
}
767+
assert.ok(error instanceof Error, "error expected");
768+
assert.strictEqual(error.message, enableDiskManifestsError);
769+
});
770+
771+
it("enable disk manifests with VALID path", async function() {
772+
assert.strictEqual(await devSettings.areDiskManifestsEnabled(), diskManifestsDisableStr);
773+
774+
try {
775+
const path = await devSettings.enableDiskManifests(testExecDirPath);
776+
assert.strictEqual(path, testExecDirPath);
777+
} catch (err: any) {
778+
console.log(err);
779+
assert.fail("unexpected error");
780+
}
781+
});
782+
});
783+
784+
describe("validate disabling disk manifest", async function() {
785+
it("disable disk manifests", async function() {
786+
assert.strictEqual(await devSettings.areDiskManifestsEnabled(), diskManifestsEnabledPrefix + testExecDirPath);
787+
await devSettings.disableDiskManifests();
788+
assert.strictEqual(await devSettings.areDiskManifestsEnabled(), diskManifestsDisableStr);
789+
})
790+
});
791+
}
792+
});

0 commit comments

Comments
 (0)