UNPKG

@frontitude/cli

Version:

The Frontitude CLI enables product teams to integrate their code with Frontitude (frontitude.com), thus creating a single source of truth for their product copy, from design to development.

1 lines 4.35 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PullCommand=void 0;const tslib_1=require("tslib"),core_1=require("@oclif/core"),clc=require("cli-color"),strings=tslib_1.__importStar(require("../../strings.json")),ErrorNames=tslib_1.__importStar(require("../../common/constants/ErrorNames")),codebaseIntegration_1=require("../../lib/codebaseIntegration"),Loader_1=require("../../lib/ui/Loader"),string_1=require("../../utils/string"),logger=tslib_1.__importStar(require("../../common/logger")),getFilesUpdateSummaryString=e=>{let s="";for(const r of Object.keys(e))s+=(0,string_1.replaceVariables)(strings["pullCommand-fileUpdateSummary"],{fileName:clc.yellow(r),addedCount:clc.bold(e[r].added),changedCount:clc.bold(e[r].edited)}),s+="\n ";return s};class PullCommand extends core_1.Command{async run(){const{flags:e}=await this.parse(PullCommand),{status:s,"has-key":r,"access-token":a,"dry-run":t,"include-translations":i,"include-metadata":o,tags:l,pages:n,frames:d,nested:m}=e;let u;a&&(process.env.ACCESS_TOKEN=a);try{u=t?new Loader_1.Loader(strings["pullCommand-loaderDryRunMessage"],strings["pullCommand-loaderDryRunMessage-success"],strings["pullCommand-loaderDryRunMessage-fail"]):new Loader_1.Loader(strings["pullCommand-loaderMessage"],"",strings["pullCommand-loaderMessage-fail"]),u.start();const e=l?l.split(",").map((e=>e.trim())):void 0,a=n?n.split(",").map((e=>e.trim())):void 0,g=d?d.split(",").map((e=>e.trim())):void 0,c=await(0,codebaseIntegration_1.pullProjectsTextsIntoCodebase)({status:s,hasKey:r,isIncludeTranslations:i,isIncludeMetadata:o,isUseNestedFormat:m,tagNames:e,pageNames:a,frameNames:g},t);t||u.updateSuccessMessage(strings["pullCommand-loaderMessage-success"].replace("{{filesUpdateSummary}}",getFilesUpdateSummaryString(c))),u.succeed(),t&&(this.log(strings["pullCommand-dryRunResultHeader"]),this.log(JSON.stringify(c,null,2)))}catch(s){if(u&&u.fail(),s.name===ErrorNames.PERMISSION_DENIED_DEVELOPER_INTEGRATION_IS_TURNED_OFF)return void this.log(strings["pullCommand-error-developerIntegrationIsTurnedOff"]);if(s.name===ErrorNames.NO_CONFIGURED_SOURCES)return void this.log(strings["pullCommand-error-noConfiguredSources"]);if(s.name===ErrorNames.NO_CONFIGURED_OUTPUT_FILE)return void this.log(strings["pullCommand-error-noConfiguredOutputFile"]);if(s.name===ErrorNames.TAGS_NOT_EXIST_IN_WORKSPACE)return void this.log((0,string_1.replaceVariables)(strings["pullCommand-error-tagsNotExistInWorkspace"],{tagNames:s.message}));if(s.name===ErrorNames.PAGES_NOT_EXIST_IN_PROJECTS)return void this.log((0,string_1.replaceVariables)(strings["pullCommand-error-pagesNotExistInProjects"],{pageNames:s.message}));if(s.name===ErrorNames.FRAMES_NOT_EXIST_IN_PROJECTS)return void this.log((0,string_1.replaceVariables)(strings["pullCommand-error-framesNotExistInProjects"],{frameNames:s.message}));this.log(s.message);const{"access-token":r,...a}=e;logger.error(s,{message:"error in pull command",flagsWithoutAccessToken:a})}}}exports.PullCommand=PullCommand,PullCommand.description=strings["pullCommand-commandDescription"],PullCommand.flags={nested:core_1.Flags.boolean({description:strings["pullCommand-flagDescription-nested"],default:!1,required:!1}),status:core_1.Flags.string({description:strings["pullCommand-flagDescription-status"],options:["draft","review","final","all"],default:"all",required:!1}),"has-key":core_1.Flags.boolean({description:strings["pullCommand-flagDescription-hasKey"],default:!1,required:!1}),"access-token":core_1.Flags.string({description:strings["pullCommand-flagDescription-accessToken"],default:"",required:!1}),"dry-run":core_1.Flags.boolean({description:strings["pullCommand-flagDescription-dryRun"],default:!1,required:!1}),"include-translations":core_1.Flags.boolean({description:strings["pullCommand-flagDescription-includeTranslations"],default:!1,required:!1}),"include-metadata":core_1.Flags.boolean({description:strings["pullCommand-flagDescription-includeMetadata"],default:!1,required:!1}),tags:core_1.Flags.string({description:strings["pullCommand-flagDescription-tags"],default:void 0,required:!1}),pages:core_1.Flags.string({description:strings["pullCommand-flagDescription-pages"],default:void 0,required:!1}),frames:core_1.Flags.string({description:strings["pullCommand-flagDescription-frames"],default:void 0,required:!1,aliases:["screens"]})};