forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (51 loc) · 2.04 KB
/
index.js
File metadata and controls
60 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import path from 'path'
import { app } from 'electron'
import os from 'os'
import { isDirectory } from 'common/filesystem'
import parseArgs from './parser'
import { getPath } from '../utils'
const write = s => process.stdout.write(s)
const writeLine = s => write(s + '\n')
const cli = () => {
let argv = process.argv.slice(1)
if (process.env.NODE_ENV === 'development') {
// Don't pass electron development arguments to MarkText and change user data path.
argv = ['--user-data-dir', path.join(getPath('appData'), 'marktext-dev')]
}
const args = parseArgs(argv, true)
if (args['--help']) {
write(`Usage: marktext [commands] [path ...]
Available commands:
--debug Enable debug mode
--safe Disable plugins and other user configuration
-n, --new-window Open a new window on second-instance
--user-data-dir Change the user data directory
--disable-gpu Disable GPU hardware acceleration
--disable-spellcheck Disable built-in spellchecker
-v, --verbose Be verbose
--version Print version information
-h, --help Print this help message
`)
process.exit(0)
}
if (args['--version']) {
writeLine(`MarkText: ${global.MARKTEXT_VERSION_STRING}`)
writeLine(`Node.js: ${process.versions.node}`)
writeLine(`Electron: ${process.versions.electron}`)
writeLine(`Chromium: ${process.versions.chrome}`)
writeLine(`OS: ${os.type()} ${os.arch()} ${os.release()}`)
process.exit(0)
}
// Check for portable mode and ensure the user data path is absolute. We assume
// that the path is writable if not this lead to an application crash.
if (!args['--user-data-dir']) {
const portablePath = path.join(app.getAppPath(), '..', '..', 'marktext-user-data')
if (isDirectory(portablePath)) {
args['--user-data-dir'] = portablePath
}
} else {
args['--user-data-dir'] = path.resolve(args['--user-data-dir'])
}
return args
}
export default cli