diff --git a/src/cli.ts b/src/cli.ts index 781c68f..593eb7b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -125,7 +125,7 @@ program .command('deploy') .description('Deploy contracts to different networks, only supports devnet and testnet') .option('--network ', 'Specify the network to deploy to', 'devnet') - .option('--target ', 'Specify the relative bin target folder to deploy to') + .option('--target ', 'Specify the script binaries file/folder path to deploy') .option('--config ', 'Specify the offckb.config.ts file path for deployment', undefined) .option('-t, --type-id', 'Specify if use upgradable type id to deploy the script') .option('--privkey ', 'Specify the private key to deploy scripts') diff --git a/src/cmd/deploy.ts b/src/cmd/deploy.ts index 258fbf4..4b0df02 100644 --- a/src/cmd/deploy.ts +++ b/src/cmd/deploy.ts @@ -1,7 +1,7 @@ import { NetworkOption, Network } from '../type/base'; import path from 'path'; import { deployerAccount } from '../cfg/account'; -import { listBinaryFilesInFolder, isAbsolutePath } from '../util/fs'; +import { isAbsolutePath, getBinaryFilesFromPath } from '../util/fs'; import { validateNetworkOpt } from '../util/validator'; import { deployBinaries, getToDeployBinsPath, recordDeployResult } from '../deploy'; import { CKB } from '../sdk/ckb'; @@ -30,9 +30,8 @@ export async function deploy( const configPath = opt.config; const targetFolder = opt.target; if (targetFolder) { - const binFolder = isAbsolutePath(targetFolder) ? targetFolder : path.resolve(process.cwd(), targetFolder); - const bins = listBinaryFilesInFolder(binFolder); - const binPaths = bins.map((bin) => path.resolve(binFolder, bin)); + const binFilesOrFolder = isAbsolutePath(targetFolder) ? targetFolder : path.resolve(process.cwd(), targetFolder); + const binPaths = getBinaryFilesFromPath(binFilesOrFolder); const results = await deployBinaries(binPaths, privateKey, enableTypeId, ckb); // record the deployed contract infos diff --git a/src/deploy/index.ts b/src/deploy/index.ts index b38aa0e..a256f2b 100644 --- a/src/deploy/index.ts +++ b/src/deploy/index.ts @@ -2,7 +2,7 @@ import { DeploymentOptions, generateDeploymentToml } from '../deploy/toml'; import { DeploymentRecipe, generateDeploymentMigrationFile, Migration } from '../deploy/migration'; import { genMyScriptsJsonFile } from '../scripts/gen'; import { OffCKBConfigFile } from '../template/offckb-config'; -import { listBinaryFilesInFolder, readFileToUint8Array, isAbsolutePath } from '../util/fs'; +import { readFileToUint8Array, isAbsolutePath, getBinaryFilesFromPath } from '../util/fs'; import path from 'path'; import fs from 'fs'; import { Network } from '../type/base'; @@ -19,11 +19,12 @@ export function getToDeployBinsPath(userOffCKBConfigPath: string) { const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/); if (match && match[1]) { const contractBinFolderValue = match[1]; - const binFolderPath = isAbsolutePath(contractBinFolderValue) + const binFileOrFolderPath = isAbsolutePath(contractBinFolderValue) ? contractBinFolderValue : path.resolve(userOffCKBConfigPath, contractBinFolderValue); - const bins = listBinaryFilesInFolder(binFolderPath); - return bins.map((bin) => path.resolve(binFolderPath, bin)); + + const bins = getBinaryFilesFromPath(binFileOrFolderPath); + return bins; } else { console.log('contractBinFolder value not found in offckb.config.ts'); return []; diff --git a/src/util/fs.ts b/src/util/fs.ts index 9a97c06..b826e6a 100644 --- a/src/util/fs.ts +++ b/src/util/fs.ts @@ -100,6 +100,22 @@ export async function readFileToUint8Array(filePath: string): Promise path.join(folderPath, f)); // Filter out only the binary files (assuming they have extensions like .exe, .bin, .dll, etc.) - const binaryFiles = files.filter((file) => { - const filePath = path.join(folderPath, file); - // Check if the file is a regular file and not a directory - return fs.statSync(filePath).isFile() && isBinaryFile(filePath); - }); - + const binaryFiles = files.filter((file) => fs.statSync(file).isFile() && isBinaryFile(file)); return binaryFiles; }