diff --git a/.editorconfig b/.editorconfig index 9495107..83c1115 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,4 +6,4 @@ end_of_line = lf insert_final_newline = true indent_style = space indent_size = 2 -trim_trailing_whitespace = true \ No newline at end of file +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index 233829b..d69a4c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ deno.d.ts .vscode -.local \ No newline at end of file +.local diff --git a/run b/run index ada1af1..74d1c6d 100755 --- a/run +++ b/run @@ -16,4 +16,4 @@ else fi denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@" -exec deno $denocmd $denoargs \ No newline at end of file +exec deno $denocmd $denoargs diff --git a/src/normalize.ts b/src/normalize.ts index 41cc129..f513f50 100755 --- a/src/normalize.ts +++ b/src/normalize.ts @@ -42,6 +42,13 @@ export class ProjectNormalizer { await this.formatPath(path); } + async writeLines(path: string, lines: string[]) { + await this.sys.writeTextFile( + path, + lines.concat("").join("\n"), + ); + } + async formatPath(path: string) { await this.sys.run({ cmd: ["./run", "fmt", "-q", path], @@ -49,7 +56,7 @@ export class ProjectNormalizer { } async updateRunScript() { - await this.sys.writeTextFile( + await this.writeLines( "run", [ `#!/bin/sh`, @@ -71,7 +78,7 @@ export class ProjectNormalizer { ``, `denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"`, `exec deno $denocmd $denoargs`, - ].join("\n"), + ], ); await this.sys.chmod("run", 0o755); } @@ -86,7 +93,7 @@ export class ProjectNormalizer { } async updateEditorConfig() { - await this.sys.writeTextFile( + await this.writeLines( ".editorconfig", [ `root = true`, @@ -98,7 +105,7 @@ export class ProjectNormalizer { `indent_style = space`, `indent_size = 2`, `trim_trailing_whitespace = true`, - ].join("\n"), + ], ); } @@ -168,25 +175,25 @@ export class ProjectNormalizer { } async updateGitIgnore() { - await this.sys.writeTextFile( + await this.writeLines( ".gitignore", [ `deno.d.ts`, `.vscode`, `.local`, - ].join("\n"), + ], ); } async updateGitHooks() { - await this.sys.writeTextFile( + await this.writeLines( ".git/hooks/pre-commit", [ `#!/bin/sh`, `set -e`, `./run fmt --check`, `./run test`, - ].join("\n"), + ], ); await this.sys.chmod(".git/hooks/pre-commit", 0o755); } @@ -203,13 +210,13 @@ export class ProjectNormalizer { } } } - await this.sys.writeTextFile( + await this.writeLines( "README.md", [ `# typescript/${project}`, `[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/${project}?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=${project})`, sections, - ].join("\n"), + ], ); await this.formatPath("README.md"); }