|
| 1 | +# Converting a Pluggable Widget into a Mendix **Module** |
| 2 | + |
| 3 | +This guide captures the workflow we followed in chat to turn **@mendix/calendar-web** (a standalone widget) into **@mendix/calendar** (a full-fledged module that ships pages, domain model, microflows _and_ the widget). It mirrors the conventions used by the automation scripts in this mono-repo (`automation/utils`). |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Terminology |
| 8 | + |
| 9 | +| Term | Purpose | |
| 10 | +| ------------------- | ---------------------------------------------------------------------------------------------------------------------------- | |
| 11 | +| _Widget package_ | `.mpk` produced by Rollup in `packages/pluggableWidgets/<name>-web`; contains only `<clientModule>` (JavaScript, XML, SCSS). | |
| 12 | +| _Module package_ | `.mpk` exported by Studio Pro; contains `<module>` (pages, microflows, domain model **plus** embedded widget mpk). | |
| 13 | +| **Authoring app** | Your working project where you design the pages/microflows for the module. | |
| 14 | +| **Host / test app** | A minimal blank project used by CI to (re)export the module; committed to `mendix/testProjects` repo. | |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 2. Prerequisites |
| 19 | + |
| 20 | +- Node + `pnpm install` executed in the mono-repo. |
| 21 | +- **@mendix/_widget_-web** already builds (`pnpm run build`). |
| 22 | +- GitHub Personal-Access Token saved as secret `GH_PAT` for release workflow. |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## 3. Create / Export the Module in Studio Pro |
| 27 | + |
| 28 | +1. **Authoring app**: make sure everything lives inside one module (e.g. _Calendar_). |
| 29 | +2. Right–click that module → _Export module package…_ → save `Calendar.mpk`. |
| 30 | + _This file contains pages, flows, entities and the widget placeholder._ |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## 4. Prepare the Host Test Project |
| 35 | + |
| 36 | +1. Start a **Blank App** in Studio Pro (or `mx create-project`). |
| 37 | +2. _App → Import module package…_ and select the `Calendar.mpk` from step 3. |
| 38 | +3. Optional: add a navigation item to a Calendar page so the app runs out-of-box. |
| 39 | +4. Close Studio Pro. |
| 40 | +5. In terminal: |
| 41 | + ```bash |
| 42 | + cd <project-folder> |
| 43 | + git init |
| 44 | + git switch -c calendar-web # branch must match package.json |
| 45 | + git remote add origin https://github.com/mendix/testProjects.git |
| 46 | + echo "/deployment/\n/theme-cache/" > .gitignore |
| 47 | + git add . |
| 48 | + git commit -m "Initial Calendar host project" |
| 49 | + git push -u origin calendar-web # or pull –rebase first if branch exists |
| 50 | + ``` |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## 5. Scaffold the Module Package in the Mono-repo |
| 55 | + |
| 56 | +``` |
| 57 | +packages/modules/calendar/ |
| 58 | + ├─ package.json ← see template below |
| 59 | + ├─ CHANGELOG.md |
| 60 | + ├─ LICENSE ← Apache 2.0 copy |
| 61 | + ├─ .prettierrc.js |
| 62 | + └─ scripts/ |
| 63 | + ├─ build.ts |
| 64 | + ├─ push-update.ts |
| 65 | + ├─ release.ts |
| 66 | + └─ tsconfig.json |
| 67 | +``` |
| 68 | +
|
| 69 | +### `package.json` highlights |
| 70 | +
|
| 71 | +```jsonc |
| 72 | +{ |
| 73 | + "name": "@mendix/calendar", |
| 74 | + "mxpackage": { |
| 75 | + "type": "module", |
| 76 | + "name": "Calendar", |
| 77 | + "mpkName": "Calendar.mpk", |
| 78 | + "dependencies": ["@mendix/calendar-web"] |
| 79 | + }, |
| 80 | + "moduleFolderNameInModeler": "calendar", // themesource/javascriptsource |
| 81 | + "testProject": { |
| 82 | + "githubUrl": "https://github.com/mendix/testProjects", |
| 83 | + "branchName": "calendar-web" |
| 84 | + }, |
| 85 | + "scripts": { |
| 86 | + "build:module": "ts-node --project scripts/tsconfig.json scripts/build.ts", |
| 87 | + "release:module": "ts-node --project scripts/tsconfig.json scripts/release.ts" |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +Scripts are copied from `packages/modules/file-uploader/scripts/`. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## 6. Local Verification |
| 97 | + |
| 98 | +```bash |
| 99 | +# build the widget first |
| 100 | +pnpm --filter @mendix/calendar-web run build |
| 101 | + |
| 102 | +# Option A: point to a running Studio Pro project |
| 103 | +export MX_PROJECT_PATH="$HOME/Mendix/CalendarHost" |
| 104 | + |
| 105 | +# Option B: rely on tests/testProject folder |
| 106 | +# (create it or let cloneTestProject do it in release script) |
| 107 | + |
| 108 | +pnpm --filter @mendix/calendar run build:module |
| 109 | +``` |
| 110 | + |
| 111 | +The command clones (or uses `MX_PROJECT_PATH`) and copies `com.mendix.widget.web.calendar.mpk` into `widgets/`. Open the project in Studio Pro and run. |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## 7. Produce the Distributable MPK |
| 116 | + |
| 117 | +```bash |
| 118 | +pnpm --filter @mendix/calendar run release:module |
| 119 | +``` |
| 120 | + |
| 121 | +Pipeline steps (see `automation/utils/src/steps.ts`): |
| 122 | + |
| 123 | +1. `removeDist` clean old output |
| 124 | +2. `cloneTestProject` clone branch `calendar-web` |
| 125 | +3. `writeModuleVersion` / `copyModuleLicense` |
| 126 | +4. `copyWidgetsToProject` add fresh widget mpk |
| 127 | +5. `createModuleMpk` export Calendar module via _mxbuild_ |
| 128 | +6. `addWidgetsToMpk` embed widget MPK in module MPK |
| 129 | +7. `moveModuleToDist` place under `dist/<version>/Calendar.mpk` |
| 130 | + |
| 131 | +Upload the resulting MPK to the Mendix Marketplace. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## 8. CI / GitHub Actions |
| 136 | + |
| 137 | +• `.github/workflows/CreateGitHubRelease.yml` uses `${{ secrets.GH_PAT }}` to create a release and attach the MPK asset. Set that PAT in _Repo → Settings → Secrets → Actions_. |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## 9. Quick Checklist |
| 142 | + |
| 143 | +✔ Authoring module exported → `Calendar.mpk` |
| 144 | +✔ Host project committed to `testProjects` (`calendar-web` branch) |
| 145 | +✔ `@mendix/calendar` module package with correct metadata & scripts |
| 146 | +✔ Local `build:module` works |
| 147 | +✔ `release:module` produces `dist/Calendar.mpk` |
| 148 | + |
| 149 | +You now have a fully-packaged module ready for Marketplace users to drag-and-drop without extra configuration. |
0 commit comments