You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/02/20 06:25:27 UTC
[incubator-openwhisk] branch master updated: Script to extract view
functions as js files (#3293)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 50e5e6c Script to extract view functions as js files (#3293)
50e5e6c is described below
commit 50e5e6c319a2848cfb65089b103bbf1b71193087
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue Feb 20 11:55:23 2018 +0530
Script to extract view functions as js files (#3293)
---
tools/build/scanCode.cfg | 1 +
tools/dev/README.md | 43 +++++++++++++++++++
tools/dev/build.gradle | 14 ++++++
tools/dev/src/main/groovy/couchdbViews.groovy | 61 +++++++++++++++++++++++++++
4 files changed, 119 insertions(+)
diff --git a/tools/build/scanCode.cfg b/tools/build/scanCode.cfg
index 685819a..b87c233 100644
--- a/tools/build/scanCode.cfg
+++ b/tools/build/scanCode.cfg
@@ -31,6 +31,7 @@ deploy.xml=no_tabs, no_trailing_spaces, eol_at_eof
bin
tests/build/reports
tests/dat
+tools/dev/build
# openwhisk-catalog exclusions (Python samples)
packages/samples/hello
# The following repos. have so far been identified as having scanning errors
diff --git a/tools/dev/README.md b/tools/dev/README.md
new file mode 100644
index 0000000..ca05172
--- /dev/null
+++ b/tools/dev/README.md
@@ -0,0 +1,43 @@
+# Utility Scripts
+
+This module is a collection of few utility scripts for OpenWhisk development. The scripts
+can be invoked as gradle tasks. Depending on your current directory the gradle command would
+change
+
+With current directory set to OpenWhisk home
+
+ ./gradlew -p tools/dev <taskName>
+
+With this module being base directory
+
+ ../../gradlew <taskName>
+
+## couchdbViews
+
+Extracts and dump the design docs js in readable format. It reads all the design docs from
+_<OPENWHISH_HOME>/ansibles/files_ and dumps them in _build/views_ directory
+
+Sample output
+
+ $./gradlew -p tools/dev couchdbViews
+ Processing whisks_design_document_for_entities_db_v2.1.0.json
+ - whisks.v2.1.0-rules.js
+ - whisks.v2.1.0-packages-public.js
+ - whisks.v2.1.0-packages.js
+ - whisks.v2.1.0-actions.js
+ - whisks.v2.1.0-triggers.js
+ Processing activations_design_document_for_activations_db.json
+ - activations-byDate.js
+ Processing auth_index.json
+ - subjects-identities.js
+ Processing filter_design_document.json
+ Processing whisks_design_document_for_activations_db_v2.1.0.json
+ - whisks.v2.1.0-activations.js
+ Skipping runtimes.json
+ Processing logCleanup_design_document_for_activations_db.json
+ - logCleanup-byDateWithLogs.js
+ Processing whisks_design_document_for_all_entities_db_v2.1.0.json
+ - all-whisks.v2.1.0-all.js
+ Processing whisks_design_document_for_activations_db_filters_v2.1.0.json
+ - whisks-filters.v2.1.0-activations.js
+ Generated view json files in /path/too/tools/build/views
diff --git a/tools/dev/build.gradle b/tools/dev/build.gradle
new file mode 100644
index 0000000..af112a8
--- /dev/null
+++ b/tools/dev/build.gradle
@@ -0,0 +1,14 @@
+apply plugin: 'groovy'
+
+def owHome = project.projectDir.parentFile.parentFile
+
+dependencies {
+ compile localGroovy()
+}
+
+task couchdbViews(type: JavaExec) {
+ description 'Dumps CouchDB views as js files'
+ main = 'couchdbViews'
+ args owHome.absolutePath
+ classpath = sourceSets.main.runtimeClasspath
+}
diff --git a/tools/dev/src/main/groovy/couchdbViews.groovy b/tools/dev/src/main/groovy/couchdbViews.groovy
new file mode 100644
index 0000000..2de008a
--- /dev/null
+++ b/tools/dev/src/main/groovy/couchdbViews.groovy
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+import groovy.json.JsonSlurper
+
+assert args : "Expecting the OpenWhisk home directory to passed"
+def owHomePath = args[0]
+
+File designDocDir = new File("$owHomePath/ansible/files")
+File buildDir = createFreshBuildDir()
+
+designDocDir.listFiles({it.name.endsWith(".json")} as FileFilter).each {File file ->
+ def json = new JsonSlurper().parse(file)
+
+ //Design docs json have first field as _id. So use that to determine if json
+ //is a design doc or not
+ String id = json._id
+ if (id && id.startsWith("_design/")){
+ println "Processing ${file.name}"
+ String baseName = id.substring("_design/".length())
+ json.views?.each{String viewName, def view ->
+ String viewJs = parseViewJs(view.map)
+ File viewFile = new File(buildDir, "$baseName-${viewName}.js")
+ viewFile.text = viewJs
+ println "\t- ${viewFile.name}"
+ }
+ } else {
+ println "Skipping ${file.name}"
+ }
+}
+println "Generated view json files in ${buildDir.absolutePath}"
+
+private static File createFreshBuildDir() {
+ File dir = new File("build/views")
+ if (dir.exists()) {
+ dir.deleteDir()
+ }
+ dir.mkdirs()
+ dir
+}
+
+private static String parseViewJs(String jsonText) {
+ jsonText.replace("\\n", "")
+ .replace('\"','"')
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
rabbah@apache.org.