@tinacms/cli 0.60.12 → 0.60.15

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
@@ -79,7 +79,7 @@ var init_server = __esm({
79
79
  # We've got a simple query set up for you to get started
80
80
  # but there's plenty more for you to explore on your own!
81
81
  query MyQuery {
82
- getCollections {
82
+ collections {
83
83
  documents {
84
84
  id
85
85
  sys {
@@ -114,7 +114,11 @@ var commander = __toModule(require("commander"));
114
114
 
115
115
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/package.json
116
116
  var name = "@tinacms/cli";
117
- var version = "0.60.12";
117
+ var version = "0.60.15";
118
+
119
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
120
+ var import_graphql = __toModule(require("@tinacms/graphql"));
121
+ var import_datalayer = __toModule(require("@tinacms/datalayer"));
118
122
 
119
123
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/theme.ts
120
124
  var import_chalk = __toModule(require("chalk"));
@@ -127,29 +131,6 @@ var logText = import_chalk.default.italic.gray;
127
131
  var warnText = import_chalk.default.yellowBright.bgBlack;
128
132
  var CONFIRMATION_TEXT = import_chalk.default.dim("enter to confirm");
129
133
 
130
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
131
- var chain = async (cmds, options) => {
132
- const ctx = {};
133
- const next = async (middlewareIndex) => {
134
- if (middlewareIndex >= cmds.length) {
135
- process.exit(0);
136
- }
137
- try {
138
- await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
139
- } catch (err) {
140
- console.error(` ${dangerText(err)}`);
141
- process.exit(1);
142
- }
143
- };
144
- if (cmds.length > 0) {
145
- await next(0);
146
- }
147
- };
148
-
149
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
150
- var import_graphql = __toModule(require("@tinacms/graphql"));
151
- var import_datalayer = __toModule(require("@tinacms/datalayer"));
152
-
153
134
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/logger/index.ts
154
135
  var import_log4js = __toModule(require("log4js"));
155
136
  var logger = import_log4js.default.getLogger();
@@ -173,11 +154,12 @@ async function attachSchema(ctx, next, options) {
173
154
  next();
174
155
  }
175
156
 
157
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
158
+ var import_graphql6 = __toModule(require("graphql"));
159
+ var import_fs_extra = __toModule(require("fs-extra"));
160
+
176
161
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
177
162
  var import_graphql5 = __toModule(require("graphql"));
178
- var import_core = __toModule(require("@graphql-codegen/core"));
179
- var import_typescript = __toModule(require("@graphql-codegen/typescript"));
180
- var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
181
163
 
182
164
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/plugin.ts
183
165
  var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
@@ -214,6 +196,13 @@ var AddGeneratedClient = {
214
196
  plugin: AddGeneratedClientFunc
215
197
  };
216
198
 
199
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
200
+ var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
201
+ var import_core = __toModule(require("@graphql-codegen/core"));
202
+ var import_load = __toModule(require("@graphql-tools/load"));
203
+ var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
204
+ var import_typescript = __toModule(require("@graphql-codegen/typescript"));
205
+
217
206
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
218
207
  var import_graphql3 = __toModule(require("graphql"));
219
208
  var import_graphql4 = __toModule(require("graphql"));
@@ -296,10 +285,12 @@ var plugin = (schema, documents, config) => {
296
285
  };
297
286
 
298
287
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
299
- var import_load = __toModule(require("@graphql-tools/load"));
300
- var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
301
- var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = { noSDK: false }) => {
302
- logger.info("Generating types...");
288
+ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = {
289
+ noSDK: false,
290
+ verbose: false
291
+ }) => {
292
+ if (options.verbose)
293
+ logger.info("Generating types...");
303
294
  try {
304
295
  let docs = [];
305
296
  let fragDocs = [];
@@ -364,8 +355,6 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
364
355
  };
365
356
 
366
357
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
367
- var import_graphql6 = __toModule(require("graphql"));
368
- var import_fs_extra = __toModule(require("fs-extra"));
369
358
  async function genTypes({ schema }, next, options) {
370
359
  const typesPath = process.cwd() + "/.tina/__generated__/types.ts";
371
360
  const fragPath = process.cwd() + "/.tina/__generated__/*.{graphql,gql}";
@@ -375,7 +364,7 @@ async function genTypes({ schema }, next, options) {
375
364
  // DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
376
365
  ${typescriptTypes}
377
366
  `);
378
- logger.info(`Typescript types => ${logText(typesPath)}`);
367
+ logger.info(` Typescript types => ${logText(typesPath)}`);
379
368
  const schemaString = await (0, import_graphql6.printSchema)(schema);
380
369
  const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
381
370
  await import_fs_extra.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
@@ -385,478 +374,261 @@ schema {
385
374
  mutation: Mutation
386
375
  }
387
376
  `);
388
- logger.info(`GraphQL types ====> ${logText(schemaPath)}`);
377
+ logger.info(` GraphQL types ====> ${logText(schemaPath)}
378
+ `);
389
379
  next();
390
380
  }
391
381
 
392
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
393
- var import_child_process = __toModule(require("child_process"));
394
- var import_path4 = __toModule(require("path"));
395
- var import_graphql7 = __toModule(require("@tinacms/graphql"));
382
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
383
+ var import_graphql9 = __toModule(require("@tinacms/graphql"));
396
384
  var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
397
385
 
398
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
399
- var import_path3 = __toModule(require("path"));
400
- var import_fs_extra3 = __toModule(require("fs-extra"));
401
- var import_esbuild = __toModule(require("esbuild"));
402
-
403
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
404
- var defaultSchema = (sep) => `
405
- import { defineSchema, defineConfig } from "tinacms";
406
-
407
- export default defineSchema({
408
- collections: [
409
- {
410
- label: "Blog Posts",
411
- name: "posts",
412
- path: "content${sep}posts",
413
- fields: [
414
- {
415
- type: "string",
416
- label: "Title",
417
- name: "title",
418
- },
419
- {
420
- type: "rich-text",
421
- label: "Blog Post Body",
422
- name: "body",
423
- isBody: true,
424
- templates: [
425
- {
426
- name: "PageSection",
427
- label: "Page Section",
428
- fields: [
429
- {
430
- type: "string",
431
- name: "heading",
432
- label: "Heading",
433
- },
434
- {
435
- type: "string",
436
- name: "content",
437
- label: "Content",
438
- ui: {
439
- component: "textarea"
386
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/audit.ts
387
+ var import_graphql7 = __toModule(require("@tinacms/graphql"));
388
+ var import_path2 = __toModule(require("path"));
389
+ var import_graphql8 = __toModule(require("@tinacms/graphql"));
390
+ var import_chalk2 = __toModule(require("chalk"));
391
+ var auditCollection = async (args) => {
392
+ let warning = false;
393
+ const { collection, database, rootPath: rootPath2 } = args;
394
+ logger.info(`Checking collection ${collection.name}`);
395
+ const query = `query {
396
+ collection(collection: "${collection.name}") {
397
+ format
398
+ documents {
399
+ edges {
400
+ node {
401
+ ...on Document {
402
+ _sys {
403
+ extension
404
+ path
440
405
  }
441
406
  }
442
- ],
443
- },
444
- ]
445
- },
446
- ],
447
- },
448
- ],
449
- });
450
-
451
-
452
-
453
-
454
- // Your tina config
455
- // ==============
456
- const branch = 'main'
457
- // When working locally, hit our local filesystem.
458
- // On a Vercel deployment, hit the Tina Cloud API
459
- const apiURL =
460
- process.env.NODE_ENV == 'development'
461
- ? 'http://localhost:4001/graphql'
462
- : \`https://content.tinajs.io/content/\${process.env.NEXT_PUBLIC_TINA_CLIENT_ID}/github/\${branch}\`
463
-
464
- export const tinaConfig = defineConfig({
465
- apiURL,
466
- cmsCallback: (cms) => {
467
- // add your CMS callback code here (if you want)
407
+ }
408
+ }
409
+ }
410
+ }
411
+ }
412
+ `;
413
+ const result = await (0, import_graphql7.resolve)({
414
+ database,
415
+ query,
416
+ variables: {}
417
+ });
418
+ const format = result.data.collection.format;
419
+ const docs = result.data.collection.documents.edges;
420
+ docs.forEach((x) => {
421
+ const node = x.node;
422
+ if (node._sys.extension.replace(".", "") !== format) {
423
+ warning = true;
424
+ logger.warn(import_chalk2.default.yellowBright(`WARNING: there is a file with extension \`${node._sys.extension}\` but in your schema it is defined to be \`.${format}\`
468
425
 
469
- // The Route Mapper
470
- /**
471
- * 1. Import \`tinacms\` and \`RouteMappingPlugin\`
472
- **/
473
- import("tinacms").then(({ RouteMappingPlugin }) => {
474
- /**
475
- * 2. Define the \`RouteMappingPlugin\` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details
476
- **/
477
- const RouteMapping = new RouteMappingPlugin((collection, document) => {
478
- return undefined;
426
+ location: ${import_path2.default.join(rootPath2, node._sys.path)}`));
427
+ }
428
+ });
429
+ return warning;
430
+ };
431
+ var auditDocuments = async (args) => {
432
+ const { collection, database, rootPath: rootPath2, useDefaultValues } = args;
433
+ const query = `query {
434
+ collection(collection: "${collection.name}") {
435
+ format
436
+ slug
437
+ documents {
438
+ edges {
439
+ node {
440
+ ...on Document {
441
+ _sys {
442
+ extension
443
+ path
444
+ relativePath
445
+ }
446
+ }
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }
452
+ `;
453
+ const result = await (0, import_graphql7.resolve)({
454
+ database,
455
+ query,
456
+ variables: {}
457
+ });
458
+ let error = false;
459
+ const documents = result.data.collection.documents.edges;
460
+ for (let i = 0; i < documents.length; i++) {
461
+ const node = documents[i].node;
462
+ const fullPath = import_path2.default.join(rootPath2, node._sys.path);
463
+ logger.info(`Checking document: ${fullPath}`);
464
+ const documentQuery = `query {
465
+ document(collection: "${collection.name}", relativePath: "${node._sys.relativePath}") {
466
+ __typename
467
+ ...on Document {
468
+ _values
469
+ }
470
+ }
471
+ }`;
472
+ const docResult = await (0, import_graphql7.resolve)({
473
+ database,
474
+ query: documentQuery,
475
+ variables: {}
476
+ });
477
+ const topLevelDefaults = {};
478
+ if (useDefaultValues && typeof collection.fields !== "string") {
479
+ collection.fields.filter((x) => !x.list).forEach((x) => {
480
+ const value = x.ui;
481
+ if (typeof value !== "undefined") {
482
+ topLevelDefaults[x.name] = value.defaultValue;
483
+ }
479
484
  });
480
- /**
481
- * 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
482
- **/
483
- cms.plugins.add(RouteMapping);
485
+ }
486
+ const params = transformDocumentIntoMutationRequestPayload(docResult.data.document._values, {
487
+ includeCollection: true,
488
+ includeTemplate: typeof collection.templates !== "undefined"
489
+ }, topLevelDefaults);
490
+ const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
491
+ updateDocument(
492
+ collection: $collection,
493
+ relativePath: $relativePath,
494
+ params: $params
495
+ ){__typename}
496
+ }`;
497
+ const mutationRes = await (0, import_graphql7.resolve)({
498
+ database,
499
+ query: mutation,
500
+ variables: {
501
+ params,
502
+ collection: collection.name,
503
+ relativePath: node._sys.relativePath
504
+ },
505
+ silenceErrors: true
484
506
  });
485
-
486
- return cms;
487
- },
488
- });
489
- `;
490
-
491
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getSchemaPath.ts
492
- var import_path2 = __toModule(require("path"));
493
- var import_fs_extra2 = __toModule(require("fs-extra"));
494
- var ErrorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
495
- var getSchemaPath = ({ projectDir }) => {
496
- if (!import_fs_extra2.default.existsSync(projectDir)) {
497
- throw new Error(ErrorMessage);
498
- }
499
- const inputPathTS = import_path2.default.join(projectDir, "schema.ts");
500
- const inputPathJS = import_path2.default.join(projectDir, "schema.js");
501
- const inputPathTSX = import_path2.default.join(projectDir, "schema.tsx");
502
- const inputPathJSX = import_path2.default.join(projectDir, "schema.jsx");
503
- let inputFile;
504
- if (import_fs_extra2.default.existsSync(inputPathTS)) {
505
- inputFile = inputPathTS;
506
- } else if (import_fs_extra2.default.existsSync(inputPathJS)) {
507
- inputFile = inputPathJS;
508
- } else if (import_fs_extra2.default.existsSync(inputPathTSX)) {
509
- inputFile = inputPathTSX;
510
- } else if (import_fs_extra2.default.existsSync(inputPathJSX)) {
511
- inputFile = inputPathJSX;
512
- }
513
- if (!inputFile) {
514
- throw new Error(ErrorMessage);
507
+ if (mutationRes.errors) {
508
+ mutationRes.errors.forEach((err) => {
509
+ error = true;
510
+ logger.error(import_chalk2.default.red(err.message));
511
+ });
512
+ }
515
513
  }
516
- return inputFile;
517
- };
518
-
519
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/errors/index.ts
520
- var BuildSchemaError = class extends Error {
521
- constructor(message) {
522
- super(message);
523
- this.name = "BuildSchemaError";
524
- }
525
- };
526
- var ExecuteSchemaError = class extends Error {
527
- constructor(message) {
528
- super(message);
529
- this.name = "ExecuteSchemaError";
530
- }
531
- };
532
- var handleServerErrors = (e) => {
533
- if (e.name === "BuildSchemaError") {
534
- logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
535
- Error Message Below
536
- ${e}`);
537
- } else if (e.name === "ExecuteSchemaError") {
538
- logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
539
- Error Message Below
540
- ${e}`);
541
- } else if (e.name === "TinaSchemaValidationError") {
542
- logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
543
- Error Message Below
544
- ${e}`);
545
- } else {
546
- logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
547
- ${e.message}`);
548
- }
549
- };
550
-
551
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
552
- var tinaPath = import_path3.default.join(process.cwd(), ".tina");
553
- var packageJSONFilePath = import_path3.default.join(process.cwd(), "package.json");
554
- var tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
555
- var tinaTempPath = import_path3.default.join(tinaGeneratedPath, "temp");
556
- var tinaConfigPath = import_path3.default.join(tinaGeneratedPath, "config");
557
- var resetGeneratedFolder = async () => {
558
- try {
559
- await import_fs_extra3.default.rmdir(tinaGeneratedPath, {
560
- recursive: true
561
- });
562
- } catch (e) {
563
- console.log(e);
564
- }
565
- await import_fs_extra3.default.mkdir(tinaGeneratedPath);
566
- await import_fs_extra3.default.outputFile(import_path3.default.join(tinaGeneratedPath, ".gitignore"), "db");
514
+ return error;
567
515
  };
568
- var cleanup = async ({ tinaTempPath: tinaTempPath2 }) => {
569
- await import_fs_extra3.default.remove(tinaTempPath2);
516
+ var transformDocumentIntoMutationRequestPayload = (document, instructions, defaults) => {
517
+ const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
518
+ const params = transformParams(rest);
519
+ const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
520
+ return instructions.includeCollection ? { [_collection]: __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate)) } : __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate));
570
521
  };
571
- var compile = async (_ctx, _next, options = { schemaFileType: "ts" }) => {
572
- logger.info(logText("Compiling..."));
573
- const { schemaFileType: requestedSchemaFileType = "ts" } = options;
574
- const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
575
- if (!schemaFileType2) {
576
- throw new Error(`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`);
577
- }
578
- if (_ctx) {
579
- _ctx.schemaFileType = schemaFileType2;
580
- }
581
- let schemaExists = true;
582
- try {
583
- getSchemaPath({ projectDir: tinaPath });
584
- } catch {
585
- schemaExists = false;
586
- }
587
- if (!schemaExists) {
588
- logger.info(dangerText(`
589
- .tina/schema.${schemaFileType2} not found, Creating one for you...
590
- See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
591
- `));
592
- const file = import_path3.default.join(tinaPath, `schema.${schemaFileType2}`);
593
- await import_fs_extra3.default.ensureFile(file);
594
- await import_fs_extra3.default.writeFile(file, defaultSchema(import_path3.default.sep));
522
+ var transformParams = (data) => {
523
+ if (["string", "number", "boolean"].includes(typeof data)) {
524
+ return data;
595
525
  }
596
- try {
597
- await transpile(tinaPath, tinaTempPath);
598
- } catch (e) {
599
- await cleanup({ tinaTempPath });
600
- throw new BuildSchemaError(e);
526
+ if (Array.isArray(data)) {
527
+ return data.map((item) => transformParams(item));
601
528
  }
602
- Object.keys(require.cache).map((key) => {
603
- if (key.startsWith(tinaTempPath)) {
604
- delete require.cache[require.resolve(key)];
605
- }
606
- });
607
529
  try {
608
- const schemaFunc = require(import_path3.default.join(tinaTempPath, "schema.js"));
609
- const schemaObject = schemaFunc.default;
610
- await import_fs_extra3.default.outputFile(import_path3.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
611
- await cleanup({ tinaTempPath });
530
+ (0, import_graphql8.assertShape)(data, (yup) => yup.object({ _template: yup.string().required() }));
531
+ const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
532
+ const nested = transformParams(rest);
533
+ return { [_template]: nested };
612
534
  } catch (e) {
613
- await cleanup({ tinaTempPath });
614
- if (e instanceof Error) {
615
- if (e.name === "TinaSchemaValidationError") {
616
- throw e;
535
+ if (e.message === "Failed to assertShape - _template is a required field") {
536
+ if (!data) {
537
+ return void 0;
538
+ return [];
617
539
  }
540
+ const accum = {};
541
+ Object.entries(data).map(([keyName, value]) => {
542
+ accum[keyName] = transformParams(value);
543
+ });
544
+ return accum;
545
+ } else {
546
+ if (!data) {
547
+ return void 0;
548
+ return [];
549
+ }
550
+ throw e;
618
551
  }
619
- throw new ExecuteSchemaError(e);
620
552
  }
621
553
  };
622
- var transpile = async (projectDir, tempDir) => {
623
- logger.info(logText("Building javascript..."));
624
- const packageJSON = JSON.parse(import_fs_extra3.default.readFileSync(packageJSONFilePath).toString() || "{}");
625
- const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
626
- const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
627
- const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
628
- const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
629
- const inputFile = getSchemaPath({ projectDir });
630
- const outputPath = import_path3.default.join(tempDir, "schema.js");
631
- await (0, import_esbuild.build)({
632
- bundle: true,
633
- platform: "neutral",
634
- target: ["node10.4"],
635
- entryPoints: [inputFile],
636
- treeShaking: true,
637
- external: [...external, "./node_modules/*"],
638
- loader: loaders,
639
- outfile: outputPath
640
- });
641
- logger.info(logText(`Javascript built`));
642
- };
643
- var defineSchema = (config) => {
644
- return config;
645
- };
646
- var loaders = {
647
- ".aac": "file",
648
- ".css": "file",
649
- ".eot": "file",
650
- ".flac": "file",
651
- ".gif": "file",
652
- ".jpeg": "file",
653
- ".jpg": "file",
654
- ".json": "json",
655
- ".mp3": "file",
656
- ".mp4": "file",
657
- ".ogg": "file",
658
- ".otf": "file",
659
- ".png": "file",
660
- ".svg": "file",
661
- ".ttf": "file",
662
- ".wav": "file",
663
- ".webm": "file",
664
- ".webp": "file",
665
- ".woff": "file",
666
- ".woff2": "file",
667
- ".js": "jsx",
668
- ".jsx": "jsx",
669
- ".tsx": "tsx"
670
- };
554
+ function filterObject(obj) {
555
+ const ret = {};
556
+ Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
557
+ return ret;
558
+ }
671
559
 
672
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
673
- var import_chokidar = __toModule(require("chokidar"));
560
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
561
+ var import_chalk3 = __toModule(require("chalk"));
562
+ var import_prompts = __toModule(require("prompts"));
674
563
  var import_metrics = __toModule(require("@tinacms/metrics"));
564
+ var rootPath = process.cwd();
565
+ var audit = async (ctx, next, options) => {
566
+ const telemetry = new import_metrics.Telemetry({ disabled: options.noTelemetry });
567
+ await telemetry.submitRecord({
568
+ event: {
569
+ name: "tinacms:cli:audit:invoke",
570
+ clean: Boolean(options.clean),
571
+ useDefaults: Boolean(options.useDefaultValues)
572
+ }
573
+ });
574
+ if (options.clean) {
575
+ logger.info(`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${import_chalk3.default.bold("clean git tree")} so unwanted changes can be undone.
675
576
 
676
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/lock.ts
677
- var AsyncLock = class {
678
- constructor() {
679
- this.disable = () => {
680
- };
681
- this.promise = Promise.resolve();
577
+ `);
578
+ const res = await (0, import_prompts.default)({
579
+ name: "useClean",
580
+ type: "confirm",
581
+ message: `Do you want to continue?`
582
+ });
583
+ if (!res.useClean) {
584
+ logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit not complete"));
585
+ process.exit(0);
586
+ }
682
587
  }
683
- enable() {
684
- this.promise = new Promise((resolve2) => this.disable = resolve2);
588
+ if (options.useDefaultValues && !options.clean) {
589
+ logger.warn(import_chalk3.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
590
+ }
591
+ const bridge = options.clean ? new import_datalayer2.FilesystemBridge(rootPath) : new import_datalayer2.AuditFileSystemBridge(rootPath);
592
+ const store = options.clean ? new import_datalayer2.FilesystemStore({ rootPath }) : new import_datalayer2.AuditFilesystemStore({ rootPath });
593
+ const database = await (0, import_graphql9.createDatabase)({ store, bridge });
594
+ const schema = await database.getSchema();
595
+ const collections = schema.getCollections();
596
+ let warning = false;
597
+ let error = false;
598
+ for (let i = 0; i < collections.length; i++) {
599
+ const collection = collections[i];
600
+ const returnWarning = await auditCollection({
601
+ collection,
602
+ database,
603
+ rootPath,
604
+ useDefaultValues: options.useDefaultValues
605
+ });
606
+ const returnError = await auditDocuments({
607
+ collection,
608
+ database,
609
+ rootPath,
610
+ useDefaultValues: options.useDefaultValues
611
+ });
612
+ warning = warning || returnWarning;
613
+ error = error || returnError;
685
614
  }
615
+ ctx.warning = warning;
616
+ ctx.error = error;
617
+ next();
686
618
  };
687
-
688
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
689
- var lock = new AsyncLock();
690
- var gqlPackageFile = require.resolve("@tinacms/graphql");
691
- async function startServer(_ctx, _next, {
692
- port = 4001,
693
- command,
694
- noWatch,
695
- experimentalData,
696
- noSDK,
697
- noTelemetry,
698
- watchFolders
699
- }) {
700
- lock.disable();
701
- const rootPath2 = process.cwd();
702
- const t = new import_metrics.Telemetry({ disabled: Boolean(noTelemetry) });
703
- t.submitRecord({
704
- event: {
705
- name: "tinacms:cli:server:start:invoke"
706
- }
707
- });
708
- if (!process.env.CI && !noWatch) {
709
- await resetGeneratedFolder();
619
+ var printFinalMessage = async (ctx, next, _options) => {
620
+ if (ctx.error) {
621
+ logger.error(import_chalk3.default.redBright(`\u203C\uFE0F Audit ${import_chalk3.default.bold("failed")} with errors`));
622
+ } else if (ctx.warning) {
623
+ logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
624
+ } else {
625
+ logger.info(import_chalk3.default.greenBright("\u2705 Audit passed"));
710
626
  }
711
- const bridge = new import_datalayer2.FilesystemBridge(rootPath2);
712
- const store = experimentalData ? new import_datalayer2.LevelStore(rootPath2) : new import_datalayer2.FilesystemStore({ rootPath: rootPath2 });
713
- const shouldBuild = bridge.supportsBuilding();
714
- const database = await (0, import_graphql7.createDatabase)({ store, bridge });
715
- const startSubprocess = () => {
716
- if (typeof command === "string") {
717
- const commands = command.split(" ");
718
- const firstCommand = commands[0];
719
- const args = commands.slice(1) || [];
720
- const ps = import_child_process.default.spawn(firstCommand, args, {
721
- stdio: "inherit",
722
- shell: true
723
- });
724
- ps.on("error", (code) => {
725
- logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
726
- logger.error(`name: ${code.name}
727
- message: ${code.message}
728
-
729
- stack: ${code.stack || "No stack was provided"}`);
730
- });
731
- ps.on("close", (code) => {
732
- logger.info(`child process exited with code ${code}`);
733
- process.exit(code);
734
- });
735
- }
736
- };
737
- let ready = false;
738
- const build2 = async (noSDK2) => {
739
- await lock.promise;
740
- lock.enable();
741
- try {
742
- if (!process.env.CI && !noWatch) {
743
- await resetGeneratedFolder();
744
- }
745
- const database2 = await (0, import_graphql7.createDatabase)({ store, bridge });
746
- await compile(null, null);
747
- const schema = await (0, import_graphql7.buildSchema)(rootPath2, database2);
748
- await genTypes({ schema }, () => {
749
- }, { noSDK: noSDK2 });
750
- } catch (error) {
751
- throw error;
752
- } finally {
753
- lock.disable();
754
- }
755
- };
756
- const foldersToWatch = (watchFolders || []).map((x) => import_path4.default.join(rootPath2, x));
757
- if (!noWatch && !process.env.CI) {
758
- import_chokidar.default.watch([
759
- ...foldersToWatch,
760
- `${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
761
- ], {
762
- ignored: [
763
- "**/node_modules/**/*",
764
- "**/.next/**/*",
765
- `${import_path4.default.resolve(rootPath2)}/.tina/__generated__/**/*`
766
- ]
767
- }).on("ready", async () => {
768
- console.log("Generating Tina config");
769
- try {
770
- if (shouldBuild) {
771
- await build2(noSDK);
772
- }
773
- ready = true;
774
- startSubprocess();
775
- } catch (e) {
776
- handleServerErrors(e);
777
- console.log(e);
778
- process.exit(0);
779
- }
780
- }).on("all", async () => {
781
- if (ready) {
782
- logger.info("Tina change detected, regenerating config");
783
- try {
784
- if (shouldBuild) {
785
- await build2(noSDK);
786
- }
787
- } catch (e) {
788
- handleServerErrors(e);
789
- t.submitRecord({
790
- event: {
791
- name: "tinacms:cli:server:error",
792
- errorMessage: e.message
793
- }
794
- });
795
- }
796
- }
797
- });
798
- } else {
799
- if (shouldBuild) {
800
- await build2(noSDK);
801
- }
802
- }
803
- const state = {
804
- server: null,
805
- sockets: []
806
- };
807
- let isReady = false;
808
- const start = async () => {
809
- const s = (init_server(), server_exports);
810
- state.server = await s.default(database);
811
- state.server.listen(port, () => {
812
- logger.info(`Started Filesystem GraphQL server on port: ${port}`);
813
- logger.info(`Visit the playground at http://localhost:${port}/altair/`);
814
- });
815
- state.server.on("error", function(e) {
816
- if (e.code === "EADDRINUSE") {
817
- logger.error(dangerText(`Port 4001 already in use`));
818
- process.exit();
819
- }
820
- throw e;
821
- });
822
- state.server.on("connection", (socket) => {
823
- state.sockets.push(socket);
824
- });
825
- };
826
- const restart = async () => {
827
- logger.info("Detected change to gql package, restarting...");
828
- delete require.cache[gqlPackageFile];
829
- state.sockets.forEach((socket) => {
830
- if (socket.destroyed === false) {
831
- socket.destroy();
832
- }
833
- });
834
- state.sockets = [];
835
- state.server.close(() => {
836
- logger.info("Server closed");
837
- start();
838
- });
839
- };
840
- if (!noWatch && !process.env.CI) {
841
- import_chokidar.default.watch([gqlPackageFile]).on("ready", async () => {
842
- isReady = true;
843
- start();
844
- }).on("all", async () => {
845
- if (isReady) {
846
- restart();
847
- }
848
- });
849
- } else {
850
- if (process.env.CI) {
851
- logger.info("Detected CI environment, omitting watch commands...");
852
- }
853
- start();
854
- startSubprocess();
855
- }
856
- }
627
+ next();
628
+ };
857
629
 
858
630
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
859
- var import_chalk2 = __toModule(require("chalk"));
631
+ var import_chalk4 = __toModule(require("chalk"));
860
632
  var adminPage = `import { TinaAdmin } from 'tinacms';
861
633
  export default TinaAdmin;
862
634
  `;
@@ -865,7 +637,7 @@ title: Vote For Pedro
865
637
  ---
866
638
  # Welcome to the blog.
867
639
 
868
- > To edit this site head over to the [\`/admin\`](/admin) route. Then click the pencil icon in the bottom lefthand corner to start editing \u{1F999}.
640
+ > To edit this site head over to the [\`/admin\`](/admin) route. Then click the pencil icon in the bottom lefthand corner to start editing \u{1F999}.
869
641
 
870
642
  # Dixi gaude Arethusa
871
643
 
@@ -890,7 +662,7 @@ mille rigidi sub taurum.
890
662
  `;
891
663
  var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
892
664
  // This is a demo file once you have tina setup feel free to delete this file
893
-
665
+
894
666
  import { staticRequest, gql } from "tinacms";
895
667
  import Head from "next/head";
896
668
  import { createGlobalStyle } from "styled-components";
@@ -899,11 +671,9 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
899
671
 
900
672
  const query = gql\`
901
673
  query BlogPostQuery($relativePath: String!) {
902
- getPostsDocument(relativePath: $relativePath) {
903
- data {
674
+ posts(relativePath: $relativePath) {
904
675
  title
905
- body
906
- }
676
+ body
907
677
  }
908
678
  }
909
679
  \`
@@ -941,7 +711,7 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
941
711
  text-decoration: underline;
942
712
  }
943
713
  \`;
944
-
714
+
945
715
  const BlogPage = (props) => {
946
716
  const { data } = useTina({
947
717
  query,
@@ -968,10 +738,10 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
968
738
  }}
969
739
  >
970
740
  <h1 className="text-3xl m-8 text-center leading-8 font-extrabold tracking-tight text-gray-900 sm:text-4xl">
971
- {data.getPostsDocument.data.title}
741
+ {data.posts.title}
972
742
  </h1>
973
743
  <ContentSection
974
- content={data.getPostsDocument.data.body}
744
+ content={data.posts.body}
975
745
  ></ContentSection>
976
746
  </div>
977
747
  <div className="bg-green-100 text-center">
@@ -989,7 +759,7 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
989
759
  </>
990
760
  );
991
761
  };
992
-
762
+
993
763
  export const getStaticProps = async ({ params }) => {
994
764
  const variables = { relativePath: \`\${params.filename}.md\` }
995
765
  let data = {}
@@ -1010,16 +780,18 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
1010
780
  },
1011
781
  }
1012
782
  };
1013
-
783
+
1014
784
  export const getStaticPaths = async () => {
1015
785
  const postsListData = (await staticRequest({
1016
786
  query: gql\`
1017
787
  query GetPostsList {
1018
- getPostsList {
788
+ postsConnection {
1019
789
  edges {
1020
790
  node {
1021
- sys {
1022
- filename
791
+ ...on Document {
792
+ _sys {
793
+ filename
794
+ }
1023
795
  }
1024
796
  }
1025
797
  }
@@ -1027,15 +799,15 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
1027
799
  }
1028
800
  \`,
1029
801
  }));
1030
-
802
+
1031
803
  return {
1032
- paths: postsListData.getPostsList.edges.map((post) => ({
1033
- params: { filename: post.node.sys.filename },
804
+ paths: postsListData.postsConnection.edges.map((post) => ({
805
+ params: { filename: post.node._sys.filename },
1034
806
  })),
1035
807
  fallback: false,
1036
808
  };
1037
809
  };
1038
-
810
+
1039
811
  export default BlogPage;
1040
812
 
1041
813
  const PageSection = props => {
@@ -1050,7 +822,7 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
1050
822
  const components = {
1051
823
  PageSection: PageSection,
1052
824
  }
1053
-
825
+
1054
826
  const ContentSection = ({ content }) => {
1055
827
  return (
1056
828
  <div className="relative py-16 bg-white overflow-hidden">
@@ -1166,21 +938,37 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
1166
938
  </div>
1167
939
  );
1168
940
  };
1169
-
941
+
1170
942
  `;
1171
943
  var AppJsContent = (usingSrc, extraImports) => {
1172
- const importLine = import_chalk2.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
944
+ const importLine = `import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`;
945
+ return `${importLine}
946
+ ${extraImports || ""}
947
+
948
+ const App = ({ Component, pageProps }) => {
949
+ return (
950
+ <Tina>
951
+ <Component {...pageProps} />
952
+ </Tina>
953
+ )
954
+ }
955
+
956
+ export default App
957
+ `;
958
+ };
959
+ var AppJsContentPrintout = (usingSrc, extraImports) => {
960
+ const importLine = import_chalk4.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
1173
961
  return `${importLine}
1174
962
  ${extraImports || ""}
1175
963
 
1176
964
  const App = ({ Component, pageProps }) => {
1177
965
  return (
1178
- ${import_chalk2.default.green("+ <Tina>")}
966
+ ${import_chalk4.default.green("+ <Tina>")}
1179
967
  <Component {...pageProps} />
1180
- ${import_chalk2.default.green("+ </Tina>")}
968
+ ${import_chalk4.default.green("+ </Tina>")}
1181
969
  )
1182
970
  }
1183
-
971
+
1184
972
  export default App
1185
973
  `;
1186
974
  };
@@ -1231,12 +1019,12 @@ function extendNextScripts(scripts) {
1231
1019
  }
1232
1020
 
1233
1021
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
1234
- var import_fs_extra4 = __toModule(require("fs-extra"));
1022
+ var import_fs_extra2 = __toModule(require("fs-extra"));
1235
1023
  var import_progress = __toModule(require("progress"));
1236
1024
  var import_metrics2 = __toModule(require("@tinacms/metrics"));
1237
- var import_chalk3 = __toModule(require("chalk"));
1238
- var import_path5 = __toModule(require("path"));
1239
- var import_prompts = __toModule(require("prompts"));
1025
+ var import_chalk5 = __toModule(require("chalk"));
1026
+ var import_path3 = __toModule(require("path"));
1027
+ var import_prompts2 = __toModule(require("prompts"));
1240
1028
  function execShellCommand(cmd) {
1241
1029
  const exec = require("child_process").exec;
1242
1030
  return new Promise((resolve2, _reject) => {
@@ -1262,7 +1050,7 @@ async function initTina(ctx, next, options) {
1262
1050
  var MIN_REACT_VERSION = ">=16.14.0";
1263
1051
  async function checkDeps(ctx, next, options) {
1264
1052
  const bar = new import_progress.default("Checking dependencies. :prog", 1);
1265
- const packageJSON = JSON.parse((await import_fs_extra4.default.readFileSync(packageJSONPath)).toString());
1053
+ const packageJSON = JSON.parse((await import_fs_extra2.default.readFileSync(packageJSONPath)).toString());
1266
1054
  if (!checkPackage(packageJSON, "react") || !checkPackage(packageJSON, "react-dom")) {
1267
1055
  const message = `Unable to initialize Tina due to outdated dependencies, try upgrading the following packages:
1268
1056
  "react@${MIN_REACT_VERSION}"
@@ -1328,348 +1116,600 @@ async function installDeps(ctx, next, options) {
1328
1116
  next();
1329
1117
  }
1330
1118
  var baseDir = process.cwd();
1331
- var packageJSONPath = import_path5.default.join(baseDir, "package.json");
1332
- var blogContentPath = import_path5.default.join(baseDir, "content", "posts");
1333
- var blogPostPath = import_path5.default.join(blogContentPath, "HelloWorld.md");
1334
- var TinaFolder = import_path5.default.join(baseDir, ".tina");
1335
- var componentFolder = import_path5.default.join(TinaFolder, "components");
1336
- var TinaProviderPath = import_path5.default.join(componentFolder, "TinaProvider.js");
1337
- var TinaDynamicProvider = import_path5.default.join(componentFolder, "TinaDynamicProvider.js");
1119
+ var packageJSONPath = import_path3.default.join(baseDir, "package.json");
1120
+ var blogContentPath = import_path3.default.join(baseDir, "content", "posts");
1121
+ var blogPostPath = import_path3.default.join(blogContentPath, "HelloWorld.md");
1122
+ var TinaFolder = import_path3.default.join(baseDir, ".tina");
1123
+ var componentFolder = import_path3.default.join(TinaFolder, "components");
1124
+ var TinaProviderPath = import_path3.default.join(componentFolder, "TinaProvider.js");
1125
+ var TinaDynamicProvider = import_path3.default.join(componentFolder, "TinaDynamicProvider.js");
1338
1126
  async function tinaSetup(_ctx, next, _options) {
1339
- const usingSrc = import_fs_extra4.default.pathExistsSync(import_path5.default.join(baseDir, "src"));
1340
- if (!import_fs_extra4.default.pathExistsSync(blogPostPath)) {
1127
+ const usingSrc = import_fs_extra2.default.pathExistsSync(import_path3.default.join(baseDir, "src"));
1128
+ if (!import_fs_extra2.default.pathExistsSync(blogPostPath)) {
1341
1129
  logger.info(logText("Adding a content folder..."));
1342
- import_fs_extra4.default.mkdirpSync(blogContentPath);
1343
- import_fs_extra4.default.writeFileSync(blogPostPath, blogPost);
1130
+ import_fs_extra2.default.mkdirpSync(blogContentPath);
1131
+ import_fs_extra2.default.writeFileSync(blogPostPath, blogPost);
1344
1132
  }
1345
- if (!import_fs_extra4.default.existsSync(TinaProviderPath) && !import_fs_extra4.default.existsSync(TinaDynamicProvider)) {
1346
- import_fs_extra4.default.mkdirpSync(componentFolder);
1347
- import_fs_extra4.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.schemaFileType || "ts"}'`));
1348
- import_fs_extra4.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
1133
+ if (!import_fs_extra2.default.existsSync(TinaProviderPath) && !import_fs_extra2.default.existsSync(TinaDynamicProvider)) {
1134
+ import_fs_extra2.default.mkdirpSync(componentFolder);
1135
+ import_fs_extra2.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.schemaFileType || "ts"}'`));
1136
+ import_fs_extra2.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
1349
1137
  }
1350
1138
  logger.level = "info";
1351
- const pagesPath = import_path5.default.join(baseDir, usingSrc ? "src" : "", "pages");
1352
- const appPath = import_path5.default.join(pagesPath, "_app.js");
1353
- const appPathTS = import_path5.default.join(pagesPath, "_app.tsx");
1354
- const appExtension = import_fs_extra4.default.existsSync(appPath) ? ".js" : ".tsx";
1355
- if (!import_fs_extra4.default.pathExistsSync(appPath) && !import_fs_extra4.default.pathExistsSync(appPathTS)) {
1139
+ const pagesPath = import_path3.default.join(baseDir, usingSrc ? "src" : "", "pages");
1140
+ const appPath = import_path3.default.join(pagesPath, "_app.js");
1141
+ const appPathTS = import_path3.default.join(pagesPath, "_app.tsx");
1142
+ const appExtension = import_fs_extra2.default.existsSync(appPath) ? ".js" : ".tsx";
1143
+ if (!import_fs_extra2.default.pathExistsSync(appPath) && !import_fs_extra2.default.pathExistsSync(appPathTS)) {
1356
1144
  logger.info(logText("Adding _app.js ... \u2705"));
1357
- import_fs_extra4.default.writeFileSync(appPath, AppJsContent(usingSrc));
1145
+ import_fs_extra2.default.writeFileSync(appPath, AppJsContent(usingSrc));
1358
1146
  } else {
1359
- const override = await (0, import_prompts.default)({
1147
+ const override = await (0, import_prompts2.default)({
1360
1148
  name: "res",
1361
1149
  type: "confirm",
1362
- message: `do you want us to ${import_chalk3.default.bold(`override`)} your _app${appExtension}?`
1150
+ message: `do you want us to ${import_chalk5.default.bold(`override`)} your _app${appExtension}?`
1363
1151
  });
1364
1152
  _ctx.overrideApp = override.res;
1365
1153
  if (override.res) {
1366
1154
  logger.info(logText(`Adding _app${appExtension} ... \u2705`));
1367
- const appPathWithExtension = import_path5.default.join(pagesPath, `_app${appExtension}`);
1368
- const fileContent = import_fs_extra4.default.pathExistsSync(appPath) ? (0, import_fs_extra4.readFileSync)(appPath) : (0, import_fs_extra4.readFileSync)(appPathTS);
1155
+ const appPathWithExtension = import_path3.default.join(pagesPath, `_app${appExtension}`);
1156
+ const fileContent = import_fs_extra2.default.pathExistsSync(appPath) ? (0, import_fs_extra2.readFileSync)(appPath) : (0, import_fs_extra2.readFileSync)(appPathTS);
1369
1157
  const matches = [
1370
1158
  ...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
1371
1159
  ];
1372
1160
  const primaryMatches = matches.map((x) => x[0]);
1373
- import_fs_extra4.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
1161
+ import_fs_extra2.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
1374
1162
  }
1375
1163
  }
1376
- const tinaBlogPagePath = import_path5.default.join(pagesPath, "demo", "blog");
1377
- const tinaBlogPagePathFile = import_path5.default.join(tinaBlogPagePath, "[filename].js");
1378
- if (!import_fs_extra4.default.pathExistsSync(tinaBlogPagePathFile)) {
1379
- import_fs_extra4.default.mkdirpSync(tinaBlogPagePath);
1380
- import_fs_extra4.default.writeFileSync(tinaBlogPagePathFile, nextPostPage());
1164
+ const tinaBlogPagePath = import_path3.default.join(pagesPath, "demo", "blog");
1165
+ const tinaBlogPagePathFile = import_path3.default.join(tinaBlogPagePath, "[filename].js");
1166
+ if (!import_fs_extra2.default.pathExistsSync(tinaBlogPagePathFile)) {
1167
+ import_fs_extra2.default.mkdirpSync(tinaBlogPagePath);
1168
+ import_fs_extra2.default.writeFileSync(tinaBlogPagePathFile, nextPostPage());
1381
1169
  }
1382
1170
  logger.info("Adding a content folder... \u2705");
1383
- const packagePath = import_path5.default.join(baseDir, "package.json");
1384
- const pack = JSON.parse((0, import_fs_extra4.readFileSync)(packagePath).toString());
1171
+ const packagePath = import_path3.default.join(baseDir, "package.json");
1172
+ const pack = JSON.parse((0, import_fs_extra2.readFileSync)(packagePath).toString());
1385
1173
  const oldScripts = pack.scripts || {};
1386
1174
  const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
1387
1175
  scripts: extendNextScripts(oldScripts)
1388
1176
  }), null, 2);
1389
- (0, import_fs_extra4.writeFileSync)(packagePath, newPack);
1390
- const adminPath = import_path5.default.join(pagesPath, "admin.js");
1391
- if (import_fs_extra4.default.pathExistsSync(import_path5.default.join(pagesPath, "admin"))) {
1177
+ (0, import_fs_extra2.writeFileSync)(packagePath, newPack);
1178
+ const adminPath = import_path3.default.join(pagesPath, "admin.js");
1179
+ if (import_fs_extra2.default.pathExistsSync(import_path3.default.join(pagesPath, "admin"))) {
1392
1180
  logger.warn(`Unable to add /pages/admin.js, this path already exists.
1393
1181
  Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
1394
1182
  return next();
1395
1183
  }
1396
- (0, import_fs_extra4.outputFileSync)(adminPath, adminPage);
1184
+ (0, import_fs_extra2.outputFileSync)(adminPath, adminPage);
1397
1185
  next();
1398
1186
  }
1399
1187
  async function successMessage(ctx, next, options) {
1400
- const usingSrc = import_fs_extra4.default.pathExistsSync(import_path5.default.join(baseDir, "src"));
1401
- logger.info(`Tina setup ${import_chalk3.default.underline.green("done")} \u2705
1188
+ const usingSrc = import_fs_extra2.default.pathExistsSync(import_path3.default.join(baseDir, "src"));
1189
+ logger.info(`Tina setup ${import_chalk5.default.underline.green("done")} \u2705
1402
1190
  `);
1403
1191
  logger.info("Next Steps: \n");
1404
1192
  if (!ctx.overrideApp) {
1405
- logger.info(`${import_chalk3.default.bold("Add the Tina wrapper")}`);
1193
+ logger.info(`${import_chalk5.default.bold("Add the Tina wrapper")}`);
1406
1194
  logger.info(`\u26A0\uFE0F Before using Tina, you will NEED to add the Tina wrapper to your _app.jsx
1407
1195
  `);
1408
- logger.info(`${AppJsContent(usingSrc)}`);
1196
+ logger.info(`${AppJsContentPrintout(usingSrc)}`);
1409
1197
  }
1410
- logger.info(`${import_chalk3.default.bold("Run your site with Tina")}`);
1198
+ logger.info(`${import_chalk5.default.bold("Run your site with Tina")}`);
1411
1199
  logger.info(` yarn dev
1412
1200
  `);
1413
- logger.info(`${import_chalk3.default.bold("Start Editing")}`);
1201
+ logger.info(`${import_chalk5.default.bold("Start Editing")}`);
1414
1202
  logger.info(` Go to 'http://localhost:3000/admin'
1415
1203
  `);
1416
- logger.info(`${import_chalk3.default.bold("Read the docs")}`);
1204
+ logger.info(`${import_chalk5.default.bold("Read the docs")}`);
1417
1205
  logger.info(` Check out 'https://tina.io/docs/introduction/tina-init/#adding-tina' for help getting started with Tina
1418
1206
  `);
1419
1207
  logger.info(`Enjoy Tina! \u{1F999}`);
1420
1208
  next();
1421
1209
  }
1422
1210
 
1423
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
1424
- var import_graphql10 = __toModule(require("@tinacms/graphql"));
1425
- var import_datalayer3 = __toModule(require("@tinacms/datalayer"));
1211
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
1212
+ var chain = async (cmds, options) => {
1213
+ const ctx = {};
1214
+ const next = async (middlewareIndex) => {
1215
+ if (middlewareIndex >= cmds.length) {
1216
+ process.exit(0);
1217
+ }
1218
+ try {
1219
+ await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
1220
+ } catch (err) {
1221
+ console.error(` ${dangerText(err)}`);
1222
+ process.exit(1);
1223
+ }
1224
+ };
1225
+ if (cmds.length > 0) {
1226
+ await next(0);
1227
+ }
1228
+ };
1426
1229
 
1427
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/audit.ts
1428
- var import_graphql8 = __toModule(require("@tinacms/graphql"));
1429
- var import_path6 = __toModule(require("path"));
1430
- var import_graphql9 = __toModule(require("@tinacms/graphql"));
1431
- var import_chalk4 = __toModule(require("chalk"));
1432
- var auditCollection = async (args) => {
1433
- let warning = false;
1434
- const { collection, database, rootPath: rootPath2 } = args;
1435
- logger.info(`Checking collection ${collection.name}`);
1436
- const query = `query {
1437
- getCollection(collection: "${collection.name}") {
1438
- format
1439
- documents {
1440
- edges {
1441
- node {
1442
- ...on Document {
1443
- sys {
1444
- extension
1445
- path
1446
- }
1447
- }
1448
- }
1449
- }
1450
- }
1451
- }
1452
- }
1453
- `;
1454
- const result = await (0, import_graphql8.resolve)({
1455
- database,
1456
- query,
1457
- variables: {}
1458
- });
1459
- const format = result.data.getCollection.format;
1460
- const docs = result.data.getCollection.documents.edges;
1461
- docs.forEach((x) => {
1462
- const node = x.node;
1463
- if (node.sys.extension.replace(".", "") !== format) {
1464
- warning = true;
1465
- logger.warn(import_chalk4.default.yellowBright(`WARNING: there is a file with extension \`${node.sys.extension}\` but in your schema it is defined to be \`.${format}\`
1230
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
1231
+ var import_chalk7 = __toModule(require("chalk"));
1466
1232
 
1467
- location: ${import_path6.default.join(rootPath2, node.sys.path)}`));
1468
- }
1469
- });
1470
- return warning;
1233
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/errors/index.ts
1234
+ var BuildSchemaError = class extends Error {
1235
+ constructor(message) {
1236
+ super(message);
1237
+ this.name = "BuildSchemaError";
1238
+ }
1471
1239
  };
1472
- var auditDocuments = async (args) => {
1473
- const { collection, database, rootPath: rootPath2, useDefaultValues } = args;
1474
- const query = `query {
1475
- getCollection(collection: "${collection.name}") {
1476
- format
1477
- slug
1478
- documents {
1479
- edges {
1480
- node {
1481
- ...on Document {
1482
- sys {
1483
- extension
1484
- path
1485
- relativePath
1240
+ var ExecuteSchemaError = class extends Error {
1241
+ constructor(message) {
1242
+ super(message);
1243
+ this.name = "ExecuteSchemaError";
1244
+ }
1245
+ };
1246
+ var handleServerErrors = (e) => {
1247
+ if (e.name === "BuildSchemaError") {
1248
+ logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
1249
+ Error Message Below
1250
+ ${e}`);
1251
+ } else if (e.name === "ExecuteSchemaError") {
1252
+ logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
1253
+ Error Message Below
1254
+ ${e}`);
1255
+ } else if (e.name === "TinaSchemaValidationError") {
1256
+ logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
1257
+ Error Message Below
1258
+ ${e}`);
1259
+ } else {
1260
+ logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
1261
+ ${e.message}`);
1262
+ }
1263
+ };
1264
+
1265
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
1266
+ var import_fs_extra4 = __toModule(require("fs-extra"));
1267
+ var import_path5 = __toModule(require("path"));
1268
+ var import_esbuild = __toModule(require("esbuild"));
1269
+
1270
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
1271
+ var defaultSchema = (sep) => `
1272
+ import { defineSchema, defineConfig } from "tinacms";
1273
+
1274
+ const schema = defineSchema({
1275
+ collections: [
1276
+ {
1277
+ label: "Blog Posts",
1278
+ name: "posts",
1279
+ path: "content${sep}posts",
1280
+ fields: [
1281
+ {
1282
+ type: "string",
1283
+ label: "Title",
1284
+ name: "title",
1285
+ },
1286
+ {
1287
+ type: "rich-text",
1288
+ label: "Blog Post Body",
1289
+ name: "body",
1290
+ isBody: true,
1291
+ templates: [
1292
+ {
1293
+ name: "PageSection",
1294
+ label: "Page Section",
1295
+ fields: [
1296
+ {
1297
+ type: "string",
1298
+ name: "heading",
1299
+ label: "Heading",
1300
+ },
1301
+ {
1302
+ type: "string",
1303
+ name: "content",
1304
+ label: "Content",
1305
+ ui: {
1306
+ component: "textarea"
1486
1307
  }
1487
1308
  }
1488
- }
1489
- }
1490
- }
1491
- }
1492
- }
1493
- `;
1494
- const result = await (0, import_graphql8.resolve)({
1495
- database,
1496
- query,
1497
- variables: {}
1498
- });
1499
- let error = false;
1500
- const documents = result.data.getCollection.documents.edges;
1501
- for (let i = 0; i < documents.length; i++) {
1502
- const node = documents[i].node;
1503
- const fullPath = import_path6.default.join(rootPath2, node.sys.path);
1504
- logger.info(`Checking document: ${fullPath}`);
1505
- const documentQuery = `query {
1506
- getDocument(collection: "${collection.name}", relativePath: "${node.sys.relativePath}") {
1507
- __typename
1508
- ...on Document {
1509
- values
1510
- }
1511
- }
1512
- }`;
1513
- const docResult = await (0, import_graphql8.resolve)({
1514
- database,
1515
- query: documentQuery,
1516
- variables: {}
1517
- });
1518
- const topLevelDefaults = {};
1519
- if (useDefaultValues && typeof collection.fields !== "string") {
1520
- collection.fields.filter((x) => !x.list).forEach((x) => {
1521
- const value = x.ui;
1522
- if (typeof value !== "undefined") {
1523
- topLevelDefaults[x.name] = value.defaultValue;
1524
- }
1309
+ ],
1310
+ },
1311
+ ]
1312
+ },
1313
+ ],
1314
+ },
1315
+ ],
1316
+ });
1317
+
1318
+ export default schema
1319
+
1320
+ // Your tina config
1321
+ // ==============
1322
+ const branch = 'main'
1323
+ // When working locally, hit our local filesystem.
1324
+ // On a Vercel deployment, hit the Tina Cloud API
1325
+ const apiURL =
1326
+ process.env.NODE_ENV == 'development'
1327
+ ? 'http://localhost:4001/graphql'
1328
+ : \`https://content.tinajs.io/content/\${process.env.NEXT_PUBLIC_TINA_CLIENT_ID}/github/\${branch}\`
1329
+
1330
+ export const tinaConfig = defineConfig({
1331
+ apiURL,
1332
+ schema,
1333
+ cmsCallback: (cms) => {
1334
+ // add your CMS callback code here (if you want)
1335
+
1336
+ // The Route Mapper
1337
+ /**
1338
+ * 1. Import \`tinacms\` and \`RouteMappingPlugin\`
1339
+ **/
1340
+ import("tinacms").then(({ RouteMappingPlugin }) => {
1341
+ /**
1342
+ * 2. Define the \`RouteMappingPlugin\` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details
1343
+ **/
1344
+ const RouteMapping = new RouteMappingPlugin((collection, document) => {
1345
+ return undefined;
1525
1346
  });
1526
- }
1527
- const params = transformDocumentIntoMutationRequestPayload(docResult.data.getDocument.values, {
1528
- includeCollection: true,
1529
- includeTemplate: typeof collection.templates !== "undefined"
1530
- }, topLevelDefaults);
1531
- const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
1532
- updateDocument(
1533
- collection: $collection,
1534
- relativePath: $relativePath,
1535
- params: $params
1536
- ){__typename}
1537
- }`;
1538
- const mutationRes = await (0, import_graphql8.resolve)({
1539
- database,
1540
- query: mutation,
1541
- variables: {
1542
- params,
1543
- collection: collection.name,
1544
- relativePath: node.sys.relativePath
1545
- },
1546
- silenceErrors: true
1347
+ /**
1348
+ * 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
1349
+ **/
1350
+ cms.plugins.add(RouteMapping);
1547
1351
  });
1548
- if (mutationRes.errors) {
1549
- mutationRes.errors.forEach((err) => {
1550
- error = true;
1551
- logger.error(import_chalk4.default.red(err.message));
1552
- });
1352
+
1353
+ return cms;
1354
+ },
1355
+ });
1356
+ `;
1357
+
1358
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getSchemaPath.ts
1359
+ var import_path4 = __toModule(require("path"));
1360
+ var import_fs_extra3 = __toModule(require("fs-extra"));
1361
+ var ErrorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
1362
+ var getSchemaPath = ({ projectDir }) => {
1363
+ if (!import_fs_extra3.default.existsSync(projectDir)) {
1364
+ throw new Error(ErrorMessage);
1365
+ }
1366
+ const inputPathTS = import_path4.default.join(projectDir, "schema.ts");
1367
+ const inputPathJS = import_path4.default.join(projectDir, "schema.js");
1368
+ const inputPathTSX = import_path4.default.join(projectDir, "schema.tsx");
1369
+ const inputPathJSX = import_path4.default.join(projectDir, "schema.jsx");
1370
+ let inputFile;
1371
+ if (import_fs_extra3.default.existsSync(inputPathTS)) {
1372
+ inputFile = inputPathTS;
1373
+ } else if (import_fs_extra3.default.existsSync(inputPathJS)) {
1374
+ inputFile = inputPathJS;
1375
+ } else if (import_fs_extra3.default.existsSync(inputPathTSX)) {
1376
+ inputFile = inputPathTSX;
1377
+ } else if (import_fs_extra3.default.existsSync(inputPathJSX)) {
1378
+ inputFile = inputPathJSX;
1379
+ }
1380
+ if (!inputFile) {
1381
+ throw new Error(ErrorMessage);
1382
+ }
1383
+ return inputFile;
1384
+ };
1385
+
1386
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
1387
+ var tinaPath = import_path5.default.join(process.cwd(), ".tina");
1388
+ var packageJSONFilePath = import_path5.default.join(process.cwd(), "package.json");
1389
+ var tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
1390
+ var tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp");
1391
+ var tinaConfigPath = import_path5.default.join(tinaGeneratedPath, "config");
1392
+ var resetGeneratedFolder = async () => {
1393
+ try {
1394
+ await import_fs_extra4.default.rmdir(tinaGeneratedPath, {
1395
+ recursive: true
1396
+ });
1397
+ } catch (e) {
1398
+ console.log(e);
1399
+ }
1400
+ await import_fs_extra4.default.mkdir(tinaGeneratedPath);
1401
+ await import_fs_extra4.default.outputFile(import_path5.default.join(tinaGeneratedPath, ".gitignore"), "db");
1402
+ };
1403
+ var cleanup = async ({ tinaTempPath: tinaTempPath2 }) => {
1404
+ await import_fs_extra4.default.remove(tinaTempPath2);
1405
+ };
1406
+ var compile = async (_ctx, _next, options) => {
1407
+ if (!options.schemaFileType)
1408
+ options = __spreadProps(__spreadValues({}, options), { schemaFileType: "ts" });
1409
+ if (options.verbose) {
1410
+ logger.info(logText("Compiling..."));
1411
+ }
1412
+ const { schemaFileType: requestedSchemaFileType = "ts" } = options;
1413
+ const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
1414
+ if (!schemaFileType2) {
1415
+ throw new Error(`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`);
1416
+ }
1417
+ if (_ctx) {
1418
+ _ctx.schemaFileType = schemaFileType2;
1419
+ }
1420
+ let schemaExists = true;
1421
+ try {
1422
+ getSchemaPath({ projectDir: tinaPath });
1423
+ } catch {
1424
+ schemaExists = false;
1425
+ }
1426
+ if (!schemaExists) {
1427
+ logger.info(dangerText(`
1428
+ .tina/schema.${schemaFileType2} not found, Creating one for you...
1429
+ See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
1430
+ `));
1431
+ const file = import_path5.default.join(tinaPath, `schema.${schemaFileType2}`);
1432
+ await import_fs_extra4.default.ensureFile(file);
1433
+ await import_fs_extra4.default.writeFile(file, defaultSchema(import_path5.default.sep));
1434
+ }
1435
+ try {
1436
+ await transpile(tinaPath, tinaTempPath, options.verbose);
1437
+ } catch (e) {
1438
+ await cleanup({ tinaTempPath });
1439
+ throw new BuildSchemaError(e);
1440
+ }
1441
+ Object.keys(require.cache).map((key) => {
1442
+ if (key.startsWith(tinaTempPath)) {
1443
+ delete require.cache[require.resolve(key)];
1553
1444
  }
1445
+ });
1446
+ try {
1447
+ const schemaFunc = require(import_path5.default.join(tinaTempPath, "schema.js"));
1448
+ const schemaObject = schemaFunc.default;
1449
+ await import_fs_extra4.default.outputFile(import_path5.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
1450
+ await cleanup({ tinaTempPath });
1451
+ } catch (e) {
1452
+ await cleanup({ tinaTempPath });
1453
+ if (e instanceof Error) {
1454
+ if (e.name === "TinaSchemaValidationError") {
1455
+ throw e;
1456
+ }
1457
+ }
1458
+ throw new ExecuteSchemaError(e);
1554
1459
  }
1555
- return error;
1556
1460
  };
1557
- var transformDocumentIntoMutationRequestPayload = (document, instructions, defaults) => {
1558
- const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
1559
- const params = transformParams(rest);
1560
- const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
1561
- return instructions.includeCollection ? { [_collection]: __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate)) } : __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate));
1461
+ var transpile = async (projectDir, tempDir, verbose) => {
1462
+ if (verbose)
1463
+ logger.info(logText("Building javascript..."));
1464
+ const packageJSON = JSON.parse(import_fs_extra4.default.readFileSync(packageJSONFilePath).toString() || "{}");
1465
+ const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
1466
+ const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
1467
+ const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
1468
+ const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
1469
+ const inputFile = getSchemaPath({ projectDir });
1470
+ const outputPath = import_path5.default.join(tempDir, "schema.js");
1471
+ await (0, import_esbuild.build)({
1472
+ bundle: true,
1473
+ platform: "neutral",
1474
+ target: ["node10.4"],
1475
+ entryPoints: [inputFile],
1476
+ treeShaking: true,
1477
+ external: [...external, "./node_modules/*"],
1478
+ loader: loaders,
1479
+ outfile: outputPath
1480
+ });
1481
+ if (verbose)
1482
+ logger.info(logText(`Javascript built`));
1483
+ };
1484
+ var defineSchema = (config) => {
1485
+ return config;
1486
+ };
1487
+ var loaders = {
1488
+ ".aac": "file",
1489
+ ".css": "file",
1490
+ ".eot": "file",
1491
+ ".flac": "file",
1492
+ ".gif": "file",
1493
+ ".jpeg": "file",
1494
+ ".jpg": "file",
1495
+ ".json": "json",
1496
+ ".mp3": "file",
1497
+ ".mp4": "file",
1498
+ ".ogg": "file",
1499
+ ".otf": "file",
1500
+ ".png": "file",
1501
+ ".svg": "file",
1502
+ ".ttf": "file",
1503
+ ".wav": "file",
1504
+ ".webm": "file",
1505
+ ".webp": "file",
1506
+ ".woff": "file",
1507
+ ".woff2": "file",
1508
+ ".js": "jsx",
1509
+ ".jsx": "jsx",
1510
+ ".tsx": "tsx"
1562
1511
  };
1563
- var transformParams = (data) => {
1564
- if (["string", "number", "boolean"].includes(typeof data)) {
1565
- return data;
1566
- }
1567
- if (Array.isArray(data)) {
1568
- return data.map((item) => transformParams(item));
1512
+
1513
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
1514
+ var import_datalayer3 = __toModule(require("@tinacms/datalayer"));
1515
+ var import_graphql10 = __toModule(require("@tinacms/graphql"));
1516
+
1517
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/lock.ts
1518
+ var AsyncLock = class {
1519
+ constructor() {
1520
+ this.disable = () => {
1521
+ };
1522
+ this.promise = Promise.resolve();
1569
1523
  }
1570
- try {
1571
- (0, import_graphql9.assertShape)(data, (yup) => yup.object({ _template: yup.string().required() }));
1572
- const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
1573
- const nested = transformParams(rest);
1574
- return { [_template]: nested };
1575
- } catch (e) {
1576
- if (e.message === "Failed to assertShape - _template is a required field") {
1577
- if (!data) {
1578
- return void 0;
1579
- return [];
1580
- }
1581
- const accum = {};
1582
- Object.entries(data).map(([keyName, value]) => {
1583
- accum[keyName] = transformParams(value);
1584
- });
1585
- return accum;
1586
- } else {
1587
- if (!data) {
1588
- return void 0;
1589
- return [];
1590
- }
1591
- throw e;
1592
- }
1524
+ enable() {
1525
+ this.promise = new Promise((resolve2) => this.disable = resolve2);
1593
1526
  }
1594
1527
  };
1595
- function filterObject(obj) {
1596
- const ret = {};
1597
- Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
1598
- return ret;
1599
- }
1600
1528
 
1601
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
1602
- var import_chalk5 = __toModule(require("chalk"));
1603
- var import_prompts2 = __toModule(require("prompts"));
1529
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
1604
1530
  var import_metrics3 = __toModule(require("@tinacms/metrics"));
1605
- var rootPath = process.cwd();
1606
- var audit = async (ctx, next, options) => {
1607
- const telemetry = new import_metrics3.Telemetry({ disabled: options.noTelemetry });
1608
- await telemetry.submitRecord({
1531
+ var import_chalk6 = __toModule(require("chalk"));
1532
+ var import_child_process = __toModule(require("child_process"));
1533
+ var import_chokidar = __toModule(require("chokidar"));
1534
+ var import_path6 = __toModule(require("path"));
1535
+ var lock = new AsyncLock();
1536
+ var gqlPackageFile = require.resolve("@tinacms/graphql");
1537
+ async function startServer(_ctx, _next, {
1538
+ port = 4001,
1539
+ command,
1540
+ noWatch,
1541
+ experimentalData,
1542
+ noSDK,
1543
+ noTelemetry,
1544
+ watchFolders,
1545
+ verbose
1546
+ }) {
1547
+ lock.disable();
1548
+ const rootPath2 = process.cwd();
1549
+ const t = new import_metrics3.Telemetry({ disabled: Boolean(noTelemetry) });
1550
+ t.submitRecord({
1609
1551
  event: {
1610
- name: "tinacms:cli:audit:invoke",
1611
- clean: Boolean(options.clean),
1612
- useDefaults: Boolean(options.useDefaultValues)
1552
+ name: "tinacms:cli:server:start:invoke"
1613
1553
  }
1614
1554
  });
1615
- if (options.clean) {
1616
- logger.info(`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${import_chalk5.default.bold("clean git tree")} so unwanted changes can be undone.
1555
+ if (!process.env.CI && !noWatch) {
1556
+ await resetGeneratedFolder();
1557
+ }
1558
+ const bridge = new import_datalayer3.FilesystemBridge(rootPath2);
1559
+ const store = experimentalData ? new import_datalayer3.LevelStore(rootPath2) : new import_datalayer3.FilesystemStore({ rootPath: rootPath2 });
1560
+ const shouldBuild = bridge.supportsBuilding();
1561
+ const database = await (0, import_graphql10.createDatabase)({ store, bridge });
1562
+ const startSubprocess = () => {
1563
+ if (typeof command === "string") {
1564
+ const commands = command.split(" ");
1565
+ const firstCommand = commands[0];
1566
+ const args = commands.slice(1) || [];
1567
+ const ps = import_child_process.default.spawn(firstCommand, args, {
1568
+ stdio: "inherit",
1569
+ shell: true
1570
+ });
1571
+ ps.on("error", (code) => {
1572
+ logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
1573
+ logger.error(`name: ${code.name}
1574
+ message: ${code.message}
1617
1575
 
1618
- `);
1619
- const res = await (0, import_prompts2.default)({
1620
- name: "useClean",
1621
- type: "confirm",
1622
- message: `Do you want to continue?`
1576
+ stack: ${code.stack || "No stack was provided"}`);
1577
+ });
1578
+ ps.on("close", (code) => {
1579
+ logger.info(`child process exited with code ${code}`);
1580
+ process.exit(code);
1581
+ });
1582
+ }
1583
+ };
1584
+ let ready = false;
1585
+ const build2 = async (noSDK2) => {
1586
+ await lock.promise;
1587
+ lock.enable();
1588
+ try {
1589
+ if (!process.env.CI && !noWatch) {
1590
+ await resetGeneratedFolder();
1591
+ }
1592
+ const database2 = await (0, import_graphql10.createDatabase)({ store, bridge });
1593
+ await compile(null, null, { verbose });
1594
+ const schema = await (0, import_graphql10.buildSchema)(rootPath2, database2);
1595
+ await genTypes({ schema }, () => {
1596
+ }, { noSDK: noSDK2, verbose });
1597
+ } catch (error) {
1598
+ throw error;
1599
+ } finally {
1600
+ lock.disable();
1601
+ }
1602
+ };
1603
+ const foldersToWatch = (watchFolders || []).map((x) => import_path6.default.join(rootPath2, x));
1604
+ if (!noWatch && !process.env.CI) {
1605
+ import_chokidar.default.watch([
1606
+ ...foldersToWatch,
1607
+ `${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
1608
+ ], {
1609
+ ignored: [
1610
+ "**/node_modules/**/*",
1611
+ "**/.next/**/*",
1612
+ `${import_path6.default.resolve(rootPath2)}/.tina/__generated__/**/*`
1613
+ ]
1614
+ }).on("ready", async () => {
1615
+ if (verbose)
1616
+ console.log("Generating Tina config");
1617
+ try {
1618
+ if (shouldBuild) {
1619
+ await build2(noSDK);
1620
+ }
1621
+ ready = true;
1622
+ startSubprocess();
1623
+ } catch (e) {
1624
+ handleServerErrors(e);
1625
+ console.log(e);
1626
+ process.exit(0);
1627
+ }
1628
+ }).on("all", async () => {
1629
+ if (ready) {
1630
+ logger.info("Tina change detected, regenerating config");
1631
+ try {
1632
+ if (shouldBuild) {
1633
+ await build2(noSDK);
1634
+ }
1635
+ } catch (e) {
1636
+ handleServerErrors(e);
1637
+ t.submitRecord({
1638
+ event: {
1639
+ name: "tinacms:cli:server:error",
1640
+ errorMessage: e.message
1641
+ }
1642
+ });
1643
+ }
1644
+ }
1623
1645
  });
1624
- if (!res.useClean) {
1625
- logger.warn(import_chalk5.default.yellowBright("\u26A0\uFE0F Audit not complete"));
1626
- process.exit(0);
1646
+ } else {
1647
+ if (shouldBuild) {
1648
+ await build2(noSDK);
1627
1649
  }
1628
1650
  }
1629
- if (options.useDefaultValues && !options.clean) {
1630
- logger.warn(import_chalk5.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
1631
- }
1632
- const bridge = options.clean ? new import_datalayer3.FilesystemBridge(rootPath) : new import_datalayer3.AuditFileSystemBridge(rootPath);
1633
- const store = options.clean ? new import_datalayer3.FilesystemStore({ rootPath }) : new import_datalayer3.AuditFilesystemStore({ rootPath });
1634
- const database = await (0, import_graphql10.createDatabase)({ store, bridge });
1635
- const schema = await database.getSchema();
1636
- const collections = schema.getCollections();
1637
- let warning = false;
1638
- let error = false;
1639
- for (let i = 0; i < collections.length; i++) {
1640
- const collection = collections[i];
1641
- const returnWarning = await auditCollection({
1642
- collection,
1643
- database,
1644
- rootPath,
1645
- useDefaultValues: options.useDefaultValues
1651
+ const state = {
1652
+ server: null,
1653
+ sockets: []
1654
+ };
1655
+ let isReady = false;
1656
+ const start = async () => {
1657
+ const s = (init_server(), server_exports);
1658
+ state.server = await s.default(database);
1659
+ state.server.listen(port, () => {
1660
+ const altairUrl = `http://localhost:${port}/altair/`;
1661
+ const cmsUrl = `[your-development-url]/admin`;
1662
+ if (verbose)
1663
+ logger.info(`Started Filesystem GraphQL server on port: ${port}`);
1664
+ logger.info(`Visit the GraphQL playground at ${import_chalk6.default.underline.blueBright(altairUrl)}
1665
+ or`);
1666
+ logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
1667
+ `);
1646
1668
  });
1647
- const returnError = await auditDocuments({
1648
- collection,
1649
- database,
1650
- rootPath,
1651
- useDefaultValues: options.useDefaultValues
1669
+ state.server.on("error", function(e) {
1670
+ if (e.code === "EADDRINUSE") {
1671
+ logger.error(dangerText(`Port 4001 already in use`));
1672
+ process.exit();
1673
+ }
1674
+ throw e;
1675
+ });
1676
+ state.server.on("connection", (socket) => {
1677
+ state.sockets.push(socket);
1678
+ });
1679
+ };
1680
+ const restart = async () => {
1681
+ logger.info("Detected change to gql package, restarting...");
1682
+ delete require.cache[gqlPackageFile];
1683
+ state.sockets.forEach((socket) => {
1684
+ if (socket.destroyed === false) {
1685
+ socket.destroy();
1686
+ }
1687
+ });
1688
+ state.sockets = [];
1689
+ state.server.close(() => {
1690
+ logger.info("Server closed");
1691
+ start();
1692
+ });
1693
+ };
1694
+ if (!noWatch && !process.env.CI) {
1695
+ import_chokidar.default.watch([gqlPackageFile]).on("ready", async () => {
1696
+ isReady = true;
1697
+ start();
1698
+ }).on("all", async () => {
1699
+ if (isReady) {
1700
+ restart();
1701
+ }
1652
1702
  });
1653
- warning = warning || returnWarning;
1654
- error = error || returnError;
1655
- }
1656
- ctx.warning = warning;
1657
- ctx.error = error;
1658
- next();
1659
- };
1660
- var printFinalMessage = async (ctx, next, _options) => {
1661
- if (ctx.error) {
1662
- logger.error(import_chalk5.default.redBright(`\u203C\uFE0F Audit ${import_chalk5.default.bold("failed")} with errors`));
1663
- } else if (ctx.warning) {
1664
- logger.warn(import_chalk5.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
1665
1703
  } else {
1666
- logger.info(import_chalk5.default.greenBright("\u2705 Audit passed"));
1704
+ if (process.env.CI) {
1705
+ logger.info("Detected CI environment, omitting watch commands...");
1706
+ }
1707
+ start();
1708
+ startSubprocess();
1667
1709
  }
1668
- next();
1669
- };
1710
+ }
1670
1711
 
1671
1712
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
1672
- var import_chalk6 = __toModule(require("chalk"));
1673
1713
  var CMD_GEN_TYPES = "schema:types";
1674
1714
  var CMD_START_SERVER = "server:start";
1675
1715
  var CMD_COMPILE_MODELS = "schema:compile";
@@ -1715,6 +1755,10 @@ var watchFileOption = {
1715
1755
  name: "-w, --watchFolders [folders...]",
1716
1756
  description: "a list of folders (relative to where this is being run) that the cli will watch for changes"
1717
1757
  };
1758
+ var verboseOption = {
1759
+ name: "-v, --verbose",
1760
+ description: "increase verbosity of logged output"
1761
+ };
1718
1762
  var baseCmds = [
1719
1763
  {
1720
1764
  command: CMD_START_SERVER,
@@ -1726,7 +1770,8 @@ var baseCmds = [
1726
1770
  noWatchOption,
1727
1771
  noSDKCodegenOption,
1728
1772
  noTelemetryOption,
1729
- watchFileOption
1773
+ watchFileOption,
1774
+ verboseOption
1730
1775
  ],
1731
1776
  action: (options) => chain([startServer], options)
1732
1777
  },
@@ -1777,7 +1822,7 @@ var baseCmds = [
1777
1822
  genTypes,
1778
1823
  async (_ctx, next) => {
1779
1824
  logger.level = "info";
1780
- logger.info(import_chalk6.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
1825
+ logger.info(import_chalk7.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
1781
1826
  next();
1782
1827
  },
1783
1828
  audit,