@tinacms/cli 0.0.0-9594668-20241223035907 → 0.0.0-984566a-20250219181559

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
@@ -17,23 +17,28 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
23
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
28
 
25
29
  // src/index.ts
26
- var src_exports = {};
27
- __export(src_exports, {
28
- default: () => src_default
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => index_default
29
33
  });
30
- module.exports = __toCommonJS(src_exports);
34
+ module.exports = __toCommonJS(index_exports);
31
35
  var import_clipanion8 = require("clipanion");
32
36
 
33
37
  // package.json
34
- var version = "1.7.0";
38
+ var version = "1.8.4";
35
39
 
36
40
  // src/next/commands/dev-command/index.ts
41
+ var import_async_lock = __toESM(require("async-lock"));
37
42
  var import_clipanion2 = require("clipanion");
38
43
  var import_fs_extra6 = __toESM(require("fs-extra"));
39
44
  var import_path5 = __toESM(require("path"));
@@ -41,12 +46,12 @@ var import_chokidar = __toESM(require("chokidar"));
41
46
  var import_graphql10 = require("@tinacms/graphql");
42
47
 
43
48
  // src/next/config-manager.ts
44
- var import_fs_extra2 = __toESM(require("fs-extra"));
49
+ var import_fs_extra = __toESM(require("fs-extra"));
45
50
  var import_path = __toESM(require("path"));
46
51
  var import_os = __toESM(require("os"));
47
52
  var esbuild = __toESM(require("esbuild"));
48
53
  var dotenv = __toESM(require("dotenv"));
49
- var import_normalize_path2 = __toESM(require("normalize-path"));
54
+ var import_normalize_path = __toESM(require("normalize-path"));
50
55
  var import_chalk2 = __toESM(require("chalk"));
51
56
 
52
57
  // src/logger/index.ts
@@ -57,7 +62,10 @@ function isUnicodeSupported() {
57
62
  if (process.platform !== "win32") {
58
63
  return process.env.TERM !== "linux";
59
64
  }
60
- return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || Boolean(process.env.TERMINUS_SUBLIME) || process.env.ConEmuTask === "{cmd::Cmder}" || process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
65
+ return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || // Windows Terminal
66
+ Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
67
+ process.env.ConEmuTask === "{cmd::Cmder}" || // ConEmu and cmder
68
+ process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
61
69
  }
62
70
 
63
71
  // src/logger/index.ts
@@ -157,490 +165,6 @@ var S_SUCCESS = s("\u25C6", "*");
157
165
  var S_WARN = s("\u25B2", "!");
158
166
  var S_ERROR = s("\u25A0", "x");
159
167
 
160
- // src/next/vite/index.ts
161
- var import_node_path2 = __toESM(require("path"));
162
- var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
163
- var import_fs_extra = __toESM(require("fs-extra"));
164
- var import_normalize_path = __toESM(require("normalize-path"));
165
- var import_vite = require("vite");
166
-
167
- // src/next/vite/tailwind.ts
168
- var import_node_path = __toESM(require("path"));
169
- var import_aspect_ratio = __toESM(require("@tailwindcss/aspect-ratio"));
170
- var import_container_queries = __toESM(require("@tailwindcss/container-queries"));
171
- var import_typography = __toESM(require("@tailwindcss/typography"));
172
- var import_tailwindcss = __toESM(require("tailwindcss"));
173
- var import_defaultTheme = __toESM(require("tailwindcss/defaultTheme.js"));
174
- var tinaTailwind = (spaPath, prebuildFilePath) => {
175
- return {
176
- name: "vite-plugin-tina",
177
- config: (viteConfig) => {
178
- const plugins = [];
179
- const content = [
180
- import_node_path.default.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
181
- prebuildFilePath,
182
- require.resolve("tinacms")
183
- ];
184
- const tw = (0, import_tailwindcss.default)({
185
- theme: {
186
- columns: {
187
- auto: "auto",
188
- 1: "1",
189
- 2: "2",
190
- 3: "3",
191
- 4: "4",
192
- 5: "5",
193
- 6: "6",
194
- 7: "7",
195
- 8: "8",
196
- 9: "9",
197
- 10: "10",
198
- 11: "11",
199
- 12: "12",
200
- "3xs": "256px",
201
- "2xs": "288px",
202
- xs: "320px",
203
- sm: "384px",
204
- md: "448px",
205
- lg: "512px",
206
- xl: "576px",
207
- "2xl": "672px",
208
- "3xl": "768px",
209
- "4xl": "896px",
210
- "5xl": "1024px",
211
- "6xl": "1152px",
212
- "7xl": "1280px"
213
- },
214
- spacing: {
215
- px: "1px",
216
- 0: "0px",
217
- 0.5: "2px",
218
- 1: "4px",
219
- 1.5: "6px",
220
- 2: "8px",
221
- 2.5: "10px",
222
- 3: "12px",
223
- 3.5: "14px",
224
- 4: "16px",
225
- 5: "20px",
226
- 6: "24px",
227
- 7: "28px",
228
- 8: "32px",
229
- 9: "36px",
230
- 10: "40px",
231
- 11: "44px",
232
- 12: "48px",
233
- 14: "56px",
234
- 16: "64px",
235
- 18: "72px",
236
- 20: "80px",
237
- 24: "96px",
238
- 28: "114px",
239
- 32: "128px",
240
- 36: "144px",
241
- 40: "160px",
242
- 44: "176px",
243
- 48: "192px",
244
- 52: "208px",
245
- 56: "224px",
246
- 60: "240px",
247
- 64: "256px",
248
- 72: "288px",
249
- 80: "320px",
250
- 96: "384px"
251
- },
252
- borderRadius: {
253
- none: "0px",
254
- sm: "2px",
255
- DEFAULT: "4px",
256
- md: "6px",
257
- lg: "8px",
258
- xl: "12px",
259
- "2xl": "16px",
260
- "3xl": "24px",
261
- full: "9999px"
262
- },
263
- borderWidth: {
264
- DEFAULT: "1px",
265
- 0: "0",
266
- 2: "2px",
267
- 3: "3px",
268
- 4: "4px",
269
- 6: "6px",
270
- 8: "8px"
271
- },
272
- fontSize: {
273
- xs: ["13px", { lineHeight: "1.33" }],
274
- sm: ["14px", { lineHeight: "1.43" }],
275
- base: ["16px", { lineHeight: "1.5" }],
276
- md: ["16px", { lineHeight: "1.5" }],
277
- lg: ["18px", { lineHeight: "1.55" }],
278
- xl: ["20px", { lineHeight: "1.4" }],
279
- "2xl": ["24px", { lineHeight: "1.33" }],
280
- "3xl": ["30px", { lineHeight: "1.2" }],
281
- "4xl": ["36px", { lineHeight: "1.1" }],
282
- "5xl": ["48px", { lineHeight: "1" }],
283
- "6xl": ["60px", { lineHeight: "1" }],
284
- "7xl": ["72px", { lineHeight: "1" }],
285
- "8xl": ["96px", { lineHeight: "1" }],
286
- "9xl": ["128px", { lineHeight: "1" }]
287
- },
288
- opacity: {
289
- 0: "0",
290
- 5: ".05",
291
- 7: ".07",
292
- 10: ".1",
293
- 15: ".15",
294
- 20: ".2",
295
- 25: ".25",
296
- 30: ".3",
297
- 40: ".4",
298
- 50: ".5",
299
- 60: ".6",
300
- 70: ".7",
301
- 75: ".75",
302
- 80: ".8",
303
- 90: ".9",
304
- 100: "1"
305
- },
306
- zIndex: {
307
- "-1": "-1",
308
- base: "9000",
309
- panel: "9400",
310
- menu: "9800",
311
- chrome: "10200",
312
- overlay: "10600",
313
- modal: "10800",
314
- 0: "0",
315
- 10: "10",
316
- 20: "20",
317
- 30: "30",
318
- 40: "40",
319
- 25: "25",
320
- 50: "50",
321
- 75: "75",
322
- 100: "100",
323
- auto: "auto"
324
- },
325
- extend: {
326
- scale: {
327
- 97: ".97",
328
- 103: "1.03"
329
- },
330
- transitionDuration: {
331
- 0: "0ms",
332
- 2e3: "2000ms"
333
- },
334
- boxShadow: {
335
- xs: "0 0 0 1px rgba(0, 0, 0, 0.05)",
336
- outline: "0 0 0 3px rgba(66, 153, 225, 0.5)"
337
- },
338
- colors: {
339
- blue: {
340
- 50: "#DCEEFF",
341
- 100: "#B4DBFF",
342
- 200: "#85C5FE",
343
- 300: "#4EABFE",
344
- 400: "#2296fe",
345
- 500: "#0084FF",
346
- 600: "#0574e4",
347
- 700: "#0D5DBD",
348
- 800: "#144696",
349
- 900: "#1D2C6C",
350
- 1e3: "#241748"
351
- },
352
- gray: {
353
- 50: "#F6F6F9",
354
- 100: "#EDECF3",
355
- 150: "#E6E3EF",
356
- 200: "#E1DDEC",
357
- 250: "#C9C5D5",
358
- 300: "#b2adbe",
359
- 400: "#918c9e",
360
- 500: "#716c7f",
361
- 600: "#565165",
362
- 700: "#433e52",
363
- 800: "#363145",
364
- 900: "#252336",
365
- 1e3: "#1c1b2e"
366
- },
367
- orange: {
368
- 400: "#EB6337",
369
- 500: "#EC4815",
370
- 600: "#DC4419"
371
- },
372
- background: "#FFFFFF",
373
- foreground: "#0A0A0A",
374
- muted: "#F5F5F5",
375
- "muted-foreground": "#737373",
376
- popover: "#FFFFFF",
377
- "popover-foreground": "#0A0A0A",
378
- card: "#FFFFFF",
379
- "card-foreground": "#0A0A0A",
380
- border: "#E5E5E5",
381
- input: "#E5E5E5",
382
- primary: "#171717",
383
- "primary-foreground": "#FAFAFA",
384
- secondary: "#F5F5F5",
385
- "secondary-foreground": "#171717",
386
- accent: "#F5F5F5",
387
- "accent-foreground": "#171717",
388
- destructive: "#FF3B3B",
389
- "destructive-foreground": "#FAFAFA",
390
- ring: "#0A0A0A"
391
- },
392
- fontFamily: {
393
- sans: ["Inter", ...import_defaultTheme.default.fontFamily.sans]
394
- },
395
- lineHeight: {
396
- 3: "12px",
397
- 4: "16px",
398
- 5: "20px",
399
- 6: "24px",
400
- 7: "28px",
401
- 8: "32px",
402
- 9: "36px",
403
- 10: "40px"
404
- },
405
- maxWidth: {
406
- form: "900px"
407
- },
408
- screens: {
409
- xs: "320px",
410
- sm: "560px",
411
- md: "720px",
412
- lg: "1030px"
413
- }
414
- }
415
- },
416
- content,
417
- plugins: [
418
- (0, import_typography.default)({ className: "tina-prose" }),
419
- import_aspect_ratio.default,
420
- import_container_queries.default
421
- ]
422
- });
423
- plugins.push(tw);
424
- return {
425
- css: {
426
- postcss: {
427
- plugins
428
- }
429
- }
430
- };
431
- }
432
- };
433
- };
434
-
435
- // src/next/vite/index.ts
436
- async function listFilesRecursively({
437
- directoryPath,
438
- config: config2,
439
- roothPath
440
- }) {
441
- const fullDirectoryPath = import_node_path2.default.join(
442
- roothPath,
443
- config2.publicFolder,
444
- directoryPath
445
- );
446
- const exists = await import_fs_extra.default.pathExists(fullDirectoryPath);
447
- if (!exists) {
448
- return { "0": [] };
449
- }
450
- const items = await import_fs_extra.default.readdir(fullDirectoryPath);
451
- const staticMediaItems = [];
452
- for (const item of items) {
453
- const itemPath = import_node_path2.default.join(fullDirectoryPath, item);
454
- const stats = await import_fs_extra.default.promises.lstat(itemPath);
455
- const staticMediaItem = {
456
- id: item,
457
- filename: item,
458
- type: stats.isDirectory() ? "dir" : "file",
459
- directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
460
- src: `/${import_node_path2.default.join(directoryPath, item)}`,
461
- thumbnails: {
462
- "75x75": `/${import_node_path2.default.join(directoryPath, item)}`,
463
- "400x400": `/${import_node_path2.default.join(directoryPath, item)}`,
464
- "1000x1000": `/${import_node_path2.default.join(directoryPath, item)}`
465
- }
466
- };
467
- if (stats.isDirectory()) {
468
- staticMediaItem.children = await listFilesRecursively({
469
- directoryPath: import_node_path2.default.join(directoryPath, item),
470
- config: config2,
471
- roothPath
472
- });
473
- }
474
- staticMediaItems.push(staticMediaItem);
475
- }
476
- function chunkArrayIntoObject(array, chunkSize) {
477
- const result = {};
478
- for (let i = 0; i < array.length; i += chunkSize) {
479
- const chunkKey = `${i / chunkSize * 20}`;
480
- result[chunkKey] = array.slice(i, i + chunkSize);
481
- }
482
- return result;
483
- }
484
- return chunkArrayIntoObject(staticMediaItems, 20);
485
- }
486
- var loadProjectConfig = async ({
487
- rootPath,
488
- viteConfigEnv
489
- }) => {
490
- if (viteConfigEnv) {
491
- const configFileJs = import_node_path2.default.join(rootPath, "vite.config.js");
492
- const configFileTs = import_node_path2.default.join(rootPath, "vite.config.ts");
493
- if (import_fs_extra.default.existsSync(configFileJs)) {
494
- return await (0, import_vite.loadConfigFromFile)(viteConfigEnv, configFileJs);
495
- } else if (import_fs_extra.default.existsSync(configFileTs)) {
496
- return await (0, import_vite.loadConfigFromFile)(viteConfigEnv, configFileTs);
497
- }
498
- }
499
- return { config: {} };
500
- };
501
- var createConfig = async ({
502
- configManager,
503
- database,
504
- apiURL,
505
- plugins = [],
506
- noWatch,
507
- rollupOptions,
508
- viteConfigEnv
509
- }) => {
510
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
511
- const projectConfig = await loadProjectConfig({
512
- rootPath: configManager.rootPath,
513
- viteConfigEnv
514
- });
515
- const publicEnv = {};
516
- Object.keys(process.env).forEach((key) => {
517
- if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
518
- try {
519
- if (typeof process.env[key] === "string") {
520
- publicEnv[key] = process.env[key];
521
- } else {
522
- publicEnv[key] = JSON.stringify(process.env[key]);
523
- }
524
- } catch (error) {
525
- console.warn(
526
- `Could not stringify public env process.env.${key} env variable`
527
- );
528
- console.warn(error);
529
- }
530
- }
531
- });
532
- const staticMediaPath = import_node_path2.default.join(
533
- configManager.generatedFolderPath,
534
- "static-media.json"
535
- );
536
- if ((_b = (_a = configManager.config.media) == null ? void 0 : _a.tina) == null ? void 0 : _b.static) {
537
- const staticMedia = await listFilesRecursively({
538
- directoryPath: ((_c = configManager.config.media.tina) == null ? void 0 : _c.mediaRoot) || "",
539
- config: configManager.config.media.tina,
540
- roothPath: configManager.rootPath
541
- });
542
- await import_fs_extra.default.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
543
- } else {
544
- await import_fs_extra.default.outputFile(staticMediaPath, `[]`);
545
- }
546
- const alias = {
547
- TINA_IMPORT: configManager.prebuildFilePath,
548
- SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
549
- STATIC_MEDIA_IMPORT: staticMediaPath,
550
- crypto: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
551
- fs: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
552
- os: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
553
- path: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts")
554
- };
555
- if (configManager.shouldSkipSDK()) {
556
- alias["CLIENT_IMPORT"] = import_node_path2.default.join(
557
- configManager.spaRootPath,
558
- "src",
559
- "dummy-client.ts"
560
- );
561
- } else {
562
- alias["CLIENT_IMPORT"] = configManager.isUsingTs() ? configManager.generatedTypesTSFilePath : configManager.generatedTypesJSFilePath;
563
- }
564
- let basePath;
565
- if (configManager.config.build.basePath) {
566
- basePath = configManager.config.build.basePath;
567
- }
568
- const fullVersion = configManager.getTinaGraphQLVersion();
569
- const version2 = `${fullVersion.major}.${fullVersion.minor}`;
570
- const config2 = {
571
- root: configManager.spaRootPath,
572
- base: `/${basePath ? `${(0, import_normalize_path.default)(basePath)}/` : ""}${(0, import_normalize_path.default)(
573
- configManager.config.build.outputFolder
574
- )}/`,
575
- appType: "spa",
576
- resolve: {
577
- alias: {
578
- ...(_d = projectConfig.config.resolve) == null ? void 0 : _d.alias,
579
- ...alias
580
- },
581
- dedupe: ["graphql", "tinacms", "react", "react-dom", "react-router-dom"]
582
- },
583
- define: {
584
- "process.env": `new Object(${JSON.stringify(publicEnv)})`,
585
- "process.platform": `"${process.platform}"`,
586
- __API_URL__: `"${apiURL}"`,
587
- __BASE_PATH__: `"${((_f = (_e = configManager.config) == null ? void 0 : _e.build) == null ? void 0 : _f.basePath) || ""}"`,
588
- __TINA_GRAPHQL_VERSION__: version2
589
- },
590
- logLevel: "error",
591
- optimizeDeps: {
592
- force: true,
593
- include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
594
- },
595
- server: {
596
- host: (_i = (_h = (_g = configManager.config) == null ? void 0 : _g.build) == null ? void 0 : _h.host) != null ? _i : false,
597
- watch: noWatch ? {
598
- ignored: ["**/*"]
599
- } : {
600
- ignored: [
601
- `${configManager.tinaFolderPath}/**/!(config.prebuild.jsx|_graphql.json)`
602
- ]
603
- },
604
- fs: {
605
- strict: false
606
- }
607
- },
608
- build: {
609
- sourcemap: false,
610
- outDir: configManager.outputFolderPath,
611
- emptyOutDir: true,
612
- rollupOptions
613
- },
614
- plugins: [
615
- (0, import_plugin_react.default)({
616
- babel: {
617
- compact: true
618
- }
619
- }),
620
- (0, import_vite.splitVendorChunkPlugin)(),
621
- tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
622
- ...plugins
623
- ]
624
- };
625
- return config2;
626
- };
627
-
628
- // src/utils/resolve-alias-helpers.ts
629
- async function loadViteConfig(rootPath) {
630
- try {
631
- return await loadProjectConfig({
632
- rootPath,
633
- viteConfigEnv: {
634
- command: "build",
635
- mode: "production"
636
- }
637
- });
638
- } catch (error) {
639
- console.error("Failed to load Vite config:", error.message);
640
- throw new Error("Error loading Vite configuration");
641
- }
642
- }
643
-
644
168
  // src/next/config-manager.ts
645
169
  var TINA_FOLDER = "tina";
646
170
  var LEGACY_TINA_FOLDER = ".tina";
@@ -655,7 +179,7 @@ var ConfigManager = class {
655
179
  tinaGraphQLVersion,
656
180
  legacyNoSDK
657
181
  }) {
658
- this.rootPath = (0, import_normalize_path2.default)(rootPath);
182
+ this.rootPath = (0, import_normalize_path.default)(rootPath);
659
183
  this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
660
184
  this.legacyNoSDK = legacyNoSDK;
661
185
  }
@@ -696,7 +220,7 @@ var ConfigManager = class {
696
220
  this.generatedCachePath = import_path.default.join(
697
221
  this.generatedFolderPath,
698
222
  ".cache",
699
- String(new Date().getTime())
223
+ String((/* @__PURE__ */ new Date()).getTime())
700
224
  );
701
225
  this.generatedGraphQLGQLPath = import_path.default.join(
702
226
  this.generatedFolderPath,
@@ -766,13 +290,13 @@ var ConfigManager = class {
766
290
  this.generatedFolderPath,
767
291
  "databaseClient.js"
768
292
  );
769
- const clientExists = this.isUsingTs() ? await import_fs_extra2.default.pathExists(this.generatedClientTSFilePath) : await import_fs_extra2.default.pathExists(this.generatedClientJSFilePath);
293
+ const clientExists = this.isUsingTs() ? await import_fs_extra.default.pathExists(this.generatedClientTSFilePath) : await import_fs_extra.default.pathExists(this.generatedClientJSFilePath);
770
294
  if (!clientExists) {
771
295
  const file = "export default ()=>({})\nexport const client = ()=>({})";
772
296
  if (this.isUsingTs()) {
773
- await import_fs_extra2.default.outputFile(this.generatedClientTSFilePath, file);
297
+ await import_fs_extra.default.outputFile(this.generatedClientTSFilePath, file);
774
298
  } else {
775
- await import_fs_extra2.default.outputFile(this.generatedClientJSFilePath, file);
299
+ await import_fs_extra.default.outputFile(this.generatedClientJSFilePath, file);
776
300
  }
777
301
  }
778
302
  const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
@@ -797,7 +321,7 @@ var ConfigManager = class {
797
321
  this.config.localContentPath || ""
798
322
  );
799
323
  if (this.config.localContentPath) {
800
- const localContentPathExists = await import_fs_extra2.default.pathExists(fullLocalContentPath);
324
+ const localContentPathExists = await import_fs_extra.default.pathExists(fullLocalContentPath);
801
325
  if (localContentPathExists) {
802
326
  logger.info(`Using separate content repo at ${fullLocalContentPath}`);
803
327
  this.contentRootPath = fullLocalContentPath;
@@ -823,13 +347,13 @@ var ConfigManager = class {
823
347
  }
824
348
  async getTinaFolderPath(rootPath) {
825
349
  const tinaFolderPath = import_path.default.join(rootPath, TINA_FOLDER);
826
- const tinaFolderExists = await import_fs_extra2.default.pathExists(tinaFolderPath);
350
+ const tinaFolderExists = await import_fs_extra.default.pathExists(tinaFolderPath);
827
351
  if (tinaFolderExists) {
828
352
  this.isUsingLegacyFolder = false;
829
353
  return tinaFolderPath;
830
354
  }
831
355
  const legacyFolderPath = import_path.default.join(rootPath, LEGACY_TINA_FOLDER);
832
- const legacyFolderExists = await import_fs_extra2.default.pathExists(legacyFolderPath);
356
+ const legacyFolderExists = await import_fs_extra.default.pathExists(legacyFolderPath);
833
357
  if (legacyFolderExists) {
834
358
  this.isUsingLegacyFolder = true;
835
359
  return legacyFolderPath;
@@ -848,7 +372,7 @@ var ConfigManager = class {
848
372
  patch: version2[2] || "x"
849
373
  };
850
374
  }
851
- const generatedSchema = import_fs_extra2.default.readJSONSync(this.generatedSchemaJSONPath);
375
+ const generatedSchema = import_fs_extra.default.readJSONSync(this.generatedSchemaJSONPath);
852
376
  if (!generatedSchema || !(typeof (generatedSchema == null ? void 0 : generatedSchema.version) !== "undefined")) {
853
377
  throw new Error(
854
378
  `Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
@@ -883,6 +407,9 @@ var ConfigManager = class {
883
407
  }
884
408
  throw `No path provided to print`;
885
409
  }
410
+ /**
411
+ * Given a filepath without an extension, find the first match (eg. tsx, ts, jsx, js)
412
+ */
886
413
  async getPathWithExtension(filepath) {
887
414
  const extensions = ["tsx", "ts", "jsx", "js"];
888
415
  let result;
@@ -892,7 +419,7 @@ var ConfigManager = class {
892
419
  return;
893
420
  }
894
421
  const filepathWithExtension = `${filepath}.${ext}`;
895
- const exists = import_fs_extra2.default.existsSync(filepathWithExtension);
422
+ const exists = import_fs_extra.default.existsSync(filepathWithExtension);
896
423
  if (exists) {
897
424
  result = filepathWithExtension;
898
425
  }
@@ -911,11 +438,10 @@ var ConfigManager = class {
911
438
  loader: loaders
912
439
  });
913
440
  const result = require(outfile);
914
- import_fs_extra2.default.removeSync(outfile);
441
+ import_fs_extra.default.removeSync(outfile);
915
442
  return result.default;
916
443
  }
917
444
  async loadConfigFile(generatedFolderPath, configFilePath) {
918
- var _a;
919
445
  const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
920
446
  const preBuildConfigPath = import_path.default.join(
921
447
  this.generatedFolderPath,
@@ -924,9 +450,7 @@ var ConfigManager = class {
924
450
  const outfile = import_path.default.join(tmpdir, "config.build.jsx");
925
451
  const outfile2 = import_path.default.join(tmpdir, "config.build.js");
926
452
  const tempTSConfigFile = import_path.default.join(tmpdir, "tsconfig.json");
927
- const viteConfig = await loadViteConfig(this.rootPath);
928
- console.log("latest");
929
- import_fs_extra2.default.outputFileSync(tempTSConfigFile, "{}");
453
+ import_fs_extra.default.outputFileSync(tempTSConfigFile, "{}");
930
454
  const result2 = await esbuild.build({
931
455
  entryPoints: [configFilePath],
932
456
  bundle: true,
@@ -954,12 +478,12 @@ var ConfigManager = class {
954
478
  logLevel: "silent",
955
479
  platform: "node",
956
480
  outfile,
957
- loader: loaders,
958
- alias: (_a = viteConfig.config.resolve) == null ? void 0 : _a.alias
481
+ loader: loaders
959
482
  });
960
483
  await esbuild.build({
961
484
  entryPoints: [outfile],
962
485
  bundle: true,
486
+ // Suppress warning about comparison with -0 from client module
963
487
  logLevel: "silent",
964
488
  platform: "node",
965
489
  outfile: outfile2,
@@ -973,8 +497,8 @@ var ConfigManager = class {
973
497
  console.error(e);
974
498
  throw e;
975
499
  }
976
- import_fs_extra2.default.removeSync(outfile);
977
- import_fs_extra2.default.removeSync(outfile2);
500
+ import_fs_extra.default.removeSync(outfile);
501
+ import_fs_extra.default.removeSync(outfile2);
978
502
  return {
979
503
  config: result.default,
980
504
  prebuildPath: preBuildConfigPath,
@@ -1059,58 +583,527 @@ var devHTML = (port) => `<!DOCTYPE html>
1059
583
  <title>TinaCMS</title>
1060
584
  </head>
1061
585
 
1062
- <!-- if development -->
1063
- <script type="module">
1064
- import RefreshRuntime from 'http://localhost:${port}/@react-refresh'
1065
- RefreshRuntime.injectIntoGlobalHook(window)
1066
- window.$RefreshReg$ = () => {}
1067
- window.$RefreshSig$ = () => (type) => type
1068
- window.__vite_plugin_react_preamble_installed__ = true
1069
- <\/script>
1070
- <script type="module" src="http://localhost:${port}/@vite/client"><\/script>
1071
- <script>
1072
- function handleLoadError() {
1073
- // Assets have failed to load
1074
- document.getElementById('root').innerHTML = '${errorHTML}';
586
+ <!-- if development -->
587
+ <script type="module">
588
+ import RefreshRuntime from 'http://localhost:${port}/@react-refresh'
589
+ RefreshRuntime.injectIntoGlobalHook(window)
590
+ window.$RefreshReg$ = () => {}
591
+ window.$RefreshSig$ = () => (type) => type
592
+ window.__vite_plugin_react_preamble_installed__ = true
593
+ </script>
594
+ <script type="module" src="http://localhost:${port}/@vite/client"></script>
595
+ <script>
596
+ function handleLoadError() {
597
+ // Assets have failed to load
598
+ document.getElementById('root').innerHTML = '${errorHTML}';
599
+ }
600
+ </script>
601
+ <script
602
+ type="module"
603
+ src="http://localhost:${port}/src/main.tsx"
604
+ onerror="handleLoadError()"
605
+ ></script>
606
+ <body class="tina-tailwind">
607
+ <div id="root"></div>
608
+ </body>
609
+ </html>`;
610
+
611
+ // src/utils/theme.ts
612
+ var import_chalk3 = __toESM(require("chalk"));
613
+ var successText = import_chalk3.default.bold.green;
614
+ var focusText = import_chalk3.default.bold;
615
+ var dangerText = import_chalk3.default.bold.red;
616
+ var neutralText = import_chalk3.default.bold.cyan;
617
+ var linkText = import_chalk3.default.bold.cyan;
618
+ var labelText = import_chalk3.default.bold;
619
+ var cmdText = import_chalk3.default.inverse;
620
+ var indentedCmd = (str) => {
621
+ return ` \u2503 ` + str;
622
+ };
623
+ var indentText = (str) => {
624
+ return String(str).split("\n").map((line) => ` ${line}`).join("\n");
625
+ };
626
+ var logText = import_chalk3.default.italic.gray;
627
+ var warnText = import_chalk3.default.yellowBright.bgBlack;
628
+ var titleText = import_chalk3.default.bgHex("d2f1f8").hex("ec4816");
629
+ var CONFIRMATION_TEXT = import_chalk3.default.dim("enter to confirm");
630
+
631
+ // src/next/commands/dev-command/server/index.ts
632
+ var import_vite3 = require("vite");
633
+
634
+ // src/next/vite/index.ts
635
+ var import_node_path2 = __toESM(require("path"));
636
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
637
+ var import_fs_extra2 = __toESM(require("fs-extra"));
638
+ var import_normalize_path2 = __toESM(require("normalize-path"));
639
+ var import_vite = require("vite");
640
+
641
+ // src/next/vite/tailwind.ts
642
+ var import_node_path = __toESM(require("path"));
643
+ var import_aspect_ratio = __toESM(require("@tailwindcss/aspect-ratio"));
644
+ var import_container_queries = __toESM(require("@tailwindcss/container-queries"));
645
+ var import_typography = __toESM(require("@tailwindcss/typography"));
646
+ var import_tailwindcss = __toESM(require("tailwindcss"));
647
+ var import_defaultTheme = __toESM(require("tailwindcss/defaultTheme.js"));
648
+ var tinaTailwind = (spaPath, prebuildFilePath) => {
649
+ return {
650
+ name: "vite-plugin-tina",
651
+ // @ts-ignore
652
+ config: (viteConfig) => {
653
+ const plugins = [];
654
+ const content = [
655
+ import_node_path.default.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
656
+ prebuildFilePath,
657
+ require.resolve("tinacms")
658
+ ];
659
+ const tw = (0, import_tailwindcss.default)({
660
+ theme: {
661
+ columns: {
662
+ auto: "auto",
663
+ 1: "1",
664
+ 2: "2",
665
+ 3: "3",
666
+ 4: "4",
667
+ 5: "5",
668
+ 6: "6",
669
+ 7: "7",
670
+ 8: "8",
671
+ 9: "9",
672
+ 10: "10",
673
+ 11: "11",
674
+ 12: "12",
675
+ "3xs": "256px",
676
+ "2xs": "288px",
677
+ xs: "320px",
678
+ sm: "384px",
679
+ md: "448px",
680
+ lg: "512px",
681
+ xl: "576px",
682
+ "2xl": "672px",
683
+ "3xl": "768px",
684
+ "4xl": "896px",
685
+ "5xl": "1024px",
686
+ "6xl": "1152px",
687
+ "7xl": "1280px"
688
+ },
689
+ spacing: {
690
+ px: "1px",
691
+ 0: "0px",
692
+ 0.5: "2px",
693
+ 1: "4px",
694
+ 1.5: "6px",
695
+ 2: "8px",
696
+ 2.5: "10px",
697
+ 3: "12px",
698
+ 3.5: "14px",
699
+ 4: "16px",
700
+ 5: "20px",
701
+ 6: "24px",
702
+ 7: "28px",
703
+ 8: "32px",
704
+ 9: "36px",
705
+ 10: "40px",
706
+ 11: "44px",
707
+ 12: "48px",
708
+ 14: "56px",
709
+ 16: "64px",
710
+ 18: "72px",
711
+ 20: "80px",
712
+ 24: "96px",
713
+ 28: "114px",
714
+ 32: "128px",
715
+ 36: "144px",
716
+ 40: "160px",
717
+ 44: "176px",
718
+ 48: "192px",
719
+ 52: "208px",
720
+ 56: "224px",
721
+ 60: "240px",
722
+ 64: "256px",
723
+ 72: "288px",
724
+ 80: "320px",
725
+ 96: "384px"
726
+ },
727
+ borderRadius: {
728
+ none: "0px",
729
+ sm: "2px",
730
+ DEFAULT: "4px",
731
+ md: "6px",
732
+ lg: "8px",
733
+ xl: "12px",
734
+ "2xl": "16px",
735
+ "3xl": "24px",
736
+ full: "9999px"
737
+ },
738
+ borderWidth: {
739
+ DEFAULT: "1px",
740
+ 0: "0",
741
+ 2: "2px",
742
+ 3: "3px",
743
+ 4: "4px",
744
+ 6: "6px",
745
+ 8: "8px"
746
+ },
747
+ fontSize: {
748
+ xs: ["13px", { lineHeight: "1.33" }],
749
+ sm: ["14px", { lineHeight: "1.43" }],
750
+ base: ["16px", { lineHeight: "1.5" }],
751
+ md: ["16px", { lineHeight: "1.5" }],
752
+ lg: ["18px", { lineHeight: "1.55" }],
753
+ xl: ["20px", { lineHeight: "1.4" }],
754
+ "2xl": ["24px", { lineHeight: "1.33" }],
755
+ "3xl": ["30px", { lineHeight: "1.2" }],
756
+ "4xl": ["36px", { lineHeight: "1.1" }],
757
+ "5xl": ["48px", { lineHeight: "1" }],
758
+ "6xl": ["60px", { lineHeight: "1" }],
759
+ "7xl": ["72px", { lineHeight: "1" }],
760
+ "8xl": ["96px", { lineHeight: "1" }],
761
+ "9xl": ["128px", { lineHeight: "1" }]
762
+ },
763
+ opacity: {
764
+ 0: "0",
765
+ 5: ".05",
766
+ 7: ".07",
767
+ 10: ".1",
768
+ 15: ".15",
769
+ 20: ".2",
770
+ 25: ".25",
771
+ 30: ".3",
772
+ 40: ".4",
773
+ 50: ".5",
774
+ 60: ".6",
775
+ 70: ".7",
776
+ 75: ".75",
777
+ 80: ".8",
778
+ 90: ".9",
779
+ 100: "1"
780
+ },
781
+ zIndex: {
782
+ "-1": "-1",
783
+ base: "9000",
784
+ panel: "9400",
785
+ menu: "9800",
786
+ chrome: "10200",
787
+ overlay: "10600",
788
+ modal: "10800",
789
+ 0: "0",
790
+ 10: "10",
791
+ 20: "20",
792
+ 30: "30",
793
+ 40: "40",
794
+ 25: "25",
795
+ 50: "50",
796
+ 75: "75",
797
+ 100: "100",
798
+ auto: "auto"
799
+ },
800
+ extend: {
801
+ scale: {
802
+ 97: ".97",
803
+ 103: "1.03"
804
+ },
805
+ transitionDuration: {
806
+ 0: "0ms",
807
+ 2e3: "2000ms"
808
+ },
809
+ boxShadow: {
810
+ xs: "0 0 0 1px rgba(0, 0, 0, 0.05)",
811
+ outline: "0 0 0 3px rgba(66, 153, 225, 0.5)"
812
+ },
813
+ colors: {
814
+ blue: {
815
+ 50: "#DCEEFF",
816
+ 100: "#B4DBFF",
817
+ 200: "#85C5FE",
818
+ 300: "#4EABFE",
819
+ 400: "#2296fe",
820
+ 500: "#0084FF",
821
+ 600: "#0574e4",
822
+ 700: "#0D5DBD",
823
+ 800: "#144696",
824
+ 900: "#1D2C6C",
825
+ 1e3: "#241748"
826
+ },
827
+ gray: {
828
+ 50: "#F6F6F9",
829
+ 100: "#EDECF3",
830
+ 150: "#E6E3EF",
831
+ 200: "#E1DDEC",
832
+ 250: "#C9C5D5",
833
+ 300: "#b2adbe",
834
+ 400: "#918c9e",
835
+ 500: "#716c7f",
836
+ 600: "#565165",
837
+ 700: "#433e52",
838
+ 800: "#363145",
839
+ 900: "#252336",
840
+ 1e3: "#1c1b2e"
841
+ },
842
+ orange: {
843
+ 400: "#EB6337",
844
+ 500: "#EC4815",
845
+ 600: "#DC4419"
846
+ },
847
+ background: "#FFFFFF",
848
+ foreground: "#0A0A0A",
849
+ muted: "#F5F5F5",
850
+ "muted-foreground": "#737373",
851
+ popover: "#FFFFFF",
852
+ "popover-foreground": "#0A0A0A",
853
+ card: "#FFFFFF",
854
+ "card-foreground": "#0A0A0A",
855
+ border: "#E5E5E5",
856
+ input: "#E5E5E5",
857
+ primary: "#171717",
858
+ "primary-foreground": "#FAFAFA",
859
+ secondary: "#F5F5F5",
860
+ "secondary-foreground": "#171717",
861
+ accent: "#F5F5F5",
862
+ "accent-foreground": "#171717",
863
+ destructive: "#FF3B3B",
864
+ "destructive-foreground": "#FAFAFA",
865
+ ring: "#0A0A0A"
866
+ },
867
+ fontFamily: {
868
+ sans: ["Inter", ...import_defaultTheme.default.fontFamily.sans]
869
+ },
870
+ lineHeight: {
871
+ 3: "12px",
872
+ 4: "16px",
873
+ 5: "20px",
874
+ 6: "24px",
875
+ 7: "28px",
876
+ 8: "32px",
877
+ 9: "36px",
878
+ 10: "40px"
879
+ },
880
+ maxWidth: {
881
+ form: "900px"
882
+ },
883
+ screens: {
884
+ xs: "320px",
885
+ sm: "560px",
886
+ md: "720px",
887
+ lg: "1030px"
888
+ }
889
+ }
890
+ },
891
+ content,
892
+ plugins: [
893
+ (0, import_typography.default)({ className: "tina-prose" }),
894
+ import_aspect_ratio.default,
895
+ import_container_queries.default
896
+ ]
897
+ });
898
+ plugins.push(tw);
899
+ return {
900
+ css: {
901
+ postcss: {
902
+ plugins
903
+ }
904
+ }
905
+ };
906
+ }
907
+ };
908
+ };
909
+
910
+ // src/next/vite/index.ts
911
+ async function listFilesRecursively({
912
+ directoryPath,
913
+ config: config2,
914
+ roothPath
915
+ }) {
916
+ const fullDirectoryPath = import_node_path2.default.join(
917
+ roothPath,
918
+ config2.publicFolder,
919
+ directoryPath
920
+ );
921
+ const exists = await import_fs_extra2.default.pathExists(fullDirectoryPath);
922
+ if (!exists) {
923
+ return { "0": [] };
1075
924
  }
1076
- <\/script>
1077
- <script
1078
- type="module"
1079
- src="http://localhost:${port}/src/main.tsx"
1080
- onerror="handleLoadError()"
1081
- ><\/script>
1082
- <body class="tina-tailwind">
1083
- <div id="root"></div>
1084
- </body>
1085
- </html>`;
1086
-
1087
- // src/utils/theme.ts
1088
- var import_chalk3 = __toESM(require("chalk"));
1089
- var successText = import_chalk3.default.bold.green;
1090
- var focusText = import_chalk3.default.bold;
1091
- var dangerText = import_chalk3.default.bold.red;
1092
- var neutralText = import_chalk3.default.bold.cyan;
1093
- var linkText = import_chalk3.default.bold.cyan;
1094
- var labelText = import_chalk3.default.bold;
1095
- var cmdText = import_chalk3.default.inverse;
1096
- var indentedCmd = (str) => {
1097
- return ` \u2503 ` + str;
1098
- };
1099
- var indentText = (str) => {
1100
- return String(str).split("\n").map((line) => ` ${line}`).join("\n");
925
+ const items = await import_fs_extra2.default.readdir(fullDirectoryPath);
926
+ const staticMediaItems = [];
927
+ for (const item of items) {
928
+ const itemPath = import_node_path2.default.join(fullDirectoryPath, item);
929
+ const stats = await import_fs_extra2.default.promises.lstat(itemPath);
930
+ const staticMediaItem = {
931
+ id: item,
932
+ filename: item,
933
+ type: stats.isDirectory() ? "dir" : "file",
934
+ directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
935
+ src: `/${import_node_path2.default.join(directoryPath, item)}`,
936
+ thumbnails: {
937
+ "75x75": `/${import_node_path2.default.join(directoryPath, item)}`,
938
+ "400x400": `/${import_node_path2.default.join(directoryPath, item)}`,
939
+ "1000x1000": `/${import_node_path2.default.join(directoryPath, item)}`
940
+ }
941
+ };
942
+ if (stats.isDirectory()) {
943
+ staticMediaItem.children = await listFilesRecursively({
944
+ directoryPath: import_node_path2.default.join(directoryPath, item),
945
+ config: config2,
946
+ roothPath
947
+ });
948
+ }
949
+ staticMediaItems.push(staticMediaItem);
950
+ }
951
+ function chunkArrayIntoObject(array, chunkSize) {
952
+ const result = {};
953
+ for (let i = 0; i < array.length; i += chunkSize) {
954
+ const chunkKey = `${i / chunkSize * 20}`;
955
+ result[chunkKey] = array.slice(i, i + chunkSize);
956
+ }
957
+ return result;
958
+ }
959
+ return chunkArrayIntoObject(staticMediaItems, 20);
960
+ }
961
+ var createConfig = async ({
962
+ configManager,
963
+ apiURL,
964
+ plugins = [],
965
+ noWatch,
966
+ rollupOptions
967
+ }) => {
968
+ var _a, _b, _c, _d, _e, _f, _g, _h;
969
+ const publicEnv = {};
970
+ Object.keys(process.env).forEach((key) => {
971
+ if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
972
+ try {
973
+ if (typeof process.env[key] === "string") {
974
+ publicEnv[key] = process.env[key];
975
+ } else {
976
+ publicEnv[key] = JSON.stringify(process.env[key]);
977
+ }
978
+ } catch (error) {
979
+ console.warn(
980
+ `Could not stringify public env process.env.${key} env variable`
981
+ );
982
+ console.warn(error);
983
+ }
984
+ }
985
+ });
986
+ const staticMediaPath = import_node_path2.default.join(
987
+ configManager.generatedFolderPath,
988
+ "static-media.json"
989
+ );
990
+ if ((_b = (_a = configManager.config.media) == null ? void 0 : _a.tina) == null ? void 0 : _b.static) {
991
+ const staticMedia = await listFilesRecursively({
992
+ directoryPath: ((_c = configManager.config.media.tina) == null ? void 0 : _c.mediaRoot) || "",
993
+ config: configManager.config.media.tina,
994
+ roothPath: configManager.rootPath
995
+ });
996
+ await import_fs_extra2.default.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
997
+ } else {
998
+ await import_fs_extra2.default.outputFile(staticMediaPath, `[]`);
999
+ }
1000
+ const alias = {
1001
+ TINA_IMPORT: configManager.prebuildFilePath,
1002
+ SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
1003
+ STATIC_MEDIA_IMPORT: staticMediaPath,
1004
+ crypto: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
1005
+ fs: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
1006
+ os: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
1007
+ path: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts")
1008
+ };
1009
+ if (configManager.shouldSkipSDK()) {
1010
+ alias["CLIENT_IMPORT"] = import_node_path2.default.join(
1011
+ configManager.spaRootPath,
1012
+ "src",
1013
+ "dummy-client.ts"
1014
+ );
1015
+ } else {
1016
+ alias["CLIENT_IMPORT"] = configManager.isUsingTs() ? configManager.generatedTypesTSFilePath : configManager.generatedTypesJSFilePath;
1017
+ }
1018
+ let basePath;
1019
+ if (configManager.config.build.basePath) {
1020
+ basePath = configManager.config.build.basePath;
1021
+ }
1022
+ const fullVersion = configManager.getTinaGraphQLVersion();
1023
+ const version2 = `${fullVersion.major}.${fullVersion.minor}`;
1024
+ const config2 = {
1025
+ root: configManager.spaRootPath,
1026
+ base: `/${basePath ? `${(0, import_normalize_path2.default)(basePath)}/` : ""}${(0, import_normalize_path2.default)(
1027
+ configManager.config.build.outputFolder
1028
+ )}/`,
1029
+ appType: "spa",
1030
+ resolve: {
1031
+ alias,
1032
+ dedupe: ["graphql", "tinacms", "react", "react-dom", "react-router-dom"]
1033
+ },
1034
+ define: {
1035
+ /**
1036
+ * Since we prebuild the config.ts, it's possible for modules to be loaded which make
1037
+ * use of `process`. The main scenario where this is an issue is when co-locating schema
1038
+ * definitions with source files, and specifically source files which impor from NextJS.
1039
+ *
1040
+ * Some examples of what NextJS uses for `process.env` are:
1041
+ * - `process.env.__NEXT_TRAILING_SLASH`
1042
+ * - `process.env.__NEXT_CROSS_ORIGIN`
1043
+ * - `process.env.__NEXT_I18N_SUPPORT`
1044
+ *
1045
+ * Also, interestingly some of the advice for handling this doesn't work, references to replacing
1046
+ * `process.env` with `{}` are problematic, because browsers don't understand the `{}.` syntax,
1047
+ * but node does. This was a surprise, but using `new Object()` seems to do the trick.
1048
+ */
1049
+ "process.env": `new Object(${JSON.stringify(publicEnv)})`,
1050
+ // Used by picomatch https://github.com/micromatch/picomatch/blob/master/lib/utils.js#L4
1051
+ "process.platform": `"${process.platform}"`,
1052
+ __API_URL__: `"${apiURL}"`,
1053
+ __BASE_PATH__: `"${((_e = (_d = configManager.config) == null ? void 0 : _d.build) == null ? void 0 : _e.basePath) || ""}"`,
1054
+ __TINA_GRAPHQL_VERSION__: version2
1055
+ },
1056
+ logLevel: "error",
1057
+ // Vite import warnings are noisy
1058
+ optimizeDeps: {
1059
+ force: true,
1060
+ // Not 100% sure why this isn't being picked up automatically, this works from within the monorepo
1061
+ // but breaks externally
1062
+ include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
1063
+ },
1064
+ server: {
1065
+ host: (_h = (_g = (_f = configManager.config) == null ? void 0 : _f.build) == null ? void 0 : _g.host) != null ? _h : false,
1066
+ watch: noWatch ? {
1067
+ ignored: ["**/*"]
1068
+ } : {
1069
+ // Ignore everything except for the alias fields we specified above
1070
+ ignored: [
1071
+ `${configManager.tinaFolderPath}/**/!(config.prebuild.jsx|_graphql.json)`
1072
+ ]
1073
+ },
1074
+ fs: {
1075
+ strict: false
1076
+ }
1077
+ },
1078
+ build: {
1079
+ sourcemap: false,
1080
+ outDir: configManager.outputFolderPath,
1081
+ emptyOutDir: true,
1082
+ rollupOptions
1083
+ },
1084
+ plugins: [
1085
+ /**
1086
+ * `splitVendorChunkPlugin` is needed because `tinacms` is quite large,
1087
+ * Vite's chunking strategy chokes on memory issues for smaller machines (ie. on CI).
1088
+ */
1089
+ (0, import_plugin_react.default)({
1090
+ babel: {
1091
+ // Supresses the warning [NOTE] babel The code generator has deoptimised the styling of
1092
+ compact: true
1093
+ }
1094
+ }),
1095
+ (0, import_vite.splitVendorChunkPlugin)(),
1096
+ tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
1097
+ ...plugins
1098
+ ]
1099
+ };
1100
+ return config2;
1101
1101
  };
1102
- var logText = import_chalk3.default.italic.gray;
1103
- var warnText = import_chalk3.default.yellowBright.bgBlack;
1104
- var titleText = import_chalk3.default.bgHex("d2f1f8").hex("ec4816");
1105
- var CONFIRMATION_TEXT = import_chalk3.default.dim("enter to confirm");
1106
-
1107
- // src/next/commands/dev-command/server/index.ts
1108
- var import_vite4 = require("vite");
1109
1102
 
1110
1103
  // src/next/vite/plugins.ts
1111
1104
  var import_pluginutils = require("@rollup/pluginutils");
1112
1105
  var import_fs = __toESM(require("fs"));
1113
- var import_vite3 = require("vite");
1106
+ var import_vite2 = require("vite");
1114
1107
  var import_esbuild = require("esbuild");
1115
1108
  var import_path3 = __toESM(require("path"));
1116
1109
  var import_body_parser = __toESM(require("body-parser"));
@@ -1172,8 +1165,7 @@ var createMediaRouter = (config2) => {
1172
1165
  };
1173
1166
  var parseMediaFolder = (str) => {
1174
1167
  let returnString = str;
1175
- if (returnString.startsWith("/"))
1176
- returnString = returnString.substr(1);
1168
+ if (returnString.startsWith("/")) returnString = returnString.substr(1);
1177
1169
  if (returnString.endsWith("/"))
1178
1170
  returnString = returnString.substr(0, returnString.length - 1);
1179
1171
  return returnString;
@@ -1338,7 +1330,8 @@ var devServerEndPointsPlugin = ({
1338
1330
  configManager,
1339
1331
  apiURL,
1340
1332
  database,
1341
- searchIndex
1333
+ searchIndex,
1334
+ databaseLock
1342
1335
  }) => {
1343
1336
  const plug = {
1344
1337
  name: "graphql-endpoints",
@@ -1382,14 +1375,17 @@ var devServerEndPointsPlugin = ({
1382
1375
  }
1383
1376
  if (req.url === "/graphql") {
1384
1377
  const { query, variables } = req.body;
1385
- const result = await (0, import_graphql.resolve)({
1386
- config: {
1387
- useRelativeMedia: true
1388
- },
1389
- database,
1390
- query,
1391
- variables,
1392
- verbose: false
1378
+ let result;
1379
+ await databaseLock(async () => {
1380
+ result = await (0, import_graphql.resolve)({
1381
+ config: {
1382
+ useRelativeMedia: true
1383
+ },
1384
+ database,
1385
+ query,
1386
+ variables,
1387
+ verbose: false
1388
+ });
1393
1389
  });
1394
1390
  res.end(JSON.stringify(result));
1395
1391
  return;
@@ -1433,13 +1429,14 @@ function viteTransformExtension({
1433
1429
  previousExport: exportAsDefault ? null : code
1434
1430
  }
1435
1431
  });
1436
- const res = await (0, import_vite3.transformWithEsbuild)(componentCode, id, {
1432
+ const res = await (0, import_vite2.transformWithEsbuild)(componentCode, id, {
1437
1433
  loader: "jsx",
1438
1434
  ...esbuildOptions
1439
1435
  });
1440
1436
  return {
1441
1437
  code: res.code,
1442
1438
  map: null
1439
+ // TODO:
1443
1440
  };
1444
1441
  }
1445
1442
  }
@@ -1447,19 +1444,33 @@ function viteTransformExtension({
1447
1444
  }
1448
1445
 
1449
1446
  // src/next/commands/dev-command/server/index.ts
1450
- var createDevServer = async (configManager, database, searchIndex, apiURL, noWatch) => {
1447
+ var createDevServer = async (configManager, database, searchIndex, apiURL, noWatch, databaseLock) => {
1451
1448
  const plugins = [
1452
1449
  transformTsxPlugin({ configManager }),
1453
- devServerEndPointsPlugin({ apiURL, configManager, database, searchIndex }),
1450
+ devServerEndPointsPlugin({
1451
+ apiURL,
1452
+ configManager,
1453
+ database,
1454
+ searchIndex,
1455
+ databaseLock
1456
+ }),
1454
1457
  viteTransformExtension()
1455
1458
  ];
1456
- return (0, import_vite4.createServer)(
1459
+ return (0, import_vite3.createServer)(
1457
1460
  await createConfig({
1458
1461
  configManager,
1459
1462
  database,
1460
1463
  apiURL,
1461
1464
  plugins,
1462
1465
  noWatch,
1466
+ /**
1467
+ * Ensure Vite's import scan uses the spaMainPath as the input
1468
+ * so it properly finds everything. This is for dev only, and when
1469
+ * running the server outside of this monorepo vite fails to find
1470
+ * and optimize the imports, so you get errors about it not being
1471
+ * able to find an export from a module, and it's always a CJS
1472
+ * module that Vite would usually transform to an ES module.
1473
+ */
1463
1474
  rollupOptions: {
1464
1475
  input: configManager.spaMainPath,
1465
1476
  onwarn(warning, warn) {
@@ -1468,10 +1479,6 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
1468
1479
  }
1469
1480
  warn(warning);
1470
1481
  }
1471
- },
1472
- viteConfigEnv: {
1473
- command: "serve",
1474
- mode: "development"
1475
1482
  }
1476
1483
  })
1477
1484
  );
@@ -1589,6 +1596,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
1589
1596
  node,
1590
1597
  documentVariableName,
1591
1598
  operationType,
1599
+ // This is the only line that is different
1592
1600
  operationResultType: `{data: ${operationResultType}, errors?: { message: string, locations: { line: number, column: number }[], path: string[] }[], variables: ${operationVariablesTypes}, query: string}`,
1593
1601
  operationVariablesTypes
1594
1602
  });
@@ -1637,6 +1645,8 @@ var plugin = (schema, documents, config2) => {
1637
1645
  const visitor = new GenericSdkVisitor(schema, allFragments, config2);
1638
1646
  const visitorResult = (0, import_graphql3.visit)(allAst, { leave: visitor });
1639
1647
  return {
1648
+ // We will take care of imports
1649
+ // prepend: visitor.getImports(),
1640
1650
  content: [
1641
1651
  visitor.fragments,
1642
1652
  ...visitorResult.definitions.filter((t) => typeof t === "string"),
@@ -1652,6 +1662,7 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
1652
1662
  docs = await loadGraphQLDocuments(queryPathGlob);
1653
1663
  fragDocs = await loadGraphQLDocuments(fragDocPath);
1654
1664
  const res = await (0, import_core.codegen)({
1665
+ // Filename is not used. This is because the typescript plugin returns a string instead of writing to a file.
1655
1666
  filename: process.cwd(),
1656
1667
  schema: (0, import_graphql5.parse)((0, import_graphql5.printSchema)(schema)),
1657
1668
  documents: [...docs, ...fragDocs],
@@ -1686,9 +1697,12 @@ var loadGraphQLDocuments = async (globPath) => {
1686
1697
  loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
1687
1698
  });
1688
1699
  } catch (e) {
1689
- if ((e.message || "").includes(
1690
- "Unable to find any GraphQL type definitions for the following pointers:"
1691
- )) {
1700
+ if (
1701
+ // https://www.graphql-tools.com/docs/documents-loading#no-files-found
1702
+ (e.message || "").includes(
1703
+ "Unable to find any GraphQL type definitions for the following pointers:"
1704
+ )
1705
+ ) {
1692
1706
  } else {
1693
1707
  throw e;
1694
1708
  }
@@ -1850,12 +1864,9 @@ var Codegen = class {
1850
1864
  const baseUrl = ((_d = this.configManager.config.tinaioConfig) == null ? void 0 : _d.contentApiUrlOverride) || `https://${TINA_HOST}`;
1851
1865
  if ((!branch || !clientId || !token) && !this.port && !this.configManager.config.contentApiUrlOverride) {
1852
1866
  const missing = [];
1853
- if (!branch)
1854
- missing.push("branch");
1855
- if (!clientId)
1856
- missing.push("clientId");
1857
- if (!token)
1858
- missing.push("token");
1867
+ if (!branch) missing.push("branch");
1868
+ if (!clientId) missing.push("clientId");
1869
+ if (!token) missing.push("token");
1859
1870
  throw new Error(
1860
1871
  `Client not configured properly. Missing ${missing.join(
1861
1872
  ", "
@@ -2009,7 +2020,11 @@ schema {
2009
2020
  }
2010
2021
  };
2011
2022
  var maybeWarnFragmentSize = async (filepath) => {
2012
- if ((await import_fs_extra4.default.stat(filepath)).size > 100 * 1024) {
2023
+ if (
2024
+ // is the file bigger than 100kb?
2025
+ (await import_fs_extra4.default.stat(filepath)).size > // convert to 100 kb to bytes
2026
+ 100 * 1024
2027
+ ) {
2013
2028
  console.warn(
2014
2029
  "Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below."
2015
2030
  );
@@ -2037,6 +2052,7 @@ var import_many_level = require("many-level");
2037
2052
  var import_memory_level = require("memory-level");
2038
2053
  var createDBServer = (port) => {
2039
2054
  const levelHost = new import_many_level.ManyLevelHost(
2055
+ // @ts-ignore
2040
2056
  new import_memory_level.MemoryLevel({
2041
2057
  valueEncoding: "json"
2042
2058
  })
@@ -2187,7 +2203,9 @@ var BaseCommand = class extends import_clipanion.Command {
2187
2203
  let subProc;
2188
2204
  if (this.subCommand) {
2189
2205
  subProc = await startSubprocess2({ command: this.subCommand });
2190
- logger.info(`Starting subprocess: ${import_chalk4.default.cyan(this.subCommand)}`);
2206
+ logger.info(
2207
+ `Running web application with command: ${import_chalk4.default.cyan(this.subCommand)}`
2208
+ );
2191
2209
  }
2192
2210
  function exitHandler(options, exitCode) {
2193
2211
  if (subProc) {
@@ -2311,6 +2329,7 @@ var import_search = require("@tinacms/search");
2311
2329
  var DevCommand = class extends BaseCommand {
2312
2330
  constructor() {
2313
2331
  super(...arguments);
2332
+ // NOTE: camelCase commands for string options don't work if there's an `=` used https://github.com/arcanis/clipanion/issues/141
2314
2333
  this.watchFolders = import_clipanion2.Option.String("-w,--watchFolders", {
2315
2334
  description: "DEPRECATED - a list of folders (relative to where this is being run) that the cli will watch for changes"
2316
2335
  });
@@ -2320,6 +2339,7 @@ var DevCommand = class extends BaseCommand {
2320
2339
  this.outputSearchIndexPath = import_clipanion2.Option.String("--outputSearchIndexPath", {
2321
2340
  description: "Path to write the search index to"
2322
2341
  });
2342
+ this.indexingLock = new import_async_lock.default();
2323
2343
  }
2324
2344
  async catch(error) {
2325
2345
  logger.error("Error occured during tinacms dev");
@@ -2340,10 +2360,13 @@ var DevCommand = class extends BaseCommand {
2340
2360
  rootPath: this.rootPath,
2341
2361
  legacyNoSDK: this.noSDK
2342
2362
  });
2343
- logger.info("Starting Tina Dev Server");
2363
+ logger.info("\u{1F999} TinaCMS Dev Server is initializing...");
2344
2364
  this.logDeprecationWarnings();
2345
2365
  createDBServer(Number(this.datalayerPort));
2346
2366
  let database = null;
2367
+ const dbLock = async (fn) => {
2368
+ return this.indexingLock.acquire("Key", fn);
2369
+ };
2347
2370
  const setup = async ({ firstTime }) => {
2348
2371
  try {
2349
2372
  await configManager.processConfig();
@@ -2394,9 +2417,6 @@ var DevCommand = class extends BaseCommand {
2394
2417
  await import_fs_extra6.default.outputFile(filePath, tinaLockContent);
2395
2418
  }
2396
2419
  }
2397
- if (!this.noWatch) {
2398
- this.watchQueries(configManager, async () => await codegen2.execute());
2399
- }
2400
2420
  await this.indexContentWithSpinner({
2401
2421
  database,
2402
2422
  graphQLSchema: graphQLSchema2,
@@ -2406,6 +2426,13 @@ var DevCommand = class extends BaseCommand {
2406
2426
  if (!firstTime) {
2407
2427
  logger.error("Re-index complete");
2408
2428
  }
2429
+ if (!this.noWatch) {
2430
+ this.watchQueries(
2431
+ configManager,
2432
+ dbLock,
2433
+ async () => await codegen2.execute()
2434
+ );
2435
+ }
2409
2436
  return { apiURL: apiURL2, database, graphQLSchema: graphQLSchema2, tinaSchema: tinaSchema2 };
2410
2437
  } catch (e) {
2411
2438
  logger.error(`
@@ -2440,14 +2467,6 @@ ${dangerText(e.message)}
2440
2467
  tokenSplitRegex: (_d = (_c = configManager.config.search) == null ? void 0 : _c.tina) == null ? void 0 : _d.tokenSplitRegex
2441
2468
  });
2442
2469
  await searchIndexClient.onStartIndexing();
2443
- const server = await createDevServer(
2444
- configManager,
2445
- database,
2446
- searchIndexClient.searchIndex,
2447
- apiURL,
2448
- this.noWatch
2449
- );
2450
- await server.listen(Number(this.port));
2451
2470
  const searchIndexer = new import_search.SearchIndexer({
2452
2471
  batchSize: ((_e = configManager.config.search) == null ? void 0 : _e.indexBatchSize) || 100,
2453
2472
  bridge: new import_graphql10.FilesystemBridge(
@@ -2473,12 +2492,26 @@ ${dangerText(e.message)}
2473
2492
  this.watchContentFiles(
2474
2493
  configManager,
2475
2494
  database,
2495
+ dbLock,
2476
2496
  configManager.config.search && searchIndexer
2477
2497
  );
2498
+ }
2499
+ const server = await createDevServer(
2500
+ configManager,
2501
+ database,
2502
+ searchIndexClient.searchIndex,
2503
+ apiURL,
2504
+ this.noWatch,
2505
+ dbLock
2506
+ );
2507
+ await server.listen(Number(this.port));
2508
+ if (!this.noWatch) {
2478
2509
  import_chokidar.default.watch(configManager.watchList).on("change", async () => {
2479
- logger.info(`Tina config change detected, rebuilding`);
2480
- await setup({ firstTime: false });
2481
- server.ws.send({ type: "full-reload", path: "*" });
2510
+ await dbLock(async () => {
2511
+ logger.info(`Tina config change detected, rebuilding`);
2512
+ await setup({ firstTime: false });
2513
+ server.ws.send({ type: "full-reload", path: "*" });
2514
+ });
2482
2515
  });
2483
2516
  }
2484
2517
  const subItems = [];
@@ -2491,7 +2524,7 @@ ${dangerText(e.message)}
2491
2524
  const summaryItems = [
2492
2525
  {
2493
2526
  emoji: "\u{1F999}",
2494
- heading: "Tina Config",
2527
+ heading: "TinaCMS URLs",
2495
2528
  subItems: [
2496
2529
  {
2497
2530
  key: "CMS",
@@ -2526,14 +2559,28 @@ ${dangerText(e.message)}
2526
2559
  });
2527
2560
  }
2528
2561
  summary({
2529
- heading: "Tina Dev Server is running...",
2562
+ heading: "\u2705 \u{1F999} TinaCMS Dev Server is active:",
2530
2563
  items: [
2531
2564
  ...summaryItems
2565
+ // {
2566
+ // emoji: '📚',
2567
+ // heading: 'Useful links',
2568
+ // subItems: [
2569
+ // {
2570
+ // key: 'Custom queries',
2571
+ // value: 'https://tina.io/querying',
2572
+ // },
2573
+ // {
2574
+ // key: 'Visual editing',
2575
+ // value: 'https://tina.io/visual-editing',
2576
+ // },
2577
+ // ],
2578
+ // },
2532
2579
  ]
2533
2580
  });
2534
2581
  await this.startSubCommand();
2535
2582
  }
2536
- watchContentFiles(configManager, database, searchIndexer) {
2583
+ watchContentFiles(configManager, database, databaseLock, searchIndexer) {
2537
2584
  const collectionContentFiles = [];
2538
2585
  configManager.config.schema.collections.forEach((collection) => {
2539
2586
  const collectionGlob = `${import_path5.default.join(
@@ -2549,39 +2596,42 @@ ${dangerText(e.message)}
2549
2596
  if (!ready) {
2550
2597
  return;
2551
2598
  }
2552
- const pathFromRoot = configManager.printContentRelativePath(addedFile);
2553
- await database.indexContentByPaths([pathFromRoot]).catch(console.error);
2554
- if (searchIndexer) {
2555
- await searchIndexer.indexContentByPaths([pathFromRoot]).catch(console.error);
2556
- }
2599
+ await databaseLock(async () => {
2600
+ const pathFromRoot = configManager.printContentRelativePath(addedFile);
2601
+ await database.indexContentByPaths([pathFromRoot]).catch(console.error);
2602
+ if (searchIndexer) {
2603
+ await searchIndexer.indexContentByPaths([pathFromRoot]).catch(console.error);
2604
+ }
2605
+ });
2557
2606
  }).on("change", async (changedFile) => {
2558
2607
  const pathFromRoot = configManager.printContentRelativePath(changedFile);
2559
- await database.indexContentByPaths([pathFromRoot]).catch(console.error);
2560
- if (searchIndexer) {
2561
- await searchIndexer.indexContentByPaths([pathFromRoot]).catch(console.error);
2562
- }
2608
+ await databaseLock(async () => {
2609
+ await database.indexContentByPaths([pathFromRoot]).catch(console.error);
2610
+ if (searchIndexer) {
2611
+ await searchIndexer.indexContentByPaths([pathFromRoot]).catch(console.error);
2612
+ }
2613
+ });
2563
2614
  }).on("unlink", async (removedFile) => {
2564
2615
  const pathFromRoot = configManager.printContentRelativePath(removedFile);
2565
- await database.deleteContentByPaths([pathFromRoot]).catch(console.error);
2566
- if (searchIndexer) {
2567
- await searchIndexer.deleteIndexContent([pathFromRoot]).catch(console.error);
2568
- }
2616
+ await databaseLock(async () => {
2617
+ await database.deleteContentByPaths([pathFromRoot]).catch(console.error);
2618
+ if (searchIndexer) {
2619
+ await searchIndexer.deleteIndexContent([pathFromRoot]).catch(console.error);
2620
+ }
2621
+ });
2569
2622
  });
2570
2623
  }
2571
- watchQueries(configManager, callback) {
2572
- let ready = false;
2573
- import_chokidar.default.watch(configManager.userQueriesAndFragmentsGlob).on("ready", () => {
2574
- ready = true;
2575
- }).on("add", async (addedFile) => {
2576
- await callback();
2577
- }).on("change", async (changedFile) => {
2578
- await callback();
2579
- }).on("unlink", async (removedFile) => {
2580
- await callback();
2581
- });
2624
+ watchQueries(configManager, databaseLock, callback) {
2625
+ const executeCallback = async (_) => {
2626
+ await databaseLock(async () => {
2627
+ await callback();
2628
+ });
2629
+ };
2630
+ import_chokidar.default.watch(configManager.userQueriesAndFragmentsGlob).on("add", executeCallback).on("change", executeCallback).on("unlink", executeCallback);
2582
2631
  }
2583
2632
  };
2584
2633
  DevCommand.paths = [["dev"], ["server:start"]];
2634
+ // Prevent indexes and reads occurring at once
2585
2635
  DevCommand.usage = import_clipanion2.Command.Usage({
2586
2636
  category: `Commands`,
2587
2637
  description: `Builds Tina and starts the dev server`,
@@ -2600,7 +2650,7 @@ var import_path6 = __toESM(require("path"));
2600
2650
  var import_graphql11 = require("@tinacms/graphql");
2601
2651
 
2602
2652
  // src/next/commands/build-command/server.ts
2603
- var import_vite6 = require("vite");
2653
+ var import_vite5 = require("vite");
2604
2654
  var buildProductionSpa = async (configManager, database, apiURL) => {
2605
2655
  const publicEnv = {};
2606
2656
  Object.keys(process.env).forEach((key) => {
@@ -2632,13 +2682,9 @@ var buildProductionSpa = async (configManager, database, apiURL) => {
2632
2682
  }
2633
2683
  warn(warning);
2634
2684
  }
2635
- },
2636
- viteConfigEnv: {
2637
- command: "build",
2638
- mode: "production"
2639
2685
  }
2640
2686
  });
2641
- return (0, import_vite6.build)(config2);
2687
+ return (0, import_vite5.build)(config2);
2642
2688
  };
2643
2689
 
2644
2690
  // src/next/commands/build-command/index.ts
@@ -2775,6 +2821,9 @@ var BuildCommand = class extends BaseCommand {
2775
2821
  this.tinaGraphQLVersion = import_clipanion3.Option.String("--tina-graphql-version", {
2776
2822
  description: "Specify the version of @tinacms/graphql to use (defaults to latest)"
2777
2823
  });
2824
+ /**
2825
+ * This option allows the user to skip the tina cloud checks if they want to. This could be useful for mismatched GraphQL versions or if they want to build only using the local client and never connect to Tina Cloud
2826
+ */
2778
2827
  this.skipCloudChecks = import_clipanion3.Option.Boolean("--skip-cloud-checks", false, {
2779
2828
  description: "Skips checking the provided cloud config."
2780
2829
  });
@@ -2880,7 +2929,8 @@ ${dangerText(e.message)}
2880
2929
  database,
2881
2930
  null,
2882
2931
  apiURL,
2883
- true
2932
+ true,
2933
+ (lockedFn) => lockedFn()
2884
2934
  );
2885
2935
  await server.listen(Number(this.port));
2886
2936
  console.log("server listening on port", this.port);
@@ -3515,6 +3565,7 @@ var auditDocuments = async (args) => {
3515
3565
  logger.error(import_chalk5.default.red(err.message));
3516
3566
  if (err.originalError.originalError) {
3517
3567
  logger.error(
3568
+ // @ts-ignore FIXME: this doesn't seem right
3518
3569
  import_chalk5.default.red(` ${err.originalError.originalError.message}`)
3519
3570
  );
3520
3571
  }
@@ -3720,7 +3771,9 @@ var detectEnvironment = async ({
3720
3771
  const usingSrc = import_fs_extra8.default.pathExistsSync(import_path7.default.join(baseDir, "src")) && (import_fs_extra8.default.pathExistsSync(import_path7.default.join(baseDir, "src", "app")) || import_fs_extra8.default.pathExistsSync(import_path7.default.join(baseDir, "src", "pages")));
3721
3772
  const tinaFolder = import_path7.default.join(baseDir, "tina");
3722
3773
  const tinaConfigExists = Boolean(
3723
- await import_fs_extra8.default.pathExists(tinaFolder) && (await import_fs_extra8.default.readdir(tinaFolder)).find((x) => x.includes("config"))
3774
+ // Does the tina folder exist?
3775
+ await import_fs_extra8.default.pathExists(tinaFolder) && // Does the tina folder contain a config file?
3776
+ (await import_fs_extra8.default.readdir(tinaFolder)).find((x) => x.includes("config"))
3724
3777
  );
3725
3778
  const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
3726
3779
  Boolean
@@ -3955,6 +4008,7 @@ var supportedDatabaseAdapters = {
3955
4008
  {
3956
4009
  from: "mongodb",
3957
4010
  imported: [],
4011
+ // not explicitly imported
3958
4012
  packageName: "mongodb"
3959
4013
  }
3960
4014
  ]
@@ -4027,6 +4081,10 @@ var chooseDatabaseAdapter = async ({
4027
4081
  title: "MongoDB",
4028
4082
  value: "mongodb"
4029
4083
  }
4084
+ // {
4085
+ // title: "I'll create my own database adapter",
4086
+ // value: 'other',
4087
+ // },
4030
4088
  ]
4031
4089
  }
4032
4090
  ]);
@@ -4304,6 +4362,7 @@ async function configure(env, opts) {
4304
4362
  packageManager,
4305
4363
  forestryMigrate: false,
4306
4364
  isLocalEnvVarName: "TINA_PUBLIC_IS_LOCAL",
4365
+ // TODO: give this a better default
4307
4366
  typescript: false
4308
4367
  };
4309
4368
  if (config2.framework.name === "next") {
@@ -4407,15 +4466,25 @@ var import_js_yaml = __toESM(require("js-yaml"));
4407
4466
  var import_zod = __toESM(require("zod"));
4408
4467
 
4409
4468
  // src/cmds/forestry-migrate/util/errorSingleton.ts
4410
- var ErrorSingleton = class {
4469
+ var ErrorSingleton = class _ErrorSingleton {
4470
+ /**
4471
+ * The Singleton's constructor should always be private to prevent direct
4472
+ * construction calls with the `new` operator.
4473
+ */
4411
4474
  constructor() {
4412
4475
  }
4476
+ /**
4477
+ * The static method that controls the access to the singleton instance.
4478
+ *
4479
+ * This implementation let you subclass the Singleton class while keeping
4480
+ * just one instance of each subclass around.
4481
+ */
4413
4482
  static getInstance() {
4414
- if (!ErrorSingleton.instance) {
4415
- ErrorSingleton.instance = new ErrorSingleton();
4416
- ErrorSingleton.instance.collectionNameErrors = [];
4483
+ if (!_ErrorSingleton.instance) {
4484
+ _ErrorSingleton.instance = new _ErrorSingleton();
4485
+ _ErrorSingleton.instance.collectionNameErrors = [];
4417
4486
  }
4418
- return ErrorSingleton.instance;
4487
+ return _ErrorSingleton.instance;
4419
4488
  }
4420
4489
  addErrorName(error) {
4421
4490
  this.collectionNameErrors.push(error);
@@ -4458,8 +4527,7 @@ var makeFieldsWithInternalCode = ({
4458
4527
  if (hasBody) {
4459
4528
  return [bodyField, `__TINA_INTERNAL__:::...${field}():::`];
4460
4529
  } else {
4461
- if (spread)
4462
- return `__TINA_INTERNAL__:::...${field}():::`;
4530
+ if (spread) return `__TINA_INTERNAL__:::...${field}():::`;
4463
4531
  return `__TINA_INTERNAL__:::${field}():::`;
4464
4532
  }
4465
4533
  };
@@ -4543,6 +4611,7 @@ var forestryConfigSchema = import_zod.default.object({
4543
4611
  )
4544
4612
  });
4545
4613
  var forestryFieldWithoutField = import_zod.default.object({
4614
+ // TODO: maybe better type this?
4546
4615
  type: import_zod.default.union([
4547
4616
  import_zod.default.literal("text"),
4548
4617
  import_zod.default.literal("datetime"),
@@ -4566,6 +4635,7 @@ var forestryFieldWithoutField = import_zod.default.object({
4566
4635
  default: import_zod.default.any().optional(),
4567
4636
  template: import_zod.default.string().optional(),
4568
4637
  config: import_zod.default.object({
4638
+ // min and max are used for lists
4569
4639
  min: import_zod.default.number().optional().nullable(),
4570
4640
  max: import_zod.default.number().optional().nullable(),
4571
4641
  required: import_zod.default.boolean().optional().nullable(),
@@ -4579,6 +4649,7 @@ var forestryFieldWithoutField = import_zod.default.object({
4579
4649
  import_zod.default.literal("pages"),
4580
4650
  import_zod.default.literal("documents"),
4581
4651
  import_zod.default.literal("simple"),
4652
+ // TODO: I want to ignore this key if its invalid
4582
4653
  import_zod.default.string()
4583
4654
  ]).optional().nullable(),
4584
4655
  section: import_zod.default.string().optional().nullable()
@@ -4614,6 +4685,7 @@ var transformForestryFieldsToTinaFields = ({
4614
4685
  }
4615
4686
  let field;
4616
4687
  switch (forestryField2.type) {
4688
+ // Single filed types
4617
4689
  case "text":
4618
4690
  field = {
4619
4691
  type: "string",
@@ -4693,6 +4765,7 @@ var transformForestryFieldsToTinaFields = ({
4693
4765
  );
4694
4766
  }
4695
4767
  break;
4768
+ // List Types
4696
4769
  case "list":
4697
4770
  field = {
4698
4771
  type: "string",
@@ -4715,6 +4788,7 @@ var transformForestryFieldsToTinaFields = ({
4715
4788
  }
4716
4789
  };
4717
4790
  break;
4791
+ // Object (Group) types
4718
4792
  case "field_group":
4719
4793
  field = {
4720
4794
  type: "object",
@@ -4755,6 +4829,7 @@ var transformForestryFieldsToTinaFields = ({
4755
4829
  });
4756
4830
  const fieldsString = stringifyLabelWithField(template2.label);
4757
4831
  const t = {
4832
+ // @ts-ignore
4758
4833
  fields: makeFieldsWithInternalCode({
4759
4834
  hasBody: false,
4760
4835
  field: fieldsString
@@ -4792,6 +4867,7 @@ var transformForestryFieldsToTinaFields = ({
4792
4867
  spread: true
4793
4868
  });
4794
4869
  tinaFields.push(
4870
+ // @ts-ignore
4795
4871
  field2
4796
4872
  );
4797
4873
  break;
@@ -4851,6 +4927,7 @@ var parseSections = ({ val }) => {
4851
4927
 
4852
4928
  // src/cmds/forestry-migrate/index.ts
4853
4929
  var BODY_FIELD = {
4930
+ // This is the body field
4854
4931
  type: "rich-text",
4855
4932
  name: "body",
4856
4933
  label: "Body of Document",
@@ -4909,8 +4986,7 @@ var generateAllTemplates = async ({
4909
4986
  };
4910
4987
  var generateCollectionFromForestrySection = (args) => {
4911
4988
  const { section, templateMap } = args;
4912
- if (section.read_only)
4913
- return;
4989
+ if (section.read_only) return;
4914
4990
  let format3 = "md";
4915
4991
  if (section.new_doc_ext) {
4916
4992
  const ext = checkExt(section.new_doc_ext);
@@ -4977,12 +5053,14 @@ var generateCollectionFromForestrySection = (args) => {
4977
5053
  if (((forestryTemplates == null ? void 0 : forestryTemplates.length) || 0) > 1) {
4978
5054
  c = {
4979
5055
  ...baseCollection,
5056
+ // @ts-expect-error
4980
5057
  templates: forestryTemplates.map((tem) => {
4981
5058
  const currentTemplate = templateMap.get(tem);
4982
5059
  const fieldsString = stringifyLabelWithField(
4983
5060
  currentTemplate.templateObj.label
4984
5061
  );
4985
5062
  return {
5063
+ // fields: [BODY_FIELD],
4986
5064
  fields: makeFieldsWithInternalCode({
4987
5065
  hasBody,
4988
5066
  field: fieldsString,
@@ -5000,6 +5078,8 @@ var generateCollectionFromForestrySection = (args) => {
5000
5078
  const fieldsString = stringifyLabelWithField(template.templateObj.label);
5001
5079
  c = {
5002
5080
  ...baseCollection,
5081
+ // fields: [BODY_FIELD],
5082
+ // @ts-expect-error
5003
5083
  fields: makeFieldsWithInternalCode({
5004
5084
  field: fieldsString,
5005
5085
  hasBody,
@@ -5747,6 +5827,7 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
5747
5827
  ) : [];
5748
5828
  const newImports = [
5749
5829
  .../* @__PURE__ */ new Set([
5830
+ // we use Set to remove duplicates
5750
5831
  ...existingImports,
5751
5832
  ...imports
5752
5833
  ])
@@ -5901,6 +5982,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
5901
5982
  );
5902
5983
  const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
5903
5984
  const importMap = {
5985
+ // iterate over configImports and add them to the import map
5904
5986
  ...configImports.reduce((acc, { from, imported }) => {
5905
5987
  acc[from] = imported;
5906
5988
  return acc;
@@ -6075,7 +6157,13 @@ async function apply({
6075
6157
  config: config2
6076
6158
  });
6077
6159
  }
6078
- if (env.tinaConfigExists && params.isBackendInit && config2.hosting === "self-host" && (((_a = config2.authProvider) == null ? void 0 : _a.name) || "") !== "tina-cloud") {
6160
+ if (
6161
+ // if the config was just generated we do not need to update the config file because it will be generated correctly
6162
+ env.tinaConfigExists && // Are we running tinacms init backend
6163
+ params.isBackendInit && // Do the user choose the 'self-host' option
6164
+ config2.hosting === "self-host" && // the user did not choose the 'tina-cloud' auth provider
6165
+ (((_a = config2.authProvider) == null ? void 0 : _a.name) || "") !== "tina-cloud"
6166
+ ) {
6079
6167
  await addSelfHostedTinaAuthToConfig(config2, env.generatedFiles["config"]);
6080
6168
  }
6081
6169
  logNextSteps({
@@ -6368,6 +6456,7 @@ var other = ({ packageManager }) => {
6368
6456
  const packageManagers = {
6369
6457
  pnpm: `pnpm`,
6370
6458
  npm: `npx`,
6459
+ // npx is the way to run executables that aren't in your "scripts"
6371
6460
  yarn: `yarn`
6372
6461
  };
6373
6462
  return `${packageManagers[packageManager]} tinacms dev -c "<your dev command>"`;
@@ -6380,6 +6469,7 @@ var frameworkDevCmds = {
6380
6469
  const packageManagers = {
6381
6470
  pnpm: `pnpm`,
6382
6471
  npm: `npm run`,
6472
+ // npx is the way to run executables that aren't in your "scripts"
6383
6473
  yarn: `yarn`
6384
6474
  };
6385
6475
  return `${packageManagers[packageManager]} dev`;
@@ -6636,6 +6726,4 @@ cli.register(SearchIndexCommand);
6636
6726
  cli.register(import_clipanion8.Builtins.DefinitionsCommand);
6637
6727
  cli.register(import_clipanion8.Builtins.HelpCommand);
6638
6728
  cli.register(import_clipanion8.Builtins.VersionCommand);
6639
- var src_default = cli;
6640
- // Annotate the CommonJS export names for ESM import in node:
6641
- 0 && (module.exports = {});
6729
+ var index_default = cli;