Skip to content

feat: introduced CLI mode to the parser #36

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

Merged
merged 10 commits into from
Jul 30, 2024
Merged
Changes from all 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
1 change: 0 additions & 1 deletion bin/.gitkeep

This file was deleted.

57 changes: 57 additions & 0 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

import { argv } from 'node:process';
import { resolve } from 'node:path';

import { Command, Option } from 'commander';

import createGenerator from '../src/generators.mjs';
import createLoader from '../src/loader.mjs';
import createParser from '../src/parser.mjs';
import generators from '../src/generators/index.mjs';

const program = new Command();

program
.name('api-docs-tooling')
.description('CLI tool to generate API documentation of a Node.js project.')
.requiredOption(
'-i, --input <patterns...>',
'Specify input file patterns using glob syntax'
)
.requiredOption('-o, --output <path>', 'Specify the output directory path')
.addOption(
new Option(
'-t, --target [mode...]',
'Set the processing target mode'
).choices(Object.keys(generators))
)
.parse(argv);

/**
* @typedef {keyof generators} Target A list of the available generator names.
*
* @typedef {Object} Options
* @property {Array<string>|string} input Specifies the glob/path for input files.
* @property {string} output Specifies the directory where output files will be saved.
* @property {Target} target Specifies the generator target mode.
*
* @name ProgramOptions
* @type {Options}
* @description The return type for values sent to the program from the CLI.
*/
const { input, output, target } = program.opts();

const { loadFiles } = createLoader();
const { parseApiDocs } = createParser();

const apiDocFiles = loadFiles(input);

const parsedApiDocs = await parseApiDocs(apiDocFiles);

const { runGenerators } = createGenerator(parsedApiDocs);

await runGenerators({
generators: target,
output: resolve(output),
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "@node-core/api-docs-tooling",
"scripts": {
"lint": "eslint .",
"format": "prettier --write .",
"prepare": "husky"
},
"bin": {
"api-docs-tooling": "./bin/cli.mjs"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"@types/node": "^20.14.10",
@@ -16,6 +20,7 @@
},
"dependencies": {
"github-slugger": "^2.0.0",
"commander": "^12.1.0",
"glob": "^11.0.0",
"remark": "^15.0.1",
"remark-gfm": "^4.0.0",
2 changes: 1 addition & 1 deletion src/generators/index.mjs
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@
import jsonSimple from './json-simple/index.mjs';
import legacyHtml from './legacy-html/index.mjs';

export default { jsonSimple, legacyHtml };
export default { 'json-simple': jsonSimple, 'legacy-html': legacyHtml };
2 changes: 1 addition & 1 deletion src/generators/json-simple/index.mjs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import { join } from 'node:path';
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
*/
export default {
name: 'jsonSimple',
name: 'json-simple',

version: '1.0.0',

2 changes: 1 addition & 1 deletion src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* @type {import('../types.d.ts').GeneratorMetadata<Input, void>}
*/
export default {
name: 'legacyHtml',
name: 'legacy-html',

version: '1.0.0',