1 | 'use strict'
|
2 |
|
3 | const _ = require('lodash')
|
4 | const { version: elintVersion } = require('../package.json')
|
5 | const { version: eslintVersion } = require('eslint/package.json')
|
6 | const { version: stylelintVersion } = require('stylelint/package.json')
|
7 | const { version: commitlintVersion } = require('@commitlint/core/package.json')
|
8 | const { version: huskyVersion } = require('husky/package.json')
|
9 | const tryRequire = require('./utils/try-require')
|
10 | const padEnd = require('./utils/pad-end')
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function 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 |
|
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 |
|
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 |
|
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 |
|
60 | module.exports = version
|