]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Initial version of script for dealing with locale authors
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 21 Mar 2016 01:46:00 +0000 (18:46 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 31 Aug 2016 17:48:12 +0000 (10:48 -0700)
scripts/locales.js [new file with mode: 0755]

diff --git a/scripts/locales.js b/scripts/locales.js
new file mode 100755 (executable)
index 0000000..3ce5832
--- /dev/null
@@ -0,0 +1,74 @@
+var fs = require('fs'),
+    path = require('path');
+
+var localeDir = path.join('src', 'locale');
+
+var args = process.argv.slice(2);
+
+function help() {
+    console.log(process.argv[1], '[list]');
+    console.log();
+    console.log("    list      show all authors in all locales");
+    console.log("    mention   show all authors in all locales, ready to copy-paste in github issue");
+}
+
+function extract() {
+    var authors = {};
+    fs.readdirSync(localeDir).forEach(function (locale) {
+        var content = fs.readFileSync(path.join(localeDir, locale), {encoding: 'utf-8'}),
+            localeCode = locale.split('.')[0],
+            localeAuthors = [];
+        content.split('\n').forEach(function (line) {
+            var match = line.match(/^\/\/! author.*github[.]com\/(.*)$/);
+            if (match !== null) {
+                // console.log("  ", line);
+                localeAuthors.push(match[1]);
+            }
+        });
+        if (localeAuthors.length === 0) {
+            // use to debug
+            content.split('\n').forEach(function (line) {
+                var match = line.match(/^\/\/! author(.*)$/);
+                if (match !== null) {
+                    // console.log("  ", line);
+                    localeAuthors.push('---' + match[1]);
+                }
+            });
+            console.log(localeCode, localeAuthors);
+        } else {
+            authors[localeCode] = localeAuthors;
+        }
+    });
+    return authors;
+}
+
+function list() {
+    var authors = extract();
+    Object.keys(authors).forEach(function (localeCode) {
+        console.log(localeCode, authors[localeCode]);
+    });
+}
+
+function mention() {
+    var authors = extract();
+    Object.keys(authors).forEach(function (localeCode) {
+        console.log('- [ ]', localeCode, authors[localeCode].map(function (author) { return "@" + author; }).join(" "));
+    });
+}
+
+if (args.length === 0) {
+    help();
+    process.exit(0);
+}
+
+switch (args[0]) {
+    case 'list':
+        list();
+        break;
+    case 'mention':
+        mention();
+        break;
+    default:
+        console.log("unknown argument", args[0]);
+        break;
+}