Skip to content

Commit d59623d

Browse files
committed
Add nextConfig slots. Turn compilerOptions into nextConfig. Add todos.
1 parent 80c9531 commit d59623d

File tree

9 files changed

+127
-29
lines changed

9 files changed

+127
-29
lines changed

packages/create-next-stack/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@
7575
"endent": "^2.1.0",
7676
"execa": "^5.1.1",
7777
"inquirer": "^9.1.5",
78+
"lodash": "^4.17.21",
7879
"rimraf": "^5.0.0",
7980
"tslib": "^2.5.0",
8081
"validate-npm-package-name": "^5.0.0"
8182
},
8283
"devDependencies": {
8384
"@jest/globals": "^29.5.0",
8485
"@types/inquirer": "^9.0.3",
86+
"@types/lodash": "^4.14.195",
8587
"@types/node": "^18.15.13",
8688
"@types/uuid": "^9.0.1",
8789
"@types/validate-npm-package-name": "^4.0.0",

packages/create-next-stack/prod-assets/templates/LandingPage/LandingPageTemplate.module.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
gap: 40px;
1616
}
1717

18-
.technologyGridIntro {
19-
max-width: 600px;
18+
.textContainer {
2019
gap: 0.5rem;
2120
}
2221

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

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ type PluginConfig = DeeplyReadonly<{
2323
scripts?: Script[]
2424
/** A series of functions that are run by Create Next Stack. */
2525
steps?: Record<string, RawStep>
26-
/** Compiler options to set. */
27-
compilerOptions?: NextConfig["compiler"]
2826
/**
2927
* Environment variables needed by the plugin.
3028
* These variables are added to the generated .env and README.md files.
@@ -37,6 +35,11 @@ type PluginConfig = DeeplyReadonly<{
3735
/** Default value of the environment variable. */
3836
defaultValue: string
3937
}>
38+
/**
39+
* List of things to be done manually by the user after a project has been created.
40+
* The list will be added to the generated landing page, the README.md file and written to the console.
41+
*/
42+
todos?: string[]
4043
/** Slots to fill in the generated files. */
4144
slots?: {
4245
/** Slots to fill in the _app.tsx file. The file is generated using the following template:
@@ -81,8 +84,12 @@ type PluginConfig = DeeplyReadonly<{
8184
* import NextDocument, { Html, Head, Main, NextScript } from "next/document";
8285
* ${imports}
8386
*
87+
* ${afterImports}
88+
*
8489
* export default class Document extends NextDocument {
90+
* ${classMembers}
8591
* render() {
92+
* ${renderLogic}
8693
* return (
8794
* <Html lang="en" ${htmlAttributes}>
8895
* <Head>
@@ -101,21 +108,47 @@ type PluginConfig = DeeplyReadonly<{
101108
* ```
102109
*/
103110
document?: {
104-
/** Code to add to the imports section of the _document.tsx file. */
111+
/** Code to add to the imports section of the `_document.tsx` file. */
105112
imports?: string
106-
/** Code to add after the imports section of the _document.tsx file. */
113+
/** Code to add after the imports section of the `_document.tsx` file. */
107114
afterImports?: string
108-
/** Code to add to the class members of the Document class in _document.tsx file. */
115+
/** Code to add to the class members of the `Document` class in `_document.tsx` file. */
109116
classMembers?: string
110-
/** Code to add before the return statement of the Document render function in _document.tsx file. */
117+
/** Code to add before the return statement of the `Document` render function in `_document.tsx` file. */
111118
renderLogic?: string
112-
/** Code to add to the attributes of the <Html> tag of the _document.tsx file. */
119+
/** Code to add to the attributes of the <Html> tag of the `_document.tsx` file. */
113120
htmlAttributes?: string
114-
/** Code to add to the <Head> tag of the _document.tsx file. */
121+
/** Code to add to the <Head> tag of the `_document.tsx` file. */
115122
headTags?: string
116-
/** Code to add to the <body> tag of the _document.tsx file. */
123+
/** Code to add to the <body> tag of the `_document.tsx` file. */
117124
body?: string
118125
}
126+
/**
127+
* Slots to fill in the next.config.js file. The file is generated using the following template:
128+
*
129+
* ```js
130+
* `
131+
* ${imports}
132+
*
133+
* const nextConfig = {
134+
* reactStrictMode: true,
135+
* ${...nextConfig}
136+
* };
137+
*
138+
* module.exports = ${wrappersStart}nextConfig${wrappersEnd};
139+
* `
140+
* ```
141+
*/
142+
nextConfigJs?: {
143+
/** Code to add to the imports section of the `next.config.js` file. */
144+
imports?: string
145+
/** JSON object to merge into the `nextConfig` object of the `next.config.js` file. */
146+
nextConfig?: NextConfig
147+
/** Code to add to the start of the export of the `nextConfig` object of the `next.config.js` file. */
148+
wrappersStart?: string
149+
/** Code to add to the end of the export of the `nextConfig` object of the `next.config.js` file. */
150+
wrappersEnd?: string
151+
}
119152
}
120153
}>
121154

packages/create-next-stack/src/main/plugins/create-next-stack/add-content/templates/LandingPage/generate-LandingPageTemplate.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import endent from "endent"
22
import { ValidCNSInputs } from "../../../../../create-next-stack-types"
33
import { getProjectNameOfPath } from "../../../../../helpers/get-project-name-of-path"
4+
import { filterPlugins } from "../../../../../setup/setup"
45

56
export const generateLandingPageTemplate = (inputs: ValidCNSInputs): string => {
7+
const todos = filterPlugins(inputs).flatMap((plugin) => plugin.todos ?? [])
8+
const hasTodos = todos.length > 0
9+
610
return endent`
711
import Script from "next/script";
812
import styles from "./LandingPageTemplate.module.css";
@@ -100,6 +104,23 @@ export const generateLandingPageTemplate = (inputs: ValidCNSInputs): string => {
100104
</Subtitle>
101105
</Container>
102106
</Section>
107+
${
108+
hasTodos
109+
? endent`
110+
<Section>
111+
<Container className={styles.textContainer}>
112+
<H2>Final steps</H2>
113+
<Paragraph>
114+
There are a few final steps that we were not able to perform
115+
automatically. We have provided a complete list for you in the{" "}
116+
<InlineCode>README.md</InlineCode> file. You should take care of
117+
these before you can start developing your project.
118+
</Paragraph>
119+
</Container>
120+
</Section>
121+
`
122+
: ""
123+
}
103124
<Section>
104125
<Container className={styles.technologyGridIntro}>
105126
<H2>Technologies</H2>
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
import endent from "endent"
2+
import { merge } from "lodash"
3+
import { NextConfig } from "next"
24
import { ValidCNSInputs } from "../../../create-next-stack-types"
5+
import { nonNull } from "../../../helpers/non-null"
36
import { stringify } from "../../../helpers/stringify"
47
import { filterPlugins } from "../../../setup/setup"
58

69
export const generateNextConfig = async (
710
inputs: ValidCNSInputs
811
): Promise<string> => {
9-
const compilerOptions = filterPlugins(inputs).reduce(
10-
(acc, plugin) => ({
11-
...acc,
12-
...plugin.compilerOptions,
13-
}),
14-
{}
15-
)
12+
const defaultNextConfig: NextConfig = {
13+
reactStrictMode: true,
14+
}
15+
const nextConfigs = filterPlugins(inputs)
16+
.map((plugin) => plugin.slots?.nextConfigJs?.nextConfig)
17+
.filter(nonNull)
18+
const mergedNextConfig = merge(defaultNextConfig, ...nextConfigs)
19+
20+
const imports = filterPlugins(inputs)
21+
.map((plugin) => plugin.slots?.nextConfigJs?.imports)
22+
.filter(nonNull)
23+
.join("\n")
24+
25+
const wrappersStart = filterPlugins(inputs)
26+
.map((plugin) => plugin.slots?.nextConfigJs?.wrappersStart)
27+
.filter(nonNull)
28+
29+
const wrappersEnd = filterPlugins(inputs)
30+
.map((plugin) => plugin.slots?.nextConfigJs?.wrappersEnd)
31+
.filter(nonNull)
1632

1733
return endent`
34+
${imports}
35+
1836
/** @type {import('next').NextConfig} */
19-
const nextConfig = {
20-
reactStrictMode: true,
21-
compiler: ${stringify(compilerOptions)},
22-
};
37+
const nextConfig = ${stringify(mergedNextConfig)};
2338
24-
module.exports = nextConfig;
39+
module.exports = ${wrappersStart}nextConfig${wrappersEnd};
2540
`
2641
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ export const emotionPlugin = createPlugin({
4141
},
4242
},
4343
},
44-
compilerOptions: {
45-
emotion: true,
44+
slots: {
45+
nextConfigJs: {
46+
nextConfig: {
47+
compiler: {
48+
emotion: true,
49+
},
50+
},
51+
},
4652
},
4753
} as const)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export const plausiblePlugin = createPlugin({
5858
</PlausibleProvider>
5959
`,
6060
},
61+
nextConfigJs: {
62+
imports: endent`
63+
import { withPlausibleProxy } from "next-plausible";
64+
`,
65+
wrappersStart: "withPlausibleProxy()(",
66+
wrappersEnd: ")",
67+
},
6168
},
6269
environmentVariables: [
6370
{
@@ -66,4 +73,8 @@ export const plausiblePlugin = createPlugin({
6673
defaultValue: "example.com",
6774
},
6875
],
76+
todos: [
77+
`Set up an account in Plausible Analytics, and add your website in their dashboard.`,
78+
`Update the ${websiteDomainEnvVar} environment variable to your website's domain to connect Plausible Analytics to your app.`,
79+
],
6980
} as const)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ export const styledComponentsPlugin = createPlugin({
3030
],
3131
},
3232
],
33-
compilerOptions: {
34-
styledComponents: true,
33+
slots: {
34+
nextConfigJs: {
35+
nextConfig: {
36+
compiler: {
37+
styledComponents: true,
38+
},
39+
},
40+
},
3541
},
3642
} as const)

pnpm-lock.yaml

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)