EG/Cesium-1.132/node_modules/gulp-plugin-extras/index.js
2025-08-25 17:48:13 +08:00

44 lines
921 B
JavaScript

import transformStream from 'easy-transform-stream';
import PluginError from './plugin-error.js';
export function gulpPlugin(name, onFile, {
onFinish,
supportsDirectories = false,
supportsAnyType = false,
} = {}) {
return transformStream(
{
objectMode: true,
},
async file => {
if (!supportsAnyType) {
if (file.isNull() && !(supportsDirectories && file.isDirectory())) {
return file;
}
if (file.isStream()) {
throw new PluginError(name, 'Streaming not supported');
}
}
try {
return await onFile(file);
} catch (error) {
throw new PluginError(name, error, {
fileName: file.path,
showStack: true,
});
}
},
onFinish && async function * (stream) {
try {
yield * onFinish(stream);
} catch (error) {
throw new PluginError(name, error, {showStack: true});
}
},
);
}
export {default as PluginError} from './plugin-error.js';