github-desktop/script/review-logs.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-10-19 23:04:47 +00:00
/* eslint-disable no-sync */
import * as fs from 'fs'
import * as path from 'path'
2017-11-20 01:30:16 +00:00
import * as os from 'os'
import { getProductName } from '../app/package-info'
import { getExecutableName } from './dist-info'
function getUserDataPath() {
if (process.platform === 'win32') {
2018-06-22 13:44:22 +00:00
if (process.env.APPDATA) {
return path.join(process.env.APPDATA, getExecutableName())
} else {
throw new Error(
`Unable to find the application data directory on Windows :(`
)
}
2017-11-20 01:30:16 +00:00
} else if (process.platform === 'darwin') {
const home = os.homedir()
return path.join(home, 'Library', 'Application Support', getProductName())
} else if (process.platform === 'linux') {
if (process.env.XDG_CONFIG_HOME) {
return path.join(process.env.XDG_CONFIG_HOME, getProductName())
}
const home = os.homedir()
return path.join(home, '.config', getProductName())
} else {
throw new Error(
2020-06-24 18:28:06 +00:00
`I dunno how to resolve the user data path for ${process.platform} ${process.arch} :(`
2017-11-20 01:30:16 +00:00
)
}
}
export function getLogFiles(): ReadonlyArray<string> {
2017-09-24 00:01:43 +00:00
const directory = path.join(getUserDataPath(), 'logs')
if (!fs.existsSync(directory)) {
return []
}
const fileNames = fs.readdirSync(directory)
return fileNames
.filter(fileName => fileName.endsWith('.log'))
.map(fileName => path.join(directory, fileName))
}