Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Extract core pipeline stages into its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
dpisani-atl committed Jan 14, 2020
1 parent b29663f commit 7f22b53
Show file tree
Hide file tree
Showing 148 changed files with 184 additions and 40 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"packages": [
"packages/file-viewer",
"packages/react-changelogs",
"packages/gatsby-generator"
"packages/gatsby-generator",
"packages/pipeline-stages"
]
},
"dependencies": {
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/gatsby-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
},
"files": [
"static",
"default-pages",
"babel.config.js",
"gatsby-node.js",
"gatsby-config.js",
Expand Down Expand Up @@ -66,6 +65,7 @@
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.4.3",
"@brisk-docs/file-viewer": "^0.2.5",
"@brisk-docs/pipeline-stages": "^0.1.0",
"@brisk-docs/react-changelogs": "^0.1.11",
"@emotion/core": "^10.0.9",
"@emotion/styled": "^10.0.9",
Expand Down
15 changes: 9 additions & 6 deletions packages/gatsby-generator/src/pipeline/buildPagesPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import scanMetadata from './stages/scan-metadata';
import generateWebsiteInfo from './stages/generate-website-info';
import generatePages from './stages/generate-pages';
import {
scanMetadataStage,
generateWebsiteInfoStage,
generatePagesStage,
} from '@brisk-docs/pipeline-stages';

import allPaths from './getAllPaths';

const buildPipeline = async (configPath?: string) => {
const { rootPath, wrappersPath, pagesPath, pkgRoot, config } = await allPaths(
configPath,
);

return scanMetadata({
return scanMetadataStage({
rootPath,
packagePathPatterns: config.packagesPaths,
customPackageFields: config.customPackageFields,
docs: config.docs,
showSubExamples: config.showSubExamples,
})
.then(projectData => generateWebsiteInfo(projectData))
.then(projectData => generateWebsiteInfoStage(projectData))
.then(websiteInfo =>
generatePages({
generatePagesStage({
wrappersPath,
pagesPath,
packageRoot: pkgRoot,
Expand Down
14 changes: 8 additions & 6 deletions packages/gatsby-generator/src/pipeline/buildPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import path from 'path';
import fs from 'fs-extra';
import scanMetadata from './stages/scan-metadata';
import generateWebsiteInfo from './stages/generate-website-info';
import generatePages from './stages/generate-pages';
import {
scanMetadataStage,
generateWebsiteInfoStage,
generatePagesStage,
} from '@brisk-docs/pipeline-stages';
import runGatsby from './stages/run-gatsby';
import allPaths from './getAllPaths';

Expand All @@ -15,16 +17,16 @@ const buildPipeline = async (
configPath,
);

return scanMetadata({
return scanMetadataStage({
rootPath,
packagePathPatterns: config.packagesPaths,
customPackageFields: config.customPackageFields,
docs: config.docs,
showSubExamples: config.showSubExamples,
})
.then(projectData => generateWebsiteInfo(projectData))
.then(projectData => generateWebsiteInfoStage(projectData))
.then(websiteInfo =>
generatePages({
generatePagesStage({
wrappersPath,
pagesPath,
packageRoot: pkgRoot,
Expand Down
14 changes: 8 additions & 6 deletions packages/gatsby-generator/src/pipeline/devPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import scanMetadata from './stages/scan-metadata';
import generateWebsiteInfo from './stages/generate-website-info';
import generatePages from './stages/generate-pages';
import {
scanMetadataStage,
generateWebsiteInfoStage,
generatePagesStage,
} from '@brisk-docs/pipeline-stages';
import runGatsby from './stages/run-gatsby';
import allPaths from './getAllPaths';

Expand All @@ -9,16 +11,16 @@ const devPipeline = async (configPath?: string, gatsbyOptions?: string[]) => {
configPath,
);

return scanMetadata({
return scanMetadataStage({
rootPath,
packagePathPatterns: config.packagesPaths,
customPackageFields: config.customPackageFields,
docs: config.docs,
showSubExamples: config.showSubExamples,
})
.then(projectData => generateWebsiteInfo(projectData))
.then(projectData => generateWebsiteInfoStage(projectData))
.then(websiteInfo =>
generatePages({
generatePagesStage({
wrappersPath,
pagesPath,
packageRoot: pkgRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createStage from '../make-pipeline-stage';
import { makePipelineStage } from '@brisk-docs/pipeline-stages';
// @ts-ignore
import createNextServer from '../run-website/next-server';

Expand All @@ -10,7 +10,7 @@ interface StageInput {
nextOptions?: string[];
}

export default createStage(
export default makePipelineStage(
'build-website',
async (input: StageInput): Promise<void> => {
return createNextServer(input);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createStage from '../make-pipeline-stage';
import { makePipelineStage } from '@brisk-docs/pipeline-stages';

// @ts-ignore: Importing non-ts file with no definition
import createGatsbyServer from './gatsby-server';
Expand All @@ -14,7 +14,7 @@ interface StageInput {
// Boilerplate, uncomment when used
// interface StageConfig {}

export default createStage(
export default makePipelineStage(
'run-gatsby',
async (input: StageInput): Promise<void> => createGatsbyServer(input),
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createStage from '../make-pipeline-stage';
import { makePipelineStage } from '@brisk-docs/pipeline-stages';

// @ts-ignore: Importing non-ts file with no definition
import createNextServer from './next-server';
Expand All @@ -14,7 +14,7 @@ interface StageInput {
// Boilerplate, uncomment when used
// interface StageConfig {}

export default createStage(
export default makePipelineStage(
'run-website',
async (input: StageInput): Promise<void> => {
createNextServer(input);
Expand Down
13 changes: 13 additions & 0 deletions packages/pipeline-stages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Brisk Docs Core Pipeline

This library contains the core modules that Brisk Docs uses to read docs from a monorepo and generate the code for
pages in the docs website.

Brisk's website generation functionality is broken down into a series of stages that can be run independently or in a
complete pipeline. This package exposes the following stages:

- Scan metadata: Scans the source of a monorepo and extract information about packages and docs within
- Generate website info: Creates a plan for the structure of the docs website using provided metadata
- Generate pages: Writes files to disk for all the pages to be built into the running website

For creating and running a docs website end to end please use `@brisk-docs/gatsby-generator`.
3 changes: 3 additions & 0 deletions packages/pipeline-stages/data/packages-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"metaData": []
}
5 changes: 5 additions & 0 deletions packages/pipeline-stages/data/pages-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"packages": [],
"docs": [],
"readme": []
}
5 changes: 5 additions & 0 deletions packages/pipeline-stages/data/site-meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"siteName": "",
"packages": {},
"docs": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ Brisk docs uses a pipeline of build stages to take the docs in a codebase and tu
- [Scan metadata stage](./1-scan-metadata-stage.md)
- [Generate website info stage](./2-generate-website-info-stage.md)
- [Generate pages stage](./3-generate-pages-stage.md)
- [Build website stage](./4-build-website-stage.md)
- [Start website stage](./5-start-website-stage.md)
27 changes: 27 additions & 0 deletions packages/pipeline-stages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@brisk-docs/pipeline-stages",
"version": "0.1.0",
"main": "dist/pipeline-stages.cjs.js",
"files": [
"default-pages",
"dist"
],
"dependencies": {
"@babel/runtime": "^7.4.3",
"filenamify": "^4.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"js-yaml": "^3.13.1",
"lodash.flatten": "^4.4.0",
"outdent": "^0.7.0",
"pkg-dir": "^4.2.0",
"remark-frontmatter": "^1.3.2",
"remark-parse": "^6.0.3",
"title-case": "^2.1.1",
"unified": "^7.1.0"
},
"peerDependencies": {},
"devDependencies": {
"jest-fixtures": "^0.6.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TemplateSpecifier } from '../../../../types';
import { TemplateSpecifier } from '../types';

export interface ProjectDocsConfig {
// absolute path to the docs in the filesystem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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,
Expand Down Expand Up @@ -49,7 +50,8 @@ export default createStage(
async (input: StageInput): Promise<StageOutput> => {
const { pagesPath, wrappersPath } = input;
await cleanPages(pagesPath);
await addBasePages(input.packageRoot, pagesPath);
const defaultPagesPath = await getDefaultPagesPath();
await addBasePages(defaultPagesPath, pagesPath);

const generatorConfig = { pagesPath, wrappersPath };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Generate pages build stage integration', () => {
},
],
},
packageRoot: path.resolve(__dirname, '..', '..', '..', '..'),
packageRoot: path.resolve(__dirname, '..', '..'),
sitemap: { packages: [], docs: { docs: [] } },
readmePageData: [],
packagesMeta: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
singleComponentTemplate,
wrappedComponentTemplate,
} from './templates';
import { TemplateSpecifier } from '../../../../types';
import { TemplateSpecifier } from '../types';

export type StageInput = {
// Absolute path to directory containing page wrapper components
Expand Down Expand Up @@ -281,11 +281,10 @@ export const cleanPages = async (pagesPath: string) => {

/**
* Adds the default pages into the pages directory
* @param packageRoot root path of packages
* @param defaultPagesPath absolure path to where the default pages are located
* @param pagesPath the pages directory path
*/
export const addBasePages = async (packageRoot: string, pagesPath: string) => {
const defaultPagesPath = path.join(packageRoot, 'default-pages');
export const addBasePages = async (defaultPagesPath: string, pagesPath: string) => {
await fs.copy(defaultPagesPath, pagesPath);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TemplateSpecifier } from '../../../../../../types';
import { TemplateSpecifier } from '../../../types';

const outdent = require('outdent');

Expand Down
4 changes: 4 additions & 0 deletions packages/pipeline-stages/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as makePipelineStage } from './make-pipeline-stage';
export { default as generatePagesStage } from './generate-pages';
export { default as generateWebsiteInfoStage } from './generate-website-info';
export { default as scanMetadataStage } from './scan-metadata';
72 changes: 72 additions & 0 deletions packages/pipeline-stages/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/** This is metadata specified in the frontmatter of markdown pages */
export type PageMeta = {
/** Title of the page, defaults to titlecased version of doc.id (filename) */
title: string;
};

export interface BasePage<T> {
id: string;
pagePath: string;
children?: Array<T>;
}

export interface DocsPage extends BasePage<DocsPage> {
meta: PageMeta;
}

export interface ExamplePage extends BasePage<ExamplePage> {
isolatedPath: string;
}

export interface NestedExamplePage extends ExamplePage {
children: ExamplePage[];
}

export type Page = DocsPage | ExamplePage | NestedExamplePage;

type Maintainers = string | string[];

type Repository = string | { type: string; url: string; directory?: string };

type PackageMeta = {
id: string;
description: string;
version: string;
maintainers?: Maintainers;
repository?: Repository;
};

export declare type PackageMetadata = {
metaData: PackageMeta[];
};

export declare type PackageInfo = {
id: string;
description: string;
version: string;
maintainers?: Maintainers;
packageId: string;
homePath: string;
homeMeta: PageMeta | undefined;
changelogPath: string;
docs: DocsPage[];
examples: ExamplePage[];
subExamples: NestedExamplePage[];
repository: Repository;
parentId?: string;
packageTitle?: string;
};

export type pageType =
| 'package:changelog'
| 'package:doc'
| 'package:exampe'
| 'package:home'
| 'doc:doc';

export type TemplateSpecifier = {
page: pageType;
position: 'above' | 'below' | 'replace';
// Path to the component from the docs config
component: string;
};
Loading

0 comments on commit 7f22b53

Please sign in to comment.