@toreda/build-tools
Version:

88 lines (87 loc) • 3.75 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GulpSteps = void 0;
const gulp_1 = require("gulp");
const nunjucksRender = require('gulp-nunjucks-render');
class GulpSteps {
constructor(run, create, linter, clean, log) {
this.run = run;
this.create = create;
this.clean = clean;
this.linter = linter;
this.log = log.makeLog('GulpSteps');
}
webpack() {
return __awaiter(this, void 0, void 0, function* () {
yield this.run.webpack();
return (0, gulp_1.src)('.', { allowEmpty: true });
});
}
copyContents(srcPattern, destPath) {
return (0, gulp_1.src)(srcPattern).pipe((0, gulp_1.dest)(destPath));
}
createDir(targetPath, overwrite) {
return __awaiter(this, void 0, void 0, function* () {
const targetPaths = Array.isArray(targetPath) ? targetPath : [];
if (typeof targetPath === 'string') {
targetPaths.push(targetPath);
}
for (const target of targetPaths) {
yield this.create.dir(target, overwrite);
}
return (0, gulp_1.src)('.', { allowEmpty: true });
});
}
cleanDir(targetPath, force) {
return __awaiter(this, void 0, void 0, function* () {
const targetPaths = Array.isArray(targetPath) ? targetPath : [];
if (typeof targetPath === 'string') {
targetPaths.push(targetPath);
}
for (const target of targetPaths) {
yield this.clean.dir(target, force);
}
return (0, gulp_1.src)('.', { allowEmpty: true });
});
}
transpile(options) {
return __awaiter(this, void 0, void 0, function* () {
const tsConfigDir = typeof options.tsConfigDirPath === 'string' ? options.tsConfigDirPath : './dist';
const tsConfigFilname = typeof options.tsConfigFilePath === 'string' ? options.tsConfigDirPath : 'tsconfig.json';
return yield this.run.typescript(tsConfigDir, tsConfigFilname);
});
}
lint(tgt) {
return __awaiter(this, void 0, void 0, function* () {
const fnLog = this.log.makeLog('lint');
const summary = yield this.linter.execute(tgt);
if (!summary.status.success) {
const msg = `Linter did not complete successfully due to error code '${summary.status.code}'. ${summary.status.description}.`;
if (tgt.abortOnLimitBreak === true) {
throw new Error(msg);
}
else {
fnLog.error(msg);
}
}
return (0, gulp_1.src)('.', { allowEmpty: true });
});
}
renderNunjucksHtml(templatePath, srcPattern, destPath) {
return (0, gulp_1.src)(srcPattern)
.pipe(nunjucksRender({
path: templatePath
}))
.pipe((0, gulp_1.dest)(destPath));
}
}
exports.GulpSteps = GulpSteps;