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.markdown 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. # config-chain
  2. A module for loading custom configurations
  3. ## NOTE: Feature Freeze
  4. [![locked](http://badges.github.io/stability-badges/dist/locked.svg)](http://github.com/badges/stability-badges)
  5. This module is frozen.
  6. In general, we recommend using [rc](https://github.com/dominictarr/rc) instead,
  7. but as [npm](https://github.com/npmjs/npm) depends on this, it cannot be changed.
  8. ## Install
  9. ```sh
  10. yarn add config-chain
  11. # npm users
  12. npm install --save config-chain
  13. ```
  14. ## Usage
  15. ```js
  16. const cc = require('config-chain');
  17. console.log(cc.env('TERM_', process.env));
  18. /*
  19. { SESSION_ID: 'w1:5F38',
  20. PROGRAM_VERSION: '3.1.2',
  21. PROGRAM: 'iTerm.app' }
  22. */
  23. ```
  24. The `.env` function gets all the keys on the provided object which are
  25. prefixed by the specified prefix, removes the prefix, and puts the values on a new object.
  26. <br/>
  27. ## Full Usage
  28. ``` js
  29. // npm install config-chain
  30. var cc = require('config-chain')
  31. , opts = require('optimist').argv //ALWAYS USE OPTIMIST FOR COMMAND LINE OPTIONS.
  32. , env = opts.env || process.env.YOUR_APP_ENV || 'dev' //SET YOUR ENV LIKE THIS.
  33. // EACH ARG TO CONFIGURATOR IS LOADED INTO CONFIGURATION CHAIN
  34. // EARLIER ITEMS OVERIDE LATER ITEMS
  35. // PUTS COMMAND LINE OPTS FIRST, AND DEFAULTS LAST!
  36. //strings are interpereted as filenames.
  37. //will be loaded synchronously
  38. var conf =
  39. cc(
  40. //OVERRIDE SETTINGS WITH COMMAND LINE OPTS
  41. opts,
  42. //ENV VARS IF PREFIXED WITH 'myApp_'
  43. cc.env('myApp_'), //myApp_foo = 'like this'
  44. //FILE NAMED BY ENV
  45. path.join(__dirname, 'config.' + env + '.json'),
  46. //IF `env` is PRODUCTION
  47. env === 'prod'
  48. ? path.join(__dirname, 'special.json') //load a special file
  49. : null //NULL IS IGNORED!
  50. //SUBDIR FOR ENV CONFIG
  51. path.join(__dirname, 'config', env, 'config.json'),
  52. //SEARCH PARENT DIRECTORIES FROM CURRENT DIR FOR FILE
  53. cc.find('config.json'),
  54. //PUT DEFAULTS LAST
  55. {
  56. host: 'localhost'
  57. port: 8000
  58. })
  59. var host = conf.get('host')
  60. // or
  61. var host = conf.store.host
  62. ```
  63. Finally, flexible configurations! 👌
  64. ## Custom Configuations
  65. ```javascript
  66. var cc = require('config-chain')
  67. // all the stuff you did before
  68. var config = cc({
  69. some: 'object'
  70. },
  71. cc.find('config.json'),
  72. cc.env('myApp_')
  73. )
  74. // CONFIGS AS A SERVICE, aka "CaaS", aka EVERY DEVOPS DREAM OMG!
  75. .addUrl('http://configurator:1234/my-configs')
  76. // ASYNC FTW!
  77. .addFile('/path/to/file.json')
  78. // OBJECTS ARE OK TOO, they're SYNC but they still ORDER RIGHT
  79. // BECAUSE PROMISES ARE USED BUT NO, NOT *THOSE* PROMISES, JUST
  80. // ACTUAL PROMISES LIKE YOU MAKE TO YOUR MOM, KEPT OUT OF LOVE
  81. .add({ another: 'object' })
  82. // DIE A THOUSAND DEATHS IF THIS EVER HAPPENS!!
  83. .on('error', function (er) {
  84. // IF ONLY THERE WAS SOMETHIGN HARDER THAN THROW
  85. // MY SORROW COULD BE ADEQUATELY EXPRESSED. /o\
  86. throw er
  87. })
  88. // THROW A PARTY IN YOUR FACE WHEN ITS ALL LOADED!!
  89. .on('load', function (config) {
  90. console.awesome('HOLY SHIT!')
  91. })
  92. ```
  93. # API Docs
  94. ## cc(...args)
  95. MAKE A CHAIN AND ADD ALL THE ARGS.
  96. If the arg is a STRING, then it shall be a JSON FILENAME.
  97. RETURN THE CHAIN!
  98. ## cc.json(...args)
  99. Join the args into a JSON filename!
  100. SYNC I/O!
  101. ## cc.find(relativePath)
  102. SEEK the RELATIVE PATH by climbing the TREE OF DIRECTORIES.
  103. RETURN THE FOUND PATH!
  104. SYNC I/O!
  105. ## cc.parse(content, file, type)
  106. Parse the content string, and guess the type from either the
  107. specified type or the filename.
  108. RETURN THE RESULTING OBJECT!
  109. NO I/O!
  110. ## cc.env(prefix, env=process.env)
  111. Get all the keys on the provided object which are
  112. prefixed by the specified prefix, removes the prefix, and puts the values on a new object.
  113. RETURN THE RESULTING OBJECT!
  114. NO I/O!
  115. ## cc.ConfigChain()
  116. The ConfigChain class for CRAY CRAY JQUERY STYLE METHOD CHAINING!
  117. One of these is returned by the main exported function, as well.
  118. It inherits (prototypically) from
  119. [ProtoList](https://github.com/isaacs/proto-list/), and also inherits
  120. (parasitically) from
  121. [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
  122. It has all the methods from both, and except where noted, they are
  123. unchanged.
  124. ### LET IT BE KNOWN THAT chain IS AN INSTANCE OF ConfigChain.
  125. ## chain.sources
  126. A list of all the places where it got stuff. The keys are the names
  127. passed to addFile or addUrl etc, and the value is an object with some
  128. info about the data source.
  129. ## chain.addFile(filename, type, [name=filename])
  130. Filename is the name of the file. Name is an arbitrary string to be
  131. used later if you desire. Type is either 'ini' or 'json', and will
  132. try to guess intelligently if omitted.
  133. Loaded files can be saved later.
  134. ## chain.addUrl(url, type, [name=url])
  135. Same as the filename thing, but with a url.
  136. Can't be saved later.
  137. ## chain.addEnv(prefix, env, [name='env'])
  138. Add all the keys from the env object that start with the prefix.
  139. ## chain.addString(data, file, type, [name])
  140. Parse the string and add it to the set. (Mainly used internally.)
  141. ## chain.add(object, [name])
  142. Add the object to the set.
  143. ## chain.root {Object}
  144. The root from which all the other config objects in the set descend
  145. prototypically.
  146. Put your defaults here.
  147. ## chain.set(key, value, name)
  148. Set the key to the value on the named config object. If name is
  149. unset, then set it on the first config object in the set. (That is,
  150. the one with the highest priority, which was added first.)
  151. ## chain.get(key, [name])
  152. Get the key from the named config object explicitly, or from the
  153. resolved configs if not specified.
  154. ## chain.save(name, type)
  155. Write the named config object back to its origin.
  156. Currently only supported for env and file config types.
  157. For files, encode the data according to the type.
  158. ## chain.on('save', function () {})
  159. When one or more files are saved, emits `save` event when they're all
  160. saved.
  161. ## chain.on('load', function (chain) {})
  162. When the config chain has loaded all the specified files and urls and
  163. such, the 'load' event fires.