{"id":16185219,"url":"https://github.com/davemo/grunt-rails-asset-digest","last_synced_at":"2025-03-16T10:31:56.157Z","repository":{"id":11184481,"uuid":"13562994","full_name":"davemo/grunt-rails-asset-digest","owner":"davemo","description":"grunt-rails-asset-digest","archived":false,"fork":false,"pushed_at":"2024-06-17T11:24:16.000Z","size":133,"stargazers_count":15,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-08T17:09:23.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"emqtt/emqttc","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davemo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-14T14:08:07.000Z","updated_at":"2024-02-15T15:40:38.000Z","dependencies_parsed_at":"2024-10-23T01:02:53.037Z","dependency_job_id":null,"html_url":"https://github.com/davemo/grunt-rails-asset-digest","commit_stats":{"total_commits":34,"total_committers":3,"mean_commits":"11.333333333333334","dds":0.05882352941176472,"last_synced_commit":"ccb5d7b182d5de77ee74cb08ed732518feb41af3"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davemo%2Fgrunt-rails-asset-digest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davemo%2Fgrunt-rails-asset-digest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davemo%2Fgrunt-rails-asset-digest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davemo%2Fgrunt-rails-asset-digest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davemo","download_url":"https://codeload.github.com/davemo/grunt-rails-asset-digest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814898,"owners_count":20352037,"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-10-10T07:13:48.473Z","updated_at":"2025-03-16T10:31:55.896Z","avatar_url":"https://github.com/davemo.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grunt-rails-asset-digest\n\n[![Node.js CI](https://github.com/davemo/grunt-rails-asset-digest/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/davemo/grunt-rails-asset-digest/actions/workflows/node.js.yml)\n\n## Rails Version Support\n\nRails 4 significantly changed how the asset manifest is generated. As such if you are still on Rails 3.2 (using manifest.yml) you should use `v0.3.2` of this plugin `npm install grunt-rails-asset-digest@0.3.2 --save`; `v1.4.1` tracks support for Rails 4 and above.\n\n\u003e Generates fingerprinted assets and appends entries to a sprockets-rails manifest.json\n\n## Intended Use\n\nThis plugin is intended to be used by those who are integrating a grunt workflow alongside of the [sprockets-rails](https://github.com/rails/sprockets-rails). As such, this task expects to be run _after_ the [sprockets-rails](https://github.com/rails/sprockets-rails) has generated an asset manifest.json file.\n\nThis approach works well in that it only manages fingerprinting and manifest modification for the files that are explicitly managed in the `files` property and it guarantees that existing entries generated by [sprockets-rails](https://github.com/rails/sprockets-rails) will not be touched.\n\n## Why would I use this?\n\nIf you are using something like [Lineman](http://www.linemanjs.com) or [Grunt](http://www.gruntjs.com) and want more control over an advanced front-end workflow to be used alongside a legacy Rails application. A great candidate for this task is to utilize it during construction of a rich-client JavaScript application that lives inside a Rails application. You can let the Rails asset pipeline manage legacy files, and let your Grunt workflow manage your rich-client files.\n\nIdeally this task should not exist; the best way to build a rich-client JavaScript application is to decouple it completely from the serverside. However this is a reasonable _first step_ in refactoring to extract assets from the world of rails/sprockets and still be able to hook into most rails app deploy processes.\n\n## How would I integrate this task?\n\nAdjust your rails deployment lifecycle to run this task prior to deploying/uploading assets (whether to a CDN, or just in `public/assets` which is where this task will dump fingerprinted assets by default). Here's an example configuration in a [Capistrano](https://github.com/capistrano/capistrano) deploy setup that uses [Lineman](http://www.linemanjs.com) to manage the lifecycle of a rich-client application that still lives within a rails source tree. (The same techniques will work with vanilla Grunt, you'll just have to manage the task aliasing yourself)\n\n```coffeescript\n# linemans config/application.coffee\nappTasks:\n  common: [\n    \"sass\"\n    \"coffee\"\n    \"concat\"\n  ]\n  dist: [\n    \"uglify\"\n    \"rails_asset_digest\"\n    \"clean\"\n  ]\n```\n\n```ruby\n# config/deploy.rb\n\nafter 'assets:compress', 'assets:compile_with_lineman', 'assets:upload'\n\ntask :compile_with_lineman\n  logger.important \"Compiling other assets with Lineman\"\n  run \"lineman build\" # run grunt tasks in common and dist phases\nend\n```\n\n**Note:** this is a _very_ narrowly focused task, and you might not get much use out of it :)\n\n## Getting Started\nThis plugin requires Grunt `~0.4.1`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-rails-asset-digest --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-rails-asset-digest');\n```\n\n## The \"rails_asset_digest\" task\n\n### Overview\nIn your project's Gruntfile, add a section named `rails_asset_digest` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n  rails_asset_digest: {\n    options: {\n      algorithm: 'md5',          // default fingerprinting algorithm to use\n      assetPath: 'public/assets' // default location where manifest.json lives\n    },\n    your_target: {\n      files: {\n        // dest : src\n        \"public/assets/javascript-file.js\"    : \"input/path/to/javascript-file.js\",\n        \"public/assets/sourcemap-file.js.map\" : \"input/path/to/sourcemap-file.js.map\",\n        \"public/assets/style.css\"             : \"input/path/to/style.css\"\n      }\n    },\n  },\n})\n```\n\n### Sample Output\n\nGiven the configuration in the Overview section above, you can expect `grunt rails_asset_digest` to output the following to `public/assets`\n\n```shell\nls -la public/assets\nmanifest.json\njavascript-file-a5a14aa0f19b8fe989f3b79fc72b9b36.js\nsourcemap-file-365b31e16181703b506e90b57f95b568.js.map\nstyle-1fd9137f040f2440d26da164c65e7f66.css\n```\n\nAnd the associaated fingerprinted entries in manifest.json like so:\n\n```json\n{\n  \"files\" : {\n    \"javascript-file-a5a14aa0f19b8fe989f3b79fc72b9b36.js\" : {\n      \"mtime\": \"2014-02-04T18:14:52.0\",\n      \"digest\": \"a5a14aa0f19b8fe989f3b79fc72b9b36\",\n      \"size\": 32,\n      \"logical_path\": \"javascript-file.js\"\n    },\n    \"sourcemap-file-365b31e16181703b506e90b57f95b568.js.map\" : {\n      \"mtime\": \"2014-02-04T18:14:52.0\",\n      \"digest\": \"365b31e16181703b506e90b57f95b568\",\n      \"size\": 49,\n      \"logical_path\": \"sourcemap-file.js.map\"\n    },\n    \"style-1fd9137f040f2440d26da164c65e7f66.css\" : {\n      \"mtime\": \"2014-02-04T18:14:52.0\",\n      \"digest\": \"1fd9137f040f2440d26da164c65e7f66\",\n      \"size\": 17,\n      \"logical_path\": \"style.css\"\n    }\n  },\n  \"assets\" : {\n    \"javascript-file.js\" : \"javascript-file-a5a14aa0f19b8fe989f3b79fc72b9b36.js\",\n    \"sourcemap-file.js\" : \"sourcemap-file-365b31e16181703b506e90b57f95b568.js.map\",\n    \"style.css\" : \"style-1fd9137f040f2440d26da164c65e7f66.css\"\n  }\n}\n```\n\n### Options\n\n#### options.algorithm\nType: `String`\nDefault value: `md5`\n\nThe digest algorithm used to fingerprint the assets, *note:* Rails 4 (via the [sprockets-rails](https://github.com/rails/sprockets-rails) plugin) doesn't actually use an MD5 hash based on the contents of the file anymore, it just uses a random hex digest. It doesn't matter what value is in the hash of the filename as long as the entry in the manifest matches the name of the file on disk.\n\n#### options.assetPath\nType: `String`\nDefault value: `public/assets`\n\nThe location of the rails asset path\n\n#### options.manifestName\nType: `String`\nDefault value: `manifest.json`\n\nThe name of the manifest file, so you can provide your own secret to prevent people guessing the name if so desired.\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Running Specs\n\n* clone this repo\n* `npm install`\n* `npm test`\n\n## Changelog\n\n## Release History\n\n * 2021-11-19   v1.4.1   update deps for grunt 1.4.0 + refactor tests\n * 2014-02-05   v0.4.0   support rails 4 + sprockets-rails manifest.json format\n * 2014-02-04   v0.3.2   no-op: align version number with supported rails version\n * 2013-10-15   v0.2.0   bugfix: asserts the output of written files actually exist\n * 2013-10-15   v0.1.1   bugfix: normalizes asset path to append trailing /\n * 2013-10-14   v0.1.0   Initial release.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavemo%2Fgrunt-rails-asset-digest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavemo%2Fgrunt-rails-asset-digest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavemo%2Fgrunt-rails-asset-digest/lists"}