@tinacms/cli 0.61.8 → 0.61.11

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.
@@ -11,3 +11,4 @@
11
11
  limitations under the License.
12
12
  */
13
13
  export declare const attachPath: (ctx: any, next: () => void, _options: any) => Promise<void>;
14
+ export declare const isProjectTs: (rootPath: string) => Promise<boolean>;
@@ -10,22 +10,17 @@
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import { Bridge, Database } from '@tinacms/graphql';
14
- import { Store } from '@tinacms/datalayer';
15
- interface BuildOptions {
16
- ctx: any;
17
- database: Database;
18
- store: Store;
19
- bridge: Bridge;
20
- noWatch?: boolean;
21
- isomorphicGitBridge?: boolean;
13
+ import { Database } from '@tinacms/graphql';
14
+ import { DocumentNode } from 'graphql';
15
+ interface ClientGenOptions {
16
+ noSDK?: boolean;
17
+ local?: boolean;
22
18
  verbose?: boolean;
19
+ }
20
+ interface BuildOptions {
23
21
  dev?: boolean;
24
- local?: boolean;
25
- noSDK?: boolean;
26
- beforeBuild?: () => Promise<any>;
27
- afterBuild?: () => Promise<any>;
28
- skipIndex?: boolean;
22
+ verbose?: boolean;
23
+ rootPath?: string;
29
24
  }
30
25
  interface BuildSetupOptions {
31
26
  isomorphicGitBridge?: boolean;
@@ -36,7 +31,32 @@ export declare const buildSetupCmdServerStart: (ctx: any, next: () => void, opts
36
31
  export declare const buildSetupCmdAudit: (ctx: any, next: () => void, options: {
37
32
  clean: boolean;
38
33
  }) => Promise<void>;
39
- export declare const buildCmdBuild: (ctx: any, next: () => void, options: Omit<BuildOptions & BuildSetupOptions, 'bridge' | 'database' | 'store'>) => Promise<void>;
40
- export declare const auditCmdBuild: (ctx: any, next: () => void, options: Omit<BuildOptions & BuildSetupOptions, 'bridge' | 'database' | 'store'>) => Promise<void>;
41
- export declare const build: ({ noWatch, ctx, bridge, database, store, beforeBuild, afterBuild, dev, local, verbose, noSDK, skipIndex, }: BuildOptions) => Promise<void>;
34
+ export declare const buildCmdBuild: (ctx: {
35
+ builder: ConfigBuilder;
36
+ rootPath: string;
37
+ usingTs: boolean;
38
+ }, next: () => void, options: Omit<BuildOptions & BuildSetupOptions & ClientGenOptions, 'bridge' | 'database' | 'store'>) => Promise<void>;
39
+ export declare const auditCmdBuild: (ctx: {
40
+ builder: ConfigBuilder;
41
+ rootPath: string;
42
+ database: Database;
43
+ }, next: () => void, options: Omit<BuildOptions & BuildSetupOptions, 'bridge' | 'database' | 'store'>) => Promise<void>;
44
+ export declare class ConfigBuilder {
45
+ private database;
46
+ constructor(database: Database);
47
+ build({ dev, verbose, rootPath }: BuildOptions): Promise<{
48
+ schema: any;
49
+ graphQLSchema: DocumentNode;
50
+ tinaSchema: any;
51
+ }>;
52
+ genTypedClient({ usingTs, compiledSchema, noSDK, verbose, local, }: ClientGenOptions & {
53
+ usingTs: boolean;
54
+ compiledSchema: any;
55
+ }): Promise<void>;
56
+ }
57
+ export declare const buildAdmin: ({ schema, local, rootPath, }: {
58
+ schema: any;
59
+ local: boolean;
60
+ rootPath: string;
61
+ }) => Promise<void>;
42
62
  export {};
@@ -15,7 +15,13 @@ declare type AuditArgs = {
15
15
  collection: TinaCloudCollection;
16
16
  database: Database;
17
17
  rootPath: string;
18
+ documents: {
19
+ node: {
20
+ path: string;
21
+ };
22
+ }[];
18
23
  useDefaultValues: boolean;
24
+ verbose?: boolean;
19
25
  };
20
26
  export declare const auditCollection: (args: AuditArgs) => Promise<boolean>;
21
27
  export declare const auditDocuments: (args: AuditArgs) => Promise<boolean>;
@@ -10,4 +10,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- export declare const defaultSchema = "\nimport { defineSchema, defineConfig } from 'tinacms'\nimport { client } from './__generated__/client'\n\n\nconst branch =\n process.env.NEXT_PUBLIC_TINA_BRANCH ||\n process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||\n process.env.HEAD ||\n 'main'\nconst schema = defineSchema({\n // See https://tina.io/docs/tina-cloud/connecting-site/ for more information about this config\n config: {\n token: '<Your Read Only Token>', // generated on app.tina.io,\n clientId: '<Your Client ID>', // generated on app.tina.io\n branch,\n },\n collections: [\n {\n label: 'Blog Posts',\n name: 'post',\n path: 'content/posts',\n format: 'mdx',\n fields: [\n {\n type: 'string',\n label: 'Title',\n name: 'title',\n },\n {\n type: 'rich-text',\n label: 'Blog Post Body',\n name: 'body',\n isBody: true,\n templates: [\n {\n name: 'PageSection',\n label: 'Page Section',\n fields: [\n {\n type: 'string',\n name: 'heading',\n label: 'Heading',\n },\n {\n type: 'string',\n name: 'content',\n label: 'Content',\n ui: {\n component: 'textarea',\n },\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n})\n\nexport default schema\n\n// Your tina config\n\nexport const tinaConfig = defineConfig({\n client,\n schema,\n cmsCallback: (cms) => {\n // add your CMS callback code here (if you want)\n\n // The Route Mapper\n /**\n * 1. Import `tinacms` and `RouteMappingPlugin`\n **/\n import('tinacms').then(({ RouteMappingPlugin }) => {\n /**\n * 2. Define the `RouteMappingPlugin` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details\n **/\n const RouteMapping = new RouteMappingPlugin((collection, document) => {\n return undefined\n })\n /**\n * 3. Add the `RouteMappingPlugin` to the `cms`.\n **/\n cms.plugins.add(RouteMapping)\n })\n\n return cms\n },\n})\n\n";
13
+ export declare const defaultSchema = "\nimport { defineSchema, defineConfig } from 'tinacms'\nimport { client } from './__generated__/client'\n\n\nconst branch =\n process.env.NEXT_PUBLIC_TINA_BRANCH ||\n process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||\n process.env.HEAD ||\n 'main'\nconst schema = defineSchema({\n // See https://tina.io/docs/tina-cloud/connecting-site/ for more information about this config\n config: {\n token: '<Your Read Only Token>', // generated on app.tina.io,\n clientId: '<Your Client ID>', // generated on app.tina.io\n branch,\n },\n collections: [\n {\n label: 'Blog Posts',\n name: 'post',\n path: 'content/posts',\n format: 'mdx',\n ui: {\n router: ({ document }) => {\n // 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.\n return `/demo/blog/${document._sys.filename}`\n },\n },\n fields: [\n {\n type: 'string',\n label: 'Title',\n name: 'title',\n },\n {\n type: 'rich-text',\n label: 'Blog Post Body',\n name: 'body',\n isBody: true,\n templates: [\n {\n name: 'PageSection',\n label: 'Page Section',\n fields: [\n {\n type: 'string',\n name: 'heading',\n label: 'Heading',\n },\n {\n type: 'string',\n name: 'content',\n label: 'Content',\n ui: {\n component: 'textarea',\n },\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n})\n\nexport default schema\n\n// Your tina config\n\nexport const tinaConfig = defineConfig({\n client,\n schema,\n})\n\n";
@@ -20,14 +20,16 @@ export declare const compileClient: (ctx: any, next: any, options: {
20
20
  verbose?: boolean;
21
21
  dev?: boolean;
22
22
  }) => Promise<any>;
23
- export declare const compileFile: (ctx: any, _next: any, options: {
23
+ export declare const compileFile: (options: {
24
24
  schemaFileType?: string;
25
25
  verbose?: boolean;
26
26
  dev?: boolean;
27
+ rootPath: string;
27
28
  }, fileName: string) => Promise<{}>;
28
- export declare const compileSchema: (ctx: any, _next: any, options: {
29
+ export declare const compileSchema: (options: {
29
30
  schemaFileType?: string;
30
31
  verbose?: boolean;
31
32
  dev?: boolean;
32
- }) => Promise<void>;
33
+ rootPath;
34
+ }) => Promise<any>;
33
35
  export declare const defineSchema: (config: TinaCloudSchema) => TinaCloudSchema;
@@ -10,5 +10,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- export * from './attachSchema';
14
13
  export * from './genTypes';
@@ -10,12 +10,12 @@
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
+ import type { Bridge, Database } from '@tinacms/graphql';
14
+ import { ConfigBuilder } from '../../buildTina';
13
15
  interface Options {
14
16
  port?: number;
15
17
  command?: string;
16
18
  watchFolders?: string[];
17
- experimentalData?: boolean;
18
- isomorphicGitBridge?: boolean;
19
19
  noWatch?: boolean;
20
20
  noSDK: boolean;
21
21
  noTelemetry: boolean;
@@ -23,5 +23,11 @@ interface Options {
23
23
  dev?: boolean;
24
24
  local: boolean;
25
25
  }
26
- export declare function startServer(ctx: any, next: any, { port, noWatch, isomorphicGitBridge, noSDK, noTelemetry, watchFolders, verbose, dev, local, }: Options): Promise<void>;
26
+ export declare function startServer(ctx: {
27
+ builder: ConfigBuilder;
28
+ rootPath: string;
29
+ database: Database;
30
+ bridge: Bridge;
31
+ usingTs: boolean;
32
+ }, next: any, { port, noWatch, noSDK, noTelemetry, watchFolders, verbose, dev, }: Options): Promise<void>;
27
33
  export {};
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_extra7, import_path9, MediaModel;
73
+ var import_fs_extra8, import_path10, MediaModel;
74
74
  var init_media = __esm({
75
75
  "src/server/models/media.ts"() {
76
- import_fs_extra7 = __toModule(require("fs-extra"));
77
- import_path9 = __toModule(require("path"));
76
+ import_fs_extra8 = __toModule(require("fs-extra"));
77
+ import_path10 = __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_path9.join)(this.publicFolder, this.mediaRoot, args.searchPath);
86
+ const folderPath = (0, import_path10.join)(this.publicFolder, this.mediaRoot, args.searchPath);
87
87
  const searchPath = parseMediaFolder(args.searchPath);
88
- const filesStr = await import_fs_extra7.default.readdir(folderPath);
88
+ const filesStr = await import_fs_extra8.default.readdir(folderPath);
89
89
  const filesProm = filesStr.map(async (file) => {
90
- const filePath = (0, import_path9.join)(folderPath, file);
91
- const stat = await import_fs_extra7.default.stat(filePath);
90
+ const filePath = (0, import_path10.join)(folderPath, file);
91
+ const stat = await import_fs_extra8.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_path9.join)(this.publicFolder, this.mediaRoot, args.searchPath);
148
- await import_fs_extra7.default.stat(file);
149
- await import_fs_extra7.default.remove(file);
147
+ const file = (0, import_path10.join)(this.publicFolder, this.mediaRoot, args.searchPath);
148
+ await import_fs_extra8.default.stat(file);
149
+ await import_fs_extra8.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_path10, import_multer, createMediaRouter;
161
+ var import_express, import_path11, 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_path10 = __toModule(require("path"));
165
+ import_path11 = __toModule(require("path"));
166
166
  import_multer = __toModule(require("multer"));
167
167
  init_media();
168
168
  createMediaRouter = (config) => {
169
- const mediaFolder = (0, import_path10.join)(process.cwd(), config.publicFolder, config.mediaRoot);
169
+ const mediaFolder = (0, import_path11.join)(process.cwd(), config.publicFolder, config.mediaRoot);
170
170
  const storage = import_multer.default.diskStorage({
171
171
  destination: function(req, file, cb) {
172
172
  cb(null, mediaFolder);
@@ -293,7 +293,7 @@ var commander = __toModule(require("commander"));
293
293
 
294
294
  // package.json
295
295
  var name = "@tinacms/cli";
296
- var version = "0.61.8";
296
+ var version = "0.61.11";
297
297
 
298
298
  // src/cmds/audit/audit.ts
299
299
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -313,81 +313,14 @@ logger.level = "info";
313
313
  // src/cmds/audit/audit.ts
314
314
  var import_graphql2 = __toModule(require("@tinacms/graphql"));
315
315
  var import_chalk = __toModule(require("chalk"));
316
- var auditCollection = async (args) => {
317
- let warning = false;
318
- const { collection, database, rootPath: rootPath2 } = args;
319
- logger.info(`Checking collection ${collection.name}`);
320
- const query = `query {
321
- collection(collection: "${collection.name}") {
322
- format
323
- documents {
324
- edges {
325
- node {
326
- ...on Document {
327
- _sys {
328
- extension
329
- path
330
- }
331
- }
332
- }
333
- }
334
- }
335
- }
336
- }
337
- `;
338
- const result = await (0, import_graphql.resolve)({
339
- database,
340
- query,
341
- variables: {}
342
- });
343
- const format = result.data.collection.format;
344
- const docs = result.data.collection.documents.edges;
345
- docs.forEach((x) => {
346
- const node = x.node;
347
- if (node._sys.extension.replace(".", "") !== format) {
348
- warning = true;
349
- logger.warn(import_chalk.default.yellowBright(`WARNING: there is a file with extension \`${node._sys.extension}\` but in your schema it is defined to be \`.${format}\`
350
-
351
- location: ${import_path.default.join(rootPath2, node._sys.path)}`));
352
- }
353
- });
354
- return warning;
355
- };
356
316
  var auditDocuments = async (args) => {
357
- const { collection, database, rootPath: rootPath2, useDefaultValues } = args;
358
- const query = `query {
359
- collection(collection: "${collection.name}") {
360
- format
361
- slug
362
- documents {
363
- edges {
364
- node {
365
- ...on Document {
366
- _sys {
367
- extension
368
- path
369
- relativePath
370
- }
371
- }
372
- }
373
- }
374
- }
375
- }
376
- }
377
- `;
378
- const result = await (0, import_graphql.resolve)({
379
- database,
380
- query,
381
- variables: {}
382
- });
317
+ const { collection, database, useDefaultValues, documents } = args;
383
318
  let error = false;
384
- const documents = result.data.collection.documents.edges;
385
319
  for (let i = 0; i < documents.length; i++) {
386
320
  const node = documents[i].node;
387
- const fullPath = import_path.default.join(rootPath2, node._sys.path);
388
- logger.info(`Checking document: ${fullPath}`);
321
+ const relativePath = node.path.replace(`${collection.path}/`, "");
389
322
  const documentQuery = `query {
390
- document(collection: "${collection.name}", relativePath: "${node._sys.relativePath}") {
323
+ document(collection: "${collection.name}", relativePath: "${relativePath}") {
391
324
  __typename
392
325
  ...on Document {
393
326
  _values
@@ -397,44 +330,58 @@ var auditDocuments = async (args) => {
397
330
  const docResult = await (0, import_graphql.resolve)({
398
331
  database,
399
332
  query: documentQuery,
400
- variables: {}
333
+ variables: {},
334
+ silenceErrors: true,
335
+ verbose: args.verbose || false,
336
+ isAudit: true
401
337
  });
402
- const topLevelDefaults = {};
403
- if (useDefaultValues && typeof collection.fields !== "string") {
404
- collection.fields.filter((x) => !x.list).forEach((x) => {
405
- const value = x.ui;
406
- if (typeof value !== "undefined") {
407
- topLevelDefaults[x.name] = value.defaultValue;
338
+ if (docResult.errors) {
339
+ error = true;
340
+ docResult.errors.forEach((err) => {
341
+ logger.error(import_chalk.default.red(err.message));
342
+ if (err.originalError.originalError) {
343
+ logger.error(import_chalk.default.red(` ${err.originalError.originalError.message}`));
408
344
  }
409
345
  });
410
- }
411
- const params = transformDocumentIntoMutationRequestPayload(docResult.data.document._values, {
412
- includeCollection: true,
413
- includeTemplate: typeof collection.templates !== "undefined"
414
- }, topLevelDefaults);
415
- const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
346
+ } else {
347
+ const topLevelDefaults = {};
348
+ if (useDefaultValues && typeof collection.fields !== "string") {
349
+ collection.fields.filter((x) => !x.list).forEach((x) => {
350
+ const value = x.ui;
351
+ if (typeof value !== "undefined") {
352
+ topLevelDefaults[x.name] = value.defaultValue;
353
+ }
354
+ });
355
+ }
356
+ const params = transformDocumentIntoMutationRequestPayload(docResult.data.document._values, {
357
+ includeCollection: true,
358
+ includeTemplate: typeof collection.templates !== "undefined"
359
+ }, topLevelDefaults);
360
+ const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
416
361
  updateDocument(
417
362
  collection: $collection,
418
363
  relativePath: $relativePath,
419
364
  params: $params
420
365
  ){__typename}
421
366
  }`;
422
- const mutationRes = await (0, import_graphql.resolve)({
423
- database,
424
- query: mutation,
425
- variables: {
426
- params,
427
- collection: collection.name,
428
- relativePath: node._sys.relativePath
429
- },
430
- silenceErrors: true,
431
- verbose: true
432
- });
433
- if (mutationRes.errors) {
434
- mutationRes.errors.forEach((err) => {
435
- error = true;
436
- logger.error(import_chalk.default.red(err.message));
367
+ const mutationRes = await (0, import_graphql.resolve)({
368
+ database,
369
+ query: mutation,
370
+ variables: {
371
+ params,
372
+ collection: collection.name,
373
+ relativePath
374
+ },
375
+ isAudit: true,
376
+ silenceErrors: true,
377
+ verbose: args.verbose || false
437
378
  });
379
+ if (mutationRes.errors) {
380
+ mutationRes.errors.forEach((err) => {
381
+ error = true;
382
+ logger.error(import_chalk.default.red(err.message));
383
+ });
384
+ }
438
385
  }
439
386
  }
440
387
  return error;
@@ -484,9 +431,22 @@ function filterObject(obj) {
484
431
  }
485
432
 
486
433
  // src/cmds/audit/index.ts
487
- var import_chalk2 = __toModule(require("chalk"));
434
+ var import_chalk3 = __toModule(require("chalk"));
488
435
  var import_prompts = __toModule(require("prompts"));
489
436
  var import_metrics = __toModule(require("@tinacms/metrics"));
437
+
438
+ // src/utils/theme.ts
439
+ var import_chalk2 = __toModule(require("chalk"));
440
+ var successText = import_chalk2.default.bold.green;
441
+ var dangerText = import_chalk2.default.bold.red;
442
+ var neutralText = import_chalk2.default.bold.cyan;
443
+ var labelText = import_chalk2.default.bold;
444
+ var cmdText = import_chalk2.default.inverse;
445
+ var logText = import_chalk2.default.italic.gray;
446
+ var warnText = import_chalk2.default.yellowBright.bgBlack;
447
+ var CONFIRMATION_TEXT = import_chalk2.default.dim("enter to confirm");
448
+
449
+ // src/cmds/audit/index.ts
490
450
  var rootPath = process.cwd();
491
451
  var audit = async (ctx, next, options) => {
492
452
  const telemetry = new import_metrics.Telemetry({ disabled: options.noTelemetry });
@@ -498,7 +458,7 @@ var audit = async (ctx, next, options) => {
498
458
  }
499
459
  });
500
460
  if (options.clean) {
501
- 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_chalk2.default.bold("clean git tree")} so unwanted changes can be undone.
461
+ logger.info(`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${import_chalk3.default.bold("clean git tree")} so unwanted changes can be undone.
502
462
 
503
463
  `);
504
464
  const res = await (0, import_prompts.default)({
@@ -507,52 +467,47 @@ var audit = async (ctx, next, options) => {
507
467
  message: `Do you want to continue?`
508
468
  });
509
469
  if (!res.useClean) {
510
- logger.warn(import_chalk2.default.yellowBright("\u26A0\uFE0F Audit not complete"));
470
+ logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit not complete"));
511
471
  process.exit(0);
512
472
  }
513
473
  }
514
474
  if (options.useDefaultValues && !options.clean) {
515
- logger.warn(import_chalk2.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
475
+ logger.warn(import_chalk3.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
516
476
  }
517
477
  const database = ctx.database;
518
478
  const schema = await database.getSchema();
519
479
  const collections = schema.getCollections();
520
- let warning = false;
521
480
  let error = false;
522
481
  for (let i = 0; i < collections.length; i++) {
523
482
  const collection = collections[i];
524
- const returnWarning = await auditCollection({
525
- collection,
526
- database,
527
- rootPath,
528
- useDefaultValues: options.useDefaultValues
529
- });
483
+ const docs = await database.query({ collection: collection.name, first: -1, filterChain: [] }, (item) => ({ path: item }));
484
+ logger.info(`Checking ${neutralText(collection.name)} collection`);
530
485
  const returnError = await auditDocuments({
531
486
  collection,
532
487
  database,
533
488
  rootPath,
534
- useDefaultValues: options.useDefaultValues
489
+ useDefaultValues: options.useDefaultValues,
490
+ documents: docs.edges,
491
+ verbose: ctx.verbose
535
492
  });
536
- warning = warning || returnWarning;
537
493
  error = error || returnError;
538
494
  }
539
- ctx.warning = warning;
540
495
  ctx.error = error;
541
496
  next();
542
497
  };
543
498
  var printFinalMessage = async (ctx, next, _options) => {
544
499
  if (ctx.error) {
545
- logger.error(import_chalk2.default.redBright(`\u203C\uFE0F Audit ${import_chalk2.default.bold("failed")} with errors`));
500
+ logger.error(import_chalk3.default.redBright(`\u203C\uFE0F Audit ${import_chalk3.default.bold("failed")} with errors`));
546
501
  } else if (ctx.warning) {
547
- logger.warn(import_chalk2.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
502
+ logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
548
503
  } else {
549
- logger.info(import_chalk2.default.greenBright("\u2705 Audit passed"));
504
+ logger.info(import_chalk3.default.greenBright("\u2705 Audit passed"));
550
505
  }
551
506
  next();
552
507
  };
553
508
 
554
509
  // src/cmds/init/setup-files/index.ts
555
- var import_chalk3 = __toModule(require("chalk"));
510
+ var import_chalk4 = __toModule(require("chalk"));
556
511
  var adminPage = `import { TinaAdmin } from 'tinacms';
557
512
  export default TinaAdmin;
558
513
  `;
@@ -856,15 +811,15 @@ export default App
856
811
  `;
857
812
  };
858
813
  var AppJsContentPrintout = (usingSrc, extraImports) => {
859
- const importLine = import_chalk3.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
814
+ const importLine = import_chalk4.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
860
815
  return `${importLine}
861
816
  ${extraImports || ""}
862
817
 
863
818
  const App = ({ Component, pageProps }) => {
864
819
  return (
865
- ${import_chalk3.default.green("+ <Tina>")}
820
+ ${import_chalk4.default.green("+ <Tina>")}
866
821
  <Component {...pageProps} />
867
- ${import_chalk3.default.green("+ </Tina>")}
822
+ ${import_chalk4.default.green("+ </Tina>")}
868
823
  )
869
824
  }
870
825
 
@@ -905,17 +860,6 @@ const DynamicTina = ({ children }) => {
905
860
  export default DynamicTina
906
861
  `;
907
862
 
908
- // src/utils/theme.ts
909
- var import_chalk4 = __toModule(require("chalk"));
910
- var successText = import_chalk4.default.bold.green;
911
- var dangerText = import_chalk4.default.bold.red;
912
- var neutralText = import_chalk4.default.bold.cyan;
913
- var labelText = import_chalk4.default.bold;
914
- var cmdText = import_chalk4.default.inverse;
915
- var logText = import_chalk4.default.italic.gray;
916
- var warnText = import_chalk4.default.yellowBright.bgBlack;
917
- var CONFIRMATION_TEXT = import_chalk4.default.dim("enter to confirm");
918
-
919
863
  // src/utils/script-helpers.ts
920
864
  function generateGqlScript(scriptValue) {
921
865
  return `tinacms dev -c "${scriptValue}"`;
@@ -1048,7 +992,7 @@ async function tinaSetup(_ctx, next, _options) {
1048
992
  }
1049
993
  if (!import_fs_extra.default.existsSync(TinaProviderPath) && !import_fs_extra.default.existsSync(TinaDynamicProvider)) {
1050
994
  import_fs_extra.default.mkdirpSync(componentFolder);
1051
- import_fs_extra.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.schemaFileType || "ts"}'`));
995
+ import_fs_extra.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.usingTs ? "ts" : "js"}'`));
1052
996
  import_fs_extra.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
1053
997
  }
1054
998
  logger.level = "info";
@@ -1141,6 +1085,9 @@ var chain = async (cmds, options) => {
1141
1085
  await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
1142
1086
  } catch (err) {
1143
1087
  console.error(` ${dangerText(err)}`);
1088
+ if (err.stack) {
1089
+ console.log(err.stack);
1090
+ }
1144
1091
  process.exit(1);
1145
1092
  }
1146
1093
  };
@@ -1219,6 +1166,12 @@ const schema = defineSchema({
1219
1166
  name: 'post',
1220
1167
  path: 'content/posts',
1221
1168
  format: 'mdx',
1169
+ ui: {
1170
+ router: ({ document }) => {
1171
+ // 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.
1172
+ return \`/demo/blog/\${document._sys.filename}\`
1173
+ },
1174
+ },
1222
1175
  fields: [
1223
1176
  {
1224
1177
  type: 'string',
@@ -1264,28 +1217,6 @@ export default schema
1264
1217
  export const tinaConfig = defineConfig({
1265
1218
  client,
1266
1219
  schema,
1267
- cmsCallback: (cms) => {
1268
- // add your CMS callback code here (if you want)
1269
-
1270
- // The Route Mapper
1271
- /**
1272
- * 1. Import \`tinacms\` and \`RouteMappingPlugin\`
1273
- **/
1274
- import('tinacms').then(({ RouteMappingPlugin }) => {
1275
- /**
1276
- * 2. Define the \`RouteMappingPlugin\` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details
1277
- **/
1278
- const RouteMapping = new RouteMappingPlugin((collection, document) => {
1279
- return undefined
1280
- })
1281
- /**
1282
- * 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
1283
- **/
1284
- cms.plugins.add(RouteMapping)
1285
- })
1286
-
1287
- return cms
1288
- },
1289
1220
  })
1290
1221
 
1291
1222
  `;
@@ -1304,9 +1235,9 @@ var getPath = ({
1304
1235
  }
1305
1236
  const filePaths = allowedTypes.map((ext) => import_path3.default.join(projectDir, `${filename}.${ext}`));
1306
1237
  let inputFile = void 0;
1307
- filePaths.every((path7) => {
1308
- if (import_fs_extra2.default.existsSync(path7)) {
1309
- inputFile = path7;
1238
+ filePaths.every((path8) => {
1239
+ if (import_fs_extra2.default.existsSync(path8)) {
1240
+ inputFile = path8;
1310
1241
  return false;
1311
1242
  }
1312
1243
  return true;
@@ -1425,8 +1356,8 @@ var compileClient = async (ctx, next, options) => {
1425
1356
  }
1426
1357
  return next();
1427
1358
  };
1428
- var compileFile = async (ctx, _next, options, fileName) => {
1429
- const root2 = ctx.rootPath;
1359
+ var compileFile = async (options, fileName) => {
1360
+ const root2 = options.rootPath;
1430
1361
  if (!root2) {
1431
1362
  throw new Error("ctx.rootPath has not been attached");
1432
1363
  }
@@ -1447,9 +1378,6 @@ var compileFile = async (ctx, _next, options, fileName) => {
1447
1378
  if (!schemaFileType2) {
1448
1379
  throw new Error(`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`);
1449
1380
  }
1450
- if (ctx) {
1451
- ctx.schemaFileType = schemaFileType2;
1452
- }
1453
1381
  let schemaExists = true;
1454
1382
  try {
1455
1383
  getPath({
@@ -1507,14 +1435,14 @@ var compileFile = async (ctx, _next, options, fileName) => {
1507
1435
  }
1508
1436
  return returnObject;
1509
1437
  };
1510
- var compileSchema = async (ctx, _next, options) => {
1511
- const root2 = ctx.rootPath;
1438
+ var compileSchema = async (options) => {
1439
+ const root2 = options.rootPath;
1512
1440
  const tinaPath = import_path4.default.join(root2, ".tina");
1513
1441
  const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
1514
1442
  const tinaConfigPath = import_path4.default.join(tinaGeneratedPath, "config");
1515
- let schema = await compileFile(ctx, _next, options, "schema");
1443
+ let schema = await compileFile(options, "schema");
1516
1444
  try {
1517
- const config = await compileFile(ctx, _next, options, "config");
1445
+ const config = await compileFile(options, "config");
1518
1446
  const configCopy = _.cloneDeep(config);
1519
1447
  delete configCopy.schema;
1520
1448
  if (config == null ? void 0 : config.schema) {
@@ -1522,8 +1450,8 @@ var compileSchema = async (ctx, _next, options) => {
1522
1450
  }
1523
1451
  } catch (e) {
1524
1452
  }
1525
- ctx.schema = schema;
1526
1453
  await import_fs_extra3.default.outputFile(import_path4.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
1454
+ return schema;
1527
1455
  };
1528
1456
  var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
1529
1457
  if (verbose)
@@ -1593,29 +1521,36 @@ var loaders = {
1593
1521
  };
1594
1522
 
1595
1523
  // src/cmds/start-server/index.ts
1596
- var import_path11 = __toModule(require("path"));
1524
+ var import_path12 = __toModule(require("path"));
1597
1525
  var import_chalk6 = __toModule(require("chalk"));
1598
1526
  var import_chokidar = __toModule(require("chokidar"));
1599
1527
  var import_metrics3 = __toModule(require("@tinacms/metrics"));
1600
1528
 
1601
- // src/buildTina/index.ts
1602
- var import_async_retry = __toModule(require("async-retry"));
1603
- var import_fs_extra6 = __toModule(require("fs-extra"));
1604
- var import_graphql10 = __toModule(require("@tinacms/graphql"));
1605
- var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
1606
- var import_path8 = __toModule(require("path"));
1529
+ // src/cmds/start-server/lock.ts
1530
+ var AsyncLock = class {
1531
+ constructor() {
1532
+ this.disable = () => {
1533
+ };
1534
+ this.promise = Promise.resolve();
1535
+ }
1536
+ enable() {
1537
+ this.promise = new Promise((resolve2) => this.disable = resolve2);
1538
+ }
1539
+ };
1607
1540
 
1608
- // src/cmds/query-gen/attachSchema.ts
1609
- var import_graphql4 = __toModule(require("@tinacms/graphql"));
1541
+ // src/buildTina/index.ts
1542
+ var import_fs_extra7 = __toModule(require("fs-extra"));
1543
+ var import_graphql9 = __toModule(require("@tinacms/graphql"));
1610
1544
  var import_datalayer = __toModule(require("@tinacms/datalayer"));
1545
+ var import_path9 = __toModule(require("path"));
1611
1546
 
1612
1547
  // src/cmds/query-gen/genTypes.ts
1613
- var import_graphql9 = __toModule(require("graphql"));
1548
+ var import_graphql8 = __toModule(require("graphql"));
1614
1549
  var import_fs_extra4 = __toModule(require("fs-extra"));
1615
1550
  var import_path6 = __toModule(require("path"));
1616
1551
 
1617
1552
  // src/codegen/index.ts
1618
- var import_graphql8 = __toModule(require("graphql"));
1553
+ var import_graphql7 = __toModule(require("graphql"));
1619
1554
 
1620
1555
  // src/codegen/plugin.ts
1621
1556
  var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
@@ -1667,14 +1602,14 @@ var import_typescript_operations = __toModule(require("@graphql-codegen/typescri
1667
1602
  var import_typescript = __toModule(require("@graphql-codegen/typescript"));
1668
1603
 
1669
1604
  // src/codegen/sdkPlugin/index.ts
1605
+ var import_graphql5 = __toModule(require("graphql"));
1670
1606
  var import_graphql6 = __toModule(require("graphql"));
1671
- var import_graphql7 = __toModule(require("graphql"));
1672
1607
  var import_path5 = __toModule(require("path"));
1673
1608
 
1674
1609
  // src/codegen/sdkPlugin/visitor.ts
1675
1610
  var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
1676
1611
  var import_auto_bind = __toModule(require("auto-bind"));
1677
- var import_graphql5 = __toModule(require("graphql"));
1612
+ var import_graphql4 = __toModule(require("graphql"));
1678
1613
  var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBaseVisitor {
1679
1614
  constructor(schema, fragments, rawConfig) {
1680
1615
  super(schema, fragments, rawConfig, {
@@ -1690,7 +1625,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
1690
1625
  }
1691
1626
  buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
1692
1627
  if (node.name == null) {
1693
- throw new Error("Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + (0, import_graphql5.print)(node));
1628
+ throw new Error("Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + (0, import_graphql4.print)(node));
1694
1629
  } else {
1695
1630
  this._operationsToInclude.push({
1696
1631
  node,
@@ -1705,7 +1640,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
1705
1640
  get sdkContent() {
1706
1641
  const usingObservable = !!this.config.usingObservableFrom;
1707
1642
  const allPossibleActions = this._operationsToInclude.map((o) => {
1708
- const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every((v) => v.type.kind !== import_graphql5.Kind.NON_NULL_TYPE || v.defaultValue);
1643
+ const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every((v) => v.type.kind !== import_graphql4.Kind.NON_NULL_TYPE || v.defaultValue);
1709
1644
  const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
1710
1645
  return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
1711
1646
  return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
@@ -1723,11 +1658,11 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
1723
1658
 
1724
1659
  // src/codegen/sdkPlugin/index.ts
1725
1660
  var plugin = (schema, documents, config) => {
1726
- const allAst = (0, import_graphql7.concatAST)(documents.reduce((prev, v) => {
1661
+ const allAst = (0, import_graphql6.concatAST)(documents.reduce((prev, v) => {
1727
1662
  return [...prev, v.document];
1728
1663
  }, []));
1729
1664
  const allFragments = [
1730
- ...allAst.definitions.filter((d) => d.kind === import_graphql7.Kind.FRAGMENT_DEFINITION).map((fragmentDef) => ({
1665
+ ...allAst.definitions.filter((d) => d.kind === import_graphql6.Kind.FRAGMENT_DEFINITION).map((fragmentDef) => ({
1731
1666
  node: fragmentDef,
1732
1667
  name: fragmentDef.name.value,
1733
1668
  onType: fragmentDef.typeCondition.name.value,
@@ -1736,7 +1671,7 @@ var plugin = (schema, documents, config) => {
1736
1671
  ...config.externalFragments || []
1737
1672
  ];
1738
1673
  const visitor = new GenericSdkVisitor(schema, allFragments, config);
1739
- const visitorResult = (0, import_graphql6.visit)(allAst, { leave: visitor });
1674
+ const visitorResult = (0, import_graphql5.visit)(allAst, { leave: visitor });
1740
1675
  return {
1741
1676
  content: [
1742
1677
  visitor.fragments,
@@ -1753,64 +1688,53 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
1753
1688
  }) => {
1754
1689
  if (options.verbose)
1755
1690
  logger.info("Generating types...");
1756
- try {
1757
- let docs = [];
1758
- let fragDocs = [];
1759
- try {
1760
- if (!options.noSDK) {
1761
- docs = await (0, import_load.loadDocuments)(queryPathGlob, {
1762
- loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
1763
- });
1764
- }
1765
- } catch (e) {
1766
- let showErrorMessage = true;
1767
- const message = e.message || "";
1768
- if (message.includes("Unable to find any GraphQL type definitions for the following pointers:")) {
1769
- showErrorMessage = false;
1770
- }
1771
- if (showErrorMessage) {
1772
- console.error(e);
1773
- }
1774
- }
1775
- try {
1776
- if (!options.noSDK) {
1777
- fragDocs = await (0, import_load.loadDocuments)(fragDocPath, {
1778
- loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
1779
- });
1780
- }
1781
- } catch (error) {
1782
- console.error(error);
1691
+ let docs = [];
1692
+ let fragDocs = [];
1693
+ if (!options.noSDK) {
1694
+ docs = await loadGraphQLDocuments(queryPathGlob);
1695
+ fragDocs = await loadGraphQLDocuments(fragDocPath);
1696
+ }
1697
+ const res = await (0, import_core.codegen)({
1698
+ filename: process.cwd(),
1699
+ schema: (0, import_graphql7.parse)((0, import_graphql7.printSchema)(schema)),
1700
+ documents: [...docs, ...fragDocs],
1701
+ config: {},
1702
+ plugins: [
1703
+ { typescript: {} },
1704
+ { typescriptOperations: {} },
1705
+ {
1706
+ typescriptSdk: {}
1707
+ },
1708
+ { AddGeneratedClient: {} }
1709
+ ],
1710
+ pluginMap: {
1711
+ typescript: {
1712
+ plugin: import_typescript.plugin
1713
+ },
1714
+ typescriptOperations: {
1715
+ plugin: import_typescript_operations.plugin
1716
+ },
1717
+ typescriptSdk: {
1718
+ plugin
1719
+ },
1720
+ AddGeneratedClient
1783
1721
  }
1784
- const res = await (0, import_core.codegen)({
1785
- filename: process.cwd(),
1786
- schema: (0, import_graphql8.parse)((0, import_graphql8.printSchema)(schema)),
1787
- documents: [...docs, ...fragDocs],
1788
- config: {},
1789
- plugins: [
1790
- { typescript: {} },
1791
- { typescriptOperations: {} },
1792
- {
1793
- typescriptSdk: {}
1794
- },
1795
- { AddGeneratedClient: {} }
1796
- ],
1797
- pluginMap: {
1798
- typescript: {
1799
- plugin: import_typescript.plugin
1800
- },
1801
- typescriptOperations: {
1802
- plugin: import_typescript_operations.plugin
1803
- },
1804
- typescriptSdk: {
1805
- plugin
1806
- },
1807
- AddGeneratedClient
1808
- }
1722
+ });
1723
+ return res;
1724
+ };
1725
+ var loadGraphQLDocuments = async (globPath) => {
1726
+ let result = [];
1727
+ try {
1728
+ result = await (0, import_load.loadDocuments)(globPath, {
1729
+ loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
1809
1730
  });
1810
- return res;
1811
1731
  } catch (e) {
1812
- console.error(e);
1732
+ if ((e.message || "").includes("Unable to find any GraphQL type definitions for the following pointers:")) {
1733
+ } else {
1734
+ throw e;
1735
+ }
1813
1736
  }
1737
+ return result;
1814
1738
  };
1815
1739
 
1816
1740
  // src/cmds/query-gen/genTypes.ts
@@ -1871,7 +1795,7 @@ async function genTypes({ schema, usingTs }, next, options) {
1871
1795
  const jsCode = await (0, import_esbuild2.transform)(code, { loader: "ts" });
1872
1796
  await import_fs_extra4.default.outputFile(typesJSPath, jsCode.code);
1873
1797
  }
1874
- const schemaString = await (0, import_graphql9.printSchema)(schema);
1798
+ const schemaString = await (0, import_graphql8.printSchema)(schema);
1875
1799
  const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
1876
1800
  await import_fs_extra4.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
1877
1801
  ${schemaString}
@@ -1975,159 +1899,156 @@ async function spin({
1975
1899
  return res;
1976
1900
  }
1977
1901
 
1902
+ // src/buildTina/attachPath.ts
1903
+ var import_fs_extra6 = __toModule(require("fs-extra"));
1904
+ var import_path8 = __toModule(require("path"));
1905
+ var attachPath = async (ctx, next, _options) => {
1906
+ ctx.rootPath = process.cwd();
1907
+ ctx.usingTs = await isProjectTs(ctx.rootPath);
1908
+ next();
1909
+ };
1910
+ var isProjectTs = async (rootPath2) => {
1911
+ const tinaPath = import_path8.default.join(rootPath2, ".tina");
1912
+ return await (0, import_fs_extra6.pathExists)(import_path8.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra6.pathExists)(import_path8.default.join(tinaPath, "schema.tsx"));
1913
+ };
1914
+
1978
1915
  // src/buildTina/index.ts
1979
1916
  var buildSetupCmdBuild = async (ctx, next, opts) => {
1980
1917
  const rootPath2 = ctx.rootPath;
1981
- const { bridge, database, store } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
1918
+ const { bridge, database } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
1982
1919
  rootPath: rootPath2,
1983
1920
  useMemoryStore: true
1984
1921
  }));
1985
1922
  ctx.bridge = bridge;
1986
1923
  ctx.database = database;
1987
- ctx.store = store;
1924
+ ctx.builder = new ConfigBuilder(database);
1988
1925
  next();
1989
1926
  };
1990
1927
  var buildSetupCmdServerStart = async (ctx, next, opts) => {
1991
1928
  const rootPath2 = ctx.rootPath;
1992
- const { bridge, database, store } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
1929
+ const { bridge, database } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
1993
1930
  rootPath: rootPath2,
1994
1931
  useMemoryStore: false
1995
1932
  }));
1996
1933
  ctx.bridge = bridge;
1997
1934
  ctx.database = database;
1998
- ctx.store = store;
1935
+ ctx.builder = new ConfigBuilder(database);
1999
1936
  next();
2000
1937
  };
2001
1938
  var buildSetupCmdAudit = async (ctx, next, options) => {
2002
1939
  const rootPath2 = ctx.rootPath;
2003
- const bridge = options.clean ? new import_datalayer2.FilesystemBridge(rootPath2) : new import_datalayer2.AuditFileSystemBridge(rootPath2);
2004
- const store = new import_datalayer2.LevelStore(rootPath2, false);
2005
- const database = await (0, import_graphql10.createDatabase)({ store, bridge });
1940
+ const bridge = options.clean ? new import_datalayer.FilesystemBridge(rootPath2) : new import_datalayer.AuditFileSystemBridge(rootPath2);
1941
+ const store = new import_datalayer.LevelStore(rootPath2, false);
1942
+ const database = await (0, import_graphql9.createDatabase)({ store, bridge });
2006
1943
  ctx.bridge = bridge;
2007
1944
  ctx.database = database;
2008
- ctx.store = store;
1945
+ ctx.builder = new ConfigBuilder(database);
2009
1946
  next();
2010
1947
  };
2011
1948
  var buildSetup = async ({
2012
1949
  isomorphicGitBridge: isomorphicGitBridge2,
2013
- experimentalData,
2014
1950
  rootPath: rootPath2,
2015
1951
  useMemoryStore
2016
1952
  }) => {
2017
- const fsBridge = new import_datalayer2.FilesystemBridge(rootPath2);
1953
+ const fsBridge = new import_datalayer.FilesystemBridge(rootPath2);
2018
1954
  const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
2019
- const bridge = isomorphicGitBridge2 ? new import_datalayer2.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
2020
- const store = new import_datalayer2.LevelStore(rootPath2, useMemoryStore);
2021
- const database = await (0, import_graphql10.createDatabase)({ store, bridge });
1955
+ const bridge = isomorphicGitBridge2 ? new import_datalayer.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
1956
+ const store = new import_datalayer.LevelStore(rootPath2, useMemoryStore);
1957
+ const database = await (0, import_graphql9.createDatabase)({ store, bridge });
2022
1958
  return { database, bridge, store };
2023
1959
  };
2024
1960
  var buildCmdBuild = async (ctx, next, options) => {
2025
- const bridge = ctx.bridge;
2026
- const database = ctx.database;
2027
- const store = ctx.store;
2028
- await build2(__spreadProps(__spreadValues({}, options), {
2029
- bridge,
2030
- database,
2031
- store,
2032
- ctx,
2033
- skipIndex: true
2034
- }));
1961
+ const { schema } = await ctx.builder.build(__spreadValues({
1962
+ rootPath: ctx.rootPath
1963
+ }, options));
1964
+ await ctx.builder.genTypedClient({
1965
+ compiledSchema: schema,
1966
+ local: options.local,
1967
+ noSDK: options.noSDK,
1968
+ verbose: options.verbose,
1969
+ usingTs: ctx.usingTs
1970
+ });
1971
+ await buildAdmin({
1972
+ local: options.local,
1973
+ rootPath: ctx.rootPath,
1974
+ schema
1975
+ });
2035
1976
  next();
2036
1977
  };
2037
1978
  var auditCmdBuild = async (ctx, next, options) => {
2038
- const bridge = ctx.bridge;
2039
- const database = ctx.database;
2040
- const store = ctx.store;
2041
- await build2(__spreadProps(__spreadValues({}, options), {
2042
- local: true,
2043
- verbose: true,
2044
- bridge,
2045
- database,
2046
- store,
2047
- ctx
1979
+ const { graphQLSchema, tinaSchema } = await ctx.builder.build(__spreadProps(__spreadValues({
1980
+ rootPath: ctx.rootPath
1981
+ }, options), {
1982
+ verbose: true
2048
1983
  }));
1984
+ await ctx.database.indexContent({ graphQLSchema, tinaSchema });
2049
1985
  next();
2050
1986
  };
2051
- var build2 = async ({
2052
- noWatch,
2053
- ctx,
2054
- bridge,
2055
- database,
2056
- store,
2057
- beforeBuild,
2058
- afterBuild,
2059
- dev,
2060
- local,
2061
- verbose,
2062
- noSDK,
2063
- skipIndex
2064
- }) => {
2065
- var _a, _b;
2066
- const rootPath2 = ctx.rootPath;
2067
- if (!rootPath2) {
2068
- throw new Error("Root path has not been attached");
1987
+ var ConfigBuilder = class {
1988
+ constructor(database) {
1989
+ this.database = database;
2069
1990
  }
2070
- const tinaGeneratedPath = import_path8.default.join(rootPath2, ".tina", "__generated__");
2071
- database.clearCache();
2072
- if (beforeBuild) {
2073
- await beforeBuild();
2074
- }
2075
- try {
2076
- await import_fs_extra6.default.mkdirp(tinaGeneratedPath);
2077
- await store.close();
1991
+ async build({ dev, verbose, rootPath: rootPath2 }) {
1992
+ const usingTs = await isProjectTs(rootPath2);
1993
+ if (!rootPath2) {
1994
+ throw new Error("Root path has not been attached");
1995
+ }
1996
+ const tinaGeneratedPath = import_path9.default.join(rootPath2, ".tina", "__generated__");
1997
+ this.database.clearCache();
1998
+ await import_fs_extra7.default.mkdirp(tinaGeneratedPath);
1999
+ await this.database.store.close();
2078
2000
  await resetGeneratedFolder({
2079
2001
  tinaGeneratedPath,
2080
- usingTs: ctx.usingTs
2002
+ usingTs
2081
2003
  });
2082
- await store.open();
2083
- const cliFlags = [];
2084
- cliFlags.push("experimentalData");
2085
- cliFlags.push("isomorphicGitBridge");
2086
- const database2 = await (0, import_graphql10.createDatabase)({ store, bridge });
2087
- await compileSchema(ctx, null, { verbose, dev });
2088
- const schema = await (0, import_async_retry.default)(async () => await (0, import_graphql10.buildSchema)(rootPath2, database2, cliFlags, skipIndex));
2089
- await genTypes({ schema, usingTs: ctx.usingTs }, () => {
2004
+ await this.database.store.open();
2005
+ const compiledSchema = await compileSchema({
2006
+ verbose,
2007
+ dev,
2008
+ rootPath: rootPath2
2009
+ });
2010
+ const { graphQLSchema, tinaSchema } = await (0, import_graphql9.buildSchema)(rootPath2, this.database, ["experimentalData", "isomorphicGitBridge"]);
2011
+ return { schema: compiledSchema, graphQLSchema, tinaSchema };
2012
+ }
2013
+ async genTypedClient({
2014
+ usingTs,
2015
+ compiledSchema,
2016
+ noSDK,
2017
+ verbose,
2018
+ local
2019
+ }) {
2020
+ const astSchema = await (0, import_graphql9.getASTSchema)(this.database);
2021
+ await genTypes({ schema: astSchema, usingTs }, () => {
2090
2022
  }, {
2091
2023
  noSDK,
2092
2024
  verbose
2093
2025
  });
2094
- await genClient({ tinaSchema: ctx.schema, usingTs: ctx.usingTs }, () => {
2026
+ await genClient({ tinaSchema: compiledSchema, usingTs }, () => {
2095
2027
  }, {
2096
2028
  local
2097
2029
  });
2098
- if ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build) {
2099
- await spin({
2100
- text: "Building static site",
2101
- waitFor: async () => {
2102
- var _a2, _b2, _c, _d, _e, _f;
2103
- await (0, import_app.viteBuild)({
2104
- local,
2105
- rootPath: rootPath2,
2106
- outputFolder: (_c = (_b2 = (_a2 = ctx.schema) == null ? void 0 : _a2.config) == null ? void 0 : _b2.build) == null ? void 0 : _c.outputFolder,
2107
- publicFolder: (_f = (_e = (_d = ctx.schema) == null ? void 0 : _d.config) == null ? void 0 : _e.build) == null ? void 0 : _f.publicFolder
2108
- });
2109
- }
2110
- });
2111
- console.log("\nDone building static site");
2112
- }
2113
- } catch (error) {
2114
- throw error;
2115
- } finally {
2116
- if (afterBuild) {
2117
- await afterBuild();
2118
- }
2119
2030
  }
2120
2031
  };
2121
-
2122
- // src/cmds/start-server/lock.ts
2123
- var AsyncLock = class {
2124
- constructor() {
2125
- this.disable = () => {
2126
- };
2127
- this.promise = Promise.resolve();
2128
- }
2129
- enable() {
2130
- this.promise = new Promise((resolve2) => this.disable = resolve2);
2032
+ var buildAdmin = async ({
2033
+ schema,
2034
+ local,
2035
+ rootPath: rootPath2
2036
+ }) => {
2037
+ var _a;
2038
+ if ((_a = schema == null ? void 0 : schema.config) == null ? void 0 : _a.build) {
2039
+ await spin({
2040
+ text: "Building static site",
2041
+ waitFor: async () => {
2042
+ var _a2, _b, _c, _d;
2043
+ await (0, import_app.viteBuild)({
2044
+ local,
2045
+ rootPath: rootPath2,
2046
+ outputFolder: (_b = (_a2 = schema == null ? void 0 : schema.config) == null ? void 0 : _a2.build) == null ? void 0 : _b.outputFolder,
2047
+ publicFolder: (_d = (_c = schema == null ? void 0 : schema.config) == null ? void 0 : _c.build) == null ? void 0 : _d.publicFolder
2048
+ });
2049
+ }
2050
+ });
2051
+ console.log("\nDone building static site");
2131
2052
  }
2132
2053
  };
2133
2054
 
@@ -2138,13 +2059,11 @@ var gqlPackageFile = require.resolve("@tinacms/graphql");
2138
2059
  async function startServer(ctx, next, {
2139
2060
  port = 4001,
2140
2061
  noWatch,
2141
- isomorphicGitBridge: isomorphicGitBridge2,
2142
2062
  noSDK,
2143
2063
  noTelemetry,
2144
2064
  watchFolders,
2145
2065
  verbose,
2146
- dev,
2147
- local
2066
+ dev
2148
2067
  }) {
2149
2068
  buildLock.disable();
2150
2069
  reBuildLock.disable();
@@ -2157,7 +2076,6 @@ async function startServer(ctx, next, {
2157
2076
  });
2158
2077
  const bridge = ctx.bridge;
2159
2078
  const database = ctx.database;
2160
- const store = ctx.store;
2161
2079
  const shouldBuild = bridge.supportsBuilding();
2162
2080
  let ready = false;
2163
2081
  const state = {
@@ -2220,7 +2138,34 @@ or`);
2220
2138
  });
2221
2139
  });
2222
2140
  };
2223
- const foldersToWatch = (watchFolders || []).map((x) => import_path11.default.join(rootPath2, x));
2141
+ const build2 = async () => {
2142
+ try {
2143
+ await beforeBuild();
2144
+ const { schema, graphQLSchema, tinaSchema } = await ctx.builder.build({
2145
+ rootPath: ctx.rootPath,
2146
+ dev,
2147
+ verbose
2148
+ });
2149
+ await ctx.builder.genTypedClient({
2150
+ compiledSchema: schema,
2151
+ local: true,
2152
+ noSDK,
2153
+ verbose,
2154
+ usingTs: ctx.usingTs
2155
+ });
2156
+ await ctx.database.indexContent({ graphQLSchema, tinaSchema });
2157
+ await buildAdmin({
2158
+ local: true,
2159
+ rootPath: ctx.rootPath,
2160
+ schema
2161
+ });
2162
+ } catch (error) {
2163
+ throw error;
2164
+ } finally {
2165
+ await afterBuild();
2166
+ }
2167
+ };
2168
+ const foldersToWatch = (watchFolders || []).map((x) => import_path12.default.join(rootPath2, x));
2224
2169
  if (!noWatch && !process.env.CI) {
2225
2170
  import_chokidar.default.watch([
2226
2171
  ...foldersToWatch,
@@ -2230,27 +2175,14 @@ or`);
2230
2175
  ignored: [
2231
2176
  "**/node_modules/**/*",
2232
2177
  "**/.next/**/*",
2233
- `${import_path11.default.resolve(rootPath2)}/.tina/__generated__/**/*`
2178
+ `${import_path12.default.resolve(rootPath2)}/.tina/__generated__/**/*`
2234
2179
  ]
2235
2180
  }).on("ready", async () => {
2236
2181
  if (verbose)
2237
2182
  console.log("Generating Tina config");
2238
2183
  try {
2239
2184
  if (shouldBuild) {
2240
- await build2({
2241
- bridge,
2242
- ctx,
2243
- database,
2244
- store,
2245
- dev,
2246
- isomorphicGitBridge: isomorphicGitBridge2,
2247
- local: true,
2248
- noSDK,
2249
- noWatch,
2250
- verbose,
2251
- beforeBuild,
2252
- afterBuild
2253
- });
2185
+ await build2();
2254
2186
  }
2255
2187
  ready = true;
2256
2188
  isReady = true;
@@ -2268,20 +2200,7 @@ or`);
2268
2200
  logger.info("Tina change detected, regenerating config");
2269
2201
  try {
2270
2202
  if (shouldBuild) {
2271
- await build2({
2272
- bridge,
2273
- ctx,
2274
- database,
2275
- store,
2276
- dev,
2277
- isomorphicGitBridge: isomorphicGitBridge2,
2278
- local: true,
2279
- noSDK,
2280
- noWatch,
2281
- verbose,
2282
- beforeBuild,
2283
- afterBuild
2284
- });
2203
+ await build2();
2285
2204
  }
2286
2205
  if (isReady) {
2287
2206
  await restart();
@@ -2304,20 +2223,7 @@ or`);
2304
2223
  logger.info("Detected CI environment, omitting watch commands...");
2305
2224
  }
2306
2225
  if (shouldBuild) {
2307
- await build2({
2308
- bridge,
2309
- ctx,
2310
- database,
2311
- store,
2312
- dev,
2313
- isomorphicGitBridge: isomorphicGitBridge2,
2314
- local: true,
2315
- noSDK,
2316
- noWatch,
2317
- verbose,
2318
- beforeBuild,
2319
- afterBuild
2320
- });
2226
+ await build2();
2321
2227
  }
2322
2228
  await start();
2323
2229
  next();
@@ -2423,16 +2329,6 @@ stack: ${code.stack || "No stack was provided"}`);
2423
2329
  }
2424
2330
  };
2425
2331
 
2426
- // src/buildTina/attachPath.ts
2427
- var import_fs_extra8 = __toModule(require("fs-extra"));
2428
- var import_path12 = __toModule(require("path"));
2429
- var attachPath = async (ctx, next, _options) => {
2430
- ctx.rootPath = process.cwd();
2431
- const tinaPath = import_path12.default.join(ctx.rootPath, ".tina");
2432
- ctx.usingTs = await (0, import_fs_extra8.pathExists)(import_path12.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra8.pathExists)(import_path12.default.join(tinaPath, "schema.tsx"));
2433
- next();
2434
- };
2435
-
2436
2332
  // src/cmds/baseCmds.ts
2437
2333
  var CMD_START_SERVER = "server:start";
2438
2334
  var CMD_DEV = "dev";
@@ -2596,7 +2492,12 @@ var baseCmds = [
2596
2492
  ], options)
2597
2493
  },
2598
2494
  {
2599
- options: [cleanOption, useDefaultValuesOption, noTelemetryOption],
2495
+ options: [
2496
+ cleanOption,
2497
+ useDefaultValuesOption,
2498
+ noTelemetryOption,
2499
+ verboseOption
2500
+ ],
2600
2501
  command: AUDIT,
2601
2502
  description: "Audit your schema and the files to check for errors",
2602
2503
  action: (options) => chain([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "0.61.8",
3
+ "version": "0.61.11",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -52,15 +52,14 @@
52
52
  "@graphql-codegen/visitor-plugin-common": "^2.4.0",
53
53
  "@graphql-tools/graphql-file-loader": "^7.2.0",
54
54
  "@graphql-tools/load": "^7.3.2",
55
- "@tinacms/app": "0.0.8",
55
+ "@tinacms/app": "0.0.11",
56
56
  "@tinacms/datalayer": "0.2.3",
57
- "@tinacms/graphql": "0.63.4",
57
+ "@tinacms/graphql": "0.63.7",
58
58
  "@tinacms/metrics": "0.0.3",
59
- "@tinacms/schema-tools": "0.1.0",
59
+ "@tinacms/schema-tools": "0.1.2",
60
60
  "add": "^2.0.6",
61
61
  "ajv": "^6.12.3",
62
62
  "altair-express-middleware": "4.0.6",
63
- "async-retry": "^1.3.3",
64
63
  "auto-bind": "^4.0.0",
65
64
  "axios": "0.21.2",
66
65
  "body-parser": "^1.19.0",
@@ -1,13 +0,0 @@
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 function attachSchema(ctx: any, next: () => void, options: any): Promise<void>;