|
@ -1,5 +1,5 @@ |
|
|
import { homedir } from 'os'; |
|
|
import { homedir } from 'os'; |
|
|
import { join as pathJoin } from 'path'; |
|
|
import path from 'path'; |
|
|
import fs from 'fs-promise'; |
|
|
import fs from 'fs-promise'; |
|
|
import fetch from 'node-fetch'; |
|
|
import fetch from 'node-fetch'; |
|
|
import { stringify as stringifyQuery } from 'querystring'; |
|
|
import { stringify as stringifyQuery } from 'querystring'; |
|
@ -77,12 +77,13 @@ async function register () { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default async function () { |
|
|
export default async function () { |
|
|
const path = resolve(os.homedir(), '.now.json'); |
|
|
const file = path.resolve(homedir(), '.now.json'); |
|
|
const loginData = await register(); |
|
|
const loginData = await register(); |
|
|
let existing = null; |
|
|
let existing = null; |
|
|
try { |
|
|
try { |
|
|
existing = await fs.readFile(path, 'utf8'); |
|
|
existing = await fs.readFile(file, 'utf8'); |
|
|
} catch(err){} |
|
|
existing = JSON.parse(existing); |
|
|
|
|
|
} catch (err) {} |
|
|
const config = Object.extend({}, existing, loginData); |
|
|
const config = Object.extend({}, existing, loginData); |
|
|
return fs.writeFile(path, JSON.stringify(config)); |
|
|
return fs.writeFile(file, JSON.stringify(config)); |
|
|
} |
|
|
} |
|
|