documentationjs / documentationjs/documentation
Flow Parsing
- Dominant language
- JavaScript
- Stars
- 5.8k
- Forks
- 481
- PR merge metrics
- No merged PRs in 30d
Description
The following code picks up only the type declarations and the comments. I had to use @name and @memberof to get the levels correct but there's no parameters being picked up (e.g init doesn't have documented parameters). This is functional code which appears to be the problem - traditional instantiation works well.
```'use strict';
import { join } from 'path';
import fsp from 'fs-promise';
import { EventEmitter } from 'events';
/**
* The minimum requirements for a standard file based operation
*/
type minimalFileDescriptorType = {
name:string,
path:Array,
encoding:?string
}
/**
* The minimum requirements for a path operation
*/
type pathFileDescriptorType = {
name:?string,
path:Array
}
/**
* The minimum requirements for a write operation (data/buffer)
*/
type writeFileDescriptorType = {
name:string,
path:Array,
content:string|Buffer,
encoding:?string
}
module.exports = {
/**
* Service requires a configuration and must have dependencies pre-fulfilled
* @name init;
*/
init: (config:Object, services:Object):Promise => Promise.resolve().then(() => {
const { root } = config;
/**
* Local storage operations (local could be NFS mapped of course...)
* Every function has a Many alternative, e.g readMany
*/
const fns = {
/**
* Read a file
* @memberof init;
*/
read: (fD:minimalFileDescriptorType):Promise => fsp
.readFile(join(...root, ...fD.path, fD.name), fD.encoding),
/**
* Read file stream
*/
readStream: (fD:minimalFileDescriptorType):EventEmitter => fsp
.createReadStream(join(...root, ...fD.path, fD.name), fD.encoding),
/**
* Write data to a file
*/
write: (fD:writeFileDescriptorType):Promise => fsp
.writeFile(join(...root, ...fD.path, fD.name), fD.content, fD.encoding),
/**
* Write file stream
*/
writeStream: (fD:minimalFileDescriptorType):EventEmitter => fsp
.createWriteStream(join(...root, ...fD.path, fD.name), fD.encoding),
/**
* Lists directory contents
*/
ls: (path:Array):Promise => fsp
.readdir(join(...root, ...path)),
/**
* Removes a file
*/
rm: (fD:minimalFileDescriptor):Promise => fsp
.unlink(join(...root, ...fD.path, fD.name)),
/**
* Removes a directory. Think rf -rf
*/
rmdir: (path:Array):Promise => fsp
.remove(join(...root, ...path)),
/**
* Checks the existance of a dir or file
*/
stat: (fD:pathFileDescriptorType):Promise => fsp
.stat(join(...root, ...fD.path, fD.name || ''))
.then(() => true)
.catch(() => false),
/**
* Creates a path if it doesn't exist. Think mkdir -p
*/
mkdir: (path:Array):Promise => fsp
.mkdirs(join(...root, ...path)),
/**
* Generates a path representation with which another application can upload to
*/
getUploadUrl: (fD:minimalFileDescriptorType):Promise => Promise.resolve()
.then(() => {
return {
url: 'file://' + join(...root, ...fD.path, fD.name)
};
}),
/**
* Generates a path representation with which another application can download from
*/
getDownloadUrl: (fD:minimalFileDescriptorType):Promise => fns.getUploadUrl(fD)
};
// create Many version of the above
Object.keys(fns)
.forEach(key => {
fns[`${key}Many`] = (paths:Array, ...args) => Promise.all(
paths
.map(path => fns[key](path, ...args))
);
})
return fns;
})
};
```
Contributor guide
Assessment
This issue has not been assessed yet.