Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript versions of the homepage starters #95

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7f36c25
setup to use tsc
aghreed Mar 8, 2022
f16f915
working initial pass on transpilation within publish script
aghreed Mar 8, 2022
25ffa94
adjust data.js content and publish script to accommodate only running…
aghreed Mar 8, 2022
50ab14d
convert ui.js to ui.tsx - update all .css.ts imports to explicitly us…
aghreed Mar 9, 2022
091db7d
convert over all the src/components to ts
aghreed Mar 9, 2022
7b32ace
wip converting pages to tsx
aghreed Mar 11, 2022
477c60e
fix logic in publish script
aghreed Mar 11, 2022
d246222
remove .ts file extension from import of vanilla-extract files - upda…
aghreed Mar 11, 2022
111f7af
updates after self-review
aghreed Mar 11, 2022
97e0750
use more types in components
aghreed Mar 11, 2022
80c7413
merge in work from components branch
aghreed Mar 14, 2022
25ca6ce
convert pages to TS and flesh out sections.tsx functionality
aghreed Mar 15, 2022
e7eef40
resolve newline issue during transpilation with code comments
aghreed Mar 15, 2022
6add91f
update publish script and data file
aghreed Mar 15, 2022
222a545
use union types of string literals rather than enums
aghreed Mar 16, 2022
513d184
Merge pull request #97 from gatsbyjs/chore/ts-pages-components
aghreed Mar 16, 2022
db1d92a
revert to old sections component implementation but with types
aghreed Mar 16, 2022
db9829b
remove unused type
aghreed Mar 16, 2022
8f9d74a
tweak publish script for TS concerns
aghreed Mar 17, 2022
2e75135
add yarn.lock file to list of files copied over in publish to ensure …
aghreed Mar 22, 2022
e43d532
support the TS flavors of the READMEs and handle renaming in publish …
aghreed Mar 23, 2022
293707b
merge in main
aghreed Mar 23, 2022
efb2de8
adjust publish script to remove about.tsx from ts wordpress starter
aghreed Mar 23, 2022
1c89da1
add deleted array to checks for when to commit in publish script
aghreed Mar 23, 2022
103cc7d
remove strict mode flag - update per PR feedback
aghreed Mar 28, 2022
e8040ea
update how fileExt in inline code are replaced in READMEs - rephrase …
aghreed Mar 28, 2022
04eb709
merge in latest from main
aghreed Mar 28, 2022
c15a69f
re-add Fallback component for when blocktype does not match a component
aghreed Mar 28, 2022
2511ce8
tweaks to publish script
aghreed Mar 28, 2022
dd924ff
update note on TS and JS versions
aghreed Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"remark-parse": "^10.0.1",
"remark-stringify": "^10.0.2",
"simple-git": "^3.1.0",
"typescript": "^4.6.2",
"unified": "^10.1.1",
"unist-util-visit": "^4.1.0"
},
Expand Down
59 changes: 58 additions & 1 deletion scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require("fs-extra")
const path = require("path")
const debug = require("debug")
const SimpleGit = require("simple-git")
const ts = require("typescript")
const data = require("./data")

/*
Expand Down Expand Up @@ -73,7 +74,7 @@ const createStarterDist = async (basename) => {
]

// copy root files
const rootFiles = [".gitignore", "src", "gatsby-browser.js", "LICENSE"]
const rootFiles = [".gitignore", "gatsby-browser.js", "LICENSE"]
rootFiles.forEach((file) => {
const dest = path.join(dir.dist, name, file)
console.log(`Copying '${file}' to '${dest}'`)
Expand All @@ -82,6 +83,62 @@ const createStarterDist = async (basename) => {
})
})

// array to contain all directories found inside src, seeded with src to begin with
const srcDirectories = ["src"]
// function to traverse src directory and collect array of all filenames within
const getAllSrcFiles = (dirPath = "src", filesArray = []) => {
fs.readdirSync(dirPath).forEach((file) => {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
srcDirectories.push(dirPath + "/" + file)
filesArray = getAllSrcFiles(dirPath + "/" + file, filesArray)
} else {
filesArray.push(path.join(dirPath, "/", file))
}
})
return filesArray
}

const srcFiles = getAllSrcFiles()
// create any directories needed
srcDirectories.forEach((directory) => {
const destDirectory = path.join(dir.dist, name, directory)
console.log(`Copying '${directory}' to '${destDirectory}'`)
fs.mkdirSync(destDirectory)
})
// transpile typescript src files
srcFiles.forEach((srcFilename) => {
const extension = path.extname(srcFilename)
// we want to skip over the .css.ts files and only transpile .ts/.tsx
if (
(extension === ".ts" || extension === ".tsx") &&
!srcFilename.includes(".css.ts")
) {
console.log(`Transpiling '${srcFilename}'`)
const { outputText } = ts.transpileModule(
fs.readFileSync(srcFilename).toString(),
{
compilerOptions: { jsx: "preserve", target: "es2016" },
}
)
// update the filename extension
const newExtension = extension === ".ts" ? ".js" : ".jsx"
const dest = path.join(
dir.dist,
name,
srcFilename.replace(extension, newExtension)
)
console.log(`Copying transpiled version of '${srcFilename}' to '${dest}`)
fs.writeFileSync(dest, outputText)
} else {
// copy over src files that don't require transpilation
const dest = path.join(dir.dist, name, srcFilename)
console.log(`Copying '${srcFilename}' to '${dest}'`)
fs.copySync(srcFilename, dest, {
filter: (n) => !ignore.includes(n),
})
}
})

// copy cms-specific files
const files = [
".env.EXAMPLE",
Expand Down
9 changes: 8 additions & 1 deletion src/components/caret.js → src/components/caret.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as React from "react"
import { caret } from "./caret.css.ts"
export default function CaretDown({ direction = "down", size = 9 }) {

export default function CaretDown({
direction = "down",
size = 9,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use the size prop at all; I'd be keen to remove it to simplify the API a little

}: {
direction: string
size: number
}) {
const width = size
aghreed marked this conversation as resolved.
Show resolved Hide resolved
const height = (8 / 9) * size
return (
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14356,6 +14356,11 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4"
integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==

uc-first-array@^1.1.10:
version "1.1.10"
resolved "https://registry.yarnpkg.com/uc-first-array/-/uc-first-array-1.1.10.tgz#f9e8017bd8a409ffc98a0d72ef49a8feaa6729b4"
Expand Down