├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── example.js ├── index.js ├── package.json └── tests ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | tmp 4 | *.log* 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '4' 4 | - '6' 5 | sudo: false 6 | cache: 7 | directories: 8 | - node_modules 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # dev-env-status-check changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## Unreleased 8 | 9 | * ??? 10 | 11 | ## v1.0.0 12 | 13 | ### Changed 14 | 15 | * switched from a function with callback to a stream that emits `data` events 16 | * limited the commands checked to `node`, `npm`, and `git` for now 17 | 18 | ### Added 19 | 20 | * added minimal test 21 | 22 | ## v0.0.0 23 | 24 | ### Added 25 | 26 | * initial implementation focused on macOS -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at sethvincent@gmail.com. The project team 59 | will review and investigate all complaints, and will respond in a way that it deems 60 | appropriate to the circumstances. The project team is obligated to maintain 61 | confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute to dev-env-status-check 2 | 3 | ## Prerequisites: 4 | 5 | - Familiarity with [GitHub pull requests](https://help.github.com/articles/using-pull-requests) and issues. 6 | - Knowledge of [markdown](https://help.github.com/articles/markdown-basics/) for editing `.md` documents. 7 | - Understanding of JavaScript. 8 | 9 | ## Types of contributions 10 | 11 | Here are a few of the types of contributions that we're looking for. Have an idea but it doesn't fit into this list? Make an issue for it in the issues queue of the project. 12 | 13 | ### Ideas 14 | 15 | Participate in an issues thread or start your own to have your voice heard. 16 | 17 | ### Design 18 | 19 | Create mockups & prototypes for new and revised sections of the site and implement the changes. 20 | 21 | ### Code 22 | 23 | Fix issues or contribute new features to this or any related projects. 24 | 25 | ### Writing 26 | 27 | Contribute your expertise in an area by helping us expand the text in the application, README.md file, and other content. 28 | 29 | ### Copy editing 30 | 31 | Fix typos, clarify language, and generally improve the quality of the content. 32 | 33 | ## Steps to contributing 34 | 35 | - Fork the repository 36 | - Create a branch for your changes 37 | - Make the changes you'd like to contribute. See the "types of contributions" list above to learn more about what we're looking for 38 | - Submit a pull request 39 | 40 | ## Conduct 41 | 42 | We are committed to providing a friendly, safe, and welcoming environment for 43 | all, regardless of gender, sexual orientation, disability, ethnicity, religion, 44 | or similar personal characteristic. 45 | 46 | Be kind and courteous. There's no need to be mean or rude. 47 | Respect that people have differences of opinion and that every design or 48 | implementation choice carries a trade-off and numerous costs. There is seldom 49 | a right answer, merely an optimal answer given a set of values and 50 | circumstances. 51 | 52 | Keep unstructured critique to a minimum. If you have solid ideas you 53 | want to experiment with, make a fork and see how it works. 54 | 55 | Avoid using overtly sexual nicknames or other nicknames that 56 | might detract from a friendly, safe and welcoming environment for all. 57 | 58 | We will exclude you from interaction if you insult, demean or harass anyone. 59 | That is not welcome behavior. We interpret the term "harassment" as 60 | including the definition in the 61 | [Citizen Code of Conduct](CONDUCT.md); 62 | if you have any lack of clarity about what might be included in that concept, 63 | please read their definition. In particular, we don't tolerate behavior that 64 | excludes people in socially marginalized groups. 65 | 66 | Private harassment is also unacceptable. No matter who you are, if you feel 67 | you have been or are being harassed or made uncomfortable by a community 68 | member, please contact one of the channel ops or any of the core team 69 | immediately. Whether you're a regular contributor or a newcomer, we care about 70 | making this community a safe place for you and we've got your back. 71 | 72 | Likewise any spamming, trolling, flaming, baiting or other attention-stealing 73 | behavior is not welcome. 74 | 75 | 76 | ## Communication 77 | 78 | See the [README](README.md#contact) for detailed communication and maintainer contact information. 79 | 80 | Please follow the conduct guidelines above in all communication about this project. Language issues 81 | are often contentious and we'd like to keep discussion brief, civil and focused 82 | on what we're actually doing, not wandering off into too much imaginary stuff. 83 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # [ISC License](https://spdx.org/licenses/ISC) 2 | 3 | Copyright (c) 2016, Seth Vincent 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dev-env-status-check 2 | 3 | Check the availability of common Node development environment dependencies like `node`, `npm`, `git`, and others. 4 | 5 | [![npm][npm-image]][npm-url] 6 | [![travis][travis-image]][travis-url] 7 | [![standard][standard-image]][standard-url] 8 | [![conduct][conduct]][conduct-url] 9 | 10 | [npm-image]: https://img.shields.io/npm/v/dev-env-status-check.svg?style=flat-square 11 | [npm-url]: https://www.npmjs.com/package/dev-env-status-check 12 | [travis-image]: https://img.shields.io/travis/sethvincent/dev-env-status-check.svg?style=flat-square 13 | [travis-url]: https://travis-ci.org/sethvincent/dev-env-status-check 14 | [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 15 | [standard-url]: http://npm.im/standard 16 | [conduct]: https://img.shields.io/badge/code%20of%20conduct-contributor%20covenant-green.svg?style=flat-square 17 | [conduct-url]: CONDUCT.md 18 | 19 | ## About 20 | 21 | When helping a new programmer set up their computer for the first time it can be difficult to debug their system. 22 | 23 | This module intends to be a high-level approach to checking which dependencies are correctly set up on a computer. 24 | 25 | It's written with node, which may seem a little silly (what if they don't have node yet?!), but the intent is to use this inside Electron apps. 26 | 27 | The first electron app to use this module is [dev-env-status](https://github.com/sethvincent/dev-env-status), a simple app that shows the availability of each tool and how to install it if needed. 28 | 29 | ## Work in progress 30 | 31 | There are still some improvements that need to be made before ready for use. [Contributions are welcome.](CONTRIBUTING.md) 32 | 33 | ### Planned improvements (PRs welcome!) 34 | 35 | This module needs to be tested and adapted for use on both linux and windows. 36 | 37 | There are ways this module can be smarter about detecting system dependencies. For example: what if a macOS user doesn't have `gcc` yet? 38 | 39 | For now this only checks node, npm, and git. It would be cool to accept arbitrary commands. 40 | 41 | Check out the [dev-env-status](https://github.com/sethvincent/dev-env-status) repo for additional improvements. 42 | 43 | ### Command-line tools that are checked: 44 | 45 | - `node` 46 | - `npm` 47 | - `git` 48 | 49 | ### Each tool returns an object with: 50 | 51 | - `exists` – boolean 52 | - `path` – absolute path for the command 53 | - `version` – version of the command 54 | 55 | ### Operating system information 56 | 57 | You're also provided information about the computer's operating system: 58 | 59 | - `arch` – return value of `os.arch()` 60 | - `platform` – return value of `os.platform()` 61 | - `release` – return value of `os.release()` 62 | - `name` – `macOS Sierra` for example 63 | 64 | ## Install 65 | 66 | ```sh 67 | npm install --save dev-env-status-check 68 | ``` 69 | 70 | ## Usage 71 | 72 | ```js 73 | var check = require('dev-env-status-check') 74 | 75 | var stream = check() 76 | 77 | stream.on('data', function (data) { 78 | if (data.type === 'os') { 79 | console.log('operating system info:', data) 80 | } else { 81 | console.log('status of ' + data.command + ':', data) 82 | } 83 | }) 84 | ``` 85 | 86 | Each data event returns an object with information about the computer. 87 | 88 | If the object has a `type` property of `os`, it contains information about the operating system: 89 | 90 | ```js 91 | { 92 | type: 'os', 93 | arch: 'x64', 94 | platform: 'darwin', 95 | release: '16.1.0', 96 | name: 'macOS Sierra' 97 | } 98 | ``` 99 | 100 | If the object has a `type` property of `command`, it contains information about one of the commands. For example: 101 | 102 | ```js 103 | { 104 | type: 'command', 105 | command: 'node', 106 | exists: true, 107 | path: '/Users/sdv/.nvm/versions/node/v6.9.1/bin/node', 108 | version: '6.9.1' 109 | } 110 | ``` 111 | 112 | ## Contributing 113 | 114 | Contributions are welcome! Please read the [contributing guidelines](CONTRIBUTING.md) first. 115 | 116 | ## Conduct 117 | 118 | It is important that this project contributes to a friendly, safe, and welcoming environment for all. Read this project's [code of conduct](CONDUCT.md) 119 | 120 | ## Changelog 121 | 122 | Read about the changes to this project in [CHANGELOG.md](CHANGELOG.md). The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). 123 | 124 | ## Contact 125 | 126 | - **issues** – Please open issues in the [issues queue](https://github.com/sethvincent/dev-env-status-check/issues) 127 | - **twitter** – Have a question? [@sethdvincent](https://twitter.com/sethdvincent) 128 | - **email** – Need in-depth support via paid contract? Send an email to sethvincent@gmail.com 129 | 130 | ## License 131 | 132 | [ISC](LICENSE.md) 133 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | var check = require('./index') 2 | 3 | var stream = check() 4 | 5 | stream.on('data', function (data) { 6 | if (data.type === 'os') { 7 | console.log('operating system info:', data) 8 | } else { 9 | console.log('status of ' + data.command + ':', data) 10 | } 11 | }) 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var os = require('os') 2 | var exec = require('child_process').exec 3 | var exists = require('command-exists') 4 | var through = require('through2') 5 | var each = require('each-async') 6 | var osName = require('os-name') 7 | var which = require('which') 8 | var xtend = require('xtend') 9 | 10 | module.exports = function devEnvStatusCheck (options) { 11 | var stream = through.obj() 12 | 13 | var osInfo = { 14 | type: 'os', 15 | arch: os.arch(), 16 | platform: os.platform(), 17 | release: os.release(), 18 | name: osName(os.platform(), os.release()) 19 | } 20 | 21 | stream.write(osInfo) 22 | 23 | var tools = { 24 | node: { 25 | versionFormat: function (str) { 26 | return str.split('v')[1] 27 | } 28 | }, 29 | npm: { 30 | versionFormat: function (str) { 31 | return str 32 | } 33 | }, 34 | git: { 35 | versionFormat: function (str) { 36 | return str.split('git version ')[1] 37 | } 38 | } 39 | } 40 | 41 | var keys = Object.keys(tools) 42 | 43 | each(keys, function (key, i, next) { 44 | var opts = tools[key] 45 | check(key, opts, function (status) { 46 | stream.write(xtend(status)) 47 | next() 48 | }) 49 | }, function () { 50 | stream.end() 51 | }) 52 | 53 | return stream 54 | } 55 | 56 | function check (tool, opts, callback) { 57 | var versionCmd = opts.versionCommand || tool + ' --version' 58 | var versionFormat = opts.versionFormat || function (str) { return str } 59 | 60 | var status = { 61 | type: 'command', 62 | command: tool 63 | } 64 | 65 | exists(tool, function (err, ok) { 66 | if (err) return error(status, tool, err, callback) 67 | 68 | if (ok) { 69 | status.exists = true 70 | which(tool, function (err, cmdpath) { 71 | if (err) return error(status, tool, err, callback) 72 | 73 | status.path = cmdpath 74 | exec(versionCmd, function (err, stdout, stderr) { 75 | if (err) return error(status, tool, err, callback) 76 | 77 | status.version = versionFormat(stdout.split('\n')[0]) 78 | callback(status) 79 | }) 80 | }) 81 | } else { 82 | status.exists = false 83 | callback(status) 84 | } 85 | }) 86 | } 87 | 88 | function error (status, property, err, cb) { 89 | status[property].err = err 90 | cb(status) 91 | } 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-env-status-check", 3 | "version": "1.0.0", 4 | "description": "Check the availability of common Node development environment dependencies", 5 | "main": "index.js", 6 | "dependencies": { 7 | "command-exists": "^1.0.2", 8 | "each-async": "^1.1.1", 9 | "os-name": "^2.0.1", 10 | "tape": "^4.6.3", 11 | "through2": "^2.0.1", 12 | "which": "^1.2.12", 13 | "xtend": "^4.0.1" 14 | }, 15 | "devDependencies": { 16 | "standard": "^8.5.0" 17 | }, 18 | "scripts": { 19 | "test": "standard && node tests/*.js" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/sethvincent/dev-env-status-check.git" 24 | }, 25 | "keywords": [ 26 | "dev env", 27 | "development environment", 28 | "nodeschool", 29 | "adventuretron" 30 | ], 31 | "author": "sethvincent", 32 | "license": "ISC", 33 | "bugs": { 34 | "url": "https://github.com/sethvincent/dev-env-status-check/issues" 35 | }, 36 | "homepage": "https://github.com/sethvincent/dev-env-status-check#readme" 37 | } 38 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | 3 | Tests are run using [tape](https://npmjs.com/tape). 4 | 5 | Linting is performed using [standard](https://npmjs.com/standard) 6 | 7 | ## Running tests 8 | 9 | ```sh 10 | git clone {this repo} 11 | cd {this repo} 12 | npm install 13 | npm test 14 | ``` 15 | 16 | `npm test` runs both the linter and the tests. 17 | 18 | ### Just run the linter 19 | 20 | ```sh 21 | npm run lint 22 | ``` 23 | 24 | ### Only run the tests 25 | 26 | ```sh 27 | npm run test:no-lint 28 | ``` 29 | -------------------------------------------------------------------------------- /tests/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | 3 | var check = require('../index') 4 | 5 | test('get os info, node, npm, and git', function (t) { 6 | var stream = check() 7 | var osStatus 8 | var tools = [] 9 | 10 | stream.on('data', function (data) { 11 | if (data.type === 'os') { 12 | osStatus = data 13 | } else { 14 | if (data.exists) tools.push(data) 15 | } 16 | }) 17 | 18 | stream.on('end', function () { 19 | t.ok(osStatus) 20 | t.equal(tools.length, 3) 21 | t.end() 22 | }) 23 | }) 24 | --------------------------------------------------------------------------------