1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| 'use strict';
module.exports = core;
const semver = require('semver'); const colors = require('colors/safe'); const userHome = require('user-home'); const pathExists = require('path-exists').sync; const log = require('@xuven-cli-dev/log');
const constant = require('./const'); const pkg = require('../package.json');
let args;
function core() { try { checkPkgVersion(); checkNodeVersion(); checkRoot(); checkUserHome(); checkInputArgs(); log.verbose('debug', 'test debug log'); } catch (e) { log.error(e.message); } }
function checkInputArgs() { const minimist = require('minimist'); args = minimist(process.argv.slice(2)); checkArgs(); }
function checkArgs() { if (args.debug) { process.env.LOG_LEVEL = 'verbose'; } else { process.env.LOG_LEVEL = 'info'; } log.level = process.env.LOG_LEVEL; }
function checkUserHome() { if (!userHome || !pathExists(userHome)) { throw new Error(colors.red('当前登录用户主目录不存在!')); } }
function checkRoot() { const rootCheck = require('root-check'); rootCheck(); }
function checkNodeVersion() { const currentVersion = process.version; const lowestVersion = constant.LOWEST_NODE_VERSION; if (!semver.gte(currentVersion, lowestVersion)) { throw new Error(colors.red(`xuven-cli-dev 需要安装 v${lowestVersion} 以上版本的 Node.js`)); } }
function checkPkgVersion() { log.info('cli', pkg.version); }
|