diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 7d30814c07..d7a862806a 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -45,6 +45,9 @@ jobs: run: git diff --quiet origin/master HEAD -- yarn.lock continue-on-error: true + - name: verify doc links + run: node docs/verify-links.js + - name: yarn install run: yarn install --frozen-lockfile diff --git a/docs/README.md b/docs/README.md index 2bda6a5aaa..cdbfbc5578 100644 --- a/docs/README.md +++ b/docs/README.md @@ -43,11 +43,7 @@ better yet, a pull request. - [Overview](features/techdocs/README.md) - [Getting Started](features/techdocs/getting-started.md) - [Concepts](features/techdocs/concepts.md) - - [Reading Documentation](features/techdocs/reading-documentation.md) - - [Writing Documentation](features/techdocs/writing-documentation.md) - - [Publishing Documentation](features/techdocs/publishing-documentation.md) - - [Contributing](features/techdocs/contributing.md) - - [Debugging](features/techdocs/debugging.md) + - [Creating and Publishing Documentation](features/techdocs/creating-and-publishing.md) - [FAQ](features/techdocs/FAQ.md) - Plugins - [Overview](plugins/index.md) diff --git a/docs/verify-links.js b/docs/verify-links.js new file mode 100755 index 0000000000..8c865309f9 --- /dev/null +++ b/docs/verify-links.js @@ -0,0 +1,89 @@ +#!/usr/bin/env node +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const { resolve: resolvePath, dirname } = require('path'); +const fs = require('fs-extra'); +const fetch = require('node-fetch'); +const recursive = require('recursive-readdir'); + +const projectRoot = resolvePath(__dirname, '..'); + +async function verifyUrl(basePath, url) { + url = url.replace(/#.*$/, ''); + url = url.replace( + /https:\/\/github.com\/spotify\/backstage\/(tree|blob)\/master/, + '', + ); + if (!url) { + return; + } + + // Only verify existence of local files for now, so skip anything with a schema + if (!url.match(/[a-z]+:/)) { + const path = url.startsWith('/') + ? resolvePath(projectRoot, `.${url}`) + : resolvePath(dirname(resolvePath(projectRoot, basePath)), url); + const exists = await fs.pathExists(path); + if (!exists) { + return { url, basePath }; + } + } + + return; +} + +async function verifyFile(filePath) { + const content = await fs.readFile(filePath, 'utf8'); + const mdLinks = content.match(/\[.+?\]\(.+?\)/g) || []; + const badUrls = []; + + for (const mdLink of mdLinks) { + const url = mdLink.match(/\[.+\]\((.+)\)/)[1].trim(); + const badUrl = await verifyUrl(filePath, url); + if (badUrl) { + badUrls.push(badUrl); + } + } + + return badUrls; +} + +async function main() { + process.chdir(projectRoot); + + const files = await recursive('.', ['node_modules', 'dist', 'bin']); + const mdFiles = files.filter(f => f.endsWith('.md')); + const badUrls = []; + + for (const mdFile of mdFiles) { + const badFileUrls = await verifyFile(mdFile); + badUrls.push(...badFileUrls); + } + + if (badUrls.length) { + console.log(`Found ${badUrls.length} bad links within repo`); + for (const { url, basePath } of badUrls) { + console.error(`Unable to reach ${url}, linked from ${basePath}`); + } + process.exit(1); + } +} + +main().catch(error => { + console.error(error.stack); + process.exit(1); +}); diff --git a/packages/cli/templates/default-plugin/README.md.hbs b/packages/cli/templates/default-plugin/README.md.hbs index d6f2d65134..6d68ca8250 100644 --- a/packages/cli/templates/default-plugin/README.md.hbs +++ b/packages/cli/templates/default-plugin/README.md.hbs @@ -10,4 +10,4 @@ Your plugin has been added to the example app in this repository, meaning you'll You can also serve the plugin in isolation by running `yarn start` in the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. -It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. +It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory. diff --git a/plugins/README.md b/plugins/README.md index 50f4395bd9..a7fe648bf7 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -2,7 +2,7 @@ Backstage is a single-page application composed of a set of plugins. -Our goal for the plugin ecosystem is that the definition of a plugin is flexible enough to allow you to expose pretty much any kind of infrastructure or software development tool as a plugin in Backstage. By following strong [design guidelines](https://github.com/spotify/backstage/blob/master/docs/design.md) we ensure the the overall user experience stays consistent between plugins. +Our goal for the plugin ecosystem is that the definition of a plugin is flexible enough to allow you to expose pretty much any kind of infrastructure or software development tool as a plugin in Backstage. By following strong [design guidelines](https://github.com/spotify/backstage/blob/master/docs/dls/design.md) we ensure the the overall user experience stays consistent between plugins. ![plugin](../docs/plugins/my-plugin_screenshot.png) diff --git a/plugins/gitops-profiles/README.md b/plugins/gitops-profiles/README.md index d083c97b84..472ea3cc4e 100644 --- a/plugins/gitops-profiles/README.md +++ b/plugins/gitops-profiles/README.md @@ -11,7 +11,7 @@ Your plugin has been added to the example app in this repository, meaning you'll You can also serve the plugin in isolation by running `yarn start` in the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. -It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. +It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory. ## Use GitOps-API backend with Backstage diff --git a/plugins/graphql/README.md b/plugins/graphql/README.md index 3f85ec766e..ae58396880 100644 --- a/plugins/graphql/README.md +++ b/plugins/graphql/README.md @@ -1,13 +1,28 @@ -# graphql +# GraphQL Backend -Welcome to the graphql backend plugin! +## Getting Started -_This plugin was created through the Backstage CLI_ +This backend plugin can be started in a standalone mode from directly in this package +with `yarn start`. However, it will have limited functionality and that process is +most convenient when developing the plugin itself. -## Getting started +To run it within the backend do: -Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/graphql](http://localhost:3000/graphql). +1. Register the router in `packages/backend/src/index.ts`: -You can also serve the plugin in isolation by running `yarn start` in the plugin directory. -This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. -It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. +```ts +const graphqlEnv = useHotMemoize(module, () => createEnv('graphql')); + +const service = createServiceBuilder(module) + .loadConfig(configReader) + /** several different routers */ + .addRouter('/graphql', await graphql(graphqlEnv)); +``` + +2. Start the backend + +```bash +yarn workspace example-backend start +``` + +This will launch the full example backend. diff --git a/plugins/sentry/README.md b/plugins/sentry/README.md index cce2228094..73cca29d34 100644 --- a/plugins/sentry/README.md +++ b/plugins/sentry/README.md @@ -10,7 +10,7 @@ Your plugin has been added to the example app in this repository, meaning you'll You can also serve the plugin in isolation by running `yarn start` in the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. -It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. +It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory. Needs SENTRY_TOKEN set in the environment for the backend to startup diff --git a/plugins/techdocs/README.md b/plugins/techdocs/README.md index b763679a1c..4a92c814a1 100644 --- a/plugins/techdocs/README.md +++ b/plugins/techdocs/README.md @@ -4,17 +4,13 @@ Welcome to the TechDocs plugin - Spotify's docs-like-code approach built directl **WIP: This plugin is a work in progress. It is not ready for use yet. Follow our progress on [the Backstage Discord](https://discord.gg/MUpMjP2) under #docs-like-code or on [our GitHub Milestone](https://github.com/spotify/backstage/milestone/15).** -## Sections - -- [MkDocs](./mkdocs/README.md) - ## Getting started Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/docs](http://localhost:3000/docs). You can also serve the plugin in isolation by running `yarn start` in the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. -It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. +It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory. ## Configuration diff --git a/plugins/techdocs/src/reader/README.md b/plugins/techdocs/src/reader/README.md new file mode 100644 index 0000000000..464090415c --- /dev/null +++ b/plugins/techdocs/src/reader/README.md @@ -0,0 +1 @@ +# TODO diff --git a/plugins/techdocs/src/reader/transformers/README.md b/plugins/techdocs/src/reader/transformers/README.md new file mode 100644 index 0000000000..464090415c --- /dev/null +++ b/plugins/techdocs/src/reader/transformers/README.md @@ -0,0 +1 @@ +# TODO