Skip to content

Commit 2f4765b

Browse files
committed
Add IDs to technologies, add technologies sort order and tests
1 parent 9b081b3 commit 2f4765b

32 files changed

+108
-34
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ See the [Framer Motion plugin](packages/create-next-stack/src/main/plugins/emoti
9292

9393
```typescript
9494
export const framerMotionPlugin = createPlugin({
95+
id: "framer-motion",
9596
name: "Framer Motion",
9697
description: "Adds support for Framer Motion",
9798
active: ({ flags }) => Boolean(flags["framer-motion"]),
@@ -103,6 +104,7 @@ export const framerMotionPlugin = createPlugin({
103104
},
104105
technologies: [
105106
{
107+
id: "framerMotion",
106108
name: "Framer Motion",
107109
description:
108110
"Framer Motion is a popular React animation library. It allows users to create both simple animations and complex gesture-based interactions. The library implements a declarative API, otherwise known as spring animations, which lets the developer define the animation's end state, letting the library handle the rest.",

packages/create-next-stack/src/main/plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export type Package = {
5858
}
5959

6060
type Technology = {
61+
/** ID that uniquely identified the technology across all plugins' technologies. */
62+
id: string
6163
/** The name of the technology. */
6264
name: string
6365
/** Description of a technology. This is displayed in the generated README.md file, as well as in the landing page's list of technologies. */
@@ -93,9 +95,7 @@ type Script = {
9395
}
9496

9597
type RawStep = {
96-
/**
97-
* `id` should be written in camelCase, and should be unique across all plugins' steps.
98-
*/
98+
/** ID that uniquely identified the technology across all plugins' steps. */
9999
id: string
100100

101101
/**

packages/create-next-stack/src/main/plugins/chakra-ui/chakra-ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const chakraUIPlugin = createPlugin({
2020
},
2121
technologies: [
2222
{
23+
id: "chakraUI",
2324
name: "Chakra UI",
2425
description:
2526
"Chakra UI is a simple, modular, and accessible React component library that provides all the building blocks needed to build React user interfaces. It uses Emotion under the hood and includes components ranging from basic buttons and form input fields to tooltips and modals.",
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import endent from "endent"
22
import { ValidCNSInputs } from "../../../../../create-next-stack-types"
3-
import { DeeplyReadonly } from "../../../../../helpers/deeply-readonly"
43
import { stringify } from "../../../../../helpers/stringify"
5-
import { filterPlugins } from "../../../../../setup/setup"
6-
7-
// TODO: Add a technologies sort order here. Use TypeScript to force setting all plugin technologies.
4+
import { getSortedFilteredTechnologies } from "../../../sort-orders/technologies"
85

96
// This type should match the one in the template below.
107
export type Technology = {
@@ -17,9 +14,7 @@ export type Technology = {
1714
}
1815

1916
export const generateTechnologies = (inputs: ValidCNSInputs): string => {
20-
const pluginTechnologies = filterPlugins(inputs).flatMap(
21-
(plugin): DeeplyReadonly<Technology[]> => plugin.technologies ?? []
22-
)
17+
const technologies = getSortedFilteredTechnologies(inputs)
2318

2419
return endent`
2520
export type Technology = {
@@ -30,6 +25,6 @@ export const generateTechnologies = (inputs: ValidCNSInputs): string => {
3025
url: string;
3126
}>;
3227
};
33-
export const technologies: Technology[] = ${stringify(pluginTechnologies)};
28+
export const technologies: Technology[] = ${stringify(technologies)};
3429
`
3530
}

packages/create-next-stack/src/main/plugins/create-next-stack/add-readme/generate-script-table-rows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ValidCNSInputs } from "../../../create-next-stack-types"
2-
import { getSortedFilteredScripts } from "../scripts/sort-order"
2+
import { getSortedFilteredScripts } from "../sort-orders/scripts"
33

44
export const generateScriptTableRows = async (
55
inputs: ValidCNSInputs

packages/create-next-stack/src/main/plugins/create-next-stack/add-readme/generate-technology-table-rows.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
import { ValidCNSInputs } from "../../../create-next-stack-types"
2-
import { filterPlugins } from "../../../setup/setup"
2+
import { getSortedFilteredTechnologies } from "../sort-orders/technologies"
33

44
export const generateTechnologyTableRows = async (
55
inputs: ValidCNSInputs
66
): Promise<string> => {
7-
type TechnologyTableRow = {
8-
name: string
9-
links: string
10-
}
11-
12-
const technologies: TechnologyTableRow[] = filterPlugins(inputs).flatMap(
13-
({ technologies }) => {
14-
if (!technologies) return []
15-
return technologies.map((technology) => ({
16-
name: technology.name,
17-
links: technology.links
18-
.map((l) => `[${l.title}](${l.url})`)
19-
.join(" - "),
20-
}))
21-
}
7+
const technologies = getSortedFilteredTechnologies(inputs).map(
8+
(technology) => ({
9+
name: technology.name,
10+
links: technology.links.map((l) => `[${l.title}](${l.url})`).join(" - "),
11+
})
2212
)
23-
2413
return technologies
2514
.map((technology) => `| ${technology.name} | ${technology.links} |`)
2615
.join("\n")

packages/create-next-stack/src/main/plugins/create-next-stack/create-next-stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { generateIndexPage } from "./add-content/pages/generate-index"
2222
import { generateLandingPageTemplate } from "./add-content/templates/LandingPage/generate-LandingPageTemplate"
2323
import { generateTechnologies } from "./add-content/templates/LandingPage/generate-technologies"
2424
import { generateReadme } from "./add-readme/generate-readme"
25-
import { getSortedFilteredScripts } from "./scripts/sort-order"
25+
import { getSortedFilteredScripts } from "./sort-orders/scripts"
2626

2727
const gitAttributesFilename = ".gitattributes"
2828

packages/create-next-stack/src/main/plugins/create-next-stack/scripts/sort-order.test.ts renamed to packages/create-next-stack/src/main/plugins/create-next-stack/sort-orders/scripts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from "@jest/globals"
22
import { plugins } from "../../../setup/setup"
3-
import { scriptsSortOrder } from "./sort-order"
3+
import { scriptsSortOrder } from "./scripts"
44

55
test("`scriptsSortOrder` contains no duplicates", () => {
66
const seenScripts = new Set<string>()

packages/create-next-stack/src/main/plugins/create-next-stack/scripts/sort-order.ts renamed to packages/create-next-stack/src/main/plugins/create-next-stack/sort-orders/scripts.ts

File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { test } from "@jest/globals"
2+
import { plugins } from "../../../setup/setup"
3+
import { technologiesSortOrder } from "./technologies"
4+
5+
test("`technologiesSortOrder` contains no duplicates", () => {
6+
const seenTechnologies = new Set<string>()
7+
for (const technology of technologiesSortOrder) {
8+
if (seenTechnologies.has(technology)) {
9+
throw new Error(
10+
`Duplicate technology with name "${technology}" found in sort-order.ts`
11+
)
12+
}
13+
seenTechnologies.add(technology)
14+
}
15+
})
16+
17+
test("`technologiesSortOrder` includes all plugins' technologies", () => {
18+
const requiredTechnologyIDs = plugins.flatMap((plugin) =>
19+
plugin.technologies //
20+
? Object.values(plugin.technologies).map((technology) => technology.id)
21+
: []
22+
)
23+
const actualTechnologyIDs = new Set(technologiesSortOrder)
24+
for (const requiredTechnology of requiredTechnologyIDs) {
25+
if (!actualTechnologyIDs.has(requiredTechnology)) {
26+
throw new Error(
27+
`Missing technology with name "${requiredTechnology}" in sort-order.ts`
28+
)
29+
}
30+
}
31+
})

0 commit comments

Comments
 (0)