mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-17 11:17:28 +03:00
fix(tauri.js): eslint errors (#250)
This commit is contained in:
parent
232af15a2e
commit
fbfacb5e44
@ -1,7 +1,7 @@
|
||||
import { TauriConfig } from 'types'
|
||||
import merge from 'webpack-merge'
|
||||
const getTauriConfig = require('../helpers/tauri-config')
|
||||
import Runner from '../runner'
|
||||
const getTauriConfig = require('../helpers/tauri-config')
|
||||
|
||||
module.exports = async (config: TauriConfig): Promise<void> => {
|
||||
const tauri = new Runner()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { TauriConfig } from 'types'
|
||||
import merge from 'webpack-merge'
|
||||
const getTauriConfig = require('../helpers/tauri-config')
|
||||
import Runner from '../runner'
|
||||
const getTauriConfig = require('../helpers/tauri-config')
|
||||
|
||||
module.exports = async (config: TauriConfig): Promise<void> => {
|
||||
const tauri = new Runner()
|
||||
|
@ -1,14 +1,16 @@
|
||||
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')
|
||||
import toml from '@tauri-apps/toml'
|
||||
import chalk from 'chalk'
|
||||
import { sync as spawn } from 'cross-spawn'
|
||||
import fs from 'fs'
|
||||
import os from 'os'
|
||||
import path from 'path'
|
||||
import { appDir, tauriDir } from '../helpers/app-paths'
|
||||
import { TauriConfig } from './../types/config'
|
||||
|
||||
interface DirInfo {
|
||||
path: string
|
||||
name: string
|
||||
type?: 'folder'|'file'
|
||||
type?: 'folder' | 'file'
|
||||
children?: DirInfo[]
|
||||
}
|
||||
|
||||
@ -21,9 +23,9 @@ function dirTree(filename: string): DirInfo {
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
info.type = 'folder'
|
||||
info.children = fs.readdirSync(filename).map(function (child: string) {
|
||||
info.children = fs.readdirSync(filename).map(function(child: string) {
|
||||
return dirTree(filename + '/' + child)
|
||||
});
|
||||
})
|
||||
} else {
|
||||
info.type = 'file'
|
||||
}
|
||||
@ -31,16 +33,21 @@ function dirTree(filename: string): DirInfo {
|
||||
return info
|
||||
}
|
||||
|
||||
function getVersion (command: string, args: string[] = [], formatter?: (output: string) => string) {
|
||||
function getVersion(
|
||||
command: string,
|
||||
args: string[] = [],
|
||||
formatter?: (output: string) => 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
|
||||
.green(formatter === undefined ? output : formatter(output))
|
||||
.replace('\n', '')
|
||||
}
|
||||
return chalk.red('Not installed')
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
return chalk.red('Not installed')
|
||||
}
|
||||
}
|
||||
@ -51,21 +58,24 @@ interface Info {
|
||||
value?: string
|
||||
}
|
||||
|
||||
function printInfo (info: Info) {
|
||||
console.log(`${info.section ? '\n' : ''}${info.key}${info.value === undefined ? '' : ' - ' + info.value}`)
|
||||
function printInfo(info: Info): void {
|
||||
console.log(
|
||||
`${info.section ? '\n' : ''}${info.key}${
|
||||
info.value === undefined ? '' : ' - ' + info.value
|
||||
}`
|
||||
)
|
||||
}
|
||||
|
||||
function printAppInfo(tauriDir: string) {
|
||||
function printAppInfo(tauriDir: string): void {
|
||||
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 tauriVersion = (): string => {
|
||||
const tauri = tomlContents.dependencies.tauri
|
||||
if (tauri) {
|
||||
if (tauri.version) {
|
||||
@ -73,57 +83,97 @@ function printAppInfo(tauriDir: string) {
|
||||
}
|
||||
if (tauri.path) {
|
||||
try {
|
||||
const tauriTomlPath = path.resolve(tauriDir, tauri.path, 'Cargo.toml')
|
||||
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.green(
|
||||
`${tauriTomlContents.package.version} (from source)`
|
||||
)
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
return chalk.red('unknown')
|
||||
}
|
||||
|
||||
|
||||
printInfo({ key: ' tauri', value: tauriVersion() })
|
||||
}
|
||||
catch (_) { }
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
const tauriMode = (config: TauriConfig): string => {
|
||||
if (config.tauri.embeddedServer) {
|
||||
return chalk.green(config.tauri.embeddedServer.active ? 'embedded-server' : 'no-server')
|
||||
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 (_) { }
|
||||
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: '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: ' 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: ' 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 || [])) {
|
||||
for (const artifact of tree.children || []) {
|
||||
if (artifact.type === 'folder') {
|
||||
console.log(`/${artifact.name}`)
|
||||
}
|
||||
|
@ -1,16 +1,21 @@
|
||||
import { inject } from '../template'
|
||||
import { TauriConfig } from 'types'
|
||||
import { inject } from '../template'
|
||||
|
||||
module.exports = (args: {
|
||||
directory: string
|
||||
force: false | 'conf' | 'template' | 'all'
|
||||
logging: boolean
|
||||
tauriPath?: string,
|
||||
tauriPath?: string
|
||||
customConfig?: Partial<TauriConfig>
|
||||
}): boolean => {
|
||||
return inject(args.directory, 'all', {
|
||||
force: args.force,
|
||||
logging: args.logging,
|
||||
tauriPath: args.tauriPath
|
||||
}, args.customConfig)
|
||||
return inject(
|
||||
args.directory,
|
||||
'all',
|
||||
{
|
||||
force: args.force,
|
||||
logging: args.logging,
|
||||
tauriPath: args.tauriPath
|
||||
},
|
||||
args.customConfig
|
||||
)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
import fglob from 'fast-glob'
|
||||
import fs from 'fs-extra'
|
||||
import { isBinaryFileSync as isBinary } from 'isbinaryfile'
|
||||
import { template } from 'lodash'
|
||||
import { template } from 'lodash'
|
||||
import { join, resolve } from 'path'
|
||||
|
||||
const copyTemplates = ({
|
||||
|
Loading…
Reference in New Issue
Block a user