How to use the userscript-metadata.isLeft function in userscript-metadata

To help you get started, we’ve selected a few userscript-metadata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SimonAlling / userscripter / src / build / internal / webpack-plugin.ts View on Github external
compilation => {
                const logger = compilation.getLogger(UserscripterWebpackPlugin.name);
                // Validate environment variables:
                const overridden = overrideBuildConfig(w.buildConfig, w.env);
                compilation.errors.push(...overridden.errors.map(compose(Error, Msg.envVarError)));
                // Validate build config:
                const configErrors = buildConfigErrors(overridden.buildConfig);
                compilation.errors.push(...configErrors.map(compose(Error, Msg.buildConfigError)));
                // Validate metadata:
                const metadataValidationResult = Metadata.validateWith(w.metadataSchema)(w.metadata(w.buildConfig));
                if (Metadata.isLeft(metadataValidationResult)) {
                    compilation.errors.push(...metadataValidationResult.Left.map(compose(Error, Msg.metadataError)));
                } else {
                    compilation.warnings.push(...metadataValidationResult.Right.warnings.map(Msg.metadataWarning));
                }
                // Log metadata:
                const metadataAsset = distFileName(w.buildConfig.id, "meta");
                logger.info((compilation.assets[metadataAsset] as RawSource).source());
            },
        );