diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c5529f..04c651c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 4.1.0 IN PROGRESS * Populate module descriptor's `name` field with module-name if `description` is missing. Refs STCLI-272. +* Populate module descriptor's `metadata` field with remaining `stripes` properties. Refs STCLI-274. ## [4.0.0](https://github.com/folio-org/stripes-cli/tree/v4.0.0) (2025-02-24) [Full Changelog](https://github.com/folio-org/stripes-cli/compare/v3.2.0...v4.0.0) diff --git a/lib/cli/generate-module-descriptor.js b/lib/cli/generate-module-descriptor.js index 0bdecb4..d5304a8 100644 --- a/lib/cli/generate-module-descriptor.js +++ b/lib/cli/generate-module-descriptor.js @@ -1,5 +1,5 @@ -// Logic borrowed from stripes-core's package2md.js excluding file load and console output -// $ node ../stripes-core/util/package2md.js package.json > MD.json +const { omit } = require('lodash'); + module.exports = function generateModuleDescriptor(packageJson, isStrict) { const stripes = packageJson.stripes || {}; const moduleDescriptor = { @@ -12,6 +12,9 @@ module.exports = function generateModuleDescriptor(packageJson, isStrict) { moduleDescriptor.requires = Object.keys(interfaces).map(key => ({ id: key, version: interfaces[key] })); const optional = stripes.optionalOkapiInterfaces || []; moduleDescriptor.optional = Object.keys(optional).map(key => ({ id: key, version: optional[key] })); + moduleDescriptor.metadata = { + stripes: omit(stripes, ['okapiInterfaces', 'optionalOkapiInterfaces', 'permissionSets']), + }; } return moduleDescriptor; }; diff --git a/lib/commands/mod/descriptor.js b/lib/commands/mod/descriptor.js index 401295c..f6c50c7 100644 --- a/lib/commands/mod/descriptor.js +++ b/lib/commands/mod/descriptor.js @@ -14,7 +14,8 @@ function moduleDescriptorCommand(argv) { DescriptorService.writeModuleDescriptorsToDirectory(descriptors, argv.output); console.log(`${descriptors.length} module descriptors written to ${argv.output}`); } else if (argv.full) { - console.log(JSON.stringify(descriptors, null, 2)); + const output = argv.single && descriptors.length === 1 ? descriptors[0] : descriptors; + console.log(JSON.stringify(output, null, 2)); } else { descriptors.forEach(descriptor => console.log(descriptor.id)); } @@ -40,6 +41,11 @@ module.exports = { type: 'boolean', default: false, }) + .option('single', { + describe: 'Full JSON descriptor for a single module in the current working directory', + type: 'boolean', + default: false, + }) .option('output', { describe: 'Directory to write descriptors to as JSON files', type: 'string', diff --git a/test/okapi/descriptor-service.spec.js b/test/okapi/descriptor-service.spec.js index 5f6780a..9ad4d19 100644 --- a/test/okapi/descriptor-service.spec.js +++ b/test/okapi/descriptor-service.spec.js @@ -130,7 +130,8 @@ describe('The descriptor-service', function () { id: 'backend2', version: '3.1' } - ] + ], + metadata: { stripes: { type: packageJsonStub.stripes.type } } }]; const output = this.sut.getUiModuleDescriptor(true); @@ -189,7 +190,8 @@ describe('The descriptor-service', function () { id: 'backend2', version: '3.1' } - ] + ], + metadata: { stripes: { type: packageJsonStub.stripes.type } } }; });