UNPKG

gherkin

Version:
75 lines 3.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var stream_1 = require("stream"); var cucumber_messages_1 = require("cucumber-messages"); var ParserMessageStream_1 = __importDefault(require("./stream/ParserMessageStream")); var GherkinExe_1 = __importDefault(require("./external/GherkinExe")); var fs_1 = __importDefault(require("fs")); var SourceMessageStream_1 = __importDefault(require("./stream/SourceMessageStream")); var gherkin_languages_json_1 = __importDefault(require("./gherkin-languages.json")); var makeGherkinOptions_1 = __importDefault(require("./makeGherkinOptions")); function fromStream(stream, options) { if (options === void 0) { options = {}; } return stream_1.pipeline(stream, new cucumber_messages_1.BinaryToMessageStream(cucumber_messages_1.messages.Envelope.decodeDelimited), new ParserMessageStream_1.default(options)); } function fromPaths(paths, options) { if (options === void 0) { options = {}; } options = makeGherkinOptions_1.default(options); if (process.env.GHERKIN_EXECUTABLE) { return new GherkinExe_1.default(process.env.GHERKIN_EXECUTABLE, paths, [], options).messageStream(); } var combinedMessageStream = new stream_1.PassThrough({ writableObjectMode: true, readableObjectMode: true, }); function pipeSequentially() { var path = paths.shift(); if (path !== undefined) { var parserMessageStream = new ParserMessageStream_1.default(options); parserMessageStream.on('end', function () { pipeSequentially(); }); var end = paths.length === 0; fs_1.default.createReadStream(path, { encoding: 'utf-8' }) .pipe(new SourceMessageStream_1.default(path)) .pipe(parserMessageStream) .pipe(combinedMessageStream, { end: end }); } } pipeSequentially(); return combinedMessageStream; } function fromSources(envelopes, options) { if (options === void 0) { options = {}; } options = makeGherkinOptions_1.default(options); if (process.env.GHERKIN_EXECUTABLE) { return new GherkinExe_1.default(process.env.GHERKIN_EXECUTABLE, [], envelopes, options).messageStream(); } var combinedMessageStream = new stream_1.PassThrough({ objectMode: true }); function pipeSequentially() { var envelope = envelopes.shift(); if (envelope !== undefined && envelope.source) { var parserMessageStream = new ParserMessageStream_1.default(options); parserMessageStream.pipe(combinedMessageStream, { end: envelopes.length === 0, }); parserMessageStream.on('end', pipeSequentially); parserMessageStream.end(envelope); } } pipeSequentially(); return combinedMessageStream; } function dialects() { return gherkin_languages_json_1.default; } exports.default = { fromPaths: fromPaths, fromStream: fromStream, fromSources: fromSources, dialects: dialects, }; //# sourceMappingURL=Gherkin.js.map