1. class DryRunTracker {
  2. constructor() {
  3. this.executedStrings = [];
  4. this.overrides = {};
  5. }
  6. /**
  7. * Executes a string and tracks its execution.
  8. * @param {string} str The string to execute.
  9. * @param {Function} callback Optional callback function to execute after the string.
  10. * @returns {boolean} True if the string was executed, false otherwise.
  11. */
  12. execute(str, callback = null) {
  13. this.executedStrings.push(str);
  14. // Check for overrides
  15. if (this.overrides[str]) {
  16. console.warn(`Dry-run: String "${str}" is overridden.`);
  17. return false; //Don't actually execute the string
  18. }
  19. try {
  20. // Simulate execution. Replace with actual execution logic if needed.
  21. console.log(`Dry-run: Executing string: ${str}`);
  22. if (callback) {
  23. callback();
  24. }
  25. return true;
  26. } catch (error) {
  27. console.error(`Dry-run: Error executing string "${str}":`, error);
  28. return false;
  29. }
  30. }
  31. /**
  32. * Sets an override for a string. Prevents the string from being executed.
  33. * @param {string} str The string to override.
  34. * @param {any} value The override value.
  35. */
  36. override(str, value) {
  37. this.overrides[str] = value;
  38. }
  39. /**
  40. * Returns the list of executed strings.
  41. * @returns {string[]} The list of executed strings.
  42. */
  43. getExecutedStrings() {
  44. return this.executedStrings;
  45. }
  46. /**
  47. * Returns the current overrides.
  48. * @returns {object} The overrides object.
  49. */
  50. getOverrides() {
  51. return this.overrides;
  52. }
  53. }
  54. // Export the class (if needed for module use)
  55. export default DryRunTracker;

Add your comment