import { Ini, Cliffy, Compress, Base64, FS, Colors } from "./deps.ts"; import setupCMD from "./commands/setup.ts"; export interface IMeta { name: string; version: string; description?: string; author?: string; contributors?: string[]; files: string[]; } let verbose = false; export function log(...args: any) { if (verbose) console.log(...args); } let config: any = {}; let configLocation = ""; let configInitialized = false; export function getConfig(name: string) { if (!configInitialized) throw new Error("Not initialized!"); return config[name]; } export async function setConfig(name: string, value: string) { if (!configInitialized) throw new Error("Not initialized!"); config[name] = value; const data = Ini.encode(config); await Deno.writeFile(configLocation, new TextEncoder().encode(data), { create: true, }); } export async function getMeta() { log("Reading meta.json"); return (await FS.readJson("meta.json")) as IMeta; } export async function setMeta(meta: IMeta): Promise { log("Saving meta.json"); return FS.writeJson("meta.json", meta, { spaces: " ", }); } let interactive = true; export function isInteractive() { return interactive; } export async function init(globalOptions: any) { configLocation = globalOptions.config; interactive = globalOptions.interactive; verbose = globalOptions.verbose; try { const data = Deno.readFileSync(configLocation); config = Ini.decode(new TextDecoder().decode(data)); } catch (err) { log("Error loading config:"); log(err); } configInitialized = true; if (!config.username || !config.registry || !config.password) { if (!isInteractive()) { console.error( Colors.red("Run setup or set necessary value in " + configLocation) ); } else { await setupCMD(); } } }