Skip to content

Commit

Permalink
feat(exposed/exists): adds exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 26, 2019
1 parent 6e7efb2 commit 758ad8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/exposed/file/exists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import core from '~/core';
import { exists as _exists } from '~/utils/file';

/**
* Verifies `file` exists and throws if it doesn't. `file` can be either a file or a directory, and be relative to the project's directory.
* @returns A `TScript`, as a function, that won't be executed until called by `kpo` -hence, calling `exists` won't have any effect until the returned function is called.
*/
export default function exists(file: string) {
return async function exists(): Promise<void> {
if (!path.isAbsolute(file)) {
const paths = await core.paths();
file = path.join(paths.directory, file);
}
await _exists(file, { fail: true });
};
}
1 change: 1 addition & 0 deletions src/exposed/file/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as json } from './json';
export { default as exists } from './exists';

0 comments on commit 758ad8d

Please sign in to comment.