How to use userscript-metadata - 10 common examples

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.ts View on Github external
hostedAt: null,
    mainFile: "main.ts",
    mode: Mode.development,
    nightly: false,
    now: x.now,
    outDir: "dist",
    rootDir: x.rootDir,
    sassVariableGetter: "getGlobal",
    sassVariables: {},
    sourceDir: "src",
    verbose: false,
});

export const DEFAULT_METADATA_SCHEMA: Metadata.ValidateOptions = {
    items: {
        ...Metadata.DEFAULT_ITEMS,
        version: Metadata.DEFAULT_ITEMS.version.butRequired(), // Validated against a subset of SemVer by default.
        run_at: Metadata.DEFAULT_ITEMS.run_at.butRequired(),
    },
    warnings: Metadata.DEFAULT_WARNINGS,
    underscoresAsHyphens: true,
} as const;

export function createWebpackConfig(x: WebpackConfigParameters): webpack.Configuration {
    const buildConfig = (
        // We intentionally ignore any errors here; they will be handled by our Webpack plugin.
        overrideBuildConfig(x.buildConfig, x.env).buildConfig
    );
    const {
        allowJs,
        id,
        mainFile,
github SimonAlling / userscripter / src / build / internal / webpack.ts View on Github external
mainFile: "main.ts",
    mode: Mode.development,
    nightly: false,
    now: x.now,
    outDir: "dist",
    rootDir: x.rootDir,
    sassVariableGetter: "getGlobal",
    sassVariables: {},
    sourceDir: "src",
    verbose: false,
});

export const DEFAULT_METADATA_SCHEMA: Metadata.ValidateOptions = {
    items: {
        ...Metadata.DEFAULT_ITEMS,
        version: Metadata.DEFAULT_ITEMS.version.butRequired(), // Validated against a subset of SemVer by default.
        run_at: Metadata.DEFAULT_ITEMS.run_at.butRequired(),
    },
    warnings: Metadata.DEFAULT_WARNINGS,
    underscoresAsHyphens: true,
} as const;

export function createWebpackConfig(x: WebpackConfigParameters): webpack.Configuration {
    const buildConfig = (
        // We intentionally ignore any errors here; they will be handled by our Webpack plugin.
        overrideBuildConfig(x.buildConfig, x.env).buildConfig
    );
    const {
        allowJs,
        id,
        mainFile,
        mode,
github SimonAlling / userscripter / .userscripter / build / metadata.ts View on Github external
                errors.some(e => e.kind !== Kind.INVALID_KEY) // Key rules cannot be customized.
                ? "\n" + Msg.metadataValidationHint
github SimonAlling / userscripter / src / build / internal / webpack.ts View on Github external
now: x.now,
    outDir: "dist",
    rootDir: x.rootDir,
    sassVariableGetter: "getGlobal",
    sassVariables: {},
    sourceDir: "src",
    verbose: false,
});

export const DEFAULT_METADATA_SCHEMA: Metadata.ValidateOptions = {
    items: {
        ...Metadata.DEFAULT_ITEMS,
        version: Metadata.DEFAULT_ITEMS.version.butRequired(), // Validated against a subset of SemVer by default.
        run_at: Metadata.DEFAULT_ITEMS.run_at.butRequired(),
    },
    warnings: Metadata.DEFAULT_WARNINGS,
    underscoresAsHyphens: true,
} as const;

export function createWebpackConfig(x: WebpackConfigParameters): webpack.Configuration {
    const buildConfig = (
        // We intentionally ignore any errors here; they will be handled by our Webpack plugin.
        overrideBuildConfig(x.buildConfig, x.env).buildConfig
    );
    const {
        allowJs,
        id,
        mainFile,
        mode,
        nightly,
        now,
        outDir,
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());
            },
        );
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());
            },
        );
github SimonAlling / userscripter / .userscripter / build / messages.ts View on Github external
export const metadataError = (error: ValidationError) => {
    switch (error.kind) {
        case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
        case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
        case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
        case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
        case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
        default: throw new Error("Unknown metadata error.");
    }
}
github SimonAlling / userscripter / .userscripter / build / messages.ts View on Github external
export const metadataError = (error: ValidationError) => {
    switch (error.kind) {
        case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
        case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
        case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
        case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
        case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
        default: throw new Error("Unknown metadata error.");
    }
}
github SimonAlling / userscripter / .userscripter / build / messages.ts View on Github external
export const metadataError = (error: ValidationError) => {
    switch (error.kind) {
        case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
        case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
        case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
        case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
        case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
        default: throw new Error("Unknown metadata error.");
    }
}
github SimonAlling / userscripter / .userscripter / build / messages.ts View on Github external
export const metadataError = (error: ValidationError) => {
    switch (error.kind) {
        case Kind.INVALID_KEY: return `Invalid key: "${error.entry.key}". ${error.reason}`;
        case Kind.INVALID_VALUE: return `Invalid ${tag(error.entry.key)} value: ${JSON.stringify(error.entry.value)}. ${error.reason}`;
        case Kind.MULTIPLE_UNIQUE: return `Multiple ${tag(error.item.key)} values. Only one value is allowed.`;
        case Kind.REQUIRED_MISSING: return `A ${tag(error.item.key)} entry is required, but none was found.`;
        case Kind.UNRECOGNIZED_KEY: return `Unrecognized key: "${error.entry.key}".`;
        default: throw new Error("Unknown metadata error.");
    }
}