loccon
Version:
A simple local context storage and management tool with CLI and web interfaces. Store, search, and organize code snippets, notes, and development contexts with sharded JSON storage.
106 lines • 4.25 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigManager = void 0;
const path = __importStar(require("path"));
const fs = __importStar(require("fs-extra"));
const os = __importStar(require("os"));
class ConfigManager {
static isGlobalInstall() {
// Check if we're in a global npm installation context
const currentPath = process.cwd();
const nodeModulesPath = path.join(os.homedir(), '.npm-global', 'lib', 'node_modules');
return currentPath.includes(nodeModulesPath) || currentPath.includes('/usr/local/lib/node_modules');
}
static getStoragePath(customPath) {
if (customPath) {
return path.resolve(customPath);
}
if (this.isGlobalInstall()) {
return path.join(os.homedir(), '.loccon');
}
else {
return path.join(process.cwd(), '.loccon');
}
}
static async initializeStorage(storagePath) {
const shardsDir = path.join(storagePath, 'shards');
// Create directories
await fs.ensureDir(storagePath);
await fs.ensureDir(shardsDir);
// Initialize config.json if it doesn't exist
const configPath = path.join(storagePath, 'config.json');
if (!await fs.pathExists(configPath)) {
const config = {
version: '1.0.0',
storageType: 'sharded',
maxShardSize: '5MB',
created: new Date().toISOString(),
lastAccessed: new Date().toISOString()
};
await fs.writeJson(configPath, config, { spaces: 2 });
}
// Initialize index.json if it doesn't exist
const indexPath = path.join(storagePath, 'index.json');
if (!await fs.pathExists(indexPath)) {
const index = {
tagToShard: {},
lastUpdated: new Date().toISOString()
};
await fs.writeJson(indexPath, index, { spaces: 2 });
}
// Initialize metadata.json if it doesn't exist
const metadataPath = path.join(storagePath, 'metadata.json');
if (!await fs.pathExists(metadataPath)) {
const metadata = {
totalEntries: 0,
totalShards: 0,
currentShard: '',
shards: {}
};
await fs.writeJson(metadataPath, metadata, { spaces: 2 });
}
}
static async updateLastAccessed(storagePath) {
const configPath = path.join(storagePath, 'config.json');
if (await fs.pathExists(configPath)) {
const config = await fs.readJson(configPath);
config.lastAccessed = new Date().toISOString();
await fs.writeJson(configPath, config, { spaces: 2 });
}
}
}
exports.ConfigManager = ConfigManager;
//# sourceMappingURL=config.js.map