The create-widget.ts CLI tool scaffolds new custom widgets for the MP Custom Widgets library by cloning the WidgetTemplate and customizing it with your widget name.
npm run create-widgetYou will be prompted:
Name of New Widget:
Enter your widget name (can include spaces). The CLI will:
- Convert the name to a folder-safe format (spaces → underscores)
- Copy the WidgetTemplate to a new folder in
Widgets/ - Rename and update template files automatically
- Update demo.html with the new widget configuration
$ npm run create-widget
Name of New Widget: My Awesome Widget
Creating widget: My_Awesome_Widget
Renamed template.html to My_Awesome_Widget.html
Updated demo.html with new template path
Widget created successfully at: s:/MPCustomWidgets/Widgets/My_Awesome_WidgetWidgets/
└── My_Awesome_Widget/ # New folder (spaces replaced with underscores)
├── Template/
│ └── My_Awesome_Widget.html # Renamed from template.html
├── demo.html # Updated with correct paths and widget name
└── README.md # Template documentation
The CLI automatically modifies demo.html:
| What Changes | From | To |
|---|---|---|
| Template path | /Widgets/WidgetTemplate/Template/template.html |
/Widgets/My_Awesome_Widget/Template/My_Awesome_Widget.html |
| Widget heading | <h2>Widget Template</h2> |
<h2>My Awesome Widget</h2> |
| Description | "Clone this template..." | "Widget Cloned by create-widget" |
| Element ID | id="MyCustomWidget" |
id="My_Awesome_Widget" |
| Removes instructional text | <h4>The data-template parameter must be updated...</h4> |
(deleted) |
Prompts user for input and returns answer as a promise.
Recursively copies all files and subdirectories from source to target.
Main execution function:
- Prompts for widget name
- Validates input (exits if empty or folder exists)
- Creates new widget folder from template
- Renames template.html to match folder name
- Updates demo.html with correct paths and names
Widget name required:
Widget name is required!
Exit code: 1
Widget already exists:
Widget folder already exists: s:/MPCustomWidgets/Widgets/My_Widget
Exit code: 1
- Node.js with TypeScript support (tsx)
- Existing
Widgets/WidgetTemplate/folder must be present - Must be run from project root directory
- Edit
Widgets/YourWidget/Template/YourWidget.html- Update LiquidJS template - Edit
Widgets/YourWidget/demo.html- Configure data attributes (data-sp, data-host, etc.) - Create MinistryPlatform stored procedure (prefixed with
api_Custom_) - Test widget using demo.html in browser
- Update widget README.md with specific documentation