fix(techdocs-cli): cross-platform build script
Co-authored-by: Emma Indal <emma.indahl@gmail.com> Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
+3
-2
@@ -30,8 +30,8 @@
|
||||
"lerna": "lerna",
|
||||
"storybook": "yarn workspace storybook start",
|
||||
"build-storybook": "yarn workspace storybook build-storybook",
|
||||
"techdocs-cli": "yarn workspace @techdocs/cli build && packages/techdocs-cli/bin/techdocs-cli",
|
||||
"techdocs-cli:dev": "yarn workspace @techdocs/cli build:dev && TECHDOCS_CLI_DEV_MODE=true packages/techdocs-cli/bin/techdocs-cli",
|
||||
"techdocs-cli": "node scripts/techdocs-cli.js",
|
||||
"techdocs-cli:dev": "cross-env TECHDOCS_CLI_DEV_MODE=true node scripts/techdocs-cli.js",
|
||||
"prepare": "husky install",
|
||||
"lock:check": "yarn-lock-check"
|
||||
},
|
||||
@@ -63,6 +63,7 @@
|
||||
"@spotify/prettier-config": "^11.0.0",
|
||||
"@types/webpack": "^5.28.0",
|
||||
"command-exists": "^1.2.9",
|
||||
"cross-env": "^7.0.0",
|
||||
"concurrently": "^6.0.0",
|
||||
"eslint-plugin-notice": "^0.9.10",
|
||||
"fs-extra": "9.1.0",
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
"scripts": {
|
||||
"start": "nodemon --",
|
||||
"build": "./scripts/build.sh",
|
||||
"build:dev": "TECHDOCS_CLI_DEV_MODE=true yarn build",
|
||||
"clean": "backstage-cli clean",
|
||||
"lint": "backstage-cli lint",
|
||||
"test": "backstage-cli test --testPathIgnorePatterns src/e2e.test.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Backstage Authors
|
||||
# Copyright 2021 The Backstage Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -16,26 +16,29 @@
|
||||
|
||||
set -e
|
||||
|
||||
# Build the TechDocs CLI
|
||||
npx backstage-cli -- build --outputs cjs
|
||||
SCRIPT_DIR=$(dirname $0)
|
||||
TECHDOCS_CLI_DIR="$SCRIPT_DIR"/..
|
||||
TECHDOCS_CLI_EMBEDDED_APP_DIR="$TECHDOCS_CLI_DIR"/../embedded-techdocs-app
|
||||
|
||||
# Make sure to do `yarn run build` in packages/embedded-techdocs before building here.
|
||||
compile_and_build_cli() {
|
||||
echo "📄 Compiling..."
|
||||
yarn workspace @techdocs/cli tsc > /dev/null
|
||||
echo "📦️ Building..."
|
||||
pushd $TECHDOCS_CLI_DIR > /dev/null
|
||||
npx backstage-cli build --outputs cjs > /dev/null
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
EMBEDDED_TECHDOCS_APP_PATH=../embedded-techdocs-app
|
||||
TECHDOCS_PREVIEW_SOURCE=$EMBEDDED_TECHDOCS_APP_PATH/dist
|
||||
TECHDOCS_PREVIEW_DEST=dist/techdocs-preview-bundle
|
||||
build_and_embed_app() {
|
||||
echo "🚚 Embedding app..."
|
||||
if [ "$TECHDOCS_CLI_DEV_MODE" = "true" ] ; then
|
||||
yarn workspace embedded-techdocs-app build:dev > /dev/null
|
||||
else
|
||||
yarn workspace embedded-techdocs-app build > /dev/null
|
||||
fi
|
||||
cp -r "$TECHDOCS_CLI_EMBEDDED_APP_DIR"/dist "$TECHDOCS_CLI_DIR"/dist/techdocs-preview-bundle > /dev/null
|
||||
}
|
||||
|
||||
# Build the embedded-techdocs-app
|
||||
pushd $EMBEDDED_TECHDOCS_APP_PATH >/dev/null
|
||||
if [[ $TECHDOCS_CLI_DEV_MODE == "true" ]]; then
|
||||
yarn build:dev
|
||||
else
|
||||
yarn build
|
||||
fi
|
||||
popd >/dev/null
|
||||
|
||||
cp -r $TECHDOCS_PREVIEW_SOURCE $TECHDOCS_PREVIEW_DEST
|
||||
|
||||
# Write to console
|
||||
echo "[techdocs-cli]: Built the dist/ folder"
|
||||
echo "[techdocs-cli]: Imported @backstage/plugin-techdocs dist/ folder into techdocs-preview-bundle/"
|
||||
compile_and_build_cli
|
||||
build_and_embed_app
|
||||
echo "🏁 Ready!"
|
||||
|
||||
@@ -77,8 +77,8 @@ export default async function serve(cmd: Command) {
|
||||
|
||||
// Wait until mkdocs server has started so that Backstage starts with docs loaded
|
||||
// Takes 1-5 seconds
|
||||
for (let attempt = 0; attempt < 10; attempt++) {
|
||||
await new Promise(r => setTimeout(r, 1000));
|
||||
for (let attempt = 0; attempt < 30; attempt++) {
|
||||
await new Promise(r => setTimeout(r, 3000));
|
||||
if (mkdocsServerHasStarted) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const FIXTURE_DIR = path.resolve(PROJECT_ROOT_DIR, 'src/fixture');
|
||||
|
||||
describe('end-to-end', () => {
|
||||
it('shows help text', async () => {
|
||||
jest.setTimeout(10000);
|
||||
jest.setTimeout(30000);
|
||||
const proc = await executeTechDocsCliCommand(['--help']);
|
||||
|
||||
expect(proc.combinedStdOutErr).toContain('Usage: techdocs-cli [options]');
|
||||
@@ -30,10 +30,10 @@ describe('end-to-end', () => {
|
||||
});
|
||||
|
||||
it('can generate', async () => {
|
||||
jest.setTimeout(10000);
|
||||
jest.setTimeout(30000);
|
||||
const proc = await executeTechDocsCliCommand(['generate', '--no-docker'], {
|
||||
cwd: FIXTURE_DIR,
|
||||
killAfter: 8000,
|
||||
killAfter: 16000,
|
||||
});
|
||||
|
||||
expect(proc.combinedStdOutErr).toContain('Successfully generated docs');
|
||||
@@ -41,12 +41,12 @@ describe('end-to-end', () => {
|
||||
});
|
||||
|
||||
it('can serve in mkdocs', async () => {
|
||||
jest.setTimeout(10000);
|
||||
jest.setTimeout(30000);
|
||||
const proc = await executeTechDocsCliCommand(
|
||||
['serve:mkdocs', '--no-docker'],
|
||||
{
|
||||
cwd: FIXTURE_DIR,
|
||||
killAfter: 8000,
|
||||
killAfter: 16000,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -55,10 +55,10 @@ describe('end-to-end', () => {
|
||||
});
|
||||
|
||||
it('can serve in backstage', async () => {
|
||||
jest.setTimeout(10000);
|
||||
jest.setTimeout(30000);
|
||||
const proc = await executeTechDocsCliCommand(['serve', '--no-docker'], {
|
||||
cwd: FIXTURE_DIR,
|
||||
killAfter: 8000,
|
||||
killAfter: 16000,
|
||||
});
|
||||
|
||||
expect(proc.combinedStdOutErr).toContain('Starting mkdocs server');
|
||||
|
||||
@@ -40,6 +40,7 @@ export const runMkdocsServer = async (options: {
|
||||
`${process.cwd()}:/content`,
|
||||
'-p',
|
||||
`${port}:${port}`,
|
||||
'-it',
|
||||
dockerImage,
|
||||
'serve',
|
||||
'--dev-addr',
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
execSync(`yarn workspace @techdocs/cli build`, { stdio: 'inherit' });
|
||||
execSync(`yarn workspace @techdocs/cli link`, { stdio: 'ignore' });
|
||||
execSync(`techdocs-cli ${args.join(' ')}`, { stdio: 'inherit' });
|
||||
execSync(`yarn workspace @techdocs/cli unlink`, { stdio: 'ignore' });
|
||||
Reference in New Issue
Block a user