skaya
Version:
CLI SDK for full-stack automation: scaffold frontend, backend & blockchain. Future-ready for Web3, integrations, server components & logging.
45 lines (42 loc) • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getApiKey = getApiKey;
// src/config.ts
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const os_1 = require("os");
const dotenv_1 = __importDefault(require("dotenv"));
// Load .env file if exists
dotenv_1.default.config();
// src/config.ts
function getApiKey() {
// Check environment variable first
const envKey = process.env.SKAYA_API_KEY;
if (envKey)
return envKey;
// Then check .npmrc files
const checkNpmrc = (filePath) => {
var _a;
if ((0, fs_1.existsSync)(filePath)) {
const npmrc = (0, fs_1.readFileSync)(filePath, 'utf-8');
const match = npmrc.match(/skaya_api_key\s*=\s*(.+)/);
return (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.trim();
}
};
const localNpmrcKey = checkNpmrc(path_1.default.join(process.cwd(), '.npmrc'));
if (localNpmrcKey)
return localNpmrcKey;
const globalNpmrcKey = checkNpmrc(path_1.default.join((0, os_1.homedir)(), '.npmrc'));
if (globalNpmrcKey)
return globalNpmrcKey;
throw new Error(`
API key not found. Please configure it in one of these ways:
1. Environment variable (recommended):
export SKAYA_API_KEY=your_key_here
2. Local .npmrc file:
echo 'skaya_api_key=your_key_here' >> .npmrc
`);
}