new
Create new Xec artifacts (projects, scripts, commands, tasks, profiles, or extensions).
Synopsisβ
xec new [type] [name] [options]
xec n [type] [name] [options] # Alias
Descriptionβ
The new
command creates various Xec artifacts with pre-configured templates. It provides an interactive mode when no arguments are provided, or can be used with specific arguments for automation.
Argumentsβ
[type]
- Type of artifact to create:project
,script
,command
,task
,profile
, orextension
[name]
- Name for the new artifact
Optionsβ
General Optionsβ
-d, --description <desc>
- Description for the artifact-f, --force
- Overwrite existing files-p, --profile <name>
- Apply profile after creation-i, --interactive
- Enable interactive mode (default for this command)
Project Optionsβ
-m, --minimal
- Create minimal structure (projects only)--skip-git
- Skip git initialization (projects only)
Script & Command Optionsβ
--advanced
- Use advanced template with more features--js
- Create JavaScript instead of TypeScript (scripts/commands only)
Template Optionsβ
--from <template>
- Create from a template or example
Examplesβ
Interactive Modeβ
# Interactive mode to create any artifact
xec new
# Interactive mode with alias
xec n
Project Creationβ
# Create a new Xec project
xec new project my-app
# Create minimal project structure
xec new project my-app --minimal
# Create project with description
xec new project my-app --description "My automation project"
# Skip git initialization
xec new project my-app --skip-git
Script Creationβ
# Create a new TypeScript script
xec new script deploy
# Create JavaScript script
xec new script deploy --js
# Create advanced script with more features
xec new script deploy --advanced
# Create script with description
xec new script backup --description "Database backup script"
Command Creationβ
# Create a new CLI command
xec new command mycmd
# Create advanced command with subcommands
xec new command mycmd --advanced
# Create JavaScript command
xec new command mycmd --js
Task Creationβ
# Create a new task
xec new task build
# Create task with description
xec new task deploy --description "Deploy application to production"
# Create advanced multi-step task
xec new task deploy --advanced
Profile Creationβ
# Create environment profile
xec new profile production
# Create profile with description
xec new profile staging --description "Staging environment configuration"
# Create advanced profile with targets
xec new profile production --advanced
Extension Creationβ
# Create a new extension
xec new extension my-extension
# Create advanced extension
xec new extension my-extension --advanced
# Create extension with description
xec new extension monitoring --description "System monitoring extension"
Artifact Typesβ
Projectβ
Creates a complete Xec project with:
.xec/config.yaml
- Main configuration.xec/scripts/
- Script directory with examples.xec/commands/
- Custom commands directory.xec/.gitignore
- Git ignore file- Documentation and examples
Templates:
- Minimal - Basic structure with essential files
- Standard - Full structure with examples and documentation
Scriptβ
Creates executable scripts with shebang and imports:
- TypeScript or JavaScript files
- Pre-configured with Xec imports
- Executable permissions set
- Example code and documentation
Templates:
- Basic - Simple script structure
- Advanced - Complex script with argument parsing and error handling
Commandβ
Creates dynamic CLI commands:
- Command definition with arguments and options
- Action handlers
- Help documentation
- Integration with Commander.js
Templates:
- Basic - Simple command with basic options
- Advanced - Complex command with subcommands and validation
Taskβ
Creates reusable task definitions:
- Task configuration in YAML format
- Parameter definitions
- Step definitions
- Error handling configuration
Templates:
- Simple - Single command task
- Standard - Task with parameters
- Advanced - Multi-step task with hooks and error handling
Profileβ
Creates environment profiles:
- Environment-specific variables
- Target configurations
- Environment variables
- Profile inheritance
Templates:
- Basic - Simple profile with variables
- Advanced - Complex profile with targets and inheritance
Extensionβ
Creates Xec extensions:
- Extension manifest
- Task definitions
- Configuration schema
- Documentation and examples
Templates:
- Basic - Simple extension structure
- Advanced - Full extension with scripts and examples
Template Variablesβ
All templates support variable replacement:
{name}
- Artifact name{description}
- Artifact description{filepath}
- File path (scripts only)
Project Structureβ
When creating a project, the following structure is generated:
my-project/
βββ .xec/
β βββ config.yaml # Main configuration
β βββ .gitignore # Git ignore rules
β βββ scripts/ # Executable scripts
β β βββ example.js # Example script
β βββ commands/ # Custom CLI commands
β β βββ hello.js # Example command
β βββ cache/ # Cache directory
β βββ logs/ # Log files
β βββ tmp/ # Temporary files
βββ README.md # Project documentation
Script Templatesβ
Basic Script (TypeScript)β
#!/usr/bin/env xec
/**
* {description}
*
* Usage: xec {filepath}
*/
// Type-safe command execution
const result = await $`echo "Hello from TypeScript!"`;
log.success(result.stdout);
// Work with files using built-in fs
const files = await glob('**/*.ts');
log.step(`Found ${files.length} TypeScript files`);
// Interactive prompts with type inference
const name = await question({
message: 'What is your name?',
defaultValue: 'Developer'
});
log.info(chalk.blue(`Hello, ${name}!`));
Advanced Script Featuresβ
- Command line argument parsing
- Configuration loading and profile application
- Retry logic and error handling
- Progress indicators and spinners
- Environment validation
- Cleanup functions
Command Templatesβ
Basic Commandβ
/**
* {description}
*
* This command will be available as: xec {name} [arguments]
*/
export function command(program) {
program
.command('{name} [args...]')
.description('{description}')
.option('-v, --verbose', 'Enable verbose output')
.action(async (args, options) => {
const { log } = await import('@clack/prompts');
// Your command logic here
log.info('Running {name} command...');
if (options.verbose) {
log.step('Verbose mode enabled');
log.step(`Arguments: ${args.join(', ') || 'none'}`);
}
// Example: Use $ from @xec-sh/core
const { $ } = await import('@xec-sh/core');
const result = await $`echo "Command {name} executed successfully!"`;
log.success(result.stdout);
});
}
Validationβ
The command validates artifact names based on type:
- Project names: Letters, numbers, hyphens, underscores
- Script names: Letters, numbers, hyphens, underscores, dots
- Command/Task/Profile names: Letters, numbers, hyphens, underscores, colons
- Extension names: Letters, numbers, hyphens, underscores
Git Integrationβ
For projects, git initialization is automatic unless --skip-git
is used:
- Creates git repository
- Adds all files
- Creates initial commit with message "Initial Xec project setup"
File Permissionsβ
Scripts are automatically made executable (chmod 755) after creation.
Error Handlingβ
The command provides helpful error messages for:
- Invalid artifact names
- Existing files (unless
--force
is used) - Missing project directories
- Invalid template options
Related Commandsβ
Configurationβ
Command behavior can be configured in .xec/config.yaml
:
commands:
new:
defaultType: script
defaultLanguage: typescript
gitInit: true
makeExecutable: true
Exit Codesβ
0
- Success1
- General error2
- Invalid arguments3
- File exists (without --force)4
- Validation error5
- Template error