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

Commit 6dbc7dc

Browse files
authored
Issue/afp 355 website pipeline (#166)
* AFP-355: Create scaffold for website build pipeline * AFP-355: Fix babel configs to produce working bin scripts. Remove styled-components from react-changelogs. Add config options to pipeline interface. * AFP-355: Add changesets * AFP-355: Reset babel dependencies back to their previous versions
1 parent a53f861 commit 6dbc7dc

38 files changed

+280
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"releases": [
3+
{ "name": "changeset-bot", "type": "patch" },
4+
{ "name": "@brisk-docs/file-viewer", "type": "patch" },
5+
{ "name": "@brisk-docs/react-changelogs", "type": "patch" },
6+
{ "name": "@brisk-docs/website", "type": "patch" }
7+
],
8+
"dependents": []
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix babel configs for building packages to produce working dists for node scripts.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"releases": [{ "name": "@brisk-docs/react-changelogs", "type": "patch" }],
3+
"dependents": []
4+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use emotion instead of styled components.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"releases": [{ "name": "@brisk-docs/website", "type": "minor" }],
3+
"dependents": []
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add scaffolding for new website build pipeline. This is available as a brisk-next command.

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
presets: ['next/babel', '@zeit/next-typescript/babel'],
2+
presets: ['@babel/preset-env', '@babel/react', '@babel/preset-typescript'],
33
plugins: [
44
'emotion',
55
[

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"delete:dist": "bolt ws exec --parallel -- rm -rf dist",
2121
"delete:modules": "bolt ws exec --parallel -- rm -rf node_modules && rm -rf node_modules",
2222
"docs": "node packages/website/src/bin/index.js dev",
23+
"docs-next": "node packages/website/bin.js",
2324
"prettier": "prettier --write \"**/*.{js,ts,tsx}\"",
2425
"lint": "yarn lint:eslint && yarn lint:prettier && yarn check:types",
2526
"lint:prettier": "prettier --list-different \"**/*.{js,ts,tsx}\"",
@@ -40,7 +41,8 @@
4041
"preconstruct": {
4142
"packages": [
4243
"packages/react-changelogs",
43-
"packages/file-viewer"
44+
"packages/file-viewer",
45+
"packages/website"
4446
]
4547
},
4648
"dependencies": {

packages/changeset-bot/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('changeset-bot', () => {
1717
const app = probot.load(changesetBot);
1818

1919
// just return a test token
20-
app.app = () => 'test';
20+
app.app = () => 'test.ts';
2121
});
2222

2323
it('should add a comment when there is no comment', async () => {

packages/file-viewer/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@atlaskit/icon": "^16.0.1",
3737
"@atlaskit/theme": "^6.0.0",
3838
"@atlaskit/toggle": "^7.0.0",
39+
"@babel/runtime": "^7.4.3",
3940
"@babel/runtime-corejs2": "^7.4.3",
4041
"@emotion/core": "^10.0.9",
4142
"@emotion/styled": "^10.0.9",
@@ -45,4 +46,4 @@
4546
"react-addons-text-content": "^0.0.4",
4647
"react-markdown": "^2.5.0"
4748
}
48-
}
49+
}

packages/react-changelogs/examples/filter-changelogs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import styled from 'styled-components';
2+
import styled from '@emotion/styled';
33
import { gridSize, math } from '@atlaskit/theme';
44
import Changelog from '../src/components/changelog';
55

packages/react-changelogs/examples/set-changelog-entries-per-page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import styled from 'styled-components';
2+
import styled from '@emotion/styled';
33
import { gridSize, math } from '@atlaskit/theme';
44
import Changelog from '../src/components/changelog';
55

packages/react-changelogs/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
"@atlaskit/css-reset": "^3.0.5",
3535
"@atlaskit/pagination": "^10.0.1",
3636
"@atlaskit/theme": "^6.0.0",
37+
"@babel/runtime": "^7.4.3",
3738
"@babel/runtime-corejs2": "^7.4.3",
39+
"@emotion/core": "^10.0.9",
40+
"@emotion/styled": "^10.0.9",
3841
"prismjs": "^1.15.0",
3942
"react-addons-text-content": "^0.0.4",
4043
"react-markdown": "^2.5.0",
41-
"semver": "^5.4.1",
42-
"styled-components": "^3.2.6"
44+
"semver": "^5.4.1"
4345
}
44-
}
46+
}

packages/react-changelogs/src/components/changelog.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react';
22
// @ts-ignore - The types for ReactMarkdown are wrong and do not think it has a default export
33
import ReactMarkdown from 'react-markdown';
4-
import styled, { css } from 'styled-components';
5-
import { math, gridSize, colors, borderRadius } from '@atlaskit/theme';
4+
import styled from '@emotion/styled';
5+
import { gridSize, colors, borderRadius } from '@atlaskit/theme';
66
import Pagination from '@atlaskit/pagination';
77
import filterChangelog from '../utils/filter-changelog';
88
import divideChangelog from '../utils/divide-changelog';
99

10-
const gutter = math.multiply(gridSize, 3);
10+
const gutter = gridSize() * 3;
1111

1212
const H3 = styled.h3`
1313
color: ${colors.N200};
@@ -56,8 +56,8 @@ const LogItem = styled.div`
5656
5757
${(p: { major: boolean }) =>
5858
p.major
59-
? css`
60-
&:not(:first-child) {
59+
? `
60+
&:not(:first-of-type) {
6161
border-top: 2px solid ${colors.N30};
6262
margin-top: ${gutter}px;
6363
padding-top: ${gutter}px;

packages/website/bin.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable strict */
3+
4+
'use strict';
5+
6+
const runPipeline = require('./').default;
7+
8+
runPipeline().catch(e => console.error(e));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Scan metadata build stage
2+
3+
This is the start of the Brisk pipeline. During this stage, the target project is scanned in order to find all the
4+
packages, examples and docs that will be used in the final website. The output of this stage is a data structure
5+
containing all of this info.
6+
7+
This stage should be the only one in the pipeline to be reading the user's filesystem to find the location of important
8+
files or for other metadata. This is to avoid harmful couplings of the filesystem to the finished website.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generate website info build stage
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Generate pages build stage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Build website build stage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Start website build stage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# The brisk website build pipeline
2+
3+
Brisk docs uses a pipeline of build stages to take the docs in a codebase and turn it into a website.
4+
5+
## Build stages reference
6+
7+
- [Scan metadata stage](./1-scan-metadata-stage.md)
8+
- [Generate website info stage](./2-generate-website-info-stage.md)
9+
- [Generate pages stage](./3-generate-pages-stage.md)
10+
- [Build website stage](./4-build-website-stage.md)
11+
- [Start website stage](./5-start-website-stage.md)

packages/website/docs/nesting/work.md

-1
This file was deleted.

packages/website/package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "@brisk-docs/website",
33
"version": "0.7.4",
44
"description": "The Brisk website documenter",
5-
"main": "src/bin/index.js",
5+
"main": "dist/website.cjs.js",
6+
"module": "dist/website.esm.js",
67
"maintainers": [
78
"Dean Pisani",
89
"Aparna Raj",
@@ -21,7 +22,11 @@
2122
"start": "node src/bin/index.js start"
2223
},
2324
"bin": {
24-
"brisk": "src/bin/index.js"
25+
"brisk": "src/bin/index.js",
26+
"brisk-next": "bin.js"
27+
},
28+
"engines": {
29+
"node": ">=10.0.0"
2530
},
2631
"files": [
2732
"src",
@@ -33,7 +38,9 @@
3338
"next.config.js",
3439
"next-externals.js",
3540
"types.ts",
36-
"tsconfig.json"
41+
"tsconfig.json",
42+
"bin.js",
43+
"dist"
3744
],
3845
"dependencies": {
3946
"@atlaskit/avatar": "^14.1.8",
@@ -120,4 +127,4 @@
120127
"mock-fs": "^4.10.1",
121128
"ts-loader": "^5.3.3"
122129
}
123-
}
130+
}

packages/website/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import runPipeline from './pipeline';
2+
3+
export default runPipeline;
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scanMetadata from './stages/scan-metadata';
2+
import generateWebsiteInfo from './stages/generate-website-info';
3+
import generatePages from './stages/generate-pages';
4+
import buildWebsite from './stages/build-website';
5+
import runWebsite from './stages/run-website';
6+
7+
export default () => {
8+
const initialConfiguration = {};
9+
return scanMetadata(initialConfiguration, {})
10+
.then(result => generateWebsiteInfo(result, {}))
11+
.then(result => generatePages(result, {}))
12+
.then(result => buildWebsite(result, {}))
13+
.then(result => runWebsite(result, {}))
14+
.then(() => {
15+
console.log('Thanks for documenting with brisk-docs! 🎿');
16+
});
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import createStage from '../make-pipline-stage';
2+
3+
interface StageInput {}
4+
5+
// Boilerplate, uncomment when used
6+
// interface StageConfig {}
7+
8+
interface StageOutput {}
9+
10+
export default createStage(
11+
'build-website',
12+
async (input: StageInput): Promise<StageOutput> => {
13+
return input;
14+
},
15+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe('Build website stage', () => {
2+
it.skip('needs tests', () => {});
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import createStage from '../make-pipline-stage';
2+
3+
interface StageInput {}
4+
5+
// Boilerplate, uncomment when used
6+
// interface StageConfig {}
7+
8+
export interface StageOutput {}
9+
10+
export default createStage(
11+
'generate-pages',
12+
async (input: StageInput): Promise<StageOutput> => {
13+
return input;
14+
},
15+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe('Generate pages build stage', () => {
2+
it.skip('needs tests', () => {});
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import createStage from '../make-pipline-stage';
2+
3+
interface StageInput {}
4+
5+
// Boilerplate, uncomment when used
6+
// interface StageConfig {}
7+
8+
interface StageOutput {}
9+
10+
export default createStage(
11+
'generate-website-info',
12+
async (input: StageInput): Promise<StageOutput> => {
13+
return input;
14+
},
15+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe('Generate website info build stage', () => {
2+
it.skip('needs tests', () => {});
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { PerformanceObserver } from 'perf_hooks';
2+
import createStage from './make-pipline-stage';
3+
4+
describe('Pipeline stage generator', () => {
5+
it('creates a run property from the given function', async () => {
6+
const step = jest.fn();
7+
step.mockReturnValue(Promise.resolve('result'));
8+
9+
const runStage = createStage('test-stage', step);
10+
const stageInput = {};
11+
const stageConfig = {};
12+
const result = await runStage(stageInput, stageConfig);
13+
14+
expect(step).toHaveBeenCalledWith(stageInput, stageConfig);
15+
expect(result).toBe('result');
16+
});
17+
18+
it('sends a performance measure event to the performance timing API', () => {
19+
const getPerformanceMetric = new Promise((resolve, reject) => {
20+
const obs = new PerformanceObserver(items => {
21+
const entry = items
22+
.getEntries()
23+
.find(e => e.name === 'brisk-pipeline-stage-duration:test-stage');
24+
if (!entry) {
25+
reject(
26+
new Error('brisk-pipeline-stage-duration:test-stage entry missing'),
27+
);
28+
} else {
29+
resolve(entry.duration);
30+
}
31+
32+
obs.disconnect();
33+
});
34+
obs.observe({ entryTypes: ['measure'] });
35+
});
36+
37+
const runStage = createStage('test-stage', () => Promise.resolve());
38+
runStage({}, {});
39+
40+
return expect(getPerformanceMetric).resolves.toEqual(expect.any(Number));
41+
});
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { performance } from 'perf_hooks';
2+
3+
export type PipelineStage<StageInput, StageConfig, StageOutput> = (
4+
input: StageInput,
5+
configOptions: StageConfig,
6+
) => Promise<StageOutput>;
7+
8+
/**
9+
* Creates a stage for the website build pipeline with performance profiling
10+
* built in.
11+
*/
12+
export default <StageInput, StageConfig, StageOutput>(
13+
id: string,
14+
buildStep: (
15+
input: StageInput,
16+
configOptions: StageConfig,
17+
) => Promise<StageOutput>,
18+
): PipelineStage<StageInput, StageConfig, StageOutput> => {
19+
return async (
20+
input: StageInput,
21+
configOptions: StageConfig,
22+
): Promise<StageOutput> => {
23+
const perfBeginId = `brisk-pipeline-stage-begin:${id}`;
24+
const perfEndId = `brisk-pipeline-stage-end:${id}`;
25+
26+
performance.mark(perfBeginId);
27+
28+
const result = await buildStep(input, configOptions);
29+
30+
performance.mark(perfEndId);
31+
performance.measure(
32+
`brisk-pipeline-stage-duration:${id}`,
33+
perfBeginId,
34+
perfEndId,
35+
);
36+
37+
return result;
38+
};
39+
};

0 commit comments

Comments
 (0)