Chore: Remove old scripts (#24911)
parent
3f9b7752c7
commit
5be13fcac0
@ -1,114 +0,0 @@ |
||||
/* eslint import/no-unresolved: 0 */ |
||||
|
||||
const fs = require('fs'); |
||||
|
||||
const async = require('async'); |
||||
const _ = require('underscore'); |
||||
const translate = require('google-translate'); |
||||
|
||||
if (!process.argv[2]) { |
||||
console.error('You must inform your Google API key: node auto-translate.js [google-api-key]\n'); |
||||
process.exit(); |
||||
} |
||||
|
||||
const googleTranslate = translate(process.argv[2]); |
||||
|
||||
googleTranslate.getSupportedLanguages(function (err, langs) { |
||||
if (err) { |
||||
console.log(err); |
||||
return; |
||||
} |
||||
|
||||
async.eachSeries(['../../packages/rocketchat-lib/i18n/'], function (path, callback) { |
||||
console.log(`Translating files in: ${path}`); |
||||
const enContents = fs.readFileSync(`${path}en.i18n.json`, 'utf-8'); |
||||
const enUnsorted = JSON.parse(enContents); |
||||
const en = {}; |
||||
_.keys(enUnsorted) |
||||
.sort(function (a, b) { |
||||
if (a.toLowerCase() !== b.toLowerCase()) { |
||||
return a.toLowerCase().localeCompare(b.toLowerCase()); |
||||
} |
||||
return a.localeCompare(b); |
||||
}) |
||||
.forEach(function (key) { |
||||
en[key] = enUnsorted[key]; |
||||
}); |
||||
fs.writeFileSync(`${path}en.i18n.json`, JSON.stringify(en, null, ' ').replace(/": "/g, '" : "'), 'utf8'); |
||||
|
||||
const files = fs.readdirSync(path); |
||||
async.eachSeries( |
||||
files, |
||||
function (file, callback) { |
||||
if (file === 'en.i18n.json') { |
||||
return callback(); |
||||
} |
||||
|
||||
let lang = file.replace('.i18n.json', ''); |
||||
|
||||
if (lang === 'ug' || lang === 'zh-HK') { |
||||
return callback(); |
||||
} |
||||
|
||||
const destContents = fs.readFileSync(path + file, 'utf-8'); |
||||
const destJson = JSON.parse(destContents); |
||||
const toTranslate = {}; |
||||
const newContent = {}; |
||||
|
||||
for (let key in en) { |
||||
if (en.hasOwnProperty(key)) { |
||||
key = `${key}`; |
||||
if (destJson[key]) { |
||||
newContent[key] = destJson[key]; |
||||
} else { |
||||
newContent[key] = ''; |
||||
toTranslate[key] = en[key]; |
||||
} |
||||
} |
||||
} |
||||
|
||||
const invertToTranslate = _.invert(toTranslate); |
||||
const toTranslateLang = _.keys(invertToTranslate); |
||||
|
||||
if (lang === 'ms-MY') { |
||||
lang = 'ms'; |
||||
} |
||||
|
||||
if (lang === 'ta-IN') { |
||||
lang = 'ta'; |
||||
} |
||||
|
||||
if (lang === 'he') { |
||||
lang = 'iw'; |
||||
} |
||||
|
||||
if (langs.indexOf(lang) !== -1 && toTranslateLang.length > 1) { |
||||
console.log(lang, toTranslateLang.length); |
||||
googleTranslate.translate(toTranslateLang, 'en', lang, function (err, translations) { |
||||
if (err) { |
||||
console.log(lang, err); |
||||
} else { |
||||
for (const key in translations) { |
||||
if (translations.hasOwnProperty(key)) { |
||||
newContent[invertToTranslate[translations[key].originalText]] = translations[key].translatedText; |
||||
} |
||||
} |
||||
const newJsonString = JSON.stringify(newContent, null, ' ').replace(/": "/g, '" : "'); |
||||
fs.writeFileSync(path + file, newJsonString, 'utf8'); |
||||
setTimeout(function () { |
||||
return callback(); |
||||
}, 1000); |
||||
} |
||||
}); |
||||
} else { |
||||
const newJsonString = JSON.stringify(newContent, null, ' ').replace(/": "/g, '" : "'); |
||||
fs.writeFileSync(path + file, newJsonString, 'utf8'); |
||||
return callback(); |
||||
} |
||||
}, |
||||
function () { |
||||
return callback(); |
||||
}, |
||||
); |
||||
}); |
||||
}); |
||||
@ -1,76 +0,0 @@ |
||||
const fs = require('fs'); |
||||
const path = require('path'); |
||||
|
||||
const _ = require('underscore'); |
||||
|
||||
let contents = fs.readFileSync(`${__dirname}/../../packages/rocketchat-lib/i18n/en.i18n.json`, 'utf-8'); |
||||
const keys = _.keys(JSON.parse(contents)); |
||||
// var keys = _.keys(JSON.parse(contents)).filter(function(key) { return ['_Description', '_male', '_female', 'theme-color-'].every(function(word) { return key.indexOf(word) === -1; }); });
|
||||
const keysFound = []; |
||||
|
||||
function inspectFile(key, contents) { |
||||
if (contents && contents.indexOf(key) !== -1) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
function ignoreFunc(file) { |
||||
if ( |
||||
['/.meteor/', '/node_modules/', '/moment-locales/'].some(function (word) { |
||||
return file.indexOf(word) !== -1; |
||||
}) |
||||
) { |
||||
return true; |
||||
} |
||||
const ext = path.extname(file); |
||||
return ext !== '.coffee' && ext !== '.js' && ext !== '.html'; |
||||
} |
||||
|
||||
const walk = function (dir, done) { |
||||
let results = []; |
||||
fs.readdir(dir, function (err, list) { |
||||
if (err) { |
||||
return done(err); |
||||
} |
||||
let pending = list.length; |
||||
if (!pending) { |
||||
return done(null, results); |
||||
} |
||||
list.forEach(function (file) { |
||||
file = path.resolve(dir, file); |
||||
fs.stat(file, function (err, stat) { |
||||
if (stat && stat.isDirectory()) { |
||||
walk(file, function (err, res) { |
||||
results = results.concat(res); |
||||
if (!--pending) { |
||||
done(null, results); |
||||
} |
||||
}); |
||||
} else { |
||||
if (!ignoreFunc(file)) { |
||||
results.push(file); |
||||
} |
||||
if (!--pending) { |
||||
done(null, results); |
||||
} |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
walk(`${__dirname}/../..`, function (err, files) { |
||||
if (err) { |
||||
throw err; |
||||
} |
||||
files.forEach(function (file) { |
||||
contents = fs.readFileSync(file, 'utf-8'); |
||||
const searchKeys = _.difference(keys, keysFound); |
||||
searchKeys.forEach(function (key) { |
||||
if (inspectFile(key, contents)) { |
||||
keysFound.push(key); |
||||
} |
||||
}); |
||||
}); |
||||
console.log(_.difference(keys, keysFound)); |
||||
}); |
||||
@ -1,9 +0,0 @@ |
||||
{ |
||||
"dependencies": { |
||||
"async": "^2.0.0-rc.3", |
||||
"fs": "0.0.2", |
||||
"google-translate": "^1.0.6", |
||||
"recursive-readdir": "^2.0.0", |
||||
"underscore": "^1.8.3" |
||||
} |
||||
} |
||||
@ -1,18 +0,0 @@ |
||||
{ |
||||
"name": "unsubscribe_csv", |
||||
"version": "0.0.1", |
||||
"private": true, |
||||
"scripts": { |
||||
"start": "node unsubscribe.js" |
||||
}, |
||||
"dependencies": { |
||||
"commander": "^2.9.0", |
||||
"ddp": "^0.11.0", |
||||
"line-by-line": "^0.1.3", |
||||
"line-reader": "^0.2.4", |
||||
"moment": "^2.10.2", |
||||
"mongodb": "^2.1.0", |
||||
"underscore": "^1.6.0", |
||||
"wait.for": "^0.6.6" |
||||
} |
||||
} |
||||
@ -1,62 +0,0 @@ |
||||
/* eslint import/no-unresolved: 0 */ |
||||
|
||||
import lineReader from 'line-reader'; |
||||
import program from 'commander'; |
||||
import wait from 'wait.for'; |
||||
import { MongoClient } from 'mongodb'; |
||||
|
||||
program |
||||
.usage('[options]') |
||||
.option( |
||||
'-v, --verbose', |
||||
'Verbose', |
||||
function (v, total) { |
||||
return total + 1; |
||||
}, |
||||
0, |
||||
) |
||||
.option('-M, --mongo-db [mongo db]', 'Mongo DB', 'localhost:27017') |
||||
.option('-N, --db-name [db name]', 'DB Name', 'meteor') |
||||
.on('--help', function () { |
||||
console.log(' Example:'); |
||||
console.log(''); |
||||
console.log(' $ node unsubscribe.js'); |
||||
return console.log(''); |
||||
}) |
||||
.parse(process.argv); |
||||
|
||||
wait.launchFiber(function () { |
||||
const db = wait.forMethod(MongoClient, 'connect', `mongodb://${program.mongoDb}/${program.dbName}`, { |
||||
replSet: { |
||||
socketOptions: { |
||||
connectTimeoutMS: 300000, |
||||
}, |
||||
}, |
||||
}); |
||||
|
||||
const User = db.collection('users'); |
||||
return lineReader.eachLine('./unsubscribe.csv', function (line, last) { |
||||
const row = line.split(','); |
||||
if (program.verbose) { |
||||
console.log(row[0]); |
||||
} |
||||
return wait.launchFiber(function () { |
||||
wait.forMethod( |
||||
User, |
||||
'update', |
||||
{ |
||||
'emails.address': row[0], |
||||
}, |
||||
{ |
||||
$set: { |
||||
'mailer.unsubscribed': true, |
||||
}, |
||||
}, |
||||
); |
||||
|
||||
if (last) { |
||||
return process.exit(); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue