Skip to content

Commit

Permalink
feat: expose utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed May 15, 2020
1 parent 3b144b7 commit 79d3898
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs'
import { promisify } from 'util'
import glob from 'fast-glob'
import rimraf from 'rimraf'
import mkdirp from 'mkdirp'
import ensureDir from 'mkdirp'
import Wares from './wares'

export type Middleware = (ctx: Majo) => Promise<void> | void
Expand Down Expand Up @@ -185,7 +185,7 @@ export class Majo {
if (this.onWrite) {
this.onWrite(filename, target)
}
return mkdirp(path.dirname(target)).then(() =>
return ensureDir(path.dirname(target)).then(() =>
writeFile(target, contents)
)
})
Expand Down Expand Up @@ -271,4 +271,16 @@ export class Majo {

const majo = () => new Majo()

export { majo, fs, glob }
export { majo, remove, glob, ensureDir }

/**
* Ensure directory exists before writing file
*/
export const outputFile = (
filepath: string,
data: any,
options?: fs.WriteFileOptions
) =>
ensureDir(path.dirname(filepath)).then(() =>
writeFile(filepath, data, options)
)
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path'
import { majo, fs, glob } from '../src'
import { majo, glob, remove } from '../src'

test('main', async () => {
const outputDir = path.join(__dirname, 'output/main')
await fs.remove(outputDir)
await remove(outputDir)
const stream = await majo()
.source('**', { baseDir: path.join(__dirname, 'fixture/source') })
.dest('./output/main', { baseDir: __dirname })
Expand Down

0 comments on commit 79d3898

Please sign in to comment.