├── .gitignore ├── .gitattributes ├── .travis.yml ├── cli.js ├── .editorconfig ├── .jshintrc ├── readme.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | require('./doctor').run(); 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "curly": true, 6 | "eqeqeq": true, 7 | "eqnull": true, 8 | "immed": true, 9 | "latedef": true, 10 | "newcap": true, 11 | "noarg": true, 12 | "undef": true, 13 | "strict": false, 14 | "indent": 2, 15 | "quotmark": "single", 16 | "laxbreak": true 17 | } 18 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Yeoman Doctor [![Build Status](https://travis-ci.org/yeoman/doctor.svg?branch=master)](https://travis-ci.org/yeoman/doctor) 2 | 3 | > Detect potential issues with users system that could prevent Yeoman from working correctly 4 | 5 | 6 | ## Usage 7 | 8 | Use as part of [yo](https://github.com/yeoman/yo): 9 | 10 | ```sh 11 | $ yo doctor 12 | ``` 13 | 14 | If installed globally, you can also call `yodoctor`. 15 | 16 | 17 | ## License 18 | 19 | [BSD license](http://opensource.org/licenses/bsd-license.php) and copyright Google. 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yeoman-doctor", 3 | "version": "1.0.0", 4 | "description": "Detect potential issues with users system that could prevent Yeoman from working correctly", 5 | "license": "BSD", 6 | "author": "Yeoman team", 7 | "repository": "yeoman/doctor", 8 | "engines": { 9 | "node": ">=0.10.0", 10 | "npm": ">=1.4.3" 11 | }, 12 | "bin": { 13 | "yodoctor": "cli.js" 14 | }, 15 | "scripts": { 16 | "test": "jshint index.js" 17 | }, 18 | "files": [ 19 | "index.js", 20 | "cli.js" 21 | ], 22 | "keywords": [ 23 | "yeoman", 24 | "yo", 25 | "doctor" 26 | ], 27 | "dependencies": { 28 | "chalk": "^0.5.1", 29 | "shelljs": "^0.3.0", 30 | "user-home": "^1.1.0" 31 | }, 32 | "devDependencies": { 33 | "jshint": "^2.5.6" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var chalk = require('chalk'); 6 | var shell = require('shelljs'); 7 | var userHome = require('user-home'); 8 | 9 | var doctor = module.exports = { 10 | errors: [], 11 | 12 | run: function () { 13 | this.checkNodePath(); 14 | this.checkGlobalConfig(); 15 | this.logErrors(); 16 | }, 17 | 18 | logErrors: function () { 19 | if (!this.errors.length) { 20 | console.log(chalk.green('[Yeoman Doctor] Everything looks all right!')); 21 | console.log(); 22 | return; 23 | } 24 | 25 | console.log(chalk.red('[Yeoman Doctor] Uh oh, I found potential errors on your machine\n---------------\n')); 26 | this.errors.forEach(function (errMsg) { 27 | console.log('[' + chalk.red('Error') + '] ' + errMsg); 28 | console.log(); 29 | }); 30 | }, 31 | 32 | checkNodePath: function () { 33 | if (!process.env.NODE_PATH) { 34 | return; 35 | } 36 | 37 | var nodePaths = process.env.NODE_PATH.split(path.delimiter).map(path.normalize); 38 | var npmRoot = shell.exec('npm -g root', { silent: true }).output; 39 | 40 | npmRoot = path.normalize(npmRoot.trim()); 41 | 42 | if (nodePaths.indexOf(npmRoot) < 0) { 43 | this.nodePathMismatch({ 44 | nodePaths: nodePaths, 45 | npmRoot: npmRoot 46 | }); 47 | } 48 | }, 49 | 50 | nodePathMismatch: function (val) { 51 | var output = ''; 52 | output += 'npm root value is not in your NODE_PATH\n'; 53 | output += ' [' + chalk.cyan('info') + ']\n'; 54 | output += [ 55 | ' NODE_PATH = ' + val.nodePaths.join(path.delimiter), 56 | ' npm root = ' + val.npmRoot 57 | ].join('\n'); 58 | output += '\n\n [' + chalk.cyan('Fix') + '] Append the npm root value to your NODE_PATH variable\n'; 59 | 60 | if (process.platform === 'win32') { 61 | output += [ 62 | ' If you\'re using cmd.exe, run this command to fix the issue:', 63 | ' setx NODE_PATH "%NODE_PATH%;' + val.npmRoot + '"', 64 | ' Then restart your command line. Otherwise, you can setup NODE_PATH manually:', 65 | ' https://github.com/sindresorhus/guides/blob/master/set-environment-variables.md#windows' 66 | ].join('\n'); 67 | } else { 68 | output += [ 69 | ' Add this line to your .bashrc', 70 | ' export NODE_PATH=$NODE_PATH:' + val.npmRoot, 71 | ' Or run this command', 72 | ' echo "export NODE_PATH=$NODE_PATH:' + val.npmRoot + '" >> ~/.bashrc && source ~/.bashrc' 73 | ].join('\n'); 74 | } 75 | 76 | this.errors.push(output); 77 | }, 78 | 79 | checkGlobalConfig: function() { 80 | var configPath = path.join(userHome, '.yo-rc-global.json'); 81 | 82 | if (!fs.existsSync(configPath)) { 83 | return; 84 | } 85 | 86 | try { 87 | JSON.parse(fs.readFileSync(configPath, 'utf8')); 88 | } catch (err) { 89 | if (err instanceof SyntaxError) { 90 | var output = [ 91 | 'Your global config file is not a valid JSON.', 92 | 'It contains the following syntax error: ' + err.message, 93 | 'Please open \'' + configPath + '\' and fix it manually.' 94 | ].join('\n'); 95 | this.errors.push(output); 96 | } else { 97 | this.errors.push(err.message); 98 | } 99 | } 100 | } 101 | }; 102 | --------------------------------------------------------------------------------