update
This commit is contained in:
169
ts/mod_config/index.ts
Normal file
169
ts/mod_config/index.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
// gitzone config - manage release registry configuration
|
||||
|
||||
import * as plugins from './mod.plugins.js';
|
||||
import { ReleaseConfig } from './classes.releaseconfig.js';
|
||||
|
||||
export { ReleaseConfig };
|
||||
|
||||
export const run = async (argvArg: any) => {
|
||||
const command = argvArg._?.[1] || 'show';
|
||||
const value = argvArg._?.[2];
|
||||
|
||||
switch (command) {
|
||||
case 'show':
|
||||
await handleShow();
|
||||
break;
|
||||
case 'add':
|
||||
await handleAdd(value);
|
||||
break;
|
||||
case 'remove':
|
||||
await handleRemove(value);
|
||||
break;
|
||||
case 'clear':
|
||||
await handleClear();
|
||||
break;
|
||||
default:
|
||||
showHelp();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Show current registry configuration
|
||||
*/
|
||||
async function handleShow(): Promise<void> {
|
||||
const config = await ReleaseConfig.fromCwd();
|
||||
const registries = config.getRegistries();
|
||||
|
||||
console.log('');
|
||||
console.log('╭─────────────────────────────────────────────────────────────╮');
|
||||
console.log('│ Release Registry Configuration │');
|
||||
console.log('╰─────────────────────────────────────────────────────────────╯');
|
||||
console.log('');
|
||||
|
||||
if (registries.length === 0) {
|
||||
plugins.logger.log('info', 'No release registries configured.');
|
||||
console.log('');
|
||||
console.log(' Run `gitzone config add <registry-url>` to add one.');
|
||||
console.log('');
|
||||
} else {
|
||||
plugins.logger.log('info', `Configured registries (${registries.length}):`);
|
||||
console.log('');
|
||||
registries.forEach((url, index) => {
|
||||
console.log(` ${index + 1}. ${url}`);
|
||||
});
|
||||
console.log('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a registry URL
|
||||
*/
|
||||
async function handleAdd(url?: string): Promise<void> {
|
||||
if (!url) {
|
||||
// Interactive mode
|
||||
const interactInstance = new plugins.smartinteract.SmartInteract();
|
||||
const response = await interactInstance.askQuestion({
|
||||
type: 'input',
|
||||
name: 'registryUrl',
|
||||
message: 'Enter registry URL:',
|
||||
default: 'https://registry.npmjs.org',
|
||||
validate: (input: string) => {
|
||||
return !!(input && input.trim() !== '');
|
||||
},
|
||||
});
|
||||
url = (response as any).value;
|
||||
}
|
||||
|
||||
const config = await ReleaseConfig.fromCwd();
|
||||
const added = config.addRegistry(url!);
|
||||
|
||||
if (added) {
|
||||
await config.save();
|
||||
plugins.logger.log('success', `Added registry: ${url}`);
|
||||
} else {
|
||||
plugins.logger.log('warn', `Registry already exists: ${url}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a registry URL
|
||||
*/
|
||||
async function handleRemove(url?: string): Promise<void> {
|
||||
const config = await ReleaseConfig.fromCwd();
|
||||
const registries = config.getRegistries();
|
||||
|
||||
if (registries.length === 0) {
|
||||
plugins.logger.log('warn', 'No registries configured to remove.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
// Interactive mode - show list to select from
|
||||
const interactInstance = new plugins.smartinteract.SmartInteract();
|
||||
const response = await interactInstance.askQuestion({
|
||||
type: 'list',
|
||||
name: 'registryUrl',
|
||||
message: 'Select registry to remove:',
|
||||
choices: registries,
|
||||
default: registries[0],
|
||||
});
|
||||
url = (response as any).value;
|
||||
}
|
||||
|
||||
const removed = config.removeRegistry(url!);
|
||||
|
||||
if (removed) {
|
||||
await config.save();
|
||||
plugins.logger.log('success', `Removed registry: ${url}`);
|
||||
} else {
|
||||
plugins.logger.log('warn', `Registry not found: ${url}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all registries
|
||||
*/
|
||||
async function handleClear(): Promise<void> {
|
||||
const config = await ReleaseConfig.fromCwd();
|
||||
|
||||
if (!config.hasRegistries()) {
|
||||
plugins.logger.log('info', 'No registries to clear.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirm before clearing
|
||||
const confirmed = await plugins.smartinteract.SmartInteract.getCliConfirmation(
|
||||
'Clear all configured registries?',
|
||||
false
|
||||
);
|
||||
|
||||
if (confirmed) {
|
||||
config.clearRegistries();
|
||||
await config.save();
|
||||
plugins.logger.log('success', 'All registries cleared.');
|
||||
} else {
|
||||
plugins.logger.log('info', 'Operation cancelled.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help for config command
|
||||
*/
|
||||
function showHelp(): void {
|
||||
console.log('');
|
||||
console.log('Usage: gitzone config <command> [options]');
|
||||
console.log('');
|
||||
console.log('Commands:');
|
||||
console.log(' show Display current registry configuration');
|
||||
console.log(' add [url] Add a registry URL');
|
||||
console.log(' remove [url] Remove a registry URL');
|
||||
console.log(' clear Clear all registries');
|
||||
console.log('');
|
||||
console.log('Examples:');
|
||||
console.log(' gitzone config show');
|
||||
console.log(' gitzone config add https://registry.npmjs.org');
|
||||
console.log(' gitzone config add https://verdaccio.example.com');
|
||||
console.log(' gitzone config remove https://registry.npmjs.org');
|
||||
console.log(' gitzone config clear');
|
||||
console.log('');
|
||||
}
|
||||
Reference in New Issue
Block a user