0
# Project Creation
1
2
Complete project scaffolding functionality for creating new JavaScript and TypeScript library projects with modern development tooling.
3
4
## Capabilities
5
6
### New Command
7
8
Creates a new library project with interactive configuration or pre-specified options.
9
10
```bash { .api }
11
jslib new [projectname] [options]
12
jslib n [projectname] [options]
13
14
# Options:
15
--force, -f # Force create (overwrite existing project)
16
--config, -c # Initialize only the configuration file
17
--npmname, -n <name> # Initialize the npm package name
18
--umdname, --umd <name> # Initialize the UMD name for package
19
--username, -u <name> # Initialize the username
20
--type, -t <type> # Initialize the js/ts selection
21
--manager, -m <manager> # Select the package management method
22
```
23
24
**Usage Examples:**
25
26
```bash
27
# Interactive creation (prompts for all options)
28
npx @js-lib/cli new my-lib
29
30
# Create with specific options
31
npx @js-lib/cli new my-lib --type js --username johndoe --manager npm
32
33
# Force overwrite existing directory
34
npx @js-lib/cli new existing-project --force
35
36
# Create only configuration file in current directory
37
npx @js-lib/cli new --config --type ts
38
```
39
40
### Project Creation Process
41
42
The CLI handles project creation through the following internal process:
43
44
1. **Argument Processing**: Combines command line options with interactive prompt responses
45
2. **Validation**: Validates project name, NPM package name, and other inputs
46
3. **Template Selection**: Chooses appropriate template (JavaScript or TypeScript)
47
4. **Directory Creation**: Creates project directory structure
48
5. **File Generation**: Copies and processes template files
49
6. **Configuration**: Creates project configuration files
50
7. **Dependency Installation**: Optionally runs package manager installation
51
52
### Template Types
53
54
The CLI supports two complete project templates:
55
56
#### JavaScript Template (module-js)
57
- ES6+ source code structure
58
- Rollup build configuration
59
- Mocha testing framework
60
- ESLint + Prettier code formatting
61
- GitHub Actions CI/CD
62
- Browser and Node.js compatibility
63
64
#### TypeScript Template (module-ts)
65
- TypeScript source code structure
66
- Type declaration generation
67
- Same tooling as JavaScript template
68
- Full type safety throughout build pipeline
69
70
### Project Structure
71
72
Generated projects include:
73
74
```
75
my-project/
76
├── src/ # Source code directory
77
├── test/ # Unit tests
78
├── demo/ # Usage examples
79
├── dist/ # Compiled output
80
├── doc/ # Documentation
81
├── .github/ # GitHub Actions workflows
82
├── package.json # NPM package configuration
83
├── rollup.config.js # Build configuration
84
├── .eslintrc.js # Linting rules
85
├── .prettierrc.json # Code formatting
86
└── jslib.json # Project metadata for updates
87
```
88
89
### Error Handling
90
91
The creation process includes validation and error handling:
92
93
- **Project exists**: Prevents overwriting unless `--force` is used
94
- **Invalid NPM names**: Validates package names using validate-npm-package-name
95
- **Missing parameters**: Prompts for required information interactively
96
- **File system errors**: Graceful handling of permission and disk space issues
97
98
### Configuration-Only Mode
99
100
The `--config` flag allows initializing only the `jslib.json` configuration file in the current directory, useful for existing projects that want to enable update functionality.
101
102
```bash
103
# Initialize config in existing project
104
cd existing-project
105
npx @js-lib/cli new --config --type js
106
```