src/utils.js
async function validateDirPathForCLI (dirPath) {
  try {
    await validateDirPath(dirPath);
  } catch (error) {
    if (!error.userError) throw error;
    if (error.details[0].startsWith('Source path must be a directory')) {
      const args = process.argv.reduce((acc, o, idx) => {
        // Discard the first 2 arguments.
        if (idx < 1) return acc;
        if (o === dirPath) return acc.concat(path.dirname(dirPath));
        return acc.concat(o);
      }, []);

      throw userError([
        'Source path must be a directory. Try running with the following instead:',
        '',
        `  node ${args.join(' ')}`,
        ''
      ]);
    }
    throw error;
  }
}
async function validateDirPathForCLI (dirPath) {
  try {
    await validateDirPath(dirPath);
  } catch (error) {
    if (!error.userError) throw error;
    if (error.details[0].startsWith('Source path must be a directory')) {
      const args = process.argv.reduce((acc, o, idx) => {
        // Discard the first 2 arguments.
        if (idx < 1) return acc;
        if (o === dirPath) return acc.concat(path.dirname(dirPath));
        return acc.concat(o);
      }, []);

      throw userError([
        'Source path must be a directory. Try running with the following instead:',
        '',
        `  node ${args.join(' ')}`,
        ''
      ]);
    }
    throw error;
  }
}
async function validateDirPathForCLI ( dirPath ) { try { await validateDirPath ( dirPath ) ; } catch ( error ) { if ( ! error . userError ) throw error ; if ( error . details [ 0 ] . startsWith ( 'Source path must be a directory' ) ) { const args = process . argv . reduce ( ( acc , o , idx ) => { // Discard the first 2 arguments. if ( idx < 1 ) return acc ; if ( o === dirPath ) return acc . concat ( path . dirname ( dirPath ) ) ; return acc . concat ( o ) ; } , [ ] ) ; throw userError ( [ 'Source path must be a directory. Try running with the following instead:' , '' , ` ${ args . join ( ' ' ) } ` , '' ] ) ; } throw error ; } }
Same functionality as validateDirPath but with error messages directed at a
CLI tool.
Validates that the given path is a directory, throwing user errors
in other cases.

@param {string} dirPath Path to validate

@see validateDirPath()
@throws Error if validation fails
Same functionality as validateDirPath but with error messages directed at a CLI tool . Validates that the given path is a directory throwing user errors in other cases .