From a5ca82e8484a56fbcc64182691a4b3d4d140ad40 Mon Sep 17 00:00:00 2001 From: Justin Lettau Date: Tue, 15 Dec 2020 09:49:51 -0800 Subject: [PATCH] feat: add eol config option Closes #7 --- .github/workflows/ci.yml | 5 ----- README.md | 4 ++++ docker/config.json | 3 ++- package-lock.json | 5 +++++ package.json | 1 + src/common/config.ts | 6 ++++++ src/common/file-utility.ts | 15 +++++++++++++++ 7 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01c614d..a115e97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,11 +28,6 @@ jobs: e2e: runs-on: ubuntu-latest steps: - - name: Config - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - name: Checkout uses: actions/checkout@v2 diff --git a/README.md b/README.md index b044a3c..5c1d25f 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,10 @@ following properties are supported. **includeConstraintName** (`boolean`): Optional. Indicates if constraint names should be scripted. Default is `false`. +**eol** (`string`: Optional. Line ending character (`auto`, `crlf`, or `lf`). Default is `auto`. + +Note: See [Git documentation](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_formatting_and_whitespace) for information about how Git handles line endings. + # Examples ### Connections diff --git a/docker/config.json b/docker/config.json index 84d4679..d9466c9 100644 --- a/docker/config.json +++ b/docker/config.json @@ -15,5 +15,6 @@ "Person.CountryRegion", "Person.PhoneNumberType", "Purchasing.ShipMethod" - ] + ], + "eol": "crlf" } diff --git a/package-lock.json b/package-lock.json index e8380eb..9c663cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2976,6 +2976,11 @@ "ansi-colors": "^4.1.1" } }, + "eol": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/eol/-/eol-0.9.1.tgz", + "integrity": "sha512-Ds/TEoZjwggRoz/Q2O7SE3i4Jm66mqTDfmdHdq/7DKVk3bro9Q8h6WdXKdPqFLMoqxrDK5SVRzHVPOS6uuGtrg==" + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", diff --git a/package.json b/package.json index be7c8b8..6bafd6f 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "checksum": "^0.1.1", "cli-table": "^0.3.4", "commander": "^6.2.0", + "eol": "^0.9.1", "filenamify": "^4.2.0", "fs-extra": "^9.0.1", "glob": "^7.1.6", diff --git a/src/common/config.ts b/src/common/config.ts index 6dd574d..69df6f9 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -154,6 +154,11 @@ export default class Config implements IConfig { */ includeConstraintName = false; + /** + * Line ending character. + */ + eol: 'auto' | 'crlf' | 'lf' = 'auto'; + /** * Get root output directory. */ @@ -237,6 +242,7 @@ export default class Config implements IConfig { Object.assign(this.idempotency, config.idempotency); this.includeConstraintName = config.includeConstraintName || this.includeConstraintName; + this.eol = config.eol || this.eol; } catch (error) { console.error( 'Could not find or parse config file. You can use the `init` command to create one!' diff --git a/src/common/file-utility.ts b/src/common/file-utility.ts index b0a1d40..76aa749 100644 --- a/src/common/file-utility.ts +++ b/src/common/file-utility.ts @@ -1,5 +1,6 @@ import chalk = require('chalk'); import * as checksum from 'checksum'; +import * as eol from 'eol'; import filenamify = require('filenamify'); import * as fs from 'fs-extra'; import * as glob from 'glob'; @@ -71,6 +72,20 @@ export default class FileUtility { } file = path.join(this.config.getRoot(), dir, file); + + switch (this.config.eol) { + case 'crlf': + content = eol.crlf(content); + break; + case 'lf': + content = eol.lf(content); + break; + case 'auto': + default: + content = eol.auto(content); + break; + } + content = content.trim(); const cacheKey = this.normalize(file);