mirror of
https://github.com/scratchfoundation/scratch-l10n.git
synced 2025-01-03 11:25:51 -05:00
feat: migrate push help script
This commit is contained in:
parent
db7a2a4ca0
commit
2907601077
1 changed files with 15 additions and 21 deletions
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
|
const {txPush, txCreateResource} = require('../lib/transifex.js');
|
||||||
|
|
||||||
const usage = `
|
const usage = `
|
||||||
Pull knowledge base articles from Freshdesk and push to scratch-help project on transifex. Usage:
|
Pull knowledge base articles from Freshdesk and push to scratch-help project on transifex. Usage:
|
||||||
|
@ -22,15 +23,10 @@ if (!process.env.TX_TOKEN || !process.env.FRESHDESK_TOKEN || args.length > 0) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
import transifex from 'transifex';
|
|
||||||
import FreshdeskApi from './freshdesk-api.js';
|
import FreshdeskApi from './freshdesk-api.js';
|
||||||
|
|
||||||
const FD = new FreshdeskApi('https://mitscratch.freshdesk.com', process.env.FRESHDESK_TOKEN);
|
const FD = new FreshdeskApi('https://mitscratch.freshdesk.com', process.env.FRESHDESK_TOKEN);
|
||||||
const TX_PROJECT = 'scratch-help';
|
const TX_PROJECT = 'scratch-help';
|
||||||
const TX = new transifex({
|
|
||||||
project_slug: TX_PROJECT,
|
|
||||||
credential: 'api:' + process.env.TX_TOKEN
|
|
||||||
});
|
|
||||||
|
|
||||||
const categoryNames = {};
|
const categoryNames = {};
|
||||||
const folderNames = {};
|
const folderNames = {};
|
||||||
|
@ -46,33 +42,31 @@ const makeTxId = item => {
|
||||||
return `${item.name.replace(/[ /]/g, '').slice(0, 30)}_${item.id}`;
|
return `${item.name.replace(/[ /]/g, '').slice(0, 30)}_${item.id}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const txPushResource = (name, articles, type) => {
|
const txPushResource = async (name, articles, type) => {
|
||||||
const resourceData = {
|
const resourceData = {
|
||||||
slug: name,
|
slug: name,
|
||||||
name: name,
|
name: name,
|
||||||
priority: 0, // default to normal priority
|
|
||||||
i18n_type: type,
|
i18n_type: type,
|
||||||
content: '{}'
|
priority: 0, // default to normal priority
|
||||||
|
content: articles
|
||||||
};
|
};
|
||||||
TX.resourceCreateMethod(TX_PROJECT, resourceData, (err) => {
|
|
||||||
// ignore already created error report others
|
try {
|
||||||
if (err && err.response.statusCode !== 400) {
|
await txPush(TX_PROJECT, name, articles);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.statusCode !== 404) {
|
||||||
process.stdout.write(`Transifex Error: ${err.message}\n`);
|
process.stdout.write(`Transifex Error: ${err.message}\n`);
|
||||||
process.stdout.write(
|
process.stdout.write(
|
||||||
`Transifex Error ${err.response.statusCode.toString()}: ${err.response.body}\n`);
|
`Transifex Error ${err.response.statusCode.toString()}: ${err.response.body}\n`);
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// update Transifex with English source
|
|
||||||
TX.uploadSourceLanguageMethod(TX_PROJECT, name,
|
// file not found - create it, but also give message
|
||||||
{content: JSON.stringify(articles, null, 2)}, (err1) => {
|
if (err.statusCode === 404) {
|
||||||
if (err1) {
|
await txCreateResource(TX_PROJECT, resourceData);
|
||||||
process.stdout.write(`Transifex Error:${err1.name}, ${err1.message}\n`);
|
}
|
||||||
process.stdout.write(`Transifex Error:${err1.toString()}\n`);
|
}
|
||||||
process.exitCode = 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue