This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.15 by this push:
new 4ecef4b ui: prevent same string docHelp override (#5014)
4ecef4b is described below
commit 4ecef4bfb486dd78c8406b4f203c24cb7521117b
Author: Abhishek Kumar <[email protected]>
AuthorDate: Wed May 12 16:20:17 2021 +0530
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 <[email protected]>
---
ui/package.json | 2 ++
ui/postbuild.sh | 36 ++++++++++++++++++++++++++++++++++++
ui/prebuild.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++
ui/public/config.json | 6 +++---
ui/src/utils/plugins.js | 2 +-
5 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/ui/package.json b/ui/package.json
index fcc561f..3879ee9 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -24,9 +24,11 @@
"url": "https://github.com/apache/cloudstack/issues"
},
"scripts": {
+ "prebuild": "./prebuild.sh",
"start": "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",
+ "postbuild": "./postbuild.sh",
"lint": "vue-cli-service lint",
"i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)'
--locales './src/locales/**/*.json'",
"test:unit": "vue-cli-service test:unit"
diff --git a/ui/postbuild.sh b/ui/postbuild.sh
new file mode 100755
index 0000000..ab7734f
--- /dev/null
+++ b/ui/postbuild.sh
@@ -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}
diff --git a/ui/prebuild.sh b/ui/prebuild.sh
new file mode 100755
index 0000000..771daa8
--- /dev/null
+++ b/ui/prebuild.sh
@@ -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}
diff --git a/ui/public/config.json b/ui/public/config.json
index 9f3b723..4c9be76 100644
--- a/ui/public/config.json
+++ b/ui/public/config.json
@@ -6,8 +6,8 @@
"logo": "assets/logo.svg",
"banner": "assets/banner.svg",
"error": {
- "404": "assets/404.png",
"403": "assets/403.png",
+ "404": "assets/404.png",
"500": "assets/500.png"
},
"theme": {
@@ -46,7 +46,7 @@
"jp": "label.japanese.keyboard",
"sc": "label.simplified.chinese.keyboard"
},
- "docHelpMappings": {},
"plugins": [],
- "basicZoneEnabled": true
+ "basicZoneEnabled": true,
+ "docHelpMappings": {}
}
diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js
index 905f0b1..3276eea 100644
--- a/ui/src/utils/plugins.js
+++ b/ui/src/utils/plugins.js
@@ -175,7 +175,7 @@ export const configUtilPlugin = {
if (docHelp && docHelpMappings &&
docHelpMappings.constructor === Object &&
Object.keys(docHelpMappings).length > 0) {
for (var key in docHelpMappings) {
- if (docHelp.includes(key)) {
+ if (docHelp.includes(key) && docHelp !== docHelpMappings[key]) {
docHelp = docHelp.replace(key, docHelpMappings[key])
break
}