UNPKG

wechat-page-generator

Version:

๐Ÿš€ Automatic page generator for WeChat Mini Program with ready-made templates

190 lines (136 loc) โ€ข 3.77 kB
# ๐Ÿš€ 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!**