@@ -4,38 +4,21 @@ import {homedir} from 'os'
44import * as path from 'path'
55
66let configDir
7- if ( process . env . HMD_CLI_CONFIG_DIR || process . env . CMD_CLI_CONFIG_DIR ) {
8- configDir = process . env . HMD_CLI_CONFIG_DIR || process . env . CMD_CLI_CONFIG_DIR || ''
7+ if ( process . env . HMD_CLI_CONFIG_DIR ) {
8+ configDir = process . env . HMD_CLI_CONFIG_DIR || ''
99} else {
1010 configDir = path . join ( homedir ( ) , '.hackmd' )
1111}
1212
1313const configFilePath = path . join ( configDir , 'config.json' )
14- const defaultCookiePath = path . join ( homedir ( ) , '.hackmd' , 'cookies.json' )
1514
1615const defaultConfig = {
17- cookiePath : defaultCookiePath ,
18- serverUrl : 'https://hackmd.io' ,
19- enterprise : true
20- }
21-
22- function toBooleanConfig ( configValue ?: string | boolean ) {
23- if ( configValue && typeof configValue === 'string' ) {
24- return ( configValue === 'true' )
25- }
26- return configValue
16+ hackmdAPIEndpointURL : 'https://api.hackmd.io/v1'
2717}
2818
2919const envConfig = {
30- cookiePath : process . env . HMD_CLI_COOKIE_PATH || process . env . CMD_CLI_COOKIE_PATH ,
31- serverUrl : process . env . HMD_CLI_SERVER_URL || process . env . CMD_CLI_SERVER_URL ,
32- enterprise : ( process . env . HMD_CLI_COOKIE_PATH || process . env . HMD_CLI_SERVER_URL )
33- ? true
34- : ( process . env . CMD_CLI_COOKIE_PATH || process . env . CMD_CLI_SERVER_URL )
35- ? false
36- : toBooleanConfig ( process . env . HMD_CLI_ENTERPRISE ) ,
37- loginID : process . env . HMD_CLI_ID || process . env . CMD_CLI_ID ,
38- loginPassword : process . env . HMD_CLI_PASSWORD || process . env . CMD_CLI_PASSWORD
20+ hackmdAPIEndpointURL : process . env . HMD_API_ENDPOINT_URL ,
21+ accesstoken : process . env . HMD_API_ACCESS_TOKEN
3922}
4023
4124// look for a readable config file; we can merge it with the env.
@@ -66,54 +49,4 @@ ${err}
6649// prefer environment config over file config
6750const config = defaults ( envConfig , readConfig , defaultConfig )
6851
69- const cookieDirPath = path . dirname ( config . cookiePath )
70- try {
71- fs . mkdirSync ( cookieDirPath )
72- } catch ( err ) {
73- if ( err . code !== 'EEXIST' ) {
74- throw new Error ( `
75-
76- Could not create dir for cookie file at ${ cookieDirPath } . Encountered exception:
77-
78- ${ err }
79-
80- ` )
81- }
82- // at this point, the directory exists. if the cookie file does not exist,
83- // ensure the dir is writable (because we will create the file); otherwise
84- // ensure the file itself is writable.
85- let hasExistingCookieFile = false
86- try {
87- fs . existsSync ( config . cookiePath )
88- hasExistingConfigFile = true
89- // tslint:disable-next-line: no-unused
90- } catch ( ignored ) { }
91-
92- if ( hasExistingCookieFile ) {
93- try {
94- fs . accessSync ( config . cookiePath , fs . constants . W_OK )
95- } catch ( err ) {
96- throw new Error ( `
97-
98- Cookie file ${ config . cookiePath } is not writable. Encountered exception:
99-
100- ${ err }
101-
102- ` )
103- }
104- } else {
105- try {
106- fs . accessSync ( cookieDirPath , fs . constants . W_OK )
107- } catch ( err ) {
108- throw new Error ( `
109-
110- Dir for cookie file at ${ cookieDirPath } is not writable. Encountered exception:
111-
112- ${ err }
113-
114- ` )
115- }
116- }
117- }
118-
11952export default config
0 commit comments