@tsdi/pack
Version:
@tsdi/pack is simple build tasks, base on AOP, Ioc container, via @tsdi. dev build pack activities.
137 lines (135 loc) • 4.79 kB
JavaScript
import { __awaiter, __decorate, __metadata } from "tslib";
import { isArray, isNullOrUndefined, isString } from '@tsdi/ioc';
import { Input } from '@tsdi/components';
import { Task } from '@tsdi/activities';
import { rollup } from 'rollup';
import { NodeActivity } from '../NodeActivity';
/**
* rollup activity.
*
* @export
* @class RollupActivity
* @extends {NodeActivity<void>}
*/
let RollupActivity = class RollupActivity extends NodeActivity {
execute(ctx) {
return __awaiter(this, void 0, void 0, function* () {
let opts = yield ctx.resolveExpression(this.options);
opts = opts || { input: '' };
yield Promise.all(this.getInputProps()
.map((n) => __awaiter(this, void 0, void 0, function* () {
let val = yield ctx.resolveExpression(this[n]);
this.setOptions(ctx, opts, n, val);
})));
yield Promise.all((isArray(opts.output) ? opts.output : [opts.output]).map((output) => __awaiter(this, void 0, void 0, function* () {
if (this.sourcemap) {
let sourceMap = yield ctx.resolveExpression(this.sourcemap);
if (sourceMap) {
output.sourcemap = isString(sourceMap) ? true : sourceMap;
}
}
if (this.globals) {
let globals = yield ctx.resolveExpression(this.globals);
output.globals = globals;
}
else {
output.globals = {};
}
if (isArray(opts.external) && opts.external.length) {
opts.external = this.vailfExternal(opts.external);
opts.external.forEach(k => {
if (output.globals[k]) {
output.globals[k] = k;
}
});
}
if (output.file) {
output.file = ctx.platform.toRootPath(output.file);
}
if (output.dir) {
output.dir = ctx.platform.toRootPath(output.dir);
}
if (!output.name && output.file) {
output.name = ctx.platform.getFileName(output.file);
}
yield this.resolvePlugins(ctx, opts);
if (opts.plugins) {
opts.plugins = opts.plugins.filter(p => p);
}
let bundle = yield rollup(opts);
yield bundle.write(output);
}))).catch(err => {
console.error(err);
throw err;
});
});
}
getInputProps() {
return ['input', 'output', 'plugins', 'external', 'cache', 'watch'];
}
setOptions(ctx, opts, key, val) {
if (key === 'input') {
val = ctx.platform.toRootSrc(val);
}
if (isArray(val) && val.length) {
val = val.filter(f => !isNullOrUndefined(f));
if (val.length) {
opts[key] = val;
}
}
else if (val) {
opts[key] = val;
}
}
vailfExternal(external) {
return external || [];
}
resolvePlugins(ctx, opts) {
return __awaiter(this, void 0, void 0, function* () {
});
}
static ρAnn() {
return { "name": "RollupActivity", "params": { "execute": ["ctx"], "setOptions": ["ctx", "opts", "key", "val"], "vailfExternal": ["external"], "resolvePlugins": ["ctx", "opts"] } };
}
};
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "input", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "output", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "plugins", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "external", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "globals", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "sourcemap", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "cache", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "options", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], RollupActivity.prototype, "watch", void 0);
RollupActivity = __decorate([
Task('rollup')
], RollupActivity);
export { RollupActivity };
//# sourceMappingURL=../sourcemaps/rollups/RollupActivity.js.map