Skip to content

Commit 4dca1bb

Browse files
authored
fix(cli): windows EOL (#2554 by @frankcalise)
1 parent c0543f7 commit 4dca1bb

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

src/commands/new.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -566,35 +566,21 @@ export default {
566566
// #region Format generator templates EOL for Windows
567567
let warnAboutEOL = false
568568
if (isWindows) {
569-
// find unix2dos to help convert EOL, usually installed with git, ie: C:\Program Files\Git\usr\bin\unix2dos.EXE
570-
const unixToDosPath = await system.exec("which unix2dos")
571-
// find all templates Ignite provides by default
572-
const templates = filesystem.find(`${targetPath}/ignite/templates`, {
573-
directories: false,
574-
files: true,
575-
matching: "*.ejs",
576-
})
577-
578-
log(`unix2dos path: ${unixToDosPath}`)
579-
log(`templates to change EOL: ${templates}`)
580-
if (unixToDosPath) {
581-
// running the output from `which` result above seems to not work, so just pop the binary name
582-
const unixToDosCmd = unixToDosPath.split("/").pop()
583-
const results = await Promise.allSettled(
584-
templates.map(async (file) => {
585-
log(`Converting EOL for ${file}`)
586-
await system.run(`${unixToDosCmd} ${file}`)
587-
}),
588-
)
569+
try {
570+
const templates = filesystem.find(`${targetPath}/ignite/templates`, {
571+
directories: false,
572+
files: true,
573+
matching: "*.ejs",
574+
})
589575

590-
// inspect the results of conversion and log
591-
results.forEach((result) => {
592-
if (result.status === "rejected") {
593-
warnAboutEOL = true
594-
log(`Error converting EOL: ${JSON.stringify(result.reason)}`)
595-
}
576+
log(`templates to change EOL: ${templates}`)
577+
templates.map(async (file) => {
578+
log(`Converting EOL for ${file}`)
579+
let template = read(file)
580+
template = template.replace(/\n/g, "\r\n")
581+
write(file, template)
596582
})
597-
} else {
583+
} catch {
598584
warnAboutEOL = true
599585
}
600586
}

0 commit comments

Comments
 (0)