rabbah closed pull request #3293: Script to extract view functions as js files
URL: https://github.com/apache/incubator-openwhisk/pull/3293
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tools/build/scanCode.cfg b/tools/build/scanCode.cfg
index 685819a1dd..b87c2337c6 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 0000000000..ca05172a62
--- /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 0000000000..af112a86ef
--- /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 0000000000..2de008a06d
--- /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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to