@tinacms/cli 0.61.27 → 0.62.1

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
@@ -70,11 +70,11 @@ var init_utils = __esm({
70
70
  });
71
71
 
72
72
  // src/server/models/media.ts
73
- var import_fs_extra8, import_path11, MediaModel;
73
+ var import_fs_extra7, import_path9, MediaModel;
74
74
  var init_media = __esm({
75
75
  "src/server/models/media.ts"() {
76
- import_fs_extra8 = __toModule(require("fs-extra"));
77
- import_path11 = __toModule(require("path"));
76
+ import_fs_extra7 = __toModule(require("fs-extra"));
77
+ import_path9 = __toModule(require("path"));
78
78
  init_utils();
79
79
  MediaModel = class {
80
80
  constructor({ publicFolder, mediaRoot }) {
@@ -83,12 +83,12 @@ var init_media = __esm({
83
83
  }
84
84
  async listMedia(args) {
85
85
  try {
86
- const folderPath = (0, import_path11.join)(this.publicFolder, this.mediaRoot, args.searchPath);
86
+ const folderPath = (0, import_path9.join)(this.publicFolder, this.mediaRoot, args.searchPath);
87
87
  const searchPath = parseMediaFolder(args.searchPath);
88
- const filesStr = await import_fs_extra8.default.readdir(folderPath);
88
+ const filesStr = await import_fs_extra7.default.readdir(folderPath);
89
89
  const filesProm = filesStr.map(async (file) => {
90
- const filePath = (0, import_path11.join)(folderPath, file);
91
- const stat = await import_fs_extra8.default.stat(filePath);
90
+ const filePath = (0, import_path9.join)(folderPath, file);
91
+ const stat = await import_fs_extra7.default.stat(filePath);
92
92
  let src = `/${file}`;
93
93
  const isFile = stat.isFile();
94
94
  if (!isFile) {
@@ -144,9 +144,9 @@ var init_media = __esm({
144
144
  }
145
145
  async deleteMedia(args) {
146
146
  try {
147
- const file = (0, import_path11.join)(this.publicFolder, this.mediaRoot, args.searchPath);
148
- await import_fs_extra8.default.stat(file);
149
- await import_fs_extra8.default.remove(file);
147
+ const file = (0, import_path9.join)(this.publicFolder, this.mediaRoot, args.searchPath);
148
+ await import_fs_extra7.default.stat(file);
149
+ await import_fs_extra7.default.remove(file);
150
150
  return { ok: true };
151
151
  } catch (error) {
152
152
  console.error(error);
@@ -158,15 +158,15 @@ var init_media = __esm({
158
158
  });
159
159
 
160
160
  // src/server/routes/index.ts
161
- var import_express, import_path12, import_multer, createMediaRouter;
161
+ var import_express, import_path10, import_multer, createMediaRouter;
162
162
  var init_routes = __esm({
163
163
  "src/server/routes/index.ts"() {
164
164
  import_express = __toModule(require("express"));
165
- import_path12 = __toModule(require("path"));
165
+ import_path10 = __toModule(require("path"));
166
166
  import_multer = __toModule(require("multer"));
167
167
  init_media();
168
168
  createMediaRouter = (config2) => {
169
- const mediaFolder = (0, import_path12.join)(process.cwd(), config2.publicFolder, config2.mediaRoot);
169
+ const mediaFolder = (0, import_path10.join)(process.cwd(), config2.publicFolder, config2.mediaRoot);
170
170
  const storage = import_multer.default.diskStorage({
171
171
  destination: function(req, file, cb) {
172
172
  cb(null, mediaFolder);
@@ -302,7 +302,7 @@ var commander = __toModule(require("commander"));
302
302
 
303
303
  // package.json
304
304
  var name = "@tinacms/cli";
305
- var version = "0.61.27";
305
+ var version = "0.62.1";
306
306
 
307
307
  // src/cmds/audit/audit.ts
308
308
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -515,872 +515,274 @@ var printFinalMessage = async (ctx, next, _options) => {
515
515
  next();
516
516
  };
517
517
 
518
- // src/cmds/init/index.ts
519
- var import_path3 = __toModule(require("path"));
520
-
521
- // src/cmds/init/setup-files/index.ts
522
- var import_chalk4 = __toModule(require("chalk"));
523
- var adminPage = `import { TinaAdmin } from 'tinacms';
524
- export default TinaAdmin;
525
- `;
526
- var blogPost = `---
527
- title: Vote For Pedro
528
- ---
529
- # Welcome to the blog.
530
-
531
- > 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}.
532
-
533
- # Dixi gaude Arethusa
518
+ // src/cmds/baseCmds.ts
519
+ var import_config2 = __toModule(require("dotenv/config"));
534
520
 
535
- <PageSection heading="Oscula mihi" content="Lorem markdownum numerabilis armentorum platanus, cultros coniunx sibi per
536
- silvas, nostris clausit sequemur diverso scopulosque. Fecit tum alta sed non
537
- falcato murmura, geminas donata Amyntore, quoque Nox. Invitam inquit, modo
538
- nocte; ut ignis faciemque manes in imagine sinistra ut mucrone non ramos
539
- sepulcro supplex. Crescentesque populos motura, fit cumque. Verumque est; retro
540
- sibi tristia bracchia Aetola telae caruerunt et."/>
521
+ // src/middleware.ts
522
+ var chain = async (cmds, options) => {
523
+ const ctx = {};
524
+ const next = async (middlewareIndex) => {
525
+ if (middlewareIndex >= cmds.length) {
526
+ process.exit(0);
527
+ }
528
+ try {
529
+ await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
530
+ } catch (err) {
531
+ console.error(` ${dangerText(err)}`);
532
+ if (err.stack) {
533
+ console.log(err.stack);
534
+ }
535
+ process.exit(1);
536
+ }
537
+ };
538
+ if (cmds.length > 0) {
539
+ await next(0);
540
+ }
541
+ };
541
542
 
543
+ // src/cmds/baseCmds.ts
544
+ var import_chalk5 = __toModule(require("chalk"));
542
545
 
543
- ## Mutato fefellimus sit demisit aut alterius sollicito
546
+ // src/cmds/compile/index.ts
547
+ var _ = __toModule(require("lodash"));
544
548
 
545
- Phaethonteos vestes quem involvite iuvenca; furiali anne: sati totumque,
546
- **corpora** cum rapacibus nunc! Nervis repetatne, miserabile doleas, deprensum
547
- hunc, fluctus Threicio, ad urbes, magicaeque, quid. Per credensque series adicis
548
- poteram [quidem](#)! Iam uni mensas victrix
549
- vittas ut flumina Satyri adulter; bellum iacet domitae repercusso truncis urnis
550
- mille rigidi sub taurum.
549
+ // src/cmds/start-server/errors/index.ts
550
+ var import_graphql3 = __toModule(require("@tinacms/graphql"));
551
+ var BuildSchemaError = class extends Error {
552
+ constructor(message) {
553
+ super(message);
554
+ this.name = "BuildSchemaError";
555
+ }
556
+ };
557
+ var ExecuteSchemaError = class extends Error {
558
+ constructor(message) {
559
+ super(message);
560
+ this.name = "ExecuteSchemaError";
561
+ }
562
+ };
563
+ var handleServerErrors = (e) => {
564
+ if (e.name === "BuildSchemaError") {
565
+ logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
566
+ Error Message Below
567
+ ${e}`);
568
+ } else if (e.name === "ExecuteSchemaError") {
569
+ logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
570
+ Error Message Below
571
+ ${e}`);
572
+ } else if (e.name === "TinaSchemaValidationError") {
573
+ logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
574
+ Error Message Below
575
+ ${e}`);
576
+ } else if (e instanceof import_graphql3.TinaFetchError) {
577
+ (0, import_graphql3.handleFetchErrorError)(e, true);
578
+ } else {
579
+ logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
580
+ ${e.message}`);
581
+ }
582
+ };
551
583
 
584
+ // src/cmds/compile/index.ts
585
+ var import_fs_extra2 = __toModule(require("fs-extra"));
586
+ var import_path3 = __toModule(require("path"));
587
+ var import_esbuild = __toModule(require("esbuild"));
552
588
 
553
- `;
554
- var nextPostPage = ({
555
- usingSrc
556
- }) => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
557
- // This is a demo file once you have tina setup feel free to delete this file
558
-
559
- import Head from 'next/head'
560
- import { useTina } from 'tinacms/dist/edit-state'
561
- import { TinaMarkdown } from 'tinacms/dist/rich-text'
562
- import client from '${usingSrc ? "../" : ""}../../../.tina/__generated__/client'
563
-
564
- const BlogPage = (props) => {
565
- const { data } = useTina({
566
- query: props.query,
567
- variables: props.variables,
568
- data: props.data,
569
- })
570
-
571
- return (
572
- <>
573
- <Head>
574
- {/* Tailwind CDN */}
575
- <link
576
- rel="stylesheet"
577
- href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.7/tailwind.min.css"
578
- integrity="sha512-y6ZMKFUQrn+UUEVoqYe8ApScqbjuhjqzTuwUMEGMDuhS2niI8KA3vhH2LenreqJXQS+iIXVTRL2iaNfJbDNA1Q=="
579
- crossOrigin="anonymous"
580
- referrerPolicy="no-referrer"
581
- />
582
- </Head>
583
- <div>
584
- <div
585
- style={{
586
- textAlign: 'center',
587
- }}
588
- >
589
- <h1 className="text-3xl m-8 text-center leading-8 font-extrabold tracking-tight text-gray-900 sm:text-4xl">
590
- {data.post.title}
591
- </h1>
592
- <ContentSection content={data.post.body}></ContentSection>
593
- </div>
594
- <div className="bg-green-100 text-center">
595
- Lost and looking for a place to start?
596
- <a
597
- href="https://tina.io/guides/tina-cloud/getting-started/overview/"
598
- className="text-blue-500 underline"
599
- >
600
- {' '}
601
- Check out this guide
602
- </a>{' '}
603
- to see how add TinaCMS to an existing Next.js site.
604
- </div>
605
- </div>
606
- </>
607
- )
589
+ // src/lib/getPath.ts
590
+ var import_path2 = __toModule(require("path"));
591
+ var import_fs_extra = __toModule(require("fs-extra"));
592
+ var fileExists = ({
593
+ projectDir,
594
+ filename,
595
+ allowedTypes
596
+ }) => {
597
+ if (!import_fs_extra.default.existsSync(projectDir)) {
598
+ return false;
608
599
  }
609
-
610
- export const getStaticProps = async ({ params }) => {
611
- let data = {}
612
- let query = {}
613
- let variables = { relativePath: \`\${params.filename}.mdx\` }
614
- try {
615
- const res = await client.queries.post(variables)
616
- query = res.query
617
- data = res.data
618
- variables = res.variables
619
- } catch {
620
- // swallow errors related to document creation
600
+ const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
601
+ let inputFile = void 0;
602
+ filePaths.every((path9) => {
603
+ if (import_fs_extra.default.existsSync(path9)) {
604
+ inputFile = path9;
605
+ return false;
621
606
  }
622
-
623
- return {
624
- props: {
625
- variables: variables,
626
- data: data,
627
- query: query,
628
- //myOtherProp: 'some-other-data',
629
- },
607
+ return true;
608
+ });
609
+ return Boolean(inputFile);
610
+ };
611
+ var getPath = ({
612
+ projectDir,
613
+ filename,
614
+ allowedTypes,
615
+ errorMessage
616
+ }) => {
617
+ if (!import_fs_extra.default.existsSync(projectDir)) {
618
+ throw new Error(errorMessage);
619
+ }
620
+ const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
621
+ let inputFile = void 0;
622
+ filePaths.every((path9) => {
623
+ if (import_fs_extra.default.existsSync(path9)) {
624
+ inputFile = path9;
625
+ return false;
630
626
  }
627
+ return true;
628
+ });
629
+ if (!inputFile) {
630
+ throw new Error(errorMessage);
631
631
  }
632
-
633
- export const getStaticPaths = async () => {
634
- const postsListData = await client.queries.postConnection()
635
-
636
- return {
637
- paths: postsListData.data.postConnection.edges.map((post) => ({
638
- params: { filename: post.node._sys.filename },
639
- })),
640
- fallback: false,
632
+ return inputFile;
633
+ };
634
+ var getClientPath = ({ projectDir }) => {
635
+ const filename = "client";
636
+ const allowedTypes = ["js", "ts"];
637
+ const errorMessage = "Must provide a `.tina/client.{ts,js}`";
638
+ return getPath({ projectDir, filename, allowedTypes, errorMessage });
639
+ };
640
+
641
+ // src/cmds/compile/index.ts
642
+ var generatedFilesToRemove = [
643
+ "_graphql.json",
644
+ "__lookup.json",
645
+ "__schema.json",
646
+ "frags.gql",
647
+ "queries.gql",
648
+ "schema.gql",
649
+ "db"
650
+ ];
651
+ var resetGeneratedFolder = async ({
652
+ tinaGeneratedPath,
653
+ usingTs,
654
+ isBuild
655
+ }) => {
656
+ try {
657
+ if (isBuild) {
658
+ await import_fs_extra2.default.emptyDir(tinaGeneratedPath);
659
+ } else {
660
+ for (let index = 0; index < generatedFilesToRemove.length; index++) {
661
+ const file = generatedFilesToRemove[index];
662
+ if (file === "db") {
663
+ try {
664
+ await import_fs_extra2.default.remove(import_path3.default.join(tinaGeneratedPath, file));
665
+ } catch (_e) {
666
+ }
667
+ } else {
668
+ await import_fs_extra2.default.remove(import_path3.default.join(tinaGeneratedPath, file));
669
+ }
670
+ }
641
671
  }
672
+ } catch (e) {
673
+ console.log(e);
642
674
  }
643
-
644
- export default BlogPage
645
-
646
- const PageSection = (props) => {
647
- return (
648
- <>
649
- <h2>{props.heading}</h2>
650
- <p>{props.content}</p>
651
- </>
652
- )
675
+ await import_fs_extra2.default.mkdirp(tinaGeneratedPath);
676
+ const ext = usingTs ? "ts" : "js";
677
+ if (!await import_fs_extra2.default.pathExists(import_path3.default.join(tinaGeneratedPath, `types.${ext}`))) {
678
+ await import_fs_extra2.default.writeFile(import_path3.default.join(tinaGeneratedPath, `types.${ext}`), `
679
+ export const queries = (client)=>({})
680
+ `);
653
681
  }
654
-
655
- const components = {
656
- PageSection: PageSection,
682
+ if (!await import_fs_extra2.default.pathExists(import_path3.default.join(tinaGeneratedPath, `client.${ext}`))) {
683
+ await import_fs_extra2.default.writeFile(import_path3.default.join(tinaGeneratedPath, `client.${ext}`), `
684
+ export const client = ()=>{}
685
+ export default client
686
+ `);
657
687
  }
658
-
659
- const ContentSection = ({ content }) => {
660
- return (
661
- <div className="relative py-16 bg-white overflow-hidden">
662
- <div className="hidden lg:block lg:absolute lg:inset-y-0 lg:h-full lg:w-full">
663
- <div
664
- className="relative h-full text-lg max-w-prose mx-auto"
665
- aria-hidden="true"
666
- >
667
- <svg
668
- className="absolute top-12 left-full transform translate-x-32"
669
- width={404}
670
- height={384}
671
- fill="none"
672
- viewBox="0 0 404 384"
673
- >
674
- <defs>
675
- <pattern
676
- id="74b3fd99-0a6f-4271-bef2-e80eeafdf357"
677
- x={0}
678
- y={0}
679
- width={20}
680
- height={20}
681
- patternUnits="userSpaceOnUse"
682
- >
683
- <rect
684
- x={0}
685
- y={0}
686
- width={4}
687
- height={4}
688
- className="text-gray-200"
689
- fill="currentColor"
690
- />
691
- </pattern>
692
- </defs>
693
- <rect
694
- width={404}
695
- height={384}
696
- fill="url(#74b3fd99-0a6f-4271-bef2-e80eeafdf357)"
697
- />
698
- </svg>
699
- <svg
700
- className="absolute top-1/2 right-full transform -translate-y-1/2 -translate-x-32"
701
- width={404}
702
- height={384}
703
- fill="none"
704
- viewBox="0 0 404 384"
705
- >
706
- <defs>
707
- <pattern
708
- id="f210dbf6-a58d-4871-961e-36d5016a0f49"
709
- x={0}
710
- y={0}
711
- width={20}
712
- height={20}
713
- patternUnits="userSpaceOnUse"
714
- >
715
- <rect
716
- x={0}
717
- y={0}
718
- width={4}
719
- height={4}
720
- className="text-gray-200"
721
- fill="currentColor"
722
- />
723
- </pattern>
724
- </defs>
725
- <rect
726
- width={404}
727
- height={384}
728
- fill="url(#f210dbf6-a58d-4871-961e-36d5016a0f49)"
729
- />
730
- </svg>
731
- <svg
732
- className="absolute bottom-12 left-full transform translate-x-32"
733
- width={404}
734
- height={384}
735
- fill="none"
736
- viewBox="0 0 404 384"
737
- >
738
- <defs>
739
- <pattern
740
- id="d3eb07ae-5182-43e6-857d-35c643af9034"
741
- x={0}
742
- y={0}
743
- width={20}
744
- height={20}
745
- patternUnits="userSpaceOnUse"
746
- >
747
- <rect
748
- x={0}
749
- y={0}
750
- width={4}
751
- height={4}
752
- className="text-gray-200"
753
- fill="currentColor"
754
- />
755
- </pattern>
756
- </defs>
757
- <rect
758
- width={404}
759
- height={384}
760
- fill="url(#d3eb07ae-5182-43e6-857d-35c643af9034)"
761
- />
762
- </svg>
763
- </div>
764
- </div>
765
- <div className="relative px-4 sm:px-6 lg:px-8">
766
- <div className="text-lg max-w-prose mx-auto">
767
- <TinaMarkdown components={components} content={content} />
768
- </div>
769
- </div>
770
- </div>
771
- )
772
- }`;
773
- var AppJsContent = (usingSrc, extraImports) => {
774
- const importLine = `import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`;
775
- return `${importLine}
776
- ${extraImports || ""}
777
-
778
- const App = ({ Component, pageProps }) => {
779
- return (
780
- <Tina>
781
- <Component {...pageProps} />
782
- </Tina>
783
- )
784
- }
785
-
786
- export default App
787
- `;
688
+ await import_fs_extra2.default.outputFile(import_path3.default.join(tinaGeneratedPath, ".gitignore"), `app
689
+ db
690
+ prebuild
691
+ client.ts
692
+ client.js
693
+ types.ts
694
+ types.js
695
+ types.d.ts
696
+ frags.gql
697
+ queries.gql
698
+ schema.gql
699
+ out.jsx
700
+ `);
788
701
  };
789
- var AppJsContentPrintout = (usingSrc, extraImports) => {
790
- const importLine = import_chalk4.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
791
- return `${importLine}
792
- ${extraImports || ""}
793
-
794
- const App = ({ Component, pageProps }) => {
795
- return (
796
- ${import_chalk4.default.green("+ <Tina>")}
797
- <Component {...pageProps} />
798
- ${import_chalk4.default.green("+ </Tina>")}
799
- )
800
- }
801
-
802
- export default App
803
- `;
702
+ var cleanup = async ({ tinaTempPath }) => {
703
+ await import_fs_extra2.default.remove(tinaTempPath);
804
704
  };
805
-
806
- // src/cmds/init/setup-files/tinaProvider.ts
807
- var TinaProvider = `import TinaCMS from 'tinacms'
808
- import { tinaConfig } from '../schema.ts'
809
-
810
- // Importing the TinaProvider directly into your page will cause Tina to be added to the production bundle.
811
- // Instead, import the tina/provider/index default export to have it dynamially imported in edit-moode
812
- /**
813
- *
814
- * @private Do not import this directly, please import the dynamic provider instead
815
- */
816
- const TinaProvider = ({ children }) => {
817
- return <TinaCMS {...tinaConfig}>{children}</TinaCMS>
818
- }
819
-
820
- export default TinaProvider
821
- `;
822
- var TinaProviderDynamic = `import dynamic from 'next/dynamic'
823
- const TinaProvider = dynamic(() => import('./TinaProvider'), { ssr: false })
824
- import { TinaEditProvider } from 'tinacms/dist/edit-state'
825
-
826
- const DynamicTina = ({ children }) => {
827
- return (
828
- <>
829
- <TinaEditProvider editMode={<TinaProvider>{children}</TinaProvider>}>
830
- {children}
831
- </TinaEditProvider>
832
- </>
833
- )
834
- }
835
-
836
- export default DynamicTina
837
- `;
838
-
839
- // src/utils/script-helpers.ts
840
- function generateGqlScript(scriptValue) {
841
- return `tinacms dev -c "${scriptValue}"`;
842
- }
843
- function extendNextScripts(scripts) {
844
- return __spreadProps(__spreadValues({}, scripts), {
845
- dev: generateGqlScript((scripts == null ? void 0 : scripts.dev) || "next dev"),
846
- build: `tinacms build && ${(scripts == null ? void 0 : scripts.build) || "next build"}`,
847
- start: `tinacms build && ${(scripts == null ? void 0 : scripts.start) || "next start"}`
848
- });
849
- }
850
-
851
- // src/cmds/init/index.ts
852
- var import_fs_extra2 = __toModule(require("fs-extra"));
853
- var import_progress = __toModule(require("progress"));
854
- var import_metrics2 = __toModule(require("@tinacms/metrics"));
855
- var import_chalk5 = __toModule(require("chalk"));
856
- var import_path4 = __toModule(require("path"));
857
- var import_prompts2 = __toModule(require("prompts"));
858
-
859
- // src/lib/getPath.ts
860
- var import_path2 = __toModule(require("path"));
861
- var import_fs_extra = __toModule(require("fs-extra"));
862
- var fileExists = ({
863
- projectDir,
864
- filename,
865
- allowedTypes
866
- }) => {
867
- if (!import_fs_extra.default.existsSync(projectDir)) {
868
- return false;
705
+ var compileClient = async (ctx, next, options) => {
706
+ const root2 = ctx.rootPath;
707
+ if (!root2) {
708
+ throw new Error("ctx.rootPath has not been attached");
869
709
  }
870
- const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
871
- let inputFile = void 0;
872
- filePaths.every((path10) => {
873
- if (import_fs_extra.default.existsSync(path10)) {
874
- inputFile = path10;
875
- return false;
710
+ const tinaPath = import_path3.default.join(root2, ".tina");
711
+ const tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
712
+ const packageJSONFilePath = import_path3.default.join(root2, "package.json");
713
+ const tinaTempPath = import_path3.default.join(tinaGeneratedPath, "temp_client");
714
+ if (!options.clientFileType)
715
+ options = __spreadProps(__spreadValues({}, options), { clientFileType: "ts" });
716
+ if (options.verbose) {
717
+ logger.info(logText("Compiling Client..."));
718
+ }
719
+ const { clientFileType: requestedClientFileType = "ts" } = options;
720
+ const allowedFileTypes = ["ts", "js"];
721
+ if (allowedFileTypes.includes(requestedClientFileType) === false) {
722
+ throw new Error(`Requested schema file type '${requestedClientFileType}' is not valid. Supported schema file types: 'ts, js'`);
723
+ }
724
+ if (ctx) {
725
+ ctx.clientFileType = requestedClientFileType;
726
+ }
727
+ let clientExists = true;
728
+ const projectDir = import_path3.default.join(tinaPath, "__generated__");
729
+ try {
730
+ getClientPath({ projectDir });
731
+ } catch {
732
+ clientExists = false;
733
+ }
734
+ if (!clientExists) {
735
+ if (options.verbose) {
736
+ logger.info(logText(`.tina/client.${requestedClientFileType} not found, skipping compile client...`));
876
737
  }
877
- return true;
878
- });
879
- return Boolean(inputFile);
880
- };
881
- var getPath = ({
882
- projectDir,
883
- filename,
884
- allowedTypes,
885
- errorMessage
886
- }) => {
887
- if (!import_fs_extra.default.existsSync(projectDir)) {
888
- throw new Error(errorMessage);
738
+ return next();
889
739
  }
890
- const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
891
- let inputFile = void 0;
892
- filePaths.every((path10) => {
893
- if (import_fs_extra.default.existsSync(path10)) {
894
- inputFile = path10;
895
- return false;
740
+ try {
741
+ const define = {};
742
+ if (!process.env.NODE_ENV) {
743
+ define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
744
+ }
745
+ const inputFile = getClientPath({
746
+ projectDir
747
+ });
748
+ await transpile(inputFile, "client.js", tinaTempPath, options.verbose, define, packageJSONFilePath);
749
+ } catch (e) {
750
+ await cleanup({ tinaTempPath });
751
+ throw new BuildSchemaError(e);
752
+ }
753
+ Object.keys(require.cache).map((key) => {
754
+ if (key.startsWith(tinaTempPath)) {
755
+ delete require.cache[require.resolve(key)];
896
756
  }
897
- return true;
898
757
  });
899
- if (!inputFile) {
900
- throw new Error(errorMessage);
758
+ try {
759
+ const clientFunc = require(import_path3.default.join(tinaTempPath, "client.js"));
760
+ const client = clientFunc.default;
761
+ ctx.client = client;
762
+ await cleanup({ tinaTempPath });
763
+ } catch (e) {
764
+ await cleanup({ tinaTempPath });
765
+ if (e instanceof Error) {
766
+ if (e.name === "TinaSchemaValidationError") {
767
+ throw e;
768
+ }
769
+ }
770
+ throw new ExecuteSchemaError(e);
901
771
  }
902
- return inputFile;
903
- };
904
- var getClientPath = ({ projectDir }) => {
905
- const filename = "client";
906
- const allowedTypes = ["js", "ts"];
907
- const errorMessage = "Must provide a `.tina/client.{ts,js}`";
908
- return getPath({ projectDir, filename, allowedTypes, errorMessage });
909
- };
910
-
911
- // src/cmds/compile/defaultSchema.ts
912
- var defaultSchema = `
913
- import { defineSchema, defineConfig } from 'tinacms'
914
- import { client } from './__generated__/client'
915
-
916
-
917
- const branch =
918
- process.env.NEXT_PUBLIC_TINA_BRANCH ||
919
- process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||
920
- process.env.HEAD ||
921
- 'main'
922
- const schema = defineSchema({
923
- // See https://tina.io/docs/tina-cloud/connecting-site/ for more information about this config
924
- config: {
925
- token: '<Your Read Only Token>', // generated on app.tina.io,
926
- clientId: '<Your Client ID>', // generated on app.tina.io
927
- branch,
928
- },
929
- collections: [
930
- {
931
- label: 'Blog Posts',
932
- name: 'post',
933
- path: 'content/posts',
934
- format: 'mdx',
935
- ui: {
936
- router: ({ document }) => {
937
- // This can be used to add contextual editing to your site. See https://tina.io/docs/tinacms-context/#accessing-contextual-editing-from-the-cms for more information.
938
- return \`/demo/blog/\${document._sys.filename}\`
939
- },
940
- },
941
- fields: [
942
- {
943
- type: 'string',
944
- label: 'Title',
945
- name: 'title',
946
- },
947
- {
948
- type: 'rich-text',
949
- label: 'Blog Post Body',
950
- name: 'body',
951
- isBody: true,
952
- templates: [
953
- {
954
- name: 'PageSection',
955
- label: 'Page Section',
956
- fields: [
957
- {
958
- type: 'string',
959
- name: 'heading',
960
- label: 'Heading',
961
- },
962
- {
963
- type: 'string',
964
- name: 'content',
965
- label: 'Content',
966
- ui: {
967
- component: 'textarea',
968
- },
969
- },
970
- ],
971
- },
972
- ],
973
- },
974
- ],
975
- },
976
- ],
977
- })
978
-
979
- export default schema
980
-
981
- // Your tina config
982
-
983
- export const tinaConfig = defineConfig({
984
- client,
985
- schema,
986
- })
987
-
988
- `;
989
-
990
- // src/cmds/init/index.ts
991
- function execShellCommand(cmd) {
992
- const exec = require("child_process").exec;
993
- return new Promise((resolve2, reject) => {
994
- exec(cmd, (error, stdout, stderr) => {
995
- if (error) {
996
- reject(error);
997
- }
998
- resolve2(stdout ? stdout : stderr);
999
- });
1000
- });
1001
- }
1002
- async function initTina(ctx, next, options) {
1003
- const telemetry = new import_metrics2.Telemetry({ disabled: options.noTelemetry });
1004
- const root2 = ctx.rootPath;
1005
- const tsConfigPath = import_path3.default.join(root2, "tsconfig.json");
1006
- const usingTs = await import_fs_extra2.default.pathExists(tsConfigPath);
1007
- const schemaFileType2 = (options == null ? void 0 : options.schemaFileType) || usingTs ? "ts" : "js";
1008
- await telemetry.submitRecord({
1009
- event: {
1010
- name: "tinacms:cli:init:invoke",
1011
- schemaFileType: schemaFileType2
1012
- }
1013
- });
1014
- logger.info(successText("Setting up Tina..."));
1015
- const tinaPath = import_path3.default.join(root2, ".tina");
1016
- const schemaExists = fileExists({
1017
- projectDir: tinaPath,
1018
- filename: "schema",
1019
- allowedTypes: ["js", "jsx", "tsx", "ts"]
1020
- });
1021
- if (!schemaExists) {
1022
- const file = import_path3.default.join(tinaPath, `schema.${schemaFileType2}`);
1023
- await import_fs_extra2.default.ensureFile(file);
1024
- await import_fs_extra2.default.writeFile(file, defaultSchema);
1025
- }
1026
- next();
1027
- }
1028
- var MIN_REACT_VERSION = ">=16.14.0";
1029
- async function checkDeps(ctx, next, options) {
1030
- const bar = new import_progress.default("Checking dependencies. :prog", 1);
1031
- if (!import_fs_extra2.default.existsSync(packageJSONPath)) {
1032
- throw new Error("No package.json Found. Please run tinacms init at the root of your app");
1033
- }
1034
- const packageJSON = JSON.parse((await import_fs_extra2.default.readFileSync(packageJSONPath)).toString());
1035
- if (!checkPackage(packageJSON, "react") || !checkPackage(packageJSON, "react-dom")) {
1036
- const message = `Unable to initialize Tina due to outdated dependencies, try upgrading the following packages:
1037
- "react@${MIN_REACT_VERSION}"
1038
- "react-dom@${MIN_REACT_VERSION}"
1039
-
1040
- Then re-rerun "@tinacms/cli init"`;
1041
- throw new Error(message);
1042
- }
1043
- bar.tick({
1044
- prog: "\u2705"
1045
- });
1046
- logger.level = "fatal";
1047
- next();
1048
- }
1049
- var checkPackage = (packageJSON, packageName) => {
1050
- let strippedVersion;
1051
- Object.entries(packageJSON.dependencies).map(([depPackageName, version2]) => {
1052
- if (depPackageName === packageName) {
1053
- strippedVersion = version2.replace(/^[^a-zA-Z0-9]*|[^a-zA-Z0-9]*$/g, "");
1054
- }
1055
- });
1056
- if (!strippedVersion) {
1057
- throw new Error(`Please add ${packageName} to your project`);
1058
- }
1059
- return checkVersion(strippedVersion);
1060
- };
1061
- var checkVersion = (version2) => {
1062
- const majorMin = 16;
1063
- const minorMin = 14;
1064
- const parts = version2.split(".");
1065
- const major = Number(parts[0]);
1066
- const minor = Number(parts[1]);
1067
- if (parts.length === 1) {
1068
- if (isNaN(major)) {
1069
- return true;
1070
- } else if (major > majorMin) {
1071
- return true;
1072
- } else {
1073
- return false;
1074
- }
1075
- }
1076
- if (major > majorMin) {
1077
- return true;
1078
- } else if (major === majorMin) {
1079
- if (minor >= minorMin) {
1080
- return true;
1081
- } else {
1082
- return false;
1083
- }
1084
- } else {
1085
- return false;
1086
- }
1087
- };
1088
- async function installDeps(ctx, next, options) {
1089
- const bar = new import_progress.default("Installing Tina packages. This might take a moment... :prog", 2);
1090
- const deps = ["tinacms", "@tinacms/cli"];
1091
- bar.tick({
1092
- prog: ""
1093
- });
1094
- const installCMD = `yarn add ${deps.join(" ")}`;
1095
- await execShellCommand(installCMD);
1096
- bar.tick({
1097
- prog: "\u2705"
1098
- });
1099
- logger.level = "fatal";
1100
- next();
1101
- }
1102
- var baseDir = process.cwd();
1103
- var packageJSONPath = import_path4.default.join(baseDir, "package.json");
1104
- var blogContentPath = import_path4.default.join(baseDir, "content", "posts");
1105
- var blogPostPath = import_path4.default.join(blogContentPath, "HelloWorld.mdx");
1106
- var TinaFolder = import_path4.default.join(baseDir, ".tina");
1107
- var componentFolder = import_path4.default.join(TinaFolder, "components");
1108
- var TinaProviderPath = import_path4.default.join(componentFolder, "TinaProvider.js");
1109
- var TinaDynamicProvider = import_path4.default.join(componentFolder, "TinaDynamicProvider.js");
1110
- async function tinaSetup(_ctx, next, _options) {
1111
- const usingSrc = !import_fs_extra2.default.pathExistsSync(import_path4.default.join(baseDir, "pages"));
1112
- if (!import_fs_extra2.default.pathExistsSync(blogPostPath)) {
1113
- logger.info(logText("Adding a content folder..."));
1114
- import_fs_extra2.default.mkdirpSync(blogContentPath);
1115
- import_fs_extra2.default.writeFileSync(blogPostPath, blogPost);
1116
- }
1117
- if (!import_fs_extra2.default.existsSync(TinaProviderPath) && !import_fs_extra2.default.existsSync(TinaDynamicProvider)) {
1118
- import_fs_extra2.default.mkdirpSync(componentFolder);
1119
- import_fs_extra2.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.usingTs ? "ts" : "js"}'`));
1120
- import_fs_extra2.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
1121
- }
1122
- logger.level = "info";
1123
- const pagesPath = import_path4.default.join(baseDir, usingSrc ? "src" : "", "pages");
1124
- const appPath = import_path4.default.join(pagesPath, "_app.js");
1125
- const appPathTS = import_path4.default.join(pagesPath, "_app.tsx");
1126
- const appExtension = import_fs_extra2.default.existsSync(appPath) ? ".js" : ".tsx";
1127
- if (!import_fs_extra2.default.pathExistsSync(appPath) && !import_fs_extra2.default.pathExistsSync(appPathTS)) {
1128
- logger.info(logText("Adding _app.js ... \u2705"));
1129
- import_fs_extra2.default.writeFileSync(appPath, AppJsContent(usingSrc));
1130
- } else {
1131
- const override = await (0, import_prompts2.default)({
1132
- name: "res",
1133
- type: "confirm",
1134
- message: `do you want us to ${import_chalk5.default.bold(`override`)} your _app${appExtension}?`
1135
- });
1136
- _ctx.overrideApp = override.res;
1137
- if (override.res) {
1138
- logger.info(logText(`Adding _app${appExtension} ... \u2705`));
1139
- const appPathWithExtension = import_path4.default.join(pagesPath, `_app${appExtension}`);
1140
- const fileContent = import_fs_extra2.default.pathExistsSync(appPath) ? (0, import_fs_extra2.readFileSync)(appPath) : (0, import_fs_extra2.readFileSync)(appPathTS);
1141
- const matches = [
1142
- ...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
1143
- ];
1144
- const primaryMatches = matches.map((x) => x[0]);
1145
- import_fs_extra2.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
1146
- }
1147
- }
1148
- const tinaBlogPagePath = import_path4.default.join(pagesPath, "demo", "blog");
1149
- const tinaBlogPagePathFile = import_path4.default.join(tinaBlogPagePath, "[filename].js");
1150
- if (!import_fs_extra2.default.pathExistsSync(tinaBlogPagePathFile)) {
1151
- import_fs_extra2.default.mkdirpSync(tinaBlogPagePath);
1152
- import_fs_extra2.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
1153
- }
1154
- logger.info("Adding a content folder... \u2705");
1155
- if (!import_fs_extra2.default.existsSync(packageJSONPath)) {
1156
- throw new Error("No package.json Found. Please run tinacms init at the root of your app");
1157
- } else {
1158
- const pack = JSON.parse((0, import_fs_extra2.readFileSync)(packageJSONPath).toString());
1159
- const oldScripts = pack.scripts || {};
1160
- const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
1161
- scripts: extendNextScripts(oldScripts)
1162
- }), null, 2);
1163
- (0, import_fs_extra2.writeFileSync)(packageJSONPath, newPack);
1164
- }
1165
- const adminPath = import_path4.default.join(pagesPath, "admin.js");
1166
- if (import_fs_extra2.default.pathExistsSync(import_path4.default.join(pagesPath, "admin"))) {
1167
- logger.warn(`Unable to add /pages/admin.js, this path already exists.
1168
- Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
1169
- return next();
1170
- }
1171
- (0, import_fs_extra2.outputFileSync)(adminPath, adminPage);
1172
- next();
1173
- }
1174
- async function successMessage(ctx, next, options) {
1175
- const usingSrc = import_fs_extra2.default.pathExistsSync(import_path4.default.join(baseDir, "src"));
1176
- logger.info(`Tina setup ${import_chalk5.default.underline.green("done")} \u2705
1177
- `);
1178
- logger.info("Next Steps: \n");
1179
- if (!ctx.overrideApp) {
1180
- logger.info(`${import_chalk5.default.bold("Add the Tina wrapper")}`);
1181
- logger.info(`\u26A0\uFE0F Before using Tina, you will NEED to add the Tina wrapper to your _app.jsx
1182
- `);
1183
- logger.info(`${AppJsContentPrintout(usingSrc)}`);
1184
- }
1185
- logger.info(`${import_chalk5.default.bold("Run your site with Tina")}`);
1186
- logger.info(` yarn dev
1187
- `);
1188
- logger.info(`${import_chalk5.default.bold("Start Editing")}`);
1189
- logger.info(` Go to 'http://localhost:3000/admin'
1190
- `);
1191
- logger.info(`${import_chalk5.default.bold("Read the docs")}`);
1192
- logger.info(` Check out 'https://tina.io/docs/introduction/tina-init/#adding-tina' for help getting started with Tina
1193
- `);
1194
- logger.info(`Enjoy Tina! \u{1F999}`);
1195
- next();
1196
- }
1197
-
1198
- // src/cmds/baseCmds.ts
1199
- var import_config = __toModule(require("dotenv/config"));
1200
-
1201
- // src/middleware.ts
1202
- var chain = async (cmds, options) => {
1203
- const ctx = {};
1204
- const next = async (middlewareIndex) => {
1205
- if (middlewareIndex >= cmds.length) {
1206
- process.exit(0);
1207
- }
1208
- try {
1209
- await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
1210
- } catch (err) {
1211
- console.error(` ${dangerText(err)}`);
1212
- if (err.stack) {
1213
- console.log(err.stack);
1214
- }
1215
- process.exit(1);
1216
- }
1217
- };
1218
- if (cmds.length > 0) {
1219
- await next(0);
1220
- }
1221
- };
1222
-
1223
- // src/cmds/baseCmds.ts
1224
- var import_chalk7 = __toModule(require("chalk"));
1225
-
1226
- // src/cmds/compile/index.ts
1227
- var _ = __toModule(require("lodash"));
1228
-
1229
- // src/cmds/start-server/errors/index.ts
1230
- var import_graphql3 = __toModule(require("@tinacms/graphql"));
1231
- var BuildSchemaError = class extends Error {
1232
- constructor(message) {
1233
- super(message);
1234
- this.name = "BuildSchemaError";
1235
- }
1236
- };
1237
- var ExecuteSchemaError = class extends Error {
1238
- constructor(message) {
1239
- super(message);
1240
- this.name = "ExecuteSchemaError";
1241
- }
1242
- };
1243
- var handleServerErrors = (e) => {
1244
- if (e.name === "BuildSchemaError") {
1245
- logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
1246
- Error Message Below
1247
- ${e}`);
1248
- } else if (e.name === "ExecuteSchemaError") {
1249
- logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
1250
- Error Message Below
1251
- ${e}`);
1252
- } else if (e.name === "TinaSchemaValidationError") {
1253
- logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
1254
- Error Message Below
1255
- ${e}`);
1256
- } else if (e instanceof import_graphql3.TinaFetchError) {
1257
- (0, import_graphql3.handleFetchErrorError)(e, true);
1258
- } else {
1259
- logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
1260
- ${e.message}`);
1261
- }
1262
- };
1263
-
1264
- // src/cmds/compile/index.ts
1265
- var import_fs_extra3 = __toModule(require("fs-extra"));
1266
- var import_path5 = __toModule(require("path"));
1267
- var import_esbuild = __toModule(require("esbuild"));
1268
- var resetGeneratedFolder = async ({
1269
- tinaGeneratedPath,
1270
- usingTs
1271
- }) => {
1272
- try {
1273
- await import_fs_extra3.default.emptyDir(tinaGeneratedPath);
1274
- } catch (e) {
1275
- console.log(e);
1276
- }
1277
- await import_fs_extra3.default.mkdirp(tinaGeneratedPath);
1278
- const ext = usingTs ? "ts" : "js";
1279
- await import_fs_extra3.default.writeFile(import_path5.default.join(tinaGeneratedPath, `types.${ext}`), `
1280
- export const queries = (client)=>({})
1281
- `);
1282
- await import_fs_extra3.default.writeFile(import_path5.default.join(tinaGeneratedPath, `client.${ext}`), `
1283
- export const client = ()=>{}
1284
- export default client
1285
- `);
1286
- await import_fs_extra3.default.outputFile(import_path5.default.join(tinaGeneratedPath, ".gitignore"), `app
1287
- db
1288
- prebuild
1289
- client.ts
1290
- client.js
1291
- types.ts
1292
- types.js
1293
- types.d.ts
1294
- frags.gql
1295
- queries.gql
1296
- schema.gql
1297
- out.jsx
1298
- `);
1299
- };
1300
- var cleanup = async ({ tinaTempPath }) => {
1301
- await import_fs_extra3.default.remove(tinaTempPath);
1302
- };
1303
- var compileClient = async (ctx, next, options) => {
1304
- const root2 = ctx.rootPath;
1305
- if (!root2) {
1306
- throw new Error("ctx.rootPath has not been attached");
1307
- }
1308
- const tinaPath = import_path5.default.join(root2, ".tina");
1309
- const tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
1310
- const packageJSONFilePath = import_path5.default.join(root2, "package.json");
1311
- const tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp_client");
1312
- if (!options.clientFileType)
1313
- options = __spreadProps(__spreadValues({}, options), { clientFileType: "ts" });
1314
- if (options.verbose) {
1315
- logger.info(logText("Compiling Client..."));
1316
- }
1317
- const { clientFileType: requestedClientFileType = "ts" } = options;
1318
- const allowedFileTypes = ["ts", "js"];
1319
- if (allowedFileTypes.includes(requestedClientFileType) === false) {
1320
- throw new Error(`Requested schema file type '${requestedClientFileType}' is not valid. Supported schema file types: 'ts, js'`);
1321
- }
1322
- if (ctx) {
1323
- ctx.clientFileType = requestedClientFileType;
1324
- }
1325
- let clientExists = true;
1326
- const projectDir = import_path5.default.join(tinaPath, "__generated__");
1327
- try {
1328
- getClientPath({ projectDir });
1329
- } catch {
1330
- clientExists = false;
1331
- }
1332
- if (!clientExists) {
1333
- if (options.verbose) {
1334
- logger.info(logText(`.tina/client.${requestedClientFileType} not found, skipping compile client...`));
1335
- }
1336
- return next();
1337
- }
1338
- try {
1339
- const define = {};
1340
- if (!process.env.NODE_ENV) {
1341
- define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
1342
- }
1343
- const inputFile = getClientPath({
1344
- projectDir
1345
- });
1346
- await transpile(inputFile, "client.js", tinaTempPath, options.verbose, define, packageJSONFilePath);
1347
- } catch (e) {
1348
- await cleanup({ tinaTempPath });
1349
- throw new BuildSchemaError(e);
1350
- }
1351
- Object.keys(require.cache).map((key) => {
1352
- if (key.startsWith(tinaTempPath)) {
1353
- delete require.cache[require.resolve(key)];
1354
- }
1355
- });
1356
- try {
1357
- const clientFunc = require(import_path5.default.join(tinaTempPath, "client.js"));
1358
- const client = clientFunc.default;
1359
- ctx.client = client;
1360
- await cleanup({ tinaTempPath });
1361
- } catch (e) {
1362
- await cleanup({ tinaTempPath });
1363
- if (e instanceof Error) {
1364
- if (e.name === "TinaSchemaValidationError") {
1365
- throw e;
1366
- }
1367
- }
1368
- throw new ExecuteSchemaError(e);
1369
- }
1370
- return next();
772
+ return next();
1371
773
  };
1372
774
  var compileFile = async (options, fileName) => {
1373
775
  const root2 = options.rootPath;
1374
776
  if (!root2) {
1375
777
  throw new Error("ctx.rootPath has not been attached");
1376
778
  }
1377
- const tinaPath = import_path5.default.join(root2, ".tina");
1378
- const tsConfigPath = import_path5.default.join(root2, "tsconfig.json");
1379
- const tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
1380
- const tinaTempPath = import_path5.default.join(tinaGeneratedPath, `temp_${fileName}`);
1381
- const packageJSONFilePath = import_path5.default.join(root2, "package.json");
779
+ const tinaPath = import_path3.default.join(root2, ".tina");
780
+ const tsConfigPath = import_path3.default.join(root2, "tsconfig.json");
781
+ const tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
782
+ const tinaTempPath = import_path3.default.join(tinaGeneratedPath, `temp_${fileName}`);
783
+ const packageJSONFilePath = import_path3.default.join(root2, "package.json");
1382
784
  if (!options.schemaFileType) {
1383
- const usingTs = await import_fs_extra3.default.pathExists(tsConfigPath);
785
+ const usingTs = await import_fs_extra2.default.pathExists(tsConfigPath);
1384
786
  options = __spreadProps(__spreadValues({}, options), { schemaFileType: usingTs ? "ts" : "js" });
1385
787
  }
1386
788
  if (options.verbose) {
@@ -1414,7 +816,7 @@ var compileFile = async (options, fileName) => {
1414
816
  });
1415
817
  let returnObject = {};
1416
818
  try {
1417
- const schemaFunc = require(import_path5.default.join(tinaTempPath, `${fileName}.cjs`));
819
+ const schemaFunc = require(import_path3.default.join(tinaTempPath, `${fileName}.cjs`));
1418
820
  returnObject = schemaFunc.default;
1419
821
  await cleanup({ tinaTempPath });
1420
822
  } catch (e) {
@@ -1430,9 +832,9 @@ var compileFile = async (options, fileName) => {
1430
832
  };
1431
833
  var compileSchema = async (options) => {
1432
834
  const root2 = options.rootPath;
1433
- const tinaPath = import_path5.default.join(root2, ".tina");
1434
- const tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
1435
- const tinaConfigPath = import_path5.default.join(tinaGeneratedPath, "config");
835
+ const tinaPath = import_path3.default.join(root2, ".tina");
836
+ const tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
837
+ const tinaConfigPath = import_path3.default.join(tinaGeneratedPath, "config");
1436
838
  const schemaExists = fileExists({
1437
839
  projectDir: tinaPath,
1438
840
  filename: "schema",
@@ -1460,18 +862,18 @@ See here for migration steps, see here: https://tina.io/blog/upgrading-to-iframe
1460
862
  schema = __spreadProps(__spreadValues({}, config2.schema), { config: configCopy });
1461
863
  }
1462
864
  }
1463
- await import_fs_extra3.default.outputFile(import_path5.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
865
+ await import_fs_extra2.default.outputFile(import_path3.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
1464
866
  return schema;
1465
867
  };
1466
868
  var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
1467
869
  if (verbose)
1468
870
  logger.info(logText("Building javascript..."));
1469
- const packageJSON = JSON.parse(import_fs_extra3.default.readFileSync(packageJSONFilePath).toString() || "{}");
871
+ const packageJSON = JSON.parse(import_fs_extra2.default.readFileSync(packageJSONFilePath).toString() || "{}");
1470
872
  const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
1471
873
  const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
1472
874
  const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
1473
875
  const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
1474
- const prebuiltInputPath = import_path5.default.join(tempDir, "temp-output.jsx");
876
+ const prebuiltInputPath = import_path3.default.join(tempDir, "temp-output.jsx");
1475
877
  await (0, import_esbuild.build)({
1476
878
  bundle: true,
1477
879
  platform: "neutral",
@@ -1483,9 +885,9 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
1483
885
  outfile: prebuiltInputPath,
1484
886
  define
1485
887
  });
1486
- const tempTsConfigPath = import_path5.default.join(tempDir, "temp-tsconfig.json");
1487
- await import_fs_extra3.default.outputFileSync(tempTsConfigPath, "{}");
1488
- const outputPath = import_path5.default.join(tempDir, outputFile);
888
+ const tempTsConfigPath = import_path3.default.join(tempDir, "temp-tsconfig.json");
889
+ await import_fs_extra2.default.outputFileSync(tempTsConfigPath, "{}");
890
+ const outputPath = import_path3.default.join(tempDir, outputFile);
1489
891
  await (0, import_esbuild.build)({
1490
892
  bundle: true,
1491
893
  platform: "neutral",
@@ -1532,10 +934,10 @@ var loaders = {
1532
934
  };
1533
935
 
1534
936
  // src/cmds/start-server/index.ts
1535
- var import_path13 = __toModule(require("path"));
1536
- var import_chalk6 = __toModule(require("chalk"));
937
+ var import_path11 = __toModule(require("path"));
938
+ var import_chalk4 = __toModule(require("chalk"));
1537
939
  var import_chokidar = __toModule(require("chokidar"));
1538
- var import_metrics3 = __toModule(require("@tinacms/metrics"));
940
+ var import_metrics2 = __toModule(require("@tinacms/metrics"));
1539
941
 
1540
942
  // src/cmds/start-server/lock.ts
1541
943
  var AsyncLock = class {
@@ -1550,15 +952,15 @@ var AsyncLock = class {
1550
952
  };
1551
953
 
1552
954
  // src/buildTina/index.ts
1553
- var import_fs_extra7 = __toModule(require("fs-extra"));
955
+ var import_fs_extra6 = __toModule(require("fs-extra"));
1554
956
  var import_graphql9 = __toModule(require("@tinacms/graphql"));
1555
957
  var import_datalayer = __toModule(require("@tinacms/datalayer"));
1556
- var import_path10 = __toModule(require("path"));
958
+ var import_path8 = __toModule(require("path"));
1557
959
 
1558
960
  // src/cmds/query-gen/genTypes.ts
1559
961
  var import_graphql8 = __toModule(require("graphql"));
1560
- var import_fs_extra4 = __toModule(require("fs-extra"));
1561
- var import_path7 = __toModule(require("path"));
962
+ var import_fs_extra3 = __toModule(require("fs-extra"));
963
+ var import_path5 = __toModule(require("path"));
1562
964
 
1563
965
  // src/codegen/index.ts
1564
966
  var import_graphql7 = __toModule(require("graphql"));
@@ -1615,7 +1017,7 @@ var import_typescript = __toModule(require("@graphql-codegen/typescript"));
1615
1017
  // src/codegen/sdkPlugin/index.ts
1616
1018
  var import_graphql5 = __toModule(require("graphql"));
1617
1019
  var import_graphql6 = __toModule(require("graphql"));
1618
- var import_path6 = __toModule(require("path"));
1020
+ var import_path4 = __toModule(require("path"));
1619
1021
 
1620
1022
  // src/codegen/sdkPlugin/visitor.ts
1621
1023
  var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
@@ -1752,7 +1154,7 @@ var loadGraphQLDocuments = async (globPath) => {
1752
1154
  var import_esbuild2 = __toModule(require("esbuild"));
1753
1155
  var TINA_HOST = "content.tinajs.io";
1754
1156
  var root = process.cwd();
1755
- var generatedPath = import_path7.default.join(root, ".tina", "__generated__");
1157
+ var generatedPath = import_path5.default.join(root, ".tina", "__generated__");
1756
1158
  async function genClient({
1757
1159
  tinaSchema,
1758
1160
  usingTs
@@ -1773,8 +1175,8 @@ async function genClient({
1773
1175
  throw new Error(`Client not configured properly. Missing ${missing.join(", ")}. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information`);
1774
1176
  }
1775
1177
  const apiURL = options.local ? `http://localhost:${options.port || 4001}/graphql` : `${baseUrl}/content/${clientId}/github/${branch}`;
1776
- const clientPath = import_path7.default.join(generatedPath, `client.${usingTs ? "ts" : "js"}`);
1777
- import_fs_extra4.default.writeFileSync(clientPath, `import { createClient } from "tinacms/dist/client";
1178
+ const clientPath = import_path5.default.join(generatedPath, `client.${usingTs ? "ts" : "js"}`);
1179
+ import_fs_extra3.default.writeFileSync(clientPath, `import { createClient } from "tinacms/dist/client";
1778
1180
  import { queries } from "./types";
1779
1181
  export const client = createClient({ url: '${apiURL}', token: '${token}', queries });
1780
1182
  export default client;
@@ -1800,16 +1202,16 @@ async function genTypes({ schema, usingTs }, next, options) {
1800
1202
  ${typescriptTypes}
1801
1203
  `;
1802
1204
  if (usingTs) {
1803
- await import_fs_extra4.default.outputFile(typesPath, code);
1205
+ await import_fs_extra3.default.outputFile(typesPath, code);
1804
1206
  logger.info(` Typescript types => ${logText(typesPath)}`);
1805
1207
  } else {
1806
- await import_fs_extra4.default.outputFile(typesDPath, code);
1208
+ await import_fs_extra3.default.outputFile(typesDPath, code);
1807
1209
  const jsCode = await (0, import_esbuild2.transform)(code, { loader: "ts" });
1808
- await import_fs_extra4.default.outputFile(typesJSPath, jsCode.code);
1210
+ await import_fs_extra3.default.outputFile(typesJSPath, jsCode.code);
1809
1211
  }
1810
1212
  const schemaString = await (0, import_graphql8.printSchema)(schema);
1811
1213
  const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
1812
- await import_fs_extra4.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
1214
+ await import_fs_extra3.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
1813
1215
  ${schemaString}
1814
1216
  schema {
1815
1217
  query: Query
@@ -1822,15 +1224,15 @@ schema {
1822
1224
  }
1823
1225
 
1824
1226
  // src/buildTina/git.ts
1825
- var import_fs_extra5 = __toModule(require("fs-extra"));
1227
+ var import_fs_extra4 = __toModule(require("fs-extra"));
1826
1228
  var import_ini = __toModule(require("ini"));
1827
1229
  var import_os = __toModule(require("os"));
1828
- var import_path8 = __toModule(require("path"));
1230
+ var import_path6 = __toModule(require("path"));
1829
1231
  var resolveGitRoot = async () => {
1830
- const pathParts = process.cwd().split(import_path8.default.sep);
1232
+ const pathParts = process.cwd().split(import_path6.default.sep);
1831
1233
  while (true) {
1832
- const pathToGit = pathParts.join(import_path8.default.sep);
1833
- if (await import_fs_extra5.default.pathExists(import_path8.default.join(pathToGit, ".git"))) {
1234
+ const pathToGit = pathParts.join(import_path6.default.sep);
1235
+ if (await import_fs_extra4.default.pathExists(import_path6.default.join(pathToGit, ".git"))) {
1834
1236
  return pathToGit;
1835
1237
  }
1836
1238
  if (!pathParts.length) {
@@ -1855,9 +1257,9 @@ async function makeIsomorphicOptions(fsBridge) {
1855
1257
  await fsBridge.delete(filepath);
1856
1258
  }
1857
1259
  };
1858
- const userGitConfig = `${import_os.default.homedir()}${import_path8.default.sep}.gitconfig`;
1859
- if (await import_fs_extra5.default.pathExists(userGitConfig)) {
1860
- const config2 = import_ini.default.parse(await import_fs_extra5.default.readFile(userGitConfig, "utf-8"));
1260
+ const userGitConfig = `${import_os.default.homedir()}${import_path6.default.sep}.gitconfig`;
1261
+ if (await import_fs_extra4.default.pathExists(userGitConfig)) {
1262
+ const config2 = import_ini.default.parse(await import_fs_extra4.default.readFile(userGitConfig, "utf-8"));
1861
1263
  if ((_a = config2["user"]) == null ? void 0 : _a["name"]) {
1862
1264
  options.author.name = config2["user"]["name"];
1863
1265
  }
@@ -1867,7 +1269,7 @@ async function makeIsomorphicOptions(fsBridge) {
1867
1269
  }
1868
1270
  let repoGitConfig = void 0;
1869
1271
  if (!options.author.name) {
1870
- repoGitConfig = import_ini.default.parse(await import_fs_extra5.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1272
+ repoGitConfig = import_ini.default.parse(await import_fs_extra4.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1871
1273
  if ((_c = repoGitConfig["user"]) == null ? void 0 : _c["name"]) {
1872
1274
  options.author.name = repoGitConfig["user"]["name"];
1873
1275
  }
@@ -1876,7 +1278,7 @@ async function makeIsomorphicOptions(fsBridge) {
1876
1278
  }
1877
1279
  }
1878
1280
  if (!options.author.email) {
1879
- repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra5.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1281
+ repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra4.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1880
1282
  if ((_d = repoGitConfig["user"]) == null ? void 0 : _d["email"]) {
1881
1283
  options.author.email = repoGitConfig["user"]["email"];
1882
1284
  }
@@ -1913,16 +1315,16 @@ async function spin({
1913
1315
  }
1914
1316
 
1915
1317
  // src/buildTina/attachPath.ts
1916
- var import_fs_extra6 = __toModule(require("fs-extra"));
1917
- var import_path9 = __toModule(require("path"));
1318
+ var import_fs_extra5 = __toModule(require("fs-extra"));
1319
+ var import_path7 = __toModule(require("path"));
1918
1320
  var attachPath = async (ctx, next, _options) => {
1919
1321
  ctx.rootPath = process.cwd();
1920
1322
  ctx.usingTs = await isProjectTs(ctx.rootPath);
1921
1323
  next();
1922
1324
  };
1923
1325
  var isProjectTs = async (rootPath2) => {
1924
- const tinaPath = import_path9.default.join(rootPath2, ".tina");
1925
- return await (0, import_fs_extra6.pathExists)(import_path9.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra6.pathExists)(import_path9.default.join(tinaPath, "schema.tsx")) || await (0, import_fs_extra6.pathExists)(import_path9.default.join(tinaPath, "config.ts")) || await (0, import_fs_extra6.pathExists)(import_path9.default.join(tinaPath, "config.tsx"));
1326
+ const tinaPath = import_path7.default.join(rootPath2, ".tina");
1327
+ return await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "schema.tsx")) || await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "config.ts")) || await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "config.tsx"));
1926
1328
  };
1927
1329
 
1928
1330
  // src/buildTina/index.ts
@@ -1951,7 +1353,7 @@ var buildSetupCmdServerStart = async (ctx, next, opts) => {
1951
1353
  var buildSetupCmdAudit = async (ctx, next, options) => {
1952
1354
  const rootPath2 = ctx.rootPath;
1953
1355
  const bridge = options.clean ? new import_datalayer.FilesystemBridge(rootPath2) : new import_datalayer.AuditFileSystemBridge(rootPath2);
1954
- await import_fs_extra7.default.ensureDirSync(import_path10.default.join(rootPath2, ".tina", "__generated__"));
1356
+ await import_fs_extra6.default.ensureDirSync(import_path8.default.join(rootPath2, ".tina", "__generated__"));
1955
1357
  const store = new import_datalayer.LevelStore(rootPath2, false);
1956
1358
  const database = await (0, import_graphql9.createDatabase)({ store, bridge });
1957
1359
  ctx.bridge = bridge;
@@ -1967,7 +1369,7 @@ var buildSetup = async ({
1967
1369
  const fsBridge = new import_datalayer.FilesystemBridge(rootPath2);
1968
1370
  const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
1969
1371
  const bridge = isomorphicGitBridge2 ? new import_datalayer.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
1970
- await import_fs_extra7.default.ensureDirSync(import_path10.default.join(rootPath2, ".tina", "__generated__"));
1372
+ await import_fs_extra6.default.ensureDirSync(import_path8.default.join(rootPath2, ".tina", "__generated__"));
1971
1373
  const store = new import_datalayer.LevelStore(rootPath2, useMemoryStore);
1972
1374
  const database = await (0, import_graphql9.createDatabase)({ store, bridge });
1973
1375
  return { database, bridge, store };
@@ -2011,18 +1413,19 @@ var ConfigBuilder = class {
2011
1413
  constructor(database) {
2012
1414
  this.database = database;
2013
1415
  }
2014
- async build({ dev, verbose, rootPath: rootPath2 }) {
1416
+ async build({ dev, verbose, rootPath: rootPath2, local }) {
2015
1417
  const usingTs = await isProjectTs(rootPath2);
2016
1418
  if (!rootPath2) {
2017
1419
  throw new Error("Root path has not been attached");
2018
1420
  }
2019
- const tinaGeneratedPath = import_path10.default.join(rootPath2, ".tina", "__generated__");
1421
+ const tinaGeneratedPath = import_path8.default.join(rootPath2, ".tina", "__generated__");
2020
1422
  this.database.clearCache();
2021
- await import_fs_extra7.default.mkdirp(tinaGeneratedPath);
1423
+ await import_fs_extra6.default.mkdirp(tinaGeneratedPath);
2022
1424
  await this.database.store.close();
2023
1425
  await resetGeneratedFolder({
2024
1426
  tinaGeneratedPath,
2025
- usingTs
1427
+ usingTs,
1428
+ isBuild: !local
2026
1429
  });
2027
1430
  await this.database.store.open();
2028
1431
  const compiledSchema = await compileSchema({
@@ -2100,7 +1503,7 @@ async function startServer(ctx, next, {
2100
1503
  buildLock.disable();
2101
1504
  reBuildLock.disable();
2102
1505
  const rootPath2 = ctx.rootPath;
2103
- const t = new import_metrics3.Telemetry({ disabled: Boolean(noTelemetry) });
1506
+ const t = new import_metrics2.Telemetry({ disabled: Boolean(noTelemetry) });
2104
1507
  t.submitRecord({
2105
1508
  event: {
2106
1509
  name: "tinacms:cli:server:start:invoke"
@@ -2135,9 +1538,9 @@ async function startServer(ctx, next, {
2135
1538
  const cmsUrl = ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build) ? `[your-development-url]/${ctx.schema.config.build.outputFolder}/index.html` : `[your-development-url]/admin`;
2136
1539
  if (verbose)
2137
1540
  logger.info(`Started Filesystem GraphQL server on port: ${port}`);
2138
- logger.info(`Visit the GraphQL playground at ${import_chalk6.default.underline.blueBright(altairUrl)}
1541
+ logger.info(`Visit the GraphQL playground at ${import_chalk4.default.underline.blueBright(altairUrl)}
2139
1542
  or`);
2140
- logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
1543
+ logger.info(`Enter the CMS at ${import_chalk4.default.underline.blueBright(cmsUrl)}
2141
1544
  `);
2142
1545
  resolve2();
2143
1546
  });
@@ -2178,8 +1581,8 @@ or`);
2178
1581
  await beforeBuild();
2179
1582
  const { schema, graphQLSchema, tinaSchema } = await ctx.builder.build({
2180
1583
  rootPath: ctx.rootPath,
2181
- dev,
2182
- verbose
1584
+ verbose,
1585
+ local: true
2183
1586
  });
2184
1587
  ctx.schema = schema;
2185
1588
  const apiUrl = await ctx.builder.genTypedClient({
@@ -2208,7 +1611,7 @@ or`);
2208
1611
  await afterBuild();
2209
1612
  }
2210
1613
  };
2211
- const foldersToWatch = (watchFolders || []).map((x) => import_path13.default.join(rootPath2, x));
1614
+ const foldersToWatch = (watchFolders || []).map((x) => import_path11.default.join(rootPath2, x));
2212
1615
  if (!noWatch && !process.env.CI) {
2213
1616
  import_chokidar.default.watch([
2214
1617
  ...foldersToWatch,
@@ -2218,7 +1621,7 @@ or`);
2218
1621
  ignored: [
2219
1622
  "**/node_modules/**/*",
2220
1623
  "**/.next/**/*",
2221
- `${import_path13.default.resolve(rootPath2)}/.tina/__generated__/**/*`
1624
+ `${import_path11.default.resolve(rootPath2)}/.tina/__generated__/**/*`
2222
1625
  ]
2223
1626
  }).on("ready", async () => {
2224
1627
  if (verbose)
@@ -2272,133 +1675,479 @@ or`);
2272
1675
  }
2273
1676
  }
2274
1677
 
2275
- // src/cmds/statusChecks/waitForIndexing.ts
2276
- var import_progress2 = __toModule(require("progress"));
2277
- var POLLING_INTERVAL = 5e3;
2278
- var STATUS_INPROGRESS = "inprogress";
2279
- var STATUS_COMPLETE = "complete";
2280
- var STATUS_FAILED = "failed";
2281
- var IndexFailedError = class extends Error {
2282
- constructor(message) {
2283
- super(message);
2284
- this.name = "IndexFailedError";
2285
- }
2286
- };
2287
- var waitForDB = async (ctx, next, options) => {
2288
- if (!ctx.client) {
2289
- throw new Error("No Tina Cloud found. For more information on how to setup the Tina Cloud see https://tina.io/docs/features/data-fetching/#making-requests-with-the-tina-client");
2290
- }
2291
- const client = ctx.client;
2292
- const { host, clientId, branch, isLocalClient } = client.parseURL();
2293
- if (isLocalClient) {
2294
- return next();
2295
- }
2296
- const bar = new import_progress2.default("Checking indexing process in Tina Cloud... :prog", 1);
2297
- const pollForStatus = async () => {
2298
- try {
2299
- if (options.verbose) {
2300
- logger.info(logText("Polling for status..."));
2301
- }
2302
- const headers = new Headers();
2303
- headers.append("Content-Type", "application/json");
2304
- if (client.readonlyToken) {
2305
- headers.append("X-API-KEY", client.readonlyToken);
2306
- }
2307
- const response = await fetch(`https://${host}/db/${clientId}/status/${branch}`, {
2308
- method: "GET",
2309
- headers
2310
- });
2311
- const { status, error } = await response.json();
2312
- const statusMessage = `Indexing status: '${status}'`;
2313
- if (status === STATUS_COMPLETE) {
2314
- bar.tick({
2315
- prog: "\u2705"
2316
- });
2317
- return next();
2318
- } else if (status === STATUS_INPROGRESS) {
2319
- if (options.verbose) {
2320
- logger.info(logText(`${statusMessage}, trying again in 5 seconds`));
2321
- }
2322
- setTimeout(pollForStatus, POLLING_INTERVAL);
2323
- } else if (status === STATUS_FAILED) {
2324
- throw new IndexFailedError(`Attempting to index but responded with status 'failed', To retry the indexing process, click \u201CReset Repository Cache\u201D in tina cloud advance settings. ${error}`);
2325
- } else {
2326
- throw new IndexFailedError(`Attempting to index but responded with status 'unknown', To retry the indexing process, click \u201CReset Repository Cache\u201D in tina cloud advance settings. ${error}`);
2327
- }
2328
- } catch (e) {
2329
- if (e instanceof IndexFailedError) {
2330
- bar.tick({
2331
- prog: "\u274C"
2332
- });
2333
- throw e;
2334
- } else {
2335
- throw new Error(`Unable to query DB for indexing status, encountered error: ${e.message}`);
2336
- }
2337
- }
2338
- };
2339
- spin({
2340
- text: "Checking indexing process in Tina Cloud...",
2341
- waitFor: pollForStatus
1678
+ // src/cmds/statusChecks/waitForIndexing.ts
1679
+ var import_progress = __toModule(require("progress"));
1680
+ var POLLING_INTERVAL = 5e3;
1681
+ var STATUS_INPROGRESS = "inprogress";
1682
+ var STATUS_COMPLETE = "complete";
1683
+ var STATUS_FAILED = "failed";
1684
+ var IndexFailedError = class extends Error {
1685
+ constructor(message) {
1686
+ super(message);
1687
+ this.name = "IndexFailedError";
1688
+ }
1689
+ };
1690
+ var waitForDB = async (ctx, next, options) => {
1691
+ if (!ctx.client) {
1692
+ throw new Error("No Tina Cloud found. For more information on how to setup the Tina Cloud see https://tina.io/docs/features/data-fetching/#making-requests-with-the-tina-client");
1693
+ }
1694
+ const client = ctx.client;
1695
+ const { host, clientId, branch, isLocalClient } = client.parseURL();
1696
+ if (isLocalClient) {
1697
+ return next();
1698
+ }
1699
+ const bar = new import_progress.default("Checking indexing process in Tina Cloud... :prog", 1);
1700
+ const pollForStatus = async () => {
1701
+ try {
1702
+ if (options.verbose) {
1703
+ logger.info(logText("Polling for status..."));
1704
+ }
1705
+ const headers = new Headers();
1706
+ headers.append("Content-Type", "application/json");
1707
+ if (client.readonlyToken) {
1708
+ headers.append("X-API-KEY", client.readonlyToken);
1709
+ }
1710
+ const response = await fetch(`https://${host}/db/${clientId}/status/${branch}`, {
1711
+ method: "GET",
1712
+ headers
1713
+ });
1714
+ const { status, error } = await response.json();
1715
+ const statusMessage = `Indexing status: '${status}'`;
1716
+ if (status === STATUS_COMPLETE) {
1717
+ bar.tick({
1718
+ prog: "\u2705"
1719
+ });
1720
+ return next();
1721
+ } else if (status === STATUS_INPROGRESS) {
1722
+ if (options.verbose) {
1723
+ logger.info(logText(`${statusMessage}, trying again in 5 seconds`));
1724
+ }
1725
+ setTimeout(pollForStatus, POLLING_INTERVAL);
1726
+ } else if (status === STATUS_FAILED) {
1727
+ throw new IndexFailedError(`Attempting to index but responded with status 'failed', To retry the indexing process, click \u201CReset Repository Cache\u201D in tina cloud advance settings. ${error}`);
1728
+ } else {
1729
+ throw new IndexFailedError(`Attempting to index but responded with status 'unknown', To retry the indexing process, click \u201CReset Repository Cache\u201D in tina cloud advance settings. ${error}`);
1730
+ }
1731
+ } catch (e) {
1732
+ if (e instanceof IndexFailedError) {
1733
+ bar.tick({
1734
+ prog: "\u274C"
1735
+ });
1736
+ throw e;
1737
+ } else {
1738
+ throw new Error(`Unable to query DB for indexing status, encountered error: ${e.message}`);
1739
+ }
1740
+ }
1741
+ };
1742
+ spin({
1743
+ text: "Checking indexing process in Tina Cloud...",
1744
+ waitFor: pollForStatus
1745
+ });
1746
+ };
1747
+
1748
+ // src/cmds/startSubprocess/index.ts
1749
+ var import_child_process = __toModule(require("child_process"));
1750
+ var startSubprocess = async (_ctx, next, { command }) => {
1751
+ if (typeof command === "string") {
1752
+ const commands = command.split(" ");
1753
+ const firstCommand = commands[0];
1754
+ const args = commands.slice(1) || [];
1755
+ const ps = import_child_process.default.spawn(firstCommand, args, {
1756
+ stdio: "inherit",
1757
+ shell: true
1758
+ });
1759
+ ps.on("error", (code) => {
1760
+ logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
1761
+ logger.error(`name: ${code.name}
1762
+ message: ${code.message}
1763
+
1764
+ stack: ${code.stack || "No stack was provided"}`);
1765
+ });
1766
+ ps.on("close", (code) => {
1767
+ logger.info(`child process exited with code ${code}`);
1768
+ process.exit(code);
1769
+ });
1770
+ }
1771
+ };
1772
+
1773
+ // src/cmds/init/index.ts
1774
+ var import_path12 = __toModule(require("path"));
1775
+ var import_fs_extra8 = __toModule(require("fs-extra"));
1776
+ var import_prompts2 = __toModule(require("prompts"));
1777
+ var import_metrics3 = __toModule(require("@tinacms/metrics"));
1778
+
1779
+ // src/cmds/init/setup-files/index.ts
1780
+ var nextPostPage = ({
1781
+ usingSrc
1782
+ }) => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
1783
+ // This is a demo file once you have tina setup feel free to delete this file
1784
+
1785
+ import Head from 'next/head'
1786
+ import { useTina } from 'tinacms/dist/react'
1787
+ import { TinaMarkdown } from 'tinacms/dist/rich-text'
1788
+ import client from '${usingSrc ? "../" : ""}../../../.tina/__generated__/client'
1789
+
1790
+ const BlogPage = (props) => {
1791
+ const { data } = useTina({
1792
+ query: props.query,
1793
+ variables: props.variables,
1794
+ data: props.data,
1795
+ })
1796
+
1797
+ return (
1798
+ <>
1799
+ <Head>
1800
+ {/* Tailwind CDN */}
1801
+ <link
1802
+ rel="stylesheet"
1803
+ href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.7/tailwind.min.css"
1804
+ integrity="sha512-y6ZMKFUQrn+UUEVoqYe8ApScqbjuhjqzTuwUMEGMDuhS2niI8KA3vhH2LenreqJXQS+iIXVTRL2iaNfJbDNA1Q=="
1805
+ crossOrigin="anonymous"
1806
+ referrerPolicy="no-referrer"
1807
+ />
1808
+ </Head>
1809
+ <div>
1810
+ <div
1811
+ style={{
1812
+ textAlign: 'center',
1813
+ }}
1814
+ >
1815
+ <h1 className="text-3xl m-8 text-center leading-8 font-extrabold tracking-tight text-gray-900 sm:text-4xl">
1816
+ {data.post.title}
1817
+ </h1>
1818
+ <ContentSection content={data.post.body}></ContentSection>
1819
+ </div>
1820
+ <div className="bg-green-100 text-center">
1821
+ Lost and looking for a place to start?
1822
+ <a
1823
+ href="https://tina.io/guides/tina-cloud/getting-started/overview/"
1824
+ className="text-blue-500 underline"
1825
+ >
1826
+ {' '}
1827
+ Check out this guide
1828
+ </a>{' '}
1829
+ to see how add TinaCMS to an existing Next.js site.
1830
+ </div>
1831
+ </div>
1832
+ </>
1833
+ )
1834
+ }
1835
+
1836
+ export const getStaticProps = async ({ params }) => {
1837
+ let data = {}
1838
+ let query = {}
1839
+ let variables = { relativePath: \`\${params.filename}.md\` }
1840
+ try {
1841
+ const res = await client.queries.post(variables)
1842
+ query = res.query
1843
+ data = res.data
1844
+ variables = res.variables
1845
+ } catch {
1846
+ // swallow errors related to document creation
1847
+ }
1848
+
1849
+ return {
1850
+ props: {
1851
+ variables: variables,
1852
+ data: data,
1853
+ query: query,
1854
+ //myOtherProp: 'some-other-data',
1855
+ },
1856
+ }
1857
+ }
1858
+
1859
+ export const getStaticPaths = async () => {
1860
+ const postsListData = await client.queries.postConnection()
1861
+
1862
+ return {
1863
+ paths: postsListData.data.postConnection.edges.map((post) => ({
1864
+ params: { filename: post.node._sys.filename },
1865
+ })),
1866
+ fallback: false,
1867
+ }
1868
+ }
1869
+
1870
+ export default BlogPage
1871
+
1872
+ const PageSection = (props) => {
1873
+ return (
1874
+ <>
1875
+ <h2>{props.heading}</h2>
1876
+ <p>{props.content}</p>
1877
+ </>
1878
+ )
1879
+ }
1880
+
1881
+ const components = {
1882
+ PageSection: PageSection,
1883
+ }
1884
+
1885
+ const ContentSection = ({ content }) => {
1886
+ return (
1887
+ <div className="relative py-16 bg-white overflow-hidden">
1888
+ <div className="hidden lg:block lg:absolute lg:inset-y-0 lg:h-full lg:w-full">
1889
+ <div
1890
+ className="relative h-full text-lg max-w-prose mx-auto"
1891
+ aria-hidden="true"
1892
+ >
1893
+ <svg
1894
+ className="absolute top-12 left-full transform translate-x-32"
1895
+ width={404}
1896
+ height={384}
1897
+ fill="none"
1898
+ viewBox="0 0 404 384"
1899
+ >
1900
+ <defs>
1901
+ <pattern
1902
+ id="74b3fd99-0a6f-4271-bef2-e80eeafdf357"
1903
+ x={0}
1904
+ y={0}
1905
+ width={20}
1906
+ height={20}
1907
+ patternUnits="userSpaceOnUse"
1908
+ >
1909
+ <rect
1910
+ x={0}
1911
+ y={0}
1912
+ width={4}
1913
+ height={4}
1914
+ className="text-gray-200"
1915
+ fill="currentColor"
1916
+ />
1917
+ </pattern>
1918
+ </defs>
1919
+ <rect
1920
+ width={404}
1921
+ height={384}
1922
+ fill="url(#74b3fd99-0a6f-4271-bef2-e80eeafdf357)"
1923
+ />
1924
+ </svg>
1925
+ <svg
1926
+ className="absolute top-1/2 right-full transform -translate-y-1/2 -translate-x-32"
1927
+ width={404}
1928
+ height={384}
1929
+ fill="none"
1930
+ viewBox="0 0 404 384"
1931
+ >
1932
+ <defs>
1933
+ <pattern
1934
+ id="f210dbf6-a58d-4871-961e-36d5016a0f49"
1935
+ x={0}
1936
+ y={0}
1937
+ width={20}
1938
+ height={20}
1939
+ patternUnits="userSpaceOnUse"
1940
+ >
1941
+ <rect
1942
+ x={0}
1943
+ y={0}
1944
+ width={4}
1945
+ height={4}
1946
+ className="text-gray-200"
1947
+ fill="currentColor"
1948
+ />
1949
+ </pattern>
1950
+ </defs>
1951
+ <rect
1952
+ width={404}
1953
+ height={384}
1954
+ fill="url(#f210dbf6-a58d-4871-961e-36d5016a0f49)"
1955
+ />
1956
+ </svg>
1957
+ <svg
1958
+ className="absolute bottom-12 left-full transform translate-x-32"
1959
+ width={404}
1960
+ height={384}
1961
+ fill="none"
1962
+ viewBox="0 0 404 384"
1963
+ >
1964
+ <defs>
1965
+ <pattern
1966
+ id="d3eb07ae-5182-43e6-857d-35c643af9034"
1967
+ x={0}
1968
+ y={0}
1969
+ width={20}
1970
+ height={20}
1971
+ patternUnits="userSpaceOnUse"
1972
+ >
1973
+ <rect
1974
+ x={0}
1975
+ y={0}
1976
+ width={4}
1977
+ height={4}
1978
+ className="text-gray-200"
1979
+ fill="currentColor"
1980
+ />
1981
+ </pattern>
1982
+ </defs>
1983
+ <rect
1984
+ width={404}
1985
+ height={384}
1986
+ fill="url(#d3eb07ae-5182-43e6-857d-35c643af9034)"
1987
+ />
1988
+ </svg>
1989
+ </div>
1990
+ </div>
1991
+ <div className="relative px-4 sm:px-6 lg:px-8">
1992
+ <div className="text-lg max-w-prose mx-auto">
1993
+ <TinaMarkdown components={components} content={content} />
1994
+ </div>
1995
+ </div>
1996
+ </div>
1997
+ )
1998
+ }`;
1999
+
2000
+ // src/utils/script-helpers.ts
2001
+ function generateGqlScript(scriptValue) {
2002
+ return `tinacms dev -c "${scriptValue}"`;
2003
+ }
2004
+ function extendNextScripts(scripts) {
2005
+ return __spreadProps(__spreadValues({}, scripts), {
2006
+ dev: generateGqlScript((scripts == null ? void 0 : scripts.dev) || "next dev"),
2007
+ build: `tinacms build && ${(scripts == null ? void 0 : scripts.build) || "next build"}`,
2008
+ start: `tinacms build && ${(scripts == null ? void 0 : scripts.start) || "next start"}`
2342
2009
  });
2343
- };
2010
+ }
2344
2011
 
2345
- // src/cmds/startSubprocess/index.ts
2346
- var import_child_process = __toModule(require("child_process"));
2347
- var startSubprocess = async (_ctx, next, { command }) => {
2348
- if (typeof command === "string") {
2349
- const commands = command.split(" ");
2350
- const firstCommand = commands[0];
2351
- const args = commands.slice(1) || [];
2352
- const ps = import_child_process.default.spawn(firstCommand, args, {
2353
- stdio: "inherit",
2354
- shell: true
2355
- });
2356
- ps.on("error", (code) => {
2357
- logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
2358
- logger.error(`name: ${code.name}
2359
- message: ${code.message}
2012
+ // src/cmds/init/setup-files/config.ts
2013
+ var configExamples = {
2014
+ next: () => `import { defineConfig } from 'tinacms'
2360
2015
 
2361
- stack: ${code.stack || "No stack was provided"}`);
2362
- });
2363
- ps.on("close", (code) => {
2364
- logger.info(`child process exited with code ${code}`);
2365
- process.exit(code);
2366
- });
2016
+ // Your hosting provider likely exposes this as an environment variable
2017
+ const branch = process.env.HEAD || process.env.VERCEL_GIT_COMMIT_REF || 'main'
2018
+
2019
+ export default defineConfig({
2020
+ branch,
2021
+ clientId: null, // Get this from tina.io
2022
+ token: null, // Get this from tina.io
2023
+ build: {
2024
+ outputFolder: 'admin',
2025
+ publicFolder: 'public',
2026
+ },
2027
+ media: {
2028
+ tina: {
2029
+ mediaRoot: 'uploads',
2030
+ publicFolder: 'public',
2031
+ },
2032
+ },
2033
+ schema: {
2034
+ collections: [
2035
+ {
2036
+ name: 'post',
2037
+ label: 'Posts',
2038
+ path: 'content/posts',
2039
+ fields: [
2040
+ {
2041
+ type: 'string',
2042
+ name: 'title',
2043
+ label: 'Title',
2044
+ isTitle: true,
2045
+ required: true,
2046
+ },
2047
+ {
2048
+ type: 'rich-text',
2049
+ name: 'body',
2050
+ label: 'Body',
2051
+ isBody: true,
2052
+ },
2053
+ ],
2054
+ ui: {
2055
+ // This is an DEMO router. You can remove this to fit your site
2056
+ router: ({ document }) => \`/demo/blog/\${document._sys.filename}\`,
2057
+ },
2058
+ },
2059
+ ],
2060
+ },
2061
+ })
2062
+ `,
2063
+ other: (args) => {
2064
+ return `
2065
+ import { defineConfig } from "tinacms";
2066
+
2067
+ // Your hosting provider likely exposes this as an environment variable
2068
+ const branch = process.env.HEAD || process.env.VERCEL_GIT_COMMIT_REF || "main";
2069
+
2070
+ export default defineConfig({
2071
+ branch,
2072
+ clientId: null, // Get this from tina.io
2073
+ token: null, // Get this from tina.io
2074
+ build: {
2075
+ outputFolder: "admin",
2076
+ publicFolder: "${args.publicFolder}",
2077
+ },
2078
+ media: {
2079
+ tina: {
2080
+ mediaRoot: "uploads",
2081
+ publicFolder: "${args.publicFolder}",
2082
+ },
2083
+ },
2084
+ schema: {
2085
+ collections: [
2086
+ {
2087
+ name: "post",
2088
+ label: "Posts",
2089
+ path: "content/posts",
2090
+ fields: [
2091
+ {
2092
+ type: "string",
2093
+ name: "title",
2094
+ label: "Title",
2095
+ isTitle: true,
2096
+ required: true,
2097
+ },
2098
+ {
2099
+ type: "rich-text",
2100
+ name: "body",
2101
+ label: "Body",
2102
+ isBody: true,
2103
+ },
2104
+ ],
2105
+ },
2106
+ ],
2107
+ },
2108
+ });
2109
+ `;
2367
2110
  }
2368
2111
  };
2369
2112
 
2370
- // src/cmds/init/static.ts
2371
- var import_path14 = __toModule(require("path"));
2372
- var import_fs_extra9 = __toModule(require("fs-extra"));
2373
- var import_prompts3 = __toModule(require("prompts"));
2374
- var import_metrics4 = __toModule(require("@tinacms/metrics"));
2113
+ // src/cmds/init/index.ts
2375
2114
  async function initStaticTina(ctx, next, options) {
2115
+ const baseDir = ctx.rootPath;
2376
2116
  logger.level = "info";
2377
2117
  const packageManager = await choosePackageManager();
2118
+ const framework = await chooseFramework();
2378
2119
  const usingTypescript = await chooseTypescript();
2379
- const publicFolder = await choosePublicFolder();
2120
+ const publicFolder = await choosePublicFolder({ framework });
2380
2121
  await reportTelemetry(usingTypescript, options.noTelemetry);
2381
- const hasPackageJSON = await import_fs_extra9.default.pathExistsSync("package.json");
2122
+ const hasPackageJSON = await import_fs_extra8.default.pathExistsSync("package.json");
2382
2123
  if (!hasPackageJSON) {
2383
2124
  await createPackageJSON();
2384
2125
  }
2385
- const hasGitignore = await import_fs_extra9.default.pathExistsSync(".gitignore");
2126
+ const hasGitignore = await import_fs_extra8.default.pathExistsSync(".gitignore");
2386
2127
  if (!hasGitignore) {
2387
- await createGitignore();
2128
+ await createGitignore({ baseDir });
2388
2129
  } else {
2389
- const hasNodeModulesIgnored = await checkGitignoreForNodeModules();
2130
+ const hasNodeModulesIgnored = await checkGitignoreForNodeModules({
2131
+ baseDir
2132
+ });
2390
2133
  if (!hasNodeModulesIgnored) {
2391
- await addNodeModulesToGitignore();
2134
+ await addNodeModulesToGitignore({ baseDir });
2392
2135
  }
2393
2136
  }
2394
2137
  await addDependencies(packageManager);
2395
- await addConfigFile(publicFolder, usingTypescript);
2396
- await addContentFile();
2397
- logNextSteps(packageManager);
2138
+ await addConfigFile({ publicFolder, baseDir, usingTypescript, framework });
2139
+ await addContentFile({ baseDir });
2140
+ if (framework.reactive) {
2141
+ await addReactiveFile[framework.name]({
2142
+ baseDir,
2143
+ framework,
2144
+ usingTypescript
2145
+ });
2146
+ }
2147
+ logNextSteps({ packageManager, framework });
2398
2148
  }
2399
- var baseDir2 = process.cwd();
2400
2149
  var choosePackageManager = async () => {
2401
- const option = await (0, import_prompts3.default)({
2150
+ const option = await (0, import_prompts2.default)({
2402
2151
  name: "selection",
2403
2152
  type: "select",
2404
2153
  message: "Choose your package manager",
@@ -2411,7 +2160,7 @@ var choosePackageManager = async () => {
2411
2160
  return option["selection"];
2412
2161
  };
2413
2162
  var chooseTypescript = async () => {
2414
- const option = await (0, import_prompts3.default)({
2163
+ const option = await (0, import_prompts2.default)({
2415
2164
  name: "selection",
2416
2165
  type: "confirm",
2417
2166
  initial: true,
@@ -2419,19 +2168,37 @@ var chooseTypescript = async () => {
2419
2168
  });
2420
2169
  return option["selection"];
2421
2170
  };
2422
- var choosePublicFolder = async () => {
2423
- const option = await (0, import_prompts3.default)({
2171
+ var choosePublicFolder = async ({ framework }) => {
2172
+ if (framework.name === "next") {
2173
+ return "public";
2174
+ }
2175
+ const option = await (0, import_prompts2.default)({
2424
2176
  name: "selection",
2425
2177
  type: "text",
2426
2178
  message: 'Where are public assets stored? (default: "public")'
2427
2179
  });
2428
2180
  return option["selection"] || "public";
2429
2181
  };
2182
+ var chooseFramework = async () => {
2183
+ const option = await (0, import_prompts2.default)({
2184
+ name: "selection",
2185
+ type: "select",
2186
+ message: "What framework are you using?",
2187
+ choices: [
2188
+ { title: "Next.js", value: { name: "next", reactive: true } },
2189
+ {
2190
+ title: "Other (SSG frameworks like hugo, jekyll, etc.)",
2191
+ value: { name: "other", reactive: false }
2192
+ }
2193
+ ]
2194
+ });
2195
+ return option["selection"];
2196
+ };
2430
2197
  var reportTelemetry = async (usingTypescript, noTelemetry) => {
2431
2198
  if (noTelemetry) {
2432
2199
  logger.info(logText("Telemetry disabled"));
2433
2200
  }
2434
- const telemetry = new import_metrics4.Telemetry({ disabled: noTelemetry });
2201
+ const telemetry = new import_metrics3.Telemetry({ disabled: noTelemetry });
2435
2202
  const schemaFileType2 = usingTypescript ? "ts" : "js";
2436
2203
  await telemetry.submitRecord({
2437
2204
  event: {
@@ -2444,22 +2211,24 @@ var createPackageJSON = async () => {
2444
2211
  logger.info(logText("No package.json found, creating one"));
2445
2212
  await execShellCommand(`npm init --yes`);
2446
2213
  };
2447
- var createGitignore = async () => {
2214
+ var createGitignore = async ({ baseDir }) => {
2448
2215
  logger.info(logText("No .gitignore found, creating one"));
2449
- await import_fs_extra9.default.outputFileSync(import_path14.default.join(baseDir2, ".gitignore"), "node_modules");
2216
+ await import_fs_extra8.default.outputFileSync(import_path12.default.join(baseDir, ".gitignore"), "node_modules");
2450
2217
  };
2451
- var checkGitignoreForNodeModules = async () => {
2452
- const gitignoreContent = await import_fs_extra9.default.readFileSync(import_path14.default.join(baseDir2, ".gitignore")).toString();
2218
+ var checkGitignoreForNodeModules = async ({
2219
+ baseDir
2220
+ }) => {
2221
+ const gitignoreContent = await import_fs_extra8.default.readFileSync(import_path12.default.join(baseDir, ".gitignore")).toString();
2453
2222
  return gitignoreContent.split("\n").some((item) => item === "node_modules");
2454
2223
  };
2455
- var addNodeModulesToGitignore = async () => {
2224
+ var addNodeModulesToGitignore = async ({ baseDir }) => {
2456
2225
  logger.info(logText("Adding node_modules to .gitignore"));
2457
- const gitignoreContent = await import_fs_extra9.default.readFileSync(import_path14.default.join(baseDir2, ".gitignore")).toString();
2226
+ const gitignoreContent = await import_fs_extra8.default.readFileSync(import_path12.default.join(baseDir, ".gitignore")).toString();
2458
2227
  const newGitignoreContent = [
2459
2228
  ...gitignoreContent.split("\n"),
2460
2229
  "node_modules"
2461
2230
  ].join("\n");
2462
- await import_fs_extra9.default.writeFileSync(import_path14.default.join(baseDir2, ".gitignore"), newGitignoreContent);
2231
+ await import_fs_extra8.default.writeFileSync(import_path12.default.join(baseDir, ".gitignore"), newGitignoreContent);
2463
2232
  };
2464
2233
  var addDependencies = async (packageManager) => {
2465
2234
  logger.info(logText("Adding dependencies, this might take a moment..."));
@@ -2472,103 +2241,89 @@ var addDependencies = async (packageManager) => {
2472
2241
  logger.info(` ${logText(packageManagers[packageManager])}`);
2473
2242
  await execShellCommand(packageManagers[packageManager]);
2474
2243
  };
2475
- var addConfigFile = async (publicFolder, usingTypescript) => {
2476
- const configPath = import_path14.default.join(".tina", `config.${usingTypescript ? "ts" : "js"}`);
2477
- const fullConfigPath = import_path14.default.join(baseDir2, configPath);
2478
- if (import_fs_extra9.default.pathExistsSync(fullConfigPath)) {
2479
- const override = await (0, import_prompts3.default)({
2244
+ var addConfigFile = async ({
2245
+ framework,
2246
+ baseDir,
2247
+ publicFolder,
2248
+ usingTypescript
2249
+ }) => {
2250
+ const configPath = import_path12.default.join(".tina", `config.${usingTypescript ? "ts" : "js"}`);
2251
+ const fullConfigPath = import_path12.default.join(baseDir, configPath);
2252
+ if (import_fs_extra8.default.pathExistsSync(fullConfigPath)) {
2253
+ const override = await (0, import_prompts2.default)({
2480
2254
  name: "selection",
2481
2255
  type: "confirm",
2482
2256
  message: `Found existing file at ${configPath}. Would you like to override?`
2483
2257
  });
2484
2258
  if (override["selection"]) {
2485
2259
  logger.info(logText(`Overriding file at ${configPath}.`));
2486
- await import_fs_extra9.default.outputFileSync(fullConfigPath, config({ publicFolder }));
2260
+ await import_fs_extra8.default.outputFileSync(fullConfigPath, config({ publicFolder, framework }));
2487
2261
  } else {
2488
2262
  logger.info(logText(`Not overriding file at ${configPath}.`));
2489
2263
  }
2490
2264
  } else {
2491
2265
  logger.info(logText(`Adding config file at .tina/config.${usingTypescript ? "ts" : "js"}`));
2492
- await import_fs_extra9.default.outputFileSync(fullConfigPath, config({ publicFolder }));
2266
+ await import_fs_extra8.default.outputFileSync(fullConfigPath, config({ publicFolder, framework }));
2493
2267
  }
2494
2268
  };
2495
- var addContentFile = async () => {
2496
- const contentPath = import_path14.default.join("content", "posts", "hello-world.md");
2497
- const fullContentPath = import_path14.default.join(baseDir2, contentPath);
2498
- if (import_fs_extra9.default.pathExistsSync(fullContentPath)) {
2499
- const override = await (0, import_prompts3.default)({
2269
+ var addContentFile = async ({ baseDir }) => {
2270
+ const contentPath = import_path12.default.join("content", "posts", "hello-world.md");
2271
+ const fullContentPath = import_path12.default.join(baseDir, contentPath);
2272
+ if (import_fs_extra8.default.pathExistsSync(fullContentPath)) {
2273
+ const override = await (0, import_prompts2.default)({
2500
2274
  name: "selection",
2501
2275
  type: "confirm",
2502
2276
  message: `Found existing file at ${contentPath}. Would you like to override?`
2503
2277
  });
2504
2278
  if (override["selection"]) {
2505
2279
  logger.info(logText(`Overriding file at ${contentPath}.`));
2506
- await import_fs_extra9.default.outputFileSync(fullContentPath, content);
2280
+ await import_fs_extra8.default.outputFileSync(fullContentPath, content);
2507
2281
  } else {
2508
2282
  logger.info(logText(`Not overriding file at ${contentPath}.`));
2509
2283
  }
2510
2284
  } else {
2511
2285
  logger.info(logText(`Adding content file at ${contentPath}`));
2512
- await import_fs_extra9.default.outputFileSync(fullContentPath, content);
2286
+ await import_fs_extra8.default.outputFileSync(fullContentPath, content);
2513
2287
  }
2514
2288
  };
2515
- var logNextSteps = (packageManager) => {
2516
- const packageManagers = {
2517
- pnpm: `pnpm`,
2518
- npm: `npx`,
2519
- yarn: `yarn`
2520
- };
2521
- logger.info(`
2522
- ${successText("TinaCMS has been initialized, to get started run:")}
2523
-
2524
- ${packageManagers[packageManager]} tinacms dev -c "<your dev command>"
2525
- `);
2526
- };
2527
- var config = (args) => `
2528
- import { defineStaticConfig } from "tinacms";
2529
-
2530
- // Your hosting provider likely exposes this as an environment variable
2531
- const branch = process.env.HEAD || process.env.VERCEL_GIT_COMMIT_REF || "main";
2532
-
2533
- export default defineStaticConfig({
2534
- branch,
2535
- clientId: null, // Get this from tina.io
2536
- token: null, // Get this from tina.io
2537
- build: {
2538
- outputFolder: "admin",
2539
- publicFolder: "${args.publicFolder}",
2540
- },
2541
- media: {
2542
- tina: {
2543
- mediaRoot: "uploads",
2544
- publicFolder: "${args.publicFolder}",
2545
- },
2546
- },
2547
- schema: {
2548
- collections: [
2549
- {
2550
- name: "post",
2551
- label: "Posts",
2552
- path: "content/posts",
2553
- fields: [
2554
- {
2555
- type: "string",
2556
- name: "title",
2557
- label: "Title",
2558
- isTitle: true,
2559
- },
2560
- {
2561
- type: "rich-text",
2562
- name: "body",
2563
- label: "Body",
2564
- isBody: true,
2565
- },
2566
- ],
2567
- },
2568
- ],
2289
+ var logNextSteps = ({
2290
+ framework,
2291
+ packageManager
2292
+ }) => {
2293
+ logSteps[framework.name]({ packageManager });
2294
+ };
2295
+ var logSteps = {
2296
+ other: ({ packageManager }) => {
2297
+ const packageManagers = {
2298
+ pnpm: `pnpm`,
2299
+ npm: `npx`,
2300
+ yarn: `yarn`
2301
+ };
2302
+ logger.info(`
2303
+ ${successText("TinaCMS has been initialized, to get started run:")}
2304
+
2305
+ ${packageManagers[packageManager]} tinacms dev -c "<your dev command>"
2306
+ `);
2569
2307
  },
2570
- });
2571
- `;
2308
+ next: ({ packageManager }) => {
2309
+ const packageManagers = {
2310
+ pnpm: `pnpm`,
2311
+ npm: `npm run`,
2312
+ yarn: `yarn`
2313
+ };
2314
+ logger.info(`
2315
+ ${successText("TinaCMS has been initialized, to get started run:")}
2316
+
2317
+ "${packageManagers[packageManager]} dev"
2318
+ `);
2319
+ logger.info(`
2320
+ ${successText("TinaCMS user interface is available at: <YourDevURL>/admin/index.html")}
2321
+ `);
2322
+ }
2323
+ };
2324
+ var config = (args) => {
2325
+ return configExamples[args.framework.name](args);
2326
+ };
2572
2327
  var content = `---
2573
2328
  title: Hello, World!
2574
2329
  ---
@@ -2579,14 +2334,48 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non lorem diam. Quis
2579
2334
 
2580
2335
  Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a posuere eros justo nec sem. Nullam laoreet accumsan metus, sit amet tincidunt orci egestas nec. Pellentesque ut aliquet ante, at tristique nunc. Donec non massa nibh. Ut posuere lacus non aliquam laoreet. Fusce pharetra ligula a felis porttitor, at mollis ipsum maximus. Donec quam tortor, vehicula a magna sit amet, tincidunt dictum enim. In hac habitasse platea dictumst. Mauris sit amet ornare ligula, blandit consequat risus. Duis malesuada pellentesque lectus, non feugiat turpis eleifend a. Nullam tempus ante et diam pretium, ac faucibus ligula interdum.
2581
2336
  `;
2337
+ var addReactiveFile = {
2338
+ next: ({
2339
+ baseDir,
2340
+ usingTypescript
2341
+ }) => {
2342
+ const usingSrc = !import_fs_extra8.default.pathExistsSync(import_path12.default.join(baseDir, "pages"));
2343
+ const pagesPath = import_path12.default.join(baseDir, usingSrc ? "src" : "", "pages");
2344
+ const packageJSONPath = import_path12.default.join(baseDir, "package.json");
2345
+ const tinaBlogPagePath = import_path12.default.join(pagesPath, "demo", "blog");
2346
+ const tinaBlogPagePathFile = import_path12.default.join(tinaBlogPagePath, `[filename].${usingTypescript ? "tsx" : "js"}`);
2347
+ if (!import_fs_extra8.default.pathExistsSync(tinaBlogPagePathFile)) {
2348
+ import_fs_extra8.default.mkdirpSync(tinaBlogPagePath);
2349
+ import_fs_extra8.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
2350
+ }
2351
+ logger.info("Adding a nextjs example... \u2705");
2352
+ const pack = JSON.parse(import_fs_extra8.default.readFileSync(packageJSONPath).toString());
2353
+ const oldScripts = pack.scripts || {};
2354
+ const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
2355
+ scripts: extendNextScripts(oldScripts)
2356
+ }), null, 2);
2357
+ import_fs_extra8.default.writeFileSync(packageJSONPath, newPack);
2358
+ }
2359
+ };
2360
+ function execShellCommand(cmd) {
2361
+ const exec = require("child_process").exec;
2362
+ return new Promise((resolve2, reject) => {
2363
+ exec(cmd, (error, stdout, stderr) => {
2364
+ if (error) {
2365
+ reject(error);
2366
+ }
2367
+ resolve2(stdout ? stdout : stderr);
2368
+ });
2369
+ });
2370
+ }
2582
2371
 
2583
2372
  // src/cmds/statusChecks/checkClientInformation.ts
2584
- var import_progress3 = __toModule(require("progress"));
2373
+ var import_progress2 = __toModule(require("progress"));
2585
2374
  var checkClientInfo = async (ctx, next, _options) => {
2586
2375
  var _a;
2587
2376
  const client = ctx.client;
2588
2377
  const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
2589
- const bar = new import_progress3.default("Checking clientId, token and branch. :prog", 1);
2378
+ const bar = new import_progress2.default("Checking clientId, token and branch. :prog", 1);
2590
2379
  try {
2591
2380
  await client.request({
2592
2381
  query: `query {
@@ -2654,10 +2443,6 @@ var cleanOption = {
2654
2443
  name: "--clean",
2655
2444
  description: "Updates all content files to remove any data not explicitly permitted by the current schema definition"
2656
2445
  };
2657
- var staticOption = {
2658
- name: "--static",
2659
- description: "Bundle Tina as a static assset"
2660
- };
2661
2446
  var useDefaultValuesOption = {
2662
2447
  name: "--useDefaultValues",
2663
2448
  description: "Adds default values to the graphQL mutation so that default values can be filled into existing documents (useful for adding a field with `required: true`)"
@@ -2768,26 +2553,11 @@ var baseCmds = [
2768
2553
  experimentalDatalayer,
2769
2554
  isomorphicGitBridge,
2770
2555
  noTelemetryOption,
2771
- schemaFileType,
2772
- staticOption
2556
+ schemaFileType
2773
2557
  ],
2774
2558
  description: "Add Tina Cloud to an existing project",
2775
2559
  action: (options) => {
2776
- if (options.static) {
2777
- chain([attachPath, checkOptions, initStaticTina], options);
2778
- } else {
2779
- chain([
2780
- attachPath,
2781
- checkOptions,
2782
- checkDeps,
2783
- initTina,
2784
- installDeps,
2785
- buildSetupCmdBuild,
2786
- buildCmdBuild,
2787
- tinaSetup,
2788
- successMessage
2789
- ], options);
2790
- }
2560
+ chain([attachPath, checkOptions, initStaticTina], options);
2791
2561
  }
2792
2562
  },
2793
2563
  {
@@ -2805,7 +2575,7 @@ var baseCmds = [
2805
2575
  auditCmdBuild,
2806
2576
  async (_ctx, next) => {
2807
2577
  logger.level = "info";
2808
- logger.info(import_chalk7.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
2578
+ logger.info(import_chalk5.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
2809
2579
  next();
2810
2580
  },
2811
2581
  audit,