{"id":21077675,"url":"https://github.com/loo2k/moz-rev-all","last_synced_at":"2025-09-01T12:38:17.080Z","repository":{"id":57303396,"uuid":"62602461","full_name":"loo2k/moz-rev-all","owner":"loo2k","description":"Fork from https://github.com/smysnk/gulp-rev-all","archived":false,"fork":false,"pushed_at":"2016-07-05T09:38:55.000Z","size":407,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T21:12:54.929Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loo2k.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-05T03:13:21.000Z","updated_at":"2016-07-05T09:00:30.000Z","dependencies_parsed_at":"2022-09-17T21:30:44.854Z","dependency_job_id":null,"html_url":"https://github.com/loo2k/moz-rev-all","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fmoz-rev-all","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fmoz-rev-all/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fmoz-rev-all/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loo2k%2Fmoz-rev-all/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loo2k","download_url":"https://codeload.github.com/loo2k/moz-rev-all/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521288,"owners_count":20304187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T19:37:47.228Z","updated_at":"2025-03-14T04:11:29.856Z","avatar_url":"https://github.com/loo2k.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [gulp](https://github.com/wearefractal/gulp)-rev-all [![Build Status](https://travis-ci.org/smysnk/gulp-rev-all.png?branch=master)](https://travis-ci.org/smysnk/gulp-rev-all)\n\n\u003e Static asset revisioning with dependency considerations, appends content hash to each filename (eg. unicorn.css =\u003e unicorn.098f6bcd.css), re-writes references.\n\n\n## Purpose\n\nBy using the HTTP server response header ``expires`` combined with filename revisioning, static assets can be made cacheable for extended periods of time. Returning visitors will have the assets cached for super fast load times.\n\nAdditionally, content distribution networks like [CloudFront](http://aws.amazon.com/cloudfront/) let you cache static assets in [Edge Locations](http://aws.amazon.com/about-aws/globalinfrastructure/) for extended periods of time.\n\n\n## Why fork?\n\nThis project was forked from [gulp-rev](https://github.com/sindresorhus/gulp-rev) to add reference processing and rewriting functionality.  \nIt is the philosophy of `gulp-rev` that concerns should be seperated between revisioning the files and re-writing references to those files.  `gulp-rev-all` does not agree with this, we believe you need to analyze each revisioned files' references, to calculate a final hash for caching purposes.  \n\n### Consider the following example:\nA css file makes reference to an image.  If the image changes, the hash of the css file remains the same since its contents have not changed.  Web clients that have previously cached this css file will not correctly resolve the new image.\nIf we take in to consideration the dependency graph while calculating the css file hash, we can have it change if any of its child references have changed.\n\nSo to recap, `gulp-rev-all` not only handles reference re-writing but it also takes child references into consideration when calculating a hashes.\n\n## Upgrading to v0.8.x\n\nNOTICE: Major breaking changes occured between the last release v0.7.6 and v0.8.x that you should be aware of.\n  - It is now required to instantiate a `var revAll = new RevAll()` instance before piping through revAll.revision()\n  - Reference dependency analysis has been greatly simplified, previous method was way too complex\n  - No longer requires references to exist physically on disk, can now be piped through, embracing nature of gulp\n  - New Feature: Ignoring files has changed, `ignore` option has been removed and has been replaced with `dontGlobal, dontRenameFile, dontUpdateReference, dontSearchFile` which allows for more control and less ambiguity on what is being ignored\n  - New Feature: Manifest and Version files can be created in the same gulp-rev-all run without issue\n  - Bug Fix: References without quotes were not getting updated \n  - Change: `silent` \u0026 `quiet` options, renamed to `debug` to control logging output\n\n## Install\n\nInstall with [npm](https://npmjs.org/)\n\n```\nnpm install --save-dev gulp-rev-all\n```\n\n## Usage\n\n```js\nvar gulp = require('gulp');\nvar RevAll = require('gulp-rev-all');\n\ngulp.task('default', function () {\n\n    var revAll = new RevAll();\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('cdn'));\n\n});\n```\n\n\n```js\nvar gulp = require('gulp');\nvar RevAll = require('gulp-rev-all');\nvar awspublish = require('gulp-awspublish');\nvar cloudfront = require(\"gulp-cloudfront\");\n\nvar aws = {\n  \"params\": {\n    \"Bucket\": \"bucket-name\"\n  },\n  \"accessKeyId\": \"AKIAI3Z7CUAFHG53DMJA\",\n  \"secretAccessKey\": \"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\",\n  \"distributionId\": \"E1SYAKGEMSK3OD\",\n  \"region\": \"us-standard\",\n};\n\nvar publisher = awspublish.create(aws);\nvar headers = {'Cache-Control': 'max-age=315360000, no-transform, public'};\n\ngulp.task('default', function () {\n\n    var revAll = new RevAll();\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(awspublish.gzip())\n        .pipe(publisher.publish(headers))\n        .pipe(publisher.cache())\n        .pipe(awspublish.reporter())\n        .pipe(cloudfront(aws));\n\n});\n```\n  * See [gulp-awspublish](https://www.npmjs.org/package/gulp-awspublish), [gulp-cloudfront](https://www.npmjs.org/package/gulp-cloudfront)\n\n## Methods\n\n### .revision()\nReturns a transform function that can be used to pipe files through so that they may be revisioned, also corrects refererences to said files.\n\n### .manifestFile()\nReturns a transform function that will filter out any existing files going through the pipe and will emit a new manifest file.  Must be called after `.revision()`.\n\n```js\nvar gulp = require('gulp');\nvar RevAll = require('gulp-rev-all');\n\ngulp.task('default', function () {\n\n    var revAll = new RevAll();\n    return gulp.src(['assets/**'])\n        .pipe(gulp.dest('build/assets'))  \n        .pipe(revAll.revision())\n        .pipe(gulp.dest('build/assets'))  \n        .pipe(revAll.manifestFile())\n        .pipe(gulp.dest('build/assets')); \n\n});\n```\n\nAn asset manifest, mapping the original paths to the revisioned paths, will be written to `build/assets/rev-manifest.json`:\n\n```json\n{\n    \"css/unicorn.css\": \"css/unicorn.098f6bcd.css\",\n    \"js/unicorn.js\": \"js/unicorn.273c2cin.js\"\n}\n```\n\n### .versionFile()\nReturns a transform function that will filter out any existing files going through the pipe and will emit a new version file.  Must be called after `.revision()`.\n\n```js\nvar gulp = require('gulp');\nvar RevAll = require('gulp-rev-all');\n\ngulp.task('default', function () {\n\n    var revAll = new RevAll();\n    return gulp.src(['assets/**'])\n        .pipe(gulp.dest('build/assets'))\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('build/assets'))\n        .pipe(revAll.versionFile())\n        .pipe(gulp.dest('build/assets'));\n\n});\n```\n\nThe version file will contain the build date and a combined hash of all the revisioned files, will be written to `build/assets/rev-version.json`.\n\n```json\n{\n    \"hash\": \"c969a1154f2a5c0689d8ec4b0eafd584\",\n    \"timestamp\": \"2014-10-11T12:13:48.466Z\"\n}\n```\n\n\n## Options\n```js\nvar revAll = new RevAll({ options });\n```\n\n#### fileNameVersion\nType: `String`\u003cbr/\u003e\nDefault: `rev-version.json`\u003cbr /\u003e\nSet the filename of the file created by revAll.versionFile()\u003cbr/\u003e\n\n#### fileNameManifest\nSet the filename of the file created by revAll.manifestFile()\u003cbr/\u003e\nType: `String`\u003cbr/\u003e\nDefault: `rev-manifest.json`\n\n#### dontGlobal\n\nDon't rename, search or update refrences in files matching these rules\u003cbr/\u003e\nType: `Array of (Regex and/or String)`\u003cbr/\u003e\nDefault: `[ /^\\/favicon.ico$/ ]`\u003cbr/\u003e\n\n#### dontRenameFile\nDon't rename files matching these rules\u003cbr/\u003e\nType: `Array of (Regex and/or String)`\u003cbr/\u003e\nDefault: `[]`\n\n#### dontUpdateReference\nDon't update references matching these rules\u003cbr/\u003e\nType: `Array of (Regex and/or String)`\u003cbr/\u003e\nDefault: `[]`\n\n#### dontSearchFile\nDon't search for references in files matching these rules\u003cbr/\u003e\nType: `Array of (Regex and/or String)`\u003cbr/\u003e\nDefault: `[]`\n\nIn some cases, you may not want to rev your `*.html` files:\n\n```js\ngulp.task('default', function () {\n\n    var revAll = new RevAll({ dontRenameFile: [/^\\/favicon.ico$/g, '.html'] });\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('cdn'))\n\n});\n```\n\nEvery html file except the root `/index.html` file:\n\n```js\ngulp.task('default', function () {\n\n    var revAll = new RevAll({ dontRenameFile: [/^\\/favicon.ico$/g, /^\\/index.html/g] });\n    gulp.src('dist/**')\n        .pipe(revAll.revision()))\n        .pipe(gulp.dest('cdn'))\n});\n```\n\n#### hashLength\nChange the length of the hash appended to the end of each revisioned file (use `transformFilename` for more complicated scenarios).\u003cbr/\u003e\nType: `hashLength`\u003cbr/\u003e\nDefault: `8`\u003cbr/\u003e\n\n```js\ngulp.task('default', function () {\n\n    var revAll = new RevAll({ hashLength: 4 });\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('cdn'))\n});\n```\n\n#### prefix\nPrefixes absolute references with a string (use `transformPath` for more complicated scenarios). Useful for adding a full url path to files.\u003cbr/\u003e\nType: `prefix`\u003cbr/\u003e\nDefault: `none`\u003cbr/\u003e\n\n```js\ngulp.task('default', function () {\n\n    var revAll = new RevAll({ prefix: 'http://1234.cloudfront.net/' });\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('cdn'))\n\n});\n```\n\n#### transformPath\nSpecify a function to transform the reference path. Useful in instances where the local file structure does not reflect what the remote file structure will be.\u003cbr/\u003e\nType: `function (rev, source, path)`\u003cbr/\u003e\nDefault: `none`\u003cbr/\u003e\n\nThe function takes three arguments:\n  - `rev` - revisioned reference path\n  - `source` - original reference path\n  - `path` - path to the file\n\n\n```js\ngulp.task('default', function () {\n\n    var revAll = new RevAll({\n        transformPath: function (rev, source, path) {\n            // on the remote server, image files are served from `/images`\n            return rev.replace('/img', '/images');\n        }\n    });\n\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('cdn'))\n\n});\n```\n\n#### transformFilename\nIf the default naming convention does not suite your needs, you can specify a custom filename transform. \u003cbr/\u003e\nType: `function (file, hash)`\u003cbr/\u003e\nDefault: `none`\u003cbr/\u003e\n\nThe function takes one argument:\n  - `file` - file to be revisioned\n  - `hash` - calculated hash of the file\n\n```js\ngulp.task('default', function () {\n\n    var revAll = new RevAll({\n        transformFilename: function (file, hash) {\n            var ext = path.extname(file.path);\n            return hash.substr(0, 5) + '.'  + path.basename(file.path, ext) + ext; // 3410c.filename.ext\n        }\n    });\n\n    gulp.src('dist/**')\n        .pipe(revAll.revision())\n        .pipe(gulp.dest('cdn'))\n        \n});\n```\n\n#### debug\nIf you set this options to true, verbose logging will be emitted to console.\u003cbr/\u003e\nType: `Boolean`\u003cbr/\u003e\nDefault: `false`\u003cbr/\u003e\n\n## Annotater \u0026 Replacer\n\nIn some cases, false-positives may occur.  Strings that are similar to a file reference may be incorrectly replaced.\u003cbr/\u003e\n\nIn the example below, the 2nd instance of 'xyz' is not reference to the file xyz.js:\n\n```js\nrequire('xyz');\n\nangular.controller('myController', ['xyz', function(xyz) {\n   ...\n}]);\n```\n\nIt will still however be replaced resulting in file corruption:\n\n```js\nrequire('xyz.123');\n\nangular.controller('myController', ['xyz.123', function(xyz) {\n   ...\n}]);\n```\n\nThis behaviour can be avoided by passing custom ```annotator``` and ```replacer``` functions in as options.\n\n### Annotator\n\nThe annotator function is called with the original file content and path.\nAnnotator function should return a list of objects that contain fragments of the file content in order.\nYou may split the file up into as many fragments as necessary and attach any other metadata to the fragments.\nThe file will be reassembled in order. \u003cbr/\u003e\n\nThe default annotator returns one fragment with no annotations:\n\n```js\noptions.annotator = function(contents, path) {\n    var fragments = [{'contents': contents}];\n    return fragments;\n};\n```\n\n### Replacer\n\nThe replacer function's job is to replace references to revisioned files. The paremeters are as follows:\u003cbr/\u003e\n\n```fragment```: a file fragment as created in the annotator function.\u003cbr/\u003e\n```replaceRegExp```: parameter is a regular expression that can be used to match the part of the fragement to be replaced. The regular expression has 4 capture groups. $1 \u0026 $4 are what precedes and follows the reference. $2 is the file path without the extension, and $3 is the file extension.\u003cbr/\u003e\n```newReference```: what gulp-rev-all wants to replace the file path without the extension ($2) with.\u003cbr/\u003e\n```referencedFile```: contains additional properties of the file reference thats being replaced. See the 'Additional Properties' section for more information.\u003cbr/\u003e\n\nThe default replacer function is as follows:\n\n```js\noptions.replacer = function(fragment, replaceRegExp, newReference, referencedFile) {\n     fragment.contents = fragment.contents.replace(replaceRegExp, '$1' + newReference + '$3$4');\n};\n```\n\nYou can overide the default annotator and replacer to change the behaviour of gulp-rev-all and deal with problematic edge cases.\n\n## Additional Properties\n\n### file.revPathOriginal \nThe original full path of the file, before revisioning.\n\n### file.revFilenameOriginal\nThe original filename less the file extension, before revisioning.\n\n### file.revFilenameExtOriginal\nThe original file extension, before revisioning.\n\n### file.revHashOriginal\nThe original hash of the asset before any calculations by `gulp-rev-all`.\n\n### file.revHash\nThe hash of the asset as calculated by `gulp-rev-all`, you can use this for customizing the file renaming, or for building different manifest formats.\n\n\n## Tips\n\nMake sure to set the files to [never expire](http://developer.yahoo.com/performance/rules.html#expires) for this to have an effect.\n\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT) © [Joshua Bellamy-Henn](http://www.joshuabellamyhenn.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floo2k%2Fmoz-rev-all","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floo2k%2Fmoz-rev-all","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floo2k%2Fmoz-rev-all/lists"}