Skip to content

Commit

Permalink
chore(gatsby): Convert utils/page-html to typescript (#22118)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawamataryo authored Mar 10, 2020
1 parent 54a0db5 commit 955d357
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/gatsby/src/commands/build-utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fs = require(`fs-extra`)
const path = require(`path`)
const {
remove: removePageHtmlFile,
import {
remove as removePageHtmlFile,
getPageHtmlFilePath,
} = require(`../utils/page-html`)
} from "../utils/page-html"
const {
remove: removePageDataFile,
fixedPagePath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const fs = require(`fs-extra`)
const path = require(`path`)
import fs from "fs-extra"
import path from "path"

const checkForHtmlSuffix = pagePath => !/\.(html?)$/i.test(pagePath)

const remove = async ({ publicDir }, pagePath) => {
const filePath = getPageHtmlFilePath(publicDir, pagePath)

return fs.remove(filePath)
}
const checkForHtmlSuffix = (pagePath: string): boolean =>
!/\.(html?)$/i.test(pagePath)

// copied from https://github.com/markdalgleish/static-site-generator-webpack-plugin/blob/master/index.js#L161
const getPageHtmlFilePath = (dir, outputPath) => {
export const getPageHtmlFilePath = (
dir: string,
outputPath: string
): string => {
let outputFileName = outputPath.replace(/^(\/|\\)/, ``) // Remove leading slashes for webpack-dev-server

if (checkForHtmlSuffix(outputPath)) {
Expand All @@ -20,7 +18,11 @@ const getPageHtmlFilePath = (dir, outputPath) => {
return path.join(dir, outputFileName)
}

module.exports = {
remove,
getPageHtmlFilePath,
export const remove = async (
{ publicDir }: { publicDir: string },
pagePath: string
): Promise<void> => {
const filePath = getPageHtmlFilePath(publicDir, pagePath)

return await fs.remove(filePath)
}
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/worker/render-html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require(`fs-extra`)
const Promise = require(`bluebird`)
const { join } = require(`path`)
const { getPageHtmlFilePath } = require(`../../utils/page-html`)
import { getPageHtmlFilePath } from "../../utils/page-html"

export function renderHTML({ htmlComponentRendererPath, paths, envVars }) {
// This is being executed in child process, so we need to set some vars
Expand Down

0 comments on commit 955d357

Please sign in to comment.