function ensureFileSync(filePath) {
  try {
    // if file exists
    const stat = Deno.lstatSync(filePath);
    if (!stat.isFile) {
      throw new Error(
        `Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`,
      );
    }
  } catch (err) {
    // if file not exists
    if (err instanceof Deno.errors.NotFound) {
      // ensure dir exists
      ensureDirSync(path.dirname(filePath));
      // create file
      Deno.writeFileSync(filePath, new Uint8Array());
      return;
    }
    throw err;
  }
}
/**
 * Ensures that the file exists.
 * If the file that is requested to be created is in directories that do not
 * exist,
 * these directories are created. If the file already exists,
 * it is NOT MODIFIED.
 * Requires the `--allow-read` and `--allow-write` flag.
 */
Ensures that the file exists.
If the file that is requested to be created is in directories that do not
exist,
these directories are created. If the file already exists,
it is NOT MODIFIED.
Ensures that the file exists . If the file that is requested to be created is in directories that do not exist these directories are created . If the file already exists it is NOT MODIFIED .
function ensureFileSync(filePath) {
  try {
    const stat = Deno.lstatSync(filePath);
    if (!stat.isFile) {
      throw new Error(
        `Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`,
      );
    }
  } catch (err) {
    if (err instanceof Deno.errors.NotFound) {
      ensureDirSync(path.dirname(filePath));
      Deno.writeFileSync(filePath, new Uint8Array());
      return;
    }
    throw err;
  }
}
function ensureFileSync ( filePath ) { try { const stat = Deno . lstatSync ( filePath ) ; if ( ! stat . isFile ) { throw new Error ( ` ${ getFileInfoType ( stat ) } ` , ) ; } } catch ( err ) { if ( err instanceof Deno . errors . NotFound ) { ensureDirSync ( path . dirname ( filePath ) ) ; Deno . writeFileSync ( filePath , new Uint8Array ( ) ) ; return ; } throw err ; } }
Ensures that the file exists.
Ensures that the file exists .
// if file exists // if file not exists // ensure dir exists // create file