@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
40 lines • 1.17 kB
JavaScript
import { execSync, logger, config } from './../utils/index.js';
const LAST_NPM_AUTH_ON = 'lastNpmAuthOn';
const authenticate = onError => {
try {
execSync('npx google-artifactregistry-auth', {
stdio: 'pipe'
});
config.set(LAST_NPM_AUTH_ON, Date.now());
} catch (error) {
if (onError) {
onError(error);
} else {
throw error;
}
}
};
export default options => {
const now = Date.now();
const lastCheck = config.get(LAST_NPM_AUTH_ON) ?? 0;
if (options?.force || lastCheck === 0 || now - lastCheck > 1000 * 60 * 30) {
const spinner = logger.spinner('Authenticating with Google Artifact Registry...');
try {
authenticate(error => {
if (error.message.includes('not recognized as an internal or external command')) {
spinner.warn('google-artifactregistry-auth is not installed. Installing now...');
execSync('npm install -g google-artifactregistry-auth', {
stdio: 'pipe'
});
authenticate();
} else {
throw error;
}
});
spinner.succeed();
} catch (error) {
spinner.fail();
throw error;
}
}
};