@roots/bud-build
Version:
bud.js core module
293 lines (292 loc) • 6.3 kB
JavaScript
import { __decorate } from "tslib";
import Registrable from '@roots/bud-build/helpers/registrable';
import { bind } from '@roots/bud-support/decorators/bind';
import isFunction from '@roots/bud-support/isFunction';
import isString from '@roots/bud-support/isString';
import logger from '@roots/bud-support/logger';
/**
* RuleSetRule
*/
class Rule extends Registrable {
/**
* RuleSetRule exclude
*/
exclude;
/**
* RuleSetRule generator
*/
generator;
/**
* RuleSetRule include
*/
include;
/**
* RuleSetRule issuer
*/
issuer;
/**
* RuleSetRule parser
*/
parser;
/**
* RuleSetRule resolve
*/
resolve;
/**
* RuleSetRule resourceQuery
*/
resourceQuery;
/**
* RuleSetRule test
*/
test;
/**
* RuleSetRule type
*/
type;
/**
* RuleSetRule use
*/
use;
/**
* Class constructor
*/
constructor(_app, options) {
super(_app);
this._app = _app;
if (!options)
return;
this.setTest(options.test);
this.setUse(options.use);
this.setInclude(options.include);
this.setExclude(options.exclude);
this.setType(options.type);
this.setParser(options.parser);
this.setGenerator(options.generator);
this.setResolve(options.resolve);
}
/**
* Get `exclude` value
*/
getExclude() {
return this.exclude?.map(this.unwrap);
}
/**
* Get generator value
*/
getGenerator() {
return this.unwrap(this.generator);
}
/**
* Get `include` value
*/
getInclude() {
return this.include?.map(this.unwrap);
}
/**
* Get `issuer` value
*/
getIssuer() {
return this.issuer;
}
/**
* Get `parser` value
*/
getParser() {
return this.unwrap(this.parser);
}
/**
* Set resolve value
*/
getResolve() {
return this.unwrap(this.resolve);
}
/**
* Get `include` value
*/
getResourceQuery() {
return isFunction(this.resourceQuery)
? this.resourceQuery(this.app)
: this.resourceQuery;
}
/**
* Get `test` value
*/
getTest() {
return this.unwrap(this.test);
}
/**
* Get `type` value
*/
getType() {
return this.unwrap(this.type);
}
/**
* Get `use` value
*/
getUse() {
return this.use;
}
/**
* Set exclude value
*/
setExclude(excludes) {
this.exclude = isFunction(excludes) ? excludes(this.exclude) : excludes;
return this;
}
/**
* Set generator value
*/
setGenerator(generator) {
this.generator = this.wrap(generator);
return this;
}
/**
* Set `include` value
*/
setInclude(includes) {
this.include = isFunction(includes) ? includes(this.include) : includes;
return this;
}
/**
* Set `issuer` value
*/
setIssuer(issuer) {
this.issuer = issuer;
return this;
}
/**
* Set `parser` value
*/
setParser(parser) {
this.parser = this.wrap(parser);
return this;
}
/**
* Set resolve value
*/
setResolve(resolve) {
this.resolve = resolve;
return this;
}
/**
* Set `include` value
*/
setResourceQuery(query) {
this.resourceQuery = isFunction(query)
? query(this.resourceQuery)
: query;
return this;
}
/**
* Set `test` value
*/
setTest(test) {
this.test = test;
return this;
}
/**
* Set type value
*/
setType(type) {
this.type = type;
return this;
}
/**
* Set `use` value
*/
setUse(use) {
this.use = isFunction(use) ? use(this.getUse()) : use;
return this;
}
/**
* Produce final Base output
*/
toWebpack() {
const output = Object.entries({
exclude: this.getExclude(),
generator: this.getGenerator(),
include: this.getInclude(),
issuer: this.getIssuer(),
parser: this.getParser(),
resolve: this.getResolve(),
resourceQuery: this.getResourceQuery(),
test: this.getTest(),
type: this.getType(),
use: this.getUse()
?.filter(Boolean)
.map(item => isString(item) && item in this.app.build.items
? this.app.build.items[item]
: item)
.filter(Boolean)
.map(item => !isString(item) && `toWebpack` in item ? item.toWebpack() : item),
}).reduce((a, [k, v]) => {
if (v === undefined)
return a;
return { ...a, [k]: v };
}, {});
logger.info(`built rule`, output);
return output;
}
}
__decorate([
bind
], Rule.prototype, "getExclude", null);
__decorate([
bind
], Rule.prototype, "getGenerator", null);
__decorate([
bind
], Rule.prototype, "getInclude", null);
__decorate([
bind
], Rule.prototype, "getIssuer", null);
__decorate([
bind
], Rule.prototype, "getParser", null);
__decorate([
bind
], Rule.prototype, "getResourceQuery", null);
__decorate([
bind
], Rule.prototype, "getTest", null);
__decorate([
bind
], Rule.prototype, "getType", null);
__decorate([
bind
], Rule.prototype, "getUse", null);
__decorate([
bind
], Rule.prototype, "setExclude", null);
__decorate([
bind
], Rule.prototype, "setGenerator", null);
__decorate([
bind
], Rule.prototype, "setInclude", null);
__decorate([
bind
], Rule.prototype, "setIssuer", null);
__decorate([
bind
], Rule.prototype, "setParser", null);
__decorate([
bind
], Rule.prototype, "setResolve", null);
__decorate([
bind
], Rule.prototype, "setResourceQuery", null);
__decorate([
bind
], Rule.prototype, "setTest", null);
__decorate([
bind
], Rule.prototype, "setType", null);
__decorate([
bind
], Rule.prototype, "setUse", null);
__decorate([
bind
], Rule.prototype, "toWebpack", null);
export { Rule as default };