-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Blissfully/fix_under_circle
Apply Elm Format in single, dir-wide step
- Loading branch information
Showing
16 changed files
with
141 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,9 @@ | ||
import { spawn } from "child_process"; | ||
import { execSync } from "child_process"; | ||
import * as fs from "fs-extra"; | ||
|
||
const globalInstallPath = `${__dirname}/../node_modules/.bin/elm-format`; | ||
const localInstallPath = `${__dirname}/../../.bin/elm-format`; | ||
|
||
export const writeFile = (path: string, value: string): void => { | ||
const elmFormatPath = findElmFormatPath(); | ||
|
||
if (elmFormatPath) { | ||
writeWithElmFormat(path, value, elmFormatPath); | ||
} else { | ||
writeWithoutFormatting(path, value); | ||
} | ||
}; | ||
|
||
const writeWithElmFormat = ( | ||
path: string, | ||
value: string, | ||
elmFormatPath: string | ||
): void => { | ||
const elmFormat = spawn( | ||
elmFormatPath, | ||
["--stdin", "--elm-version=0.19", "--output", path], | ||
{ | ||
shell: true | ||
} | ||
); | ||
|
||
elmFormat.stdin.write(value); | ||
elmFormat.stdin.end(); | ||
|
||
elmFormat.stdout.on("data", data => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
elmFormat.stderr.on("data", data => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
elmFormat.on("close", code => { | ||
if (code !== 0) { | ||
console.log(`elm-format process exited with code ${code}. | ||
Was attempting to write to path ${path} with contents: | ||
${value}`); | ||
process.exit(code); | ||
} | ||
}); | ||
}; | ||
|
||
const writeWithoutFormatting = (path: string, value: string) => { | ||
fs.writeFileSync(path, value); | ||
}; | ||
|
||
const findElmFormatPath = (): string | null => { | ||
if (fs.existsSync(globalInstallPath)) { | ||
return globalInstallPath; | ||
} else if (fs.existsSync(localInstallPath)) { | ||
return localInstallPath; | ||
} else { | ||
return null; | ||
} | ||
export const applyElmFormat = (fileOrFolderToFormat: string): void => { | ||
execSync(`npx elm-format --elm-version=0.19 --yes ${fileOrFolderToFormat}/`); | ||
}; |
Oops, something went wrong.