Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Pirates [![Version][version-badge]][npm-link] [![Build Status][build-badge]][build-link] [![Coverage][codecov-badge]][codecov-link] [![Commitizen friendly][cz-badge]][cz-link] [![semantic-release][sr-badge]][sr-link] [![MIT License][license-badge]][license-link]
  2. ### Properly hijack require
  3. [version-badge]: https://img.shields.io/npm/v/pirates.svg "npm version"
  4. [downloads-badge]: https://img.shields.io/npm/dm/pirates.svg "npm downloads"
  5. [npm-link]: http://npm.im/pirates "npm"
  6. [codecov-badge]: https://img.shields.io/codecov/c/github/ariporad/pirates/master.svg?style=flat "codecov"
  7. [codecov-link]: https://codecov.io/gh/ariporad/pirates "codecov"
  8. [license-badge]: https://img.shields.io/npm/l/express.svg "MIT License"
  9. [license-link]: http://ariporad.mit-license.org "MIT License"
  10. [build-badge]: https://travis-ci.org/ariporad/pirates.svg "Travis CI Build Status"
  11. [build-link]: https://travis-ci.org/ariporad/pirates "Travis CI Build Status"
  12. [cz-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg "Commitizen friendly"
  13. [cz-link]: http://commitizen.github.io/cz-cli/ "Commitizen friendly"
  14. [sr-badge]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
  15. [sr-link]: https://github.com/semantic-release/semantic-release
  16. ## Why?
  17. Two reasons:
  18. 1. Babel and istanbul were breaking each other.
  19. 2. Everyone seemed to re-invent the wheel on this, and everyone wanted a solution that was DRY, simple, easy to use,
  20. and made everything Just Work™, while allowing multiple require hooks, in a fashion similar to calling `super`.
  21. For some context, see [the Babel issue thread][] which started this all, then [the nyc issue thread][], where
  22. discussion was moved (as we began to discuss just using the code nyc had developed), and finally to [#1][issue-1]
  23. where discussion was finally moved.
  24. [the Babel issue thread]: https://github.com/babel/babel/pull/3062 "Babel Issue Thread"
  25. [the nyc issue thread]: https://github.com/bcoe/nyc/issues/70 "NYC Issue Thread"
  26. [issue-1]: https://github.com/ariporad/pirates/issues/1 "Issue #1"
  27. ## Installation
  28. npm install --save pirates
  29. ## Usage
  30. Using pirates is really easy:
  31. ```javascript
  32. // my-module/register.js
  33. const addHook = require('pirates').addHook;
  34. // Or if you use ES modules
  35. // import { addHook } from 'pirates';
  36. function matcher(filename) {
  37. // Here, you can inspect the filename to determine if it should be hooked or
  38. // not. Just return a truthy/falsey. Files in node_modules are automatically ignored,
  39. // unless otherwise specified in options (see below).
  40. // TODO: Implement your logic here
  41. return true;
  42. }
  43. const revert = addHook(
  44. (code, filename) => code.replace('@@foo', 'console.log(\'foo\');'),
  45. { exts: ['.js'], matcher }
  46. );
  47. // And later, if you want to un-hook require, you can just do:
  48. revert();
  49. ```
  50. ## API
  51. ### pirates.addHook(hook, [opts={ [matcher: true], [exts: ['.js']], [ignoreNodeModules: true] }]);
  52. Add a require hook. `hook` must be a function that takes `(code, filename)`, and returns the modified code. `opts` is
  53. an optional options object. Available options are: `matcher`, which is a function that accepts a filename, and
  54. returns a truthy value if the file should be hooked (defaults to a function that always returns true), falsey if
  55. otherwise; `exts`, which is an array of extensions to hook, they should begin with `.` (defaults to `['.js']`);
  56. `ignoreNodeModules`, if true, any file in a `node_modules` folder wont be hooked (the matcher also wont be called),
  57. if false, then the matcher will be called for any files in `node_modules` (defaults to true).
  58. ## Projects that use Pirates
  59. See the [wiki page](https://github.com/ariporad/pirates/wiki/Projects-using-Pirates). If you add Pirates to your project,
  60. (And you should! It works best if everyone uses it. Then we can have a happy world full of happy require hooks!), please
  61. add yourself to the wiki.
  62. ## License
  63. [MIT](http://ariporad.mit-license.org)