-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
65 lines (55 loc) · 2.02 KB
/
example.js
File metadata and controls
65 lines (55 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { loadConfigs, getConfig, watchConfigs } from './dist/index.mjs';
// Example usage of the config-manager library
async function example() {
console.log('🚀 Config Manager Example');
console.log('========================\n');
try {
// Load all configurations
console.log('Loading configurations...');
const allConfigs = await loadConfigs();
console.log('\n📋 Available Categories:');
Object.keys(allConfigs).forEach(category => {
console.log(` - ${category}: ${Object.keys(allConfigs[category] || {}).length} files`);
});
// Get specific category
console.log('\n🔧 Build Configurations:');
const buildConfigs = getConfig('build');
if (Object.keys(buildConfigs).length > 0) {
Object.entries(buildConfigs).forEach(([name, config]) => {
console.log(` - ${name}:`, typeof config === 'object' ? 'Object' : 'Other');
});
} else {
console.log(' No build configurations found');
}
// Get environment variables
console.log('\n🌍 Environment Variables:');
const envConfigs = getConfig('env');
if (Object.keys(envConfigs).length > 0) {
Object.entries(envConfigs).slice(0, 5).forEach(([key, value]) => {
console.log(` - ${key}: ${value}`);
});
if (Object.keys(envConfigs).length > 5) {
console.log(` ... and ${Object.keys(envConfigs).length - 5} more`);
}
} else {
console.log(' No environment variables found');
}
// Demonstrate watching (optional)
console.log('\n👀 Watching for file changes...');
const watcher = watchConfigs((updatedConfigs) => {
console.log('✅ Configurations updated!');
});
// Close watcher after 5 seconds for demo purposes
setTimeout(() => {
watcher.close();
console.log('\n✨ Example completed!');
}, 5000);
} catch (error) {
console.error('❌ Error:', error);
}
}
// Run the example if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
example();
}
export { example };