@techdocs/cli 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/{PublisherConfig-4eefa446.cjs.js → PublisherConfig-a09bdfcc.cjs.js} +7 -7
- package/dist/cjs/{PublisherConfig-4eefa446.cjs.js.map → PublisherConfig-a09bdfcc.cjs.js.map} +1 -1
- package/dist/cjs/{generate-391c018a.cjs.js → generate-86756c8c.cjs.js} +8 -8
- package/dist/cjs/{generate-391c018a.cjs.js.map → generate-86756c8c.cjs.js.map} +1 -1
- package/dist/cjs/{migrate-eedd77be.cjs.js → migrate-04a51fb3.cjs.js} +7 -7
- package/dist/cjs/{migrate-eedd77be.cjs.js.map → migrate-04a51fb3.cjs.js.map} +1 -1
- package/dist/cjs/{mkdocs-3446534f.cjs.js → mkdocs-f1cf9408.cjs.js} +6 -6
- package/dist/cjs/{mkdocs-3446534f.cjs.js.map → mkdocs-f1cf9408.cjs.js.map} +1 -1
- package/dist/cjs/{mkdocsServer-54486fc6.cjs.js → mkdocsServer-7058189d.cjs.js} +2 -2
- package/dist/cjs/{mkdocsServer-54486fc6.cjs.js.map → mkdocsServer-7058189d.cjs.js.map} +1 -1
- package/dist/cjs/{publish-b72ab7ac.cjs.js → publish-d1ccb001.cjs.js} +8 -8
- package/dist/cjs/{publish-b72ab7ac.cjs.js.map → publish-d1ccb001.cjs.js.map} +1 -1
- package/dist/cjs/{serve-7ca882f7.cjs.js → serve-639872a5.cjs.js} +12 -12
- package/dist/cjs/{serve-7ca882f7.cjs.js.map → serve-639872a5.cjs.js.map} +1 -1
- package/dist/cjs/{utility-597170e7.cjs.js → utility-6042a9ba.cjs.js} +5 -7
- package/dist/cjs/{utility-597170e7.cjs.js.map → utility-6042a9ba.cjs.js.map} +1 -1
- package/dist/index.cjs.js +9 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/techdocs-preview-bundle/.config-schema.json +12 -0
- package/dist/techdocs-preview-bundle/index.html +1 -1
- package/dist/techdocs-preview-bundle/static/{1553.b196c066.chunk.js → 1553.d6c469d0.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{1553.b196c066.chunk.js.map → 1553.d6c469d0.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{1959.36e7858c.chunk.js → 1959.e8b17392.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{1959.36e7858c.chunk.js.map → 1959.e8b17392.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{390.d7537222.chunk.js → 390.bec751d9.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{390.d7537222.chunk.js.map → 390.bec751d9.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{4022.91fbea78.chunk.js → 4022.9fd48756.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{4022.91fbea78.chunk.js.map → 4022.9fd48756.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{4960.1233073b.chunk.js → 4960.72d48737.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{4960.1233073b.chunk.js.map → 4960.72d48737.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{6105.32d43fcf.chunk.js → 6105.f231cc00.chunk.js} +1 -1
- package/dist/techdocs-preview-bundle/static/{6105.32d43fcf.chunk.js.map → 6105.f231cc00.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{6235.49ff359a.chunk.js → 6235.c6038f55.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{6235.49ff359a.chunk.js.map → 6235.c6038f55.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{6650.d336b3bc.chunk.js → 6650.c6449e3f.chunk.js} +1 -1
- package/dist/techdocs-preview-bundle/static/{6650.d336b3bc.chunk.js.map → 6650.c6449e3f.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/8015.07e09f1c.chunk.js +2 -0
- package/dist/techdocs-preview-bundle/static/8015.07e09f1c.chunk.js.map +1 -0
- package/dist/techdocs-preview-bundle/static/{8061.525ebd5c.chunk.js → 8061.16540ebf.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{8061.525ebd5c.chunk.js.map → 8061.16540ebf.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/8718.5dc1c9b2.chunk.js +2 -0
- package/dist/techdocs-preview-bundle/static/8718.5dc1c9b2.chunk.js.map +1 -0
- package/dist/techdocs-preview-bundle/static/{8792.d2185dc8.chunk.js → 8792.c0493394.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{8792.d2185dc8.chunk.js.map → 8792.c0493394.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{9028.38d39eff.chunk.js → 9028.de55c09a.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{9028.38d39eff.chunk.js.map → 9028.de55c09a.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/main.b94cbfc7.js +2 -0
- package/dist/techdocs-preview-bundle/static/main.b94cbfc7.js.map +1 -0
- package/dist/techdocs-preview-bundle/static/{module-hot-loader.550aeb54.js → module-hot-loader.ec8a2690.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{module-hot-loader.550aeb54.js.LICENSE.txt → module-hot-loader.ec8a2690.js.LICENSE.txt} +0 -0
- package/dist/techdocs-preview-bundle/static/{module-hot-loader.550aeb54.js.map → module-hot-loader.ec8a2690.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{module-material-table.3a6dac89.js → module-material-table.9755327e.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{module-material-table.3a6dac89.js.map → module-material-table.9755327e.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/module-material-ui.ed23d76f.js +3 -0
- package/dist/techdocs-preview-bundle/static/{module-material-ui.af63fffa.js.LICENSE.txt → module-material-ui.ed23d76f.js.LICENSE.txt} +0 -0
- package/dist/techdocs-preview-bundle/static/module-material-ui.ed23d76f.js.map +1 -0
- package/dist/techdocs-preview-bundle/static/module-react-beautiful-dnd.da6c1d82.js +2 -0
- package/dist/techdocs-preview-bundle/static/module-react-beautiful-dnd.da6c1d82.js.map +1 -0
- package/dist/techdocs-preview-bundle/static/{react-syntax-highlighter_languages_highlight_cLike.f197a4c8.chunk.js → react-syntax-highlighter_languages_highlight_cLike.0613bb54.chunk.js} +2 -2
- package/dist/techdocs-preview-bundle/static/{react-syntax-highlighter_languages_highlight_cLike.f197a4c8.chunk.js.map → react-syntax-highlighter_languages_highlight_cLike.0613bb54.chunk.js.map} +1 -1
- package/dist/techdocs-preview-bundle/static/{runtime.73551f6b.js → runtime.b94cbfc7.js} +2 -2
- package/dist/techdocs-preview-bundle/static/runtime.b94cbfc7.js.map +1 -0
- package/dist/techdocs-preview-bundle/static/vendor.b94cbfc7.js +3 -0
- package/dist/techdocs-preview-bundle/static/{vendor.73551f6b.js.LICENSE.txt → vendor.b94cbfc7.js.LICENSE.txt} +0 -0
- package/dist/techdocs-preview-bundle/static/vendor.b94cbfc7.js.map +1 -0
- package/package.json +6 -6
- package/dist/techdocs-preview-bundle/static/4968.02594898.chunk.js +0 -2
- package/dist/techdocs-preview-bundle/static/4968.02594898.chunk.js.map +0 -1
- package/dist/techdocs-preview-bundle/static/main.73551f6b.js +0 -2
- package/dist/techdocs-preview-bundle/static/main.73551f6b.js.map +0 -1
- package/dist/techdocs-preview-bundle/static/module-material-ui.af63fffa.js +0 -3
- package/dist/techdocs-preview-bundle/static/module-material-ui.af63fffa.js.map +0 -1
- package/dist/techdocs-preview-bundle/static/module-react-beautiful-dnd.2394f1f9.js +0 -2
- package/dist/techdocs-preview-bundle/static/module-react-beautiful-dnd.2394f1f9.js.map +0 -1
- package/dist/techdocs-preview-bundle/static/runtime.73551f6b.js.map +0 -1
- package/dist/techdocs-preview-bundle/static/vendor.73551f6b.js +0 -3
- package/dist/techdocs-preview-bundle/static/vendor.73551f6b.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -29,11 +29,11 @@ const _PublisherConfig = class {
|
|
|
29
29
|
type: "awsS3",
|
|
30
30
|
awsS3: {
|
|
31
31
|
bucketName: cmd.storageName,
|
|
32
|
-
...cmd.awsBucketRootPath && {bucketRootPath: cmd.awsBucketRootPath},
|
|
33
|
-
...cmd.awsRoleArn && {credentials: {roleArn: cmd.awsRoleArn}},
|
|
34
|
-
...cmd.awsEndpoint && {endpoint: cmd.awsEndpoint},
|
|
35
|
-
...cmd.awsS3ForcePathStyle && {s3ForcePathStyle: true},
|
|
36
|
-
...cmd.awsS3sse && {sse: cmd.awsS3sse}
|
|
32
|
+
...cmd.awsBucketRootPath && { bucketRootPath: cmd.awsBucketRootPath },
|
|
33
|
+
...cmd.awsRoleArn && { credentials: { roleArn: cmd.awsRoleArn } },
|
|
34
|
+
...cmd.awsEndpoint && { endpoint: cmd.awsEndpoint },
|
|
35
|
+
...cmd.awsS3ForcePathStyle && { s3ForcePathStyle: true },
|
|
36
|
+
...cmd.awsS3sse && { sse: cmd.awsS3sse }
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -57,7 +57,7 @@ const _PublisherConfig = class {
|
|
|
57
57
|
type: "googleGcs",
|
|
58
58
|
googleGcs: {
|
|
59
59
|
bucketName: cmd.storageName,
|
|
60
|
-
...cmd.gcsBucketRootPath && {bucketRootPath: cmd.gcsBucketRootPath}
|
|
60
|
+
...cmd.gcsBucketRootPath && { bucketRootPath: cmd.gcsBucketRootPath }
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
}
|
|
@@ -94,4 +94,4 @@ PublisherConfig.configFactories = {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
exports.PublisherConfig = PublisherConfig;
|
|
97
|
-
//# sourceMappingURL=PublisherConfig-
|
|
97
|
+
//# sourceMappingURL=PublisherConfig-a09bdfcc.cjs.js.map
|
package/dist/cjs/{PublisherConfig-4eefa446.cjs.js.map → PublisherConfig-a09bdfcc.cjs.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublisherConfig-
|
|
1
|
+
{"version":3,"file":"PublisherConfig-a09bdfcc.cjs.js","sources":["../../src/lib/PublisherConfig.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ConfigReader } from '@backstage/config';\nimport { Command } from 'commander';\n\ntype Publisher = keyof typeof PublisherConfig['configFactories'];\ntype PublisherConfiguration = {\n [p in Publisher]?: any;\n} & {\n type: Publisher;\n};\n\n/**\n * Helper when working with publisher-related configurations.\n */\nexport class PublisherConfig {\n /**\n * Maps publisher-specific config keys to config getters.\n */\n private static configFactories = {\n awsS3: PublisherConfig.getValidAwsS3Config,\n azureBlobStorage: PublisherConfig.getValidAzureConfig,\n googleGcs: PublisherConfig.getValidGoogleGcsConfig,\n openStackSwift: PublisherConfig.getValidOpenStackSwiftConfig,\n };\n\n /**\n * Returns Backstage config suitable for use when instantiating a Publisher. If\n * there are any missing or invalid options provided, an error is thrown.\n *\n * Note: This assumes that proper credentials are set in Environment\n * variables for the respective GCS/AWS clients to work.\n */\n static getValidConfig(cmd: Command): ConfigReader {\n const publisherType = cmd.publisherType;\n\n if (!PublisherConfig.isKnownPublisher(publisherType)) {\n throw new Error(`Unknown publisher type ${cmd.publisherType}`);\n }\n\n return new ConfigReader({\n // This backend config is not used at all. Just something needed a create a mock discovery instance.\n backend: {\n baseUrl: 'http://localhost:7007',\n listen: {\n port: 7007,\n },\n },\n techdocs: {\n publisher: PublisherConfig.configFactories[publisherType](cmd),\n legacyUseCaseSensitiveTripletPaths:\n cmd.legacyUseCaseSensitiveTripletPaths,\n },\n });\n }\n\n /**\n * Typeguard to ensure the publisher has a known config getter.\n */\n private static isKnownPublisher(\n type: string,\n ): type is keyof typeof PublisherConfig['configFactories'] {\n return PublisherConfig.configFactories.hasOwnProperty(type);\n }\n\n /**\n * Retrieve valid AWS S3 configuration based on the command.\n */\n private static getValidAwsS3Config(cmd: Command): PublisherConfiguration {\n return {\n type: 'awsS3',\n awsS3: {\n bucketName: cmd.storageName,\n ...(cmd.awsBucketRootPath && { bucketRootPath: cmd.awsBucketRootPath }),\n ...(cmd.awsRoleArn && { credentials: { roleArn: cmd.awsRoleArn } }),\n ...(cmd.awsEndpoint && { endpoint: cmd.awsEndpoint }),\n ...(cmd.awsS3ForcePathStyle && { s3ForcePathStyle: true }),\n ...(cmd.awsS3sse && { sse: cmd.awsS3sse }),\n },\n };\n }\n\n /**\n * Retrieve valid Azure Blob Storage configuration based on the command.\n */\n private static getValidAzureConfig(cmd: Command): PublisherConfiguration {\n if (!cmd.azureAccountName) {\n throw new Error(\n `azureBlobStorage requires --azureAccountName to be specified`,\n );\n }\n\n return {\n type: 'azureBlobStorage',\n azureBlobStorage: {\n containerName: cmd.storageName,\n credentials: {\n accountName: cmd.azureAccountName,\n accountKey: cmd.azureAccountKey,\n },\n },\n };\n }\n\n /**\n * Retrieve valid GCS configuration based on the command.\n */\n private static getValidGoogleGcsConfig(cmd: Command): PublisherConfiguration {\n return {\n type: 'googleGcs',\n googleGcs: {\n bucketName: cmd.storageName,\n ...(cmd.gcsBucketRootPath && { bucketRootPath: cmd.gcsBucketRootPath }),\n },\n };\n }\n\n /**\n * Retrieves valid OpenStack Swift configuration based on the command.\n */\n private static getValidOpenStackSwiftConfig(\n cmd: Command,\n ): PublisherConfiguration {\n const missingParams = [\n 'osCredentialId',\n 'osSecret',\n 'osAuthUrl',\n 'osSwiftUrl',\n ].filter((param: string) => !cmd[param]);\n\n if (missingParams.length) {\n throw new Error(\n `openStackSwift requires the following params to be specified: ${missingParams.join(\n ', ',\n )}`,\n );\n }\n\n return {\n type: 'openStackSwift',\n openStackSwift: {\n containerName: cmd.storageName,\n credentials: {\n id: cmd.osCredentialId,\n secret: cmd.osSecret,\n },\n authUrl: cmd.osAuthUrl,\n swiftUrl: cmd.osSwiftUrl,\n },\n };\n }\n}\n"],"names":["ConfigReader"],"mappings":";;;;AA6BO,+BAAsB;AAAA,SAkBpB,eAAe,KAA4B;AAChD,UAAM,gBAAgB,IAAI;AAE1B,QAAI,CAAC,iBAAgB,iBAAiB,gBAAgB;AACpD,YAAM,IAAI,MAAM,0BAA0B,IAAI;AAAA;AAGhD,WAAO,IAAIA,oBAAa;AAAA,MAEtB,SAAS;AAAA,QACP,SAAS;AAAA,QACT,QAAQ;AAAA,UACN,MAAM;AAAA;AAAA;AAAA,MAGV,UAAU;AAAA,QACR,WAAW,iBAAgB,gBAAgB,eAAe;AAAA,QAC1D,oCACE,IAAI;AAAA;AAAA;AAAA;AAAA,SAQG,iBACb,MACyD;AACzD,WAAO,iBAAgB,gBAAgB,eAAe;AAAA;AAAA,SAMzC,oBAAoB,KAAsC;AACvE,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,QACL,YAAY,IAAI;AAAA,WACZ,IAAI,qBAAqB,EAAE,gBAAgB,IAAI;AAAA,WAC/C,IAAI,cAAc,EAAE,aAAa,EAAE,SAAS,IAAI;AAAA,WAChD,IAAI,eAAe,EAAE,UAAU,IAAI;AAAA,WACnC,IAAI,uBAAuB,EAAE,kBAAkB;AAAA,WAC/C,IAAI,YAAY,EAAE,KAAK,IAAI;AAAA;AAAA;AAAA;AAAA,SAQtB,oBAAoB,KAAsC;AACvE,QAAI,CAAC,IAAI,kBAAkB;AACzB,YAAM,IAAI,MACR;AAAA;AAIJ,WAAO;AAAA,MACL,MAAM;AAAA,MACN,kBAAkB;AAAA,QAChB,eAAe,IAAI;AAAA,QACnB,aAAa;AAAA,UACX,aAAa,IAAI;AAAA,UACjB,YAAY,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,SAST,wBAAwB,KAAsC;AAC3E,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,QACT,YAAY,IAAI;AAAA,WACZ,IAAI,qBAAqB,EAAE,gBAAgB,IAAI;AAAA;AAAA;AAAA;AAAA,SAQ1C,6BACb,KACwB;AACxB,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,CAAC,UAAkB,CAAC,IAAI;AAEjC,QAAI,cAAc,QAAQ;AACxB,YAAM,IAAI,MACR,iEAAiE,cAAc,KAC7E;AAAA;AAKN,WAAO;AAAA,MACL,MAAM;AAAA,MACN,gBAAgB;AAAA,QACd,eAAe,IAAI;AAAA,QACnB,aAAa;AAAA,UACX,IAAI,IAAI;AAAA,UACR,QAAQ,IAAI;AAAA;AAAA,QAEd,SAAS,IAAI;AAAA,QACb,UAAU,IAAI;AAAA;AAAA;AAAA;AAAA;;AApIf,gBAIU,kBAAkB;AAAA,EAC/B,OAAO,iBAAgB;AAAA,EACvB,kBAAkB,iBAAgB;AAAA,EAClC,WAAW,iBAAgB;AAAA,EAC3B,gBAAgB,iBAAgB;AAAA;;;;"}
|
|
@@ -6,7 +6,7 @@ var Docker = require('dockerode');
|
|
|
6
6
|
var techdocsCommon = require('@backstage/techdocs-common');
|
|
7
7
|
var backendCommon = require('@backstage/backend-common');
|
|
8
8
|
var config = require('@backstage/config');
|
|
9
|
-
var utility = require('./utility-
|
|
9
|
+
var utility = require('./utility-6042a9ba.cjs.js');
|
|
10
10
|
var process$1 = require('process');
|
|
11
11
|
require('winston');
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
|
16
16
|
var Docker__default = /*#__PURE__*/_interopDefaultLegacy(Docker);
|
|
17
17
|
|
|
18
18
|
async function generate(cmd) {
|
|
19
|
-
const logger = utility.createLogger({verbose: cmd.verbose});
|
|
19
|
+
const logger = utility.createLogger({ verbose: cmd.verbose });
|
|
20
20
|
const sourceDir = path.resolve(cmd.sourceDir);
|
|
21
21
|
const outputDir = path.resolve(cmd.outputDir);
|
|
22
22
|
const dockerImage = cmd.dockerImage;
|
|
@@ -24,7 +24,7 @@ async function generate(cmd) {
|
|
|
24
24
|
logger.info(`Using source dir ${sourceDir}`);
|
|
25
25
|
logger.info(`Will output generated files in ${outputDir}`);
|
|
26
26
|
logger.verbose("Creating output directory if it does not exist.");
|
|
27
|
-
await fs__default[
|
|
27
|
+
await fs__default["default"].ensureDir(outputDir);
|
|
28
28
|
const config$1 = new config.ConfigReader({
|
|
29
29
|
techdocs: {
|
|
30
30
|
generator: {
|
|
@@ -34,8 +34,8 @@ async function generate(cmd) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
const dockerClient = new Docker__default[
|
|
38
|
-
const containerRunner = new backendCommon.DockerContainerRunner({dockerClient});
|
|
37
|
+
const dockerClient = new Docker__default["default"]();
|
|
38
|
+
const containerRunner = new backendCommon.DockerContainerRunner({ dockerClient });
|
|
39
39
|
let parsedLocationAnnotation = {};
|
|
40
40
|
if (cmd.techdocsRef) {
|
|
41
41
|
try {
|
|
@@ -57,10 +57,10 @@ async function generate(cmd) {
|
|
|
57
57
|
} : {},
|
|
58
58
|
logger,
|
|
59
59
|
etag: cmd.etag,
|
|
60
|
-
...process.env.LOG_LEVEL === "debug" ? {logStream: process$1.stdout} : {}
|
|
60
|
+
...process.env.LOG_LEVEL === "debug" ? { logStream: process$1.stdout } : {}
|
|
61
61
|
});
|
|
62
62
|
logger.info("Done!");
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
exports
|
|
66
|
-
//# sourceMappingURL=generate-
|
|
65
|
+
exports["default"] = generate;
|
|
66
|
+
//# sourceMappingURL=generate-86756c8c.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-
|
|
1
|
+
{"version":3,"file":"generate-86756c8c.cjs.js","sources":["../../src/commands/generate/generate.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolve } from 'path';\nimport { Command } from 'commander';\nimport fs from 'fs-extra';\nimport Docker from 'dockerode';\nimport {\n TechdocsGenerator,\n ParsedLocationAnnotation,\n} from '@backstage/techdocs-common';\nimport { DockerContainerRunner } from '@backstage/backend-common';\nimport { ConfigReader } from '@backstage/config';\nimport {\n convertTechDocsRefToLocationAnnotation,\n createLogger,\n} from '../../lib/utility';\nimport { stdout } from 'process';\n\nexport default async function generate(cmd: Command) {\n // Use techdocs-common package to generate docs. Keep consistency between Backstage and CI generating docs.\n // Docs can be prepared using actions/checkout or git clone, or similar paradigms on CI. The TechDocs CI workflow\n // will run on the CI pipeline containing the documentation files.\n\n const logger = createLogger({ verbose: cmd.verbose });\n\n const sourceDir = resolve(cmd.sourceDir);\n const outputDir = resolve(cmd.outputDir);\n const dockerImage = cmd.dockerImage;\n const pullImage = cmd.pull;\n\n logger.info(`Using source dir ${sourceDir}`);\n logger.info(`Will output generated files in ${outputDir}`);\n\n logger.verbose('Creating output directory if it does not exist.');\n\n await fs.ensureDir(outputDir);\n\n const config = new ConfigReader({\n techdocs: {\n generator: {\n runIn: cmd.docker ? 'docker' : 'local',\n dockerImage,\n pullImage,\n },\n },\n });\n\n // Docker client (conditionally) used by the generators, based on techdocs.generators config.\n const dockerClient = new Docker();\n const containerRunner = new DockerContainerRunner({ dockerClient });\n\n let parsedLocationAnnotation = {} as ParsedLocationAnnotation;\n if (cmd.techdocsRef) {\n try {\n parsedLocationAnnotation = convertTechDocsRefToLocationAnnotation(\n cmd.techdocsRef,\n );\n } catch (err) {\n logger.error(err.message);\n }\n }\n\n // Generate docs using @backstage/techdocs-common\n const techdocsGenerator = await TechdocsGenerator.fromConfig(config, {\n logger,\n containerRunner,\n });\n\n logger.info('Generating documentation...');\n\n await techdocsGenerator.run({\n inputDir: sourceDir,\n outputDir,\n ...(cmd.techdocsRef\n ? {\n parsedLocationAnnotation,\n }\n : {}),\n logger,\n etag: cmd.etag,\n ...(process.env.LOG_LEVEL === 'debug' ? { logStream: stdout } : {}),\n });\n\n logger.info('Done!');\n}\n"],"names":["createLogger","resolve","fs","config","ConfigReader","Docker","DockerContainerRunner","convertTechDocsRefToLocationAnnotation","TechdocsGenerator","stdout"],"mappings":";;;;;;;;;;;;;;;;;wBAgCuC,KAAc;AAKnD,QAAM,SAASA,qBAAa,EAAE,SAAS,IAAI;AAE3C,QAAM,YAAYC,aAAQ,IAAI;AAC9B,QAAM,YAAYA,aAAQ,IAAI;AAC9B,QAAM,cAAc,IAAI;AACxB,QAAM,YAAY,IAAI;AAEtB,SAAO,KAAK,oBAAoB;AAChC,SAAO,KAAK,kCAAkC;AAE9C,SAAO,QAAQ;AAEf,QAAMC,uBAAG,UAAU;AAEnB,QAAMC,WAAS,IAAIC,oBAAa;AAAA,IAC9B,UAAU;AAAA,MACR,WAAW;AAAA,QACT,OAAO,IAAI,SAAS,WAAW;AAAA,QAC/B;AAAA,QACA;AAAA;AAAA;AAAA;AAMN,QAAM,eAAe,IAAIC;AACzB,QAAM,kBAAkB,IAAIC,oCAAsB,EAAE;AAEpD,MAAI,2BAA2B;AAC/B,MAAI,IAAI,aAAa;AACnB,QAAI;AACF,iCAA2BC,+CACzB,IAAI;AAAA,aAEC,KAAP;AACA,aAAO,MAAM,IAAI;AAAA;AAAA;AAKrB,QAAM,oBAAoB,MAAMC,iCAAkB,WAAWL,UAAQ;AAAA,IACnE;AAAA,IACA;AAAA;AAGF,SAAO,KAAK;AAEZ,QAAM,kBAAkB,IAAI;AAAA,IAC1B,UAAU;AAAA,IACV;AAAA,OACI,IAAI,cACJ;AAAA,MACE;AAAA,QAEF;AAAA,IACJ;AAAA,IACA,MAAM,IAAI;AAAA,OACN,QAAQ,IAAI,cAAc,UAAU,EAAE,WAAWM,qBAAW;AAAA;AAGlE,SAAO,KAAK;AAAA;;;;"}
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var backendCommon = require('@backstage/backend-common');
|
|
4
4
|
var techdocsCommon = require('@backstage/techdocs-common');
|
|
5
|
-
var utility = require('./utility-
|
|
6
|
-
var PublisherConfig = require('./PublisherConfig-
|
|
5
|
+
var utility = require('./utility-6042a9ba.cjs.js');
|
|
6
|
+
var PublisherConfig = require('./PublisherConfig-a09bdfcc.cjs.js');
|
|
7
7
|
require('winston');
|
|
8
8
|
require('@backstage/config');
|
|
9
9
|
|
|
10
10
|
async function migrate(cmd) {
|
|
11
|
-
const logger = utility.createLogger({verbose: cmd.verbose});
|
|
11
|
+
const logger = utility.createLogger({ verbose: cmd.verbose });
|
|
12
12
|
const config = PublisherConfig.PublisherConfig.getValidConfig(cmd);
|
|
13
13
|
const discovery = backendCommon.SingleHostDiscovery.fromConfig(config);
|
|
14
|
-
const publisher = await techdocsCommon.Publisher.fromConfig(config, {logger, discovery});
|
|
14
|
+
const publisher = await techdocsCommon.Publisher.fromConfig(config, { logger, discovery });
|
|
15
15
|
if (!publisher.migrateDocsCase) {
|
|
16
16
|
throw new Error(`Migration not implemented for ${cmd.publisherType}`);
|
|
17
17
|
}
|
|
18
|
-
const {isAvailable} = await publisher.getReadiness();
|
|
18
|
+
const { isAvailable } = await publisher.getReadiness();
|
|
19
19
|
if (!isAvailable) {
|
|
20
20
|
throw new Error("");
|
|
21
21
|
}
|
|
@@ -30,5 +30,5 @@ async function migrate(cmd) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
exports
|
|
34
|
-
//# sourceMappingURL=migrate-
|
|
33
|
+
exports["default"] = migrate;
|
|
34
|
+
//# sourceMappingURL=migrate-04a51fb3.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-
|
|
1
|
+
{"version":3,"file":"migrate-04a51fb3.cjs.js","sources":["../../src/commands/migrate/migrate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SingleHostDiscovery } from '@backstage/backend-common';\nimport { Publisher } from '@backstage/techdocs-common';\nimport { Command } from 'commander';\nimport { createLogger } from '../../lib/utility';\nimport { PublisherConfig } from '../../lib/PublisherConfig';\n\nexport default async function migrate(cmd: Command) {\n const logger = createLogger({ verbose: cmd.verbose });\n\n const config = PublisherConfig.getValidConfig(cmd);\n const discovery = SingleHostDiscovery.fromConfig(config);\n const publisher = await Publisher.fromConfig(config, { logger, discovery });\n\n if (!publisher.migrateDocsCase) {\n throw new Error(`Migration not implemented for ${cmd.publisherType}`);\n }\n\n // Check that the publisher's underlying storage is ready and available.\n const { isAvailable } = await publisher.getReadiness();\n if (!isAvailable) {\n // Error messages printed in getReadiness() call. This ensures exit code 1.\n throw new Error('');\n }\n\n // Validate and parse migration arguments.\n const removeOriginal = cmd.removeOriginal;\n const numericConcurrency = parseInt(cmd.concurrency, 10);\n\n if (!Number.isInteger(numericConcurrency) || numericConcurrency <= 0) {\n throw new Error(\n `Concurrency must be a number greater than 1. ${cmd.concurrency} provided.`,\n );\n }\n\n await publisher.migrateDocsCase({\n concurrency: numericConcurrency,\n removeOriginal,\n });\n}\n"],"names":["createLogger","PublisherConfig","SingleHostDiscovery","Publisher"],"mappings":";;;;;;;;;uBAsBsC,KAAc;AAClD,QAAM,SAASA,qBAAa,EAAE,SAAS,IAAI;AAE3C,QAAM,SAASC,gCAAgB,eAAe;AAC9C,QAAM,YAAYC,kCAAoB,WAAW;AACjD,QAAM,YAAY,MAAMC,yBAAU,WAAW,QAAQ,EAAE,QAAQ;AAE/D,MAAI,CAAC,UAAU,iBAAiB;AAC9B,UAAM,IAAI,MAAM,iCAAiC,IAAI;AAAA;AAIvD,QAAM,EAAE,gBAAgB,MAAM,UAAU;AACxC,MAAI,CAAC,aAAa;AAEhB,UAAM,IAAI,MAAM;AAAA;AAIlB,QAAM,iBAAiB,IAAI;AAC3B,QAAM,qBAAqB,SAAS,IAAI,aAAa;AAErD,MAAI,CAAC,OAAO,UAAU,uBAAuB,sBAAsB,GAAG;AACpE,UAAM,IAAI,MACR,gDAAgD,IAAI;AAAA;AAIxD,QAAM,UAAU,gBAAgB;AAAA,IAC9B,aAAa;AAAA,IACb;AAAA;AAAA;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var openBrowser = require('react-dev-utils/openBrowser');
|
|
4
|
-
var utility = require('./utility-
|
|
5
|
-
var mkdocsServer = require('./mkdocsServer-
|
|
4
|
+
var utility = require('./utility-6042a9ba.cjs.js');
|
|
5
|
+
var mkdocsServer = require('./mkdocsServer-7058189d.cjs.js');
|
|
6
6
|
require('winston');
|
|
7
7
|
require('child_process');
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
var openBrowser__default = /*#__PURE__*/_interopDefaultLegacy(openBrowser);
|
|
12
12
|
|
|
13
13
|
async function serveMkdocs(cmd) {
|
|
14
|
-
const logger = utility.createLogger({verbose: cmd.verbose});
|
|
14
|
+
const logger = utility.createLogger({ verbose: cmd.verbose });
|
|
15
15
|
const dockerAddr = `http://0.0.0.0:${cmd.port}`;
|
|
16
16
|
const localAddr = `http://127.0.0.1:${cmd.port}`;
|
|
17
17
|
const expectedDevAddr = cmd.docker ? dockerAddr : localAddr;
|
|
@@ -28,7 +28,7 @@ async function serveMkdocs(cmd) {
|
|
|
28
28
|
logger.info(`
|
|
29
29
|
Starting mkdocs server on ${localAddr}
|
|
30
30
|
`);
|
|
31
|
-
openBrowser__default[
|
|
31
|
+
openBrowser__default["default"](localAddr);
|
|
32
32
|
boolOpenBrowserTriggered = true;
|
|
33
33
|
}
|
|
34
34
|
});
|
|
@@ -43,5 +43,5 @@ Starting mkdocs server on ${localAddr}
|
|
|
43
43
|
await mkdocsServer.waitForSignal([childProcess]);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
exports
|
|
47
|
-
//# sourceMappingURL=mkdocs-
|
|
46
|
+
exports["default"] = serveMkdocs;
|
|
47
|
+
//# sourceMappingURL=mkdocs-f1cf9408.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mkdocs-
|
|
1
|
+
{"version":3,"file":"mkdocs-f1cf9408.cjs.js","sources":["../../src/commands/serve/mkdocs.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Command } from 'commander';\nimport openBrowser from 'react-dev-utils/openBrowser';\nimport { createLogger } from '../../lib/utility';\nimport { runMkdocsServer } from '../../lib/mkdocsServer';\nimport { LogFunc, waitForSignal } from '../../lib/run';\n\nexport default async function serveMkdocs(cmd: Command) {\n const logger = createLogger({ verbose: cmd.verbose });\n\n const dockerAddr = `http://0.0.0.0:${cmd.port}`;\n const localAddr = `http://127.0.0.1:${cmd.port}`;\n const expectedDevAddr = cmd.docker ? dockerAddr : localAddr;\n // We want to open browser only once based on a log.\n let boolOpenBrowserTriggered = false;\n\n const logFunc: LogFunc = data => {\n // Sometimes the lines contain an unnecessary extra new line in between\n const logLines = data.toString().split('\\n');\n const logPrefix = cmd.docker ? '[docker/mkdocs]' : '[mkdocs]';\n logLines.forEach(line => {\n if (line === '') {\n return;\n }\n\n // Logs from container is verbose.\n logger.verbose(`${logPrefix} ${line}`);\n\n // When the server has started, open a new browser tab for the user.\n if (\n !boolOpenBrowserTriggered &&\n line.includes(`Serving on ${expectedDevAddr}`)\n ) {\n // Always open the local address, since 0.0.0.0 belongs to docker\n logger.info(`\\nStarting mkdocs server on ${localAddr}\\n`);\n openBrowser(localAddr);\n boolOpenBrowserTriggered = true;\n }\n });\n };\n // mkdocs writes all of its logs to stderr by default, and not stdout.\n // https://github.com/mkdocs/mkdocs/issues/879#issuecomment-203536006\n // Had me questioning this whole implementation for half an hour.\n\n // Commander stores --no-docker in cmd.docker variable\n const childProcess = await runMkdocsServer({\n port: cmd.port,\n dockerImage: cmd.dockerImage,\n useDocker: cmd.docker,\n stdoutLogFunc: logFunc,\n stderrLogFunc: logFunc,\n });\n\n // Keep waiting for user to cancel the process\n await waitForSignal([childProcess]);\n}\n"],"names":["createLogger","runMkdocsServer","waitForSignal"],"mappings":";;;;;;;;;;;;2BAsB0C,KAAc;AACtD,QAAM,SAASA,qBAAa,EAAE,SAAS,IAAI;AAE3C,QAAM,aAAa,kBAAkB,IAAI;AACzC,QAAM,YAAY,oBAAoB,IAAI;AAC1C,QAAM,kBAAkB,IAAI,SAAS,aAAa;AAElD,MAAI,2BAA2B;AAE/B,QAAM,UAAmB,UAAQ;AAE/B,UAAM,WAAW,KAAK,WAAW,MAAM;AACvC,UAAM,YAAY,IAAI,SAAS,oBAAoB;AACnD,aAAS,QAAQ,UAAQ;AACvB,UAAI,SAAS,IAAI;AACf;AAAA;AAIF,aAAO,QAAQ,GAAG,aAAa;AAG/B,UACE,CAAC,4BACD,KAAK,SAAS,cAAc,oBAC5B;AAEA,eAAO,KAAK;AAAA,4BAA+B;AAAA;AAC3C,wCAAY;AACZ,mCAA2B;AAAA;AAAA;AAAA;AASjC,QAAM,eAAe,MAAMC,6BAAgB;AAAA,IACzC,MAAM,IAAI;AAAA,IACV,aAAa,IAAI;AAAA,IACjB,WAAW,IAAI;AAAA,IACf,eAAe;AAAA,IACf,eAAe;AAAA;AAIjB,QAAMC,2BAAc,CAAC;AAAA;;;;"}
|
|
@@ -4,7 +4,7 @@ var child_process = require('child_process');
|
|
|
4
4
|
|
|
5
5
|
const run = async (name, args = [], options = {}) => {
|
|
6
6
|
var _a;
|
|
7
|
-
const {stdoutLogFunc, stderrLogFunc} = options;
|
|
7
|
+
const { stdoutLogFunc, stderrLogFunc } = options;
|
|
8
8
|
const env = {
|
|
9
9
|
...process.env,
|
|
10
10
|
FORCE_COLOR: "true",
|
|
@@ -85,4 +85,4 @@ const runMkdocsServer = async (options) => {
|
|
|
85
85
|
|
|
86
86
|
exports.runMkdocsServer = runMkdocsServer;
|
|
87
87
|
exports.waitForSignal = waitForSignal;
|
|
88
|
-
//# sourceMappingURL=mkdocsServer-
|
|
88
|
+
//# sourceMappingURL=mkdocsServer-7058189d.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mkdocsServer-
|
|
1
|
+
{"version":3,"file":"mkdocsServer-7058189d.cjs.js","sources":["../../src/lib/run.ts","../../src/lib/mkdocsServer.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { spawn, SpawnOptions, ChildProcess } from 'child_process';\n\nexport type LogFunc = (data: Buffer | string) => void;\ntype SpawnOptionsPartialEnv = Omit<SpawnOptions, 'env'> & {\n env?: Partial<NodeJS.ProcessEnv>;\n // Pipe stdout to this log function\n stdoutLogFunc?: LogFunc;\n // Pipe stderr to this log function\n stderrLogFunc?: LogFunc;\n};\n\n// TODO: Accept log functions to pipe logs with.\n// Runs a child command, returning the child process instance.\n// Use it along with waitForSignal to run a long running process e.g. mkdocs serve\nexport const run = async (\n name: string,\n args: string[] = [],\n options: SpawnOptionsPartialEnv = {},\n): Promise<ChildProcess> => {\n const { stdoutLogFunc, stderrLogFunc } = options;\n\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n FORCE_COLOR: 'true',\n ...(options.env ?? {}),\n };\n\n // Refer: https://nodejs.org/api/child_process.html#child_process_subprocess_stdio\n const stdio = [\n 'inherit',\n stdoutLogFunc ? 'pipe' : 'inherit',\n stderrLogFunc ? 'pipe' : 'inherit',\n ] as ('inherit' | 'pipe')[];\n\n const childProcess = spawn(name, args, {\n stdio: stdio,\n ...options,\n env,\n });\n\n if (stdoutLogFunc && childProcess.stdout) {\n childProcess.stdout.on('data', stdoutLogFunc);\n }\n if (stderrLogFunc && childProcess.stderr) {\n childProcess.stderr.on('data', stderrLogFunc);\n }\n\n return childProcess;\n};\n\n// Block indefinitely and wait for a signal to kill the child process(es)\n// Throw error if any child process errors\n// Resolves only when all processes exit with status code 0\nexport async function waitForSignal(\n childProcesses: Array<ChildProcess>,\n): Promise<void> {\n const promises: Array<Promise<void>> = [];\n\n for (const signal of ['SIGINT', 'SIGTERM'] as const) {\n process.on(signal, () => {\n childProcesses.forEach(childProcess => {\n childProcess.kill();\n });\n });\n }\n\n childProcesses.forEach(childProcess => {\n if (typeof childProcess.exitCode === 'number') {\n if (childProcess.exitCode) {\n throw new Error(`Non zero exit code from child process`);\n }\n return;\n }\n\n promises.push(\n new Promise<void>((resolve, reject) => {\n childProcess.once('error', reject);\n childProcess.once('exit', resolve);\n }),\n );\n });\n\n await Promise.all(promises);\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ChildProcess } from 'child_process';\nimport { run, LogFunc } from './run';\n\nexport const runMkdocsServer = async (options: {\n port?: string;\n useDocker?: boolean;\n dockerImage?: string;\n stdoutLogFunc?: LogFunc;\n stderrLogFunc?: LogFunc;\n}): Promise<ChildProcess> => {\n const port = options.port ?? '8000';\n const useDocker = options.useDocker ?? true;\n const dockerImage = options.dockerImage ?? 'spotify/techdocs';\n\n if (useDocker) {\n return await run(\n 'docker',\n [\n 'run',\n '--rm',\n '-w',\n '/content',\n '-v',\n `${process.cwd()}:/content`,\n '-p',\n `${port}:${port}`,\n '-it',\n dockerImage,\n 'serve',\n '--dev-addr',\n `0.0.0.0:${port}`,\n ],\n {\n stdoutLogFunc: options.stdoutLogFunc,\n stderrLogFunc: options.stderrLogFunc,\n },\n );\n }\n\n return await run('mkdocs', ['serve', '--dev-addr', `127.0.0.1:${port}`], {\n stdoutLogFunc: options.stdoutLogFunc,\n stderrLogFunc: options.stderrLogFunc,\n });\n};\n"],"names":["spawn"],"mappings":";;;;MA6Ba,MAAM,OACjB,MACA,OAAiB,IACjB,UAAkC,OACR;AAjC5B;AAkCE,QAAM,EAAE,eAAe,kBAAkB;AAEzC,QAAM,MAAyB;AAAA,OAC1B,QAAQ;AAAA,IACX,aAAa;AAAA,OACT,cAAQ,QAAR,YAAe;AAAA;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AAO,MAAM,IAAI,UAAU,CAAC,SAAS,cAAc,aAAa,SAAS;AAAA,IACvE,eAAe,QAAQ;AAAA,IACvB,eAAe,QAAQ;AAAA;AAAA;;;;;"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
|
-
var utility = require('./utility-
|
|
4
|
+
var utility = require('./utility-6042a9ba.cjs.js');
|
|
5
5
|
var backendCommon = require('@backstage/backend-common');
|
|
6
6
|
var techdocsCommon = require('@backstage/techdocs-common');
|
|
7
|
-
var PublisherConfig = require('./PublisherConfig-
|
|
7
|
+
var PublisherConfig = require('./PublisherConfig-a09bdfcc.cjs.js');
|
|
8
8
|
require('winston');
|
|
9
9
|
require('@backstage/config');
|
|
10
10
|
|
|
11
11
|
async function publish(cmd) {
|
|
12
|
-
const logger = utility.createLogger({verbose: cmd.verbose});
|
|
12
|
+
const logger = utility.createLogger({ verbose: cmd.verbose });
|
|
13
13
|
const config = PublisherConfig.PublisherConfig.getValidConfig(cmd);
|
|
14
14
|
const discovery = backendCommon.SingleHostDiscovery.fromConfig(config);
|
|
15
|
-
const publisher = await techdocsCommon.Publisher.fromConfig(config, {logger, discovery});
|
|
16
|
-
const {isAvailable} = await publisher.getReadiness();
|
|
15
|
+
const publisher = await techdocsCommon.Publisher.fromConfig(config, { logger, discovery });
|
|
16
|
+
const { isAvailable } = await publisher.getReadiness();
|
|
17
17
|
if (!isAvailable) {
|
|
18
18
|
return Promise.reject(new Error(""));
|
|
19
19
|
}
|
|
@@ -26,9 +26,9 @@ async function publish(cmd) {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
const directory = path.resolve(cmd.directory);
|
|
29
|
-
await publisher.publish({entity, directory});
|
|
29
|
+
await publisher.publish({ entity, directory });
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
exports
|
|
34
|
-
//# sourceMappingURL=publish-
|
|
33
|
+
exports["default"] = publish;
|
|
34
|
+
//# sourceMappingURL=publish-d1ccb001.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-
|
|
1
|
+
{"version":3,"file":"publish-d1ccb001.cjs.js","sources":["../../src/commands/publish/publish.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolve } from 'path';\nimport { Command } from 'commander';\nimport { createLogger } from '../../lib/utility';\nimport { SingleHostDiscovery } from '@backstage/backend-common';\nimport { Publisher } from '@backstage/techdocs-common';\nimport { Entity } from '@backstage/catalog-model';\nimport { PublisherConfig } from '../../lib/PublisherConfig';\n\nexport default async function publish(cmd: Command): Promise<any> {\n const logger = createLogger({ verbose: cmd.verbose });\n\n const config = PublisherConfig.getValidConfig(cmd);\n const discovery = SingleHostDiscovery.fromConfig(config);\n const publisher = await Publisher.fromConfig(config, { logger, discovery });\n\n // Check that the publisher's underlying storage is ready and available.\n const { isAvailable } = await publisher.getReadiness();\n if (!isAvailable) {\n // Error messages printed in getReadiness() call. This ensures exit code 1.\n return Promise.reject(new Error(''));\n }\n\n const [namespace, kind, name] = cmd.entity.split('/');\n const entity = {\n kind,\n metadata: {\n namespace,\n name,\n },\n } as Entity;\n\n const directory = resolve(cmd.directory);\n await publisher.publish({ entity, directory });\n\n return true;\n}\n"],"names":["createLogger","PublisherConfig","SingleHostDiscovery","Publisher","resolve"],"mappings":";;;;;;;;;;uBAwBsC,KAA4B;AAChE,QAAM,SAASA,qBAAa,EAAE,SAAS,IAAI;AAE3C,QAAM,SAASC,gCAAgB,eAAe;AAC9C,QAAM,YAAYC,kCAAoB,WAAW;AACjD,QAAM,YAAY,MAAMC,yBAAU,WAAW,QAAQ,EAAE,QAAQ;AAG/D,QAAM,EAAE,gBAAgB,MAAM,UAAU;AACxC,MAAI,CAAC,aAAa;AAEhB,WAAO,QAAQ,OAAO,IAAI,MAAM;AAAA;AAGlC,QAAM,CAAC,WAAW,MAAM,QAAQ,IAAI,OAAO,MAAM;AACjD,QAAM,SAAS;AAAA,IACb;AAAA,IACA,UAAU;AAAA,MACR;AAAA,MACA;AAAA;AAAA;AAIJ,QAAM,YAAYC,aAAQ,IAAI;AAC9B,QAAM,UAAU,QAAQ,EAAE,QAAQ;AAElC,SAAO;AAAA;;;;"}
|
|
@@ -5,8 +5,8 @@ var openBrowser = require('react-dev-utils/openBrowser');
|
|
|
5
5
|
var serveHandler = require('serve-handler');
|
|
6
6
|
var http = require('http');
|
|
7
7
|
var httpProxy = require('http-proxy');
|
|
8
|
-
var utility = require('./utility-
|
|
9
|
-
var mkdocsServer = require('./mkdocsServer-
|
|
8
|
+
var utility = require('./utility-6042a9ba.cjs.js');
|
|
9
|
+
var mkdocsServer = require('./mkdocsServer-7058189d.cjs.js');
|
|
10
10
|
require('winston');
|
|
11
11
|
require('child_process');
|
|
12
12
|
|
|
@@ -27,7 +27,7 @@ class HTTPServer {
|
|
|
27
27
|
this.verbose = verbose;
|
|
28
28
|
}
|
|
29
29
|
createProxy() {
|
|
30
|
-
const proxy = httpProxy__default[
|
|
30
|
+
const proxy = httpProxy__default["default"].createProxyServer({
|
|
31
31
|
target: `http://localhost:${this.mkdocsPort}`
|
|
32
32
|
});
|
|
33
33
|
return (request) => {
|
|
@@ -40,7 +40,7 @@ class HTTPServer {
|
|
|
40
40
|
async serve() {
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
const proxyHandler = this.createProxy();
|
|
43
|
-
const server = http__default[
|
|
43
|
+
const server = http__default["default"].createServer((request, response) => {
|
|
44
44
|
var _a;
|
|
45
45
|
if ((_a = request.url) == null ? void 0 : _a.startsWith(this.proxyEndpoint)) {
|
|
46
46
|
const [proxy, forwardPath] = proxyHandler(request);
|
|
@@ -52,13 +52,13 @@ class HTTPServer {
|
|
|
52
52
|
request.url = forwardPath;
|
|
53
53
|
return proxy.web(request, response);
|
|
54
54
|
}
|
|
55
|
-
return serveHandler__default[
|
|
55
|
+
return serveHandler__default["default"](request, response, {
|
|
56
56
|
public: this.backstageBundleDir,
|
|
57
57
|
trailingSlash: true,
|
|
58
|
-
rewrites: [{source: "**", destination: "index.html"}]
|
|
58
|
+
rewrites: [{ source: "**", destination: "index.html" }]
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
-
const logger = utility.createLogger({verbose: false});
|
|
61
|
+
const logger = utility.createLogger({ verbose: false });
|
|
62
62
|
server.listen(this.backstagePort, () => {
|
|
63
63
|
if (this.verbose) {
|
|
64
64
|
logger.info(`[techdocs-preview-bundle] Running local version of Backstage at http://localhost:${this.backstagePort}`);
|
|
@@ -73,7 +73,7 @@ class HTTPServer {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
async function serve(cmd) {
|
|
76
|
-
const logger = utility.createLogger({verbose: cmd.verbose});
|
|
76
|
+
const logger = utility.createLogger({ verbose: cmd.verbose });
|
|
77
77
|
const isDevMode = Object.keys(process.env).includes("TECHDOCS_CLI_DEV_MODE") ? true : false;
|
|
78
78
|
const backstagePort = 3e3;
|
|
79
79
|
const backstageBackendPort = 7007;
|
|
@@ -112,7 +112,7 @@ async function serve(cmd) {
|
|
|
112
112
|
if (!mkdocsServerHasStarted) {
|
|
113
113
|
logger.error("mkdocs server did not start. Exiting. Try re-running command with -v option for more details.");
|
|
114
114
|
}
|
|
115
|
-
const techdocsPreviewBundlePath = path__default[
|
|
115
|
+
const techdocsPreviewBundlePath = path__default["default"].join(path__default["default"].dirname(require.resolve("@techdocs/cli/package.json")), "dist", "techdocs-preview-bundle");
|
|
116
116
|
const port = isDevMode ? backstageBackendPort : backstagePort;
|
|
117
117
|
const httpServer = new HTTPServer(techdocsPreviewBundlePath, port, cmd.mkdocsPort, cmd.verbose);
|
|
118
118
|
httpServer.serve().catch((err) => {
|
|
@@ -120,12 +120,12 @@ async function serve(cmd) {
|
|
|
120
120
|
mkdocsChildProcess.kill();
|
|
121
121
|
process.exit(1);
|
|
122
122
|
}).then(() => {
|
|
123
|
-
openBrowser__default[
|
|
123
|
+
openBrowser__default["default"](`http://localhost:${port}/docs/default/component/local/`);
|
|
124
124
|
logger.info(`Serving docs in Backstage at http://localhost:${port}/docs/default/component/local/
|
|
125
125
|
Opening browser.`);
|
|
126
126
|
});
|
|
127
127
|
await mkdocsServer.waitForSignal([mkdocsChildProcess]);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
exports
|
|
131
|
-
//# sourceMappingURL=serve-
|
|
130
|
+
exports["default"] = serve;
|
|
131
|
+
//# sourceMappingURL=serve-639872a5.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-7ca882f7.cjs.js","sources":["../../src/lib/httpServer.ts","../../src/commands/serve/serve.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport serveHandler from 'serve-handler';\nimport http from 'http';\nimport httpProxy from 'http-proxy';\nimport { createLogger } from './utility';\n\nexport default class HTTPServer {\n private readonly proxyEndpoint: string;\n private readonly backstageBundleDir: string;\n private readonly backstagePort: number;\n private readonly mkdocsPort: number;\n private readonly verbose: boolean;\n\n constructor(\n backstageBundleDir: string,\n backstagePort: number,\n mkdocsPort: number,\n verbose: boolean,\n ) {\n this.proxyEndpoint = '/api/';\n this.backstageBundleDir = backstageBundleDir;\n this.backstagePort = backstagePort;\n this.mkdocsPort = mkdocsPort;\n this.verbose = verbose;\n }\n\n // Create a Proxy for mkdocs server\n private createProxy() {\n const proxy = httpProxy.createProxyServer({\n target: `http://localhost:${this.mkdocsPort}`,\n });\n\n return (request: http.IncomingMessage): [httpProxy, string] => {\n // If the request goes to /api/ we want to remove /api/ from the prefix of the request URL.\n // e.g. ['/', 'api', pathChunks]\n const [, , ...pathChunks] = request.url?.split('/') ?? [];\n const forwardPath = pathChunks.join('/');\n\n return [proxy, forwardPath];\n };\n }\n\n public async serve(): Promise<http.Server> {\n return new Promise<http.Server>((resolve, reject) => {\n const proxyHandler = this.createProxy();\n const server = http.createServer(\n (request: http.IncomingMessage, response: http.ServerResponse) => {\n if (request.url?.startsWith(this.proxyEndpoint)) {\n const [proxy, forwardPath] = proxyHandler(request);\n\n proxy.on('error', (error: Error) => {\n reject(error);\n });\n\n response.setHeader('Access-Control-Allow-Origin', '*');\n response.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');\n\n request.url = forwardPath;\n return proxy.web(request, response);\n }\n\n return serveHandler(request, response, {\n public: this.backstageBundleDir,\n trailingSlash: true,\n rewrites: [{ source: '**', destination: 'index.html' }],\n });\n },\n );\n\n const logger = createLogger({ verbose: false });\n server.listen(this.backstagePort, () => {\n if (this.verbose) {\n logger.info(\n `[techdocs-preview-bundle] Running local version of Backstage at http://localhost:${this.backstagePort}`,\n );\n }\n resolve(server);\n });\n\n server.on('error', (error: Error) => {\n reject(error);\n });\n });\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Command } from 'commander';\nimport path from 'path';\nimport openBrowser from 'react-dev-utils/openBrowser';\nimport HTTPServer from '../../lib/httpServer';\nimport { runMkdocsServer } from '../../lib/mkdocsServer';\nimport { LogFunc, waitForSignal } from '../../lib/run';\nimport { createLogger } from '../../lib/utility';\n\nexport default async function serve(cmd: Command) {\n const logger = createLogger({ verbose: cmd.verbose });\n\n // Determine if we want to run in local dev mode or not\n // This will run the backstage http server on a different port and only used\n // for proxying mkdocs to the backstage app running locally (e.g. with webpack-dev-server)\n const isDevMode = Object.keys(process.env).includes('TECHDOCS_CLI_DEV_MODE')\n ? true\n : false;\n\n // TODO: Backstage app port should also be configurable as a CLI option. However, since we bundle\n // a backstage app, we define app.baseUrl in the app-config.yaml.\n // Hence, it is complicated to make this configurable.\n const backstagePort = 3000;\n const backstageBackendPort = 7007;\n\n const mkdocsDockerAddr = `http://0.0.0.0:${cmd.mkdocsPort}`;\n const mkdocsLocalAddr = `http://127.0.0.1:${cmd.mkdocsPort}`;\n const mkdocsExpectedDevAddr = cmd.docker ? mkdocsDockerAddr : mkdocsLocalAddr;\n\n let mkdocsServerHasStarted = false;\n const mkdocsLogFunc: LogFunc = data => {\n // Sometimes the lines contain an unnecessary extra new line\n const logLines = data.toString().split('\\n');\n const logPrefix = cmd.docker ? '[docker/mkdocs]' : '[mkdocs]';\n logLines.forEach(line => {\n if (line === '') {\n return;\n }\n\n logger.verbose(`${logPrefix} ${line}`);\n\n // When the server has started, open a new browser tab for the user.\n if (\n !mkdocsServerHasStarted &&\n line.includes(`Serving on ${mkdocsExpectedDevAddr}`)\n ) {\n mkdocsServerHasStarted = true;\n }\n });\n };\n // mkdocs writes all of its logs to stderr by default, and not stdout.\n // https://github.com/mkdocs/mkdocs/issues/879#issuecomment-203536006\n // Had me questioning this whole implementation for half an hour.\n logger.info('Starting mkdocs server.');\n const mkdocsChildProcess = await runMkdocsServer({\n port: cmd.mkdocsPort,\n dockerImage: cmd.dockerImage,\n useDocker: cmd.docker,\n stdoutLogFunc: mkdocsLogFunc,\n stderrLogFunc: mkdocsLogFunc,\n });\n\n // Wait until mkdocs server has started so that Backstage starts with docs loaded\n // Takes 1-5 seconds\n for (let attempt = 0; attempt < 30; attempt++) {\n await new Promise(r => setTimeout(r, 3000));\n if (mkdocsServerHasStarted) {\n break;\n }\n logger.info('Waiting for mkdocs server to start...');\n }\n\n if (!mkdocsServerHasStarted) {\n logger.error(\n 'mkdocs server did not start. Exiting. Try re-running command with -v option for more details.',\n );\n }\n\n // Run the embedded-techdocs Backstage app\n const techdocsPreviewBundlePath = path.join(\n path.dirname(require.resolve('@techdocs/cli/package.json')),\n 'dist',\n 'techdocs-preview-bundle',\n );\n\n const port = isDevMode ? backstageBackendPort : backstagePort;\n const httpServer = new HTTPServer(\n techdocsPreviewBundlePath,\n port,\n cmd.mkdocsPort,\n cmd.verbose,\n );\n\n httpServer\n .serve()\n .catch(err => {\n logger.error(err);\n mkdocsChildProcess.kill();\n process.exit(1);\n })\n .then(() => {\n // The last three things default/component/local/ don't matter. They can be anything.\n openBrowser(`http://localhost:${port}/docs/default/component/local/`);\n logger.info(\n `Serving docs in Backstage at http://localhost:${port}/docs/default/component/local/\\nOpening browser.`,\n );\n });\n\n await waitForSignal([mkdocsChildProcess]);\n}\n"],"names":["httpProxy","http","serveHandler","createLogger","runMkdocsServer","path","waitForSignal"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAqBgC;AAAA,EAO9B,YACE,oBACA,eACA,YACA,SACA;AACA,SAAK,gBAAgB;AACrB,SAAK,qBAAqB;AAC1B,SAAK,gBAAgB;AACrB,SAAK,aAAa;AAClB,SAAK,UAAU;AAAA;AAAA,EAIT,cAAc;AACpB,UAAM,QAAQA,8BAAU,kBAAkB;AAAA,MACxC,QAAQ,oBAAoB,KAAK;AAAA;AAGnC,WAAO,CAAC,YAAuD;AA/CnE;AAkDM,YAAM,QAAQ,cAAc,oBAAQ,QA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WAAW,MAAM;AACvC,UAAM,YAAY,IAAI,SAAS,oBAAoB;AACnD,aAAS,QAAQ,UAAQ;AACvB,UAAI,SAAS,IAAI;AACf;AAAA;AAGF,aAAO,QAAQ,GAAG,aAAa;AAG/B,UACE,CAAC,0BACD,KAAK,SAAS,cAAc,0BAC5B;AACA,iCAAyB;AAAA;AAAA;AAAA;AAO/B,SAAO,KAAK;AACZ,QAAM,qBAAqB,MAAMC,6BAAgB;AAAA,IAC/C,MAAM,IAAI;AAAA,IACV,aAAa,IAAI;AAAA,IACjB,WAAW,IAAI;AAAA,IACf,eAAe;AAAA,IACf,eAAe;AAAA;AAKjB,WAAS,UAAU,GAAG,UAAU,IAAI,WAAW;AAC7C,UAAM,IAAI,QAAQ,OAAK,WAAW,GAAG;AACrC,QAAI,wBAAwB;AAC1B;AAAA;AAEF,WAAO,KAAK;AAAA;AAGd,MAAI,CAAC,wBAAwB;AAC3B,WAAO,MACL;AAAA;AAKJ,QAAM,4BAA4BC,yBAAK,KACrCA,yBAAK,QAAQ,QAAQ,QAAQ,gCAC7B,QACA;AAGF,QAAM,OAAO,YAAY,uBAAuB;AAChD,QAAM,aAAa,IAAI,WACrB,2BACA,MACA,IAAI,YACJ,IAAI;AAGN,aACG,QACA,MAAM,SAAO;AACZ,WAAO,MAAM;AACb,uBAAmB;AACnB,YAAQ,KAAK;AAAA,KAEd,KAAK,MAAM;AAEV,oCAAY,oBAAoB;AAChC,WAAO,KACL,iDAAiD;AAAA;AAAA;AAIvD,QAAMC,2BAAc,CAAC;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"serve-639872a5.cjs.js","sources":["../../src/lib/httpServer.ts","../../src/commands/serve/serve.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport serveHandler from 'serve-handler';\nimport http from 'http';\nimport httpProxy from 'http-proxy';\nimport { createLogger } from './utility';\n\nexport default class HTTPServer {\n private readonly proxyEndpoint: string;\n private readonly backstageBundleDir: string;\n private readonly backstagePort: number;\n private readonly mkdocsPort: number;\n private readonly verbose: boolean;\n\n constructor(\n backstageBundleDir: string,\n backstagePort: number,\n mkdocsPort: number,\n verbose: boolean,\n ) {\n this.proxyEndpoint = '/api/';\n this.backstageBundleDir = backstageBundleDir;\n this.backstagePort = backstagePort;\n this.mkdocsPort = mkdocsPort;\n this.verbose = verbose;\n }\n\n // Create a Proxy for mkdocs server\n private createProxy() {\n const proxy = httpProxy.createProxyServer({\n target: `http://localhost:${this.mkdocsPort}`,\n });\n\n return (request: http.IncomingMessage): [httpProxy, string] => {\n // If the request goes to /api/ we want to remove /api/ from the prefix of the request URL.\n // e.g. ['/', 'api', pathChunks]\n const [, , ...pathChunks] = request.url?.split('/') ?? [];\n const forwardPath = pathChunks.join('/');\n\n return [proxy, forwardPath];\n };\n }\n\n public async serve(): Promise<http.Server> {\n return new Promise<http.Server>((resolve, reject) => {\n const proxyHandler = this.createProxy();\n const server = http.createServer(\n (request: http.IncomingMessage, response: http.ServerResponse) => {\n if (request.url?.startsWith(this.proxyEndpoint)) {\n const [proxy, forwardPath] = proxyHandler(request);\n\n proxy.on('error', (error: Error) => {\n reject(error);\n });\n\n response.setHeader('Access-Control-Allow-Origin', '*');\n response.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');\n\n request.url = forwardPath;\n return proxy.web(request, response);\n }\n\n return serveHandler(request, response, {\n public: this.backstageBundleDir,\n trailingSlash: true,\n rewrites: [{ source: '**', destination: 'index.html' }],\n });\n },\n );\n\n const logger = createLogger({ verbose: false });\n server.listen(this.backstagePort, () => {\n if (this.verbose) {\n logger.info(\n `[techdocs-preview-bundle] Running local version of Backstage at http://localhost:${this.backstagePort}`,\n );\n }\n resolve(server);\n });\n\n server.on('error', (error: Error) => {\n reject(error);\n });\n });\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Command } from 'commander';\nimport path from 'path';\nimport openBrowser from 'react-dev-utils/openBrowser';\nimport HTTPServer from '../../lib/httpServer';\nimport { runMkdocsServer } from '../../lib/mkdocsServer';\nimport { LogFunc, waitForSignal } from '../../lib/run';\nimport { createLogger } from '../../lib/utility';\n\nexport default async function serve(cmd: Command) {\n const logger = createLogger({ verbose: cmd.verbose });\n\n // Determine if we want to run in local dev mode or not\n // This will run the backstage http server on a different port and only used\n // for proxying mkdocs to the backstage app running locally (e.g. with webpack-dev-server)\n const isDevMode = Object.keys(process.env).includes('TECHDOCS_CLI_DEV_MODE')\n ? true\n : false;\n\n // TODO: Backstage app port should also be configurable as a CLI option. However, since we bundle\n // a backstage app, we define app.baseUrl in the app-config.yaml.\n // Hence, it is complicated to make this configurable.\n const backstagePort = 3000;\n const backstageBackendPort = 7007;\n\n const mkdocsDockerAddr = `http://0.0.0.0:${cmd.mkdocsPort}`;\n const mkdocsLocalAddr = `http://127.0.0.1:${cmd.mkdocsPort}`;\n const mkdocsExpectedDevAddr = cmd.docker ? mkdocsDockerAddr : mkdocsLocalAddr;\n\n let mkdocsServerHasStarted = false;\n const mkdocsLogFunc: LogFunc = data => {\n // Sometimes the lines contain an unnecessary extra new line\n const logLines = data.toString().split('\\n');\n const logPrefix = cmd.docker ? '[docker/mkdocs]' : '[mkdocs]';\n logLines.forEach(line => {\n if (line === '') {\n return;\n }\n\n logger.verbose(`${logPrefix} ${line}`);\n\n // When the server has started, open a new browser tab for the user.\n if (\n !mkdocsServerHasStarted &&\n line.includes(`Serving on ${mkdocsExpectedDevAddr}`)\n ) {\n mkdocsServerHasStarted = true;\n }\n });\n };\n // mkdocs writes all of its logs to stderr by default, and not stdout.\n // https://github.com/mkdocs/mkdocs/issues/879#issuecomment-203536006\n // Had me questioning this whole implementation for half an hour.\n logger.info('Starting mkdocs server.');\n const mkdocsChildProcess = await runMkdocsServer({\n port: cmd.mkdocsPort,\n dockerImage: cmd.dockerImage,\n useDocker: cmd.docker,\n stdoutLogFunc: mkdocsLogFunc,\n stderrLogFunc: mkdocsLogFunc,\n });\n\n // Wait until mkdocs server has started so that Backstage starts with docs loaded\n // Takes 1-5 seconds\n for (let attempt = 0; attempt < 30; attempt++) {\n await new Promise(r => setTimeout(r, 3000));\n if (mkdocsServerHasStarted) {\n break;\n }\n logger.info('Waiting for mkdocs server to start...');\n }\n\n if (!mkdocsServerHasStarted) {\n logger.error(\n 'mkdocs server did not start. Exiting. Try re-running command with -v option for more details.',\n );\n }\n\n // Run the embedded-techdocs Backstage app\n const techdocsPreviewBundlePath = path.join(\n path.dirname(require.resolve('@techdocs/cli/package.json')),\n 'dist',\n 'techdocs-preview-bundle',\n );\n\n const port = isDevMode ? backstageBackendPort : backstagePort;\n const httpServer = new HTTPServer(\n techdocsPreviewBundlePath,\n port,\n cmd.mkdocsPort,\n cmd.verbose,\n );\n\n httpServer\n .serve()\n .catch(err => {\n logger.error(err);\n mkdocsChildProcess.kill();\n process.exit(1);\n })\n .then(() => {\n // The last three things default/component/local/ don't matter. They can be anything.\n openBrowser(`http://localhost:${port}/docs/default/component/local/`);\n logger.info(\n `Serving docs in Backstage at http://localhost:${port}/docs/default/component/local/\\nOpening browser.`,\n );\n });\n\n await waitForSignal([mkdocsChildProcess]);\n}\n"],"names":["httpProxy","http","serveHandler","createLogger","runMkd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oCAAY,oBAAoB;AAChC,WAAO,KACL,iDAAiD;AAAA;AAAA;AAIvD,QAAMC,2BAAc,CAAC;AAAA;;;;"}
|
|
@@ -11,14 +11,12 @@ function _interopNamespace(e) {
|
|
|
11
11
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
12
|
Object.defineProperty(n, k, d.get ? d : {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return e[k];
|
|
16
|
-
}
|
|
14
|
+
get: function () { return e[k]; }
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
18
|
}
|
|
21
|
-
n[
|
|
19
|
+
n["default"] = e;
|
|
22
20
|
return Object.freeze(n);
|
|
23
21
|
}
|
|
24
22
|
|
|
@@ -29,7 +27,7 @@ const convertTechDocsRefToLocationAnnotation = (techdocsRef) => {
|
|
|
29
27
|
if (!type || !target) {
|
|
30
28
|
throw new Error(`Can not parse --techdocs-ref ${techdocsRef}. Should be of type HOST:URL.`);
|
|
31
29
|
}
|
|
32
|
-
return {type, target};
|
|
30
|
+
return { type, target };
|
|
33
31
|
};
|
|
34
32
|
const createLogger = ({
|
|
35
33
|
verbose = false
|
|
@@ -37,7 +35,7 @@ const createLogger = ({
|
|
|
37
35
|
const logger = winston__namespace.createLogger({
|
|
38
36
|
level: verbose ? "verbose" : "info",
|
|
39
37
|
transports: [
|
|
40
|
-
new winston__namespace.transports.Console({format: winston__namespace.format.simple()})
|
|
38
|
+
new winston__namespace.transports.Console({ format: winston__namespace.format.simple() })
|
|
41
39
|
]
|
|
42
40
|
});
|
|
43
41
|
return logger;
|
|
@@ -45,4 +43,4 @@ const createLogger = ({
|
|
|
45
43
|
|
|
46
44
|
exports.convertTechDocsRefToLocationAnnotation = convertTechDocsRefToLocationAnnotation;
|
|
47
45
|
exports.createLogger = createLogger;
|
|
48
|
-
//# sourceMappingURL=utility-
|
|
46
|
+
//# sourceMappingURL=utility-6042a9ba.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utility-
|
|
1
|
+
{"version":3,"file":"utility-6042a9ba.cjs.js","sources":["../../src/lib/utility.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n RemoteProtocol,\n ParsedLocationAnnotation,\n} from '@backstage/techdocs-common';\nimport * as winston from 'winston';\n\nexport const convertTechDocsRefToLocationAnnotation = (\n techdocsRef: string,\n): ParsedLocationAnnotation => {\n // Split on the first colon for the protocol and the rest after the first split\n // is the location.\n const [type, target] = techdocsRef.split(/:(.+)/) as [\n RemoteProtocol?,\n string?,\n ];\n\n if (!type || !target) {\n throw new Error(\n `Can not parse --techdocs-ref ${techdocsRef}. Should be of type HOST:URL.`,\n );\n }\n\n return { type, target };\n};\n\nexport const createLogger = ({\n verbose = false,\n}: {\n verbose: boolean;\n}): winston.Logger => {\n const logger = winston.createLogger({\n level: verbose ? 'verbose' : 'info',\n transports: [\n new winston.transports.Console({ format: winston.format.simple() }),\n ],\n });\n\n return logger;\n};\n"],"names":["winston"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;MAqBa,yCAAyC,CACpD,gBAC6B;AAG7B,QAAM,CAAC,MAAM,UAAU,YAAY,MAAM;AAKzC,MAAI,CAAC,QAAQ,CAAC,QAAQ;AACpB,UAAM,IAAI,MACR,gCAAgC;AAAA;AAIpC,SAAO,EAAE,MAAM;AAAA;MAGJ,eAAe,CAAC;AAAA,EAC3B,UAAU;AAAA,MAGU;AACpB,QAAM,SAASA,mBAAQ,aAAa;AAAA,IAClC,OAAO,UAAU,YAAY;AAAA,IAC7B,YAAY;AAAA,MACV,IAAIA,mBAAQ,WAAW,QAAQ,EAAE,QAAQA,mBAAQ,OAAO;AAAA;AAAA;AAI5D,SAAO;AAAA;;;;;"}
|