@tinacms/cli 0.60.18 → 0.60.21

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,30 @@
1
1
  # tinacms-cli
2
2
 
3
+ ## 0.60.21
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e2aafcd93]
8
+ - Updated dependencies [a20fed8b7]
9
+ - @tinacms/graphql@0.60.6
10
+
11
+ ## 0.60.20
12
+
13
+ ### Patch Changes
14
+
15
+ - f71f55ac3: Fixd issue where --dev caused a breaking change
16
+ - Updated dependencies [57f09bdd7]
17
+ - @tinacms/graphql@0.60.5
18
+
19
+ ## 0.60.19
20
+
21
+ ### Patch Changes
22
+
23
+ - d103b27ad: Fix issue where new collections would not be added when CLI restarts
24
+ - e06dbb3ca: Adds `waitForDB` cmd to cli
25
+ - Updated dependencies [d103b27ad]
26
+ - @tinacms/graphql@0.60.4
27
+
3
28
  ## 0.60.18
4
29
 
5
30
  ### Patch Changes
@@ -10,10 +10,12 @@ 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
+ import 'dotenv/config';
13
14
  import { Command } from '../command';
14
15
  export declare const CMD_GEN_TYPES = "schema:types";
15
16
  export declare const CMD_START_SERVER = "server:start";
16
17
  export declare const CMD_COMPILE_MODELS = "schema:compile";
18
+ export declare const CMD_WAIT_FOR_DB = "server:waitForDB";
17
19
  export declare const INIT = "init";
18
20
  export declare const AUDIT = "audit";
19
21
  export declare const baseCmds: Command[];
@@ -12,8 +12,14 @@ limitations under the License.
12
12
  */
13
13
  import type { TinaCloudSchema } from '@tinacms/graphql';
14
14
  export declare const resetGeneratedFolder: () => Promise<void>;
15
- export declare const compile: (_ctx: any, _next: any, options: {
15
+ export declare const compileClient: (ctx: any, next: any, options: {
16
+ clientFileType?: string;
17
+ verbose?: boolean;
18
+ dev?: boolean;
19
+ }) => Promise<any>;
20
+ export declare const compileSchema: (_ctx: any, _next: any, options: {
16
21
  schemaFileType?: string;
17
22
  verbose?: boolean;
23
+ dev?: boolean;
18
24
  }) => Promise<void>;
19
25
  export declare const defineSchema: (config: TinaCloudSchema) => TinaCloudSchema;
@@ -20,6 +20,7 @@ interface Options {
20
20
  noSDK: boolean;
21
21
  noTelemetry: boolean;
22
22
  verbose?: boolean;
23
+ dev?: boolean;
23
24
  }
24
- export declare function startServer(_ctx: any, _next: any, { port, command, noWatch, experimentalData, tinaCloudMediaStore, noSDK, noTelemetry, watchFolders, verbose, }: Options): Promise<void>;
25
+ export declare function startServer(_ctx: any, next: any, { port, noWatch, experimentalData, tinaCloudMediaStore, noSDK, noTelemetry, watchFolders, verbose, dev, }: Options): Promise<void>;
25
26
  export {};
@@ -0,0 +1,17 @@
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
+ interface Options {
14
+ command?: string;
15
+ }
16
+ export declare const startSubprocess: (_ctx: any, next: any, { command }: Options) => Promise<void>;
17
+ export {};
@@ -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 waitForDB: (ctx: any, next: any, options: {
14
+ verbose?: boolean;
15
+ }) => Promise<any>;
package/dist/index.js CHANGED
@@ -37,6 +37,9 @@ var __objRest = (source, exclude) => {
37
37
  var __esm = (fn, res) => function __init() {
38
38
  return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
39
39
  };
40
+ var __commonJS = (cb, mod) => function __require() {
41
+ return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
42
+ };
40
43
  var __export = (target, all) => {
41
44
  __markAsModule(target);
42
45
  for (var name2 in all)
@@ -54,6 +57,123 @@ var __toModule = (module2) => {
54
57
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
55
58
  };
56
59
 
60
+ // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/lib/main.js
61
+ var require_main = __commonJS({
62
+ "pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/lib/main.js"(exports, module2) {
63
+ var fs6 = require("fs");
64
+ var path4 = require("path");
65
+ var os = require("os");
66
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
67
+ function parse2(src) {
68
+ const obj = {};
69
+ let lines = src.toString();
70
+ lines = lines.replace(/\r\n?/mg, "\n");
71
+ let match;
72
+ while ((match = LINE.exec(lines)) != null) {
73
+ const key = match[1];
74
+ let value = match[2] || "";
75
+ value = value.trim();
76
+ const maybeQuote = value[0];
77
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
78
+ if (maybeQuote === '"') {
79
+ value = value.replace(/\\n/g, "\n");
80
+ value = value.replace(/\\r/g, "\r");
81
+ }
82
+ obj[key] = value;
83
+ }
84
+ return obj;
85
+ }
86
+ function _log(message) {
87
+ console.log(`[dotenv][DEBUG] ${message}`);
88
+ }
89
+ function _resolveHome(envPath) {
90
+ return envPath[0] === "~" ? path4.join(os.homedir(), envPath.slice(1)) : envPath;
91
+ }
92
+ function config(options) {
93
+ let dotenvPath = path4.resolve(process.cwd(), ".env");
94
+ let encoding = "utf8";
95
+ const debug = Boolean(options && options.debug);
96
+ const override = Boolean(options && options.override);
97
+ if (options) {
98
+ if (options.path != null) {
99
+ dotenvPath = _resolveHome(options.path);
100
+ }
101
+ if (options.encoding != null) {
102
+ encoding = options.encoding;
103
+ }
104
+ }
105
+ try {
106
+ const parsed = DotenvModule.parse(fs6.readFileSync(dotenvPath, { encoding }));
107
+ Object.keys(parsed).forEach(function(key) {
108
+ if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
109
+ process.env[key] = parsed[key];
110
+ } else {
111
+ if (override === true) {
112
+ process.env[key] = parsed[key];
113
+ }
114
+ if (debug) {
115
+ if (override === true) {
116
+ _log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
117
+ } else {
118
+ _log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
119
+ }
120
+ }
121
+ }
122
+ });
123
+ return { parsed };
124
+ } catch (e) {
125
+ if (debug) {
126
+ _log(`Failed to load ${dotenvPath} ${e.message}`);
127
+ }
128
+ return { error: e };
129
+ }
130
+ }
131
+ var DotenvModule = {
132
+ config,
133
+ parse: parse2
134
+ };
135
+ module2.exports.config = DotenvModule.config;
136
+ module2.exports.parse = DotenvModule.parse;
137
+ module2.exports = DotenvModule;
138
+ }
139
+ });
140
+
141
+ // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/lib/env-options.js
142
+ var require_env_options = __commonJS({
143
+ "pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/lib/env-options.js"(exports, module2) {
144
+ var options = {};
145
+ if (process.env.DOTENV_CONFIG_ENCODING != null) {
146
+ options.encoding = process.env.DOTENV_CONFIG_ENCODING;
147
+ }
148
+ if (process.env.DOTENV_CONFIG_PATH != null) {
149
+ options.path = process.env.DOTENV_CONFIG_PATH;
150
+ }
151
+ if (process.env.DOTENV_CONFIG_DEBUG != null) {
152
+ options.debug = process.env.DOTENV_CONFIG_DEBUG;
153
+ }
154
+ if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
155
+ options.override = process.env.DOTENV_CONFIG_OVERRIDE;
156
+ }
157
+ module2.exports = options;
158
+ }
159
+ });
160
+
161
+ // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/lib/cli-options.js
162
+ var require_cli_options = __commonJS({
163
+ "pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/lib/cli-options.js"(exports, module2) {
164
+ var re = /^dotenv_config_(encoding|path|debug|override)=(.+)$/;
165
+ module2.exports = function optionMatcher(args) {
166
+ return args.reduce(function(acc, cur) {
167
+ const matches = cur.match(re);
168
+ if (matches) {
169
+ acc[matches[1]] = matches[2];
170
+ }
171
+ return acc;
172
+ }, {});
173
+ };
174
+ }
175
+ });
176
+
57
177
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/models/media.ts
58
178
  var import_fs_extra5, import_path6, MediaModel;
59
179
  var init_media = __esm({
@@ -228,7 +348,7 @@ var commander = __toModule(require("commander"));
228
348
 
229
349
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/package.json
230
350
  var name = "@tinacms/cli";
231
- var version = "0.60.18";
351
+ var version = "0.60.21";
232
352
 
233
353
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
234
354
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -1339,6 +1459,11 @@ async function successMessage(ctx, next, options) {
1339
1459
  next();
1340
1460
  }
1341
1461
 
1462
+ // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/config.js
1463
+ (function() {
1464
+ require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
1465
+ })();
1466
+
1342
1467
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
1343
1468
  var chain = async (cmds, options) => {
1344
1469
  const ctx = {};
@@ -1486,39 +1611,49 @@ export const tinaConfig = defineConfig({
1486
1611
  });
1487
1612
  `;
1488
1613
 
1489
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getSchemaPath.ts
1614
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getPath.ts
1490
1615
  var import_path4 = __toModule(require("path"));
1491
1616
  var import_fs_extra3 = __toModule(require("fs-extra"));
1492
- var ErrorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
1493
- var getSchemaPath = ({ projectDir }) => {
1617
+ var getPath = ({
1618
+ projectDir,
1619
+ filename,
1620
+ allowedTypes,
1621
+ errorMessage
1622
+ }) => {
1494
1623
  if (!import_fs_extra3.default.existsSync(projectDir)) {
1495
- throw new Error(ErrorMessage);
1496
- }
1497
- const inputPathTS = import_path4.default.join(projectDir, "schema.ts");
1498
- const inputPathJS = import_path4.default.join(projectDir, "schema.js");
1499
- const inputPathTSX = import_path4.default.join(projectDir, "schema.tsx");
1500
- const inputPathJSX = import_path4.default.join(projectDir, "schema.jsx");
1501
- let inputFile;
1502
- if (import_fs_extra3.default.existsSync(inputPathTS)) {
1503
- inputFile = inputPathTS;
1504
- } else if (import_fs_extra3.default.existsSync(inputPathJS)) {
1505
- inputFile = inputPathJS;
1506
- } else if (import_fs_extra3.default.existsSync(inputPathTSX)) {
1507
- inputFile = inputPathTSX;
1508
- } else if (import_fs_extra3.default.existsSync(inputPathJSX)) {
1509
- inputFile = inputPathJSX;
1624
+ throw new Error(errorMessage);
1510
1625
  }
1626
+ const filePaths = allowedTypes.map((ext) => import_path4.default.join(projectDir, `${filename}.${ext}`));
1627
+ let inputFile = void 0;
1628
+ filePaths.every((path4) => {
1629
+ if (import_fs_extra3.default.existsSync(path4)) {
1630
+ inputFile = path4;
1631
+ return false;
1632
+ }
1633
+ return true;
1634
+ });
1511
1635
  if (!inputFile) {
1512
- throw new Error(ErrorMessage);
1636
+ throw new Error(errorMessage);
1513
1637
  }
1514
1638
  return inputFile;
1515
1639
  };
1640
+ var getSchemaPath = ({ projectDir }) => {
1641
+ const filename = "schema";
1642
+ const allowedTypes = ["js", "jsx", "ts", "tsx"];
1643
+ const errorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
1644
+ return getPath({ projectDir, filename, allowedTypes, errorMessage });
1645
+ };
1646
+ var getClientPath = ({ projectDir }) => {
1647
+ const filename = "client";
1648
+ const allowedTypes = ["js", "ts"];
1649
+ const errorMessage = "Must provide a `.tina/client.{ts,js}`";
1650
+ return getPath({ projectDir, filename, allowedTypes, errorMessage });
1651
+ };
1516
1652
 
1517
1653
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
1518
1654
  var tinaPath = import_path5.default.join(process.cwd(), ".tina");
1519
1655
  var packageJSONFilePath = import_path5.default.join(process.cwd(), "package.json");
1520
1656
  var tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
1521
- var tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp");
1522
1657
  var tinaConfigPath = import_path5.default.join(tinaGeneratedPath, "config");
1523
1658
  var resetGeneratedFolder = async () => {
1524
1659
  try {
@@ -1534,14 +1669,74 @@ export const queries = (client)=>({})
1534
1669
  `);
1535
1670
  await import_fs_extra4.default.outputFile(import_path5.default.join(tinaGeneratedPath, ".gitignore"), "db");
1536
1671
  };
1537
- var cleanup = async ({ tinaTempPath: tinaTempPath2 }) => {
1538
- await import_fs_extra4.default.remove(tinaTempPath2);
1672
+ var cleanup = async ({ tinaTempPath }) => {
1673
+ await import_fs_extra4.default.remove(tinaTempPath);
1674
+ };
1675
+ var compileClient = async (ctx, next, options) => {
1676
+ const tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp_client");
1677
+ if (!options.clientFileType)
1678
+ options = __spreadProps(__spreadValues({}, options), { clientFileType: "ts" });
1679
+ if (options.verbose) {
1680
+ logger.info(logText("Compiling Client..."));
1681
+ }
1682
+ const { clientFileType: requestedClientFileType = "ts" } = options;
1683
+ const allowedFileTypes = ["ts", "js"];
1684
+ if (allowedFileTypes.includes(requestedClientFileType) === false) {
1685
+ throw new Error(`Requested schema file type '${requestedClientFileType}' is not valid. Supported schema file types: 'ts, js'`);
1686
+ }
1687
+ if (ctx) {
1688
+ ctx.clientFileType = requestedClientFileType;
1689
+ }
1690
+ let clientExists = true;
1691
+ try {
1692
+ getClientPath({ projectDir: tinaPath });
1693
+ } catch {
1694
+ clientExists = false;
1695
+ }
1696
+ if (!clientExists) {
1697
+ if (options.verbose) {
1698
+ logger.info(logText(`.tina/client.${requestedClientFileType} not found, skipping compile client...`));
1699
+ }
1700
+ return next();
1701
+ }
1702
+ try {
1703
+ const define = {};
1704
+ if (!process.env.NODE_ENV) {
1705
+ define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
1706
+ }
1707
+ const inputFile = getClientPath({ projectDir: tinaPath });
1708
+ await transpile(inputFile, "client.js", tinaTempPath, options.verbose, define);
1709
+ } catch (e) {
1710
+ await cleanup({ tinaTempPath });
1711
+ throw new BuildSchemaError(e);
1712
+ }
1713
+ Object.keys(require.cache).map((key) => {
1714
+ if (key.startsWith(tinaTempPath)) {
1715
+ delete require.cache[require.resolve(key)];
1716
+ }
1717
+ });
1718
+ try {
1719
+ const clientFunc = require(import_path5.default.join(tinaTempPath, "client.js"));
1720
+ const client = clientFunc.default;
1721
+ ctx.client = client;
1722
+ await cleanup({ tinaTempPath });
1723
+ } catch (e) {
1724
+ await cleanup({ tinaTempPath });
1725
+ if (e instanceof Error) {
1726
+ if (e.name === "TinaSchemaValidationError") {
1727
+ throw e;
1728
+ }
1729
+ }
1730
+ throw new ExecuteSchemaError(e);
1731
+ }
1732
+ return next();
1539
1733
  };
1540
- var compile = async (_ctx, _next, options) => {
1734
+ var compileSchema = async (_ctx, _next, options) => {
1735
+ const tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp_schema");
1541
1736
  if (!options.schemaFileType)
1542
1737
  options = __spreadProps(__spreadValues({}, options), { schemaFileType: "ts" });
1543
1738
  if (options.verbose) {
1544
- logger.info(logText("Compiling..."));
1739
+ logger.info(logText("Compiling Schema..."));
1545
1740
  }
1546
1741
  const { schemaFileType: requestedSchemaFileType = "ts" } = options;
1547
1742
  const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
@@ -1567,7 +1762,12 @@ var compile = async (_ctx, _next, options) => {
1567
1762
  await import_fs_extra4.default.writeFile(file, defaultSchema);
1568
1763
  }
1569
1764
  try {
1570
- await transpile(tinaPath, tinaTempPath, options.verbose);
1765
+ const define = {};
1766
+ if (!process.env.NODE_ENV) {
1767
+ define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
1768
+ }
1769
+ const inputFile = getSchemaPath({ projectDir: tinaPath });
1770
+ await transpile(inputFile, "schema.js", tinaTempPath, options.verbose, define);
1571
1771
  } catch (e) {
1572
1772
  await cleanup({ tinaTempPath });
1573
1773
  throw new BuildSchemaError(e);
@@ -1592,7 +1792,7 @@ var compile = async (_ctx, _next, options) => {
1592
1792
  throw new ExecuteSchemaError(e);
1593
1793
  }
1594
1794
  };
1595
- var transpile = async (projectDir, tempDir, verbose) => {
1795
+ var transpile = async (inputFile, outputFile, tempDir, verbose, define) => {
1596
1796
  if (verbose)
1597
1797
  logger.info(logText("Building javascript..."));
1598
1798
  const packageJSON = JSON.parse(import_fs_extra4.default.readFileSync(packageJSONFilePath).toString() || "{}");
@@ -1600,8 +1800,7 @@ var transpile = async (projectDir, tempDir, verbose) => {
1600
1800
  const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
1601
1801
  const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
1602
1802
  const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
1603
- const inputFile = getSchemaPath({ projectDir });
1604
- const outputPath = import_path5.default.join(tempDir, "schema.js");
1803
+ const outputPath = import_path5.default.join(tempDir, outputFile);
1605
1804
  await (0, import_esbuild.build)({
1606
1805
  bundle: true,
1607
1806
  platform: "neutral",
@@ -1610,7 +1809,8 @@ var transpile = async (projectDir, tempDir, verbose) => {
1610
1809
  treeShaking: true,
1611
1810
  external: [...external, "./node_modules/*"],
1612
1811
  loader: loaders,
1613
- outfile: outputPath
1812
+ outfile: outputPath,
1813
+ define
1614
1814
  });
1615
1815
  if (verbose)
1616
1816
  logger.info(logText(`Javascript built`));
@@ -1663,21 +1863,20 @@ var AsyncLock = class {
1663
1863
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
1664
1864
  var import_metrics3 = __toModule(require("@tinacms/metrics"));
1665
1865
  var import_chalk6 = __toModule(require("chalk"));
1666
- var import_child_process = __toModule(require("child_process"));
1667
1866
  var import_chokidar = __toModule(require("chokidar"));
1668
1867
  var import_path8 = __toModule(require("path"));
1669
1868
  var lock = new AsyncLock();
1670
1869
  var gqlPackageFile = require.resolve("@tinacms/graphql");
1671
- async function startServer(_ctx, _next, {
1870
+ async function startServer(_ctx, next, {
1672
1871
  port = 4001,
1673
- command,
1674
1872
  noWatch,
1675
1873
  experimentalData,
1676
1874
  tinaCloudMediaStore: tinaCloudMediaStore2,
1677
1875
  noSDK,
1678
1876
  noTelemetry,
1679
1877
  watchFolders,
1680
- verbose
1878
+ verbose,
1879
+ dev
1681
1880
  }) {
1682
1881
  lock.disable();
1683
1882
  const rootPath2 = process.cwd();
@@ -1694,30 +1893,9 @@ async function startServer(_ctx, _next, {
1694
1893
  const store = experimentalData ? new import_datalayer3.LevelStore(rootPath2) : new import_datalayer3.FilesystemStore({ rootPath: rootPath2 });
1695
1894
  const shouldBuild = bridge.supportsBuilding();
1696
1895
  const database = await (0, import_graphql10.createDatabase)({ store, bridge });
1697
- const startSubprocess = () => {
1698
- if (typeof command === "string") {
1699
- const commands = command.split(" ");
1700
- const firstCommand = commands[0];
1701
- const args = commands.slice(1) || [];
1702
- const ps = import_child_process.default.spawn(firstCommand, args, {
1703
- stdio: "inherit",
1704
- shell: true
1705
- });
1706
- ps.on("error", (code) => {
1707
- logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
1708
- logger.error(`name: ${code.name}
1709
- message: ${code.message}
1710
-
1711
- stack: ${code.stack || "No stack was provided"}`);
1712
- });
1713
- ps.on("close", (code) => {
1714
- logger.info(`child process exited with code ${code}`);
1715
- process.exit(code);
1716
- });
1717
- }
1718
- };
1719
1896
  let ready = false;
1720
1897
  const build2 = async (noSDK2) => {
1898
+ database.clearCache();
1721
1899
  await lock.promise;
1722
1900
  lock.enable();
1723
1901
  try {
@@ -1731,7 +1909,7 @@ stack: ${code.stack || "No stack was provided"}`);
1731
1909
  cliFlags.push("tinaCloudMediaStore");
1732
1910
  }
1733
1911
  const database2 = await (0, import_graphql10.createDatabase)({ store, bridge });
1734
- await compile(null, null, { verbose });
1912
+ await compileSchema(null, null, { verbose, dev });
1735
1913
  const schema = await (0, import_graphql10.buildSchema)(rootPath2, database2, cliFlags);
1736
1914
  await genTypes({ schema }, () => {
1737
1915
  }, { noSDK: noSDK2, verbose });
@@ -1760,7 +1938,7 @@ stack: ${code.stack || "No stack was provided"}`);
1760
1938
  await build2(noSDK);
1761
1939
  }
1762
1940
  ready = true;
1763
- startSubprocess();
1941
+ next();
1764
1942
  } catch (e) {
1765
1943
  handleServerErrors(e);
1766
1944
  console.log(e);
@@ -1846,14 +2024,114 @@ or`);
1846
2024
  logger.info("Detected CI environment, omitting watch commands...");
1847
2025
  }
1848
2026
  start();
1849
- startSubprocess();
2027
+ next();
1850
2028
  }
1851
2029
  }
1852
2030
 
2031
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/waitForDB/index.ts
2032
+ var POLLING_INTERVAL = 5e3;
2033
+ var STATUS_INPROGRESS = "inprogress";
2034
+ var STATUS_COMPLETE = "complete";
2035
+ var STATUS_FAILED = "failed";
2036
+ var IndexFailedError = class extends Error {
2037
+ constructor(message) {
2038
+ super(message);
2039
+ this.name = "IndexFailedError";
2040
+ }
2041
+ };
2042
+ var waitForDB = async (ctx, next, options) => {
2043
+ if (options.verbose) {
2044
+ logger.info(logText("Waiting for DB..."));
2045
+ }
2046
+ if (!ctx.client) {
2047
+ if (options.verbose) {
2048
+ logger.info(logText("client is unavailable, skipping..."));
2049
+ }
2050
+ return next();
2051
+ }
2052
+ const client = ctx.client;
2053
+ const { host, clientId, branch, isLocalClient } = client.parseURL();
2054
+ if (isLocalClient) {
2055
+ if (options.verbose) {
2056
+ logger.info(logText("client is local, skipping..."));
2057
+ }
2058
+ return next();
2059
+ }
2060
+ const pollForStatus = async () => {
2061
+ try {
2062
+ if (options.verbose) {
2063
+ logger.info(logText("Polling for status..."));
2064
+ }
2065
+ const headers = new Headers();
2066
+ headers.append("Content-Type", "application/json");
2067
+ if (client.readonlyToken) {
2068
+ headers.append("X-API-KEY", client.readonlyToken);
2069
+ }
2070
+ const response = await fetch(`https://${host}/db/${clientId}/status/${branch}`, {
2071
+ method: "GET",
2072
+ headers
2073
+ });
2074
+ const { status, error } = await response.json();
2075
+ const statusMessage = `DB responded with: '${status}'`;
2076
+ if (status === STATUS_COMPLETE) {
2077
+ if (options.verbose) {
2078
+ logger.info(logText(`${statusMessage}`));
2079
+ }
2080
+ return next();
2081
+ } else if (status === STATUS_INPROGRESS) {
2082
+ if (options.verbose) {
2083
+ logger.info(logText(`${statusMessage}, trying again in 5 seconds`));
2084
+ }
2085
+ setTimeout(pollForStatus, POLLING_INTERVAL);
2086
+ } else if (status === STATUS_FAILED) {
2087
+ throw new IndexFailedError(`Attempting to index DB responded with status 'failed', ${error}`);
2088
+ } else {
2089
+ if (options.verbose) {
2090
+ logger.info(logText(`${statusMessage}`));
2091
+ }
2092
+ return next();
2093
+ }
2094
+ } catch (e) {
2095
+ if (e instanceof IndexFailedError) {
2096
+ throw e;
2097
+ } else {
2098
+ throw new Error(`Unable to query DB for indexing status, encountered error: ${e.message}`);
2099
+ }
2100
+ }
2101
+ };
2102
+ pollForStatus();
2103
+ };
2104
+
2105
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/startSubprocess/index.ts
2106
+ var import_child_process = __toModule(require("child_process"));
2107
+ var startSubprocess = async (_ctx, next, { command }) => {
2108
+ if (typeof command === "string") {
2109
+ const commands = command.split(" ");
2110
+ const firstCommand = commands[0];
2111
+ const args = commands.slice(1) || [];
2112
+ const ps = import_child_process.default.spawn(firstCommand, args, {
2113
+ stdio: "inherit",
2114
+ shell: true
2115
+ });
2116
+ ps.on("error", (code) => {
2117
+ logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
2118
+ logger.error(`name: ${code.name}
2119
+ message: ${code.message}
2120
+
2121
+ stack: ${code.stack || "No stack was provided"}`);
2122
+ });
2123
+ ps.on("close", (code) => {
2124
+ logger.info(`child process exited with code ${code}`);
2125
+ process.exit(code);
2126
+ });
2127
+ }
2128
+ };
2129
+
1853
2130
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
1854
2131
  var CMD_GEN_TYPES = "schema:types";
1855
2132
  var CMD_START_SERVER = "server:start";
1856
2133
  var CMD_COMPILE_MODELS = "schema:compile";
2134
+ var CMD_WAIT_FOR_DB = "server:waitForDB";
1857
2135
  var INIT = "init";
1858
2136
  var AUDIT = "audit";
1859
2137
  var startServerPortOption = {
@@ -1904,6 +2182,10 @@ var tinaCloudMediaStore = {
1904
2182
  name: "--tinaCloudMediaStore",
1905
2183
  description: "Automatically pushes updates from GitHub to the Tina Cloud Media Store"
1906
2184
  };
2185
+ var developmentOption = {
2186
+ name: "--dev",
2187
+ description: "Uses NODE_ENV=development when compiling client and schema"
2188
+ };
1907
2189
  var baseCmds = [
1908
2190
  {
1909
2191
  command: CMD_START_SERVER,
@@ -1917,15 +2199,28 @@ var baseCmds = [
1917
2199
  noSDKCodegenOption,
1918
2200
  noTelemetryOption,
1919
2201
  watchFileOption,
1920
- verboseOption
2202
+ verboseOption,
2203
+ developmentOption
2204
+ ],
2205
+ action: (options) => chain([startServer, startSubprocess], options)
2206
+ },
2207
+ {
2208
+ command: CMD_WAIT_FOR_DB,
2209
+ description: "Wait for DB to finish indexing, start subprocess",
2210
+ options: [
2211
+ subCommand,
2212
+ experimentalDatalayer,
2213
+ noTelemetryOption,
2214
+ verboseOption,
2215
+ developmentOption
1921
2216
  ],
1922
- action: (options) => chain([startServer], options)
2217
+ action: (options) => chain([compileClient, waitForDB, startSubprocess], options)
1923
2218
  },
1924
2219
  {
1925
2220
  command: CMD_COMPILE_MODELS,
1926
2221
  description: "Compile schema into static files for the server",
1927
2222
  options: [experimentalDatalayer, tinaCloudMediaStore, noTelemetryOption],
1928
- action: (options) => chain([compile], options)
2223
+ action: (options) => chain([compileSchema], options)
1929
2224
  },
1930
2225
  {
1931
2226
  command: CMD_GEN_TYPES,
@@ -1952,7 +2247,7 @@ var baseCmds = [
1952
2247
  initTina,
1953
2248
  installDeps,
1954
2249
  async (_ctx, next, options2) => {
1955
- await compile(_ctx, next, options2);
2250
+ await compileSchema(_ctx, next, options2);
1956
2251
  next();
1957
2252
  },
1958
2253
  attachSchema,
@@ -1971,7 +2266,7 @@ var baseCmds = [
1971
2266
  next();
1972
2267
  },
1973
2268
  async (_ctx, next) => {
1974
- await compile(_ctx, next, options);
2269
+ await compileSchema(_ctx, next, options);
1975
2270
  next();
1976
2271
  },
1977
2272
  attachSchema,
@@ -13,3 +13,6 @@ limitations under the License.
13
13
  export declare const getSchemaPath: ({ projectDir }: {
14
14
  projectDir: string;
15
15
  }) => any;
16
+ export declare const getClientPath: ({ projectDir }: {
17
+ projectDir: string;
18
+ }) => any;
@@ -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 * from './getSchemaPath';
13
+ export * from './getPath';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "0.60.18",
3
+ "version": "0.60.21",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -59,7 +59,7 @@
59
59
  "@graphql-tools/graphql-file-loader": "^7.2.0",
60
60
  "@graphql-tools/load": "^7.3.2",
61
61
  "@tinacms/datalayer": "0.1.1",
62
- "@tinacms/graphql": "0.60.3",
62
+ "@tinacms/graphql": "0.60.6",
63
63
  "@tinacms/metrics": "0.0.3",
64
64
  "@tinacms/schema-tools": "0.0.4",
65
65
  "@yarnpkg/esbuild-plugin-pnp": "^2.0.1-rc.3",
@@ -73,6 +73,7 @@
73
73
  "chokidar": "^3.5.1",
74
74
  "commander": "^9.0.0",
75
75
  "cors": "^2.8.5",
76
+ "dotenv": "^16.0.1",
76
77
  "esbuild": "^0.14.20",
77
78
  "esm": "3.2.25",
78
79
  "express": "^4.17.1",