An npm package that distributes a versioned draw.io shape library for architecture context blocks and includes a CLI to upgrade existing diagrams when the library changes. Install once, npx architecture-blocks upgrade to keep all your diagrams in sync.
- Initialize npm package with TypeScript
- Configure tsup for CLI + library build
- Configure vitest for testing
- Set up package.json with name
@ea-toolkit/architecture-blocks, bin entry for CLI - .gitignore, tsconfig.json, vitest.config.ts
src/library/shapes.ts— define all ArchiMate context block shapes- Each shape has: blockId (stable identifier), name, layer, style string, fill color, dimensions
- Cover all layers: application, business, technology, strategy, motivation, implementation, physical, composite
- Include ArchiMate type attributes (appType, busType, techType, etc.)
src/library/generator.ts— generate draw.io library XML from shape definitions- Each shape gets
data-block-idanddata-library-versionattributes embedded in the XML - Output: valid .xml file importable by draw.io as custom shape library
- Version stamped from package.json
scripts/postinstall.ts— copies generated library to configurable location (default: ./drawio-libraries/)src/index.ts— exports library path and version for programmatic use- Generate library XML during build step
src/lib/parser.ts— parse .drawio files (XML, optionally multi-page)- Extract all mxCell and object elements with their styles, attributes, geometry
- Handle both compressed (base64+deflate) and uncompressed diagram content
- Return structured representation: pages > cells (vertices + edges)
src/lib/matcher.ts— match diagram shapes to library definitions- Match by
data-block-idattribute on cells - Return: matched shapes with current version, library version, and whether upgrade needed
- Handle shapes that have no data-block-id (skip gracefully)
src/lib/differ.ts— compare current shape style against library definition- Parse style strings into key-value pairs
- Identify changed properties (fillColor, strokeColor, strokeWidth, fontColor, fontSize, etc.)
- Only flag visual style changes — ignore position, size, label content
test/fixtures/— create sample .drawio files with known shapestest/parser.test.ts— test XML parsing, multi-page handling, compressed contenttest/matcher.test.ts— test shape matching by data-block-idtest/differ.test.ts— test style comparison and diff output
src/lib/upgrader.ts— apply style updates to matched shapes- Update only style properties (colors, stroke, font)
- Update
data-library-versionattribute - NEVER modify: positions, connections, labels/text, grouping, geometry
src/lib/backup.ts— create .drawio.bak before writingsrc/lib/validator.ts— validate XML before and after modification- If output XML is malformed → abort and restore from backup
- Support --no-backup flag
test/upgrader.test.ts— end-to-end upgrade tests- Test: shape style updated, version bumped
- Test: positions, connections, labels preserved
- Test: multi-page files handled correctly
- Test: files with zero context blocks = no-op
- Test: backup created and restored on failure
- Recursive .drawio file finder for given path
- Default to current directory
- Respect .gitignore patterns (optional)
src/library/versions.ts— track version history and migration paths- Map old version styles to new version styles
- Support skipping versions (1.0.0 → 1.3.0 should work)
src/cli.ts— commander.js based CLI- Commands: upgrade, check, version
- Global options: --verbose, --dry-run, --no-backup
npx architecture-blocks upgrade [path]- Find all .drawio files, parse, match, diff, upgrade
- Output: per-file summary of changes
- Dry-run mode: show what would change without modifying
npx architecture-blocks check [path]- Report stale shapes without modifying
- Exit code 1 if stale shapes found (useful for CI)
npx architecture-blocks version- Show installed library version
- Clean, readable terminal output (verbose and summary modes)
- Per-file, per-page, per-shape breakdown
- Summary line: "X blocks found, Y need upgrade across Z files"
- Installation instructions
- CLI usage with examples
- How to import the library into draw.io
- How the upgrade works
- CI integration example (using check command)
- Clean package.json (files, exports, bin)
- Build produces dist/ with CLI + library
- Verify npx architecture-blocks works from a clean install
- Add LICENSE (MIT)
- Shape definitions cover all ArchiMate layers
- Generated XML imports correctly in draw.io
- Shapes have data-block-id and data-library-version embedded
- Parser handles both compressed and uncompressed .drawio files
- Matcher correctly identifies shapes by data-block-id
- Differ correctly identifies style changes only
- Upgrade updates styles without touching positions/connections/labels
- Backup created before every write
- Malformed output triggers abort + restore
- All three CLI commands work via npx
- Dry-run shows accurate preview
- Check exits with code 1 on stale shapes
- Package installs cleanly from npm
- README is clear and complete