ui: prevent same string docHelp override (#5014)

Prevent same string docHelp suffix override.
List all existing docHelp suffixes in the config file during the build process.
Updated apache/cloudstack-documentation#199

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2021-05-12 16:20:17 +05:30 committed by GitHub
parent 493d6a08d2
commit 4ecef4bfb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 4 deletions

View File

@ -24,9 +24,11 @@
"url": "https://github.com/apache/cloudstack/issues" "url": "https://github.com/apache/cloudstack/issues"
}, },
"scripts": { "scripts": {
"prebuild": "./prebuild.sh",
"start": "vue-cli-service lint --no-fix && vue-cli-service serve", "start": "vue-cli-service lint --no-fix && vue-cli-service serve",
"serve": "vue-cli-service lint --no-fix && vue-cli-service serve", "serve": "vue-cli-service lint --no-fix && vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"postbuild": "./postbuild.sh",
"lint": "vue-cli-service lint", "lint": "vue-cli-service lint",
"i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'", "i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'",
"test:unit": "vue-cli-service test:unit" "test:unit": "vue-cli-service test:unit"

36
ui/postbuild.sh Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
DIR=$(dirname $0)
configFile="$DIR/public/config.json"
tmpFile="$DIR/public/config.json.tmp"
echo "Post-build: removing all docHelp suffixes in ${configFile}"
node > ${tmpFile} <<EOF
// Read config
var data = require('${configFile}');
// Clear docHelpMappings
data.docHelpMappings = {};
// Output config
console.log(JSON.stringify(data, null, 2));
EOF
mv ${tmpFile} ${configFile}

47
ui/prebuild.sh Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
DIR=$(dirname $0)
configFile="$DIR/public/config.json"
tmpFile="$DIR/public/config.json.tmp"
echo "Pre-build: list all docHelp suffixes in ${configFile}"
for m in $(grep "docHelp: '" -R ./src | sed "s/^.*: '//g" | sed "s/',//g" | sort | uniq); do
docHelpMappings+="${m},"
done;
node > ${tmpFile} <<EOF
// Read config
var data = require('${configFile}');
// Add docHelpMappings
var suffixes = '${docHelpMappings}';
suffixes = suffixes.split(',');
var mappings = {}
for (const suffix of suffixes) {
if (suffix) {
mappings[suffix] = suffix;
}
}
data.docHelpMappings = mappings;
// Output config
console.log(JSON.stringify(data, null, 2));
EOF
mv ${tmpFile} ${configFile}

View File

@ -6,8 +6,8 @@
"logo": "assets/logo.svg", "logo": "assets/logo.svg",
"banner": "assets/banner.svg", "banner": "assets/banner.svg",
"error": { "error": {
"404": "assets/404.png",
"403": "assets/403.png", "403": "assets/403.png",
"404": "assets/404.png",
"500": "assets/500.png" "500": "assets/500.png"
}, },
"theme": { "theme": {
@ -46,7 +46,7 @@
"jp": "label.japanese.keyboard", "jp": "label.japanese.keyboard",
"sc": "label.simplified.chinese.keyboard" "sc": "label.simplified.chinese.keyboard"
}, },
"docHelpMappings": {},
"plugins": [], "plugins": [],
"basicZoneEnabled": true "basicZoneEnabled": true,
"docHelpMappings": {}
} }

View File

@ -175,7 +175,7 @@ export const configUtilPlugin = {
if (docHelp && docHelpMappings && if (docHelp && docHelpMappings &&
docHelpMappings.constructor === Object && Object.keys(docHelpMappings).length > 0) { docHelpMappings.constructor === Object && Object.keys(docHelpMappings).length > 0) {
for (var key in docHelpMappings) { for (var key in docHelpMappings) {
if (docHelp.includes(key)) { if (docHelp.includes(key) && docHelp !== docHelpMappings[key]) {
docHelp = docHelp.replace(key, docHelpMappings[key]) docHelp = docHelp.replace(key, docHelpMappings[key])
break break
} }