|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | +const yaml = require('js-yaml'); |
| 6 | + |
| 7 | +const RHDH_DIR = process.env.RHDH_DIR |
| 8 | + ? path.resolve(process.env.RHDH_DIR) |
| 9 | + : path.resolve(__dirname, '../../../..', 'rhdh'); |
| 10 | + |
| 11 | +const LOCAL_CONFIG = path.join(RHDH_DIR, 'app-config.local.yaml'); |
| 12 | +const INITIAL_CONFIG = path.join(__dirname, 'config-for-rhdh-repo.yaml'); |
| 13 | + |
| 14 | +const pluginKey = 'red-hat-developer-hub.backstage-plugin-orchestrator'; |
| 15 | +const widgetsPluginKey = |
| 16 | + 'red-hat-developer-hub.backstage-plugin-orchestrator-form-widgets'; |
| 17 | + |
| 18 | +const orchestratorDynamicPlugins = { |
| 19 | + rootDirectory: 'dynamic-plugins-root', |
| 20 | + frontend: { |
| 21 | + [widgetsPluginKey]: {}, |
| 22 | + [pluginKey]: { |
| 23 | + appIcons: [ |
| 24 | + { |
| 25 | + name: 'orchestratorIcon', |
| 26 | + importName: 'OrchestratorIcon', |
| 27 | + }, |
| 28 | + ], |
| 29 | + dynamicRoutes: [ |
| 30 | + { |
| 31 | + path: '/orchestrator', |
| 32 | + importName: 'OrchestratorPage', |
| 33 | + menuItem: { |
| 34 | + icon: 'orchestratorIcon', |
| 35 | + text: 'Orchestrator', |
| 36 | + }, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + }, |
| 41 | +}; |
| 42 | + |
| 43 | +const orchestratorConfig = { |
| 44 | + sonataFlowService: { |
| 45 | + baseUrl: 'http://localhost', |
| 46 | + port: 8899, |
| 47 | + autoStart: true, |
| 48 | + workflowsSource: { |
| 49 | + gitRepositoryUrl: |
| 50 | + 'https://github.com/rhdhorchestrator/backstage-orchestrator-workflows.git', |
| 51 | + localPath: path.resolve( |
| 52 | + __dirname, |
| 53 | + '../packages/backend/.devModeTemp/repository', |
| 54 | + ), |
| 55 | + }, |
| 56 | + }, |
| 57 | + dataIndexService: { |
| 58 | + url: 'http://localhost:8899', |
| 59 | + }, |
| 60 | +}; |
| 61 | + |
| 62 | +function createLocalConfigIfMissing() { |
| 63 | + if (!fs.existsSync(LOCAL_CONFIG)) { |
| 64 | + if (!fs.existsSync(INITIAL_CONFIG)) { |
| 65 | + console.error('❌ Missing app-config.example.yaml'); |
| 66 | + process.exit(1); |
| 67 | + } |
| 68 | + fs.copyFileSync(INITIAL_CONFIG, LOCAL_CONFIG); |
| 69 | + console.log('📝 Created app-config.local.yaml from example'); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +function updateConfig() { |
| 74 | + const raw = fs.readFileSync(LOCAL_CONFIG, 'utf8'); |
| 75 | + const config = yaml.load(raw) || {}; |
| 76 | + |
| 77 | + // Merge dynamicPlugins |
| 78 | + if (!config.dynamicPlugins) { |
| 79 | + config.dynamicPlugins = orchestratorDynamicPlugins; |
| 80 | + console.log('✅ Added dynamicPlugins section.'); |
| 81 | + } else { |
| 82 | + config.dynamicPlugins.rootDirectory ??= 'dynamic-plugins-root'; |
| 83 | + config.dynamicPlugins.frontend ??= {}; |
| 84 | + |
| 85 | + if (!config.dynamicPlugins.frontend[pluginKey]) { |
| 86 | + config.dynamicPlugins.frontend[pluginKey] = |
| 87 | + orchestratorDynamicPlugins.frontend[pluginKey]; |
| 88 | + console.log(`✅ Added frontend plugin: ${pluginKey}`); |
| 89 | + } |
| 90 | + |
| 91 | + if (!config.dynamicPlugins.frontend[widgetsPluginKey]) { |
| 92 | + config.dynamicPlugins.frontend[widgetsPluginKey] = |
| 93 | + orchestratorDynamicPlugins.frontend[widgetsPluginKey]; |
| 94 | + console.log(`✅ Added frontend plugin: ${widgetsPluginKey}`); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + // Merge orchestrator config |
| 99 | + config.orchestrator = { |
| 100 | + ...(config.orchestrator || {}), |
| 101 | + ...orchestratorConfig, |
| 102 | + }; |
| 103 | + |
| 104 | + const updated = yaml.dump(config, { lineWidth: -1 }); |
| 105 | + fs.writeFileSync(LOCAL_CONFIG, updated, 'utf8'); |
| 106 | + console.log(`✅ Updated ${LOCAL_CONFIG} with orchestrator config.`); |
| 107 | +} |
| 108 | + |
| 109 | +function main() { |
| 110 | + if (!fs.existsSync(RHDH_DIR)) { |
| 111 | + console.error(`❌ RHDH repo not found at: ${RHDH_DIR}`); |
| 112 | + process.exit(1); |
| 113 | + } |
| 114 | + createLocalConfigIfMissing(); |
| 115 | + updateConfig(); |
| 116 | +} |
| 117 | + |
| 118 | +main(); |
0 commit comments