import { writeFile, existsSync } from 'fs';
import { join, resolve } from 'path';
import * as fs from 'fs';

// Get the directory where package.json is located
const gitDir: any = process.env.INIT_CWD;
const fileName = 'pre-push-mine';
const filePath = join(gitDir, '.git', 'hooks', fileName);

// Check if the file already exists
if (!existsSync(filePath)) {
  // The content of the generated JavaScript file
  console.log('__dirname - ', __dirname);
  let logicFile = resolve(__dirname, 'validator-script.sh');
  const fileContent = fs.readFileSync(logicFile, 'utf8');

  // Write the file to the directory
  writeFile(filePath, fileContent, (err) => {
    if (err) {
      console.error('Error creating file:', err);
    } else {
      console.log('File created:', filePath);
    }
  });
} else {
  console.log('File already exists:', filePath);
}
