-
Notifications
You must be signed in to change notification settings - Fork 85
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
refactor(bin/electron-forge): make desktop.ejs easier to read #1099
base: develop
Are you sure you want to change the base?
Conversation
bin/electron-forge/desktop.ejs
Outdated
[ | ||
["Name", productName], | ||
["Comment", description], | ||
["GenericName", genericName], | ||
["Exec", name ? `${name} %U` : undefined], | ||
["Icon", name], | ||
["Type", "Application"], | ||
["StartupNotify", "true"], | ||
["StartupWMClass", productName], | ||
["Categories", categories?.length ? `${categories.join(";")};` : undefined], | ||
["MimeType", mimeType?.length ? `${mimeType.join(";")};` : undefined] | ||
].map(line => line[1] ? line.join("=") : undefined) | ||
.filter(line => !!line) | ||
.join("\n")%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't an object navigated with Object.entries
make it even more readable?
Seems that the order is stable for ES2015+, https://stackoverflow.com/a/23202095/4898894
And either way, I don't think the order matters that much inside desktop entries.
And yes, it was absolutely hideous. I think it's how the guys in Electron Forge do it, might be worth contributing the change upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't an object navigated with
Object.entries
make it even more readable?
Yes, using Object.entries works as well and would look like the one below
[Desktop Entry]
<%=
Object.entries({
"Name": productName,
"Comment": description,
"GenericName": genericName,
"Exec": name ? `${name} %U` : undefined,
"Icon": name,
"Type": "Application",
"StartupNotify": "true",
"StartupWMClass": productName,
"Categories": categories?.length ? `${categories.join(";")};` : undefined,
"MimeType": mimeType?.length ? `${mimeType.join(";")};` : undefined
})
.map(line => line[1] ? line.join("=") : undefined)
.filter(line => !!line)
.join("\n")%>
not too much of a huge difference IMHO, but I don't mind changing it either – anything is better than the previous one :-D
will commit the change in a couple minutes.
I think it's how the guys in Electron Forge do it, might be worth contributing the change upstream.
yes, our original file was based on the node_modules/electron-installer-debian/resources/desktop.ejs
file.
– I'll might give it a try to bring it to upstream as well, thanks
in theory we could use variables in ejs, but unfortunately electron uses lodash template to create the file, which itself DOES NOT like any let/const/var assignments – wasted a bit of time finding this out, before coming up with this solution
4b24d76
to
61e5602
Compare
Hi,
This PR aims to make the desktop.ejs template that is used for the Linux packages a lot easier to read.
We just define the lines as an Array tuple, and then filter out any values, which are falsy (or in this case undefined), before joining them with a "\n" new line.
electron-forge correctly packages the file and its output is identical to the previous template
I admit, this a tiny bit of a useless refactor, but it still irked me to see that file in its previous state :-D