import * as plugins from './mod.plugins.js';
import * as paths from '../paths.js';

import { Project } from '../classes.project.js';

import { logger } from '../gitzone.logging.js';
const gitignorePath = plugins.path.join(paths.cwd, './.gitignore');

export const run = async (projectArg: Project) => {
  const gitignoreExists = await plugins.smartfile.fs.fileExists(gitignorePath);
  const templateModule = await import('../mod_template/index.js');
  const ciTemplate = await templateModule.getTemplate('gitignore');
  if (gitignoreExists) {
    // lets get the existing gitignore file
    const existingGitIgnoreString = plugins.smartfile.fs.toStringSync(gitignorePath);
    let customPart = existingGitIgnoreString.split('# custom\n')[1];
    customPart ? null : (customPart = '');
  }
  ciTemplate.writeToDisk(paths.cwd);
  logger.log('info', 'Added a .gitignore!');
};