Skip to content

Commit

Permalink
feat: add option for a custom SPEC file (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcastilloec authored Oct 30, 2023
1 parent 0ca9555 commit ab6694f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ Default: [`resources/desktop.ejs`](https://github.com/electron-userland/electron

The absolute path to a custom template for the generated [FreeDesktop.org desktop entry](http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html) file.

#### options.specTemplate
Type: `String`
Default: [`resources/spec.ejs`](https://github.com/electron-userland/electron-installer-redhat/blob/main/resources/spec.ejs)

The absolute path to a custom template for the generated [SPEC file](https://rpm-packaging-guide.github.io/#what-is-a-spec-file).

## Meta

* Code: `git clone git://github.com/electron-userland/electron-installer-redhat.git`
Expand Down
6 changes: 5 additions & 1 deletion src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class RedhatInstaller extends common.ElectronInstaller {
return path.resolve(__dirname, '../resources/desktop.ejs')
}

get defaultSpecTemplatePath () {
return path.resolve(__dirname, '../resources/spec.ejs')
}

get packagePattern () {
return path.join(this.stagingDir, 'RPMS', this.options.arch, '*.rpm')
}
Expand Down Expand Up @@ -69,7 +73,7 @@ class RedhatInstaller extends common.ElectronInstaller {
* See: https://fedoraproject.org/wiki/How_to_create_an_RPM_package
*/
async createSpec () {
const src = path.resolve(__dirname, '../resources/spec.ejs')
const src = this.options.specTemplate || this.defaultSpecTemplatePath
this.options.logger(`Creating spec file at ${this.specPath}`)

return common.wrapError('creating spec file', async () => this.createTemplatedFile(src, this.specPath))
Expand Down
40 changes: 40 additions & 0 deletions test/fixtures/custom.spec.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
%define _binary_payload w<%= compressionLevel %>.xzdio

Name: <%= name %>
Version: <%= version %>
Release: <%= revision %>%{?dist}
<% if (description) { print(`Summary: ${description}\n`) }
%>
<% if (license) { print(`License: ${license}\n`) }
if (homepage) { print(`URL: ${homepage}\n`) }
if (license || homepage) { print('\n') }
%>Requires: <%= requires.join(', ') %>
AutoReqProv: no

<% if (productDescription) {
%>%description
<% print(productDescription)
print('\n\n\n') }
%>%install
mkdir -p %{buildroot}/usr/
cp <%= process.platform === 'darwin' ? '-R' : '-r' %> usr/* %{buildroot}/usr/


%files
/usr/bin/<%= name %>
/usr/lib/<%= name %>/
/usr/share/applications/<%= name %>.desktop
/usr/share/doc/<%= name %>/
<% if (_.isObject(icon)) {
_.forEach(icon, function (path, resolution) {
%>/usr/share/icons/hicolor/<%= resolution %>/apps/<%= name %><%= resolution === 'symbolic' ? '-symbolic' : '' %>.<%= ['scalable', 'symbolic'].includes(resolution) ? 'svg' : 'png' %>
<% }) } else {
%>/usr/share/pixmaps/<%= name %>.png
<% } %>

%changelog
* Wed Feb 02 2022 John Doe <johndoe@johndoe.com> - 0.1
- First release
19 changes: 19 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ describe('module', function () {
}
)

describeInstaller(
'with an app with a custom SPEC file',
{
src: 'test/fixtures/app-with-asar/',
options: {
arch: 'x86',
specTemplate: 'test/fixtures/custom.spec.ejs'
}
},
'generates a `.rpm` package with custom spec',
async outputDir => {
await assertASARRpmExists(outputDir)
const stdout = await spawn('rpm', ['-qp', '--changelog', 'footest.x86.rpm'], { cwd: outputDir })
if (!stdout.includes('* Wed Feb 02 2022 John Doe <johndoe@johndoe.com> - 0.1\n- First release')) {
throw new Error(`RPM missing changelog:\n ${stdout}`)
}
}
)

if (process.platform === 'darwin') {
describeInstaller(
'with an app with %_target_os linux',
Expand Down

0 comments on commit ab6694f

Please sign in to comment.