diff --git a/packages/techdocs-cli/.eslintrc.js b/packages/techdocs-cli/.eslintrc.js deleted file mode 100644 index 503c048748..0000000000 --- a/packages/techdocs-cli/.eslintrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - extends: [require.resolve('@backstage/cli/config/eslint.backend')], - rules: { - 'no-console': 0, - }, -}; diff --git a/packages/techdocs-cli/CHANGELOG.md b/packages/techdocs-cli/CHANGELOG.md deleted file mode 100644 index 9add3bb173..0000000000 --- a/packages/techdocs-cli/CHANGELOG.md +++ /dev/null @@ -1,17 +0,0 @@ -# @techdocs/cli - -## 0.1.2 - -### Patch Changes - -- Updated dependencies [28edd7d29] -- Updated dependencies [3472c8be7] -- Updated dependencies [1d0aec70f] -- Updated dependencies [a3840bed2] -- Updated dependencies [72f6cda35] -- Updated dependencies [8c2b76e45] -- Updated dependencies [cba4e4d97] -- Updated dependencies [8afce088a] -- Updated dependencies [9a3b3dbf1] -- Updated dependencies [7bbeb049f] - - @backstage/cli@0.2.0 diff --git a/packages/techdocs-cli/README.md b/packages/techdocs-cli/README.md deleted file mode 100644 index 031f26fd93..0000000000 --- a/packages/techdocs-cli/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# TechDocs CLI - -Check out the [TechDocs README](https://github.com/backstage/backstage/blob/master/plugins/techdocs/README.md) to learn more. - -**WIP: This cli 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/backstage/backstage/milestone/15).** - -## Prerequisities - -Run the following command from the project root: - -```bash -yarn install -``` - -## Run TechDocs CLI - -You'll need Docker installed and running to use this. - -```bash -cd packages/techdocs-container/mock-docs - -# To get a view of your docs in Backstage, use: -npx techdocs-cli serve - -# To view the raw mkdocs site (without Backstage), use: -npx techdocs-cli serve:mkdocs -``` - -If you run `npx techdocs-cli serve` you should have a `localhost:3000` serving TechDocs in Backstage, as well as `localhost:8000` serving Mkdocs (which won't open up and be exposed to the user). - -If running `npx techdocs-cli serve:mkdocs` you will have `localhost:8000` exposed, serving Mkdocs. - -Happy hacking! - -## Deploying a new version - -Deploying the Node packages to NPM happens automatically on merge to `master` through GitHub Actions. The deployment happens through Lerna which determines which packages throughout the Backstage project have changed. In our case, the package is called `techdocs-cli` in the repository but `@techdocs/cli` in the NPM registry. - -> Note: Once a package is published under a version, any subsequent changes will not override that version. You will need to bump up the version across the entire Backstage repository, which can be done through Lerna (see the command below). - -In order to bump up all packages, go to the root of the Backstage repository. To see the current version see the `lerna.json` under the `version` key. To then update all the versions (locally on your machine), run the following: - -```bash -git checkout -b bump-up-version -yarn lerna version --no-push --allow-branch --yes -``` - -Upon being merged to master, Lerna will then automatically publish these packages as configured by the Backstage core team. diff --git a/packages/techdocs-cli/bin/build.sh b/packages/techdocs-cli/bin/build.sh deleted file mode 100755 index 0a3dfeb96d..0000000000 --- a/packages/techdocs-cli/bin/build.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# 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. - -set -e - -TECHDOCS_PREVIEW_SOURCE=../../plugins/techdocs/dist -TECHDOCS_PREVIEW_DEST=../../packages/techdocs-cli/dist/techdocs-preview-bundle - -# Build the CLI -yarn run backstage-cli -- build --outputs cjs - -# Create export of the TechDocs plugin -APP_CONFIG_techdocs_storageUrl='"http://localhost:3000/api"' yarn workspace @backstage/plugin-techdocs export - -# Copy over export to techdocs-cli dist/ folder -cp -r $TECHDOCS_PREVIEW_SOURCE $TECHDOCS_PREVIEW_DEST - -# Write to console -echo "[techdocs-cli]: Built the dist/ folder" -echo "[techdocs-cli]: Imported @backstage/plugin-techdocs dist/ folder into techdocs-preview-bundle/" diff --git a/packages/techdocs-cli/bin/techdocs-cli b/packages/techdocs-cli/bin/techdocs-cli deleted file mode 100755 index 9818edf417..0000000000 --- a/packages/techdocs-cli/bin/techdocs-cli +++ /dev/null @@ -1,36 +0,0 @@ -#!/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. - */ - -/* eslint-disable no-restricted-syntax */ -const path = require('path'); - -// Figure out whether we're running inside the backstage repo or as an installed dependency -const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src')); - -if (!isLocal) { - require('..'); -} else { - require('ts-node').register({ - transpileOnly: true, - project: path.resolve(__dirname, '../../../tsconfig.json'), - compilerOptions: { - module: 'CommonJS', - }, - }); - - require('../src'); -} diff --git a/packages/techdocs-cli/package.json b/packages/techdocs-cli/package.json deleted file mode 100644 index ee3785b0cc..0000000000 --- a/packages/techdocs-cli/package.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "@techdocs/cli", - "description": "CLI for running TechDocs locally.", - "version": "0.1.2", - "private": false, - "publishConfig": { - "access": "public" - }, - "repository": { - "type": "git", - "url": "https://github.com/backstage/backstage", - "directory": "packages/techdocs-cli" - }, - "keywords": [ - "backstage", - "techdocs" - ], - "license": "Apache-2.0", - "main": "dist/index.cjs.js", - "scripts": { - "build": "./bin/build.sh", - "lint": "backstage-cli lint", - "test": "backstage-cli test --passWithNoTests", - "clean": "backstage-cli clean", - "start": "nodemon --" - }, - "bin": { - "techdocs-cli": "bin/techdocs-cli" - }, - "devDependencies": { - "@types/serve-handler": "^6.1.0" - }, - "files": [ - "bin", - "dist" - ], - "nodemonConfig": { - "watch": "./src", - "exec": "bin/build && bin/techdocs-cli", - "ext": "ts" - }, - "dependencies": { - "@backstage/cli": "^0.2.0", - "commander": "^6.1.0", - "fs-extra": "^9.0.1", - "http-proxy": "^1.18.1", - "react-dev-utils": "^10.2.1", - "serve-handler": "^6.1.3" - } -} diff --git a/packages/techdocs-cli/src/index.ts b/packages/techdocs-cli/src/index.ts deleted file mode 100644 index 824bdb84fc..0000000000 --- a/packages/techdocs-cli/src/index.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. - */ -import { spawn, ChildProcess } from 'child_process'; -import program from 'commander'; -import { version } from '../package.json'; -import path from 'path'; -import HTTPServer from './lib/httpServer'; -import openBrowser from 'react-dev-utils/openBrowser'; - -const run = (name: string, args: string[] = []): ChildProcess => { - const [stdin, stdout, stderr] = [ - 'inherit' as const, - 'pipe' as const, - 'inherit' as const, - ]; - - const childProcess = spawn(name, args, { - stdio: [stdin, stdout, stderr], - shell: true, - env: { - ...process.env, - FORCE_COLOR: 'true', - }, - }); - - childProcess.once('error', error => { - console.error(error); - childProcess.kill(); - }); - - childProcess.once('exit', () => { - process.exit(0); - }); - - return childProcess; -}; - -const runMkdocsServer = (options?: { - devAddr: string; -}): Promise => { - const devAddr = options?.devAddr ?? '0.0.0.0:8000'; - - return new Promise(resolve => { - const childProcess = run('docker', [ - 'run', - '-it', - '-w', - '/content', - '-v', - `${process.cwd()}:/content`, - '-p', - '8000:8000', - 'spotify/techdocs', - 'serve', - '-a', - devAddr, - ]); - - childProcess.stdout?.on('data', rawData => { - const data = rawData.toString().split('\n')[0]; - console.log('[mkdocs] ', data); - - if (data.includes(`Serving on http://${devAddr}`)) { - resolve(childProcess); - } - }); - }); -}; - -const main = (argv: string[]) => { - program.name('techdocs-cli').version(version); - - program - .command('serve:mkdocs') - .description('Serve a documentation project locally') - .action(() => { - runMkdocsServer().then(() => { - openBrowser('http://localhost:8000'); - }); - }); - - program - .command('serve') - .description('Serve a documentation project locally') - .action(() => { - // Mkdocs server - const mkdocsServer = runMkdocsServer(); - - // Local Backstage Preview - const techdocsPreviewBundlePath = path.join( - /* eslint-disable-next-line no-restricted-syntax */ - __dirname, - '..', - 'dist', - 'techdocs-preview-bundle', - ); - - const httpServer = new HTTPServer(techdocsPreviewBundlePath, 3000) - .serve() - .catch(err => { - console.error(err); - mkdocsServer.then(childProcess => childProcess.kill()); - }); - - Promise.all([mkdocsServer, httpServer]).then(() => { - openBrowser('http://localhost:3000/docs/local-dev/'); - }); - }); - - program.parse(argv); -}; - -main(process.argv); diff --git a/packages/techdocs-cli/src/lib/httpServer.ts b/packages/techdocs-cli/src/lib/httpServer.ts deleted file mode 100644 index 6e6578840e..0000000000 --- a/packages/techdocs-cli/src/lib/httpServer.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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. - */ - -import serveHandler from 'serve-handler'; -import http from 'http'; -import httpProxy from 'http-proxy'; - -export default class HTTPServer { - proxyEndpoint: string; - - constructor(public dir: string, public port: number) { - this.proxyEndpoint = '/api/'; - } - - private createProxy() { - const proxy = httpProxy.createProxyServer({ - target: 'http://localhost:8000', - }); - - return (request: http.IncomingMessage): [httpProxy, string] => { - const [, ...pathChunks] = - request.url?.substring(this.proxyEndpoint.length).split('/') ?? []; - const forwardPath = pathChunks.join('/'); - - return [proxy, forwardPath]; - }; - } - - public async serve(): Promise { - return new Promise((resolve, reject) => { - const proxyHandler = this.createProxy(); - - const server = http.createServer( - (request: http.IncomingMessage, response: http.ServerResponse) => { - if (request.url?.startsWith(this.proxyEndpoint)) { - const [proxy, forwardPath] = proxyHandler(request); - - proxy.on('error', (error: Error) => { - reject(error); - }); - - request.url = forwardPath; - return proxy.web(request, response); - } - - return serveHandler(request, response, { - public: this.dir, - trailingSlash: true, - rewrites: [{ source: '**', destination: 'index.html' }], - }); - }, - ); - - server.listen(this.port, () => { - console.log( - '[techdocs-preview-bundle] Running local version of Backstage at http://localhost:3000', - ); - resolve(server); - }); - - server.on('error', (error: Error) => { - reject(error); - }); - }); - } -}