github-desktop/app/app-info.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

import * as fs from 'fs'
2017-12-22 12:04:04 +00:00
import * as Path from 'path'
2017-12-22 12:04:04 +00:00
import { getSHA } from './git-info'
import { getUpdatesURL, getChannel } from '../script/dist-info'
import { version, productName } from './package.json'
2017-12-22 12:04:04 +00:00
const projectRoot = Path.dirname(__dirname)
const devClientId = '3a723b10ac5575cc5bb9'
const devClientSecret = '22c34d87789a365981ed921352a7b9a8c3f69d54'
const channel = getChannel()
2017-12-22 12:04:04 +00:00
export function getCLICommands() {
return (
// eslint-disable-next-line no-sync
fs
.readdirSync(Path.resolve(projectRoot, 'app', 'src', 'cli', 'commands'))
.filter(name => name.endsWith('.ts'))
.map(name => name.replace(/\.ts$/, ''))
)
}
2017-12-22 12:04:04 +00:00
const s = JSON.stringify
2017-12-22 12:04:04 +00:00
export function getReplacements() {
const isDevBuild = channel === 'development'
return {
__OAUTH_CLIENT_ID__: s(process.env.DESKTOP_OAUTH_CLIENT_ID || devClientId),
__OAUTH_SECRET__: s(
process.env.DESKTOP_OAUTH_CLIENT_SECRET || devClientSecret
),
__DARWIN__: process.platform === 'darwin',
__WIN32__: process.platform === 'win32',
__LINUX__: process.platform === 'linux',
__APP_NAME__: s(productName),
__APP_VERSION__: s(version),
__DEV__: isDevBuild,
__RELEASE_CHANNEL__: s(channel),
2017-12-22 12:04:04 +00:00
__UPDATES_URL__: s(getUpdatesURL()),
__SHA__: s(getSHA()),
__CLI_COMMANDS__: s(getCLICommands()),
'process.platform': s(process.platform),
'process.env.NODE_ENV': s(process.env.NODE_ENV || 'development'),
'process.env.TEST_ENV': s(process.env.TEST_ENV),
}
}