UNPKG

j-2024-cli

Version:

一个mini版的脚手架

38 lines (35 loc) 1.16 kB
const { configPath, defaultConfig } = require('../constants.js'); const { existsSync, readFileSync, writeFileSync } = require("fs"); const { decode, encode } = require('ini'); const organization = "j-cli"; // 组织名 const accessToken = "38175368a9509544041306174f4a3f76"; // 令牌 function setConfig(value, option) { const { exists, config } = getAllConfig(); const action = Object.keys(option)[0]; const key = option[action]; console.log(configPath) if (action === "get") { console.log(config[key]); } else if (action === "set") { config[key] = value; writeFileSync(configPath, encode(config)); } else if (action === "delete") { delete config[key]; if (exists) { writeFileSync(configPath, encode(config)); } } } function getAllConfig() { let config = { organization, accessToken }; // 所有的配置信息 let exists = existsSync(configPath); if (exists) { let userConfig = decode(readFileSync(configPath, "utf-8")); Object.assign(config, defaultConfig, userConfig); } return { exists, config }; }; module.exports = { setConfig, getAllConfig }