@@ -6,19 +6,26 @@ import * as fs from "fs";
66import * as fsExtra from "fs-extra" ;
77import * as path from "path" ;
88import * as util from "util" ;
9- import { execSync } from "child_process" ;
9+ import { exec , execSync } from "child_process" ;
1010import { convert } from "office-addin-manifest-converter" ;
1111import { ExpectedError } from "office-addin-usage-data" ;
1212
1313/* global console */
1414
15+ const execAsync = util . promisify ( exec ) ;
1516const skipBackup : string [ ] = [ "node_modules" ] ;
1617
1718export 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
105112async function updateManifestXmlReferences ( ) : Promise < void > {
0 commit comments