@tinacms/cli 0.61.6 → 0.61.9

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.
@@ -17,6 +17,8 @@ interface BuildOptions {
17
17
  database: Database;
18
18
  store: Store;
19
19
  bridge: Bridge;
20
+ /** In some cases (like audit) there's no need to build the SPA */
21
+ buildFrontend?: boolean;
20
22
  noWatch?: boolean;
21
23
  isomorphicGitBridge?: boolean;
22
24
  verbose?: boolean;
@@ -38,5 +40,5 @@ export declare const buildSetupCmdAudit: (ctx: any, next: () => void, options: {
38
40
  }) => Promise<void>;
39
41
  export declare const buildCmdBuild: (ctx: any, next: () => void, options: Omit<BuildOptions & BuildSetupOptions, 'bridge' | 'database' | 'store'>) => Promise<void>;
40
42
  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>;
43
+ export declare const build: ({ noWatch, ctx, bridge, database, store, beforeBuild, afterBuild, dev, local, verbose, buildFrontend, noSDK, skipIndex, }: BuildOptions) => Promise<void>;
42
44
  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>;
package/dist/index.js CHANGED
@@ -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.6";
296
+ var version = "0.61.9";
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}"`;
@@ -1304,9 +1248,9 @@ var getPath = ({
1304
1248
  }
1305
1249
  const filePaths = allowedTypes.map((ext) => import_path3.default.join(projectDir, `${filename}.${ext}`));
1306
1250
  let inputFile = void 0;
1307
- filePaths.every((path7) => {
1308
- if (import_fs_extra2.default.existsSync(path7)) {
1309
- inputFile = path7;
1251
+ filePaths.every((path8) => {
1252
+ if (import_fs_extra2.default.existsSync(path8)) {
1253
+ inputFile = path8;
1310
1254
  return false;
1311
1255
  }
1312
1256
  return true;
@@ -1533,14 +1477,29 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
1533
1477
  const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
1534
1478
  const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
1535
1479
  const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
1480
+ const prebuiltInputPath = import_path4.default.join(tempDir, "temp-output.jsx");
1481
+ await (0, import_esbuild.build)({
1482
+ bundle: true,
1483
+ platform: "neutral",
1484
+ target: ["es2020"],
1485
+ entryPoints: [inputFile],
1486
+ treeShaking: true,
1487
+ external: [...external, "./node_modules/*"],
1488
+ loader: loaders,
1489
+ outfile: prebuiltInputPath,
1490
+ define
1491
+ });
1492
+ const tempTsConfigPath = import_path4.default.join(tempDir, "temp-tsconfig.json");
1493
+ await import_fs_extra3.default.outputFileSync(tempTsConfigPath, "{}");
1536
1494
  const outputPath = import_path4.default.join(tempDir, outputFile);
1537
1495
  await (0, import_esbuild.build)({
1538
1496
  bundle: true,
1539
1497
  platform: "neutral",
1540
1498
  target: ["node10.4"],
1541
- entryPoints: [inputFile],
1499
+ entryPoints: [prebuiltInputPath],
1542
1500
  treeShaking: true,
1543
1501
  external: [...external, "./node_modules/*"],
1502
+ tsconfig: tempTsConfigPath,
1544
1503
  loader: loaders,
1545
1504
  outfile: outputPath,
1546
1505
  define
@@ -2029,6 +1988,7 @@ var auditCmdBuild = async (ctx, next, options) => {
2029
1988
  bridge,
2030
1989
  database,
2031
1990
  store,
1991
+ buildFrontend: false,
2032
1992
  ctx
2033
1993
  }));
2034
1994
  next();
@@ -2044,6 +2004,7 @@ var build2 = async ({
2044
2004
  dev,
2045
2005
  local,
2046
2006
  verbose,
2007
+ buildFrontend = true,
2047
2008
  noSDK,
2048
2009
  skipIndex
2049
2010
  }) => {
@@ -2080,7 +2041,7 @@ var build2 = async ({
2080
2041
  }, {
2081
2042
  local
2082
2043
  });
2083
- if ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build) {
2044
+ if (buildFrontend && ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build)) {
2084
2045
  await spin({
2085
2046
  text: "Building static site",
2086
2047
  waitFor: async () => {
@@ -2581,7 +2542,12 @@ var baseCmds = [
2581
2542
  ], options)
2582
2543
  },
2583
2544
  {
2584
- options: [cleanOption, useDefaultValuesOption, noTelemetryOption],
2545
+ options: [
2546
+ cleanOption,
2547
+ useDefaultValuesOption,
2548
+ noTelemetryOption,
2549
+ verboseOption
2550
+ ],
2585
2551
  command: AUDIT,
2586
2552
  description: "Audit your schema and the files to check for errors",
2587
2553
  action: (options) => chain([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "0.61.6",
3
+ "version": "0.61.9",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -52,9 +52,9 @@
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.7",
56
- "@tinacms/datalayer": "0.2.2",
57
- "@tinacms/graphql": "0.63.3",
55
+ "@tinacms/app": "0.0.9",
56
+ "@tinacms/datalayer": "0.2.3",
57
+ "@tinacms/graphql": "0.63.5",
58
58
  "@tinacms/metrics": "0.0.3",
59
59
  "@tinacms/schema-tools": "0.1.0",
60
60
  "add": "^2.0.6",
@@ -70,7 +70,7 @@
70
70
  "commander": "^9.0.0",
71
71
  "cors": "^2.8.5",
72
72
  "dotenv": "^16.0.1",
73
- "esbuild": "^0.14.20",
73
+ "esbuild": "^0.15.5",
74
74
  "esm": "3.2.25",
75
75
  "express": "^4.17.1",
76
76
  "fast-glob": "^3.2.4",