#!/usr/bin/env node
const semver = require('semver')
const chalk = require('chalk')
module.exports = {
  checkVersion (wanted: string) {
    if (semver.lt(process.version, wanted)) {
      console.log(chalk.red(
        '您所用的Node版本为：' + process.version + ', kd脚手架需要Node' + wanted + '.\n请切换Node版本，或者更新Node版本'
      ))
      process.exit(1)
    }
  },
  isPrimitive (value: any): boolean {
    return (
      typeof value === 'string' ||
      typeof value === 'number' ||
      // $flow-disable-line
      typeof value === 'symbol' ||
      typeof value === 'boolean'
    )
  },
  getType(sup: any) {
    return (sup.toString().match(/function\s*(\w+)\s*\(\)/) || [])[1]
  }
}
