Skip to content

Commit

Permalink
Merge pull request backstage#461 from spotify/lighthouse-plugin
Browse files Browse the repository at this point in the history
Add plugin for lighthouse-audit-service
  • Loading branch information
Paul Marbach authored Apr 8, 2020
2 parents 05ddedb + f6d3c5c commit 27d9524
Show file tree
Hide file tree
Showing 46 changed files with 3,143 additions and 42 deletions.
3 changes: 2 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"dependencies": {
"@backstage/cli": "^0.1.1-alpha.3",
"@backstage/core": "^0.1.1-alpha.3",
"@backstage/theme": "^0.1.1-alpha.3",
"@backstage/plugin-home-page": "^0.1.1-alpha.3",
"@backstage/plugin-lighthouse": "^0.1.1-alpha.3",
"@backstage/plugin-welcome": "^0.1.1-alpha.3",
"@backstage/theme": "^0.1.1-alpha.3",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ import {
featureFlagsApiRef,
FeatureFlags,
} from '@backstage/core';
import {
lighthouseApiRef,
LighthouseRestApi,
} from '@backstage/plugin-lighthouse';

import { ErrorDisplayForwarder } from './components/ErrorDisplay/ErrorDisplay';

const builder = ApiRegistry.builder();

export const errorDialogForwarder = new ErrorDisplayForwarder();

builder.add(errorApiRef, errorDialogForwarder);

builder.add(featureFlagsApiRef, new FeatureFlags());

builder.add(lighthouseApiRef, new LighthouseRestApi('http://localhost:3003'));

export default builder.build() as ApiHolder;
4 changes: 2 additions & 2 deletions packages/app/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { default as HomePagePlugin } from '@backstage/plugin-home-page';
import { default as WelcomePlugin } from '@backstage/plugin-welcome';
export { HomePagePlugin, WelcomePlugin };
import { default as LighthousePlugin } from '@backstage/plugin-lighthouse';
export { HomePagePlugin, WelcomePlugin, LighthousePlugin };
4 changes: 3 additions & 1 deletion packages/cli/config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"noEmit": false,
"declarationMap": true,
"incremental": true,
"module": "es6"
"module": "es6",
"resolveJsonModule": true,
"esModuleInterop": true
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/plugin/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
}),
commonjs({
include: ['node_modules/**', '../../node_modules/**'],
exclude: ['**/*.stories.js'],
exclude: ['**/*.stories.*', '**/*.test.*'],
}),
postcss(),
imageFiles(),
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/templates/default-plugin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@backstage/cli/config/eslint.js')],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/prop-types */
/*
* Copyright 2020 Spotify AB
*
Expand Down
10 changes: 1 addition & 9 deletions packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
overrides: [
{
files: ['**/*.ts?(x)'],
rules: {
// TODO: add prop types and set to 1
'react/prop-types': 0,
},
},
],
extends: [require.resolve('@backstage/cli/config/eslint.js')],
rules: {
// TODO: add prop types to JS and remove
'react/prop-types': 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
"react-router": "^5.1.2"
},
"peerDependencies": {
"@backstage/theme": "^0.1.1-alpha.2"
"@backstage/theme": "^0.1.1-alpha.3"
}
}
1 change: 1 addition & 0 deletions packages/core/src/api/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
export { default as ApiProvider, useApi } from './ApiProvider';
export { default as ApiRegistry } from './ApiRegistry';
export { default as ApiTestRegistry } from './ApiTestRegistry';
export { default as ApiRef } from './ApiRef';
export * from './types';
export * from './definitions';
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export { AlphaLabel, BetaLabel } from './components/Lifecycle';
export { default as SupportButton } from './components/SupportButton';
export { default as SortableTable } from './components/SortableTable';
export { FeatureCalloutCircular } from './components/FeatureDiscovery/FeatureCalloutCircular';
export * from './components/Status';
20 changes: 18 additions & 2 deletions packages/core/src/layout/Content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import React, { FC } from 'react';
import classNames from 'classnames';
import { Theme, makeStyles } from '@material-ui/core';

const useStyles = makeStyles((theme: Theme) => ({
Expand All @@ -25,12 +26,27 @@ const useStyles = makeStyles((theme: Theme) => ({
paddingBottom: theme.spacing(3),
...theme.mixins.gutters({}),
},
stretch: {
display: 'flex',
flexDirection: 'column',
flexGrow: 1,
},
}));

const Content: FC<{}> = ({ children, ...props }) => {
const Content: FC<{ stretch?: boolean; className?: string }> = ({
children,
className,
stretch,
...props
}) => {
const classes = useStyles();
return (
<article {...props} className={classes.root}>
<article
{...props}
className={classNames(classes.root, className, {
[classes.stretch]: stretch,
})}
>
{children}
</article>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/layout/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useStyles = makeStyles(() => ({
"'pageHeader pageHeader pageHeader' 'pageSubheader pageSubheader pageSubheader' 'pageNav pageContent pageSidebar'",
gridTemplateRows: 'auto auto 1fr',
gridTemplateColumns: 'auto 1fr auto',
minHeight: '100%',
minHeight: '100vh',
},
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"react-router-dom": "^5.1.2"
},
"peerDependencies": {
"@backstage/theme": "^0.1.1-alpha.2",
"@backstage/theme": "^0.1.1-alpha.3",
"@material-ui/core": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
Expand Down
3 changes: 3 additions & 0 deletions plugins/home-page/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@backstage/cli/config/eslint.js')],
};
4 changes: 2 additions & 2 deletions plugins/home-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"react-dom": "^16.12.0"
},
"peerDependencies": {
"@backstage/core": "^0.1.1-alpha.2",
"@backstage/theme": "^0.1.1-alpha.2",
"@backstage/core": "^0.1.1-alpha.3",
"@backstage/theme": "^0.1.1-alpha.3",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
Expand Down
3 changes: 3 additions & 0 deletions plugins/lighthouse/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@backstage/cli/config/eslint.js')],
};
51 changes: 51 additions & 0 deletions plugins/lighthouse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# @backstage/plugin-lighthouse

A frontend for [lighthouse-audit-service](https://github.com/spotify/lighthouse-audit-service), this plugin allows you to trigger Lighthouse audits on websites and track them over time.

## Getting Started

### Use cases

Google's [Lighthouse](https://developers.google.com/web/tools/lighthouse) auditing tool for websites
is a great open-source resource forbenchmarking and improving the accessibility, performance, SEO, and best practices of your site.
At Spotify, we keep track of Lighthouse audit scores over time to look at trends and overall areas for investment.

This plugin allows you to generate on-demand Lighthouse audits for websites, and to track the trends for the
top-level categories of Lighthouse at a glance.

In the future, we hope to add support for scheduling audits (which we do internally), as well as allowing
custom runs of Lighthouse to be ingested (for auditing sites that require authentication or some session state).

### Installation

To get started, you will need a running instance of [lighthouse-audit-service](https://github.com/spotify/lighthouse-audit-service).
_It's likely you will need to enable CORS when running lighthouse-audit-service. Initialize the app
with the environment variable `LAS_CORS` set to `true`._

When you have an instance running that Backstage can hook into, make sure to export the plugin in
your app's [`plugins.ts`](https://github.com/spotify/backstage/blob/master/packages/app/src/plugins.ts)
to enable the plugin:

```js
import { default as LighthousePlugin } from '@backstage/plugin-lighthouse';
export LighthousePlugin;
```

Then, you need to use the `lighthouseApiRef` exported from the plugin to initialize the Rest API in
your [`apis.ts`](https://github.com/spotify/backstage/blob/master/packages/app/src/apis.ts).

```js
import { ApiHolder, ApiRegistry } from '@backstage/core';
import {
lighthouseApiRef,
LighthouseRestApi,
} from '@backstage/lighthouse-audits';

const builder = ApiRegistry.builder();

export const lighthouseApi =
new LighthouseRestApi(/* your service url here! */);
builder.add(lighthouseApiRef, lighthouseApi);

export default builder.build() as ApiHolder;
```
50 changes: 50 additions & 0 deletions plugins/lighthouse/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@backstage/plugin-lighthouse",
"version": "0.1.1-alpha.3",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build:watch": "backstage-cli plugin:build --watch",
"build": "backstage-cli plugin:build",
"lint": "backstage-cli lint",
"test": "backstage-cli test"
},
"dependencies": {
"react-markdown": "^4.3.1",
"react-sparklines": "^1.7.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.3",
"@backstage/core": "^0.1.1-alpha.3",
"@backstage/test-utils": "^0.1.1-alpha.3",
"@backstage/theme": "^0.1.1-alpha.3",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react-sparklines": "^1.7.0",
"@types/testing-library__jest-dom": "5.0.2",
"jest-fetch-mock": "^3.0.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-use": "^13.24.0"
},
"peerDependencies": {
"@backstage/core": "^0.1.1-alpha.3",
"@backstage/theme": "^0.1.1-alpha.3",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-use": "^13.24.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "80d92fff-52ec-4ef5-848f-9cec8b383e41",
"url": "https://anchor.fm",
"timeCreated": "2020-03-31T15:34:02.199-04:00",
"status": "RUNNING"
}
Loading

0 comments on commit 27d9524

Please sign in to comment.