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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # bin-wrapper [![Build Status](https://travis-ci.org/kevva/bin-wrapper.svg?branch=master)](https://travis-ci.org/kevva/bin-wrapper)
  2. > Binary wrapper that makes your programs seamlessly available as local dependencies
  3. ## Install
  4. ```
  5. $ npm install bin-wrapper
  6. ```
  7. ## Usage
  8. ```js
  9. const BinWrapper = require('bin-wrapper');
  10. const base = 'https://github.com/imagemin/gifsicle-bin/raw/master/vendor';
  11. const bin = new BinWrapper()
  12. .src(`${base}/macos/gifsicle`, 'darwin')
  13. .src(`${base}/linux/x64/gifsicle`, 'linux', 'x64')
  14. .src(`${base}/win/x64/gifsicle.exe`, 'win32', 'x64')
  15. .dest(path.join('vendor'))
  16. .use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle')
  17. .version('>=1.71');
  18. (async () => {
  19. await bin.run(['--version']);
  20. console.log('gifsicle is working');
  21. })();
  22. ```
  23. Get the path to your binary with `bin.path()`:
  24. ```js
  25. console.log(bin.path());
  26. //=> 'path/to/vendor/gifsicle'
  27. ```
  28. ## API
  29. ### `new BinWrapper(options)`
  30. Creates a new `BinWrapper` instance.
  31. #### options
  32. Type: `Object`
  33. ##### skipCheck
  34. Type: `boolean`<br>
  35. Default: `false`
  36. Whether to skip the binary check or not.
  37. ##### strip
  38. Type: `number`<br>
  39. Default: `1`
  40. Strip a number of leading paths from file names on extraction.
  41. ### .src(url, [os], [arch])
  42. Adds a source to download.
  43. #### url
  44. Type: `string`
  45. Accepts a URL pointing to a file to download.
  46. #### os
  47. Type: `string`
  48. Tie the source to a specific OS.
  49. #### arch
  50. Type: `string`
  51. Tie the source to a specific arch.
  52. ### .dest(destination)
  53. #### destination
  54. Type: `string`
  55. Accepts a path which the files will be downloaded to.
  56. ### .use(binary)
  57. #### binary
  58. Type: `string`
  59. Define which file to use as the binary.
  60. ### .path()
  61. Returns the full path to your binary.
  62. ### .version(range)
  63. #### range
  64. Type: `string`
  65. Define a [semver range](https://github.com/isaacs/node-semver#ranges) to check
  66. the binary against.
  67. ### .run([arguments])
  68. Runs the search for the binary. If no binary is found it will download the file
  69. using the URL provided in `.src()`.
  70. #### arguments
  71. Type: `Array`<br>
  72. Default: `['--version']`
  73. Command to run the binary with. If it exits with code `0` it means that the
  74. binary is working.
  75. ## License
  76. MIT © [Kevin Mårtensson](http://kevinmartensson.com)