@tinacms/cli 2.3.0 → 2.4.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/dist/index.js CHANGED
@@ -2,17 +2,17 @@
2
2
  import { Cli, Builtins } from "clipanion";
3
3
 
4
4
  // package.json
5
- var version = "2.3.0";
5
+ var version = "2.4.0";
6
6
 
7
7
  // src/next/commands/dev-command/index.ts
8
- import path9 from "path";
8
+ import path10 from "path";
9
9
  import { FilesystemBridge as FilesystemBridge2, buildSchema } from "@tinacms/graphql";
10
10
  import { Telemetry } from "@tinacms/metrics";
11
11
  import { LocalSearchIndexClient, SearchIndexer } from "@tinacms/search";
12
12
  import AsyncLock from "async-lock";
13
13
  import chokidar from "chokidar";
14
14
  import { Command as Command2, Option as Option2 } from "clipanion";
15
- import fs8 from "fs-extra";
15
+ import fs9 from "fs-extra";
16
16
 
17
17
  // src/logger/index.ts
18
18
  import chalk from "chalk";
@@ -565,6 +565,11 @@ var Codegen = class {
565
565
  this.configManager.generatedTypesTSFilePath,
566
566
  codeString
567
567
  );
568
+ const jsTypes = await transform(codeString, { loader: "ts" });
569
+ await fs.outputFile(
570
+ this.configManager.generatedTypesJSFilePath,
571
+ jsTypes.code
572
+ );
568
573
  await fs.outputFile(
569
574
  this.configManager.generatedClientTSFilePath,
570
575
  clientString
@@ -577,7 +582,6 @@ var Codegen = class {
577
582
  }
578
583
  await unlinkIfExists(this.configManager.generatedClientJSFilePath);
579
584
  await unlinkIfExists(this.configManager.generatedTypesDFilePath);
580
- await unlinkIfExists(this.configManager.generatedTypesJSFilePath);
581
585
  } else {
582
586
  await fs.outputFile(
583
587
  this.configManager.generatedTypesDFilePath,
@@ -684,7 +688,7 @@ var Codegen = class {
684
688
  import { resolve } from "@tinacms/datalayer";
685
689
  import type { TinaClient } from "tinacms/dist/client";
686
690
 
687
- import { queries } from "${this.configManager.isUsingTs() ? "./types" : "./types.js"}";
691
+ import { queries } from "./types.js";
688
692
  import database from "../database";
689
693
 
690
694
  export async function databaseRequest({ query, variables, user }) {
@@ -750,7 +754,7 @@ export default databaseClient;
750
754
  const errorPolicy = this.configManager.config?.client?.errorPolicy;
751
755
  const apiURL = this.getApiURL();
752
756
  const clientString = `import { createClient } from "tinacms/dist/client";
753
- import { queries } from "${this.configManager.isUsingTs() ? "./types" : "./types.js"}";
757
+ import { queries } from "./types.js";
754
758
  export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${normalizePath(
755
759
  this.configManager.generatedCachePath
756
760
  )}', ` : ""}url: ${this.localContentBuild ? `process.env.TINA_LOCAL_URL || '${apiURL}'` : `'${apiURL}'`}, token: '${token}', queries, ${errorPolicy ? `errorPolicy: '${errorPolicy}'` : ""} });
@@ -812,9 +816,8 @@ var unlinkIfExists = async (filepath) => {
812
816
  };
813
817
 
814
818
  // src/next/config-manager.ts
815
- import fs3 from "fs-extra";
816
- import path4 from "path";
817
- import os from "os";
819
+ import fs4 from "fs-extra";
820
+ import path5 from "path";
818
821
  import { pathToFileURL } from "url";
819
822
  import * as esbuild from "esbuild";
820
823
  import * as dotenv from "dotenv";
@@ -873,6 +876,76 @@ async function resolveContentRootPath(params) {
873
876
  return params.rootPath;
874
877
  }
875
878
 
879
+ // src/next/external-resolver.ts
880
+ var EXTERNAL_BASELINE = ["better-sqlite3"];
881
+ var resolveDatabaseExternals = (config2) => {
882
+ const userExternals = config2?.build?.externalDependencies ?? [];
883
+ return [...EXTERNAL_BASELINE, ...userExternals];
884
+ };
885
+
886
+ // src/next/cache-manager.ts
887
+ import fs3 from "fs-extra";
888
+ import path4 from "path";
889
+ var buildReadOnlyMountErrorMessage = (cacheParentPath, underlyingError) => `TinaCMS cannot write to ${cacheParentPath}.
890
+
891
+ Tina v3 needs write access to your project's tina/__generated__/.cache/ directory at build time. This usually means your project directory is read-only \u2014 common in some Docker setups (\`:ro\` volumes), AWS Lambda's \`/var/task\`, sandboxed CI runners, or restricted file permissions.
892
+
893
+ To resolve, either:
894
+ - Make the project directory writable (e.g. remount with read-write access, or copy the project to a writable location), or
895
+ - Run \`tinacms build\` against a writable copy of your project and deploy the resulting artifacts.
896
+
897
+ Underlying error: ${underlyingError.code} ${underlyingError.message}`;
898
+ var READONLY_ERROR_CODES = /* @__PURE__ */ new Set(["EACCES", "EROFS", "EPERM"]);
899
+ var prepareCacheLocation = async (generatedFolderPath, now = Date.now()) => {
900
+ const parentPath = path4.join(generatedFolderPath, ".cache");
901
+ try {
902
+ if (await fs3.pathExists(parentPath)) {
903
+ await fs3.remove(parentPath);
904
+ }
905
+ await fs3.ensureDir(parentPath);
906
+ } catch (err) {
907
+ const code = err?.code;
908
+ if (code && READONLY_ERROR_CODES.has(code)) {
909
+ throw new Error(
910
+ buildReadOnlyMountErrorMessage(parentPath, err)
911
+ );
912
+ }
913
+ throw err;
914
+ }
915
+ return {
916
+ parentPath,
917
+ buildPath: path4.join(parentPath, String(now))
918
+ };
919
+ };
920
+ var reapBuildSubdir = (buildSubdirPath, buildParentPath) => {
921
+ fs3.removeSync(buildSubdirPath);
922
+ try {
923
+ fs3.rmdirSync(buildParentPath);
924
+ } catch (err) {
925
+ if (err?.code !== "ENOTEMPTY") throw err;
926
+ }
927
+ };
928
+
929
+ // src/next/build-database-esbuild-config.ts
930
+ var buildDatabaseEsbuildConfig = (opts) => ({
931
+ entryPoints: [opts.entryPoint],
932
+ bundle: true,
933
+ platform: "node",
934
+ format: "esm",
935
+ outfile: opts.outfile,
936
+ loader: opts.loader,
937
+ external: opts.external,
938
+ // Provide a require() polyfill for ESM bundles containing CommonJS packages.
939
+ // Some bundled packages (e.g., 'scmp' used by 'mongodb-level') use
940
+ // require('crypto'). When esbuild inlines these CommonJS packages, it keeps
941
+ // the require() calls, but ESM doesn't have a global require. This banner
942
+ // creates one using Node.js's official createRequire API, allowing the
943
+ // bundled CommonJS code to work in ESM.
944
+ banner: {
945
+ js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
946
+ }
947
+ });
948
+
876
949
  // src/next/config-manager.ts
877
950
  var TINA_FOLDER = "tina";
878
951
  var LEGACY_TINA_FOLDER = ".tina";
@@ -932,7 +1005,7 @@ var ConfigManager = class {
932
1005
  this.legacyNoSDK = legacyNoSDK;
933
1006
  }
934
1007
  isUsingTs() {
935
- return [".ts", ".tsx"].includes(path4.extname(this.tinaConfigFilePath));
1008
+ return [".ts", ".tsx"].includes(path5.extname(this.tinaConfigFilePath));
936
1009
  }
937
1010
  hasSelfHostedConfig() {
938
1011
  return !!this.selfHostedDatabaseFilePath;
@@ -957,12 +1030,12 @@ var ConfigManager = class {
957
1030
  )
958
1031
  );
959
1032
  }
960
- this.envFilePath = path4.resolve(
961
- path4.join(this.tinaFolderPath, "..", ".env")
1033
+ this.envFilePath = path5.resolve(
1034
+ path5.join(this.tinaFolderPath, "..", ".env")
962
1035
  );
963
1036
  dotenv.config({ path: this.envFilePath });
964
1037
  this.tinaConfigFilePath = await this.getPathWithExtension(
965
- path4.join(this.tinaFolderPath, "config")
1038
+ path5.join(this.tinaFolderPath, "config")
966
1039
  );
967
1040
  if (!this.tinaConfigFilePath) {
968
1041
  throw new Error(
@@ -970,89 +1043,86 @@ var ConfigManager = class {
970
1043
  );
971
1044
  }
972
1045
  this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
973
- path4.join(this.tinaFolderPath, "database")
1046
+ path5.join(this.tinaFolderPath, "database")
974
1047
  );
975
- this.generatedFolderPath = path4.join(this.tinaFolderPath, GENERATED_FOLDER);
976
- this.generatedCachePath = path4.join(
977
- this.generatedFolderPath,
978
- ".cache",
979
- String((/* @__PURE__ */ new Date()).getTime())
980
- );
981
- this.generatedGraphQLGQLPath = path4.join(
1048
+ this.generatedFolderPath = path5.join(this.tinaFolderPath, GENERATED_FOLDER);
1049
+ const cacheLocation = await prepareCacheLocation(this.generatedFolderPath);
1050
+ this.generatedCachePath = cacheLocation.buildPath;
1051
+ this.generatedGraphQLGQLPath = path5.join(
982
1052
  this.generatedFolderPath,
983
1053
  GRAPHQL_GQL_FILE
984
1054
  );
985
- this.generatedGraphQLJSONPath = path4.join(
1055
+ this.generatedGraphQLJSONPath = path5.join(
986
1056
  this.generatedFolderPath,
987
1057
  GRAPHQL_JSON_FILE
988
1058
  );
989
- this.generatedSchemaJSONPath = path4.join(
1059
+ this.generatedSchemaJSONPath = path5.join(
990
1060
  this.generatedFolderPath,
991
1061
  SCHEMA_JSON_FILE
992
1062
  );
993
- this.generatedLookupJSONPath = path4.join(
1063
+ this.generatedLookupJSONPath = path5.join(
994
1064
  this.generatedFolderPath,
995
1065
  LOOKUP_JSON_FILE
996
1066
  );
997
- this.generatedQueriesFilePath = path4.join(
1067
+ this.generatedQueriesFilePath = path5.join(
998
1068
  this.generatedFolderPath,
999
1069
  "queries.gql"
1000
1070
  );
1001
- this.generatedFragmentsFilePath = path4.join(
1071
+ this.generatedFragmentsFilePath = path5.join(
1002
1072
  this.generatedFolderPath,
1003
1073
  "frags.gql"
1004
1074
  );
1005
- this.generatedTypesTSFilePath = path4.join(
1075
+ this.generatedTypesTSFilePath = path5.join(
1006
1076
  this.generatedFolderPath,
1007
1077
  "types.ts"
1008
1078
  );
1009
- this.generatedTypesJSFilePath = path4.join(
1079
+ this.generatedTypesJSFilePath = path5.join(
1010
1080
  this.generatedFolderPath,
1011
1081
  "types.js"
1012
1082
  );
1013
- this.generatedTypesDFilePath = path4.join(
1083
+ this.generatedTypesDFilePath = path5.join(
1014
1084
  this.generatedFolderPath,
1015
1085
  "types.d.ts"
1016
1086
  );
1017
- this.userQueriesAndFragmentsGlob = path4.join(
1087
+ this.userQueriesAndFragmentsGlob = path5.join(
1018
1088
  this.tinaFolderPath,
1019
1089
  "queries/**/*.{graphql,gql}"
1020
1090
  );
1021
- this.generatedQueriesAndFragmentsGlob = path4.join(
1091
+ this.generatedQueriesAndFragmentsGlob = path5.join(
1022
1092
  this.generatedFolderPath,
1023
1093
  "*.{graphql,gql}"
1024
1094
  );
1025
- this.generatedClientTSFilePath = path4.join(
1095
+ this.generatedClientTSFilePath = path5.join(
1026
1096
  this.generatedFolderPath,
1027
1097
  "client.ts"
1028
1098
  );
1029
- this.generatedClientJSFilePath = path4.join(
1099
+ this.generatedClientJSFilePath = path5.join(
1030
1100
  this.generatedFolderPath,
1031
1101
  "client.js"
1032
1102
  );
1033
- this.generatedClientDFilePath = path4.join(
1103
+ this.generatedClientDFilePath = path5.join(
1034
1104
  this.generatedFolderPath,
1035
1105
  "client.d.ts"
1036
1106
  );
1037
- this.generatedDatabaseClientDFilePath = path4.join(
1107
+ this.generatedDatabaseClientDFilePath = path5.join(
1038
1108
  this.generatedFolderPath,
1039
1109
  "databaseClient.d.ts"
1040
1110
  );
1041
- this.generatedDatabaseClientTSFilePath = path4.join(
1111
+ this.generatedDatabaseClientTSFilePath = path5.join(
1042
1112
  this.generatedFolderPath,
1043
1113
  "databaseClient.ts"
1044
1114
  );
1045
- this.generatedDatabaseClientJSFilePath = path4.join(
1115
+ this.generatedDatabaseClientJSFilePath = path5.join(
1046
1116
  this.generatedFolderPath,
1047
1117
  "databaseClient.js"
1048
1118
  );
1049
- const clientExists = this.isUsingTs() ? await fs3.pathExists(this.generatedClientTSFilePath) : await fs3.pathExists(this.generatedClientJSFilePath);
1119
+ const clientExists = this.isUsingTs() ? await fs4.pathExists(this.generatedClientTSFilePath) : await fs4.pathExists(this.generatedClientJSFilePath);
1050
1120
  if (!clientExists) {
1051
1121
  const file = "export default ()=>({})\nexport const client = ()=>({})";
1052
1122
  if (this.isUsingTs()) {
1053
- await fs3.outputFile(this.generatedClientTSFilePath, file);
1123
+ await fs4.outputFile(this.generatedClientTSFilePath, file);
1054
1124
  } else {
1055
- await fs3.outputFile(this.generatedClientJSFilePath, file);
1125
+ await fs4.outputFile(this.generatedClientJSFilePath, file);
1056
1126
  }
1057
1127
  }
1058
1128
  const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
@@ -1062,16 +1132,16 @@ var ConfigManager = class {
1062
1132
  this.watchList = watchList;
1063
1133
  this.config = config2;
1064
1134
  this.prebuildFilePath = prebuildPath;
1065
- this.publicFolderPath = path4.join(
1135
+ this.publicFolderPath = path5.join(
1066
1136
  this.rootPath,
1067
1137
  this.config.build.publicFolder
1068
1138
  );
1069
- this.outputFolderPath = path4.join(
1139
+ this.outputFolderPath = path5.join(
1070
1140
  this.publicFolderPath,
1071
1141
  this.config.build.outputFolder
1072
1142
  );
1073
- this.outputHTMLFilePath = path4.join(this.outputFolderPath, "index.html");
1074
- this.outputGitignorePath = path4.join(this.outputFolderPath, ".gitignore");
1143
+ this.outputHTMLFilePath = path5.join(this.outputFolderPath, "index.html");
1144
+ this.outputGitignorePath = path5.join(this.outputFolderPath, ".gitignore");
1075
1145
  this.contentRootPath = await resolveContentRootPath({
1076
1146
  rootPath: this.rootPath,
1077
1147
  tinaFolderPath: this.tinaFolderPath,
@@ -1079,17 +1149,17 @@ var ConfigManager = class {
1079
1149
  localContentPath: this.config.localContentPath
1080
1150
  });
1081
1151
  this.spaMainPath = require2.resolve("@tinacms/app");
1082
- this.spaRootPath = path4.join(this.spaMainPath, "..", "..");
1152
+ this.spaRootPath = path5.join(this.spaMainPath, "..", "..");
1083
1153
  }
1084
1154
  async getTinaFolderPath(rootPath) {
1085
- const tinaFolderPath = path4.join(rootPath, TINA_FOLDER);
1086
- const tinaFolderExists = await fs3.pathExists(tinaFolderPath);
1155
+ const tinaFolderPath = path5.join(rootPath, TINA_FOLDER);
1156
+ const tinaFolderExists = await fs4.pathExists(tinaFolderPath);
1087
1157
  if (tinaFolderExists) {
1088
1158
  this.isUsingLegacyFolder = false;
1089
1159
  return tinaFolderPath;
1090
1160
  }
1091
- const legacyFolderPath = path4.join(rootPath, LEGACY_TINA_FOLDER);
1092
- const legacyFolderExists = await fs3.pathExists(legacyFolderPath);
1161
+ const legacyFolderPath = path5.join(rootPath, LEGACY_TINA_FOLDER);
1162
+ const legacyFolderExists = await fs4.pathExists(legacyFolderPath);
1093
1163
  if (legacyFolderExists) {
1094
1164
  this.isUsingLegacyFolder = true;
1095
1165
  return legacyFolderPath;
@@ -1108,7 +1178,7 @@ var ConfigManager = class {
1108
1178
  patch: version2[2] || "x"
1109
1179
  };
1110
1180
  }
1111
- const generatedSchema = fs3.readJSONSync(this.generatedSchemaJSONPath);
1181
+ const generatedSchema = fs4.readJSONSync(this.generatedSchemaJSONPath);
1112
1182
  if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
1113
1183
  throw new Error(
1114
1184
  `Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
@@ -1119,40 +1189,40 @@ var ConfigManager = class {
1119
1189
  printGeneratedClientFilePath() {
1120
1190
  if (this.isUsingTs()) {
1121
1191
  return normalizePath2(
1122
- path4.relative(this.rootPath, this.generatedClientTSFilePath)
1192
+ path5.relative(this.rootPath, this.generatedClientTSFilePath)
1123
1193
  );
1124
1194
  }
1125
1195
  return normalizePath2(
1126
- path4.relative(this.rootPath, this.generatedClientJSFilePath)
1196
+ path5.relative(this.rootPath, this.generatedClientJSFilePath)
1127
1197
  );
1128
1198
  }
1129
1199
  printGeneratedTypesFilePath() {
1130
1200
  return normalizePath2(
1131
- path4.relative(this.rootPath, this.generatedTypesTSFilePath)
1201
+ path5.relative(this.rootPath, this.generatedTypesTSFilePath)
1132
1202
  );
1133
1203
  }
1134
1204
  printoutputHTMLFilePath() {
1135
1205
  return normalizePath2(
1136
- path4.relative(this.publicFolderPath, this.outputHTMLFilePath)
1206
+ path5.relative(this.publicFolderPath, this.outputHTMLFilePath)
1137
1207
  );
1138
1208
  }
1139
1209
  printRelativePath(filename) {
1140
1210
  if (filename) {
1141
- return normalizePath2(path4.relative(this.rootPath, filename));
1211
+ return normalizePath2(path5.relative(this.rootPath, filename));
1142
1212
  }
1143
1213
  throw `No path provided to print`;
1144
1214
  }
1145
1215
  printPrebuildFilePath() {
1146
1216
  return normalizePath2(
1147
- path4.relative(
1148
- path4.join(this.rootPath, this.tinaFolderPath),
1217
+ path5.relative(
1218
+ path5.join(this.rootPath, this.tinaFolderPath),
1149
1219
  this.prebuildFilePath
1150
1220
  )
1151
1221
  );
1152
1222
  }
1153
1223
  printContentRelativePath(filename) {
1154
1224
  if (filename) {
1155
- return normalizePath2(path4.relative(this.contentRootPath, filename));
1225
+ return normalizePath2(path5.relative(this.contentRootPath, filename));
1156
1226
  }
1157
1227
  throw `No path provided to print`;
1158
1228
  }
@@ -1168,7 +1238,7 @@ var ConfigManager = class {
1168
1238
  return;
1169
1239
  }
1170
1240
  const filepathWithExtension = `${filepath}.${ext}`;
1171
- const exists = fs3.existsSync(filepathWithExtension);
1241
+ const exists = fs4.existsSync(filepathWithExtension);
1172
1242
  if (exists) {
1173
1243
  result = filepathWithExtension;
1174
1244
  }
@@ -1177,41 +1247,34 @@ var ConfigManager = class {
1177
1247
  return result;
1178
1248
  }
1179
1249
  async loadDatabaseFile() {
1180
- const tmpdir = path4.join(os.tmpdir(), Date.now().toString());
1181
- const outfile = path4.join(tmpdir, "database.build.mjs");
1182
- await esbuild.build({
1183
- entryPoints: [this.selfHostedDatabaseFilePath],
1184
- bundle: true,
1185
- platform: "node",
1186
- format: "esm",
1187
- outfile,
1188
- loader: loaders,
1189
- // Provide a require() polyfill for ESM bundles containing CommonJS packages.
1190
- // Some bundled packages (e.g., 'scmp' used by 'mongodb-level') use require('crypto').
1191
- // When esbuild inlines these CommonJS packages, it keeps the require() calls,
1192
- // but ESM doesn't have a global require. This banner creates one using Node.js's
1193
- // official createRequire API, allowing the bundled CommonJS code to work in ESM.
1194
- banner: {
1195
- js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
1196
- }
1197
- });
1250
+ const buildDir = path5.join(this.generatedCachePath, "database");
1251
+ const outfile = path5.join(buildDir, "database.build.mjs");
1252
+ const external = resolveDatabaseExternals(this.config);
1253
+ await esbuild.build(
1254
+ buildDatabaseEsbuildConfig({
1255
+ entryPoint: this.selfHostedDatabaseFilePath,
1256
+ outfile,
1257
+ external,
1258
+ loader: loaders
1259
+ })
1260
+ );
1198
1261
  const result = await import(pathToFileURL(outfile).href);
1199
- fs3.removeSync(outfile);
1262
+ reapBuildSubdir(buildDir, this.generatedCachePath);
1200
1263
  return result.default;
1201
1264
  }
1202
1265
  async loadConfigFile(generatedFolderPath, configFilePath) {
1203
- const tmpdir = path4.join(os.tmpdir(), Date.now().toString());
1204
- const preBuildConfigPath = path4.join(
1266
+ const buildDir = path5.join(this.generatedCachePath, "config");
1267
+ const preBuildConfigPath = path5.join(
1205
1268
  this.generatedFolderPath,
1206
1269
  "config.prebuild.jsx"
1207
1270
  );
1208
- const outfile = path4.join(tmpdir, "config.build.jsx");
1209
- const outfile2 = path4.join(tmpdir, "config.build.mjs");
1210
- const tempTSConfigFile = path4.join(tmpdir, "tsconfig.json");
1271
+ const outfile = path5.join(buildDir, "config.build.jsx");
1272
+ const outfile2 = path5.join(buildDir, "config.build.mjs");
1273
+ const tempTSConfigFile = path5.join(buildDir, "tsconfig.json");
1211
1274
  const esmRequireBanner = {
1212
1275
  js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
1213
1276
  };
1214
- fs3.outputFileSync(tempTSConfigFile, "{}");
1277
+ fs4.outputFileSync(tempTSConfigFile, "{}");
1215
1278
  const result2 = await esbuild.build({
1216
1279
  entryPoints: [configFilePath],
1217
1280
  bundle: true,
@@ -1261,8 +1324,7 @@ var ConfigManager = class {
1261
1324
  console.error(e);
1262
1325
  throw e;
1263
1326
  }
1264
- fs3.removeSync(outfile);
1265
- fs3.removeSync(outfile2);
1327
+ reapBuildSubdir(buildDir, this.generatedCachePath);
1266
1328
  return {
1267
1329
  config: result.default,
1268
1330
  prebuildPath: preBuildConfigPath,
@@ -1387,7 +1449,7 @@ stack: ${code.stack || "No stack was provided"}`);
1387
1449
 
1388
1450
  // src/next/commands/baseCommands.ts
1389
1451
  import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
1390
- import fs4 from "fs-extra";
1452
+ import fs5 from "fs-extra";
1391
1453
  var BaseCommand = class extends Command {
1392
1454
  experimentalDataLayer = Option.Boolean("--experimentalData", {
1393
1455
  description: "DEPRECATED - Build the server with additional data querying capabilities"
@@ -1469,7 +1531,7 @@ var BaseCommand = class extends Command {
1469
1531
  const rootPath = configManager.rootPath;
1470
1532
  let sha;
1471
1533
  try {
1472
- sha = await getSha({ fs: fs4, dir: rootPath });
1534
+ sha = await getSha({ fs: fs5, dir: rootPath });
1473
1535
  } catch (e) {
1474
1536
  if (partialReindex) {
1475
1537
  console.error(
@@ -1479,7 +1541,7 @@ var BaseCommand = class extends Command {
1479
1541
  }
1480
1542
  }
1481
1543
  const lastSha = await database.getMetadata("lastSha");
1482
- const exists = lastSha && await shaExists({ fs: fs4, dir: rootPath, sha: lastSha });
1544
+ const exists = lastSha && await shaExists({ fs: fs5, dir: rootPath, sha: lastSha });
1483
1545
  let res;
1484
1546
  if (partialReindex && lastSha && exists && sha) {
1485
1547
  const pathFilter = {};
@@ -1494,14 +1556,14 @@ var BaseCommand = class extends Command {
1494
1556
  };
1495
1557
  }
1496
1558
  const { added, modified, deleted } = await getChangedFiles({
1497
- fs: fs4,
1559
+ fs: fs5,
1498
1560
  dir: rootPath,
1499
1561
  from: lastSha,
1500
1562
  to: sha,
1501
1563
  pathFilter
1502
1564
  });
1503
1565
  const tinaPathUpdates = modified.filter(
1504
- (path17) => path17.startsWith(".tina/__generated__/_schema.json") || path17.startsWith("tina/tina-lock.json")
1566
+ (path18) => path18.startsWith(".tina/__generated__/_schema.json") || path18.startsWith("tina/tina-lock.json")
1505
1567
  );
1506
1568
  if (tinaPathUpdates.length > 0) {
1507
1569
  res = await database.indexContent({
@@ -1620,9 +1682,9 @@ var devHTML = (port) => `<!DOCTYPE html>
1620
1682
  import { createServer as createViteServer } from "vite";
1621
1683
 
1622
1684
  // src/next/vite/index.ts
1623
- import path6 from "node:path";
1685
+ import path7 from "node:path";
1624
1686
  import react from "@vitejs/plugin-react";
1625
- import fs5 from "fs-extra";
1687
+ import fs6 from "fs-extra";
1626
1688
  import normalizePath3 from "normalize-path";
1627
1689
  import {
1628
1690
  splitVendorChunkPlugin
@@ -1689,7 +1751,7 @@ function filterPublicEnv(env = process.env) {
1689
1751
  }
1690
1752
 
1691
1753
  // src/next/vite/tailwind.ts
1692
- import path5 from "node:path";
1754
+ import path6 from "node:path";
1693
1755
  import aspectRatio from "@tailwindcss/aspect-ratio";
1694
1756
  import containerQueries from "@tailwindcss/container-queries";
1695
1757
  import twTypography from "@tailwindcss/typography";
@@ -1704,7 +1766,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
1704
1766
  const require2 = createRequire2(import.meta.url);
1705
1767
  const plugins = [];
1706
1768
  const content = [
1707
- path5.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
1769
+ path6.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
1708
1770
  prebuildFilePath,
1709
1771
  require2.resolve("tinacms")
1710
1772
  ];
@@ -1968,35 +2030,35 @@ async function listFilesRecursively({
1968
2030
  config: config2,
1969
2031
  roothPath
1970
2032
  }) {
1971
- const fullDirectoryPath = path6.join(
2033
+ const fullDirectoryPath = path7.join(
1972
2034
  roothPath,
1973
2035
  config2.publicFolder,
1974
2036
  directoryPath
1975
2037
  );
1976
- const exists = await fs5.pathExists(fullDirectoryPath);
2038
+ const exists = await fs6.pathExists(fullDirectoryPath);
1977
2039
  if (!exists) {
1978
2040
  return { "0": [] };
1979
2041
  }
1980
- const items = await fs5.readdir(fullDirectoryPath);
2042
+ const items = await fs6.readdir(fullDirectoryPath);
1981
2043
  const staticMediaItems = [];
1982
2044
  for (const item of items) {
1983
- const itemPath = path6.join(fullDirectoryPath, item);
1984
- const stats = await fs5.promises.lstat(itemPath);
2045
+ const itemPath = path7.join(fullDirectoryPath, item);
2046
+ const stats = await fs6.promises.lstat(itemPath);
1985
2047
  const staticMediaItem = {
1986
2048
  id: item,
1987
2049
  filename: item,
1988
2050
  type: stats.isDirectory() ? "dir" : "file",
1989
2051
  directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
1990
- src: `/${path6.join(directoryPath, item)}`,
2052
+ src: `/${path7.join(directoryPath, item)}`,
1991
2053
  thumbnails: {
1992
- "75x75": `/${path6.join(directoryPath, item)}`,
1993
- "400x400": `/${path6.join(directoryPath, item)}`,
1994
- "1000x1000": `/${path6.join(directoryPath, item)}`
2054
+ "75x75": `/${path7.join(directoryPath, item)}`,
2055
+ "400x400": `/${path7.join(directoryPath, item)}`,
2056
+ "1000x1000": `/${path7.join(directoryPath, item)}`
1995
2057
  }
1996
2058
  };
1997
2059
  if (stats.isDirectory()) {
1998
2060
  staticMediaItem.children = await listFilesRecursively({
1999
- directoryPath: path6.join(directoryPath, item),
2061
+ directoryPath: path7.join(directoryPath, item),
2000
2062
  config: config2,
2001
2063
  roothPath
2002
2064
  });
@@ -2021,7 +2083,7 @@ var createConfig = async ({
2021
2083
  rollupOptions
2022
2084
  }) => {
2023
2085
  const publicEnv = filterPublicEnv();
2024
- const staticMediaPath = path6.join(
2086
+ const staticMediaPath = path7.join(
2025
2087
  configManager.generatedFolderPath,
2026
2088
  "static-media.json"
2027
2089
  );
@@ -2031,21 +2093,21 @@ var createConfig = async ({
2031
2093
  config: configManager.config.media.tina,
2032
2094
  roothPath: configManager.rootPath
2033
2095
  });
2034
- await fs5.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
2096
+ await fs6.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
2035
2097
  } else {
2036
- await fs5.outputFile(staticMediaPath, `[]`);
2098
+ await fs6.outputFile(staticMediaPath, `[]`);
2037
2099
  }
2038
2100
  const alias = {
2039
2101
  TINA_IMPORT: configManager.prebuildFilePath,
2040
2102
  SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
2041
2103
  STATIC_MEDIA_IMPORT: staticMediaPath,
2042
- crypto: path6.join(configManager.spaRootPath, "src", "dummy-client.ts"),
2043
- fs: path6.join(configManager.spaRootPath, "src", "dummy-client.ts"),
2044
- os: path6.join(configManager.spaRootPath, "src", "dummy-client.ts"),
2045
- path: path6.join(configManager.spaRootPath, "src", "dummy-client.ts")
2104
+ crypto: path7.join(configManager.spaRootPath, "src", "dummy-client.ts"),
2105
+ fs: path7.join(configManager.spaRootPath, "src", "dummy-client.ts"),
2106
+ os: path7.join(configManager.spaRootPath, "src", "dummy-client.ts"),
2107
+ path: path7.join(configManager.spaRootPath, "src", "dummy-client.ts")
2046
2108
  };
2047
2109
  if (configManager.shouldSkipSDK()) {
2048
- alias["CLIENT_IMPORT"] = path6.join(
2110
+ alias["CLIENT_IMPORT"] = path7.join(
2049
2111
  configManager.spaRootPath,
2050
2112
  "src",
2051
2113
  "dummy-client.ts"
@@ -2155,8 +2217,8 @@ var createConfig = async ({
2155
2217
  };
2156
2218
 
2157
2219
  // src/next/vite/plugins.ts
2158
- import fs7 from "fs";
2159
- import path8 from "path";
2220
+ import fs8 from "fs";
2221
+ import path9 from "path";
2160
2222
  import { createFilter } from "@rollup/pluginutils";
2161
2223
  import { resolve as gqlResolve } from "@tinacms/graphql";
2162
2224
  import bodyParser from "body-parser";
@@ -2165,11 +2227,11 @@ import { transform as esbuildTransform } from "esbuild";
2165
2227
  import { transformWithEsbuild } from "vite";
2166
2228
 
2167
2229
  // src/next/commands/dev-command/server/media.ts
2168
- import path7, { join } from "path";
2230
+ import path8, { join } from "path";
2169
2231
  import busboy from "busboy";
2170
- import fs6 from "fs-extra";
2232
+ import fs7 from "fs-extra";
2171
2233
  var createMediaRouter = (config2) => {
2172
- const mediaFolder = path7.join(
2234
+ const mediaFolder = path8.join(
2173
2235
  config2.rootPath,
2174
2236
  config2.publicFolder,
2175
2237
  config2.mediaRoot
@@ -2233,8 +2295,8 @@ var createMediaRouter = (config2) => {
2233
2295
  );
2234
2296
  return;
2235
2297
  }
2236
- await fs6.ensureDir(path7.dirname(saveTo));
2237
- file.pipe(fs6.createWriteStream(saveTo));
2298
+ await fs7.ensureDir(path8.dirname(saveTo));
2299
+ file.pipe(fs7.createWriteStream(saveTo));
2238
2300
  });
2239
2301
  bb.on("error", (error) => {
2240
2302
  responded = true;
@@ -2264,18 +2326,18 @@ var parseMediaFolder = (str) => {
2264
2326
  var ENCODED_TRAVERSAL_RE = /%2e%2e|%2f|%5c/i;
2265
2327
  function resolveRealPath(candidate) {
2266
2328
  try {
2267
- return fs6.realpathSync(candidate);
2329
+ return fs7.realpathSync(candidate);
2268
2330
  } catch {
2269
- const parent = path7.dirname(candidate);
2331
+ const parent = path8.dirname(candidate);
2270
2332
  if (parent === candidate) return candidate;
2271
- return path7.join(resolveRealPath(parent), path7.basename(candidate));
2333
+ return path8.join(resolveRealPath(parent), path8.basename(candidate));
2272
2334
  }
2273
2335
  }
2274
2336
  function assertSymlinkWithinBase(resolved, resolvedBase, userPath) {
2275
2337
  try {
2276
- const realBase = fs6.realpathSync(resolvedBase);
2338
+ const realBase = fs7.realpathSync(resolvedBase);
2277
2339
  const realResolved = resolveRealPath(resolved);
2278
- if (realResolved !== realBase && !realResolved.startsWith(realBase + path7.sep)) {
2340
+ if (realResolved !== realBase && !realResolved.startsWith(realBase + path8.sep)) {
2279
2341
  throw new PathTraversalError(userPath);
2280
2342
  }
2281
2343
  } catch (err) {
@@ -2286,13 +2348,13 @@ function resolveWithinBase(userPath, baseDir) {
2286
2348
  if (ENCODED_TRAVERSAL_RE.test(userPath)) {
2287
2349
  throw new PathTraversalError(userPath);
2288
2350
  }
2289
- const resolvedBase = path7.resolve(baseDir);
2290
- const resolved = path7.resolve(path7.join(baseDir, userPath));
2351
+ const resolvedBase = path8.resolve(baseDir);
2352
+ const resolved = path8.resolve(path8.join(baseDir, userPath));
2291
2353
  if (resolved === resolvedBase) {
2292
2354
  assertSymlinkWithinBase(resolved, resolvedBase, userPath);
2293
2355
  return resolvedBase;
2294
2356
  }
2295
- if (resolved.startsWith(resolvedBase + path7.sep)) {
2357
+ if (resolved.startsWith(resolvedBase + path8.sep)) {
2296
2358
  assertSymlinkWithinBase(resolved, resolvedBase, userPath);
2297
2359
  return resolved;
2298
2360
  }
@@ -2302,12 +2364,12 @@ function resolveStrictlyWithinBase(userPath, baseDir) {
2302
2364
  if (ENCODED_TRAVERSAL_RE.test(userPath)) {
2303
2365
  throw new PathTraversalError(userPath);
2304
2366
  }
2305
- const resolvedBase = path7.resolve(baseDir) + path7.sep;
2306
- const resolved = path7.resolve(path7.join(baseDir, userPath));
2367
+ const resolvedBase = path8.resolve(baseDir) + path8.sep;
2368
+ const resolved = path8.resolve(path8.join(baseDir, userPath));
2307
2369
  if (!resolved.startsWith(resolvedBase)) {
2308
2370
  throw new PathTraversalError(userPath);
2309
2371
  }
2310
- assertSymlinkWithinBase(resolved, path7.resolve(baseDir), userPath);
2372
+ assertSymlinkWithinBase(resolved, path8.resolve(baseDir), userPath);
2311
2373
  return resolved;
2312
2374
  }
2313
2375
  var MediaModel = class {
@@ -2324,16 +2386,16 @@ var MediaModel = class {
2324
2386
  const mediaBase = join(this.rootPath, this.publicFolder, this.mediaRoot);
2325
2387
  const validatedPath = resolveWithinBase(args.searchPath, mediaBase);
2326
2388
  const searchPath = parseMediaFolder(args.searchPath);
2327
- if (!await fs6.pathExists(validatedPath)) {
2389
+ if (!await fs7.pathExists(validatedPath)) {
2328
2390
  return {
2329
2391
  files: [],
2330
2392
  directories: []
2331
2393
  };
2332
2394
  }
2333
- const filesStr = await fs6.readdir(validatedPath);
2395
+ const filesStr = await fs7.readdir(validatedPath);
2334
2396
  const filesProm = filesStr.map(async (file) => {
2335
2397
  const filePath = join(validatedPath, file);
2336
- const stat = await fs6.stat(filePath);
2398
+ const stat = await fs7.stat(filePath);
2337
2399
  let src = `/${file}`;
2338
2400
  const isFile = stat.isFile();
2339
2401
  if (!isFile) {
@@ -2392,8 +2454,8 @@ var MediaModel = class {
2392
2454
  try {
2393
2455
  const mediaBase = join(this.rootPath, this.publicFolder, this.mediaRoot);
2394
2456
  const file = resolveStrictlyWithinBase(args.searchPath, mediaBase);
2395
- await fs6.stat(file);
2396
- await fs6.remove(file);
2457
+ await fs7.stat(file);
2458
+ await fs7.remove(file);
2397
2459
  return { ok: true };
2398
2460
  } catch (error) {
2399
2461
  if (error instanceof PathTraversalError) throw error;
@@ -2501,7 +2563,7 @@ var transformTsxPlugin = ({
2501
2563
  const plug = {
2502
2564
  name: "transform-tsx",
2503
2565
  async transform(code, id) {
2504
- const extName = path8.extname(id);
2566
+ const extName = path9.extname(id);
2505
2567
  if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
2506
2568
  const result = await esbuildTransform(code, { loader: "tsx" });
2507
2569
  return {
@@ -2612,7 +2674,7 @@ function viteTransformExtension({
2612
2674
  async transform(code, id) {
2613
2675
  if (filter(id)) {
2614
2676
  const { transform: transform2 } = await import("@svgr/core");
2615
- const svgCode = await fs7.promises.readFile(
2677
+ const svgCode = await fs8.promises.readFile(
2616
2678
  id.replace(/\?.*$/, ""),
2617
2679
  "utf8"
2618
2680
  );
@@ -2704,7 +2766,7 @@ var DevCommand = class extends BaseCommand {
2704
2766
  ]
2705
2767
  });
2706
2768
  async catch(error) {
2707
- logger.error("Error occured during tinacms dev");
2769
+ logger.error("Error occurred during tinacms dev");
2708
2770
  console.error(error);
2709
2771
  process.exit(1);
2710
2772
  }
@@ -2762,13 +2824,13 @@ var DevCommand = class extends BaseCommand {
2762
2824
  });
2763
2825
  const apiURL2 = await codegen2.execute();
2764
2826
  if (!configManager.isUsingLegacyFolder) {
2765
- const schemaObject = await fs8.readJSON(
2827
+ const schemaObject = await fs9.readJSON(
2766
2828
  configManager.generatedSchemaJSONPath
2767
2829
  );
2768
- const lookupObject = await fs8.readJSON(
2830
+ const lookupObject = await fs9.readJSON(
2769
2831
  configManager.generatedLookupJSONPath
2770
2832
  );
2771
- const graphqlSchemaObject = await fs8.readJSON(
2833
+ const graphqlSchemaObject = await fs9.readJSON(
2772
2834
  configManager.generatedGraphQLJSONPath
2773
2835
  );
2774
2836
  const tinaLockFilename = "tina-lock.json";
@@ -2777,8 +2839,8 @@ var DevCommand = class extends BaseCommand {
2777
2839
  lookup: lookupObject,
2778
2840
  graphql: graphqlSchemaObject
2779
2841
  });
2780
- fs8.writeFileSync(
2781
- path9.join(configManager.tinaFolderPath, tinaLockFilename),
2842
+ fs9.writeFileSync(
2843
+ path10.join(configManager.tinaFolderPath, tinaLockFilename),
2782
2844
  tinaLockContent
2783
2845
  );
2784
2846
  }
@@ -2822,8 +2884,8 @@ ${dangerText(e.message)}
2822
2884
  const { apiURL, graphQLSchema, tinaSchema } = await setup({
2823
2885
  firstTime: true
2824
2886
  });
2825
- await fs8.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
2826
- await fs8.outputFile(
2887
+ await fs9.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
2888
+ await fs9.outputFile(
2827
2889
  configManager.outputGitignorePath,
2828
2890
  "index.html\nassets/"
2829
2891
  );
@@ -2968,7 +3030,7 @@ ${dangerText(e.message)}
2968
3030
  watchContentFiles(configManager, database, databaseLock, searchIndexer) {
2969
3031
  const collectionContentFiles = [];
2970
3032
  configManager.config.schema.collections.forEach((collection) => {
2971
- const collectionGlob = `${path9.join(
3033
+ const collectionGlob = `${path10.join(
2972
3034
  configManager.contentRootPath,
2973
3035
  collection.path
2974
3036
  )}/**/*.${collection.format || "md"}`;
@@ -3018,17 +3080,16 @@ ${dangerText(e.message)}
3018
3080
 
3019
3081
  // src/next/commands/build-command/index.ts
3020
3082
  import crypto from "crypto";
3021
- import path10 from "path";
3083
+ import path11 from "path";
3022
3084
  import { diff } from "@graphql-inspector/core";
3023
3085
  import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
3024
- import { Telemetry as Telemetry2 } from "@tinacms/metrics";
3025
3086
  import { parseURL as parseURL2 } from "@tinacms/schema-tools";
3026
3087
  import {
3027
3088
  SearchIndexer as SearchIndexer2,
3028
3089
  TinaCMSSearchIndexClient
3029
3090
  } from "@tinacms/search";
3030
3091
  import { Command as Command3, Option as Option3 } from "clipanion";
3031
- import fs9 from "fs-extra";
3092
+ import fs10 from "fs-extra";
3032
3093
  import {
3033
3094
  buildASTSchema as buildASTSchema2,
3034
3095
  buildClientSchema,
@@ -3165,6 +3226,75 @@ var waitForDB = async (config2, apiUrl, previewName, verbose) => {
3165
3226
  });
3166
3227
  };
3167
3228
 
3229
+ // src/utils/posthog.ts
3230
+ import { randomUUID } from "node:crypto";
3231
+ import { PostHog } from "posthog-node";
3232
+
3233
+ // src/utils/fetchPostHogConfig.ts
3234
+ async function fetchPostHogConfig(endpointUrl) {
3235
+ try {
3236
+ const response = await fetch(endpointUrl, {
3237
+ method: "GET",
3238
+ headers: {
3239
+ "Content-Type": "application/json"
3240
+ },
3241
+ // Cap latency for offline / firewalled developers. Endpoint is
3242
+ // typically single-digit ms when reachable; a timeout returns {}
3243
+ // and disables telemetry for this run, which is the right behavior.
3244
+ signal: AbortSignal.timeout(2e3)
3245
+ });
3246
+ if (!response.ok) {
3247
+ throw new Error(`Failed to fetch PostHog config: ${response.statusText}`);
3248
+ }
3249
+ const config2 = await response.json();
3250
+ return {
3251
+ POSTHOG_API_KEY: config2.api_key,
3252
+ POSTHOG_ENDPOINT: config2.host
3253
+ };
3254
+ } catch {
3255
+ return {};
3256
+ }
3257
+ }
3258
+
3259
+ // src/utils/posthog.ts
3260
+ function generateSessionId() {
3261
+ return randomUUID();
3262
+ }
3263
+ var BuildInvokeEvent = "tinacms-cli-build-invoke";
3264
+ var BuildFinishedEvent = "tinacms-cli-build-finished";
3265
+ async function initializePostHog(configEndpoint, disableGeoip) {
3266
+ if (process.env.TINA_DEV === "true") return null;
3267
+ let apiKey;
3268
+ let endpoint;
3269
+ if (configEndpoint) {
3270
+ const config2 = await fetchPostHogConfig(configEndpoint);
3271
+ apiKey = config2.POSTHOG_API_KEY;
3272
+ endpoint = config2.POSTHOG_ENDPOINT;
3273
+ }
3274
+ if (!apiKey) return null;
3275
+ return new PostHog(apiKey, {
3276
+ host: endpoint,
3277
+ disableGeoip: disableGeoip ?? true
3278
+ });
3279
+ }
3280
+ function postHogCapture(client, distinctId, event, properties) {
3281
+ if (!client) {
3282
+ return;
3283
+ }
3284
+ try {
3285
+ client.capture({
3286
+ distinctId,
3287
+ event,
3288
+ properties: {
3289
+ ...properties,
3290
+ system: "tinacms/cli"
3291
+ }
3292
+ });
3293
+ } catch (error) {
3294
+ console.error("Error capturing event:", error);
3295
+ }
3296
+ }
3297
+
3168
3298
  // src/next/commands/build-command/index.ts
3169
3299
  var BuildCommand = class extends BaseCommand {
3170
3300
  static paths = [["build"]];
@@ -3208,7 +3338,17 @@ var BuildCommand = class extends BaseCommand {
3208
3338
  category: `Commands`,
3209
3339
  description: `Build the CMS and autogenerated modules for usage with TinaCloud`
3210
3340
  });
3341
+ posthogClient = null;
3342
+ buildStartedAt = 0;
3343
+ buildRunId = generateSessionId();
3211
3344
  async catch(error) {
3345
+ const errorCode = error?.errorCode ?? "ERR_BUILD_FAILED";
3346
+ postHogCapture(this.posthogClient, this.buildRunId, BuildFinishedEvent, {
3347
+ success: false,
3348
+ durationMs: Date.now() - this.buildStartedAt,
3349
+ errorCode
3350
+ });
3351
+ if (this.posthogClient) await this.posthogClient.shutdown();
3212
3352
  console.error(error);
3213
3353
  process.exit(1);
3214
3354
  }
@@ -3245,6 +3385,27 @@ var BuildCommand = class extends BaseCommand {
3245
3385
  process.exit(1);
3246
3386
  }
3247
3387
  const localContentOnly = this.contentOption === "local";
3388
+ this.posthogClient = this.noTelemetry ? null : await initializePostHog(
3389
+ "https://identity-v2.tinajs.io/v2/posthog-token",
3390
+ false
3391
+ );
3392
+ const buildInvokeEventPayload = {
3393
+ hasLocalOption: Boolean(this.localOption),
3394
+ hasContentLocal: localContentOnly,
3395
+ skipIndexing: Boolean(this.skipIndexing),
3396
+ partialReindex: Boolean(this.partialReindex),
3397
+ hasPreviewName: Boolean(this.previewName),
3398
+ specifiesTinaGraphQLVersions: Boolean(this.tinaGraphQLVersion),
3399
+ skipCloudChecks: Boolean(this.skipCloudChecks),
3400
+ skipSearchIndex: Boolean(this.skipSearchIndex)
3401
+ };
3402
+ this.buildStartedAt = Date.now();
3403
+ postHogCapture(
3404
+ this.posthogClient,
3405
+ this.buildRunId,
3406
+ BuildInvokeEvent,
3407
+ buildInvokeEventPayload
3408
+ );
3248
3409
  try {
3249
3410
  await configManager.processConfig();
3250
3411
  } catch (e) {
@@ -3253,15 +3414,10 @@ ${dangerText(e.message)}`);
3253
3414
  logger.error(
3254
3415
  dangerText("Unable to build, please fix your Tina config and try again")
3255
3416
  );
3256
- process.exit(1);
3417
+ throw Object.assign(new Error(e.message), {
3418
+ errorCode: "ERR_CONFIG_LOAD_FAILED"
3419
+ });
3257
3420
  }
3258
- const telemetry = new Telemetry2({ disabled: this.noTelemetry });
3259
- await telemetry.submitRecord({
3260
- event: {
3261
- name: "tinacms:cli:build:invoke",
3262
- hasLocalContentPath: Boolean(configManager.config.localContentPath)
3263
- }
3264
- });
3265
3421
  if (localContentOnly && !this.localOption) {
3266
3422
  const config2 = configManager.config;
3267
3423
  const missing = [];
@@ -3269,12 +3425,11 @@ ${dangerText(e.message)}`);
3269
3425
  if (!config2.clientId) missing.push("clientId");
3270
3426
  if (!config2.token) missing.push("token");
3271
3427
  if (missing.length > 0) {
3272
- logger.error(
3273
- `${dangerText(
3274
- `ERROR: --content=local requires ${missing.join(", ")} to be configured, since the generated client must point to TinaCloud.`
3275
- )}`
3276
- );
3277
- process.exit(1);
3428
+ const message = `--content=local requires ${missing.join(", ")} to be configured, since the generated client must point to TinaCloud.`;
3429
+ logger.error(`${dangerText(`ERROR: ${message}`)}`);
3430
+ throw Object.assign(new Error(message), {
3431
+ errorCode: "ERR_MISSING_CLOUD_CREDS"
3432
+ });
3278
3433
  }
3279
3434
  }
3280
3435
  let server;
@@ -3317,7 +3472,9 @@ ${dangerText(e.message)}
3317
3472
  if (this.verbose) {
3318
3473
  console.error(e);
3319
3474
  }
3320
- process.exit(1);
3475
+ throw Object.assign(new Error(e.message), {
3476
+ errorCode: "ERR_INDEXING_FAILED"
3477
+ });
3321
3478
  }
3322
3479
  }
3323
3480
  if (this.localOption || localContentOnly) {
@@ -3390,11 +3547,13 @@ ${dangerText(e.message)}
3390
3547
  if (this.verbose) {
3391
3548
  console.error(e);
3392
3549
  }
3393
- process.exit(1);
3550
+ throw Object.assign(new Error(e.message), {
3551
+ errorCode: "ERR_CLOUD_CHECK_FAILED"
3552
+ });
3394
3553
  }
3395
3554
  }
3396
3555
  await buildProductionSpa(configManager, database, codegen2.productionUrl);
3397
- await fs9.outputFile(
3556
+ await fs10.outputFile(
3398
3557
  configManager.outputGitignorePath,
3399
3558
  "index.html\nassets/"
3400
3559
  );
@@ -3462,7 +3621,9 @@ ${dangerText(e.message)}
3462
3621
  });
3463
3622
  if (err) {
3464
3623
  logger.error(`${dangerText(`ERROR: ${err.message}`)}`);
3465
- process.exit(1);
3624
+ throw Object.assign(new Error(err.message), {
3625
+ errorCode: "ERR_SEARCH_INDEX_FAILED"
3626
+ });
3466
3627
  }
3467
3628
  }
3468
3629
  const summaryItems = [];
@@ -3508,6 +3669,11 @@ ${dangerText(e.message)}
3508
3669
  process.env.NODE_ENV = "production";
3509
3670
  }
3510
3671
  }
3672
+ postHogCapture(this.posthogClient, this.buildRunId, BuildFinishedEvent, {
3673
+ success: true,
3674
+ durationMs: Date.now() - this.buildStartedAt
3675
+ });
3676
+ if (this.posthogClient) await this.posthogClient.shutdown();
3511
3677
  if (this.subCommand) {
3512
3678
  await this.startSubCommand();
3513
3679
  } else {
@@ -3772,7 +3938,7 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3772
3938
  }
3773
3939
  const localTinaSchema = JSON.parse(
3774
3940
  await database.bridge.get(
3775
- path10.join(database.tinaDirectory, "__generated__", "_schema.json")
3941
+ path11.join(database.tinaDirectory, "__generated__", "_schema.json")
3776
3942
  )
3777
3943
  );
3778
3944
  localTinaSchema.version = void 0;
@@ -3892,7 +4058,7 @@ import { buildSchema as buildSchema3 } from "@tinacms/graphql";
3892
4058
 
3893
4059
  // src/next/commands/audit-command/audit.ts
3894
4060
  import prompts from "prompts";
3895
- import { Telemetry as Telemetry3 } from "@tinacms/metrics";
4061
+ import { Telemetry as Telemetry2 } from "@tinacms/metrics";
3896
4062
  import { resolve } from "@tinacms/graphql";
3897
4063
  import chalk5 from "chalk";
3898
4064
  var audit = async ({
@@ -3902,7 +4068,7 @@ var audit = async ({
3902
4068
  noTelemetry,
3903
4069
  verbose
3904
4070
  }) => {
3905
- const telemetry = new Telemetry3({ disabled: noTelemetry });
4071
+ const telemetry = new Telemetry2({ disabled: noTelemetry });
3906
4072
  await telemetry.submitRecord({
3907
4073
  event: {
3908
4074
  name: "tinacms:cli:audit:invoke",
@@ -4078,7 +4244,7 @@ var AuditCommand = class extends Command4 {
4078
4244
  description: `Audit config and content files`
4079
4245
  });
4080
4246
  async catch(error) {
4081
- logger.error("Error occured during tinacms audit");
4247
+ logger.error("Error occurred during tinacms audit");
4082
4248
  if (this.verbose) {
4083
4249
  console.error(error);
4084
4250
  }
@@ -4135,26 +4301,26 @@ var AuditCommand = class extends Command4 {
4135
4301
  import { Command as Command6, Option as Option6 } from "clipanion";
4136
4302
 
4137
4303
  // src/cmds/init/detectEnvironment.ts
4138
- import fs10 from "fs-extra";
4139
- import path11 from "path";
4304
+ import fs11 from "fs-extra";
4305
+ import path12 from "path";
4140
4306
  var checkGitignoreForItem = async ({
4141
4307
  baseDir,
4142
4308
  line
4143
4309
  }) => {
4144
- const gitignoreContent = fs10.readFileSync(path11.join(baseDir, ".gitignore")).toString();
4310
+ const gitignoreContent = fs11.readFileSync(path12.join(baseDir, ".gitignore")).toString();
4145
4311
  return gitignoreContent.split("\n").some((item) => item === line);
4146
4312
  };
4147
4313
  var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
4148
4314
  const result = {
4149
- fullPathTS: path11.join(
4315
+ fullPathTS: path12.join(
4150
4316
  parentPath,
4151
4317
  `${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
4152
4318
  ),
4153
- fullPathJS: path11.join(
4319
+ fullPathJS: path12.join(
4154
4320
  parentPath,
4155
4321
  `${name2}.${opts?.extensionOverride || "js"}`
4156
4322
  ),
4157
- fullPathOverride: opts?.extensionOverride ? path11.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
4323
+ fullPathOverride: opts?.extensionOverride ? path12.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
4158
4324
  generatedFileType,
4159
4325
  name: name2,
4160
4326
  parentPath,
@@ -4172,8 +4338,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
4172
4338
  };
4173
4339
  }
4174
4340
  };
4175
- result.typescriptExists = await fs10.pathExists(result.fullPathTS);
4176
- result.javascriptExists = await fs10.pathExists(result.fullPathJS);
4341
+ result.typescriptExists = await fs11.pathExists(result.fullPathTS);
4342
+ result.javascriptExists = await fs11.pathExists(result.fullPathJS);
4177
4343
  return result;
4178
4344
  };
4179
4345
  var detectEnvironment = async ({
@@ -4182,21 +4348,21 @@ var detectEnvironment = async ({
4182
4348
  rootPath,
4183
4349
  debug = false
4184
4350
  }) => {
4185
- const hasForestryConfig = await fs10.pathExists(
4186
- path11.join(pathToForestryConfig, ".forestry", "settings.yml")
4351
+ const hasForestryConfig = await fs11.pathExists(
4352
+ path12.join(pathToForestryConfig, ".forestry", "settings.yml")
4187
4353
  );
4188
- const sampleContentPath = path11.join(
4354
+ const sampleContentPath = path12.join(
4189
4355
  baseDir,
4190
4356
  "content",
4191
4357
  "posts",
4192
4358
  "hello-world.md"
4193
4359
  );
4194
- const usingSrc = fs10.pathExistsSync(path11.join(baseDir, "src")) && (fs10.pathExistsSync(path11.join(baseDir, "src", "app")) || fs10.pathExistsSync(path11.join(baseDir, "src", "pages")));
4195
- const tinaFolder = path11.join(baseDir, "tina");
4360
+ const usingSrc = fs11.pathExistsSync(path12.join(baseDir, "src")) && (fs11.pathExistsSync(path12.join(baseDir, "src", "app")) || fs11.pathExistsSync(path12.join(baseDir, "src", "pages")));
4361
+ const tinaFolder = path12.join(baseDir, "tina");
4196
4362
  const tinaConfigExists = Boolean(
4197
4363
  // Does the tina folder exist?
4198
- await fs10.pathExists(tinaFolder) && // Does the tina folder contain a config file?
4199
- (await fs10.readdir(tinaFolder)).find((x) => x.includes("config"))
4364
+ await fs11.pathExists(tinaFolder) && // Does the tina folder contain a config file?
4365
+ (await fs11.readdir(tinaFolder)).find((x) => x.includes("config"))
4200
4366
  );
4201
4367
  const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
4202
4368
  Boolean
@@ -4208,12 +4374,12 @@ var detectEnvironment = async ({
4208
4374
  "next-api-handler": await makeGeneratedFile(
4209
4375
  "[...routes]",
4210
4376
  "next-api-handler",
4211
- path11.join(...pagesDir, "api", "tina")
4377
+ path12.join(...pagesDir, "api", "tina")
4212
4378
  ),
4213
4379
  "reactive-example": await makeGeneratedFile(
4214
4380
  "[filename]",
4215
4381
  "reactive-example",
4216
- path11.join(...pagesDir, "demo", "blog"),
4382
+ path12.join(...pagesDir, "demo", "blog"),
4217
4383
  {
4218
4384
  typescriptSuffix: "tsx"
4219
4385
  }
@@ -4221,22 +4387,22 @@ var detectEnvironment = async ({
4221
4387
  "users-json": await makeGeneratedFile(
4222
4388
  "index",
4223
4389
  "users-json",
4224
- path11.join(baseDir, "content", "users"),
4390
+ path12.join(baseDir, "content", "users"),
4225
4391
  { extensionOverride: "json" }
4226
4392
  ),
4227
4393
  "sample-content": await makeGeneratedFile(
4228
4394
  "hello-world",
4229
4395
  "sample-content",
4230
- path11.join(baseDir, "content", "posts"),
4396
+ path12.join(baseDir, "content", "posts"),
4231
4397
  { extensionOverride: "md" }
4232
4398
  )
4233
4399
  };
4234
- const hasSampleContent = await fs10.pathExists(sampleContentPath);
4235
- const hasPackageJSON = await fs10.pathExists("package.json");
4400
+ const hasSampleContent = await fs11.pathExists(sampleContentPath);
4401
+ const hasPackageJSON = await fs11.pathExists("package.json");
4236
4402
  let hasTinaDeps = false;
4237
4403
  if (hasPackageJSON) {
4238
4404
  try {
4239
- const packageJSON = await fs10.readJSON("package.json");
4405
+ const packageJSON = await fs11.readJSON("package.json");
4240
4406
  const deps = [];
4241
4407
  if (packageJSON?.dependencies) {
4242
4408
  deps.push(...Object.keys(packageJSON.dependencies));
@@ -4253,15 +4419,19 @@ var detectEnvironment = async ({
4253
4419
  );
4254
4420
  }
4255
4421
  }
4256
- const hasGitIgnore = await fs10.pathExists(path11.join(".gitignore"));
4422
+ const hasGitIgnore = await fs11.pathExists(path12.join(".gitignore"));
4257
4423
  const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
4258
4424
  const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
4259
4425
  const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
4426
+ const hasGitIgnoreTinaGenerated = hasGitIgnore && await checkGitignoreForItem({
4427
+ baseDir,
4428
+ line: "tina/__generated__"
4429
+ });
4260
4430
  let frontMatterFormat;
4261
4431
  if (hasForestryConfig) {
4262
- const hugoConfigPath = path11.join(rootPath, "config.toml");
4263
- if (await fs10.pathExists(hugoConfigPath)) {
4264
- const hugoConfig = await fs10.readFile(hugoConfigPath, "utf8");
4432
+ const hugoConfigPath = path12.join(rootPath, "config.toml");
4433
+ if (await fs11.pathExists(hugoConfigPath)) {
4434
+ const hugoConfig = await fs11.readFile(hugoConfigPath, "utf8");
4265
4435
  const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
4266
4436
  if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
4267
4437
  frontMatterFormat = metaDataFormat;
@@ -4275,6 +4445,7 @@ var detectEnvironment = async ({
4275
4445
  gitIgnoreNodeModulesExists: hasGitIgnoreNodeModules,
4276
4446
  gitIgnoreEnvExists: hasGitIgnoreEnv,
4277
4447
  gitIgnoreTinaEnvExists: hasEnvTina,
4448
+ gitIgnoreTinaGeneratedExists: hasGitIgnoreTinaGenerated,
4278
4449
  packageJSONExists: hasPackageJSON,
4279
4450
  sampleContentExists: hasSampleContent,
4280
4451
  sampleContentPath,
@@ -4874,19 +5045,19 @@ var CLICommand = class {
4874
5045
  };
4875
5046
 
4876
5047
  // src/cmds/init/apply.ts
4877
- import path15 from "path";
5048
+ import path16 from "path";
4878
5049
 
4879
5050
  // src/cmds/forestry-migrate/index.ts
4880
- import fs12 from "fs-extra";
4881
- import path13 from "path";
5051
+ import fs13 from "fs-extra";
5052
+ import path14 from "path";
4882
5053
  import yaml2 from "js-yaml";
4883
5054
  import pkg from "minimatch";
4884
5055
  import { parseFile, stringifyFile } from "@tinacms/graphql";
4885
5056
  import { CONTENT_FORMATS } from "@tinacms/schema-tools";
4886
5057
 
4887
5058
  // src/cmds/forestry-migrate/util/index.ts
4888
- import fs11 from "fs-extra";
4889
- import path12 from "path";
5059
+ import fs12 from "fs-extra";
5060
+ import path13 from "path";
4890
5061
  import yaml from "js-yaml";
4891
5062
  import z2 from "zod";
4892
5063
 
@@ -5313,7 +5484,7 @@ var transformForestryFieldsToTinaFields = ({
5313
5484
  return tinaFields;
5314
5485
  };
5315
5486
  var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
5316
- const templatePath = path12.join(
5487
+ const templatePath = path13.join(
5317
5488
  pathToForestryConfig,
5318
5489
  ".forestry",
5319
5490
  "front_matter",
@@ -5322,7 +5493,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
5322
5493
  );
5323
5494
  let templateString = "";
5324
5495
  try {
5325
- templateString = fs11.readFileSync(templatePath).toString();
5496
+ templateString = fs12.readFileSync(templatePath).toString();
5326
5497
  } catch {
5327
5498
  throw new Error(
5328
5499
  `Could not find template ${tem} at ${templatePath}
@@ -5388,9 +5559,9 @@ function checkExt(ext) {
5388
5559
  var generateAllTemplates = async ({
5389
5560
  pathToForestryConfig
5390
5561
  }) => {
5391
- const allTemplates = (await fs12.readdir(
5392
- path13.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
5393
- )).map((tem) => path13.basename(tem, ".yml"));
5562
+ const allTemplates = (await fs13.readdir(
5563
+ path14.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
5564
+ )).map((tem) => path14.basename(tem, ".yml"));
5394
5565
  const templateMap = /* @__PURE__ */ new Map();
5395
5566
  const proms = allTemplates.map(async (tem) => {
5396
5567
  try {
@@ -5535,9 +5706,9 @@ var generateCollectionFromForestrySection = (args) => {
5535
5706
  return c;
5536
5707
  } else if (section.type === "document") {
5537
5708
  const filePath = section.path;
5538
- const extname = path13.extname(filePath);
5539
- const fileName = path13.basename(filePath, extname);
5540
- const dir = path13.dirname(filePath);
5709
+ const extname = path14.extname(filePath);
5710
+ const fileName = path14.basename(filePath, extname);
5711
+ const dir = path14.dirname(filePath);
5541
5712
  const ext = checkExt(extname);
5542
5713
  if (ext) {
5543
5714
  const fields = [];
@@ -5599,8 +5770,8 @@ var generateCollections = async ({
5599
5770
  templateMap,
5600
5771
  usingTypescript
5601
5772
  });
5602
- const forestryConfig = await fs12.readFile(
5603
- path13.join(pathToForestryConfig, ".forestry", "settings.yml")
5773
+ const forestryConfig = await fs13.readFile(
5774
+ path14.join(pathToForestryConfig, ".forestry", "settings.yml")
5604
5775
  );
5605
5776
  rewriteTemplateKeysInDocs({
5606
5777
  templateMap,
@@ -5630,12 +5801,12 @@ var rewriteTemplateKeysInDocs = (args) => {
5630
5801
  const { templateObj } = templateMap.get(templateKey);
5631
5802
  templateObj?.pages?.forEach((page) => {
5632
5803
  try {
5633
- const filePath = path13.join(page);
5634
- if (fs12.lstatSync(filePath).isDirectory()) {
5804
+ const filePath = path14.join(page);
5805
+ if (fs13.lstatSync(filePath).isDirectory()) {
5635
5806
  return;
5636
5807
  }
5637
- const extname = path13.extname(filePath);
5638
- const fileContent = fs12.readFileSync(filePath).toString();
5808
+ const extname = path14.extname(filePath);
5809
+ const fileContent = fs13.readFileSync(filePath).toString();
5639
5810
  const content = parseFile(
5640
5811
  fileContent,
5641
5812
  extname,
@@ -5646,7 +5817,7 @@ var rewriteTemplateKeysInDocs = (args) => {
5646
5817
  _template: stringifyLabel(templateKey),
5647
5818
  ...content
5648
5819
  };
5649
- fs12.writeFileSync(
5820
+ fs13.writeFileSync(
5650
5821
  filePath,
5651
5822
  stringifyFile(newContent, extname, true, markdownParseConfig)
5652
5823
  );
@@ -5660,13 +5831,13 @@ var rewriteTemplateKeysInDocs = (args) => {
5660
5831
  };
5661
5832
 
5662
5833
  // src/cmds/init/apply.ts
5663
- import { Telemetry as Telemetry4 } from "@tinacms/metrics";
5664
- import fs15 from "fs-extra";
5834
+ import { Telemetry as Telemetry3 } from "@tinacms/metrics";
5835
+ import fs16 from "fs-extra";
5665
5836
 
5666
5837
  // src/next/commands/codemod-command/index.ts
5667
5838
  import { Command as Command5, Option as Option5 } from "clipanion";
5668
- import fs13 from "fs-extra";
5669
- import path14 from "path";
5839
+ import fs14 from "fs-extra";
5840
+ import path15 from "path";
5670
5841
  var CodemodCommand = class extends Command5 {
5671
5842
  static paths = [["codemod"], ["codemod", "move-tina-folder"]];
5672
5843
  rootPath = Option5.String("--rootPath", {
@@ -5707,13 +5878,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
5707
5878
  logger.error(e.message);
5708
5879
  process.exit(1);
5709
5880
  }
5710
- const tinaDestination = path14.join(configManager.rootPath, "tina");
5711
- if (await fs13.existsSync(tinaDestination)) {
5881
+ const tinaDestination = path15.join(configManager.rootPath, "tina");
5882
+ if (await fs14.existsSync(tinaDestination)) {
5712
5883
  logger.info(
5713
5884
  `Folder already exists at ${tinaDestination}. Either delete this folder to complete the codemod, or ensure you have properly copied your config from the ".tina" folder.`
5714
5885
  );
5715
5886
  } else {
5716
- await fs13.moveSync(configManager.tinaFolderPath, tinaDestination);
5887
+ await fs14.moveSync(configManager.tinaFolderPath, tinaDestination);
5717
5888
  await writeGitignore(configManager.rootPath);
5718
5889
  logger.info(
5719
5890
  "Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
@@ -5721,8 +5892,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
5721
5892
  }
5722
5893
  };
5723
5894
  var writeGitignore = async (rootPath) => {
5724
- await fs13.outputFileSync(
5725
- path14.join(rootPath, "tina", ".gitignore"),
5895
+ await fs14.outputFileSync(
5896
+ path15.join(rootPath, "tina", ".gitignore"),
5726
5897
  "__generated__"
5727
5898
  );
5728
5899
  };
@@ -6160,7 +6331,7 @@ function extendNextScripts(scripts, opts) {
6160
6331
 
6161
6332
  // src/cmds/init/codegen/index.ts
6162
6333
  import ts2 from "typescript";
6163
- import fs14 from "fs-extra";
6334
+ import fs15 from "fs-extra";
6164
6335
 
6165
6336
  // src/cmds/init/codegen/util.ts
6166
6337
  import ts from "typescript";
@@ -6397,7 +6568,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
6397
6568
  const pathToConfig = configFile.resolve(config2.typescript).path;
6398
6569
  const sourceFile = ts2.createSourceFile(
6399
6570
  pathToConfig,
6400
- fs14.readFileSync(pathToConfig, "utf8"),
6571
+ fs15.readFileSync(pathToConfig, "utf8"),
6401
6572
  config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
6402
6573
  );
6403
6574
  const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
@@ -6447,7 +6618,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
6447
6618
  )
6448
6619
  ].map((visitor) => makeTransformer(visitor))
6449
6620
  );
6450
- return fs14.writeFile(
6621
+ return fs15.writeFile(
6451
6622
  pathToConfig,
6452
6623
  ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
6453
6624
  );
@@ -6504,6 +6675,9 @@ async function apply({
6504
6675
  if (!env.gitIgnoreEnvExists) {
6505
6676
  itemsToAdd.push(".env");
6506
6677
  }
6678
+ if (!env.gitIgnoreTinaGeneratedExists) {
6679
+ itemsToAdd.push("tina/__generated__");
6680
+ }
6507
6681
  if (itemsToAdd.length > 0) {
6508
6682
  await updateGitIgnore({ baseDir, items: itemsToAdd });
6509
6683
  }
@@ -6565,8 +6739,8 @@ async function apply({
6565
6739
  await addConfigFile({
6566
6740
  configArgs: {
6567
6741
  config: config2,
6568
- publicFolder: path15.join(
6569
- path15.relative(process.cwd(), pathToForestryConfig),
6742
+ publicFolder: path16.join(
6743
+ path16.relative(process.cwd(), pathToForestryConfig),
6570
6744
  config2.publicFolder
6571
6745
  ),
6572
6746
  collections,
@@ -6623,7 +6797,7 @@ var reportTelemetry = async ({
6623
6797
  if (noTelemetry) {
6624
6798
  logger.info(logText("Telemetry disabled"));
6625
6799
  }
6626
- const telemetry = new Telemetry4({ disabled: noTelemetry });
6800
+ const telemetry = new Telemetry3({ disabled: noTelemetry });
6627
6801
  const schemaFileType = usingTypescript ? "ts" : "js";
6628
6802
  await telemetry.submitRecord({
6629
6803
  event: {
@@ -6639,18 +6813,21 @@ var createPackageJSON = async () => {
6639
6813
  };
6640
6814
  var createGitignore = async ({ baseDir }) => {
6641
6815
  logger.info(logText("No .gitignore found, creating one"));
6642
- fs15.outputFileSync(path15.join(baseDir, ".gitignore"), "node_modules");
6816
+ fs16.outputFileSync(
6817
+ path16.join(baseDir, ".gitignore"),
6818
+ "node_modules\ntina/__generated__\n"
6819
+ );
6643
6820
  };
6644
6821
  var updateGitIgnore = async ({
6645
6822
  baseDir,
6646
6823
  items
6647
6824
  }) => {
6648
6825
  logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
6649
- const gitignoreContent = fs15.readFileSync(path15.join(baseDir, ".gitignore")).toString();
6826
+ const gitignoreContent = fs16.readFileSync(path16.join(baseDir, ".gitignore")).toString();
6650
6827
  const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
6651
6828
  "\n"
6652
6829
  );
6653
- await fs15.writeFile(path15.join(baseDir, ".gitignore"), newGitignoreContent);
6830
+ await fs16.writeFile(path16.join(baseDir, ".gitignore"), newGitignoreContent);
6654
6831
  };
6655
6832
  var addDependencies = async (config2, env, params) => {
6656
6833
  const { packageManager } = config2;
@@ -6721,22 +6898,22 @@ var writeGeneratedFile = async ({
6721
6898
  content,
6722
6899
  typescript
6723
6900
  }) => {
6724
- const { exists, path: path17, parentPath } = generatedFile.resolve(typescript);
6901
+ const { exists, path: path18, parentPath } = generatedFile.resolve(typescript);
6725
6902
  if (exists) {
6726
6903
  if (overwrite) {
6727
- logger.info(`Overwriting file at ${path17}... \u2705`);
6728
- fs15.outputFileSync(path17, content);
6904
+ logger.info(`Overwriting file at ${path18}... \u2705`);
6905
+ fs16.outputFileSync(path18, content);
6729
6906
  } else {
6730
- logger.info(`Not overwriting file at ${path17}.`);
6907
+ logger.info(`Not overwriting file at ${path18}.`);
6731
6908
  logger.info(
6732
- logText(`Please add the following to ${path17}:
6909
+ logText(`Please add the following to ${path18}:
6733
6910
  ${indentText(content)}}`)
6734
6911
  );
6735
6912
  }
6736
6913
  } else {
6737
- logger.info(`Adding file at ${path17}... \u2705`);
6738
- await fs15.ensureDir(parentPath);
6739
- fs15.outputFileSync(path17, content);
6914
+ logger.info(`Adding file at ${path18}... \u2705`);
6915
+ await fs16.ensureDir(parentPath);
6916
+ fs16.outputFileSync(path18, content);
6740
6917
  }
6741
6918
  };
6742
6919
  var addConfigFile = async ({
@@ -6814,7 +6991,7 @@ var addContentFile = async ({
6814
6991
  return () => ({
6815
6992
  exists: env.sampleContentExists,
6816
6993
  path: env.sampleContentPath,
6817
- parentPath: path15.dirname(env.sampleContentPath)
6994
+ parentPath: path16.dirname(env.sampleContentPath)
6818
6995
  });
6819
6996
  }
6820
6997
  },
@@ -6837,10 +7014,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
6837
7014
  return `${x.key}=${x.value || "***"}`;
6838
7015
  }).join("\n") + `
6839
7016
  TINA_PUBLIC_IS_LOCAL=true`;
6840
- const envFile = path15.join(process.cwd(), ".env");
6841
- if (!fs15.existsSync(envFile)) {
7017
+ const envFile = path16.join(process.cwd(), ".env");
7018
+ if (!fs16.existsSync(envFile)) {
6842
7019
  logger.info(`Adding .env file to your project... \u2705`);
6843
- fs15.writeFileSync(envFile, envFileText);
7020
+ fs16.writeFileSync(envFile, envFileText);
6844
7021
  } else {
6845
7022
  logger.info(
6846
7023
  "Please add the following environment variables to your .env file"
@@ -6909,7 +7086,7 @@ var addReactiveFile = {
6909
7086
  baseDir,
6910
7087
  dataLayer
6911
7088
  }) => {
6912
- const packageJsonPath = path15.join(baseDir, "package.json");
7089
+ const packageJsonPath = path16.join(baseDir, "package.json");
6913
7090
  await writeGeneratedFile({
6914
7091
  generatedFile,
6915
7092
  typescript: config2.typescript,
@@ -6922,7 +7099,7 @@ var addReactiveFile = {
6922
7099
  })
6923
7100
  });
6924
7101
  logger.info("Adding a nextjs example... \u2705");
6925
- const packageJson = JSON.parse(fs15.readFileSync(packageJsonPath).toString());
7102
+ const packageJson = JSON.parse(fs16.readFileSync(packageJsonPath).toString());
6926
7103
  const scripts = packageJson.scripts || {};
6927
7104
  const updatedPackageJson = JSON.stringify(
6928
7105
  {
@@ -6935,7 +7112,7 @@ var addReactiveFile = {
6935
7112
  null,
6936
7113
  2
6937
7114
  );
6938
- fs15.writeFileSync(packageJsonPath, updatedPackageJson);
7115
+ fs16.writeFileSync(packageJsonPath, updatedPackageJson);
6939
7116
  }
6940
7117
  };
6941
7118
  function execShellCommand(cmd) {
@@ -7006,7 +7183,7 @@ var InitCommand = class extends Command6 {
7006
7183
  description: `Add Tina to an existing project`
7007
7184
  });
7008
7185
  async catch(error) {
7009
- logger.error("Error occured during tinacms init");
7186
+ logger.error("Error occurred during tinacms init");
7010
7187
  console.error(error);
7011
7188
  process.exit(1);
7012
7189
  }
@@ -7045,7 +7222,7 @@ var SearchIndexCommand = class extends Command7 {
7045
7222
  description: `Index the site for search`
7046
7223
  });
7047
7224
  async catch(error) {
7048
- logger.error("Error occured during tinacms search-index");
7225
+ logger.error("Error occurred during tinacms search-index");
7049
7226
  console.error(error);
7050
7227
  process.exit(1);
7051
7228
  }
@@ -7135,8 +7312,8 @@ var SearchIndexCommand = class extends Command7 {
7135
7312
  import { Command as Command8, Option as Option8 } from "clipanion";
7136
7313
 
7137
7314
  // src/next/commands/doctor-command/doctor.ts
7138
- import path16 from "path";
7139
- import fs16 from "fs-extra";
7315
+ import path17 from "path";
7316
+ import fs17 from "fs-extra";
7140
7317
  import yaml3 from "js-yaml";
7141
7318
  var DEPENDENCY_TYPES = [
7142
7319
  "dependencies",
@@ -7169,11 +7346,11 @@ function getTinaDependencies(packageJson) {
7169
7346
  );
7170
7347
  }
7171
7348
  async function readProjectPackageJson(rootPath) {
7172
- const packageJsonPath = path16.join(rootPath, "package.json");
7173
- if (!await fs16.pathExists(packageJsonPath)) {
7349
+ const packageJsonPath = path17.join(rootPath, "package.json");
7350
+ if (!await fs17.pathExists(packageJsonPath)) {
7174
7351
  throw new Error(`No package.json found at ${packageJsonPath}`);
7175
7352
  }
7176
- return fs16.readJSON(packageJsonPath);
7353
+ return fs17.readJSON(packageJsonPath);
7177
7354
  }
7178
7355
  async function resolveInstalledVersions({
7179
7356
  rootPath,
@@ -7296,14 +7473,14 @@ function isLocalReference(version2) {
7296
7473
  );
7297
7474
  }
7298
7475
  async function readNodeModulesVersion(rootPath, packageName) {
7299
- const packageJsonPath = path16.join(
7476
+ const packageJsonPath = path17.join(
7300
7477
  rootPath,
7301
7478
  "node_modules",
7302
7479
  ...packageName.split("/"),
7303
7480
  "package.json"
7304
7481
  );
7305
- if (!await fs16.pathExists(packageJsonPath)) return void 0;
7306
- const packageJson = await fs16.readJSON(packageJsonPath);
7482
+ if (!await fs17.pathExists(packageJsonPath)) return void 0;
7483
+ const packageJson = await fs17.readJSON(packageJsonPath);
7307
7484
  return typeof packageJson.version === "string" ? packageJson.version : void 0;
7308
7485
  }
7309
7486
  async function readLockfileVersions(rootPath) {
@@ -7319,10 +7496,10 @@ async function readLockfileVersions(rootPath) {
7319
7496
  return /* @__PURE__ */ new Map();
7320
7497
  }
7321
7498
  async function readPackageLockVersions(rootPath) {
7322
- const lockfilePath = path16.join(rootPath, "package-lock.json");
7499
+ const lockfilePath = path17.join(rootPath, "package-lock.json");
7323
7500
  const versions = /* @__PURE__ */ new Map();
7324
- if (!await fs16.pathExists(lockfilePath)) return versions;
7325
- const lockfile = await fs16.readJSON(lockfilePath);
7501
+ if (!await fs17.pathExists(lockfilePath)) return versions;
7502
+ const lockfile = await fs17.readJSON(lockfilePath);
7326
7503
  for (const [key, value] of Object.entries(lockfile.packages || {})) {
7327
7504
  if (!key.startsWith("node_modules/")) continue;
7328
7505
  const name2 = key.replace(/^node_modules\//, "");
@@ -7340,10 +7517,10 @@ async function readPackageLockVersions(rootPath) {
7340
7517
  return versions;
7341
7518
  }
7342
7519
  async function readPnpmLockVersions(rootPath) {
7343
- const lockfilePath = path16.join(rootPath, "pnpm-lock.yaml");
7520
+ const lockfilePath = path17.join(rootPath, "pnpm-lock.yaml");
7344
7521
  const versions = /* @__PURE__ */ new Map();
7345
- if (!await fs16.pathExists(lockfilePath)) return versions;
7346
- const lockfile = yaml3.load(await fs16.readFile(lockfilePath, "utf8"));
7522
+ if (!await fs17.pathExists(lockfilePath)) return versions;
7523
+ const lockfile = yaml3.load(await fs17.readFile(lockfilePath, "utf8"));
7347
7524
  const rootImporter = lockfile?.importers?.["."];
7348
7525
  for (const dependencyType of DEPENDENCY_TYPES) {
7349
7526
  for (const [name2, value] of Object.entries(
@@ -7363,10 +7540,10 @@ async function readPnpmLockVersions(rootPath) {
7363
7540
  return versions;
7364
7541
  }
7365
7542
  async function readYarnLockVersions(rootPath) {
7366
- const lockfilePath = path16.join(rootPath, "yarn.lock");
7543
+ const lockfilePath = path17.join(rootPath, "yarn.lock");
7367
7544
  const versions = /* @__PURE__ */ new Map();
7368
- if (!await fs16.pathExists(lockfilePath)) return versions;
7369
- const contents = await fs16.readFile(lockfilePath, "utf8");
7545
+ if (!await fs17.pathExists(lockfilePath)) return versions;
7546
+ const contents = await fs17.readFile(lockfilePath, "utf8");
7370
7547
  if (contents.includes("__metadata:")) {
7371
7548
  return readYarnBerryLockVersions(contents);
7372
7549
  }