UNPKG

mydata-cli

Version:

A CLI tool for interacting with MyData API and managing data. Supports login, data retrieval, and more. Built with Node.js.

27 lines (22 loc) 684 B
import fs from "fs-extra"; const configPath = "./.mycli-config.json"; export function saveToken(token) { const config = getConfig(); // 👈 Preserve existing keys config.token = token; fs.writeJsonSync(configPath, config, { spaces: 2 }); } export function getToken() { if (fs.existsSync(configPath)) { const { token } = fs.readJsonSync(configPath); return token; } return null; } export function getConfig() { return fs.existsSync(configPath) ? fs.readJsonSync(configPath) : {}; } export function setConfig(key, value) { const config = getConfig(); config[key] = value; fs.writeJsonSync(configPath, config, { spaces: 2 }); }