infographic-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2025-01-20
9
+
10
+ ### Added
11
+ - Initial release of `@antv/infographic-cli`
12
+ - Simple command `ifgc` to render infographics from .info files to SVG
13
+ - Support for 236+ built-in infographic templates
14
+ - `template` command to list all available templates
15
+ - Theme support (`--theme` option)
16
+ - Background color customization (`--background` option)
17
+ - Config file support (`--config` option)
18
+ - Stdin input support for AI integration
19
+ - Comprehensive test suite (26 tests)
20
+
21
+ ### Features
22
+ - Render from file: `ifgc -i input.info -o output.svg`
23
+ - Render from stdin: `echo "..." | ifgc -o output.svg`
24
+ - List templates: `ifgc template`
25
+ - Automatic output file naming (defaults to input.svg)
26
+ - Quiet mode for script usage (`--quiet`)
27
+
28
+ ### Dependencies
29
+ - `@antv/infographic` ^0.2.11
30
+ - `chalk` ^5.4.1
31
+ - `commander` ^12.1.0
32
+
33
+ [0.1.0]: https://github.com/lyw405/infographic-cli/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lyw405
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # @antv/infographic-cli
2
+
3
+ [![npm version](https://badge.fury.io/js/%40antv%2Finfographic-cli.svg)](https://www.npmjs.com/package/@antv/infographic-cli)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js Version](https://img.shields.io/node/v/%40antv%2Finfographic-cli.svg)](https://www.npmjs.com/package/@antv/infographic-cli)
6
+
7
+ Command-line interface for [AntV Infographic](https://github.com/antvis/Infographic) - render declarative infographic syntax to SVG images.
8
+
9
+ ## Quick Start
10
+
11
+ ```bash
12
+ # Install
13
+ npm install -g @antv/infographic-cli
14
+
15
+ # Render from stdin
16
+ echo 'infographic list-row-simple-horizontal-arrow
17
+ data
18
+ title My First Infographic
19
+ items
20
+ - label Step 1
21
+ - label Step 2' | ifgc -o output.svg
22
+
23
+ # Render from file
24
+ ifgc -i input.info -o output.svg
25
+
26
+ # List available templates
27
+ ifgc template
28
+ ```
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install -g @antv/infographic-cli
34
+ ```
35
+
36
+ This installs two commands: `ifgc` (short) and `infographic` (long).
37
+
38
+ ## Usage
39
+
40
+ ### Basic Rendering
41
+
42
+ ```bash
43
+ # From file (output defaults to input.svg)
44
+ ifgc -i input.info
45
+
46
+ # Specify output file
47
+ ifgc -i input.info -o output.svg
48
+
49
+ # From stdin
50
+ echo '...' | ifgc -o output.svg
51
+
52
+ # From stdin with file input
53
+ cat input.info | ifgc -o output.svg
54
+ ```
55
+
56
+ ### Options
57
+
58
+ | Option | Description |
59
+ |--------|-------------|
60
+ | `-i, --input <file>` | Input .info file (omit to read from stdin) |
61
+ | `-o, --output <file>` | Output file (default: input.svg) |
62
+ | `--background <color>` | Background color (default: transparent) |
63
+ | `-c, --config <file>` | JSON configuration file |
64
+ | `-t, --theme <name>` | Theme name |
65
+ | `-q, --quiet` | Suppress log output |
66
+
67
+ ### List Templates
68
+
69
+ ```bash
70
+ ifgc template
71
+ ```
72
+
73
+ Visit [AntV Infographic](https://github.com/antvis/Infographic) to see template previews.
74
+
75
+ ## Examples
76
+
77
+ ### Example 1: Simple Step List
78
+
79
+ ```bash
80
+ cat > steps.info << EOF
81
+ infographic list-row-simple-horizontal-arrow
82
+ data
83
+ title Getting Started
84
+ desc Three simple steps to begin
85
+ items
86
+ - label Step 1
87
+ desc Install the package
88
+ - label Step 2
89
+ desc Create your first infographic
90
+ - label Step 3
91
+ desc Export and share
92
+ EOF
93
+
94
+ ifgc -i steps.info -o steps.svg
95
+ ```
96
+
97
+ ### Example 2: Timeline
98
+
99
+ ```bash
100
+ cat > timeline.info << EOF
101
+ infographic timeline-horizontal-basic-date
102
+ data
103
+ title Project Roadmap
104
+ items
105
+ - label Q1
106
+ desc Planning
107
+ - label Q2
108
+ desc Development
109
+ - label Q3
110
+ desc Testing
111
+ - label Q4
112
+ desc Launch
113
+ EOF
114
+
115
+ ifgc -i timeline.info -o timeline.svg
116
+ ```
117
+
118
+ ### Example 3: Using Theme
119
+
120
+ ```bash
121
+ cat > swot.info << EOF
122
+ infographic compare-quadrant-four-areas-card
123
+ data
124
+ title SWOT Analysis
125
+ items
126
+ - label Strengths
127
+ desc Internal advantages
128
+ - label Weaknesses
129
+ desc Internal limitations
130
+ - label Opportunities
131
+ desc External possibilities
132
+ - label Threats
133
+ desc External risks
134
+ EOF
135
+
136
+ ifgc -i swot.info -o swot.svg -t dark
137
+ ```
138
+
139
+ ### Example 4: From stdin
140
+
141
+ ```bash
142
+ echo 'infographic list-row-simple-horizontal-arrow
143
+ data
144
+ title Quick Tasks
145
+ items
146
+ - label Task A
147
+ - label Task B
148
+ - label Task C' | ifgc -o tasks.svg
149
+ ```
150
+
151
+ ## Output Format
152
+
153
+ ### SVG (Default)
154
+
155
+ Infographic is a vector graphics format, perfect for:
156
+
157
+ - **Web use** - Scalable, interactive, small file size
158
+ - **Documentation** - GitHub, GitLab, Notion, etc.
159
+ - **Design tools** - Figma, Sketch, Illustrator
160
+ - **Code documentation** - Docusaurus, VitePress, etc.
161
+
162
+ ### Converting to PNG
163
+
164
+ If you need PNG for specific use cases, you can convert the SVG:
165
+
166
+ **Online tools**:
167
+ - [SVG to PNG](https://svgtopng.com/)
168
+ - [CloudConvert](https://cloudconvert.com/svg-to-png)
169
+
170
+ **Command line** (requires additional tools):
171
+ - ImageMagick: `convert output.svg output.png`
172
+ - Node.js with sharp: `sharp('output.svg').png().toFile('output.png')`
173
+
174
+ ## Infographic Syntax
175
+
176
+ Learn more about the declarative infographic syntax at [antvis/Infographic](https://github.com/antvis/Infographic).
177
+
178
+ ## See Also
179
+
180
+ - [AntV Infographic](https://github.com/antvis/Infographic) - The core library
181
+ - [Infographic Documentation](https://infographic.antv.vision/) - Official documentation
182
+ - [Infographic Editor](https://infographic.antv.vision/examples) - Online examples
183
+
184
+ ## License
185
+
186
+ MIT &copy; 2026 [lyw405](https://github.com/lyw405)
187
+
188
+ ## Changelog
189
+
190
+ See [CHANGELOG.md](CHANGELOG.md) for a list of changes in each version.
package/dist/cli.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { error } from './utils/error.js';
3
+ import { program } from './index.js';
4
+ try {
5
+ await program.parseAsync(process.argv);
6
+ }
7
+ catch (err) {
8
+ error(err instanceof Error ? err.message : String(err));
9
+ }
@@ -0,0 +1,59 @@
1
+ import fs from 'fs/promises';
2
+ import { renderToString } from '@antv/infographic/ssr';
3
+ import { error, info, success } from '../utils/error.js';
4
+ import { getInputData } from '../utils/input.js';
5
+ import { getDefaultOutput, writeOutput } from '../utils/output.js';
6
+ export async function renderCommand(options) {
7
+ const { input, output: userOutput, quiet, config: configFile, theme, } = options;
8
+ const log = quiet ? () => { } : info;
9
+ // Validate input
10
+ if (input && input !== '-') {
11
+ try {
12
+ await fs.access(input);
13
+ }
14
+ catch {
15
+ error(`Input file "${input}" doesn't exist`);
16
+ }
17
+ }
18
+ // Read config file if provided
19
+ let config = {};
20
+ if (configFile) {
21
+ try {
22
+ const configContent = await fs.readFile(configFile, 'utf-8');
23
+ config = JSON.parse(configContent);
24
+ }
25
+ catch {
26
+ error(`Configuration file "${configFile}" is invalid or doesn't exist`);
27
+ }
28
+ }
29
+ // Merge CLI options with config
30
+ if (theme)
31
+ config.theme = theme;
32
+ // Determine output file (always SVG)
33
+ let output = userOutput;
34
+ if (!output) {
35
+ const actualInput = input && input !== '-' ? input : undefined;
36
+ output = getDefaultOutput(actualInput);
37
+ }
38
+ else if (output === '-') {
39
+ output = '/dev/stdout';
40
+ }
41
+ // Read input data
42
+ const inputData = await getInputData(input && input !== '-' ? input : undefined);
43
+ if (!inputData.trim()) {
44
+ error('No input data provided');
45
+ }
46
+ log(`Rendering infographic...`);
47
+ try {
48
+ // Render using SSR
49
+ const svgString = await renderToString(inputData, config);
50
+ await writeOutput(output, svgString);
51
+ if (output !== '/dev/stdout') {
52
+ success(`Infographic rendered to ${output}`);
53
+ }
54
+ }
55
+ catch (err) {
56
+ const message = err instanceof Error ? err.message : String(err);
57
+ error(`Failed to render: ${message}`);
58
+ }
59
+ }
@@ -0,0 +1,11 @@
1
+ import { getTemplates } from '@antv/infographic';
2
+ import { info } from '../utils/error.js';
3
+ export async function templateCommand() {
4
+ const templates = getTemplates();
5
+ info(`Available templates (${templates.length}):\n`);
6
+ for (const templateName of templates) {
7
+ console.log(` • ${templateName}`);
8
+ }
9
+ console.log('');
10
+ console.log('📖 Visit https://github.com/antvis/Infographic to see template previews and examples');
11
+ }
@@ -0,0 +1,33 @@
1
+ import { parseSyntax } from '@antv/infographic';
2
+ import { error, success, warn } from '../utils/error.js';
3
+ import { getInputData } from '../utils/input.js';
4
+ export async function validateCommand(input) {
5
+ const inputData = await getInputData(input);
6
+ if (!inputData.trim()) {
7
+ error('No input data provided');
8
+ }
9
+ const result = parseSyntax(inputData);
10
+ if (result.errors.length > 0) {
11
+ console.error('\nSyntax errors:\n');
12
+ for (const err of result.errors) {
13
+ console.error(` • ${err.message}`);
14
+ console.error(` at line ${err.line}`);
15
+ if (err.raw) {
16
+ console.error(` near: ${err.raw.substring(0, 50)}...`);
17
+ }
18
+ }
19
+ console.error('');
20
+ process.exit(1);
21
+ }
22
+ if (result.warnings.length > 0) {
23
+ warn('Syntax validated with warnings:\n');
24
+ for (const warning of result.warnings) {
25
+ console.warn(` • ${warning.message}`);
26
+ console.warn(` at line ${warning.line}`);
27
+ }
28
+ console.warn('');
29
+ }
30
+ else {
31
+ success('Syntax is valid!');
32
+ }
33
+ }
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { renderCommand } from './commands/render.js';
4
+ import { templateCommand } from './commands/template.js';
5
+ import { error } from './utils/error.js';
6
+ const packageJson = await import('../package.json', {
7
+ with: { type: 'json' },
8
+ });
9
+ const program = new Command();
10
+ program
11
+ .name('ifgc')
12
+ .description('Command-line interface for AntV Infographic - render declarative infographics to SVG')
13
+ .version(packageJson.default.version);
14
+ // Main options (render by default, like mmdc)
15
+ program
16
+ .option('-i, --input <file>', 'Input .info file (omit to read from stdin)')
17
+ .option('-o, --output <file>', 'Output file (default: input file with .svg extension)')
18
+ .option('--background <color>', 'Background color (default: transparent)', 'transparent')
19
+ .option('-c, --config <file>', 'JSON configuration file')
20
+ .option('-t, --theme <name>', 'Theme name')
21
+ .option('-q, --quiet', 'Suppress log output')
22
+ .action(async (options) => {
23
+ try {
24
+ await renderCommand(options);
25
+ }
26
+ catch (err) {
27
+ error(err instanceof Error ? err.message : String(err));
28
+ }
29
+ });
30
+ // Template subcommand (helper)
31
+ program
32
+ .command('template')
33
+ .description('List available infographic templates')
34
+ .action(async () => {
35
+ try {
36
+ await templateCommand();
37
+ }
38
+ catch (err) {
39
+ error(err instanceof Error ? err.message : String(err));
40
+ }
41
+ });
42
+ export { program };
@@ -0,0 +1,11 @@
1
+ import chalk from 'chalk';
2
+ export function error(message) {
3
+ console.error(chalk.red(`\n✖ ${message}\n`));
4
+ process.exit(1);
5
+ }
6
+ export function info(message) {
7
+ console.info(chalk.cyan(message));
8
+ }
9
+ export function success(message) {
10
+ console.info(chalk.green(`\n✔ ${message}\n`));
11
+ }
@@ -0,0 +1,23 @@
1
+ import fs from 'fs/promises';
2
+ import readline from 'readline';
3
+ export async function getInputData(inputFile) {
4
+ if (inputFile) {
5
+ return await fs.readFile(inputFile, 'utf-8');
6
+ }
7
+ return await new Promise((resolve, reject) => {
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ crlfDelay: Infinity,
11
+ });
12
+ let data = '';
13
+ rl.on('line', (line) => {
14
+ data += line + '\n';
15
+ });
16
+ rl.on('close', () => {
17
+ resolve(data);
18
+ });
19
+ rl.on('error', (err) => {
20
+ reject(err);
21
+ });
22
+ });
23
+ }
@@ -0,0 +1,19 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ export async function writeOutput(output, data) {
4
+ if (output === '/dev/stdout') {
5
+ process.stdout.write(data);
6
+ }
7
+ else {
8
+ const outputDir = path.dirname(output);
9
+ await fs.mkdir(outputDir, { recursive: true });
10
+ await fs.writeFile(output, data);
11
+ }
12
+ }
13
+ export function getDefaultOutput(input) {
14
+ if (input) {
15
+ const inputWithoutExt = input.replace(/\.(info|txt)$/, '');
16
+ return `${inputWithoutExt}.svg`;
17
+ }
18
+ return 'out.svg';
19
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,9 @@
1
+ export interface RenderOptions {
2
+ input?: string;
3
+ output?: string;
4
+ background?: string;
5
+ quiet?: boolean;
6
+ config?: string;
7
+ theme?: string;
8
+ }
9
+ export declare function renderCommand(options: RenderOptions): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function templateCommand(): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function validateCommand(input?: string): Promise<void>;
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ declare const program: Command;
4
+ export { program };
@@ -0,0 +1,3 @@
1
+ export declare function error(message: string): never;
2
+ export declare function info(message: string): void;
3
+ export declare function success(message: string): void;
@@ -0,0 +1 @@
1
+ export declare function getInputData(inputFile: string | undefined): Promise<string>;
@@ -0,0 +1,2 @@
1
+ export declare function writeOutput(output: string, data: string | Buffer): Promise<void>;
2
+ export declare function getDefaultOutput(input: string | undefined): string;
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "infographic-cli",
3
+ "version": "0.1.0",
4
+ "description": "Command-line interface for AntV Infographic",
5
+ "license": "MIT",
6
+ "author": "lyw405",
7
+ "type": "module",
8
+ "bin": {
9
+ "ifgc": "./dist/cli.js",
10
+ "infographic": "./dist/cli.js"
11
+ },
12
+ "engines": {
13
+ "node": "^18.19 || >=20.0"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist-types/index.d.ts"
18
+ }
19
+ },
20
+ "types": "./dist-types/index.d.ts",
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "dev": "tsc --watch",
24
+ "lint": "eslint src",
25
+ "test": "vitest --run",
26
+ "test:examples": "vitest --run __tests__/integration/examples.test.ts",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "dependencies": {
30
+ "@antv/infographic": "^0.2.11",
31
+ "chalk": "^5.4.1",
32
+ "commander": "^12.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^24.3.1",
36
+ "@typescript-eslint/eslint-plugin": "^8.53.1",
37
+ "@typescript-eslint/parser": "^8.53.1",
38
+ "eslint": "^9.39.2",
39
+ "eslint-plugin-import": "^2.32.0",
40
+ "globals": "^17.0.0",
41
+ "typescript": "^5.9.2",
42
+ "vitest": "^3.2.4"
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "dist-types",
47
+ "README.md",
48
+ "CHANGELOG.md",
49
+ "LICENSE"
50
+ ],
51
+ "keywords": [
52
+ "infographic",
53
+ "cli",
54
+ "visualization",
55
+ "antv"
56
+ ]
57
+ }