@tinacms/cli 0.60.3 → 0.60.6

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,44 @@
1
1
  # tinacms-cli
2
2
 
3
+ ## 0.60.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 98622111d: Use [esbuild](https://esbuild.github.io/) to build the schema instead of typescript.
8
+
9
+ This allows the user to
10
+
11
+ - use non typescript files like JS, JSX, TS
12
+ - Import from outside of the tina folder
13
+
14
+ The downside
15
+
16
+ - Now type errors will still pass (The schema will compile) and one will get an error at runtime instead of compile time
17
+
18
+ - Updated dependencies [c730fa1dd]
19
+ - Updated dependencies [cd0f6f022]
20
+ - @tinacms/graphql@0.59.7
21
+
22
+ ## 0.60.5
23
+
24
+ ### Patch Changes
25
+
26
+ - 399fbf4fa: Fix an issue where builds weren't happening during CI, this is only an issue for the experimental data layer
27
+
28
+ ## 0.60.4
29
+
30
+ ### Patch Changes
31
+
32
+ - a05546eb4: Added basic open source telemetry
33
+
34
+ See [this discussion](https://github.com/tinacms/tinacms/discussions/2451) for more information and how to opt out.
35
+
36
+ - Updated dependencies [8bf0ac832]
37
+ - Updated dependencies [a05546eb4]
38
+ - @tinacms/metrics@0.0.2
39
+ - @tinacms/datalayer@0.0.2
40
+ - @tinacms/graphql@0.59.6
41
+
3
42
  ## 0.60.3
4
43
 
5
44
  ### Patch Changes
@@ -0,0 +1,19 @@
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 class BuildSchemaError extends Error {
14
+ constructor(message: any);
15
+ }
16
+ export declare class ExecuteSchemaError extends Error {
17
+ constructor(message: any);
18
+ }
19
+ export declare const handleServerErrors: (e: Error) => void;
@@ -13,9 +13,11 @@ limitations under the License.
13
13
  interface Options {
14
14
  port?: number;
15
15
  command?: string;
16
+ watchFolders?: string[];
16
17
  experimentalData?: boolean;
17
18
  noWatch?: boolean;
18
19
  noSDK: boolean;
20
+ noTelemetry: boolean;
19
21
  }
20
- export declare function startServer(_ctx: any, _next: any, { port, command, noWatch, experimentalData, noSDK }: Options): Promise<void>;
22
+ export declare function startServer(_ctx: any, _next: any, { port, command, noWatch, experimentalData, noSDK, noTelemetry, watchFolders, }: Options): Promise<void>;
21
23
  export {};
@@ -0,0 +1,18 @@
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 class AsyncLock {
14
+ disable: any;
15
+ promise: any;
16
+ constructor();
17
+ enable(): void;
18
+ }
package/dist/index.js CHANGED
@@ -1,10 +1,39 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
8
  var __getProtoOf = Object.getPrototypeOf;
6
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7
24
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
8
37
  var __esm = (fn, res) => function __init() {
9
38
  return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
10
39
  };
@@ -85,7 +114,7 @@ var commander = __toModule(require("commander"));
85
114
 
86
115
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/package.json
87
116
  var name = "@tinacms/cli";
88
- var version = "0.60.3";
117
+ var version = "0.60.6";
89
118
 
90
119
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/theme.ts
91
120
  var import_chalk = __toModule(require("chalk"));
@@ -362,16 +391,14 @@ schema {
362
391
 
363
392
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
364
393
  var import_child_process = __toModule(require("child_process"));
365
- var import_path3 = __toModule(require("path"));
394
+ var import_path4 = __toModule(require("path"));
366
395
  var import_graphql7 = __toModule(require("@tinacms/graphql"));
367
396
  var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
368
397
 
369
398
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
370
- var import_fast_glob = __toModule(require("fast-glob"));
371
- var import_normalize_path = __toModule(require("normalize-path"));
372
- var import_path2 = __toModule(require("path"));
373
- var import_fs_extra2 = __toModule(require("fs-extra"));
374
- var ts = __toModule(require("typescript"));
399
+ var import_path3 = __toModule(require("path"));
400
+ var import_fs_extra3 = __toModule(require("fs-extra"));
401
+ var import_esbuild = __toModule(require("esbuild"));
375
402
 
376
403
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
377
404
  var defaultSchema = `
@@ -404,70 +431,206 @@ export default defineSchema({
404
431
  });
405
432
  `;
406
433
 
434
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getSchemaPath.ts
435
+ var import_path2 = __toModule(require("path"));
436
+ var import_fs_extra2 = __toModule(require("fs-extra"));
437
+ var ErrorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
438
+ var getSchemaPath = ({ projectDir }) => {
439
+ if (!import_fs_extra2.default.existsSync(projectDir)) {
440
+ throw new Error(ErrorMessage);
441
+ }
442
+ const inputPathTS = import_path2.default.join(projectDir, "schema.ts");
443
+ const inputPathJS = import_path2.default.join(projectDir, "schema.js");
444
+ const inputPathTSX = import_path2.default.join(projectDir, "schema.tsx");
445
+ const inputPathJSX = import_path2.default.join(projectDir, "schema.jsx");
446
+ let inputFile;
447
+ if (import_fs_extra2.default.existsSync(inputPathTS)) {
448
+ inputFile = inputPathTS;
449
+ } else if (import_fs_extra2.default.existsSync(inputPathJS)) {
450
+ inputFile = inputPathJS;
451
+ } else if (import_fs_extra2.default.existsSync(inputPathTSX)) {
452
+ inputFile = inputPathTSX;
453
+ } else if (import_fs_extra2.default.existsSync(inputPathJSX)) {
454
+ inputFile = inputPathJSX;
455
+ }
456
+ if (!inputFile) {
457
+ throw new Error(ErrorMessage);
458
+ }
459
+ return inputFile;
460
+ };
461
+
462
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/errors/index.ts
463
+ var BuildSchemaError = class extends Error {
464
+ constructor(message) {
465
+ super(message);
466
+ this.name = "BuildSchemaError";
467
+ }
468
+ };
469
+ var ExecuteSchemaError = class extends Error {
470
+ constructor(message) {
471
+ super(message);
472
+ this.name = "ExecuteSchemaError";
473
+ }
474
+ };
475
+ var handleServerErrors = (e) => {
476
+ if (e instanceof BuildSchemaError) {
477
+ logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
478
+ Error Message Below
479
+ ${e}`);
480
+ } else if (e instanceof ExecuteSchemaError) {
481
+ logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
482
+ Error Message Below
483
+ ${e}`);
484
+ } else {
485
+ logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
486
+ ${e.message}`);
487
+ }
488
+ };
489
+
407
490
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
408
- var tinaPath = import_path2.default.join(process.cwd(), ".tina");
409
- var tinaGeneratedPath = import_path2.default.join(tinaPath, "__generated__");
410
- var tinaTempPath = import_path2.default.join(tinaGeneratedPath, "temp");
411
- var tinaConfigPath = import_path2.default.join(tinaGeneratedPath, "config");
491
+ var tinaPath = import_path3.default.join(process.cwd(), ".tina");
492
+ var packageJSONFilePath = import_path3.default.join(process.cwd(), "package.json");
493
+ var tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
494
+ var tinaTempPath = import_path3.default.join(tinaGeneratedPath, "temp");
495
+ var tinaConfigPath = import_path3.default.join(tinaGeneratedPath, "config");
412
496
  var resetGeneratedFolder = async () => {
413
497
  try {
414
- await import_fs_extra2.default.rmdir(tinaGeneratedPath, {
498
+ await import_fs_extra3.default.rmdir(tinaGeneratedPath, {
415
499
  recursive: true
416
500
  });
417
501
  } catch (e) {
418
502
  console.log(e);
419
503
  }
420
- await import_fs_extra2.default.mkdir(tinaGeneratedPath);
421
- await import_fs_extra2.default.outputFile(import_path2.default.join(tinaGeneratedPath, ".gitignore"), "db");
504
+ await import_fs_extra3.default.mkdir(tinaGeneratedPath);
505
+ await import_fs_extra3.default.outputFile(import_path3.default.join(tinaGeneratedPath, ".gitignore"), "db");
506
+ };
507
+ var cleanup = async ({ tinaTempPath: tinaTempPath2 }) => {
508
+ await import_fs_extra3.default.remove(tinaTempPath2);
422
509
  };
423
510
  var compile = async (_ctx, _next) => {
424
511
  logger.info(logText("Compiling..."));
425
- if (!import_fs_extra2.default.existsSync(tinaPath) || !import_fs_extra2.default.existsSync(import_path2.default.join(tinaPath, "schema.ts"))) {
512
+ let schemaExists = true;
513
+ try {
514
+ getSchemaPath({ projectDir: tinaPath });
515
+ } catch {
516
+ schemaExists = false;
517
+ }
518
+ if (!schemaExists) {
426
519
  logger.info(dangerText(`
427
520
  .tina/schema.ts not found, Creating one for you...
428
521
  See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
429
522
  `));
430
- const file = import_path2.default.join(tinaPath, "schema.ts");
431
- await import_fs_extra2.default.ensureFile(file);
432
- await import_fs_extra2.default.writeFile(file, defaultSchema);
523
+ const file = import_path3.default.join(tinaPath, "schema.ts");
524
+ await import_fs_extra3.default.ensureFile(file);
525
+ await import_fs_extra3.default.writeFile(file, defaultSchema);
526
+ }
527
+ try {
528
+ await transpile(tinaPath, tinaTempPath);
529
+ } catch (e) {
530
+ await cleanup({ tinaTempPath });
531
+ throw new BuildSchemaError(e);
433
532
  }
434
- await transpile2(tinaPath, tinaTempPath);
435
533
  Object.keys(require.cache).map((key) => {
436
534
  if (key.startsWith(tinaTempPath)) {
437
535
  delete require.cache[require.resolve(key)];
438
536
  }
439
537
  });
440
- const schemaFunc = require(import_path2.default.join(tinaTempPath, "schema.js"));
441
- const schemaObject = schemaFunc.default;
442
- await import_fs_extra2.default.outputFile(import_path2.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
443
- await import_fs_extra2.default.remove(tinaTempPath);
538
+ try {
539
+ const schemaFunc = require(import_path3.default.join(tinaTempPath, "schema.js"));
540
+ const schemaObject = schemaFunc.default;
541
+ await import_fs_extra3.default.outputFile(import_path3.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
542
+ await cleanup({ tinaTempPath });
543
+ } catch (e) {
544
+ await cleanup({ tinaTempPath });
545
+ throw new ExecuteSchemaError(e);
546
+ }
444
547
  };
445
- var transpile2 = async (projectDir, tempDir) => {
446
- logger.info(logText("Transpiling..."));
447
- const posixProjectDir = (0, import_normalize_path.default)(projectDir);
448
- const posixTempDir = (0, import_normalize_path.default)(tempDir);
449
- return Promise.all(import_fast_glob.default.sync(import_path2.default.join(projectDir, "**", "*.ts").replace(/\\/g, "/"), {
450
- ignore: [
451
- import_path2.default.join(projectDir, "__generated__", "**", "*.ts").replace(/\\/g, "/")
452
- ]
453
- }).map(async function(file) {
454
- const fullPath = import_path2.default.resolve(file);
455
- const contents = await import_fs_extra2.default.readFileSync(fullPath).toString();
456
- const newContent = ts.transpile(contents);
457
- const newPath = file.replace(posixProjectDir, posixTempDir).replace(".ts", ".js");
458
- await import_fs_extra2.default.outputFile(newPath, newContent);
459
- return true;
460
- }));
548
+ var transpile = async (projectDir, tempDir) => {
549
+ logger.info(logText("Building javascript..."));
550
+ const packageJSON = JSON.parse(import_fs_extra3.default.readFileSync(packageJSONFilePath).toString() || "{}");
551
+ const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
552
+ const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
553
+ const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
554
+ const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
555
+ const inputFile = getSchemaPath({ projectDir });
556
+ const outputPath = import_path3.default.join(tempDir, "schema.js");
557
+ await (0, import_esbuild.build)({
558
+ bundle: true,
559
+ platform: "neutral",
560
+ target: ["node10.4"],
561
+ entryPoints: [inputFile],
562
+ treeShaking: true,
563
+ external: [...external, "./node_modules/*"],
564
+ loader: loaders,
565
+ outfile: outputPath
566
+ });
567
+ logger.info(logText(`Javascript built`));
461
568
  };
462
569
  var defineSchema = (config) => {
463
570
  return config;
464
571
  };
572
+ var loaders = {
573
+ ".aac": "file",
574
+ ".css": "file",
575
+ ".eot": "file",
576
+ ".flac": "file",
577
+ ".gif": "file",
578
+ ".jpeg": "file",
579
+ ".jpg": "file",
580
+ ".json": "json",
581
+ ".mp3": "file",
582
+ ".mp4": "file",
583
+ ".ogg": "file",
584
+ ".otf": "file",
585
+ ".png": "file",
586
+ ".svg": "file",
587
+ ".ttf": "file",
588
+ ".wav": "file",
589
+ ".webm": "file",
590
+ ".webp": "file",
591
+ ".woff": "file",
592
+ ".woff2": "file",
593
+ ".js": "jsx",
594
+ ".jsx": "jsx",
595
+ ".tsx": "tsx"
596
+ };
465
597
 
466
598
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
467
599
  var import_chokidar = __toModule(require("chokidar"));
600
+ var import_metrics = __toModule(require("@tinacms/metrics"));
601
+
602
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/lock.ts
603
+ var AsyncLock = class {
604
+ constructor() {
605
+ this.disable = () => {
606
+ };
607
+ this.promise = Promise.resolve();
608
+ }
609
+ enable() {
610
+ this.promise = new Promise((resolve2) => this.disable = resolve2);
611
+ }
612
+ };
613
+
614
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
615
+ var lock = new AsyncLock();
468
616
  var gqlPackageFile = require.resolve("@tinacms/graphql");
469
- async function startServer(_ctx, _next, { port = 4001, command, noWatch, experimentalData, noSDK }) {
617
+ async function startServer(_ctx, _next, {
618
+ port = 4001,
619
+ command,
620
+ noWatch,
621
+ experimentalData,
622
+ noSDK,
623
+ noTelemetry,
624
+ watchFolders
625
+ }) {
626
+ lock.disable();
470
627
  const rootPath2 = process.cwd();
628
+ const t = new import_metrics.Telemetry({ disabled: Boolean(noTelemetry) });
629
+ t.submitRecord({
630
+ event: {
631
+ name: "tinacms:cli:server:start:invoke"
632
+ }
633
+ });
471
634
  if (!process.env.CI && !noWatch) {
472
635
  await resetGeneratedFolder();
473
636
  }
@@ -498,19 +661,45 @@ stack: ${code.stack || "No stack was provided"}`);
498
661
  }
499
662
  };
500
663
  let ready = false;
664
+ const build2 = async (noSDK2) => {
665
+ await lock.promise;
666
+ lock.enable();
667
+ try {
668
+ if (!process.env.CI && !noWatch) {
669
+ await resetGeneratedFolder();
670
+ }
671
+ const database2 = await (0, import_graphql7.createDatabase)({ store, bridge });
672
+ await compile(null, null);
673
+ const schema = await (0, import_graphql7.buildSchema)(rootPath2, database2);
674
+ await genTypes({ schema }, () => {
675
+ }, { noSDK: noSDK2 });
676
+ } catch (error) {
677
+ throw error;
678
+ } finally {
679
+ lock.disable();
680
+ }
681
+ };
682
+ const foldersToWatch = (watchFolders || []).map((x) => import_path4.default.join(rootPath2, x));
501
683
  if (!noWatch && !process.env.CI) {
502
- import_chokidar.default.watch([`${rootPath2}/**/*.{ts,gql,graphql}`], {
503
- ignored: `${import_path3.default.resolve(rootPath2)}/.tina/__generated__/**/*`
684
+ import_chokidar.default.watch([
685
+ ...foldersToWatch,
686
+ `${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
687
+ ], {
688
+ ignored: [
689
+ "**/node_modules/**/*",
690
+ "**/.next/**/*",
691
+ `${import_path4.default.resolve(rootPath2)}/.tina/__generated__/**/*`
692
+ ]
504
693
  }).on("ready", async () => {
505
694
  console.log("Generating Tina config");
506
695
  try {
507
696
  if (shouldBuild) {
508
- await build(noSDK);
697
+ await build2(noSDK);
509
698
  }
510
699
  ready = true;
511
700
  startSubprocess();
512
701
  } catch (e) {
513
- logger.info(dangerText(`${e.message}`));
702
+ handleServerErrors(e);
514
703
  console.log(e);
515
704
  process.exit(0);
516
705
  }
@@ -519,25 +708,24 @@ stack: ${code.stack || "No stack was provided"}`);
519
708
  logger.info("Tina change detected, regenerating config");
520
709
  try {
521
710
  if (shouldBuild) {
522
- await build(noSDK);
711
+ await build2(noSDK);
523
712
  }
524
713
  } catch (e) {
525
- logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
526
- ${e.message}`);
714
+ handleServerErrors(e);
715
+ t.submitRecord({
716
+ event: {
717
+ name: "tinacms:cli:server:error",
718
+ errorMessage: e.message
719
+ }
720
+ });
527
721
  }
528
722
  }
529
723
  });
530
- }
531
- const build = async (noSDK2) => {
532
- if (!process.env.CI && !noWatch) {
533
- await resetGeneratedFolder();
724
+ } else {
725
+ if (shouldBuild) {
726
+ await build2(noSDK);
534
727
  }
535
- const database2 = await (0, import_graphql7.createDatabase)({ store, bridge });
536
- await compile(null, null);
537
- const schema = await (0, import_graphql7.buildSchema)(rootPath2, database2);
538
- await genTypes({ schema }, () => {
539
- }, { noSDK: noSDK2 });
540
- };
728
+ }
541
729
  const state = {
542
730
  server: null,
543
731
  sockets: []
@@ -594,10 +782,11 @@ stack: ${code.stack || "No stack was provided"}`);
594
782
  }
595
783
 
596
784
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
597
- var import_fs_extra3 = __toModule(require("fs-extra"));
598
- var import_path4 = __toModule(require("path"));
785
+ var import_fs_extra4 = __toModule(require("fs-extra"));
786
+ var import_path5 = __toModule(require("path"));
599
787
  var import_progress = __toModule(require("progress"));
600
788
  var import_prompts = __toModule(require("prompts"));
789
+ var import_metrics2 = __toModule(require("@tinacms/metrics"));
601
790
 
602
791
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
603
792
  var adminPage = `import { TinaAdmin } from 'tinacms';
@@ -946,7 +1135,7 @@ export default App
946
1135
  var import_chalk2 = __toModule(require("chalk"));
947
1136
  function execShellCommand(cmd) {
948
1137
  const exec = require("child_process").exec;
949
- return new Promise((resolve2, reject) => {
1138
+ return new Promise((resolve2, _reject) => {
950
1139
  exec(cmd, (error, stdout, stderr) => {
951
1140
  if (error) {
952
1141
  console.warn(error);
@@ -956,6 +1145,8 @@ function execShellCommand(cmd) {
956
1145
  });
957
1146
  }
958
1147
  async function initTina(ctx, next, options) {
1148
+ const telemetry = new import_metrics2.Telemetry({ disabled: options.noTelemetry });
1149
+ await telemetry.submitRecord({ event: { name: "tinacms:cli:init:invoke" } });
959
1150
  logger.info(successText("Setting up Tina..."));
960
1151
  next();
961
1152
  }
@@ -974,26 +1165,26 @@ async function installDeps(ctx, next, options) {
974
1165
  next();
975
1166
  }
976
1167
  var baseDir = process.cwd();
977
- var TinaWrapperPathDir = import_path4.default.join(baseDir, "components");
978
- var TinaWrapperPath = import_path4.default.join(TinaWrapperPathDir, "tina-wrapper.tsx");
979
- var blogContentPath = import_path4.default.join(baseDir, "content", "posts");
980
- var blogPostPath = import_path4.default.join(blogContentPath, "HelloWorld.md");
1168
+ var TinaWrapperPathDir = import_path5.default.join(baseDir, "components");
1169
+ var TinaWrapperPath = import_path5.default.join(TinaWrapperPathDir, "tina-wrapper.tsx");
1170
+ var blogContentPath = import_path5.default.join(baseDir, "content", "posts");
1171
+ var blogPostPath = import_path5.default.join(blogContentPath, "HelloWorld.md");
981
1172
  async function tinaSetup(ctx, next, options) {
982
- const useingSrc = import_fs_extra3.default.pathExistsSync(import_path4.default.join(baseDir, "src"));
983
- if (!import_fs_extra3.default.pathExistsSync(blogPostPath)) {
1173
+ const useingSrc = import_fs_extra4.default.pathExistsSync(import_path5.default.join(baseDir, "src"));
1174
+ if (!import_fs_extra4.default.pathExistsSync(blogPostPath)) {
984
1175
  logger.info(logText("Adding a content folder..."));
985
- import_fs_extra3.default.mkdirpSync(blogContentPath);
986
- import_fs_extra3.default.writeFileSync(blogPostPath, blogPost);
1176
+ import_fs_extra4.default.mkdirpSync(blogContentPath);
1177
+ import_fs_extra4.default.writeFileSync(blogPostPath, blogPost);
987
1178
  }
988
1179
  logger.level = "info";
989
- const pagesPath = import_path4.default.join(baseDir, useingSrc ? "src" : "", "pages");
990
- const appPath = import_path4.default.join(pagesPath, "_app.js");
991
- const appPathTS = import_path4.default.join(pagesPath, "_app.tsx");
992
- const appExtension = import_fs_extra3.default.existsSync(appPath) ? ".js" : ".tsx";
1180
+ const pagesPath = import_path5.default.join(baseDir, useingSrc ? "src" : "", "pages");
1181
+ const appPath = import_path5.default.join(pagesPath, "_app.js");
1182
+ const appPathTS = import_path5.default.join(pagesPath, "_app.tsx");
1183
+ const appExtension = import_fs_extra4.default.existsSync(appPath) ? ".js" : ".tsx";
993
1184
  let wrapper = false;
994
- if (!import_fs_extra3.default.pathExistsSync(appPath) && !import_fs_extra3.default.pathExistsSync(appPathTS)) {
1185
+ if (!import_fs_extra4.default.pathExistsSync(appPath) && !import_fs_extra4.default.pathExistsSync(appPathTS)) {
995
1186
  logger.info(logText("Adding _app.js ... \u2705"));
996
- import_fs_extra3.default.writeFileSync(appPath, AppJsContent());
1187
+ import_fs_extra4.default.writeFileSync(appPath, AppJsContent());
997
1188
  } else {
998
1189
  const override = await (0, import_prompts.default)({
999
1190
  name: "res",
@@ -1002,50 +1193,47 @@ async function tinaSetup(ctx, next, options) {
1002
1193
  });
1003
1194
  if (override.res) {
1004
1195
  logger.info(logText(`Adding _app${appExtension} ... \u2705`));
1005
- const appPathWithExtension = import_path4.default.join(pagesPath, `_app${appExtension}`);
1006
- const fileContent = import_fs_extra3.default.pathExistsSync(appPath) ? (0, import_fs_extra3.readFileSync)(appPath) : (0, import_fs_extra3.readFileSync)(appPathTS);
1196
+ const appPathWithExtension = import_path5.default.join(pagesPath, `_app${appExtension}`);
1197
+ const fileContent = import_fs_extra4.default.pathExistsSync(appPath) ? (0, import_fs_extra4.readFileSync)(appPath) : (0, import_fs_extra4.readFileSync)(appPathTS);
1007
1198
  const matches = [
1008
1199
  ...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
1009
1200
  ];
1010
1201
  const primaryMatches = matches.map((x) => x[0]);
1011
- import_fs_extra3.default.writeFileSync(appPathWithExtension, AppJsContent(primaryMatches.join("\n")));
1202
+ import_fs_extra4.default.writeFileSync(appPathWithExtension, AppJsContent(primaryMatches.join("\n")));
1012
1203
  } else {
1013
1204
  wrapper = true;
1014
1205
  logger.info(dangerText(`Heads up, to enable live-editing you'll need to wrap your page or site in Tina:
1015
1206
  `, warnText(AppJsContent())));
1016
1207
  }
1017
1208
  }
1018
- const tinaBlogPagePath = import_path4.default.join(pagesPath, "demo", "blog");
1019
- const tinaBlogPagePathFile = import_path4.default.join(tinaBlogPagePath, "[filename].js");
1020
- if (!import_fs_extra3.default.pathExistsSync(tinaBlogPagePathFile)) {
1021
- import_fs_extra3.default.mkdirpSync(tinaBlogPagePath);
1022
- import_fs_extra3.default.writeFileSync(tinaBlogPagePathFile, nextPostPage());
1209
+ const tinaBlogPagePath = import_path5.default.join(pagesPath, "demo", "blog");
1210
+ const tinaBlogPagePathFile = import_path5.default.join(tinaBlogPagePath, "[filename].js");
1211
+ if (!import_fs_extra4.default.pathExistsSync(tinaBlogPagePathFile)) {
1212
+ import_fs_extra4.default.mkdirpSync(tinaBlogPagePath);
1213
+ import_fs_extra4.default.writeFileSync(tinaBlogPagePathFile, nextPostPage());
1023
1214
  }
1024
1215
  logger.info("Adding a content folder... \u2705");
1025
- const packagePath = import_path4.default.join(baseDir, "package.json");
1026
- const pack = JSON.parse((0, import_fs_extra3.readFileSync)(packagePath).toString());
1216
+ const packagePath = import_path5.default.join(baseDir, "package.json");
1217
+ const pack = JSON.parse((0, import_fs_extra4.readFileSync)(packagePath).toString());
1027
1218
  const oldScripts = pack.scripts || {};
1028
- const newPack = JSON.stringify({
1029
- ...pack,
1030
- scripts: {
1031
- ...oldScripts,
1219
+ const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
1220
+ scripts: __spreadProps(__spreadValues({}, oldScripts), {
1032
1221
  "tina-dev": 'yarn tinacms server:start -c "next dev"',
1033
1222
  "tina-build": 'yarn tinacms server:start -c "next build"',
1034
1223
  "tina-start": 'yarn tinacms server:start -c "next start"'
1035
- }
1036
- }, null, 2);
1037
- (0, import_fs_extra3.writeFileSync)(packagePath, newPack);
1038
- const adminPath = import_path4.default.join(pagesPath, "admin", "[[...tina]].js");
1039
- if (import_fs_extra3.default.pathExistsSync(import_path4.default.join(pagesPath, "admin"))) {
1224
+ })
1225
+ }), null, 2);
1226
+ (0, import_fs_extra4.writeFileSync)(packagePath, newPack);
1227
+ const adminPath = import_path5.default.join(pagesPath, "admin", "[[...tina]].js");
1228
+ if (import_fs_extra4.default.pathExistsSync(import_path5.default.join(pagesPath, "admin"))) {
1040
1229
  logger.warn(`Unable to add /pages/admin/[[...tina]].js, this path already exists.
1041
1230
  Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
1042
1231
  return next();
1043
1232
  }
1044
- (0, import_fs_extra3.outputFileSync)(adminPath, adminPage);
1233
+ (0, import_fs_extra4.outputFileSync)(adminPath, adminPage);
1045
1234
  next();
1046
1235
  }
1047
1236
  async function successMessage(ctx, next, options) {
1048
- const baseDir2 = process.cwd();
1049
1237
  logger.info(`Tina setup ${import_chalk2.default.underline.green("done")} \u2705
1050
1238
  Start your dev server with ${successText(`yarn tina-dev`)} and go to http://localhost:3000/demo/blog/HelloWorld to ${successText("check it out the page that was created for you")}
1051
1239
  Enjoy Tina \u{1F999} !
@@ -1059,7 +1247,7 @@ var import_datalayer3 = __toModule(require("@tinacms/datalayer"));
1059
1247
 
1060
1248
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/audit.ts
1061
1249
  var import_graphql8 = __toModule(require("@tinacms/graphql"));
1062
- var import_path5 = __toModule(require("path"));
1250
+ var import_path6 = __toModule(require("path"));
1063
1251
  var import_graphql9 = __toModule(require("@tinacms/graphql"));
1064
1252
  var import_chalk3 = __toModule(require("chalk"));
1065
1253
  var auditCollection = async (args) => {
@@ -1097,7 +1285,7 @@ var auditCollection = async (args) => {
1097
1285
  warning = true;
1098
1286
  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
1287
 
1100
- location: ${import_path5.default.join(rootPath2, node.sys.path)}`));
1288
+ location: ${import_path6.default.join(rootPath2, node.sys.path)}`));
1101
1289
  }
1102
1290
  });
1103
1291
  return warning;
@@ -1133,7 +1321,7 @@ var auditDocuments = async (args) => {
1133
1321
  const documents = result.data.getCollection.documents.edges;
1134
1322
  for (let i = 0; i < documents.length; i++) {
1135
1323
  const node = documents[i].node;
1136
- const fullPath = import_path5.default.join(rootPath2, node.sys.path);
1324
+ const fullPath = import_path6.default.join(rootPath2, node.sys.path);
1137
1325
  logger.info(`Checking document: ${fullPath}`);
1138
1326
  const documentQuery = `query {
1139
1327
  getDocument(collection: "${collection.name}", relativePath: "${node.sys.relativePath}") {
@@ -1188,10 +1376,10 @@ var auditDocuments = async (args) => {
1188
1376
  return error;
1189
1377
  };
1190
1378
  var transformDocumentIntoMutationRequestPayload = (document, instructions, defaults) => {
1191
- const { _collection, __typename, _template, ...rest } = document;
1379
+ const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
1192
1380
  const params = transformParams(rest);
1193
1381
  const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
1194
- return instructions.includeCollection ? { [_collection]: { ...defaults, ...filterObject(paramsWithTemplate) } } : { ...defaults, ...filterObject(paramsWithTemplate) };
1382
+ return instructions.includeCollection ? { [_collection]: __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate)) } : __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate));
1195
1383
  };
1196
1384
  var transformParams = (data) => {
1197
1385
  if (["string", "number", "boolean"].includes(typeof data)) {
@@ -1202,7 +1390,7 @@ var transformParams = (data) => {
1202
1390
  }
1203
1391
  try {
1204
1392
  (0, import_graphql9.assertShape)(data, (yup) => yup.object({ _template: yup.string().required() }));
1205
- const { _template, __typename, ...rest } = data;
1393
+ const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
1206
1394
  const nested = transformParams(rest);
1207
1395
  return { [_template]: nested };
1208
1396
  } catch (e) {
@@ -1234,8 +1422,17 @@ function filterObject(obj) {
1234
1422
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
1235
1423
  var import_chalk4 = __toModule(require("chalk"));
1236
1424
  var import_prompts2 = __toModule(require("prompts"));
1425
+ var import_metrics3 = __toModule(require("@tinacms/metrics"));
1237
1426
  var rootPath = process.cwd();
1238
1427
  var audit = async (ctx, next, options) => {
1428
+ const telemetry = new import_metrics3.Telemetry({ disabled: options.noTelemetry });
1429
+ await telemetry.submitRecord({
1430
+ event: {
1431
+ name: "tinacms:cli:audit:invoke",
1432
+ clean: Boolean(options.clean),
1433
+ useDefaults: Boolean(options.useDefaultValues)
1434
+ }
1435
+ });
1239
1436
  if (options.clean) {
1240
1437
  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
1438
 
@@ -1321,12 +1518,20 @@ var noSDKCodegenOption = {
1321
1518
  };
1322
1519
  var cleanOption = {
1323
1520
  name: "--clean",
1324
- description: "Submit gql mutation to all files to git rid of any data that is not defined in the `schema.ts`"
1521
+ description: "Updates all content files to remove any data not explicitly permitted by the current schema definition"
1325
1522
  };
1326
1523
  var useDefaultValuesOption = {
1327
1524
  name: "--useDefaultValues",
1328
1525
  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
1526
  };
1527
+ var noTelemetryOption = {
1528
+ name: "--noTelemetry",
1529
+ description: "Disable anonymous telemetry that is collected"
1530
+ };
1531
+ var watchFileOption = {
1532
+ name: "-w, --watchFolders [folders...]",
1533
+ description: "a list of folders (relative to where this is being run) that the cli will watch for changes"
1534
+ };
1330
1535
  var baseCmds = [
1331
1536
  {
1332
1537
  command: CMD_START_SERVER,
@@ -1336,25 +1541,27 @@ var baseCmds = [
1336
1541
  subCommand,
1337
1542
  experimentalDatalayer,
1338
1543
  noWatchOption,
1339
- noSDKCodegenOption
1544
+ noSDKCodegenOption,
1545
+ noTelemetryOption,
1546
+ watchFileOption
1340
1547
  ],
1341
1548
  action: (options) => chain([startServer], options)
1342
1549
  },
1343
1550
  {
1344
1551
  command: CMD_COMPILE_MODELS,
1345
1552
  description: "Compile schema into static files for the server",
1346
- options: [experimentalDatalayer],
1553
+ options: [experimentalDatalayer, noTelemetryOption],
1347
1554
  action: (options) => chain([compile], options)
1348
1555
  },
1349
1556
  {
1350
1557
  command: CMD_GEN_TYPES,
1351
1558
  description: "Generate a GraphQL query for your site's schema, (and optionally Typescript types)",
1352
- options: [experimentalDatalayer, noSDKCodegenOption],
1559
+ options: [experimentalDatalayer, noSDKCodegenOption, noTelemetryOption],
1353
1560
  action: (options) => chain([attachSchema, genTypes], options)
1354
1561
  },
1355
1562
  {
1356
1563
  command: INIT,
1357
- options: [experimentalDatalayer],
1564
+ options: [experimentalDatalayer, noTelemetryOption],
1358
1565
  description: "Add Tina Cloud to an existing project",
1359
1566
  action: (options) => chain([
1360
1567
  initTina,
@@ -1370,7 +1577,7 @@ var baseCmds = [
1370
1577
  ], options)
1371
1578
  },
1372
1579
  {
1373
- options: [cleanOption, useDefaultValuesOption],
1580
+ options: [cleanOption, useDefaultValuesOption, noTelemetryOption],
1374
1581
  command: AUDIT,
1375
1582
  description: "Audit your schema and the files to check for errors",
1376
1583
  action: (options) => chain([
@@ -0,0 +1,15 @@
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 getSchemaPath: ({ projectDir }: {
14
+ projectDir: string;
15
+ }) => any;
@@ -0,0 +1,13 @@
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 * from './getSchemaPath';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "0.60.3",
3
+ "version": "0.60.6",
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.5",
24
+ "@tinacms/scripts": "0.50.6",
25
25
  "@types/clear": "0.1.0",
26
26
  "@types/cors": "2.8.5",
27
27
  "@types/express": "^4.17.7",
@@ -38,7 +38,8 @@
38
38
  "@types/progress": "^2.0.3",
39
39
  "@types/prompts": "^2.0.13",
40
40
  "@types/yup": "^0.29.11",
41
- "jest": "^27.0.6"
41
+ "jest": "^27.0.6",
42
+ "typescript": "^4.3.5"
42
43
  },
43
44
  "scripts": {
44
45
  "build": "echo \"Run `yarn build` from the root of the repository instead\"",
@@ -57,7 +58,10 @@
57
58
  "@graphql-tools/graphql-file-loader": "^7.2.0",
58
59
  "@graphql-tools/load": "^7.3.2",
59
60
  "@tinacms/datalayer": "0.0.2",
60
- "@tinacms/graphql": "0.59.6",
61
+ "@tinacms/graphql": "0.59.7",
62
+ "@tinacms/metrics": "0.0.2",
63
+ "@yarnpkg/esbuild-plugin-pnp": "^2.0.1-rc.3",
64
+ "add": "^2.0.6",
61
65
  "ajv": "^6.12.3",
62
66
  "altair-express-middleware": "4.0.6",
63
67
  "auto-bind": "^4.0.0",
@@ -65,8 +69,9 @@
65
69
  "body-parser": "^1.19.0",
66
70
  "chalk": "^2.4.2",
67
71
  "chokidar": "^3.5.1",
68
- "commander": "5.1.0",
72
+ "commander": "^9.0.0",
69
73
  "cors": "^2.8.5",
74
+ "esbuild": "^0.14.20",
70
75
  "esm": "3.2.25",
71
76
  "express": "^4.17.1",
72
77
  "fast-glob": "^3.2.4",
@@ -75,11 +80,11 @@
75
80
  "js-yaml": "^4.0.0",
76
81
  "lodash": "^4.17.19",
77
82
  "lodash.get": "^4.4.2",
78
- "log4js": "^6.3.0",
83
+ "log4js": "^6.4.0",
79
84
  "normalize-path": "^3.0.0",
80
85
  "progress": "^2.0.3",
81
86
  "prompts": "^2.4.1",
82
- "typescript": "^4.3.5",
87
+ "yarn": "^1.22.17",
83
88
  "yup": "^0.32.9"
84
89
  },
85
90
  "publishConfig": {