@tinacms/cli 0.0.0-b4c6a60-20241010070518 → 0.0.0-b720fb9-20241203044105

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
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(src_exports);
31
31
  var import_clipanion8 = require("clipanion");
32
32
 
33
33
  // package.json
34
- var version = "1.6.9";
34
+ var version = "1.6.12";
35
35
 
36
36
  // src/next/commands/dev-command/index.ts
37
37
  var import_clipanion2 = require("clipanion");
@@ -41,582 +41,20 @@ var import_chokidar = __toESM(require("chokidar"));
41
41
  var import_graphql10 = require("@tinacms/graphql");
42
42
 
43
43
  // src/next/config-manager.ts
44
- var import_fs_extra = __toESM(require("fs-extra"));
44
+ var import_fs_extra2 = __toESM(require("fs-extra"));
45
45
  var import_path = __toESM(require("path"));
46
46
  var import_os = __toESM(require("os"));
47
47
  var esbuild = __toESM(require("esbuild"));
48
48
  var dotenv = __toESM(require("dotenv"));
49
- var import_normalize_path = __toESM(require("normalize-path"));
49
+ var import_normalize_path2 = __toESM(require("normalize-path"));
50
50
  var import_chalk2 = __toESM(require("chalk"));
51
51
 
52
- // src/logger/index.ts
53
- var import_chalk = __toESM(require("chalk"));
54
-
55
- // src/logger/is-unicode-supported.ts
56
- function isUnicodeSupported() {
57
- if (process.platform !== "win32") {
58
- return process.env.TERM !== "linux";
59
- }
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";
61
- }
62
-
63
- // src/logger/index.ts
64
- var import_log4js = __toESM(require("log4js"));
65
- var logger = import_log4js.default.getLogger();
66
- import_log4js.default.configure({
67
- appenders: {
68
- out: { type: "stdout", layout: { type: "messagePassThrough" } }
69
- },
70
- categories: { default: { appenders: ["out"], level: "info" } }
71
- });
72
- logger.level = "info";
73
- function ansiRegex() {
74
- const pattern = [
75
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
76
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
77
- ].join("|");
78
- return new RegExp(pattern, "g");
79
- }
80
- var bar = "\u2502";
81
- var strip = (str) => str.replace(ansiRegex(), "");
82
- var note = (message = "", title = "") => {
83
- const lines = `
84
- ${message}
85
- `.split("\n");
86
- const len = lines.reduce((sum, ln) => {
87
- ln = strip(ln);
88
- return ln.length > sum ? ln.length : sum;
89
- }, 0) + 2;
90
- const msg = lines.map(
91
- (ln) => `${import_chalk.default.gray(bar)} ${import_chalk.default.white(ln)}${" ".repeat(
92
- len - strip(ln).length
93
- )}${import_chalk.default.gray(bar)}`
94
- ).join("\n");
95
- const underscoreLen = len - title.length - 1 > 0 ? len - title.length - 1 : 0;
96
- process.stdout.write(
97
- `${import_chalk.default.gray(bar)}
98
- ${import_chalk.default.green("\u25CB")} ${import_chalk.default.reset(
99
- title
100
- )} ${import_chalk.default.gray("\u2500".repeat(underscoreLen) + "\u256E")}
101
- ${msg}
102
- ${import_chalk.default.gray(
103
- "\u251C" + "\u2500".repeat(len + 2) + "\u256F"
104
- )}
105
- `
106
- );
107
- };
108
- var summary = (content) => {
109
- const outString = [];
110
- let longestKey = 0;
111
- content.items.forEach((item) => {
112
- item.subItems.forEach((subItem) => {
113
- if (subItem.key.length > longestKey) {
114
- longestKey = subItem.key.length;
115
- }
116
- });
117
- });
118
- content.items.forEach((item) => {
119
- outString.push(`${item.emoji} ${import_chalk.default.cyan(item.heading)}`);
120
- item.subItems.forEach((subItem) => {
121
- const spaces = longestKey - subItem.key.length + 4;
122
- outString.push(
123
- ` ${subItem.key}:${[...Array(spaces)].join(" ")}${import_chalk.default.cyan(
124
- subItem.value
125
- )}`
126
- );
127
- });
128
- outString.push(``);
129
- });
130
- if (process.env.CI) {
131
- logger.info(JSON.stringify(content, null, 2));
132
- } else {
133
- note(outString.join("\n"), content.heading);
134
- }
135
- };
136
- var unicode = isUnicodeSupported();
137
- var s = (c, fallback) => unicode ? c : fallback;
138
- var S_STEP_ACTIVE = s("\u25C6", "*");
139
- var S_STEP_CANCEL = s("\u25A0", "x");
140
- var S_STEP_ERROR = s("\u25B2", "x");
141
- var S_STEP_SUBMIT = s("\u25C7", "o");
142
- var S_BAR_START = s("\u250C", "T");
143
- var S_BAR = s("\u2502", "|");
144
- var S_BAR_END = s("\u2514", "\u2014");
145
- var S_RADIO_ACTIVE = s("\u25CF", ">");
146
- var S_RADIO_INACTIVE = s("\u25CB", " ");
147
- var S_CHECKBOX_ACTIVE = s("\u25FB", "[\u2022]");
148
- var S_CHECKBOX_SELECTED = s("\u25FC", "[+]");
149
- var S_CHECKBOX_INACTIVE = s("\u25FB", "[ ]");
150
- var S_PASSWORD_MASK = s("\u25AA", "\u2022");
151
- var S_BAR_H = s("\u2500", "-");
152
- var S_CORNER_TOP_RIGHT = s("\u256E", "+");
153
- var S_CONNECT_LEFT = s("\u251C", "+");
154
- var S_CORNER_BOTTOM_RIGHT = s("\u256F", "+");
155
- var S_INFO = s("\u25CF", "\u2022");
156
- var S_SUCCESS = s("\u25C6", "*");
157
- var S_WARN = s("\u25B2", "!");
158
- var S_ERROR = s("\u25A0", "x");
159
-
160
- // src/next/config-manager.ts
161
- var TINA_FOLDER = "tina";
162
- var LEGACY_TINA_FOLDER = ".tina";
163
- var GENERATED_FOLDER = "__generated__";
164
- var GRAPHQL_JSON_FILE = "_graphql.json";
165
- var GRAPHQL_GQL_FILE = "schema.gql";
166
- var SCHEMA_JSON_FILE = "_schema.json";
167
- var LOOKUP_JSON_FILE = "_lookup.json";
168
- var ConfigManager = class {
169
- constructor({
170
- rootPath = process.cwd(),
171
- tinaGraphQLVersion,
172
- legacyNoSDK
173
- }) {
174
- this.rootPath = (0, import_normalize_path.default)(rootPath);
175
- this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
176
- this.legacyNoSDK = legacyNoSDK;
177
- }
178
- isUsingTs() {
179
- return [".ts", ".tsx"].includes(import_path.default.extname(this.tinaConfigFilePath));
180
- }
181
- hasSelfHostedConfig() {
182
- return !!this.selfHostedDatabaseFilePath;
183
- }
184
- hasSeparateContentRoot() {
185
- return this.rootPath !== this.contentRootPath;
186
- }
187
- shouldSkipSDK() {
188
- var _a;
189
- if (this.legacyNoSDK) {
190
- return this.legacyNoSDK;
191
- }
192
- return ((_a = this.config.client) == null ? void 0 : _a.skip) || false;
193
- }
194
- async processConfig() {
195
- this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
196
- this.envFilePath = import_path.default.resolve(
197
- import_path.default.join(this.tinaFolderPath, "..", ".env")
198
- );
199
- dotenv.config({ path: this.envFilePath });
200
- this.tinaConfigFilePath = await this.getPathWithExtension(
201
- import_path.default.join(this.tinaFolderPath, "config")
202
- );
203
- if (!this.tinaConfigFilePath) {
204
- throw new Error(
205
- `Unable to find config file in ${this.tinaFolderPath}. Looking for a file named "config.{ts,tsx,js,jsx}"`
206
- );
207
- }
208
- this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
209
- import_path.default.join(this.tinaFolderPath, "database")
210
- );
211
- this.generatedFolderPath = import_path.default.join(this.tinaFolderPath, GENERATED_FOLDER);
212
- this.generatedCachePath = import_path.default.join(
213
- this.generatedFolderPath,
214
- ".cache",
215
- String(new Date().getTime())
216
- );
217
- this.generatedGraphQLGQLPath = import_path.default.join(
218
- this.generatedFolderPath,
219
- GRAPHQL_GQL_FILE
220
- );
221
- this.generatedGraphQLJSONPath = import_path.default.join(
222
- this.generatedFolderPath,
223
- GRAPHQL_JSON_FILE
224
- );
225
- this.generatedSchemaJSONPath = import_path.default.join(
226
- this.generatedFolderPath,
227
- SCHEMA_JSON_FILE
228
- );
229
- this.generatedLookupJSONPath = import_path.default.join(
230
- this.generatedFolderPath,
231
- LOOKUP_JSON_FILE
232
- );
233
- this.generatedQueriesFilePath = import_path.default.join(
234
- this.generatedFolderPath,
235
- "queries.gql"
236
- );
237
- this.generatedFragmentsFilePath = import_path.default.join(
238
- this.generatedFolderPath,
239
- "frags.gql"
240
- );
241
- this.generatedTypesTSFilePath = import_path.default.join(
242
- this.generatedFolderPath,
243
- "types.ts"
244
- );
245
- this.generatedTypesJSFilePath = import_path.default.join(
246
- this.generatedFolderPath,
247
- "types.js"
248
- );
249
- this.generatedTypesDFilePath = import_path.default.join(
250
- this.generatedFolderPath,
251
- "types.d.ts"
252
- );
253
- this.userQueriesAndFragmentsGlob = import_path.default.join(
254
- this.tinaFolderPath,
255
- "queries/**/*.{graphql,gql}"
256
- );
257
- this.generatedQueriesAndFragmentsGlob = import_path.default.join(
258
- this.generatedFolderPath,
259
- "*.{graphql,gql}"
260
- );
261
- this.generatedClientTSFilePath = import_path.default.join(
262
- this.generatedFolderPath,
263
- "client.ts"
264
- );
265
- this.generatedClientJSFilePath = import_path.default.join(
266
- this.generatedFolderPath,
267
- "client.js"
268
- );
269
- this.generatedClientDFilePath = import_path.default.join(
270
- this.generatedFolderPath,
271
- "client.d.ts"
272
- );
273
- this.generatedDatabaseClientDFilePath = import_path.default.join(
274
- this.generatedFolderPath,
275
- "databaseClient.d.ts"
276
- );
277
- this.generatedDatabaseClientTSFilePath = import_path.default.join(
278
- this.generatedFolderPath,
279
- "databaseClient.ts"
280
- );
281
- this.generatedDatabaseClientJSFilePath = import_path.default.join(
282
- this.generatedFolderPath,
283
- "databaseClient.js"
284
- );
285
- const clientExists = this.isUsingTs() ? await import_fs_extra.default.pathExists(this.generatedClientTSFilePath) : await import_fs_extra.default.pathExists(this.generatedClientJSFilePath);
286
- if (!clientExists) {
287
- const file = "export default ()=>({})\nexport const client = ()=>({})";
288
- if (this.isUsingTs()) {
289
- await import_fs_extra.default.outputFile(this.generatedClientTSFilePath, file);
290
- } else {
291
- await import_fs_extra.default.outputFile(this.generatedClientJSFilePath, file);
292
- }
293
- }
294
- const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
295
- this.generatedFolderPath,
296
- this.tinaConfigFilePath
297
- );
298
- this.watchList = watchList;
299
- this.config = config2;
300
- this.prebuildFilePath = prebuildPath;
301
- this.publicFolderPath = import_path.default.join(
302
- this.rootPath,
303
- this.config.build.publicFolder
304
- );
305
- this.outputFolderPath = import_path.default.join(
306
- this.publicFolderPath,
307
- this.config.build.outputFolder
308
- );
309
- this.outputHTMLFilePath = import_path.default.join(this.outputFolderPath, "index.html");
310
- this.outputGitignorePath = import_path.default.join(this.outputFolderPath, ".gitignore");
311
- const fullLocalContentPath = import_path.default.join(
312
- this.tinaFolderPath,
313
- this.config.localContentPath || ""
314
- );
315
- if (this.config.localContentPath) {
316
- const localContentPathExists = await import_fs_extra.default.pathExists(fullLocalContentPath);
317
- if (localContentPathExists) {
318
- logger.info(`Using separate content repo at ${fullLocalContentPath}`);
319
- this.contentRootPath = fullLocalContentPath;
320
- } else {
321
- logger.warn(
322
- `${import_chalk2.default.yellow("Warning:")} The localContentPath ${import_chalk2.default.cyan(
323
- fullLocalContentPath
324
- )} does not exist. Please create it or remove the localContentPath from your config file at ${import_chalk2.default.cyan(
325
- this.tinaConfigFilePath
326
- )}`
327
- );
328
- }
329
- }
330
- if (!this.contentRootPath) {
331
- this.contentRootPath = this.rootPath;
332
- }
333
- this.generatedFolderPathContentRepo = import_path.default.join(
334
- await this.getTinaFolderPath(this.contentRootPath),
335
- GENERATED_FOLDER
336
- );
337
- this.spaMainPath = require.resolve("@tinacms/app");
338
- this.spaRootPath = import_path.default.join(this.spaMainPath, "..", "..");
339
- }
340
- async getTinaFolderPath(rootPath) {
341
- const tinaFolderPath = import_path.default.join(rootPath, TINA_FOLDER);
342
- const tinaFolderExists = await import_fs_extra.default.pathExists(tinaFolderPath);
343
- if (tinaFolderExists) {
344
- this.isUsingLegacyFolder = false;
345
- return tinaFolderPath;
346
- }
347
- const legacyFolderPath = import_path.default.join(rootPath, LEGACY_TINA_FOLDER);
348
- const legacyFolderExists = await import_fs_extra.default.pathExists(legacyFolderPath);
349
- if (legacyFolderExists) {
350
- this.isUsingLegacyFolder = true;
351
- return legacyFolderPath;
352
- }
353
- throw new Error(
354
- `Unable to find Tina folder, if you're working in folder outside of the Tina config be sure to specify --rootPath`
355
- );
356
- }
357
- getTinaGraphQLVersion() {
358
- var _a, _b;
359
- if (this.tinaGraphQLVersionFromCLI) {
360
- return this.tinaGraphQLVersionFromCLI;
361
- }
362
- const generatedSchema = import_fs_extra.default.readJSONSync(this.generatedSchemaJSONPath);
363
- if (!generatedSchema || !(typeof (generatedSchema == null ? void 0 : generatedSchema.version) !== "undefined") || !(typeof ((_a = generatedSchema == null ? void 0 : generatedSchema.version) == null ? void 0 : _a.major) === "string") || !(typeof ((_b = generatedSchema == null ? void 0 : generatedSchema.version) == null ? void 0 : _b.minor) === "string")) {
364
- throw new Error(
365
- `Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
366
- );
367
- }
368
- return `${generatedSchema.version.major}.${generatedSchema.version.minor}`;
369
- }
370
- printGeneratedClientFilePath() {
371
- if (this.isUsingTs()) {
372
- return this.generatedClientTSFilePath.replace(`${this.rootPath}/`, "");
373
- }
374
- return this.generatedClientJSFilePath.replace(`${this.rootPath}/`, "");
375
- }
376
- printGeneratedTypesFilePath() {
377
- return this.generatedTypesTSFilePath.replace(`${this.rootPath}/`, "");
378
- }
379
- printoutputHTMLFilePath() {
380
- return this.outputHTMLFilePath.replace(`${this.publicFolderPath}/`, "");
381
- }
382
- printRelativePath(filename) {
383
- if (filename) {
384
- return filename.replace(/\\/g, "/").replace(`${this.rootPath}/`, "");
385
- }
386
- throw `No path provided to print`;
387
- }
388
- printPrebuildFilePath() {
389
- return this.prebuildFilePath.replace(/\\/g, "/").replace(`${this.rootPath}/${this.tinaFolderPath}/`, "");
390
- }
391
- printContentRelativePath(filename) {
392
- if (filename) {
393
- return filename.replace(/\\/g, "/").replace(`${this.contentRootPath}/`, "");
394
- }
395
- throw `No path provided to print`;
396
- }
397
- async getPathWithExtension(filepath) {
398
- const extensions = ["tsx", "ts", "jsx", "js"];
399
- let result;
400
- await Promise.all(
401
- extensions.map(async (ext) => {
402
- if (result) {
403
- return;
404
- }
405
- const filepathWithExtension = `${filepath}.${ext}`;
406
- const exists = import_fs_extra.default.existsSync(filepathWithExtension);
407
- if (exists) {
408
- result = filepathWithExtension;
409
- }
410
- })
411
- );
412
- return result;
413
- }
414
- async loadDatabaseFile() {
415
- const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
416
- const outfile = import_path.default.join(tmpdir, "database.build.js");
417
- await esbuild.build({
418
- entryPoints: [this.selfHostedDatabaseFilePath],
419
- bundle: true,
420
- platform: "node",
421
- outfile,
422
- loader: loaders
423
- });
424
- const result = require(outfile);
425
- import_fs_extra.default.removeSync(outfile);
426
- return result.default;
427
- }
428
- async loadConfigFile(generatedFolderPath, configFilePath) {
429
- const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
430
- const prebuild = import_path.default.join(this.generatedFolderPath, "config.prebuild.jsx");
431
- const outfile = import_path.default.join(tmpdir, "config.build.jsx");
432
- const outfile2 = import_path.default.join(tmpdir, "config.build.js");
433
- const tempTSConfigFile = import_path.default.join(tmpdir, "tsconfig.json");
434
- import_fs_extra.default.outputFileSync(tempTSConfigFile, "{}");
435
- const result2 = await esbuild.build({
436
- entryPoints: [configFilePath],
437
- bundle: true,
438
- target: ["es2020"],
439
- platform: "browser",
440
- format: "esm",
441
- logLevel: "silent",
442
- packages: "external",
443
- ignoreAnnotations: true,
444
- outfile: prebuild,
445
- loader: loaders,
446
- metafile: true
447
- });
448
- const flattenedList = [];
449
- Object.keys(result2.metafile.inputs).forEach((key) => {
450
- if (key.includes("node_modules") || key.includes("__generated__")) {
451
- return;
452
- }
453
- flattenedList.push(key);
454
- });
455
- await esbuild.build({
456
- entryPoints: [configFilePath],
457
- bundle: true,
458
- target: ["es2020"],
459
- logLevel: "silent",
460
- platform: "node",
461
- outfile,
462
- loader: loaders
463
- });
464
- await esbuild.build({
465
- entryPoints: [outfile],
466
- bundle: true,
467
- logLevel: "silent",
468
- platform: "node",
469
- outfile: outfile2,
470
- loader: loaders
471
- });
472
- let result;
473
- try {
474
- result = require(outfile2);
475
- } catch (e) {
476
- console.error("Unexpected error loading config");
477
- console.error(e);
478
- throw e;
479
- }
480
- import_fs_extra.default.removeSync(outfile);
481
- import_fs_extra.default.removeSync(outfile2);
482
- return {
483
- config: result.default,
484
- prebuildPath: prebuild,
485
- watchList: flattenedList
486
- };
487
- }
488
- };
489
- var loaders = {
490
- ".aac": "file",
491
- ".css": "file",
492
- ".eot": "file",
493
- ".flac": "file",
494
- ".gif": "file",
495
- ".jpeg": "file",
496
- ".jpg": "file",
497
- ".json": "json",
498
- ".mp3": "file",
499
- ".mp4": "file",
500
- ".ogg": "file",
501
- ".otf": "file",
502
- ".png": "file",
503
- ".svg": "file",
504
- ".ttf": "file",
505
- ".wav": "file",
506
- ".webm": "file",
507
- ".webp": "file",
508
- ".woff": "file",
509
- ".woff2": "file",
510
- ".js": "jsx",
511
- ".jsx": "jsx",
512
- ".tsx": "tsx"
513
- };
514
-
515
- // src/next/commands/dev-command/html.ts
516
- var errorHTML = `<style type="text/css">
517
- #no-assets-placeholder body {
518
- font-family: sans-serif;
519
- font-size: 16px;
520
- line-height: 1.4;
521
- color: #333;
522
- background-color: #f5f5f5;
523
- }
524
- #no-assets-placeholder {
525
- max-width: 600px;
526
- margin: 0 auto;
527
- padding: 40px;
528
- text-align: center;
529
- background-color: #fff;
530
- box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
531
- }
532
- #no-assets-placeholder h1 {
533
- font-size: 24px;
534
- margin-bottom: 20px;
535
- }
536
- #no-assets-placeholder p {
537
- margin-bottom: 10px;
538
- }
539
- #no-assets-placeholder a {
540
- color: #0077cc;
541
- text-decoration: none;
542
- }
543
- #no-assets-placeholder a:hover {
544
- text-decoration: underline;
545
- }
546
- </style>
547
- <div id="no-assets-placeholder">
548
- <h1>Failed loading TinaCMS assets</h1>
549
- <p>
550
- Your TinaCMS configuration may be misconfigured, and we could not load
551
- the assets for this page.
552
- </p>
553
- <p>
554
- Please visit <a href="https://tina.io/docs/tina-cloud/faq/#how-do-i-resolve-failed-loading-tinacms-assets-error">this doc</a> for help.
555
- </p>
556
- </div>
557
- </div>`.trim().replace(/[\r\n\s]+/g, " ");
558
- var devHTML = (port) => `<!DOCTYPE html>
559
- <html lang="en">
560
- <head>
561
- <meta charset="UTF-8" />
562
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
563
- <title>TinaCMS</title>
564
- </head>
565
-
566
- <!-- if development -->
567
- <script type="module">
568
- import RefreshRuntime from 'http://localhost:${port}/@react-refresh'
569
- RefreshRuntime.injectIntoGlobalHook(window)
570
- window.$RefreshReg$ = () => {}
571
- window.$RefreshSig$ = () => (type) => type
572
- window.__vite_plugin_react_preamble_installed__ = true
573
- <\/script>
574
- <script type="module" src="http://localhost:${port}/@vite/client"><\/script>
575
- <script>
576
- function handleLoadError() {
577
- // Assets have failed to load
578
- document.getElementById('root').innerHTML = '${errorHTML}';
579
- }
580
- <\/script>
581
- <script
582
- type="module"
583
- src="http://localhost:${port}/src/main.tsx"
584
- onerror="handleLoadError()"
585
- ><\/script>
586
- <body class="tina-tailwind">
587
- <div id="root"></div>
588
- </body>
589
- </html>`;
590
-
591
- // src/utils/theme.ts
592
- var import_chalk3 = __toESM(require("chalk"));
593
- var successText = import_chalk3.default.bold.green;
594
- var focusText = import_chalk3.default.bold;
595
- var dangerText = import_chalk3.default.bold.red;
596
- var neutralText = import_chalk3.default.bold.cyan;
597
- var linkText = import_chalk3.default.bold.cyan;
598
- var labelText = import_chalk3.default.bold;
599
- var cmdText = import_chalk3.default.inverse;
600
- var indentedCmd = (str) => {
601
- return ` \u2503 ` + str;
602
- };
603
- var indentText = (str) => {
604
- return String(str).split("\n").map((line) => ` ${line}`).join("\n");
605
- };
606
- var logText = import_chalk3.default.italic.gray;
607
- var warnText = import_chalk3.default.yellowBright.bgBlack;
608
- var titleText = import_chalk3.default.bgHex("d2f1f8").hex("ec4816");
609
- var CONFIRMATION_TEXT = import_chalk3.default.dim("enter to confirm");
610
-
611
- // src/next/commands/dev-command/server/index.ts
612
- var import_vite3 = require("vite");
613
-
614
- // src/next/vite/index.ts
615
- var import_node_path2 = __toESM(require("path"));
616
- var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
617
- var import_fs_extra2 = __toESM(require("fs-extra"));
618
- var import_normalize_path2 = __toESM(require("normalize-path"));
619
- var import_vite = require("vite");
52
+ // src/next/vite/index.ts
53
+ var import_node_path2 = __toESM(require("path"));
54
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
55
+ var import_fs_extra = __toESM(require("fs-extra"));
56
+ var import_normalize_path = __toESM(require("normalize-path"));
57
+ var import_vite = require("vite");
620
58
 
621
59
  // src/next/vite/tailwind.ts
622
60
  var import_node_path = __toESM(require("path"));
@@ -881,183 +319,778 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
881
319
  plugins
882
320
  }
883
321
  }
884
- };
322
+ };
323
+ }
324
+ };
325
+ };
326
+
327
+ // src/next/vite/index.ts
328
+ async function listFilesRecursively({
329
+ directoryPath,
330
+ config: config2,
331
+ roothPath
332
+ }) {
333
+ const fullDirectoryPath = import_node_path2.default.join(
334
+ roothPath,
335
+ config2.publicFolder,
336
+ directoryPath
337
+ );
338
+ const exists = await import_fs_extra.default.pathExists(fullDirectoryPath);
339
+ if (!exists) {
340
+ return { "0": [] };
341
+ }
342
+ const items = await import_fs_extra.default.readdir(fullDirectoryPath);
343
+ const staticMediaItems = [];
344
+ for (const item of items) {
345
+ const itemPath = import_node_path2.default.join(fullDirectoryPath, item);
346
+ const stats = await import_fs_extra.default.promises.lstat(itemPath);
347
+ const staticMediaItem = {
348
+ id: item,
349
+ filename: item,
350
+ type: stats.isDirectory() ? "dir" : "file",
351
+ directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
352
+ src: `/${import_node_path2.default.join(directoryPath, item)}`,
353
+ thumbnails: {
354
+ "75x75": `/${import_node_path2.default.join(directoryPath, item)}`,
355
+ "400x400": `/${import_node_path2.default.join(directoryPath, item)}`,
356
+ "1000x1000": `/${import_node_path2.default.join(directoryPath, item)}`
357
+ }
358
+ };
359
+ if (stats.isDirectory()) {
360
+ staticMediaItem.children = await listFilesRecursively({
361
+ directoryPath: import_node_path2.default.join(directoryPath, item),
362
+ config: config2,
363
+ roothPath
364
+ });
365
+ }
366
+ staticMediaItems.push(staticMediaItem);
367
+ }
368
+ function chunkArrayIntoObject(array, chunkSize) {
369
+ const result = {};
370
+ for (let i = 0; i < array.length; i += chunkSize) {
371
+ const chunkKey = `${i / chunkSize * 20}`;
372
+ result[chunkKey] = array.slice(i, i + chunkSize);
373
+ }
374
+ return result;
375
+ }
376
+ return chunkArrayIntoObject(staticMediaItems, 20);
377
+ }
378
+ var loadProjectConfig = async ({
379
+ rootPath,
380
+ viteConfigEnv
381
+ }) => {
382
+ if (viteConfigEnv) {
383
+ const configFileJs = import_node_path2.default.join(rootPath, "vite.config.js");
384
+ const configFileTs = import_node_path2.default.join(rootPath, "vite.config.ts");
385
+ if (import_fs_extra.default.existsSync(configFileJs)) {
386
+ return await (0, import_vite.loadConfigFromFile)(viteConfigEnv, configFileJs);
387
+ } else if (import_fs_extra.default.existsSync(configFileTs)) {
388
+ return await (0, import_vite.loadConfigFromFile)(viteConfigEnv, configFileTs);
389
+ }
390
+ }
391
+ return { config: {} };
392
+ };
393
+ var createConfig = async ({
394
+ configManager,
395
+ database,
396
+ apiURL,
397
+ plugins = [],
398
+ noWatch,
399
+ rollupOptions,
400
+ viteConfigEnv
401
+ }) => {
402
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
403
+ const projectConfig = await loadProjectConfig({
404
+ rootPath: configManager.rootPath,
405
+ viteConfigEnv
406
+ });
407
+ const publicEnv = {};
408
+ Object.keys(process.env).forEach((key) => {
409
+ if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
410
+ try {
411
+ if (typeof process.env[key] === "string") {
412
+ publicEnv[key] = process.env[key];
413
+ } else {
414
+ publicEnv[key] = JSON.stringify(process.env[key]);
415
+ }
416
+ } catch (error) {
417
+ console.warn(
418
+ `Could not stringify public env process.env.${key} env variable`
419
+ );
420
+ console.warn(error);
421
+ }
422
+ }
423
+ });
424
+ const staticMediaPath = import_node_path2.default.join(
425
+ configManager.generatedFolderPath,
426
+ "static-media.json"
427
+ );
428
+ if ((_b = (_a = configManager.config.media) == null ? void 0 : _a.tina) == null ? void 0 : _b.static) {
429
+ const staticMedia = await listFilesRecursively({
430
+ directoryPath: ((_c = configManager.config.media.tina) == null ? void 0 : _c.mediaRoot) || "",
431
+ config: configManager.config.media.tina,
432
+ roothPath: configManager.rootPath
433
+ });
434
+ await import_fs_extra.default.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
435
+ } else {
436
+ await import_fs_extra.default.outputFile(staticMediaPath, `[]`);
437
+ }
438
+ const alias = {
439
+ TINA_IMPORT: configManager.prebuildFilePath,
440
+ SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
441
+ STATIC_MEDIA_IMPORT: staticMediaPath,
442
+ crypto: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
443
+ fs: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
444
+ os: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
445
+ path: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts")
446
+ };
447
+ if (configManager.shouldSkipSDK()) {
448
+ alias["CLIENT_IMPORT"] = import_node_path2.default.join(
449
+ configManager.spaRootPath,
450
+ "src",
451
+ "dummy-client.ts"
452
+ );
453
+ } else {
454
+ alias["CLIENT_IMPORT"] = configManager.isUsingTs() ? configManager.generatedTypesTSFilePath : configManager.generatedTypesJSFilePath;
455
+ }
456
+ let basePath;
457
+ if (configManager.config.build.basePath) {
458
+ basePath = configManager.config.build.basePath;
459
+ }
460
+ const config2 = {
461
+ root: configManager.spaRootPath,
462
+ base: `/${basePath ? `${(0, import_normalize_path.default)(basePath)}/` : ""}${(0, import_normalize_path.default)(
463
+ configManager.config.build.outputFolder
464
+ )}/`,
465
+ appType: "spa",
466
+ resolve: {
467
+ alias: {
468
+ ...(_d = projectConfig.config.resolve) == null ? void 0 : _d.alias,
469
+ ...alias
470
+ },
471
+ dedupe: ["graphql", "tinacms", "react", "react-dom", "react-router-dom"]
472
+ },
473
+ define: {
474
+ "process.env": `new Object(${JSON.stringify(publicEnv)})`,
475
+ "process.platform": `"${process.platform}"`,
476
+ __API_URL__: `"${apiURL}"`,
477
+ __BASE_PATH__: `"${((_f = (_e = configManager.config) == null ? void 0 : _e.build) == null ? void 0 : _f.basePath) || ""}"`,
478
+ __TINA_GRAPHQL_VERSION__: `"${configManager.getTinaGraphQLVersion()}"`
479
+ },
480
+ logLevel: "error",
481
+ optimizeDeps: {
482
+ force: true,
483
+ include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
484
+ },
485
+ server: {
486
+ host: (_i = (_h = (_g = configManager.config) == null ? void 0 : _g.build) == null ? void 0 : _h.host) != null ? _i : false,
487
+ watch: noWatch ? {
488
+ ignored: ["**/*"]
489
+ } : {
490
+ ignored: [
491
+ `${configManager.tinaFolderPath}/**/!(config.prebuild.jsx|_graphql.json)`
492
+ ]
493
+ },
494
+ fs: {
495
+ strict: false
496
+ }
497
+ },
498
+ build: {
499
+ sourcemap: false,
500
+ outDir: configManager.outputFolderPath,
501
+ emptyOutDir: true,
502
+ rollupOptions
503
+ },
504
+ plugins: [
505
+ (0, import_plugin_react.default)({
506
+ babel: {
507
+ compact: true
508
+ }
509
+ }),
510
+ (0, import_vite.splitVendorChunkPlugin)(),
511
+ tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
512
+ ...plugins
513
+ ]
514
+ };
515
+ return config2;
516
+ };
517
+
518
+ // src/logger/index.ts
519
+ var import_chalk = __toESM(require("chalk"));
520
+
521
+ // src/logger/is-unicode-supported.ts
522
+ function isUnicodeSupported() {
523
+ if (process.platform !== "win32") {
524
+ return process.env.TERM !== "linux";
525
+ }
526
+ 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";
527
+ }
528
+
529
+ // src/logger/index.ts
530
+ var import_log4js = __toESM(require("log4js"));
531
+ var logger = import_log4js.default.getLogger();
532
+ import_log4js.default.configure({
533
+ appenders: {
534
+ out: { type: "stdout", layout: { type: "messagePassThrough" } }
535
+ },
536
+ categories: { default: { appenders: ["out"], level: "info" } }
537
+ });
538
+ logger.level = "info";
539
+ function ansiRegex() {
540
+ const pattern = [
541
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
542
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
543
+ ].join("|");
544
+ return new RegExp(pattern, "g");
545
+ }
546
+ var bar = "\u2502";
547
+ var strip = (str) => str.replace(ansiRegex(), "");
548
+ var note = (message = "", title = "") => {
549
+ const lines = `
550
+ ${message}
551
+ `.split("\n");
552
+ const len = lines.reduce((sum, ln) => {
553
+ ln = strip(ln);
554
+ return ln.length > sum ? ln.length : sum;
555
+ }, 0) + 2;
556
+ const msg = lines.map(
557
+ (ln) => `${import_chalk.default.gray(bar)} ${import_chalk.default.white(ln)}${" ".repeat(
558
+ len - strip(ln).length
559
+ )}${import_chalk.default.gray(bar)}`
560
+ ).join("\n");
561
+ const underscoreLen = len - title.length - 1 > 0 ? len - title.length - 1 : 0;
562
+ process.stdout.write(
563
+ `${import_chalk.default.gray(bar)}
564
+ ${import_chalk.default.green("\u25CB")} ${import_chalk.default.reset(
565
+ title
566
+ )} ${import_chalk.default.gray("\u2500".repeat(underscoreLen) + "\u256E")}
567
+ ${msg}
568
+ ${import_chalk.default.gray(
569
+ "\u251C" + "\u2500".repeat(len + 2) + "\u256F"
570
+ )}
571
+ `
572
+ );
573
+ };
574
+ var summary = (content) => {
575
+ const outString = [];
576
+ let longestKey = 0;
577
+ content.items.forEach((item) => {
578
+ item.subItems.forEach((subItem) => {
579
+ if (subItem.key.length > longestKey) {
580
+ longestKey = subItem.key.length;
581
+ }
582
+ });
583
+ });
584
+ content.items.forEach((item) => {
585
+ outString.push(`${item.emoji} ${import_chalk.default.cyan(item.heading)}`);
586
+ item.subItems.forEach((subItem) => {
587
+ const spaces = longestKey - subItem.key.length + 4;
588
+ outString.push(
589
+ ` ${subItem.key}:${[...Array(spaces)].join(" ")}${import_chalk.default.cyan(
590
+ subItem.value
591
+ )}`
592
+ );
593
+ });
594
+ outString.push(``);
595
+ });
596
+ if (process.env.CI) {
597
+ logger.info(JSON.stringify(content, null, 2));
598
+ } else {
599
+ note(outString.join("\n"), content.heading);
600
+ }
601
+ };
602
+ var unicode = isUnicodeSupported();
603
+ var s = (c, fallback) => unicode ? c : fallback;
604
+ var S_STEP_ACTIVE = s("\u25C6", "*");
605
+ var S_STEP_CANCEL = s("\u25A0", "x");
606
+ var S_STEP_ERROR = s("\u25B2", "x");
607
+ var S_STEP_SUBMIT = s("\u25C7", "o");
608
+ var S_BAR_START = s("\u250C", "T");
609
+ var S_BAR = s("\u2502", "|");
610
+ var S_BAR_END = s("\u2514", "\u2014");
611
+ var S_RADIO_ACTIVE = s("\u25CF", ">");
612
+ var S_RADIO_INACTIVE = s("\u25CB", " ");
613
+ var S_CHECKBOX_ACTIVE = s("\u25FB", "[\u2022]");
614
+ var S_CHECKBOX_SELECTED = s("\u25FC", "[+]");
615
+ var S_CHECKBOX_INACTIVE = s("\u25FB", "[ ]");
616
+ var S_PASSWORD_MASK = s("\u25AA", "\u2022");
617
+ var S_BAR_H = s("\u2500", "-");
618
+ var S_CORNER_TOP_RIGHT = s("\u256E", "+");
619
+ var S_CONNECT_LEFT = s("\u251C", "+");
620
+ var S_CORNER_BOTTOM_RIGHT = s("\u256F", "+");
621
+ var S_INFO = s("\u25CF", "\u2022");
622
+ var S_SUCCESS = s("\u25C6", "*");
623
+ var S_WARN = s("\u25B2", "!");
624
+ var S_ERROR = s("\u25A0", "x");
625
+
626
+ // src/next/config-manager.ts
627
+ var TINA_FOLDER = "tina";
628
+ var LEGACY_TINA_FOLDER = ".tina";
629
+ var GENERATED_FOLDER = "__generated__";
630
+ var GRAPHQL_JSON_FILE = "_graphql.json";
631
+ var GRAPHQL_GQL_FILE = "schema.gql";
632
+ var SCHEMA_JSON_FILE = "_schema.json";
633
+ var LOOKUP_JSON_FILE = "_lookup.json";
634
+ var ConfigManager = class {
635
+ constructor({
636
+ rootPath = process.cwd(),
637
+ tinaGraphQLVersion,
638
+ legacyNoSDK
639
+ }) {
640
+ this.rootPath = (0, import_normalize_path2.default)(rootPath);
641
+ this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
642
+ this.legacyNoSDK = legacyNoSDK;
643
+ }
644
+ isUsingTs() {
645
+ return [".ts", ".tsx"].includes(import_path.default.extname(this.tinaConfigFilePath));
646
+ }
647
+ hasSelfHostedConfig() {
648
+ return !!this.selfHostedDatabaseFilePath;
649
+ }
650
+ hasSeparateContentRoot() {
651
+ return this.rootPath !== this.contentRootPath;
652
+ }
653
+ shouldSkipSDK() {
654
+ var _a;
655
+ if (this.legacyNoSDK) {
656
+ return this.legacyNoSDK;
657
+ }
658
+ return ((_a = this.config.client) == null ? void 0 : _a.skip) || false;
659
+ }
660
+ async processConfig() {
661
+ this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
662
+ this.envFilePath = import_path.default.resolve(
663
+ import_path.default.join(this.tinaFolderPath, "..", ".env")
664
+ );
665
+ dotenv.config({ path: this.envFilePath });
666
+ this.tinaConfigFilePath = await this.getPathWithExtension(
667
+ import_path.default.join(this.tinaFolderPath, "config")
668
+ );
669
+ if (!this.tinaConfigFilePath) {
670
+ throw new Error(
671
+ `Unable to find config file in ${this.tinaFolderPath}. Looking for a file named "config.{ts,tsx,js,jsx}"`
672
+ );
673
+ }
674
+ this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
675
+ import_path.default.join(this.tinaFolderPath, "database")
676
+ );
677
+ this.generatedFolderPath = import_path.default.join(this.tinaFolderPath, GENERATED_FOLDER);
678
+ this.generatedCachePath = import_path.default.join(
679
+ this.generatedFolderPath,
680
+ ".cache",
681
+ String(new Date().getTime())
682
+ );
683
+ this.generatedGraphQLGQLPath = import_path.default.join(
684
+ this.generatedFolderPath,
685
+ GRAPHQL_GQL_FILE
686
+ );
687
+ this.generatedGraphQLJSONPath = import_path.default.join(
688
+ this.generatedFolderPath,
689
+ GRAPHQL_JSON_FILE
690
+ );
691
+ this.generatedSchemaJSONPath = import_path.default.join(
692
+ this.generatedFolderPath,
693
+ SCHEMA_JSON_FILE
694
+ );
695
+ this.generatedLookupJSONPath = import_path.default.join(
696
+ this.generatedFolderPath,
697
+ LOOKUP_JSON_FILE
698
+ );
699
+ this.generatedQueriesFilePath = import_path.default.join(
700
+ this.generatedFolderPath,
701
+ "queries.gql"
702
+ );
703
+ this.generatedFragmentsFilePath = import_path.default.join(
704
+ this.generatedFolderPath,
705
+ "frags.gql"
706
+ );
707
+ this.generatedTypesTSFilePath = import_path.default.join(
708
+ this.generatedFolderPath,
709
+ "types.ts"
710
+ );
711
+ this.generatedTypesJSFilePath = import_path.default.join(
712
+ this.generatedFolderPath,
713
+ "types.js"
714
+ );
715
+ this.generatedTypesDFilePath = import_path.default.join(
716
+ this.generatedFolderPath,
717
+ "types.d.ts"
718
+ );
719
+ this.userQueriesAndFragmentsGlob = import_path.default.join(
720
+ this.tinaFolderPath,
721
+ "queries/**/*.{graphql,gql}"
722
+ );
723
+ this.generatedQueriesAndFragmentsGlob = import_path.default.join(
724
+ this.generatedFolderPath,
725
+ "*.{graphql,gql}"
726
+ );
727
+ this.generatedClientTSFilePath = import_path.default.join(
728
+ this.generatedFolderPath,
729
+ "client.ts"
730
+ );
731
+ this.generatedClientJSFilePath = import_path.default.join(
732
+ this.generatedFolderPath,
733
+ "client.js"
734
+ );
735
+ this.generatedClientDFilePath = import_path.default.join(
736
+ this.generatedFolderPath,
737
+ "client.d.ts"
738
+ );
739
+ this.generatedDatabaseClientDFilePath = import_path.default.join(
740
+ this.generatedFolderPath,
741
+ "databaseClient.d.ts"
742
+ );
743
+ this.generatedDatabaseClientTSFilePath = import_path.default.join(
744
+ this.generatedFolderPath,
745
+ "databaseClient.ts"
746
+ );
747
+ this.generatedDatabaseClientJSFilePath = import_path.default.join(
748
+ this.generatedFolderPath,
749
+ "databaseClient.js"
750
+ );
751
+ const clientExists = this.isUsingTs() ? await import_fs_extra2.default.pathExists(this.generatedClientTSFilePath) : await import_fs_extra2.default.pathExists(this.generatedClientJSFilePath);
752
+ if (!clientExists) {
753
+ const file = "export default ()=>({})\nexport const client = ()=>({})";
754
+ if (this.isUsingTs()) {
755
+ await import_fs_extra2.default.outputFile(this.generatedClientTSFilePath, file);
756
+ } else {
757
+ await import_fs_extra2.default.outputFile(this.generatedClientJSFilePath, file);
758
+ }
759
+ }
760
+ const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
761
+ this.generatedFolderPath,
762
+ this.tinaConfigFilePath
763
+ );
764
+ this.watchList = watchList;
765
+ this.config = config2;
766
+ this.prebuildFilePath = prebuildPath;
767
+ this.publicFolderPath = import_path.default.join(
768
+ this.rootPath,
769
+ this.config.build.publicFolder
770
+ );
771
+ this.outputFolderPath = import_path.default.join(
772
+ this.publicFolderPath,
773
+ this.config.build.outputFolder
774
+ );
775
+ this.outputHTMLFilePath = import_path.default.join(this.outputFolderPath, "index.html");
776
+ this.outputGitignorePath = import_path.default.join(this.outputFolderPath, ".gitignore");
777
+ const fullLocalContentPath = import_path.default.join(
778
+ this.tinaFolderPath,
779
+ this.config.localContentPath || ""
780
+ );
781
+ if (this.config.localContentPath) {
782
+ const localContentPathExists = await import_fs_extra2.default.pathExists(fullLocalContentPath);
783
+ if (localContentPathExists) {
784
+ logger.info(`Using separate content repo at ${fullLocalContentPath}`);
785
+ this.contentRootPath = fullLocalContentPath;
786
+ } else {
787
+ logger.warn(
788
+ `${import_chalk2.default.yellow("Warning:")} The localContentPath ${import_chalk2.default.cyan(
789
+ fullLocalContentPath
790
+ )} does not exist. Please create it or remove the localContentPath from your config file at ${import_chalk2.default.cyan(
791
+ this.tinaConfigFilePath
792
+ )}`
793
+ );
794
+ }
885
795
  }
886
- };
887
- };
888
-
889
- // src/next/vite/index.ts
890
- async function listFilesRecursively({
891
- directoryPath,
892
- config: config2,
893
- roothPath
894
- }) {
895
- const fullDirectoryPath = import_node_path2.default.join(
896
- roothPath,
897
- config2.publicFolder,
898
- directoryPath
899
- );
900
- const exists = await import_fs_extra2.default.pathExists(fullDirectoryPath);
901
- if (!exists) {
902
- return { "0": [] };
796
+ if (!this.contentRootPath) {
797
+ this.contentRootPath = this.rootPath;
798
+ }
799
+ this.generatedFolderPathContentRepo = import_path.default.join(
800
+ await this.getTinaFolderPath(this.contentRootPath),
801
+ GENERATED_FOLDER
802
+ );
803
+ this.spaMainPath = require.resolve("@tinacms/app");
804
+ this.spaRootPath = import_path.default.join(this.spaMainPath, "..", "..");
903
805
  }
904
- const items = await import_fs_extra2.default.readdir(fullDirectoryPath);
905
- const staticMediaItems = [];
906
- for (const item of items) {
907
- const itemPath = import_node_path2.default.join(fullDirectoryPath, item);
908
- const stats = await import_fs_extra2.default.promises.lstat(itemPath);
909
- const staticMediaItem = {
910
- id: item,
911
- filename: item,
912
- type: stats.isDirectory() ? "dir" : "file",
913
- directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
914
- src: `/${import_node_path2.default.join(directoryPath, item)}`,
915
- thumbnails: {
916
- "75x75": `/${import_node_path2.default.join(directoryPath, item)}`,
917
- "400x400": `/${import_node_path2.default.join(directoryPath, item)}`,
918
- "1000x1000": `/${import_node_path2.default.join(directoryPath, item)}`
919
- }
920
- };
921
- if (stats.isDirectory()) {
922
- staticMediaItem.children = await listFilesRecursively({
923
- directoryPath: import_node_path2.default.join(directoryPath, item),
924
- config: config2,
925
- roothPath
926
- });
806
+ async getTinaFolderPath(rootPath) {
807
+ const tinaFolderPath = import_path.default.join(rootPath, TINA_FOLDER);
808
+ const tinaFolderExists = await import_fs_extra2.default.pathExists(tinaFolderPath);
809
+ if (tinaFolderExists) {
810
+ this.isUsingLegacyFolder = false;
811
+ return tinaFolderPath;
927
812
  }
928
- staticMediaItems.push(staticMediaItem);
813
+ const legacyFolderPath = import_path.default.join(rootPath, LEGACY_TINA_FOLDER);
814
+ const legacyFolderExists = await import_fs_extra2.default.pathExists(legacyFolderPath);
815
+ if (legacyFolderExists) {
816
+ this.isUsingLegacyFolder = true;
817
+ return legacyFolderPath;
818
+ }
819
+ throw new Error(
820
+ `Unable to find Tina folder, if you're working in folder outside of the Tina config be sure to specify --rootPath`
821
+ );
929
822
  }
930
- function chunkArrayIntoObject(array, chunkSize) {
931
- const result = {};
932
- for (let i = 0; i < array.length; i += chunkSize) {
933
- const chunkKey = `${i / chunkSize * 20}`;
934
- result[chunkKey] = array.slice(i, i + chunkSize);
823
+ getTinaGraphQLVersion() {
824
+ var _a, _b;
825
+ if (this.tinaGraphQLVersionFromCLI) {
826
+ return this.tinaGraphQLVersionFromCLI;
935
827
  }
936
- return result;
828
+ const generatedSchema = import_fs_extra2.default.readJSONSync(this.generatedSchemaJSONPath);
829
+ if (!generatedSchema || !(typeof (generatedSchema == null ? void 0 : generatedSchema.version) !== "undefined") || !(typeof ((_a = generatedSchema == null ? void 0 : generatedSchema.version) == null ? void 0 : _a.major) === "string") || !(typeof ((_b = generatedSchema == null ? void 0 : generatedSchema.version) == null ? void 0 : _b.minor) === "string")) {
830
+ throw new Error(
831
+ `Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
832
+ );
833
+ }
834
+ return `${generatedSchema.version.major}.${generatedSchema.version.minor}`;
937
835
  }
938
- return chunkArrayIntoObject(staticMediaItems, 20);
939
- }
940
- var createConfig = async ({
941
- configManager,
942
- database,
943
- apiURL,
944
- plugins = [],
945
- noWatch,
946
- rollupOptions
947
- }) => {
948
- var _a, _b, _c, _d, _e, _f, _g, _h;
949
- const publicEnv = {};
950
- Object.keys(process.env).forEach((key) => {
951
- if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
952
- try {
953
- if (typeof process.env[key] === "string") {
954
- publicEnv[key] = process.env[key];
955
- } else {
956
- publicEnv[key] = JSON.stringify(process.env[key]);
957
- }
958
- } catch (error) {
959
- console.warn(
960
- `Could not stringify public env process.env.${key} env variable`
961
- );
962
- console.warn(error);
963
- }
836
+ printGeneratedClientFilePath() {
837
+ if (this.isUsingTs()) {
838
+ return this.generatedClientTSFilePath.replace(`${this.rootPath}/`, "");
964
839
  }
965
- });
966
- const staticMediaPath = import_node_path2.default.join(
967
- configManager.generatedFolderPath,
968
- "static-media.json"
969
- );
970
- if ((_b = (_a = configManager.config.media) == null ? void 0 : _a.tina) == null ? void 0 : _b.static) {
971
- const staticMedia = await listFilesRecursively({
972
- directoryPath: ((_c = configManager.config.media.tina) == null ? void 0 : _c.mediaRoot) || "",
973
- config: configManager.config.media.tina,
974
- roothPath: configManager.rootPath
975
- });
976
- await import_fs_extra2.default.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
977
- } else {
978
- await import_fs_extra2.default.outputFile(staticMediaPath, `[]`);
840
+ return this.generatedClientJSFilePath.replace(`${this.rootPath}/`, "");
979
841
  }
980
- const alias = {
981
- TINA_IMPORT: configManager.prebuildFilePath,
982
- SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
983
- STATIC_MEDIA_IMPORT: staticMediaPath,
984
- crypto: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
985
- fs: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
986
- os: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts"),
987
- path: import_node_path2.default.join(configManager.spaRootPath, "src", "dummy-client.ts")
988
- };
989
- if (configManager.shouldSkipSDK()) {
990
- alias["CLIENT_IMPORT"] = import_node_path2.default.join(
991
- configManager.spaRootPath,
992
- "src",
993
- "dummy-client.ts"
842
+ printGeneratedTypesFilePath() {
843
+ return this.generatedTypesTSFilePath.replace(`${this.rootPath}/`, "");
844
+ }
845
+ printoutputHTMLFilePath() {
846
+ return this.outputHTMLFilePath.replace(`${this.publicFolderPath}/`, "");
847
+ }
848
+ printRelativePath(filename) {
849
+ if (filename) {
850
+ return filename.replace(/\\/g, "/").replace(`${this.rootPath}/`, "");
851
+ }
852
+ throw `No path provided to print`;
853
+ }
854
+ printPrebuildFilePath() {
855
+ return this.prebuildFilePath.replace(/\\/g, "/").replace(`${this.rootPath}/${this.tinaFolderPath}/`, "");
856
+ }
857
+ printContentRelativePath(filename) {
858
+ if (filename) {
859
+ return filename.replace(/\\/g, "/").replace(`${this.contentRootPath}/`, "");
860
+ }
861
+ throw `No path provided to print`;
862
+ }
863
+ async getPathWithExtension(filepath) {
864
+ const extensions = ["tsx", "ts", "jsx", "js"];
865
+ let result;
866
+ await Promise.all(
867
+ extensions.map(async (ext) => {
868
+ if (result) {
869
+ return;
870
+ }
871
+ const filepathWithExtension = `${filepath}.${ext}`;
872
+ const exists = import_fs_extra2.default.existsSync(filepathWithExtension);
873
+ if (exists) {
874
+ result = filepathWithExtension;
875
+ }
876
+ })
994
877
  );
995
- } else {
996
- alias["CLIENT_IMPORT"] = configManager.isUsingTs() ? configManager.generatedTypesTSFilePath : configManager.generatedTypesJSFilePath;
878
+ return result;
879
+ }
880
+ async loadDatabaseFile() {
881
+ const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
882
+ const outfile = import_path.default.join(tmpdir, "database.build.js");
883
+ await esbuild.build({
884
+ entryPoints: [this.selfHostedDatabaseFilePath],
885
+ bundle: true,
886
+ platform: "node",
887
+ outfile,
888
+ loader: loaders
889
+ });
890
+ const result = require(outfile);
891
+ import_fs_extra2.default.removeSync(outfile);
892
+ return result.default;
893
+ }
894
+ async loadConfigFile(generatedFolderPath, configFilePath) {
895
+ var _a, _b;
896
+ const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
897
+ const prebuild = import_path.default.join(this.generatedFolderPath, "config.prebuild.jsx");
898
+ const outfile = import_path.default.join(tmpdir, "config.build.jsx");
899
+ const outfile2 = import_path.default.join(tmpdir, "config.build.js");
900
+ const tempTSConfigFile = import_path.default.join(tmpdir, "tsconfig.json");
901
+ const viteConfig = await loadProjectConfig({
902
+ rootPath: this.rootPath,
903
+ viteConfigEnv: {
904
+ command: "build",
905
+ mode: "production"
906
+ }
907
+ });
908
+ import_fs_extra2.default.outputFileSync(tempTSConfigFile, "{}");
909
+ const result2 = await esbuild.build({
910
+ entryPoints: [configFilePath],
911
+ bundle: true,
912
+ target: ["es2020"],
913
+ platform: "browser",
914
+ format: "esm",
915
+ logLevel: "silent",
916
+ packages: "external",
917
+ ignoreAnnotations: true,
918
+ outfile: prebuild,
919
+ loader: loaders,
920
+ metafile: true,
921
+ alias: (_a = viteConfig.config.resolve) == null ? void 0 : _a.alias
922
+ });
923
+ const flattenedList = [];
924
+ Object.keys(result2.metafile.inputs).forEach((key) => {
925
+ if (key.includes("node_modules") || key.includes("__generated__")) {
926
+ return;
927
+ }
928
+ flattenedList.push(key);
929
+ });
930
+ await esbuild.build({
931
+ entryPoints: [configFilePath],
932
+ bundle: true,
933
+ target: ["es2020"],
934
+ logLevel: "silent",
935
+ platform: "node",
936
+ outfile,
937
+ loader: loaders,
938
+ alias: (_b = viteConfig.config.resolve) == null ? void 0 : _b.alias
939
+ });
940
+ await esbuild.build({
941
+ entryPoints: [outfile],
942
+ bundle: true,
943
+ logLevel: "silent",
944
+ platform: "node",
945
+ outfile: outfile2,
946
+ loader: loaders
947
+ });
948
+ let result;
949
+ try {
950
+ result = require(outfile2);
951
+ } catch (e) {
952
+ console.error("Unexpected error loading config");
953
+ console.error(e);
954
+ throw e;
955
+ }
956
+ import_fs_extra2.default.removeSync(outfile);
957
+ import_fs_extra2.default.removeSync(outfile2);
958
+ return {
959
+ config: result.default,
960
+ prebuildPath: prebuild,
961
+ watchList: flattenedList
962
+ };
997
963
  }
998
- let basePath;
999
- if (configManager.config.build.basePath) {
1000
- basePath = configManager.config.build.basePath;
964
+ };
965
+ var loaders = {
966
+ ".aac": "file",
967
+ ".css": "file",
968
+ ".eot": "file",
969
+ ".flac": "file",
970
+ ".gif": "file",
971
+ ".jpeg": "file",
972
+ ".jpg": "file",
973
+ ".json": "json",
974
+ ".mp3": "file",
975
+ ".mp4": "file",
976
+ ".ogg": "file",
977
+ ".otf": "file",
978
+ ".png": "file",
979
+ ".svg": "file",
980
+ ".ttf": "file",
981
+ ".wav": "file",
982
+ ".webm": "file",
983
+ ".webp": "file",
984
+ ".woff": "file",
985
+ ".woff2": "file",
986
+ ".js": "jsx",
987
+ ".jsx": "jsx",
988
+ ".tsx": "tsx"
989
+ };
990
+
991
+ // src/next/commands/dev-command/html.ts
992
+ var errorHTML = `<style type="text/css">
993
+ #no-assets-placeholder body {
994
+ font-family: sans-serif;
995
+ font-size: 16px;
996
+ line-height: 1.4;
997
+ color: #333;
998
+ background-color: #f5f5f5;
999
+ }
1000
+ #no-assets-placeholder {
1001
+ max-width: 600px;
1002
+ margin: 0 auto;
1003
+ padding: 40px;
1004
+ text-align: center;
1005
+ background-color: #fff;
1006
+ box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
1007
+ }
1008
+ #no-assets-placeholder h1 {
1009
+ font-size: 24px;
1010
+ margin-bottom: 20px;
1011
+ }
1012
+ #no-assets-placeholder p {
1013
+ margin-bottom: 10px;
1014
+ }
1015
+ #no-assets-placeholder a {
1016
+ color: #0077cc;
1017
+ text-decoration: none;
1018
+ }
1019
+ #no-assets-placeholder a:hover {
1020
+ text-decoration: underline;
1021
+ }
1022
+ </style>
1023
+ <div id="no-assets-placeholder">
1024
+ <h1>Failed loading TinaCMS assets</h1>
1025
+ <p>
1026
+ Your TinaCMS configuration may be misconfigured, and we could not load
1027
+ the assets for this page.
1028
+ </p>
1029
+ <p>
1030
+ Please visit <a href="https://tina.io/docs/tina-cloud/faq/#how-do-i-resolve-failed-loading-tinacms-assets-error">this doc</a> for help.
1031
+ </p>
1032
+ </div>
1033
+ </div>`.trim().replace(/[\r\n\s]+/g, " ");
1034
+ var devHTML = (port) => `<!DOCTYPE html>
1035
+ <html lang="en">
1036
+ <head>
1037
+ <meta charset="UTF-8" />
1038
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
1039
+ <title>TinaCMS</title>
1040
+ </head>
1041
+
1042
+ <!-- if development -->
1043
+ <script type="module">
1044
+ import RefreshRuntime from 'http://localhost:${port}/@react-refresh'
1045
+ RefreshRuntime.injectIntoGlobalHook(window)
1046
+ window.$RefreshReg$ = () => {}
1047
+ window.$RefreshSig$ = () => (type) => type
1048
+ window.__vite_plugin_react_preamble_installed__ = true
1049
+ <\/script>
1050
+ <script type="module" src="http://localhost:${port}/@vite/client"><\/script>
1051
+ <script>
1052
+ function handleLoadError() {
1053
+ // Assets have failed to load
1054
+ document.getElementById('root').innerHTML = '${errorHTML}';
1001
1055
  }
1002
- const config2 = {
1003
- root: configManager.spaRootPath,
1004
- base: `/${basePath ? `${(0, import_normalize_path2.default)(basePath)}/` : ""}${(0, import_normalize_path2.default)(
1005
- configManager.config.build.outputFolder
1006
- )}/`,
1007
- appType: "spa",
1008
- resolve: {
1009
- alias,
1010
- dedupe: ["graphql", "tinacms", "react", "react-dom", "react-router-dom"]
1011
- },
1012
- define: {
1013
- "process.env": `new Object(${JSON.stringify(publicEnv)})`,
1014
- "process.platform": `"${process.platform}"`,
1015
- __API_URL__: `"${apiURL}"`,
1016
- __BASE_PATH__: `"${((_e = (_d = configManager.config) == null ? void 0 : _d.build) == null ? void 0 : _e.basePath) || ""}"`,
1017
- __TINA_GRAPHQL_VERSION__: `"${configManager.getTinaGraphQLVersion()}"`
1018
- },
1019
- logLevel: "error",
1020
- optimizeDeps: {
1021
- force: true,
1022
- include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
1023
- },
1024
- server: {
1025
- host: (_h = (_g = (_f = configManager.config) == null ? void 0 : _f.build) == null ? void 0 : _g.host) != null ? _h : false,
1026
- watch: noWatch ? {
1027
- ignored: ["**/*"]
1028
- } : {
1029
- ignored: [
1030
- `${configManager.tinaFolderPath}/**/!(config.prebuild.jsx|_graphql.json)`
1031
- ]
1032
- },
1033
- fs: {
1034
- strict: false
1035
- }
1036
- },
1037
- build: {
1038
- sourcemap: false,
1039
- outDir: configManager.outputFolderPath,
1040
- emptyOutDir: true,
1041
- rollupOptions
1042
- },
1043
- plugins: [
1044
- (0, import_plugin_react.default)({
1045
- babel: {
1046
- compact: true
1047
- }
1048
- }),
1049
- (0, import_vite.splitVendorChunkPlugin)(),
1050
- tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
1051
- ...plugins
1052
- ]
1053
- };
1054
- return config2;
1056
+ <\/script>
1057
+ <script
1058
+ type="module"
1059
+ src="http://localhost:${port}/src/main.tsx"
1060
+ onerror="handleLoadError()"
1061
+ ><\/script>
1062
+ <body class="tina-tailwind">
1063
+ <div id="root"></div>
1064
+ </body>
1065
+ </html>`;
1066
+
1067
+ // src/utils/theme.ts
1068
+ var import_chalk3 = __toESM(require("chalk"));
1069
+ var successText = import_chalk3.default.bold.green;
1070
+ var focusText = import_chalk3.default.bold;
1071
+ var dangerText = import_chalk3.default.bold.red;
1072
+ var neutralText = import_chalk3.default.bold.cyan;
1073
+ var linkText = import_chalk3.default.bold.cyan;
1074
+ var labelText = import_chalk3.default.bold;
1075
+ var cmdText = import_chalk3.default.inverse;
1076
+ var indentedCmd = (str) => {
1077
+ return ` \u2503 ` + str;
1078
+ };
1079
+ var indentText = (str) => {
1080
+ return String(str).split("\n").map((line) => ` ${line}`).join("\n");
1055
1081
  };
1082
+ var logText = import_chalk3.default.italic.gray;
1083
+ var warnText = import_chalk3.default.yellowBright.bgBlack;
1084
+ var titleText = import_chalk3.default.bgHex("d2f1f8").hex("ec4816");
1085
+ var CONFIRMATION_TEXT = import_chalk3.default.dim("enter to confirm");
1086
+
1087
+ // src/next/commands/dev-command/server/index.ts
1088
+ var import_vite4 = require("vite");
1056
1089
 
1057
1090
  // src/next/vite/plugins.ts
1058
1091
  var import_pluginutils = require("@rollup/pluginutils");
1059
1092
  var import_fs = __toESM(require("fs"));
1060
- var import_vite2 = require("vite");
1093
+ var import_vite3 = require("vite");
1061
1094
  var import_esbuild = require("esbuild");
1062
1095
  var import_path3 = __toESM(require("path"));
1063
1096
  var import_body_parser = __toESM(require("body-parser"));
@@ -1380,7 +1413,7 @@ function viteTransformExtension({
1380
1413
  previousExport: exportAsDefault ? null : code
1381
1414
  }
1382
1415
  });
1383
- const res = await (0, import_vite2.transformWithEsbuild)(componentCode, id, {
1416
+ const res = await (0, import_vite3.transformWithEsbuild)(componentCode, id, {
1384
1417
  loader: "jsx",
1385
1418
  ...esbuildOptions
1386
1419
  });
@@ -1400,7 +1433,7 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
1400
1433
  devServerEndPointsPlugin({ apiURL, configManager, database, searchIndex }),
1401
1434
  viteTransformExtension()
1402
1435
  ];
1403
- return (0, import_vite3.createServer)(
1436
+ return (0, import_vite4.createServer)(
1404
1437
  await createConfig({
1405
1438
  configManager,
1406
1439
  database,
@@ -1415,6 +1448,10 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
1415
1448
  }
1416
1449
  warn(warning);
1417
1450
  }
1451
+ },
1452
+ viteConfigEnv: {
1453
+ command: "serve",
1454
+ mode: "development"
1418
1455
  }
1419
1456
  })
1420
1457
  );
@@ -2209,7 +2246,7 @@ var BaseCommand = class extends import_clipanion.Command {
2209
2246
  pathFilter
2210
2247
  });
2211
2248
  const tinaPathUpdates = modified.filter(
2212
- (path13) => path13.startsWith(".tina/__generated__/_schema.json") || path13.startsWith("tina/tina-lock.json")
2249
+ (path14) => path14.startsWith(".tina/__generated__/_schema.json") || path14.startsWith("tina/tina-lock.json")
2213
2250
  );
2214
2251
  if (tinaPathUpdates.length > 0) {
2215
2252
  res = await database.indexContent({
@@ -2537,10 +2574,12 @@ DevCommand.usage = import_clipanion2.Command.Usage({
2537
2574
  var import_clipanion3 = require("clipanion");
2538
2575
  var import_progress2 = __toESM(require("progress"));
2539
2576
  var import_fs_extra7 = __toESM(require("fs-extra"));
2577
+ var import_crypto = __toESM(require("crypto"));
2578
+ var import_path6 = __toESM(require("path"));
2540
2579
  var import_graphql11 = require("@tinacms/graphql");
2541
2580
 
2542
2581
  // src/next/commands/build-command/server.ts
2543
- var import_vite5 = require("vite");
2582
+ var import_vite6 = require("vite");
2544
2583
  var buildProductionSpa = async (configManager, database, apiURL) => {
2545
2584
  const publicEnv = {};
2546
2585
  Object.keys(process.env).forEach((key) => {
@@ -2572,9 +2611,13 @@ var buildProductionSpa = async (configManager, database, apiURL) => {
2572
2611
  }
2573
2612
  warn(warning);
2574
2613
  }
2614
+ },
2615
+ viteConfigEnv: {
2616
+ command: "build",
2617
+ mode: "production"
2575
2618
  }
2576
2619
  });
2577
- return (0, import_vite5.build)(config2);
2620
+ return (0, import_vite6.build)(config2);
2578
2621
  };
2579
2622
 
2580
2623
  // src/next/commands/build-command/index.ts
@@ -2839,6 +2882,13 @@ ${dangerText(e.message)}
2839
2882
  database,
2840
2883
  codegen2.productionUrl
2841
2884
  );
2885
+ await this.checkTinaSchema(
2886
+ configManager,
2887
+ database,
2888
+ codegen2.productionUrl,
2889
+ this.previewName,
2890
+ this.verbose
2891
+ );
2842
2892
  }
2843
2893
  await buildProductionSpa(configManager, database, codegen2.productionUrl);
2844
2894
  await import_fs_extra7.default.outputFile(
@@ -3148,6 +3198,63 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3148
3198
  }
3149
3199
  }
3150
3200
  }
3201
+ async checkTinaSchema(configManager, database, apiURL, previewName, verbose) {
3202
+ const bar2 = new import_progress2.default(
3203
+ "Checking local Tina Schema matches server. :prog",
3204
+ 1
3205
+ );
3206
+ const { config: config2 } = configManager;
3207
+ const token = config2.token;
3208
+ const { clientId, branch, isLocalClient, host } = (0, import_schema_tools2.parseURL)(apiURL);
3209
+ if (isLocalClient || !host || !clientId || !branch) {
3210
+ if (verbose) {
3211
+ logger.info(logText("Not using Tina Cloud, skipping Tina Schema check"));
3212
+ }
3213
+ return;
3214
+ }
3215
+ const { tinaSchema: remoteTinaSchemaSha } = await fetchSchemaSha({
3216
+ url: `https://${host}/db/${clientId}/${previewName || branch}/schemaSha`,
3217
+ token
3218
+ });
3219
+ if (!remoteTinaSchemaSha) {
3220
+ bar2.tick({
3221
+ prog: "\u274C"
3222
+ });
3223
+ let errorMessage = `The remote Tina schema does not exist. Check indexing for this branch.`;
3224
+ if (config2 == null ? void 0 : config2.branch) {
3225
+ errorMessage += `
3226
+
3227
+ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3228
+ }
3229
+ throw new Error(errorMessage);
3230
+ }
3231
+ if (!database.bridge) {
3232
+ throw new Error(`No bridge configured`);
3233
+ }
3234
+ const localTinaSchema = JSON.parse(
3235
+ await database.bridge.get(
3236
+ import_path6.default.join(database.tinaDirectory, "__generated__", "_schema.json")
3237
+ )
3238
+ );
3239
+ localTinaSchema.version = void 0;
3240
+ const localTinaSchemaSha = import_crypto.default.createHash("sha256").update(JSON.stringify(localTinaSchema)).digest("hex");
3241
+ if (localTinaSchemaSha === remoteTinaSchemaSha) {
3242
+ bar2.tick({
3243
+ prog: "\u2705"
3244
+ });
3245
+ } else {
3246
+ bar2.tick({
3247
+ prog: "\u274C"
3248
+ });
3249
+ let errorMessage = `The local Tina schema doesn't match the remote Tina schema. Please push up your changes to GitHub to update your remote tina schema.`;
3250
+ if (config2 == null ? void 0 : config2.branch) {
3251
+ errorMessage += `
3252
+
3253
+ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3254
+ }
3255
+ throw new Error(errorMessage);
3256
+ }
3257
+ }
3151
3258
  };
3152
3259
  BuildCommand.paths = [["build"]];
3153
3260
  BuildCommand.usage = import_clipanion3.Command.Usage({
@@ -3216,6 +3323,21 @@ var fetchRemoteGraphqlSchema = async ({
3216
3323
  const data = await res.json();
3217
3324
  return data == null ? void 0 : data.data;
3218
3325
  };
3326
+ var fetchSchemaSha = async ({
3327
+ url,
3328
+ token
3329
+ }) => {
3330
+ const headers = new Headers();
3331
+ if (token) {
3332
+ headers.append("X-API-KEY", token);
3333
+ }
3334
+ const res = await fetch(url, {
3335
+ method: "GET",
3336
+ headers,
3337
+ cache: "no-cache"
3338
+ });
3339
+ return res.json();
3340
+ };
3219
3341
 
3220
3342
  // src/next/commands/audit-command/index.ts
3221
3343
  var import_clipanion4 = require("clipanion");
@@ -3469,25 +3591,25 @@ var import_clipanion6 = require("clipanion");
3469
3591
 
3470
3592
  // src/cmds/init/detectEnvironment.ts
3471
3593
  var import_fs_extra8 = __toESM(require("fs-extra"));
3472
- var import_path6 = __toESM(require("path"));
3594
+ var import_path7 = __toESM(require("path"));
3473
3595
  var checkGitignoreForItem = async ({
3474
3596
  baseDir,
3475
3597
  line
3476
3598
  }) => {
3477
- const gitignoreContent = import_fs_extra8.default.readFileSync(import_path6.default.join(baseDir, ".gitignore")).toString();
3599
+ const gitignoreContent = import_fs_extra8.default.readFileSync(import_path7.default.join(baseDir, ".gitignore")).toString();
3478
3600
  return gitignoreContent.split("\n").some((item) => item === line);
3479
3601
  };
3480
3602
  var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
3481
3603
  const result = {
3482
- fullPathTS: import_path6.default.join(
3604
+ fullPathTS: import_path7.default.join(
3483
3605
  parentPath,
3484
3606
  `${name2}.${(opts == null ? void 0 : opts.typescriptSuffix) || (opts == null ? void 0 : opts.extensionOverride) || "ts"}`
3485
3607
  ),
3486
- fullPathJS: import_path6.default.join(
3608
+ fullPathJS: import_path7.default.join(
3487
3609
  parentPath,
3488
3610
  `${name2}.${(opts == null ? void 0 : opts.extensionOverride) || "js"}`
3489
3611
  ),
3490
- fullPathOverride: (opts == null ? void 0 : opts.extensionOverride) ? import_path6.default.join(parentPath, `${name2}.${opts == null ? void 0 : opts.extensionOverride}`) : "",
3612
+ fullPathOverride: (opts == null ? void 0 : opts.extensionOverride) ? import_path7.default.join(parentPath, `${name2}.${opts == null ? void 0 : opts.extensionOverride}`) : "",
3491
3613
  generatedFileType,
3492
3614
  name: name2,
3493
3615
  parentPath,
@@ -3517,16 +3639,16 @@ var detectEnvironment = async ({
3517
3639
  }) => {
3518
3640
  var _a;
3519
3641
  const hasForestryConfig = await import_fs_extra8.default.pathExists(
3520
- import_path6.default.join(pathToForestryConfig, ".forestry", "settings.yml")
3642
+ import_path7.default.join(pathToForestryConfig, ".forestry", "settings.yml")
3521
3643
  );
3522
- const sampleContentPath = import_path6.default.join(
3644
+ const sampleContentPath = import_path7.default.join(
3523
3645
  baseDir,
3524
3646
  "content",
3525
3647
  "posts",
3526
3648
  "hello-world.md"
3527
3649
  );
3528
- const usingSrc = import_fs_extra8.default.pathExistsSync(import_path6.default.join(baseDir, "src")) && (import_fs_extra8.default.pathExistsSync(import_path6.default.join(baseDir, "src", "app")) || import_fs_extra8.default.pathExistsSync(import_path6.default.join(baseDir, "src", "pages")));
3529
- const tinaFolder = import_path6.default.join(baseDir, "tina");
3650
+ 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")));
3651
+ const tinaFolder = import_path7.default.join(baseDir, "tina");
3530
3652
  const tinaConfigExists = Boolean(
3531
3653
  await import_fs_extra8.default.pathExists(tinaFolder) && (await import_fs_extra8.default.readdir(tinaFolder)).find((x) => x.includes("config"))
3532
3654
  );
@@ -3540,12 +3662,12 @@ var detectEnvironment = async ({
3540
3662
  "next-api-handler": await makeGeneratedFile(
3541
3663
  "[...routes]",
3542
3664
  "next-api-handler",
3543
- import_path6.default.join(...pagesDir, "api", "tina")
3665
+ import_path7.default.join(...pagesDir, "api", "tina")
3544
3666
  ),
3545
3667
  "reactive-example": await makeGeneratedFile(
3546
3668
  "[filename]",
3547
3669
  "reactive-example",
3548
- import_path6.default.join(...pagesDir, "demo", "blog"),
3670
+ import_path7.default.join(...pagesDir, "demo", "blog"),
3549
3671
  {
3550
3672
  typescriptSuffix: "tsx"
3551
3673
  }
@@ -3553,13 +3675,13 @@ var detectEnvironment = async ({
3553
3675
  "users-json": await makeGeneratedFile(
3554
3676
  "index",
3555
3677
  "users-json",
3556
- import_path6.default.join(baseDir, "content", "users"),
3678
+ import_path7.default.join(baseDir, "content", "users"),
3557
3679
  { extensionOverride: "json" }
3558
3680
  ),
3559
3681
  "sample-content": await makeGeneratedFile(
3560
3682
  "hello-world",
3561
3683
  "sample-content",
3562
- import_path6.default.join(baseDir, "content", "posts"),
3684
+ import_path7.default.join(baseDir, "content", "posts"),
3563
3685
  { extensionOverride: "md" }
3564
3686
  )
3565
3687
  };
@@ -3585,13 +3707,13 @@ var detectEnvironment = async ({
3585
3707
  );
3586
3708
  }
3587
3709
  }
3588
- const hasGitIgnore = await import_fs_extra8.default.pathExists(import_path6.default.join(".gitignore"));
3710
+ const hasGitIgnore = await import_fs_extra8.default.pathExists(import_path7.default.join(".gitignore"));
3589
3711
  const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
3590
3712
  const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
3591
3713
  const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
3592
3714
  let frontMatterFormat;
3593
3715
  if (hasForestryConfig) {
3594
- const hugoConfigPath = import_path6.default.join(rootPath, "config.toml");
3716
+ const hugoConfigPath = import_path7.default.join(rootPath, "config.toml");
3595
3717
  if (await import_fs_extra8.default.pathExists(hugoConfigPath)) {
3596
3718
  const hugoConfig = await import_fs_extra8.default.readFile(hugoConfigPath, "utf8");
3597
3719
  const metaDataFormat = (_a = hugoConfig.match(/metaDataFormat = "(.*)"/)) == null ? void 0 : _a[1];
@@ -4199,18 +4321,18 @@ var CLICommand = class {
4199
4321
  };
4200
4322
 
4201
4323
  // src/cmds/init/apply.ts
4202
- var import_path10 = __toESM(require("path"));
4324
+ var import_path11 = __toESM(require("path"));
4203
4325
 
4204
4326
  // src/cmds/forestry-migrate/index.ts
4205
4327
  var import_fs_extra10 = __toESM(require("fs-extra"));
4206
- var import_path8 = __toESM(require("path"));
4328
+ var import_path9 = __toESM(require("path"));
4207
4329
  var import_js_yaml2 = __toESM(require("js-yaml"));
4208
4330
  var import_minimatch = __toESM(require("minimatch"));
4209
4331
  var import_graphql16 = require("@tinacms/graphql");
4210
4332
 
4211
4333
  // src/cmds/forestry-migrate/util/index.ts
4212
4334
  var import_fs_extra9 = __toESM(require("fs-extra"));
4213
- var import_path7 = __toESM(require("path"));
4335
+ var import_path8 = __toESM(require("path"));
4214
4336
  var import_js_yaml = __toESM(require("js-yaml"));
4215
4337
  var import_zod = __toESM(require("zod"));
4216
4338
 
@@ -4621,7 +4743,7 @@ var transformForestryFieldsToTinaFields = ({
4621
4743
  return tinaFields;
4622
4744
  };
4623
4745
  var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
4624
- const templatePath = import_path7.default.join(
4746
+ const templatePath = import_path8.default.join(
4625
4747
  pathToForestryConfig,
4626
4748
  ".forestry",
4627
4749
  "front_matter",
@@ -4696,8 +4818,8 @@ var generateAllTemplates = async ({
4696
4818
  pathToForestryConfig
4697
4819
  }) => {
4698
4820
  const allTemplates = (await import_fs_extra10.default.readdir(
4699
- import_path8.default.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
4700
- )).map((tem) => import_path8.default.basename(tem, ".yml"));
4821
+ import_path9.default.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
4822
+ )).map((tem) => import_path9.default.basename(tem, ".yml"));
4701
4823
  const templateMap = /* @__PURE__ */ new Map();
4702
4824
  const proms = allTemplates.map(async (tem) => {
4703
4825
  try {
@@ -4839,9 +4961,9 @@ var generateCollectionFromForestrySection = (args) => {
4839
4961
  return c;
4840
4962
  } else if (section.type === "document") {
4841
4963
  const filePath = section.path;
4842
- const extname = import_path8.default.extname(filePath);
4843
- const fileName = import_path8.default.basename(filePath, extname);
4844
- const dir = import_path8.default.dirname(filePath);
4964
+ const extname = import_path9.default.extname(filePath);
4965
+ const fileName = import_path9.default.basename(filePath, extname);
4966
+ const dir = import_path9.default.dirname(filePath);
4845
4967
  const ext = checkExt(extname);
4846
4968
  if (ext) {
4847
4969
  const fields = [];
@@ -4904,7 +5026,7 @@ var generateCollections = async ({
4904
5026
  usingTypescript
4905
5027
  });
4906
5028
  const forestryConfig = await import_fs_extra10.default.readFile(
4907
- import_path8.default.join(pathToForestryConfig, ".forestry", "settings.yml")
5029
+ import_path9.default.join(pathToForestryConfig, ".forestry", "settings.yml")
4908
5030
  );
4909
5031
  rewriteTemplateKeysInDocs({
4910
5032
  templateMap,
@@ -4935,11 +5057,11 @@ var rewriteTemplateKeysInDocs = (args) => {
4935
5057
  const { templateObj } = templateMap.get(templateKey);
4936
5058
  (_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
4937
5059
  try {
4938
- const filePath = import_path8.default.join(page);
5060
+ const filePath = import_path9.default.join(page);
4939
5061
  if (import_fs_extra10.default.lstatSync(filePath).isDirectory()) {
4940
5062
  return;
4941
5063
  }
4942
- const extname = import_path8.default.extname(filePath);
5064
+ const extname = import_path9.default.extname(filePath);
4943
5065
  const fileContent = import_fs_extra10.default.readFileSync(filePath).toString();
4944
5066
  const content = (0, import_graphql16.parseFile)(
4945
5067
  fileContent,
@@ -4971,7 +5093,7 @@ var import_fs_extra13 = __toESM(require("fs-extra"));
4971
5093
  // src/next/commands/codemod-command/index.ts
4972
5094
  var import_clipanion5 = require("clipanion");
4973
5095
  var import_fs_extra11 = __toESM(require("fs-extra"));
4974
- var import_path9 = __toESM(require("path"));
5096
+ var import_path10 = __toESM(require("path"));
4975
5097
  var CodemodCommand = class extends import_clipanion5.Command {
4976
5098
  constructor() {
4977
5099
  super(...arguments);
@@ -5015,7 +5137,7 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
5015
5137
  logger.error(e.message);
5016
5138
  process.exit(1);
5017
5139
  }
5018
- const tinaDestination = import_path9.default.join(configManager.rootPath, "tina");
5140
+ const tinaDestination = import_path10.default.join(configManager.rootPath, "tina");
5019
5141
  if (await import_fs_extra11.default.existsSync(tinaDestination)) {
5020
5142
  logger.info(
5021
5143
  `Folder already exists at ${tinaDestination}. Either delete this folder to complete the codemod, or ensure you have properly copied your config from the ".tina" folder.`
@@ -5030,7 +5152,7 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
5030
5152
  };
5031
5153
  var writeGitignore = async (rootPath) => {
5032
5154
  await import_fs_extra11.default.outputFileSync(
5033
- import_path9.default.join(rootPath, "tina", ".gitignore"),
5155
+ import_path10.default.join(rootPath, "tina", ".gitignore"),
5034
5156
  "__generated__"
5035
5157
  );
5036
5158
  };
@@ -5868,8 +5990,8 @@ async function apply({
5868
5990
  await addConfigFile({
5869
5991
  configArgs: {
5870
5992
  config: config2,
5871
- publicFolder: import_path10.default.join(
5872
- import_path10.default.relative(process.cwd(), pathToForestryConfig),
5993
+ publicFolder: import_path11.default.join(
5994
+ import_path11.default.relative(process.cwd(), pathToForestryConfig),
5873
5995
  config2.publicFolder
5874
5996
  ),
5875
5997
  collections,
@@ -5936,18 +6058,18 @@ var createPackageJSON = async () => {
5936
6058
  };
5937
6059
  var createGitignore = async ({ baseDir }) => {
5938
6060
  logger.info(logText("No .gitignore found, creating one"));
5939
- import_fs_extra13.default.outputFileSync(import_path10.default.join(baseDir, ".gitignore"), "node_modules");
6061
+ import_fs_extra13.default.outputFileSync(import_path11.default.join(baseDir, ".gitignore"), "node_modules");
5940
6062
  };
5941
6063
  var updateGitIgnore = async ({
5942
6064
  baseDir,
5943
6065
  items
5944
6066
  }) => {
5945
6067
  logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
5946
- const gitignoreContent = import_fs_extra13.default.readFileSync(import_path10.default.join(baseDir, ".gitignore")).toString();
6068
+ const gitignoreContent = import_fs_extra13.default.readFileSync(import_path11.default.join(baseDir, ".gitignore")).toString();
5947
6069
  const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
5948
6070
  "\n"
5949
6071
  );
5950
- await import_fs_extra13.default.writeFile(import_path10.default.join(baseDir, ".gitignore"), newGitignoreContent);
6072
+ await import_fs_extra13.default.writeFile(import_path11.default.join(baseDir, ".gitignore"), newGitignoreContent);
5951
6073
  };
5952
6074
  var addDependencies = async (config2, env, params) => {
5953
6075
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
@@ -6017,22 +6139,22 @@ var writeGeneratedFile = async ({
6017
6139
  content,
6018
6140
  typescript
6019
6141
  }) => {
6020
- const { exists, path: path13, parentPath } = generatedFile.resolve(typescript);
6142
+ const { exists, path: path14, parentPath } = generatedFile.resolve(typescript);
6021
6143
  if (exists) {
6022
6144
  if (overwrite) {
6023
- logger.info(`Overwriting file at ${path13}... \u2705`);
6024
- import_fs_extra13.default.outputFileSync(path13, content);
6145
+ logger.info(`Overwriting file at ${path14}... \u2705`);
6146
+ import_fs_extra13.default.outputFileSync(path14, content);
6025
6147
  } else {
6026
- logger.info(`Not overwriting file at ${path13}.`);
6148
+ logger.info(`Not overwriting file at ${path14}.`);
6027
6149
  logger.info(
6028
- logText(`Please add the following to ${path13}:
6150
+ logText(`Please add the following to ${path14}:
6029
6151
  ${indentText(content)}}`)
6030
6152
  );
6031
6153
  }
6032
6154
  } else {
6033
- logger.info(`Adding file at ${path13}... \u2705`);
6155
+ logger.info(`Adding file at ${path14}... \u2705`);
6034
6156
  await import_fs_extra13.default.ensureDir(parentPath);
6035
- import_fs_extra13.default.outputFileSync(path13, content);
6157
+ import_fs_extra13.default.outputFileSync(path14, content);
6036
6158
  }
6037
6159
  };
6038
6160
  var addConfigFile = async ({
@@ -6115,7 +6237,7 @@ var addContentFile = async ({
6115
6237
  return () => ({
6116
6238
  exists: env.sampleContentExists,
6117
6239
  path: env.sampleContentPath,
6118
- parentPath: import_path10.default.dirname(env.sampleContentPath)
6240
+ parentPath: import_path11.default.dirname(env.sampleContentPath)
6119
6241
  });
6120
6242
  }
6121
6243
  },
@@ -6138,7 +6260,7 @@ ${titleText(" TinaCMS ")} backend initialized!`));
6138
6260
  return `${x.key}=${x.value || "***"}`;
6139
6261
  }).join("\n") + `
6140
6262
  TINA_PUBLIC_IS_LOCAL=true`;
6141
- const envFile = import_path10.default.join(process.cwd(), ".env");
6263
+ const envFile = import_path11.default.join(process.cwd(), ".env");
6142
6264
  if (!import_fs_extra13.default.existsSync(envFile)) {
6143
6265
  logger.info(`Adding .env file to your project... \u2705`);
6144
6266
  import_fs_extra13.default.writeFileSync(envFile, envFileText);
@@ -6202,7 +6324,7 @@ var addReactiveFile = {
6202
6324
  dataLayer
6203
6325
  }) => {
6204
6326
  var _a, _b;
6205
- const packageJsonPath = import_path10.default.join(baseDir, "package.json");
6327
+ const packageJsonPath = import_path11.default.join(baseDir, "package.json");
6206
6328
  await writeGeneratedFile({
6207
6329
  generatedFile,
6208
6330
  typescript: config2.typescript,