1. const fs = require('fs');
  2. const path = require('path');
  3. /**
  4. * Prepares the environment for a one-off script.
  5. * Creates necessary directories and files.
  6. *
  7. * @param {string} scriptName The name of the script.
  8. */
  9. function prepareEnvironment(scriptName) {
  10. const scriptDir = path.join(__dirname, 'scripts', scriptName);
  11. const scriptFile = path.join(scriptDir, scriptName + '.js');
  12. // Create the scripts directory if it doesn't exist.
  13. if (!fs.existsSync(path.join(__dirname, 'scripts'))) {
  14. fs.mkdirSync(path.join(__dirname, 'scripts'));
  15. }
  16. // Create the script directory.
  17. if (!fs.existsSync(scriptDir)) {
  18. fs.mkdirSync(scriptDir);
  19. }
  20. // Create an empty script file.
  21. if (!fs.existsSync(scriptFile)) {
  22. fs.writeFileSync(scriptFile, '// Your script code here\n', 'utf8');
  23. console.log(`Created script file: ${scriptFile}`);
  24. } else {
  25. console.log(`Script file already exists: ${scriptFile}`);
  26. }
  27. }
  28. module.exports = prepareEnvironment;

Add your comment