2019-04-18 15:49:17 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
import { MarkdownFileParser } from './utils';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the skeleton of CLI documentation/reference web page at:
|
|
|
|
* https://www.balena.io/docs/reference/cli/
|
|
|
|
*
|
|
|
|
* The `getCapitanoDoc` function in this module parses README.md and adds
|
|
|
|
* some content to this object.
|
|
|
|
*/
|
|
|
|
const capitanoDoc = {
|
|
|
|
title: 'Balena CLI Documentation',
|
|
|
|
introduction: '',
|
|
|
|
categories: [
|
|
|
|
{
|
|
|
|
title: 'API keys',
|
|
|
|
files: ['build/actions/api-key.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Application',
|
|
|
|
files: ['build/actions/app.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Authentication',
|
|
|
|
files: ['build/actions/auth.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Device',
|
|
|
|
files: ['build/actions/device.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Environment Variables',
|
2019-04-02 11:26:21 +00:00
|
|
|
files: [
|
2019-09-06 13:43:53 +00:00
|
|
|
'build/actions-oclif/envs.js',
|
2019-04-02 11:26:21 +00:00
|
|
|
'build/actions-oclif/env/add.js',
|
2019-09-06 13:43:53 +00:00
|
|
|
'build/actions-oclif/env/rename.js',
|
2019-08-07 09:28:15 +00:00
|
|
|
'build/actions-oclif/env/rm.js',
|
2019-04-02 11:26:21 +00:00
|
|
|
],
|
2019-04-18 15:49:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Tags',
|
|
|
|
files: ['build/actions/tags.js'],
|
|
|
|
},
|
|
|
|
{
|
2019-06-24 15:51:07 +00:00
|
|
|
title: 'Help and Version',
|
|
|
|
files: ['build/actions/help.js', 'build/actions-oclif/version.js'],
|
2019-04-18 15:49:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Keys',
|
|
|
|
files: ['build/actions/keys.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Logs',
|
|
|
|
files: ['build/actions/logs.js'],
|
|
|
|
},
|
|
|
|
{
|
2019-06-05 22:17:59 +00:00
|
|
|
title: 'Network',
|
|
|
|
files: [
|
|
|
|
'build/actions/scan.js',
|
|
|
|
'build/actions/ssh.js',
|
|
|
|
'build/actions/tunnel.js',
|
|
|
|
],
|
2019-04-18 15:49:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Notes',
|
|
|
|
files: ['build/actions/notes.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'OS',
|
2019-10-31 01:46:14 +00:00
|
|
|
files: ['build/actions/os.js', 'build/actions-oclif/os/configure.js'],
|
2019-04-18 15:49:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Config',
|
|
|
|
files: ['build/actions/config.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Preload',
|
|
|
|
files: ['build/actions/preload.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Push',
|
|
|
|
files: ['build/actions/push.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Settings',
|
|
|
|
files: ['build/actions/settings.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Local',
|
|
|
|
files: ['build/actions/local/index.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Deploy',
|
|
|
|
files: ['build/actions/build.js', 'build/actions/deploy.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Platform',
|
|
|
|
files: ['build/actions/join.js', 'build/actions/leave.js'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Utilities',
|
|
|
|
files: ['build/actions/util.js'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify and return the `capitanoDoc` object above in order to render the
|
|
|
|
* CLI documentation/reference web page at:
|
|
|
|
* https://www.balena.io/docs/reference/cli/
|
|
|
|
*
|
|
|
|
* This function parses the README.md file to extract relevant sections
|
|
|
|
* for the documentation web page.
|
|
|
|
*/
|
|
|
|
export async function getCapitanoDoc(): Promise<typeof capitanoDoc> {
|
|
|
|
const readmePath = path.join(__dirname, '..', '..', 'README.md');
|
|
|
|
const mdParser = new MarkdownFileParser(readmePath);
|
2019-04-29 15:33:09 +00:00
|
|
|
const sections: string[] = await Promise.all([
|
2019-04-18 15:49:17 +00:00
|
|
|
mdParser.getSectionOfTitle('About').then((sectionLines: string) => {
|
|
|
|
// delete the title of the 'About' section for the web page
|
|
|
|
const match = /^(#+)\s+.+?\n\s*([^]*)/.exec(sectionLines);
|
|
|
|
if (!match || match.length < 3) {
|
|
|
|
throw new Error(`Error parsing section title`);
|
|
|
|
}
|
|
|
|
// match[1] has the title, match[2] has the rest
|
|
|
|
return match && match[2];
|
|
|
|
}),
|
|
|
|
mdParser.getSectionOfTitle('Installation'),
|
|
|
|
mdParser.getSectionOfTitle('Getting Started'),
|
|
|
|
mdParser.getSectionOfTitle('Support, FAQ and troubleshooting'),
|
2019-04-29 15:33:09 +00:00
|
|
|
]);
|
|
|
|
capitanoDoc.introduction = sections.join('\n');
|
|
|
|
return capitanoDoc;
|
2019-04-18 15:49:17 +00:00
|
|
|
}
|