lingo.dev 0.78.17 → 0.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/cli.cjs CHANGED
@@ -620,9 +620,9 @@ function makeGitlabInitializer(spinner) {
620
620
 
621
621
  // src/cli/cmd/init.ts
622
622
 
623
- var openUrl = (path14) => {
623
+ var openUrl = (path15) => {
624
624
  const settings = getSettings(void 0);
625
- _open2.default.call(void 0, `${settings.auth.webUrl}${path14}`, { wait: false });
625
+ _open2.default.call(void 0, `${settings.auth.webUrl}${path15}`, { wait: false });
626
626
  };
627
627
  var throwHelpError = (option, value) => {
628
628
  if (value === "help") {
@@ -962,8 +962,8 @@ var files_default = new (0, _interactivecommander.Command)().command("files").de
962
962
  } else if (type.target) {
963
963
  result.push(...targetPaths);
964
964
  }
965
- result.forEach((path14) => {
966
- console.log(path14);
965
+ result.forEach((path15) => {
966
+ console.log(path15);
967
967
  });
968
968
  }
969
969
  }
@@ -1531,9 +1531,9 @@ function createHtmlLoader() {
1531
1531
  const bDepth = b.split("/").length;
1532
1532
  return aDepth - bDepth;
1533
1533
  });
1534
- paths.forEach((path14) => {
1535
- const value = data[path14];
1536
- const [nodePath, attribute] = path14.split("#");
1534
+ paths.forEach((path15) => {
1535
+ const value = data[path15];
1536
+ const [nodePath, attribute] = path15.split("#");
1537
1537
  const [rootTag, ...indices] = nodePath.split("/");
1538
1538
  let parent = rootTag === "head" ? document.head : document.body;
1539
1539
  let current = parent;
@@ -2597,18 +2597,18 @@ function createRawDatoValue(parsedDatoValue, originalRawDatoValue, isClean = fal
2597
2597
  }
2598
2598
  function serializeStructuredText(rawStructuredText) {
2599
2599
  return serializeStructuredTextNode(rawStructuredText);
2600
- function serializeStructuredTextNode(node, path14 = [], acc = {}) {
2600
+ function serializeStructuredTextNode(node, path15 = [], acc = {}) {
2601
2601
  if ("document" in node) {
2602
- return serializeStructuredTextNode(node.document, [...path14, "document"], acc);
2602
+ return serializeStructuredTextNode(node.document, [...path15, "document"], acc);
2603
2603
  }
2604
2604
  if (!_lodash2.default.isNil(node.value)) {
2605
- acc[[...path14, "value"].join(".")] = node.value;
2605
+ acc[[...path15, "value"].join(".")] = node.value;
2606
2606
  } else if (_lodash2.default.get(node, "type") === "block") {
2607
- acc[[...path14, "item"].join(".")] = serializeBlock(node.item);
2607
+ acc[[...path15, "item"].join(".")] = serializeBlock(node.item);
2608
2608
  }
2609
2609
  if (node.children) {
2610
2610
  for (let i = 0; i < node.children.length; i++) {
2611
- serializeStructuredTextNode(node.children[i], [...path14, i.toString()], acc);
2611
+ serializeStructuredTextNode(node.children[i], [...path15, i.toString()], acc);
2612
2612
  }
2613
2613
  }
2614
2614
  return acc;
@@ -2667,8 +2667,8 @@ function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = f
2667
2667
  }
2668
2668
  function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
2669
2669
  const result = _lodash2.default.cloneDeep(originalRawStructuredText);
2670
- for (const [path14, value] of _lodash2.default.entries(parsedStructuredText)) {
2671
- const realPath = _lodash2.default.chain(path14.split(".")).flatMap((s) => !_lodash2.default.isNaN(_lodash2.default.toNumber(s)) ? ["children", s] : s).value();
2670
+ for (const [path15, value] of _lodash2.default.entries(parsedStructuredText)) {
2671
+ const realPath = _lodash2.default.chain(path15.split(".")).flatMap((s) => !_lodash2.default.isNaN(_lodash2.default.toNumber(s)) ? ["children", s] : s).value();
2672
2672
  const deserializedValue = createRawDatoValue(value, _lodash2.default.get(originalRawStructuredText, realPath), true);
2673
2673
  _lodash2.default.set(result, realPath, deserializedValue);
2674
2674
  }
@@ -3953,10 +3953,637 @@ var mcp_default = new (0, _interactivecommander.Command)().command("mcp").descri
3953
3953
  console.log("Lingo.dev MCP Server running on stdio");
3954
3954
  });
3955
3955
 
3956
+ // src/cli/cmd/ci.ts
3957
+
3958
+
3959
+ // ../../action/src/main.ts
3960
+
3961
+
3962
+ // ../../action/src/flows/pull-request.ts
3963
+
3964
+
3965
+ // ../../action/src/flows/in-branch.ts
3966
+
3967
+
3968
+
3969
+ // ../../action/src/flows/_base.ts
3970
+ var IntegrationFlow = class {
3971
+ constructor(ora, platformKit) {
3972
+ this.ora = ora;
3973
+ this.platformKit = platformKit;
3974
+ }
3975
+
3976
+ };
3977
+ var gitConfig = {
3978
+ userName: "Lingo.dev",
3979
+ userEmail: "support@lingo.dev"
3980
+ };
3981
+
3982
+ // ../../action/src/flows/in-branch.ts
3983
+ var InBranchFlow = class extends IntegrationFlow {
3984
+ async preRun() {
3985
+ this.ora.start("Configuring git");
3986
+ const canContinue = this.configureGit();
3987
+ this.ora.succeed("Git configured");
3988
+ return canContinue;
3989
+ }
3990
+ async run(forcePush = false) {
3991
+ this.ora.start("Running Lingo.dev");
3992
+ await this.runLingoDotDev();
3993
+ this.ora.succeed("Done running Lingo.dev");
3994
+ _child_process.execSync.call(void 0, `rm -f i18n.cache`, { stdio: "inherit" });
3995
+ this.ora.start("Checking for changes");
3996
+ const hasChanges = this.checkCommitableChanges();
3997
+ this.ora.succeed(hasChanges ? "Changes detected" : "No changes detected");
3998
+ if (hasChanges) {
3999
+ this.ora.start("Committing changes");
4000
+ _child_process.execSync.call(void 0, `git add .`, { stdio: "inherit" });
4001
+ _child_process.execSync.call(void 0, `git status --porcelain`, { stdio: "inherit" });
4002
+ _child_process.execSync.call(void 0, `git commit -m "${this.platformKit.config.commitMessage}"`, {
4003
+ stdio: "inherit"
4004
+ });
4005
+ this.ora.succeed("Changes committed");
4006
+ this.ora.start("Pushing changes to remote");
4007
+ const currentBranch = _nullishCoalesce(this.i18nBranchName, () => ( this.platformKit.platformConfig.baseBranchName));
4008
+ _child_process.execSync.call(void 0, `git push origin ${currentBranch} ${forcePush ? "--force" : ""}`, {
4009
+ stdio: "inherit"
4010
+ });
4011
+ this.ora.succeed("Changes pushed to remote");
4012
+ }
4013
+ return hasChanges;
4014
+ }
4015
+ checkCommitableChanges() {
4016
+ return _child_process.execSync.call(void 0, 'git status --porcelain || echo "has_changes"', {
4017
+ encoding: "utf8"
4018
+ }).length > 0;
4019
+ }
4020
+ async runLingoDotDev() {
4021
+ _child_process.execSync.call(void 0, `npx lingo.dev@latest i18n --api-key ${this.platformKit.config.replexicaApiKey}`, { stdio: "inherit" });
4022
+ }
4023
+ configureGit() {
4024
+ const { processOwnCommits } = this.platformKit.config;
4025
+ const { baseBranchName } = this.platformKit.platformConfig;
4026
+ this.ora.info(`Current working directory:`);
4027
+ _child_process.execSync.call(void 0, `pwd`, { stdio: "inherit" });
4028
+ _child_process.execSync.call(void 0, `ls -la`, { stdio: "inherit" });
4029
+ _child_process.execSync.call(void 0, `git config --global safe.directory ${process.cwd()}`);
4030
+ _child_process.execSync.call(void 0, `git config user.name "${gitConfig.userName}"`);
4031
+ _child_process.execSync.call(void 0, `git config user.email "${gitConfig.userEmail}"`);
4032
+ _optionalChain([this, 'access', _146 => _146.platformKit, 'optionalAccess', _147 => _147.gitConfig, 'call', _148 => _148()]);
4033
+ _child_process.execSync.call(void 0, `git fetch origin ${baseBranchName}`, { stdio: "inherit" });
4034
+ _child_process.execSync.call(void 0, `git checkout ${baseBranchName} --`, { stdio: "inherit" });
4035
+ if (!processOwnCommits) {
4036
+ const currentAuthor = `${gitConfig.userName} <${gitConfig.userEmail}>`;
4037
+ const authorOfLastCommit = _child_process.execSync.call(void 0, `git log -1 --pretty=format:'%an <%ae>'`).toString();
4038
+ if (authorOfLastCommit === currentAuthor) {
4039
+ this.ora.warn(
4040
+ `The last commit was already made by ${currentAuthor}, so this run will be skipped, as running again would have no effect. See docs: https://docs.lingo.dev/ci-action/overview`
4041
+ );
4042
+ return false;
4043
+ }
4044
+ }
4045
+ const workingDir = _path2.default.resolve(process.cwd(), this.platformKit.config.workingDir);
4046
+ if (workingDir !== process.cwd()) {
4047
+ this.ora.info(`Changing to working directory: ${this.platformKit.config.workingDir}`);
4048
+ process.chdir(workingDir);
4049
+ }
4050
+ return true;
4051
+ }
4052
+ };
4053
+
4054
+ // ../../action/src/flows/pull-request.ts
4055
+ var PullRequestFlow = class extends InBranchFlow {
4056
+ async preRun() {
4057
+ const canContinue = await _optionalChain([super.preRun.bind(this), 'optionalCall', _149 => _149()]);
4058
+ if (!canContinue) {
4059
+ return false;
4060
+ }
4061
+ this.ora.start("Calculating automated branch name");
4062
+ this.i18nBranchName = this.calculatePrBranchName();
4063
+ this.ora.succeed(`Automated branch name calculated: ${this.i18nBranchName}`);
4064
+ this.ora.start("Checking if branch exists");
4065
+ const branchExists = await this.checkBranchExistance(this.i18nBranchName);
4066
+ this.ora.succeed(branchExists ? "Branch exists" : "Branch does not exist");
4067
+ if (branchExists) {
4068
+ this.ora.start(`Checking out branch ${this.i18nBranchName}`);
4069
+ this.checkoutI18nBranch(this.i18nBranchName);
4070
+ this.ora.succeed(`Checked out branch ${this.i18nBranchName}`);
4071
+ this.ora.start(`Syncing with ${this.platformKit.platformConfig.baseBranchName}`);
4072
+ this.syncI18nBranch();
4073
+ this.ora.succeed(`Checked out and synced branch ${this.i18nBranchName}`);
4074
+ } else {
4075
+ this.ora.start(`Creating branch ${this.i18nBranchName}`);
4076
+ this.createI18nBranch(this.i18nBranchName);
4077
+ this.ora.succeed(`Created branch ${this.i18nBranchName}`);
4078
+ }
4079
+ return true;
4080
+ }
4081
+ async run() {
4082
+ return super.run(true);
4083
+ }
4084
+ async postRun() {
4085
+ if (!this.i18nBranchName) {
4086
+ throw new Error("i18nBranchName is not set. Did you forget to call preRun?");
4087
+ }
4088
+ this.ora.start("Checking if PR already exists");
4089
+ const pullRequestNumber = await this.ensureFreshPr(this.i18nBranchName);
4090
+ this.ora.succeed(`Pull request ready: ${this.platformKit.buildPullRequestUrl(pullRequestNumber)}`);
4091
+ }
4092
+ calculatePrBranchName() {
4093
+ return `lingo.dev/${this.platformKit.platformConfig.baseBranchName}`;
4094
+ }
4095
+ async checkBranchExistance(prBranchName) {
4096
+ return this.platformKit.branchExists({
4097
+ branch: prBranchName
4098
+ });
4099
+ }
4100
+ async ensureFreshPr(i18nBranchName) {
4101
+ this.ora.start(
4102
+ `Checking for existing PR with head ${i18nBranchName} and base ${this.platformKit.platformConfig.baseBranchName}`
4103
+ );
4104
+ const existingPrNumber = await this.platformKit.getOpenPullRequestNumber({
4105
+ branch: i18nBranchName
4106
+ });
4107
+ this.ora.succeed(existingPrNumber ? "PR found" : "No PR found");
4108
+ if (existingPrNumber) {
4109
+ this.ora.start(`Closing existing PR ${existingPrNumber}`);
4110
+ await this.platformKit.closePullRequest({
4111
+ pullRequestNumber: existingPrNumber
4112
+ });
4113
+ this.ora.succeed(`Closed existing PR ${existingPrNumber}`);
4114
+ }
4115
+ this.ora.start(`Creating new PR`);
4116
+ const newPrNumber = await this.platformKit.createPullRequest({
4117
+ head: i18nBranchName,
4118
+ title: this.platformKit.config.pullRequestTitle,
4119
+ body: this.getPrBodyContent()
4120
+ });
4121
+ this.ora.succeed(`Created new PR ${newPrNumber}`);
4122
+ if (existingPrNumber) {
4123
+ this.ora.start(`Posting comment about outdated PR ${existingPrNumber}`);
4124
+ await this.platformKit.commentOnPullRequest({
4125
+ pullRequestNumber: existingPrNumber,
4126
+ body: `This PR is now outdated. A new version has been created at ${this.platformKit.buildPullRequestUrl(
4127
+ newPrNumber
4128
+ )}`
4129
+ });
4130
+ this.ora.succeed(`Posted comment about outdated PR ${existingPrNumber}`);
4131
+ }
4132
+ return newPrNumber;
4133
+ }
4134
+ checkoutI18nBranch(i18nBranchName) {
4135
+ _child_process.execSync.call(void 0, `git fetch origin ${i18nBranchName}`, { stdio: "inherit" });
4136
+ _child_process.execSync.call(void 0, `git checkout -b ${i18nBranchName}`, {
4137
+ stdio: "inherit"
4138
+ });
4139
+ }
4140
+ createI18nBranch(i18nBranchName) {
4141
+ try {
4142
+ _child_process.execSync.call(void 0, `git fetch origin ${this.platformKit.platformConfig.baseBranchName}`, { stdio: "inherit" });
4143
+ _child_process.execSync.call(void 0, `git checkout -b ${i18nBranchName} origin/${this.platformKit.platformConfig.baseBranchName}`, {
4144
+ stdio: "inherit"
4145
+ });
4146
+ } catch (error) {
4147
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
4148
+ this.ora.fail(`Failed to create branch: ${errorMessage}`);
4149
+ this.ora.info(`
4150
+ Troubleshooting tips:
4151
+ 1. Make sure you have permission to create branches
4152
+ 2. Check if the branch already exists locally (try 'git branch -a')
4153
+ 3. Verify connectivity to remote repository
4154
+ `);
4155
+ throw new Error(`Branch creation failed: ${errorMessage}`);
4156
+ }
4157
+ }
4158
+ syncI18nBranch() {
4159
+ if (!this.i18nBranchName) {
4160
+ throw new Error("i18nBranchName is not set");
4161
+ }
4162
+ this.ora.start(`Fetching latest changes from ${this.platformKit.platformConfig.baseBranchName}`);
4163
+ _child_process.execSync.call(void 0, `git fetch origin ${this.platformKit.platformConfig.baseBranchName}`, { stdio: "inherit" });
4164
+ this.ora.succeed(`Fetched latest changes from ${this.platformKit.platformConfig.baseBranchName}`);
4165
+ try {
4166
+ this.ora.start("Attempting to rebase branch");
4167
+ _child_process.execSync.call(void 0, `git rebase origin/${this.platformKit.platformConfig.baseBranchName}`, { stdio: "inherit" });
4168
+ this.ora.succeed("Successfully rebased branch");
4169
+ } catch (error) {
4170
+ this.ora.warn("Rebase failed, falling back to alternative sync method");
4171
+ this.ora.start("Aborting failed rebase");
4172
+ _child_process.execSync.call(void 0, "git rebase --abort", { stdio: "inherit" });
4173
+ this.ora.succeed("Aborted failed rebase");
4174
+ this.ora.start(`Resetting to ${this.platformKit.platformConfig.baseBranchName}`);
4175
+ _child_process.execSync.call(void 0, `git reset --hard origin/${this.platformKit.platformConfig.baseBranchName}`, { stdio: "inherit" });
4176
+ this.ora.succeed(`Reset to ${this.platformKit.platformConfig.baseBranchName}`);
4177
+ this.ora.start("Restoring target files");
4178
+ const targetFiles = ["i18n.lock"];
4179
+ const targetFileNames = _child_process.execSync.call(void 0,
4180
+ `npx lingo.dev@latest show files --target ${this.platformKit.platformConfig.baseBranchName}`,
4181
+ { encoding: "utf8" }
4182
+ ).split("\n").filter(Boolean);
4183
+ targetFiles.push(...targetFileNames);
4184
+ _child_process.execSync.call(void 0, `git fetch origin ${this.i18nBranchName}`, { stdio: "inherit" });
4185
+ for (const file of targetFiles) {
4186
+ try {
4187
+ _child_process.execSync.call(void 0, `git checkout FETCH_HEAD -- ${file}`, { stdio: "inherit" });
4188
+ } catch (error2) {
4189
+ this.ora.warn(`Skipping non-existent file: ${file}`);
4190
+ continue;
4191
+ }
4192
+ }
4193
+ this.ora.succeed("Restored target files");
4194
+ }
4195
+ this.ora.start("Checking for changes to commit");
4196
+ const hasChanges = this.checkCommitableChanges();
4197
+ if (hasChanges) {
4198
+ _child_process.execSync.call(void 0, "git add .", { stdio: "inherit" });
4199
+ _child_process.execSync.call(void 0, `git commit -m "chore: sync with ${this.platformKit.platformConfig.baseBranchName}"`, {
4200
+ stdio: "inherit"
4201
+ });
4202
+ this.ora.succeed("Committed additional changes");
4203
+ } else {
4204
+ this.ora.succeed("No changes to commit");
4205
+ }
4206
+ }
4207
+ getPrBodyContent() {
4208
+ return `
4209
+ Hey team,
4210
+
4211
+ [**Lingo.dev**](https://lingo.dev) here with fresh translations!
4212
+
4213
+ ### In this update
4214
+
4215
+ - Added missing translations
4216
+ - Performed brand voice, context and glossary checks
4217
+ - Enhanced translations using Lingo.dev Localization Engine
4218
+
4219
+ ### Next Steps
4220
+
4221
+ - [ ] Review the changes
4222
+ - [ ] Merge when ready
4223
+ `.trim();
4224
+ }
4225
+ };
4226
+
4227
+ // ../../action/src/platforms/bitbucket.ts
4228
+
4229
+ var _bitbucket = require('bitbucket'); var _bitbucket2 = _interopRequireDefault(_bitbucket);
4230
+
4231
+
4232
+ // ../../action/src/platforms/_base.ts
4233
+
4234
+ var defaultMessage = "feat: update translations via @lingodotdev";
4235
+ var PlatformKit = class {
4236
+ gitConfig() {
4237
+ }
4238
+ get config() {
4239
+ const env = _zod2.default.object({
4240
+ LINGODOTDEV_API_KEY: _zod2.default.string(),
4241
+ LINGODOTDEV_PULL_REQUEST: _zod2.default.preprocess((val) => val === "true" || val === true, _zod2.default.boolean()),
4242
+ LINGODOTDEV_COMMIT_MESSAGE: _zod2.default.string().optional(),
4243
+ LINGODOTDEV_PULL_REQUEST_TITLE: _zod2.default.string().optional(),
4244
+ LINGODOTDEV_WORKING_DIRECTORY: _zod2.default.string().optional(),
4245
+ LINGODOTDEV_PROCESS_OWN_COMMITS: _zod2.default.preprocess((val) => val === "true" || val === true, _zod2.default.boolean()).optional()
4246
+ }).parse(process.env);
4247
+ return {
4248
+ replexicaApiKey: env.LINGODOTDEV_API_KEY,
4249
+ isPullRequestMode: env.LINGODOTDEV_PULL_REQUEST,
4250
+ commitMessage: env.LINGODOTDEV_COMMIT_MESSAGE || defaultMessage,
4251
+ pullRequestTitle: env.LINGODOTDEV_PULL_REQUEST_TITLE || defaultMessage,
4252
+ workingDir: env.LINGODOTDEV_WORKING_DIRECTORY || ".",
4253
+ processOwnCommits: env.LINGODOTDEV_PROCESS_OWN_COMMITS || false
4254
+ };
4255
+ }
4256
+ };
4257
+
4258
+ // ../../action/src/platforms/bitbucket.ts
4259
+ var { Bitbucket } = _bitbucket2.default;
4260
+ var BitbucketPlatformKit = class extends PlatformKit {
4261
+
4262
+ get bb() {
4263
+ if (!this._bb) {
4264
+ this._bb = new Bitbucket({
4265
+ auth: { token: this.platformConfig.bbToken || "" }
4266
+ });
4267
+ }
4268
+ return this._bb;
4269
+ }
4270
+ async branchExists({ branch }) {
4271
+ return await this.bb.repositories.getBranch({
4272
+ workspace: this.platformConfig.repositoryOwner,
4273
+ repo_slug: this.platformConfig.repositoryName,
4274
+ name: branch
4275
+ }).then((r) => r.data).then((v) => !!v).catch((r) => r.status === 404 ? false : Promise.reject(r));
4276
+ }
4277
+ async getOpenPullRequestNumber({ branch }) {
4278
+ return await this.bb.repositories.listPullRequests({
4279
+ workspace: this.platformConfig.repositoryOwner,
4280
+ repo_slug: this.platformConfig.repositoryName,
4281
+ state: "OPEN"
4282
+ }).then(({ data: { values } }) => {
4283
+ return _optionalChain([values, 'optionalAccess', _150 => _150.find, 'call', _151 => _151(
4284
+ ({ source, destination }) => _optionalChain([source, 'optionalAccess', _152 => _152.branch, 'optionalAccess', _153 => _153.name]) === branch && _optionalChain([destination, 'optionalAccess', _154 => _154.branch, 'optionalAccess', _155 => _155.name]) === this.platformConfig.baseBranchName
4285
+ )]);
4286
+ }).then((pr) => _optionalChain([pr, 'optionalAccess', _156 => _156.id]));
4287
+ }
4288
+ async closePullRequest({ pullRequestNumber }) {
4289
+ await this.bb.repositories.declinePullRequest({
4290
+ workspace: this.platformConfig.repositoryOwner,
4291
+ repo_slug: this.platformConfig.repositoryName,
4292
+ pull_request_id: pullRequestNumber
4293
+ });
4294
+ }
4295
+ async createPullRequest({ title, body, head }) {
4296
+ return await this.bb.repositories.createPullRequest({
4297
+ workspace: this.platformConfig.repositoryOwner,
4298
+ repo_slug: this.platformConfig.repositoryName,
4299
+ _body: {
4300
+ title,
4301
+ description: body,
4302
+ source: { branch: { name: head } },
4303
+ destination: { branch: { name: this.platformConfig.baseBranchName } }
4304
+ }
4305
+ }).then(({ data }) => _nullishCoalesce(data.id, () => ( 0)));
4306
+ }
4307
+ async commentOnPullRequest({ pullRequestNumber, body }) {
4308
+ await this.bb.repositories.createPullRequestComment({
4309
+ workspace: this.platformConfig.repositoryOwner,
4310
+ repo_slug: this.platformConfig.repositoryName,
4311
+ pull_request_id: pullRequestNumber,
4312
+ _body: {
4313
+ content: {
4314
+ raw: body
4315
+ }
4316
+ }
4317
+ });
4318
+ }
4319
+ async gitConfig() {
4320
+ _child_process.execSync.call(void 0, "git config --unset http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy", {
4321
+ stdio: "inherit"
4322
+ });
4323
+ _child_process.execSync.call(void 0, "git config http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy http://host.docker.internal:29418/", {
4324
+ stdio: "inherit"
4325
+ });
4326
+ }
4327
+ get platformConfig() {
4328
+ const env = _zod2.default.object({
4329
+ BITBUCKET_BRANCH: _zod2.default.string(),
4330
+ BITBUCKET_REPO_FULL_NAME: _zod2.default.string(),
4331
+ BB_TOKEN: _zod2.default.string().optional()
4332
+ }).parse(process.env);
4333
+ const [repositoryOwner, repositoryName] = env.BITBUCKET_REPO_FULL_NAME.split("/");
4334
+ return {
4335
+ baseBranchName: env.BITBUCKET_BRANCH,
4336
+ repositoryOwner,
4337
+ repositoryName,
4338
+ bbToken: env.BB_TOKEN
4339
+ };
4340
+ }
4341
+ buildPullRequestUrl(pullRequestNumber) {
4342
+ const { repositoryOwner, repositoryName } = this.platformConfig;
4343
+ return `https://bitbucket.org/${repositoryOwner}/${repositoryName}/pull-requests/${pullRequestNumber}`;
4344
+ }
4345
+ };
4346
+
4347
+ // ../../action/src/platforms/github.ts
4348
+ var _octokit2 = require('octokit');
4349
+
4350
+
4351
+ var GitHubPlatformKit = class extends PlatformKit {
4352
+
4353
+ get octokit() {
4354
+ if (!this._octokit) {
4355
+ this._octokit = new (0, _octokit2.Octokit)({ auth: this.platformConfig.ghToken });
4356
+ }
4357
+ return this._octokit;
4358
+ }
4359
+ async branchExists({ branch }) {
4360
+ return await this.octokit.rest.repos.getBranch({
4361
+ branch,
4362
+ owner: this.platformConfig.repositoryOwner,
4363
+ repo: this.platformConfig.repositoryName
4364
+ }).then((r) => r.data).then((v) => !!v).catch((r) => r.status === 404 ? false : Promise.reject(r));
4365
+ }
4366
+ async getOpenPullRequestNumber({ branch }) {
4367
+ return await this.octokit.rest.pulls.list({
4368
+ head: `${this.platformConfig.repositoryOwner}:${branch}`,
4369
+ owner: this.platformConfig.repositoryOwner,
4370
+ repo: this.platformConfig.repositoryName,
4371
+ base: this.platformConfig.baseBranchName,
4372
+ state: "open"
4373
+ }).then(({ data }) => data[0]).then((pr) => _optionalChain([pr, 'optionalAccess', _157 => _157.number]));
4374
+ }
4375
+ async closePullRequest({ pullRequestNumber }) {
4376
+ await this.octokit.rest.pulls.update({
4377
+ pull_number: pullRequestNumber,
4378
+ owner: this.platformConfig.repositoryOwner,
4379
+ repo: this.platformConfig.repositoryName,
4380
+ state: "closed"
4381
+ });
4382
+ }
4383
+ async createPullRequest({ head, title, body }) {
4384
+ return await this.octokit.rest.pulls.create({
4385
+ head,
4386
+ title,
4387
+ body,
4388
+ owner: this.platformConfig.repositoryOwner,
4389
+ repo: this.platformConfig.repositoryName,
4390
+ base: this.platformConfig.baseBranchName
4391
+ }).then(({ data }) => data.number);
4392
+ }
4393
+ async commentOnPullRequest({ pullRequestNumber, body }) {
4394
+ await this.octokit.rest.issues.createComment({
4395
+ issue_number: pullRequestNumber,
4396
+ body,
4397
+ owner: this.platformConfig.repositoryOwner,
4398
+ repo: this.platformConfig.repositoryName
4399
+ });
4400
+ }
4401
+ async gitConfig() {
4402
+ const { ghToken, repositoryOwner, repositoryName } = this.platformConfig;
4403
+ const { processOwnCommits } = this.config;
4404
+ if (ghToken && processOwnCommits) {
4405
+ console.log("Using provided GH_TOKEN. This will trigger your CI/CD pipeline to run again.");
4406
+ const url = `https://${ghToken}@github.com/${repositoryOwner}/${repositoryName}.git`;
4407
+ _child_process.execSync.call(void 0, `git remote set-url origin ${url}`, {
4408
+ stdio: "inherit"
4409
+ });
4410
+ }
4411
+ }
4412
+ get platformConfig() {
4413
+ const env = _zod2.default.object({
4414
+ GITHUB_REPOSITORY: _zod2.default.string(),
4415
+ GITHUB_REPOSITORY_OWNER: _zod2.default.string(),
4416
+ GITHUB_REF_NAME: _zod2.default.string(),
4417
+ GITHUB_HEAD_REF: _zod2.default.string(),
4418
+ GH_TOKEN: _zod2.default.string().optional()
4419
+ }).parse(process.env);
4420
+ const baseBranchName = !env.GITHUB_REF_NAME.endsWith("/merge") ? env.GITHUB_REF_NAME : env.GITHUB_HEAD_REF;
4421
+ return {
4422
+ ghToken: env.GH_TOKEN,
4423
+ baseBranchName,
4424
+ repositoryOwner: env.GITHUB_REPOSITORY_OWNER,
4425
+ repositoryName: env.GITHUB_REPOSITORY.split("/")[1]
4426
+ };
4427
+ }
4428
+ buildPullRequestUrl(pullRequestNumber) {
4429
+ const { repositoryOwner, repositoryName } = this.platformConfig;
4430
+ return `https://github.com/${repositoryOwner}/${repositoryName}/pull/${pullRequestNumber}`;
4431
+ }
4432
+ };
4433
+
4434
+ // ../../action/src/platforms/gitlab.ts
4435
+ var _rest = require('@gitbeaker/rest');
4436
+
4437
+
4438
+ var gl = new (0, _rest.Gitlab)({ token: "" });
4439
+ var GitlabPlatformKit = class extends PlatformKit {
4440
+
4441
+ constructor() {
4442
+ super();
4443
+ process.chdir(this.platformConfig.projectDir);
4444
+ }
4445
+ get gitlab() {
4446
+ if (!this._gitlab) {
4447
+ this._gitlab = new (0, _rest.Gitlab)({
4448
+ token: this.platformConfig.glToken || ""
4449
+ });
4450
+ }
4451
+ return this._gitlab;
4452
+ }
4453
+ get platformConfig() {
4454
+ const env = _zod2.default.object({
4455
+ GL_TOKEN: _zod2.default.string().optional(),
4456
+ CI_COMMIT_BRANCH: _zod2.default.string(),
4457
+ CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: _zod2.default.string().optional(),
4458
+ CI_PROJECT_NAMESPACE: _zod2.default.string(),
4459
+ CI_PROJECT_NAME: _zod2.default.string(),
4460
+ CI_PROJECT_ID: _zod2.default.string(),
4461
+ CI_PROJECT_DIR: _zod2.default.string(),
4462
+ CI_REPOSITORY_URL: _zod2.default.string()
4463
+ }).parse(process.env);
4464
+ const config = {
4465
+ glToken: env.GL_TOKEN,
4466
+ baseBranchName: _nullishCoalesce(env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME, () => ( env.CI_COMMIT_BRANCH)),
4467
+ repositoryOwner: env.CI_PROJECT_NAMESPACE,
4468
+ repositoryName: env.CI_PROJECT_NAME,
4469
+ gitlabProjectId: env.CI_PROJECT_ID,
4470
+ projectDir: env.CI_PROJECT_DIR,
4471
+ reporitoryUrl: env.CI_REPOSITORY_URL
4472
+ };
4473
+ return config;
4474
+ }
4475
+ async branchExists({ branch }) {
4476
+ try {
4477
+ await this.gitlab.Branches.show(this.platformConfig.gitlabProjectId, branch);
4478
+ return true;
4479
+ } catch (e2) {
4480
+ return false;
4481
+ }
4482
+ }
4483
+ async getOpenPullRequestNumber({ branch }) {
4484
+ const mergeRequests = await this.gitlab.MergeRequests.all({
4485
+ projectId: this.platformConfig.gitlabProjectId,
4486
+ sourceBranch: branch,
4487
+ state: "opened"
4488
+ });
4489
+ return _optionalChain([mergeRequests, 'access', _158 => _158[0], 'optionalAccess', _159 => _159.iid]);
4490
+ }
4491
+ async closePullRequest({ pullRequestNumber }) {
4492
+ await this.gitlab.MergeRequests.edit(this.platformConfig.gitlabProjectId, pullRequestNumber, {
4493
+ stateEvent: "close"
4494
+ });
4495
+ }
4496
+ async createPullRequest({ head, title, body }) {
4497
+ const mr = await this.gitlab.MergeRequests.create(
4498
+ this.platformConfig.gitlabProjectId,
4499
+ head,
4500
+ this.platformConfig.baseBranchName,
4501
+ title,
4502
+ {
4503
+ description: body
4504
+ }
4505
+ );
4506
+ return mr.iid;
4507
+ }
4508
+ async commentOnPullRequest({ pullRequestNumber, body }) {
4509
+ await this.gitlab.MergeRequestNotes.create(this.platformConfig.gitlabProjectId, pullRequestNumber, body);
4510
+ }
4511
+ gitConfig() {
4512
+ const url = `https://oauth2:${this.platformConfig.glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`;
4513
+ _child_process.execSync.call(void 0, `git remote set-url origin ${url}`, {
4514
+ stdio: "inherit"
4515
+ });
4516
+ }
4517
+ buildPullRequestUrl(pullRequestNumber) {
4518
+ return `https://gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}/-/merge_requests/${pullRequestNumber}`;
4519
+ }
4520
+ };
4521
+
4522
+ // ../../action/src/platforms/index.ts
4523
+ var getPlatformKit = () => {
4524
+ if (process.env.BITBUCKET_PIPELINE_UUID) {
4525
+ return new BitbucketPlatformKit();
4526
+ }
4527
+ if (process.env.GITHUB_ACTION) {
4528
+ return new GitHubPlatformKit();
4529
+ }
4530
+ if (process.env.GITLAB_CI) {
4531
+ return new GitlabPlatformKit();
4532
+ }
4533
+ throw new Error("This platform is not supported");
4534
+ };
4535
+
4536
+ // ../../action/src/main.ts
4537
+ async function main() {
4538
+ const ora = _ora2.default.call(void 0, );
4539
+ const platformKit = getPlatformKit();
4540
+ const { isPullRequestMode } = platformKit.config;
4541
+ ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
4542
+ const flow = isPullRequestMode ? new PullRequestFlow(ora, platformKit) : new InBranchFlow(ora, platformKit);
4543
+ const canRun = await _optionalChain([flow, 'access', _160 => _160.preRun, 'optionalCall', _161 => _161()]);
4544
+ if (canRun === false) {
4545
+ return;
4546
+ }
4547
+ const hasChanges = await flow.run();
4548
+ if (!hasChanges) {
4549
+ return;
4550
+ }
4551
+ await _optionalChain([flow, 'access', _162 => _162.postRun, 'optionalCall', _163 => _163()]);
4552
+ }
4553
+
4554
+ // src/cli/cmd/ci.ts
4555
+ var ci_default = new (0, _interactivecommander.Command)().command("ci").description("Run Lingo.dev CI/CD action").helpOption("-h, --help", "Show help").option("--pull-request", "Create a pull request with the changes", false).option("--commit-message <message>", "Commit message").option("--pull-request-title <title>", "Pull request title").option("--working-directory <dir>", "Working directory").option("--process-own-commits", "Process commits made by this action", false).action(async (options, program) => {
4556
+ const apiKey = program.args[0];
4557
+ const settings = getSettings(apiKey);
4558
+ if (!settings.auth.apiKey) {
4559
+ console.error("No API key provided");
4560
+ return;
4561
+ }
4562
+ const authenticator = createAuthenticator({
4563
+ apiUrl: settings.auth.apiUrl,
4564
+ apiKey: settings.auth.apiKey
4565
+ });
4566
+ const auth = await authenticator.whoami();
4567
+ if (!auth) {
4568
+ console.error("Not authenticated");
4569
+ return;
4570
+ }
4571
+ const env = {
4572
+ LINGODOTDEV_API_KEY: settings.auth.apiKey,
4573
+ LINGODOTDEV_PULL_REQUEST: _optionalChain([options, 'access', _164 => _164.pullRequest, 'optionalAccess', _165 => _165.toString, 'call', _166 => _166()]) || "false",
4574
+ ...options.commitMessage && { LINGODOTDEV_COMMIT_MESSAGE: options.commitMessage },
4575
+ ...options.pullRequestTitle && { LINGODOTDEV_PULL_REQUEST_TITLE: options.pullRequestTitle },
4576
+ ...options.workingDirectory && { LINGODOTDEV_WORKING_DIRECTORY: options.workingDirectory },
4577
+ ...options.processOwnCommits && { LINGODOTDEV_PROCESS_OWN_COMMITS: options.processOwnCommits.toString() }
4578
+ };
4579
+ process.env = { ...process.env, ...env };
4580
+ main();
4581
+ });
4582
+
3956
4583
  // package.json
3957
4584
  var package_default = {
3958
4585
  name: "lingo.dev",
3959
- version: "0.78.17",
4586
+ version: "0.79.0",
3960
4587
  description: "Lingo.dev CLI",
3961
4588
  private: false,
3962
4589
  publishConfig: {
@@ -4014,11 +4641,13 @@ var package_default = {
4014
4641
  license: "Apache-2.0",
4015
4642
  dependencies: {
4016
4643
  "@datocms/cma-client-node": "^3.4.0",
4644
+ "@gitbeaker/rest": "^39.34.3",
4017
4645
  "@inquirer/prompts": "^7.2.3",
4018
4646
  "@lingo.dev/_sdk": "workspace:*",
4019
4647
  "@lingo.dev/_spec": "workspace:*",
4020
4648
  "@modelcontextprotocol/sdk": "^1.5.0",
4021
4649
  "@paralleldrive/cuid2": "^2.2.2",
4650
+ bitbucket: "^2.12.0",
4022
4651
  chalk: "^5.4.1",
4023
4652
  cors: "^2.8.5",
4024
4653
  "csv-parse": "^5.6.0",
@@ -4048,6 +4677,7 @@ var package_default = {
4048
4677
  marked: "^15.0.6",
4049
4678
  "node-webvtt": "^1.9.4",
4050
4679
  "object-hash": "^3.0.0",
4680
+ octokit: "^4.0.2",
4051
4681
  open: "^10.1.0",
4052
4682
  ora: "^8.1.1",
4053
4683
  "p-limit": "^6.2.0",
@@ -4107,7 +4737,7 @@ ${_gradientstring.vice.call(void 0,
4107
4737
 
4108
4738
  Website: https://lingo.dev
4109
4739
  `
4110
- ).version(`v${package_default.version}`, "-v, --version", "Show version").addCommand(init_default).interactive("-y, --no-interactive", "Disable interactive mode").addCommand(i18n_default).addCommand(auth_default).addCommand(show_default).addCommand(lockfile_default).addCommand(cleanup_default).addCommand(mcp_default).exitOverride((err) => {
4740
+ ).version(`v${package_default.version}`, "-v, --version", "Show version").addCommand(init_default).interactive("-y, --no-interactive", "Disable interactive mode").addCommand(i18n_default).addCommand(auth_default).addCommand(show_default).addCommand(lockfile_default).addCommand(cleanup_default).addCommand(mcp_default).addCommand(ci_default).exitOverride((err) => {
4111
4741
  if (err.code === "commander.helpDisplayed" || err.code === "commander.version" || err.code === "commander.help") {
4112
4742
  process.exit(0);
4113
4743
  }