UNPKG

@toreda/build-tools

Version:

![Toreda](https://content.toreda.com/logo/toreda-logo.png)

85 lines (84 loc) 3.79 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Run = void 0; const gulp_1 = require("gulp"); const path_1 = __importDefault(require("path")); const gulp_sourcemaps_1 = __importDefault(require("gulp-sourcemaps")); const gulp_typescript_1 = __importDefault(require("gulp-typescript")); const webpack_1 = __importDefault(require("webpack")); const mergeStream = require('merge-stream'); class Run { constructor(cfg, events, log) { if (!cfg) { throw new Error('Run init - cfg arg missing.'); } if (!events) { throw new Error('Run init - events arg missing.'); } this.log = log.makeLog('Run'); this.events = events; this.cfg = cfg; } webpack(options = {}) { const fnLog = this.log.makeLog('webpack'); fnLog.debug('Webpack started'); const cfgPath = this.cfg.getWebpackCfgPath(options); const resolvedPath = path_1.default.resolve(cfgPath); return new Promise((resolve, reject) => { Promise.resolve().then(() => __importStar(require(resolvedPath))).then((webpackConfig) => { (0, webpack_1.default)(webpackConfig, (err, stats) => { if (err) { fnLog.error(`Webpack stopped due to failure: ${err.message}.`); return reject(err); } if (!stats) { throw new Error('weback build failure: no stats in build callback'); } if (stats.hasErrors()) { fnLog.error('webpack build error: '); stats.compilation.errors.forEach((error) => { fnLog.error(error); }); return reject(stats.compilation.errors.join('\n')); } resolve((0, gulp_1.src)('.', { allowEmpty: true })); }); }); }); } typescript(destPath, tsConfigPath) { const outputPath = typeof destPath === 'string' ? destPath : 'dist'; const useConfigPath = tsConfigPath ? tsConfigPath : './tsconfig.json'; const tsConfig = require(path_1.default.resolve(useConfigPath)); const filesGlob = tsConfig.filesGlob; const tsResult = (0, gulp_1.src)(filesGlob).pipe((0, gulp_typescript_1.default)(tsConfig.compilerOptions)); return mergeStream(tsResult, tsResult.js).pipe(gulp_sourcemaps_1.default.write('.')).pipe((0, gulp_1.dest)(outputPath)); } } exports.Run = Run;