@tinacms/cli 1.0.8 → 1.1.0

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.
Files changed (45) hide show
  1. package/LICENSE +8 -0
  2. package/dist/buildTina/attachDatabase.d.ts +8 -0
  3. package/dist/buildTina/attachPath.d.ts +1 -10
  4. package/dist/buildTina/git.d.ts +1 -10
  5. package/dist/buildTina/index.d.ts +13 -10
  6. package/dist/cmds/audit/audit.d.ts +1 -10
  7. package/dist/cmds/audit/index.d.ts +1 -10
  8. package/dist/cmds/baseCmds.d.ts +1 -10
  9. package/dist/cmds/compile/defaultSchema.d.ts +1 -10
  10. package/dist/cmds/compile/index.d.ts +3 -10
  11. package/dist/cmds/forestry-migrate/index.d.ts +1 -10
  12. package/dist/cmds/forestry-migrate/util/errorSingleton.d.ts +1 -10
  13. package/dist/cmds/forestry-migrate/util/index.d.ts +1 -10
  14. package/dist/cmds/init/setup-files/config.d.ts +1 -10
  15. package/dist/cmds/init/setup-files/index.d.ts +1 -10
  16. package/dist/cmds/query-gen/genTypes.d.ts +1 -10
  17. package/dist/cmds/query-gen/index.d.ts +1 -10
  18. package/dist/cmds/start-server/errors/index.d.ts +1 -10
  19. package/dist/cmds/start-server/index.d.ts +3 -11
  20. package/dist/cmds/start-server/lock.d.ts +1 -10
  21. package/dist/cmds/start-server/server.d.ts +1 -10
  22. package/dist/cmds/startSubprocess/index.d.ts +1 -10
  23. package/dist/cmds/statusChecks/checkClientInformation.d.ts +5 -12
  24. package/dist/cmds/statusChecks/waitForIndexing.d.ts +2 -23
  25. package/dist/codegen/index.d.ts +1 -10
  26. package/dist/codegen/plugin.d.ts +1 -10
  27. package/dist/codegen/sdkPlugin/config.d.ts +1 -10
  28. package/dist/codegen/sdkPlugin/index.d.ts +1 -10
  29. package/dist/codegen/sdkPlugin/visitor.d.ts +1 -10
  30. package/dist/command.d.ts +1 -10
  31. package/dist/index.d.ts +1 -10
  32. package/dist/index.js +276 -215
  33. package/dist/lib/getPath.d.ts +2 -11
  34. package/dist/lib/index.d.ts +1 -10
  35. package/dist/logger/index.d.ts +1 -10
  36. package/dist/middleware.d.ts +1 -10
  37. package/dist/server/index.d.ts +1 -10
  38. package/dist/server/models/media.d.ts +1 -10
  39. package/dist/server/routes/index.d.ts +1 -10
  40. package/dist/server/server.d.ts +2 -11
  41. package/dist/utils/index.d.ts +1 -10
  42. package/dist/utils/script-helpers.d.ts +0 -12
  43. package/dist/utils/spinner.d.ts +1 -10
  44. package/dist/utils/theme.d.ts +1 -10
  45. package/package.json +10 -7
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_extra6, import_path8, 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_extra6 = __toModule(require("fs-extra"));
77
+ import_path8 = __toModule(require("path"));
78
78
  init_utils();
79
79
  MediaModel = class {
80
80
  constructor({ rootPath: rootPath2, publicFolder, mediaRoot }) {
@@ -84,12 +84,12 @@ var init_media = __esm({
84
84
  }
85
85
  async listMedia(args) {
86
86
  try {
87
- const folderPath = (0, import_path9.join)(this.rootPath, this.publicFolder, this.mediaRoot, args.searchPath);
87
+ const folderPath = (0, import_path8.join)(this.rootPath, this.publicFolder, this.mediaRoot, args.searchPath);
88
88
  const searchPath = parseMediaFolder(args.searchPath);
89
- const filesStr = await import_fs_extra7.default.readdir(folderPath);
89
+ const filesStr = await import_fs_extra6.default.readdir(folderPath);
90
90
  const filesProm = filesStr.map(async (file) => {
91
- const filePath = (0, import_path9.join)(folderPath, file);
92
- const stat = await import_fs_extra7.default.stat(filePath);
91
+ const filePath = (0, import_path8.join)(folderPath, file);
92
+ const stat = await import_fs_extra6.default.stat(filePath);
93
93
  let src = `/${file}`;
94
94
  const isFile = stat.isFile();
95
95
  if (!isFile) {
@@ -145,9 +145,9 @@ var init_media = __esm({
145
145
  }
146
146
  async deleteMedia(args) {
147
147
  try {
148
- const file = (0, import_path9.join)(this.rootPath, this.publicFolder, this.mediaRoot, args.searchPath);
149
- await import_fs_extra7.default.stat(file);
150
- await import_fs_extra7.default.remove(file);
148
+ const file = (0, import_path8.join)(this.rootPath, this.publicFolder, this.mediaRoot, args.searchPath);
149
+ await import_fs_extra6.default.stat(file);
150
+ await import_fs_extra6.default.remove(file);
151
151
  return { ok: true };
152
152
  } catch (error) {
153
153
  console.error(error);
@@ -159,15 +159,15 @@ var init_media = __esm({
159
159
  });
160
160
 
161
161
  // src/server/routes/index.ts
162
- var import_express, import_path10, import_multer, createMediaRouter;
162
+ var import_express, import_path9, import_multer, createMediaRouter;
163
163
  var init_routes = __esm({
164
164
  "src/server/routes/index.ts"() {
165
165
  import_express = __toModule(require("express"));
166
- import_path10 = __toModule(require("path"));
166
+ import_path9 = __toModule(require("path"));
167
167
  import_multer = __toModule(require("multer"));
168
168
  init_media();
169
169
  createMediaRouter = (config2) => {
170
- const mediaFolder = (0, import_path10.join)(config2.rootPath, config2.publicFolder, config2.mediaRoot);
170
+ const mediaFolder = (0, import_path9.join)(config2.rootPath, config2.publicFolder, config2.mediaRoot);
171
171
  const storage = import_multer.default.diskStorage({
172
172
  destination: function(req, file, cb) {
173
173
  cb(null, mediaFolder);
@@ -304,7 +304,7 @@ var commander = __toModule(require("commander"));
304
304
 
305
305
  // package.json
306
306
  var name = "@tinacms/cli";
307
- var version = "1.0.8";
307
+ var version = "1.1.0";
308
308
 
309
309
  // src/cmds/audit/audit.ts
310
310
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -552,7 +552,7 @@ var chain = async (cmds, options) => {
552
552
  var import_chalk4 = __toModule(require("chalk"));
553
553
 
554
554
  // src/cmds/start-server/index.ts
555
- var import_path11 = __toModule(require("path"));
555
+ var import_path10 = __toModule(require("path"));
556
556
  var import_chokidar = __toModule(require("chokidar"));
557
557
  var import_metrics2 = __toModule(require("@tinacms/metrics"));
558
558
 
@@ -604,10 +604,11 @@ var handleServerErrors = (e) => {
604
604
  };
605
605
 
606
606
  // src/buildTina/index.ts
607
- var import_fs_extra6 = __toModule(require("fs-extra"));
607
+ var import_fs_extra5 = __toModule(require("fs-extra"));
608
608
  var import_graphql9 = __toModule(require("@tinacms/graphql"));
609
609
  var import_datalayer = __toModule(require("@tinacms/datalayer"));
610
- var import_path8 = __toModule(require("path"));
610
+ var import_memory_level = __toModule(require("memory-level"));
611
+ var import_path7 = __toModule(require("path"));
611
612
 
612
613
  // src/cmds/compile/index.ts
613
614
  var _ = __toModule(require("lodash"));
@@ -628,9 +629,9 @@ var fileExists = ({
628
629
  }
629
630
  const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
630
631
  let inputFile = void 0;
631
- filePaths.every((path11) => {
632
- if (import_fs_extra.default.existsSync(path11)) {
633
- inputFile = path11;
632
+ filePaths.every((path12) => {
633
+ if (import_fs_extra.default.existsSync(path12)) {
634
+ inputFile = path12;
634
635
  return false;
635
636
  }
636
637
  return true;
@@ -644,18 +645,22 @@ var getPath = ({
644
645
  errorMessage
645
646
  }) => {
646
647
  if (!import_fs_extra.default.existsSync(projectDir)) {
647
- throw new Error(errorMessage);
648
+ if (errorMessage) {
649
+ throw new Error(errorMessage);
650
+ } else {
651
+ throw new Error(`Could not find ${projectDir}`);
652
+ }
648
653
  }
649
654
  const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
650
655
  let inputFile = void 0;
651
- filePaths.every((path11) => {
652
- if (import_fs_extra.default.existsSync(path11)) {
653
- inputFile = path11;
656
+ filePaths.every((path12) => {
657
+ if (import_fs_extra.default.existsSync(path12)) {
658
+ inputFile = path12;
654
659
  return false;
655
660
  }
656
661
  return true;
657
662
  });
658
- if (!inputFile) {
663
+ if (!inputFile && errorMessage) {
659
664
  throw new Error(errorMessage);
660
665
  }
661
666
  return inputFile;
@@ -819,7 +824,7 @@ See here for migration steps, see here: https://tina.io/blog/upgrading-to-iframe
819
824
  await import_fs_extra2.default.outputFile(import_path3.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
820
825
  return schema;
821
826
  };
822
- var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
827
+ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath, platform = "neutral") => {
823
828
  if (verbose)
824
829
  logger.info(logText("Building javascript..."));
825
830
  const packageJSON = JSON.parse(import_fs_extra2.default.readFileSync(packageJSONFilePath).toString() || "{}");
@@ -830,7 +835,7 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
830
835
  const prebuiltInputPath = import_path3.default.join(tempDir, "temp-output.jsx");
831
836
  await (0, import_esbuild.build)({
832
837
  bundle: true,
833
- platform: "neutral",
838
+ platform,
834
839
  target: ["es2020"],
835
840
  entryPoints: [inputFile],
836
841
  treeShaking: true,
@@ -844,7 +849,7 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
844
849
  const outputPath = import_path3.default.join(tempDir, outputFile);
845
850
  await (0, import_esbuild.build)({
846
851
  bundle: true,
847
- platform: "neutral",
852
+ platform,
848
853
  target: ["node10.4"],
849
854
  entryPoints: [prebuiltInputPath],
850
855
  format: "cjs",
@@ -1088,13 +1093,13 @@ async function genClient({
1088
1093
  usingTs,
1089
1094
  rootPath: rootPath2
1090
1095
  }, options) {
1091
- var _a, _b, _c, _d, _e;
1096
+ var _a, _b, _c, _d, _e, _f, _g;
1092
1097
  const generatedPath = import_path5.default.join(rootPath2, ".tina", "__generated__");
1093
1098
  const branch = (_a = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _a.branch;
1094
1099
  const clientId = (_b = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _b.clientId;
1095
1100
  const token = (_c = tinaSchema.config) == null ? void 0 : _c.token;
1096
1101
  const baseUrl = ((_e = (_d = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _d.tinaioConfig) == null ? void 0 : _e.contentApiUrlOverride) || `https://${TINA_HOST}`;
1097
- if ((!branch || !clientId || !token) && !(options == null ? void 0 : options.local)) {
1102
+ if ((!branch || !clientId || !token) && !(options == null ? void 0 : options.local) && !((_f = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _f.contentApiUrlOverride)) {
1098
1103
  const missing = [];
1099
1104
  if (!branch)
1100
1105
  missing.push("branch");
@@ -1104,7 +1109,10 @@ async function genClient({
1104
1109
  missing.push("token");
1105
1110
  throw new Error(`Client not configured properly. Missing ${missing.join(", ")}. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information`);
1106
1111
  }
1107
- const apiURL = options.local ? `http://localhost:${options.port || 4001}/graphql` : `${baseUrl}/content/${clientId}/github/${branch}`;
1112
+ let apiURL = options.local ? `http://localhost:${options.port || 4001}/graphql` : `${baseUrl}/content/${clientId}/github/${branch}`;
1113
+ if ((_g = tinaSchema.config) == null ? void 0 : _g.contentApiUrlOverride) {
1114
+ apiURL = tinaSchema.config.contentApiUrlOverride;
1115
+ }
1108
1116
  const clientPath = import_path5.default.join(generatedPath, `client.${usingTs ? "ts" : "js"}`);
1109
1117
  import_fs_extra3.default.writeFileSync(clientPath, `import { createClient } from "tinacms/dist/client";
1110
1118
  import { queries } from "./types";
@@ -1154,72 +1162,6 @@ schema {
1154
1162
  next();
1155
1163
  }
1156
1164
 
1157
- // src/buildTina/git.ts
1158
- var import_fs_extra4 = __toModule(require("fs-extra"));
1159
- var import_ini = __toModule(require("ini"));
1160
- var import_os = __toModule(require("os"));
1161
- var import_path6 = __toModule(require("path"));
1162
- var resolveGitRoot = async () => {
1163
- const pathParts = process.cwd().split(import_path6.default.sep);
1164
- while (true) {
1165
- const pathToGit = pathParts.join(import_path6.default.sep);
1166
- if (await import_fs_extra4.default.pathExists(import_path6.default.join(pathToGit, ".git"))) {
1167
- return pathToGit;
1168
- }
1169
- if (!pathParts.length) {
1170
- throw new Error("Unable to locate your .git folder (required for isomorphicGitBridge)");
1171
- }
1172
- pathParts.pop();
1173
- }
1174
- };
1175
- async function makeIsomorphicOptions(fsBridge) {
1176
- var _a, _b, _c, _d;
1177
- const gitRoot = await resolveGitRoot();
1178
- const options = {
1179
- gitRoot,
1180
- author: {
1181
- name: "",
1182
- email: ""
1183
- },
1184
- onPut: async (filepath, data) => {
1185
- await fsBridge.put(filepath, data);
1186
- },
1187
- onDelete: async (filepath) => {
1188
- await fsBridge.delete(filepath);
1189
- }
1190
- };
1191
- const userGitConfig = `${import_os.default.homedir()}${import_path6.default.sep}.gitconfig`;
1192
- if (await import_fs_extra4.default.pathExists(userGitConfig)) {
1193
- const config2 = import_ini.default.parse(await import_fs_extra4.default.readFile(userGitConfig, "utf-8"));
1194
- if ((_a = config2["user"]) == null ? void 0 : _a["name"]) {
1195
- options.author.name = config2["user"]["name"];
1196
- }
1197
- if ((_b = config2["user"]) == null ? void 0 : _b["email"]) {
1198
- options.author.email = config2["user"]["email"];
1199
- }
1200
- }
1201
- let repoGitConfig = void 0;
1202
- if (!options.author.name) {
1203
- repoGitConfig = import_ini.default.parse(await import_fs_extra4.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1204
- if ((_c = repoGitConfig["user"]) == null ? void 0 : _c["name"]) {
1205
- options.author.name = repoGitConfig["user"]["name"];
1206
- }
1207
- if (!options.author.name) {
1208
- throw new Error('Unable to determine user.name from git config. Hint: `git config --global user.name "John Doe"`');
1209
- }
1210
- }
1211
- if (!options.author.email) {
1212
- repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra4.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1213
- if ((_d = repoGitConfig["user"]) == null ? void 0 : _d["email"]) {
1214
- options.author.email = repoGitConfig["user"]["email"];
1215
- }
1216
- if (!options.author.email) {
1217
- throw new Error("Unable to determine user.email from git config. Hint: `git config --global user.email johndoe@example.com`");
1218
- }
1219
- }
1220
- return options;
1221
- }
1222
-
1223
1165
  // src/buildTina/index.ts
1224
1166
  var import_app = __toModule(require("@tinacms/app"));
1225
1167
 
@@ -1260,70 +1202,60 @@ function spin({
1260
1202
  }
1261
1203
 
1262
1204
  // src/buildTina/attachPath.ts
1263
- var import_fs_extra5 = __toModule(require("fs-extra"));
1264
- var import_path7 = __toModule(require("path"));
1205
+ var import_fs_extra4 = __toModule(require("fs-extra"));
1206
+ var import_path6 = __toModule(require("path"));
1265
1207
  var attachPath = async (ctx, next, options) => {
1266
1208
  ctx.rootPath = options.rootPath || process.cwd();
1267
1209
  ctx.usingTs = await isProjectTs(ctx.rootPath);
1268
1210
  next();
1269
1211
  };
1270
1212
  var isProjectTs = async (rootPath2) => {
1271
- const tinaPath = import_path7.default.join(rootPath2, ".tina");
1272
- return await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "schema.tsx")) || await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "config.ts")) || await (0, import_fs_extra5.pathExists)(import_path7.default.join(tinaPath, "config.tsx"));
1213
+ const tinaPath = import_path6.default.join(rootPath2, ".tina");
1214
+ return await (0, import_fs_extra4.pathExists)(import_path6.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra4.pathExists)(import_path6.default.join(tinaPath, "schema.tsx")) || await (0, import_fs_extra4.pathExists)(import_path6.default.join(tinaPath, "config.ts")) || await (0, import_fs_extra4.pathExists)(import_path6.default.join(tinaPath, "config.tsx"));
1273
1215
  };
1274
1216
 
1275
1217
  // src/buildTina/index.ts
1276
1218
  var buildSetupCmdBuild = async (ctx, next, opts) => {
1277
1219
  const rootPath2 = ctx.rootPath;
1278
- const { bridge, database } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
1279
- rootPath: rootPath2,
1280
- useMemoryStore: true
1220
+ await buildSetup(__spreadProps(__spreadValues({}, opts), {
1221
+ rootPath: rootPath2
1281
1222
  }));
1282
- ctx.bridge = bridge;
1283
- ctx.database = database;
1284
- ctx.builder = new ConfigBuilder(database);
1223
+ ctx.builder = new ConfigBuilder(ctx.database);
1285
1224
  next();
1286
1225
  };
1287
1226
  var buildSetupCmdServerStart = async (ctx, next, opts) => {
1288
1227
  const rootPath2 = ctx.rootPath;
1289
- const { bridge, database } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
1290
- rootPath: rootPath2,
1291
- useMemoryStore: false
1228
+ await buildSetup(__spreadProps(__spreadValues({}, opts), {
1229
+ rootPath: rootPath2
1292
1230
  }));
1293
- ctx.bridge = bridge;
1294
- ctx.database = database;
1295
- ctx.builder = new ConfigBuilder(database);
1231
+ ctx.builder = new ConfigBuilder(ctx.database);
1296
1232
  next();
1297
1233
  };
1298
1234
  var buildSetupCmdAudit = async (ctx, next, options) => {
1299
1235
  const rootPath2 = ctx.rootPath;
1300
1236
  const bridge = options.clean ? new import_datalayer.FilesystemBridge(rootPath2) : new import_datalayer.AuditFileSystemBridge(rootPath2);
1301
- await import_fs_extra6.default.ensureDirSync(import_path8.default.join(rootPath2, ".tina", "__generated__"));
1302
- const store = new import_datalayer.LevelStore(rootPath2, false);
1303
- const database = await (0, import_graphql9.createDatabase)({ store, bridge });
1237
+ await import_fs_extra5.default.ensureDirSync(import_path7.default.join(rootPath2, ".tina", "__generated__"));
1238
+ const database = await (0, import_graphql9.createDatabase)({
1239
+ level: new import_memory_level.MemoryLevel({
1240
+ valueEncoding: "json"
1241
+ }),
1242
+ bridge
1243
+ });
1304
1244
  ctx.bridge = bridge;
1305
1245
  ctx.database = database;
1306
- ctx.builder = new ConfigBuilder(database);
1246
+ ctx.builder = new ConfigBuilder(ctx.database);
1307
1247
  next();
1308
1248
  };
1309
- var buildSetup = async ({
1310
- isomorphicGitBridge: isomorphicGitBridge2,
1311
- rootPath: rootPath2,
1312
- useMemoryStore
1313
- }) => {
1314
- const fsBridge = new import_datalayer.FilesystemBridge(rootPath2);
1315
- const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
1316
- const bridge = isomorphicGitBridge2 ? new import_datalayer.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
1317
- await import_fs_extra6.default.ensureDirSync(import_path8.default.join(rootPath2, ".tina", "__generated__"));
1318
- const store = new import_datalayer.LevelStore(rootPath2, useMemoryStore);
1319
- const database = await (0, import_graphql9.createDatabase)({ store, bridge });
1320
- return { database, bridge, store };
1249
+ var buildSetup = async ({ rootPath: rootPath2 }) => {
1250
+ await import_fs_extra5.default.ensureDirSync(import_path7.default.join(rootPath2, ".tina", "__generated__"));
1321
1251
  };
1322
1252
  var buildCmdBuild = async (ctx, next, options) => {
1323
- const { schema } = await ctx.builder.build(__spreadValues({
1253
+ const { schema, graphQLSchema, tinaSchema } = await ctx.builder.build(__spreadValues({
1324
1254
  rootPath: ctx.rootPath
1325
1255
  }, options));
1326
1256
  ctx.schema = schema;
1257
+ ctx.graphQLSchema = graphQLSchema;
1258
+ ctx.tinaSchema = tinaSchema;
1327
1259
  const apiUrl = await ctx.builder.genTypedClient({
1328
1260
  compiledSchema: schema,
1329
1261
  local: options.local,
@@ -1356,6 +1288,19 @@ var auditCmdBuild = async (ctx, next, options) => {
1356
1288
  });
1357
1289
  next();
1358
1290
  };
1291
+ var indexIntoSelfHostedDatabase = async (ctx, next) => {
1292
+ if (!ctx.isSelfHostedDatabase) {
1293
+ return next();
1294
+ }
1295
+ const { graphQLSchema, tinaSchema } = ctx;
1296
+ await spin({
1297
+ waitFor: async () => {
1298
+ await ctx.database.indexContent({ graphQLSchema, tinaSchema });
1299
+ },
1300
+ text: "Indexing to self-hosted database"
1301
+ });
1302
+ next();
1303
+ };
1359
1304
  var ConfigBuilder = class {
1360
1305
  constructor(database) {
1361
1306
  this.database = database;
@@ -1366,16 +1311,14 @@ var ConfigBuilder = class {
1366
1311
  if (!rootPath2) {
1367
1312
  throw new Error("Root path has not been attached");
1368
1313
  }
1369
- const tinaGeneratedPath = import_path8.default.join(rootPath2, ".tina", "__generated__");
1314
+ const tinaGeneratedPath = import_path7.default.join(rootPath2, ".tina", "__generated__");
1370
1315
  this.database.clearCache();
1371
- await import_fs_extra6.default.mkdirp(tinaGeneratedPath);
1372
- await this.database.store.close();
1316
+ await import_fs_extra5.default.mkdirp(tinaGeneratedPath);
1373
1317
  await resetGeneratedFolder({
1374
1318
  tinaGeneratedPath,
1375
1319
  usingTs,
1376
1320
  isBuild: !local
1377
1321
  });
1378
- await this.database.store.open();
1379
1322
  const compiledSchema = await compileSchema({
1380
1323
  verbose,
1381
1324
  dev,
@@ -1387,14 +1330,14 @@ var ConfigBuilder = class {
1387
1330
  }
1388
1331
  let localContentPath = compiledSchema.config.localContentPath;
1389
1332
  if (!localContentPath.startsWith("/")) {
1390
- localContentPath = import_path8.default.join(process.cwd(), ".tina", localContentPath);
1333
+ localContentPath = import_path7.default.join(process.cwd(), ".tina", localContentPath);
1391
1334
  }
1392
- if (await import_fs_extra6.default.pathExists(localContentPath)) {
1335
+ if (await import_fs_extra5.default.pathExists(localContentPath)) {
1393
1336
  logger.info(logText(`Using separate content path ${localContentPath}`));
1394
1337
  } else {
1395
1338
  logger.warn(warnText(`Using separate content path ${localContentPath}
1396
1339
  but no directory was found at that location, creating one...`));
1397
- await import_fs_extra6.default.mkdir(localContentPath);
1340
+ await import_fs_extra5.default.mkdir(localContentPath);
1398
1341
  }
1399
1342
  this.database.bridge.addOutputPath(localContentPath);
1400
1343
  }
@@ -1585,7 +1528,7 @@ async function startServer(ctx, next, {
1585
1528
  await afterBuild();
1586
1529
  }
1587
1530
  };
1588
- const foldersToWatch = (watchFolders || []).map((x) => import_path11.default.join(rootPath2, x));
1531
+ const foldersToWatch = (watchFolders || []).map((x) => import_path10.default.join(rootPath2, x));
1589
1532
  if (!noWatch && !process.env.CI) {
1590
1533
  import_chokidar.default.watch([
1591
1534
  ...foldersToWatch,
@@ -1595,7 +1538,7 @@ async function startServer(ctx, next, {
1595
1538
  ignored: [
1596
1539
  "**/node_modules/**/*",
1597
1540
  "**/.next/**/*",
1598
- `${import_path11.default.resolve(rootPath2)}/.tina/__generated__/**/*`
1541
+ `${import_path10.default.resolve(rootPath2)}/.tina/__generated__/**/*`
1599
1542
  ]
1600
1543
  }).on("ready", async () => {
1601
1544
  if (verbose)
@@ -1651,7 +1594,7 @@ async function startServer(ctx, next, {
1651
1594
 
1652
1595
  // src/cmds/statusChecks/waitForIndexing.ts
1653
1596
  var import_progress = __toModule(require("progress"));
1654
- var import_url_pattern = __toModule(require("url-pattern"));
1597
+ var import_schema_tools = __toModule(require("@tinacms/schema-tools"));
1655
1598
  var POLLING_INTERVAL = 5e3;
1656
1599
  var STATUS_INPROGRESS = "inprogress";
1657
1600
  var STATUS_COMPLETE = "complete";
@@ -1664,7 +1607,10 @@ var IndexFailedError = class extends Error {
1664
1607
  };
1665
1608
  var waitForDB = async (ctx, next, options) => {
1666
1609
  const token = ctx.schema.config.token;
1667
- const { clientId, branch, isLocalClient, host } = parseURL(ctx.apiUrl);
1610
+ if (ctx.isSelfHostedDatabase) {
1611
+ return next();
1612
+ }
1613
+ const { clientId, branch, isLocalClient, host } = (0, import_schema_tools.parseURL)(ctx.apiUrl);
1668
1614
  if (isLocalClient) {
1669
1615
  return next();
1670
1616
  }
@@ -1717,32 +1663,6 @@ var waitForDB = async (ctx, next, options) => {
1717
1663
  waitFor: pollForStatus
1718
1664
  });
1719
1665
  };
1720
- var parseURL = (url) => {
1721
- if (url.includes("localhost")) {
1722
- return {
1723
- host: "localhost",
1724
- branch: null,
1725
- isLocalClient: true,
1726
- clientId: null
1727
- };
1728
- }
1729
- const params = new URL(url);
1730
- const pattern = new import_url_pattern.default("/content/:clientId/github/*", {
1731
- escapeChar: " "
1732
- });
1733
- const result = pattern.match(params.pathname);
1734
- const branch = result == null ? void 0 : result._;
1735
- const clientId = result == null ? void 0 : result.clientId;
1736
- if (!branch || !clientId) {
1737
- throw new Error(`Invalid URL format provided. Expected: https://content.tinajs.io/content/<ClientID>/github/<Branch> but but received ${url}`);
1738
- }
1739
- return {
1740
- host: params.host,
1741
- clientId,
1742
- branch,
1743
- isLocalClient: false
1744
- };
1745
- };
1746
1666
 
1747
1667
  // src/cmds/startSubprocess/index.ts
1748
1668
  var import_child_process = __toModule(require("child_process"));
@@ -1770,9 +1690,9 @@ stack: ${code.stack || "No stack was provided"}`);
1770
1690
  };
1771
1691
 
1772
1692
  // src/cmds/init/index.ts
1773
- var import_path14 = __toModule(require("path"));
1693
+ var import_path13 = __toModule(require("path"));
1774
1694
  var import_prettier = __toModule(require("prettier"));
1775
- var import_fs_extra10 = __toModule(require("fs-extra"));
1695
+ var import_fs_extra9 = __toModule(require("fs-extra"));
1776
1696
  var import_prompts2 = __toModule(require("prompts"));
1777
1697
  var import_metrics3 = __toModule(require("@tinacms/metrics"));
1778
1698
 
@@ -2114,8 +2034,8 @@ var configExamples = {
2114
2034
  };
2115
2035
 
2116
2036
  // src/cmds/forestry-migrate/util/index.ts
2117
- var import_fs_extra8 = __toModule(require("fs-extra"));
2118
- var import_path12 = __toModule(require("path"));
2037
+ var import_fs_extra7 = __toModule(require("fs-extra"));
2038
+ var import_path11 = __toModule(require("path"));
2119
2039
  var import_js_yaml = __toModule(require("js-yaml"));
2120
2040
  var import_zod = __toModule(require("zod"));
2121
2041
 
@@ -2398,10 +2318,10 @@ var transformForestryFieldsToTinaFields = ({
2398
2318
  return tinaFields;
2399
2319
  };
2400
2320
  var getFieldsFromTemplates = ({ tem, rootPath: rootPath2, skipBlocks = false }) => {
2401
- const templatePath = import_path12.default.join(rootPath2, ".forestry", "front_matter", "templates", `${tem}.yml`);
2321
+ const templatePath = import_path11.default.join(rootPath2, ".forestry", "front_matter", "templates", `${tem}.yml`);
2402
2322
  let templateString = "";
2403
2323
  try {
2404
- templateString = import_fs_extra8.default.readFileSync(templatePath).toString();
2324
+ templateString = import_fs_extra7.default.readFileSync(templatePath).toString();
2405
2325
  } catch {
2406
2326
  throw new Error(`Could not find template ${tem} at ${templatePath}
2407
2327
 
@@ -2422,8 +2342,8 @@ var parseTemplates = ({ val }) => {
2422
2342
  return template;
2423
2343
  };
2424
2344
  var hasForestryConfig = async ({ rootPath: rootPath2 }) => {
2425
- const forestryPath = import_path12.default.join(rootPath2, ".forestry", "settings.yml");
2426
- const exists = await import_fs_extra8.default.pathExists(forestryPath);
2345
+ const forestryPath = import_path11.default.join(rootPath2, ".forestry", "settings.yml");
2346
+ const exists = await import_fs_extra7.default.pathExists(forestryPath);
2427
2347
  return {
2428
2348
  path: forestryPath,
2429
2349
  exists
@@ -2435,8 +2355,8 @@ var parseSections = ({ val }) => {
2435
2355
  };
2436
2356
 
2437
2357
  // src/cmds/forestry-migrate/index.ts
2438
- var import_fs_extra9 = __toModule(require("fs-extra"));
2439
- var import_path13 = __toModule(require("path"));
2358
+ var import_fs_extra8 = __toModule(require("fs-extra"));
2359
+ var import_path12 = __toModule(require("path"));
2440
2360
  var import_js_yaml2 = __toModule(require("js-yaml"));
2441
2361
  var import_minimatch = __toModule(require("minimatch"));
2442
2362
  var import_graphql10 = __toModule(require("@tinacms/graphql"));
@@ -2453,7 +2373,7 @@ var stringifyLabel = (label) => {
2453
2373
  var generateAllCollections = async ({
2454
2374
  rootPath: rootPath2
2455
2375
  }) => {
2456
- const allTemplates = (await import_fs_extra9.default.readdir(import_path13.default.join(rootPath2, ".forestry", "front_matter", "templates"))).map((tem) => import_path13.default.basename(tem, ".yml"));
2376
+ const allTemplates = (await import_fs_extra8.default.readdir(import_path12.default.join(rootPath2, ".forestry", "front_matter", "templates"))).map((tem) => import_path12.default.basename(tem, ".yml"));
2457
2377
  const templateMap = new Map();
2458
2378
  const proms = allTemplates.map(async (tem) => {
2459
2379
  try {
@@ -2476,7 +2396,7 @@ var generateCollections = async ({
2476
2396
  rootPath: rootPath2
2477
2397
  }) => {
2478
2398
  const templateMap = await generateAllCollections({ rootPath: rootPath2 });
2479
- const forestryConfig = await import_fs_extra9.default.readFile(forestryPath);
2399
+ const forestryConfig = await import_fs_extra8.default.readFile(forestryPath);
2480
2400
  const forestryYaml = import_js_yaml2.default.load(forestryConfig.toString());
2481
2401
  const forestrySchema = parseSections({ val: forestryYaml });
2482
2402
  const collections = [];
@@ -2512,14 +2432,14 @@ var generateCollections = async ({
2512
2432
  });
2513
2433
  (_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
2514
2434
  try {
2515
- const filePath = import_path13.default.join(rootPath2, page);
2516
- const extname2 = import_path13.default.extname(filePath);
2517
- const fileContent = import_fs_extra9.default.readFileSync(filePath).toString();
2435
+ const filePath = import_path12.default.join(rootPath2, page);
2436
+ const extname2 = import_path12.default.extname(filePath);
2437
+ const fileContent = import_fs_extra8.default.readFileSync(filePath).toString();
2518
2438
  const content2 = (0, import_graphql10.parseFile)(fileContent, extname2, (yup) => yup.object({}));
2519
2439
  const newContent = __spreadValues({
2520
2440
  _template: stringifyLabel(tem)
2521
2441
  }, content2);
2522
- import_fs_extra9.default.writeFileSync(filePath, (0, import_graphql10.stringifyFile)(newContent, extname2, true));
2442
+ import_fs_extra8.default.writeFileSync(filePath, (0, import_graphql10.stringifyFile)(newContent, extname2, true));
2523
2443
  } catch (error) {
2524
2444
  console.log("Error updating file", page);
2525
2445
  }
@@ -2552,14 +2472,14 @@ var generateCollections = async ({
2552
2472
  fields.push(...additionalFields);
2553
2473
  (_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
2554
2474
  try {
2555
- const filePath = import_path13.default.join(rootPath2, page);
2556
- const extname2 = import_path13.default.extname(filePath);
2557
- const fileContent = import_fs_extra9.default.readFileSync(filePath).toString();
2475
+ const filePath = import_path12.default.join(rootPath2, page);
2476
+ const extname2 = import_path12.default.extname(filePath);
2477
+ const fileContent = import_fs_extra8.default.readFileSync(filePath).toString();
2558
2478
  const content2 = (0, import_graphql10.parseFile)(fileContent, extname2, (yup) => yup.object({}));
2559
2479
  const newContent = __spreadValues({
2560
2480
  _template: stringifyLabel(tem)
2561
2481
  }, content2);
2562
- import_fs_extra9.default.writeFileSync(filePath, (0, import_graphql10.stringifyFile)(newContent, extname2, true));
2482
+ import_fs_extra8.default.writeFileSync(filePath, (0, import_graphql10.stringifyFile)(newContent, extname2, true));
2563
2483
  } catch (error) {
2564
2484
  logger.log("Error updating file", page);
2565
2485
  }
@@ -2619,11 +2539,11 @@ async function initStaticTina(ctx, next, options) {
2619
2539
  hasForestryConfig: forestryPath.exists,
2620
2540
  noTelemetry: options.noTelemetry
2621
2541
  });
2622
- const hasPackageJSON = await import_fs_extra10.default.pathExistsSync("package.json");
2542
+ const hasPackageJSON = await import_fs_extra9.default.pathExistsSync("package.json");
2623
2543
  if (!hasPackageJSON) {
2624
2544
  await createPackageJSON();
2625
2545
  }
2626
- const hasGitignore = await import_fs_extra10.default.pathExistsSync(".gitignore");
2546
+ const hasGitignore = await import_fs_extra9.default.pathExistsSync(".gitignore");
2627
2547
  if (!hasGitignore) {
2628
2548
  await createGitignore({ baseDir });
2629
2549
  } else {
@@ -2787,22 +2707,22 @@ var createPackageJSON = async () => {
2787
2707
  };
2788
2708
  var createGitignore = async ({ baseDir }) => {
2789
2709
  logger.info(logText("No .gitignore found, creating one"));
2790
- await import_fs_extra10.default.outputFileSync(import_path14.default.join(baseDir, ".gitignore"), "node_modules");
2710
+ await import_fs_extra9.default.outputFileSync(import_path13.default.join(baseDir, ".gitignore"), "node_modules");
2791
2711
  };
2792
2712
  var checkGitignoreForNodeModules = async ({
2793
2713
  baseDir
2794
2714
  }) => {
2795
- const gitignoreContent = await import_fs_extra10.default.readFileSync(import_path14.default.join(baseDir, ".gitignore")).toString();
2715
+ const gitignoreContent = await import_fs_extra9.default.readFileSync(import_path13.default.join(baseDir, ".gitignore")).toString();
2796
2716
  return gitignoreContent.split("\n").some((item) => item === "node_modules");
2797
2717
  };
2798
2718
  var addNodeModulesToGitignore = async ({ baseDir }) => {
2799
2719
  logger.info(logText("Adding node_modules to .gitignore"));
2800
- const gitignoreContent = await import_fs_extra10.default.readFileSync(import_path14.default.join(baseDir, ".gitignore")).toString();
2720
+ const gitignoreContent = await import_fs_extra9.default.readFileSync(import_path13.default.join(baseDir, ".gitignore")).toString();
2801
2721
  const newGitignoreContent = [
2802
2722
  ...gitignoreContent.split("\n"),
2803
2723
  "node_modules"
2804
2724
  ].join("\n");
2805
- await import_fs_extra10.default.writeFileSync(import_path14.default.join(baseDir, ".gitignore"), newGitignoreContent);
2725
+ await import_fs_extra9.default.writeFileSync(import_path13.default.join(baseDir, ".gitignore"), newGitignoreContent);
2806
2726
  };
2807
2727
  var addDependencies = async (packageManager) => {
2808
2728
  logger.info(logText("Adding dependencies, this might take a moment..."));
@@ -2817,9 +2737,9 @@ var addDependencies = async (packageManager) => {
2817
2737
  };
2818
2738
  var addConfigFile = async (args) => {
2819
2739
  const { baseDir, usingTypescript } = args;
2820
- const configPath = import_path14.default.join(".tina", `config.${usingTypescript ? "ts" : "js"}`);
2821
- const fullConfigPath = import_path14.default.join(baseDir, configPath);
2822
- if (import_fs_extra10.default.pathExistsSync(fullConfigPath)) {
2740
+ const configPath = import_path13.default.join(".tina", `config.${usingTypescript ? "ts" : "js"}`);
2741
+ const fullConfigPath = import_path13.default.join(baseDir, configPath);
2742
+ if (import_fs_extra9.default.pathExistsSync(fullConfigPath)) {
2823
2743
  const override = await (0, import_prompts2.default)({
2824
2744
  name: "selection",
2825
2745
  type: "confirm",
@@ -2827,19 +2747,19 @@ var addConfigFile = async (args) => {
2827
2747
  });
2828
2748
  if (override["selection"]) {
2829
2749
  logger.info(logText(`Overriding file at ${configPath}.`));
2830
- await import_fs_extra10.default.outputFileSync(fullConfigPath, config(args));
2750
+ await import_fs_extra9.default.outputFileSync(fullConfigPath, config(args));
2831
2751
  } else {
2832
2752
  logger.info(logText(`Not overriding file at ${configPath}.`));
2833
2753
  }
2834
2754
  } else {
2835
2755
  logger.info(logText(`Adding config file at .tina/config.${usingTypescript ? "ts" : "js"}`));
2836
- await import_fs_extra10.default.outputFileSync(fullConfigPath, config(args));
2756
+ await import_fs_extra9.default.outputFileSync(fullConfigPath, config(args));
2837
2757
  }
2838
2758
  };
2839
2759
  var addContentFile = async ({ baseDir }) => {
2840
- const contentPath = import_path14.default.join("content", "posts", "hello-world.md");
2841
- const fullContentPath = import_path14.default.join(baseDir, contentPath);
2842
- if (import_fs_extra10.default.pathExistsSync(fullContentPath)) {
2760
+ const contentPath = import_path13.default.join("content", "posts", "hello-world.md");
2761
+ const fullContentPath = import_path13.default.join(baseDir, contentPath);
2762
+ if (import_fs_extra9.default.pathExistsSync(fullContentPath)) {
2843
2763
  const override = await (0, import_prompts2.default)({
2844
2764
  name: "selection",
2845
2765
  type: "confirm",
@@ -2847,13 +2767,13 @@ var addContentFile = async ({ baseDir }) => {
2847
2767
  });
2848
2768
  if (override["selection"]) {
2849
2769
  logger.info(logText(`Overriding file at ${contentPath}.`));
2850
- await import_fs_extra10.default.outputFileSync(fullContentPath, content);
2770
+ await import_fs_extra9.default.outputFileSync(fullContentPath, content);
2851
2771
  } else {
2852
2772
  logger.info(logText(`Not overriding file at ${contentPath}.`));
2853
2773
  }
2854
2774
  } else {
2855
2775
  logger.info(logText(`Adding content file at ${contentPath}`));
2856
- await import_fs_extra10.default.outputFileSync(fullContentPath, content);
2776
+ await import_fs_extra9.default.outputFileSync(fullContentPath, content);
2857
2777
  }
2858
2778
  };
2859
2779
  var logNextSteps = ({
@@ -2907,22 +2827,22 @@ var addReactiveFile = {
2907
2827
  baseDir,
2908
2828
  usingTypescript
2909
2829
  }) => {
2910
- const usingSrc = !import_fs_extra10.default.pathExistsSync(import_path14.default.join(baseDir, "pages"));
2911
- const pagesPath = import_path14.default.join(baseDir, usingSrc ? "src" : "", "pages");
2912
- const packageJSONPath = import_path14.default.join(baseDir, "package.json");
2913
- const tinaBlogPagePath = import_path14.default.join(pagesPath, "demo", "blog");
2914
- const tinaBlogPagePathFile = import_path14.default.join(tinaBlogPagePath, `[filename].${usingTypescript ? "tsx" : "js"}`);
2915
- if (!import_fs_extra10.default.pathExistsSync(tinaBlogPagePathFile)) {
2916
- import_fs_extra10.default.mkdirpSync(tinaBlogPagePath);
2917
- import_fs_extra10.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
2830
+ const usingSrc = !import_fs_extra9.default.pathExistsSync(import_path13.default.join(baseDir, "pages"));
2831
+ const pagesPath = import_path13.default.join(baseDir, usingSrc ? "src" : "", "pages");
2832
+ const packageJSONPath = import_path13.default.join(baseDir, "package.json");
2833
+ const tinaBlogPagePath = import_path13.default.join(pagesPath, "demo", "blog");
2834
+ const tinaBlogPagePathFile = import_path13.default.join(tinaBlogPagePath, `[filename].${usingTypescript ? "tsx" : "js"}`);
2835
+ if (!import_fs_extra9.default.pathExistsSync(tinaBlogPagePathFile)) {
2836
+ import_fs_extra9.default.mkdirpSync(tinaBlogPagePath);
2837
+ import_fs_extra9.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
2918
2838
  }
2919
2839
  logger.info("Adding a nextjs example... \u2705");
2920
- const pack = JSON.parse(import_fs_extra10.default.readFileSync(packageJSONPath).toString());
2840
+ const pack = JSON.parse(import_fs_extra9.default.readFileSync(packageJSONPath).toString());
2921
2841
  const oldScripts = pack.scripts || {};
2922
2842
  const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
2923
2843
  scripts: extendNextScripts(oldScripts)
2924
2844
  }), null, 2);
2925
- import_fs_extra10.default.writeFileSync(packageJSONPath, newPack);
2845
+ import_fs_extra9.default.writeFileSync(packageJSONPath, newPack);
2926
2846
  }
2927
2847
  };
2928
2848
  function execShellCommand(cmd) {
@@ -2937,8 +2857,142 @@ function execShellCommand(cmd) {
2937
2857
  });
2938
2858
  }
2939
2859
 
2860
+ // src/buildTina/attachDatabase.ts
2861
+ var path11 = __toModule(require("path"));
2862
+ var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
2863
+ var import_graphql11 = __toModule(require("@tinacms/graphql"));
2864
+ var import_fs_extra11 = __toModule(require("fs-extra"));
2865
+
2866
+ // src/buildTina/git.ts
2867
+ var import_fs_extra10 = __toModule(require("fs-extra"));
2868
+ var import_ini = __toModule(require("ini"));
2869
+ var import_os = __toModule(require("os"));
2870
+ var import_path14 = __toModule(require("path"));
2871
+ var resolveGitRoot = async () => {
2872
+ const pathParts = process.cwd().split(import_path14.default.sep);
2873
+ while (true) {
2874
+ const pathToGit = pathParts.join(import_path14.default.sep);
2875
+ if (await import_fs_extra10.default.pathExists(import_path14.default.join(pathToGit, ".git"))) {
2876
+ return pathToGit;
2877
+ }
2878
+ if (!pathParts.length) {
2879
+ throw new Error("Unable to locate your .git folder (required for isomorphicGitBridge)");
2880
+ }
2881
+ pathParts.pop();
2882
+ }
2883
+ };
2884
+ async function makeIsomorphicOptions(fsBridge) {
2885
+ var _a, _b, _c, _d;
2886
+ const gitRoot = await resolveGitRoot();
2887
+ const options = {
2888
+ gitRoot,
2889
+ author: {
2890
+ name: "",
2891
+ email: ""
2892
+ },
2893
+ onPut: async (filepath, data) => {
2894
+ await fsBridge.put(filepath, data);
2895
+ },
2896
+ onDelete: async (filepath) => {
2897
+ await fsBridge.delete(filepath);
2898
+ }
2899
+ };
2900
+ const userGitConfig = `${import_os.default.homedir()}${import_path14.default.sep}.gitconfig`;
2901
+ if (await import_fs_extra10.default.pathExists(userGitConfig)) {
2902
+ const config2 = import_ini.default.parse(await import_fs_extra10.default.readFile(userGitConfig, "utf-8"));
2903
+ if ((_a = config2["user"]) == null ? void 0 : _a["name"]) {
2904
+ options.author.name = config2["user"]["name"];
2905
+ }
2906
+ if ((_b = config2["user"]) == null ? void 0 : _b["email"]) {
2907
+ options.author.email = config2["user"]["email"];
2908
+ }
2909
+ }
2910
+ let repoGitConfig = void 0;
2911
+ if (!options.author.name) {
2912
+ repoGitConfig = import_ini.default.parse(await import_fs_extra10.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
2913
+ if ((_c = repoGitConfig["user"]) == null ? void 0 : _c["name"]) {
2914
+ options.author.name = repoGitConfig["user"]["name"];
2915
+ }
2916
+ if (!options.author.name) {
2917
+ throw new Error('Unable to determine user.name from git config. Hint: `git config --global user.name "John Doe"`');
2918
+ }
2919
+ }
2920
+ if (!options.author.email) {
2921
+ repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra10.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
2922
+ if ((_d = repoGitConfig["user"]) == null ? void 0 : _d["email"]) {
2923
+ options.author.email = repoGitConfig["user"]["email"];
2924
+ }
2925
+ if (!options.author.email) {
2926
+ throw new Error("Unable to determine user.email from git config. Hint: `git config --global user.email johndoe@example.com`");
2927
+ }
2928
+ }
2929
+ return options;
2930
+ }
2931
+
2932
+ // src/buildTina/attachDatabase.ts
2933
+ var import_memory_level2 = __toModule(require("memory-level"));
2934
+ var import_many_level = __toModule(require("many-level"));
2935
+ var import_readable_stream = __toModule(require("readable-stream"));
2936
+ var import_net = __toModule(require("net"));
2937
+ var attachDatabase = async (ctx, next, _options) => {
2938
+ const tinaPath = path11.join(ctx.rootPath, ".tina");
2939
+ const tinaGeneratedPath = path11.join(tinaPath, "__generated__");
2940
+ const tinaTempPath = path11.join(tinaGeneratedPath, `temp_database`);
2941
+ const define = {};
2942
+ if (!process.env.NODE_ENV) {
2943
+ define["process.env.NODE_ENV"] = _options.dev ? '"development"' : '"production"';
2944
+ }
2945
+ const inputFile = getPath({
2946
+ projectDir: path11.join(ctx.rootPath, ".tina"),
2947
+ filename: "database",
2948
+ allowedTypes: ["js", "jsx", "tsx", "ts"]
2949
+ });
2950
+ const fsBridge = new import_datalayer2.FilesystemBridge(ctx.rootPath);
2951
+ const levelHost = new import_many_level.ManyLevelHost(new import_memory_level2.MemoryLevel({
2952
+ valueEncoding: "json"
2953
+ }));
2954
+ const server = (0, import_net.createServer)(function(socket) {
2955
+ (0, import_readable_stream.pipeline)(socket, levelHost.createRpcStream(), socket, () => {
2956
+ });
2957
+ });
2958
+ server.listen(9e3);
2959
+ ctx.dbServer = server;
2960
+ if (inputFile) {
2961
+ try {
2962
+ await transpile(inputFile, "database.cjs", tinaTempPath, _options.verbose, define, path11.join(ctx.rootPath, "package.json"), "node");
2963
+ } catch (e) {
2964
+ await import_fs_extra11.default.remove(tinaTempPath);
2965
+ throw new BuildSchemaError(e);
2966
+ }
2967
+ Object.keys(require.cache).map((key) => {
2968
+ if (key.startsWith(tinaTempPath)) {
2969
+ delete require.cache[require.resolve(key)];
2970
+ }
2971
+ });
2972
+ try {
2973
+ const databaseFunc = require(path11.join(tinaTempPath, `database.cjs`));
2974
+ ctx.database = databaseFunc.default;
2975
+ ctx.database.bridge = fsBridge;
2976
+ ctx.bridge = ctx.database.bridge;
2977
+ ctx.isSelfHostedDatabase = true;
2978
+ await import_fs_extra11.default.remove(tinaTempPath);
2979
+ } catch (e) {
2980
+ await import_fs_extra11.default.remove(tinaTempPath);
2981
+ throw e;
2982
+ }
2983
+ } else {
2984
+ const bridge = _options.isomorphicGitBridge ? new import_datalayer2.IsomorphicBridge(ctx.rootPath, _options.isomorphicGitBridge && await makeIsomorphicOptions(fsBridge)) : fsBridge;
2985
+ const level = new import_graphql11.TinaLevelClient();
2986
+ level.openConnection();
2987
+ ctx.database = await (0, import_graphql11.createDatabase)({ level, bridge });
2988
+ ctx.bridge = bridge;
2989
+ }
2990
+ next();
2991
+ };
2992
+
2940
2993
  // src/cmds/statusChecks/checkClientInformation.ts
2941
2994
  var import_progress2 = __toModule(require("progress"));
2995
+ var import_schema_tools2 = __toModule(require("@tinacms/schema-tools"));
2942
2996
  async function request(args) {
2943
2997
  const headers = new Headers();
2944
2998
  if (args.token) {
@@ -2977,9 +3031,12 @@ Message from server: ${json.message}`;
2977
3031
  }
2978
3032
  var checkClientInfo = async (ctx, next, _options) => {
2979
3033
  var _a;
3034
+ if (ctx.isSelfHostedDatabase) {
3035
+ return next();
3036
+ }
2980
3037
  const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
2981
3038
  const token = config2.token;
2982
- const { clientId, branch, host } = parseURL(ctx.apiUrl);
3039
+ const { clientId, branch, host } = (0, import_schema_tools2.parseURL)(ctx.apiUrl);
2983
3040
  const url = `https://${host}/db/${clientId}/status/${branch}`;
2984
3041
  const bar = new import_progress2.default("Checking clientId, token and branch. :prog", 1);
2985
3042
  try {
@@ -3101,6 +3158,7 @@ var baseCmds = [
3101
3158
  ],
3102
3159
  action: (options) => chain([
3103
3160
  attachPath,
3161
+ attachDatabase,
3104
3162
  async (ctx, next, _2) => {
3105
3163
  logger.warn(warnText("server:start will be deprecated in the future, please use `tinacms dev` instead"));
3106
3164
  next();
@@ -3127,6 +3185,7 @@ var baseCmds = [
3127
3185
  ],
3128
3186
  action: (options) => chain([
3129
3187
  attachPath,
3188
+ attachDatabase,
3130
3189
  checkOptions,
3131
3190
  buildSetupCmdServerStart,
3132
3191
  startServer,
@@ -3148,11 +3207,13 @@ var baseCmds = [
3148
3207
  ],
3149
3208
  action: (options) => chain([
3150
3209
  attachPath,
3210
+ attachDatabase,
3151
3211
  checkOptions,
3152
3212
  buildSetupCmdBuild,
3153
3213
  buildCmdBuild,
3154
3214
  checkClientInfo,
3155
- waitForDB
3215
+ waitForDB,
3216
+ indexIntoSelfHostedDatabase
3156
3217
  ], options)
3157
3218
  },
3158
3219
  {