@tinacms/cli 0.0.0-df15996-20250420014759 → 0.0.0-e024aec-20250526035050

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
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(index_exports);
35
35
  var import_clipanion8 = require("clipanion");
36
36
 
37
37
  // package.json
38
- var version = "1.9.5";
38
+ var version = "1.9.7";
39
39
 
40
40
  // src/next/commands/dev-command/index.ts
41
41
  var import_path5 = __toESM(require("path"));
@@ -587,13 +587,12 @@ var Codegen = class {
587
587
  return apiURL;
588
588
  }
589
589
  _createApiUrl() {
590
- var _a, _b, _c, _d;
591
- const branch = (_a = this.configManager.config) == null ? void 0 : _a.branch;
592
- const clientId = (_b = this.configManager.config) == null ? void 0 : _b.clientId;
593
- const token = (_c = this.configManager.config) == null ? void 0 : _c.token;
590
+ const branch = this.configManager.config?.branch;
591
+ const clientId = this.configManager.config?.clientId;
592
+ const token = this.configManager.config?.token;
594
593
  const fullVersion = this.configManager.getTinaGraphQLVersion();
595
594
  const version2 = `${fullVersion.major}.${fullVersion.minor}`;
596
- const baseUrl = ((_d = this.configManager.config.tinaioConfig) == null ? void 0 : _d.contentApiUrlOverride) || `https://${TINA_HOST}`;
595
+ const baseUrl = this.configManager.config.tinaioConfig?.contentApiUrlOverride || `https://${TINA_HOST}`;
597
596
  if ((!branch || !clientId || !token) && !this.port && !this.configManager.config.contentApiUrlOverride) {
598
597
  const missing = [];
599
598
  if (!branch) missing.push("branch");
@@ -621,7 +620,6 @@ var Codegen = class {
621
620
  return this.apiURL;
622
621
  }
623
622
  async genDatabaseClient() {
624
- var _a, _b;
625
623
  const authCollection = this.tinaSchema.getCollections().find((c) => c.isAuthCollection);
626
624
  let authFields = [];
627
625
  if (authCollection) {
@@ -632,7 +630,7 @@ var Codegen = class {
632
630
  if (usersFields.length > 1) {
633
631
  throw new Error("Only one user field is allowed");
634
632
  }
635
- authFields = (_b = (_a = usersFields[0]) == null ? void 0 : _a.collectable) == null ? void 0 : _b.fields.map((f) => {
633
+ authFields = usersFields[0]?.collectable?.fields.map((f) => {
636
634
  if (f.type !== "password" && f.type !== "object") {
637
635
  if (f.uid) {
638
636
  return `id:${f.name}`;
@@ -710,9 +708,8 @@ export default databaseClient;
710
708
  `;
711
709
  }
712
710
  async genClient() {
713
- var _a, _b, _c;
714
- const token = (_a = this.configManager.config) == null ? void 0 : _a.token;
715
- const errorPolicy = (_c = (_b = this.configManager.config) == null ? void 0 : _b.client) == null ? void 0 : _c.errorPolicy;
711
+ const token = this.configManager.config?.token;
712
+ const errorPolicy = this.configManager.config?.client?.errorPolicy;
716
713
  const apiURL = this.getApiURL();
717
714
  const clientString = `import { createClient } from "tinacms/dist/client";
718
715
  import { queries } from "./types";
@@ -811,11 +808,10 @@ var ConfigManager = class {
811
808
  return this.rootPath !== this.contentRootPath;
812
809
  }
813
810
  shouldSkipSDK() {
814
- var _a;
815
811
  if (this.legacyNoSDK) {
816
812
  return this.legacyNoSDK;
817
813
  }
818
- return ((_a = this.config.client) == null ? void 0 : _a.skip) || false;
814
+ return this.config.client?.skip || false;
819
815
  }
820
816
  async processConfig() {
821
817
  this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
@@ -991,7 +987,7 @@ var ConfigManager = class {
991
987
  };
992
988
  }
993
989
  const generatedSchema = import_fs_extra2.default.readJSONSync(this.generatedSchemaJSONPath);
994
- if (!generatedSchema || !(typeof (generatedSchema == null ? void 0 : generatedSchema.version) !== "undefined")) {
990
+ if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
995
991
  throw new Error(
996
992
  `Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
997
993
  );
@@ -1168,7 +1164,7 @@ var createDBServer = (port) => {
1168
1164
  });
1169
1165
  });
1170
1166
  dbServer.once("error", (err) => {
1171
- if ((err == null ? void 0 : err.code) === "EADDRINUSE") {
1167
+ if (err?.code === "EADDRINUSE") {
1172
1168
  throw new Error(
1173
1169
  `Tina Dev server is already in use. Datalayer server is busy on port ${port}`
1174
1170
  );
@@ -1319,7 +1315,6 @@ var BaseCommand = class extends import_clipanion.Command {
1319
1315
  const warnings = [];
1320
1316
  await spin({
1321
1317
  waitFor: async () => {
1322
- var _a, _b;
1323
1318
  const rootPath = configManager.rootPath;
1324
1319
  let sha;
1325
1320
  try {
@@ -1344,7 +1339,7 @@ var BaseCommand = class extends import_clipanion.Command {
1344
1339
  }
1345
1340
  for (const collection of tinaSchema.getCollections()) {
1346
1341
  pathFilter[collection.path] = {
1347
- matches: ((_a = collection.match) == null ? void 0 : _a.exclude) || ((_b = collection.match) == null ? void 0 : _b.include) ? tinaSchema.getMatches({ collection }) : void 0
1342
+ matches: collection.match?.exclude || collection.match?.include ? tinaSchema.getMatches({ collection }) : void 0
1348
1343
  };
1349
1344
  }
1350
1345
  const { added, modified, deleted } = await (0, import_graphql8.getChangedFiles)({
@@ -1379,7 +1374,7 @@ var BaseCommand = class extends import_clipanion.Command {
1379
1374
  if (sha) {
1380
1375
  await database.setMetadata("lastSha", sha);
1381
1376
  }
1382
- if (res == null ? void 0 : res.warnings) {
1377
+ if (res?.warnings) {
1383
1378
  warnings.push(...res.warnings);
1384
1379
  }
1385
1380
  },
@@ -1474,14 +1469,14 @@ var devHTML = (port) => `<!DOCTYPE html>
1474
1469
  var import_vite3 = require("vite");
1475
1470
 
1476
1471
  // src/next/vite/index.ts
1477
- var import_node_path2 = __toESM(require("path"));
1472
+ var import_node_path2 = __toESM(require("node:path"));
1478
1473
  var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
1479
1474
  var import_fs_extra4 = __toESM(require("fs-extra"));
1480
1475
  var import_normalize_path3 = __toESM(require("normalize-path"));
1481
1476
  var import_vite = require("vite");
1482
1477
 
1483
1478
  // src/next/vite/tailwind.ts
1484
- var import_node_path = __toESM(require("path"));
1479
+ var import_node_path = __toESM(require("node:path"));
1485
1480
  var import_aspect_ratio = __toESM(require("@tailwindcss/aspect-ratio"));
1486
1481
  var import_container_queries = __toESM(require("@tailwindcss/container-queries"));
1487
1482
  var import_typography = __toESM(require("@tailwindcss/typography"));
@@ -1807,7 +1802,6 @@ var createConfig = async ({
1807
1802
  noWatch,
1808
1803
  rollupOptions
1809
1804
  }) => {
1810
- var _a, _b, _c, _d, _e, _f, _g, _h;
1811
1805
  const publicEnv = {};
1812
1806
  Object.keys(process.env).forEach((key) => {
1813
1807
  if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
@@ -1829,9 +1823,9 @@ var createConfig = async ({
1829
1823
  configManager.generatedFolderPath,
1830
1824
  "static-media.json"
1831
1825
  );
1832
- if ((_b = (_a = configManager.config.media) == null ? void 0 : _a.tina) == null ? void 0 : _b.static) {
1826
+ if (configManager.config.media?.tina?.static) {
1833
1827
  const staticMedia = await listFilesRecursively({
1834
- directoryPath: ((_c = configManager.config.media.tina) == null ? void 0 : _c.mediaRoot) || "",
1828
+ directoryPath: configManager.config.media.tina?.mediaRoot || "",
1835
1829
  config: configManager.config.media.tina,
1836
1830
  roothPath: configManager.rootPath
1837
1831
  });
@@ -1892,7 +1886,7 @@ var createConfig = async ({
1892
1886
  // Used by picomatch https://github.com/micromatch/picomatch/blob/master/lib/utils.js#L4
1893
1887
  "process.platform": `"${process.platform}"`,
1894
1888
  __API_URL__: `"${apiURL}"`,
1895
- __BASE_PATH__: `"${((_e = (_d = configManager.config) == null ? void 0 : _d.build) == null ? void 0 : _e.basePath) || ""}"`,
1889
+ __BASE_PATH__: `"${configManager.config?.build?.basePath || ""}"`,
1896
1890
  __TINA_GRAPHQL_VERSION__: version2
1897
1891
  },
1898
1892
  logLevel: "error",
@@ -1904,7 +1898,7 @@ var createConfig = async ({
1904
1898
  include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
1905
1899
  },
1906
1900
  server: {
1907
- host: (_h = (_g = (_f = configManager.config) == null ? void 0 : _f.build) == null ? void 0 : _g.host) != null ? _h : false,
1901
+ host: configManager.config?.build?.host ?? false,
1908
1902
  watch: noWatch ? {
1909
1903
  ignored: ["**/*"]
1910
1904
  } : {
@@ -1983,8 +1977,7 @@ var createMediaRouter = (config2) => {
1983
1977
  const handlePost = async function(req, res) {
1984
1978
  const bb = (0, import_busboy.default)({ headers: req.headers });
1985
1979
  bb.on("file", async (_name, file, _info) => {
1986
- var _a;
1987
- const fullPath = decodeURI((_a = req.url) == null ? void 0 : _a.slice("/media/upload/".length));
1980
+ const fullPath = decodeURI(req.url?.slice("/media/upload/".length));
1988
1981
  const saveTo = import_path3.default.join(mediaFolder, ...fullPath.split("/"));
1989
1982
  await import_fs_extra5.default.ensureDir(import_path3.default.dirname(saveTo));
1990
1983
  file.pipe(import_fs_extra5.default.createWriteStream(saveTo));
@@ -2086,7 +2079,7 @@ var MediaModel = class {
2086
2079
  return {
2087
2080
  files: [],
2088
2081
  directories: [],
2089
- error: error == null ? void 0 : error.toString()
2082
+ error: error?.toString()
2090
2083
  };
2091
2084
  }
2092
2085
  }
@@ -2103,7 +2096,7 @@ var MediaModel = class {
2103
2096
  return { ok: true };
2104
2097
  } catch (error) {
2105
2098
  console.error(error);
2106
- return { ok: false, message: error == null ? void 0 : error.toString() };
2099
+ return { ok: false, message: error?.toString() };
2107
2100
  }
2108
2101
  }
2109
2102
  };
@@ -2181,13 +2174,12 @@ var devServerEndPointsPlugin = ({
2181
2174
  server.middlewares.use((0, import_cors.default)());
2182
2175
  server.middlewares.use(import_body_parser.default.json({ limit: "5mb" }));
2183
2176
  server.middlewares.use(async (req, res, next) => {
2184
- var _a;
2185
- const mediaPaths = (_a = configManager.config.media) == null ? void 0 : _a.tina;
2177
+ const mediaPaths = configManager.config.media?.tina;
2186
2178
  const mediaRouter = createMediaRouter({
2187
2179
  rootPath: configManager.rootPath,
2188
2180
  apiURL,
2189
- publicFolder: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.publicFolder) || ""),
2190
- mediaRoot: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.mediaRoot) || "")
2181
+ publicFolder: parseMediaFolder(mediaPaths?.publicFolder || ""),
2182
+ mediaRoot: parseMediaFolder(mediaPaths?.mediaRoot || "")
2191
2183
  });
2192
2184
  const searchIndexRouter = createSearchIndexRouter({
2193
2185
  config: { apiURL, searchPath: "searchIndex" },
@@ -2260,7 +2252,7 @@ function viteTransformExtension({
2260
2252
  name: "vite-plugin-svgr",
2261
2253
  async transform(code, id) {
2262
2254
  if (filter(id)) {
2263
- const { transform: transform2 } = await Promise.resolve().then(() => __toESM(require("@svgr/core")));
2255
+ const { transform: transform2 } = await import("@svgr/core");
2264
2256
  const svgCode = await import_fs.default.promises.readFile(
2265
2257
  id.replace(/\?.*$/, ""),
2266
2258
  "utf8"
@@ -2345,6 +2337,20 @@ var DevCommand = class extends BaseCommand {
2345
2337
  });
2346
2338
  this.indexingLock = new import_async_lock.default();
2347
2339
  }
2340
+ static {
2341
+ this.paths = [["dev"], ["server:start"]];
2342
+ }
2343
+ static {
2344
+ // Prevent indexes and reads occurring at once
2345
+ this.usage = import_clipanion2.Command.Usage({
2346
+ category: `Commands`,
2347
+ description: `Builds Tina and starts the dev server`,
2348
+ examples: [
2349
+ [`A basic example`, `$0 dev`],
2350
+ [`A second example`, `$0 dev --rootPath`]
2351
+ ]
2352
+ });
2353
+ }
2348
2354
  async catch(error) {
2349
2355
  logger.error("Error occured during tinacms dev");
2350
2356
  console.error(error);
@@ -2359,7 +2365,6 @@ var DevCommand = class extends BaseCommand {
2359
2365
  }
2360
2366
  }
2361
2367
  async execute() {
2362
- var _a, _b, _c, _d, _e, _f;
2363
2368
  const configManager = new ConfigManager({
2364
2369
  rootPath: this.rootPath,
2365
2370
  legacyNoSDK: this.noSDK
@@ -2467,19 +2472,19 @@ ${dangerText(e.message)}
2467
2472
  "index.html\nassets/"
2468
2473
  );
2469
2474
  const searchIndexClient = new import_search.LocalSearchIndexClient({
2470
- stopwordLanguages: (_b = (_a = configManager.config.search) == null ? void 0 : _a.tina) == null ? void 0 : _b.stopwordLanguages,
2471
- tokenSplitRegex: (_d = (_c = configManager.config.search) == null ? void 0 : _c.tina) == null ? void 0 : _d.tokenSplitRegex
2475
+ stopwordLanguages: configManager.config.search?.tina?.stopwordLanguages,
2476
+ tokenSplitRegex: configManager.config.search?.tina?.tokenSplitRegex
2472
2477
  });
2473
2478
  await searchIndexClient.onStartIndexing();
2474
2479
  const searchIndexer = new import_search.SearchIndexer({
2475
- batchSize: ((_e = configManager.config.search) == null ? void 0 : _e.indexBatchSize) || 100,
2480
+ batchSize: configManager.config.search?.indexBatchSize || 100,
2476
2481
  bridge: new import_graphql10.FilesystemBridge(
2477
2482
  configManager.rootPath,
2478
2483
  configManager.contentRootPath
2479
2484
  ),
2480
2485
  schema: tinaSchema,
2481
2486
  client: searchIndexClient,
2482
- textIndexLength: ((_f = configManager.config.search) == null ? void 0 : _f.maxSearchIndexFieldLength) || 100
2487
+ textIndexLength: configManager.config.search?.maxSearchIndexFieldLength || 100
2483
2488
  });
2484
2489
  if (configManager.config.search) {
2485
2490
  await spin({
@@ -2638,16 +2643,6 @@ ${dangerText(e.message)}
2638
2643
  import_chokidar.default.watch(configManager.userQueriesAndFragmentsGlob).on("add", executeCallback).on("change", executeCallback).on("unlink", executeCallback);
2639
2644
  }
2640
2645
  };
2641
- DevCommand.paths = [["dev"], ["server:start"]];
2642
- // Prevent indexes and reads occurring at once
2643
- DevCommand.usage = import_clipanion2.Command.Usage({
2644
- category: `Commands`,
2645
- description: `Builds Tina and starts the dev server`,
2646
- examples: [
2647
- [`A basic example`, `$0 dev`],
2648
- [`A second example`, `$0 dev --rootPath`]
2649
- ]
2650
- });
2651
2646
 
2652
2647
  // src/next/commands/build-command/index.ts
2653
2648
  var import_crypto = __toESM(require("crypto"));
@@ -2845,12 +2840,20 @@ var BuildCommand = class extends BaseCommand {
2845
2840
  description: "Disables the client build cache"
2846
2841
  });
2847
2842
  }
2843
+ static {
2844
+ this.paths = [["build"]];
2845
+ }
2846
+ static {
2847
+ this.usage = import_clipanion3.Command.Usage({
2848
+ category: `Commands`,
2849
+ description: `Build the CMS and autogenerated modules for usage with TinaCloud`
2850
+ });
2851
+ }
2848
2852
  async catch(error) {
2849
2853
  console.error(error);
2850
2854
  process.exit(1);
2851
2855
  }
2852
2856
  async execute() {
2853
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2854
2857
  logger.info("Starting Tina build");
2855
2858
  this.logDeprecationWarnings();
2856
2859
  const configManager = new ConfigManager({
@@ -2939,45 +2942,63 @@ ${dangerText(e.message)}
2939
2942
  }
2940
2943
  const skipCloudChecks = this.skipCloudChecks || configManager.hasSelfHostedConfig();
2941
2944
  if (!skipCloudChecks) {
2942
- const { hasUpstream, timestamp } = await this.checkClientInfo(
2943
- configManager,
2944
- codegen2.productionUrl,
2945
- this.previewBaseBranch
2946
- );
2947
- if (!hasUpstream && this.upstreamBranch) {
2948
- logger.warn(
2949
- `${dangerText(
2950
- `WARN: Upstream branch '${this.upstreamBranch}' specified but no upstream project was found.`
2951
- )}`
2945
+ try {
2946
+ const clientInfo = await this.checkClientInfo(
2947
+ configManager,
2948
+ codegen2.productionUrl,
2949
+ this.previewBaseBranch
2952
2950
  );
2951
+ if (clientInfo.detectedBotBranch) {
2952
+ logger.warn(
2953
+ `${warnText(
2954
+ `WARN: Detected bot branch. Using schema/content from default branch '${clientInfo.defaultBranch}' instead of '${configManager.config.branch}'.`
2955
+ )}`
2956
+ );
2957
+ }
2958
+ if (!clientInfo.hasUpstream && this.upstreamBranch) {
2959
+ logger.warn(
2960
+ `${dangerText(
2961
+ `WARN: Upstream branch '${this.upstreamBranch}' specified but no upstream project was found.`
2962
+ )}`
2963
+ );
2964
+ }
2965
+ if (clientInfo.hasUpstream || this.previewBaseBranch && this.previewName) {
2966
+ await this.syncProject(configManager, codegen2.productionUrl, {
2967
+ upstreamBranch: this.upstreamBranch,
2968
+ previewBaseBranch: this.previewBaseBranch,
2969
+ previewName: this.previewName
2970
+ });
2971
+ }
2972
+ await waitForDB(
2973
+ configManager.config,
2974
+ codegen2.productionUrl,
2975
+ this.previewName,
2976
+ false
2977
+ );
2978
+ await this.checkGraphqlSchema(
2979
+ configManager,
2980
+ database,
2981
+ codegen2.productionUrl,
2982
+ clientInfo.timestamp
2983
+ );
2984
+ await this.checkTinaSchema(
2985
+ configManager,
2986
+ database,
2987
+ codegen2.productionUrl,
2988
+ this.previewName,
2989
+ this.verbose,
2990
+ clientInfo.timestamp
2991
+ );
2992
+ } catch (e) {
2993
+ logger.error(`
2994
+
2995
+ ${dangerText(e.message)}
2996
+ `);
2997
+ if (this.verbose) {
2998
+ console.error(e);
2999
+ }
3000
+ process.exit(1);
2953
3001
  }
2954
- if (hasUpstream || this.previewBaseBranch && this.previewName) {
2955
- await this.syncProject(configManager, codegen2.productionUrl, {
2956
- upstreamBranch: this.upstreamBranch,
2957
- previewBaseBranch: this.previewBaseBranch,
2958
- previewName: this.previewName
2959
- });
2960
- }
2961
- await waitForDB(
2962
- configManager.config,
2963
- codegen2.productionUrl,
2964
- this.previewName,
2965
- false
2966
- );
2967
- await this.checkGraphqlSchema(
2968
- configManager,
2969
- database,
2970
- codegen2.productionUrl,
2971
- timestamp
2972
- );
2973
- await this.checkTinaSchema(
2974
- configManager,
2975
- database,
2976
- codegen2.productionUrl,
2977
- this.previewName,
2978
- this.verbose,
2979
- timestamp
2980
- );
2981
3002
  }
2982
3003
  await buildProductionSpa(configManager, database, codegen2.productionUrl);
2983
3004
  await import_fs_extra7.default.outputFile(
@@ -2986,9 +3007,9 @@ ${dangerText(e.message)}
2986
3007
  );
2987
3008
  if (configManager.config.search && !this.skipSearchIndex && !this.localOption) {
2988
3009
  let client;
2989
- const hasTinaSearch = Boolean((_b = (_a = configManager.config) == null ? void 0 : _a.search) == null ? void 0 : _b.tina);
3010
+ const hasTinaSearch = Boolean(configManager.config?.search?.tina);
2990
3011
  if (hasTinaSearch) {
2991
- if (!((_c = configManager.config) == null ? void 0 : _c.branch)) {
3012
+ if (!configManager.config?.branch) {
2992
3013
  logger.error(
2993
3014
  `${dangerText(
2994
3015
  `ERROR: Branch not configured in tina search configuration.`
@@ -2998,11 +3019,11 @@ ${dangerText(e.message)}
2998
3019
  "Branch not configured in tina search configuration."
2999
3020
  );
3000
3021
  }
3001
- if (!((_d = configManager.config) == null ? void 0 : _d.clientId)) {
3022
+ if (!configManager.config?.clientId) {
3002
3023
  logger.error(`${dangerText(`ERROR: clientId not configured.`)}`);
3003
3024
  throw new Error("clientId not configured.");
3004
3025
  }
3005
- if (!((_g = (_f = (_e = configManager.config) == null ? void 0 : _e.search) == null ? void 0 : _f.tina) == null ? void 0 : _g.indexerToken)) {
3026
+ if (!configManager.config?.search?.tina?.indexerToken) {
3006
3027
  logger.error(
3007
3028
  `${dangerText(
3008
3029
  `ERROR: indexerToken not configured in tina search configuration.`
@@ -3013,16 +3034,16 @@ ${dangerText(e.message)}
3013
3034
  );
3014
3035
  }
3015
3036
  client = new import_search2.TinaCMSSearchIndexClient({
3016
- apiUrl: `${((_h = configManager.config.tinaioConfig) == null ? void 0 : _h.contentApiUrlOverride) || "https://content.tinajs.io"}/searchIndex/${(_i = configManager.config) == null ? void 0 : _i.clientId}`,
3017
- branch: (_j = configManager.config) == null ? void 0 : _j.branch,
3018
- indexerToken: (_m = (_l = (_k = configManager.config) == null ? void 0 : _k.search) == null ? void 0 : _l.tina) == null ? void 0 : _m.indexerToken,
3019
- stopwordLanguages: (_p = (_o = (_n = configManager.config) == null ? void 0 : _n.search) == null ? void 0 : _o.tina) == null ? void 0 : _p.stopwordLanguages
3037
+ apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
3038
+ branch: configManager.config?.branch,
3039
+ indexerToken: configManager.config?.search?.tina?.indexerToken,
3040
+ stopwordLanguages: configManager.config?.search?.tina?.stopwordLanguages
3020
3041
  });
3021
3042
  } else {
3022
- client = (_r = (_q = configManager.config) == null ? void 0 : _q.search) == null ? void 0 : _r.searchClient;
3043
+ client = configManager.config?.search?.searchClient;
3023
3044
  }
3024
3045
  const searchIndexer = new import_search2.SearchIndexer({
3025
- batchSize: ((_s = configManager.config.search) == null ? void 0 : _s.indexBatchSize) || 100,
3046
+ batchSize: configManager.config.search?.indexBatchSize || 100,
3026
3047
  bridge: new import_graphql11.FilesystemBridge(
3027
3048
  configManager.rootPath,
3028
3049
  configManager.contentRootPath
@@ -3090,86 +3111,88 @@ ${dangerText(e.message)}
3090
3111
  }
3091
3112
  }
3092
3113
  async checkClientInfo(configManager, apiURL, previewBaseBranch) {
3114
+ const MAX_RETRIES = 5;
3093
3115
  const { config: config2 } = configManager;
3094
3116
  const token = config2.token;
3095
3117
  const { clientId, branch, host } = (0, import_schema_tools2.parseURL)(apiURL);
3096
- const url = `https://${host}/db/${clientId}/status/${previewBaseBranch || branch}`;
3097
3118
  const bar2 = new import_progress2.default("Checking clientId and token. :prog", 1);
3098
- let branchKnown = false;
3099
- let hasUpstream = false;
3100
- let timestamp;
3101
- try {
3102
- const res = await request({
3103
- token,
3104
- url
3105
- });
3106
- timestamp = res.timestamp || 0;
3107
- bar2.tick({
3108
- prog: "\u2705"
3109
- });
3110
- if (!(res.status === "unknown")) {
3111
- branchKnown = true;
3112
- }
3113
- if (res.hasUpstream) {
3114
- hasUpstream = true;
3119
+ const getBranchInfo = async () => {
3120
+ const url = `https://${host}/db/${clientId}/status/${previewBaseBranch || branch}`;
3121
+ const branchInfo2 = {
3122
+ status: "unknown",
3123
+ branchKnown: false,
3124
+ hasUpstream: false,
3125
+ timestamp: 0,
3126
+ detectedBotBranch: false,
3127
+ defaultBranch: void 0
3128
+ };
3129
+ try {
3130
+ const res = await request({
3131
+ token,
3132
+ url
3133
+ });
3134
+ branchInfo2.status = res.status;
3135
+ branchInfo2.branchKnown = res.status !== "unknown";
3136
+ branchInfo2.timestamp = res.timestamp || 0;
3137
+ branchInfo2.hasUpstream = res.hasUpstream;
3138
+ branchInfo2.detectedBotBranch = res.json.detectedBotBranch;
3139
+ branchInfo2.defaultBranch = res.json.defaultBranch;
3140
+ } catch (e) {
3141
+ summary({
3142
+ heading: "Error when checking client information",
3143
+ items: [
3144
+ {
3145
+ emoji: "\u274C",
3146
+ heading: "You provided",
3147
+ subItems: [
3148
+ {
3149
+ key: "clientId",
3150
+ value: config2.clientId
3151
+ },
3152
+ {
3153
+ key: "branch",
3154
+ value: config2.branch
3155
+ },
3156
+ {
3157
+ key: "token",
3158
+ value: config2.token
3159
+ }
3160
+ ]
3161
+ }
3162
+ ]
3163
+ });
3164
+ throw e;
3115
3165
  }
3116
- } catch (e) {
3117
- summary({
3118
- heading: "Error when checking client information",
3119
- items: [
3120
- {
3121
- emoji: "\u274C",
3122
- heading: "You provided",
3123
- subItems: [
3124
- {
3125
- key: "clientId",
3126
- value: config2.clientId
3127
- },
3128
- {
3129
- key: "branch",
3130
- value: config2.branch
3131
- },
3132
- {
3133
- key: "token",
3134
- value: config2.token
3135
- }
3136
- ]
3137
- }
3138
- ]
3139
- });
3140
- throw e;
3141
- }
3142
- const branchBar = new import_progress2.default("Checking branch is on TinaCloud. :prog", 1);
3143
- if (branchKnown) {
3166
+ return branchInfo2;
3167
+ };
3168
+ const branchInfo = await getBranchInfo();
3169
+ bar2.tick({
3170
+ prog: "\u2705"
3171
+ });
3172
+ const branchBar = new import_progress2.default(
3173
+ `Checking branch '${config2.branch}' is on TinaCloud. :prog`,
3174
+ 1
3175
+ );
3176
+ if (branchInfo.branchKnown) {
3144
3177
  branchBar.tick({
3145
3178
  prog: "\u2705"
3146
3179
  });
3147
- return {
3148
- hasUpstream,
3149
- timestamp
3150
- };
3180
+ return branchInfo;
3151
3181
  }
3152
- for (let i = 0; i <= 5; i++) {
3153
- await sleepAndCallFunc({
3154
- fn: async () => {
3155
- const res = await request({
3156
- token,
3157
- url
3158
- });
3159
- if (this.verbose) {
3160
- logger.info(
3161
- `Branch status: ${res.status}. Attempt: ${i + 1}. Trying again in 5 seconds.`
3162
- );
3163
- }
3164
- if (!(res.status === "unknown")) {
3165
- branchBar.tick({
3166
- prog: "\u2705"
3167
- });
3168
- return;
3169
- }
3170
- },
3171
- ms: 5e3
3172
- });
3182
+ for (let i = 1; i <= MAX_RETRIES; i++) {
3183
+ await timeout(5e3);
3184
+ const branchInfo2 = await getBranchInfo();
3185
+ if (this.verbose) {
3186
+ logger.info(
3187
+ `Branch status: ${branchInfo2.status}. Attempt: ${i}. Trying again in 5 seconds.`
3188
+ );
3189
+ }
3190
+ if (branchInfo2.branchKnown) {
3191
+ branchBar.tick({
3192
+ prog: "\u2705"
3193
+ });
3194
+ return branchInfo2;
3195
+ }
3173
3196
  }
3174
3197
  branchBar.tick({
3175
3198
  prog: "\u274C"
@@ -3177,7 +3200,7 @@ ${dangerText(e.message)}
3177
3200
  logger.error(
3178
3201
  `${dangerText(
3179
3202
  `ERROR: Branch '${branch}' is not on TinaCloud.`
3180
- )} Please make sure that branch '${branch}' exists in your repository and that you have pushed your all changes to the remote. View all all branches and there current status here: ${linkText(
3203
+ )} Please make sure that branch '${branch}' exists in your repository and that you have pushed your all changes to the remote. View all branches and their current status here: ${linkText(
3181
3204
  `https://app.tina.io/projects/${clientId}/configuration`
3182
3205
  )}`
3183
3206
  );
@@ -3252,7 +3275,7 @@ ${dangerText(e.message)}
3252
3275
  prog: "\u274C"
3253
3276
  });
3254
3277
  let errorMessage = `The remote GraphQL schema does not exist. Check indexing for this branch.`;
3255
- if (config2 == null ? void 0 : config2.branch) {
3278
+ if (config2?.branch) {
3256
3279
  errorMessage += `
3257
3280
 
3258
3281
  Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
@@ -3284,7 +3307,7 @@ Check out '${faqLink}' for possible solutions.`}`;
3284
3307
  Additional info:
3285
3308
 
3286
3309
  `;
3287
- if (config2 == null ? void 0 : config2.branch) {
3310
+ if (config2?.branch) {
3288
3311
  errorMessage += ` Branch: ${config2.branch}, Client ID: ${config2.clientId}
3289
3312
  `;
3290
3313
  }
@@ -3333,7 +3356,7 @@ Additional info:
3333
3356
  prog: "\u274C"
3334
3357
  });
3335
3358
  let errorMessage = `The remote Tina schema does not exist. Check indexing for this branch.`;
3336
- if (config2 == null ? void 0 : config2.branch) {
3359
+ if (config2?.branch) {
3337
3360
  errorMessage += `
3338
3361
 
3339
3362
  Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
@@ -3364,7 +3387,7 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3364
3387
  Additional info:
3365
3388
 
3366
3389
  `;
3367
- if (config2 == null ? void 0 : config2.branch) {
3390
+ if (config2?.branch) {
3368
3391
  errorMessage += ` Branch: ${config2.branch}, Client ID: ${config2.clientId}
3369
3392
  `;
3370
3393
  }
@@ -3376,18 +3399,13 @@ Additional info:
3376
3399
  }
3377
3400
  }
3378
3401
  };
3379
- BuildCommand.paths = [["build"]];
3380
- BuildCommand.usage = import_clipanion3.Command.Usage({
3381
- category: `Commands`,
3382
- description: `Build the CMS and autogenerated modules for usage with TinaCloud`
3383
- });
3384
3402
  async function request(args) {
3385
3403
  const headers = new Headers();
3386
3404
  if (args.token) {
3387
3405
  headers.append("X-API-KEY", args.token);
3388
3406
  }
3389
3407
  headers.append("Content-Type", "application/json");
3390
- const url = args == null ? void 0 : args.url;
3408
+ const url = args?.url;
3391
3409
  const res = await fetch(url, {
3392
3410
  method: args.method || "GET",
3393
3411
  headers,
@@ -3417,9 +3435,10 @@ Message from server: ${json.message}`;
3417
3435
  );
3418
3436
  }
3419
3437
  return {
3420
- status: json == null ? void 0 : json.status,
3421
- timestamp: json == null ? void 0 : json.timestamp,
3422
- hasUpstream: (json == null ? void 0 : json.hasUpstream) || false
3438
+ status: json?.status,
3439
+ timestamp: json?.timestamp,
3440
+ hasUpstream: json?.hasUpstream || false,
3441
+ json
3423
3442
  };
3424
3443
  }
3425
3444
  var fetchRemoteGraphqlSchema = async ({
@@ -3442,7 +3461,7 @@ var fetchRemoteGraphqlSchema = async ({
3442
3461
  });
3443
3462
  const data = await res.json();
3444
3463
  return {
3445
- remoteSchema: data == null ? void 0 : data.data,
3464
+ remoteSchema: data?.data,
3446
3465
  remoteRuntimeVersion: res.headers.get("tinacms-grapqhl-version"),
3447
3466
  remoteProjectVersion: res.headers.get("tinacms-graphql-project-version")
3448
3467
  };
@@ -3652,6 +3671,15 @@ var AuditCommand = class extends import_clipanion4.Command {
3652
3671
  description: "Specify a port to run the datalayer server on. (default 9000)"
3653
3672
  });
3654
3673
  }
3674
+ static {
3675
+ this.paths = [["audit"]];
3676
+ }
3677
+ static {
3678
+ this.usage = import_clipanion4.Command.Usage({
3679
+ category: `Commands`,
3680
+ description: `Audit config and content files`
3681
+ });
3682
+ }
3655
3683
  async catch(error) {
3656
3684
  logger.error("Error occured during tinacms audit");
3657
3685
  if (this.verbose) {
@@ -3705,11 +3733,6 @@ var AuditCommand = class extends import_clipanion4.Command {
3705
3733
  process.exit();
3706
3734
  }
3707
3735
  };
3708
- AuditCommand.paths = [["audit"]];
3709
- AuditCommand.usage = import_clipanion4.Command.Usage({
3710
- category: `Commands`,
3711
- description: `Audit config and content files`
3712
- });
3713
3736
 
3714
3737
  // src/next/commands/init-command/index.ts
3715
3738
  var import_clipanion6 = require("clipanion");
@@ -3728,13 +3751,13 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
3728
3751
  const result = {
3729
3752
  fullPathTS: import_path7.default.join(
3730
3753
  parentPath,
3731
- `${name2}.${(opts == null ? void 0 : opts.typescriptSuffix) || (opts == null ? void 0 : opts.extensionOverride) || "ts"}`
3754
+ `${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
3732
3755
  ),
3733
3756
  fullPathJS: import_path7.default.join(
3734
3757
  parentPath,
3735
- `${name2}.${(opts == null ? void 0 : opts.extensionOverride) || "js"}`
3758
+ `${name2}.${opts?.extensionOverride || "js"}`
3736
3759
  ),
3737
- fullPathOverride: (opts == null ? void 0 : opts.extensionOverride) ? import_path7.default.join(parentPath, `${name2}.${opts == null ? void 0 : opts.extensionOverride}`) : "",
3760
+ fullPathOverride: opts?.extensionOverride ? import_path7.default.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
3738
3761
  generatedFileType,
3739
3762
  name: name2,
3740
3763
  parentPath,
@@ -3762,7 +3785,6 @@ var detectEnvironment = async ({
3762
3785
  rootPath,
3763
3786
  debug = false
3764
3787
  }) => {
3765
- var _a;
3766
3788
  const hasForestryConfig = await import_fs_extra8.default.pathExists(
3767
3789
  import_path7.default.join(pathToForestryConfig, ".forestry", "settings.yml")
3768
3790
  );
@@ -3819,10 +3841,10 @@ var detectEnvironment = async ({
3819
3841
  try {
3820
3842
  const packageJSON = await import_fs_extra8.default.readJSON("package.json");
3821
3843
  const deps = [];
3822
- if (packageJSON == null ? void 0 : packageJSON.dependencies) {
3844
+ if (packageJSON?.dependencies) {
3823
3845
  deps.push(...Object.keys(packageJSON.dependencies));
3824
3846
  }
3825
- if (packageJSON == null ? void 0 : packageJSON.devDependencies) {
3847
+ if (packageJSON?.devDependencies) {
3826
3848
  deps.push(...Object.keys(packageJSON.devDependencies));
3827
3849
  }
3828
3850
  if (deps.includes("@tinacms/cli") && deps.includes("tinacms")) {
@@ -3843,7 +3865,7 @@ var detectEnvironment = async ({
3843
3865
  const hugoConfigPath = import_path7.default.join(rootPath, "config.toml");
3844
3866
  if (await import_fs_extra8.default.pathExists(hugoConfigPath)) {
3845
3867
  const hugoConfig = await import_fs_extra8.default.readFile(hugoConfigPath, "utf8");
3846
- const metaDataFormat = (_a = hugoConfig.match(/metaDataFormat = "(.*)"/)) == null ? void 0 : _a[1];
3868
+ const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
3847
3869
  if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
3848
3870
  frontMatterFormat = metaDataFormat;
3849
3871
  }
@@ -4494,8 +4516,7 @@ var ErrorSingleton = class _ErrorSingleton {
4494
4516
  this.collectionNameErrors.push(error);
4495
4517
  }
4496
4518
  printCollectionNameErrors() {
4497
- var _a;
4498
- if ((_a = this.collectionNameErrors) == null ? void 0 : _a.length) {
4519
+ if (this.collectionNameErrors?.length) {
4499
4520
  logger.error(
4500
4521
  dangerText("ERROR: TinaCMS only supports alphanumeric template names")
4501
4522
  );
@@ -4677,8 +4698,7 @@ var transformForestryFieldsToTinaFields = ({
4677
4698
  skipBlocks = false
4678
4699
  }) => {
4679
4700
  const tinaFields = [];
4680
- fields == null ? void 0 : fields.forEach((forestryField2) => {
4681
- var _a, _b, _c, _d;
4701
+ fields?.forEach((forestryField2) => {
4682
4702
  if (forestryField2.name === "menu") {
4683
4703
  logger.info(
4684
4704
  warnText(
@@ -4754,12 +4774,12 @@ var transformForestryFieldsToTinaFields = ({
4754
4774
  };
4755
4775
  break;
4756
4776
  case "select":
4757
- if ((_a = forestryField2.config) == null ? void 0 : _a.options) {
4777
+ if (forestryField2.config?.options) {
4758
4778
  field = {
4759
4779
  type: "string",
4760
4780
  ...getTinaFieldsFromName(forestryField2.name),
4761
4781
  label: forestryField2.label,
4762
- options: ((_b = forestryField2.config) == null ? void 0 : _b.options) || []
4782
+ options: forestryField2.config?.options || []
4763
4783
  };
4764
4784
  } else {
4765
4785
  logger.info(
@@ -4777,7 +4797,7 @@ var transformForestryFieldsToTinaFields = ({
4777
4797
  label: forestryField2.label,
4778
4798
  list: true
4779
4799
  };
4780
- if ((_c = forestryField2.config) == null ? void 0 : _c.options) {
4800
+ if (forestryField2.config?.options) {
4781
4801
  field.options = forestryField2.config.options;
4782
4802
  }
4783
4803
  break;
@@ -4825,7 +4845,7 @@ var transformForestryFieldsToTinaFields = ({
4825
4845
  break;
4826
4846
  }
4827
4847
  const templates2 = [];
4828
- forestryField2 == null ? void 0 : forestryField2.template_types.forEach((tem) => {
4848
+ forestryField2?.template_types.forEach((tem) => {
4829
4849
  const { template: template2 } = getFieldsFromTemplates({
4830
4850
  tem,
4831
4851
  skipBlocks: true,
@@ -4883,7 +4903,7 @@ var transformForestryFieldsToTinaFields = ({
4883
4903
  );
4884
4904
  }
4885
4905
  if (field) {
4886
- if ((_d = forestryField2.config) == null ? void 0 : _d.required) {
4906
+ if (forestryField2.config?.required) {
4887
4907
  field = { ...field, required: true };
4888
4908
  }
4889
4909
  tinaFields.push(field);
@@ -4945,8 +4965,7 @@ var stringifyLabelWithField = (label) => {
4945
4965
  return `${labelString}Fields`;
4946
4966
  };
4947
4967
  var transformForestryMatchToTinaMatch = (match) => {
4948
- var _a, _b;
4949
- const newMatch = (_b = (_a = match.replace(" ", "").replace(/\.?(mdx|md|json|yaml|yml|toml)/g, "")) == null ? void 0 : _a.replace(/\..*$/g, "")) == null ? void 0 : _b.replace("{}", "");
4968
+ const newMatch = match.replace(" ", "").replace(/\.?(mdx|md|json|yaml|yml|toml)/g, "")?.replace(/\..*$/g, "")?.replace("{}", "");
4950
4969
  if (match !== newMatch) {
4951
4970
  logger.info(
4952
4971
  `Info: Match ${match} was transformed to ${newMatch}. See ${linkText(
@@ -5011,18 +5030,18 @@ var generateCollectionFromForestrySection = (args) => {
5011
5030
  }
5012
5031
  if (section.match) {
5013
5032
  baseCollection.match = {
5014
- ...(baseCollection == null ? void 0 : baseCollection.match) || {},
5033
+ ...baseCollection?.match || {},
5015
5034
  include: transformForestryMatchToTinaMatch(section.match)
5016
5035
  };
5017
5036
  }
5018
5037
  if (section.exclude) {
5019
5038
  baseCollection.match = {
5020
- ...(baseCollection == null ? void 0 : baseCollection.match) || {},
5039
+ ...baseCollection?.match || {},
5021
5040
  exclude: transformForestryMatchToTinaMatch(section.exclude)
5022
5041
  };
5023
5042
  }
5024
5043
  if (section.type === "directory") {
5025
- if (!(section == null ? void 0 : section.path) || section.path === "/" || section.path === "./" || section.path === ".") {
5044
+ if (!section?.path || section.path === "/" || section.path === "./" || section.path === ".") {
5026
5045
  logger.log(
5027
5046
  warnText(
5028
5047
  `Warning: Section ${section.label} is using a Root Path. Currently, Tina Does not support Root paths see ${linkText(
@@ -5032,11 +5051,11 @@ var generateCollectionFromForestrySection = (args) => {
5032
5051
  );
5033
5052
  return;
5034
5053
  }
5035
- const forestryTemplates = (section == null ? void 0 : section.templates) || [];
5054
+ const forestryTemplates = section?.templates || [];
5036
5055
  if (forestryTemplates.length === 0 && section.create === "all") {
5037
5056
  for (const templateKey of templateMap.keys()) {
5038
5057
  const { templateObj } = templateMap.get(templateKey);
5039
- const pages = templateObj == null ? void 0 : templateObj.pages;
5058
+ const pages = templateObj?.pages;
5040
5059
  if (pages) {
5041
5060
  let glob = section.match;
5042
5061
  const skipPath = section.path === "" || section.path === "/" || !section.path;
@@ -5053,7 +5072,7 @@ var generateCollectionFromForestrySection = (args) => {
5053
5072
  }
5054
5073
  const hasBody = ["md", "mdx", "markdown"].includes(format3);
5055
5074
  let c;
5056
- if (((forestryTemplates == null ? void 0 : forestryTemplates.length) || 0) > 1) {
5075
+ if ((forestryTemplates?.length || 0) > 1) {
5057
5076
  c = {
5058
5077
  ...baseCollection,
5059
5078
  // @ts-expect-error
@@ -5075,7 +5094,7 @@ var generateCollectionFromForestrySection = (args) => {
5075
5094
  })
5076
5095
  };
5077
5096
  }
5078
- if ((forestryTemplates == null ? void 0 : forestryTemplates.length) === 1) {
5097
+ if (forestryTemplates?.length === 1) {
5079
5098
  const tem = forestryTemplates[0];
5080
5099
  const template = templateMap.get(tem);
5081
5100
  const fieldsString = stringifyLabelWithField(template.templateObj.label);
@@ -5090,7 +5109,7 @@ var generateCollectionFromForestrySection = (args) => {
5090
5109
  })
5091
5110
  };
5092
5111
  }
5093
- if ((forestryTemplates == null ? void 0 : forestryTemplates.length) === 0) {
5112
+ if (forestryTemplates?.length === 0) {
5094
5113
  logger.warn(
5095
5114
  warnText(
5096
5115
  `No templates found for section ${section.label}. Please see ${linkText(
@@ -5103,7 +5122,7 @@ var generateCollectionFromForestrySection = (args) => {
5103
5122
  fields: [BODY_FIELD]
5104
5123
  };
5105
5124
  }
5106
- if ((section == null ? void 0 : section.create) === "none") {
5125
+ if (section?.create === "none") {
5107
5126
  c.ui = {
5108
5127
  ...c.ui,
5109
5128
  allowedActions: {
@@ -5125,7 +5144,7 @@ var generateCollectionFromForestrySection = (args) => {
5125
5144
  }
5126
5145
  for (const currentTemplateName of templateMap.keys()) {
5127
5146
  const { templateObj, fields: additionalFields } = templateMap.get(currentTemplateName);
5128
- const pages = (templateObj == null ? void 0 : templateObj.pages) || [];
5147
+ const pages = templateObj?.pages || [];
5129
5148
  if (pages.includes(section.path)) {
5130
5149
  fields.push(...additionalFields);
5131
5150
  break;
@@ -5204,11 +5223,10 @@ var generateCollections = async ({
5204
5223
  };
5205
5224
  };
5206
5225
  var rewriteTemplateKeysInDocs = (args) => {
5207
- var _a;
5208
5226
  const { templateMap, markdownParseConfig } = args;
5209
5227
  for (const templateKey of templateMap.keys()) {
5210
5228
  const { templateObj } = templateMap.get(templateKey);
5211
- (_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
5229
+ templateObj?.pages?.forEach((page) => {
5212
5230
  try {
5213
5231
  const filePath = import_path9.default.join(page);
5214
5232
  if (import_fs_extra10.default.lstatSync(filePath).isDirectory()) {
@@ -5257,6 +5275,15 @@ var CodemodCommand = class extends import_clipanion5.Command {
5257
5275
  description: "increase verbosity of logged output"
5258
5276
  });
5259
5277
  }
5278
+ static {
5279
+ this.paths = [["codemod"], ["codemod", "move-tina-folder"]];
5280
+ }
5281
+ static {
5282
+ this.usage = import_clipanion5.Command.Usage({
5283
+ category: `Commands`,
5284
+ description: `Use codemods for various Tina tasks`
5285
+ });
5286
+ }
5260
5287
  async catch(error) {
5261
5288
  console.log(error);
5262
5289
  }
@@ -5277,11 +5304,6 @@ var CodemodCommand = class extends import_clipanion5.Command {
5277
5304
  await command2();
5278
5305
  }
5279
5306
  };
5280
- CodemodCommand.paths = [["codemod"], ["codemod", "move-tina-folder"]];
5281
- CodemodCommand.usage = import_clipanion5.Command.Usage({
5282
- category: `Commands`,
5283
- description: `Use codemods for various Tina tasks`
5284
- });
5285
5307
  var moveTinaFolder = async (rootPath = process.cwd()) => {
5286
5308
  const configManager = new ConfigManager({ rootPath });
5287
5309
  try {
@@ -5561,11 +5583,10 @@ var baseFields = `[
5561
5583
  },
5562
5584
  ]`;
5563
5585
  var generateCollectionString = (args) => {
5564
- var _a, _b, _c, _d;
5565
5586
  if (args.collections) {
5566
5587
  return args.collections;
5567
5588
  }
5568
- let extraTinaCollections = (_b = (_a = args.config.authProvider) == null ? void 0 : _a.extraTinaCollections) == null ? void 0 : _b.join(",\n");
5589
+ let extraTinaCollections = args.config.authProvider?.extraTinaCollections?.join(",\n");
5569
5590
  if (extraTinaCollections) {
5570
5591
  extraTinaCollections = extraTinaCollections + ",";
5571
5592
  }
@@ -5591,18 +5612,17 @@ var generateCollectionString = (args) => {
5591
5612
  },
5592
5613
  },
5593
5614
  ]`;
5594
- if (((_d = (_c = args.config) == null ? void 0 : _c.framework) == null ? void 0 : _d.name) === "next") {
5615
+ if (args.config?.framework?.name === "next") {
5595
5616
  return nextExampleCollection;
5596
5617
  }
5597
5618
  return baseCollections;
5598
5619
  };
5599
5620
  var generateConfig = (args) => {
5600
- var _a, _b, _c;
5601
- const isUsingTinaCloud = !args.selfHosted || ((_a = args.config.authProvider) == null ? void 0 : _a.name) === "tina-cloud";
5621
+ const isUsingTinaCloud = !args.selfHosted || args.config.authProvider?.name === "tina-cloud";
5602
5622
  let extraImports = "";
5603
5623
  if (args.selfHosted) {
5604
5624
  if (args.config.authProvider) {
5605
- extraImports = extraImports + makeImportString((_b = args.config.authProvider) == null ? void 0 : _b.configImports);
5625
+ extraImports = extraImports + makeImportString(args.config.authProvider?.configImports);
5606
5626
  }
5607
5627
  if (!isUsingTinaCloud) {
5608
5628
  extraImports = extraImports + `
@@ -5625,7 +5645,7 @@ import { LocalAuthProvider } from "tinacms";`;
5625
5645
  branch,
5626
5646
  ${args.selfHosted && !isUsingTinaCloud ? `authProvider: isLocal
5627
5647
  ? new LocalAuthProvider()
5628
- :${(_c = args.config) == null ? void 0 : _c.authProvider.configAuthProviderClass},` : ""}
5648
+ :${args.config?.authProvider.configAuthProviderClass},` : ""}
5629
5649
  ${isUsingTinaCloud ? `// Get this from tina.io
5630
5650
  clientId: process.env.NEXT_PUBLIC_TINA_CLIENT_ID,` : ""}
5631
5651
  ${isUsingTinaCloud ? `// Get this from tina.io
@@ -5652,11 +5672,10 @@ import { LocalAuthProvider } from "tinacms";`;
5652
5672
 
5653
5673
  // src/cmds/init/templates/database.ts
5654
5674
  var databaseTemplate = ({ config: config2 }) => {
5655
- var _a, _b, _c, _d;
5656
5675
  return `
5657
5676
  import { createDatabase, createLocalDatabase } from '@tinacms/datalayer'
5658
- ${makeImportString((_a = config2.gitProvider) == null ? void 0 : _a.imports)}
5659
- ${makeImportString((_b = config2.databaseAdapter) == null ? void 0 : _b.imports)}
5677
+ ${makeImportString(config2.gitProvider?.imports)}
5678
+ ${makeImportString(config2.databaseAdapter?.imports)}
5660
5679
 
5661
5680
  const branch = (process.env.GITHUB_BRANCH ||
5662
5681
  process.env.VERCEL_GIT_COMMIT_REF ||
@@ -5668,8 +5687,8 @@ const isLocal = process.env.${config2.isLocalEnvVarName} === 'true'
5668
5687
  export default isLocal
5669
5688
  ? createLocalDatabase()
5670
5689
  : createDatabase({
5671
- gitProvider: ${(_c = config2.gitProvider) == null ? void 0 : _c.gitProviderClassText},
5672
- databaseAdapter: ${(_d = config2.databaseAdapter) == null ? void 0 : _d.databaseAdapterClassText},
5690
+ gitProvider: ${config2.gitProvider?.gitProviderClassText},
5691
+ databaseAdapter: ${config2.databaseAdapter?.databaseAdapterClassText},
5673
5692
  namespace: branch,
5674
5693
  })
5675
5694
  `;
@@ -5680,10 +5699,9 @@ var nextApiRouteTemplate = ({
5680
5699
  config: config2,
5681
5700
  env
5682
5701
  }) => {
5683
- var _a, _b;
5684
5702
  const extraPath = env.usingSrc ? "../" : "";
5685
5703
  return `import { TinaNodeBackend, LocalBackendAuthProvider } from '@tinacms/datalayer'
5686
- ${makeImportString((_a = config2.authProvider) == null ? void 0 : _a.backendAuthProviderImports)}
5704
+ ${makeImportString(config2.authProvider?.backendAuthProviderImports)}
5687
5705
 
5688
5706
 
5689
5707
 
@@ -5694,7 +5712,7 @@ var nextApiRouteTemplate = ({
5694
5712
  const handler = TinaNodeBackend({
5695
5713
  authProvider: isLocal
5696
5714
  ? LocalBackendAuthProvider()
5697
- : ${((_b = config2.authProvider) == null ? void 0 : _b.backendAuthProvider) || ""},
5715
+ : ${config2.authProvider?.backendAuthProvider || ""},
5698
5716
  databaseClient,
5699
5717
  })
5700
5718
 
@@ -5722,19 +5740,18 @@ var import_prettier2 = require("prettier");
5722
5740
  // src/utils/script-helpers.ts
5723
5741
  function generateGqlScript(scriptValue, opts) {
5724
5742
  const cmd = `tinacms dev -c "${scriptValue}"`;
5725
- if (opts == null ? void 0 : opts.isLocalEnvVarName) {
5743
+ if (opts?.isLocalEnvVarName) {
5726
5744
  return `${opts.isLocalEnvVarName}=true ${cmd}`;
5727
5745
  }
5728
5746
  return cmd;
5729
5747
  }
5730
5748
  function extendNextScripts(scripts, opts) {
5731
- var _a, _b;
5732
5749
  const result = {
5733
5750
  ...scripts,
5734
- dev: !(scripts == null ? void 0 : scripts.dev) || ((_a = scripts == null ? void 0 : scripts.dev) == null ? void 0 : _a.indexOf("tinacms dev -c")) === -1 ? generateGqlScript((scripts == null ? void 0 : scripts.dev) || "next dev", opts) : scripts == null ? void 0 : scripts.dev,
5735
- build: !(scripts == null ? void 0 : scripts.build) || !((_b = scripts == null ? void 0 : scripts.build) == null ? void 0 : _b.startsWith("tinacms build &&")) ? `tinacms build && ${(scripts == null ? void 0 : scripts.build) || "next build"}` : scripts == null ? void 0 : scripts.build
5751
+ dev: !scripts?.dev || scripts?.dev?.indexOf("tinacms dev -c") === -1 ? generateGqlScript(scripts?.dev || "next dev", opts) : scripts?.dev,
5752
+ build: !scripts?.build || !scripts?.build?.startsWith("tinacms build &&") ? `tinacms build && ${scripts?.build || "next build"}` : scripts?.build
5736
5753
  };
5737
- if ((opts == null ? void 0 : opts.addSetupUsers) && !scripts["setup:users"]) {
5754
+ if (opts?.addSetupUsers && !scripts["setup:users"]) {
5738
5755
  result["setup:users"] = "tinacms-next-auth setup";
5739
5756
  }
5740
5757
  return result;
@@ -5816,7 +5833,6 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
5816
5833
  }
5817
5834
  };
5818
5835
  var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
5819
- var _a;
5820
5836
  if (import_typescript3.default.isSourceFile(node)) {
5821
5837
  const newStatements = [...node.statements];
5822
5838
  let changed = false;
@@ -5825,7 +5841,7 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
5825
5841
  for (const statement of newStatements) {
5826
5842
  if (import_typescript3.default.isImportDeclaration(statement) && import_typescript3.default.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === moduleName) {
5827
5843
  foundImportStatement = true;
5828
- const existingImports = ((_a = statement.importClause) == null ? void 0 : _a.namedBindings) && import_typescript3.default.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements.map(
5844
+ const existingImports = statement.importClause?.namedBindings && import_typescript3.default.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements.map(
5829
5845
  (e) => e.name.text
5830
5846
  ) : [];
5831
5847
  const newImports = [
@@ -6042,7 +6058,6 @@ async function apply({
6042
6058
  params,
6043
6059
  config: config2
6044
6060
  }) {
6045
- var _a;
6046
6061
  if (config2.framework.name === "other" && config2.hosting === "self-host") {
6047
6062
  logger.error(
6048
6063
  logText(
@@ -6168,7 +6183,7 @@ async function apply({
6168
6183
  env.tinaConfigExists && // Are we running tinacms init backend
6169
6184
  params.isBackendInit && // Do the user choose the 'self-host' option
6170
6185
  config2.hosting === "self-host" && // the user did not choose the 'tina-cloud' auth provider
6171
- (((_a = config2.authProvider) == null ? void 0 : _a.name) || "") !== "tina-cloud"
6186
+ (config2.authProvider?.name || "") !== "tina-cloud"
6172
6187
  ) {
6173
6188
  await addSelfHostedTinaAuthToConfig(config2, env.generatedFiles["config"]);
6174
6189
  }
@@ -6236,7 +6251,6 @@ var updateGitIgnore = async ({
6236
6251
  await import_fs_extra13.default.writeFile(import_path11.default.join(baseDir, ".gitignore"), newGitignoreContent);
6237
6252
  };
6238
6253
  var addDependencies = async (config2, env, params) => {
6239
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
6240
6254
  const { packageManager } = config2;
6241
6255
  const tagVersion = params.tinaVersion ? `@${params.tinaVersion}` : "";
6242
6256
  let deps = [];
@@ -6252,18 +6266,18 @@ var addDependencies = async (config2, env, params) => {
6252
6266
  deps.push("@tinacms/datalayer");
6253
6267
  }
6254
6268
  deps.push(
6255
- ...((_b = (_a = config2.databaseAdapter) == null ? void 0 : _a.imports) == null ? void 0 : _b.map((x) => x.packageName)) || []
6269
+ ...config2.databaseAdapter?.imports?.map((x) => x.packageName) || []
6256
6270
  );
6257
- deps.push(...((_c = config2.authProvider) == null ? void 0 : _c.peerDependencies) || []);
6271
+ deps.push(...config2.authProvider?.peerDependencies || []);
6258
6272
  deps.push(
6259
- ...((_e = (_d = config2.authProvider) == null ? void 0 : _d.backendAuthProviderImports) == null ? void 0 : _e.map(
6273
+ ...config2.authProvider?.backendAuthProviderImports?.map(
6260
6274
  (x) => x.packageName
6261
- )) || []
6275
+ ) || []
6262
6276
  );
6263
6277
  deps.push(
6264
- ...((_g = (_f = config2.authProvider) == null ? void 0 : _f.configImports) == null ? void 0 : _g.map((x) => x.packageName)) || []
6278
+ ...config2.authProvider?.configImports?.map((x) => x.packageName) || []
6265
6279
  );
6266
- deps.push(...((_i = (_h = config2.gitProvider) == null ? void 0 : _h.imports) == null ? void 0 : _i.map((x) => x.packageName)) || []);
6280
+ deps.push(...config2.gitProvider?.imports?.map((x) => x.packageName) || []);
6267
6281
  if (tagVersion) {
6268
6282
  deps = deps.map(
6269
6283
  (dep) => dep.indexOf("tina") >= 0 ? `${dep}${tagVersion}` : dep
@@ -6327,12 +6341,11 @@ var addConfigFile = async ({
6327
6341
  generatedFile,
6328
6342
  config: config2
6329
6343
  }) => {
6330
- var _a;
6331
6344
  const content = (0, import_prettier2.format)(generateConfig(configArgs), {
6332
6345
  parser: "babel"
6333
6346
  });
6334
6347
  await writeGeneratedFile({
6335
- overwrite: (_a = config2.overwriteList) == null ? void 0 : _a.includes("config"),
6348
+ overwrite: config2.overwriteList?.includes("config"),
6336
6349
  generatedFile,
6337
6350
  content,
6338
6351
  typescript: config2.typescript
@@ -6346,10 +6359,9 @@ var addDatabaseFile = async ({
6346
6359
  config: config2,
6347
6360
  generatedFile
6348
6361
  }) => {
6349
- var _a;
6350
6362
  await writeGeneratedFile({
6351
6363
  generatedFile,
6352
- overwrite: (_a = config2.overwriteList) == null ? void 0 : _a.includes("database"),
6364
+ overwrite: config2.overwriteList?.includes("database"),
6353
6365
  content: databaseTemplate({ config: config2 }),
6354
6366
  typescript: config2.typescript
6355
6367
  });
@@ -6359,13 +6371,12 @@ var addNextApiRoute = async ({
6359
6371
  generatedFile,
6360
6372
  env
6361
6373
  }) => {
6362
- var _a;
6363
6374
  const content = (0, import_prettier2.format)(nextApiRouteTemplate({ config: config2, env }), {
6364
6375
  parser: "babel"
6365
6376
  });
6366
6377
  await writeGeneratedFile({
6367
6378
  generatedFile,
6368
- overwrite: (_a = config2.overwriteList) == null ? void 0 : _a.includes("next-api-handler"),
6379
+ overwrite: config2.overwriteList?.includes("next-api-handler"),
6369
6380
  content,
6370
6381
  typescript: config2.typescript
6371
6382
  });
@@ -6375,10 +6386,9 @@ var addTemplateFile = async ({
6375
6386
  generatedFile,
6376
6387
  config: config2
6377
6388
  }) => {
6378
- var _a;
6379
6389
  await writeGeneratedFile({
6380
6390
  generatedFile,
6381
- overwrite: (_a = config2.overwriteList) == null ? void 0 : _a.includes(generatedFile.generatedFileType),
6391
+ overwrite: config2.overwriteList?.includes(generatedFile.generatedFileType),
6382
6392
  content,
6383
6393
  typescript: config2.typescript
6384
6394
  });
@@ -6387,7 +6397,6 @@ var addContentFile = async ({
6387
6397
  config: config2,
6388
6398
  env
6389
6399
  }) => {
6390
- var _a;
6391
6400
  await writeGeneratedFile({
6392
6401
  generatedFile: {
6393
6402
  javascriptExists: false,
@@ -6405,7 +6414,7 @@ var addContentFile = async ({
6405
6414
  });
6406
6415
  }
6407
6416
  },
6408
- overwrite: (_a = config2.overwriteList) == null ? void 0 : _a.includes("sample-content"),
6417
+ overwrite: config2.overwriteList?.includes("sample-content"),
6409
6418
  content: helloWorldPost,
6410
6419
  typescript: false
6411
6420
  });
@@ -6496,12 +6505,11 @@ var addReactiveFile = {
6496
6505
  baseDir,
6497
6506
  dataLayer
6498
6507
  }) => {
6499
- var _a, _b;
6500
6508
  const packageJsonPath = import_path11.default.join(baseDir, "package.json");
6501
6509
  await writeGeneratedFile({
6502
6510
  generatedFile,
6503
6511
  typescript: config2.typescript,
6504
- overwrite: (_a = config2.overwriteList) == null ? void 0 : _a.includes(
6512
+ overwrite: config2.overwriteList?.includes(
6505
6513
  generatedFile.generatedFileType
6506
6514
  ),
6507
6515
  content: templates["demo-post-page"]({
@@ -6517,7 +6525,7 @@ var addReactiveFile = {
6517
6525
  ...packageJson,
6518
6526
  scripts: extendNextScripts(scripts, {
6519
6527
  isLocalEnvVarName: config2.isLocalEnvVarName,
6520
- addSetupUsers: ((_b = config2.authProvider) == null ? void 0 : _b.name) === "next-auth"
6528
+ addSetupUsers: config2.authProvider?.name === "next-auth"
6521
6529
  })
6522
6530
  },
6523
6531
  null,
@@ -6592,6 +6600,15 @@ var InitCommand = class extends import_clipanion6.Command {
6592
6600
  description: "Specify a version for tina dependencies"
6593
6601
  });
6594
6602
  }
6603
+ static {
6604
+ this.paths = [["init"], ["init", "backend"]];
6605
+ }
6606
+ static {
6607
+ this.usage = import_clipanion6.Command.Usage({
6608
+ category: `Commands`,
6609
+ description: `Add Tina to an existing project`
6610
+ });
6611
+ }
6595
6612
  async catch(error) {
6596
6613
  logger.error("Error occured during tinacms init");
6597
6614
  console.error(error);
@@ -6611,11 +6628,6 @@ var InitCommand = class extends import_clipanion6.Command {
6611
6628
  process.exit();
6612
6629
  }
6613
6630
  };
6614
- InitCommand.paths = [["init"], ["init", "backend"]];
6615
- InitCommand.usage = import_clipanion6.Command.Usage({
6616
- category: `Commands`,
6617
- description: `Add Tina to an existing project`
6618
- });
6619
6631
 
6620
6632
  // src/next/commands/searchindex-command/index.ts
6621
6633
  var import_clipanion7 = require("clipanion");
@@ -6631,13 +6643,21 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
6631
6643
  description: "increase verbosity of logged output"
6632
6644
  });
6633
6645
  }
6646
+ static {
6647
+ this.paths = [["search-index"]];
6648
+ }
6649
+ static {
6650
+ this.usage = import_clipanion7.Command.Usage({
6651
+ category: `Commands`,
6652
+ description: `Index the site for search`
6653
+ });
6654
+ }
6634
6655
  async catch(error) {
6635
6656
  logger.error("Error occured during tinacms search-index");
6636
6657
  console.error(error);
6637
6658
  process.exit(1);
6638
6659
  }
6639
6660
  async execute() {
6640
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
6641
6661
  const rootPath = this.rootPath || process.cwd();
6642
6662
  const configManager = new ConfigManager({ rootPath });
6643
6663
  try {
@@ -6648,7 +6668,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
6648
6668
  console.error(e);
6649
6669
  }
6650
6670
  }
6651
- if (!((_a = configManager.config) == null ? void 0 : _a.search)) {
6671
+ if (!configManager.config?.search) {
6652
6672
  logger.error("No search config found");
6653
6673
  process.exit(1);
6654
6674
  }
@@ -6657,9 +6677,9 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
6657
6677
  schema: { ...schema, config: configManager.config }
6658
6678
  });
6659
6679
  let client;
6660
- const hasTinaSearch = Boolean((_c = (_b = configManager.config) == null ? void 0 : _b.search) == null ? void 0 : _c.tina);
6680
+ const hasTinaSearch = Boolean(configManager.config?.search?.tina);
6661
6681
  if (hasTinaSearch) {
6662
- if (!((_d = configManager.config) == null ? void 0 : _d.branch)) {
6682
+ if (!configManager.config?.branch) {
6663
6683
  logger.error(
6664
6684
  `${dangerText(
6665
6685
  `ERROR: Branch not configured in tina search configuration.`
@@ -6667,11 +6687,11 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
6667
6687
  );
6668
6688
  throw new Error("Branch not configured in tina search configuration.");
6669
6689
  }
6670
- if (!((_e = configManager.config) == null ? void 0 : _e.clientId)) {
6690
+ if (!configManager.config?.clientId) {
6671
6691
  logger.error(`${dangerText(`ERROR: clientId not configured.`)}`);
6672
6692
  throw new Error("clientId not configured.");
6673
6693
  }
6674
- if (!((_h = (_g = (_f = configManager.config) == null ? void 0 : _f.search) == null ? void 0 : _g.tina) == null ? void 0 : _h.indexerToken)) {
6694
+ if (!configManager.config?.search?.tina?.indexerToken) {
6675
6695
  logger.error(
6676
6696
  `${dangerText(
6677
6697
  `ERROR: indexerToken not configured in tina search configuration.`
@@ -6682,22 +6702,22 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
6682
6702
  );
6683
6703
  }
6684
6704
  client = new import_search3.TinaCMSSearchIndexClient({
6685
- apiUrl: `${((_i = configManager.config.tinaioConfig) == null ? void 0 : _i.contentApiUrlOverride) || "https://content.tinajs.io"}/searchIndex/${(_j = configManager.config) == null ? void 0 : _j.clientId}`,
6686
- branch: (_k = configManager.config) == null ? void 0 : _k.branch,
6687
- indexerToken: (_n = (_m = (_l = configManager.config) == null ? void 0 : _l.search) == null ? void 0 : _m.tina) == null ? void 0 : _n.indexerToken,
6688
- stopwordLanguages: (_q = (_p = (_o = configManager.config) == null ? void 0 : _o.search) == null ? void 0 : _p.tina) == null ? void 0 : _q.stopwordLanguages
6705
+ apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
6706
+ branch: configManager.config?.branch,
6707
+ indexerToken: configManager.config?.search?.tina?.indexerToken,
6708
+ stopwordLanguages: configManager.config?.search?.tina?.stopwordLanguages
6689
6709
  });
6690
6710
  } else {
6691
- client = (_s = (_r = configManager.config) == null ? void 0 : _r.search) == null ? void 0 : _s.searchClient;
6711
+ client = configManager.config?.search?.searchClient;
6692
6712
  }
6693
6713
  const searchIndexer = new import_search3.SearchIndexer({
6694
- batchSize: ((_t = configManager.config.search) == null ? void 0 : _t.indexBatchSize) || 100,
6714
+ batchSize: configManager.config.search?.indexBatchSize || 100,
6695
6715
  bridge: new import_graphql17.FilesystemBridge(
6696
6716
  configManager.rootPath,
6697
6717
  configManager.contentRootPath
6698
6718
  ),
6699
6719
  schema: tinaSchema,
6700
- textIndexLength: ((_u = configManager.config.search) == null ? void 0 : _u.maxSearchIndexFieldLength) || 100,
6720
+ textIndexLength: configManager.config.search?.maxSearchIndexFieldLength || 100,
6701
6721
  client
6702
6722
  });
6703
6723
  let err;
@@ -6718,11 +6738,6 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
6718
6738
  process.exit(0);
6719
6739
  }
6720
6740
  };
6721
- SearchIndexCommand.paths = [["search-index"]];
6722
- SearchIndexCommand.usage = import_clipanion7.Command.Usage({
6723
- category: `Commands`,
6724
- description: `Index the site for search`
6725
- });
6726
6741
 
6727
6742
  // src/index.ts
6728
6743
  var cli = new import_clipanion8.Cli({