Extend existing scripts; don't duplicate them
If you're about to write a new script that's >80% the same as an existing one with small differences (different env, different mode, different flag combo), extend the existing one with a CLI argument or config option instead of writing a parallel copy.
Why
Two near-identical scripts diverge over time. A bug fix lands in one and not the other. A new feature gets added inconsistently. Reviewers can't tell which is canonical. The duplicated logic compounds with every change.
How to apply
When you notice you'd be copying an existing script and changing a few values:
- Identify what's actually different — usually a flag, env var, or config field.
- Add that as a CLI arg (
--mode prod/--target dev) or env knob to the existing script. - Update callers if needed.
If the differences are structural (different control flow, different inputs, different outputs), then a separate script IS appropriate — but check first whether the structural difference can be expressed as a parameter.