Skip to content

Commit 4ee1960

Browse files
Crafting: Programmatically run generator from bin script (#125)
## Checklist - Contains unit tests ❌ - Contains breaking changes ❌ - Compatible with: MX 7️⃣, 8️⃣, 9️⃣ - Did you update version and changelog? ✅ - PR title properly formatted (`[XX-000]: description`)? ✅ ## This PR contains - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [ ] Other (describe) ## What is the purpose of this PR? There was a noticeable startup time when generating a widget using `npx @mendix/generator-widget`. This was due to the bin script installing yeoman and the generator globally each time. ## Relevant changes - The generator is run using `yeoman-environment` (which the `yo` cli tool is a wrapper for). - Dependencies with vulnerabilities have been patched using `npm audit` ## What should be covered while testing? Generating a widget using the `bin.js` script.
2 parents bbc0d65 + 4a5efbf commit 4ee1960

4 files changed

Lines changed: 2024 additions & 3339 deletions

File tree

packages/generator-widget/CHANGELOG.md

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

77
## [Unreleased]
88

9+
### Changed
10+
11+
- We improved the startup time when using the generator with `npx`.
12+
913
### Fixed
1014

1115
- We fixed the error message when attempting to generate a widget in a non-empty directory. (Issue #123)
1216

17+
### Security
18+
19+
- We updated dependencies to recent security patches.
20+
1321
## [10.15.0] - 2024-09-24
1422

1523
### Changed

packages/generator-widget/bin.js

100644100755
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#!/usr/bin/env node
2-
3-
const { readFileSync } = require("fs");
42
var { join } = require("path");
5-
const { execSync } = require("child_process");
63
const chalk = require("chalk");
74

8-
const packageJson = readFileSync(join(__dirname, "package.json"));
9-
const version = JSON.parse(packageJson).version;
10-
const args = process.argv.slice(2);
5+
console.log(chalk.bold.blueBright("Initializing the widget generator..."));
6+
const yeoman = require('yeoman-environment');
7+
const env = yeoman.createEnv();
8+
env.register(join(__dirname, "./generators/app/index.js"), "@mendix/widget");
119

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" });
10+
const args = process.argv.slice(2);
11+
env.run(['@mendix/widget', ...args].join(" "))

0 commit comments

Comments
 (0)