@contextjs/context
v25.1.0
Published
ContextJS - Command-line interface for building and managing ContextJS applications.
Maintainers
Readme
@contextjs/context
Official CLI for building and managing ContextJS projects.
Features
- Unified command-line interface for all ContextJS-based projects
- Fast, extensible project build and watch support
- Seamless integration with the ContextJS ecosystem
- Full support for TypeScript compiler flags via
ctx buildandctx watch - Support for custom compiler extensions via
--extensionsorcontext.ctxp - Easily scaffold new projects from official templates (see below)
Installation
For the full CLI experience, including templates, install both @contextjs/context and @contextjs/templates globally:
npm install -g @contextjs/context @contextjs/templatesThis exposes the ctx command in your terminal, with official templates automatically discovered when you run ctx new.
The
@contextjs/templatespackage is separate so you can install only what you need: just the CLI, just the templates, or both. You can also install it locally in your project if you prefer not to install it globally.
You can also install third-party templates and commands to use, the ContextJS ecosystem is designed to be extensible.
Usage
Display help and available options
ctxVersion
ctx --versionctx -vNew project (with templates)
Requires
@contextjs/templatesinstalled globally.
ctx new webapi myApi
ctx new webapi -n myApi
ctx new webapi --name myApiIf no project name is provided, the current folder name will be used:
ctx new webapiBuild
Build all detected projects:
ctx buildBuild specific projects:
ctx build myApi1 myApi2 ...You can pass TypeScript compiler options directly:
ctx build --noEmitOnError --target ES2022Use a custom extension for the TypeScript compiler:
ctx build --extensions=./src/my-extension.tsOr define extensions in context.ctxp:
{
"compilerExtensions": ["./src/my-extension.ts"]
}Watch
Watch and rebuild all projects on file changes:
ctx watchWatch specific projects:
ctx watch myApi1 myApi2 ...Include TypeScript flags with watch:
ctx watch --moduleResolution NodeNext --strict trueExternal extensions are supported in watch mode as well:
ctx watch --extensions=./src/my-extension.tsProject Templates
Templates are provided by the @contextjs/templates package.
- Install it globally to make all official templates available to the CLI.
- When you run
ctx new ..., templates are automatically discovered and listed.
You can find a list of available templates in the @contextjs/templates README.
Project commands
ctx new <template> --name <projectName>: Create a new project using the specified template.ctx build [projectName1 projectName2 ...]: Builds one or more projectsctx watch [projectName1 projectName2 ...]: Watches one or more projects for changes and rebuilds them automaticallyctx restore [projectName1 projectName2 ...]: Restores the project dependencies and configurationsctx run [projectName1 projectName2 ...]: Runs the specified projects.ctx --version: Displays the current version of the CLIctx -v: Alias for--version
Project Structure
When you create a new project using ctx new webapi myapi, the following layout is generated:
myapi/
├── context.ctxp
├── tsconfig.json
├── package.json
└── src/
└── main.tsAll files are preconfigured to follow ContextJS conventions and integrate cleanly with the rest of the ecosystem.
