0
# Interactive Configuration
1
2
Comprehensive prompt-based configuration system for collecting project metadata and user preferences during project creation via CLI commands.
3
4
## Capabilities
5
6
### Interactive Prompts System
7
8
The CLI automatically triggers interactive prompts to collect missing project configuration when creating new projects.
9
10
```bash { .api }
11
# When running: jslib new [projectname]
12
# The CLI prompts for any missing information:
13
14
# Project Name Prompt
15
project name: [default: projectname]
16
17
# NPM Package Name Prompt (with validation)
18
npm package name: [default: projectname]
19
20
# UMD Name Prompt
21
UMD name for package: [default: projectname]
22
23
# GitHub Username Prompt
24
github user name: [required]
25
26
# Template Type Selection
27
select template:
28
❯ JavaScript
29
TypeScript
30
31
# Package Manager Selection
32
package manager:
33
❯ npm
34
no install
35
```
36
37
### Prompt Details
38
39
The CLI presents interactive prompts with the following behavior:
40
41
#### Project Name Prompt
42
- **Message**: "project name:"
43
- **Default**: Uses the provided project directory name
44
- **Validation**: Requires non-empty input
45
46
#### NPM Package Name Prompt
47
- **Message**: "npm package name:"
48
- **Default**: Uses the project directory name
49
- **Validation**: Validates against NPM naming conventions using validate-npm-package-name
50
- **Supports**: Scoped packages (e.g., @company/package-name)
51
52
#### UMD Name Prompt
53
- **Message**: "UMD name for package:"
54
- **Default**: Uses the project directory name
55
- **Validation**: Requires non-empty input
56
- **Purpose**: Global variable name for UMD builds
57
58
#### GitHub Username Prompt
59
- **Message**: "github user name:"
60
- **Default**: None (required input)
61
- **Validation**: Requires non-empty input
62
- **Purpose**: Used in generated README and package.json
63
64
#### Template Type Selection
65
- **Message**: "select template:"
66
- **Choices**: JavaScript, TypeScript
67
- **Default**: None (user must select)
68
- **Result**: Determines which project template to use
69
70
#### Package Manager Selection
71
- **Message**: "package manager:"
72
- **Choices**: npm, no install
73
- **Default**: None (user must select)
74
- **Result**: Whether to run npm install after project creation
75
76
### Smart Prompting Logic
77
78
The prompt system is intelligent about what questions to ask:
79
80
- **Skip Provided Options**: Only prompts for values not provided via command line
81
- **Conditional Prompts**: Certain prompts depend on previous answers
82
- **Default Values**: Sensible defaults based on project name or previous inputs
83
- **Validation**: Real-time validation with helpful error messages
84
85
### Validation Rules
86
87
Each prompt includes specific validation:
88
89
#### NPM Name Validation
90
- Uses `validate-npm-package-name` library
91
- Checks for valid NPM package naming conventions
92
- Prevents reserved names and invalid characters
93
- Allows scoped packages (e.g., `@company/package`)
94
95
#### General Name Validation
96
- Requires non-empty strings
97
- Trims whitespace automatically
98
- Validates against common naming patterns
99
100
#### Template Type Validation
101
- Restricts to supported template types
102
- Maps user-friendly names to internal codes
103
- Provides clear selection options
104
105
### Usage Examples
106
107
```bash
108
# Full interactive mode (all prompts)
109
npx @js-lib/cli new
110
111
# Partial interactive mode (skip username prompt)
112
npx @js-lib/cli new my-lib --username johndoe
113
114
# Minimal interactive mode (only template type prompt)
115
npx @js-lib/cli new my-lib --npmname @company/my-lib --username johndoe --umdname MyLib
116
```
117
118
### Integration with Inquirer
119
120
The system is built on the Inquirer.js library, providing:
121
122
- **Rich UI**: Colored prompts with clear formatting
123
- **Input Validation**: Real-time validation with error messages
124
- **Default Values**: Smart defaults to speed up configuration
125
- **List Selection**: Easy-to-use selection lists for choices
126
- **Cross-platform**: Works consistently across operating systems
127
128
### Error Handling
129
130
The prompt system handles various error conditions:
131
132
- **User Interruption**: Graceful handling of Ctrl+C
133
- **Invalid Input**: Clear error messages with retry options
134
- **Network Issues**: Fallback behavior for validation that requires network access
135
- **Terminal Compatibility**: Adapts to different terminal capabilities