Skip to content

Commit 41dd49d

Browse files
authored
Merge pull request #105 from akd-io/release/0.1.4
Release 0.1.4
2 parents 0d9c9b4 + 14b1f3f commit 41dd49d

35 files changed

+470
-119
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Technologies marked as _convenience installs_ are technologies that work out of
6565
| [Styled Components](https://styled-components.com/) | [Docs](https://styled-components.com/docs) - [GitHub repo](https://github.com/styled-components/styled-components) |
6666
| [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) |
6767
| [Sass](https://sass-lang.com/) <img width="14" alt="convenience install icon" src="assets/convenience-icon.png"> | [Docs](https://sass-lang.com/documentation) - [Next.js-specific docs](https://nextjs.org/docs/basic-features/built-in-css-support#sass-support) |
68+
| [Chakra UI](https://chakra-ui.com/) | [Docs](https://chakra-ui.com/docs/getting-started) - [GitHub repo](https://github.com/chakra-ui/chakra-ui) |
6869
| [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) |
6970
| [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) |
7071
| [Framer Motion](https://www.framer.com/motion/) <img width="14" alt="convenience install icon" src="assets/convenience-icon.png"> | [Docs](https://www.framer.com/docs/) - [GitHub repo](https://github.com/framer/motion) |
@@ -87,15 +88,16 @@ ARGUMENTS
8788
OPTIONS
8889
-h, --help Shows the CLI help information.
8990
-v, --version Shows the CLI version information.
91+
--chakra Adds Chakra UI. (Component library) (Requires Emotion and Framer Motion)
9092
--debug Show verbose error messages for debugging purposes.
91-
--formatting-pre-commit-hook Adds a formatting pre-commit hook.
93+
--formatting-pre-commit-hook Adds a formatting pre-commit hook. (Requires Prettier)
9294
--formik Adds Formik. (Form library)
9395
--framer-motion Adds Framer Motion. (Animation library)
9496
--github-actions Adds a GitHub Actions continuous integration workflow.
95-
--package-manager=(yarn|npm) Sets the preferred package manager.
97+
--package-manager=(yarn|npm) Sets the preferred package manager. (Required)
9698
--prettier Adds Prettier. (Code formatting)
9799
--react-hook-form Adds React Hook Form. (Form library)
98-
--styling=<styling-method> Sets the preferred styling method. <styling-method> = emotion|styled-components|css-modules|css-modules-with-sass
100+
--styling=<styling-method> Sets the preferred styling method. (Required) <styling-method> = emotion|styled-components|css-modules|css-modules-with-sass
99101
```
100102

101103
## License

bin-test/run-prod.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\run-prod" %*

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-next-stack",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"author": "Anders Kjær Damgaard @akd-io",
55
"bin": {
66
"create-next-stack": "./bin/run"
@@ -58,7 +58,7 @@
5858
"prepare": "husky install",
5959
"prepack": "yarn build && oclif-dev readme",
6060
"build": "rimraf lib && tsc -b",
61-
"test": "yarn build && node lib/tests/e2e/test.js",
61+
"test": "yarn build && yarn run test-only",
6262
"test-only": "node lib/tests/e2e/test.js",
6363
"manual-test": "yarn build && node lib/tests/e2e/manual-test.js --debug",
6464
"quick-test": "yarn build && node lib/tests/e2e/manual-test.js --debug --package-manager=npm --styling=css-modules",

prod-assets/templates/LandingPage/components/H1.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
margin-bottom: 20px;
44

55
font-size: 3rem;
6+
font-weight: bold;
67
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.h2 {
22
margin: 0;
33
margin-bottom: 20px;
4+
5+
font-size: 1.5rem;
6+
font-weight: bold;
47
}

src/main/create-next-stack-types.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,30 @@ export const validateFlags = (
7373
flags: CreateNextStackFlags
7474
): flags is ValidCreateNextStackFlags => {
7575
if (typeof flags["package-manager"] !== "string") {
76-
throw new TypeError(
76+
throw new Error(
7777
'Outside interactive mode, you are required to specify a package manager. Read about the "--package-manager" option using --help.'
7878
)
7979
}
8080
if (typeof flags.styling !== "string") {
81-
throw new TypeError(
81+
throw new Error(
8282
'Outside interactive mode, you are required to specify a styling method. Read about the "--styling" option using --help.'
8383
)
8484
}
85+
if (flags.chakra && flags.styling !== "emotion") {
86+
throw new Error(
87+
"Chakra UI (category: Component library, flag: --chakra) requires Emotion (category: Styling, flag: --styling=emotion)."
88+
)
89+
}
90+
if (flags.chakra && !flags["framer-motion"]) {
91+
throw new Error(
92+
"Chakra UI (category: Component library, flag: --chakra) requires Framer Motion (category: Animation, flag: --framer-motion)."
93+
)
94+
}
95+
if (flags["formatting-pre-commit-hook"] && !flags["prettier"]) {
96+
throw new Error(
97+
"Formatting pre-commit hook (category: Miscellaneous, flag: --formatting-pre-commit-hook) requires Prettier (category: Formatting, flag: --prettier)."
98+
)
99+
}
85100
return true
86101
}
87102

src/main/helpers/exit-with-error.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { ExitError } from "@oclif/errors"
12
import { logError } from "../logging"
23
import { inDebugMode } from "./is-debug-enabled"
34

45
export const exitWithError = (error: unknown): never => {
5-
if (error instanceof Error) {
6+
if (error instanceof ExitError && error.oclif.exit === 0) {
7+
process.exit(0)
8+
} else if (error instanceof Error) {
69
if (error.stack != null) {
710
logError(error.stack)
811
}

src/main/helpers/json-files.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ export const toObject = (object: unknown): Record<string, unknown> => {
7474
* @param object
7575
* @returns
7676
*/
77-
export const toArray = (array: unknown): unknown[] => {
78-
if (isUnknownArray(array)) {
79-
return array
77+
export const toArray = (value: unknown): unknown[] => {
78+
if (isUnknownArray(value)) {
79+
return value
80+
} else if (typeof value === "string") {
81+
return [value]
8082
} else {
8183
return []
8284
}

src/main/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CreateNextStack extends Command {
4242
// Package manager:
4343
"package-manager": flags.enum({
4444
options: writablePackageManagerOptions,
45-
description: "Sets the preferred package manager.",
45+
description: "Sets the preferred package manager. (Required)",
4646
}),
4747

4848
// Formatting:
@@ -53,12 +53,18 @@ class CreateNextStack extends Command {
5353
// Styling:
5454
styling: flags.enum({
5555
options: writableStylingOptions,
56-
description: `Sets the preferred styling method. <styling-method> = ${writableStylingOptions.join(
56+
description: `Sets the preferred styling method. (Required) <styling-method> = ${writableStylingOptions.join(
5757
"|"
5858
)}`,
5959
helpValue: "<styling-method>",
6060
}),
6161

62+
// Component libraries:
63+
chakra: flags.boolean({
64+
description:
65+
"Adds Chakra UI. (Component library) (Requires Emotion and Framer Motion)",
66+
}),
67+
6268
// Form libraries:
6369
"react-hook-form": flags.boolean({
6470
description: "Adds React Hook Form. (Form library)",
@@ -79,8 +85,7 @@ class CreateNextStack extends Command {
7985

8086
// Formatting pre-commit hook
8187
"formatting-pre-commit-hook": flags.boolean({
82-
description: "Adds a formatting pre-commit hook.",
83-
dependsOn: ["prettier"],
88+
description: "Adds a formatting pre-commit hook. (Requires Prettier)",
8489
}),
8590
}
8691

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,95 @@
11
import { ValidCreateNextStackFlags } from "../create-next-stack-types"
2-
import { ThenArg } from "../helpers/then-arg"
32
import { withKeyConstraint } from "../helpers/with-key-constraint"
43
import { CategoryValue, promptOptionalCategories } from "./questions/categories"
5-
import { promptAnimation } from "./questions/categories/animation"
6-
import { promptContinuousIntegration } from "./questions/categories/continuous-integration"
7-
import { promptFormStateManagement } from "./questions/categories/form-state-management"
8-
import { promptFormatting } from "./questions/categories/formatting"
4+
import {
5+
AnimationValue,
6+
promptAnimation,
7+
} from "./questions/categories/animation"
8+
import {
9+
ComponentLibraryValue,
10+
promptComponentLibraries,
11+
} from "./questions/categories/component-libraries"
12+
import {
13+
ContinuousIntegrationValue,
14+
promptContinuousIntegration,
15+
} from "./questions/categories/continuous-integration"
16+
import {
17+
FormStateManagementValue,
18+
promptFormStateManagement,
19+
} from "./questions/categories/form-state-management"
20+
import {
21+
FormattingValue,
22+
promptFormatting,
23+
} from "./questions/categories/formatting"
924
import {
1025
MiscellaneousValue,
1126
promptMiscellaneous,
1227
} from "./questions/categories/miscellaneous"
13-
import { promptPackageManager } from "./questions/categories/package-manager"
14-
import { promptStyling } from "./questions/categories/styling"
28+
import {
29+
PackageManagerValue,
30+
promptPackageManager,
31+
} from "./questions/categories/package-manager"
32+
import { promptStyling, StylingValue } from "./questions/categories/styling"
1533

1634
const categoryToPromptFunction = withKeyConstraint<CategoryValue>()({
1735
formatting: promptFormatting,
36+
componentLibraries: promptComponentLibraries,
1837
formStateManagement: promptFormStateManagement,
1938
animation: promptAnimation,
2039
continuousIntegration: promptContinuousIntegration,
2140
} as const)
2241

23-
type PromptReturnType = ThenArg<
24-
ReturnType<typeof categoryToPromptFunction[CategoryValue]>
25-
>
26-
export type OptionalTechnology = PromptReturnType extends Array<unknown>
27-
? PromptReturnType[number]
28-
: PromptReturnType
42+
export type Technology =
43+
| AnimationValue
44+
| ComponentLibraryValue
45+
| ContinuousIntegrationValue
46+
| FormStateManagementValue
47+
| FormattingValue
48+
| MiscellaneousValue
49+
| PackageManagerValue
50+
| StylingValue
2951

3052
export const performFlagsQuestionnaire =
3153
async (): Promise<ValidCreateNextStackFlags> => {
54+
const technologies = new Set<Technology>()
55+
3256
// Mandatory prompts
3357
const packageManager = await promptPackageManager()
58+
technologies.add(packageManager)
3459
const stylingMethod = await promptStyling()
60+
technologies.add(stylingMethod)
3561

3662
// Optional categories prompt
3763
const optionalCategories = await promptOptionalCategories()
38-
const optionalTechnologies = new Set<OptionalTechnology>()
3964
for (const category of optionalCategories) {
40-
const additionalTechnologies = await categoryToPromptFunction[category]()
41-
additionalTechnologies.forEach((tech) => optionalTechnologies.add(tech))
65+
const optionalTechnologies = await categoryToPromptFunction[category](
66+
technologies
67+
)
68+
optionalTechnologies.forEach((tech) => technologies.add(tech))
4269
}
4370

4471
// TODO: Remove prettier-check when promptMiscellaneous adds more options
4572
let miscellaneous: Set<MiscellaneousValue> = new Set()
46-
if (optionalTechnologies.has("prettier")) {
47-
miscellaneous = await promptMiscellaneous(optionalTechnologies)
73+
if (technologies.has("prettier")) {
74+
miscellaneous = await promptMiscellaneous(technologies)
75+
miscellaneous.forEach((tech) => technologies.add(tech))
4876
}
4977

50-
return {
78+
const result: Required<
79+
Omit<ValidCreateNextStackFlags, "help" | "version" | "debug">
80+
> = {
5181
"package-manager": packageManager,
5282
styling: stylingMethod,
53-
prettier: optionalTechnologies.has("prettier"),
54-
"react-hook-form": optionalTechnologies.has("reactHookForm"),
55-
formik: optionalTechnologies.has("formik"),
56-
"framer-motion": optionalTechnologies.has("framerMotion"),
57-
"github-actions": optionalTechnologies.has("githubActions"),
83+
prettier: technologies.has("prettier"),
84+
"react-hook-form": technologies.has("reactHookForm"),
85+
formik: technologies.has("formik"),
86+
"framer-motion": technologies.has("framerMotion"),
87+
"github-actions": technologies.has("githubActions"),
5888
"formatting-pre-commit-hook": miscellaneous.has(
5989
"formattingPreCommitHook"
6090
),
91+
chakra: technologies.has("chakra"),
6192
}
93+
94+
return result
6295
}

0 commit comments

Comments
 (0)