From ff348df9fefb4f150d7225fa561e8de3d62eae39 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Wed, 25 Nov 2020 19:21:21 +0100 Subject: [PATCH] techdocs-common: Initialize package and move common code from techdocs-backend --- packages/backend/package.json | 1 + packages/backend/src/plugins/techdocs.ts | 4 +- packages/techdocs-common/.eslintrc.js | 3 + packages/techdocs-common/README.md | 7 +++ packages/techdocs-common/package.json | 55 +++++++++++++++++++ .../techdocs-common}/src/default-branch.ts | 0 .../techdocs-common}/src/git-auth.ts | 0 .../techdocs-common}/src/helpers.test.ts | 0 .../techdocs-common}/src/helpers.ts | 2 +- .../techdocs-common/src}/index.ts | 3 + .../stages/generate/__fixtures__/mkdocs.yml | 0 .../__fixtures__/mkdocs_with_repo_url.yml | 0 .../src}/stages/generate/generators.test.ts | 2 +- .../src}/stages/generate/generators.ts | 0 .../src}/stages/generate/helpers.test.ts | 2 +- .../src}/stages/generate/helpers.ts | 2 +- .../src}/stages/generate/index.ts | 0 .../src}/stages/generate/techdocs.ts | 0 .../src}/stages/generate/types.ts | 2 +- .../techdocs-common/src}/stages/index.ts | 0 .../src}/stages/prepare/commonGit.test.ts | 6 +- .../src}/stages/prepare/commonGit.ts | 5 +- .../src}/stages/prepare/dir.test.ts | 6 +- .../src}/stages/prepare/dir.ts | 5 +- .../src}/stages/prepare/index.ts | 0 .../src}/stages/prepare/preparers.ts | 2 +- .../src}/stages/prepare/types.ts | 0 .../src}/stages/prepare/url.ts | 3 +- .../src}/stages/publish/index.ts | 0 .../src}/stages/publish/local.test.ts | 4 +- .../src}/stages/publish/local.ts | 0 .../src}/stages/publish/publish.ts | 0 .../test-component-folder-AP2Wti/mock-file | 0 .../src}/stages/publish/types.ts | 0 plugins/techdocs-backend/package.json | 7 +-- plugins/techdocs-backend/src/index.ts | 1 - .../techdocs-backend/src/service/helpers.ts | 5 +- .../techdocs-backend/src/service/router.ts | 8 ++- .../src/service/standaloneServer.ts | 2 +- plugins/techdocs/package.json | 1 + 40 files changed, 100 insertions(+), 38 deletions(-) create mode 100644 packages/techdocs-common/.eslintrc.js create mode 100644 packages/techdocs-common/README.md create mode 100644 packages/techdocs-common/package.json rename {plugins/techdocs-backend => packages/techdocs-common}/src/default-branch.ts (100%) rename {plugins/techdocs-backend => packages/techdocs-common}/src/git-auth.ts (100%) rename {plugins/techdocs-backend => packages/techdocs-common}/src/helpers.test.ts (100%) rename {plugins/techdocs-backend => packages/techdocs-common}/src/helpers.ts (98%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/index.ts (87%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/__fixtures__/mkdocs.yml (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/__fixtures__/mkdocs_with_repo_url.yml (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/generators.test.ts (96%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/generators.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/helpers.test.ts (99%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/helpers.ts (99%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/index.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/techdocs.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/generate/types.ts (97%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/index.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/commonGit.test.ts (95%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/commonGit.ts (94%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/dir.test.ts (95%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/dir.ts (96%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/index.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/preparers.ts (95%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/types.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/prepare/url.ts (95%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/publish/index.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/publish/local.test.ts (90%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/publish/local.ts (100%) rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/publish/publish.ts (100%) create mode 100644 packages/techdocs-common/src/stages/publish/test-component-folder-AP2Wti/mock-file rename {plugins/techdocs-backend/src/techdocs => packages/techdocs-common/src}/stages/publish/types.ts (100%) diff --git a/packages/backend/package.json b/packages/backend/package.json index beb2567bd7..158ff043b2 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -31,6 +31,7 @@ "@backstage/plugin-scaffolder-backend": "^0.3.2", "@backstage/plugin-sentry-backend": "^0.1.3", "@backstage/plugin-techdocs-backend": "^0.3.0", + "@backstage/techdocs-common": "^0.1.1", "@gitbeaker/node": "^25.2.0", "@octokit/rest": "^18.0.0", "azure-devops-node-api": "^10.1.1", diff --git a/packages/backend/src/plugins/techdocs.ts b/packages/backend/src/plugins/techdocs.ts index 3669911c0c..25d17801ea 100644 --- a/packages/backend/src/plugins/techdocs.ts +++ b/packages/backend/src/plugins/techdocs.ts @@ -14,8 +14,8 @@ * limitations under the License. */ +import { createRouter } from '@backstage/plugin-techdocs-backend'; import { - createRouter, DirectoryPreparer, Preparers, Generators, @@ -23,7 +23,7 @@ import { CommonGitPreparer, UrlPreparer, Publisher, -} from '@backstage/plugin-techdocs-backend'; +} from '@backstage/techdocs-common'; import { PluginEnvironment } from '../types'; import Docker from 'dockerode'; diff --git a/packages/techdocs-common/.eslintrc.js b/packages/techdocs-common/.eslintrc.js new file mode 100644 index 0000000000..16a033dbc6 --- /dev/null +++ b/packages/techdocs-common/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: [require.resolve('@backstage/cli/config/eslint.backend')], +}; diff --git a/packages/techdocs-common/README.md b/packages/techdocs-common/README.md new file mode 100644 index 0000000000..acf267bbfb --- /dev/null +++ b/packages/techdocs-common/README.md @@ -0,0 +1,7 @@ +# @backstage/techdocs-common + +Common functionalities for TechDocs, to be shared between techdocs plugins and techdocs-cli + +## Usage + +TODO: List supported APIs diff --git a/packages/techdocs-common/package.json b/packages/techdocs-common/package.json new file mode 100644 index 0000000000..6edb1fc589 --- /dev/null +++ b/packages/techdocs-common/package.json @@ -0,0 +1,55 @@ +{ + "name": "@backstage/techdocs-common", + "description": "Common functionalities for TechDocs, to be shared between techdocs plugins and techdocs-cli", + "version": "0.1.1", + "main": "src/index.ts", + "types": "src/index.ts", + "private": false, + "publishConfig": { + "access": "public", + "main": "dist/index.cjs.js", + "types": "dist/index.d.ts" + }, + "homepage": "https://backstage.io", + "repository": { + "type": "git", + "url": "https://github.com/backstage/backstage", + "directory": "packages/techdocs-common" + }, + "keywords": [ + "techdocs", + "backstage" + ], + "license": "Apache-2.0", + "files": [ + "dist" + ], + "scripts": { + "build": "backstage-cli build --outputs cjs,types", + "lint": "backstage-cli lint", + "test": "backstage-cli test", + "prepack": "backstage-cli prepack", + "postpack": "backstage-cli postpack", + "clean": "backstage-cli clean" + }, + "bugs": { + "url": "https://github.com/backstage/backstage/issues" + }, + "dependencies": { + "@backstage/backend-common": "^0.3.2", + "@backstage/catalog-model": "^0.3.1", + "@backstage/config": "^0.1.1", + "cross-fetch": "^3.0.6", + "dockerode": "^3.2.1", + "fs-extra": "^9.0.1", + "git-url-parse": "^11.4.0", + "js-yaml": "^3.14.0", + "mock-fs": "^4.13.0", + "nodegit": "^0.27.0", + "@types/dockerode": "^2.5.34", + "winston": "^3.2.1" + }, + "devDependencies": { + "@backstage/cli": "^0.3.1" + } +} diff --git a/plugins/techdocs-backend/src/default-branch.ts b/packages/techdocs-common/src/default-branch.ts similarity index 100% rename from plugins/techdocs-backend/src/default-branch.ts rename to packages/techdocs-common/src/default-branch.ts diff --git a/plugins/techdocs-backend/src/git-auth.ts b/packages/techdocs-common/src/git-auth.ts similarity index 100% rename from plugins/techdocs-backend/src/git-auth.ts rename to packages/techdocs-common/src/git-auth.ts diff --git a/plugins/techdocs-backend/src/helpers.test.ts b/packages/techdocs-common/src/helpers.test.ts similarity index 100% rename from plugins/techdocs-backend/src/helpers.test.ts rename to packages/techdocs-common/src/helpers.test.ts diff --git a/plugins/techdocs-backend/src/helpers.ts b/packages/techdocs-common/src/helpers.ts similarity index 98% rename from plugins/techdocs-backend/src/helpers.ts rename to packages/techdocs-common/src/helpers.ts index fcf5a4f194..e08d58d58e 100644 --- a/plugins/techdocs-backend/src/helpers.ts +++ b/packages/techdocs-common/src/helpers.ts @@ -23,7 +23,7 @@ import { getDefaultBranch } from './default-branch'; import { getGitRepoType, getTokenForGitRepo } from './git-auth'; import { Entity } from '@backstage/catalog-model'; import { InputError, UrlReader } from '@backstage/backend-common'; -import { RemoteProtocol } from './techdocs/stages/prepare/types'; +import { RemoteProtocol } from './stages/prepare/types'; import { Logger } from 'winston'; // Enables core.longpaths on windows to prevent crashing when checking out repos with long foldernames and/or deep nesting diff --git a/plugins/techdocs-backend/src/techdocs/index.ts b/packages/techdocs-common/src/index.ts similarity index 87% rename from plugins/techdocs-backend/src/techdocs/index.ts rename to packages/techdocs-common/src/index.ts index 7113525bb8..a6e1831049 100644 --- a/plugins/techdocs-backend/src/techdocs/index.ts +++ b/packages/techdocs-common/src/index.ts @@ -14,3 +14,6 @@ * limitations under the License. */ export * from './stages'; +export * from './helpers'; +export * from './default-branch'; +export * from './git-auth'; diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/__fixtures__/mkdocs.yml b/packages/techdocs-common/src/stages/generate/__fixtures__/mkdocs.yml similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/generate/__fixtures__/mkdocs.yml rename to packages/techdocs-common/src/stages/generate/__fixtures__/mkdocs.yml diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/__fixtures__/mkdocs_with_repo_url.yml b/packages/techdocs-common/src/stages/generate/__fixtures__/mkdocs_with_repo_url.yml similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/generate/__fixtures__/mkdocs_with_repo_url.yml rename to packages/techdocs-common/src/stages/generate/__fixtures__/mkdocs_with_repo_url.yml diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/generators.test.ts b/packages/techdocs-common/src/stages/generate/generators.test.ts similarity index 96% rename from plugins/techdocs-backend/src/techdocs/stages/generate/generators.test.ts rename to packages/techdocs-common/src/stages/generate/generators.test.ts index a9303c3794..7f4a964ec7 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/generate/generators.test.ts +++ b/packages/techdocs-common/src/stages/generate/generators.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Generators, TechdocsGenerator } from './'; +import { Generators, TechdocsGenerator } from '.'; import { getVoidLogger } from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/generators.ts b/packages/techdocs-common/src/stages/generate/generators.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/generate/generators.ts rename to packages/techdocs-common/src/stages/generate/generators.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/helpers.test.ts b/packages/techdocs-common/src/stages/generate/helpers.test.ts similarity index 99% rename from plugins/techdocs-backend/src/techdocs/stages/generate/helpers.test.ts rename to packages/techdocs-common/src/stages/generate/helpers.test.ts index 54ef0b1e83..83ccbbffab 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/generate/helpers.test.ts +++ b/packages/techdocs-common/src/stages/generate/helpers.test.ts @@ -28,7 +28,7 @@ import { patchMkdocsYmlPreBuild, } from './helpers'; import { RemoteProtocol } from '../prepare/types'; -import { ParsedLocationAnnotation } from '../../../helpers'; +import { ParsedLocationAnnotation } from '../../helpers'; const mockEntity = { apiVersion: 'version', diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/helpers.ts b/packages/techdocs-common/src/stages/generate/helpers.ts similarity index 99% rename from plugins/techdocs-backend/src/techdocs/stages/generate/helpers.ts rename to packages/techdocs-common/src/stages/generate/helpers.ts index 0f60712f5e..13344b8542 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/generate/helpers.ts +++ b/packages/techdocs-common/src/stages/generate/helpers.ts @@ -22,7 +22,7 @@ import yaml from 'js-yaml'; import { Logger } from 'winston'; import { Entity } from '@backstage/catalog-model'; import { SupportedGeneratorKey } from './types'; -import { ParsedLocationAnnotation } from '../../../helpers'; +import { ParsedLocationAnnotation } from '../../helpers'; import { RemoteProtocol } from '../prepare/types'; // TODO: Implement proper support for more generators. diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/index.ts b/packages/techdocs-common/src/stages/generate/index.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/generate/index.ts rename to packages/techdocs-common/src/stages/generate/index.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/techdocs.ts b/packages/techdocs-common/src/stages/generate/techdocs.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/generate/techdocs.ts rename to packages/techdocs-common/src/stages/generate/techdocs.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/generate/types.ts b/packages/techdocs-common/src/stages/generate/types.ts similarity index 97% rename from plugins/techdocs-backend/src/techdocs/stages/generate/types.ts rename to packages/techdocs-common/src/stages/generate/types.ts index 6d9ce5afca..65e411c3aa 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/generate/types.ts +++ b/packages/techdocs-common/src/stages/generate/types.ts @@ -16,7 +16,7 @@ import { Writable } from 'stream'; import Docker from 'dockerode'; import { Entity } from '@backstage/catalog-model'; -import { ParsedLocationAnnotation } from '../../../helpers'; +import { ParsedLocationAnnotation } from '../../helpers'; /** * The returned directory from the generator which is ready diff --git a/plugins/techdocs-backend/src/techdocs/stages/index.ts b/packages/techdocs-common/src/stages/index.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/index.ts rename to packages/techdocs-common/src/stages/index.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/commonGit.test.ts b/packages/techdocs-common/src/stages/prepare/commonGit.test.ts similarity index 95% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/commonGit.test.ts rename to packages/techdocs-common/src/stages/prepare/commonGit.test.ts index 843df476e9..a4240514b5 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/prepare/commonGit.test.ts +++ b/packages/techdocs-common/src/stages/prepare/commonGit.test.ts @@ -16,7 +16,7 @@ import { getVoidLogger } from '@backstage/backend-common'; import { CommonGitPreparer } from './commonGit'; -import { checkoutGitRepository } from '../../../helpers'; +import { checkoutGitRepository } from '../../helpers'; function normalizePath(path: string) { return path @@ -25,8 +25,8 @@ function normalizePath(path: string) { .join('/'); } -jest.mock('../../../helpers', () => ({ - ...jest.requireActual<{}>('../../../helpers'), +jest.mock('../../helpers', () => ({ + ...jest.requireActual<{}>('../../helpers'), checkoutGitRepository: jest.fn(() => '/tmp/backstage-repo/org/name/branch'), })); diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/commonGit.ts b/packages/techdocs-common/src/stages/prepare/commonGit.ts similarity index 94% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/commonGit.ts rename to packages/techdocs-common/src/stages/prepare/commonGit.ts index d9ba96a031..d79373fba3 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/prepare/commonGit.ts +++ b/packages/techdocs-common/src/stages/prepare/commonGit.ts @@ -17,10 +17,7 @@ import path from 'path'; import { Entity } from '@backstage/catalog-model'; import { PreparerBase } from './types'; import parseGitUrl from 'git-url-parse'; -import { - parseReferenceAnnotation, - checkoutGitRepository, -} from '../../../helpers'; +import { parseReferenceAnnotation, checkoutGitRepository } from '../../helpers'; import { Logger } from 'winston'; diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/dir.test.ts b/packages/techdocs-common/src/stages/prepare/dir.test.ts similarity index 95% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/dir.test.ts rename to packages/techdocs-common/src/stages/prepare/dir.test.ts index dc2b1d7d48..5b51f1f46d 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/prepare/dir.test.ts +++ b/packages/techdocs-common/src/stages/prepare/dir.test.ts @@ -15,7 +15,7 @@ */ import { DirectoryPreparer } from './dir'; import { getVoidLogger } from '@backstage/backend-common'; -import { checkoutGitRepository } from '../../../helpers'; +import { checkoutGitRepository } from '../../helpers'; function normalizePath(path: string) { return path @@ -24,8 +24,8 @@ function normalizePath(path: string) { .join('/'); } -jest.mock('../../../helpers', () => ({ - ...jest.requireActual<{}>('../../../helpers'), +jest.mock('../../helpers', () => ({ + ...jest.requireActual<{}>('../../helpers'), checkoutGitRepository: jest.fn(() => '/tmp/backstage-repo/org/name/branch/'), })); diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/dir.ts b/packages/techdocs-common/src/stages/prepare/dir.ts similarity index 96% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/dir.ts rename to packages/techdocs-common/src/stages/prepare/dir.ts index 1effcf61b5..cebf70e52d 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/prepare/dir.ts +++ b/packages/techdocs-common/src/stages/prepare/dir.ts @@ -16,10 +16,7 @@ import { PreparerBase } from './types'; import { Entity } from '@backstage/catalog-model'; import path from 'path'; -import { - parseReferenceAnnotation, - checkoutGitRepository, -} from '../../../helpers'; +import { parseReferenceAnnotation, checkoutGitRepository } from '../../helpers'; import { InputError } from '@backstage/backend-common'; import parseGitUrl from 'git-url-parse'; import { Logger } from 'winston'; diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/index.ts b/packages/techdocs-common/src/stages/prepare/index.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/index.ts rename to packages/techdocs-common/src/stages/prepare/index.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/preparers.ts b/packages/techdocs-common/src/stages/prepare/preparers.ts similarity index 95% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/preparers.ts rename to packages/techdocs-common/src/stages/prepare/preparers.ts index 2f0df47de4..52a47957e8 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/prepare/preparers.ts +++ b/packages/techdocs-common/src/stages/prepare/preparers.ts @@ -16,7 +16,7 @@ import { PreparerBase, RemoteProtocol, PreparerBuilder } from './types'; import { Entity } from '@backstage/catalog-model'; -import { parseReferenceAnnotation } from '../../../helpers'; +import { parseReferenceAnnotation } from '../../helpers'; export class Preparers implements PreparerBuilder { private preparerMap = new Map(); diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/types.ts b/packages/techdocs-common/src/stages/prepare/types.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/types.ts rename to packages/techdocs-common/src/stages/prepare/types.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/prepare/url.ts b/packages/techdocs-common/src/stages/prepare/url.ts similarity index 95% rename from plugins/techdocs-backend/src/techdocs/stages/prepare/url.ts rename to packages/techdocs-common/src/stages/prepare/url.ts index 330db05aa4..3407684837 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/prepare/url.ts +++ b/packages/techdocs-common/src/stages/prepare/url.ts @@ -15,8 +15,7 @@ */ import { Entity } from '@backstage/catalog-model'; import { PreparerBase } from './types'; -import { getDocFilesFromRepository } from '../../../helpers'; - +import { getDocFilesFromRepository } from '../../helpers'; import { Logger } from 'winston'; import { UrlReader } from '@backstage/backend-common'; diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/index.ts b/packages/techdocs-common/src/stages/publish/index.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/publish/index.ts rename to packages/techdocs-common/src/stages/publish/index.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts b/packages/techdocs-common/src/stages/publish/local.test.ts similarity index 90% rename from plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts rename to packages/techdocs-common/src/stages/publish/local.test.ts index 18344489e1..793c2374d9 100644 --- a/plugins/techdocs-backend/src/techdocs/stages/publish/local.test.ts +++ b/packages/techdocs-common/src/stages/publish/local.test.ts @@ -58,12 +58,12 @@ describe('local publisher', () => { await publisher.publish({ entity: mockEntity, directory: tempDir }); const publishDir = path.resolve( __dirname, - `../../../../static/docs/${mockEntity.metadata.name}`, + `../../../../../plugins/techdocs-backend/static/docs/${mockEntity.metadata.name}`, ); const resultDir = path.resolve( __dirname, - `../../../../static/docs/default/${mockEntity.kind}/${mockEntity.metadata.name}`, + `../../../../../plugins/techdocs-backend/static/docs/default/${mockEntity.kind}/${mockEntity.metadata.name}`, ); expect(fs.existsSync(resultDir)).toBeTruthy(); diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/local.ts b/packages/techdocs-common/src/stages/publish/local.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/publish/local.ts rename to packages/techdocs-common/src/stages/publish/local.ts diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/publish.ts b/packages/techdocs-common/src/stages/publish/publish.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/publish/publish.ts rename to packages/techdocs-common/src/stages/publish/publish.ts diff --git a/packages/techdocs-common/src/stages/publish/test-component-folder-AP2Wti/mock-file b/packages/techdocs-common/src/stages/publish/test-component-folder-AP2Wti/mock-file new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/techdocs-backend/src/techdocs/stages/publish/types.ts b/packages/techdocs-common/src/stages/publish/types.ts similarity index 100% rename from plugins/techdocs-backend/src/techdocs/stages/publish/types.ts rename to packages/techdocs-common/src/stages/publish/types.ts diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index bf67108457..bfa60c4b9c 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -23,19 +23,14 @@ "@backstage/backend-common": "^0.3.2", "@backstage/catalog-model": "^0.3.1", "@backstage/config": "^0.1.1", + "@backstage/techdocs-common": "^0.1.1", "@types/dockerode": "^2.5.34", "@types/express": "^4.17.6", - "command-exists-promise": "^2.0.2", "cross-fetch": "^3.0.6", "dockerode": "^3.2.1", "express": "^4.17.1", "express-promise-router": "^3.0.3", - "fs-extra": "^9.0.1", - "git-url-parse": "^11.4.0", - "js-yaml": "^3.14.0", "knex": "^0.21.6", - "mock-fs": "^4.13.0", - "nodegit": "^0.27.0", "winston": "^3.2.1" }, "devDependencies": { diff --git a/plugins/techdocs-backend/src/index.ts b/plugins/techdocs-backend/src/index.ts index 8c65708017..7612c392a2 100644 --- a/plugins/techdocs-backend/src/index.ts +++ b/plugins/techdocs-backend/src/index.ts @@ -15,4 +15,3 @@ */ export * from './service/router'; -export * from './techdocs'; diff --git a/plugins/techdocs-backend/src/service/helpers.ts b/plugins/techdocs-backend/src/service/helpers.ts index 4a736f7388..876b80781e 100644 --- a/plugins/techdocs-backend/src/service/helpers.ts +++ b/plugins/techdocs-backend/src/service/helpers.ts @@ -22,9 +22,10 @@ import { GeneratorBuilder, PreparerBase, GeneratorBase, -} from '../techdocs'; + getLocationForEntity, + getLastCommitTimestamp, +} from '@backstage/techdocs-common'; import { BuildMetadataStorage } from '../storage'; -import { getLocationForEntity, getLastCommitTimestamp } from '../helpers'; const getEntityId = (entity: Entity) => { return `${entity.kind}:${entity.metadata.namespace ?? ''}:${ diff --git a/plugins/techdocs-backend/src/service/router.ts b/plugins/techdocs-backend/src/service/router.ts index 61f0fa2e9f..0c5708e09f 100644 --- a/plugins/techdocs-backend/src/service/router.ts +++ b/plugins/techdocs-backend/src/service/router.ts @@ -20,14 +20,18 @@ import Knex from 'knex'; import fetch from 'cross-fetch'; import { Config } from '@backstage/config'; import Docker from 'dockerode'; -import { GeneratorBuilder, PreparerBuilder, PublisherBase } from '../techdocs'; +import { + GeneratorBuilder, + PreparerBuilder, + PublisherBase, + getLocationForEntity, +} from '@backstage/techdocs-common'; import { PluginEndpointDiscovery, resolvePackagePath, } from '@backstage/backend-common'; import { Entity } from '@backstage/catalog-model'; import { DocsBuilder } from './helpers'; -import { getLocationForEntity } from '../helpers'; type RouterOptions = { preparers: PreparerBuilder; diff --git a/plugins/techdocs-backend/src/service/standaloneServer.ts b/plugins/techdocs-backend/src/service/standaloneServer.ts index 89b49467d4..af3136dcda 100644 --- a/plugins/techdocs-backend/src/service/standaloneServer.ts +++ b/plugins/techdocs-backend/src/service/standaloneServer.ts @@ -28,7 +28,7 @@ import { Generators, TechdocsGenerator, Publisher, -} from '../techdocs'; +} from '@backstage/techdocs-common'; import { ConfigReader } from '@backstage/config'; export interface ServerOptions { diff --git a/plugins/techdocs/package.json b/plugins/techdocs/package.json index c8bca7d07e..6deb40fd0d 100644 --- a/plugins/techdocs/package.json +++ b/plugins/techdocs/package.json @@ -25,6 +25,7 @@ "@backstage/core": "^0.3.2", "@backstage/core-api": "^0.2.3", "@backstage/plugin-catalog": "^0.2.4", + "@backstage/techdocs-common": "^0.1.1", "@backstage/test-utils": "^0.1.3", "@backstage/theme": "^0.2.1", "@material-ui/core": "^4.11.0",