UNPKG

2.71 kBPlain TextView Raw
1#!/usr/bin/env node
2
3const
4 parseArgs = require('minimist'),
5 chalk = require('chalk')
6
7const
8 appPaths = require('../lib/app-paths')
9
10const argv = parseArgs(process.argv.slice(2), {
11 alias: {
12 h: 'help'
13 },
14 boolean: ['h']
15})
16
17if (argv.help) {
18 console.log(`
19 Description
20 Displays information about your machine and your Quasar App.
21 Usage
22 $ quasar info
23 Options
24 --help, -h Displays this message
25 `)
26 process.exit(0)
27}
28
29const
30 os = require('os'),
31 spawn = require('cross-spawn').sync
32
33function getSpawnOutput (command) {
34 try {
35 const child = spawn(command, ['--version'])
36 return child.status === 0
37 ? chalk.green(String(child.output[1]).trim())
38 : chalk.red('Not installed')
39 }
40 catch (err) {
41 return chalk.red('Not installed')
42 }
43}
44
45function safePkgInfo (pkg) {
46 try {
47 const content = require(appPaths.resolve.app(`node_modules/${pkg}/package.json`))
48 return {
49 key: ` ${String(content.name).trim()}`,
50 value: `${chalk.green(String(content.version).trim())}${content.description ? `\t(${content.description})` : ''}`
51 }
52 }
53 catch (err) {
54 return {
55 key: ` ${pkg}`,
56 value: chalk.red('Not installed')
57 }
58 }
59}
60
61const
62 getExternalIPs = require('../lib/helpers/net').getExternalNetworkInterface,
63 output = [
64 { key: 'Operating System', value: chalk.green(`${os.type()}(${os.release()}) - ${os.platform()}/${os.arch()}`), section: true },
65 { key: 'NodeJs', value: chalk.green(process.version.slice(1)) },
66 { key: 'Global packages', section: true },
67 { key: ' NPM', value: getSpawnOutput('npm') },
68 { key: ' yarn', value: getSpawnOutput('yarn') },
69 { key: ' quasar-cli', value: getSpawnOutput('quasar') },
70 { key: ' vue-cli', value: getSpawnOutput('vue') },
71 { key: ' cordova', value: getSpawnOutput('cordova') },
72 { key: 'Important local packages', section: true }
73 ]
74
75;[
76 'quasar-cli',
77 'quasar-framework',
78 'quasar-extras',
79 'vue',
80 'vue-router',
81 'vuex',
82 'electron',
83 'electron-packager',
84 'electron-builder',
85 '@babel/core',
86 'webpack',
87 'webpack-dev-server',
88 'workbox-webpack-plugin',
89 'register-service-worker'
90].forEach(pkg => output.push(safePkgInfo(pkg)))
91
92output.push(
93 { key: 'Networking', section: true },
94 { key: ' Host', value: chalk.green(os.hostname()) }
95)
96getExternalIPs().forEach(intf => {
97 output.push({
98 key: ` ${ intf.deviceName }`,
99 value: chalk.green(intf.address)
100 })
101})
102
103const spaces = output.reduce((acc, v) => Math.max(acc, v.key.length), 0)
104console.log(
105 output
106 .map(m => `${m.section ? '\n' : ''}${ m.key }${' '.repeat(spaces - m.key.length)}\t${ m.value === undefined ? '' : m.value }`).join('\n')
107)
108console.log()