UNPKG

@tobiastengler/create-relay-app

Version:

Easy configuration of Relay for existing projects

34 lines (33 loc) 1.45 kB
import { EOL } from "os"; import { bold } from "../utils/cli.js"; import { TaskBase } from "./TaskBase.js"; export class ConfigureEolOfArtifactsTask extends TaskBase { constructor(context, isGitRepo) { super(); this.context = context; this.isGitRepo = isGitRepo; this.message = "Configure Relay artifact EOL in .gitattributes"; } isEnabled() { return this.isGitRepo; } async run() { const gitAttributesPath = this.context.gitAttributesFile; this.updateMessage(this.message + " in " + bold(gitAttributesPath.rel)); const gitAttributesExpression = `*${this.context.artifactExtension} auto eol=lf`; if (!this.context.fs.exists(gitAttributesPath.abs)) { // .gitattributes does not exist - we create it. this.context.fs.writeToFile(gitAttributesPath.abs, gitAttributesExpression + EOL); } else { // .gitattributes exist - we check if our expression exists. const gitAttributesContent = await this.context.fs.readFromFile(gitAttributesPath.abs); if (gitAttributesContent.includes(gitAttributesExpression)) { this.skip("Already configured"); return; } // The expression is not part of the file - we add it. await this.context.fs.appendToFile(gitAttributesPath.abs, EOL + gitAttributesExpression + EOL); } } }