@tinacms/cli 0.60.23 → 0.60.26

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/dist/index.js CHANGED
@@ -37,9 +37,6 @@ 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
- };
43
40
  var __export = (target, all) => {
44
41
  __markAsModule(target);
45
42
  for (var name2 in all)
@@ -57,127 +54,10 @@ var __toModule = (module2) => {
57
54
  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);
58
55
  };
59
56
 
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
-
177
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/index.ts
57
+ // src/utils/index.ts
178
58
  var parseMediaFolder;
179
59
  var init_utils = __esm({
180
- "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/index.ts"() {
60
+ "src/utils/index.ts"() {
181
61
  parseMediaFolder = (str) => {
182
62
  let returnString = str;
183
63
  if (returnString.startsWith("/"))
@@ -189,44 +69,69 @@ var init_utils = __esm({
189
69
  }
190
70
  });
191
71
 
192
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/models/media.ts
72
+ // src/server/models/media.ts
193
73
  var import_fs_extra5, import_path6, MediaModel;
194
74
  var init_media = __esm({
195
- "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/models/media.ts"() {
75
+ "src/server/models/media.ts"() {
196
76
  import_fs_extra5 = __toModule(require("fs-extra"));
197
77
  import_path6 = __toModule(require("path"));
198
78
  init_utils();
199
79
  MediaModel = class {
200
- constructor({ publicFolder, syncFolder }) {
201
- this.syncFolder = syncFolder;
80
+ constructor({ publicFolder, mediaRoot }) {
81
+ this.mediaRoot = mediaRoot;
202
82
  this.publicFolder = publicFolder;
203
83
  }
204
84
  async listMedia(args) {
205
85
  try {
206
- const folderPath = (0, import_path6.join)(this.publicFolder, this.syncFolder, args.searchPath);
86
+ const folderPath = (0, import_path6.join)(this.publicFolder, this.mediaRoot, args.searchPath);
207
87
  const searchPath = parseMediaFolder(args.searchPath);
208
88
  const filesStr = await import_fs_extra5.default.readdir(folderPath);
209
89
  const filesProm = filesStr.map(async (file) => {
210
90
  const filePath = (0, import_path6.join)(folderPath, file);
211
91
  const stat = await import_fs_extra5.default.stat(filePath);
212
92
  let src = `/${file}`;
93
+ const isFile = stat.isFile();
94
+ if (!isFile) {
95
+ return {
96
+ isFile,
97
+ size: stat.size,
98
+ src,
99
+ filename: file
100
+ };
101
+ }
213
102
  if (searchPath) {
214
103
  src = `/${searchPath}${src}`;
215
104
  }
216
- if (this.syncFolder) {
217
- src = `/${this.syncFolder}${src}`;
105
+ if (this.mediaRoot) {
106
+ src = `/${this.mediaRoot}${src}`;
218
107
  }
219
108
  return {
109
+ isFile,
220
110
  size: stat.size,
221
- fileName: file,
222
111
  src,
223
- isFile: stat.isFile()
112
+ filename: file
224
113
  };
225
114
  });
226
- const files = await Promise.all(filesProm);
115
+ const offset = Number(args.cursor) || 0;
116
+ const limit = Number(args.limit) || 20;
117
+ const rawItems = await Promise.all(filesProm);
118
+ const sortedItems = rawItems.sort((a, b) => {
119
+ if (a.isFile && !b.isFile) {
120
+ return 1;
121
+ }
122
+ if (!a.isFile && b.isFile) {
123
+ return -1;
124
+ }
125
+ return 0;
126
+ });
127
+ const limitItems = sortedItems.slice(offset, offset + limit);
128
+ const files = limitItems.filter((x) => x.isFile);
129
+ const directories = limitItems.filter((x) => !x.isFile).map((x) => x.src);
130
+ const cursor = rawItems.length > offset + limit ? String(offset + limit) : null;
227
131
  return {
228
- files: files.filter((x) => x.isFile),
229
- directories: files.filter((x) => !x.isFile).map((x) => x.src)
132
+ files,
133
+ directories,
134
+ cursor
230
135
  };
231
136
  } catch (error) {
232
137
  console.error(error);
@@ -239,7 +144,7 @@ var init_media = __esm({
239
144
  }
240
145
  async deleteMedia(args) {
241
146
  try {
242
- const file = (0, import_path6.join)(this.publicFolder, this.syncFolder, args.searchPath);
147
+ const file = (0, import_path6.join)(this.publicFolder, this.mediaRoot, args.searchPath);
243
148
  await import_fs_extra5.default.stat(file);
244
149
  await import_fs_extra5.default.remove(file);
245
150
  return { ok: true };
@@ -252,16 +157,16 @@ var init_media = __esm({
252
157
  }
253
158
  });
254
159
 
255
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/routes/index.ts
160
+ // src/server/routes/index.ts
256
161
  var import_express, import_path7, import_multer, createMediaRouter;
257
162
  var init_routes = __esm({
258
- "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/routes/index.ts"() {
163
+ "src/server/routes/index.ts"() {
259
164
  import_express = __toModule(require("express"));
260
165
  import_path7 = __toModule(require("path"));
261
166
  import_multer = __toModule(require("multer"));
262
167
  init_media();
263
168
  createMediaRouter = (config) => {
264
- const mediaFolder = (0, import_path7.join)(process.cwd(), config.publicFolder, config.syncFolder);
169
+ const mediaFolder = (0, import_path7.join)(process.cwd(), config.publicFolder, config.mediaRoot);
265
170
  const storage = import_multer.default.diskStorage({
266
171
  destination: function(req, file, cb) {
267
172
  cb(null, mediaFolder);
@@ -276,28 +181,32 @@ var init_routes = __esm({
276
181
  const mediaRouter = (0, import_express.Router)();
277
182
  mediaRouter.get("/list/*", async (req, res) => {
278
183
  const folder = req.params[0];
184
+ const cursor = req.query.cursor;
185
+ const limit = req.query.limit;
279
186
  const media = await mediaModel.listMedia({
280
- searchPath: folder
187
+ searchPath: folder,
188
+ cursor,
189
+ limit
281
190
  });
282
191
  res.json(media);
283
192
  });
284
- mediaRouter.delete("/delete/*", async (req, res) => {
193
+ mediaRouter.delete("/*", async (req, res) => {
285
194
  const file = req.params[0];
286
195
  const didDelete = await mediaModel.deleteMedia({ searchPath: file });
287
196
  res.json(didDelete);
288
197
  });
289
- mediaRouter.post("/upload/*", upload.single("file"), function(req, res, next) {
290
- res.json({ ok: true });
198
+ mediaRouter.post("/upload/*", upload.single("file"), function(req, res) {
199
+ res.json({ success: true });
291
200
  });
292
201
  return mediaRouter;
293
202
  };
294
203
  }
295
204
  });
296
205
 
297
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/server.ts
206
+ // src/server/server.ts
298
207
  var import_cors, import_http, import_express2, import_altair_express_middleware, import_body_parser, gqlServer;
299
208
  var init_server = __esm({
300
- "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/server.ts"() {
209
+ "src/server/server.ts"() {
301
210
  import_cors = __toModule(require("cors"));
302
211
  import_http = __toModule(require("http"));
303
212
  import_express2 = __toModule(require("express"));
@@ -348,49 +257,49 @@ var init_server = __esm({
348
257
  const mediaPaths = ((_c = (_b = (_a = schema == null ? void 0 : schema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.media) == null ? void 0 : _c.tina) || {};
349
258
  app.use("/media", createMediaRouter({
350
259
  publicFolder: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.publicFolder) || ""),
351
- syncFolder: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.syncFolder) || "")
260
+ mediaRoot: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.mediaRoot) || "")
352
261
  }));
353
262
  return server;
354
263
  };
355
264
  }
356
265
  });
357
266
 
358
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/index.ts
267
+ // src/server/index.ts
359
268
  var init_server2 = __esm({
360
- "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/server/index.ts"() {
269
+ "src/server/index.ts"() {
361
270
  init_server();
362
271
  }
363
272
  });
364
273
 
365
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/server.ts
274
+ // src/cmds/start-server/server.ts
366
275
  var server_exports = {};
367
276
  __export(server_exports, {
368
277
  default: () => server_default
369
278
  });
370
279
  var server_default;
371
280
  var init_server3 = __esm({
372
- "pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/server.ts"() {
281
+ "src/cmds/start-server/server.ts"() {
373
282
  init_server2();
374
283
  server_default = gqlServer;
375
284
  }
376
285
  });
377
286
 
378
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/index.ts
287
+ // src/index.ts
379
288
  __export(exports, {
380
289
  defineSchema: () => defineSchema,
381
290
  init: () => init
382
291
  });
383
292
  var commander = __toModule(require("commander"));
384
293
 
385
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/package.json
294
+ // package.json
386
295
  var name = "@tinacms/cli";
387
- var version = "0.60.23";
296
+ var version = "0.60.26";
388
297
 
389
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
298
+ // src/cmds/query-gen/attachSchema.ts
390
299
  var import_graphql = __toModule(require("@tinacms/graphql"));
391
300
  var import_datalayer = __toModule(require("@tinacms/datalayer"));
392
301
 
393
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/theme.ts
302
+ // src/utils/theme.ts
394
303
  var import_chalk = __toModule(require("chalk"));
395
304
  var successText = import_chalk.default.bold.green;
396
305
  var dangerText = import_chalk.default.bold.red;
@@ -401,7 +310,7 @@ var logText = import_chalk.default.italic.gray;
401
310
  var warnText = import_chalk.default.yellowBright.bgBlack;
402
311
  var CONFIRMATION_TEXT = import_chalk.default.dim("enter to confirm");
403
312
 
404
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/logger/index.ts
313
+ // src/logger/index.ts
405
314
  var import_log4js = __toModule(require("log4js"));
406
315
  var logger = import_log4js.default.getLogger();
407
316
  import_log4js.default.configure({
@@ -412,7 +321,7 @@ import_log4js.default.configure({
412
321
  });
413
322
  logger.level = "info";
414
323
 
415
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
324
+ // src/cmds/query-gen/attachSchema.ts
416
325
  async function attachSchema(ctx, next, options) {
417
326
  logger.info(logText("Building schema..."));
418
327
  const rootPath2 = process.cwd();
@@ -424,14 +333,14 @@ async function attachSchema(ctx, next, options) {
424
333
  next();
425
334
  }
426
335
 
427
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
336
+ // src/cmds/query-gen/genTypes.ts
428
337
  var import_graphql6 = __toModule(require("graphql"));
429
338
  var import_fs_extra = __toModule(require("fs-extra"));
430
339
 
431
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
340
+ // src/codegen/index.ts
432
341
  var import_graphql5 = __toModule(require("graphql"));
433
342
 
434
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/plugin.ts
343
+ // src/codegen/plugin.ts
435
344
  var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
436
345
  return `
437
346
  // TinaSDK generated code
@@ -480,19 +389,19 @@ var AddGeneratedClient = {
480
389
  plugin: AddGeneratedClientFunc
481
390
  };
482
391
 
483
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
392
+ // src/codegen/index.ts
484
393
  var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
485
394
  var import_core = __toModule(require("@graphql-codegen/core"));
486
395
  var import_load = __toModule(require("@graphql-tools/load"));
487
396
  var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
488
397
  var import_typescript = __toModule(require("@graphql-codegen/typescript"));
489
398
 
490
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
399
+ // src/codegen/sdkPlugin/index.ts
491
400
  var import_graphql3 = __toModule(require("graphql"));
492
401
  var import_graphql4 = __toModule(require("graphql"));
493
402
  var import_path = __toModule(require("path"));
494
403
 
495
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/visitor.ts
404
+ // src/codegen/sdkPlugin/visitor.ts
496
405
  var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
497
406
  var import_auto_bind = __toModule(require("auto-bind"));
498
407
  var import_graphql2 = __toModule(require("graphql"));
@@ -542,7 +451,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
542
451
  }
543
452
  };
544
453
 
545
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
454
+ // src/codegen/sdkPlugin/index.ts
546
455
  var plugin = (schema, documents, config) => {
547
456
  const allAst = (0, import_graphql4.concatAST)(documents.reduce((prev, v) => {
548
457
  return [...prev, v.document];
@@ -567,7 +476,7 @@ var plugin = (schema, documents, config) => {
567
476
  };
568
477
  };
569
478
 
570
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
479
+ // src/codegen/index.ts
571
480
  var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = {
572
481
  noSDK: false,
573
482
  verbose: false
@@ -634,7 +543,7 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
634
543
  }
635
544
  };
636
545
 
637
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
546
+ // src/cmds/query-gen/genTypes.ts
638
547
  async function genTypes({ schema }, next, options) {
639
548
  const typesPath = process.cwd() + "/.tina/__generated__/types.ts";
640
549
  const fragPath = process.cwd() + "/.tina/__generated__/*.{graphql,gql}";
@@ -666,11 +575,11 @@ schema {
666
575
  next();
667
576
  }
668
577
 
669
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
578
+ // src/cmds/audit/index.ts
670
579
  var import_graphql9 = __toModule(require("@tinacms/graphql"));
671
580
  var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
672
581
 
673
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/audit.ts
582
+ // src/cmds/audit/audit.ts
674
583
  var import_graphql7 = __toModule(require("@tinacms/graphql"));
675
584
  var import_path2 = __toModule(require("path"));
676
585
  var import_graphql8 = __toModule(require("@tinacms/graphql"));
@@ -845,7 +754,7 @@ function filterObject(obj) {
845
754
  return ret;
846
755
  }
847
756
 
848
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
757
+ // src/cmds/audit/index.ts
849
758
  var import_chalk3 = __toModule(require("chalk"));
850
759
  var import_prompts = __toModule(require("prompts"));
851
760
  var import_metrics = __toModule(require("@tinacms/metrics"));
@@ -915,7 +824,7 @@ var printFinalMessage = async (ctx, next, _options) => {
915
824
  next();
916
825
  };
917
826
 
918
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
827
+ // src/cmds/init/setup-files/index.ts
919
828
  var import_chalk4 = __toModule(require("chalk"));
920
829
  var adminPage = `import { TinaAdmin } from 'tinacms';
921
830
  export default TinaAdmin;
@@ -1261,7 +1170,7 @@ export default App
1261
1170
  `;
1262
1171
  };
1263
1172
 
1264
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/tinaProvider.ts
1173
+ // src/cmds/init/setup-files/tinaProvider.ts
1265
1174
  var TinaProvider = `import TinaCMS from 'tinacms'
1266
1175
  import { tinaConfig } from '../schema.ts'
1267
1176
 
@@ -1294,7 +1203,7 @@ const DynamicTina = ({ children }) => {
1294
1203
  export default DynamicTina
1295
1204
  `;
1296
1205
 
1297
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/script-helpers.ts
1206
+ // src/utils/script-helpers.ts
1298
1207
  function generateGqlScript(scriptValue) {
1299
1208
  return `tinacms server:start -c "${scriptValue}"`;
1300
1209
  }
@@ -1306,7 +1215,7 @@ function extendNextScripts(scripts) {
1306
1215
  });
1307
1216
  }
1308
1217
 
1309
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
1218
+ // src/cmds/init/index.ts
1310
1219
  var import_fs_extra2 = __toModule(require("fs-extra"));
1311
1220
  var import_progress = __toModule(require("progress"));
1312
1221
  var import_metrics2 = __toModule(require("@tinacms/metrics"));
@@ -1496,12 +1405,10 @@ async function successMessage(ctx, next, options) {
1496
1405
  next();
1497
1406
  }
1498
1407
 
1499
- // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/dotenv-npm-16.0.1-d99e72bb95-e97e94476c.zip/node_modules/dotenv/config.js
1500
- (function() {
1501
- require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
1502
- })();
1408
+ // src/cmds/baseCmds.ts
1409
+ var import_config = __toModule(require("dotenv/config"));
1503
1410
 
1504
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
1411
+ // src/middleware.ts
1505
1412
  var chain = async (cmds, options) => {
1506
1413
  const ctx = {};
1507
1414
  const next = async (middlewareIndex) => {
@@ -1520,10 +1427,10 @@ var chain = async (cmds, options) => {
1520
1427
  }
1521
1428
  };
1522
1429
 
1523
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
1430
+ // src/cmds/baseCmds.ts
1524
1431
  var import_chalk7 = __toModule(require("chalk"));
1525
1432
 
1526
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/errors/index.ts
1433
+ // src/cmds/start-server/errors/index.ts
1527
1434
  var import_graphql10 = __toModule(require("@tinacms/graphql"));
1528
1435
  var BuildSchemaError = class extends Error {
1529
1436
  constructor(message) {
@@ -1558,12 +1465,12 @@ var handleServerErrors = (e) => {
1558
1465
  }
1559
1466
  };
1560
1467
 
1561
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
1468
+ // src/cmds/compile/index.ts
1562
1469
  var import_fs_extra4 = __toModule(require("fs-extra"));
1563
1470
  var import_path5 = __toModule(require("path"));
1564
1471
  var import_esbuild = __toModule(require("esbuild"));
1565
1472
 
1566
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
1473
+ // src/cmds/compile/defaultSchema.ts
1567
1474
  var defaultSchema = `
1568
1475
  import { defineSchema, defineConfig } from "tinacms";
1569
1476
 
@@ -1651,7 +1558,7 @@ export const tinaConfig = defineConfig({
1651
1558
  });
1652
1559
  `;
1653
1560
 
1654
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getPath.ts
1561
+ // src/lib/getPath.ts
1655
1562
  var import_path4 = __toModule(require("path"));
1656
1563
  var import_fs_extra3 = __toModule(require("fs-extra"));
1657
1564
  var getPath = ({
@@ -1690,14 +1597,14 @@ var getClientPath = ({ projectDir }) => {
1690
1597
  return getPath({ projectDir, filename, allowedTypes, errorMessage });
1691
1598
  };
1692
1599
 
1693
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
1600
+ // src/cmds/compile/index.ts
1694
1601
  var tinaPath = import_path5.default.join(process.cwd(), ".tina");
1695
1602
  var packageJSONFilePath = import_path5.default.join(process.cwd(), "package.json");
1696
1603
  var tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
1697
1604
  var tinaConfigPath = import_path5.default.join(tinaGeneratedPath, "config");
1698
1605
  var resetGeneratedFolder = async () => {
1699
1606
  try {
1700
- await import_fs_extra4.default.rmdir(tinaGeneratedPath, {
1607
+ await import_fs_extra4.default.rm(tinaGeneratedPath, {
1701
1608
  recursive: true
1702
1609
  });
1703
1610
  } catch (e) {
@@ -1884,11 +1791,11 @@ var loaders = {
1884
1791
  ".tsx": "tsx"
1885
1792
  };
1886
1793
 
1887
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
1794
+ // src/cmds/start-server/index.ts
1888
1795
  var import_datalayer3 = __toModule(require("@tinacms/datalayer"));
1889
1796
  var import_graphql11 = __toModule(require("@tinacms/graphql"));
1890
1797
 
1891
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/lock.ts
1798
+ // src/cmds/start-server/lock.ts
1892
1799
  var AsyncLock = class {
1893
1800
  constructor() {
1894
1801
  this.disable = () => {
@@ -1900,24 +1807,90 @@ var AsyncLock = class {
1900
1807
  }
1901
1808
  };
1902
1809
 
1903
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
1810
+ // src/cmds/start-server/index.ts
1904
1811
  var import_metrics3 = __toModule(require("@tinacms/metrics"));
1905
1812
  var import_chalk6 = __toModule(require("chalk"));
1906
1813
  var import_chokidar = __toModule(require("chokidar"));
1814
+ var import_fs_extra6 = __toModule(require("fs-extra"));
1815
+ var import_ini = __toModule(require("ini"));
1816
+ var import_os = __toModule(require("os"));
1907
1817
  var import_path8 = __toModule(require("path"));
1908
- var lock = new AsyncLock();
1818
+ var buildLock = new AsyncLock();
1819
+ var reBuildLock = new AsyncLock();
1909
1820
  var gqlPackageFile = require.resolve("@tinacms/graphql");
1821
+ var resolveGitRoot = async () => {
1822
+ const pathParts = process.cwd().split(import_path8.default.sep);
1823
+ while (true) {
1824
+ const pathToGit = pathParts.join(import_path8.default.sep);
1825
+ if (await import_fs_extra6.default.pathExists(import_path8.default.join(pathToGit, ".git"))) {
1826
+ return pathToGit;
1827
+ }
1828
+ if (!pathParts.length) {
1829
+ throw new Error("Unable to locate your .git folder (required for isomorphicGitBridge)");
1830
+ }
1831
+ pathParts.pop();
1832
+ }
1833
+ };
1834
+ async function makeIsomorphicOptions(fsBridge) {
1835
+ var _a, _b, _c, _d;
1836
+ const gitRoot = await resolveGitRoot();
1837
+ const options = {
1838
+ gitRoot,
1839
+ author: {
1840
+ name: "",
1841
+ email: ""
1842
+ },
1843
+ onPut: async (filepath, data) => {
1844
+ await fsBridge.put(filepath, data);
1845
+ },
1846
+ onDelete: async (filepath) => {
1847
+ await fsBridge.delete(filepath);
1848
+ }
1849
+ };
1850
+ const userGitConfig = `${import_os.default.homedir()}${import_path8.default.sep}.gitconfig`;
1851
+ if (await import_fs_extra6.default.pathExists(userGitConfig)) {
1852
+ const config = import_ini.default.parse(await import_fs_extra6.default.readFile(userGitConfig, "utf-8"));
1853
+ if ((_a = config["user"]) == null ? void 0 : _a["name"]) {
1854
+ options.author.name = config["user"]["name"];
1855
+ }
1856
+ if ((_b = config["user"]) == null ? void 0 : _b["email"]) {
1857
+ options.author.email = config["user"]["email"];
1858
+ }
1859
+ }
1860
+ let repoGitConfig = void 0;
1861
+ if (!options.author.name) {
1862
+ repoGitConfig = import_ini.default.parse(await import_fs_extra6.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1863
+ if ((_c = repoGitConfig["user"]) == null ? void 0 : _c["name"]) {
1864
+ options.author.name = repoGitConfig["user"]["name"];
1865
+ }
1866
+ if (!options.author.name) {
1867
+ throw new Error('Unable to determine user.name from git config. Hint: `git config --global user.name "John Doe"`');
1868
+ }
1869
+ }
1870
+ if (!options.author.email) {
1871
+ repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra6.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
1872
+ if ((_d = repoGitConfig["user"]) == null ? void 0 : _d["email"]) {
1873
+ options.author.email = repoGitConfig["user"]["email"];
1874
+ }
1875
+ if (!options.author.email) {
1876
+ throw new Error("Unable to determine user.email from git config. Hint: `git config --global user.email johndoe@example.com`");
1877
+ }
1878
+ }
1879
+ return options;
1880
+ }
1910
1881
  async function startServer(_ctx, next, {
1911
1882
  port = 4001,
1912
1883
  noWatch,
1913
1884
  experimentalData,
1885
+ isomorphicGitBridge: isomorphicGitBridge2,
1914
1886
  noSDK,
1915
1887
  noTelemetry,
1916
1888
  watchFolders,
1917
1889
  verbose,
1918
1890
  dev
1919
1891
  }) {
1920
- lock.disable();
1892
+ buildLock.disable();
1893
+ reBuildLock.disable();
1921
1894
  const rootPath2 = process.cwd();
1922
1895
  const t = new import_metrics3.Telemetry({ disabled: Boolean(noTelemetry) });
1923
1896
  t.submitRecord({
@@ -1925,18 +1898,17 @@ async function startServer(_ctx, next, {
1925
1898
  name: "tinacms:cli:server:start:invoke"
1926
1899
  }
1927
1900
  });
1928
- if (!process.env.CI && !noWatch) {
1929
- await resetGeneratedFolder();
1930
- }
1931
- const bridge = new import_datalayer3.FilesystemBridge(rootPath2);
1901
+ const fsBridge = new import_datalayer3.FilesystemBridge(rootPath2);
1902
+ const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
1903
+ const bridge = isomorphicGitBridge2 ? new import_datalayer3.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
1932
1904
  const store = experimentalData ? new import_datalayer3.LevelStore(rootPath2) : new import_datalayer3.FilesystemStore({ rootPath: rootPath2 });
1933
1905
  const shouldBuild = bridge.supportsBuilding();
1934
1906
  const database = await (0, import_graphql11.createDatabase)({ store, bridge });
1935
1907
  let ready = false;
1936
1908
  const build2 = async (noSDK2) => {
1937
1909
  database.clearCache();
1938
- await lock.promise;
1939
- lock.enable();
1910
+ await buildLock.promise;
1911
+ buildLock.enable();
1940
1912
  try {
1941
1913
  if (!process.env.CI && !noWatch) {
1942
1914
  await store.close();
@@ -1944,6 +1916,9 @@ async function startServer(_ctx, next, {
1944
1916
  await store.open();
1945
1917
  }
1946
1918
  const cliFlags = [];
1919
+ if (isomorphicGitBridge2) {
1920
+ cliFlags.push("isomorphicGitBridge");
1921
+ }
1947
1922
  const database2 = await (0, import_graphql11.createDatabase)({ store, bridge });
1948
1923
  await compileSchema(null, null, { verbose, dev });
1949
1924
  const schema = await (0, import_graphql11.buildSchema)(rootPath2, database2, cliFlags);
@@ -1952,7 +1927,7 @@ async function startServer(_ctx, next, {
1952
1927
  } catch (error) {
1953
1928
  throw error;
1954
1929
  } finally {
1955
- lock.disable();
1930
+ buildLock.disable();
1956
1931
  }
1957
1932
  };
1958
1933
  const state = {
@@ -1961,49 +1936,59 @@ async function startServer(_ctx, next, {
1961
1936
  };
1962
1937
  let isReady = false;
1963
1938
  const start = async () => {
1964
- await lock.promise;
1965
- const s = (init_server3(), server_exports);
1966
- state.server = await s.default(database);
1967
- state.server.listen(port, () => {
1968
- const altairUrl = `http://localhost:${port}/altair/`;
1969
- const cmsUrl = `[your-development-url]/admin`;
1970
- if (verbose)
1971
- logger.info(`Started Filesystem GraphQL server on port: ${port}`);
1972
- logger.info(`Visit the GraphQL playground at ${import_chalk6.default.underline.blueBright(altairUrl)}
1939
+ await buildLock.promise;
1940
+ buildLock.enable();
1941
+ try {
1942
+ const s = (init_server3(), server_exports);
1943
+ state.server = await s.default(database);
1944
+ state.server.listen(port, () => {
1945
+ const altairUrl = `http://localhost:${port}/altair/`;
1946
+ const cmsUrl = `[your-development-url]/admin`;
1947
+ if (verbose)
1948
+ logger.info(`Started Filesystem GraphQL server on port: ${port}`);
1949
+ logger.info(`Visit the GraphQL playground at ${import_chalk6.default.underline.blueBright(altairUrl)}
1973
1950
  or`);
1974
- logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
1951
+ logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
1975
1952
  `);
1976
- });
1977
- state.server.on("error", function(e) {
1978
- if (e.code === "EADDRINUSE") {
1979
- logger.error(dangerText(`Port 4001 already in use`));
1980
- process.exit();
1981
- }
1982
- throw e;
1983
- });
1984
- state.server.on("connection", (socket) => {
1985
- state.sockets.push(socket);
1986
- });
1953
+ });
1954
+ state.server.on("error", function(e) {
1955
+ if (e.code === "EADDRINUSE") {
1956
+ logger.error(dangerText(`Port 4001 already in use`));
1957
+ process.exit();
1958
+ }
1959
+ throw e;
1960
+ });
1961
+ state.server.on("connection", (socket) => {
1962
+ state.sockets.push(socket);
1963
+ });
1964
+ } catch (error) {
1965
+ throw error;
1966
+ } finally {
1967
+ buildLock.disable();
1968
+ }
1987
1969
  };
1988
1970
  const restart = async () => {
1989
- logger.info("restarting local server...");
1990
- delete require.cache[gqlPackageFile];
1991
- state.sockets.forEach((socket) => {
1992
- if (socket.destroyed === false) {
1993
- socket.destroy();
1994
- }
1995
- });
1996
- state.sockets = [];
1997
- state.server.close(() => {
1998
- logger.info("Server closed");
1999
- start();
1971
+ return new Promise((resolve2, reject) => {
1972
+ logger.info("restarting local server...");
1973
+ delete require.cache[gqlPackageFile];
1974
+ state.sockets.forEach((socket) => {
1975
+ if (socket.destroyed === false) {
1976
+ socket.destroy();
1977
+ }
1978
+ });
1979
+ state.sockets = [];
1980
+ state.server.close(async () => {
1981
+ logger.info("Server closed");
1982
+ start().then((x) => resolve2(x)).catch((err) => reject(err));
1983
+ });
2000
1984
  });
2001
1985
  };
2002
1986
  const foldersToWatch = (watchFolders || []).map((x) => import_path8.default.join(rootPath2, x));
2003
1987
  if (!noWatch && !process.env.CI) {
2004
1988
  import_chokidar.default.watch([
2005
1989
  ...foldersToWatch,
2006
- `${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
1990
+ `${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`,
1991
+ gqlPackageFile
2007
1992
  ], {
2008
1993
  ignored: [
2009
1994
  "**/node_modules/**/*",
@@ -2018,6 +2003,8 @@ or`);
2018
2003
  await build2(noSDK);
2019
2004
  }
2020
2005
  ready = true;
2006
+ isReady = true;
2007
+ await start();
2021
2008
  next();
2022
2009
  } catch (e) {
2023
2010
  handleServerErrors(e);
@@ -2026,13 +2013,15 @@ or`);
2026
2013
  }
2027
2014
  }).on("all", async () => {
2028
2015
  if (ready) {
2016
+ await reBuildLock.promise;
2017
+ reBuildLock.enable();
2029
2018
  logger.info("Tina change detected, regenerating config");
2030
2019
  try {
2031
2020
  if (shouldBuild) {
2032
2021
  await build2(noSDK);
2033
- if (isReady) {
2034
- restart();
2035
- }
2022
+ }
2023
+ if (isReady) {
2024
+ await restart();
2036
2025
  }
2037
2026
  } catch (e) {
2038
2027
  handleServerErrors(e);
@@ -2042,33 +2031,24 @@ or`);
2042
2031
  errorMessage: e.message
2043
2032
  }
2044
2033
  });
2034
+ } finally {
2035
+ reBuildLock.disable();
2045
2036
  }
2046
2037
  }
2047
2038
  });
2048
- } else {
2049
- if (shouldBuild) {
2050
- await build2(noSDK);
2051
- }
2052
- }
2053
- if (!noWatch && !process.env.CI) {
2054
- import_chokidar.default.watch([gqlPackageFile]).on("ready", async () => {
2055
- isReady = true;
2056
- start();
2057
- }).on("all", async () => {
2058
- if (isReady) {
2059
- restart();
2060
- }
2061
- });
2062
2039
  } else {
2063
2040
  if (process.env.CI) {
2064
2041
  logger.info("Detected CI environment, omitting watch commands...");
2065
2042
  }
2066
- start();
2043
+ if (shouldBuild) {
2044
+ await build2(noSDK);
2045
+ }
2046
+ await start();
2067
2047
  next();
2068
2048
  }
2069
2049
  }
2070
2050
 
2071
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/waitForDB/index.ts
2051
+ // src/cmds/waitForDB/index.ts
2072
2052
  var POLLING_INTERVAL = 5e3;
2073
2053
  var STATUS_INPROGRESS = "inprogress";
2074
2054
  var STATUS_COMPLETE = "complete";
@@ -2142,7 +2122,7 @@ var waitForDB = async (ctx, next, options) => {
2142
2122
  pollForStatus();
2143
2123
  };
2144
2124
 
2145
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/startSubprocess/index.ts
2125
+ // src/cmds/startSubprocess/index.ts
2146
2126
  var import_child_process = __toModule(require("child_process"));
2147
2127
  var startSubprocess = async (_ctx, next, { command }) => {
2148
2128
  if (typeof command === "string") {
@@ -2167,7 +2147,7 @@ stack: ${code.stack || "No stack was provided"}`);
2167
2147
  }
2168
2148
  };
2169
2149
 
2170
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
2150
+ // src/cmds/baseCmds.ts
2171
2151
  var CMD_GEN_TYPES = "schema:types";
2172
2152
  var CMD_START_SERVER = "server:start";
2173
2153
  var CMD_COMPILE_MODELS = "schema:compile";
@@ -2182,6 +2162,10 @@ var experimentalDatalayer = {
2182
2162
  name: "--experimentalData",
2183
2163
  description: "Build the server with additional data querying capabilities"
2184
2164
  };
2165
+ var isomorphicGitBridge = {
2166
+ name: "--isomorphicGitBridge",
2167
+ description: "Enable Isomorphic Git Bridge Implementation"
2168
+ };
2185
2169
  var schemaFileType = {
2186
2170
  name: "--schemaFileType [fileType]",
2187
2171
  description: "The file type to use for the Tina schema"
@@ -2231,6 +2215,7 @@ var baseCmds = [
2231
2215
  startServerPortOption,
2232
2216
  subCommand,
2233
2217
  experimentalDatalayer,
2218
+ isomorphicGitBridge,
2234
2219
  noWatchOption,
2235
2220
  noSDKCodegenOption,
2236
2221
  noTelemetryOption,
@@ -2246,6 +2231,7 @@ var baseCmds = [
2246
2231
  options: [
2247
2232
  subCommand,
2248
2233
  experimentalDatalayer,
2234
+ isomorphicGitBridge,
2249
2235
  noTelemetryOption,
2250
2236
  verboseOption,
2251
2237
  developmentOption
@@ -2255,18 +2241,28 @@ var baseCmds = [
2255
2241
  {
2256
2242
  command: CMD_COMPILE_MODELS,
2257
2243
  description: "Compile schema into static files for the server",
2258
- options: [experimentalDatalayer, noTelemetryOption],
2244
+ options: [experimentalDatalayer, isomorphicGitBridge, noTelemetryOption],
2259
2245
  action: (options) => chain([compileSchema], options)
2260
2246
  },
2261
2247
  {
2262
2248
  command: CMD_GEN_TYPES,
2263
2249
  description: "Generate a GraphQL query for your site's schema, (and optionally Typescript types)",
2264
- options: [experimentalDatalayer, noSDKCodegenOption, noTelemetryOption],
2250
+ options: [
2251
+ experimentalDatalayer,
2252
+ isomorphicGitBridge,
2253
+ noSDKCodegenOption,
2254
+ noTelemetryOption
2255
+ ],
2265
2256
  action: (options) => chain([attachSchema, genTypes], options)
2266
2257
  },
2267
2258
  {
2268
2259
  command: INIT,
2269
- options: [experimentalDatalayer, noTelemetryOption, schemaFileType],
2260
+ options: [
2261
+ experimentalDatalayer,
2262
+ isomorphicGitBridge,
2263
+ noTelemetryOption,
2264
+ schemaFileType
2265
+ ],
2270
2266
  description: "Add Tina Cloud to an existing project",
2271
2267
  action: (options) => chain([
2272
2268
  checkDeps,
@@ -2308,7 +2304,7 @@ var baseCmds = [
2308
2304
  }
2309
2305
  ];
2310
2306
 
2311
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/index.ts
2307
+ // src/index.ts
2312
2308
  var program = new commander.Command(name);
2313
2309
  var registerCommands = (commands, noHelp = false) => {
2314
2310
  commands.forEach((command, i) => {