Project type inheritance system for Nx workspaces
nx-project-types is an Nx plugin that allows you to define project types with predefined configurations, templates, and behaviors. You can apply these types to projects in your Nx workspace, ensuring consistency and making it easier to manage and scale your workspace.
npm install --save-dev nx-project-types
# or
yarn add --dev nx-project-types
# or
pnpm add -D nx-project-types- Project Type Definitions: Define reusable project configurations as types
- Type Inheritance: Apply project types to projects to inherit configuration
- Configuration Syncing: Automatically sync configuration when project types are updated
- Tag-Based Matching: Match projects to types based on their tags
- Template Support: Use templates for consistent project structure
Register the plugin in your Nx workspace by running:
nx g nx-project-types:registerThis will add the plugin to your nx.json file.
Apply a project type to a specific project:
nx g nx-project-types:apply-project-type --project=myproject --type=webapiSync project types across all projects based on their tags:
nx g nx-project-types:sync-project-typesProject types are defined in the project-type.json files in your Nx workspace. For example:
{
"name": "webapi",
"description": "Web API project",
"tags": ["scope:api", "type:webapi"],
"templateDir": "templates/webapi",
"config": {
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"options": {
"tsConfig": "tsconfig.lib.json"
}
}
}
}
}We use a hybrid approach combining trunk-based development with semantic versioning:
main: Main development branch, always in a releasable statefeature/*: Short-lived feature branches (1-2 days max)bugfix/*: Short-lived bug fix branchesrelease/*: Short-lived release brancheshotfix/*: Urgent fixes for production
-
Start a new feature/fix:
git checkout -b feature/my-feature main
-
Make changes and commit:
git add . git commit -m "feat: add new feature"
-
Push and create a PR:
git push -u origin feature/my-feature
-
After review, merge into main
We use Semantic Versioning for versioning:
- MAJOR: Incompatible API changes
- MINOR: Backward-compatible new features
- PATCH: Backward-compatible bug fixes
Our release workflow:
# Create a release
npx nx release
# Publish to npm
npx nx release publishWe use GitHub Actions for continuous integration and delivery:
- CI: Runs on PRs and pushes to main, ensuring code quality
- Release: Triggered by version tags or manually for formal releases
- Pre-Release: Creates beta/RC versions for testing
- Nightly: Automatic builds from main every day at midnight UTC
- Test Publishing: Tests the publishing process with Verdaccio
For detailed information about our CI/CD setup, see CI/CD documentation.
- Stable releases: Published to npm with the
latesttag - Beta/RC releases: Published with
betaorrctags - Nightly builds: Automatic builds from
mainwith thenightlytag
You can test the package locally using Verdaccio:
# Install Verdaccio
npm install -g verdaccio
# Start Verdaccio
verdaccio
# In a new terminal, create a user
npm adduser --registry http://localhost:4873
# Build the package
pnpm build:prod
# Publish to local registry
cd dist && npm publish --registry http://localhost:4873
# Install from local registry
npm install nx-project-types --registry http://localhost:4873This project is structured as a standard Nx workspace:
nx-project-types/
├── libs/
│ └── nx-project-types/ # Main plugin code
├── docs/ # Documentation
├── examples/ # Example projects
├── tests/ # Test files
└── nx.json # Nx configuration
# Build the plugin
pnpm build
# Run tests
pnpm test
# Lint the code
pnpm lintFor more information, see the documentation.
This project is licensed under the MIT License - see the LICENSE file for details.