Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): win EOL conversion for gen templates #2540

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/Generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ You may want to update your generators to the latest version of Ignite.
Just run `npx ignite-cli update <type>` or `npx ignite-cli update --all` from the root folder of your project to copy over the latest generators from Ignite to your project.

⚠️ Note that this will remove any customizations you've made, so make sure to make a commit first so you can roll it back!

## A Note About Windows

If you are noticing upon using the generator for a source file (such as a screen or model) that frontmatter is not removed from the newly created file, it could be that the End of Line Sequence is misconfigured. Ignite tries to take care of this on its own, but sometimes your machine will not have a proper CLI utility such as `unix2dos` installed (this usually comes with Git).

In this case, you can open VS Code (or another IDE) and convert the EOL characters for all `ejs` files in the `ignite/templates` directory. Then run the generator command again and it should create the new files properly.
49 changes: 47 additions & 2 deletions src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export default {

const packagerOptions = { packagerName }

const isWindows = process.platform === "win32"
const ignitePath = path(`${meta.src}`, "..")
const boilerplatePath = path(ignitePath, "boilerplate")
const boilerplate = (...pathParts: string[]) => path(boilerplatePath, ...pathParts)
Expand Down Expand Up @@ -552,13 +553,48 @@ export default {
}
// #endregion

// #region Format generator templates EOL for Windows
let warnAboutEOL = false
if (isWindows) {
// find unix2dos to help convert EOL, usually installed with git, ie: C:\Program Files\Git\usr\bin\unix2dos.EXE
const unixToDosPath = await system.exec("which unix2dos")
// find all templates Ignite provides by default
const templates = filesystem.find(`${targetPath}/ignite/templates`, {
directories: false,
files: true,
matching: "*.ts*.ejs",
frankcalise marked this conversation as resolved.
Show resolved Hide resolved
})

log(`unix2dos path: ${unixToDosPath}`)
log(`templates to change EOL: ${templates}`)
if (unixToDosPath) {
// running the output from `which` result above seems to not work, so just pop the binary name
const unixToDosCmd = unixToDosPath.split("/").pop()
const results = await Promise.allSettled(
templates.map(async (file) => {
log(`Converting EOL for ${file}`)
await system.run(`${unixToDosCmd} ${file}`)
}),
)
frankcalise marked this conversation as resolved.
Show resolved Hide resolved

// inspect the results of conversion and log
results.forEach((result) => {
if (result.status === "rejected") {
warnAboutEOL = true
log(`Error converting EOL: ${JSON.stringify(result.reason)}`)
}
})
} else {
warnAboutEOL = true
}
}
// #endregion

// #region Create Git Repository and Initial Commit
// commit any changes
if (git === true) {
startSpinner(" Backing everything up in source control")
try {
const isWindows = process.platform === "win32"

// The separate commands works on Windows, but not Mac OS
if (isWindows) {
await system.run(log("git init"))
Expand Down Expand Up @@ -642,6 +678,15 @@ export default {
p2()
}

if (warnAboutEOL) {
hr()
p2()
p2(yellow(`Generator templates could not be converted to Windows EOL.`))
p2(yellow(`You may want to update these manually with your code editor, more info at:`))
p2(`${link("https://docs.infinite.red/ignite/concept/generators#windows")}`)
frankcalise marked this conversation as resolved.
Show resolved Hide resolved
p2()
}

hr()
p2()
p2("Need additional help?")
Expand Down