blob: 2a55628934063cead70e13f8514a6ad223818013 [file] [log] [blame]
#!/bin/bash
# Copyright (c) 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Generates JSON data given the set of features written in the output directory.
# Call as ./data-generator.sh /path/to/input [/path/to/output]
INPUT_LOCATION=$1
DATA_FILE=${2:-"$(dirname $0)/workspaces/data.js"}
# Print the feature name to stdout as json key.
function print-feature-name {
featurename=$(basename $1 | sed 's/.feature//')
printf " '%s': " $featurename
}
# Prints the given feature to stdout as a json encoded list.
function print-feature {
cat $1 | (
# Read each line, and turn it into a comma seperated value for the list.
while read -r line; do
printf '%s,' "$line"
done
) | sed -e 's/,$/],\n/' -e 's/^/[/'
}
export -f print-feature
(
cat <<EOF
GLOBAL_JSON_DATA = JSON.stringify({
'labels': $(print-feature $INPUT_LOCATION/config.feature)
'features': {
$(
for feature in $INPUT_LOCATION/*.feature; do
print-feature-name $feature
print-feature $feature
done
)
}
});
EOF
)> $DATA_FILE