UNPKG

1.56 kBJavaScriptView Raw
1'use strict'
2
3const _ = require('lodash')
4const { version: elintVersion } = require('../package.json')
5const { version: eslintVersion } = require('eslint/package.json')
6const { version: stylelintVersion } = require('stylelint/package.json')
7const { version: commitlintVersion } = require('@commitlint/core/package.json')
8const { version: huskyVersion } = require('husky/package.json')
9const tryRequire = require('./utils/try-require')
10const padEnd = require('./utils/pad-end')
11
12/**
13 * 输出 version
14 *
15 * @returns {void}
16 */
17function version () {
18 const main = {
19 elint: elintVersion
20 }
21
22 const dep = {
23 eslint: eslintVersion,
24 stylelint: stylelintVersion,
25 commitlint: commitlintVersion,
26 husky: huskyVersion
27 }
28
29 const preset = tryRequire(/elint-preset/)[0]
30 if (preset) {
31 // eslint-disable-next-line global-require
32 const { version: presetVersion } = require(`${preset}/package.json`)
33 main[preset] = presetVersion
34 }
35
36 const output = ['> elint version', '']
37
38 const mainNameLength = Math.max(...Object.keys(main).map(k => k.length))
39
40 // 兼容 node v6
41 _.toPairs(main).forEach(([name, version]) => {
42 output.push(` ${padEnd(name, mainNameLength)} : ${version}`)
43 })
44
45 output.push('')
46 output.push(' Dependencies:')
47
48 const depNameLength = Math.max(...Object.keys(dep).map(k => k.length))
49
50 // 兼容 node v6
51 _.toPairs(dep).forEach(([name, version]) => {
52 output.push(` ${padEnd(name, depNameLength)} : ${version}`)
53 })
54
55 output.push('')
56
57 console.log(output.join('\n'))
58}
59
60module.exports = version