Remove unused files from tools/
diff --git a/tools/bin/fixyaml b/tools/bin/fixyaml
deleted file mode 100644
index 6fcba9c..0000000
--- a/tools/bin/fixyaml
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/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 yargs = require('yargs')
- .count("verbose")
- .alias('v', 'verbose')
- .describe('verbose', 'Increase verbosity level of produced output')
- .describe('source', 'Path to the documentation sources. Default: public')
- .usage('Usage: $0 [-v] [lang] [version] [--dev]\n' + +
- 'Fix the output which is produced by CrowdIn for MD files\n' +
- '\n' +
- ' <lang>: Language for which fix YAML header. If not specified then fixed for all languages.\n' +
- ' <version>: Version for which fix YAML header. If not specified then fixed all versions.\n')
- .usage('Usage: $0\n' +
- 'Fix the output which is produced by CrowdIn for MD files');
-var argv = yargs.argv;
-
-if (argv.help) {
- yargs.showHelp();
- process.exit(1);
-}
-
-var language = null;
-var version = null;
-if (argv.dev) {
- language = null;
- version = "dev";
-} else {
- var argumentsCount = argv._.length;
- if (argumentsCount !== 0) {
- if (argumentsCount === 2) {
- language = argv._[0];
- version = argv._[1];
- } else {
- var data = argv._[0];
- if (data.length === 2) {
- language = data;
- } else {
- version = data;
- }
- }
- }
-}
-
-var validator = require('../lib/docs_validator');
-new validator().fixYamlHeader(argv.source, language, version, argv.verbose);
diff --git a/tools/bin/fixyaml.bat b/tools/bin/fixyaml.bat
deleted file mode 100644
index 2c68254..0000000
--- a/tools/bin/fixyaml.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: 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.
-
-@ECHO OFF
-SET script_path="%~dp0fixyaml"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'fixyaml' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
\ No newline at end of file
diff --git a/tools/bin/genjs b/tools/bin/genjs
deleted file mode 100755
index 6985a33..0000000
--- a/tools/bin/genjs
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/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 generator = require('../lib/docs_generator');
-var yargs = require('yargs')
- .describe('dev', 'Generate dev version of English docs')
- .count("verbose")
- .alias('v', 'verbose')
- .describe('timing', 'Species level of timing measurements. If level not provided level 0 is used.')
- .describe('verbose', 'Increase verbosity level of produced output')
- .describe('source', 'Path to the documentation sources. Default: docs')
- .describe('out', 'Path where documentation would be generated. Default: public')
- .example('./bin/genjs --out public/test en', 'Generates English docs in the directory public/test')
- .example('./bin/genjs --timing', 'Basic timing measurements')
- .example('./bin/genjs --timing 1', 'Detailed timing measurements')
- .usage('Usage: $0 [-v] [...options] [--dev] [lang] [version]\n' +
- ' <lang>: Language for which generate docs. If not specified then generate for all languages.\n' +
- ' <version>: Version for which generate docs. If not specified then generate all versions.');
-var argv = yargs.argv;
-
-if (argv.help) {
- yargs.showHelp();
- process.exit(1);
-}
-
-var language = null;
-var version = null;
-if (argv.dev) {
- language = "en";
- version = "dev";
-} else {
- var argumentsCount = argv._.length;
- if (argumentsCount !== 0) {
- if (argumentsCount === 2) {
- language = argv._[0];
- version = argv._[1];
- } else {
- var data = argv._[0];
- if (data.length === 2) {
- language = data;
- } else {
- version = data;
- }
- }
- }
-}
-
-new generator(argv.source, argv.out).run(language, version, argv.verbose, argv.timing);
diff --git a/tools/bin/genjs.bat b/tools/bin/genjs.bat
deleted file mode 100644
index 70c9b92..0000000
--- a/tools/bin/genjs.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: 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.
-
-@ECHO OFF
-SET script_path="%~dp0genjs"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'genjs' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
\ No newline at end of file
diff --git a/tools/bin/incrementversion b/tools/bin/incrementversion
deleted file mode 100755
index 71be7e5..0000000
--- a/tools/bin/incrementversion
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/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('dev', 'Compare dev 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' }),
- dev_dir = path.join('docs', language, 'dev'),
- release_dir = path.join('docs', language, version),
- versionShort;
-
-prevVersion = prevVersion.replace(/rc\d+$/, '').trim();
-
-if (argv.verbose > 0) {
- console.log("Copy dev docs to " + release_dir);
-}
-
-fs.mkdirSync(release_dir);
-fs.copySync(dev_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("");
diff --git a/tools/bin/incrementversion.bat b/tools/bin/incrementversion.bat
deleted file mode 100644
index 36464e2..0000000
--- a/tools/bin/incrementversion.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: 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.
-
-@ECHO OFF
-SET script_path="%~dp0incrementversion"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'incrementversion' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
\ No newline at end of file
diff --git a/tools/bin/translationreport b/tools/bin/translationreport
deleted file mode 100755
index 5f716d6..0000000
--- a/tools/bin/translationreport
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/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 yargs = require('yargs')
- .describe('dev', 'Compare version of English docs with translated version')
- .count("verbose")
- .alias('v', 'verbose')
- .describe('verbose', 'Increase verbosity level of produced output')
- .describe('source', 'Path to the documentation sources. Default: public')
- .usage('Usage: $0 [-v] [lang] [version] [--dev]\n' +
- ' <lang>: Language for which generate docs. If not specified then generate for all languages.\n' +
- ' <version>: Version for which generate docs. If not specified then generate all versions.\n');
-var argv = yargs.argv;
-
-if (argv.help) {
- yargs.showHelp();
- process.exit(1);
-}
-
-var language = null;
-var version = null;
-if (argv.dev) {
- language = null;
- version = "dev";
-} else {
- var argumentsCount = argv._.length;
- if (argumentsCount !== 0) {
- if (argumentsCount === 2) {
- language = argv._[0];
- version = argv._[1];
- } else {
- var data = argv._[0];
- if (data.length === 2) {
- language = data;
- } else {
- version = data;
- }
- }
- }
-}
-
-var validator = require('../lib/docs_validator');
-new validator().validateTranslation(argv.source, language, version, argv.verbose);
diff --git a/tools/bin/translationreport.bat b/tools/bin/translationreport.bat
deleted file mode 100644
index 564f4e1..0000000
--- a/tools/bin/translationreport.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: 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.
-
-@ECHO OFF
-SET script_path="%~dp0translationreport"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'translationreport' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
\ No newline at end of file
diff --git a/tools/bin/validatejsdoc b/tools/bin/validatejsdoc
deleted file mode 100755
index 7823d11..0000000
--- a/tools/bin/validatejsdoc
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/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 yargs = require('yargs')
- .describe('dev', 'Compare dev version of English docs with Ruby version')
- .count("verbose")
- .alias('v', 'verbose')
- .describe('verbose', 'Increase verbosity level of produced output')
- .usage('Usage: $0 [-v] [lang] [version] [--dev]\n' +
- ' <lang>: Language for which generate docs. If not specified then generate for all languages.\n' +
- ' <version>: Version for which generate docs. If not specified then generate all versions.\n');
-var argv = yargs.argv;
-
-if (argv.help) {
- yargs.showHelp();
- process.exit(1);
-}
-
-var language = null;
-var version = null;
-if (argv.dev) {
- language = "en";
- version = "dev";
-} else {
- var argumentsCount = argv._.length;
- if (argumentsCount !== 0) {
- if (argumentsCount === 2) {
- language = argv._[0];
- version = argv._[1];
- } else {
- var data = argv._[0];
- if (data.length === 2) {
- language = data;
- } else {
- version = data;
- }
- }
- }
-}
-
-if (argv.compare) {
- var comparer = require('../lib/docs_comparer');
- new comparer().compare(language, version, argv.verbose);
-} else {
- var validator = require('../lib/docs_validator');
- new validator().validate(language, version, argv.verbose);
-}
diff --git a/tools/bin/validatejsdoc.bat b/tools/bin/validatejsdoc.bat
deleted file mode 100644
index fe36d1c..0000000
--- a/tools/bin/validatejsdoc.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: 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.
-
-@ECHO OFF
-SET script_path="%~dp0validatejsdoc"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'validatejsdoc' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
\ No newline at end of file
diff --git a/tools/lib/docs_comparer.js b/tools/lib/docs_comparer.js
deleted file mode 100644
index 60e3f7f..0000000
--- a/tools/lib/docs_comparer.js
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- 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 */
-var fs = require('fs-extra');
-var path = require('path');
-var FileHelpers = require('./file_helpers');
-var cheerio = require('cheerio');
-var jsdiff = require('diff');
-require('colors');
-
-var DocsComparer = (function () {
- 'use strict';
-
- function processEachFile (source_path, fileCallback, directoryCallback) {
- var directoryEntries = fs.readdirSync(source_path);
- directoryEntries.forEach(function (dirEntry) {
- var fullPath = path.join(source_path, dirEntry);
- var stat;
- if (!fs.existsSync(fullPath)) {
- return;
- }
-
- stat = fs.lstatSync(fullPath);
- if (stat.isFile()) {
- fileCallback(fullPath);
- return;
- }
-
- if (stat.isDirectory()) {
- if (directoryCallback(fullPath)) {
- processEachFile(fullPath, fileCallback, directoryCallback);
- }
-
- }
- });
- }
-
- /**
- * Creates a new instance of DocsComparer
- * @param inputDirectory Directory which contains files which has to be processed.
- * @param outputDirectory Directory to which store generated files.
- */
- function DocsComparer (originalDirectory, outputDirectory) {
- this.original_directory = originalDirectory || path.join(FileHelpers.getRootDirectory(), 'public');
- this.output_directory = outputDirectory || path.join(FileHelpers.getRootDirectory(), 'public/test');
- }
-
- /**
- * Compares two sets of documentation
- * @param language Language which has to be compared.
- * @param version Version which files has to be compared.
- * @param verbose_mode Verbosity level.
- */
- DocsComparer.prototype.compare = function (language, version, verbose_mode) {
- var self = this;
- var ignore_list = ['.', '..', '.DS_Store', 'test'];
-
- verbose_mode = verbose_mode || 0;
- if (verbose_mode > 0) {
- console.log('Comparing docs for lang ' + language + ' and version ' + version);
- console.log('Clearing output directory');
- }
-
- fs.readdirSync(this.original_directory).forEach(function (language_dir) {
- if (ignore_list.indexOf(language_dir) !== -1) {
- return;
- }
-
- if (language && language_dir !== language) {
- return;
- }
-
- var language_path = path.join(self.original_directory, language_dir);
-
- fs.readdirSync(language_path).forEach(function (version_dir) {
- if (ignore_list.indexOf(version_dir) !== -1) {
- return;
- }
-
- if (version && version_dir !== version) {
- return;
- }
-
- var output_path = path.join(self.output_directory, language_dir, version_dir);
- var input_path = path.join(self.original_directory, language_dir, version_dir);
- var options = {
- lang: language_dir,
- version: version_dir,
- verbose: verbose_mode
- };
-
- console.log(' => Comparing the Cordova Documentation for ' + version_dir + '-' + language_dir + '...');
- self.process(input_path, output_path, options);
- });
- });
- };
- DocsComparer.prototype.process = function (original_directory, output_path, options) {
- var self = this;
- var compareFiles;
- console.log('Processing ' + original_directory + ' and ' + output_path);
- compareFiles = function (fileName) {
- var relativePath = path.relative(original_directory, fileName);
- var targetFile;
- var originalFileStat;
- var targetFileStat;
- var originalFileSize; // eslint-disable-line no-unused-vars
- var targetFileSize; // eslint-disable-line no-unused-vars
- targetFile = path.join(output_path, relativePath);
- if (!fs.existsSync(targetFile)) {
- console.error('Path ' + relativePath + ' is missing in the new docs');
- return;
- }
-
- if (/\.html$/.test(relativePath)) {
- // Compare HTML content.
- self.compareHtml(fileName, targetFile, relativePath, options);
- } else {
- originalFileStat = fs.statSync(fileName);
- targetFileStat = fs.statSync(targetFile);
- originalFileSize = originalFileStat.size;
- targetFileSize = targetFileStat.size;
- self.compareFileSize(fileName, targetFile, relativePath, options);
- }
- };
- processEachFile(original_directory, compareFiles, function (directoryName) {
- var relativePath = path.relative(original_directory, directoryName);
- var targetFile;
- targetFile = path.join(output_path, relativePath);
- if (!fs.existsSync(targetFile)) {
- console.error('Dir ' + relativePath + '/ is missing in the new docs');
- return;
- }
-
- // console.log(relativePath + "\\");
- return true;
- });
- };
-
- DocsComparer.prototype.compareHtml = function (sourceFile, targetFile, relativePath, options) {
- if (options.verbose > 0) {
- console.log('Compare ' + relativePath);
- }
-
- if (relativePath === '_index.html') {
- if (options.lang === 'zh' || options.lang === 'ja' || options.lang === 'ko' || options.lang === 'ru') {
- console.log('File ' + relativePath + ' is skipped for the Asian languages and Russian, since this is results in out of memory exception');
- return;
- }
- }
-
- var cheerioOptions = {
- normalizeWhitespace: true,
- xmlMode: true
- };
- var sourceDom = cheerio.load(fs.readFileSync(sourceFile), cheerioOptions);
- var targetDom = cheerio.load(fs.readFileSync(targetFile), cheerioOptions);
-
- // This is identical subsets
- this.compareDomSubset(sourceDom, targetDom, 'head', relativePath, options);
- this.compareDomSubset(sourceDom, targetDom, '#sidebar', relativePath, options);
- this.compareDomSubset(sourceDom, targetDom, '#header', relativePath, options);
- this.compareDomSubset(sourceDom, targetDom, '#content', relativePath, options);
-
- // Almost identical subsets
- this.compareDomSubset(sourceDom, targetDom, '#subheader', relativePath, options);
- };
-
- DocsComparer.prototype.compareDomSubset = function (sourceDom, targetDom, subset, relativePath, options) {
- var sourceHtml = sourceDom(subset).html();
- var targetHtml = targetDom(subset).html();
- var diff;
- var changed = false;
-
- diff = jsdiff.diffChars(sourceHtml, targetHtml);
- diff.forEach(function (part) {
- changed = part.added || part.removed;
- });
- if (changed) {
- console.error("Subset of DOM '" + subset + "' for path " + relativePath + ' is different.');
- if (options.verbose > 0) {
- diff.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]);
- });
-
- console.log();
- }
- }
- };
-
- DocsComparer.prototype.compareDom = function (sourceDom, targetDom, relativePath, options) {
- var sourceHtml = sourceDom.html();
- var targetHtml = targetDom.html();
- var diff;
- var changed = false;
-
- diff = jsdiff.diffChars(sourceHtml, targetHtml);
- diff.forEach(function (part) {
- changed = part.added || part.removed;
- });
- if (changed) {
- console.error('DOM for path ' + relativePath + ' is different.');
- if (options.verbose > 0) {
- diff.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]);
- });
-
- console.log();
- }
- }
- };
-
- DocsComparer.prototype.compareFileSize = function (sourceFile, targetFile, relativePath) {
- var originalFileStat = fs.statSync(sourceFile);
- var targetFileStat = fs.statSync(targetFile);
- var originalFileSize = originalFileStat.size;
- var targetFileSize = targetFileStat.size;
-
- if (originalFileSize !== targetFileSize) {
- console.error('Path ' + relativePath + ' is different. Old size: ' + originalFileSize + '. New size: ' + targetFileSize);
- }
-
- return originalFileSize !== targetFileSize;
- };
-
- return DocsComparer;
-}());
-module.exports = DocsComparer;
diff --git a/tools/lib/docs_generator.js b/tools/lib/docs_generator.js
deleted file mode 100644
index fad5a30..0000000
--- a/tools/lib/docs_generator.js
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- 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 */
-var fs = require('fs-extra');
-var path = require('path');
-var JoDoc = require('./cordova/jodoc');
-var FileHelpers = require('./file_helpers');
-
-var DocsGenerator = (function () {
- 'use strict';
-
- function processEachFile (source_path, callback) {
- var directoryEntries = fs.readdirSync(source_path);
- directoryEntries.forEach(function (dirEntry) {
- var fullPath = path.join(source_path, dirEntry);
- var stat;
- if (!fs.existsSync(fullPath)) {
- return;
- }
-
- stat = fs.lstatSync(fullPath);
- if (stat.isFile()) {
- callback(fullPath);
- return;
- }
-
- if (stat.isDirectory()) {
- processEachFile(fullPath, callback);
-
- }
- });
- }
-
- /**
- * Creates a new instance of DocsGenerator
- * @param inputDirectory Directory which contains files which has to be processed.
- * @param outputDirectory Directory to which store generated files.
- */
- function DocsGenerator (inputDirectory, outputDirectory) {
- this.input_directory = path.resolve(inputDirectory || FileHelpers.getDefaultInputDirectory());
- this.output_directory = path.resolve(outputDirectory || FileHelpers.getDefaultOutputDirectory());
- this.working_directory = path.join(FileHelpers.getTmpDirectory(), 'docs');
- }
-
- /* Cordova Build-Time Steps
- * - For each version of the documentation
- * - Create a work space for the docs processing
- * - Pre-file processing
- * - Run joDoc
- * - Pre-file processing
- * - Release and cleanup
- */
- DocsGenerator.prototype.run = function (language, version, verbose_mode, timing) {
- var self = this;
- var ignore_list = ['.', '..', '.DS_Store'];
-
- verbose_mode = verbose_mode || 0;
- if (verbose_mode > 0) {
- console.log('Generating docs for lang ' + language + ' and version ' + version);
- // console.log("Clearing output directory");
- if (verbose_mode > 1) {
- console.log('Sources directory: ' + this.input_directory);
- console.log('Output directory: ' + this.output_directory);
- }
- }
-
- // fs.removeSync(this.output_directory);
-
- self.options = {
- verbose: verbose_mode,
- timing: timing
- };
- self.captureExecutionTime('Generate all docs', 0, function () {
- fs.readdirSync(this.input_directory).forEach(function (language_dir) {
- if (ignore_list.indexOf(language_dir) !== -1) {
- return;
- }
-
- if (language && language_dir !== language) {
- return;
- }
-
- var language_path = path.join(self.input_directory, language_dir);
-
- fs.readdirSync(language_path).forEach(function (version_dir) {
- if (ignore_list.indexOf(version_dir) !== -1) {
- return;
- }
-
- if (version && version_dir !== version) {
- return;
- }
-
- var output_path = path.join(self.output_directory, language_dir, version_dir);
- var input_path = path.join(self.input_directory, language_dir, version_dir);
- var options = {
- lang: language_dir,
- version: version_dir,
- verbose: verbose_mode,
- timing: timing
- };
- self.options = options;
- console.log(' => Generating the Cordova Documentation for ' + version_dir + '-' + language_dir + '...');
- self.captureExecutionTime('Generate docs for ' + version_dir + '-' + language_dir, 0, function () {
- try {
- self.process(input_path, output_path, options);
- } catch (e) {
- console.warn('=================================================');
- console.warn('ERROR: Generating the Cordova Documentation for ' + version_dir + '-' + language_dir + ' failed.');
- console.warn(e.stack || e.toString());
- console.warn('=================================================');
- }
- });
- self.options = {
- verbose: verbose_mode,
- timing: timing
- };
- });
-
- var output_path = path.join(self.output_directory, language_dir); // eslint-disable-line no-unused-vars
- var input_path = path.join(self.input_directory, language_dir); // eslint-disable-line no-unused-vars
- var 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);
- if (options.verbose > 1) {
- console.log('Output directory: ' + output_path);
- }
- }
-
- this.captureExecutionTime('Removing lang output directory', 1, function () {
- fs.removeSync(output_path);
- });
- this.captureExecutionTime('Copy source files to temp', 1, function () {
- fs.copySync(input_path, this.working_directory);
- });
-
- var preprocessPath,
- processPath,
- generated_path;
- this.captureExecutionTime('Pre processing docs', 1, function () {
- preprocessPath = this.before_jodoc(this.working_directory, options);
- });
- this.captureExecutionTime('joDoc-ify', 1, function () {
- processPath = this.jodocify(preprocessPath, options);
- });
- this.captureExecutionTime('Post processing docs', 1, function () {
- generated_path = this.after_jodoc(processPath, options);
- });
-
- this.captureExecutionTime('Moving to results folder', 1, function () {
- fs.ensureDirSync(path.dirname(output_path));
- fs.renameSync(generated_path, output_path);
- fs.removeSync(FileHelpers.getTmpDirectory());
- });
- };
-
- DocsGenerator.prototype.run_process_sequence = function (sequence_name, source_path, options) {
- var self = this;
- var currentModuleDir = path.dirname(module.filename);
- var directoryEntries; // eslint-disable-line no-unused-vars
- var sequenceProcessors;
- var processors;
- directoryEntries = fs.readdirSync(path.join(currentModuleDir, 'cordova', sequence_name));
- sequenceProcessors = require('./cordova/' + sequence_name + '/index');
- processors = sequenceProcessors.map(function (ProcessorConstructor) {
- return new ProcessorConstructor(options);
- });
- processors.forEach(function (process_module) {
- self.captureExecutionTime('Processor: ' + process_module.stage, 1, function () {
- if (options.verbose > 0) {
- console.log('Stage: ' + process_module.stage);
- }
-
- processEachFile(source_path, function (filename) {
- self.captureExecutionTime('File: ' + filename, 2, function () {
- process_module.run(filename);
- });
- });
- });
- });
-
- return source_path;
- };
-
- DocsGenerator.prototype.before_jodoc = function (source_path, options) {
- this.run_process_sequence('pre', source_path, options);
-
- return source_path;
- };
-
- DocsGenerator.prototype.jodocify = function (source_path, options) {
- var output_directory = path.join(FileHelpers.getTmpDirectory(), 'jodoc');
-
- new JoDoc(source_path, output_directory, options).run();
- fs.ensureDirSync(output_directory);
-
- return output_directory;
- };
-
- DocsGenerator.prototype.after_jodoc = function (source_path, options) {
- this.run_process_sequence('post', source_path, options);
- return source_path;
- };
-
- DocsGenerator.prototype.captureExecutionTime = function (step_name, level, callback) {
- var startDate;
- var finishDate;
- var timingLevel = -1;
- var secondsPassed;
- if (this.options.timing) {
- if (this.options.timing === true) {
- timingLevel = 0;
- } else {
- timingLevel = this.options.timing;
- }
- }
-
- if (timingLevel >= level) {
- startDate = new Date();
- if (this.options.verbose > 0) {
- console.log(startDate, 'Start ' + step_name);
- }
- }
-
- callback.apply(this);
- if (timingLevel >= level) {
- finishDate = new Date();
- if (this.options.verbose > 0) {
- console.log(finishDate, 'Finish ' + step_name);
- }
-
- secondsPassed = (finishDate.valueOf() - startDate.valueOf()) / 1000;
- console.log(step_name + '. Total time: ', secondsPassed);
- }
- };
-
- return DocsGenerator;
-}());
-module.exports = DocsGenerator;
diff --git a/tools/lib/docs_validator.js b/tools/lib/docs_validator.js
deleted file mode 100644
index 46f1cb9..0000000
--- a/tools/lib/docs_validator.js
+++ /dev/null
@@ -1,576 +0,0 @@
-/*
- 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, continue:true */
-/* global setImmediate */
-var fs = require('fs-extra');
-var path = require('path');
-var FileHelpers = require('./file_helpers');
-var cheerio = require('cheerio');
-var jsdiff = require('diff');
-var yaml = require('js-yaml'); // eslint-disable-line no-unused-vars
-var dir = require('node-dir');
-require('colors');
-
-var DocsValidator = (function () {
- 'use strict';
-
- function processEachFileSync (source_path, fileCallback, directoryCallback) { // eslint-disable-line no-unused-vars
- var directoryEntries = fs.readdirSync(source_path);
- directoryEntries.forEach(function (dirEntry) {
- var fullPath = path.join(source_path, dirEntry);
- var stat;
- if (!fs.existsSync(fullPath)) {
- return;
- }
-
- stat = fs.lstatSync(fullPath);
- if (stat.isFile()) {
- fileCallback(fullPath);
- return;
- }
-
- if (stat.isDirectory()) {
- if (directoryCallback(fullPath)) {
- processEachFileSync(fullPath, fileCallback, directoryCallback);
- }
-
- }
- });
- }
-
- function processEachFile (source_path, fileCallback, directoryCallback, errorCallback) { // eslint-disable-line no-unused-vars
- fs.readdirSync(source_path, function (err, directoryEntries) {
- if (err) {
- errorCallback(err);
- return;
- }
-
- directoryEntries.forEach(function (dirEntry) {
- var fullPath = path.join(source_path, dirEntry);
- fs.exists(fullPath, function (exists) {
- if (!exists) {
- return;
- }
-
- fs.lstat(fullPath, function (err, stat) {
- if (err) {
- errorCallback(err);
- return;
- }
-
- if (stat.isFile()) {
- fileCallback(fullPath);
- return;
- }
-
- if (stat.isDirectory()) {
- if (directoryCallback(fullPath)) {
- processEachFile(fullPath, fileCallback, directoryCallback, errorCallback);
- }
-
- }
- });
- });
- });
- });
- }
-
- /**
- * Creates a new instance of DocsValidator
- * @param inputDirectory Directory which contains files which has to be processed.
- */
- function DocsValidator (originalDirectory) {
- this.original_directory = originalDirectory || path.join(FileHelpers.getRootDirectory(), 'docs');
- }
-
- /**
- * Validates the specific version of documentation
- * @param language Language which has to be validated.
- * @param version Version which files has to be validated.
- * @param verbose_mode Verbosity level.
- */
- DocsValidator.prototype.validate = function (language, version, verbose_mode) {
- var self = this;
- var ignore_list = ['.', '..', '.DS_Store', 'test'];
-
- verbose_mode = verbose_mode || 0;
- if (verbose_mode > 0) {
- console.log('Comparing docs for lang ' + language + ' and version ' + version);
- console.log('Clearing output directory');
- }
-
- fs.readdirSync(this.original_directory).forEach(function (language_dir) {
- if (ignore_list.indexOf(language_dir) !== -1) {
- return;
- }
-
- if (language && language_dir !== language) {
- return;
- }
-
- var language_path = path.join(self.original_directory, language_dir);
-
- fs.readdirSync(language_path).forEach(function (version_dir) {
- if (ignore_list.indexOf(version_dir) !== -1) {
- return;
- }
-
- if (version && version_dir !== version) {
- return;
- }
-
- var input_path = path.join(self.original_directory, language_dir, version_dir);
- var options = {
- lang: language_dir,
- version: version_dir,
- verbose: verbose_mode
- };
-
- console.log(' => Validating the Cordova Documentation for ' + version_dir + '-' + language_dir + '...');
- self.process(input_path, options);
- });
- });
- };
-
- /**
- * Validates the specific version of documentation
- * @param outputDirectory Directory where documentation is stored.
- * @param language Language which has to be validated.
- * @param version Version which files has to be validated.
- * @param verbose_mode Verbosity level.
- */
- DocsValidator.prototype.validateTranslation = function (docsDirectory, language, version, verbose_mode) {
- var self = this;
- var outputDirectory = path.resolve(docsDirectory || FileHelpers.getDefaultOutputDirectory());
- var ignore_list = ['.', '..', '.DS_Store', 'test'];
-
- verbose_mode = verbose_mode || 0;
- if (verbose_mode > 0) {
- console.log('Comparing docs for lang ' + language + ' and version ' + version);
- console.log('Clearing output directory');
- }
-
- fs.readdirSync(outputDirectory).forEach(function (language_dir) {
- if (ignore_list.indexOf(language_dir) !== -1) {
- return;
- }
-
- if (language && language_dir !== language) {
- return;
- }
-
- var language_path = path.join(outputDirectory, language_dir);
-
- fs.readdirSync(language_path).forEach(function (version_dir) {
- if (ignore_list.indexOf(version_dir) !== -1) {
- return;
- }
-
- if (version && version_dir !== version) {
- return;
- }
-
- var input_path = path.join(outputDirectory, language_dir, version_dir);
- var source_path = path.join(outputDirectory, 'en', version_dir);
- var options = {
- lang: language_dir,
- version: version_dir,
- verbose: verbose_mode
- };
-
- console.log(' => Validating translation for version ' + version_dir + ' on language ' + language_dir + '...');
- self.doValidateTranslation(source_path, input_path, options);
- });
- });
- };
- DocsValidator.prototype.doValidateTranslation = function (original_directory, comparing_directory, options) {
- var self = this;
- var compareFiles; // eslint-disable-line no-unused-vars
- var completed;
- console.log('Comparing ' + original_directory);
- console.log('with ' + comparing_directory);
- completed = false;
- dir.readFiles(original_directory,
- { match: /\.html/ },
- function (err, content, filename, next) {
- if (err) {
- throw err;
- }
-
- var relativePath = path.relative(original_directory, filename);
- var alternativeFile = path.join(comparing_directory, relativePath);
- var $ = cheerio.load(alternativeFile); // eslint-disable-line no-unused-vars
- fs.readFile(alternativeFile, function (err, data) {
- if (err) {
- throw err;
- }
-
- var target = cheerio.load(data);
- var source = cheerio.load(content);
-
- self.validateLinksStructure(relativePath, source, target, options);
- self.validateDomStructure(relativePath, source, target, options);
- next();
- });
- },
- function (err, files) {
- if (err) {
- throw err;
- }
-
- completed = true;
- });
- function waitCompletition () {
- if (!completed) {
- setImmediate(waitCompletition);
- }
- }
-
- setImmediate(waitCompletition);
- };
- DocsValidator.prototype.process = function (original_directory, options) {
- var self = this;
- var compareFiles; // eslint-disable-line no-unused-vars
- var completed;
- console.log('Processing ' + original_directory);
- compareFiles = function (fileName) {
- self.validateYaml(fileName, options);
- };
- completed = false;
- dir.readFiles(original_directory,
- { match: /\.md$/ },
- function (err, content, filename, next) {
- if (err) {
- throw err;
- }
-
- self.validateYaml(filename, content, options);
- next();
- },
- function (err, files) {
- if (err) {
- throw err;
- }
-
- completed = true;
- });
- function waitCompletition () {
- if (!completed) {
- setImmediate(waitCompletition);
- }
- }
-
- setImmediate(waitCompletition);
- };
-
- DocsValidator.prototype.validateDomStructure = function (relativePath, source, target, options) {
- var sourceDom = source('#content');
- var targetDom = target('#content');
- var sourceDomList = '';
- var targetDomList = '';
- var sourceDomHtmlList = [];
- var targetDomHtmlList = [];
- var changes;
- var changed = false; // eslint-disable-line no-unused-vars
- function convertSource (element, initial, offset) {
- var i;
- var 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 + '\r\n';
- initial = convertSource(child, initial, ' ' + offset);
- }
-
- return initial;
- }
- function convertSourceHtml (element, initial, offset) {
- var i;
- var 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');
- 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();
- }
- }
- }
- };
-
- DocsValidator.prototype.validateLinksStructure = function (relativePath, source, target, options) {
- // Skip _index.html since it will have links in the different
- // order, not as in the original docs, since each word
- // will be translated to different languages.
- if (relativePath === '_index.html') {
- return;
- }
-
- var sourceLinks = source('#content a');
- var targetLinks = target('#content a');
- var sourceLinksList = '';
- var targetLinksList = '';
- var changes;
- var changed = false;
- sourceLinks.each(function (i, a) {
- var link = a.attribs.href || '';
- link = link.split('#')[0];
- if (link) {
- sourceLinksList += link + '\n';
- }
- });
- targetLinks.each(function (i, a) {
- var link = a.attribs.href || '';
- link = link.split('#')[0];
- if (link) {
- targetLinksList += link + '\n';
- }
- });
- changes = jsdiff.diffLines(sourceLinksList, targetLinksList);
- changes.forEach(function (part) {
- changed = part.added || part.removed;
- });
- if (changed) {
- console.error('Path ' + relativePath + ' has different links.');
- if (options.verbose > 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]);
- });
-
- console.log();
- }
- }
- };
-
- DocsValidator.prototype.validateYaml = function (sourceFile, content, options) {
- if (options.verbose > 0) {
- console.log('Validate ' + sourceFile);
- }
-
- var yamlRegexStripper = /^(---\s*\n[\s\S]*?\n?)^(---\s*$\n?)/m;
- var match = yamlRegexStripper.exec(content);
-
- if (!match) {
- console.log('File ' + sourceFile + ' miss the YAML license header');
- return 1;
- } else {
- if (match[1].indexOf('license:') === -1) {
- console.log('File ' + sourceFile + ' has invalid YAML license header');
- return 2;
- }
- }
-
- return 0;
- };
-
- /**
- * Validates the specific version of documentation
- * @param outputDirectory Directory where documentation is stored.
- * @param language Language which has to be validated.
- * @param version Version which files has to be validated.
- * @param verbose_mode Verbosity level.
- */
- DocsValidator.prototype.fixYamlHeader = function (docsDirectory, language, version, verbose_mode) {
- var self = this;
- var outputDirectory = path.resolve(docsDirectory || FileHelpers.getDefaultInputDirectory());
- var ignore_list = ['.', '..', '.DS_Store', 'test'];
-
- verbose_mode = verbose_mode || 0;
- if (verbose_mode > 0) {
- console.log('Fixing YAML headers for lang ' + language + ' and version ' + version);
- console.log('Clearing output directory');
- }
-
- fs.readdirSync(outputDirectory).forEach(function (language_dir) {
- if (ignore_list.indexOf(language_dir) !== -1) {
- return;
- }
-
- if (language && language_dir !== language) {
- return;
- }
-
- var language_path = path.join(outputDirectory, language_dir);
-
- fs.readdirSync(language_path).forEach(function (version_dir) {
- if (ignore_list.indexOf(version_dir) !== -1) {
- return;
- }
-
- if (version && version_dir !== version) {
- return;
- }
-
- var input_path = path.join(outputDirectory, language_dir, version_dir);
- var options = {
- lang: language_dir,
- version: version_dir,
- verbose: verbose_mode
- };
-
- console.log(' => Fix YAML header for version ' + version_dir + ' on language ' + language_dir + '...');
- self.doFixYamlHeader(input_path, options);
- });
- });
- };
- DocsValidator.prototype.doFixYamlHeader = function (lang_directory, options) {
- var self = this;
- var compareFiles; // eslint-disable-line no-unused-vars
- var completed;
- console.log('Fixing ' + lang_directory);
- completed = false;
- dir.readFiles(lang_directory,
- { match: /\.md/ },
- function (err, content, filename, next) {
- if (err) {
- throw err;
- }
-
- var relativePath = path.relative(lang_directory, filename); // eslint-disable-line no-unused-vars
- fs.readFile(filename, 'utf8', function (err, data) {
- if (err) {
- throw err;
- }
-
- var target = data; // eslint-disable-line no-unused-vars
- var validationResult = self.validateYaml(filename, content, options);
- var yamlReplaceRegex1;
- var yamlReplaceRegex2;
- var eol = require('os').type() === 'win32' ? '\r\n' : '\n';
- var prefix = ' ';
- var correctLicense = '---' + eol +
- 'license: Licensed to the Apache Software Foundation (ASF) under one' + eol +
- prefix + 'or more contributor license agreements. See the NOTICE file' + eol +
- prefix + 'distributed with this work for additional information' + eol +
- prefix + 'regarding copyright ownership. The ASF licenses this file' + eol +
- prefix + 'to you under the Apache License, Version 2.0 (the' + eol +
- prefix + '"License"); you may not use this file except in compliance' + eol +
- prefix + 'with the License. You may obtain a copy of the License at' + eol +
- eol +
- prefix + ' http://www.apache.org/licenses/LICENSE-2.0' + eol +
- eol +
- prefix + 'Unless required by applicable law or agreed to in writing,' + eol +
- prefix + 'software distributed under the License is distributed on an' + eol +
- prefix + '"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY' + eol +
- prefix + 'KIND, either express or implied. See the License for the' + eol +
- prefix + 'specific language governing permissions and limitations' + eol +
- prefix + 'under the License.' + eol +
- '---' + eol + eol;
-
- if (validationResult !== 0) {
- yamlReplaceRegex1 = /^(\* \* \*\s*\n[\s\S]*?\n?)^(\#\# (under the License\.|unter der Lizenz\.|по лицензии\.|aux termes de la licence\.|con la licenza\.|ライセンス。|라이센스\.|根據許可證。)\s*$\n?)/m; // eslint-disable-line no-useless-escape
- if (yamlReplaceRegex1.exec(content)) {
- content = correctLicense + content.replace(yamlReplaceRegex1, '');
- } else {
- yamlReplaceRegex2 = /^(\* \* \*\s*\n[\s\S]*?\n?)^(\* \* \*\s*\s*$\n?)/m;
- if (yamlReplaceRegex2.exec(content)) {
- content = correctLicense + content.replace(yamlReplaceRegex2, '');
- }
- }
-
- fs.writeFile(filename, content, 'utf8', function (err, data) {
- if (err) {
- throw err;
- }
-
- next();
- });
- } else {
- next();
- }
- });
- },
- function (err, files) {
- if (err) {
- throw err;
- }
-
- completed = true;
- });
- function waitCompletition () {
- if (!completed) {
- setImmediate(waitCompletition);
- }
- }
-
- setImmediate(waitCompletition);
- };
-
- return DocsValidator;
-}());
-module.exports = DocsValidator;