Skip to content

Commit

Permalink
Fix: Creating a service file with a custom name falls back to the pac…
Browse files Browse the repository at this point in the history
…kage.name when package.json has "files" (#108)

* Refactor service file name to accept a name rather than package obj

* fix: Creating custom service when file defined falls back to package.name
  • Loading branch information
matt-ahmet-bbc authored Mar 12, 2024
1 parent 141b8bb commit 7708579
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const path = require('path');

module.exports = {
serviceFileName: function (pkg) {
return `${pkg.name}.service`;
serviceFileName: function (name) {
return `${name}.service`;
},
serviceFile: function (root, pkg) {
return path.resolve(root, this.serviceFileName(pkg));
return path.resolve(root, this.serviceFileName(pkg.name));
},
specsDirectory: function (root) {
return path.resolve(root, 'SPECS');
Expand Down
6 changes: 3 additions & 3 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function relativeToRoot(root, files) {
});
}

function getArchiveWhitelist(pkg) {
function getArchiveWhitelist(pkg, customName) {
return {
service: files.serviceFileName(pkg),
service: files.serviceFileName(customName || pkg.name),
main: pkg.main,
files: pkg.files
};
Expand All @@ -59,7 +59,7 @@ module.exports = async (root, pkg, release, customName) => {

const serviceFile = generateServiceFile(root, customPackage);
const specFile = generateSpecFile(specsDirectory, customPackage, release);
const archiveWhitelist = getArchiveWhitelist(pkg);
const archiveWhitelist = getArchiveWhitelist(pkg, customName);

await archiver.compress(root, sourcesArchive, archiveWhitelist);

Expand Down
20 changes: 19 additions & 1 deletion test/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('generate', () => {
{
files: undefined,
main: 'index.js',
service: 'my-cool-api.service'
service: 'penguin.service'
}
);
});
Expand All @@ -135,6 +135,24 @@ describe('generate', () => {
);
});

it('creates the service file with a custom name if specified and "files" defined', async () => {
await generate('/path/to/project', pkgWithWhitelist, null, 'penguin');
sandbox.assert.calledWith(
archiver.compress,
'/path/to/project',
'/path/to/project/SOURCES/penguin.tar.gz',
{
main: 'server.js',
files: [
'lib',
'routes',
'index.js'
],
service: 'penguin.service'
}
);
});

it('creates the service file with a custom name if specified', async () => {
await generate('/path/to/project', pkg, 1, 'penguin');
sandbox.assert.calledWith(
Expand Down

0 comments on commit 7708579

Please sign in to comment.