gcal-commander
Version:
A command-line interface for Google Calendar operations
54 lines (53 loc) • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryConfigStorage = exports.FileSystemConfigStorage = void 0;
const node_fs_1 = require("node:fs");
const promises_1 = require("node:fs/promises");
const node_path_1 = require("node:path");
const paths_1 = require("../utils/paths");
class FileSystemConfigStorage {
configPath;
constructor(configPath) {
this.configPath = configPath || paths_1.AppPaths.getConfigPath();
}
async exists() {
try {
await (0, promises_1.access)(this.configPath, node_fs_1.constants.F_OK);
return true;
}
catch {
return false;
}
}
getConfigPath() {
return this.configPath;
}
async read() {
return (0, promises_1.readFile)(this.configPath, 'utf8');
}
async write(content) {
const configDir = (0, node_path_1.dirname)(this.configPath);
await (0, promises_1.mkdir)(configDir, { recursive: true });
await (0, promises_1.writeFile)(this.configPath, content, 'utf8');
}
}
exports.FileSystemConfigStorage = FileSystemConfigStorage;
class InMemoryConfigStorage {
content;
async exists() {
return this.content !== undefined;
}
getConfigPath() {
return 'in-memory';
}
async read() {
if (this.content === undefined) {
throw new Error(`ENOENT: no such file or directory`);
}
return this.content;
}
async write(content) {
this.content = content;
}
}
exports.InMemoryConfigStorage = InMemoryConfigStorage;