Skip to content

Commit

Permalink
Merge branch 'master' of github.com:seek-oss/sku into sku-config-codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Nov 14, 2024
2 parents 4af1536 + 1d0b11a commit 58d4ac2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-houses-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': patch
---

Improve logging for `sku translations` CLI commands
49 changes: 34 additions & 15 deletions packages/sku/scripts/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,52 +35,71 @@ const ensureBranch = async () => {
return branch;
};

const log = (message) => console.log(chalk.cyan(message));

(async () => {
const translationSubCommand = commandArguments[0];

console.log(chalk.cyan('Translations', translationSubCommand));

const vocabConfig = getVocabConfig();

if (!vocabConfig) {
console.log(
'No languages configured. Please set languages in sku.config.js before running translation commands',
'No languages configured. Please set languages in before running translation commands',
);
}

if (!translationSubCommands.includes(translationSubCommand)) {
throw new Error(
`Unknown command ${translationSubCommand}. Available options are ${translationSubCommands.join(
`Unknown sub-command ${translationSubCommand}. Available options are ${translationSubCommands.join(
', ',
)}`,
)}.`,
);
}

try {
if (translationSubCommand === 'compile') {
console.log('Watching for changes to translations');
compile({ watch }, vocabConfig);
log('Compiling translations...');

if (watch) {
log('Watching for changes to translations');
}

await compile({ watch }, vocabConfig);

if (!watch) {
log('Successfully compiled translations');
}
}

if (translationSubCommand === 'validate') {
validate(vocabConfig);
log('Validating translations...');
await validate(vocabConfig);
log('Successfully validated translations');
}

if (translationSubCommand === 'push') {
const branch = await ensureBranch();
push({ branch, deleteUnusedKeys }, vocabConfig);

log('Pushing translations to Phrase...');
await push({ branch, deleteUnusedKeys }, vocabConfig);
log('Successfully pushed translations to Phrase');
}

if (translationSubCommand === 'pull') {
const branch = await ensureBranch();
pull({ branch }, vocabConfig);

log('Pulling translations from Phrase...');
await pull({ branch }, vocabConfig);
log('Successfully pulled translations from Phrase');
}
} catch (e) {
if (e) {
console.error(`Error running Translations ${translationSubCommand}:`, e);
console.error(
`Error running ${chalk.bold(`translations ${translationSubCommand}`)}:`,
e,
);
}

process.exit(1);
}

if (!watch) {
console.log(chalk.cyan('Translations complete'));
}
})();

0 comments on commit 58d4ac2

Please sign in to comment.