├── .gitignore ├── LICENSE ├── README.md ├── lib └── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 27 | node_modules 28 | 29 | # Idea IDE 30 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alexander Christie 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Environmentalist 2 | 3 | Environmentalist is a CLI utility for viewing the required environmental variables of a given node project. 4 | 5 | ## Installation 6 | 7 | ``` 8 | npm install -g environmentalist 9 | ``` 10 | 11 | ## JSON Format 12 | 13 | The Environmentalist JSON format is very simple and is simply an array of objects, where each object is an environmentalist variable declaration. 14 | 15 | Here is what an environmentalist variable looks like: 16 | ```javascript 17 | { 18 | “name”: “PASSWORD_HASH_SECRET”, 19 | “description”: “Used to compute the password hash of users”, 20 | “default”: “ABCDEFGHIJKLMOP”, 21 | “required”: true 22 | } 23 | ``` 24 | 25 | A full environmentalist.json file should look like this. 26 | ```javascript 27 | [ 28 | { 29 | “name”: “PASSWORD_HASH_SECRET”, 30 | “description”: “Used to compute the password hash of users”, 31 | “default”: “ABCDEFGHIJKLMOP”, 32 | “required”: true 33 | }, 34 | { 35 | “name”: “LOG_LEVEL”, 36 | “description”: “Sets the level that will be logged by the system”, 37 | “default”: “info”, 38 | “required”: false 39 | }, 40 | { 41 | “name”: “CRAZY_VARIABLE” 42 | } 43 | ] 44 | ``` 45 | 46 | The fields meanings are as follows: 47 | 48 | ***NAME IS THE ONLY REQUIRED FIELD, EVERYTHING ELSE IS OPTIONAL*** 49 | 50 | *Name*: The Environmental variable name. This is what you would put after process.env if you were accessing it in the program. For example process.env.VARIABLE_NAME would have a name property of VARIABLE_NAME. 51 | 52 | *Description*: A description of what the variable does in the application. This is just for ease of understanding and can be a string of any length but brevity is advised. 53 | 54 | *Default*: A default value that can safely be used. If none is provided it will default to none. Do not include sensitive keys such as a SASS private key in the default, only use it to provide repository safe defaults to provide an easy way to setup environments. A good use case would be for a environmental variable that set the logging level, a bad use case would be a Amazon S3 private key. 55 | 56 | *Required*: Required means that the application ***WILL NOT FUNCTION*** without the variable. This should only be used for environmental variables without which the system will error or otherwise cease to function correctly. 57 | 58 | ## CLI Usage 59 | 60 | To run environmentalist simply run 61 | 62 | ``` 63 | environmentalist 64 | ``` 65 | 66 | inside the root directory of your package. 67 | 68 | Environmentalist will automatically analyse your package and all of its dependencies and return a table of all the environmental variables required and available from any environmentalist enabled package inside the directory chain. 69 | 70 | ## Issues and Pull Requests 71 | 72 | GitHub Issues is our issue tracker should any bugs or feature requests arise. 73 | 74 | Pull Requests are also welcomed, but try to keep the code clean and well commented. 75 | 76 | ## License 77 | 78 | MIT License, use it, love it, fork it, sell it for ingots, whatever floats your boat. 79 | 80 | Just don’t be evil. Having said that, if you find a way to make environmental variables evil I am impressed. But still don’t do it. 81 | 82 | ## Versioning 83 | 84 | We use Semantic Versioning. Yay for not breaking things! -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | var glob = require('glob' ), 4 | _ = require('underscore' ), 5 | path = require('path' ), 6 | Table = require('cli-table') 7 | 8 | // Setup the environmentalist object 9 | var environment = {} 10 | 11 | // Use glob to find environmentalist files 12 | glob("./**/environmentalist.json", {}, function (err, files) { 13 | 14 | // If there was some sort of error then kill it 15 | if ( err ) { 16 | throw err 17 | return 18 | } 19 | 20 | // Create a table to display the environmental variables 21 | var table = new Table({ 22 | head: ['Name', 'Description', 'Default', 'Required'] 23 | }) 24 | 25 | // Iterate over all returned environmentalist files 26 | _.each(files, function(file) { 27 | 28 | // Load the file from the filesystem 29 | var fileContent = require(path.resolve(process.cwd(), file)) 30 | 31 | // For each file, merge it into the environmental status object 32 | environment = _.union(environment, fileContent) 33 | 34 | _.each(fileContent, function(variable) { 35 | 36 | table.push([variable.name, variable.description || "", variable.default || "", variable.required || false]) 37 | 38 | }) 39 | 40 | }) 41 | 42 | // Display the finalized 43 | console.log(table.toString()) 44 | 45 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "environmentalist", 3 | "version": "1.0.0", 4 | "description": "A command line tool to provide repository safe overview of environmental variables used in packages and their dependencies.", 5 | "author": "Alexander Christie ", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/AJCStriker/Environmentalist" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/AJCStriker/Environmentalist/issues" 12 | }, 13 | "keywords": [ 14 | "environmentalist", 15 | "environment", 16 | "variables", 17 | "management", 18 | "dependencies" 19 | ], 20 | "license": "MIT", 21 | "preferGlobal": true, 22 | "bin": { 23 | "environmentalist": "lib/index.js" 24 | }, 25 | "dependencies": { 26 | "cli-table": "^0.3.1", 27 | "glob": "^5.0.10", 28 | "underscore": "^1.8.3" 29 | } 30 | } 31 | --------------------------------------------------------------------------------