scripts
Scripts Module
The scripts directory contains utility scripts for the cfxdevkit monorepo. These scripts automate development, maintenance, and release tasks. Each script is self-contained and executable from the repository root.
fix-kebab-groups.mjs
Resolves kebab-group violations by moving files into prefixed subdirectories and updating import references.
Process
- Reads
artifacts/llm/reports/kebab-groups.json(generated bypnpm run check:kebab-groups) - For each file group sharing a directory prefix:
- Creates subdirectory named after the prefix
- Moves files into the subdirectory, stripping the prefix from filenames
- Processes longest prefixes first to handle nesting
- In dry-run mode (
--dry-run), logs proposed moves - Otherwise, executes moves via
git mv(creating directories as needed) - Builds import replacement map (old specifier → new specifier without extension)
- Scans source files (excluding
node_modules,.git,dist,artifacts) for:.ts,.tsx,.js,.jsx,.json,.md,.mdx,.yml,.yaml,.css
- Updates import/require statements using regex to match quoted specifiers
- Reports moved files and files with updated imports
Usage
node scripts/fix-kebab-groups.mjs # Execute moves
node scripts/fix-kebab-groups.mjs --dry-run # Preview changesfix-kebab-imports.mjs
Updates import paths after kebab-group file moves, handling both relocated imports and depth-adjusted imports in moved files.
Process
- Reads
kebab-groups.jsonreport - Builds two maps:
moveMap: old file paths (without extension) → new file paths (without extension)depthShiftMap: new file paths → directory depth increase (for adjusting relative imports)
- Scans source files (same exclusions as fix-kebab-groups)
- For each import/require statement:
- Attempts to resolve specifier against
moveMap(trying extensions/index files) - If found, replaces with new relative path
- If current file was moved and specifier not in
moveMap:- Adjusts by prepending
../for each depth level increase
- Adjusts by prepending
- Attempts to resolve specifier against
- Reports files modified and total import changes
Usage
node scripts/fix-kebab-imports.mjs # Execute fixes
node scripts/fix-kebab-imports.mjs --dry-run # Preview changespublish-packages.mjs
Publishes non-private, non-ignored workspace packages to npm.
Process
- Reads
.changeset/config.jsonfor ignored packages (if any) - Discovers packages under
repos/*/packages/(onlycfx-*repos) withpackage.json - For each package:
- Skips if private, nameless, or in ignore list
- Checks if version already published via
npm view(skips if published and not dry-run) - Packs package with
pnpm pack(output to repository root) - Publishes tarball via
npm publish --access public --provenance - Removes tarball after publish
- Handles dry-run mode (
--dry-run) to simulate without publishing
Key Functions
run(): Wrapper forspawnSyncthat throws on non-zero exitreadJson(): Parses JSON filescollectPackageDirs(): Returns sorted package directory pathspackageExists(): Checks npm for existing package version
Usage
node scripts/publish-packages.mjs # Publish packages
node scripts/publish-packages.mjs --dry-run # Simulate publishscaffold-empty-packages.sh
Idempotently scaffolds standard package structure for new workspace packages.
Process
- Defines
write_if_missing: creates file only if absent - Defines
scaffold_lib: generates package structure for given:- Directory path
- Package name
- Description
- Type (
nodeorreact)
- Structure includes:
package.json: name, version, scripts, devDependencies (Vite, Vitest, etc.)tsconfig.json: extends@cfxdevkit/tsconfig/lib.jsonvite.config.ts: library build config with optional React externalsvitest.config.ts: basic test configurationsrc/index.ts: placeholder exportsrc/index.test.ts: smoke testmoon.yml: Moonrepo project configuration
- Invokes
scaffold_libfor predefined packages (framework, domains, platform)
Usage
bash scripts/scaffold-empty-packages.shsetup-trust-local-ca.sh
Installs mkcert root CA on host to trust *.dev.cfxdevkit.org certificates.
Process (run on host machine after devcontainer creation)
- Detects container engine (docker/podman) and finds running devcontainer
- Copies
rootCA.pem(androotCA-key.pemif present) from container to host temp dir - Installs mkcert on host if missing (via brew/apt/dnf)
- Sets
CAROOTto temp dir and runsmkcert -install - Optionally imports CA into NSS databases for Firefox/system trust
- Outputs instructions to restart browser and verify
https://showcase.dev.cfxdevkit.org
Usage
bash scripts/setup-trust-local-ca.shshowcase-dev.sh
Starts the showcase application (local and public variants) on ports 3010/3011.
Process
- Checks for existing listeners on ports 3010/3011
- If found, verifies they are showcase processes (by checking parent process args)
- If showcase already running, exits with message
- If port conflict (non-showcase listener), exits with error
- Otherwise, runs:
pnpm --parallel --filter @cfxdevkit/example-showcase-local --filter @cfxdevkit/example-showcase-public dev
Usage
bash scripts/showcase-dev.shstop-showcase.sh
Stops showcase application listeners on ports 3010/3011.
Process
- Uses
ssto find PIDs listening on ports 3010/3011 - Kills identified processes
- Reports action taken or absence of listeners
Usage
bash scripts/stop-showcase.shvalidate-repos.mjs
Validates all cfx-* repositories by running workspace and dependency checks.
Process
- Defines repository list:
cfx-config,cfx-core,cfx-domain,cfx-keys,cfx-llm,cfx-meta,cfx-solidity,cfx-tools,cfx-ui - Defines scripts to run per repo:
validate-workspace.mjs,check-deps.mjs - For each repo and script:
- Constructs path to
repos/<repo>/scripts/<script> - If script exists, runs via
node(inherit stdio,NO_COLOR=1) - Records failures (non-zero exit)
- Constructs path to
- After all repos:
- If failures exist, lists them and exits with code 1
- Otherwise, reports success for all repos
Usage
node scripts/validate-repos.mjswire-package-dependencies.sh
Adds internal workspace dependencies according to API contracts using pnpm.
Process
- Defines
add_dep: adds dependencies to packages matching filter--save-prodfor production deps--save-peerfor peer deps
- Applies predefined dependency wiring:
- framework:
services→cdkwallet→cdk,servicescompiler→cdkdevnode→cdkcontracts→cdkprotocol→cdkexecutor→cdkreact→cdk(prod),wallet(peer)wallet-connect→cdk(prod),wallet(peer)defi-react→cdk,services,react,wallet-connect(prod),theme(peer)testing→cdk,devnode,contracts
- domains:
game-engine→cdk,contractsautomation→cdk,services,wallet,executor,contracts
- platform:
mcp-server→cdk,services,wallet,contracts,compiler,devnode
scaffold-cli: no internal deps
- framework:
Usage
bash scripts/wire-package-dependencies.sh