Skip to content

Commit e6f6525

Browse files
[WTF-1751] Improve Widget Generator DevX by introducing npx command line (#76)
## What is the purpose of this PR? This PR introduces a npx command line to quickly scaffold a widget without the need to install Yeoman Generator and the @medix/generator-widget package. Currently, to generate a widget you need to first install the `yeoman` package globally together with the `@medix/widget-generator`. With this change you can just call the @medix/widget-generator package directly from the command line using npx. Example: `npx @mendix/generator-widget MyWidgetName`
2 parents 8a0b6e7 + 451fde8 commit e6f6525

File tree

7 files changed

+9141
-11868
lines changed

7 files changed

+9141
-11868
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ A toolset to build, test, format, run, release and lint Mendix Pluggable Widgets
1616

1717
## Generator widget
1818

19-
Yeoman scaffolding tool to let you quickly create a Mendix Pluggable Widget.
19+
Scaffolding tool to let you quickly create a Mendix Pluggable Widget.
20+
21+
#### Note
22+
23+
- If you are running the generator through multiple operating systems (e.g. running a virtualized OS with Parallels on MacOS or any other virtualization software), make sure you have the right privileges and use the same OS for generation and file manipulation.
24+
25+
- If you want to test locally your changes to the Generator Widget, simply link the package running `npm link` inside the `packages/generator-widget/` folder and then you will be able to run `yo widget SomeWidgetName`
2026

2127
[Source](./packages/generator-widget/) | [NPM Package](https://www.npmjs.com/package/@mendix/generator-widget)
2228

packages/generator-widget/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- We introduced an easier way to scaffold a pluggable widget using an npx command without the need to install Yeoman Generator and the @mendix/generator-widget package.
12+
913
## [10.5.0] - 2023-12-01
1014

1115
### Changed

packages/generator-widget/README.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Pluggable Widgets Generator
1+
# Mendix Pluggable Widgets Generator
22

33
![npm version](https://badge.fury.io/js/%40mendix%2Fgenerator-widget.svg)
44
![Mendix 8](https://img.shields.io/badge/mendix-8.0.0-brightgreen.svg)
@@ -7,39 +7,26 @@
77
![GitHub release](https://img.shields.io/github/release/mendix/widgets-tools)
88
![GitHub issues](https://img.shields.io/github/issues/mendix/widgets-tools)
99

10-
> [Yeoman](http://yeoman.io) generator for Mendix Pluggable Widgets.
11-
1210
## About
1311

14-
This generator uses the Yeoman scaffolding tool to let you quickly create a [Mendix Pluggable Widget](https://docs.mendix.com/howto/extensibility/pluggable-widgets).
12+
The Mendix Pluggable Widget Generator is a scaffolding tool to let you quickly create a [Mendix Pluggable Widget](https://docs.mendix.com/howto/extensibility/pluggable-widgets).
1513

1614
## Installation
1715

18-
1. Install [node.js](https://nodejs.org/) (version >= 12).
19-
1. Install [Yeoman](http://yeoman.io):
20-
21-
```bash
22-
npm install -g yo
23-
```
24-
25-
1. Install Pluggable Widgets Generator:
26-
27-
```bash
28-
npm install -g @mendix/generator-widget
29-
```
16+
1. Install [node.js](https://nodejs.org/) (version >= 16).
3017

3118
## Scaffold a widget project
3219

3320
1. Generate your new project inside an empty folder:
3421

3522
```bash
36-
yo @mendix/widget
23+
npx @mendix/generator-widget
3724
```
3825

3926
or automatically create the folder using:
4027

4128
```bash
42-
yo @mendix/widget MyWidgetName
29+
npx @mendix/generator-widget MyWidgetName
4330
```
4431

4532
Note that `MyWidgetName` can consist of space characters as well.
@@ -113,10 +100,6 @@ npm run release
113100
npm start
114101
```
115102

116-
- If you are running the generator through multiple operating systems (e.g. running a virtualized OS with Parallels on MacOS or any other virtualization software), make sure you have the right privileges and use the same OS for generation and file manipulation.
117-
118-
- If you want to test locally your changes to the Generator Widget, simply link the package running `npm link` inside the `packages/generator-widget/` folder and then you will be able to run `yo widget SomeWidgetName`
119-
120103
## Issues
121104

122105
Issues can be reported on [Github](https://github.com/mendix/widgets-tools/issues).

packages/generator-widget/bin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
const { readFileSync } = require("fs");
4+
var { join } = require("path");
5+
const { execSync } = require("child_process");
6+
const chalk = require("chalk");
7+
8+
const packageJson = readFileSync(join(__dirname, "package.json"));
9+
const version = JSON.parse(packageJson).version;
10+
const args = process.argv.slice(2);
11+
12+
console.log(chalk.bold.blueBright("Running widget generator..."));
13+
execSync(`npm install -g yo @mendix/generator-widget@${version}`);
14+
execSync(`yo @mendix/widget@${version} ${args.join(" ")}`, { stdio: "inherit" });

packages/generator-widget/generators/app/lib/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
`,
2020

2121
DIR_NOT_EMPTY_ERROR: chalk.bold.red(
22-
"The directory you are trying to use is not empty, please open the generator in an empty folder or type yo @mendix/widget WidgetName\n"
22+
"The directory you are trying to use is not empty, please open the generator in an empty folder or type npx @mendix/generator-widget WidgetName\n"
2323
),
2424
INSTALL_FINISH_MSG:
2525
"File configuration done, now running " + chalk.blueBright("npm install") + " to install dependencies",

0 commit comments

Comments
 (0)