{"id":17983487,"url":"https://github.com/techjacker/node-version-assets","last_synced_at":"2025-03-25T19:32:36.307Z","repository":{"id":7038276,"uuid":"8314715","full_name":"techjacker/node-version-assets","owner":"techjacker","description":"Version your static assets with MD5 hashes using node.js","archived":false,"fork":false,"pushed_at":"2018-10-04T12:44:45.000Z","size":82,"stargazers_count":63,"open_issues_count":3,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-04T13:17:17.460Z","etag":null,"topics":["caching","cdn","versioning"],"latest_commit_sha":null,"homepage":"","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/techjacker.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":"2013-02-20T14:28:03.000Z","updated_at":"2023-03-07T12:24:01.000Z","dependencies_parsed_at":"2022-08-31T09:00:14.827Z","dependency_job_id":null,"html_url":"https://github.com/techjacker/node-version-assets","commit_stats":{"total_commits":47,"total_committers":7,"mean_commits":6.714285714285714,"dds":"0.44680851063829785","last_synced_commit":"97d4e79c3b549867bdf77acd4a443479bd199efe"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fnode-version-assets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fnode-version-assets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fnode-version-assets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fnode-version-assets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techjacker","download_url":"https://codeload.github.com/techjacker/node-version-assets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222090823,"owners_count":16929472,"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":["caching","cdn","versioning"],"created_at":"2024-10-29T18:17:23.218Z","updated_at":"2024-10-29T18:17:23.869Z","avatar_url":"https://github.com/techjacker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-version-assets\n\n[![Build Status](https://travis-ci.org/techjacker/node-version-assets.svg?branch=master)](https://travis-ci.org/techjacker/node-version-assets)\n\n#### V1 release = Now works on Node.js v4+\n\n\n- Versions your static assets using the power of streams!\n- Version number produced from md5hash of each file -\u003e so unchanged assets will keep the same file name and not blow the browser cache.\n- Greps your html and css files and updates filenames of versioned files.\n- Add to your build scripts/favourite build tool.\n- See below for grunt integration example.\n\n\n## Install\n```Shell\nnpm install -g node-version-assets\n```\n\n## What it does:\n1. Renames assets on filesystem\n```Shell\n\t## BEFORE\n\t/www/project-x/public/css$ ls -l\n\t\u003e all-min.css\n\n\t## AFTER\n\t/www/project-x/public/css$ ls -l\n\t\u003e all-min.44d0440440442524c6d667900275e.css\n```\n\n2.  Find and replaces references to them in files:\n```HTML\n\t\u003c!-- index.html: BEFORE --\u003e\n\t\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"css/all-min.css\"\u003e\n\n\t\u003c!-- index.html: AFTER --\u003e\n\t\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"css/all-min.44d0440440442524c6d667900275e.css\"\u003e\n```\n\n## How this module fits into your build process:\n1. you:\t\tgenerate fresh asset and output to the location specified in options.assets (\u003e /public/css/all.min.css)\n2. module: \trenames fresh asset file to versioned name (\u003e all.min.__newversion__.css)\n3. module: \tdeletes original fresh asset file (all.min.css \u003e deleted)\n4. module: \tdeletes old versioned asset files in the same dir (all.min.__oldversion__.css \u003e deleted)\n\n\n## Example\n\n#### Input options in script:\n```JavaScript\n/* ~/www/project-x/version.js */\nvar Version = require(\"node-version-assets\");\nvar versionInstance = new Version({\n\tassets: ['public/css/all-min.css', 'public/js/app.js'],\n\tgrepFiles: ['views/prod/index.html']\n});\nversionInstance.run();\n```\n\n#### Run the script:\n\n```Shell\nandy@bada55:~/www/project-x$ node version.js\n\nDeleted Assets:\n   public/css/all-min.css\n   public/js/app.js\n\nVersioned Assets Created:\n   public/css/all-min.44d0440440442524c6d667900275e.css: file unchanged \u003e version number re-used\n   public/js/app.12d070550742574e8d87900er34.js: file unchanged \u003e version number re-used\n\nFiles whose contents were updated with refs to renamed asset files:\n   views/prod/index.html\n```\n\n#### Run with the CLI\n\nInstall `npm i -g node-version-assets`\n\n```bash\nnode-version-assets -a app.js,app.css -g index.html\n```\n\nUse `-h` to see the CLI help.\n\n## Grunt Example\n```JavaScript\ngrunt.registerTask('version-assets', 'version the static assets just created', function() {\n\n\tvar Version = require(\"node-version-assets\");\n\tvar versionInstance = new Version({\n\t\tassets: ['public/css/all-min.css', 'public/js/app.js'],\n\t\tgrepFiles: ['views/prod/index.html']\n\t});\n\n\tvar cb = this.async(); // grunt async callback\n\tversionInstance.run(cb);\n});\n\n// make sure versioning is final task\ngrunt.registerTask('default', 'lint rjs jpgmin gifmin pngmin concat cssmin version-assets');\n```\n\n## Options\n\n#### @param {options}\n- accepts: object\n\n#### @param {options.assets}\n- accepts: array of strings\n- required: each item of the array is the relative file path to the static asset\n- each static asset listed will have the new version number inserted before the file type prefix, eg:\n\t- all-min.js \u003e all.min.01135498.js\n- if there is a previous version number in the same position then it will be replaced, eg:\n\t- all-min.oldversion234.js \u003e all.min.01135498.js\n\n\n## Optional, ahem, Options\n\n#### @param {options.silence}\n- accepts: boolean\n- default: false\n- if set to true, it will silence all output to STDOUT\n\n\n#### @param {options.grepFiles}\n- accepts: array of strings\n- list of files (relative filepaths or globbed filepaths) containing references to the {options.assets} which need to be renamed\n- a globbed filepath specifies all files that matches a certain pattern (i.e. /x/y/*.html will match all files in that directory with .html suffix)\n\n#### @param {options.newVersion}\n- accepts: string (only numbers or letters)\n- not required: defaults to generating an md5 hash of the file (recommended to leave as default as md5 hashing means that assets will not blow browser cache if they're unchanged)\n\n#### @param {options.keepOriginalAndOldVersions}\n- accepts: boolean\n- set this to true if you want to disable auto-deletion of BOTH the original and old versions\n- by default the module deletes:\n\t1. the original, unversioned asset (eg app.js)\n\t2. previous versions of the asset (eg app.435fdg435TG435435.js)\n\n#### @param {options.keepOriginal}\n- accepts: boolean\n- set this to true if you want to delete just the ORIGINAL\n- if options.keepOriginalAndOldVersions is true then the old versions will still be deleted\n\n#### @param {options.keepOldVersions}\n- accepts: boolean\n- set this to true if you want to delete just the OLD VERSIONS\n- if options.keepOriginalAndOldVersions is true then the original will still be deleted\n\n#### @param {options.requireJs}\n- accepts: boolean\n- not required: defaults to false\n\nIf set to true then unsuffixed js assets (listed in the assets array) will be updated to the new version, eg:\n```HTML\n\u003cscript type=\"text/javascript\"\u003e\n\trequire.config({\n\t\tpaths: {\n\n\t\t\t\u003c!-- BEFORE: --\u003e\n\t\t\tmain: \"js/app.newie\"\n\n\t\t\t\u003c!-- AFTER: --\u003e\n\t\t\tmain: \"js/app.newie.001\"\n\t\t}\n\t});\n\u003c/script\u003e\n```\n\n#### @param {options.cdnPath}\n- accepts: string\n- not required\n- if set, will prepend the `cdnPath` to all assets that are specified with an absolute path (ie, a leading `/`), eg:\n\t- `src=\"/public/all-min.js\"` \u003e `src=\"https://cdn.example.com/public/all.min.01135498.js\"`\n\t- `src=\"images/image.jpg\"` \u003e `src=\"images/image.48503824.jpg\"`\n\t- `src=\"../images/image.jpg\"` \u003e `src=\"../images/image.48503824.jpg\"`\n\n## Potential Gotchas\n- Assets that you want versioned must be listed in the assets array\n- Check all asset paths are correct: they must be relative to the dir where you are executing the command.\n- The new assets must exist in an unversioned form on the filesystem to be renamed and be listed in the {options.assets} array\n- If you specify a version number it can only contain letters or numbers (ie no special characters)\n\n\n## Version Log\n- 0.0.2: added {options.keepOriginalAndOldVersions}\n- 0.0.3: enabled versioning of all file types (previously just utf8)\n- 0.0.4 - 0.0.8: misc bug fixes\n- 1.0.0 - Updated to work on Node.js v4+\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechjacker%2Fnode-version-assets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechjacker%2Fnode-version-assets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechjacker%2Fnode-version-assets/lists"}