infographic-gen 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xxMudCloudxx
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,419 @@
1
+ # infographic-gen
2
+
3
+ AI-powered CLI tool to generate [AntV Infographic](https://infographic.antv.vision/) SVGs from natural language prompts.
4
+
5
+ Transform your ideas into beautiful, data-driven infographics in seconds using the power of large language models and AntV's professional infographic templates.
6
+
7
+ ---
8
+
9
+ ## ✨ Features
10
+
11
+ - **Natural Language Input** — Describe your infographic in plain English or Chinese
12
+ - **AI-Powered Generation** — Uses OpenAI, DeepSeek, or other LLM providers via OpenAI SDK
13
+ - **Professional Templates** — 60+ pre-designed AntV Infographic templates (lists, sequences, hierarchies, comparisons, charts, relations, etc.)
14
+ - **Self-Correcting** — Automatically retries with error feedback if generation fails (up to 3 attempts)
15
+ - **Persistent Config** — Save API keys and settings locally for repeat use
16
+ - **Automated Sync** — Weekly checks for upstream Infographic updates via GitHub Actions
17
+ - **Fully Tested** — 131 comprehensive tests covering all features
18
+
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ### Global Installation (Recommended for CLI use)
24
+
25
+ ```bash
26
+ npm install -g infographic-gen
27
+ ```
28
+
29
+ After installation, you can use the CLI from anywhere:
30
+
31
+ ```bash
32
+ infographic-gen generate "A timeline of AI breakthroughs"
33
+ infographic-gen config set apiKey sk-...
34
+ ```
35
+
36
+ ### Local Installation (for development)
37
+
38
+ ```bash
39
+ git clone https://github.com/yourusername/infographic-gen.git
40
+ cd infographic-gen
41
+ npm install
42
+ npm run build
43
+ npm start # Run built CLI
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 🚀 Quick Start
49
+
50
+ ### 1. Configure Your LLM Provider
51
+
52
+ ```bash
53
+ infographic-gen config set apiKey sk-xxxx123
54
+ infographic-gen config set baseUrl https://api.openai.com/v1 # Optional
55
+ infographic-gen config set modelName gpt-4o # Optional
56
+ ```
57
+
58
+ **Supported Providers:**
59
+
60
+ - **OpenAI** ← Default
61
+ - **DeepSeek** — Set `baseUrl` to `https://api.deepseek.com`
62
+ - **Alibaba Cloud** (DashScope) — Set `baseUrl` with your endpoint
63
+ - Any service compatible with OpenAI SDK
64
+
65
+ View your config:
66
+
67
+ ```bash
68
+ infographic-gen config list
69
+ infographic-gen config path # Show config file location
70
+ ```
71
+
72
+ ### 2. Generate an Infographic
73
+
74
+ ```bash
75
+ infographic-gen generate "A comparison of frontend frameworks"
76
+ ```
77
+
78
+ Output: `infographic-output.svg` (in current directory)
79
+
80
+ Specify output path:
81
+
82
+ ```bash
83
+ infographic-gen gen "Data visualization trends" --output my-chart.svg
84
+ ```
85
+
86
+ ### 3. Get Help
87
+
88
+ ```bash
89
+ infographic-gen --help
90
+ infographic-gen config --help
91
+ infographic-gen generate --help
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 💡 Usage Examples
97
+
98
+ ### Example 1: Technology Timeline
99
+
100
+ ```bash
101
+ infographic-gen gen "A timeline showing the evolution of web technologies from HTTP/1.0 to HTTP/3"
102
+ ```
103
+
104
+ Will generate a timeline with key milestones, automatically selecting an appropriate template.
105
+
106
+ ### Example 2: Comparison Matrix
107
+
108
+ ```bash
109
+ infographic-gen gen "Compare the pros and cons of monolithic vs microservices architecture"
110
+ ```
111
+
112
+ Generates a comparison infographic with Strengths and Weaknesses categories.
113
+
114
+ ### Example 3: Data Chart
115
+
116
+ ```bash
117
+ infographic-gen gen "Show the distribution of programming languages by usage: Python 35%, JavaScript 28%, Java 20%, C++ 12%, Other 5%"
118
+ ```
119
+
120
+ Creates a pie/bar chart with the provided data.
121
+
122
+ ---
123
+
124
+ ## 🛠️ Development
125
+
126
+ ### Setup
127
+
128
+ ```bash
129
+ git clone https://github.com/yourusername/infographic-gen.git
130
+ cd infographic-gen
131
+ npm install
132
+ ```
133
+
134
+ ### Commands
135
+
136
+ | Command | Purpose |
137
+ | -------------------- | ----------------------------------------- |
138
+ | `npm run build` | Build CLI to `dist/index.js` |
139
+ | `npm run dev` | Watch mode (rebuild on file changes) |
140
+ | `npm start` | Run built CLI |
141
+ | `npm test` | Run full test suite (vitest) |
142
+ | `npm run test:watch` | Watch mode for tests |
143
+ | `npm run sync` | Check & update upstream @antv/infographic |
144
+ | `npm run sync:check` | Dry-run: check without updating |
145
+
146
+ ### Project Structure
147
+
148
+ ```
149
+ infographic-gen/
150
+ ├── src/
151
+ │ ├── index.ts # CLI entry point
152
+ │ ├── config/index.ts # Config store (conf library)
153
+ │ ├── utils/
154
+ │ │ ├── logger.ts # Colored output to stderr
155
+ │ │ └── spinner.ts # Ora spinner wrapper
156
+ │ └── core/
157
+ │ ├── prompts.ts # System prompts (60+ templates)
158
+ │ ├── ai.ts # OpenAI integration + self-correction
159
+ │ └── render.ts # @antv/infographic SSR rendering
160
+ ├── __tests__/ # 131 tests across 7 test files
161
+ ├── scripts/
162
+ │ └── sync-upstream.mjs # Upstream change detection
163
+ ├── .github/workflows/ # CI/CD automation
164
+ ├── package.json
165
+ ├── tsup.config.ts # Build config
166
+ ├── vitest.config.ts # Test config
167
+ └── tsconfig.json
168
+ ```
169
+
170
+ ### Adding New Features
171
+
172
+ The pipeline is straightforward:
173
+
174
+ 1. **User Input** → Commander parses CLI args
175
+ 2. **Config** → Loads LLM settings from persistent store
176
+ 3. **AI Generation** → `generateInfographicDSL()` calls LLM with system prompt
177
+ 4. **Rendering** → `renderDSLToSVG()` uses @antv/infographic SSR
178
+ 5. **Self-Correction** → If render fails, retry with error feedback (max 3 times)
179
+ 6. **Output** → Write SVG to file
180
+
181
+ ---
182
+
183
+ ## 📋 Configuration
184
+
185
+ Config is stored in:
186
+
187
+ - **macOS/Linux** — `~/.config/infographic-gen/config.json`
188
+ - **Windows** — `%APPDATA%\infographic-gen\config.json`
189
+
190
+ ### Configurable Keys
191
+
192
+ | Key | Type | Example | Notes |
193
+ | ----------- | ------ | --------------------------- | ------------------------------------------- |
194
+ | `apiKey` | string | `sk-...` | Your LLM API key |
195
+ | `baseUrl` | string | `https://api.openai.com/v1` | LLM endpoint (optional) |
196
+ | `modelName` | string | `gpt-4o` | Model to use (optional, defaults to gpt-4o) |
197
+ | `provider` | string | `openai` | For reference only |
198
+
199
+ Manage config via CLI:
200
+
201
+ ```bash
202
+ # Set
203
+ infographic-gen config set apiKey sk-...
204
+ infographic-gen config set baseUrl https://api.deepseek.com
205
+
206
+ # Get
207
+ infographic-gen config get apiKey
208
+
209
+ # List all
210
+ infographic-gen config list
211
+
212
+ # Delete
213
+ infographic-gen config delete baseUrl
214
+
215
+ # Show config file path
216
+ infographic-gen config path
217
+ ```
218
+
219
+ ---
220
+
221
+ ## 🔄 Upstream Synchronization
222
+
223
+ The tool automatically tracks upstream changes in `@antv/infographic`:
224
+
225
+ ### What is Monitored?
226
+
227
+ 1. **npm Package Version** — Detects version updates
228
+ 2. **SKILL.md Files** — The syntax specifications and template lists that guide the LLM
229
+
230
+ ### How It Works
231
+
232
+ - **Weekly Check** — GitHub Actions runs every Monday (UTC 08:00)
233
+ - **Manual Check** — Run `npm run sync:check` anytime
234
+ - **Auto-Update** — Snapshot files stored in `.upstream-snapshots/`
235
+ - **PR Creation** — If changes detected, a PR is created automatically
236
+ - **Manual Review** — You review the SKILL.md changes and update `src/core/prompts.ts` if needed
237
+
238
+ ### Local Usage
239
+
240
+ ```bash
241
+ # Check for updates (dry-run)
242
+ npm run sync:check
243
+
244
+ # Apply updates
245
+ npm run sync
246
+ ```
247
+
248
+ ---
249
+
250
+ ## 📤 Publishing to npm
251
+
252
+ ### Automatic Publishing (GitHub Actions)
253
+
254
+ When you push a tagged release, GitHub Actions automatically publishes to npm:
255
+
256
+ 1. **Create a git tag** (follows semantic versioning):
257
+
258
+ ```bash
259
+ git tag v1.0.1
260
+ git push origin v1.0.1
261
+ ```
262
+
263
+ 2. **GitHub Actions will**:
264
+ - Build the project
265
+ - Run all tests
266
+ - Publish to npm registry
267
+ - Create a GitHub Release with release notes
268
+
269
+ ### Manual Publishing
270
+
271
+ If you need to publish manually:
272
+
273
+ ```bash
274
+ npm run build # Build first
275
+ npm publish # Requires npm login
276
+ ```
277
+
278
+ ### Before Publishing
279
+
280
+ - Ensure `npm test` passes
281
+ - Update `CHANGELOG.md` with notable changes
282
+ - Bump version in `package.json` using semantic versioning:
283
+ - **MAJOR** (x.0.0) — Breaking changes
284
+ - **MINOR** (1.x.0) — New features
285
+ - **PATCH** (1.0.x) — Bug fixes
286
+
287
+ ### npm Registry Setup
288
+
289
+ The package is configured with:
290
+
291
+ ```json
292
+ {
293
+ "name": "infographic-gen",
294
+ "version": "1.0.0",
295
+ "license": "MIT",
296
+ "type": "module",
297
+ "bin": {
298
+ "infographic-gen": "./dist/index.js"
299
+ },
300
+ "files": ["dist"],
301
+ "engines": { "node": ">=18.0.0" }
302
+ }
303
+ ```
304
+
305
+ When published:
306
+
307
+ - Only `dist/` folder is included (via `"files"` field)
308
+ - Bin entry creates a global `infographic-gen` command
309
+ - ESM-only, Node.js 18+ required
310
+
311
+ ---
312
+
313
+ ## 🏗️ GitHub Actions Workflows
314
+
315
+ Two workflows are configured:
316
+
317
+ ### 1. `sync-upstream.yml` — Upstream Change Detection
318
+
319
+ - Runs weekly (Monday, 08:00 UTC)
320
+ - Detects `@antv/infographic` version updates
321
+ - Checks for SKILL.md changes
322
+ - Creates a PR if changes found
323
+
324
+ ### 2. `publish.yml` — Publish to npm
325
+
326
+ - Triggers on git tag push (v*.*.\*)
327
+ - Builds and tests
328
+ - Publishes to npm
329
+ - Creates GitHub Release
330
+
331
+ ---
332
+
333
+ ## 🧪 Testing
334
+
335
+ Run tests with vitest:
336
+
337
+ ```bash
338
+ npm test # Single run
339
+ npm run test:watch # Watch mode
340
+ ```
341
+
342
+ Test coverage:
343
+
344
+ - **131 tests** across 7 test files
345
+ - Config management (persistent storage)
346
+ - Logger & spinner utilities
347
+ - AI prompt engineering
348
+ - SSR rendering
349
+ - Command integration
350
+ - CLI end-to-end
351
+
352
+ ---
353
+
354
+ ## 📝 License
355
+
356
+ MIT — See LICENSE file
357
+
358
+ ---
359
+
360
+ ## 🤝 Contributing
361
+
362
+ Contributions welcome! Please:
363
+
364
+ 1. Fork the repository
365
+ 2. Create a feature branch (`git checkout -b feature/awesome-feature`)
366
+ 3. Ensure tests pass (`npm test`)
367
+ 4. Commit with conventional commits (`feat:`, `fix:`, etc.)
368
+ 5. Push and open a Pull Request
369
+
370
+ ---
371
+
372
+ ## 🐛 Troubleshooting
373
+
374
+ ### "Command not found: infographic-gen"
375
+
376
+ If you installed globally with `-g` but command is not recognized:
377
+
378
+ ```bash
379
+ # Check npm's global bin directory
380
+ npm config get prefix
381
+
382
+ # Ensure it's in your PATH
383
+ # On macOS/Linux: ~/.npm/_npx/node_modules/.bin should be in PATH
384
+ # On Windows: npm global bin is usually in %APPDATA%\npm
385
+ ```
386
+
387
+ ### "API Key is invalid"
388
+
389
+ Check your configuration:
390
+
391
+ ```bash
392
+ infographic-gen config get apiKey
393
+ infographic-gen config get baseUrl
394
+ ```
395
+
396
+ Ensure your API key is valid for the provider you're using.
397
+
398
+ ### "Render failed: unknown template"
399
+
400
+ The LLM might have suggested a template that doesn't exist in your version of `@antv/infographic`. Try:
401
+
402
+ 1. Update the package: `npm update @antv/infographic`
403
+ 2. Run sync: `npm run sync`
404
+ 3. Try again with a more specific prompt
405
+
406
+ ---
407
+
408
+ ## 📊 Version History
409
+
410
+ See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
411
+
412
+ ---
413
+
414
+ ## 🙏 Acknowledgments
415
+
416
+ - **[AntV Infographic](https://infographic.antv.vision/)** — Professional infographic templates & SSR engine
417
+ - **[OpenAI](https://openai.com/)** — LLM backbone
418
+ - **[Commander.js](https://github.com/tj/commander.js)** — CLI framework
419
+ - **[Ora](https://github.com/sindresorhus/ora)** — Spinner UI