Esri / generator-esri-appbuilder-js

Yeoman generator to help customize Esri's WebAppBuilder
Apache License 2.0
181 stars 61 forks source link

Widget generator does not work if App generator is not run first #119

Closed dzackgarza closed 5 years ago

dzackgarza commented 6 years ago

To reproduce:

npm install -g yo generator-esri-appbuilder-js
yo esri-appbuilder-js:widget

It looks like it attempts to read a number of config variables that are set by the main generator. In my case, I only wanted to scaffold a new widget to drop into an existing app, and didn't particularly want/need to go through the process of fiddling with Esri's WebappBuilder SDK or anything like that.

Would it perhaps be possible to just ask for these config variables in the Widget sub generator as well, instead of relying on the main generator being run first?

gavinr commented 6 years ago

@dzackgarza thanks for the report. Currently, it is required that you run the "main generator" (aka "App" or "Default" Generator) first before running the widget subgenerator. We should probably make this fact more explicit in the documentation.

You're correct that the widget generator depends on a variety of questions that are asked by the Main/App/Default Generator. For example if you've chosen to use SASS for CSS preprocessing, the widget generator will create you a style.scss file instead of a style.css file. We've never really thought about extracting the creation of the widget from the main generator, because there are so many benefits that come with the main generator including a grunt task runner, the SCSS stuff that I mentioned earlier, ES6 or TypeScript transpilation, etc. A few thoughts come to mind:

  1. Workaround: I assume you have web appbuilder developer edition installed somewhere on your machine - if you simply run the Default Generator first, pointing to that Web AppBuilder location, and then run the widget generator, you will get what you want. As long as you don't run the grunt command after you run the widget generator, no changes will be made to your Web AppBuilder install.
  2. Would making the "Web AppBuilder install root` question of the generator optional make the above workaround easier for cases like yours where you just want to get the widget files out. This might be the best "quick win" to resolve your issue above.
  3. Why do we even have a 2-step process at all? I do not think this solves your problem, but maybe we should switch to having just a single yeoman task, that automatically asks you the "initial" questions (The questions currently in the Default Generator) if necessary but if you've already answered those, jump directly into the widget questions. (props to @gbochenek for this idea)
    • As part of this process one of the questions could be something like "do you want to install the Grunt task runner (file copier and transpiler for ES6 or TypeScript) or just get the widget files directly (ES5 style javascript only)" ... this would address the request above.
    • This might be a significant re-work of the codebase, so I'd like to hear others weigh in on this
tomwayson commented 6 years ago

re: 3.

A significant reason for the 2 step process is exactly that - there are several questions you don't want to answer more than once. If it can be done as a one step process that retains the answers to the first questions (I recall that yeoman has some mechanism for that), that might be slicker, but I don't think any easier to explain than the current 2 step process.

mlewis22 commented 5 years ago

I have added a pull request to solve this - I had a project requirement for it so shared the code - #145

It will present you with the widget generation options if you haven't deployed the generator before. If you have, it continues as before. I wanted to use the template here for a project using different task runners and docker.