@tinacms/cli 0.59.0 → 0.60.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # tinacms-cli
2
2
 
3
+ ## 0.60.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 43b40cc8b: Implement useTina in CLI init
8
+ - b399c734c: Fixes support for collection.templates in graphql
9
+ - Updated dependencies [b399c734c]
10
+ - @tinacms/datalayer@0.0.2
11
+ - @tinacms/graphql@0.59.6
12
+
13
+ ## 0.60.2
14
+
15
+ ### Patch Changes
16
+
17
+ - d17de356a: Update CLI to use apiUrl
18
+ - a67b0c1d7: Dont reinstantiate bridge and store
19
+
20
+ ## 0.60.1
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [8ad8f03fd]
25
+ - Updated dependencies [04b7988d5]
26
+ - Updated dependencies [e3c41f69d]
27
+ - Updated dependencies [f5390e841]
28
+ - Updated dependencies [32082e0b3]
29
+ - @tinacms/graphql@0.59.5
30
+ - @tinacms/datalayer@0.0.1
31
+
32
+ ## 0.60.0
33
+
34
+ ### Minor Changes
35
+
36
+ - 35884152b: Adds and audit command that checks files for errors.
37
+
38
+ ### Patch Changes
39
+
40
+ - 083aa8ec6: Rebuild database every save while in local mode
41
+ - Updated dependencies [b66aefde1]
42
+ - Updated dependencies [35884152b]
43
+ - Updated dependencies [4948beec6]
44
+ - @tinacms/graphql@0.59.4
45
+
3
46
  ## 0.59.0
4
47
 
5
48
  ### Minor Changes
package/README.md CHANGED
@@ -19,20 +19,23 @@ yarn add --dev @tinacms/cli
19
19
  ## Usage
20
20
 
21
21
  ```
22
- Usage: command [options]
22
+ Usage: @tinacms/cli command [options]
23
23
 
24
24
  Options:
25
- -V, --version output the version number
26
- -h, --help display help for command
25
+ -V, --version output the version number
26
+ -h, --help display help for command
27
27
 
28
28
  Commands:
29
- server:start [options] Start Filesystem Graphql Server
30
- schema:compile Compile schema into static files for the server
31
- schema:types Generate a GraphQL query for your site's schema, (and
32
- optionally Typescript types)
33
- help [command] display help for command
29
+ server:start [options] Start Filesystem Graphql Server
30
+ schema:compile [options] Compile schema into static files for the server
31
+ schema:types [options] Generate a GraphQL query for your site's schema, (and optionally Typescript types)
32
+ init [options] Add Tina Cloud to an existing project
33
+ audit [options] Audit your schema and the files to check for errors
34
+ help [command] display help for command
34
35
  ```
35
36
 
37
+ [See our docs](https://tina.io/docs/cli-overview/) for more information about the commands.
38
+
36
39
  ## Getting started
37
40
 
38
41
  The simplest way to get started is to add a `.tina/schema.ts` file
@@ -228,3 +231,8 @@ getPostsDocument(relativePath: "voteForPedro.md") {
228
231
  To learn how to work with this data on a Tina-enabled site, check out the [client documentation](https://tina.io/docs/tina-cloud/client/)
229
232
 
230
233
  > This API is currently somewhat limited. Specifically there's no support for filtering and sorting "list" queries. We have plans to tackle that in upcoming cycles
234
+
235
+
236
+ ## API Docs
237
+
238
+ See [our doc page](https://tina.io/docs/cli-overview/) for specific API docs
@@ -0,0 +1,31 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import type { Database, TinaCloudCollection } from '@tinacms/graphql';
14
+ declare type AuditArgs = {
15
+ collection: TinaCloudCollection;
16
+ database: Database;
17
+ rootPath: string;
18
+ useDefaultValues: boolean;
19
+ };
20
+ export declare const auditCollection: (args: AuditArgs) => Promise<boolean>;
21
+ export declare const auditDocuments: (args: AuditArgs) => Promise<boolean>;
22
+ export declare const transformDocumentIntoMutationRequestPayload: (document: {
23
+ [key: string]: unknown;
24
+ _collection: string;
25
+ __typename?: string;
26
+ _template: string;
27
+ }, instructions: {
28
+ includeCollection?: boolean;
29
+ includeTemplate?: boolean;
30
+ }, defaults?: any) => any;
31
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export declare const audit: (ctx: any, next: () => void, options: any) => Promise<void>;
14
+ export declare const printFinalMessage: (ctx: any, next: () => void, _options: any) => Promise<void>;
@@ -15,4 +15,5 @@ export declare const CMD_GEN_TYPES = "schema:types";
15
15
  export declare const CMD_START_SERVER = "server:start";
16
16
  export declare const CMD_COMPILE_MODELS = "schema:compile";
17
17
  export declare const INIT = "init";
18
+ export declare const AUDIT = "audit";
18
19
  export declare const baseCmds: Command[];
package/dist/index.js CHANGED
@@ -25,14 +25,14 @@ var __toModule = (module2) => {
25
25
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
26
26
  };
27
27
 
28
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/start-server/server.ts
28
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/server.ts
29
29
  var server_exports = {};
30
30
  __export(server_exports, {
31
31
  default: () => server_default
32
32
  });
33
33
  var import_cors, import_http, import_express, import_altair_express_middleware, import_body_parser, gqlServer, server_default;
34
34
  var init_server = __esm({
35
- "pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/start-server/server.ts"() {
35
+ "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/server.ts"() {
36
36
  import_cors = __toModule(require("cors"));
37
37
  import_http = __toModule(require("http"));
38
38
  import_express = __toModule(require("express"));
@@ -76,18 +76,18 @@ var init_server = __esm({
76
76
  }
77
77
  });
78
78
 
79
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/index.ts
79
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/index.ts
80
80
  __export(exports, {
81
81
  defineSchema: () => defineSchema,
82
82
  init: () => init
83
83
  });
84
84
  var commander = __toModule(require("commander"));
85
85
 
86
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/package.json
86
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/package.json
87
87
  var name = "@tinacms/cli";
88
- var version = "0.59.0";
88
+ var version = "0.60.3";
89
89
 
90
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/utils/theme.ts
90
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/theme.ts
91
91
  var import_chalk = __toModule(require("chalk"));
92
92
  var successText = import_chalk.default.bold.green;
93
93
  var dangerText = import_chalk.default.bold.red;
@@ -98,7 +98,7 @@ var logText = import_chalk.default.italic.gray;
98
98
  var warnText = import_chalk.default.yellowBright.bgBlack;
99
99
  var CONFIRMATION_TEXT = import_chalk.default.dim("enter to confirm");
100
100
 
101
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/middleware.ts
101
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
102
102
  var chain = async (cmds, options) => {
103
103
  const ctx = {};
104
104
  const next = async (middlewareIndex) => {
@@ -117,11 +117,11 @@ var chain = async (cmds, options) => {
117
117
  }
118
118
  };
119
119
 
120
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
120
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
121
121
  var import_graphql = __toModule(require("@tinacms/graphql"));
122
122
  var import_datalayer = __toModule(require("@tinacms/datalayer"));
123
123
 
124
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/logger/index.ts
124
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/logger/index.ts
125
125
  var import_log4js = __toModule(require("log4js"));
126
126
  var logger = import_log4js.default.getLogger();
127
127
  import_log4js.default.configure({
@@ -132,25 +132,25 @@ import_log4js.default.configure({
132
132
  });
133
133
  logger.level = "info";
134
134
 
135
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
135
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
136
136
  async function attachSchema(ctx, next, options) {
137
137
  logger.info(logText("Building schema..."));
138
- const rootPath = process.cwd();
139
- const bridge = new import_datalayer.FilesystemBridge(rootPath);
140
- const store = new import_datalayer.FilesystemStore({ rootPath });
138
+ const rootPath2 = process.cwd();
139
+ const bridge = new import_datalayer.FilesystemBridge(rootPath2);
140
+ const store = new import_datalayer.FilesystemStore({ rootPath: rootPath2 });
141
141
  const database = await (0, import_graphql.createDatabase)({ store, bridge });
142
- const schema = await (0, import_graphql.buildSchema)(rootPath, database);
142
+ const schema = await (0, import_graphql.buildSchema)(rootPath2, database);
143
143
  ctx.schema = schema;
144
144
  next();
145
145
  }
146
146
 
147
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/codegen/index.ts
147
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
148
148
  var import_graphql5 = __toModule(require("graphql"));
149
149
  var import_core = __toModule(require("@graphql-codegen/core"));
150
150
  var import_typescript = __toModule(require("@graphql-codegen/typescript"));
151
151
  var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
152
152
 
153
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/codegen/plugin.ts
153
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/plugin.ts
154
154
  var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
155
155
  return `
156
156
  // TinaSDK generated code
@@ -185,12 +185,12 @@ var AddGeneratedClient = {
185
185
  plugin: AddGeneratedClientFunc
186
186
  };
187
187
 
188
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
188
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
189
189
  var import_graphql3 = __toModule(require("graphql"));
190
190
  var import_graphql4 = __toModule(require("graphql"));
191
191
  var import_path = __toModule(require("path"));
192
192
 
193
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/visitor.ts
193
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/visitor.ts
194
194
  var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
195
195
  var import_auto_bind = __toModule(require("auto-bind"));
196
196
  var import_graphql2 = __toModule(require("graphql"));
@@ -240,7 +240,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
240
240
  }
241
241
  };
242
242
 
243
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
243
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
244
244
  var plugin = (schema, documents, config) => {
245
245
  const allAst = (0, import_graphql4.concatAST)(documents.reduce((prev, v) => {
246
246
  return [...prev, v.document];
@@ -266,7 +266,7 @@ var plugin = (schema, documents, config) => {
266
266
  };
267
267
  };
268
268
 
269
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/codegen/index.ts
269
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
270
270
  var import_load = __toModule(require("@graphql-tools/load"));
271
271
  var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
272
272
  var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = { noSDK: false }) => {
@@ -334,7 +334,7 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
334
334
  }
335
335
  };
336
336
 
337
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
337
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
338
338
  var import_graphql6 = __toModule(require("graphql"));
339
339
  var import_fs_extra = __toModule(require("fs-extra"));
340
340
  async function genTypes({ schema }, next, options) {
@@ -346,7 +346,7 @@ async function genTypes({ schema }, next, options) {
346
346
  // DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
347
347
  ${typescriptTypes}
348
348
  `);
349
- logger.info(`Typescript types => ${successText(typesPath)}`);
349
+ logger.info(`Typescript types => ${logText(typesPath)}`);
350
350
  const schemaString = await (0, import_graphql6.printSchema)(schema);
351
351
  const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
352
352
  await import_fs_extra.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
@@ -356,24 +356,24 @@ schema {
356
356
  mutation: Mutation
357
357
  }
358
358
  `);
359
- logger.info(`GraphQL types ====> ${successText(schemaPath)}`);
359
+ logger.info(`GraphQL types ====> ${logText(schemaPath)}`);
360
360
  next();
361
361
  }
362
362
 
363
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
363
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
364
364
  var import_child_process = __toModule(require("child_process"));
365
365
  var import_path3 = __toModule(require("path"));
366
366
  var import_graphql7 = __toModule(require("@tinacms/graphql"));
367
367
  var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
368
368
 
369
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
369
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
370
370
  var import_fast_glob = __toModule(require("fast-glob"));
371
371
  var import_normalize_path = __toModule(require("normalize-path"));
372
372
  var import_path2 = __toModule(require("path"));
373
373
  var import_fs_extra2 = __toModule(require("fs-extra"));
374
374
  var ts = __toModule(require("typescript"));
375
375
 
376
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
376
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
377
377
  var defaultSchema = `
378
378
  import { defineSchema } from "@tinacms/cli";
379
379
 
@@ -404,7 +404,7 @@ export default defineSchema({
404
404
  });
405
405
  `;
406
406
 
407
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
407
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
408
408
  var tinaPath = import_path2.default.join(process.cwd(), ".tina");
409
409
  var tinaGeneratedPath = import_path2.default.join(tinaPath, "__generated__");
410
410
  var tinaTempPath = import_path2.default.join(tinaGeneratedPath, "temp");
@@ -463,16 +463,16 @@ var defineSchema = (config) => {
463
463
  return config;
464
464
  };
465
465
 
466
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
466
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
467
467
  var import_chokidar = __toModule(require("chokidar"));
468
468
  var gqlPackageFile = require.resolve("@tinacms/graphql");
469
469
  async function startServer(_ctx, _next, { port = 4001, command, noWatch, experimentalData, noSDK }) {
470
- const rootPath = process.cwd();
470
+ const rootPath2 = process.cwd();
471
471
  if (!process.env.CI && !noWatch) {
472
472
  await resetGeneratedFolder();
473
473
  }
474
- const bridge = new import_datalayer2.FilesystemBridge(rootPath);
475
- const store = experimentalData ? new import_datalayer2.LevelStore(rootPath) : new import_datalayer2.FilesystemStore({ rootPath });
474
+ const bridge = new import_datalayer2.FilesystemBridge(rootPath2);
475
+ const store = experimentalData ? new import_datalayer2.LevelStore(rootPath2) : new import_datalayer2.FilesystemStore({ rootPath: rootPath2 });
476
476
  const shouldBuild = bridge.supportsBuilding();
477
477
  const database = await (0, import_graphql7.createDatabase)({ store, bridge });
478
478
  const startSubprocess = () => {
@@ -499,8 +499,8 @@ stack: ${code.stack || "No stack was provided"}`);
499
499
  };
500
500
  let ready = false;
501
501
  if (!noWatch && !process.env.CI) {
502
- import_chokidar.default.watch([`${rootPath}/**/*.{ts,gql,graphql}`], {
503
- ignored: `${import_path3.default.resolve(rootPath)}/.tina/__generated__/**/*`
502
+ import_chokidar.default.watch([`${rootPath2}/**/*.{ts,gql,graphql}`], {
503
+ ignored: `${import_path3.default.resolve(rootPath2)}/.tina/__generated__/**/*`
504
504
  }).on("ready", async () => {
505
505
  console.log("Generating Tina config");
506
506
  try {
@@ -529,8 +529,12 @@ stack: ${code.stack || "No stack was provided"}`);
529
529
  });
530
530
  }
531
531
  const build = async (noSDK2) => {
532
+ if (!process.env.CI && !noWatch) {
533
+ await resetGeneratedFolder();
534
+ }
535
+ const database2 = await (0, import_graphql7.createDatabase)({ store, bridge });
532
536
  await compile(null, null);
533
- const schema = await (0, import_graphql7.buildSchema)(rootPath, database);
537
+ const schema = await (0, import_graphql7.buildSchema)(rootPath2, database2);
534
538
  await genTypes({ schema }, () => {
535
539
  }, { noSDK: noSDK2 });
536
540
  };
@@ -589,13 +593,13 @@ stack: ${code.stack || "No stack was provided"}`);
589
593
  }
590
594
  }
591
595
 
592
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
596
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
593
597
  var import_fs_extra3 = __toModule(require("fs-extra"));
594
598
  var import_path4 = __toModule(require("path"));
595
599
  var import_progress = __toModule(require("progress"));
596
600
  var import_prompts = __toModule(require("prompts"));
597
601
 
598
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
602
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
599
603
  var adminPage = `import { TinaAdmin } from 'tinacms';
600
604
  export default TinaAdmin;
601
605
  `;
@@ -635,7 +639,19 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
635
639
  import { staticRequest, gql } from "tinacms";
636
640
  import Head from "next/head";
637
641
  import { createGlobalStyle } from "styled-components";
638
-
642
+ import { useTina } from "tinacms/dist/edit-state";
643
+
644
+ const query = gql\`
645
+ query BlogPostQuery($relativePath: String!) {
646
+ getPostsDocument(relativePath: $relativePath) {
647
+ data {
648
+ title
649
+ body
650
+ }
651
+ }
652
+ }
653
+ \`
654
+
639
655
  // Styles for markdown
640
656
  const GlobalStyle = createGlobalStyle\`
641
657
  h1,h2,h3,h4,h5 {
@@ -672,6 +688,12 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
672
688
  const defaultMarked = (markdown) => markdown;
673
689
  // Use the props returned by get static props (this can be deleted when the edit provider and tina-wrapper are moved to _app.js)
674
690
  const BlogPage = (props) => {
691
+ const { data } = useTina({
692
+ query,
693
+ variables: props.variables,
694
+ data: props.data,
695
+ });
696
+
675
697
  return (
676
698
  <>
677
699
  <Head>
@@ -697,12 +719,12 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
697
719
  }}
698
720
  >
699
721
  <h1 className="text-3xl m-8 text-center leading-8 font-extrabold tracking-tight text-gray-900 sm:text-4xl">
700
- {props.data.getPostsDocument.data.title}
722
+ {data.getPostsDocument.data.title}
701
723
  </h1>
702
724
  {/* Convert markdown to html in the browser only */}
703
725
  {typeof window !== "undefined" && (
704
726
  <ContentSection
705
- content={window.marked.parse(props.data.getPostsDocument.data.body)}
727
+ content={window.marked.parse(data.getPostsDocument.data.body)}
706
728
  ></ContentSection>
707
729
  )}
708
730
  </div>
@@ -723,16 +745,6 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
723
745
  };
724
746
 
725
747
  export const getStaticProps = async ({ params }) => {
726
- const query = gql\`
727
- query BlogPostQuery($relativePath: String!) {
728
- getPostsDocument(relativePath: $relativePath) {
729
- data {
730
- title
731
- body
732
- }
733
- }
734
- }
735
- \`
736
748
  const variables = { relativePath: \`\${params.filename}.md\` }
737
749
  let data = {}
738
750
  try {
@@ -746,7 +758,6 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
746
758
 
747
759
  return {
748
760
  props: {
749
- query,
750
761
  variables,
751
762
  data,
752
763
  //myOtherProp: 'some-other-data',
@@ -903,20 +914,22 @@ import { TinaEditProvider } from 'tinacms/dist/edit-state'
903
914
  const TinaCMS = dynamic(() => import('tinacms'), { ssr: false })
904
915
  ${extraImports || ""}
905
916
 
917
+ const branch = process.env.NEXT_PUBLIC_EDIT_BRANCH || "main";
918
+ const apiURL =
919
+ process.env.NODE_ENV == "development"
920
+ ? "http://localhost:4001/graphql"
921
+ : \`https://content.tinajs.io/content/\${process.env.NEXT_PUBLIC_TINA_CLIENT_ID}/github/\${branch}\`;
922
+
906
923
  const App = ({ Component, pageProps }) => {
907
924
  return (
908
925
  <>
909
926
  <TinaEditProvider
910
927
  editMode={
911
928
  <TinaCMS
912
- clientId={process.env.NEXT_PUBLIC_TINA_CLIENT_ID}
913
- branch={process.env.NEXT_PUBLIC_EDIT_BRANCH}
914
- isLocalClient={Boolean(
915
- Number(process.env.NEXT_PUBLIC_USE_LOCAL_CLIENT ?? true)
916
- )}
917
- {...pageProps}
929
+ apiURL={apiURL}
930
+
918
931
  >
919
- {(livePageProps) => <Component {...livePageProps} />}
932
+ <Component {...pageProps} />
920
933
  </TinaCMS>
921
934
  }
922
935
  >
@@ -929,16 +942,16 @@ const App = ({ Component, pageProps }) => {
929
942
  export default App
930
943
  `;
931
944
 
932
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
945
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
933
946
  var import_chalk2 = __toModule(require("chalk"));
934
947
  function execShellCommand(cmd) {
935
948
  const exec = require("child_process").exec;
936
- return new Promise((resolve, reject) => {
949
+ return new Promise((resolve2, reject) => {
937
950
  exec(cmd, (error, stdout, stderr) => {
938
951
  if (error) {
939
952
  console.warn(error);
940
953
  }
941
- resolve(stdout ? stdout : stderr);
954
+ resolve2(stdout ? stdout : stderr);
942
955
  });
943
956
  });
944
957
  }
@@ -1040,11 +1053,252 @@ Enjoy Tina \u{1F999} !
1040
1053
  next();
1041
1054
  }
1042
1055
 
1043
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
1056
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
1057
+ var import_graphql10 = __toModule(require("@tinacms/graphql"));
1058
+ var import_datalayer3 = __toModule(require("@tinacms/datalayer"));
1059
+
1060
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/audit.ts
1061
+ var import_graphql8 = __toModule(require("@tinacms/graphql"));
1062
+ var import_path5 = __toModule(require("path"));
1063
+ var import_graphql9 = __toModule(require("@tinacms/graphql"));
1064
+ var import_chalk3 = __toModule(require("chalk"));
1065
+ var auditCollection = async (args) => {
1066
+ let warning = false;
1067
+ const { collection, database, rootPath: rootPath2 } = args;
1068
+ logger.info(`Checking collection ${collection.name}`);
1069
+ const query = `query {
1070
+ getCollection(collection: "${collection.name}") {
1071
+ format
1072
+ documents {
1073
+ edges {
1074
+ node {
1075
+ ...on Document {
1076
+ sys {
1077
+ extension
1078
+ path
1079
+ }
1080
+ }
1081
+ }
1082
+ }
1083
+ }
1084
+ }
1085
+ }
1086
+ `;
1087
+ const result = await (0, import_graphql8.resolve)({
1088
+ database,
1089
+ query,
1090
+ variables: {}
1091
+ });
1092
+ const format = result.data.getCollection.format;
1093
+ const docs = result.data.getCollection.documents.edges;
1094
+ docs.forEach((x) => {
1095
+ const node = x.node;
1096
+ if (node.sys.extension.replace(".", "") !== format) {
1097
+ warning = true;
1098
+ logger.warn(import_chalk3.default.yellowBright(`WARNING: there is a file with extension \`${node.sys.extension}\` but in your schema it is defined to be \`.${format}\`
1099
+
1100
+ location: ${import_path5.default.join(rootPath2, node.sys.path)}`));
1101
+ }
1102
+ });
1103
+ return warning;
1104
+ };
1105
+ var auditDocuments = async (args) => {
1106
+ const { collection, database, rootPath: rootPath2, useDefaultValues } = args;
1107
+ const query = `query {
1108
+ getCollection(collection: "${collection.name}") {
1109
+ format
1110
+ slug
1111
+ documents {
1112
+ edges {
1113
+ node {
1114
+ ...on Document {
1115
+ sys {
1116
+ extension
1117
+ path
1118
+ relativePath
1119
+ }
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+ `;
1127
+ const result = await (0, import_graphql8.resolve)({
1128
+ database,
1129
+ query,
1130
+ variables: {}
1131
+ });
1132
+ let error = false;
1133
+ const documents = result.data.getCollection.documents.edges;
1134
+ for (let i = 0; i < documents.length; i++) {
1135
+ const node = documents[i].node;
1136
+ const fullPath = import_path5.default.join(rootPath2, node.sys.path);
1137
+ logger.info(`Checking document: ${fullPath}`);
1138
+ const documentQuery = `query {
1139
+ getDocument(collection: "${collection.name}", relativePath: "${node.sys.relativePath}") {
1140
+ __typename
1141
+ ...on Document {
1142
+ values
1143
+ }
1144
+ }
1145
+ }`;
1146
+ const docResult = await (0, import_graphql8.resolve)({
1147
+ database,
1148
+ query: documentQuery,
1149
+ variables: {}
1150
+ });
1151
+ const topLevelDefaults = {};
1152
+ if (useDefaultValues && typeof collection.fields !== "string") {
1153
+ collection.fields.filter((x) => !x.list).forEach((x) => {
1154
+ const value = x.ui;
1155
+ if (typeof value !== "undefined") {
1156
+ topLevelDefaults[x.name] = value.defaultValue;
1157
+ }
1158
+ });
1159
+ }
1160
+ const params = transformDocumentIntoMutationRequestPayload(docResult.data.getDocument.values, {
1161
+ includeCollection: true,
1162
+ includeTemplate: typeof collection.templates !== "undefined"
1163
+ }, topLevelDefaults);
1164
+ const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
1165
+ updateDocument(
1166
+ collection: $collection,
1167
+ relativePath: $relativePath,
1168
+ params: $params
1169
+ ){__typename}
1170
+ }`;
1171
+ const mutationRes = await (0, import_graphql8.resolve)({
1172
+ database,
1173
+ query: mutation,
1174
+ variables: {
1175
+ params,
1176
+ collection: collection.name,
1177
+ relativePath: node.sys.relativePath
1178
+ },
1179
+ silenceErrors: true
1180
+ });
1181
+ if (mutationRes.errors) {
1182
+ mutationRes.errors.forEach((err) => {
1183
+ error = true;
1184
+ logger.error(import_chalk3.default.red(err.message));
1185
+ });
1186
+ }
1187
+ }
1188
+ return error;
1189
+ };
1190
+ var transformDocumentIntoMutationRequestPayload = (document, instructions, defaults) => {
1191
+ const { _collection, __typename, _template, ...rest } = document;
1192
+ const params = transformParams(rest);
1193
+ const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
1194
+ return instructions.includeCollection ? { [_collection]: { ...defaults, ...filterObject(paramsWithTemplate) } } : { ...defaults, ...filterObject(paramsWithTemplate) };
1195
+ };
1196
+ var transformParams = (data) => {
1197
+ if (["string", "number", "boolean"].includes(typeof data)) {
1198
+ return data;
1199
+ }
1200
+ if (Array.isArray(data)) {
1201
+ return data.map((item) => transformParams(item));
1202
+ }
1203
+ try {
1204
+ (0, import_graphql9.assertShape)(data, (yup) => yup.object({ _template: yup.string().required() }));
1205
+ const { _template, __typename, ...rest } = data;
1206
+ const nested = transformParams(rest);
1207
+ return { [_template]: nested };
1208
+ } catch (e) {
1209
+ if (e.message === "Failed to assertShape - _template is a required field") {
1210
+ if (!data) {
1211
+ return void 0;
1212
+ return [];
1213
+ }
1214
+ const accum = {};
1215
+ Object.entries(data).map(([keyName, value]) => {
1216
+ accum[keyName] = transformParams(value);
1217
+ });
1218
+ return accum;
1219
+ } else {
1220
+ if (!data) {
1221
+ return void 0;
1222
+ return [];
1223
+ }
1224
+ throw e;
1225
+ }
1226
+ }
1227
+ };
1228
+ function filterObject(obj) {
1229
+ const ret = {};
1230
+ Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
1231
+ return ret;
1232
+ }
1233
+
1234
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
1235
+ var import_chalk4 = __toModule(require("chalk"));
1236
+ var import_prompts2 = __toModule(require("prompts"));
1237
+ var rootPath = process.cwd();
1238
+ var audit = async (ctx, next, options) => {
1239
+ if (options.clean) {
1240
+ logger.info(`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${import_chalk4.default.bold("clean git tree")} so unwanted changes can be undone.
1241
+
1242
+ `);
1243
+ const res = await (0, import_prompts2.default)({
1244
+ name: "useClean",
1245
+ type: "confirm",
1246
+ message: `Do you want to continue?`
1247
+ });
1248
+ if (!res.useClean) {
1249
+ logger.warn(import_chalk4.default.yellowBright("\u26A0\uFE0F Audit not complete"));
1250
+ process.exit(0);
1251
+ }
1252
+ }
1253
+ if (options.useDefaultValues && !options.clean) {
1254
+ logger.warn(import_chalk4.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
1255
+ }
1256
+ const bridge = options.clean ? new import_datalayer3.FilesystemBridge(rootPath) : new import_datalayer3.AuditFileSystemBridge(rootPath);
1257
+ const store = options.clean ? new import_datalayer3.FilesystemStore({ rootPath }) : new import_datalayer3.AuditFilesystemStore({ rootPath });
1258
+ const database = await (0, import_graphql10.createDatabase)({ store, bridge });
1259
+ const schema = await database.getSchema();
1260
+ const collections = schema.getCollections();
1261
+ let warning = false;
1262
+ let error = false;
1263
+ for (let i = 0; i < collections.length; i++) {
1264
+ const collection = collections[i];
1265
+ const returnWarning = await auditCollection({
1266
+ collection,
1267
+ database,
1268
+ rootPath,
1269
+ useDefaultValues: options.useDefaultValues
1270
+ });
1271
+ const returnError = await auditDocuments({
1272
+ collection,
1273
+ database,
1274
+ rootPath,
1275
+ useDefaultValues: options.useDefaultValues
1276
+ });
1277
+ warning = warning || returnWarning;
1278
+ error = error || returnError;
1279
+ }
1280
+ ctx.warning = warning;
1281
+ ctx.error = error;
1282
+ next();
1283
+ };
1284
+ var printFinalMessage = async (ctx, next, _options) => {
1285
+ if (ctx.error) {
1286
+ logger.error(import_chalk4.default.redBright(`\u203C\uFE0F Audit ${import_chalk4.default.bold("failed")} with errors`));
1287
+ } else if (ctx.warning) {
1288
+ logger.warn(import_chalk4.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
1289
+ } else {
1290
+ logger.info(import_chalk4.default.greenBright("\u2705 Audit passed"));
1291
+ }
1292
+ next();
1293
+ };
1294
+
1295
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
1296
+ var import_chalk5 = __toModule(require("chalk"));
1044
1297
  var CMD_GEN_TYPES = "schema:types";
1045
1298
  var CMD_START_SERVER = "server:start";
1046
1299
  var CMD_COMPILE_MODELS = "schema:compile";
1047
1300
  var INIT = "init";
1301
+ var AUDIT = "audit";
1048
1302
  var startServerPortOption = {
1049
1303
  name: "--port <port>",
1050
1304
  description: "Specify a port to run the server on. (default 4001)"
@@ -1065,6 +1319,14 @@ var noSDKCodegenOption = {
1065
1319
  name: "--noSDK",
1066
1320
  description: "Don't generate the generated client SDK"
1067
1321
  };
1322
+ var cleanOption = {
1323
+ name: "--clean",
1324
+ description: "Submit gql mutation to all files to git rid of any data that is not defined in the `schema.ts`"
1325
+ };
1326
+ var useDefaultValuesOption = {
1327
+ name: "--useDefaultValues",
1328
+ 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`)"
1329
+ };
1068
1330
  var baseCmds = [
1069
1331
  {
1070
1332
  command: CMD_START_SERVER,
@@ -1106,10 +1368,34 @@ var baseCmds = [
1106
1368
  tinaSetup,
1107
1369
  successMessage
1108
1370
  ], options)
1371
+ },
1372
+ {
1373
+ options: [cleanOption, useDefaultValuesOption],
1374
+ command: AUDIT,
1375
+ description: "Audit your schema and the files to check for errors",
1376
+ action: (options) => chain([
1377
+ async (_ctx, next) => {
1378
+ logger.level = "error";
1379
+ next();
1380
+ },
1381
+ async (_ctx, next) => {
1382
+ await compile(_ctx, next);
1383
+ next();
1384
+ },
1385
+ attachSchema,
1386
+ genTypes,
1387
+ async (_ctx, next) => {
1388
+ logger.level = "info";
1389
+ logger.info(import_chalk5.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
1390
+ next();
1391
+ },
1392
+ audit,
1393
+ printFinalMessage
1394
+ ], options)
1109
1395
  }
1110
1396
  ];
1111
1397
 
1112
- // pnp:/Users/jeffsee/code/tinacms/packages/@tinacms/cli/src/index.ts
1398
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/index.ts
1113
1399
  var program = new commander.Command(name);
1114
1400
  var registerCommands = (commands, noHelp = false) => {
1115
1401
  commands.forEach((command, i) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "0.59.0",
3
+ "version": "0.60.3",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -21,7 +21,7 @@
21
21
  ]
22
22
  },
23
23
  "devDependencies": {
24
- "@tinacms/scripts": "0.50.4",
24
+ "@tinacms/scripts": "0.50.5",
25
25
  "@types/clear": "0.1.0",
26
26
  "@types/cors": "2.8.5",
27
27
  "@types/express": "^4.17.7",
@@ -56,8 +56,8 @@
56
56
  "@graphql-codegen/visitor-plugin-common": "^2.4.0",
57
57
  "@graphql-tools/graphql-file-loader": "^7.2.0",
58
58
  "@graphql-tools/load": "^7.3.2",
59
- "@tinacms/datalayer": "0.0.1",
60
- "@tinacms/graphql": "0.59.3",
59
+ "@tinacms/datalayer": "0.0.2",
60
+ "@tinacms/graphql": "0.59.6",
61
61
  "ajv": "^6.12.3",
62
62
  "altair-express-middleware": "4.0.6",
63
63
  "auto-bind": "^4.0.0",