Skip to content

Commit

Permalink
feat(tasks): adds mkdir task
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 18, 2021
1 parent 192ed1c commit b560772
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tasks/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './clear';
export * from './copy';
export * from './exec';
export * from './log';
export * from './mkdir';
export * from './move';
export * from './print';
export * from './raises';
Expand Down
28 changes: 28 additions & 0 deletions src/tasks/create/mkdir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Task, Context } from '../../definitions';
import { getPaths } from '../../helpers/paths';
import { isCancelled } from '../../utils';
import { log } from './log';
import { into } from 'pipettes';
import fs from 'fs-extra';

export interface MkdirOptions {
ensure?: boolean;
}

export function mkdir(
paths: string | string[],
options?: MkdirOptions
): Task.Async {
return async (ctx: Context): Promise<void> => {
into(ctx, log('debug', 'Create directories:', paths));

const opts = Object.assign({ ensure: false }, options);

const dirs = await getPaths(paths, ctx, { glob: false, strict: false });

for (const dir of dirs) {
if (await isCancelled(ctx)) return;
opts.ensure ? fs.ensureDir(dir) : fs.mkdir(dir);
}
};
}

0 comments on commit b560772

Please sign in to comment.