@aboutweb/irrigable 中文文档教程
irrigable
在 gulp 之上的 Streams API,连接各种构建工具。
该项目处于早期 alpha 阶段,未进行测试且界面不稳定,敬请期待更新。
Motivation
gulp 中最大的问题之一是跟踪依赖关系,并且不支持开箱即用的 ES7 或 Typescript 中的配置。
另一方面,webpack 和 rollups 很难提供代码拆分和外部资源,如 CSS 或图像。 在这些资源上使用 import 不向前兼容,而且很可能永远不会。
The Idea
这个 API 在很大程度上受到 gulp 及其流设计的启发。 Irrigable 本身已经是一个可以写入的转换流。 配置可以像结构一样组织成树状结构,因此如果附加了输入,它也可以回退到其祖先之一。
irrigable 不是提供一个大的配置,而是将它们分成更小、更容易管理的块。
Config
Nodes
所有选项都是可选的,大多数将使用父节点值作为后备。
{
cwd : String = parent.cwd || process.cwd(),
base : String = parent.base || ".",
writeBase : String = parent.writeBase || ".",
env : String | Array<String> = parent.env,
extend : Boolean = true,
last : Boolean = true,
break : Boolean = true,
fork : Boolean = false,
traverse : Function | defaultHandler,
filter : GlobString | Array<GlobString>,
micromatch : Object,
contents : Boolean = true,
cache : Object = parent.cache,
split : Boolean = parent.split || true,
watch : Boolean = parent.watch || false,
error : Function = parent.error || console.warn
sourcemap : Boolean = parent.sourcemap || false
providers : Array<String | Invocable | instanceof ReadableStream> = [],
pipecompose : Function | defaultHandler,
inputs : Input | Array<Input> = [],
pipline : Array<Invocable> = [],
outputs : Invocable | Array<Invocable> = null,
tasks : Object<String, Node> = {},
complete : Function = noop
rules : Array<Node> = [],
nodes : Array<Node> = []
}
Inputs
该流将在树上冒泡,试图匹配一个或多个节点。 输入将接收发出转换的流作为最后一个参数。
{
task : String,
last : Boolean,
glob : String
pipline : Array<Invocable>,
outputs : Invocable | Array<Invocable>,
complete : Function | noop,
sync : Function | noop,
}
Invocable
使内部差异和散列更可靠。
function
| {
[construct | invoke] : String | Function
args : Object | Array<Object>
}
如果 options 是它自己的函数,调用应该在它内部处理,并且稍后返回的函数应该至少包含一个可用于区分未来更新的属性。 如果 invoke 或 construct 是一个字符串,这将需要给定的模块,该模块应该导出一个函数。
CLI
CLI 将向根流写入一个新的配置,可能有以下选项:
short | long |
---|---|
-p | --providers |
-w | --watch |
-i | --inputs |
-o | --outputs |
-v | --verbose |
Providers
使用提供程序,您可以添加子
ArrayProvider(array
)
配置将配置数组推送到节点,这不会监视更改。
array
:应该发出的值
Example
const ArrayProvider = require("@aboutweb/irrigable/provider/array.js");
new ArrayProvider([
{ inputs : ["./some.config"]}
]);
ImportProvider(options
, parent
)
将找到所有匹配的文件使用汇总构建它们,内联执行它们并发出其 module.exports。 这也将监视变化。
<代码>选项:{
glob : GlobString | 数组
,
cwd : String = parent.cwd || 进程.cwd()
,
基础 : String = parent.base || "."
,
观看 : Boolean = parent.watch || 假的
,
错误 : Function = parent.error || 控制台警告
,
管道 : Array
},
parent:调用提供者
const irrigable = require("@aboutweb/irrigable");
const ImportProvider = require("@aboutweb/irrigable/provider/import.js");
const node = irrigable.addNode({
providers : [{
construct : ImportProvider,
args : {
glob : ["./**/build.js"]
}
}]
});
//shorthand
const short = irrigable.addNode({
providers : ["./**/build.js"]
});
Processors
Transforms
Licence
ISC的 Object = {}
节点
irrigable
Streams API on top of gulp, connecting various build tools.
The project is in an early alpha, no testing and unstable interface, stay tuned for updates.
Motivation
One of the biggest Problems in gulp is tracking dependencies, and configs in ES7 or Typescript are not supported out of the box.
On the other hand webpack and rollups having hard times providing code spliting and external resources like CSS or images. Using import on these resources is not forward compatible and will most likly never be.
The Idea
This API is heavily inspired by gulp and its stream design. Irrigable its self is already a transform stream one can write to. Configs can be organized as a tree like struct, so if an input is attached it can also fall back to one of its ancestors.
Instead of providing one big config irrigable aims to seperate these in smaller easier managable chunks.
Config
Nodes
All options are optional, most will use the parent node value as fallback.
{
cwd : String = parent.cwd || process.cwd(),
base : String = parent.base || ".",
writeBase : String = parent.writeBase || ".",
env : String | Array<String> = parent.env,
extend : Boolean = true,
last : Boolean = true,
break : Boolean = true,
fork : Boolean = false,
traverse : Function | defaultHandler,
filter : GlobString | Array<GlobString>,
micromatch : Object,
contents : Boolean = true,
cache : Object = parent.cache,
split : Boolean = parent.split || true,
watch : Boolean = parent.watch || false,
error : Function = parent.error || console.warn
sourcemap : Boolean = parent.sourcemap || false
providers : Array<String | Invocable | instanceof ReadableStream> = [],
pipecompose : Function | defaultHandler,
inputs : Input | Array<Input> = [],
pipline : Array<Invocable> = [],
outputs : Invocable | Array<Invocable> = null,
tasks : Object<String, Node> = {},
complete : Function = noop
rules : Array<Node> = [],
nodes : Array<Node> = []
}
Inputs
This streams will bubble up the tree trying to match one or more nodes. Inputs will receive the stream that issued the transformation as last argument.
{
task : String,
last : Boolean,
glob : String
pipline : Array<Invocable>,
outputs : Invocable | Array<Invocable>,
complete : Function | noop,
sync : Function | noop,
}
Invocable
Makes internal diffing and hashing more reliable.
function
| {
[construct | invoke] : String | Function
args : Object | Array<Object>
}
if options is a function it self, invocation should be handled inside it and the later returned function should contain at least a property that can used for diffing future updates. if invoke or construct is a String, this will require the given module which should export a function.
CLI
The CLI will write a new config to the root stream, with the following options possible:
short | long |
---|---|
-p | --providers |
-w | --watch |
-i | --inputs |
-o | --outputs |
-v | --verbose |
Providers
With providers you can add Subconfigs
ArrayProvider(array
)
Push an array of configs the the node, this will not watch for changes.
array
: values that should get emitted
Example
const ArrayProvider = require("@aboutweb/irrigable/provider/array.js");
new ArrayProvider([
{ inputs : ["./some.config"]}
]);
ImportProvider(options
, parent
)
Will find all matching files build them using rollup, execute them inline and emit its module.exports. This will also watch for changes.
options
: {
glob : GlobString | Array<GlobString>
,
cwd : String = parent.cwd || process.cwd()
,
base : String = parent.base || "."
,
watch : Boolean = parent.watch || false
,
error : Function = parent.error || console.warn
,
pipeline : Array<Invocable> = [],
},
parent : Object = {}
node that invoked the provider
const irrigable = require("@aboutweb/irrigable");
const ImportProvider = require("@aboutweb/irrigable/provider/import.js");
const node = irrigable.addNode({
providers : [{
construct : ImportProvider,
args : {
glob : ["./**/build.js"]
}
}]
});
//shorthand
const short = irrigable.addNode({
providers : ["./**/build.js"]
});
Processors
Transforms
Licence
ISC