rdme
Version:
ReadMe's official CLI and GitHub Action.
46 lines (45 loc) • 1.63 kB
JavaScript
import configstore from './configstore.js';
export function normalizeAPIKey(value) {
if (value === undefined) {
return undefined;
}
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : undefined;
}
/**
* Retrieves stored user data values from env variables or configstore,
* with env variables taking precedent
*/
export default function getCurrentConfig() {
const apiKey = (() => {
const rdmeAPIKey = normalizeAPIKey(process.env.RDME_API_KEY);
if (rdmeAPIKey) {
this.debug('using RDME_API_KEY env var for api key');
return rdmeAPIKey;
}
const readmeAPIKey = normalizeAPIKey(process.env.README_API_KEY);
if (readmeAPIKey) {
this.debug('using README_API_KEY env var for api key');
return readmeAPIKey;
}
this.debug('falling back to configstore value for api key');
return normalizeAPIKey(configstore.get('apiKey'));
})();
const email = (() => {
if (process.env.RDME_EMAIL) {
this.debug('using RDME_EMAIL env var for email');
return process.env.RDME_EMAIL;
}
this.debug('falling back to configstore value for email');
return configstore.get('email');
})();
const project = (() => {
if (process.env.RDME_PROJECT) {
this.debug('using RDME_PROJECT env var for project');
return process.env.RDME_PROJECT;
}
this.debug('falling back to configstore value for project');
return configstore.get('project');
})();
return { apiKey, email, project };
}