Skip to content

Commit 73a8c73

Browse files
authored
feat: vNext migration (#2035)
* feat: vNext migration
1 parent c7110ca commit 73a8c73

File tree

23 files changed

+251
-300
lines changed

23 files changed

+251
-300
lines changed

.changeset/thirty-pots-judge.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@lingo.dev/compiler": minor
3+
"@lingo.dev/_compiler": minor
4+
"@lingo.dev/_spec": minor
5+
"lingo.dev": minor
6+
"@lingo.dev/_sdk": minor
7+
---
8+
9+
Migrate SDK and CLI to unified API endpoints. All requests now use `api.lingo.dev` with `X-API-Key` auth. Added `engineId` config option (auto-migrated from `vNext`)

packages/cli/src/cli/cmd/ci/index.ts

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from "path";
21
import { Command } from "interactive-commander";
32
import createOra from "ora";
43
import { getSettings } from "../../utils/settings";
@@ -7,7 +6,6 @@ import { IIntegrationFlow } from "./flows/_base";
76
import { PullRequestFlow } from "./flows/pull-request";
87
import { InBranchFlow } from "./flows/in-branch";
98
import { getPlatformKit } from "./platforms";
10-
import { getConfig } from "../../utils/config";
119

1210
interface CIOptions {
1311
parallel?: boolean;
@@ -72,53 +70,29 @@ export default new Command()
7270
parseBooleanArg,
7371
)
7472
.action(async (options: CIOptions) => {
75-
const configDir = options.workingDirectory
76-
? path.resolve(process.cwd(), options.workingDirectory)
77-
: process.cwd();
78-
const originalCwd = process.cwd();
79-
let config;
80-
try {
81-
process.chdir(configDir);
82-
config = getConfig(false);
83-
} finally {
84-
process.chdir(originalCwd);
85-
}
86-
87-
const isVNext = !!config?.vNext;
88-
8973
const settings = getSettings(options.apiKey);
9074

91-
if (isVNext) {
92-
if (!settings.auth.vnext?.apiKey) {
93-
console.error(
94-
"No LINGO_API_KEY provided. vNext requires LINGO_API_KEY environment variable.",
95-
);
96-
return;
97-
}
98-
} else {
99-
if (!settings.auth.apiKey) {
100-
console.error("No API key provided");
101-
return;
102-
}
75+
if (!settings.auth.apiKey) {
76+
console.error(
77+
"No API key provided. Set LINGO_API_KEY environment variable or use --api-key flag.",
78+
);
79+
return;
80+
}
10381

104-
const authenticator = createAuthenticator({
105-
apiUrl: settings.auth.apiUrl,
106-
apiKey: settings.auth.apiKey,
107-
});
82+
const authenticator = createAuthenticator({
83+
apiUrl: settings.auth.apiUrl,
84+
apiKey: settings.auth.apiKey,
85+
});
10886

109-
const auth = await authenticator.whoami();
110-
if (!auth) {
111-
console.error("Not authenticated");
112-
return;
113-
}
87+
const auth = await authenticator.whoami();
88+
if (!auth) {
89+
console.error("Not authenticated");
90+
return;
11491
}
11592

11693
const env = {
11794
...(settings.auth.apiKey && {
118-
LINGODOTDEV_API_KEY: settings.auth.apiKey,
119-
}),
120-
...(settings.auth.vnext?.apiKey && {
121-
LINGO_API_KEY: settings.auth.vnext.apiKey,
95+
LINGO_API_KEY: settings.auth.apiKey,
12296
}),
12397
LINGODOTDEV_PULL_REQUEST: options.pullRequest?.toString() || "false",
12498
...(options.commitMessage && {
@@ -162,7 +136,7 @@ export default new Command()
162136
}
163137

164138
const hasChanges = await flow.run({
165-
parallel: isVNext || options.parallel,
139+
parallel: options.parallel,
166140
});
167141
if (!hasChanges) {
168142
return;

packages/cli/src/cli/cmd/ci/platforms/_base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export abstract class PlatformKit<
4747

4848
get config() {
4949
const env = Z.object({
50+
LINGO_API_KEY: Z.string().optional(),
5051
LINGODOTDEV_API_KEY: Z.string().optional(),
5152
LINGODOTDEV_PULL_REQUEST: Z.preprocess(
5253
(val) => val === "true" || val === true,
@@ -68,7 +69,7 @@ export abstract class PlatformKit<
6869
}).parse(process.env);
6970

7071
return {
71-
replexicaApiKey: env.LINGODOTDEV_API_KEY || "",
72+
replexicaApiKey: env.LINGO_API_KEY || env.LINGODOTDEV_API_KEY || "",
7273
isPullRequestMode: env.LINGODOTDEV_PULL_REQUEST,
7374
commitMessage: env.LINGODOTDEV_COMMIT_MESSAGE || defaultMessage,
7475
pullRequestTitle: env.LINGODOTDEV_PULL_REQUEST_TITLE || defaultMessage,

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ export default new Command()
439439
let processPayload = createProcessor(i18nConfig!.provider, {
440440
apiKey: settings.auth.apiKey,
441441
apiUrl: settings.auth.apiUrl,
442+
engineId: i18nConfig!.engineId,
442443
});
443444
processPayload = withExponentialBackoff(
444445
processPayload,

packages/cli/src/cli/cmd/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Press Enter to open the browser for authentication.
4949
5050
---
5151
52-
Having issues? Put LINGODOTDEV_API_KEY in your .env file instead.
52+
Having issues? Put LINGO_API_KEY in your .env file instead.
5353
`.trim() + "\n",
5454
);
5555

packages/cli/src/cli/cmd/run/setup.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ export default async function setup(input: CmdRunContext) {
5050
{
5151
title: "Selecting localization provider",
5252
task: async (ctx, task) => {
53-
const isPseudo = ctx.flags.pseudo || ctx.config?.dev?.usePseudotranslator;
53+
const isPseudo =
54+
ctx.flags.pseudo || ctx.config?.dev?.usePseudotranslator;
5455
const provider = isPseudo ? "pseudo" : ctx.config?.provider;
55-
const vNext = ctx.config?.vNext;
56-
ctx.localizer = createLocalizer(provider, ctx.flags.apiKey, vNext);
56+
const engineId = ctx.config?.engineId;
57+
ctx.localizer = createLocalizer(provider, engineId, ctx.flags.apiKey);
5758
if (!ctx.localizer) {
5859
throw new Error(
5960
"Could not create localization provider. Please check your i18n.json configuration.",
6061
);
6162
}
6263
task.title =
63-
ctx.localizer.id === "Lingo.dev" ||
64-
ctx.localizer.id === "Lingo.dev vNext"
64+
ctx.localizer.id === "Lingo.dev"
6565
? `Using ${chalk.hex(colors.green)(ctx.localizer.id)} provider`
6666
: ctx.localizer.id === "pseudo"
6767
? `Using ${chalk.hex(colors.blue)("pseudo")} mode for testing`
@@ -71,8 +71,7 @@ export default async function setup(input: CmdRunContext) {
7171
{
7272
title: "Checking authentication",
7373
enabled: (ctx) =>
74-
(ctx.localizer?.id === "Lingo.dev" ||
75-
ctx.localizer?.id === "Lingo.dev vNext") &&
74+
ctx.localizer?.id === "Lingo.dev" &&
7675
!ctx.flags.pseudo &&
7776
!ctx.config?.dev?.usePseudotranslator,
7877
task: async (ctx, task) => {
@@ -87,9 +86,7 @@ export default async function setup(input: CmdRunContext) {
8786
},
8887
{
8988
title: "Validating configuration",
90-
enabled: (ctx) =>
91-
ctx.localizer?.id !== "Lingo.dev" &&
92-
ctx.localizer?.id !== "Lingo.dev vNext",
89+
enabled: (ctx) => ctx.localizer?.id !== "Lingo.dev",
9390
task: async (ctx, task) => {
9491
const validationStatus = await ctx.localizer!.validateSettings!();
9592
if (!validationStatus.valid) {
@@ -103,9 +100,7 @@ export default async function setup(input: CmdRunContext) {
103100
{
104101
title: "Initializing localization provider",
105102
async task(ctx, task) {
106-
const isLingoDotDev =
107-
ctx.localizer!.id === "Lingo.dev" ||
108-
ctx.localizer!.id === "Lingo.dev vNext";
103+
const isLingoDotDev = ctx.localizer!.id === "Lingo.dev";
109104
const isPseudo = ctx.localizer!.id === "pseudo";
110105

111106
const subTasks = isLingoDotDev

packages/cli/src/cli/localizer/_types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ export type LocalizerProgressFn = (
1717
) => void;
1818

1919
export interface ILocalizer {
20-
id:
21-
| "Lingo.dev"
22-
| "Lingo.dev vNext"
23-
| "pseudo"
24-
| NonNullable<I18nConfig["provider"]>["id"];
20+
id: "Lingo.dev" | "pseudo" | NonNullable<I18nConfig["provider"]>["id"];
2521
checkAuth: () => Promise<{
2622
authenticated: boolean;
2723
username?: string;

packages/cli/src/cli/localizer/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import { I18nConfig } from "@lingo.dev/_spec";
22

33
import createLingoDotDevLocalizer from "./lingodotdev";
4-
import createLingoDotDevVNextLocalizer from "./lingodotdev-vnext";
54
import createExplicitLocalizer from "./explicit";
65
import createPseudoLocalizer from "./pseudo";
76
import { ILocalizer } from "./_types";
87

98
export default function createLocalizer(
109
provider: I18nConfig["provider"] | "pseudo" | null | undefined,
10+
engineId?: string,
1111
apiKey?: string,
12-
vNext?: string,
1312
): ILocalizer {
1413
if (provider === "pseudo") {
1514
return createPseudoLocalizer();
1615
}
1716

18-
// Check if vNext is configured
19-
if (vNext) {
20-
return createLingoDotDevVNextLocalizer(vNext);
21-
}
22-
2317
if (!provider) {
24-
return createLingoDotDevLocalizer(apiKey);
18+
return createLingoDotDevLocalizer(apiKey, engineId);
2519
} else {
2620
return createExplicitLocalizer(provider);
2721
}

packages/cli/src/cli/localizer/lingodotdev-vnext.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

packages/cli/src/cli/localizer/lingodotdev.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { getSettings } from "../utils/settings";
77

88
export default function createLingoDotDevLocalizer(
99
explicitApiKey?: string,
10+
engineId?: string,
1011
): ILocalizer {
11-
const { auth } = getSettings(explicitApiKey);
12+
const settings = getSettings(explicitApiKey);
1213

13-
if (!auth) {
14+
if (!settings.auth.apiKey) {
1415
throw new Error(
1516
dedent`
1617
You're trying to use ${chalk.hex(colors.green)(
@@ -20,14 +21,17 @@ export default function createLingoDotDevLocalizer(
2021
To fix this issue:
2122
1. Run ${chalk.dim("lingo.dev login")} to authenticate, or
2223
2. Use the ${chalk.dim("--api-key")} flag to provide an API key.
23-
3. Set ${chalk.dim("LINGODOTDEV_API_KEY")} environment variable.
24+
3. Set ${chalk.dim("LINGO_API_KEY")} environment variable.
2425
`,
2526
);
2627
}
2728

29+
const triggerType = process.env.CI ? "ci" : "cli";
30+
2831
const engine = new LingoDotDevEngine({
29-
apiKey: auth.apiKey,
30-
apiUrl: auth.apiUrl,
32+
apiKey: settings.auth.apiKey,
33+
apiUrl: settings.auth.apiUrl,
34+
...(engineId && { engineId }),
3135
});
3236

3337
return {
@@ -48,7 +52,7 @@ export default function createLingoDotDevLocalizer(
4852
localize: async (input: LocalizerData, onProgress) => {
4953
// Nothing to translate – return the input as-is.
5054
if (!Object.keys(input.processableData).length) {
51-
return input;
55+
return input.processableData;
5256
}
5357

5458
const processedData = await engine.localizeObject(
@@ -61,6 +65,8 @@ export default function createLingoDotDevLocalizer(
6165
[input.targetLocale]: input.targetData,
6266
},
6367
hints: input.hints,
68+
filePath: input.filePath,
69+
triggerType,
6470
},
6571
onProgress,
6672
);

0 commit comments

Comments
 (0)