@aboviq/kollektor 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

@aboviq/kollektor

构建状态 NPM 版本 XO code style

通用文件收集器,对单存储库和微服务很有用

Installation

安装 @aboviq/kollektor 使用 npm

npm install @aboviq/kollektor

Usage

Module usage

const kollektor = require('@aboviq/kollektor');

// Read all package.json files in a mono-repo async:
const packages = await kollektor({
    handlers: {
        'package.json': packageFile => require(packageFile)
    }
});

// ...or sync:
const packages = kollektor.sync({
    handlers: {
        'package.json': packageFile => require(packageFile)
    }
});

API

kollektor(options)

Name Type Description
options Object Options for specifying the behaviour of Kollektor

返回:Promise>,所有收集的信息取决于给定的处理程序

kollektor.sync(options)

Name Type Description
options Object Options for specifying the behaviour of Kollektor

返回:Array,所有根据给定的处理程序收集的信息。

Options

options.cwd

类型:字符串
默认值:process.cwd()

设置当前工作目录

options.handlers

类型:Object

示例:

{
    "handlers": {
        "package.json": () => {},
        "*.yml": () => {},
        "README.md": () => {}
    }
}
Handler definition

类型:Function
签名:handlerName :: String -> 对象 -> Object

handlerName 是处理程序的名称,通常是一个文件名,例如 "package.json" 它将为每个 package.json 文件调用处理程序发现。 handlerName 也可以是匹配多个文件的简单模式,例如:"*.yml"

当找到与 handlerName 匹配的文件时,将使用这些参数调用处理函数:

Name Type Description
fullPath String The full path to the found file
data Object This contains dir (the relative path of the folder), dirPath (the full path of the folder) and all data returned from previous handlers affecting the same folder

对于 Kollektor 的异步版本,处理函数可以是异步的(返回承诺),但对于同步版本必须是同步的版本。

从处理程序返回的任何 Object 都与当前文件夹的 data 合并,并将被馈送到影响同一文件夹中文件的下一个处理程序。 当针对特定文件夹调用并完成所有处理程序后,生成的 data 就是在收集信息的 Array 中返回的内容。 有关其工作原理的更多详细信息,请参阅测试。

Contributing

请参阅贡献指南和我们的行为准则

License

麻省理工学院 © Aboviq AB

@aboviq/kollektor

Build status NPM version XO code style

Generic file collector, useful for mono repos and microservices

Installation

Install @aboviq/kollektor using npm:

npm install @aboviq/kollektor

Usage

Module usage

const kollektor = require('@aboviq/kollektor');

// Read all package.json files in a mono-repo async:
const packages = await kollektor({
    handlers: {
        'package.json': packageFile => require(packageFile)
    }
});

// ...or sync:
const packages = kollektor.sync({
    handlers: {
        'package.json': packageFile => require(packageFile)
    }
});

API

kollektor(options)

Name Type Description
options Object Options for specifying the behaviour of Kollektor

Returns: Promise<Array<Object>>, all collected information depending on given handlers.

kollektor.sync(options)

Name Type Description
options Object Options for specifying the behaviour of Kollektor

Returns: Array<Object>, all collected information depending on given handlers.

Options

options.cwd

Type: String
Default: process.cwd()

Sets the current working directory

options.handlers

Type: Object<Handler>

Example:

{
    "handlers": {
        "package.json": () => {},
        "*.yml": () => {},
        "README.md": () => {}
    }
}
Handler definition

Type: Function
Signature: handlerName :: String -> Object -> Object

handlerName is the name of the handler and is usually a filename, e.g. "package.json" which will call the handler for each package.json file it finds. The handlerName can also be a simple pattern matching multiple files, e.g: "*.yml".

When a file is found that matches the handlerName the handler function will be called with these arguments:

Name Type Description
fullPath String The full path to the found file
data Object This contains dir (the relative path of the folder), dirPath (the full path of the folder) and all data returned from previous handlers affecting the same folder

The handler function can be async (return a promise) for the asynchronous version of Kollektor but must be synchronous for the sync version.

Any Object returned from a handler is merged with the current folder's data and will be fed to the next handler affecting files in the same folder. When all handlers have been called and completed for a specific folder the resulting data is what's being returned in the Array of collected information. See the tests for more details on how it works.

Contributing

See Contribution Guidelines and our Code Of Conduct.

License

MIT © Aboviq AB

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文