mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(tauri.js) add tauri info command (#236)
* feat(tauri.js) add `tauri info` command * fix(bug-report): add command information - thanks @nklayman for the reminder * fix(tauri-info): add cargo version * feat(tauri.js) add cargo.toml and tauri.conf.json info Co-authored-by: nothingismagick <drthompsonsmagickindustries@gmail.com>
This commit is contained in:
committed by
GitHub
parent
7845ec0e7a
commit
3ce95d2760
9
.github/ISSUE_TEMPLATE/bug_report.md
vendored
9
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -23,13 +23,16 @@ A clear and concise description of what you expected to happen.
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Platform (please complete the following information):**
|
||||
**Platform and Versions (please complete the following information):**
|
||||
<!-- You can use the `tauri info` command to get this information -->
|
||||
OS:
|
||||
Node:
|
||||
NPM:
|
||||
Yarn:
|
||||
Tauri Binding:
|
||||
Bundle Target:
|
||||
Rustc:
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
**Stack Trace**
|
||||
<!-- add if applicable -->
|
||||
3
cli/tauri.js/bin/tauri-info.js
Normal file
3
cli/tauri.js/bin/tauri-info.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const info = require('../dist/api/info')
|
||||
|
||||
info()
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const cmds = ['init', 'dev', 'build', 'help', 'icon']
|
||||
const cmds = ['init', 'dev', 'build', 'help', 'icon', 'info']
|
||||
|
||||
const cmd = process.argv[2]
|
||||
/**
|
||||
|
||||
132
cli/tauri.js/src/api/info.ts
Normal file
132
cli/tauri.js/src/api/info.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import { TauriConfig } from './../types/config';
|
||||
const os = require('os')
|
||||
const spawn = require('cross-spawn').sync
|
||||
const chalk = require('chalk')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
interface DirInfo {
|
||||
path: string
|
||||
name: string
|
||||
type?: 'folder'|'file'
|
||||
children?: DirInfo[]
|
||||
}
|
||||
|
||||
function dirTree(filename: string): DirInfo {
|
||||
const stats = fs.lstatSync(filename)
|
||||
const info: DirInfo = {
|
||||
path: filename,
|
||||
name: path.basename(filename)
|
||||
}
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
info.type = 'folder'
|
||||
info.children = fs.readdirSync(filename).map(function (child: string) {
|
||||
return dirTree(filename + '/' + child)
|
||||
});
|
||||
} else {
|
||||
info.type = 'file'
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
function getVersion (command: string, args: string[] = [], formatter?: (output: string) => string) {
|
||||
try {
|
||||
const child = spawn(command, [...args, '--version'])
|
||||
if (child.status === 0) {
|
||||
const output = String(child.output[1])
|
||||
return chalk.green(formatter === undefined ? output : formatter(output)).replace('\n', '')
|
||||
}
|
||||
return chalk.red('Not installed')
|
||||
}
|
||||
catch (err) {
|
||||
return chalk.red('Not installed')
|
||||
}
|
||||
}
|
||||
|
||||
interface Info {
|
||||
section?: boolean
|
||||
key: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
function printInfo (info: Info) {
|
||||
console.log(`${info.section ? '\n' : ''}${info.key}${info.value === undefined ? '' : ' - ' + info.value}`)
|
||||
}
|
||||
|
||||
function printAppInfo(tauriDir: string) {
|
||||
printInfo({ key: 'App', section: true })
|
||||
|
||||
try {
|
||||
const toml = require('@tauri-apps/toml')
|
||||
const tomlPath = path.join(tauriDir, 'Cargo.toml')
|
||||
const tomlFile = fs.readFileSync(tomlPath)
|
||||
// @ts-ignore
|
||||
const tomlContents = toml.parse(tomlFile)
|
||||
|
||||
const tauriVersion = () => {
|
||||
const tauri = tomlContents.dependencies.tauri
|
||||
if (tauri) {
|
||||
if (tauri.version) {
|
||||
return chalk.green(tauri.version)
|
||||
}
|
||||
if (tauri.path) {
|
||||
try {
|
||||
const tauriTomlPath = path.resolve(tauriDir, tauri.path, 'Cargo.toml')
|
||||
const tauriTomlFile = fs.readFileSync(tauriTomlPath)
|
||||
// @ts-ignore
|
||||
const tauriTomlContents = toml.parse(tauriTomlFile)
|
||||
return chalk.green(`${tauriTomlContents.package.version} (from source)`)
|
||||
} catch (_) { }
|
||||
}
|
||||
}
|
||||
return chalk.red('unknown')
|
||||
}
|
||||
|
||||
|
||||
printInfo({ key: ' tauri', value: tauriVersion() })
|
||||
}
|
||||
catch (_) { }
|
||||
|
||||
try {
|
||||
const tauriMode = (config: TauriConfig): string => {
|
||||
if (config.tauri.embeddedServer) {
|
||||
return chalk.green(config.tauri.embeddedServer.active ? 'embedded-server' : 'no-server')
|
||||
}
|
||||
return chalk.red('unset')
|
||||
}
|
||||
const configPath = path.join(tauriDir, 'tauri.conf.json')
|
||||
const config = __non_webpack_require__(configPath) as TauriConfig
|
||||
printInfo({ key: ' mode', value: tauriMode(config) })
|
||||
printInfo({ key: ' build-type', value: config.tauri.bundle && config.tauri.bundle.active ? 'bundle' : 'build' })
|
||||
printInfo({ key: ' CSP', value: config.tauri.security ? config.tauri.security.csp : 'unset' })
|
||||
printInfo({ key: ' Windows', value: config.tauri.edge && config.tauri.edge.active ? 'Edge' : 'MSHTML' })
|
||||
printInfo({ key: ' distDir', value: config.build ? chalk.green(config.build.distDir) : chalk.red('unset') })
|
||||
printInfo({ key: ' devPath', value: config.build ? chalk.green(config.build.devPath) : chalk.red('unset') })
|
||||
} catch (_) { }
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
printInfo({ key: 'Operating System', value: chalk.green(`${os.type()}(${os.release()}) - ${os.platform()}/${os.arch()}`), section: true })
|
||||
printInfo({ key: 'Node.js environment', section: true })
|
||||
printInfo({ key: ' Node.js', value: chalk.green(process.version.slice(1)) })
|
||||
printInfo({ key: ' tauri.js', value: chalk.green(require('../../package.json').version) })
|
||||
printInfo({ key: 'Rust environment', section: true })
|
||||
printInfo({ key: ' rustc', value: getVersion('rustc', [], output => output.split(' ')[1]) })
|
||||
printInfo({ key: ' cargo', value: getVersion('cargo', [], output => output.split(' ')[1]) })
|
||||
printInfo({ key: ' tauri-cli', value: getVersion('cargo', ['tauri-cli']) })
|
||||
printInfo({ key: 'Global packages', section: true })
|
||||
printInfo({ key: ' NPM', value: getVersion('npm') })
|
||||
printInfo({ key: ' yarn', value: getVersion('yarn') })
|
||||
printInfo({ key: 'App directory structure', section: true })
|
||||
|
||||
const { appDir, tauriDir } = require('../helpers/app-paths')
|
||||
const tree = dirTree(appDir)
|
||||
for (const artifact of (tree.children || [])) {
|
||||
if (artifact.type === 'folder') {
|
||||
console.log(`/${artifact.name}`)
|
||||
}
|
||||
}
|
||||
printAppInfo(tauriDir)
|
||||
}
|
||||
@@ -7,7 +7,8 @@ module.exports = {
|
||||
'api/dev': './src/api/dev.ts',
|
||||
'api/init': './src/api/init.ts',
|
||||
'api/tauricon': './src/api/tauricon.ts',
|
||||
'helpers/tauri-config': './src/helpers/tauri-config.ts'
|
||||
'helpers/tauri-config': './src/helpers/tauri-config.ts',
|
||||
'api/info': './src/api/info.ts'
|
||||
},
|
||||
mode: process.env.NODE_ENV || 'development',
|
||||
devtool: 'source-map',
|
||||
|
||||
Reference in New Issue
Block a user