From 7b7d579c37114eb115565df3962078c9c3f1709d Mon Sep 17 00:00:00 2001
From: Dean Pisani <dpisani@atlassian.com>
Date: Tue, 14 Jan 2020 14:04:10 +1100
Subject: [PATCH] Move default pages back into the gatsby generator package

---
 .gitignore                                            |  2 ++
 packages/file-viewer/package.json                     |  4 +++-
 .../default-pages/_app.tsx                            |  0
 .../default-pages/_layout.tsx                         |  0
 .../default-pages/healthcheck.tsx                     |  0
 .../default-pages/index.tsx                           |  0
 .../default-pages/packages.tsx                        |  0
 .../src/pipeline/buildPagesPipeline.ts                |  3 ++-
 .../gatsby-generator/src/pipeline/buildPipeline.ts    |  3 ++-
 packages/gatsby-generator/src/pipeline/devPipeline.ts |  3 ++-
 packages/gatsby-generator/src/pipeline/getAllPaths.ts |  2 ++
 .../__fixtures__/default-pages/default-page.js        |  0
 packages/pipeline-stages/data/packages-data.json      |  3 ---
 packages/pipeline-stages/data/pages-list.json         |  5 -----
 packages/pipeline-stages/data/site-meta.json          |  5 -----
 packages/pipeline-stages/package.json                 |  3 ++-
 .../src/generate-pages/get-default-pages-path.ts      | 10 ----------
 packages/pipeline-stages/src/generate-pages/index.ts  |  6 +++---
 .../src/generate-pages/integration.test.ts            | 11 ++++++++++-
 packages/pipeline-stages/src/generate-pages/test.ts   |  1 +
 packages/react-changelogs/package.json                |  4 +++-
 yarn.lock                                             |  6 +++---
 22 files changed, 35 insertions(+), 36 deletions(-)
 rename packages/{pipeline-stages => gatsby-generator}/default-pages/_app.tsx (100%)
 rename packages/{pipeline-stages => gatsby-generator}/default-pages/_layout.tsx (100%)
 rename packages/{pipeline-stages => gatsby-generator}/default-pages/healthcheck.tsx (100%)
 rename packages/{pipeline-stages => gatsby-generator}/default-pages/index.tsx (100%)
 rename packages/{pipeline-stages => gatsby-generator}/default-pages/packages.tsx (100%)
 create mode 100644 packages/pipeline-stages/__fixtures__/default-pages/default-page.js
 delete mode 100644 packages/pipeline-stages/data/packages-data.json
 delete mode 100644 packages/pipeline-stages/data/pages-list.json
 delete mode 100644 packages/pipeline-stages/data/site-meta.json
 delete mode 100644 packages/pipeline-stages/src/generate-pages/get-default-pages-path.ts

diff --git a/.gitignore b/.gitignore
index b544d575..72dbbf6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,8 @@ scratchings.js
 /packages/gatsby-generator/static/favicon.ico
 /packages/gatsby-generator/typings
 
+/packages/pipeline-stages/data
+
 /packages/**/bundles
 /packages/gatsby-generator/public
 /packages/**/**/yarn.lock
diff --git a/packages/file-viewer/package.json b/packages/file-viewer/package.json
index c1634d0f..d033f743 100644
--- a/packages/file-viewer/package.json
+++ b/packages/file-viewer/package.json
@@ -10,7 +10,9 @@
   ],
   "author": "Peter Yu",
   "license": "MIT",
-  "files": ["dist"],
+  "files": [
+    "dist"
+  ],
   "peerDependencies": {
     "react": "16.10.2",
     "react-dom": "^16.8.4"
diff --git a/packages/pipeline-stages/default-pages/_app.tsx b/packages/gatsby-generator/default-pages/_app.tsx
similarity index 100%
rename from packages/pipeline-stages/default-pages/_app.tsx
rename to packages/gatsby-generator/default-pages/_app.tsx
diff --git a/packages/pipeline-stages/default-pages/_layout.tsx b/packages/gatsby-generator/default-pages/_layout.tsx
similarity index 100%
rename from packages/pipeline-stages/default-pages/_layout.tsx
rename to packages/gatsby-generator/default-pages/_layout.tsx
diff --git a/packages/pipeline-stages/default-pages/healthcheck.tsx b/packages/gatsby-generator/default-pages/healthcheck.tsx
similarity index 100%
rename from packages/pipeline-stages/default-pages/healthcheck.tsx
rename to packages/gatsby-generator/default-pages/healthcheck.tsx
diff --git a/packages/pipeline-stages/default-pages/index.tsx b/packages/gatsby-generator/default-pages/index.tsx
similarity index 100%
rename from packages/pipeline-stages/default-pages/index.tsx
rename to packages/gatsby-generator/default-pages/index.tsx
diff --git a/packages/pipeline-stages/default-pages/packages.tsx b/packages/gatsby-generator/default-pages/packages.tsx
similarity index 100%
rename from packages/pipeline-stages/default-pages/packages.tsx
rename to packages/gatsby-generator/default-pages/packages.tsx
diff --git a/packages/gatsby-generator/src/pipeline/buildPagesPipeline.ts b/packages/gatsby-generator/src/pipeline/buildPagesPipeline.ts
index f1a97953..eb7de314 100644
--- a/packages/gatsby-generator/src/pipeline/buildPagesPipeline.ts
+++ b/packages/gatsby-generator/src/pipeline/buildPagesPipeline.ts
@@ -7,7 +7,7 @@ import {
 import allPaths from './getAllPaths';
 
 const buildPipeline = async (configPath?: string) => {
-  const { rootPath, wrappersPath, pagesPath, pkgRoot, config } = await allPaths(
+  const { rootPath, wrappersPath, pagesPath, pkgRoot, config, defaultPagesPath } = await allPaths(
     configPath,
   );
 
@@ -23,6 +23,7 @@ const buildPipeline = async (configPath?: string) => {
       generatePagesStage({
         wrappersPath,
         pagesPath,
+        defaultPagesPath,
         packageRoot: pkgRoot,
         ...websiteInfo,
         ...config,
diff --git a/packages/gatsby-generator/src/pipeline/buildPipeline.ts b/packages/gatsby-generator/src/pipeline/buildPipeline.ts
index f0e121e7..b3070d23 100644
--- a/packages/gatsby-generator/src/pipeline/buildPipeline.ts
+++ b/packages/gatsby-generator/src/pipeline/buildPipeline.ts
@@ -13,7 +13,7 @@ const buildPipeline = async (
   configPath?: string,
   gatsbyOptions: string[] = [],
 ) => {
-  const { rootPath, wrappersPath, pagesPath, pkgRoot, config } = await allPaths(
+  const { rootPath, wrappersPath, pagesPath, pkgRoot, config, defaultPagesPath } = await allPaths(
     configPath,
   );
 
@@ -29,6 +29,7 @@ const buildPipeline = async (
       generatePagesStage({
         wrappersPath,
         pagesPath,
+        defaultPagesPath,
         packageRoot: pkgRoot,
         ...websiteInfo,
         ...config,
diff --git a/packages/gatsby-generator/src/pipeline/devPipeline.ts b/packages/gatsby-generator/src/pipeline/devPipeline.ts
index 45148f9c..007ac9fa 100644
--- a/packages/gatsby-generator/src/pipeline/devPipeline.ts
+++ b/packages/gatsby-generator/src/pipeline/devPipeline.ts
@@ -7,7 +7,7 @@ import runGatsby from './stages/run-gatsby';
 import allPaths from './getAllPaths';
 
 const devPipeline = async (configPath?: string, gatsbyOptions?: string[]) => {
-  const { rootPath, wrappersPath, pagesPath, pkgRoot, config } = await allPaths(
+  const { rootPath, wrappersPath, pagesPath, pkgRoot, config, defaultPagesPath } = await allPaths(
     configPath,
   );
 
@@ -23,6 +23,7 @@ const devPipeline = async (configPath?: string, gatsbyOptions?: string[]) => {
       generatePagesStage({
         wrappersPath,
         pagesPath,
+        defaultPagesPath,
         packageRoot: pkgRoot,
         ...websiteInfo,
         ...config,
diff --git a/packages/gatsby-generator/src/pipeline/getAllPaths.ts b/packages/gatsby-generator/src/pipeline/getAllPaths.ts
index fd858329..25e8b6d6 100644
--- a/packages/gatsby-generator/src/pipeline/getAllPaths.ts
+++ b/packages/gatsby-generator/src/pipeline/getAllPaths.ts
@@ -13,6 +13,7 @@ const getPathData = async (configPath?: string) => {
     `./un-src/components/page-templates`,
   );
   const pagesPath = path.resolve(pkgRoot, `./pages`);
+  const defaultPagesPath = path.join(pkgRoot, 'default-pages');
 
   return {
     rootPath: cwd,
@@ -20,6 +21,7 @@ const getPathData = async (configPath?: string) => {
     pagesPath,
     pkgRoot,
     config,
+    defaultPagesPath,
   };
 };
 export default getPathData;
diff --git a/packages/pipeline-stages/__fixtures__/default-pages/default-page.js b/packages/pipeline-stages/__fixtures__/default-pages/default-page.js
new file mode 100644
index 00000000..e69de29b
diff --git a/packages/pipeline-stages/data/packages-data.json b/packages/pipeline-stages/data/packages-data.json
deleted file mode 100644
index 1f5ac0ea..00000000
--- a/packages/pipeline-stages/data/packages-data.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "metaData": []
-}
\ No newline at end of file
diff --git a/packages/pipeline-stages/data/pages-list.json b/packages/pipeline-stages/data/pages-list.json
deleted file mode 100644
index ad920eaf..00000000
--- a/packages/pipeline-stages/data/pages-list.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "packages": [],
-  "docs": [],
-  "readme": []
-}
\ No newline at end of file
diff --git a/packages/pipeline-stages/data/site-meta.json b/packages/pipeline-stages/data/site-meta.json
deleted file mode 100644
index 342476e5..00000000
--- a/packages/pipeline-stages/data/site-meta.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "siteName": "",
-  "packages": {},
-  "docs": []
-}
\ No newline at end of file
diff --git a/packages/pipeline-stages/package.json b/packages/pipeline-stages/package.json
index 264d6949..5df0efea 100644
--- a/packages/pipeline-stages/package.json
+++ b/packages/pipeline-stages/package.json
@@ -22,6 +22,7 @@
   },
   "peerDependencies": {},
   "devDependencies": {
-    "jest-fixtures": "^0.6.0"
+    "jest-fixtures": "^0.6.0",
+    "mock-fs": "^4.10.1"
   }
 }
diff --git a/packages/pipeline-stages/src/generate-pages/get-default-pages-path.ts b/packages/pipeline-stages/src/generate-pages/get-default-pages-path.ts
deleted file mode 100644
index b1b56f0c..00000000
--- a/packages/pipeline-stages/src/generate-pages/get-default-pages-path.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import path from 'path';
-import pkgDir from 'pkg-dir';
-
-// Utility to get the absolute path to the default-pages directory
-export default async () => {
-  const packageRoot = await pkgDir(__dirname);
-  if (!packageRoot) throw new Error('could not resolve default-pages path');
-
-  return path.join(packageRoot, 'default-pages')
-}
diff --git a/packages/pipeline-stages/src/generate-pages/index.ts b/packages/pipeline-stages/src/generate-pages/index.ts
index c26e6382..926356be 100644
--- a/packages/pipeline-stages/src/generate-pages/index.ts
+++ b/packages/pipeline-stages/src/generate-pages/index.ts
@@ -4,7 +4,6 @@ import { BriskConfiguration } from '../common/configuration-options';
 import { StageOutput as WebsiteInfoSpec } from '../generate-website-info';
 
 import * as pageWriters from './page-writers';
-import getDefaultPagesPath from './get-default-pages-path';
 
 const {
   generatePackageDocPage,
@@ -27,6 +26,8 @@ export type StageInput = {
   pagesPath: string;
   // The absolute path to the root of the package.
   packageRoot: string;
+  // The absolute path to the directory containing default pages
+  defaultPagesPath: string;
 } & WebsiteInfoSpec &
   BriskConfiguration;
 
@@ -48,9 +49,8 @@ const generateGenericPage = (
 export default createStage(
   'generate-pages',
   async (input: StageInput): Promise<StageOutput> => {
-    const { pagesPath, wrappersPath } = input;
+    const { pagesPath, wrappersPath, defaultPagesPath } = input;
     await cleanPages(pagesPath);
-    const defaultPagesPath = await getDefaultPagesPath();
     await addBasePages(defaultPagesPath, pagesPath);
 
     const generatorConfig = { pagesPath, wrappersPath };
diff --git a/packages/pipeline-stages/src/generate-pages/integration.test.ts b/packages/pipeline-stages/src/generate-pages/integration.test.ts
index b331c7d7..3c5cc3c1 100644
--- a/packages/pipeline-stages/src/generate-pages/integration.test.ts
+++ b/packages/pipeline-stages/src/generate-pages/integration.test.ts
@@ -1,4 +1,4 @@
-import { createTempDir } from 'jest-fixtures';
+import { createTempDir, copyFixtureIntoTempDir } from 'jest-fixtures';
 import path from 'path';
 import fs from 'fs-extra';
 import generatePagesStage, { StageInput } from './index';
@@ -6,9 +6,14 @@ import generatePagesStage, { StageInput } from './index';
 describe('Generate pages build stage integration', () => {
   let pagesPath: string;
   let wrappersPath: string;
+  let defaultPagesPath: string;
 
   beforeEach(async () => {
     const cwd = await createTempDir();
+    defaultPagesPath = await copyFixtureIntoTempDir(
+      __dirname,
+      'default-pages',
+    );
     pagesPath = path.join(cwd, 'pages');
     wrappersPath = path.join(cwd, 'wrappers');
   });
@@ -18,6 +23,7 @@ describe('Generate pages build stage integration', () => {
     const input: StageInput = {
       pagesPath,
       wrappersPath,
+      defaultPagesPath,
       pages: {
         packageDocPages: [
           {
@@ -123,5 +129,8 @@ describe('Generate pages build stage integration', () => {
       path.join(pagesPath, 'package-home-pages'),
     );
     expect(packageHomePages).toEqual(['home1.js']);
+
+    const rootPages = await fs.readdir(pagesPath);
+    expect(rootPages).toContain('default-page.js');
   });
 });
diff --git a/packages/pipeline-stages/src/generate-pages/test.ts b/packages/pipeline-stages/src/generate-pages/test.ts
index 6d85ad7d..74a4c23d 100644
--- a/packages/pipeline-stages/src/generate-pages/test.ts
+++ b/packages/pipeline-stages/src/generate-pages/test.ts
@@ -19,6 +19,7 @@ jest.mock('./page-writers', () => ({
 const inputBase = {
   wrappersPath: 'WRAPPERS_PATH',
   pagesPath: 'PAGES_PATH',
+  defaultPagesPath: 'DEFAULT_PAGES_PATH',
   pages: {
     packageDocPages: [],
     projectDocPages: [],
diff --git a/packages/react-changelogs/package.json b/packages/react-changelogs/package.json
index 09825ef7..3a669411 100644
--- a/packages/react-changelogs/package.json
+++ b/packages/react-changelogs/package.json
@@ -11,7 +11,9 @@
   ],
   "author": "Aparna Raj",
   "license": "MIT",
-  "files": ["dist"],
+  "files": [
+    "dist"
+  ],
   "peerDependencies": {
     "react": "16.10.2",
     "react-dom": "^16.8.4"
diff --git a/yarn.lock b/yarn.lock
index 7fe2d5ae..5c28b214 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -13204,9 +13204,9 @@ mkdirp@0.5.1, mkdirp@0.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
     minimist "0.0.8"
 
 mock-fs@^4.10.1:
-  version "4.10.1"
-  resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.10.1.tgz#50a07a20114a6cdb119f35762f61f46266a1e323"
-  integrity sha512-w22rOL5ZYu6HbUehB5deurghGM0hS/xBVyHMGKOuQctkk93J9z9VEOhDsiWrXOprVNQpP9uzGKdl8v9mFspKuw==
+  version "4.10.4"
+  resolved "https://packages.atlassian.com/api/npm/npm-remote/mock-fs/-/mock-fs-4.10.4.tgz#4eaa3d6f7da2f44e1f3dd6b462cbbcb7b082e3d4"
+  integrity sha1-Tqo9b32i9E4fPda0Ysu8t7CC49Q=
 
 moment@2.22.2:
   version "2.22.2"