const fs = require('fs');
const path = require('path');
/**
* Prepares the environment for a one-off script.
* Creates necessary directories and files.
*
* @param {string} scriptName The name of the script.
*/
function prepareEnvironment(scriptName) {
const scriptDir = path.join(__dirname, 'scripts', scriptName);
const scriptFile = path.join(scriptDir, scriptName + '.js');
// Create the scripts directory if it doesn't exist.
if (!fs.existsSync(path.join(__dirname, 'scripts'))) {
fs.mkdirSync(path.join(__dirname, 'scripts'));
}
// Create the script directory.
if (!fs.existsSync(scriptDir)) {
fs.mkdirSync(scriptDir);
}
// Create an empty script file.
if (!fs.existsSync(scriptFile)) {
fs.writeFileSync(scriptFile, '// Your script code here\n', 'utf8');
console.log(`Created script file: ${scriptFile}`);
} else {
console.log(`Script file already exists: ${scriptFile}`);
}
}
module.exports = prepareEnvironment;
Add your comment