UNPKG

@git.zone/cli

Version:

A comprehensive CLI tool for enhancing and managing local development workflows with gitzone utilities, focusing on project setup, version control, code formatting, and template management.

55 lines (47 loc) 1.85 kB
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.smartfs.file(gitignorePath).exists(); let customContent = ''; if (gitignoreExists) { // lets get the existing gitignore file const existingGitIgnoreString = (await plugins.smartfs .file(gitignorePath) .encoding('utf8') .read()) as string; // Check for different custom section markers const customMarkers = ['#------# custom', '# custom']; for (const marker of customMarkers) { const splitResult = existingGitIgnoreString.split(marker); if (splitResult.length > 1) { // Get everything after the marker (excluding the marker itself) customContent = splitResult[1].trim(); break; } } } // Write the template const templateModule = await import('../mod_template/index.js'); const ciTemplate = await templateModule.getTemplate('gitignore'); await ciTemplate.writeToDisk(paths.cwd); // Append the custom content if it exists if (customContent) { const newGitignoreContent = (await plugins.smartfs .file(gitignorePath) .encoding('utf8') .read()) as string; // The template already ends with "#------# custom", so just append the content const finalContent = newGitignoreContent.trimEnd() + '\n' + customContent + '\n'; await plugins.smartfs .file(gitignorePath) .encoding('utf8') .write(finalContent); logger.log('info', 'Updated .gitignore while preserving custom section!'); } else { logger.log('info', 'Added a .gitignore!'); } };