Skip to content

Commit 69c015e

Browse files
committed
feat(licenses): filter license choices to OSI approved options since question is for OSS projects
BREAKING CHANGE: the license prompt now only presents OSI approved options since the question is only presented for OSS projects
1 parent b77c3e4 commit 69c015e

4 files changed

Lines changed: 40 additions & 7 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import spdxLicenseList from 'spdx-license-list';
2+
3+
import {questionNames as coreQuestionNames} from './question-names.js';
4+
5+
export default function buildLicenseChoices({[coreQuestionNames.VISIBILITY]: visibility}) {
6+
if ('OSS' === visibility) {
7+
return Object.entries(spdxLicenseList)
8+
.filter(([, details]) => details.osiApproved)
9+
.map(([identifier]) => identifier);
10+
}
11+
return [];
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import spdxLicenseList from 'spdx-license-list';
2+
3+
import {describe, it, expect} from 'vitest';
4+
import any from '@travi/any';
5+
6+
import {questionNames as coreQuestionNames} from './question-names.js';
7+
import buildLicenseChoices from './license-choices-builder.js';
8+
9+
describe('license choices builder', () => {
10+
it('should filter the spdx license options to OSI approved licenses for OSS projects', async () => {
11+
expect(buildLicenseChoices({[coreQuestionNames.VISIBILITY]: 'OSS'}))
12+
.toEqual(Object.entries(spdxLicenseList).reduce((acc, [identifier, details]) => {
13+
if (details.osiApproved) return [...acc, identifier];
14+
15+
return acc;
16+
}, []));
17+
});
18+
19+
it('should return an empty list for non-OSS projects', async () => {
20+
expect(buildLicenseChoices(any.word())).toEqual([]);
21+
});
22+
});

src/prompts/questions-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import path from 'path';
2-
import spdxLicenseList from 'spdx-license-list/simple';
32

43
import any from '@travi/any';
54
import {assert} from 'chai';
65
import sinon from 'sinon';
76

87
import {questionNames as coreQuestionNames} from './question-names.js';
98
import * as predicates from './predicates.js';
10-
import {questionsForBaseDetails} from './questions.js';
119
import {visibilityOptions} from './visibility-options.js';
1210
import * as optionsToChoicesMapper from './options-to-choices-mapper.js';
11+
import buildLicenseChoices from './license-choices-builder.js';
12+
import {questionsForBaseDetails} from './questions.js';
1313

1414
suite('project scaffolder prompts', () => {
1515
let sandbox;
@@ -61,7 +61,7 @@ suite('project scaffolder prompts', () => {
6161
message: 'How should this this project be licensed (https://choosealicense.com/)?',
6262
type: 'list',
6363
when: predicates.licenseChoicesShouldBePresented,
64-
choices: Array.from(spdxLicenseList),
64+
choices: buildLicenseChoices,
6565
default: 'MIT'
6666
},
6767
{
@@ -113,7 +113,7 @@ suite('project scaffolder prompts', () => {
113113
message: 'How should this this project be licensed (https://choosealicense.com/)?',
114114
type: 'list',
115115
when: predicates.licenseChoicesShouldBePresented,
116-
choices: Array.from(spdxLicenseList),
116+
choices: buildLicenseChoices,
117117
default: 'MIT'
118118
},
119119
{

src/prompts/questions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {basename} from 'path';
2-
/* eslint-disable-next-line import/extensions -- needed for the esm bundle */
3-
import spdxLicenseList from 'spdx-license-list/simple.js';
42

53
import {questionNames} from './question-names.js';
64
import {
@@ -11,6 +9,7 @@ import {
119
} from './predicates.js';
1210
import {visibilityOptions} from './visibility-options.js';
1311
import mapOptionsToChoices from './options-to-choices-mapper.js';
12+
import buildLicenseChoices from './license-choices-builder.js';
1413

1514
function includeLicenseQuestions(copyrightHolder) {
1615
return [
@@ -26,7 +25,7 @@ function includeLicenseQuestions(copyrightHolder) {
2625
message: 'How should this this project be licensed (https://choosealicense.com/)?',
2726
type: 'list',
2827
when: licenseChoicesShouldBePresented,
29-
choices: Array.from(spdxLicenseList),
28+
choices: buildLicenseChoices,
3029
default: 'MIT'
3130
},
3231
{

0 commit comments

Comments
 (0)