Skip to content

Commit f64b54f

Browse files
authored
Merge pull request #54 from akd-io/release/0.0.8
Release 0.0.8
2 parents 7d7d45d + 9cc77da commit f64b54f

24 files changed

+319
-74
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dot-notation": "off",
1212
"no-process-exit": "off",
1313
"unicorn/no-process-exit": "off",
14+
"no-warning-comments": "off",
1415
"@typescript-eslint/no-use-before-define": "off"
1516
}
1617
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Technologies marked as _convenience installs_ are technologies that work out of
6161
| [ESLint](https://eslint.org/) <img width="14" alt="required icon" src="assets/required-icon.png"> | [Configuration](https://eslint.org/docs/user-guide/configuring/) - [Rules](https://eslint.org/docs/rules/) - [GitHub Repo](https://github.com/eslint/eslint) |
6262
| [Yarn](https://yarnpkg.com/) <img width="14" alt="required icon" src="assets/required-icon.png"> | [CLI Docs](https://yarnpkg.com/cli) - [GitHub repo](https://github.com/yarnpkg/berry) |
6363
| [Emotion](https://emotion.sh/docs/introduction) | [Docs](https://emotion.sh/docs/introduction) - [GitHub repo](https://github.com/emotion-js/emotion) |
64+
| [styled-components](https://styled-components.com/) | [Docs](https://styled-components.com/docs) - [GitHub repo](https://github.com/styled-components/styled-components) |
6465
| [CSS Modules](https://github.com/css-modules/css-modules) | [Docs](https://github.com/css-modules/css-modules) - [Next.js-specific docs](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css) |
6566
| [React Hook Form](https://react-hook-form.com/) <img width="14" alt="convenience install icon" src="assets/convenience-icon.png"> | [Docs](https://react-hook-form.com/get-started) - [GitHub repo](https://github.com/react-hook-form/react-hook-form) |
6667
| [Formik](https://formik.org/) <img width="14" alt="convenience install icon" src="assets/convenience-icon.png"> | [Docs](https://formik.org/docs/overview) - [GitHub repo](https://github.com/formium/formik) |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-next-stack",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"author": "Anders Kjær Damgaard @akd-io",
55
"bin": {
66
"create-next-stack": "./bin/run"

src/questionnaire/questions/technologies.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { arrayToKeyToKeyMap } from "../../helpers/array-to-key-to-key-map"
44
const techValueArray = <const>[
55
"prettier",
66
"emotion",
7+
"styledComponents",
78
"cssModules",
89
"reactHookForm",
910
"formik",
@@ -30,6 +31,10 @@ const techChoices: {
3031
name: "Emotion",
3132
checked: true,
3233
},
34+
styledComponents: {
35+
value: "styledComponents",
36+
name: "Styled Components",
37+
},
3338
cssModules: {
3439
value: "cssModules",
3540
name: "CSS Modules",
@@ -71,6 +76,7 @@ export async function promptTechnologies() {
7176

7277
new Separator("Styling:"),
7378
techChoices.emotion,
79+
techChoices.styledComponents,
7480
techChoices.cssModules,
7581

7682
new Separator("Form state management:"),
@@ -91,14 +97,13 @@ export async function promptTechnologies() {
9197
return `${techChoices.preCommitHook.name} requires ${techChoices.prettier.name}`
9298
}
9399

94-
const bothEmotionAndCSSModules =
95-
technologies.includes(techValues.emotion) &&
100+
const onlyOneStylingSelected = oneOf(
101+
technologies.includes(techValues.emotion),
102+
technologies.includes(techValues.styledComponents),
96103
technologies.includes(techValues.cssModules)
97-
const neitherEmotionNorCSSModules =
98-
!technologies.includes(techValues.emotion) &&
99-
!technologies.includes(techValues.cssModules)
100-
if (bothEmotionAndCSSModules || neitherEmotionNorCSSModules) {
101-
return `You have to pick either ${techChoices.emotion.name} or ${techChoices.cssModules.name}`
104+
)
105+
if (!onlyOneStylingSelected) {
106+
return `You have to pick exactly one styling solution.`
102107
}
103108

104109
return true
@@ -107,3 +112,10 @@ export async function promptTechnologies() {
107112

108113
return technologies
109114
}
115+
116+
const oneOf = (...booleans: boolean[]) => {
117+
const count = booleans.reduce((previous, current) => {
118+
return current ? previous + 1 : previous
119+
}, 0)
120+
return count === 1
121+
}

src/setup/packages.ts

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,96 @@
1+
import execa from "execa"
2+
3+
type Package = {
4+
readonly name: string
5+
readonly minVersion: string
6+
}
7+
8+
type InstallPackageOptions = {
9+
dev?: boolean
10+
}
11+
export const yarnAdd = async (
12+
npmPackage: Package | Package[],
13+
options?: InstallPackageOptions
14+
) => {
15+
const packageArray = Array.isArray(npmPackage) ? npmPackage : [npmPackage]
16+
17+
const packagesWithVersions = packageArray.map((pkg) =>
18+
getQuotedNameVersionCombo(pkg)
19+
)
20+
21+
let yarnAddCommand = "yarn add"
22+
if (options != null && options.dev != null && options.dev) {
23+
yarnAddCommand += " --dev"
24+
}
25+
packagesWithVersions.forEach((packageWithVersion) => {
26+
yarnAddCommand += ` ${packageWithVersion}`
27+
})
28+
return execa(yarnAddCommand)
29+
}
30+
31+
export const getQuotedNameVersionCombo = (npmPackage: Package) => {
32+
return `"${npmPackage.name}@^${npmPackage.minVersion}"`
33+
}
34+
135
export const packages = {
2-
yarn: "yarn@1",
3-
prettier: "prettier@2",
4-
"eslint-config-prettier": "eslint-config-prettier@8",
5-
"@emotion/react": "@emotion/react@11",
6-
"@emotion/styled": "@emotion/styled@11",
7-
"@emotion/babel-plugin": "@emotion/babel-plugin@11",
8-
"react-hook-form": "react-hook-form@7",
9-
formik: "formik@2",
10-
"framer-motion": "framer-motion@4",
11-
"create-next-app": "create-next-app@11",
12-
mrm: "mrm@2",
36+
yarn: {
37+
name: "yarn",
38+
minVersion: "1.0.0",
39+
},
40+
prettier: {
41+
name: "prettier",
42+
minVersion: "2.0.0",
43+
},
44+
"eslint-config-prettier": {
45+
name: "eslint-config-prettier",
46+
minVersion: "8.0.0",
47+
},
48+
"@emotion/react": {
49+
name: "@emotion/react",
50+
minVersion: "11.0.0",
51+
},
52+
"@emotion/styled": {
53+
name: "@emotion/styled",
54+
minVersion: "11.0.0",
55+
},
56+
"@emotion/babel-plugin": {
57+
name: "@emotion/babel-plugin",
58+
minVersion: "11.0.0",
59+
},
60+
"styled-components": {
61+
name: "styled-components",
62+
minVersion: "5.0.0",
63+
},
64+
"@types/styled-components": {
65+
name: "@types/styled-components",
66+
minVersion: "5.0.0",
67+
},
68+
"babel-plugin-styled-components": {
69+
name: "babel-plugin-styled-components",
70+
minVersion: "1.0.0",
71+
},
72+
"react-hook-form": {
73+
name: "react-hook-form",
74+
minVersion: "7.0.0",
75+
},
76+
formik: {
77+
name: "formik",
78+
minVersion: "2.0.0",
79+
},
80+
"framer-motion": {
81+
name: "framer-motion",
82+
minVersion: "4.0.0",
83+
},
84+
"create-next-app": {
85+
name: "create-next-app",
86+
minVersion: "11.0.0",
87+
},
88+
mrm: {
89+
name: "mrm",
90+
minVersion: "3.0.0",
91+
},
92+
"mrm-task-lint-staged": {
93+
name: "mrm-task-lint-staged",
94+
minVersion: "6.0.0",
95+
},
1396
} as const

src/setup/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { removeOfficialCNAContentStep } from "./steps/remove-official-cna-conten
1616
import { setUpEmotionStep } from "./steps/set-up-emotion"
1717
import { setUpLintStagedStep } from "./steps/set-up-lint-staged"
1818
import { setUpPrettierStep } from "./steps/set-up-prettier"
19+
import { setUpStyledComponentsStep } from "./steps/set-up-styled-components"
1920
import { updateYarnStep } from "./steps/update-yarn"
2021

2122
export async function performSetupSteps(
@@ -30,6 +31,7 @@ export async function performSetupSteps(
3031

3132
addBaseBabelConfigStep,
3233
setUpEmotionStep,
34+
setUpStyledComponentsStep,
3335

3436
setUpPrettierStep,
3537
setUpLintStagedStep,

src/setup/steps/add-content/add-content.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ export const addContentStep: Step = {
2424
writeFile("pages/_app.tsx", generateApp(answers)),
2525
]
2626

27-
if (answers.technologies.includes(techValues.emotion)) {
27+
if (
28+
answers.technologies.includes(techValues.emotion) ||
29+
answers.technologies.includes(techValues.styledComponents)
30+
) {
2831
promises.push(
2932
writeFile(
3033
"components/WithDefaultGlobalStyles.tsx",
31-
generateWithDefaultGlobalStyles()
34+
generateWithDefaultGlobalStyles(answers)
3235
)
3336
)
34-
}
35-
36-
if (answers.technologies.includes(techValues.cssModules)) {
37+
} else if (answers.technologies.includes(techValues.cssModules)) {
3738
await mkdir("styles")
3839
promises.push(writeFile("styles/index.module.css", indexCSSModule))
3940
promises.push(writeFile("styles/global-styles.css", globalStyles))
41+
} else {
42+
throw new Error(
43+
"Unsupported styling technology found in addContentStep, or no styling technology was chosen."
44+
)
4045
}
4146

4247
await Promise.all(promises)
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { QuestionnaireAnswers } from "../../../../questionnaire/questionnaire"
22
import { techValues } from "../../../../questionnaire/questions/technologies"
3-
import { generateIndexWithCssModules } from "./generate-index-with-css-modules"
4-
import { generateIndexWithEmotion } from "./generate-index-with-emotion"
3+
import { generateIndexWithCssInJs } from "./with-css-in-js/generate-index-with-css-in-js"
4+
import { generateIndexWithCssModules } from "./with-css-modules/generate-index-with-css-modules"
55

66
export const generateIndex = (answers: QuestionnaireAnswers) => {
7-
if (answers.technologies.includes(techValues.emotion)) {
8-
return generateIndexWithEmotion(answers)
9-
} else {
7+
if (
8+
answers.technologies.includes(techValues.emotion) ||
9+
answers.technologies.includes(techValues.styledComponents)
10+
) {
11+
return generateIndexWithCssInJs(answers)
12+
} else if (answers.technologies.includes(techValues.cssModules)) {
1013
return generateIndexWithCssModules(answers)
14+
} else {
15+
throw new Error(
16+
"Unsupported styling technology found in generateIndex, or no styling technology was chosen."
17+
)
1118
}
1219
}

src/setup/steps/add-content/generate-index/generate-index-with-emotion.ts renamed to src/setup/steps/add-content/generate-index/with-css-in-js/generate-index-with-css-in-js.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { QuestionnaireAnswers } from "../../../../questionnaire/questionnaire"
1+
import { QuestionnaireAnswers } from "../../../../../questionnaire/questionnaire"
22
import {
33
confettiImports,
44
confettiScriptComponent,
55
onConfettiLoadFunction,
6-
} from "./confetti-script"
6+
} from "../confetti-script"
7+
import { getStyledImport } from "./get-styled-import"
78

8-
export const generateIndexWithEmotion = (
9+
export const generateIndexWithCssInJs = (
910
answers: QuestionnaireAnswers
1011
) => /* tsx */ `
11-
import styled from "@emotion/styled";
12+
${getStyledImport(answers)}
1213
import { NextPage } from "next";
1314
${confettiImports}
1415
import Page from "../components/Page";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { QuestionnaireAnswers } from "../../../../../questionnaire/questionnaire"
2+
import { techValues } from "../../../../../questionnaire/questions/technologies"
3+
4+
export const getStyledImport = (answers: QuestionnaireAnswers) => {
5+
if (answers.technologies.includes(techValues.emotion)) {
6+
return `import styled from "@emotion/styled";`
7+
} else if (answers.technologies.includes(techValues.styledComponents)) {
8+
return `import styled from "styled-components";`
9+
} else {
10+
throw new Error(
11+
"Unsupported styled library found in getStyledImport, or no styled library was chosen."
12+
)
13+
}
14+
}

0 commit comments

Comments
 (0)