prettier
This commit is contained in:
parent
ae9d139754
commit
3d70b8f1c1
|
@ -16,7 +16,10 @@ const PHRASE_COUNT_THRESHOLD_PERCENT = 75;
|
|||
const ts = Math.floor(new Date() / 1000);
|
||||
|
||||
const hashStr = ts + keys.secret;
|
||||
const hash = crypto.createHash('md5').update(hashStr).digest('hex');
|
||||
const hash = crypto
|
||||
.createHash('md5')
|
||||
.update(hashStr)
|
||||
.digest('hex');
|
||||
const urlParams = {
|
||||
'api_key': keys.public,
|
||||
'timestamp': ts,
|
||||
|
@ -27,7 +30,8 @@ const urlParams = {
|
|||
|
||||
const pluginManifest = fs.readFileSync('tmpl/manifest.json', 'utf8');
|
||||
const pluginIndexPage = fs.readFileSync('tmpl/language-index.html', 'utf8');
|
||||
const publicKey = fs.readFileSync('keys/public-key.pem', 'utf8')
|
||||
const publicKey = fs
|
||||
.readFileSync('keys/public-key.pem', 'utf8')
|
||||
.match(/-+BEGIN PUBLIC KEY-+([\s\S]+?)-+END PUBLIC KEY-+/)[1]
|
||||
.replace(/\n/g, '');
|
||||
const defaultCountries = { 'SE': 'sv' };
|
||||
|
@ -35,9 +39,7 @@ const defaultCountries = { 'SE': 'sv' };
|
|||
module.exports = function() {
|
||||
return new Promise(resolve => {
|
||||
loadLanguages(languages =>
|
||||
loadTranslations(translations =>
|
||||
resolve(processData(languages, translations))
|
||||
)
|
||||
loadTranslations(translations => resolve(processData(languages, translations)))
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -46,8 +48,12 @@ module.exports = function() {
|
|||
return callback(JSON.parse(fs.readFileSync('./data/languages.json', 'utf8')));
|
||||
}
|
||||
console.log('Loading language names...');
|
||||
const url = API_URL_LANGUAGES.replace(':project_id', PROJECT_ID) + '?' +
|
||||
Object.keys(urlParams).map(param => param + '=' + urlParams[param]).join('&');
|
||||
const url =
|
||||
API_URL_LANGUAGES.replace(':project_id', PROJECT_ID) +
|
||||
'?' +
|
||||
Object.keys(urlParams)
|
||||
.map(param => param + '=' + urlParams[param])
|
||||
.join('&');
|
||||
https.get(url, res => {
|
||||
if (res.statusCode !== 200) {
|
||||
console.error(`API error ${res.statusCode}`);
|
||||
|
@ -71,8 +77,12 @@ module.exports = function() {
|
|||
return callback(JSON.parse(fs.readFileSync('./data/translations.json', 'utf8')));
|
||||
}
|
||||
console.log('Loading translations...');
|
||||
const url = API_URL.replace(':project_id', PROJECT_ID) + '?' +
|
||||
Object.keys(urlParams).map(param => param + '=' + urlParams[param]).join('&');
|
||||
const url =
|
||||
API_URL.replace(':project_id', PROJECT_ID) +
|
||||
'?' +
|
||||
Object.keys(urlParams)
|
||||
.map(param => param + '=' + urlParams[param])
|
||||
.join('&');
|
||||
https.get(url, res => {
|
||||
if (res.statusCode !== 200) {
|
||||
console.error(`API error ${res.statusCode}`);
|
||||
|
@ -104,12 +114,14 @@ module.exports = function() {
|
|||
continue;
|
||||
}
|
||||
const langPhraseCount = Object.keys(languageTranslations).length;
|
||||
const percentage = Math.round(langPhraseCount / totalPhraseCount * 100);
|
||||
const percentage = Math.round((langPhraseCount / totalPhraseCount) * 100);
|
||||
let skip = percentage >= PHRASE_COUNT_THRESHOLD_PERCENT ? null : 'SKIP';
|
||||
|
||||
let languageJson = JSON.stringify(languageTranslations, null, 2);
|
||||
if (!skip && fs.existsSync(`docs/translations/${lang}/${lang}.json`)) {
|
||||
const oldJson = fs.readFileSync(`docs/translations/${lang}/${lang}.json`, { encoding: 'utf8' });
|
||||
const oldJson = fs.readFileSync(`docs/translations/${lang}/${lang}.json`, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
if (oldJson === languageJson) {
|
||||
skip = 'NO CHANGES';
|
||||
}
|
||||
|
@ -117,18 +129,33 @@ module.exports = function() {
|
|||
|
||||
const action = skip ? `\x1b[35m${skip}\x1b[0m` : '\x1b[36mOK\x1b[0m';
|
||||
|
||||
console.log(`[${lang}] ${langPhraseCount} / ${totalPhraseCount} (${percentage}%) -> ${action}`);
|
||||
console.log(
|
||||
`[${lang}] ${langPhraseCount} / ${totalPhraseCount} (${percentage}%) -> ${action}`
|
||||
);
|
||||
|
||||
const langInfo = languages.data.filter(x => x.code === lang)[0];
|
||||
const region = (defaultCountries[langInfo.region] || langInfo.region).toLowerCase();
|
||||
const langName = langInfo.locale === region ? langInfo.local_name.replace(/\s*\(.*\)/, '') : langInfo.local_name;
|
||||
const langNameEn = langInfo.locale === region ? langInfo.english_name.replace(/\s*\(.*\)/, '') : langInfo.english_name;
|
||||
const langName =
|
||||
langInfo.locale === region
|
||||
? langInfo.local_name.replace(/\s*\(.*\)/, '')
|
||||
: langInfo.local_name;
|
||||
const langNameEn =
|
||||
langInfo.locale === region
|
||||
? langInfo.english_name.replace(/\s*\(.*\)/, '')
|
||||
: langInfo.english_name;
|
||||
|
||||
if (skip) {
|
||||
skipCount++;
|
||||
if (skip !== 'SKIP') {
|
||||
const manifest = JSON.parse(fs.readFileSync(`docs/translations/${lang}/manifest.json`, 'utf8'));
|
||||
meta[lang] = {name: langName, nameEn: langNameEn, count: langPhraseCount, version: manifest.version};
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(`docs/translations/${lang}/manifest.json`, 'utf8')
|
||||
);
|
||||
meta[lang] = {
|
||||
name: langName,
|
||||
nameEn: langNameEn,
|
||||
count: langPhraseCount,
|
||||
version: manifest.version
|
||||
};
|
||||
}
|
||||
} else {
|
||||
langCount++;
|
||||
|
@ -151,9 +178,9 @@ module.exports = function() {
|
|||
continue;
|
||||
}
|
||||
const textMatches = text.match(/"/g);
|
||||
const textMatchesCount = textMatches && textMatches.length || 0;
|
||||
const textMatchesCount = (textMatches && textMatches.length) || 0;
|
||||
const enTextMatches = enText.match(/"/g);
|
||||
const enTextMatchesCount = enTextMatches && enTextMatches.length || 0;
|
||||
const enTextMatchesCount = (enTextMatches && enTextMatches.length) || 0;
|
||||
if (enTextMatchesCount !== textMatchesCount) {
|
||||
const textHl = text.replace(/"/g, '\x1b[33m"\x1b[0m');
|
||||
console.warn(`[${lang}] \x1b[33mWARN:"\x1b[0m ${name}: ${textHl}`);
|
||||
|
@ -170,7 +197,9 @@ module.exports = function() {
|
|||
}
|
||||
if (enText.indexOf('{}') >= 0 && text.indexOf('{}') < 0) {
|
||||
const enTextHl = enText.replace(/{}/g, '\x1b[31m{}\x1b[0m');
|
||||
console.error(`[${lang}] \x1b[31mERROR:NO{}\x1b[0m ${name}: ${text} <--> ${enTextHl}`);
|
||||
console.error(
|
||||
`[${lang}] \x1b[31mERROR:NO{}\x1b[0m ${name}: ${text} <--> ${enTextHl}`
|
||||
);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
@ -186,18 +215,25 @@ module.exports = function() {
|
|||
meta[lang] = { name: langName, nameEn: langNameEn, count: langPhraseCount };
|
||||
|
||||
if (fs.existsSync(`docs/translations/${lang}`)) {
|
||||
const manifest = JSON.parse(fs.readFileSync(`docs/translations/${lang}/manifest.json`, 'utf8'));
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(`docs/translations/${lang}/manifest.json`, 'utf8')
|
||||
);
|
||||
if (manifest.resources.loc !== signature) {
|
||||
const parts = manifest.version.split('.');
|
||||
manifest.version = parts[0] + '.' + (+parts[1] + 1) + '.0';
|
||||
manifest.resources.loc = signature;
|
||||
fs.writeFileSync(`docs/translations/${lang}/manifest.json`, JSON.stringify(manifest, null, 2));
|
||||
fs.writeFileSync(
|
||||
`docs/translations/${lang}/manifest.json`,
|
||||
JSON.stringify(manifest, null, 2)
|
||||
);
|
||||
fs.writeFileSync(`docs/translations/${lang}/${lang}.json`, languageJson);
|
||||
}
|
||||
meta[lang].version = manifest.version;
|
||||
} else {
|
||||
fs.mkdirSync(`docs/translations/${lang}`);
|
||||
fs.writeFileSync(`docs/translations/${lang}/manifest.json`, pluginManifest
|
||||
fs.writeFileSync(
|
||||
`docs/translations/${lang}/manifest.json`,
|
||||
pluginManifest
|
||||
.replace(/{lang}/g, lang)
|
||||
.replace(/{name_ascii}/g, langNameEn.replace(/\W+/g, '-').toLowerCase())
|
||||
.replace(/{name_en}/g, langNameEn)
|
||||
|
@ -206,9 +242,9 @@ module.exports = function() {
|
|||
.replace(/{key}/g, publicKey)
|
||||
);
|
||||
fs.writeFileSync(`docs/translations/${lang}/${lang}.json`, languageJson);
|
||||
fs.writeFileSync(`docs/translations/${lang}/index.html`, pluginIndexPage
|
||||
.replace(/{lang}/g, lang)
|
||||
.replace(/{name}/g, langName)
|
||||
fs.writeFileSync(
|
||||
`docs/translations/${lang}/index.html`,
|
||||
pluginIndexPage.replace(/{lang}/g, lang).replace(/{name}/g, langName)
|
||||
);
|
||||
meta[lang].version = '1.0.0';
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const ps = require('child_process');
|
||||
|
||||
const oldKey = fs.readFileSync('keys/public-key-old.pem', 'utf8')
|
||||
const oldKey = fs
|
||||
.readFileSync('keys/public-key-old.pem', 'utf8')
|
||||
.match(/-+BEGIN PUBLIC KEY-+([\s\S]+?)-+END PUBLIC KEY-+/)[1]
|
||||
.replace(/\s+/g, '');
|
||||
const newKey = fs.readFileSync('keys/public-key.pem', 'utf8')
|
||||
const newKey = fs
|
||||
.readFileSync('keys/public-key.pem', 'utf8')
|
||||
.match(/-+BEGIN PUBLIC KEY-+([\s\S]+?)-+END PUBLIC KEY-+/)[1]
|
||||
.replace(/\s+/g, '');
|
||||
|
||||
|
@ -21,15 +23,19 @@ for (const pluginDir of pluginDirs) {
|
|||
}
|
||||
manifest.publicKey = newKey;
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
||||
const result = ps.spawnSync('node', [
|
||||
const result = ps.spawnSync(
|
||||
'node',
|
||||
[
|
||||
'../keeweb/plugins/keeweb-plugin/keeweb-plugin.js',
|
||||
'sign',
|
||||
path.join(pluginDir, pluginName),
|
||||
'--signer-module=../../../keeweb-plugins/scripts/sign',
|
||||
'--bump-version'
|
||||
], {
|
||||
],
|
||||
{
|
||||
stdio: 'inherit'
|
||||
});
|
||||
}
|
||||
);
|
||||
if (result.status) {
|
||||
throw 'Sign error';
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ function getPin() {
|
|||
}
|
||||
|
||||
module.exports = function sign(data) {
|
||||
return getPin().then(pin => signer.sign({ data, verifyKey, pin, ...signerOptions })
|
||||
.then(data => data.toString('base64')));
|
||||
return getPin().then(pin =>
|
||||
signer
|
||||
.sign({ data, verifyKey, pin, ...signerOptions })
|
||||
.then(data => data.toString('base64'))
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue