UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const path_1 = tslib_1.__importDefault(require("path"));
5const stream_1 = tslib_1.__importDefault(require("stream"));
6const humanize_list_1 = tslib_1.__importDefault(require("humanize-list"));
7const plugin_error_1 = tslib_1.__importDefault(require("plugin-error"));
8const PLUGIN_NAME = 'assert-files';
9function vinylAssertFiles(expected) {
10 const expectedPaths = new Set(expected.map(path_1.default.normalize));
11 return new stream_1.default.Transform({
12 objectMode: true,
13 transform(file, _, cb) {
14 if (!file.isNull())
15 expectedPaths.delete(file.relative);
16 cb(undefined, file);
17 },
18 flush(cb) {
19 if (expectedPaths.size !== 0) {
20 this.emit('error', new plugin_error_1.default(PLUGIN_NAME, `One or more required files do not exist in the project: ${humanize_list_1.default([...expectedPaths])}`));
21 }
22 cb();
23 },
24 });
25}
26exports.default = vinylAssertFiles;