Giter Club home page Giter Club logo

generator-esri-appbuilder-js's Introduction

Archived: this project has been archived. For help getting started building Web AppBuilder widgets, see Widget Development and Theme Development on the official documentation site.

generator-esri-appbuilder-js Build Status

Yeoman generator to help customize the ArcGIS Web AppBuilder.

About

This generator scaffolds out the boilerplate files that are needed when you are customizing the Web AppBuilder. This includes generators to set up your project and scaffold out the files needed to create custom widgets.

Screenshot

Getting Started

Installation

The first prerequisite is to have the grunt-cli installed. To install this, run:

npm install -g grunt-cli

Next you must install Yeoman:

$ npm install -g yo

Finally install generator-esri-appbuilder-js from npm:

$ npm install -g generator-esri-appbuilder-js

Running the Generators

The generators should be run in the root of a working folder for your project. This should be outside of the Web AppBuilder's folder structure (i.e. NOT in the stem app or an app that you've already created with the Web AppBuilder). The grunt tasks configured by the generators will handle copying the widget files to the appropriate folders under the Web AppBuilder's install directory. Because of this, the generator will ask you what app to use. If you select None or do not have any Web AppBuilder apps in your Web AppBuilder install directory, the grunt file will be created but will not be configured to copy your code to the appropriate app directory. If you create an app after running the Yeoman generator, you can either go to the Gruntfile and make manual edits (you'll see details in there), or you can re-run this generator and it will offer to overwrite your Gruntfile.

App (Default) Generator

The app generator installs and configures the grunt tasks and other project files and ensures that required subfolders (like widgets) exist.

  1. Navigate into the root folder of your project
  2. Run the generator with yo esri-appbuilder-js
  3. Answer the man's questions!
Prompt Description Default
Type of widget(s) to be generated Whether you want to build 2D or 3D widgets 2D
Web AppBuilder install root The root folder where you installed (unzipped) the Web AppBuilder Developer Edition [USER_HOME_FOLDER]/WebAppBuilderForArcGIS
Web AppBuilder application The name of the application you would like the grunt task to sync your code with None
Would you like to use SASS for CSS preprocessing? If you choose yes, you can utilize features from SASS like nesting, variables, etc. Yes
Which JavaScript syntax version would you like to develop in? Will widget and settings JavaScript files use ES5, ES2015, or TypeScript? ES5

Widget Generator

Scaffolds out the files needed to create a new custom widget.

  1. Navigate into the root folder of your project
  2. Run the generator with yo esri-appbuilder-js:widget
  3. Answer the man's questions!
Prompt Description Default
Widget Name Folder name for output files and widget identifier MyWidget
Widget Title Name users see in widget selector and panel title bar My Widget
Description What does this widget do? (optional) A custom Web AppBuilder widget
Base Class The widget's base class my-widget
Run inside a panel Will your widget run inside a panel? Yes
Locale (i18n) file Will your widget require a locale file? Yes
Style (CSS) file Will your widget require a style file? Yes
Config (JSON) file Will your widget require a configuration file? Yes
Template (HTML) file Will your widget require a template file? Yes
Would you like a settings page? Will your widget have a settings page? Yes
Settings template (HTML) file Will your settings page require a template file? Yes
Settings locale (i18n) file Will your settings page require a locale file? Yes
Settings style (CSS) file Will your settings page require a style file? Yes

Taking the default values for the prompts will generate the following output under the widgets folder (note: if you choose TypeScript style, there will be .ts files instead of JS):

MyWidget
│   config.json
│   manifest.json
│   Widget.html
│   Widget.js
│
├───css
│       style.css (or style.scss)
│
├───images
│       icon.png
│
├───nls
│       strings.js
│
└───setting
    |   Setting.js
    |   Setting.html
    ├───nls
    |       strings.js
    └───css
            style.css

After you copy the widget files to the Web AppBuilder's stemapp, the next time you run the Web AppBuilder, you will see something like the following on the widgets panel:

Widget in the Builder

Optional Settings

Users are also able to scaffold out widgets without creating an application base. When running yo esri-appbuilder-js:widget from a root without an existing .yo-rc.json file, these additional questions will be asked prior to the questions above.

Prompt Description Default
Choose your widget directory The location you want your widgt to be built. E.g ./ for root None
Type of widget(s) to be generated Whether you want to build 2D or 3D widgets 2D
Would you like to use SASS for CSS preprocessing? If you choose yes, you can utilize features from SASS like nesting, variables, etc. Yes
Which JavaScript syntax version would you like to develop in? Will widget and settings JavaScript files use ES5, ES2015, or TypeScript? ES5

Copying Widget Files

In order for the widgets that you're working on to be available in the Web AppBuilder you will need to copy their files to the appropriate folder under the Web AppBuilder's install root.

Copying the Files Manually

For example, let's say you've installed the Web AppBuilder in c:\WebAppBuilderForArcGIS, then you'll need to copy widget files to the following folder under the stem app:

c:\WebAppBuilderForArcGIS\client\stemapp\widgets

Also, you'll likely want to copy widget files to any applications that you've created that use them:

c:\WebAppBuilderForArcGIS\server\apps\[appId]\widgets

Unless you're using the grunt tasks, you'll need to re-copy the files each time you make changes to the files.

Running the Grunt Tasks

The easiest way to keep your widget files in sync with the Web AppBuilder is to run the grunt tasks. After running the generators, you can run the default grunt task following at the project root:

grunt

This will copy over any files that haven't already been copied over, and then start watching all files under the widgets folder for changes and re-copy the files to the Web AppBuilder's folders.

Livereload

The generator enables Livereload by default in the Gruntfile that it creates. This means the Grunt watch task will run at the default livereload port so you can use a browser extension to have the page reload when you save your source widget files. See grunt-contrib-watch for advanced customization. Extensions are available in all major browsers (Example for Google Chrome)

Linting Your Code

The app generator does not scaffold out any linting files. We recommend that you use some form of linting, either jshint, semistandard, or eslint. An example of using semistandard is below:

  1. Install semistandard:
npm install -g semistandard
  1. Below is a sample configuration you can add to your package.json:
  "semistandard": {
    "globals": [
      "define"
    ],
    "ignore": [
      "Gruntfile.js",
      "**/dist/**/*.js"
    ]
  }
  1. Validate your code:
semistandard

See the semistandard docs for more information.

TypeScript

If you choose TypeScript as the answer to the Which JavaScript syntax version would you like to develop in?, the TypeScript compiler will be used to build your Widget TypeScript file into an AMD Widget JS file that Web AppBuilder is expecting. There are a few considerations to understand when doing this.

Widgets in Template

If you add templated widgets to your html (ex: <div data-dojo-type="dijit/layout/AccordionPane" title="pane #1">accordion pane #1</div>), you both need to mix in the template:

@declare(BaseWidget, _WidgetsInTemplateMixin)
class Widget implements IWidget {

AND call the startup of _WidgetsInTemplateMixin

 public startup(args: any): void {
    BaseWidget.prototype.startup.call(this, args);
    _WidgetsInTemplateMixin.prototype.startup.call(this, args);

See here for more information on this pattern.

Building for Production

When you're ready to publish your application in a user facing environment, improve performance by running:

npm run build

The resulting package can be found in dist/buildOut/app.zip

This will repackage and compress your application with only the neccessary elements. We have found this to result in massive performance improvements.

NOTE: This feature is only available for 2D applications with a chosen Web AppBuilder application.

System Requirements

We aim to support LTS versions of Node.js. Right now that means Node.js v8.0 and heigher.

Issues

Find a bug or want to request a new feature? Please let us know by submitting an issue.

Contributing

We welcome contributions from anyone and everyone. Please see Esri's guidelines for contributing.

Credit

This generator was inspired by @steveoh and @stdavis's generator-dojo-widget as well as @dbouwman's generator-bootmap.

Licensing

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.

generator-esri-appbuilder-js's People

Contributors

davewilton avatar dependabot[bot] avatar gavinr avatar gavinr-maps avatar gbochenek avatar jcartwright-noaa avatar jpurush avatar mlewis22 avatar sevenninety avatar spohner avatar tomwayson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

generator-esri-appbuilder-js's Issues

Widget generator should base default for title on widget name

If the answer to the first prompt is 'NewWidget' then the default title should be 'New Widget' - I think this can be done by setting the default property of the title prompt to a function.

See: https://github.com/SBoudrias/Inquirer.js#question

Also, to break a string on the capital letters, see:

http://stackoverflow.com/questions/7888238/javascript-split-string-on-uppercase-characters

Also, we may want to replace the CSS prefix prompt with a prompt for base class that defaults to the dasherized widget name. That way users can override the default that we currently generate.

Pull 2D or 3D info from chosen app's config.json

After #54, the app asks if the app is 2D or 3D. If we moved that prompt to after asking for the WABROOT and app, then we could know if it's 2D or 3D based on the app's config.json. We would still need to prompt the user for 2D or 3D in the case that "none" is selected on the "Web AppBuilder Application" prompt.

Missing mkdirp dependency

Installing this on a clean machine it appears that mkdirp is not installed. I think it will be if it's moved from devDependencies to dependencies.

change initial instructions?

This is the instructions when running yo esri-appbuilder-js:

The generators should be run in the root folder of either the stem app or an app that you've already created with the Web AppBuilder.

But this is from the readme:

The generators should be run in the root of a working folder for your project. This should be outside of the Web AppBuilder's folder structure (i.e. NOT in the stem app or an app that you've already created with the Web AppBuilder). The grunt tasks configured by the generators will handle copying the widget files to the appropriate folders under the Web AppBuilder's install directory.

Option to use CSS preprocessor for styles

It would be nice if I, as a developer, could use my favorite CSS preprocessor and the gruntfile would automatically build that out into the CSS files for the widgets.

Just adding this as a placeholder for discussion.

Option to extend from an existing widget

Many times when creating a new widget, you actually want to extend from an existing widget (Measurement, layer list, etc). Would be nice if that's an option in the generator.

I hear @gbochenek has been doing some research around this concept ... PRs welcome :) :)

add ability to generate 3d widgets

Look at structure of 3d widgets in WAB 2.0 beta for differences (prob more than just the 2d/3d setting in manifest), and add a prompt that let's user choose 2/d/3d.

Don't scaffold .jshint file?

It's so easy for people to use eslint init or npm install semistandard to get exactly the rules they want instead of the JSAPI rules (which are targeting IE8, etc).

At the least we should:

  • update the .jshintc template in this to the latest JSAPI rules
  • not scaffold .jshintrc if a user chooses ES6
  • If not ES6 prompt the user if they want to use Esri's .jshintrc? dunno

Remove 2D/3D properties from manifest.json

@sam-berg discovered that the 2D/3D properties are causing widgets not to show up in the select widget dialog in beta2:

Built in Query (works):

{
  "name": "Query",
  "platform": "HTML",
  "version": "",
  "author": "Esri R&D Center Beijing",
  "description": "",
  "copyright": "",
  "license": "http://www.apache.org/licenses/LICENSE-2.0"
}

Custom, Works:

{
  "name": "CommanderSearch",
  "platform": "HTML",

  "version": "0.0.1",
  "author": "Esri Boston",
  "description": "test",
  "copyright": "",
  "license": "http://www.apache.org/licenses/LICENSE-2.0",
    "properties": {
    "inPanel": true,
    "hasLocale": false,
    "hasUIFile": false,
    "hasStyle": false
  }
}

Custom, Does not work:

{
  "name": "CommanderSearch",
  "platform": "HTML",
  "2D":"true",
  "3D":"false",
  "version": "0.0.1",
  "author": "Esri Boston",
  "description": "test",
  "copyright": "",
  "license": "http://www.apache.org/licenses/LICENSE-2.0",
    "properties": {
    "inPanel": true,
    "hasLocale": false,
    "hasUIFile": false,
    "hasStyle": false
  }

}

Custom, Does not work:

{
  "name": "CommanderSearch",
  "platform": "HTML",
  "2D":"true",
  "3D":"false",
  "version": "0.0.1",
  "author": "Esri Boston",
  "description": "test",
  "copyright": "",
  "license": "http://www.apache.org/licenses/LICENSE-2.0",
    "properties": {
    "inPanel": false,
    "hasLocale": false,
    "hasUIFile": false,
    "hasStyle": false
  }

}

Generated theme doesn't work w/ WAB v 1.3

I generated a theme using default responses to all prompts and then copied to WAB v1.3 stemapp. I then createad a new app using the Default template and tried to apply the theme. I see this error in the console:

image

Drop theme sub generator?

Is anyone using this? @spohner, @g3r4n, @jPurush, @gavinr? Seems like the normal practice for creating a custom theme is to copy an existing one that is closest to the one you want to create. So I'm not sure that a generator based on a single theme even makes much sense.

Furthermore, there's an open bug #33 that I have no plan to fix, and I don't know of any contributors that are interested in maintaining the theme generator. This means it will be hard to continue to evolve this repo as long as we have to continue to work around the broken theme generator.

One idea is to consider merging #36 as a v2 (it requires a bump in the version of the yeoman-generator dependency to at least v0.17) - at which point we could make breaking changes, including dropping the theme.

cc @yiweima, @asizer, @qlqllu

Base on yeoman-generator v0.18

Since v2.0.0 is a breaking change, might as well be on latest ver of yeoman-generator. Also, there is a very slight chance that we'll need this for #39.

Even if not, I'm almost certain that we'll want it for v2.1 so the default generator can store the user's ES6 preference for later use in the widget generator. So if this does not happen for v2.0 it will go into v2.1.

See the v0.18 blog post for info.

Widget generator should prompt for all widget properties

Currently only prompts for inPanel, but could prompt for all of the following and only build out the required files. Since all are booleans and default to true, could be done w/ one checklist prompt that defaults to checked, like:

[x] inPanel
[x] hasLocale
[x] hasStyle
[x] hasConfig
[x] hasUIFile
[x] hasSettingPage

If hasSettingsPage is checked, then could show a second prompt w/ the following (defaulting to answers from above for hasUIFile, hasLocale, and hasStyle):

[x] hasSettingUIFile
[x] hasSettingLocale
[x] hasSettingStyle

Based on the answers from above, the generator would create the appropriate files and update the properties object in manifest.json and clazz object as needed.

While this would be simple to implement (aside from basing the second pompt on answers from the first), writing tests for the un/checked state of each could be time consuming.

app generator prompts for 2d/3d

Answer will determine:

  • output folder (stemapp or stemapp3d)
  • default path to wab root folder (use current for 2d, if 3d, default to ...\WebAppBuilderForArcGIS)

Store response to 2d/3d for use in widget generator. See this blog post and PR.

prompt for app id

(either blank or a number) instead of hardcoding appDir to 2
add docs explainign this and possibly encouraging creation of test app ahead of time

see #36 for context as to ultimate goal (prompt by app name) - maybe it makes sense to go all the way at this point?

Support JSHint 2.9.x - ES Versions

Custom theme support

It would be good if the grunt task supported copying custom themes over to the Web App Builder Install as 'on screen'/inPanel=false widgets are developed as part as a theme (as far as I'm aware).

Validate against WAB v1.3

Verify that the generated widgets/themes work w/ WAB v1.3, and make any changes to match the sample widget/theme code that ships w/ v1.3.

Option for LiveReload

Using LiveReload is pretty easy, in conjunction with the "watch" Gruntfile task. Should we ask the user if they want to enable this?

Widget is not appearing in ArcGIS Web App Developer Widget container

I was able to follow instruction as described. Everything worked smoothly and I created a TEST1 widget. TEST1 widget folder has created in application's widget folder successfully. But it did not appear in Application's editor > Widget container .(Other default widgets is appearing but not new TEST1 widget)

What I am doing wrong here ?
Does new widget need to be register with ArcGIS Web App Developer module ?

Best regards

Anjitha

Add deployment grunt task?

I was reading this excellent guide on sharing your WAB widgets and I was thinking that we could help automate the "Create a Demo App" section.

I would say rather than move the demo app under the github repo, have the grunt-gh-pages task pull the app directly from the app folder under the WAB folder structure since we know the path.

not a valid path?

I've used this tool with previous versions of WAB, but recently I get an error when specifying the path to the WAB root. I've tried all the combinations of root locations; drive letters; directory names; but nothing seems to work.

I've not looked at the source code yet to see if you are catching an error that I am not aware of but I'd like to go ahead and submit this request for a possible bug.

Documentation is not accurate

Documentation says
Navigate into either stemapp or builder/apps/[appId] under your local Web AppBuilder installation
/builder/apps/[appid] does not exist, however server/apps/[appId] does

Offer option to generate ES6 files

Instead of using grunt sync/copy to copy ES5 files from the working folder to the WAB, we could work in ES6 and use grunt babel to transpile the code and output to the WAB folder.

This should happen after #28

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.