1
0
mirror of https://github.com/alrayyes/my-opinionated-gatsby-starter synced 2023-11-14 15:56:29 +00:00

added typescript

This commit is contained in:
Ryan Kes 2020-06-02 16:36:56 +02:00
parent 757e3da4a6
commit 0b25d529ae
22 changed files with 3221 additions and 541 deletions

4
.eslintignore Normal file
View File

@ -0,0 +1,4 @@
node_modules
public
.cache
coverage

14
.eslintrc.json Normal file
View File

@ -0,0 +1,14 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"react-app",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"prettier/@typescript-eslint"
],
"rules": {
"react/prop-types": "off"
}
}

15
.graphqlconfig Normal file
View File

@ -0,0 +1,15 @@
{
"name": "Untitled GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "http://localhost:8000/__graphql",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}

View File

@ -38,7 +38,7 @@ _Have another more specific idea? You may want to check out our vibrant collecti
_Note: You'll also see a second link: _`http://localhost:8000/___graphql`_. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql)._
Open the `my-default-starter` directory in your code editor of choice and edit `src/pages/index.js`. Save your changes and the browser will update in real time!
Open the `my-default-starter` directory in your code editor of choice and edit `src/pages/index.tsx`. Save your changes and the browser will update in real time!
## 🧐 What's inside?

View File

@ -1,32 +1,35 @@
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
title: "Gatsby Default Starter",
description:
"Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.",
author: "@gatsbyjs",
},
plugins: [
`gatsby-plugin-react-helmet`,
"gatsby-plugin-react-helmet",
{
resolve: `gatsby-source-filesystem`,
resolve: "gatsby-source-filesystem",
options: {
name: `images`,
name: "images",
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
"gatsby-transformer-sharp",
"gatsby-plugin-sharp",
"gatsby-plugin-typescript",
{
resolve: `gatsby-plugin-manifest`,
resolve: "gatsby-plugin-manifest",
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
name: "gatsby-starter-default",
short_name: "starter",
start_url: "/",
background_color: "#663399",
theme_color: "#663399",
display: "minimal-ui",
icon: "src/images/gatsby-icon.png", // This path is relative to the root of the site.
},
},
"gatsby-plugin-eslint",
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,

View File

@ -3,7 +3,7 @@
"private": true,
"description": "A simple starter to get up and developing quickly with Gatsby",
"version": "0.1.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"author": "Ryan Kes<alias+gatsbystarter@ryankes.eu>",
"dependencies": {
"gatsby": "^2.21.37",
"gatsby-image": "^2.4.4",
@ -19,7 +19,27 @@
"react-helmet": "^6.0.0"
},
"devDependencies": {
"prettier": "2.0.5"
"@types/node": "^14.0.6",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"@types/react-helmet": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^3.1.0",
"@typescript-eslint/parser": "^3.1.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-react-app": "^5.2.1",
"eslint-loader": "^4.0.2",
"eslint-plugin-flowtype": "^5.1.3",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^4.0.4",
"gatsby-plugin-eslint": "^2.0.8",
"husky": ">=4",
"lint-staged": ">=10",
"prettier": "2.0.5",
"typescript": "^3.9.3"
},
"keywords": [
"gatsby"
@ -28,11 +48,17 @@
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,mdx,css}\"",
"lint": "eslint . --ext ts --ext tsx --ext js --ext jsx",
"lint:fix": "yarn lint --fix",
"type-check": "tsc",
"start": "yarn develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
"test": "jest",
"test:coverage": "jest --coverage",
"storybook": "NODE_ENV=production start-storybook -s public",
"build-storybook": "NODE_ENV=production build-storybook -s public"
},
"repository": {
"type": "git",
@ -40,5 +66,14 @@
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
},
"husky": {
"hooks": {
"pre-commit": "tsc && lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": ["prettier --write", "eslint --fix"],
"*.{json,md,mdx,css,yml}": "prettier --write"
}
}

2108
schema.graphql Normal file

File diff suppressed because it is too large Load Diff

3
src/@types/components/header.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export interface HeaderInterface {
siteTitle: string
}

9
src/@types/components/image.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import { FluidObject } from "gatsby-image"
export interface ImageDataInterface {
placeholderImage: {
childImageSharp: {
fluid: FluidObject
}
}
}

11
src/@types/components/layout.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
export interface LayoutInterface {
children: React.ReactNode
}
export interface LayoutDataInterface {
site: {
siteMetadata: {
title: string
}
}
}

26
src/@types/components/seo.d.ts vendored Normal file
View File

@ -0,0 +1,26 @@
interface SEOMetaNameInterface {
name: string
content: string
}
interface SEOMetaPropertyInterface {
property: string
content: string
}
export interface SEOInterface {
description?: string
lang?: string
meta?: Array<SEOMetaNameInterface | SEOMetaPropertyInterface>
title: string
}
export interface SEODataInterface {
site: {
siteMetadata: {
title: string
description: string
author: string
}
}
}

View File

@ -1,42 +0,0 @@
import { Link } from "gatsby"
import PropTypes from "prop-types"
import React from "react"
const Header = ({ siteTitle }) => (
<header
style={{
background: `rebeccapurple`,
marginBottom: `1.45rem`,
}}
>
<div
style={{
margin: `0 auto`,
maxWidth: 960,
padding: `1.45rem 1.0875rem`,
}}
>
<h1 style={{ margin: 0 }}>
<Link
to="/"
style={{
color: `white`,
textDecoration: `none`,
}}
>
{siteTitle}
</Link>
</h1>
</div>
</header>
)
Header.propTypes = {
siteTitle: PropTypes.string,
}
Header.defaultProps = {
siteTitle: ``,
}
export default Header

34
src/components/header.tsx Normal file
View File

@ -0,0 +1,34 @@
import { Link } from "gatsby"
import React from "react"
import { HeaderInterface } from "../@types/components/header"
const Header: React.FC<HeaderInterface> = ({ siteTitle }) => (
<header
style={{
background: "rebeccapurple",
marginBottom: "1.45rem",
}}
>
<div
style={{
margin: "0 auto",
maxWidth: 960,
padding: "1.45rem 1.0875rem",
}}
>
<h1 style={{ margin: 0 }}>
<Link
to="/"
style={{
color: "white",
textDecoration: "none",
}}
>
{siteTitle}
</Link>
</h1>
</div>
</header>
)
export default Header

View File

@ -1,6 +1,7 @@
import React from "react"
import { useStaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
import { ImageDataInterface } from "../@types/components/image"
/*
* This component is built using `gatsby-image` to automatically serve optimized
@ -13,8 +14,8 @@ import Img from "gatsby-image"
* - `useStaticQuery`: https://www.gatsbyjs.org/docs/use-static-query/
*/
const Image = () => {
const data = useStaticQuery(graphql`
const Image: React.FC = () => {
const data: ImageDataInterface = useStaticQuery(graphql`
query {
placeholderImage: file(relativePath: { eq: "gatsby-astronaut.png" }) {
childImageSharp {

View File

@ -6,14 +6,17 @@
*/
import React from "react"
import PropTypes from "prop-types"
import { useStaticQuery, graphql } from "gatsby"
import Header from "./header"
import "./layout.css"
import {
LayoutDataInterface,
LayoutInterface,
} from "../@types/components/layout"
const Layout = ({ children }) => {
const data = useStaticQuery(graphql`
const Layout: React.FC<LayoutInterface> = ({ children }) => {
const data: LayoutDataInterface = useStaticQuery(graphql`
query SiteTitleQuery {
site {
siteMetadata {
@ -28,15 +31,14 @@ const Layout = ({ children }) => {
<Header siteTitle={data.site.siteMetadata.title} />
<div
style={{
margin: `0 auto`,
margin: "0 auto",
maxWidth: 960,
padding: `0 1.0875rem 1.45rem`,
padding: "0 1.0875rem 1.45rem",
}}
>
<main>{children}</main>
<footer>
© {new Date().getFullYear()}, Built with
{` `}
© {new Date().getFullYear()}, Built with{" "}
<a href="https://www.gatsbyjs.org">Gatsby</a>
</footer>
</div>
@ -44,8 +46,4 @@ const Layout = ({ children }) => {
)
}
Layout.propTypes = {
children: PropTypes.node.isRequired,
}
export default Layout

View File

@ -6,12 +6,17 @@
*/
import React from "react"
import PropTypes from "prop-types"
import { Helmet } from "react-helmet"
import { useStaticQuery, graphql } from "gatsby"
import { SEOInterface, SEODataInterface } from "../@types/components/seo"
function SEO({ description, lang, meta, title }) {
const { site } = useStaticQuery(
function SEO({
description = "",
lang = "en",
meta = [],
title,
}: SEOInterface): React.ReactElement {
const { site }: SEODataInterface = useStaticQuery(
graphql`
query {
site {
@ -36,35 +41,35 @@ function SEO({ description, lang, meta, title }) {
titleTemplate={`%s | ${site.siteMetadata.title}`}
meta={[
{
name: `description`,
name: "description",
content: metaDescription,
},
{
property: `og:title`,
property: "og:title",
content: title,
},
{
property: `og:description`,
property: "og:description",
content: metaDescription,
},
{
property: `og:type`,
content: `website`,
property: "og:type",
content: "website",
},
{
name: `twitter:card`,
content: `summary`,
name: "twitter:card",
content: "summary",
},
{
name: `twitter:creator`,
name: "twitter:creator",
content: site.siteMetadata.author,
},
{
name: `twitter:title`,
name: "twitter:title",
content: title,
},
{
name: `twitter:description`,
name: "twitter:description",
content: metaDescription,
},
].concat(meta)}
@ -72,17 +77,4 @@ function SEO({ description, lang, meta, title }) {
)
}
SEO.defaultProps = {
lang: `en`,
meta: [],
description: ``,
}
SEO.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
}
export default SEO

View File

@ -2,8 +2,9 @@ import React from "react"
import Layout from "../components/layout"
import SEO from "../components/seo"
import { PageProps } from "gatsby"
const NotFoundPage = () => (
const NotFoundPage: React.FC<PageProps> = () => (
<Layout>
<SEO title="404: Not found" />
<h1>NOT FOUND</h1>

View File

@ -1,21 +1,21 @@
import React from "react"
import { Link } from "gatsby"
import { Link, PageProps } from "gatsby"
import Layout from "../components/layout"
import Image from "../components/image"
import SEO from "../components/seo"
const IndexPage = () => (
const IndexPage: React.FC<PageProps> = () => (
<Layout>
<SEO title="Home" />
<h1>Hi people</h1>
<p>Welcome to your new Gatsby site.</p>
<p>Now go build something great.</p>
<div style={{ maxWidth: `300px`, marginBottom: `1.45rem` }}>
<div style={{ maxWidth: "300px", marginBottom: "1.45rem" }}>
<Image />
</div>
<Link to="/page-2/">Go to page 2</Link> <br />
<Link to="/using-typescript/">Go to "Using TypeScript"</Link>
<Link to="/using-typescript/">Go to &quot;Using TypeScript&quot;</Link>
</Layout>
)

View File

@ -1,10 +1,10 @@
import React from "react"
import { Link } from "gatsby"
import { Link, PageProps } from "gatsby"
import Layout from "../components/layout"
import SEO from "../components/seo"
const SecondPage = () => (
const SecondPage: React.FC<PageProps> = () => (
<Layout>
<SEO title="Page two" />
<h1>Hi from the second page</h1>

View File

@ -15,10 +15,26 @@ const UsingTypescript: React.FC<PageProps<DataProps>> = ({ data, path }) => (
<Layout>
<SEO title="Using TypeScript" />
<h1>Gatsby supports TypeScript by default!</h1>
<p>This means that you can create and write <em>.ts/.tsx</em> files for your pages, components etc. Please note that the <em>gatsby-*.js</em> files (like gatsby-node.js) currently don't support TypeScript yet.</p>
<p>For type checking you'll want to install <em>typescript</em> via npm and run <em>tsc --init</em> to create a <em>.tsconfig</em> file.</p>
<p>You're currently on the page "{path}" which was built on {data.site.buildTime}.</p>
<p>To learn more, head over to our <a href="https://www.gatsbyjs.org/docs/typescript/">documentation about TypeScript</a>.</p>
<p>
This means that you can create and write <em>.ts/.tsx</em> files for your
pages, components etc. Please note that the <em>gatsby-*.js</em> files
(like gatsby-node.js) currently don&apos;t support TypeScript yet.
</p>
<p>
For type checking you&apos;ll want to install <em>typescript</em> via npm
and run <em>tsc --init</em> to create a <em>.tsconfig</em> file.
</p>
<p>
You&apos;re currently on the page &quot;{path}&quot; which was built on{" "}
{data.site.buildTime}.
</p>
<p>
To learn more, head over to our{" "}
<a href="https://www.gatsbyjs.org/docs/typescript/">
documentation about TypeScript
</a>
.
</p>
<Link to="/">Go back to the homepage</Link>
</Layout>
)

71
tsconfig.json Normal file
View File

@ -0,0 +1,71 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true,
/* Disallow inconsistently-cased references to the same file. */
"jsx": "react"
}
}

1235
yarn.lock

File diff suppressed because it is too large Load Diff