11import { Wallet } from 'ethers' ;
22import signale from 'signale' ;
3- import fs from 'fs' ;
43import {
54 isDirectoryValid ,
65 progress ,
76 writeFile ,
87 promptOutputDirectory ,
98 promptWalletPassword ,
109 checkAndPromptOverwrite ,
10+ isDir ,
1111} from '../../utils' ;
1212
1313export const command = 'create' ;
@@ -37,22 +37,15 @@ export const promptQuestions = async () => {
3737 ! walletPath || walletPath . trim ( ) === '' || walletPath === '.' ? '.' : walletPath ;
3838
3939 // Validate: must be either an existing directory or a path ending with .json
40- let isDirectory = false ;
41- try {
42- isDirectory = fs . lstatSync ( normalizedPath ) . isDirectory ( ) ;
43- } catch ( _e ) {
44- // Path doesn't exist, check if it's a .json file path
45- }
46-
4740 const isJsonFilePath = normalizedPath . toLowerCase ( ) . endsWith ( '.json' ) ;
4841
49- if ( ! isDirectory && ! isJsonFilePath ) {
42+ if ( ! isDir ( normalizedPath ) && ! isJsonFilePath ) {
5043 throw new Error (
5144 `Invalid path: ${ normalizedPath } . Please provide either a directory path or a file path ending with .json` ,
5245 ) ;
5346 }
5447
55- if ( isDirectory && ! isDirectoryValid ( normalizedPath ) ) {
48+ if ( isDir ( normalizedPath ) && ! isDirectoryValid ( normalizedPath ) ) {
5649 throw new Error ( `Invalid directory path provided: ${ normalizedPath } ` ) ;
5750 }
5851
@@ -65,14 +58,7 @@ export const generateAndSaveWallet = async (walletPassword: string, walletPath:
6558 const normalizedPath = ! walletPath || walletPath . trim ( ) === '' ? '.' : walletPath ;
6659
6760 // Check if path is a directory
68- let isDirectory = false ;
69- try {
70- isDirectory = fs . lstatSync ( normalizedPath ) . isDirectory ( ) ;
71- } catch ( _e ) {
72- // Path doesn't exist yet, that's okay
73- }
74-
75- if ( isDirectory ) {
61+ if ( isDir ( normalizedPath ) ) {
7662 // If it's a directory (including current directory), create wallet.json inside it
7763 walletFilePath = normalizedPath === '.' ? 'wallet.json' : `${ normalizedPath } /wallet.json` ;
7864 } else if ( normalizedPath . toLowerCase ( ) . endsWith ( '.json' ) ) {
0 commit comments