setup-test-plugin.js 1.0 KB

12345678910111213141516171819202122232425
  1. const fs = require('fs');
  2. const path = require('path');
  3. // Read the vendure-config.ts file
  4. const configPath = path.join(process.cwd(), 'src', 'vendure-config.ts');
  5. let configContent = fs.readFileSync(configPath, 'utf-8');
  6. // Add the import statement at the top of the file
  7. const importStatement = `import { TestPlugin } from './plugins/test-plugin/test.plugin';\n`;
  8. configContent = importStatement + configContent;
  9. // Add TestPlugin to the plugins array
  10. // First, find the plugins array in the config
  11. const pluginsMatch = configContent.match(/plugins:\s*\[([\s\S]*?)\]/);
  12. if (pluginsMatch) {
  13. const existingPlugins = pluginsMatch[1].trim();
  14. // Replace the existing plugins array with the updated one including TestPlugin
  15. const updatedPlugins = existingPlugins
  16. ? `${existingPlugins.replace(/,\s*$/, '')},\n TestPlugin`
  17. : 'TestPlugin';
  18. configContent = configContent.replace(/plugins:\s*\[([\s\S]*?)\]/, `plugins: [${updatedPlugins}]`);
  19. }
  20. // Write the modified content back to the file
  21. fs.writeFileSync(configPath, configContent);