@mollie/crowdin-cli
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -1,2 +0,2 @@ | ||
declare const _default: (globString: string) => Promise<void>; | ||
declare const _default: (globPattern: string) => Promise<void>; | ||
export default _default; |
@@ -16,5 +16,5 @@ 'use strict'; | ||
var mkdirp = require('mkdirp'); | ||
var path = _interopDefault(require('path')); | ||
var fg = _interopDefault(require('fast-glob')); | ||
var prettier = require('prettier'); | ||
var cliLib = require('@formatjs/cli-lib'); | ||
var glob = require('glob'); | ||
@@ -271,8 +271,33 @@ // eslint-disable-next-line no-console | ||
const prettify = glob => { | ||
const prettierExecutable = path.join(process.cwd(), "node_modules", ".bin", "prettier"); | ||
const defaultConfig = { | ||
printWidth: 100, | ||
singleQuote: true, | ||
trailingComma: "all", | ||
bracketSpacing: true | ||
}; | ||
if (fs.existsSync(prettierExecutable)) { | ||
log$1.info(`Formatting ${glob} files with Prettier`); | ||
shell.exec([prettierExecutable, "--loglevel silent", "--write", `"${glob}"`].join(" ")); | ||
const prettify = async globPattern => { | ||
const configFilePath = await prettier.resolveConfigFile(); | ||
const configFileContents = await prettier.resolveConfig(configFilePath || ""); | ||
const config = configFileContents || defaultConfig; | ||
try { | ||
const files = await fg.glob(globPattern); | ||
for (const file of files) { | ||
const data = fs.readFileSync(file, "utf-8"); | ||
try { | ||
const pretty = await prettier.format(data, { ...config, | ||
parser: "typescript" | ||
}); | ||
fs.writeFileSync(file, pretty); | ||
log$1.success(`Prettified ${file}`); | ||
} catch (error) { | ||
log$1.error(`Something went wrong while prettifying the file: ${file}`); | ||
} | ||
} | ||
} catch { | ||
log$1.error("No files found, check your glob pattern"); | ||
process.exit(1); | ||
} | ||
@@ -334,10 +359,10 @@ }; | ||
})); | ||
prettify(`${options.translationsDir}/*.+(${fileExtension})`); | ||
await prettify(`${options.translationsDir}/*.${fileExtension}`); | ||
log$1.success("Translations updated"); | ||
}); | ||
var collect = (async globString => { | ||
var collect = (async globPattern => { | ||
log$1.info("Extracting messages"); | ||
mkdirp.sync(config.INTL_DIR); | ||
const files = await glob.glob(globString); | ||
const files = await fg.glob(globPattern); | ||
@@ -353,3 +378,3 @@ if (files.length === 0) { | ||
fs.writeFileSync(config.TRANSLATIONS_FILE, resultAsString); | ||
prettify(config.TRANSLATIONS_FILE); | ||
await prettify(config.TRANSLATIONS_FILE); | ||
}); | ||
@@ -363,7 +388,12 @@ | ||
const branches = await listBranches(branchName); | ||
if (branches.data.length === 0) { | ||
return log$1.error(`Couldn’t find a branch with the name: "${branchName}"`); | ||
} | ||
const branchId = branches.data[0].data.id; | ||
const files = await listFiles(branchId); | ||
try { | ||
if (deleteTasks) { | ||
const files = await listFiles(branchId); | ||
const tasks = await listTasks({ | ||
@@ -382,3 +412,3 @@ branchId | ||
await deleteBranch(branchId); | ||
log$1.success("Branch deleted"); | ||
log$1.success(`Deleted branch: ${branchName} (${branchId})`); | ||
} catch (error) { | ||
@@ -385,0 +415,0 @@ log$1.error(error); |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var a=require("commander"),t=e(require("fs")),r=e(require("axios")),n=require("@crowdin/crowdin-api-client"),s=e(n),o=e(require("chalk")),i=e(require("shelljs")),l=e(require("dotenv")),c=require("mkdirp"),d=e(require("path")),p=require("@formatjs/cli-lib"),u=require("glob");const N=console.log;var h=e=>N("⛔️ "+e),w=e=>N("✅ "+e),m=e=>N("ℹ️ "+e);l.config(),process.env.CROWDIN_PERSONAL_ACCESS_TOKEN&&process.env.CROWDIN_PROJECT_ID&&process.env.CROWDIN_LANGUAGES||(h("Please set all required CROWDIN variables in your .env file."),process.exit(1));const{stdout:E}=i.exec("git rev-parse --abbrev-ref HEAD | tr / -",{silent:!0}),f=E.replace("\n",""),I=process.cwd(),g=I+"/intl",A=process.env.CROWDIN_LANGUAGES.split(","),_=process.env.CROWDIN_DEEPL_SUPPORTED_LANGUAGES?process.env.CROWDIN_DEEPL_SUPPORTED_LANGUAGES.split(","):[],O={BRANCH_NAME:f,FILE_NAME:"source.json",CROWDIN_PERSONAL_ACCESS_TOKEN:process.env.CROWDIN_PERSONAL_ACCESS_TOKEN||"",CROWDIN_PROJECT_ID:Number(process.env.CROWDIN_PROJECT_ID),CROWDIN_LANGUAGES:A,INTL_DIR:g,TRANSLATIONS_DIR:I+"/src/intl",TRANSLATIONS_FILE:g+"/english.source.json",DEEPL_ENGINE_ID:process.env.CROWDIN_DEEPL_ENGINE_ID?Number(process.env.CROWDIN_DEEPL_ENGINE_ID):void 0,DEEPL_SUPPORTED_LANGUAGES:_},{CROWDIN_PERSONAL_ACCESS_TOKEN:S,CROWDIN_PROJECT_ID:b,FILE_NAME:y,DEEPL_ENGINE_ID:D,DEEPL_SUPPORTED_LANGUAGES:T}=O,R=n.TasksModel.Type,{translationsApi:C,sourceFilesApi:L,uploadStorageApi:P,tasksApi:v}=new s({token:S}),G=e=>{var a,t,r;return F(e)?null==e?void 0:e.error:null==e||null==(a=e.errors)||null==(t=a[0])||null==(r=t.error)?void 0:r.errors[0]};function F(e){return void 0!==e.error}const U=e=>L.listProjectBranches(b,e),k=e=>L.listProjectFiles(b,e),x=e=>P.addStorage(y,e),W=async e=>{if("finished"!==(await C.preTranslationStatus(b,e)).data.status)return new Promise(a=>{setTimeout(async()=>{await W(e),a()},1e3)})},$=async({branchName:e,file:a,clearTranslationsAndApprovals:t=!1})=>{var r,s;const i=await x(a),l=await U(e),c=null==l||null==(r=l.data[0])||null==(s=r.data)?void 0:s.id;if(!c)return{error:{code:"branchNotFound",message:"Couldn’t find a branch with the name "+o.bold(e)}};const d=await k(c);return L.updateOrRestoreFile(b,d.data[0].data.id,{storageId:i.data.id,updateOption:t?n.SourceFilesModel.UpdateOption.CLEAR_TRANSLATIONS_AND_APPROVALS:n.SourceFilesModel.UpdateOption.KEEP_TRANSLATIONS})},j=e=>v.listTasks(b,{limit:500,status:n.TasksModel.Status.TODO,...e||{}}),q=async(e,a,t,r,n)=>v.addTask(b,{title:e,fileIds:a,languageId:t,type:r,description:n}),M=async e=>v.deleteTask(b,e),B=e=>{const a=d.join(process.cwd(),"node_modules",".bin","prettier");t.existsSync(a)&&(m(`Formatting ${e} files with Prettier`),i.exec([a,"--loglevel silent","--write",`"${e}"`].join(" ")))};var K=async e=>{m("Extracting messages"),c.sync(O.INTL_DIR);const a=await u.glob(e);0===a.length&&(h("No files found, check your glob pattern"),process.exit(1));const r=await p.extract(a,{format:"crowdin"});t.writeFileSync(O.TRANSLATIONS_FILE,r),B(O.TRANSLATIONS_FILE)};class J extends a.Option{constructor(e){super("-b, --branch-name [string]",e),this.default(O.BRANCH_NAME)}}class H extends a.Option{constructor(e){super("-p, --pre-translate",e),this.default(!1)}}class V extends a.Option{constructor(e){super("-p, --delete-tasks",e),this.default(!1)}}exports.default=async e=>{const s=new a.Command,i=require("../package.json").version;s.name("mollie-crowdin").usage("<upload | collect | download | delete-branch> [options]").version(i),s.command("upload <glob>").description("scan the directory for new messages and upload them").addOption(new J("the Crowdin branch where to sync the translations to")).addOption(new a.Option("-t, --create-tasks","type of tasks to create")).addOption(new H("whether to generate pre-translations for the uploaded files")).action(async(e,a)=>{await K(e);const r=await(async e=>{m("Uploading source file to Crowdin");const a=t.createReadStream(e.translationsFile);try{const t=await(r=e.branchName,L.createBranch(b,{name:r}));if(!F(t)){const e=await(async(e,a)=>{const t=await x(a),r=await U(e);return L.createFile(b,{storageId:t.data.id,name:y,branchId:r.data[0].data.id})})(t.data.name,a);return w("Created branch "+o.bold(t.data.name)),w(`Uploaded source file (id: ${e.data.id}) to branch: ${o.bold(t.data.name)}`),{fileId:e.data.id}}h(t.error.message)}catch(t){const r=G(t);if("notUnique"===r.code){m(`Branch ${o.bold(e.branchName)} already exists`),m("Updating source file in branch: "+o.bold(e.branchName));try{const t=await $({branchName:e.branchName,clearTranslationsAndApprovals:e.clearOnUpdate,file:a});return F(t)?void h(`${t.error.code}: ${t.error.message}`):(w("Source file updated"),{fileId:t.data.id})}catch(e){h(e)}}else h(r.code+": "+r.message)}var r})({translationsFile:O.TRANSLATIONS_FILE,branchName:a.branchName,clearOnUpdate:a.preTranslate});r&&r.fileId&&(a.preTranslate&&await async function(e){try{await(async e=>{if(!D)throw new Error("To apply pre-translations, please set the CROWDIN_DEEPL_ENGINE_ID variable in your .env file.");if(0===T.length)throw new Error("To apply pre-translations, please set the CROWDIN_DEEPL_SUPPORTED_LANGUAGES variable in your .env file.");const a=await C.applyPreTranslation(b,{languageIds:T,fileIds:[e],method:n.TranslationsModel.Method.MT,engineId:D});return W(a.data.identifier)})(e),w("Successfully applied pre-translations")}catch(e){h(e)}}(r.fileId),a.createTasks&&await(async e=>{m("Creating tasks...");const a=(await U(e.branchName)).data[0].data.id,t=await j({branchId:a});await Promise.allSettled(t.data.filter(a=>a.data.fileIds.includes(e.fileId)).map(e=>M(e.data.id)));for await(const a of e.languages){const t="Review translations for "+e.branchName,r=`${e.branchName} (${a})`;try{m(`Creating task for language ${a}: ${t}`);const n=await q(t,[e.fileId],a,"proofread"===e.type?R.PROOFREAD:R.TRANSLATE,r);F(n)&&h(n.error.message),m("Successfully created task for language "+a)}catch(e){const a=G(e);h(null==a?void 0:a.message)}}})({branchName:a.branchName,fileId:r.fileId,languages:O.CROWDIN_LANGUAGES,type:"proofread"}))}),s.command("collect <glob>").description("scan the directory for new messages and save them to english.source.json").action(async e=>{await K(e)}),s.command("download").description("download new translations from Crowdin").option("--typescript","write to TypeScript files (.ts)",!1).addOption(new J("the Crowdin branch from where to download the translations")).action(async e=>{await(async e=>{t.existsSync(e.translationsFile)||(h(e.translationsFile+" does not exist."),process.exit(1)),m("Syncing source file"),c.sync(e.translationsDir);const a=t.createReadStream(e.translationsFile),n=e.typescript?"ts":"js",s=await $({branchName:e.branchName,file:a});F(s)&&(h(s.error.message||"Something went wrong while uploading the source file"),process.exit(1)),m("Downloading translations from Crowdin");const i=await Promise.all(e.languages.map(a=>(async(e,a)=>{const t=(await U(e)).data[0].data.id,n=(await k(t)).data.map(e=>e.data.id),s=await C.exportProjectTranslation(b,{fileIds:n,targetLanguageId:a});return r.get(s.data.url)})(e.branchName,a))).catch(e=>{var a;F(e)&&h(e.error.message),"notInArray"===(null==(a=G(e))?void 0:a.code)&&h("Target language not found. Make sure `CROWDIN_LANGUAGES` is correct."),process.exit(1)});m("Writing translations to: "+o.bold(e.translationsDir)),await Promise.all(e.languages.map((a,r)=>{const s=i[r];if(!s||"OK"!==s.statusText)return;const o=(e=>{const a={};return Object.keys(e).sort().forEach(t=>{a[t]=e[t].message}),a})(s.data),l=JSON.stringify(o,null,4),c=`${e.translationsDir}/${a}.${n}`,d=`// Auto generated file. Do no change. Go to Crowdin to update the translations and run './node_modules/.bin/mollie-crowdin download' to update this file.\nexport default ${l};`;return new Promise(e=>t.writeFile(c,d,()=>e(!0)))})),B(`${e.translationsDir}/*.+(${n})`),w("Translations updated")})({translationsFile:O.TRANSLATIONS_FILE,translationsDir:O.TRANSLATIONS_DIR,languages:O.CROWDIN_LANGUAGES,branchName:e.branchName,typescript:e.typescript})}),s.command("delete-branch").description("clean up branches in Crowdin").addOption(new J("the Crowdin branch to be deleted")).addOption(new V("whether to delete any associated tasks")).action(async e=>{await(async({branchName:e,deleteTasks:a})=>{m("Deleting branch from Crowdin");const t=(await U(e)).data[0].data.id,r=await k(t);try{if(a){const e=await j({branchId:t});await Promise.allSettled(e.data.filter(e=>e.data.fileIds.some(e=>r.data.some(a=>a.data.id===e))).map(e=>M(e.data.id))).then(e=>e.forEach(e=>{"rejected"===e.status&&h(e.reason)}))}await(async e=>L.deleteBranch(b,e))(t),w("Branch deleted")}catch(e){h(e)}})(e)}),await s.parseAsync(e)}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var a=require("commander"),t=e(require("fs")),r=e(require("axios")),n=require("@crowdin/crowdin-api-client"),s=e(n),o=e(require("chalk")),i=e(require("shelljs")),c=e(require("dotenv")),l=require("mkdirp"),d=e(require("fast-glob")),p=require("prettier"),u=require("@formatjs/cli-lib");const N=console.log;var h=e=>N("⛔️ "+e),w=e=>N("✅ "+e),f=e=>N("ℹ️ "+e);c.config(),process.env.CROWDIN_PERSONAL_ACCESS_TOKEN&&process.env.CROWDIN_PROJECT_ID&&process.env.CROWDIN_LANGUAGES||(h("Please set all required CROWDIN variables in your .env file."),process.exit(1));const{stdout:m}=i.exec("git rev-parse --abbrev-ref HEAD | tr / -",{silent:!0}),g=m.replace("\n",""),E=process.cwd(),I=E+"/intl",A=process.env.CROWDIN_LANGUAGES.split(","),O=process.env.CROWDIN_DEEPL_SUPPORTED_LANGUAGES?process.env.CROWDIN_DEEPL_SUPPORTED_LANGUAGES.split(","):[],_={BRANCH_NAME:g,FILE_NAME:"source.json",CROWDIN_PERSONAL_ACCESS_TOKEN:process.env.CROWDIN_PERSONAL_ACCESS_TOKEN||"",CROWDIN_PROJECT_ID:Number(process.env.CROWDIN_PROJECT_ID),CROWDIN_LANGUAGES:A,INTL_DIR:I,TRANSLATIONS_DIR:E+"/src/intl",TRANSLATIONS_FILE:I+"/english.source.json",DEEPL_ENGINE_ID:process.env.CROWDIN_DEEPL_ENGINE_ID?Number(process.env.CROWDIN_DEEPL_ENGINE_ID):void 0,DEEPL_SUPPORTED_LANGUAGES:O},{CROWDIN_PERSONAL_ACCESS_TOKEN:S,CROWDIN_PROJECT_ID:y,FILE_NAME:b,DEEPL_ENGINE_ID:D,DEEPL_SUPPORTED_LANGUAGES:T}=_,R=n.TasksModel.Type,{translationsApi:C,sourceFilesApi:L,uploadStorageApi:P,tasksApi:v}=new s({token:S}),G=e=>{var a,t,r;return F(e)?null==e?void 0:e.error:null==e||null==(a=e.errors)||null==(t=a[0])||null==(r=t.error)?void 0:r.errors[0]};function F(e){return void 0!==e.error}const k=e=>L.listProjectBranches(y,e),U=e=>L.listProjectFiles(y,e),W=e=>P.addStorage(b,e),x=async e=>{if("finished"!==(await C.preTranslationStatus(y,e)).data.status)return new Promise(a=>{setTimeout(async()=>{await x(e),a()},1e3)})},$=async({branchName:e,file:a,clearTranslationsAndApprovals:t=!1})=>{var r,s;const i=await W(a),c=await k(e),l=null==c||null==(r=c.data[0])||null==(s=r.data)?void 0:s.id;if(!l)return{error:{code:"branchNotFound",message:"Couldn’t find a branch with the name "+o.bold(e)}};const d=await U(l);return L.updateOrRestoreFile(y,d.data[0].data.id,{storageId:i.data.id,updateOption:t?n.SourceFilesModel.UpdateOption.CLEAR_TRANSLATIONS_AND_APPROVALS:n.SourceFilesModel.UpdateOption.KEEP_TRANSLATIONS})},j=e=>v.listTasks(y,{limit:500,status:n.TasksModel.Status.TODO,...e||{}}),q=async(e,a,t,r,n)=>v.addTask(y,{title:e,fileIds:a,languageId:t,type:r,description:n}),M=async e=>v.deleteTask(y,e),B={printWidth:100,singleQuote:!0,trailingComma:"all",bracketSpacing:!0},K=async e=>{const a=await p.resolveConfigFile(),r=await p.resolveConfig(a||"")||B;try{const a=await d.glob(e);for(const e of a){const a=t.readFileSync(e,"utf-8");try{const n=await p.format(a,{...r,parser:"typescript"});t.writeFileSync(e,n),w("Prettified "+e)}catch(a){h("Something went wrong while prettifying the file: "+e)}}}catch{h("No files found, check your glob pattern"),process.exit(1)}};var J=async e=>{f("Extracting messages"),l.sync(_.INTL_DIR);const a=await d.glob(e);0===a.length&&(h("No files found, check your glob pattern"),process.exit(1));const r=await u.extract(a,{format:"crowdin"});t.writeFileSync(_.TRANSLATIONS_FILE,r),await K(_.TRANSLATIONS_FILE)};class H extends a.Option{constructor(e){super("-b, --branch-name [string]",e),this.default(_.BRANCH_NAME)}}class Q extends a.Option{constructor(e){super("-p, --pre-translate",e),this.default(!1)}}class V extends a.Option{constructor(e){super("-p, --delete-tasks",e),this.default(!1)}}exports.default=async e=>{const s=new a.Command,i=require("../package.json").version;s.name("mollie-crowdin").usage("<upload | collect | download | delete-branch> [options]").version(i),s.command("upload <glob>").description("scan the directory for new messages and upload them").addOption(new H("the Crowdin branch where to sync the translations to")).addOption(new a.Option("-t, --create-tasks","type of tasks to create")).addOption(new Q("whether to generate pre-translations for the uploaded files")).action(async(e,a)=>{await J(e);const r=await(async e=>{f("Uploading source file to Crowdin");const a=t.createReadStream(e.translationsFile);try{const t=await(r=e.branchName,L.createBranch(y,{name:r}));if(!F(t)){const e=await(async(e,a)=>{const t=await W(a),r=await k(e);return L.createFile(y,{storageId:t.data.id,name:b,branchId:r.data[0].data.id})})(t.data.name,a);return w("Created branch "+o.bold(t.data.name)),w(`Uploaded source file (id: ${e.data.id}) to branch: ${o.bold(t.data.name)}`),{fileId:e.data.id}}h(t.error.message)}catch(t){const r=G(t);if("notUnique"===r.code){f(`Branch ${o.bold(e.branchName)} already exists`),f("Updating source file in branch: "+o.bold(e.branchName));try{const t=await $({branchName:e.branchName,clearTranslationsAndApprovals:e.clearOnUpdate,file:a});return F(t)?void h(`${t.error.code}: ${t.error.message}`):(w("Source file updated"),{fileId:t.data.id})}catch(e){h(e)}}else h(r.code+": "+r.message)}var r})({translationsFile:_.TRANSLATIONS_FILE,branchName:a.branchName,clearOnUpdate:a.preTranslate});r&&r.fileId&&(a.preTranslate&&await async function(e){try{await(async e=>{if(!D)throw new Error("To apply pre-translations, please set the CROWDIN_DEEPL_ENGINE_ID variable in your .env file.");if(0===T.length)throw new Error("To apply pre-translations, please set the CROWDIN_DEEPL_SUPPORTED_LANGUAGES variable in your .env file.");const a=await C.applyPreTranslation(y,{languageIds:T,fileIds:[e],method:n.TranslationsModel.Method.MT,engineId:D});return x(a.data.identifier)})(e),w("Successfully applied pre-translations")}catch(e){h(e)}}(r.fileId),a.createTasks&&await(async e=>{f("Creating tasks...");const a=(await k(e.branchName)).data[0].data.id,t=await j({branchId:a});await Promise.allSettled(t.data.filter(a=>a.data.fileIds.includes(e.fileId)).map(e=>M(e.data.id)));for await(const a of e.languages){const t="Review translations for "+e.branchName,r=`${e.branchName} (${a})`;try{f(`Creating task for language ${a}: ${t}`);const n=await q(t,[e.fileId],a,"proofread"===e.type?R.PROOFREAD:R.TRANSLATE,r);F(n)&&h(n.error.message),f("Successfully created task for language "+a)}catch(e){const a=G(e);h(null==a?void 0:a.message)}}})({branchName:a.branchName,fileId:r.fileId,languages:_.CROWDIN_LANGUAGES,type:"proofread"}))}),s.command("collect <glob>").description("scan the directory for new messages and save them to english.source.json").action(async e=>{await J(e)}),s.command("download").description("download new translations from Crowdin").option("--typescript","write to TypeScript files (.ts)",!1).addOption(new H("the Crowdin branch from where to download the translations")).action(async e=>{await(async e=>{t.existsSync(e.translationsFile)||(h(e.translationsFile+" does not exist."),process.exit(1)),f("Syncing source file"),l.sync(e.translationsDir);const a=t.createReadStream(e.translationsFile),n=e.typescript?"ts":"js",s=await $({branchName:e.branchName,file:a});F(s)&&(h(s.error.message||"Something went wrong while uploading the source file"),process.exit(1)),f("Downloading translations from Crowdin");const i=await Promise.all(e.languages.map(a=>(async(e,a)=>{const t=(await k(e)).data[0].data.id,n=(await U(t)).data.map(e=>e.data.id),s=await C.exportProjectTranslation(y,{fileIds:n,targetLanguageId:a});return r.get(s.data.url)})(e.branchName,a))).catch(e=>{var a;F(e)&&h(e.error.message),"notInArray"===(null==(a=G(e))?void 0:a.code)&&h("Target language not found. Make sure `CROWDIN_LANGUAGES` is correct."),process.exit(1)});f("Writing translations to: "+o.bold(e.translationsDir)),await Promise.all(e.languages.map((a,r)=>{const s=i[r];if(!s||"OK"!==s.statusText)return;const o=(e=>{const a={};return Object.keys(e).sort().forEach(t=>{a[t]=e[t].message}),a})(s.data),c=JSON.stringify(o,null,4),l=`${e.translationsDir}/${a}.${n}`,d=`// Auto generated file. Do no change. Go to Crowdin to update the translations and run './node_modules/.bin/mollie-crowdin download' to update this file.\nexport default ${c};`;return new Promise(e=>t.writeFile(l,d,()=>e(!0)))})),await K(`${e.translationsDir}/*.${n}`),w("Translations updated")})({translationsFile:_.TRANSLATIONS_FILE,translationsDir:_.TRANSLATIONS_DIR,languages:_.CROWDIN_LANGUAGES,branchName:e.branchName,typescript:e.typescript})}),s.command("delete-branch").description("clean up branches in Crowdin").addOption(new H("the Crowdin branch to be deleted")).addOption(new V("whether to delete any associated tasks")).action(async e=>{await(async({branchName:e,deleteTasks:a})=>{f("Deleting branch from Crowdin");const t=await k(e);if(0===t.data.length)return h(`Couldn’t find a branch with the name: "${e}"`);const r=t.data[0].data.id;try{if(a){const e=await U(r),a=await j({branchId:r});await Promise.allSettled(a.data.filter(a=>a.data.fileIds.some(a=>e.data.some(e=>e.data.id===a))).map(e=>M(e.data.id))).then(e=>e.forEach(e=>{"rejected"===e.status&&h(e.reason)}))}await(async e=>L.deleteBranch(y,e))(r),w(`Deleted branch: ${e} (${r})`)}catch(e){h(e)}})(e)}),await s.parseAsync(e)}; | ||
//# sourceMappingURL=crowdin-cli.cjs.production.min.js.map |
@@ -9,5 +9,5 @@ import { Command, Option } from 'commander'; | ||
import { sync } from 'mkdirp'; | ||
import path from 'path'; | ||
import fg from 'fast-glob'; | ||
import { resolveConfigFile, resolveConfig, format } from 'prettier'; | ||
import { extract } from '@formatjs/cli-lib'; | ||
import { glob } from 'glob'; | ||
@@ -264,8 +264,33 @@ // eslint-disable-next-line no-console | ||
const prettify = glob => { | ||
const prettierExecutable = path.join(process.cwd(), "node_modules", ".bin", "prettier"); | ||
const defaultConfig = { | ||
printWidth: 100, | ||
singleQuote: true, | ||
trailingComma: "all", | ||
bracketSpacing: true | ||
}; | ||
if (fs.existsSync(prettierExecutable)) { | ||
log$1.info(`Formatting ${glob} files with Prettier`); | ||
shell.exec([prettierExecutable, "--loglevel silent", "--write", `"${glob}"`].join(" ")); | ||
const prettify = async globPattern => { | ||
const configFilePath = await resolveConfigFile(); | ||
const configFileContents = await resolveConfig(configFilePath || ""); | ||
const config = configFileContents || defaultConfig; | ||
try { | ||
const files = await fg.glob(globPattern); | ||
for (const file of files) { | ||
const data = fs.readFileSync(file, "utf-8"); | ||
try { | ||
const pretty = await format(data, { ...config, | ||
parser: "typescript" | ||
}); | ||
fs.writeFileSync(file, pretty); | ||
log$1.success(`Prettified ${file}`); | ||
} catch (error) { | ||
log$1.error(`Something went wrong while prettifying the file: ${file}`); | ||
} | ||
} | ||
} catch { | ||
log$1.error("No files found, check your glob pattern"); | ||
process.exit(1); | ||
} | ||
@@ -327,10 +352,10 @@ }; | ||
})); | ||
prettify(`${options.translationsDir}/*.+(${fileExtension})`); | ||
await prettify(`${options.translationsDir}/*.${fileExtension}`); | ||
log$1.success("Translations updated"); | ||
}); | ||
var collect = (async globString => { | ||
var collect = (async globPattern => { | ||
log$1.info("Extracting messages"); | ||
sync(config.INTL_DIR); | ||
const files = await glob(globString); | ||
const files = await fg.glob(globPattern); | ||
@@ -346,3 +371,3 @@ if (files.length === 0) { | ||
fs.writeFileSync(config.TRANSLATIONS_FILE, resultAsString); | ||
prettify(config.TRANSLATIONS_FILE); | ||
await prettify(config.TRANSLATIONS_FILE); | ||
}); | ||
@@ -356,7 +381,12 @@ | ||
const branches = await listBranches(branchName); | ||
if (branches.data.length === 0) { | ||
return log$1.error(`Couldn’t find a branch with the name: "${branchName}"`); | ||
} | ||
const branchId = branches.data[0].data.id; | ||
const files = await listFiles(branchId); | ||
try { | ||
if (deleteTasks) { | ||
const files = await listFiles(branchId); | ||
const tasks = await listTasks({ | ||
@@ -375,3 +405,3 @@ branchId | ||
await deleteBranch(branchId); | ||
log$1.success("Branch deleted"); | ||
log$1.success(`Deleted branch: ${branchName} (${branchId})`); | ||
} catch (error) { | ||
@@ -378,0 +408,0 @@ log$1.error(error); |
@@ -1,2 +0,2 @@ | ||
declare const prettify: (glob: string) => void; | ||
declare const prettify: (globPattern: string) => Promise<void>; | ||
export default prettify; |
{ | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"license": "MIT", | ||
@@ -60,6 +60,9 @@ "name": "@mollie/crowdin-cli", | ||
"dotenv": "^8.2.0", | ||
"glob": "^10.3.10", | ||
"fast-glob": "^3.3.2", | ||
"mkdirp": "^1.0.4", | ||
"shelljs": "^0.8.5" | ||
}, | ||
"peerDependencies": { | ||
"prettier": "^3.2.2" | ||
}, | ||
"devDependencies": { | ||
@@ -66,0 +69,0 @@ "@types/commander": "^2.12.2", |
@@ -6,10 +6,10 @@ import { sync } from "mkdirp"; | ||
import { extract } from "@formatjs/cli-lib"; | ||
import { glob } from "glob"; | ||
import fg from "fast-glob"; | ||
import fs from "fs"; | ||
export default async (globString: string) => { | ||
export default async (globPattern: string) => { | ||
log.info("Extracting messages"); | ||
sync(config.INTL_DIR); | ||
const files = await glob(globString); | ||
const files = await fg.glob(globPattern); | ||
if (files.length === 0) { | ||
@@ -24,3 +24,3 @@ log.error("No files found, check your glob pattern"); | ||
prettify(config.TRANSLATIONS_FILE); | ||
await prettify(config.TRANSLATIONS_FILE); | ||
}; |
@@ -19,7 +19,12 @@ import { | ||
const branches = await listBranches(branchName); | ||
if (branches.data.length === 0) { | ||
return log.error(`Couldn’t find a branch with the name: "${branchName}"`); | ||
} | ||
const branchId = branches.data[0].data.id; | ||
const files = await listFiles(branchId); | ||
try { | ||
if (deleteTasks) { | ||
const files = await listFiles(branchId); | ||
const tasks = await listTasks({ branchId }); | ||
@@ -45,3 +50,3 @@ | ||
await deleteBranch(branchId); | ||
log.success("Branch deleted"); | ||
log.success(`Deleted branch: ${branchName} (${branchId})`); | ||
} catch (error) { | ||
@@ -48,0 +53,0 @@ log.error(error as string); |
@@ -92,5 +92,5 @@ import { sync } from "mkdirp"; | ||
prettify(`${options.translationsDir}/*.+(${fileExtension})`); | ||
await prettify(`${options.translationsDir}/*.${fileExtension}`); | ||
log.success("Translations updated"); | ||
}; |
@@ -1,21 +0,37 @@ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import shell from "shelljs"; | ||
import fg from "fast-glob"; | ||
import log from "./logging"; | ||
import * as prettier from "prettier"; | ||
const prettify = (glob: string) => { | ||
const prettierExecutable = path.join( | ||
process.cwd(), | ||
"node_modules", | ||
".bin", | ||
"prettier" | ||
); | ||
const defaultConfig: prettier.Options = { | ||
printWidth: 100, | ||
singleQuote: true, | ||
trailingComma: "all", | ||
bracketSpacing: true, | ||
}; | ||
if (fs.existsSync(prettierExecutable)) { | ||
log.info(`Formatting ${glob} files with Prettier`); | ||
shell.exec( | ||
[prettierExecutable, "--loglevel silent", "--write", `"${glob}"`].join( | ||
" " | ||
) | ||
); | ||
const prettify = async (globPattern: string) => { | ||
const configFilePath = await prettier.resolveConfigFile(); | ||
const configFileContents = await prettier.resolveConfig(configFilePath || ""); | ||
const config = configFileContents || defaultConfig; | ||
try { | ||
const files = await fg.glob(globPattern); | ||
for (const file of files) { | ||
const data = fs.readFileSync(file, "utf-8"); | ||
try { | ||
const pretty = await prettier.format(data, { | ||
...config, | ||
parser: "typescript", | ||
}); | ||
fs.writeFileSync(file, pretty); | ||
log.success(`Prettified ${file}`); | ||
} catch (error) { | ||
log.error(`Something went wrong while prettifying the file: ${file}`); | ||
} | ||
} | ||
} catch { | ||
log.error("No files found, check your glob pattern"); | ||
process.exit(1); | ||
} | ||
@@ -22,0 +38,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
193945
1762
10
+ Addedfast-glob@^3.3.2
+ Addedprettier@3.4.2(transitive)
- Removedglob@^10.3.10
- Removed@isaacs/cliui@8.0.2(transitive)
- Removed@pkgjs/parseargs@0.11.0(transitive)
- Removedansi-regex@5.0.16.1.0(transitive)
- Removedansi-styles@6.2.1(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removedeastasianwidth@0.2.0(transitive)
- Removedemoji-regex@8.0.09.2.2(transitive)
- Removedforeground-child@3.3.0(transitive)
- Removedglob@10.4.5(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjackspeak@3.4.3(transitive)
- Removedlru-cache@10.4.3(transitive)
- Removedminimatch@9.0.5(transitive)
- Removedminipass@7.1.2(transitive)
- Removedpackage-json-from-dist@1.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpath-scurry@1.11.1(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@4.1.0(transitive)
- Removedstring-width@4.2.35.1.2(transitive)
- Removedstrip-ansi@6.0.17.1.0(transitive)
- Removedwhich@2.0.2(transitive)
- Removedwrap-ansi@7.0.08.1.0(transitive)