UNPKG

stryker-webpack

Version:

[preview] A plugin for Webpack-based projects using Stryker

97 lines 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var PresetLoader_1 = require("./presetLoader/PresetLoader"); var WebpackCompiler_1 = require("./compiler/WebpackCompiler"); var WebpackTranspiler = /** @class */ (function () { function WebpackTranspiler(options) { this.config = options.config; this.presetLoader = new PresetLoader_1.default; } WebpackTranspiler.prototype.transpile = function (files) { return tslib_1.__awaiter(this, void 0, void 0, function () { var _a, err_1; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 5, , 6]); if (!!this.webpackCompiler) return [3 /*break*/, 2]; // Initialize the webpack compiler with the current directory (process.cwd) return [4 /*yield*/, this.initialize(process.cwd(), this.config.webpack)]; case 1: // Initialize the webpack compiler with the current directory (process.cwd) _b.sent(); _b.label = 2; case 2: return [4 /*yield*/, this.webpackCompiler.writeFilesToFs(files)]; case 3: _b.sent(); _a = this.createSuccessResult; return [4 /*yield*/, this.webpackCompiler.emit()]; case 4: return [2 /*return*/, _a.apply(this, [_b.sent()])]; case 5: err_1 = _b.sent(); return [2 /*return*/, this.createErrorResult(err_1.name + ": " + err_1.message)]; case 6: return [2 /*return*/]; } }); }); }; WebpackTranspiler.prototype.initialize = function (projectRoot, strykerWebpackConfig) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: strykerWebpackConfig = this.getStrykerWebpackConfig(strykerWebpackConfig); return [4 /*yield*/, this.initializeCompiler(projectRoot, strykerWebpackConfig)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; WebpackTranspiler.prototype.getStrykerWebpackConfig = function (strykerWebpackConfig) { return { project: (strykerWebpackConfig && strykerWebpackConfig.project) ? strykerWebpackConfig.project : 'default', configLocation: (strykerWebpackConfig && strykerWebpackConfig.configLocation) ? strykerWebpackConfig.configLocation : undefined }; }; WebpackTranspiler.prototype.initializeCompiler = function (projectRoot, strykerWebpackConfig) { return tslib_1.__awaiter(this, void 0, void 0, function () { var preset; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: preset = this.presetLoader.loadPreset(strykerWebpackConfig.project.toLowerCase()); this.webpackCompiler = new WebpackCompiler_1.default(preset.getWebpackConfig(projectRoot, strykerWebpackConfig.configLocation)); // Push the init files to the file system with the replace function return [4 /*yield*/, this.webpackCompiler.writeFilesToFs(preset.getInitFiles(projectRoot))]; case 1: // Push the init files to the file system with the replace function _a.sent(); return [2 /*return*/]; } }); }); }; WebpackTranspiler.prototype.createErrorResult = function (error) { return { error: error, outputFiles: [] }; }; WebpackTranspiler.prototype.createSuccessResult = function (outPutFiles) { return { error: null, outputFiles: outPutFiles }; }; WebpackTranspiler.prototype.getMappedLocation = function (sourceFileLocation) { // Waiting for a decision on how this is going to be implemented in the future // Return a 'Method nog implemented' error for now. throw new Error('Method not implemented.'); }; return WebpackTranspiler; }()); exports.default = WebpackTranspiler; //# sourceMappingURL=WebpackTranspiler.js.map