Skip to content

Commit

Permalink
types, fixes egoist#12
Browse files Browse the repository at this point in the history
  • Loading branch information
stroncium committed Jun 16, 2019
1 parent 4ada23f commit 439a065
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ import Wares from './wares'

class MajoFiles {
constructor(majo, files, meta) {
/**
* @type {Majo}
*/
this.majo = majo
/**
* @typedef {{path: string, stats: fs.Stats, contents: Buffer}} File
* @type {{[relativePath: string]: File}}
*/
this.files = files
/**
* An object you can use across middleware to share states
* @type {{[k: string]: any}}
*/
this.meta = meta
}

Expand Down Expand Up @@ -92,12 +103,21 @@ class MajoFiles {
return Object.keys(this.files).sort()
}

/**
* Rename file
* @param {string} fromPath
* @param {string} toPath
*/
rename(fromPath, toPath) {
this.createFile(toPath, this.files[fromPath])
this.deleteFile(fromPath)
return this
}

/**
* Write all current resuting files
* @param {string} destPath
*/
async writeToPath(destPath) {
await Promise.all(
Object.keys(this.files).map(filename => {
Expand Down Expand Up @@ -159,10 +179,6 @@ class Majo extends EventEmitter {
stats: true
})

/**
* @typedef {{path: string, stats: fs.Stats, contents: Buffer}} File
* @type {{[relativePath: string]: File}}
*/
const files = {}

await Promise.all(
Expand All @@ -174,10 +190,17 @@ class Majo extends EventEmitter {
})
)

/**
* @type {MajoFiles}
*/
this.majoFiles = new MajoFiles(this, files, this.meta)

await new Wares().use(this.middlewares).run(this.majoFiles)

/**
* @typedef {{path: string, stats: fs.Stats, contents: Buffer}} File
* @type {{[relativePath: string]: File}}
*/
this.files = this.majoFiles.files

return this
Expand Down

0 comments on commit 439a065

Please sign in to comment.