From ab6694f1aa9f19f44dd07a4aae11918b7cfbc59c Mon Sep 17 00:00:00 2001 From: Felipe Castillo <1280530+fcastilloec@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:05:37 -0400 Subject: [PATCH] feat: add option for a custom SPEC file (#245) --- README.md | 6 ++++++ src/installer.js | 6 +++++- test/fixtures/custom.spec.ejs | 40 +++++++++++++++++++++++++++++++++++ test/installer.js | 19 +++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/custom.spec.ejs diff --git a/README.md b/README.md index 9917b31..103face 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/installer.js b/src/installer.js index c7a3dbb..10e0c7a 100644 --- a/src/installer.js +++ b/src/installer.js @@ -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') } @@ -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)) diff --git a/test/fixtures/custom.spec.ejs b/test/fixtures/custom.spec.ejs new file mode 100644 index 0000000..deec411 --- /dev/null +++ b/test/fixtures/custom.spec.ejs @@ -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 - 0.1 +- First release diff --git a/test/installer.js b/test/installer.js index 4e57bec..36c69b7 100644 --- a/test/installer.js +++ b/test/installer.js @@ -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 - 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',