khalyomede/gulp-revisioner

View on GitHub
src/get-revision-value.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { join } from "path";
import getFileHash from "./get-file-hash";

/**
 * Get the revisioned path to the file, with a query string to use cache busting.
 *
 * @param {String} filePath The path to the file being revisioned.
 * @param {String} baseUrl The base URL that is prepended to the revisioned file path.
 * @param {String} fileContent The content of the file being reivsioned.
 */
export default (filePath: string, baseUrl: string, fileContent: string): string => {
    const hash = getFileHash(fileContent);

    return (join(baseUrl, filePath) + `?id=${hash}`).replace(/\\/g, "/");
};