{"id":13507517,"url":"https://github.com/HashNuke/rotor","last_synced_at":"2025-03-30T09:32:55.854Z","repository":{"id":14625320,"uuid":"17342748","full_name":"HashNuke/rotor","owner":"HashNuke","description":"Super-simple build system for Elixir","archived":false,"fork":false,"pushed_at":"2014-10-26T03:19:52.000Z","size":614,"stargazers_count":82,"open_issues_count":2,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T04:41:57.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/HashNuke.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":"2014-03-02T17:37:00.000Z","updated_at":"2024-12-10T10:06:09.000Z","dependencies_parsed_at":"2022-09-11T07:10:40.934Z","dependency_job_id":null,"html_url":"https://github.com/HashNuke/rotor","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/HashNuke%2Frotor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HashNuke%2Frotor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HashNuke%2Frotor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HashNuke%2Frotor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HashNuke","download_url":"https://codeload.github.com/HashNuke/rotor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301963,"owners_count":20755512,"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-08-01T02:00:35.541Z","updated_at":"2025-03-30T09:32:55.601Z","avatar_url":"https://github.com/HashNuke.png","language":"Elixir","funding_links":[],"categories":["Build Tools"],"sub_categories":[],"readme":"# Rotor\n\nRotor is a build system for Elixir projects. Use it to compile things, run commands or do anything that needs to be run when files change.\n\n\u003e *[Wreckers][1] don't call for backup, they call for cleanup ~!*\n\n[1]: http://en.wikipedia.org/wiki/Wreckers_(Transformers)\n\n\n**Define your rotor watch groups in `config/rotors.exs` in your project and they'll be loaded when your app starts**\n\n### Features\n\n* Works with any web framework or even plain mix projects\n* Easy to use\n* Extendable with simple functions\n* Can be configured to run commands or code or go to the moon.\n\n### Usage\n\n* Add rotor as a dependency to your `mix.exs`\n* Define watch groups in `config/rotors.exs`\n* Run `Rotor.start` in your `IEx` console to run the rotors\n\n### Example 1: Reload Elixir modules whenever they change\n\n```elixir\n# config/rotors.exs\n\nuse Rotor.Config\n\npaths = [\"lib/**/*\"]\n\nRotor.define :ex_modules, paths, fn(changed, _all)-\u003e\n  reload_modules(changed)\nend\n```\n\nMake changes to any file in the lib dir of your project and watch it reload in your console\n\n### Example 2: Compile CoffeeScript files whenever they change\n\n```elixir\n# config/rotors.exs\n\nuse Rotor.Config\n\npaths = [\"assets/libs/*.coffee\", \"assets/*.coffee\"]\nRotor.define :coffee_assets, paths, fn(changed_files, all_files)-\u003e\n  read_files(all_files)\n  |\u003e coffee\n  |\u003e concat\n  |\u003e write_to(\"priv/static/assets/app.js\")\nend\n\n```\n\n`touch` a file that's in the path provided and watch the rotor function being run.\n\n*The above example uses the [coffee_rotor](https://github.com/HashNuke/coffee_rotor).*\n\n\n\u003e **NOTE:** Rotor is *not* a replacement for mix. It is intended to be used as your sidekick during development.\n\n\n### Details\n\n#### What is a watch group?\n\nA set of paths you want to watch is called a *Watch group\"*. Each watch group has the following:\n\n* name\n* a list of paths to watch\n* *rotor function* - a function that is run everytime any of the files in the paths changes. It should accept 2 arguments\n  * *changed_files* - a list of maps, each containing info about a changed file\n  * *all_files* - a list of maps, each containing info about all files that matched the path\n\n#### Where to define watch groups?\n\n`config/rotors.exs` is prefered. But if you want to define them elsewhere feel free. Take a look at examples\n\n#### How to run them?\n\nRun `Rotor.start` in your `IEx` console to run the rotors.\n\nYou can also automate this by adding `Rotor.start` somewhere in your code. But be careful ~!\n\n#### How to define watch groups?\n\n```elixir\n# With default options\nRotor.define(name, files, rotor_function)\n\n# With options\nRotor.define(name, files, rotor_function, options)\n```\n\nThe rotor function is passed info about the list of files that match the paths specified. The rotor function calls other little functions called `rotors`, that run certain tasks.\n\n\n```elixir\npaths = [\"assets/javascripts/libs/*.js\", \"assets/javascripts/*.js\"]\nRotor.define :javascripts, paths, fn(changed_files, all_files)-\u003e\n  read_files(all_files)\n  |\u003e concat\n  |\u003e write_to(\"priv/static/assets/app.js\")\nend\n```\n\nThe fourth argument is options. It accepts a map. The following are valid options:\n\n* `manual` - defaults to false. If set to true, paths will only be polled when `Rotor.run/1` or `Rotor.run_async/1` is called.\n* `interval` - defaults to 2500 milliseconds (2.5 seconds). This is the interval at which files are checked for changes.\n\n\n#### Manually running watch group's rotor function\n\nIf you want files to be polled only when you say so (and not at intervals). Then pass the `manual` option as `true` when adding a group. Then use one of the following functions to trigger a poll.\n\n* `Rotor.run(group_name)` - will poll paths and run the Rotor function synchronously\n* `Rotor.run_async(group_name)` - will poll paths and run the Rotor function asynchronously\n\n\n\n#### Rotors\n\nRotor ships with a few simple helper functions in the `Rotor.BasicRotors` module.\n\n* `read_files(files)` - reads contents of files, and returns files with a property called `contents`\n* `copy_files(files, destination_dir)` - copies files to destination_dir\n* `concat(files)` - concats contents of files and returns a string\n* `write_to(contents, output_path)` - writes the contents to the file path specified in output path\n* `reload_modules(files)` - reloads the modules in the list of files passed\n\nYou can also write your own. Check the *\"Writing custom rotors\"* section below.\n\n\n### Other stuff\n\n* To remove a watch group\n\n  ```elixir\n  Rotor.stop_watching(name)\n  ```\n\n* To list all watch groups\n\n  ```elixir\n  Rotor.all\n  ```\n\n* To run a watch group's rotor function forcefully\n\n  ```elixir\n  Rotor.run(name)\n  ```\n\n### Examples\n\n```elixir\npaths = [\"assets/stylesheets/libs/*.css\", \"assets/stylesheets/*.css\"]\nRotor.define :stylesheets, paths, fn(changed_files, all_files)-\u003e\n  read_files(all_files)\n  |\u003e concat\n  |\u003e write_to(\"app.css\")\nend\n\n\npaths = [\"assets/images/*\", \"assets/fonts/*\"]\nRotor.define :images_and_fonts, paths, fn(changed_files, all_files)-\u003e\n  copy_files(files, \"priv/static/assets\")\nend\n```\n\n### Writing custom rotors\n\nRotors are just functions that accept data and do something.\n\nCheckout [coffee_rotor](https://github.com/HashNuke/coffee_rotor), which provides a rotor to compile CoffeeScript files.\n\n\n### License\n\nCopyright © 2014, Akash Manohar J, under the [MIT License](http://opensource.org/licenses/MIT)\n\n\u003e Inspired by [gulp](https://github.com/gulpjs/gulp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHashNuke%2Frotor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHashNuke%2Frotor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHashNuke%2Frotor/lists"}