Interactive interface for browsing global, full-resolution satellite imagery
mergeConfig.js and util.js converted
ZachTRice2a0cac270615
diff --git a/tasks/build/mergeConfig.js b/tasks/build/mergeConfig.jsindex 4e7d26815..ebb0a789c 100644--- a/tasks/build/mergeConfig.js+++ b/tasks/build/mergeConfig.js@@ -32,26 +32,21 @@ const conf = {}let fileCount = 0async function main () {- console.warn(inputDir)- fs.readdirSync(inputDir).forEach(file => {+ const files = fs.readdirSync(inputDir)+ for (const file of files) {try {if (!file.endsWith('.json')) returnfileCount += 1const data = JSON.parse(fs.readFileSync(path.join(inputDir, file), 'utf-8'))- dictMerge(conf, data)+ await dictMerge(conf, data)} catch (error) {throw new Error(`ERROR: ${path.join(inputDir, file)}: ${error.message}`)}- })-- const jsonOptions = {- indent: 2,- separators: [',', ': ']}- fs.writeFileSync(outputFile, JSON.stringify(conf, null, jsonOptions.indent), 'utf-8')+ fs.writeFileSync(outputFile, JSON.stringify(conf, null, 2), 'utf-8')- console.log(`${prog}: ${fileCount} file(s) merged into ${path.basename(outputFile)}`)+ console.warn(`${prog}: ${fileCount} file(s) merged into ${path.basename(outputFile)}`)}main().catch((err) => {diff --git a/tasks/build/util.js b/tasks/build/util.jsindex f5d4b1b2c..b505a9ef3 100644--- a/tasks/build/util.js+++ b/tasks/build/util.js@@ -1,18 +1,29 @@-function dictMerge (target, ...objs) {- objs.forEach(obj => {- if (!_.isPlainObject(obj)) return obj+async function dictMerge (target, ...args) {+ // Merge multiple objects+ if (args.length > 1) {+ for (const obj of args) {+ await dictMerge(target, obj)+ }+ return target+ }- _.forOwn(obj, (v, k) => {- if (_.has(target, k) && _.isPlainObject(target[k])) {- if (_.has(v, 'type') && _.has(target[k], 'type')) {- if (v.type !== target[k].type) return target+ // Recursively merge objects and set non-object values+ const obj = args[0]+ if (typeof obj !== 'object' || obj === null) {+ return obj+ }+ for (const [k, v] of Object.entries(obj)) {+ if (k in target && typeof target[k] === 'object' && target[k] !== null) {+ if ('type' in v && 'type' in target[k]) {+ if (v.type !== target[k].type) {+ return target}- Object.assign(target[k], v)- } else {- target[k] = _.cloneDeep(v)}- })- })+ await dictMerge(target[k], v)+ } else {+ target[k] = Object.assign({}, v)+ }+ }return target}diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.shindex 7b831429f..c6dc01047 100755--- a/tasks/buildOptions.sh+++ b/tasks/buildOptions.sh@@ -47,7 +47,7 @@ fimkdir -p "$DEST_DIR/config"mkdir -p "$BUILD_DIR/colormaps"-# If $FETCH_GC is set, make various API requests+# # If $FETCH_GC is set, make various API requests# if [ "$FETCH_GC" ] ; then# # TODO: Fix axios fetch timeouts# # Fetch GC files and create colormaps, vectordata and vectorstyle files@@ -68,21 +68,24 @@ mkdir -p "$BUILD_DIR/colormaps"# fi# Validate layers in wv.json with a JSON schema-# `node $SCRIPTS_DIR/validateConfigs.js \-# --inputDirectory "$SRC_DIR/common/config/wv.json/layers" \-# --schemaFile "$BASE/schemas/layer-config.json"`+`node $SCRIPTS_DIR/validateConfigs.js \+ --inputDirectory "$SRC_DIR/common/config/wv.json/layers" \+ --schemaFile "$BASE/schemas/layer-config.json"`-# if [ -e "$BUILD_DIR/features.json" ] ; then-# cp "$BUILD_DIR/features.json" "$BUILD_DIR/config/wv.json/_features.json"-# fi+if [ -e "$BUILD_DIR/features.json" ] ; then+ cp "$BUILD_DIR/features.json" "$BUILD_DIR/config/wv.json/_features.json"+fi-# # # Run extractConfigFromWMTS.js script with config.json-# if [ -e "$BUILD_DIR/config.json" ] ; then-# `node $SCRIPTS_DIR/extractConfigFromWMTS.js \-# --config "$BUILD_DIR/config.json" \-# --inputDir "$BUILD_DIR/gc" \-# --outputDir "$BUILD_DIR/_wmts"`-# fi+# TODO: Fix sometimes the following error is thrown:+# TypeError: Converting circular structure to JSON+# extractConfigFromWMTS.js:85:11+# Run extractConfigFromWMTS.js script with config.json+if [ -e "$BUILD_DIR/config.json" ] ; then+ `node $SCRIPTS_DIR/extractConfigFromWMTS.js \+ --config "$BUILD_DIR/config.json" \+ --inputDir "$BUILD_DIR/gc" \+ --outputDir "$BUILD_DIR/_wmts"`+fi# Run processVectorStyles.js and move vectorstyles where we want themif [ -e "$BUILD_DIR/gc/vectorstyles" ] ; then@@ -100,8 +103,7 @@ if [ -e "$BUILD_DIR/gc/vectordata" ] ; then--outputDir "$BUILD_DIR/config/wv.json/vectordata"`fi-# TODO: Await for entries.colors, entries.refs, entries.values,-# legend.colors, legend.tooltips, legend.ticks, legend.refs,+# TODO: fix erroneous data in files# Run processColormap.js and move colormaps where we want themif [ -e "$BUILD_DIR/colormaps" ] ; thenmkdir -p "$BUILD_DIR"/config/palettes