| #!/usr/bin/env node |
| // Licensed 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. |
| |
| const crawler = require('./lib/index.js'), |
| argument = require('./lib/argument.js'); |
| |
| const arg = process.argv[2]; |
| const template = '{{count}} {{messages}} since {{month}} ' + |
| '({{diff}} change)'; |
| |
| if (arg === '-h' || arg === '--help') { |
| return printUsage(); |
| } |
| |
| if (!argument.validArg(arg)) { |
| console.error('Error: format is YYYYMM - see ' + |
| "'generate-report --help'"); |
| process.exit(1); |
| return; |
| } |
| |
| var monthsForDiff = 3 |
| const queryParams = argument.prepareQueryParams(arg); |
| crawler(queryParams, monthsForDiff, function (err, data) { |
| if (err) { |
| logLine('Error:'); |
| console.error(err); |
| process.exit(1); |
| return; |
| } |
| |
| logLine('Your message counts:'); |
| Object.keys(data).forEach(function (el) { |
| const month = argument.getMonthAsWordFromNow(arg, monthsForDiff), |
| messageCount = data[el].curr, |
| message = messageCount > 1 ? 'messages' : 'message', |
| wikitext = template |
| .replace('{{count}}', messageCount) |
| .replace('{{month}}', month) |
| .replace('{{messages}}', message) |
| .replace('{{diff}}', data[el].diff); |
| |
| console.log(el + ':'); |
| logLine(wikitext); |
| }); |
| console.log('Happy reporting! :)'); |
| }); |
| |
| function logLine (line) { |
| console.log(line + '\n'); |
| } |
| |
| function printUsage () { |
| logLine('usage: generate-report <date> | --help'); |
| console.log('If you are reporting for February 2014, for instance,'); |
| logLine('set the date to: 201402'); |
| console.log('guide:'); |
| console.log('https://cwiki.apache.org/confluence/display' + |
| '/COUCHDB/Guide'); |
| console.log('template:'); |
| console.log('https://cwiki.apache.org/confluence/display' + |
| '/COUCHDB/Template'); |
| } |