gulp-typescript-helper
Version:
export interface CoreTypeScriptOptions
98 lines • 3.48 kB
JavaScript
;
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT
*/
Object.defineProperty(exports, "__esModule", { value: true });
var mergeValues_1 = require("./mergeValues");
var uglify = require("gulp-uglify");
var del = require("del");
var BuildHelperBase = (function () {
function BuildHelperBase(sourceFolder, destinationFolder, compilerOptions) {
this.sourceFolder = sourceFolder;
this.destinationFolder = destinationFolder;
this._preProcessors = [];
this.sourceMapOptions = {
sourceRoot: void (0)
};
this.compilerOptions
= mergeValues_1.default({}, compilerOptions);
}
BuildHelperBase.prototype.minify = function (value) {
if (value === void 0) { value = true; }
this._minify = value;
return this;
};
BuildHelperBase.prototype.addPreProcess = function (processor) {
this._preProcessors.push(processor);
return this;
};
BuildHelperBase.prototype.execute = function () {
var _this = this;
var from = this.sourceFolder, to = this.destinationFolder;
if (!from)
throw new Error("No source folder.");
if (!to)
throw new Error("No destination folder.");
if (this._clear && from == to)
throw new Error("Cannot clear a source folder.");
var _a = this.compilerOptions, module = _a.module, target = _a.target;
var message = 'Compiling TypeScript: ';
if (module && module != target)
message += target + " " + module;
else
message += target || module;
message += " " + (from == to ? from : (from + ' >> ' + to));
function emitStart() {
console.log(message);
}
if (!this._clear)
emitStart();
var render = this._clear
? del(to + '/**/*').then(function (results) {
if (results && results.length)
console.info("Folder cleared:", to);
emitStart();
return _this.onExecute();
})
: this.onExecute();
render.then(function () {
}, function (err) {
console.warn(message, "FAILED");
console.error(err);
});
return render;
};
BuildHelperBase.prototype.clear = function (value) {
if (value === void 0) { value = true; }
this._clear = value;
return this;
};
BuildHelperBase.prototype.target = function (value) {
this.compilerOptions.target = value;
return this;
};
BuildHelperBase.prototype.module = function (value) {
this.compilerOptions.module = value;
return this;
};
BuildHelperBase.prototype.addOptions = function (options) {
for (var _i = 0, _a = Object.keys(options); _i < _a.length; _i++) {
var key = _a[_i];
this.compilerOptions[key] = options[key];
}
return this;
};
BuildHelperBase.prototype.getPostProcess = function () {
return uglifyPostProcess();
};
return BuildHelperBase;
}());
exports.BuildHelperBase = BuildHelperBase;
function uglifyPostProcess() {
return uglify({
preserveComments: 'license'
});
}
exports.default = BuildHelperBase;
//# sourceMappingURL=BuildHelperBase.js.map