mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Spencer <email@spalger.com> Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
427bb03e83
commit
4b07efd597
4 changed files with 65 additions and 59 deletions
|
@ -7,4 +7,4 @@
|
|||
*/
|
||||
|
||||
require('../src/setup_node_env');
|
||||
require('../src/docs/cli');
|
||||
require('../src/dev/run_build_docs_cli').runBuildDocsCli();
|
||||
|
|
64
src/dev/run_build_docs_cli.ts
Normal file
64
src/dev/run_build_docs_cli.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import Path from 'path';
|
||||
|
||||
import dedent from 'dedent';
|
||||
import { run, REPO_ROOT, createFailError } from '@kbn/dev-utils';
|
||||
|
||||
const DEFAULT_DOC_REPO_PATH = Path.resolve(REPO_ROOT, '..', 'docs');
|
||||
|
||||
const rel = (path: string) => Path.relative(process.cwd(), path);
|
||||
|
||||
export function runBuildDocsCli() {
|
||||
run(
|
||||
async ({ flags, procRunner }) => {
|
||||
const docRepoPath =
|
||||
typeof flags.docrepo === 'string' && flags.docrepo
|
||||
? Path.resolve(process.cwd(), flags.docrepo)
|
||||
: DEFAULT_DOC_REPO_PATH;
|
||||
|
||||
try {
|
||||
await procRunner.run('build_docs', {
|
||||
cmd: rel(Path.resolve(docRepoPath, 'build_docs')),
|
||||
args: [
|
||||
['--doc', rel(Path.resolve(REPO_ROOT, 'docs/index.asciidoc'))],
|
||||
['--chunk', '1'],
|
||||
flags.open ? ['--open'] : [],
|
||||
].flat(),
|
||||
cwd: REPO_ROOT,
|
||||
wait: true,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
throw createFailError(dedent`
|
||||
Unable to run "build_docs" script from docs repo.
|
||||
Does it exist at [${rel(docRepoPath)}]?
|
||||
Do you need to pass --docrepo to specify the correct path or clone it there?
|
||||
`);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{
|
||||
description: 'Build the docs and serve them from a docker container',
|
||||
flags: {
|
||||
string: ['docrepo'],
|
||||
boolean: ['open'],
|
||||
default: {
|
||||
docrepo: DEFAULT_DOC_REPO_PATH,
|
||||
},
|
||||
help: `
|
||||
--docrepo [path] Path to the doc repo, defaults to ${rel(DEFAULT_DOC_REPO_PATH)}
|
||||
--open Automatically open the built docs in your default browser after building
|
||||
`,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { execFileSync } from 'child_process';
|
||||
import { Command } from 'commander';
|
||||
|
||||
import { defaultDocsRepoPath, buildDocsScript, buildDocsArgs } from './docs_repo';
|
||||
|
||||
const cmd = new Command('node scripts/docs');
|
||||
cmd
|
||||
.option('--docrepo [path]', 'local path to the docs repo', defaultDocsRepoPath())
|
||||
.option('--open', 'open the docs in the browser', false)
|
||||
.parse(process.argv);
|
||||
|
||||
try {
|
||||
execFileSync(buildDocsScript(cmd), buildDocsArgs(cmd));
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
console.error(`elastic/docs repo must be cloned to ${cmd.docrepo}`);
|
||||
} else {
|
||||
console.error(err.stack);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
|
||||
const kibanaDir = resolve(__dirname, '..', '..');
|
||||
|
||||
export function buildDocsScript(cmd) {
|
||||
return resolve(process.cwd(), cmd.docrepo, 'build_docs');
|
||||
}
|
||||
|
||||
export function buildDocsArgs(cmd) {
|
||||
const docsIndexFile = resolve(kibanaDir, 'docs', 'index.asciidoc');
|
||||
let args = ['--doc', docsIndexFile, '--direct_html', '--chunk=1'];
|
||||
if (cmd.open) {
|
||||
args = [...args, '--open'];
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
export function defaultDocsRepoPath() {
|
||||
return resolve(kibanaDir, '..', 'docs');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue