gt 2.26.12 → 2.27.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/auth/cliApiKey.d.ts +7 -0
  3. package/dist/auth/cliApiKey.js +18 -0
  4. package/dist/auth/cliApiKey.js.map +1 -0
  5. package/dist/cli/base.d.ts +1 -1
  6. package/dist/cli/base.js +60 -16
  7. package/dist/cli/base.js.map +1 -1
  8. package/dist/cli/commands/api.js +2 -1
  9. package/dist/cli/commands/api.js.map +1 -1
  10. package/dist/cli/commands/utils/validation.js +1 -1
  11. package/dist/cli/commands/utils/validation.js.map +1 -1
  12. package/dist/config/generateSettings.js +2 -1
  13. package/dist/config/generateSettings.js.map +1 -1
  14. package/dist/console/index.d.ts +1 -1
  15. package/dist/console/index.js +7 -1
  16. package/dist/console/index.js.map +1 -1
  17. package/dist/generated/version.d.ts +1 -1
  18. package/dist/generated/version.js +1 -1
  19. package/dist/generated/version.js.map +1 -1
  20. package/dist/setup/buildTools/index.d.ts +2 -0
  21. package/dist/setup/buildTools/index.js +11 -1
  22. package/dist/setup/buildTools/index.js.map +1 -1
  23. package/dist/setup/buildTools/vite.js +2 -1
  24. package/dist/setup/buildTools/vite.js.map +1 -1
  25. package/dist/setup/detectFramework.d.ts +5 -4
  26. package/dist/setup/detectFramework.js +7 -2
  27. package/dist/setup/detectFramework.js.map +1 -1
  28. package/dist/setup/developmentCredentials.js +1 -1
  29. package/dist/setup/instructions/base.md +1 -1
  30. package/dist/setup/instructions/gt-next.md +1 -1
  31. package/dist/setup/instructions/gt-react.md +1 -1
  32. package/dist/setup/nextSteps.d.ts +31 -0
  33. package/dist/setup/nextSteps.js +46 -0
  34. package/dist/setup/nextSteps.js.map +1 -0
  35. package/dist/setup/onboarding.d.ts +3 -0
  36. package/dist/setup/onboarding.js +3 -2
  37. package/dist/setup/onboarding.js.map +1 -1
  38. package/dist/setup/setupTarget.d.ts +2 -0
  39. package/dist/setup/setupTarget.js +10 -1
  40. package/dist/setup/setupTarget.js.map +1 -1
  41. package/dist/setup/wizard.d.ts +1 -1
  42. package/dist/setup/wizard.js +6 -8
  43. package/dist/setup/wizard.js.map +1 -1
  44. package/dist/types/index.d.ts +5 -0
  45. package/dist/types/index.js.map +1 -1
  46. package/dist/utils/api.d.ts +21 -0
  47. package/dist/utils/constants.d.ts +4 -1
  48. package/dist/utils/constants.js +5 -2
  49. package/dist/utils/constants.js.map +1 -1
  50. package/dist/utils/credentials.d.ts +3 -2
  51. package/dist/utils/credentials.js +18 -10
  52. package/dist/utils/credentials.js.map +1 -1
  53. package/dist/utils/loadEnv.d.ts +2 -0
  54. package/dist/utils/loadEnv.js +9 -1
  55. package/dist/utils/loadEnv.js.map +1 -1
  56. package/dist/workflows/stage.js +2 -1
  57. package/dist/workflows/stage.js.map +1 -1
  58. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.27.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2637](https://github.com/generaltranslation/gt/pull/2637) [`c18b328`](https://github.com/generaltranslation/gt/commit/c18b3284c1a7cd9d6e3884a9ed35abfe6ee36b30) Thanks [@eoinest](https://github.com/eoinest)! - `gt init` now detects Expo and React Native apps instead of setting them up as plain React. It stops before changing anything and links the React Native quickstart. Previously it installed `gt-react`, wrote a loader that Metro can't bundle, and saved `REACT_APP_` env names that Expo never loads.
8
+
9
+ - [#2599](https://github.com/generaltranslation/gt/pull/2599) [`f3c2c34`](https://github.com/generaltranslation/gt/commit/f3c2c343edb5a2e11cc8120513564095fc491979) Thanks [@eoinest](https://github.com/eoinest)! - Fix `next build` failing right after `gt init`. For Next.js (App Router and Pages Router), `gt init` now saves `GT_PROJECT_ID` and `GT_API_KEY` to `.env.local` instead of `NEXT_PUBLIC_` variables, so one key works in development and production. gt-next no longer fails production builds when a development key is present, and no longer reads `GT_DEV_API_KEY`. `NEXT_PUBLIC_GT_PROJECT_ID` and `NEXT_PUBLIC_GT_DEV_API_KEY` still work, and the `GT_*` names take precedence.
10
+ - During `next dev`, `withGTConfig` exposes `GT_PROJECT_ID` and `GT_API_KEY` to client code for hot reload, so whatever key `GT_API_KEY` holds reaches the browser in development. Production builds never include it. To keep the key out of the browser in development, set `runtimeUrl: ''` in `withGTConfig`, which turns off runtime translation.
11
+ - With `GT_API_KEY` in `.env.local`, a local `next build` or `next start` now uses it for runtime translation, the same as a production deployment with `GT_API_KEY` set.
12
+ - The `gt` CLI prefers your login over a `GT_API_KEY` that comes from an env file, because that key is the app's runtime key. A `GT_API_KEY` set in the shell or CI still takes precedence.
13
+
14
+ - [#2640](https://github.com/generaltranslation/gt/pull/2640) [`b90cb80`](https://github.com/generaltranslation/gt/commit/b90cb8012c05262ce6669d31d67cf62c6a1bcf43) Thanks [@eoinest](https://github.com/eoinest)! - Fix docs links that pointed to retired or missing pages. The `gt init` setup wizard now links to the quickstart for your framework (Next.js App Router, Next.js Pages Router, Vite, or React) instead of a retired tutorial that redirected to the React overview. The links in the generated AI instruction files no longer 404, and the gt-next "No locale could be determined" warning now links to the App Router static site generation guide.
15
+
16
+ - [#2643](https://github.com/generaltranslation/gt/pull/2643) [`7fbf1fa`](https://github.com/generaltranslation/gt/commit/7fbf1fa6955150868eec6bcf085005d4cbe0c78e) Thanks [@eoinest](https://github.com/eoinest)! - Make `gt translate` failures easier to act on. The no-project-ID error now points to the dashboard to find or create a project, and sign-in failures lead with the `gt login` fix instead of a generic send error.
17
+
18
+ - [#2639](https://github.com/generaltranslation/gt/pull/2639) [`69e313d`](https://github.com/generaltranslation/gt/commit/69e313d1f508a850012f6163327f2a139fd4c86e) Thanks [@eoinest](https://github.com/eoinest)! - `gt init` now ends with a single `Done!` followed by numbered next steps for your framework: wrap content in `<T>` or use `useGT()`, add `<LocaleSelector />`, run `npx gt translate`, and start the dev server. It states that setup did not mark any content for translation, and the `--json` result lists the same steps in a new `nextSteps` field. The Next.js App Router spinner and completed step now say they add `GTProvider` instead of claiming to wrap content in `<T>`.
19
+
20
+ - Updated dependencies [[`e1c64a3`](https://github.com/generaltranslation/gt/commit/e1c64a3c27c7a05ffeb81eb2d04ace795d0c3ab5)]:
21
+ - generaltranslation@9.5.10
22
+ - @generaltranslation/python-extractor@0.2.65
23
+ - @generaltranslation/supported-locales@2.1.46
24
+ - @generaltranslation/vue-extractor@0.1.24
25
+
26
+ ## 2.27.0
27
+
28
+ ### Minor Changes
29
+
30
+ - [#2604](https://github.com/generaltranslation/gt/pull/2604) [`c460193`](https://github.com/generaltranslation/gt/commit/c46019337dda8440a7174d783ad94a0f9b15f79a) Thanks [@chenxin-yan](https://github.com/chenxin-yan)! - Add `--org-id <orgId>` to `gt api-key create` to create an organization API key instead of a project key. It always uses your `gt login` session, even when an API key is configured, because API keys cannot create organization keys. `--permission` now also accepts organization permissions such as `org:context:read`, `org:projects:create`, and `project:api_keys:write`; passing one without `--org-id` fails before any request. Project keys are unchanged.
31
+
32
+ The SDK adds `createOrgApiKey` and the `OrgApiKeyPermission` enum, and the shared API adapter adds `createOrgApiKey`.
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [[`c460193`](https://github.com/generaltranslation/gt/commit/c46019337dda8440a7174d783ad94a0f9b15f79a)]:
37
+ - generaltranslation@9.5.9
38
+ - @generaltranslation/python-extractor@0.2.64
39
+ - @generaltranslation/supported-locales@2.1.45
40
+ - @generaltranslation/vue-extractor@0.1.23
41
+
3
42
  ## 2.26.12
4
43
 
5
44
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The API key the CLI sends. A GT_API_KEY from an env file is the app's
3
+ * runtime key (gt init saves a translate-only key there for Next.js), so a
4
+ * stored login acts for the CLI instead. A shell or CI GT_API_KEY stays
5
+ * authoritative.
6
+ */
7
+ export declare function resolveCliApiKey(baseUrl: string): Promise<string | undefined>;
@@ -0,0 +1,18 @@
1
+ import { hasLogin } from "./oauth.js";
2
+ import { getEnvFileApiKey } from "../utils/loadEnv.js";
3
+ //#region src/auth/cliApiKey.ts
4
+ /**
5
+ * The API key the CLI sends. A GT_API_KEY from an env file is the app's
6
+ * runtime key (gt init saves a translate-only key there for Next.js), so a
7
+ * stored login acts for the CLI instead. A shell or CI GT_API_KEY stays
8
+ * authoritative.
9
+ */
10
+ async function resolveCliApiKey(baseUrl) {
11
+ const apiKey = process.env.GT_API_KEY;
12
+ if (!apiKey || apiKey !== getEnvFileApiKey()) return apiKey;
13
+ return await hasLogin({ baseUrl }).catch(() => false) ? void 0 : apiKey;
14
+ }
15
+ //#endregion
16
+ export { resolveCliApiKey };
17
+
18
+ //# sourceMappingURL=cliApiKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliApiKey.js","names":[],"sources":["../../src/auth/cliApiKey.ts"],"sourcesContent":["import { getEnvFileApiKey } from '../utils/loadEnv.js';\nimport { hasLogin } from './oauth.js';\n\n/**\n * The API key the CLI sends. A GT_API_KEY from an env file is the app's\n * runtime key (gt init saves a translate-only key there for Next.js), so a\n * stored login acts for the CLI instead. A shell or CI GT_API_KEY stays\n * authoritative.\n */\nexport async function resolveCliApiKey(\n baseUrl: string\n): Promise<string | undefined> {\n const apiKey = process.env.GT_API_KEY;\n if (!apiKey || apiKey !== getEnvFileApiKey()) return apiKey;\n const signedIn = await hasLogin({ baseUrl }).catch(() => false);\n return signedIn ? undefined : apiKey;\n}\n"],"mappings":";;;;;;;;;AASA,eAAsB,iBACpB,SAC6B;CAC7B,MAAM,SAAS,QAAQ,IAAI;AAC3B,KAAI,CAAC,UAAU,WAAW,kBAAkB,CAAE,QAAO;AAErD,QAAO,MADgB,SAAS,EAAE,SAAS,CAAC,CAAC,YAAY,MAAM,GAC7C,KAAA,IAAY"}
@@ -105,6 +105,6 @@ export declare class BaseCLI {
105
105
  reactSetup?: ReactSetupPlan;
106
106
  /** Init without the React setup never changes application source. */
107
107
  keepAppSource?: boolean;
108
- }): Promise<void>;
108
+ }): Promise<string[] | undefined>;
109
109
  }
110
110
  export {};
package/dist/cli/base.js CHANGED
@@ -12,18 +12,20 @@ import { resolveProjectId } from "../fs/utils.js";
12
12
  import { UserAuthError, createUserAuthError } from "../auth/errors.js";
13
13
  import { hasLogin, logout, whoAmI } from "../auth/oauth.js";
14
14
  import { resolveConfig } from "../config/resolveConfig.js";
15
- import { api } from "../utils/api.js";
15
+ import { api, configureApiClient } from "../utils/api.js";
16
16
  import { generateSettings } from "../config/generateSettings.js";
17
17
  import { applySetupConfig, mergeSetupConfig } from "../fs/config/setupConfig.js";
18
18
  import { areCredentialsSet, getDevelopmentEnvNames, inspectCredentialsEnvFile } from "../utils/credentials.js";
19
19
  import { warnReactPackageCompatibility } from "../utils/reactPackageCompatibility.js";
20
- import { getBuildToolSetup } from "../setup/buildTools/index.js";
20
+ import { getBuildToolSetup, getSetupDocsUrl } from "../setup/buildTools/index.js";
21
21
  import { executeReactSetup, resolveReactSetup } from "../setup/wizard.js";
22
+ import { formatInitNextSteps, getInitNextSteps } from "../setup/nextSteps.js";
23
+ import { getPackageManager } from "../utils/packageManager.js";
22
24
  import { getDesiredLocales } from "../setup/userInput.js";
23
25
  import { loginInteractively } from "../auth/interactiveLogin.js";
24
26
  import { INIT_SOURCE_HELP, OnboardingError, asRecord, attachConfigureFlags, attachInitFlags, describeDefaults, displaySetupHeader, getConfiguredFramework, installWithProgress, parseFilePatterns, readSetupConfig, reportJsonExitsBeforeOnboarding, resolvePackageManager, runOnboarding, setupConfigPath, validateSetupPattern } from "../setup/onboarding.js";
25
27
  import { checkDevelopmentProjectInputs, productionRuntimeKeyGuidance, provisionDevelopmentCredentials, resolveDevelopmentProject, signInForSetup } from "../setup/developmentCredentials.js";
26
- import { exitIfUnsupportedSetupTarget } from "../setup/setupTarget.js";
28
+ import { exitIfUnsupportedSetupTarget, reactNativeSetupError } from "../setup/setupTarget.js";
27
29
  import { clearWarnings } from "../state/translateWarnings.js";
28
30
  import { clearOrphanedFileNames, getOrphanedFileNames } from "../state/orphanedFileNames.js";
29
31
  import { hasValidCredentials, hasValidServiceLocales } from "./commands/utils/validation.js";
@@ -50,7 +52,7 @@ import { handleApiCommand } from "./commands/api.js";
50
52
  import chalk from "chalk";
51
53
  import path from "node:path";
52
54
  import { createDiagnosticMessage, formatDiagnosticErrorDetails } from "generaltranslation/diagnostics";
53
- import { ProjectApiKeyPermission } from "generaltranslation/api";
55
+ import { OrgApiKeyPermission, ProjectApiKeyPermission } from "generaltranslation/api";
54
56
  import { manifestDirectlyDeclaresGTVue } from "@generaltranslation/vue-extractor/integration";
55
57
  import { Argument, InvalidArgumentError, Option } from "commander";
56
58
  //#region src/cli/base.ts
@@ -75,6 +77,10 @@ const emptyApiKeyNameError = createDiagnosticMessage({
75
77
  whatHappened: "The key name cannot be empty",
76
78
  fix: "Pass a non-empty value with --name"
77
79
  });
80
+ const projectApiKeyPermissions = new Set(Object.values(ProjectApiKeyPermission));
81
+ function isProjectApiKeyPermission(permission) {
82
+ return projectApiKeyPermissions.has(permission);
83
+ }
78
84
  function parseApiKeyName(value) {
79
85
  const name = value.trim();
80
86
  if (!name) throw new InvalidArgumentError(emptyApiKeyNameError);
@@ -215,15 +221,35 @@ var BaseCLI = class {
215
221
  });
216
222
  }
217
223
  setupApiKeyCommands() {
218
- attachSharedFlags(this.program.command("api-key").description("Manage API keys for the configured project").command("create").description("Create a project API key with the requested permissions and print it once").requiredOption("--name <name>", "Key name", parseApiKeyName).addOption(new Option("--permission <permissions...>", "Permissions to grant").choices(Object.values(ProjectApiKeyPermission)).makeOptionMandatory())).action(async (options) => {
224
+ attachSharedFlags(this.program.command("api-key").description("Manage API keys for the configured project or an organization").command("create").description("Create a project API key, or an organization API key with --org-id, with the requested permissions and print it once").requiredOption("--name <name>", "Key name", parseApiKeyName).option("--org-id <orgId>", "Create an organization API key for this organization instead (requires gt login)").addOption(new Option("--permission <permissions...>", "Permissions to grant").choices(Object.values(OrgApiKeyPermission)).makeOptionMandatory())).action(async (options) => {
225
+ const projectPermissions = options.permission.filter(isProjectApiKeyPermission);
226
+ const orgOnlyPermissions = options.permission.filter((permission) => !isProjectApiKeyPermission(permission));
227
+ if (!options.orgId && orgOnlyPermissions.length > 0) return logErrorAndExit(createDiagnosticMessage({
228
+ whatHappened: `${orgOnlyPermissions.join(", ")} can only be granted to organization API keys`,
229
+ fix: "Pass --org-id, or remove those permissions"
230
+ }));
219
231
  try {
220
232
  const settings = await generateSettings(options);
221
- if (!hasValidCredentials(settings)) return exitSync(1);
222
- const { apiKey } = await api.createProjectApiKey(settings.projectId, {
223
- name: options.name,
224
- permissions: options.permission
225
- });
226
- process.stdout.write(`${apiKey.key}\n`);
233
+ let key;
234
+ if (options.orgId) {
235
+ configureApiClient({
236
+ baseUrl: settings.baseUrl,
237
+ userTokenProvider: settings.userTokenProvider
238
+ });
239
+ const { apiKey } = await api.createOrgApiKey(options.orgId, {
240
+ name: options.name,
241
+ permissions: options.permission
242
+ });
243
+ key = apiKey.key;
244
+ } else {
245
+ if (!hasValidCredentials(settings)) return exitSync(1);
246
+ const { apiKey } = await api.createProjectApiKey(settings.projectId, {
247
+ name: options.name,
248
+ permissions: projectPermissions
249
+ });
250
+ key = apiKey.key;
251
+ }
252
+ process.stdout.write(`${key}\n`);
227
253
  } catch (error) {
228
254
  return logErrorAndExit(error instanceof UserAuthError ? error.message : createProjectCommandError("Failed to create the API key", error));
229
255
  }
@@ -375,6 +401,7 @@ var BaseCLI = class {
375
401
  await exitIfUnsupportedSetupTarget();
376
402
  displaySetupHeader(session, "Running setup wizard...");
377
403
  const detected = await detectFramework();
404
+ if (detected.type === "react-native") throw new OnboardingError(reactNativeSetupError);
378
405
  const reactDetected = detected.type === "react" ? detected : void 0;
379
406
  if (options.framework && !reactDetected) session.reject("--framework applies only to projects detected as React applications");
380
407
  const configFilepath = setupConfigPath(options);
@@ -419,13 +446,20 @@ var BaseCLI = class {
419
446
  }) === true;
420
447
  const reactSetup = reactDetected ? await resolveReactSetup(session, options, reactDetected, configuredReact) : void 0;
421
448
  const framework = reactSetup?.framework ?? options.framework ?? configured ?? detected.name;
422
- await this.handleInitCommand(session, options, {
449
+ const nextSteps = await this.handleInitCommand(session, options, {
423
450
  configFilepath,
424
451
  framework,
425
452
  saveFramework: Boolean(reactSetup || options.framework),
426
453
  reactSetup,
427
454
  keepAppSource: !reactSetup
428
455
  });
456
+ if (nextSteps) {
457
+ logger.endCommand(formatInitNextSteps(nextSteps));
458
+ return {
459
+ outcome: "success",
460
+ nextSteps
461
+ };
462
+ }
429
463
  logger.endCommand("Done! Check out our docs for more information on how to use General Translation: https://generaltranslation.com/docs");
430
464
  return { outcome: "success" };
431
465
  });
@@ -441,7 +475,7 @@ var BaseCLI = class {
441
475
  session.defaults = options.defaults ?? false;
442
476
  const detected = await detectFramework();
443
477
  const configFilepath = setupConfigPath(options);
444
- const framework = getConfiguredFramework(readSetupConfig(configFilepath)) ?? detected.name;
478
+ const framework = getConfiguredFramework(readSetupConfig(configFilepath)) ?? (detected.type === "react-native" ? "react" : detected.name);
445
479
  await this.handleInitCommand(session, options, {
446
480
  configFilepath,
447
481
  framework
@@ -651,9 +685,7 @@ See https://www.npmjs.com/package/gt-vue`);
651
685
  logger.info(`${chalk.yellow("[EXPERIMENTAL]")} Configuring project...`);
652
686
  if (reactSetup.install && packageManager) await installWithProgress(session, reactSetup.install, packageManager, false);
653
687
  await executeReactSetup(session, reactSetup, options);
654
- logger.endCommand(`Done! Since this wizard is experimental, please review the changes and make modifications as needed.
655
- \nNext step: start internationalizing! See the docs for more information: ${buildTool?.docsUrl ?? "https://generaltranslation.com/docs/react/tutorials/quickstart"}`);
656
- logger.startCommand("Setting up project config...");
688
+ logger.step("Setting up project config...");
657
689
  }
658
690
  const reportManualAction = ({ whatHappened, fix }) => {
659
691
  session.humanActions.push(fix);
@@ -741,6 +773,18 @@ See https://www.npmjs.com/package/gt-vue`);
741
773
  await withCredentialsError(() => provisionDevelopmentCredentials(session, project, settings, envFramework, cwd));
742
774
  logger.message(productionRuntimeKeyGuidance(settings.dashboardUrl));
743
775
  }
776
+ if (!reactSetup) return void 0;
777
+ const devPackageManager = packageManager ?? await getPackageManager(cwd, options.packageManager, true).catch(() => void 0);
778
+ const scripts = asRecord(reactSetup.packageJson.scripts);
779
+ return getInitNextSteps({
780
+ framework: reactSetup.framework,
781
+ configuredAppEntry: reactSetup.framework === "next-app" || buildTool !== void 0,
782
+ docsUrl: getSetupDocsUrl(reactSetup.framework),
783
+ locales: resolvedLocales,
784
+ configFilepath,
785
+ translationsDir: storage === "local" ? translationsDir : void 0,
786
+ devCommand: typeof scripts?.dev === "string" ? `${devPackageManager?.runScriptCommand ?? "npm run"} dev` : void 0
787
+ });
744
788
  }
745
789
  };
746
790
  //#endregion