mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-19 14:30:52 -07:00
fix: Safely restore .npmrc from backup
This commit is contained in:
@@ -110,29 +110,25 @@ function setupDev() {
|
|||||||
|
|
||||||
function setupProd() {
|
function setupProd() {
|
||||||
console.log('Configuring your global ~/.npmrc for `prod` (npmjs.org)...');
|
console.log('Configuring your global ~/.npmrc for `prod` (npmjs.org)...');
|
||||||
if (!fs.existsSync(npmrcPath)) {
|
if (!fs.existsSync(backupPath)) {
|
||||||
console.log('No ~/.npmrc file found. Already configured for prod.');
|
console.log('No backup file (`~/.npmrc.bak`) found. No changes were made.');
|
||||||
|
console.log(
|
||||||
|
'If you have manually removed the dev configuration, you are already configured for prod.',
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let npmrcContent = fs.readFileSync(npmrcPath, 'utf-8');
|
try {
|
||||||
const lines = npmrcContent.split('\n');
|
fs.copyFileSync(backupPath, npmrcPath);
|
||||||
const filteredLines = lines.filter(
|
console.log(
|
||||||
(line) =>
|
`✅ Successfully restored your configuration from ${backupPath}`,
|
||||||
!line.trim().startsWith('//npm.pkg.github.com/') &&
|
);
|
||||||
!line.trim().startsWith('@google-gemini:registry') &&
|
// Optional: remove the backup file after successful restoration
|
||||||
!line.trim().startsWith('# Added by gemini-cli'),
|
// fs.unlinkSync(backupPath);
|
||||||
);
|
// console.log(`Cleaned up backup file: ${backupPath}`);
|
||||||
|
} catch (err) {
|
||||||
if (lines.length === filteredLines.length) {
|
console.error(`Error restoring configuration: ${err}`);
|
||||||
console.log('✅ Your ~/.npmrc file is already configured for prod.');
|
process.exit(1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(npmrcPath, filteredLines.join('\n').trim() + '\n');
|
|
||||||
console.log(`✅ Successfully cleaned dev configuration from ~/.npmrc.`);
|
|
||||||
if (fs.existsSync(backupPath)) {
|
|
||||||
console.log(`Your original configuration was saved to ${backupPath}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user