Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update usage documentation for new commands #556

Merged
merged 22 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
"build": "rimraf lib && node scripts/fetch-asyncapi-example.js && tsc && echo \"Build Completed\"",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
"dev": "tsc --watch",
"generate:assets": "npm run generate:readme:toc",
"generate:assets": "npm run generate:readme:toc && npm run generate:commands",
"generate:commands": "node scripts/update_usage_docs.js",
"generate:readme:toc": "markdown-toc -i README.md",
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"lint:fix": "eslint --max-warnings 5 --config .eslintrc . --fix",
Expand Down
50 changes: 50 additions & 0 deletions scripts/update_usage_docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require('fs').promises;
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
const { exec } = require('child_process');

// Define the paths to the README and usage files
const README_PATH = './scripts/README.md'; // File path for the generated README file
const USAGE_PATH = './docs/usage.md'; // File path for the usage documentation file

// Append usage and commands tags to the README file
// These tags are later replaced by the `oclif readme` command with actual usage documentation
fs.appendFile(README_PATH, '\n\n# Usage\n\n<!-- usage -->\n\n# Commands\n\n<!-- commands -->\n')
.then(() => {
// Generate the usage documentation using the `oclif readme` command
return new Promise((resolve, reject) => {
exec('oclif readme', { cwd: './scripts' }, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
})
.then(() => {
// Define the header for the usage file
const header = `---
title: 'Usage'
weight: 40
---

The AsyncAPI CLI makes it easier to work with AsyncAPI documents.
`;

// Write the header to the usage file
return fs.writeFile(USAGE_PATH, header);
})
.then(() => {
// Read the contents of the README file
return fs.readFile(README_PATH, 'utf8');
})
.then((readmeContents) => {
// Append the README contents to the usage file
return fs.writeFile(USAGE_PATH, readmeContents, { flag: 'a' });
})
.then(() => {
// Remove the generated README file
return fs.unlink(README_PATH);
})
.catch((err) => {
console.error(err);
});