| #!/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(""); |