Interactive interface for browsing global, full-resolution satellite imagery
Document build scripts better and clean up
Jo Sprague8b6f6226e164
diff --git a/Gruntfile.js b/Gruntfile.jsindex c6fd3391d..927f7eccf 100644--- a/Gruntfile.js+++ b/Gruntfile.js@@ -2,6 +2,7 @@var fs = require('fs');var moment = require('moment');+var pkg = require('./package.json');// Build date shown in the About boxvar buildTimestamp = moment.utc().format('MMMM DD, YYYY [-] HH:mm [UTC]');@@ -11,7 +12,13 @@ var buildNonce = moment.utc().format('YYYYMMDDHHmmssSSS');var buildNumber = moment.utc().format('YYMMDDHHmmss');module.exports = function(grunt) {- var pkg = require('./package.json');+ grunt.loadNpmTasks('grunt-contrib-clean'); // Used to remove build artifacts+ grunt.loadNpmTasks('grunt-contrib-copy'); // Used to move build artifacts around+ grunt.loadNpmTasks('grunt-exec'); // Used to run bash scripts+ grunt.loadNpmTasks('grunt-git-rev-parse'); // Used to get commit hashes+ grunt.loadNpmTasks('grunt-markdown'); // Used to convert md files to html+ grunt.loadNpmTasks('grunt-mkdir'); // Used to make build directories+ grunt.loadNpmTasks('grunt-text-replace'); // Used to replace token stringsvar hasCustomOptions = fs.existsSync('options');var optionsPath = hasCustomOptions ? 'options' : 'node_modules/worldview-options-eosdis';@@ -316,7 +323,7 @@ module.exports = function(grunt) {}},- remove: {+ clean: {build: ['build'],dist: ['dist'],// Removes all JavaScript, CSS, and auxillary files not necessary@@ -417,16 +424,6 @@ module.exports = function(grunt) {});- grunt.loadNpmTasks('grunt-contrib-clean');- grunt.loadNpmTasks('grunt-contrib-copy');- grunt.loadNpmTasks('grunt-exec');- grunt.loadNpmTasks('grunt-git-rev-parse');- grunt.loadNpmTasks('grunt-markdown');- grunt.loadNpmTasks('grunt-minjson');- grunt.loadNpmTasks('grunt-mkdir');- grunt.loadNpmTasks('grunt-text-replace');- grunt.loadNpmTasks('grunt-rename');-grunt.registerTask('load_branding', 'Load branding', function () {var brand = grunt.file.readJSON('build/options/brand.json');brand.officialName = brand.officialName || brand.name;@@ -443,59 +440,58 @@ module.exports = function(grunt) {});grunt.registerTask('build', [- 'clean:build_source',- 'git-rev-parse:source',- 'copy:source',- 'clean:source',- 'exec:empty',- 'copy:release',- 'mkdir:dist',- 'exec:tar_source_debug',- 'copy:dist_source_debug_versioned',- 'exec:tar_source_release',- 'copy:dist_source_release_versioned'+ 'clean:build_source', // Clear some directories+ 'git-rev-parse:source', // Get commit hash+ 'copy:source', // Copy source files into build/worldview-debug+ 'clean:source', // Removes unneccesary assets from build directory+ 'exec:empty', // Delete empty directories in the build+ 'copy:release', // Copy build/worldview-debug into build/worldview+ 'mkdir:dist', // Make dist directory+ 'exec:tar_source_debug', // Make worldview-debug tar from /build+ 'copy:dist_source_debug_versioned', // Add version number and hash to copy of tar+ 'exec:tar_source_release', // Make worldview-debug tar from /build+ 'copy:dist_source_release_versioned' // Add version number and hash to copy of tar]);grunt.registerTask('config', [- 'clean:build_config',- 'git-rev-parse:config',- 'clean:config_src',- 'markdown',- 'copy:config_src',- 'copy:brand_info',- 'mkdir:dist',- 'exec:tar_config',- 'copy:dist_config_versioned'+ 'git-rev-parse:config', // Get commit hash+ 'markdown', // Parse metadata and pages md files into html+ 'copy:config_src', // Copy build results to web/config and web/brand+ 'copy:brand_info', // Copy brand config file to build directory+ 'mkdir:dist', // Make dist directory+ 'exec:tar_config', // Create worldview-config tar from options directory+ 'copy:dist_config_versioned' // Create copy of tar with version number]);grunt.registerTask('site', [- 'load_branding',- 'clean:build_site',- 'copy:site',- 'replace:tokens',- 'exec:tar_site_debug',- 'copy:dist_site_debug_versioned',- 'exec:tar_site_release',- 'copy:dist_site_release_versioned'+ 'load_branding', // Set grunt variables from built options file+ 'clean:build_site', // Remove some build directories+ 'copy:site', // Copy /worldview and /worldview-config builds to /build/site+ 'replace:tokens', // Replace string placeholders in JS and HTML (no CSS)+ 'exec:tar_site_debug', // Create debug tar+ 'copy:dist_site_debug_versioned', // Create debug tar with version number+ 'exec:tar_site_release', // Create release tar+ 'copy:dist_site_release_versioned' // Create release tar with version number]);grunt.registerTask('rpm-only', [- 'load_branding',- 'git-rev-parse:source',- 'clean:rpmbuild',- 'mkdir:rpmbuild',- 'copy:rpm_sources',- 'replace:rpm_sources',- 'clean:dist_rpm',- 'exec:rpmbuild',- 'copy:rpm'+ 'load_branding', // Set grunt variables from built options file+ 'git-rev-parse:source', // Get commit hash+ 'clean:rpmbuild', // Remove build/rpmbuild directory+ 'mkdir:rpmbuild', // Create build/rpmbuild directory+ 'copy:rpm_sources', // Copy sources needed to build/rpmbuild+ 'replace:rpm_sources', // Replace name, version, release and build numbers in rpm+ 'clean:dist_rpm', // Remove any existing .rpm files+ 'exec:rpmbuild', // Run the command to build the rpm+ 'copy:rpm' // Copy rpm files to /dist]);+ // Set grunt variables, move .conf file to /dist and replace @WORLDVIEW@ and @ROOT@grunt.registerTask('apache-config', ['load_branding', 'copy:apache', 'replace:apache']);grunt.registerTask('default', [- 'build',- 'config',- 'site'+ 'build', // Copy assets to build directories and generate tar files+ 'config', // Build options artifacts and put them in build, dist, web+ 'site' // Combine /build/worldview and /build/options to create final build]);};diff --git a/bin/wv-options-build b/bin/wv-options-buildindex bc5ffe6bb..341a45216 100755--- a/bin/wv-options-build+++ b/bin/wv-options-build@@ -27,6 +27,7 @@ die() {# Activate virtual Python environmentPATH=.node-virtualenv/bin:.node-virtualenv/Scripts:${PATH}+# If $FETCH_GC is set fetch GetCapabilitiesif [ "$FETCH_GC" ] ; thenrm -rf "$OPT_DIR/release/gc/*"rm -rf "$OPT_DIR/release/colormaps/gc/*"@@ -34,6 +35,7 @@ if [ "$FETCH_GC" ] ; thenexit 0fi+# Copy options files to build directory, and various other file operationsrm -rf "$BUILD_DIR" "$DEST_DIR"mkdir -p "$BUILD_DIR" "$DEST_DIR"@@ -52,10 +54,13 @@ if [ -e "$BUILD_DIR/features.json" ] ; thencp "$BUILD_DIR/features.json" "$BUILD_DIR/config/wv.json/_features.json"fi+# Run wv-options-wmts script with config.jsonif [ -e "$BUILD_DIR/config.json" ] ; then"$BIN_DIR/wv-options-wmts" "$BUILD_DIR/config.json" "$BUILD_DIR/gc" \"$BUILD_DIR/config/wv.json/_wmts" "$BUILD_DIR/colormaps"fi++# Run wv-options-colormap and move colormaps where we want themif [ -e "$BUILD_DIR/colormaps" ] ; thenmkdir -p "$BUILD_DIR"/config/palettesif [ -d "$BUILD_DIR"/gc/colormaps ] ; then@@ -66,6 +71,7 @@ if [ -e "$BUILD_DIR/colormaps" ] ; then"$BUILD_DIR/config/palettes"fi+# Run wv-options-merge on all directories in /configconfigs=$(ls "$BUILD_DIR/config")for config in $configs; docase $config in@@ -79,9 +85,11 @@ for config in $configs; doesacdone+# Copy brand files from build to destcp -r "$BUILD_DIR/brand" "$DEST_DIR"cp "$BUILD_DIR/brand.json" "$DEST_DIR"+# Validate the options build"$BIN_DIR"/wv-options-validate "$BUILD_DIR/config.json" "$DEST_DIR/config"exit 0diff --git a/bin/wv-options-fetch b/bin/wv-options-fetchindex b234b34da..b4633f0b2 100755--- a/bin/wv-options-fetch+++ b/bin/wv-options-fetch@@ -44,10 +44,13 @@ def process_remote(entry):response = urllib.urlopen(url)contents = response.read()output_file = os.path.join(output_dir, entry["to"])++ # Write GetCapabilities responses to XML fileswith open(output_file, "w") as fp:fp.write(contents)gc = xmltodict.parse(contents)+ # Find all colormaps in GetCapabilities responses and store them in memorytry:for layer in gc["Capabilities"]["Contents"]["Layer"]:ident = layer["ows:Identifier"]@@ -70,6 +73,7 @@ def process_remote(entry):print(ident)print(str(traceback.format_exc()))+# Fetch every colormap from the API and write response to file systemdef process_colormaps():print "%s: Fetching %d colormaps" % (prog, len(colormaps))sys.stdout.flush()diff --git a/doc/config.md b/doc/config.mdindex 06e869d1b..f5a3894a0 100644--- a/doc/config.md+++ b/doc/config.md@@ -135,7 +135,7 @@ New layers in the Global Imagery Browse Services (GIBS) can be added to WorldvieFirst, layers must be added to `config/wv.json/layers` and `config/wv.json/layerOrder.json`. Then they must be added to the `config/wv.json/measurements` and `config/wv.json/categories` folders so that they will be categorized in the Product Picker. Lastly, if the layers have descriptions these can be added in `config/metadata` and if they are available in the Common Metadata Repository (CMR), data download may be enabled for those layers.-- Fetch GIBS GetCapabilities with `grunt fetch`. This gets the latest layer information and colormaps from GIBS.+- Fetch GIBS GetCapabilities with `npm run getcapabilities`. This gets the latest layer information and colormaps from GIBS.- Add new layer(s)- Follow [New Layers](https://github.com/nasa-gibs/worldview/blob/master/doc/config.md#new-layers) above to create JSON file in `config/wv.json/layers`.- Add to Measurementsdiff --git a/doc/developing.md b/doc/developing.mdindex 70f8349d8..3e628e195 100644--- a/doc/developing.md+++ b/doc/developing.md@@ -2,52 +2,40 @@## npm scripts-This project uses npm to run build scripts and other tasks. Here are the essential scripts;+This project uses `npm` as an interface to run build scripts and other tasks. The scripts themselves are a combination of JavaScript, Bash and Python scripts. Here are the essential scripts;++`npm install`: Installs JavaScript and Python dependencies.++`npm run build`: Runs all build scripts and generates built versions of the app. You can also build specific assets with `npm run build:css`, `npm run build:js`, `npm run build:tests` and `npm run build:config` (compiles configuration files).`npm start`: Starts the app for local development. More specifically, starts a web server that serves the contents of the `/web` directory.-`npm test`: Runs all tests and linting to verify code quality.+`npm watch`: Runs all of the build tasks necessary for local development in watch mode so that the build is automatically when source files change. You should run `npm run build` first to fetch GIBS configuration. This does not generate a final build, and is only for local development.++`npm test`: Runs all tests and linting to verify code quality. Make sure to run `npm run build` or `npm run build:tests` first to build a testable version of Worldview.`npm run lint`: Lints code against the project's style guides. Use `npm run lint:css` or `npm run lint:js` to lint CSS or JS files separately.`npm run e2e`: Runs end-to-end tests locally. Use `npm run e2e:chrome` or `npm run e2e:firefox` to run tests in a specific browser.-`npm run browserstack`: Runs end-to-end test on Browserstack.+`npm run browserstack`: Runs end-to-end tests on Browserstack.-`npm build`: Creates JS and CSS bundles from the source and places them in `/web/build`. Use `npm run build:js` or `npm run build:css` to build JS or CSS individually.--These scripts are also available;+`npm run getcapabilites`: Makes a request to the GIBS `GetCapabilities` API and updates layer configurations.`npm run report`: Generates a readable HTML report with the results of the last end-to-end test.-`npm run preinstall`: Checks to see if your installed version of Node matches the recommended version for Worldview.-## Grunt tasksWe're in the process of replacing our Grunt tasks with npm scripts, but here are the Grunt build scripts that are available. Note, these are poorly documented and you should use caution when running these scripts if you don't know what you're doing. Your mileage may vary when running scripts marked with a `*` by themselves.-`grunt`: The default Grunt task runs all of the scripts necessary to generate a build. Among other things, it updates Python dependencies, applies branding and other configuration options, compiles assets and generates build artifacts in `/build` and `/dist`. The default Grunt task does not run tests.--`grunt test`: Runs Buster integration tests.--`grunt config`* : Updates branding and configuration options.--`grunt site`* : Generates build assets for deployment.--`grunt fetch`* : Makes a request to the GIBS `GetCapabilities` API and updates layer configurations.--`grunt build`* : Generates build assets.--`grunt lint`: Lints JavaScript files--`grunt check`: Runs `grunt test` and `grunt lint`.+`grunt`: The default Grunt task runs all of the scripts necessary to generate a build. Among other things, it applies branding and other configuration options, compiles assets and generates build artifacts in `/build` and `/dist`. The default Grunt task does not run tests.-`grunt distclean`: Removes build artifacts in `/build` and `/dist`.+`grunt config`* : Compiles branding and configuration options into an intermediate build directory and generates `tar` files of that directory.-`grunt clean`: Removes build artifacts in `/build`.+`grunt build`* : Adds a git commit hash to source files, copies them into an intermediate build directory and generates `tar` files of that directory.-`grunt update-packages`: Updates Python dependencies.+`grunt site`* : Combines the results of `grunt config` and `grunt build` into final `/build` and `/dist` directories and generates `tar` files of the final build.`grunt rpm-only`: Creates an RPM on CentOS 6 and places it in the `/dist` directory.-`grunt apache-config`* : Generates `/dist/worldview.conf` for deployment to an Apache server.+`grunt apache-config`* : Moves `worldview.conf` to the `/dist` directory for deployment to an Apache server.