gen_versions.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Licensed to the Apache Software Foundation (ASF) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. 'use strict';
  18. var path = require('path');
  19. var yaml = require('js-yaml');
  20. var util = require('./util');
  21. // constants
  22. var LANGUAGE_MAP = {
  23. 'de': 'Deutsch',
  24. 'en': 'English',
  25. 'es': 'Español',
  26. 'fr': 'Français',
  27. 'it': 'Italiano',
  28. 'ja': '日本語',
  29. 'ko': '한국어',
  30. 'pl': 'Polski',
  31. 'ru': 'Русский',
  32. 'sl': 'Slovene',
  33. 'zh-cn': '简体中文',
  34. 'zh-tw': '繁體中文'
  35. };
  36. function main () {
  37. var scriptName = process.argv[1];
  38. var rootDir = process.argv[2];
  39. var config = {};
  40. if (!rootDir) {
  41. console.error('Please specify a directory from which to generate.');
  42. process.exit(1);
  43. }
  44. // go through directory that contains all languages
  45. util.listdirsSync(rootDir).forEach(function (langId) {
  46. var langPath = path.join(rootDir, langId);
  47. var versionNames = util.listdirsSync(langPath);
  48. // get language ID
  49. var langName = LANGUAGE_MAP[langId];
  50. if (!langName) {
  51. console.error("Language identifier '" + langId + "' doesn't have an associated name. Please fix that by changing " + scriptName + '.');
  52. process.exit(1);
  53. }
  54. // set the language name and the versions it has
  55. config[langId] = {
  56. 'name': langName,
  57. 'versions': versionNames
  58. };
  59. });
  60. console.log(util.generatedBy(__filename));
  61. console.log(yaml.dump(config, { indent: 4 }));
  62. }
  63. main();