Skip to content

Commit ec84301

Browse files
committed
ensured the 'supported managers' entries are unique
1 parent 05fda99 commit ec84301

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

dist/stackapps.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseAuthor } from "./utils/author.js";
2-
import { scase } from "./utils/common.js";
2+
import { scase, uniqify } from "./utils/common.js";
33
import { makeTemplateComment, mdLink } from "./utils/index.js";
44
import { parsePackageName, prettifyPackageName } from "./utils/name.js";
55
/**
@@ -12,7 +12,7 @@ export const generateStackApps = (pkg, options) => {
1212
const { about = description, excerpt = description, installURL, languages = [], minifiedURL, orgName, orgURL, postTitle, roomURL, screenshotAlt = "screenshot of the script", screenshotURL = "", tags = [], testedIn = {}, thumbnailURL = "", worksWith = [] } = options;
1313
const browserNames = Object.keys(testedIn);
1414
const testingData = Object.values(testedIn);
15-
const managerNames = worksWith.map(scase);
15+
const managerNames = uniqify(worksWith.map(scase));
1616
const { name: authorName, url: authorUrl = "" } = parseAuthor(author);
1717
const parsedContribs = contributors.map(parseAuthor);
1818
const contribs = parsedContribs.length ? `\n\nContributors:${parsedContribs.map(({ name, url }) => `\n<br>${url ? mdLink(url, name) : name}`)}` : "";
@@ -22,9 +22,17 @@ export const generateStackApps = (pkg, options) => {
2222
const org = orgName ? `<br>Organization: ${orgURL ? mdLink(orgURL, orgName) : orgName}` : "";
2323
const room = roomURL ? `\nYou can also ${mdLink(roomURL, "drop by to chat")}, we are a friendly bunch.` : "";
2424
const screenshot = screenshotURL ? `## Screenshot\n\n!${mdLink(screenshotURL, screenshotAlt)}\n` : "";
25+
const testing = testingData.some(Boolean) ?
26+
`Version number means "last tested on":
27+
28+
| ${browserNames.map(scase).join(" | ")} |
29+
| ${new Array(browserNames.length).fill("-").join(" | ")} |
30+
| ${testingData.map((data) => data && !data.startsWith("no") ? `✔ ${data}` : "-").join(" | ")} |\n` :
31+
"";
2532
const managers = managerNames.length ?
26-
`\nSupported userscript managers:\n\n${managerNames.map((n) => `- ${scase(n)}`).join("\n")}\n` :
33+
`${testing ? "\n" : ""}Supported userscript managers:\n\n${managerNames.map((n) => `- ${scase(n)}`).join("\n")}\n` :
2734
"";
35+
const platform = managers || testing ? `\n\n### Platform\n\n${testing}${managers}` : "";
2836
const body = `
2937
${makeTemplateComment("thumbnail", thumbnailURL)}
3038
${makeTemplateComment("version", version)}
@@ -45,15 +53,7 @@ The script is licensed under the ${mdLink(`https://spdx.org/licenses/${license}`
4553
Latest version: ${version}
4654
4755
${mdLink(installURL, "Install")}${minified}
48-
49-
### Platform
50-
51-
Version number means "last tested on":
52-
53-
| ${browserNames.map(scase).join(" | ")} |
54-
| ${new Array(browserNames.length).fill("-").join(" | ")} |
55-
| ${testingData.map((data) => data && !data.startsWith("no") ? `✔ ${data}` : "-").join(" | ")} |
56-
${managers}
56+
${platform}
5757
## Change log
5858
5959
| Version | Description |

dist/validators.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @summary checks if license is a valid license
3+
*/
4+
export const validateLicense = async (license) => {
5+
if (!license)
6+
return false;
7+
return true;
8+
};

src/stackapps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseAuthor } from "./utils/author.js";
2-
import { scase } from "./utils/common.js";
2+
import { scase, uniqify } from "./utils/common.js";
33
import { makeTemplateComment, mdLink } from "./utils/index.js";
44
import { parsePackageName, prettifyPackageName } from "./utils/name.js";
55
import type { PackageInfo } from "./utils/package.js";
@@ -71,7 +71,7 @@ export const generateStackApps = (
7171
const browserNames = Object.keys(testedIn);
7272
const testingData = Object.values(testedIn);
7373

74-
const managerNames = worksWith.map(scase);
74+
const managerNames = uniqify(worksWith.map(scase));
7575

7676
const {
7777
name: authorName,

test/generator.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ describe(generateStackApps.name, async () => {
9191
expect(body).to.not.include("Supported userscript managers");
9292
});
9393

94+
it('should only add unique "works with" entries', () => {
95+
const { worksWith = [], ...options } = generatorOptions;
96+
worksWith.push(...worksWith);
97+
const { body } = generateStackApps(packageInfo, { ...options, worksWith });
98+
99+
const generatedOnlyOnce = worksWith.every((managerName) => {
100+
const matches = [...body.matchAll(new RegExp(`\\b${managerName}\\b`, "gi"))];
101+
return matches.length === 1;
102+
});
103+
104+
expect(generatedOnlyOnce).to.be.true;
105+
});
106+
94107
it('should correctly generate org info', () => {
95108
expect(body).to.match(new RegExp(`\\[${orgName}\\]\\(${orgURL}\\)`));
96109
});

0 commit comments

Comments
 (0)