wechat-page-generator
Version:
๐ Automatic page generator for WeChat Mini Program with ready-made templates
190 lines (136 loc) โข 3.77 kB
Markdown
# ๐ WeChat Page Generator
Automatically generate **WeChat Mini Program** pages with ready-to-use templates.
Instantly create a complete page with all the required files (.wxml, .js, .wxss, .json) using a single command!
## โจ Features
* ๐ฏ **Instant generation**: Automatically creates the 4 required files
* ๐จ **Optimized templates**: Clean code and modern structure
* ๐ก๏ธ **Smart validation**: Name checks and duplicate prevention
* ๐ช **Colorful interface**: Visual feedback in the terminal
* ๐ฑ **Production-ready**: Templates with complete lifecycle methods
## ๐ฆ Installation
### Global installation (recommended)
```bash
npm install -g wechat-page-generator
```
### One-time use with npx
```bash
npx wechat-page-generator profile
```
## ๐ฎ Usage
### Basic command
```bash
wx-create page-name
```
### Examples
```bash
# Simple page
wx-create profile
# Page with hyphens
wx-create user-settings
# Page with spaces (automatically cleaned)
wx-create "My Page"
```
## ๐ Generated Structure
For a page named `profile`, the following structure will be created:
```
pages/
โโโ profile/
โโโ profile.wxml # Page template
โโโ profile.js # Logic and lifecycle
โโโ profile.wxss # Page styles
โโโ profile.json # Navigation config
```
## ๐ Generated Templates
### ๐๏ธ WXML Structure
```xml
<view class="profile-container">
<view class="profile-header">
<text class="profile-title">Profile</text>
</view>
<view class="profile-content">
<!-- Content of the profile page -->
<text>Welcome to the Profile page</text>
</view>
</view>
```
### โ๏ธ JavaScript Logic
```javascript
Page({
data: {
title: 'Profile'
},
onLoad(options) {
console.log('Profile page loaded with options:', options);
},
onShow() {
console.log('Profile page displayed');
},
// ... other lifecycle methods
});
```
### ๐จ WXSS Styles
```css
.profile-container {
min-height: 100vh;
background-color: #f5f5f5;
padding: 20rpx;
}
.profile-header {
background-color: #ffffff;
border-radius: 10rpx;
padding: 30rpx;
/* ... modern styles */
}
```
### โก JSON Configuration
```json
{
"navigationBarTitleText": "Profile",
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"backgroundColor": "#f5f5f5"
}
```
## ๐ง After Generation
### 1. Add to `app.json`
```json
{
"pages": [
"pages/profile/profile"
]
}
```
### 2. Navigate to the page
```javascript
wx.navigateTo({
url: '/pages/profile/profile'
})
```
## ๐ ๏ธ Command Options
```bash
wx-create --help # Show help
wx-create --version # Show version
```
## ๐จ Error Handling
The generator includes validation for:
* โ
Valid page names
* โ
Duplicate prevention
* โ
Special characters automatically cleaned
* โ
Clear and colorful error messages
## ๐ค Contributing
Contributions are welcome!
1. Fork the project
2. Create your branch (`git checkout -b feature/new-feature`)
3. Commit your changes (`git commit -m 'Add new feature'`)
4. Push to your branch (`git push origin feature/new-feature`)
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgements
Created with โค๏ธ for the WeChat Mini Program developer community.
## ๐ Support
* ๐ **Issues**: [GitHub Issues](https://github.com/rachid-traore/wechat-page-generator/issues)
* ๐ฌ **Discussions**: [GitHub Discussions](https://github.com/rachid-traore/wechat-page-generator/discussions)
* ๐ง **Email**: [timotheetraore1@gmail.com](mailto:timotheetraore1@gmail.com)
---
โญ **Donโt forget to star the project if you found it useful!**