@perfect-abstractions/compose-cli
v0.0.5
Published
CLI to scaffold Compose facet-based diamond projects
Readme
Compose CLI
Creates new diamond-based projects using the Compose Library. Supports both Foundry and Hardhat frameworks.
Create a new project with Compose CLI
npx @perfect-abstractions/compose-cli initUsage
compose init [options]
compose templates
compose --version | -v
compose --help | -h
compose updateOptions
--name <project-name>: directory / package name for the new project.--template <template-id>: template to use (see Template registry below).--framework <foundry|hardhat>: target framework.--language <javascript|typescript>: source language (Hardhat only; defaults totypescriptwhen omitted).--install-deps/--no-install-deps: whether to install npm dependencies for Hardhat templates (defaults totrueunless disabled or using--yeswith an explicit value).--yes: non-interactive mode. Skips prompts and fills missing values with sensible defaults.--help: print CLI help text.
When --yes is not provided, compose init will prompt for any values you omit.
Non-interactive examples
# Foundry default template
compose init --name my-foundry-app --template default --framework foundry --yes
# Hardhat minimal TypeScript template, skip dependency install
compose init --name my-hardhat-minimal \
--template default \
--framework hardhat \
--language typescript \
--install-deps=false \
--yes
# Hardhat mocha-ethers TypeScript template
compose init --name my-hardhat-mocha-ethers \
--template default \
--framework hardhat \
--language typescript \
--yescompose templates prints this information in a friendly format.
Development
From the cli directory:
npm install
npm run build:templates
npm run checkTemplate registry generation
The template registry at src/config/templates.json is generated from per-template manifests under src/templates/**/template.json.
- To regenerate the registry after changing templates:
npm run build:templatesAdd a new template
To make a new template:
Create the template folder
- Add a new directory under
src/templates/<template-id>. - Example:
src/templates/erc721.
- Add a new directory under
Add a
template.jsonmanifest- Place it at
src/templates/<template-id>/template.json. - Required fields:
id: the template id (must match<template-id>).name: human‑readable name shown incompose templates.description: short description.variants: list of variant ids (see below).compatibility.frameworks: array of supported frameworks, e.g.["foundry"]or["foundry","hardhat"].
- Example:
{ "id": "erc721", "name": "ERC‑721 Diamond", "description": "Diamond project with an ERC‑721 facet", "variants": [ "erc721-foundry", "erc721-hardhat-minimal" ], "compatibility": { "frameworks": ["foundry", "hardhat"] } }
- Place it at
Add variant directories
- Variant ids follow the pattern:
<template-id>-<framework>[-<project-type>]. - The generator maps variants to paths as follows:
- Foundry:
templates/<template-id>/foundry- Example variant id:
erc721-foundry→src/templates/erc721/foundry
- Example variant id:
- Hardhat (no project type):
templates/<template-id>/hardhat- Example variant id:
erc721-hardhat→src/templates/erc721/hardhat
- Example variant id:
- Hardhat with project type (TypeScript/JS layout):
- Path pattern:
templates/<template-id>/hardhat/ts/<project-type> - Example variant id:
erc721-hardhat-minimal→src/templates/erc721/hardhat/ts/minimal
- Path pattern:
- Foundry:
- Place the scaffolded project files (contracts, configs, tests, etc.) inside each variant directory.
- Variant ids follow the pattern:
Language detection
- The CLI infers the language from the variant path:
- Paths containing
/ts/→language: "typescript". - Paths containing
/js/→language: "javascript".
- Paths containing
- For Foundry templates, language is not set on the variant; the framework alone is enough.
- The CLI infers the language from the variant path:
Regenerate the templates registry
- From the
clidirectory run:npm run build:templates - This rebuilds
src/config/templates.jsonfrom alltemplate.jsonmanifests and validates the result.
- From the
Verify your template is available
- Run:
node index.js templates - Confirm your new template and variants appear in the list.
- Run:
Smoke‑test the template
- Use your new template to scaffold a project:
node index.js init --name my-test-project --template <template-id> --framework <framework> --yes - Then run the framework’s own test / build commands in the generated project.
- Use your new template to scaffold a project:
Test the CLI locally
npm linkThis will create a symlink to the CLI in your global node_modules directory.
You can then test the CLI by running:
compose --help