Skip to content

Commit

Permalink
Fix typedContract folder move failure (#152)
Browse files Browse the repository at this point in the history
Compile command will fail at the Generating TS types phase after the
second time, because fs.move fail if the same name folder exist in the
destination path.
Added `overwrite` option so that `typedContract` moved to the correct
path as expected.
  • Loading branch information
shunsukew authored May 9, 2023
1 parent ecf80fd commit 540d60f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/lib/command-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export async function printContractInfo(metadataPath: string) {
}
}

export async function generateTypes(inputAbsPath: string, contractName: string, outputAbsPath: string) {
export async function generateTypes(inputPath: string, contractName: string, outputPath: string) {
await fs.ensureDir(TEMP_ARTIFACTS_PATH);

// Getting error if typechain-polkadot takes folder with unnecessary files/folders as inputs.
Expand All @@ -150,15 +150,15 @@ export async function generateTypes(inputAbsPath: string, contractName: string,
// Cannot generate typedContract directly to `outputAbsPath`
// because relative path of typechain-polkadot input and output folder does matter for later use.
await fs.copyFile(
path.resolve(inputAbsPath, `${contractName}.contract`),
path.resolve(inputPath, `${contractName}.contract`),
path.resolve(TEMP_ARTIFACTS_PATH, `${contractName}.contract`),
),
await fs.copyFile(
path.resolve(inputAbsPath, `${contractName}.json`),
path.resolve(inputPath, `${contractName}.json`),
path.resolve(TEMP_ARTIFACTS_PATH, `${contractName}.json`),
)

await execa.command(`npx typechain-polkadot --in ${TEMP_ARTIFACTS_PATH} --out ${TEMP_TYPED_CONTRACT_PATH}`);

await fs.move(path.resolve(TEMP_TYPED_CONTRACT_PATH), outputAbsPath)
await fs.move(path.resolve(TEMP_TYPED_CONTRACT_PATH), outputPath, { overwrite: true })
}

0 comments on commit 540d60f

Please sign in to comment.