Skip to content

Commit

Permalink
Issue/79 eol set to auto (#80)
Browse files Browse the repository at this point in the history
fix: EOL fixed if set to auto
#79
  • Loading branch information
KreativJos authored Apr 18, 2022
1 parent 80b19a5 commit 119af6c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/template/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ export default abstract class Template {
return await namespaceDetector.getNamespace();
}

private _getEolSetting(): string {
const eolSetting = vscode.workspace.getConfiguration().get('files.eol', EOL);

switch (eolSetting) {
case '\n':
case '\r\n':
return eolSetting;
case 'auto':
default:
return EOL;
}
}

protected async _createFile(templatePath: string, filePath: string, filename: string): Promise<void> {
try {
const doc = await fs.readFile(templatePath, 'utf-8');
const namespace = await this.getNamespace(filePath);
const eolSetting = vscode.workspace.getConfiguration().get('files.eol', EOL);

let text = doc;

Expand All @@ -65,7 +77,7 @@ export default abstract class Template {
.replace(Template.NamespaceRegex, namespace)
.replace(Template.ClassnameRegex, filename)
.replace('${namespaces}', this.getUsings())
.replace(Template.EolRegex, eolSetting);
.replace(Template.EolRegex, this._getEolSetting());

const cursorPosition = this._findCursorInTemplate(text);

Expand Down

0 comments on commit 119af6c

Please sign in to comment.