cli-compiler
raw JSON → 0.1.35 verified Fri May 01 auth: no javascript
A compiler for CLI command definitions written in Markdown, transforming them into JavaScript modules. Integrated with the cli-command and cli-toolkit ecosystem, it supports multiple phases including parsing, rendering, variable replacement, and module generation. This package is at version 0.1.35, with no recent releases indicating active maintenance. It is designed for Node.js environments and lacks TypeScript type definitions. Key differentiator: it uses Markdown as the source format for CLI program definitions, allowing documentation and code generation from the same file.
Common errors
error Cannot find module 'cli-compiler' ↓
cause Package not installed or version mismatch.
fix
Run
npm install cli-compiler to install the package. error TypeError: compiler is not a function ↓
cause Default import is a function, but may be imported incorrectly.
fix
Use
import compiler from 'cli-compiler' (ESM) or const compiler = require('cli-compiler').default (CJS). error SyntaxError: Unexpected token in Markdown ↓
cause Markdown does not conform to the expected CLI format.
fix
Review the cli-command specification and ensure headings and definitions are correct.
Warnings
gotcha Input markdown must strictly follow the CLI-command Markdown specification; otherwise, parsing may fail silently or produce malformed output. ↓
fix Refer to the cli-command documentation for the exact Markdown format expected.
gotcha The compiler does not validate the generated JavaScript; lint your output separately. ↓
fix Run eslint or similar on the output file.
deprecated The compiler relies on deprecated Node.js APIs such as `fs.existsSync`. ↓
fix No fix available; consider using an alternative compiler.
Install
npm install cli-compiler yarn add cli-compiler pnpm add cli-compiler Imports
- default wrong
const compiler = require('cli-compiler');correctimport compiler from 'cli-compiler'; - compile wrong
import { Compiler } from 'cli-compiler';correctimport { compile } from 'cli-compiler'; - Phases wrong
import Phases from 'cli-compiler';correctimport { Phases } from 'cli-compiler';
Quickstart
import { compile } from 'cli-compiler';
import { writeFileSync } from 'fs';
const markdown = `
# myprogram
## hello
Greet the user.
*Usage:*
myprogram hello [name]
*Description:*
Say hello to a user.
`;
const result = compile(markdown, {
name: 'myprogram',
description: 'My CLI program'
});
writeFileSync('myprogram.js', result, 'utf8');
console.log('Compiled successfully.');