Skip to content

Commit 22b674b

Browse files
committed
Support different project directory during conversion
1 parent a695fa7 commit 22b674b

5 files changed

Lines changed: 22 additions & 8 deletions

File tree

packages/office-addin-project/.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"-m",
1515
"${workspaceFolder}\\test\\TaskPane.manifest.xml",
1616
"-b",
17-
"${workspaceFolder}\\..\\temp.zip"
17+
"${workspaceFolder}\\..\\temp.zip",
18+
"--confirm"
1819
]
1920
},
2021
{

packages/office-addin-project/src/cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ commander
2929
"-b, --backup <backup-path>",
3030
"Specify the location of the backup folder for the project. Default is './backup.zip'"
3131
)
32+
.option(
33+
"-p, --project <project-path>",
34+
"Specify the location of the root directory of the project. Default is the directory of the manifest file."
35+
)
36+
.option( "--confirm", "Confirmes the conversion")
3237
.action(commands.convert);
3338

3439
if (process.argv.length > 2) {

packages/office-addin-project/src/commands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export async function convert(command: commander.Command) {
1111
try {
1212
const manifestPath: string = command.manifest ?? "./manifest.xml";
1313
const backupPath: string = command.backup ?? "./backup.zip";
14+
const projectPath: string = command.project ?? "";
15+
const shouldContinue = command.confirm ?? await asksForUserConfirmation();
1416

15-
const shouldContinue = await asksForUserConfirmation();
1617
if (shouldContinue) {
17-
await convertProject(manifestPath, backupPath);
18+
await convertProject(manifestPath, backupPath, projectPath);
1819
usageDataObject.reportSuccess("convert", { result: "Project converted" });
1920
} else {
2021
usageDataObject.reportSuccess("convert", {

packages/office-addin-project/src/convert.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ import * as fs from "fs";
66
import * as fsExtra from "fs-extra";
77
import * as path from "path";
88
import * as util from "util";
9-
import { execSync } from "child_process";
9+
import { exec, execSync } from "child_process";
1010
import { convert } from "office-addin-manifest-converter";
1111
import { ExpectedError } from "office-addin-usage-data";
1212

1313
/* global console */
1414

15+
const execAsync = util.promisify(exec);
1516
const skipBackup: string[] = ["node_modules"];
1617

1718
export async function convertProject(
1819
manifestPath: string = "./manifest.xml",
19-
backupPath: string = "./backup.zip"
20+
backupPath: string = "./backup.zip",
21+
projectDir: string = ""
2022
) {
2123
const outputPath: string = path.dirname(manifestPath);
24+
25+
// assume project dir is the same as manifest dir if not specified
26+
projectDir = projectDir === "" ? outputPath : projectDir;
27+
process.chdir(projectDir);
28+
2229
if (manifestPath.endsWith(".json")) {
2330
throw new ExpectedError(
2431
`The convert command only works on xml manifest based projects`
@@ -34,7 +41,7 @@ export async function convertProject(
3441
await backupProject(backupPath);
3542
try {
3643
await convert(manifestPath, outputPath, false /* imageDownload */, true /* imageUrls */);
37-
updatePackages();
44+
await updatePackages();
3845
await updateManifestXmlReferences();
3946
fs.unlinkSync(manifestPath);
4047
} catch (err: any) {
@@ -76,7 +83,7 @@ async function restoreBackup(backupPath: string) {
7683
zip.extractAllTo("./", true); // overwrite
7784
}
7885

79-
function updatePackages(): void {
86+
async function updatePackages(): Promise<void> {
8087
// Contains name of the package and minimum version
8188
const depedentPackages: string[] = [
8289
"office-addin-debugging",
@@ -99,7 +106,7 @@ function updatePackages(): void {
99106

100107
command += ` --save-dev`;
101108
console.log(messageToBePrinted.slice(0, -1));
102-
execSync(command);
109+
await execAsync(command);
103110
}
104111

105112
async function updateManifestXmlReferences(): Promise<void> {
File renamed without changes.

0 commit comments

Comments
 (0)