Skip to content

Commit

Permalink
feat(exposed/tags): adds rm
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 26, 2019
1 parent 2808b7c commit aba9763
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/exposed/tags/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as ensure } from './ensure';
export { default as exists } from './exists';
export { default as line } from './line';
export { default as rm } from './rm';
export { default as silent } from './silent';
26 changes: 26 additions & 0 deletions src/exposed/tags/rm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import path from 'path';
import fs from 'fs-extra';
import core from '~/core';
import asTag from '~/utils/as-tag';
import { TScript } from '~/types';
import { rejects } from 'errorish';

export default rm;

function rm(path: string): TScript;
function rm(literals: TemplateStringsArray, ...placeholders: any[]): TScript;
/**
* String tag; recursively removes `path`, which 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 `rm` won't have any effect until the returned function is called.
*/
function rm(...args: any[]): TScript {
return async function rm(): Promise<void> {
let file = asTag(args.shift(), ...args);
if (!path.isAbsolute(file)) {
const paths = await core.paths();
file = path.join(paths.directory, file);
}

await fs.remove(file).catch(rejects);
};
}

0 comments on commit aba9763

Please sign in to comment.