You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by db...@apache.org on 2015/10/19 23:11:26 UTC

docs commit: Syncing with tools from master.

Repository: cordova-docs
Updated Branches:
  refs/heads/cordova-website 89943b179 -> 290d6b21b


Syncing with tools from master.


Project: http://git-wip-us.apache.org/repos/asf/cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-docs/commit/290d6b21
Tree: http://git-wip-us.apache.org/repos/asf/cordova-docs/tree/290d6b21
Diff: http://git-wip-us.apache.org/repos/asf/cordova-docs/diff/290d6b21

Branch: refs/heads/cordova-website
Commit: 290d6b21bc8cd5b6a7b031f7b046e2d70b77c3c6
Parents: 89943b1
Author: Dmitry Blotsky <dm...@gmail.com>
Authored: Mon Oct 19 14:11:19 2015 -0700
Committer: Dmitry Blotsky <dm...@gmail.com>
Committed: Mon Oct 19 14:11:19 2015 -0700

----------------------------------------------------------------------
 tools/bin/incrementversion            | 110 +++++++++++++++++++++++++++++
 tools/lib/cordova/post/versionmenu.js |  45 ++++++++++--
 tools/lib/docs_generator.js           |  29 ++++++++
 tools/lib/docs_validator.js           |  46 +++++++++++-
 4 files changed, 225 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/290d6b21/tools/bin/incrementversion
----------------------------------------------------------------------
diff --git a/tools/bin/incrementversion b/tools/bin/incrementversion
new file mode 100755
index 0000000..e74852f
--- /dev/null
+++ b/tools/bin/incrementversion
@@ -0,0 +1,110 @@
+#!/usr/bin/env node
+/*
+       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.
+*/
+/*jslint node:true, nomen: true */
+
+var fs = require('fs-extra'),
+    path = require('path'),
+    yargs = require('yargs')
+    .describe('edge', 'Compare edge version of English docs with Ruby version')
+    .count("verbose")
+    .alias('v', 'verbose')
+    .describe('verbose', 'Increase verbosity level of produced output')
+    .demand(2)
+    .usage('Usage: $0 [lang] [version]\n' +
+        '    <lang>: Language for which update version number.\n' +
+        '    <version>: Next version.\n');
+var argv = yargs.argv;
+
+function processEachFile(source_path, callback) {
+    var directoryEntries = fs.readdirSync(source_path);
+    directoryEntries.forEach(function (dirEntry) {
+        var fullPath = path.join(source_path, dirEntry),
+            stat;
+        if (!fs.existsSync(fullPath)) {
+            return;
+        }
+
+        stat = fs.lstatSync(fullPath);
+        if (stat.isFile()) {
+            callback(fullPath);
+            return;
+        }
+
+        if (stat.isDirectory()) {
+            processEachFile(fullPath, callback);
+            return;
+        }
+    });
+}
+
+if (argv.help) {
+    yargs.showHelp();
+    process.exit(1);
+}
+
+var language = null,
+    version = null,
+    argumentsCount = argv._.length;
+if (argumentsCount === 2) {
+    language = argv._[0];
+    version = argv._[1];
+} else {
+    yargs.showHelp();
+    process.exit(1);
+}
+
+var prevVersion = fs.readFileSync('VERSION', { encoding: 'utf8' }),
+    edge_dir = path.join('docs', language, 'edge'),
+    release_dir = path.join('docs', language, version),
+    versionShort;
+
+prevVersion = prevVersion.replace(/rc\d+$/, '').trim();
+
+if (argv.verbose > 0) {
+    console.log("Copy edge docs to " + release_dir);
+}
+
+fs.mkdirSync(release_dir);
+fs.copySync(edge_dir, release_dir);
+
+versionShort = version.replace(/rc\d+$/, '').trim();
+if (prevVersion !== versionShort) {
+    // Replace x.x.x to new version in all files.
+    processEachFile(release_dir, function (filename) {
+        if (path.extname(filename) != ".md" && path.extname(filename) != ".html") {
+            return;
+        }
+        
+        var content = fs.readFileSync(filename, { encoding: 'utf8' });
+        content.replace('x.x.x', versionShort);
+        fs.writeFileSync(filename, content);
+    });
+}
+
+// Save version number to file.
+fs.writeFileSync('VERSION', version);
+
+console.log("Generated version " + version);
+console.log("");
+console.log("Next steps:");
+console.log("  1. Review the update using `git status`");
+console.log("  2. Commit the changes as 'Version " + version + "'");
+console.log("  3. Tag the commit as '" + version + "'");
+console.log("");
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/290d6b21/tools/lib/cordova/post/versionmenu.js
----------------------------------------------------------------------
diff --git a/tools/lib/cordova/post/versionmenu.js b/tools/lib/cordova/post/versionmenu.js
index 84bda9b..0adfef4 100644
--- a/tools/lib/cordova/post/versionmenu.js
+++ b/tools/lib/cordova/post/versionmenu.js
@@ -38,11 +38,12 @@ var VersionMenu = (function () {
         this.stage = "Populate version menu";
         if (languages === null) {
             languages = [];
-            versions = [];
+            versions = {};
             this.buildVersionsData();
         }
         
         this.generatedMenu = this.generateMenu();
+        this.generatedLanguageMenu = this.generateLanguageMenu();
     }
 
     VersionMenu.prototype.run = function (file, $) {
@@ -54,12 +55,22 @@ var VersionMenu = (function () {
             console.info("Building version menu for file " + file);
         }
 
-        var element;
+        var element,
+            scriptTag,
+            currentPageSettings;
 
-        element = $('#header small select').first();
-        this.generatedMenu.forEach(function (optionGroup) {
+        element = $('#header small select#language').first();
+        this.generatedLanguageMenu.forEach(function (optionGroup) {
             element.append(optionGroup).append("\n");
         });
+        element = $('head').first();
+        currentPageSettings = {
+            lang: this.options.lang,
+            version: this.options.version
+        };
+        scriptTag = cheerio("<script></script>")
+        scriptTag.text("var settings = " + JSON.stringify(currentPageSettings) + ";");
+        element.append(scriptTag);
     };
 
     VersionMenu.prototype.buildVersionsData = function () {
@@ -138,6 +149,32 @@ var VersionMenu = (function () {
         return result;
     };
 
+    VersionMenu.prototype.generateLanguageMenu = function () {
+        var result = [],
+            langGroup,
+            lang,
+            mapper,
+            key;
+
+        mapper = function (item) {
+            return item;
+        };
+
+        for (key in languages) {
+            if (languages.hasOwnProperty(key)) {
+                lang = languages[key].lang;
+                langGroup = cheerio("<option></option>");
+                langGroup.append("\n");
+                langGroup.attr('label', languages[key].label);
+                langGroup.attr('value', lang);
+
+                result.push(langGroup);
+            }
+        }
+
+        return result;
+    };
+
     return VersionMenu;
 }());
 module.exports = VersionMenu;

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/290d6b21/tools/lib/docs_generator.js
----------------------------------------------------------------------
diff --git a/tools/lib/docs_generator.js b/tools/lib/docs_generator.js
index 8ea7a20..cc5b2cf 100644
--- a/tools/lib/docs_generator.js
+++ b/tools/lib/docs_generator.js
@@ -132,10 +132,39 @@ var DocsGenerator = (function () {
                         timing: timing
                     };
                 });
+
+                var output_path = path.join(self.output_directory, language_dir),
+                    input_path = path.join(self.input_directory, language_dir),
+                    options = {
+                        lang: language_dir,
+                        verbose: verbose_mode,
+                        timing: timing
+                    };
+                self.options = options;
+            });
+            self.captureExecutionTime("Generate languages list", 0, function () {
+                try {
+                    self.buildLanguageList(self.input_directory, self.output_directory);
+                } catch (e) {
+                    console.warn("=================================================");
+                    console.warn("ERROR: Generating the Cordova Documentation Language List failed.");
+                    console.warn(e.stack || e.toString());
+                    console.warn("=================================================");
+                }
             });
         });
     };
 
+    DocsGenerator.prototype.buildLanguageList = function (input_path, output_path, options) {
+        var languages = fs.readdirSync(input_path);
+        var versions = {};
+        languages.forEach(function (language_dir) {
+            var langVersions = fs.readdirSync(path.join(input_path, language_dir));;
+            versions[language_dir] = langVersions;
+        });
+        fs.writeFileSync(path.join(output_path, "commondata.js"), "var languages = " + JSON.stringify(languages) + "; var versions = " + JSON.stringify(versions));
+    }
+
     DocsGenerator.prototype.process = function (input_path, output_path, options) {
         if (options.verbose > 0) {
             console.log("Clearing output directory for lang " + options.lang + " and version " + options.version);

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/290d6b21/tools/lib/docs_validator.js
----------------------------------------------------------------------
diff --git a/tools/lib/docs_validator.js b/tools/lib/docs_validator.js
index cb04b38..eaaac6d 100644
--- a/tools/lib/docs_validator.js
+++ b/tools/lib/docs_validator.js
@@ -287,6 +287,8 @@ var DocsValidator = (function () {
             targetDom = target("#content"),
             sourceDomList = "",
             targetDomList = "",
+            sourceDomHtmlList = [],
+            targetDomHtmlList = [],
             changes,
             changed = false;
         function convertSource(element, initial, offset) {
@@ -308,19 +310,61 @@ var DocsValidator = (function () {
 
             return initial;
         }
+        function convertSourceHtml(element, initial, offset) {
+            var i,
+                child;
+            if (element.children === undefined) {
+                console.log(element);
+            }
+
+            for (i = 0; i < element.children.length; i += 1) {
+                child = element.children[i];
+                if (child.type !== 'tag') {
+                    continue;
+                }
+
+                initial += offset + child.name + "(" + cheerio(child).html() + ")" + "\r\n";
+                //console.log(cheerio(child).html());
+                initial = convertSourceHtml(child, initial, ' ' + offset);
+            }
+
+            return initial;
+        }
         sourceDomList = convertSource(sourceDom[0], '', '');
         targetDomList = convertSource(targetDom[0], '', '');
+        sourceDomHtmlList = convertSourceHtml(sourceDom[0], '', '').split("\r\n") || [];
+        targetDomHtmlList = convertSourceHtml(targetDom[0], '', '').split("\r\n") || [];
         if (sourceDomList !== targetDomList) {
             console.error("Path " + relativePath + " has different dom structure.");
             if (options.verbose > 0) {
                 //console.log(jsdiff.createPatch(relativePath, sourceDomList, targetDomList, '', ''));
                 changes = jsdiff.diffLines(sourceDomList, targetDomList);
                 if (options.verbose > 0) {
+                    var sourceLinesCounter = 0;
+                    var targetLinesCounter = 0;
                     changes.forEach(function (part) {
                         // green for additions, red for deletions
                         // grey for common parts
                         var color = part.added ? 'green' : (part.removed ? 'red' : 'grey');
-                        process.stderr.write(part.value[color]);
+                        var value = part.value;
+                        //process.stderr.write(value[color]);
+                        if (part.added) {
+                            value = targetDomHtmlList.slice(targetLinesCounter, targetLinesCounter + part.count).join("\r\n") + "\r\n";
+                            targetLinesCounter += part.count;
+                        } else if (part.removed) {
+                            value = sourceDomHtmlList.slice(sourceLinesCounter, sourceLinesCounter + part.count).join("\r\n") + "\r\n";
+                            sourceLinesCounter += part.count;
+                        } else {
+                            sourceLinesCounter += part.count;
+                            targetLinesCounter += part.count;
+                            var contextLength = 3;
+                            if (part.count > contextLength * 2 + 1) {
+                                value = part.value.split("\r\n").slice(0, contextLength).concat(["...\r\n"], part.value.split("\r\n").slice(part.count - contextLength, part.count)).join("\r\n") + "\r\n";
+                            } else {
+                                value = part.value;
+                            }
+                        }
+                        process.stderr.write(value[color]);
                     });
 
                     console.log();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org