Closed lukeed closed 7 years ago
Now that I see this, external plugins should also accept a name
key.
Doing so will convert the API to plugin(opts, [func]) for both inline & external plugins.
// external
this.plugin({
name: 'myName',
files: false,
every: false,
*func(arr) {
// `arr` is all globs
}
})
// external w/defaults
this.plugin({
name: 'myName',
*func(file) {
// loop each `file` object
}
})
@lukeed Good new, but can you clarify:
This allows for cleaner plugin (inline & external) definitions; especially if relying on the default every and files settings.
How does it make it cleaner? The examples, I think, show the new syntax. Can we get an example using the older / less clean syntax?
Current: plugin(name, opts, func)
this.plugin('nyName', {every: false}, function * (files, opts) {
// files: all file objects
// opts: user options
});
@lukeed Thanks.
@jbucaran No problem. So what do you think on the newer suggestion?
It also could mean for simpler external plugins (aka, installed via NPM):
// current
module.exports = function () {
this.plugin('myName', {every: false}, function * (files, opts) {
// files: all file objects
// opts: user options
});
}
// with proposed change
module.exports = {
name: 'myName',
every: false,
*func(files, opts) {
// files: all file objects
// opts: user options
}
}
cc: @devmondo @hzlmn @watilde
@lukeed Proposed style is easier to not mess up, since you don't need to remember that name comes first, etc.
Current: plugin(name, opts, func)
The
func
parameter should be read as the fallback.This allows for cleaner plugin (inline & external) definitions; especially if relying on the default
every
andfiles
settings.Reference: https://github.com/flyjs/fly/issues/233#issuecomment-274749015