-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import core from '~/core'; | ||
import { TScript } from '~/types'; | ||
import asTag from '~/utils/as-tag'; | ||
import { rejects } from 'errorish'; | ||
|
||
export default ensure; | ||
|
||
function ensure(directory: string): TScript; | ||
function ensure( | ||
literals: TemplateStringsArray, | ||
...placeholders: any[] | ||
): TScript; | ||
/** | ||
* String tag; ensures `directory` exists -if it doesn't it creates it. `directory` can be relative to the project's directory. | ||
* @returns A `TScript`, as a function, that won't be executed until called by `kpo` -hence, calling `ensure` won't have any effect until the returned function is called. | ||
*/ | ||
function ensure(...args: any[]): TScript { | ||
return async function ensure(): Promise<void> { | ||
let directory = asTag(args.shift(), ...args); | ||
if (!path.isAbsolute(directory)) { | ||
const paths = await core.paths(); | ||
directory = path.join(paths.directory, directory); | ||
} | ||
|
||
await fs.ensureDir(directory).catch(rejects); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as ensure } from './ensure'; | ||
export { default as line } from './line'; | ||
export { default as silent } from './silent'; |