@ducksauce/cli
v3.0.17
Published
Command-line interface tools for managing Ducksauce projects, including project initialization, license activation, and component scaffolding.
Readme
@ducksauce/cli
Command-line interface tools for managing Ducksauce projects, including project initialization, license activation, and component scaffolding.
🚀 Quick Start
Installation
npm install -g @ducksauce/cli
# or
yarn global add @ducksauce/cli
# or
pnpm add -g @ducksauce/cliUsage
# Initialize a new project
ducksauce init
# Activate license
ducksauce license activate
# Scaffold components
ducksauce scaffold component🛠️ Commands
init
Initialize a new Ducksauce project with Payload CMS and Next.js.
ducksauce init [project-name]Options
--template <template>- Choose project template (default: basic)--package-manager <manager>- Package manager (npm, yarn, pnpm)--typescript- Use TypeScript (default: true)--tailwind- Include Tailwind CSS (default: true)--git- Initialize git repository (default: true)
Examples
# Basic initialization
ducksauce init my-project
# With specific template
ducksauce init my-project --template blog
# With custom package manager
ducksauce init my-project --package-manager pnpm
# Without TypeScript
ducksauce init my-project --typescript falseTemplates
- basic - Minimal Payload CMS + Next.js setup
- blog - Blog-focused template with posts and categories
- ecommerce - E-commerce template with products and orders
- saas - SaaS template with user management and billing
license
Manage Ducksauce licenses and entitlements.
ducksauce license <command>Commands
activate
Activate a license key.
ducksauce license activate <license-key>status
Check license status and entitlements.
ducksauce license statusdeactivate
Deactivate current license.
ducksauce license deactivateExamples
# Activate license
ducksauce license activate ds_1234567890abcdef
# Check status
ducksauce license status
# Deactivate
ducksauce license deactivatescaffold
Generate files and components for your project.
ducksauce scaffold <template> [name]Templates
component
Generate a React component.
ducksauce scaffold component ButtonOptions:
--path <path>- Output path (default: src/components)--typescript- Use TypeScript (default: true)--styled- Include styled-components--test- Include test file
page
Generate a Next.js page.
ducksauce scaffold page aboutOptions:
--path <path>- Output path (default: src/app)--typescript- Use TypeScript (default: true)--layout- Include layout file--api- Include API route
collection
Generate a Payload CMS collection.
ducksauce scaffold collection ProductOptions:
--path <path>- Output path (default: src/collections)--fields- Include common fields--hooks- Include collection hooks--access- Include access control
block
Generate a Payload CMS block.
ducksauce scaffold block HeroOptions:
--path <path>- Output path (default: src/blocks)--admin- Include admin component--frontend- Include frontend component
Examples
# Generate component
ducksauce scaffold component Button --typescript --test
# Generate page
ducksauce scaffold page about --layout --api
# Generate collection
ducksauce scaffold collection Product --fields --hooks
# Generate block
ducksauce scaffold block Hero --admin --frontend🛠️ Development
Prerequisites
- Node.js 18.20.2 or >=20.9.0
- pnpm 10.13.1+
Setup
# Install dependencies
pnpm install
# Start development mode
pnpm dev
# Build for production
pnpm build
# Run linting
pnpm lint
# Clean build artifacts
pnpm cleanProject Structure
packages/cli/
├── src/
│ ├── cli.ts # Main CLI entry point
│ ├── index.ts # Main exports
│ ├── commands/ # Command implementations
│ │ ├── init.ts
│ │ ├── license.ts
│ │ └── scaffold.ts
│ └── utils/ # Utility functions
│ ├── license.ts
│ └── workspace.ts
├── package.json
├── tsconfig.json
└── README.mdAdding New Commands
- Create command file in
src/commands/ - Export from
src/index.ts - Add to CLI in
src/cli.ts - Update this README
Example Command
// src/commands/example.ts
import { Command } from "commander";
import chalk from "chalk";
import ora from "ora";
export const exampleCommand = new Command("example")
.description("Example command description")
.argument("[name]", "Name argument")
.option("-f, --flag", "Example flag")
.action(async (name, options) => {
const spinner = ora("Running example command...").start();
try {
// Command logic here
console.log(chalk.green(`Hello ${name || "World"}!`));
spinner.succeed("Command completed successfully");
} catch (error) {
spinner.fail("Command failed");
console.error(chalk.red(error.message));
process.exit(1);
}
});📦 Building
Development Build
pnpm devThis starts tsup in watch mode, rebuilding on file changes.
Production Build
pnpm buildThis creates:
dist/cli.js- CLI executabledist/index.js- Main exportsdist/index.d.ts- TypeScript declarations
Build Configuration
The package uses tsup for building:
{
"build": "tsup src/cli.ts src/index.ts --dts --format esm"
}🧪 Testing
# Run tests
pnpm test
# Run tests in watch mode
pnpm test --watch
# Run tests with coverage
pnpm test --coverage📦 Publishing
Versioning
This package uses Changesets for versioning:
- Create a changeset:
pnpm changeset - Version the package:
pnpm release - Publish:
pnpm release(includes publishing)
Manual Publishing
# Build the package
pnpm build
# Publish to npm
pnpm publishPackage Configuration
{
"name": "@ducksauce/cli",
"version": "0.0.0",
"type": "module",
"bin": {
"ducksauce": "dist/cli.js"
},
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"files": ["dist"],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
}
}🔗 Dependencies
Dependencies
commander- CLI frameworkinquirer- Interactive promptschalk- Terminal colorsora- Terminal spinnersfs-extra- File system utilitiesglob- File pattern matching
Dev Dependencies
@types/node- Node.js TypeScript types@types/inquirer- Inquirer TypeScript types@types/fs-extra- fs-extra TypeScript types@types/glob- glob TypeScript typeseslint- Code lintingtsup- TypeScript bundlertypescript- TypeScript compiler
📚 API Reference
CLI Commands
init
Initialize a new Ducksauce project.
ducksauce init [project-name] [options]license
Manage licenses and entitlements.
ducksauce license activate <key>
ducksauce license status
ducksauce license deactivatescaffold
Generate project files and components.
ducksauce scaffold <template> [name] [options]Utility Functions
checkWorkspace
Check if current directory is a Ducksauce workspace.
import { checkWorkspace } from "@ducksauce/cli";
const isWorkspace = await checkWorkspace();validateLicense
Validate a license key.
import { validateLicense } from "@ducksauce/cli";
const isValid = await validateLicense(licenseKey);🔐 License Management
The CLI includes license management features for the Ducksauce platform.
License Storage
Licenses are stored locally in:
~/.ducksauce/licenses.json(global).ducksauce/license.json(project-specific)
License Validation
Licenses are validated against the Ducksauce license server and include:
- License Key - Unique identifier
- Features - Enabled features (blog, analytics, etc.)
- Expiry Date - License expiration
- User ID - Associated user account
Feature Entitlements
Licenses control access to features:
- Basic - Core CMS functionality
- Pro - Advanced features, analytics, custom domains
- Enterprise - White-label, priority support
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Create a changeset
- Submit a pull request
📄 License
This package is licensed under the MIT License - see the LICENSE file for details.
🆘 Support
- Documentation: This README
- Issues: Create an issue in the repository
- Discussions: Use GitHub Discussions for questions
Built with ❤️ using Commander.js and Inquirer.js.
