Skip to content

Commit 2b03497

Browse files
committed
Get old handbook pages migrated in, adds husky when you try to push to v2
1 parent cf79faa commit 2b03497

File tree

8 files changed

+126
-68
lines changed

8 files changed

+126
-68
lines changed

.vscode/launch.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Gatsby develop",
6+
"type": "node",
7+
"request": "launch",
8+
"protocol": "inspector",
9+
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby",
10+
"args": ["develop"],
11+
"cwd": "${workspaceFolder}/packages/typescriptlang-org",
12+
"stopOnEntry": false,
13+
"runtimeArgs": ["--nolazy"],
14+
"sourceMaps": true
15+
},
16+
{
17+
"name": "Gatsby build",
18+
"type": "node",
19+
"request": "launch",
20+
"protocol": "inspector",
21+
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby",
22+
"args": ["build"],
23+
"cwd": "${workspaceFolder}/packages/typescriptlang-org",
24+
"stopOnEntry": false,
25+
"runtimeArgs": ["--nolazy"],
26+
"sourceMaps": true
27+
}
28+
]
29+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"packages/*"
55
],
66
"devDependencies": {
7-
"concurrently": "^4.1.0"
7+
"concurrently": "^4.1.0",
8+
"git-branch-is": "^3.0.0",
9+
"husky": "^3.0.8"
810
},
911
"scripts": {
1012
"start": "yarn workspace typescriptlang-org start",
@@ -18,5 +20,10 @@
1820
"semi": false,
1921
"singleQuote": true,
2022
"trailingComma": "es5"
23+
},
24+
"husky": {
25+
"hooks": {
26+
"pre-push": "git-branch-is v2 && yarn run build"
27+
}
2128
}
2229
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const {setupRedirects} = require("../src/redirects/setupRedirects")
22
const {createOldHandbookPages} = require("./ingestion/createPagesForOldHandbook")
33

4-
/** @type { import("gatsby").GatsbyNode["createPages"] } */
5-
const createPages = async (args) => {
4+
import { GatsbyNode } from "gatsby"
5+
6+
export const createPages: GatsbyNode["createPages"] = async (args) => {
7+
68
// Basically this function should be passing the right
79
// functions down to other places to handle their own
810
// creation of the pages
@@ -12,7 +14,3 @@ const createPages = async (args) => {
1214

1315
return null
1416
}
15-
16-
module.export = {
17-
createPages,
18-
}

packages/typescriptlang-org/bootup/ingestion/createPagesForOldHandbook.js

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const path = require(`path`)
2+
import { NodePluginArgs, CreatePagesArgs } from "gatsby"
3+
4+
export const createOldHandbookPages = async (graphql: CreatePagesArgs["graphql"], createPage: NodePluginArgs["actions"]["createPage"]) => {
5+
const handbookPage = path.resolve(`./src/templates/handbook.tsx`)
6+
const result = await graphql(`
7+
query GetAllHandbookDocs {
8+
allFile(filter: { sourceInstanceName: { eq: "handbook-v1" } }) {
9+
nodes {
10+
name
11+
modifiedTime
12+
13+
childMarkdownRemark {
14+
frontmatter {
15+
permalink
16+
}
17+
}
18+
}
19+
}
20+
}
21+
`)
22+
23+
if (result.errors) {
24+
throw result.errors
25+
}
26+
27+
const anyData = result.data as any
28+
const docs = anyData.allFile.nodes
29+
30+
docs.forEach((post, index) => {
31+
const previous = index === docs.length - 1 ? null : docs[index + 1].node
32+
const next = index === 0 ? null : docs[index - 1].node
33+
34+
if (post.childMarkdownRemark) {
35+
createPage({
36+
path: post.childMarkdownRemark.frontmatter.permalink,
37+
component: handbookPage,
38+
context: {
39+
slug: post.childMarkdownRemark.frontmatter.permalink,
40+
previous,
41+
next,
42+
},
43+
})
44+
} else {
45+
console.log(`skipping page generation for ${post.name}`)
46+
}
47+
})
48+
}

packages/typescriptlang-org/gatsby-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// https://github.com/gatsbyjs/gatsby/issues/1457
2+
require('ts-node').register({ files: true })
3+
14
module.exports = {
25
plugins: [
36
"gatsby-plugin-codegen",

packages/typescriptlang-org/src/templates/handbook.ts renamed to packages/typescriptlang-org/src/templates/handbook.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
// @ts-check
22
import React from "react"
33
import { Link, graphql } from "gatsby"
4-
4+
import {BlogPostBySlug} from "./__generated__/BlogPostBySlug"
55
// import Bio from "../components/bio"
66
import {Layout} from "../components/layout"
77
// import SEO from "../components/seo"
88
// import { rhythm, scale } from "../utils/typography"
99

10-
class BlogPostTemplate extends React.Component {
10+
class BlogPostTemplate extends React.Component<{ pageContext: any, data: BlogPostBySlug}> {
1111
render() {
1212
const post = this.props.data.markdownRemark
13-
const siteTitle = this.props.data.site.siteMetadata.title
13+
1414
const { previous, next } = this.props.pageContext
1515
return (
16-
<Layout location={this.props.location} title={siteTitle}>
17-
{/* <SEO
18-
title={post.frontmatter.title}
19-
description={post.frontmatter.description || post.excerpt}
20-
/> */}
21-
<h1>{post.frontmatter.title}</h1>
22-
<p>{post.frontmatter.date}</p>
16+
<Layout >
17+
2318
<div dangerouslySetInnerHTML={{ __html: post.html }} />
2419
<hr/>
2520
<ul>

yarn.lock

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4781,6 +4781,11 @@ commander@^2.11.0, commander@^2.19.0, commander@^2.20.0, commander@~2.20.0:
47814781
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
47824782
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
47834783

4784+
commander@^3.0.0:
4785+
version "3.0.2"
4786+
resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e"
4787+
integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==
4788+
47844789
commander@~2.8.1:
47854790
version "2.8.1"
47864791
resolved "https://registry.yarnpkg.com/commander/-/commander-2.8.1.tgz#06be367febfda0c330aa1e2a072d3dc9762425d4"
@@ -7866,6 +7871,13 @@ getpass@^0.1.1:
78667871
dependencies:
78677872
assert-plus "^1.0.0"
78687873

7874+
git-branch-is@^3.0.0:
7875+
version "3.0.0"
7876+
resolved "https://registry.yarnpkg.com/git-branch-is/-/git-branch-is-3.0.0.tgz#bbc5b8495fcce77da60e0eb589e41af70fcd06f7"
7877+
integrity sha512-HvOU7/TBj25NeXVzmzEMVmsLFYQD8wP/orGkGaHl1unWDx7ZZAiaulPAydUCGd+DPO3IpUjyC4zBAn2oCgaZ7Q==
7878+
dependencies:
7879+
commander "^3.0.0"
7880+
78697881
git-parse@1.0.3:
78707882
version "1.0.3"
78717883
resolved "https://registry.yarnpkg.com/git-parse/-/git-parse-1.0.3.tgz#82f165201892688ec9286184b3eee5c4cf0655ac"
@@ -8714,6 +8726,23 @@ husky@^3.0.4:
87148726
run-node "^1.0.0"
87158727
slash "^3.0.0"
87168728

8729+
husky@^3.0.8:
8730+
version "3.0.8"
8731+
resolved "https://registry.yarnpkg.com/husky/-/husky-3.0.8.tgz#8de3fed26ce9b43034ef51013c4ad368b6b74ea8"
8732+
integrity sha512-HFOsgcyrX3qe/rBuqyTt+P4Gxn5P0seJmr215LAZ/vnwK3jWB3r0ck7swbzGRUbufCf9w/lgHPVbF/YXQALgfQ==
8733+
dependencies:
8734+
chalk "^2.4.2"
8735+
cosmiconfig "^5.2.1"
8736+
execa "^1.0.0"
8737+
get-stdin "^7.0.0"
8738+
is-ci "^2.0.0"
8739+
opencollective-postinstall "^2.0.2"
8740+
pkg-dir "^4.2.0"
8741+
please-upgrade-node "^3.2.0"
8742+
read-pkg "^5.1.1"
8743+
run-node "^1.0.0"
8744+
slash "^3.0.0"
8745+
87178746
hyperlinker@^1.0.0:
87188747
version "1.0.0"
87198748
resolved "https://registry.yarnpkg.com/hyperlinker/-/hyperlinker-1.0.0.tgz#23dc9e38a206b208ee49bc2d6c8ef47027df0c0e"

0 commit comments

Comments
 (0)