Skip to content

Commit 0d9c9b4

Browse files
authored
Merge pull request #103 from akd-io/release/0.1.3
Release 0.1.3
2 parents d17c366 + 987501f commit 0d9c9b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+764
-482
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ jobs:
66
build:
77
name: "Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}"
88

9-
runs-on: ${{ matrix.os }}
109
strategy:
1110
matrix:
12-
node: ["12.x", "14.x"]
11+
node: ["12", "14"]
1312
os: [ubuntu-latest, windows-latest, macOS-latest]
1413

14+
runs-on: ${{ matrix.os }}
15+
1516
steps:
1617
- name: "Check Skip Duplicate Actions"
1718
id: skip_check
@@ -27,13 +28,14 @@ jobs:
2728

2829
- name: "Use Node ${{ matrix.node }}"
2930
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
30-
uses: actions/setup-node@v1
31+
uses: actions/setup-node@v2
3132
with:
3233
node-version: ${{ matrix.node }}
34+
cache: yarn
3335

34-
- name: "Install dependencies (with cache)"
36+
- name: "Install dependencies"
3537
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
36-
uses: bahmutov/npm-install@v1
38+
run: yarn install
3739

3840
- name: "Build"
3941
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}

.github/workflows/publish.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ jobs:
1313
- name: "Checkout repo"
1414
uses: actions/checkout@v2
1515

16-
- name: "Set up Node 14"
17-
uses: actions/setup-node@v1
16+
- name: "Use latest Node LTS"
17+
uses: actions/setup-node@v2
1818
with:
19-
node-version: 14
19+
node-version: "lts/*"
20+
cache: yarn
2021

21-
- name: "Install dependencies (with cache)"
22-
uses: bahmutov/npm-install@v1
22+
- name: "Install dependencies"
23+
run: yarn install
2324

2425
- name: "Publish to npm"
2526
id: npmPublish

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Technologies marked as _convenience installs_ are technologies that work out of
6262
| [Yarn](https://yarnpkg.com/) | [CLI Docs](https://yarnpkg.com/cli) - [GitHub repo](https://github.com/yarnpkg/berry) |
6363
| [npm](https://www.npmjs.com/) | [CLI Docs](https://docs.npmjs.com/cli/) |
6464
| [Emotion](https://emotion.sh/docs/introduction) | [Docs](https://emotion.sh/docs/introduction) - [GitHub repo](https://github.com/emotion-js/emotion) |
65-
| [styled-components](https://styled-components.com/) | [Docs](https://styled-components.com/docs) - [GitHub repo](https://github.com/styled-components/styled-components) |
65+
| [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) |
6868
| [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) |
@@ -71,6 +71,7 @@ Technologies marked as _convenience installs_ are technologies that work out of
7171
| [Prettier](https://prettier.io/) | [Docs](https://prettier.io/docs/en/index.html) - [Options](https://prettier.io/docs/en/options.html) - [GitHub repo](https://github.com/prettier/prettier) |
7272
| [Husky](https://typicode.github.io/husky/) | [Docs](https://typicode.github.io/husky/) - [GitHub repo](https://github.com/typicode/husky) |
7373
| [lint-staged](https://github.com/okonet/lint-staged) | [GitHub repo](https://github.com/okonet/lint-staged) |
74+
| [GitHub Actions](https://github.com/features/actions) | [Docs](https://docs.github.com/en/actions) - [Workflow syntax](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions) |
7475

7576
## Usage
7677

@@ -90,6 +91,7 @@ OPTIONS
9091
--formatting-pre-commit-hook Adds a formatting pre-commit hook.
9192
--formik Adds Formik. (Form library)
9293
--framer-motion Adds Framer Motion. (Animation library)
94+
--github-actions Adds a GitHub Actions continuous integration workflow.
9395
--package-manager=(yarn|npm) Sets the preferred package manager.
9496
--prettier Adds Prettier. (Code formatting)
9597
--react-hook-form Adds React Hook Form. (Form library)

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.1.2",
3+
"version": "0.1.3",
44
"author": "Anders Kjær Damgaard @akd-io",
55
"bin": {
66
"create-next-stack": "./bin/run"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { IConfig } from "@oclif/config"
22
import CreateNextStack from "."
33
import { UnknownObject } from "./helpers/is-unknown-object"
4+
import { validateProjectPathInput } from "./helpers/validate-project-path"
45
import { Writable } from "./helpers/writable"
5-
import { validateProjectPathInput } from "./questionnaire/questions/validate-project-path"
66

77
/**
88
* This function is only used to retrieve the ReturnType of a call to `createNextStackInstance.parse(CreateNextStack)`.
@@ -49,13 +49,13 @@ export type ValidCreateNextStackArgs = CreateNextStackArgs & { appName: string }
4949
export const validateArgs = (
5050
args: CreateNextStackArgs
5151
): args is ValidCreateNextStackArgs => {
52-
if (typeof args.appName !== "string") {
52+
if (typeof args["appName"] !== "string") {
5353
throw new TypeError(
5454
'Outside interactive mode, you are required to specify a name for your application. Read about the "appName" argument using --help.'
5555
)
5656
}
5757

58-
const appNameValidationResult = validateProjectPathInput(args.appName)
58+
const appNameValidationResult = validateProjectPathInput(args["appName"])
5959

6060
if (typeof appNameValidationResult === "string") {
6161
throw new TypeError("Invalid app name: " + appNameValidationResult)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const inDebugMode = (): boolean => process.env.debug === "true"
1+
export const inDebugMode = (): boolean => process.env["debug"] === "true"

src/main/helpers/is-package-globally-installed.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type UnknownArray = unknown[]
2+
3+
/**
4+
* Used to test if a variable is an array and to yield stronger typing than `Array.isArray()` returns.
5+
* @param x The variable under test
6+
* @returns Whether x is an array and a strongly typed version of the object.
7+
*/
8+
export const isUnknownArray = (x: unknown): x is UnknownArray => {
9+
return Array.isArray(x)
10+
}

src/main/helpers/is-unknown-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type UnknownObject = { [key in PropertyKey]: unknown }
22

33
/**
4-
* Used to test if a variable is an object and yield stronger typing than `typeof x === "object"` does.
4+
* Used to test if a variable is an object and to yield stronger typing than `typeof x === "object"` does.
55
* Copied and slightly modified from: https://github.com/microsoft/TypeScript/issues/25720#issuecomment-533438205
66
* @param x The variable under test
77
* @returns Whether x is an object and a strongly typed version of the object.

src/main/helpers/json-files.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { promises as fs } from "fs"
2+
import { isUnknownArray } from "./is-unknown-array"
3+
import { isUnknownObject } from "./is-unknown-object"
4+
5+
export const modifyJsonFile = async (
6+
path: string,
7+
callback: (oldObject: Record<string, unknown>) => Record<string, unknown>
8+
): Promise<void> => {
9+
const oldObject = await readJsonFile(path)
10+
const newObject = callback(oldObject)
11+
await writeJsonFile(path, newObject)
12+
}
13+
14+
export const readJsonFile = async (
15+
path: string
16+
): Promise<Record<string, unknown>> => {
17+
const jsonString = await fs.readFile(path, "utf8")
18+
const jsonObject = JSON.parse(jsonString)
19+
20+
if (!isUnknownObject(jsonObject)) {
21+
throw new TypeError("Expected json object to be an object.")
22+
}
23+
24+
return jsonObject
25+
}
26+
27+
export const writeJsonFile = async (
28+
fileName: string,
29+
object: Record<string, unknown>
30+
): Promise<void> => {
31+
const objectString = JSON.stringify(object, null, 2)
32+
await fs.writeFile(fileName, objectString)
33+
}
34+
35+
/**
36+
* `toObject` takes an unknown variable, `object` and returns `object` if it's an object, or `{}` otherwise.
37+
* This makes it very easy to spread several layers of a JSON object, for example in combination with `modifyJsonFile`:
38+
*
39+
* ```typescript
40+
* await modifyJsonFile("tsconfig.json", (tsConfig) => ({
41+
* ...tsConfig,
42+
* compilerOptions: {
43+
* ...toObject(tsConfig.compilerOptions),
44+
* jsxImportSource: "@emotion/react",
45+
* },
46+
* }))
47+
* ```
48+
*
49+
* @param object
50+
* @returns
51+
*/
52+
export const toObject = (object: unknown): Record<string, unknown> => {
53+
if (isUnknownObject(object)) {
54+
return object
55+
} else {
56+
return {}
57+
}
58+
}
59+
60+
/**
61+
* `toArray` takes an unknown variable, `array` and returns `array` if it's an array, or `[]` otherwise.
62+
* This makes it very easy to spread several layers of a JSON object, for example in combination with `modifyJsonFile`:
63+
*
64+
* ```typescript
65+
* await modifyJsonFile(".babelrc", (babelConfig) => ({
66+
* ...babelConfig,
67+
* plugins: [
68+
* ["babel-plugin-styled-components"],
69+
* ...toArray(babelConfig.plugins),
70+
* ],
71+
* }))
72+
* ```
73+
*
74+
* @param object
75+
* @returns
76+
*/
77+
export const toArray = (array: unknown): unknown[] => {
78+
if (isUnknownArray(array)) {
79+
return array
80+
} else {
81+
return []
82+
}
83+
}

0 commit comments

Comments
 (0)