From 5f2bea0b97068580b91ca0b289af93acd8ead629 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 22 Dec 2020 15:02:57 +0800 Subject: [PATCH] feat(cli): support --cargo-cwd flag --- cli/src/build.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/src/build.ts b/cli/src/build.ts index 8dec9f2d..96f6553b 100644 --- a/cli/src/build.ts +++ b/cli/src/build.ts @@ -38,6 +38,9 @@ export class BuildCommand extends Command { @Command.String('--cargo-flags') cargoFlags = '' + @Command.String('--cargo-cwd') + cargoCwd!: string + @Command.String({ required: false, }) @@ -45,6 +48,9 @@ export class BuildCommand extends Command { @Command.Path('build') async execute() { + const cwd = this.cargoCwd + ? join(process.cwd(), this.cargoCwd) + : process.cwd() const releaseFlag = this.isRelease ? `--release` : '' const targetFLag = this.targetTripleDir ? `--target ${this.targetTripleDir}` @@ -71,6 +77,7 @@ export class BuildCommand extends Command { execSync(cargoCommand, { env: process.env, stdio: 'inherit', + cwd, }) const { binaryName } = getNapiConfig(this.configFileName) let dylibName = this.cargoName @@ -80,11 +87,11 @@ export class BuildCommand extends Command { try { debug('Start read toml') tomlContentString = await readFileAsync( - join(process.cwd(), 'Cargo.toml'), + join(cwd, 'Cargo.toml'), 'utf-8', ) } catch { - throw new TypeError(`Could not find Cargo.toml in ${process.cwd()}`) + throw new TypeError(`Could not find Cargo.toml in ${cwd}`) } try { @@ -151,7 +158,7 @@ export class BuildCommand extends Command { distModulePath = `${distModulePath}${platformName}.node` } - const dir = await findUp() + const dir = await findUp(cwd) if (!dir) { throw new TypeError('No target dir found')