@tinacms/cli 0.0.0-df15996-20250420014759 → 0.0.0-e0bbd2e-20251203224419
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/README.md +5 -5
- package/bin/tinacms +12 -6
- package/dist/cmds/forestry-migrate/index.d.ts +2 -2
- package/dist/cmds/init/index.d.ts +2 -2
- package/dist/cmds/init/prompts/index.d.ts +3 -2
- package/dist/cmds/init/prompts/types.d.ts +3 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1152 -1074
- package/dist/next/codegen/index.d.ts +3 -9
- package/dist/next/commands/build-command/index.d.ts +3 -0
- package/dist/utils/path.d.ts +3 -0
- package/dist/utils/sleep.d.ts +1 -0
- package/package.json +14 -9
package/dist/index.js
CHANGED
|
@@ -1,53 +1,20 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name2 in all)
|
|
9
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
1
|
// src/index.ts
|
|
30
|
-
|
|
31
|
-
__export(index_exports, {
|
|
32
|
-
default: () => index_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
var import_clipanion8 = require("clipanion");
|
|
2
|
+
import { Cli, Builtins } from "clipanion";
|
|
36
3
|
|
|
37
4
|
// package.json
|
|
38
|
-
var version = "
|
|
5
|
+
var version = "2.0.0";
|
|
39
6
|
|
|
40
7
|
// src/next/commands/dev-command/index.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
8
|
+
import path8 from "path";
|
|
9
|
+
import { FilesystemBridge as FilesystemBridge2, buildSchema } from "@tinacms/graphql";
|
|
10
|
+
import { LocalSearchIndexClient, SearchIndexer } from "@tinacms/search";
|
|
11
|
+
import AsyncLock from "async-lock";
|
|
12
|
+
import chokidar from "chokidar";
|
|
13
|
+
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
14
|
+
import fs7 from "fs-extra";
|
|
48
15
|
|
|
49
16
|
// src/logger/index.ts
|
|
50
|
-
|
|
17
|
+
import chalk from "chalk";
|
|
51
18
|
|
|
52
19
|
// src/logger/is-unicode-supported.ts
|
|
53
20
|
function isUnicodeSupported() {
|
|
@@ -61,9 +28,9 @@ function isUnicodeSupported() {
|
|
|
61
28
|
}
|
|
62
29
|
|
|
63
30
|
// src/logger/index.ts
|
|
64
|
-
|
|
65
|
-
var logger =
|
|
66
|
-
|
|
31
|
+
import log4js from "log4js";
|
|
32
|
+
var logger = log4js.getLogger();
|
|
33
|
+
log4js.configure({
|
|
67
34
|
appenders: {
|
|
68
35
|
out: { type: "stdout", layout: { type: "messagePassThrough" } }
|
|
69
36
|
},
|
|
@@ -88,18 +55,18 @@ ${message}
|
|
|
88
55
|
return ln.length > sum ? ln.length : sum;
|
|
89
56
|
}, 0) + 2;
|
|
90
57
|
const msg = lines.map(
|
|
91
|
-
(ln) => `${
|
|
58
|
+
(ln) => `${chalk.gray(bar)} ${chalk.white(ln)}${" ".repeat(
|
|
92
59
|
len - strip(ln).length
|
|
93
|
-
)}${
|
|
60
|
+
)}${chalk.gray(bar)}`
|
|
94
61
|
).join("\n");
|
|
95
62
|
const underscoreLen = len - title.length - 1 > 0 ? len - title.length - 1 : 0;
|
|
96
63
|
process.stdout.write(
|
|
97
|
-
`${
|
|
98
|
-
${
|
|
64
|
+
`${chalk.gray(bar)}
|
|
65
|
+
${chalk.green("\u25CB")} ${chalk.reset(
|
|
99
66
|
title
|
|
100
|
-
)} ${
|
|
67
|
+
)} ${chalk.gray("\u2500".repeat(underscoreLen) + "\u256E")}
|
|
101
68
|
${msg}
|
|
102
|
-
${
|
|
69
|
+
${chalk.gray(
|
|
103
70
|
"\u251C" + "\u2500".repeat(len + 2) + "\u256F"
|
|
104
71
|
)}
|
|
105
72
|
`
|
|
@@ -116,11 +83,11 @@ var summary = (content) => {
|
|
|
116
83
|
});
|
|
117
84
|
});
|
|
118
85
|
content.items.forEach((item) => {
|
|
119
|
-
outString.push(`${item.emoji} ${
|
|
86
|
+
outString.push(`${item.emoji} ${chalk.cyan(item.heading)}`);
|
|
120
87
|
item.subItems.forEach((subItem) => {
|
|
121
88
|
const spaces = longestKey - subItem.key.length + 4;
|
|
122
89
|
outString.push(
|
|
123
|
-
` ${subItem.key}:${[...Array(spaces)].join(" ")}${
|
|
90
|
+
` ${subItem.key}:${[...Array(spaces)].join(" ")}${chalk.cyan(
|
|
124
91
|
subItem.value
|
|
125
92
|
)}`
|
|
126
93
|
);
|
|
@@ -158,12 +125,12 @@ var S_WARN = s("\u25B2", "!");
|
|
|
158
125
|
var S_ERROR = s("\u25A0", "x");
|
|
159
126
|
|
|
160
127
|
// src/utils/spinner.ts
|
|
161
|
-
|
|
128
|
+
import { Spinner } from "cli-spinner";
|
|
162
129
|
async function localSpin({
|
|
163
130
|
waitFor,
|
|
164
131
|
text
|
|
165
132
|
}) {
|
|
166
|
-
const spinner = new
|
|
133
|
+
const spinner = new Spinner({
|
|
167
134
|
text: `${text} %s`,
|
|
168
135
|
stream: process.stderr,
|
|
169
136
|
onTick: function(msg) {
|
|
@@ -194,32 +161,32 @@ function spin({
|
|
|
194
161
|
}
|
|
195
162
|
|
|
196
163
|
// src/utils/theme.ts
|
|
197
|
-
|
|
198
|
-
var successText =
|
|
199
|
-
var focusText =
|
|
200
|
-
var dangerText =
|
|
201
|
-
var neutralText =
|
|
202
|
-
var linkText =
|
|
203
|
-
var labelText =
|
|
204
|
-
var cmdText =
|
|
164
|
+
import chalk2 from "chalk";
|
|
165
|
+
var successText = chalk2.bold.green;
|
|
166
|
+
var focusText = chalk2.bold;
|
|
167
|
+
var dangerText = chalk2.bold.red;
|
|
168
|
+
var neutralText = chalk2.bold.cyan;
|
|
169
|
+
var linkText = chalk2.bold.cyan;
|
|
170
|
+
var labelText = chalk2.bold;
|
|
171
|
+
var cmdText = chalk2.inverse;
|
|
205
172
|
var indentedCmd = (str) => {
|
|
206
173
|
return ` \u2503 ` + str;
|
|
207
174
|
};
|
|
208
175
|
var indentText = (str) => {
|
|
209
176
|
return String(str).split("\n").map((line) => ` ${line}`).join("\n");
|
|
210
177
|
};
|
|
211
|
-
var logText =
|
|
212
|
-
var warnText =
|
|
213
|
-
var titleText =
|
|
214
|
-
var CONFIRMATION_TEXT =
|
|
178
|
+
var logText = chalk2.italic.gray;
|
|
179
|
+
var warnText = chalk2.yellowBright.bgBlack;
|
|
180
|
+
var titleText = chalk2.bgHex("d2f1f8").hex("ec4816");
|
|
181
|
+
var CONFIRMATION_TEXT = chalk2.dim("enter to confirm");
|
|
215
182
|
|
|
216
183
|
// src/next/codegen/index.ts
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
184
|
+
import fs from "fs-extra";
|
|
185
|
+
import path from "path";
|
|
186
|
+
import { buildASTSchema, printSchema as printSchema2 } from "graphql";
|
|
220
187
|
|
|
221
188
|
// src/next/codegen/codegen/index.ts
|
|
222
|
-
|
|
189
|
+
import { parse, printSchema } from "graphql";
|
|
223
190
|
|
|
224
191
|
// src/next/codegen/codegen/plugin.ts
|
|
225
192
|
var AddGeneratedClientFunc = (apiURL) => {
|
|
@@ -288,37 +255,44 @@ var AddGeneratedClient = (apiURL) => ({
|
|
|
288
255
|
});
|
|
289
256
|
|
|
290
257
|
// src/next/codegen/codegen/index.ts
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
258
|
+
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
259
|
+
import { codegen } from "@graphql-codegen/core";
|
|
260
|
+
import { loadDocuments } from "@graphql-tools/load";
|
|
261
|
+
import { plugin as typescriptOperationsPlugin } from "@graphql-codegen/typescript-operations";
|
|
262
|
+
import { plugin as typescriptPlugin } from "@graphql-codegen/typescript";
|
|
296
263
|
|
|
297
264
|
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
298
|
-
|
|
299
|
-
|
|
265
|
+
import { visit } from "graphql";
|
|
266
|
+
import {
|
|
267
|
+
concatAST,
|
|
268
|
+
Kind as Kind2
|
|
269
|
+
} from "graphql";
|
|
300
270
|
|
|
301
271
|
// src/next/codegen/codegen/sdkPlugin/visitor.ts
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
272
|
+
import {
|
|
273
|
+
ClientSideBaseVisitor,
|
|
274
|
+
DocumentMode,
|
|
275
|
+
indentMultiline
|
|
276
|
+
} from "@graphql-codegen/visitor-plugin-common";
|
|
277
|
+
import autoBind from "auto-bind";
|
|
278
|
+
import { Kind, print } from "graphql";
|
|
279
|
+
var GenericSdkVisitor = class extends ClientSideBaseVisitor {
|
|
280
|
+
_operationsToInclude = [];
|
|
306
281
|
constructor(schema, fragments, rawConfig) {
|
|
307
282
|
super(schema, fragments, rawConfig, {
|
|
308
283
|
usingObservableFrom: rawConfig.usingObservableFrom
|
|
309
284
|
});
|
|
310
|
-
this
|
|
311
|
-
(0, import_auto_bind.default)(this);
|
|
285
|
+
autoBind(this);
|
|
312
286
|
if (this.config.usingObservableFrom) {
|
|
313
287
|
this._additionalImports.push(this.config.usingObservableFrom);
|
|
314
288
|
}
|
|
315
|
-
if (this.config.documentMode !==
|
|
289
|
+
if (this.config.documentMode !== DocumentMode.string) {
|
|
316
290
|
}
|
|
317
291
|
}
|
|
318
292
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
319
293
|
if (node.name == null) {
|
|
320
294
|
throw new Error(
|
|
321
|
-
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" +
|
|
295
|
+
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + print(node)
|
|
322
296
|
);
|
|
323
297
|
} else {
|
|
324
298
|
this._operationsToInclude.push({
|
|
@@ -336,14 +310,14 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
336
310
|
const usingObservable = !!this.config.usingObservableFrom;
|
|
337
311
|
const allPossibleActions = this._operationsToInclude.map((o) => {
|
|
338
312
|
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every(
|
|
339
|
-
(v) => v.type.kind !==
|
|
313
|
+
(v) => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue
|
|
340
314
|
);
|
|
341
315
|
const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
|
|
342
316
|
return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
|
|
343
317
|
return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
|
|
344
318
|
}`;
|
|
345
|
-
}).map((s2) =>
|
|
346
|
-
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode ===
|
|
319
|
+
}).map((s2) => indentMultiline(s2, 2));
|
|
320
|
+
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode === DocumentMode.string ? "string" : "DocumentNode"}, vars?: V, options?: C) => ${usingObservable ? "Promise<R> & Observable<R>" : "Promise<R>"}
|
|
347
321
|
export function getSdk<C>(requester: Requester<C>) {
|
|
348
322
|
return {
|
|
349
323
|
${allPossibleActions.join(",\n")}
|
|
@@ -355,14 +329,14 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
355
329
|
|
|
356
330
|
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
357
331
|
var plugin = (schema, documents, config2) => {
|
|
358
|
-
const allAst =
|
|
332
|
+
const allAst = concatAST(
|
|
359
333
|
documents.reduce((prev, v) => {
|
|
360
334
|
return [...prev, v.document];
|
|
361
335
|
}, [])
|
|
362
336
|
);
|
|
363
337
|
const allFragments = [
|
|
364
338
|
...allAst.definitions.filter(
|
|
365
|
-
(d) => d.kind ===
|
|
339
|
+
(d) => d.kind === Kind2.FRAGMENT_DEFINITION
|
|
366
340
|
).map((fragmentDef) => ({
|
|
367
341
|
node: fragmentDef,
|
|
368
342
|
name: fragmentDef.name.value,
|
|
@@ -372,7 +346,7 @@ var plugin = (schema, documents, config2) => {
|
|
|
372
346
|
...config2.externalFragments || []
|
|
373
347
|
];
|
|
374
348
|
const visitor = new GenericSdkVisitor(schema, allFragments, config2);
|
|
375
|
-
const visitorResult =
|
|
349
|
+
const visitorResult = visit(allAst, { leave: visitor });
|
|
376
350
|
return {
|
|
377
351
|
// We will take care of imports
|
|
378
352
|
// prepend: visitor.getImports(),
|
|
@@ -390,10 +364,10 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
390
364
|
let fragDocs = [];
|
|
391
365
|
docs = await loadGraphQLDocuments(queryPathGlob);
|
|
392
366
|
fragDocs = await loadGraphQLDocuments(fragDocPath);
|
|
393
|
-
const res = await
|
|
367
|
+
const res = await codegen({
|
|
394
368
|
// Filename is not used. This is because the typescript plugin returns a string instead of writing to a file.
|
|
395
369
|
filename: process.cwd(),
|
|
396
|
-
schema:
|
|
370
|
+
schema: parse(printSchema(schema)),
|
|
397
371
|
documents: [...docs, ...fragDocs],
|
|
398
372
|
config: {},
|
|
399
373
|
plugins: [
|
|
@@ -406,10 +380,10 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
406
380
|
],
|
|
407
381
|
pluginMap: {
|
|
408
382
|
typescript: {
|
|
409
|
-
plugin:
|
|
383
|
+
plugin: typescriptPlugin
|
|
410
384
|
},
|
|
411
385
|
typescriptOperations: {
|
|
412
|
-
plugin:
|
|
386
|
+
plugin: typescriptOperationsPlugin
|
|
413
387
|
},
|
|
414
388
|
typescriptSdk: {
|
|
415
389
|
plugin
|
|
@@ -422,8 +396,8 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
422
396
|
var loadGraphQLDocuments = async (globPath) => {
|
|
423
397
|
let result = [];
|
|
424
398
|
try {
|
|
425
|
-
result = await
|
|
426
|
-
loaders: [new
|
|
399
|
+
result = await loadDocuments(globPath, {
|
|
400
|
+
loaders: [new GraphQLFileLoader()]
|
|
427
401
|
});
|
|
428
402
|
} catch (e) {
|
|
429
403
|
if (
|
|
@@ -440,11 +414,27 @@ var loadGraphQLDocuments = async (globPath) => {
|
|
|
440
414
|
};
|
|
441
415
|
|
|
442
416
|
// src/next/codegen/index.ts
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
417
|
+
import { transform } from "esbuild";
|
|
418
|
+
import { mapUserFields } from "@tinacms/graphql";
|
|
419
|
+
import normalizePath from "normalize-path";
|
|
446
420
|
var TINA_HOST = "content.tinajs.io";
|
|
447
421
|
var Codegen = class {
|
|
422
|
+
configManager;
|
|
423
|
+
port;
|
|
424
|
+
schema;
|
|
425
|
+
queryDoc;
|
|
426
|
+
fragDoc;
|
|
427
|
+
isLocal;
|
|
428
|
+
// The API url used in the client
|
|
429
|
+
apiURL;
|
|
430
|
+
// This is always the local URL.
|
|
431
|
+
localUrl;
|
|
432
|
+
// production url
|
|
433
|
+
productionUrl;
|
|
434
|
+
graphqlSchemaDoc;
|
|
435
|
+
tinaSchema;
|
|
436
|
+
lookup;
|
|
437
|
+
noClientBuildCache;
|
|
448
438
|
constructor({
|
|
449
439
|
configManager,
|
|
450
440
|
port,
|
|
@@ -460,7 +450,7 @@ var Codegen = class {
|
|
|
460
450
|
this.graphqlSchemaDoc = graphqlSchemaDoc;
|
|
461
451
|
this.configManager = configManager;
|
|
462
452
|
this.port = port;
|
|
463
|
-
this.schema =
|
|
453
|
+
this.schema = buildASTSchema(graphqlSchemaDoc);
|
|
464
454
|
this.tinaSchema = tinaSchema;
|
|
465
455
|
this.queryDoc = queryDoc;
|
|
466
456
|
this.fragDoc = fragDoc;
|
|
@@ -468,19 +458,19 @@ var Codegen = class {
|
|
|
468
458
|
this.noClientBuildCache = noClientBuildCache;
|
|
469
459
|
}
|
|
470
460
|
async writeConfigFile(fileName, data) {
|
|
471
|
-
const filePath =
|
|
461
|
+
const filePath = path.join(
|
|
472
462
|
this.configManager.generatedFolderPath,
|
|
473
463
|
fileName
|
|
474
464
|
);
|
|
475
|
-
await
|
|
476
|
-
await
|
|
465
|
+
await fs.ensureFile(filePath);
|
|
466
|
+
await fs.outputFile(filePath, data);
|
|
477
467
|
if (this.configManager.hasSeparateContentRoot()) {
|
|
478
|
-
const filePath2 =
|
|
468
|
+
const filePath2 = path.join(
|
|
479
469
|
this.configManager.generatedFolderPathContentRepo,
|
|
480
470
|
fileName
|
|
481
471
|
);
|
|
482
|
-
await
|
|
483
|
-
await
|
|
472
|
+
await fs.ensureFile(filePath2);
|
|
473
|
+
await fs.outputFile(filePath2, data);
|
|
484
474
|
}
|
|
485
475
|
}
|
|
486
476
|
async removeGeneratedFilesIfExists() {
|
|
@@ -512,11 +502,11 @@ var Codegen = class {
|
|
|
512
502
|
await this.removeGeneratedFilesIfExists();
|
|
513
503
|
return apiURL;
|
|
514
504
|
}
|
|
515
|
-
await
|
|
505
|
+
await fs.outputFile(
|
|
516
506
|
this.configManager.generatedQueriesFilePath,
|
|
517
507
|
this.queryDoc
|
|
518
508
|
);
|
|
519
|
-
await
|
|
509
|
+
await fs.outputFile(
|
|
520
510
|
this.configManager.generatedFragmentsFilePath,
|
|
521
511
|
this.fragDoc
|
|
522
512
|
);
|
|
@@ -524,21 +514,21 @@ var Codegen = class {
|
|
|
524
514
|
const { clientString } = await this.genClient();
|
|
525
515
|
const databaseClientString = this.configManager.hasSelfHostedConfig() ? await this.genDatabaseClient() : "";
|
|
526
516
|
const { codeString, schemaString } = await this.genTypes();
|
|
527
|
-
await
|
|
517
|
+
await fs.outputFile(
|
|
528
518
|
this.configManager.generatedGraphQLGQLPath,
|
|
529
519
|
schemaString
|
|
530
520
|
);
|
|
531
521
|
if (this.configManager.isUsingTs()) {
|
|
532
|
-
await
|
|
522
|
+
await fs.outputFile(
|
|
533
523
|
this.configManager.generatedTypesTSFilePath,
|
|
534
524
|
codeString
|
|
535
525
|
);
|
|
536
|
-
await
|
|
526
|
+
await fs.outputFile(
|
|
537
527
|
this.configManager.generatedClientTSFilePath,
|
|
538
528
|
clientString
|
|
539
529
|
);
|
|
540
530
|
if (this.configManager.hasSelfHostedConfig()) {
|
|
541
|
-
await
|
|
531
|
+
await fs.outputFile(
|
|
542
532
|
this.configManager.generatedDatabaseClientTSFilePath,
|
|
543
533
|
databaseClientString
|
|
544
534
|
);
|
|
@@ -547,35 +537,35 @@ var Codegen = class {
|
|
|
547
537
|
await unlinkIfExists(this.configManager.generatedTypesDFilePath);
|
|
548
538
|
await unlinkIfExists(this.configManager.generatedTypesJSFilePath);
|
|
549
539
|
} else {
|
|
550
|
-
await
|
|
540
|
+
await fs.outputFile(
|
|
551
541
|
this.configManager.generatedTypesDFilePath,
|
|
552
542
|
codeString
|
|
553
543
|
);
|
|
554
|
-
const jsTypes = await
|
|
555
|
-
await
|
|
544
|
+
const jsTypes = await transform(codeString, { loader: "ts" });
|
|
545
|
+
await fs.outputFile(
|
|
556
546
|
this.configManager.generatedTypesJSFilePath,
|
|
557
547
|
jsTypes.code
|
|
558
548
|
);
|
|
559
|
-
await
|
|
549
|
+
await fs.outputFile(
|
|
560
550
|
this.configManager.generatedClientDFilePath,
|
|
561
551
|
clientString
|
|
562
552
|
);
|
|
563
|
-
const jsClient = await
|
|
564
|
-
await
|
|
553
|
+
const jsClient = await transform(clientString, { loader: "ts" });
|
|
554
|
+
await fs.outputFile(
|
|
565
555
|
this.configManager.generatedClientJSFilePath,
|
|
566
556
|
jsClient.code
|
|
567
557
|
);
|
|
568
558
|
await unlinkIfExists(this.configManager.generatedTypesTSFilePath);
|
|
569
559
|
await unlinkIfExists(this.configManager.generatedClientTSFilePath);
|
|
570
560
|
if (this.configManager.hasSelfHostedConfig()) {
|
|
571
|
-
const jsDatabaseClient = await
|
|
561
|
+
const jsDatabaseClient = await transform(databaseClientString, {
|
|
572
562
|
loader: "ts"
|
|
573
563
|
});
|
|
574
|
-
await
|
|
564
|
+
await fs.outputFile(
|
|
575
565
|
this.configManager.generatedDatabaseClientJSFilePath,
|
|
576
566
|
jsDatabaseClient.code
|
|
577
567
|
);
|
|
578
|
-
await
|
|
568
|
+
await fs.outputFile(
|
|
579
569
|
this.configManager.generatedDatabaseClientDFilePath,
|
|
580
570
|
databaseClientString
|
|
581
571
|
);
|
|
@@ -587,13 +577,12 @@ var Codegen = class {
|
|
|
587
577
|
return apiURL;
|
|
588
578
|
}
|
|
589
579
|
_createApiUrl() {
|
|
590
|
-
|
|
591
|
-
const
|
|
592
|
-
const
|
|
593
|
-
const token = (_c = this.configManager.config) == null ? void 0 : _c.token;
|
|
580
|
+
const branch = this.configManager.config?.branch;
|
|
581
|
+
const clientId = this.configManager.config?.clientId;
|
|
582
|
+
const token = this.configManager.config?.token;
|
|
594
583
|
const fullVersion = this.configManager.getTinaGraphQLVersion();
|
|
595
584
|
const version2 = `${fullVersion.major}.${fullVersion.minor}`;
|
|
596
|
-
const baseUrl =
|
|
585
|
+
const baseUrl = this.configManager.config.tinaioConfig?.contentApiUrlOverride || `https://${TINA_HOST}`;
|
|
597
586
|
if ((!branch || !clientId || !token) && !this.port && !this.configManager.config.contentApiUrlOverride) {
|
|
598
587
|
const missing = [];
|
|
599
588
|
if (!branch) missing.push("branch");
|
|
@@ -602,7 +591,7 @@ var Codegen = class {
|
|
|
602
591
|
throw new Error(
|
|
603
592
|
`Client not configured properly. Missing ${missing.join(
|
|
604
593
|
", "
|
|
605
|
-
)}. Please visit https://tina.io/docs/
|
|
594
|
+
)}. Please visit https://tina.io/docs/r/what-is-tinacloud for more information`
|
|
606
595
|
);
|
|
607
596
|
}
|
|
608
597
|
let localUrl = `http://localhost:${this.port}/graphql`;
|
|
@@ -621,18 +610,17 @@ var Codegen = class {
|
|
|
621
610
|
return this.apiURL;
|
|
622
611
|
}
|
|
623
612
|
async genDatabaseClient() {
|
|
624
|
-
var _a, _b;
|
|
625
613
|
const authCollection = this.tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
626
614
|
let authFields = [];
|
|
627
615
|
if (authCollection) {
|
|
628
|
-
const usersFields =
|
|
616
|
+
const usersFields = mapUserFields(authCollection, []);
|
|
629
617
|
if (usersFields.length === 0) {
|
|
630
618
|
throw new Error("No user field found");
|
|
631
619
|
}
|
|
632
620
|
if (usersFields.length > 1) {
|
|
633
621
|
throw new Error("Only one user field is allowed");
|
|
634
622
|
}
|
|
635
|
-
authFields =
|
|
623
|
+
authFields = usersFields[0]?.collectable?.fields.map((f) => {
|
|
636
624
|
if (f.type !== "password" && f.type !== "object") {
|
|
637
625
|
if (f.uid) {
|
|
638
626
|
return `id:${f.name}`;
|
|
@@ -710,13 +698,12 @@ export default databaseClient;
|
|
|
710
698
|
`;
|
|
711
699
|
}
|
|
712
700
|
async genClient() {
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
const errorPolicy = (_c = (_b = this.configManager.config) == null ? void 0 : _b.client) == null ? void 0 : _c.errorPolicy;
|
|
701
|
+
const token = this.configManager.config?.token;
|
|
702
|
+
const errorPolicy = this.configManager.config?.client?.errorPolicy;
|
|
716
703
|
const apiURL = this.getApiURL();
|
|
717
704
|
const clientString = `import { createClient } from "tinacms/dist/client";
|
|
718
705
|
import { queries } from "./types";
|
|
719
|
-
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${(
|
|
706
|
+
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${normalizePath(
|
|
720
707
|
this.configManager.generatedCachePath
|
|
721
708
|
)}', ` : ""}url: '${apiURL}', token: '${token}', queries, ${errorPolicy ? `errorPolicy: '${errorPolicy}'` : ""} });
|
|
722
709
|
export default client;
|
|
@@ -742,7 +729,7 @@ export default client;
|
|
|
742
729
|
${typescriptTypes}
|
|
743
730
|
`;
|
|
744
731
|
const schemaString = `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
745
|
-
${(
|
|
732
|
+
${printSchema2(this.schema)}
|
|
746
733
|
schema {
|
|
747
734
|
query: Query
|
|
748
735
|
mutation: Mutation
|
|
@@ -754,7 +741,7 @@ schema {
|
|
|
754
741
|
var maybeWarnFragmentSize = async (filepath) => {
|
|
755
742
|
if (
|
|
756
743
|
// is the file bigger than 100kb?
|
|
757
|
-
(await
|
|
744
|
+
(await fs.stat(filepath)).size > // convert to 100 kb to bytes
|
|
758
745
|
100 * 1024
|
|
759
746
|
) {
|
|
760
747
|
console.warn(
|
|
@@ -771,19 +758,34 @@ var maybeWarnFragmentSize = async (filepath) => {
|
|
|
771
758
|
}
|
|
772
759
|
};
|
|
773
760
|
var unlinkIfExists = async (filepath) => {
|
|
774
|
-
if (
|
|
775
|
-
|
|
761
|
+
if (fs.existsSync(filepath)) {
|
|
762
|
+
fs.unlinkSync(filepath);
|
|
776
763
|
}
|
|
777
764
|
};
|
|
778
765
|
|
|
779
766
|
// src/next/config-manager.ts
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
767
|
+
import fs2 from "fs-extra";
|
|
768
|
+
import path3 from "path";
|
|
769
|
+
import os from "os";
|
|
770
|
+
import { pathToFileURL } from "url";
|
|
771
|
+
import * as esbuild from "esbuild";
|
|
772
|
+
import * as dotenv from "dotenv";
|
|
773
|
+
import normalizePath2 from "normalize-path";
|
|
774
|
+
import chalk3 from "chalk";
|
|
775
|
+
import { createRequire } from "module";
|
|
776
|
+
|
|
777
|
+
// src/utils/path.ts
|
|
778
|
+
import path2 from "path";
|
|
779
|
+
function stripNativeTrailingSlash(p) {
|
|
780
|
+
const { root } = path2.parse(p);
|
|
781
|
+
let str = p;
|
|
782
|
+
while (str.length > root.length && str.endsWith(path2.sep)) {
|
|
783
|
+
str = str.slice(0, -1);
|
|
784
|
+
}
|
|
785
|
+
return str;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/next/config-manager.ts
|
|
787
789
|
var TINA_FOLDER = "tina";
|
|
788
790
|
var LEGACY_TINA_FOLDER = ".tina";
|
|
789
791
|
var GENERATED_FOLDER = "__generated__";
|
|
@@ -792,17 +794,57 @@ var GRAPHQL_GQL_FILE = "schema.gql";
|
|
|
792
794
|
var SCHEMA_JSON_FILE = "_schema.json";
|
|
793
795
|
var LOOKUP_JSON_FILE = "_lookup.json";
|
|
794
796
|
var ConfigManager = class {
|
|
797
|
+
config;
|
|
798
|
+
rootPath;
|
|
799
|
+
tinaFolderPath;
|
|
800
|
+
isUsingLegacyFolder;
|
|
801
|
+
tinaConfigFilePath;
|
|
802
|
+
tinaSpaPackagePath;
|
|
803
|
+
contentRootPath;
|
|
804
|
+
envFilePath;
|
|
805
|
+
generatedCachePath;
|
|
806
|
+
generatedFolderPath;
|
|
807
|
+
generatedFolderPathContentRepo;
|
|
808
|
+
generatedGraphQLGQLPath;
|
|
809
|
+
generatedGraphQLJSONPath;
|
|
810
|
+
generatedSchemaJSONPath;
|
|
811
|
+
generatedLookupJSONPath;
|
|
812
|
+
generatedTypesTSFilePath;
|
|
813
|
+
generatedTypesJSFilePath;
|
|
814
|
+
generatedTypesDFilePath;
|
|
815
|
+
generatedClientTSFilePath;
|
|
816
|
+
generatedClientJSFilePath;
|
|
817
|
+
generatedClientDFilePath;
|
|
818
|
+
generatedDatabaseClientJSFilePath;
|
|
819
|
+
generatedDatabaseClientTSFilePath;
|
|
820
|
+
generatedDatabaseClientDFilePath;
|
|
821
|
+
generatedQueriesFilePath;
|
|
822
|
+
generatedFragmentsFilePath;
|
|
823
|
+
generatedQueriesAndFragmentsGlob;
|
|
824
|
+
userQueriesAndFragmentsGlob;
|
|
825
|
+
publicFolderPath;
|
|
826
|
+
outputFolderPath;
|
|
827
|
+
outputHTMLFilePath;
|
|
828
|
+
outputGitignorePath;
|
|
829
|
+
selfHostedDatabaseFilePath;
|
|
830
|
+
prebuildFilePath;
|
|
831
|
+
spaRootPath;
|
|
832
|
+
spaMainPath;
|
|
833
|
+
spaHTMLPath;
|
|
834
|
+
tinaGraphQLVersionFromCLI;
|
|
835
|
+
legacyNoSDK;
|
|
836
|
+
watchList;
|
|
795
837
|
constructor({
|
|
796
838
|
rootPath = process.cwd(),
|
|
797
839
|
tinaGraphQLVersion,
|
|
798
840
|
legacyNoSDK
|
|
799
841
|
}) {
|
|
800
|
-
this.rootPath = (
|
|
842
|
+
this.rootPath = normalizePath2(rootPath);
|
|
801
843
|
this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
|
|
802
844
|
this.legacyNoSDK = legacyNoSDK;
|
|
803
845
|
}
|
|
804
846
|
isUsingTs() {
|
|
805
|
-
return [".ts", ".tsx"].includes(
|
|
847
|
+
return [".ts", ".tsx"].includes(path3.extname(this.tinaConfigFilePath));
|
|
806
848
|
}
|
|
807
849
|
hasSelfHostedConfig() {
|
|
808
850
|
return !!this.selfHostedDatabaseFilePath;
|
|
@@ -811,20 +853,20 @@ var ConfigManager = class {
|
|
|
811
853
|
return this.rootPath !== this.contentRootPath;
|
|
812
854
|
}
|
|
813
855
|
shouldSkipSDK() {
|
|
814
|
-
var _a;
|
|
815
856
|
if (this.legacyNoSDK) {
|
|
816
857
|
return this.legacyNoSDK;
|
|
817
858
|
}
|
|
818
|
-
return
|
|
859
|
+
return this.config.client?.skip || false;
|
|
819
860
|
}
|
|
820
861
|
async processConfig() {
|
|
862
|
+
const require2 = createRequire(import.meta.url);
|
|
821
863
|
this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
|
|
822
|
-
this.envFilePath =
|
|
823
|
-
|
|
864
|
+
this.envFilePath = path3.resolve(
|
|
865
|
+
path3.join(this.tinaFolderPath, "..", ".env")
|
|
824
866
|
);
|
|
825
867
|
dotenv.config({ path: this.envFilePath });
|
|
826
868
|
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
827
|
-
|
|
869
|
+
path3.join(this.tinaFolderPath, "config")
|
|
828
870
|
);
|
|
829
871
|
if (!this.tinaConfigFilePath) {
|
|
830
872
|
throw new Error(
|
|
@@ -832,89 +874,89 @@ var ConfigManager = class {
|
|
|
832
874
|
);
|
|
833
875
|
}
|
|
834
876
|
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
835
|
-
|
|
877
|
+
path3.join(this.tinaFolderPath, "database")
|
|
836
878
|
);
|
|
837
|
-
this.generatedFolderPath =
|
|
838
|
-
this.generatedCachePath =
|
|
879
|
+
this.generatedFolderPath = path3.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
880
|
+
this.generatedCachePath = path3.join(
|
|
839
881
|
this.generatedFolderPath,
|
|
840
882
|
".cache",
|
|
841
883
|
String((/* @__PURE__ */ new Date()).getTime())
|
|
842
884
|
);
|
|
843
|
-
this.generatedGraphQLGQLPath =
|
|
885
|
+
this.generatedGraphQLGQLPath = path3.join(
|
|
844
886
|
this.generatedFolderPath,
|
|
845
887
|
GRAPHQL_GQL_FILE
|
|
846
888
|
);
|
|
847
|
-
this.generatedGraphQLJSONPath =
|
|
889
|
+
this.generatedGraphQLJSONPath = path3.join(
|
|
848
890
|
this.generatedFolderPath,
|
|
849
891
|
GRAPHQL_JSON_FILE
|
|
850
892
|
);
|
|
851
|
-
this.generatedSchemaJSONPath =
|
|
893
|
+
this.generatedSchemaJSONPath = path3.join(
|
|
852
894
|
this.generatedFolderPath,
|
|
853
895
|
SCHEMA_JSON_FILE
|
|
854
896
|
);
|
|
855
|
-
this.generatedLookupJSONPath =
|
|
897
|
+
this.generatedLookupJSONPath = path3.join(
|
|
856
898
|
this.generatedFolderPath,
|
|
857
899
|
LOOKUP_JSON_FILE
|
|
858
900
|
);
|
|
859
|
-
this.generatedQueriesFilePath =
|
|
901
|
+
this.generatedQueriesFilePath = path3.join(
|
|
860
902
|
this.generatedFolderPath,
|
|
861
903
|
"queries.gql"
|
|
862
904
|
);
|
|
863
|
-
this.generatedFragmentsFilePath =
|
|
905
|
+
this.generatedFragmentsFilePath = path3.join(
|
|
864
906
|
this.generatedFolderPath,
|
|
865
907
|
"frags.gql"
|
|
866
908
|
);
|
|
867
|
-
this.generatedTypesTSFilePath =
|
|
909
|
+
this.generatedTypesTSFilePath = path3.join(
|
|
868
910
|
this.generatedFolderPath,
|
|
869
911
|
"types.ts"
|
|
870
912
|
);
|
|
871
|
-
this.generatedTypesJSFilePath =
|
|
913
|
+
this.generatedTypesJSFilePath = path3.join(
|
|
872
914
|
this.generatedFolderPath,
|
|
873
915
|
"types.js"
|
|
874
916
|
);
|
|
875
|
-
this.generatedTypesDFilePath =
|
|
917
|
+
this.generatedTypesDFilePath = path3.join(
|
|
876
918
|
this.generatedFolderPath,
|
|
877
919
|
"types.d.ts"
|
|
878
920
|
);
|
|
879
|
-
this.userQueriesAndFragmentsGlob =
|
|
921
|
+
this.userQueriesAndFragmentsGlob = path3.join(
|
|
880
922
|
this.tinaFolderPath,
|
|
881
923
|
"queries/**/*.{graphql,gql}"
|
|
882
924
|
);
|
|
883
|
-
this.generatedQueriesAndFragmentsGlob =
|
|
925
|
+
this.generatedQueriesAndFragmentsGlob = path3.join(
|
|
884
926
|
this.generatedFolderPath,
|
|
885
927
|
"*.{graphql,gql}"
|
|
886
928
|
);
|
|
887
|
-
this.generatedClientTSFilePath =
|
|
929
|
+
this.generatedClientTSFilePath = path3.join(
|
|
888
930
|
this.generatedFolderPath,
|
|
889
931
|
"client.ts"
|
|
890
932
|
);
|
|
891
|
-
this.generatedClientJSFilePath =
|
|
933
|
+
this.generatedClientJSFilePath = path3.join(
|
|
892
934
|
this.generatedFolderPath,
|
|
893
935
|
"client.js"
|
|
894
936
|
);
|
|
895
|
-
this.generatedClientDFilePath =
|
|
937
|
+
this.generatedClientDFilePath = path3.join(
|
|
896
938
|
this.generatedFolderPath,
|
|
897
939
|
"client.d.ts"
|
|
898
940
|
);
|
|
899
|
-
this.generatedDatabaseClientDFilePath =
|
|
941
|
+
this.generatedDatabaseClientDFilePath = path3.join(
|
|
900
942
|
this.generatedFolderPath,
|
|
901
943
|
"databaseClient.d.ts"
|
|
902
944
|
);
|
|
903
|
-
this.generatedDatabaseClientTSFilePath =
|
|
945
|
+
this.generatedDatabaseClientTSFilePath = path3.join(
|
|
904
946
|
this.generatedFolderPath,
|
|
905
947
|
"databaseClient.ts"
|
|
906
948
|
);
|
|
907
|
-
this.generatedDatabaseClientJSFilePath =
|
|
949
|
+
this.generatedDatabaseClientJSFilePath = path3.join(
|
|
908
950
|
this.generatedFolderPath,
|
|
909
951
|
"databaseClient.js"
|
|
910
952
|
);
|
|
911
|
-
const clientExists = this.isUsingTs() ? await
|
|
953
|
+
const clientExists = this.isUsingTs() ? await fs2.pathExists(this.generatedClientTSFilePath) : await fs2.pathExists(this.generatedClientJSFilePath);
|
|
912
954
|
if (!clientExists) {
|
|
913
955
|
const file = "export default ()=>({})\nexport const client = ()=>({})";
|
|
914
956
|
if (this.isUsingTs()) {
|
|
915
|
-
await
|
|
957
|
+
await fs2.outputFile(this.generatedClientTSFilePath, file);
|
|
916
958
|
} else {
|
|
917
|
-
await
|
|
959
|
+
await fs2.outputFile(this.generatedClientJSFilePath, file);
|
|
918
960
|
}
|
|
919
961
|
}
|
|
920
962
|
const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
|
|
@@ -924,30 +966,29 @@ var ConfigManager = class {
|
|
|
924
966
|
this.watchList = watchList;
|
|
925
967
|
this.config = config2;
|
|
926
968
|
this.prebuildFilePath = prebuildPath;
|
|
927
|
-
this.publicFolderPath =
|
|
969
|
+
this.publicFolderPath = path3.join(
|
|
928
970
|
this.rootPath,
|
|
929
971
|
this.config.build.publicFolder
|
|
930
972
|
);
|
|
931
|
-
this.outputFolderPath =
|
|
973
|
+
this.outputFolderPath = path3.join(
|
|
932
974
|
this.publicFolderPath,
|
|
933
975
|
this.config.build.outputFolder
|
|
934
976
|
);
|
|
935
|
-
this.outputHTMLFilePath =
|
|
936
|
-
this.outputGitignorePath =
|
|
937
|
-
const fullLocalContentPath =
|
|
938
|
-
this.tinaFolderPath,
|
|
939
|
-
this.config.localContentPath || ""
|
|
977
|
+
this.outputHTMLFilePath = path3.join(this.outputFolderPath, "index.html");
|
|
978
|
+
this.outputGitignorePath = path3.join(this.outputFolderPath, ".gitignore");
|
|
979
|
+
const fullLocalContentPath = stripNativeTrailingSlash(
|
|
980
|
+
path3.join(this.tinaFolderPath, this.config.localContentPath || "")
|
|
940
981
|
);
|
|
941
982
|
if (this.config.localContentPath) {
|
|
942
|
-
const localContentPathExists = await
|
|
983
|
+
const localContentPathExists = await fs2.pathExists(fullLocalContentPath);
|
|
943
984
|
if (localContentPathExists) {
|
|
944
985
|
logger.info(`Using separate content repo at ${fullLocalContentPath}`);
|
|
945
986
|
this.contentRootPath = fullLocalContentPath;
|
|
946
987
|
} else {
|
|
947
988
|
logger.warn(
|
|
948
|
-
`${
|
|
989
|
+
`${chalk3.yellow("Warning:")} The localContentPath ${chalk3.cyan(
|
|
949
990
|
fullLocalContentPath
|
|
950
|
-
)} does not exist. Please create it or remove the localContentPath from your config file at ${
|
|
991
|
+
)} does not exist. Please create it or remove the localContentPath from your config file at ${chalk3.cyan(
|
|
951
992
|
this.tinaConfigFilePath
|
|
952
993
|
)}`
|
|
953
994
|
);
|
|
@@ -956,22 +997,22 @@ var ConfigManager = class {
|
|
|
956
997
|
if (!this.contentRootPath) {
|
|
957
998
|
this.contentRootPath = this.rootPath;
|
|
958
999
|
}
|
|
959
|
-
this.generatedFolderPathContentRepo =
|
|
1000
|
+
this.generatedFolderPathContentRepo = path3.join(
|
|
960
1001
|
await this.getTinaFolderPath(this.contentRootPath),
|
|
961
1002
|
GENERATED_FOLDER
|
|
962
1003
|
);
|
|
963
|
-
this.spaMainPath =
|
|
964
|
-
this.spaRootPath =
|
|
1004
|
+
this.spaMainPath = require2.resolve("@tinacms/app");
|
|
1005
|
+
this.spaRootPath = path3.join(this.spaMainPath, "..", "..");
|
|
965
1006
|
}
|
|
966
1007
|
async getTinaFolderPath(rootPath) {
|
|
967
|
-
const tinaFolderPath =
|
|
968
|
-
const tinaFolderExists = await
|
|
1008
|
+
const tinaFolderPath = path3.join(rootPath, TINA_FOLDER);
|
|
1009
|
+
const tinaFolderExists = await fs2.pathExists(tinaFolderPath);
|
|
969
1010
|
if (tinaFolderExists) {
|
|
970
1011
|
this.isUsingLegacyFolder = false;
|
|
971
1012
|
return tinaFolderPath;
|
|
972
1013
|
}
|
|
973
|
-
const legacyFolderPath =
|
|
974
|
-
const legacyFolderExists = await
|
|
1014
|
+
const legacyFolderPath = path3.join(rootPath, LEGACY_TINA_FOLDER);
|
|
1015
|
+
const legacyFolderExists = await fs2.pathExists(legacyFolderPath);
|
|
975
1016
|
if (legacyFolderExists) {
|
|
976
1017
|
this.isUsingLegacyFolder = true;
|
|
977
1018
|
return legacyFolderPath;
|
|
@@ -990,8 +1031,8 @@ var ConfigManager = class {
|
|
|
990
1031
|
patch: version2[2] || "x"
|
|
991
1032
|
};
|
|
992
1033
|
}
|
|
993
|
-
const generatedSchema =
|
|
994
|
-
if (!generatedSchema || !(typeof
|
|
1034
|
+
const generatedSchema = fs2.readJSONSync(this.generatedSchemaJSONPath);
|
|
1035
|
+
if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
|
|
995
1036
|
throw new Error(
|
|
996
1037
|
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
997
1038
|
);
|
|
@@ -1037,7 +1078,7 @@ var ConfigManager = class {
|
|
|
1037
1078
|
return;
|
|
1038
1079
|
}
|
|
1039
1080
|
const filepathWithExtension = `${filepath}.${ext}`;
|
|
1040
|
-
const exists =
|
|
1081
|
+
const exists = fs2.existsSync(filepathWithExtension);
|
|
1041
1082
|
if (exists) {
|
|
1042
1083
|
result = filepathWithExtension;
|
|
1043
1084
|
}
|
|
@@ -1046,33 +1087,53 @@ var ConfigManager = class {
|
|
|
1046
1087
|
return result;
|
|
1047
1088
|
}
|
|
1048
1089
|
async loadDatabaseFile() {
|
|
1049
|
-
const tmpdir =
|
|
1050
|
-
const outfile =
|
|
1090
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1091
|
+
const outfile = path3.join(tmpdir, "database.build.mjs");
|
|
1051
1092
|
await esbuild.build({
|
|
1052
1093
|
entryPoints: [this.selfHostedDatabaseFilePath],
|
|
1053
1094
|
bundle: true,
|
|
1054
1095
|
platform: "node",
|
|
1096
|
+
format: "esm",
|
|
1055
1097
|
outfile,
|
|
1056
|
-
loader: loaders
|
|
1098
|
+
loader: loaders,
|
|
1099
|
+
// Provide a require() polyfill for ESM bundles containing CommonJS packages.
|
|
1100
|
+
// Some bundled packages (e.g., 'scmp' used by 'mongodb-level') use require('crypto').
|
|
1101
|
+
// When esbuild inlines these CommonJS packages, it keeps the require() calls,
|
|
1102
|
+
// but ESM doesn't have a global require. This banner creates one using Node.js's
|
|
1103
|
+
// official createRequire API, allowing the bundled CommonJS code to work in ESM.
|
|
1104
|
+
banner: {
|
|
1105
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
1106
|
+
}
|
|
1057
1107
|
});
|
|
1058
|
-
const result =
|
|
1059
|
-
|
|
1108
|
+
const result = await import(pathToFileURL(outfile).href);
|
|
1109
|
+
fs2.removeSync(outfile);
|
|
1060
1110
|
return result.default;
|
|
1061
1111
|
}
|
|
1062
1112
|
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
1063
|
-
const tmpdir =
|
|
1064
|
-
const preBuildConfigPath =
|
|
1113
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1114
|
+
const preBuildConfigPath = path3.join(
|
|
1065
1115
|
this.generatedFolderPath,
|
|
1066
1116
|
"config.prebuild.jsx"
|
|
1067
1117
|
);
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1118
|
+
const nativeNodeModulesPlugin = {
|
|
1119
|
+
name: "native-node-modules",
|
|
1120
|
+
setup(build3) {
|
|
1121
|
+
build3.onResolve({ filter: /^node:.*/ }, (args) => {
|
|
1122
|
+
return {
|
|
1123
|
+
path: args.path,
|
|
1124
|
+
external: true
|
|
1125
|
+
};
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
const outfile = path3.join(tmpdir, "config.build.jsx");
|
|
1130
|
+
const outfile2 = path3.join(tmpdir, "config.build.mjs");
|
|
1131
|
+
const tempTSConfigFile = path3.join(tmpdir, "tsconfig.json");
|
|
1132
|
+
fs2.outputFileSync(tempTSConfigFile, "{}");
|
|
1072
1133
|
const result2 = await esbuild.build({
|
|
1073
1134
|
entryPoints: [configFilePath],
|
|
1074
1135
|
bundle: true,
|
|
1075
|
-
target: ["
|
|
1136
|
+
target: ["esnext"],
|
|
1076
1137
|
platform: "browser",
|
|
1077
1138
|
format: "esm",
|
|
1078
1139
|
logLevel: "silent",
|
|
@@ -1092,9 +1153,10 @@ var ConfigManager = class {
|
|
|
1092
1153
|
await esbuild.build({
|
|
1093
1154
|
entryPoints: [configFilePath],
|
|
1094
1155
|
bundle: true,
|
|
1095
|
-
target: ["
|
|
1156
|
+
target: ["esnext"],
|
|
1096
1157
|
logLevel: "silent",
|
|
1097
1158
|
platform: "node",
|
|
1159
|
+
format: "esm",
|
|
1098
1160
|
outfile,
|
|
1099
1161
|
loader: loaders
|
|
1100
1162
|
});
|
|
@@ -1104,19 +1166,21 @@ var ConfigManager = class {
|
|
|
1104
1166
|
// Suppress warning about comparison with -0 from client module
|
|
1105
1167
|
logLevel: "silent",
|
|
1106
1168
|
platform: "node",
|
|
1169
|
+
target: ["esnext"],
|
|
1170
|
+
format: "esm",
|
|
1107
1171
|
outfile: outfile2,
|
|
1108
1172
|
loader: loaders
|
|
1109
1173
|
});
|
|
1110
1174
|
let result;
|
|
1111
1175
|
try {
|
|
1112
|
-
result =
|
|
1176
|
+
result = await import(pathToFileURL(outfile2).href);
|
|
1113
1177
|
} catch (e) {
|
|
1114
1178
|
console.error("Unexpected error loading config");
|
|
1115
1179
|
console.error(e);
|
|
1116
1180
|
throw e;
|
|
1117
1181
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1182
|
+
fs2.removeSync(outfile);
|
|
1183
|
+
fs2.removeSync(outfile2);
|
|
1120
1184
|
return {
|
|
1121
1185
|
config: result.default,
|
|
1122
1186
|
prebuildPath: preBuildConfigPath,
|
|
@@ -1151,24 +1215,28 @@ var loaders = {
|
|
|
1151
1215
|
};
|
|
1152
1216
|
|
|
1153
1217
|
// src/next/database.ts
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1218
|
+
import {
|
|
1219
|
+
createDatabaseInternal,
|
|
1220
|
+
FilesystemBridge,
|
|
1221
|
+
TinaLevelClient
|
|
1222
|
+
} from "@tinacms/graphql";
|
|
1223
|
+
import { pipeline } from "readable-stream";
|
|
1224
|
+
import { createServer } from "net";
|
|
1225
|
+
import { ManyLevelHost } from "many-level";
|
|
1226
|
+
import { MemoryLevel } from "memory-level";
|
|
1159
1227
|
var createDBServer = (port) => {
|
|
1160
|
-
const levelHost = new
|
|
1228
|
+
const levelHost = new ManyLevelHost(
|
|
1161
1229
|
// @ts-ignore
|
|
1162
|
-
new
|
|
1230
|
+
new MemoryLevel({
|
|
1163
1231
|
valueEncoding: "json"
|
|
1164
1232
|
})
|
|
1165
1233
|
);
|
|
1166
|
-
const dbServer =
|
|
1167
|
-
return
|
|
1234
|
+
const dbServer = createServer(function(socket) {
|
|
1235
|
+
return pipeline(socket, levelHost.createRpcStream(), socket, () => {
|
|
1168
1236
|
});
|
|
1169
1237
|
});
|
|
1170
1238
|
dbServer.once("error", (err) => {
|
|
1171
|
-
if (
|
|
1239
|
+
if (err?.code === "EADDRINUSE") {
|
|
1172
1240
|
throw new Error(
|
|
1173
1241
|
`Tina Dev server is already in use. Datalayer server is busy on port ${port}`
|
|
1174
1242
|
);
|
|
@@ -1178,7 +1246,7 @@ var createDBServer = (port) => {
|
|
|
1178
1246
|
};
|
|
1179
1247
|
async function createAndInitializeDatabase(configManager, datalayerPort, bridgeOverride) {
|
|
1180
1248
|
let database;
|
|
1181
|
-
const bridge = bridgeOverride || new
|
|
1249
|
+
const bridge = bridgeOverride || new FilesystemBridge(configManager.rootPath, configManager.contentRootPath);
|
|
1182
1250
|
if (configManager.hasSelfHostedConfig() && configManager.config.contentApiUrlOverride) {
|
|
1183
1251
|
database = await configManager.loadDatabaseFile();
|
|
1184
1252
|
database.bridge = bridge;
|
|
@@ -1190,9 +1258,9 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1190
1258
|
)} but there was no "contentApiUrlOverride" set. Falling back to built-in datalayer`
|
|
1191
1259
|
);
|
|
1192
1260
|
}
|
|
1193
|
-
const level = new
|
|
1261
|
+
const level = new TinaLevelClient(datalayerPort);
|
|
1194
1262
|
level.openConnection();
|
|
1195
|
-
database =
|
|
1263
|
+
database = createDatabaseInternal({
|
|
1196
1264
|
bridge,
|
|
1197
1265
|
level,
|
|
1198
1266
|
tinaDirectory: configManager.isUsingLegacyFolder ? LEGACY_TINA_FOLDER : TINA_FOLDER
|
|
@@ -1202,17 +1270,17 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1202
1270
|
}
|
|
1203
1271
|
|
|
1204
1272
|
// src/next/commands/baseCommands.ts
|
|
1205
|
-
|
|
1206
|
-
|
|
1273
|
+
import { Command, Option } from "clipanion";
|
|
1274
|
+
import chalk4 from "chalk";
|
|
1207
1275
|
|
|
1208
1276
|
// src/utils/start-subprocess.ts
|
|
1209
|
-
|
|
1277
|
+
import childProcess from "child_process";
|
|
1210
1278
|
var startSubprocess2 = async ({ command: command2 }) => {
|
|
1211
1279
|
if (typeof command2 === "string") {
|
|
1212
1280
|
const commands = command2.split(" ");
|
|
1213
1281
|
const firstCommand = commands[0];
|
|
1214
1282
|
const args = commands.slice(1) || [];
|
|
1215
|
-
const ps =
|
|
1283
|
+
const ps = childProcess.spawn(firstCommand, args, {
|
|
1216
1284
|
stdio: "inherit",
|
|
1217
1285
|
shell: true
|
|
1218
1286
|
});
|
|
@@ -1236,45 +1304,42 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
1236
1304
|
};
|
|
1237
1305
|
|
|
1238
1306
|
// src/next/commands/baseCommands.ts
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
var BaseCommand = class extends
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
description: "Disable anonymous telemetry that is collected"
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1307
|
+
import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
|
|
1308
|
+
import fs3 from "fs-extra";
|
|
1309
|
+
var BaseCommand = class extends Command {
|
|
1310
|
+
experimentalDataLayer = Option.Boolean("--experimentalData", {
|
|
1311
|
+
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
1312
|
+
});
|
|
1313
|
+
isomorphicGitBridge = Option.Boolean("--isomorphicGitBridge", {
|
|
1314
|
+
description: "DEPRECATED - Enable Isomorphic Git Bridge Implementation"
|
|
1315
|
+
});
|
|
1316
|
+
port = Option.String("-p,--port", "4001", {
|
|
1317
|
+
description: "Specify a port to run the server on. (default 4001)"
|
|
1318
|
+
});
|
|
1319
|
+
datalayerPort = Option.String("--datalayer-port", "9000", {
|
|
1320
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
1321
|
+
});
|
|
1322
|
+
subCommand = Option.String("-c,--command", {
|
|
1323
|
+
description: "The sub-command to run"
|
|
1324
|
+
});
|
|
1325
|
+
rootPath = Option.String("--rootPath", {
|
|
1326
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
1327
|
+
});
|
|
1328
|
+
verbose = Option.Boolean("-v,--verbose", false, {
|
|
1329
|
+
description: "increase verbosity of logged output"
|
|
1330
|
+
});
|
|
1331
|
+
noSDK = Option.Boolean("--noSDK", false, {
|
|
1332
|
+
description: "DEPRECATED - This should now be set in the config at client.skip = true'. Don't generate the generated client SDK"
|
|
1333
|
+
});
|
|
1334
|
+
noTelemetry = Option.Boolean("--noTelemetry", false, {
|
|
1335
|
+
description: "Disable anonymous telemetry that is collected"
|
|
1336
|
+
});
|
|
1272
1337
|
async startSubCommand() {
|
|
1273
1338
|
let subProc;
|
|
1274
1339
|
if (this.subCommand) {
|
|
1275
1340
|
subProc = await startSubprocess2({ command: this.subCommand });
|
|
1276
1341
|
logger.info(
|
|
1277
|
-
`Running web application with command: ${
|
|
1342
|
+
`Running web application with command: ${chalk4.cyan(this.subCommand)}`
|
|
1278
1343
|
);
|
|
1279
1344
|
}
|
|
1280
1345
|
function exitHandler(options, exitCode) {
|
|
@@ -1319,11 +1384,10 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1319
1384
|
const warnings = [];
|
|
1320
1385
|
await spin({
|
|
1321
1386
|
waitFor: async () => {
|
|
1322
|
-
var _a, _b;
|
|
1323
1387
|
const rootPath = configManager.rootPath;
|
|
1324
1388
|
let sha;
|
|
1325
1389
|
try {
|
|
1326
|
-
sha = await
|
|
1390
|
+
sha = await getSha({ fs: fs3, dir: rootPath });
|
|
1327
1391
|
} catch (e) {
|
|
1328
1392
|
if (partialReindex) {
|
|
1329
1393
|
console.error(
|
|
@@ -1333,7 +1397,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1333
1397
|
}
|
|
1334
1398
|
}
|
|
1335
1399
|
const lastSha = await database.getMetadata("lastSha");
|
|
1336
|
-
const exists = lastSha && await
|
|
1400
|
+
const exists = lastSha && await shaExists({ fs: fs3, dir: rootPath, sha: lastSha });
|
|
1337
1401
|
let res;
|
|
1338
1402
|
if (partialReindex && lastSha && exists && sha) {
|
|
1339
1403
|
const pathFilter = {};
|
|
@@ -1344,18 +1408,18 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1344
1408
|
}
|
|
1345
1409
|
for (const collection of tinaSchema.getCollections()) {
|
|
1346
1410
|
pathFilter[collection.path] = {
|
|
1347
|
-
matches:
|
|
1411
|
+
matches: collection.match?.exclude || collection.match?.include ? tinaSchema.getMatches({ collection }) : void 0
|
|
1348
1412
|
};
|
|
1349
1413
|
}
|
|
1350
|
-
const { added, modified, deleted } = await
|
|
1351
|
-
fs:
|
|
1414
|
+
const { added, modified, deleted } = await getChangedFiles({
|
|
1415
|
+
fs: fs3,
|
|
1352
1416
|
dir: rootPath,
|
|
1353
1417
|
from: lastSha,
|
|
1354
1418
|
to: sha,
|
|
1355
1419
|
pathFilter
|
|
1356
1420
|
});
|
|
1357
1421
|
const tinaPathUpdates = modified.filter(
|
|
1358
|
-
(
|
|
1422
|
+
(path15) => path15.startsWith(".tina/__generated__/_schema.json") || path15.startsWith("tina/tina-lock.json")
|
|
1359
1423
|
);
|
|
1360
1424
|
if (tinaPathUpdates.length > 0) {
|
|
1361
1425
|
res = await database.indexContent({
|
|
@@ -1379,7 +1443,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1379
1443
|
if (sha) {
|
|
1380
1444
|
await database.setMetadata("lastSha", sha);
|
|
1381
1445
|
}
|
|
1382
|
-
if (res
|
|
1446
|
+
if (res?.warnings) {
|
|
1383
1447
|
warnings.push(...res.warnings);
|
|
1384
1448
|
}
|
|
1385
1449
|
},
|
|
@@ -1433,7 +1497,7 @@ var errorHTML = `<style type="text/css">
|
|
|
1433
1497
|
the assets for this page.
|
|
1434
1498
|
</p>
|
|
1435
1499
|
<p>
|
|
1436
|
-
Please visit <a href="https://tina.io/docs/
|
|
1500
|
+
Please visit <a href="https://tina.io/docs/r/FAQ/#13-how-do-i-resolve-failed-loading-tinacms-assets-error">this doc</a> for help.
|
|
1437
1501
|
</p>
|
|
1438
1502
|
</div>
|
|
1439
1503
|
</div>`.trim().replace(/[\r\n\s]+/g, " ");
|
|
@@ -1471,34 +1535,38 @@ var devHTML = (port) => `<!DOCTYPE html>
|
|
|
1471
1535
|
</html>`;
|
|
1472
1536
|
|
|
1473
1537
|
// src/next/commands/dev-command/server/index.ts
|
|
1474
|
-
|
|
1538
|
+
import { createServer as createViteServer } from "vite";
|
|
1475
1539
|
|
|
1476
1540
|
// src/next/vite/index.ts
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1541
|
+
import path5 from "node:path";
|
|
1542
|
+
import react from "@vitejs/plugin-react";
|
|
1543
|
+
import fs4 from "fs-extra";
|
|
1544
|
+
import normalizePath3 from "normalize-path";
|
|
1545
|
+
import {
|
|
1546
|
+
splitVendorChunkPlugin
|
|
1547
|
+
} from "vite";
|
|
1482
1548
|
|
|
1483
1549
|
// src/next/vite/tailwind.ts
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1550
|
+
import path4 from "node:path";
|
|
1551
|
+
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
1552
|
+
import containerQueries from "@tailwindcss/container-queries";
|
|
1553
|
+
import twTypography from "@tailwindcss/typography";
|
|
1554
|
+
import tailwind from "tailwindcss";
|
|
1555
|
+
import defaultTheme from "tailwindcss/defaultTheme.js";
|
|
1556
|
+
import { createRequire as createRequire2 } from "module";
|
|
1490
1557
|
var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
1491
1558
|
return {
|
|
1492
1559
|
name: "vite-plugin-tina",
|
|
1493
1560
|
// @ts-ignore
|
|
1494
1561
|
config: (viteConfig) => {
|
|
1562
|
+
const require2 = createRequire2(import.meta.url);
|
|
1495
1563
|
const plugins = [];
|
|
1496
1564
|
const content = [
|
|
1497
|
-
|
|
1565
|
+
path4.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
1498
1566
|
prebuildFilePath,
|
|
1499
|
-
|
|
1567
|
+
require2.resolve("tinacms")
|
|
1500
1568
|
];
|
|
1501
|
-
const tw = (
|
|
1569
|
+
const tw = tailwind({
|
|
1502
1570
|
theme: {
|
|
1503
1571
|
columns: {
|
|
1504
1572
|
auto: "auto",
|
|
@@ -1686,6 +1754,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1686
1754
|
500: "#EC4815",
|
|
1687
1755
|
600: "#DC4419"
|
|
1688
1756
|
},
|
|
1757
|
+
"tina-orange": "#EC4815",
|
|
1758
|
+
"tina-orange-dark": "#C2410C",
|
|
1759
|
+
"tina-orange-light": "#FFF7ED",
|
|
1689
1760
|
background: "#FFFFFF",
|
|
1690
1761
|
foreground: "#0A0A0A",
|
|
1691
1762
|
muted: "#F5F5F5",
|
|
@@ -1707,7 +1778,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1707
1778
|
ring: "#0A0A0A"
|
|
1708
1779
|
},
|
|
1709
1780
|
fontFamily: {
|
|
1710
|
-
sans: ["Inter", ...
|
|
1781
|
+
sans: ["Inter", ...defaultTheme.fontFamily.sans]
|
|
1711
1782
|
},
|
|
1712
1783
|
lineHeight: {
|
|
1713
1784
|
3: "12px",
|
|
@@ -1732,9 +1803,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1732
1803
|
},
|
|
1733
1804
|
content,
|
|
1734
1805
|
plugins: [
|
|
1735
|
-
(
|
|
1736
|
-
|
|
1737
|
-
|
|
1806
|
+
twTypography({ className: "tina-prose" }),
|
|
1807
|
+
aspectRatio,
|
|
1808
|
+
containerQueries
|
|
1738
1809
|
]
|
|
1739
1810
|
});
|
|
1740
1811
|
plugins.push(tw);
|
|
@@ -1755,35 +1826,35 @@ async function listFilesRecursively({
|
|
|
1755
1826
|
config: config2,
|
|
1756
1827
|
roothPath
|
|
1757
1828
|
}) {
|
|
1758
|
-
const fullDirectoryPath =
|
|
1829
|
+
const fullDirectoryPath = path5.join(
|
|
1759
1830
|
roothPath,
|
|
1760
1831
|
config2.publicFolder,
|
|
1761
1832
|
directoryPath
|
|
1762
1833
|
);
|
|
1763
|
-
const exists = await
|
|
1834
|
+
const exists = await fs4.pathExists(fullDirectoryPath);
|
|
1764
1835
|
if (!exists) {
|
|
1765
1836
|
return { "0": [] };
|
|
1766
1837
|
}
|
|
1767
|
-
const items = await
|
|
1838
|
+
const items = await fs4.readdir(fullDirectoryPath);
|
|
1768
1839
|
const staticMediaItems = [];
|
|
1769
1840
|
for (const item of items) {
|
|
1770
|
-
const itemPath =
|
|
1771
|
-
const stats = await
|
|
1841
|
+
const itemPath = path5.join(fullDirectoryPath, item);
|
|
1842
|
+
const stats = await fs4.promises.lstat(itemPath);
|
|
1772
1843
|
const staticMediaItem = {
|
|
1773
1844
|
id: item,
|
|
1774
1845
|
filename: item,
|
|
1775
1846
|
type: stats.isDirectory() ? "dir" : "file",
|
|
1776
1847
|
directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
|
|
1777
|
-
src: `/${
|
|
1848
|
+
src: `/${path5.join(directoryPath, item)}`,
|
|
1778
1849
|
thumbnails: {
|
|
1779
|
-
"75x75": `/${
|
|
1780
|
-
"400x400": `/${
|
|
1781
|
-
"1000x1000": `/${
|
|
1850
|
+
"75x75": `/${path5.join(directoryPath, item)}`,
|
|
1851
|
+
"400x400": `/${path5.join(directoryPath, item)}`,
|
|
1852
|
+
"1000x1000": `/${path5.join(directoryPath, item)}`
|
|
1782
1853
|
}
|
|
1783
1854
|
};
|
|
1784
1855
|
if (stats.isDirectory()) {
|
|
1785
1856
|
staticMediaItem.children = await listFilesRecursively({
|
|
1786
|
-
directoryPath:
|
|
1857
|
+
directoryPath: path5.join(directoryPath, item),
|
|
1787
1858
|
config: config2,
|
|
1788
1859
|
roothPath
|
|
1789
1860
|
});
|
|
@@ -1807,7 +1878,6 @@ var createConfig = async ({
|
|
|
1807
1878
|
noWatch,
|
|
1808
1879
|
rollupOptions
|
|
1809
1880
|
}) => {
|
|
1810
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1811
1881
|
const publicEnv = {};
|
|
1812
1882
|
Object.keys(process.env).forEach((key) => {
|
|
1813
1883
|
if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
|
|
@@ -1825,31 +1895,31 @@ var createConfig = async ({
|
|
|
1825
1895
|
}
|
|
1826
1896
|
}
|
|
1827
1897
|
});
|
|
1828
|
-
const staticMediaPath =
|
|
1898
|
+
const staticMediaPath = path5.join(
|
|
1829
1899
|
configManager.generatedFolderPath,
|
|
1830
1900
|
"static-media.json"
|
|
1831
1901
|
);
|
|
1832
|
-
if (
|
|
1902
|
+
if (configManager.config.media?.tina?.static) {
|
|
1833
1903
|
const staticMedia = await listFilesRecursively({
|
|
1834
|
-
directoryPath:
|
|
1904
|
+
directoryPath: configManager.config.media.tina?.mediaRoot || "",
|
|
1835
1905
|
config: configManager.config.media.tina,
|
|
1836
1906
|
roothPath: configManager.rootPath
|
|
1837
1907
|
});
|
|
1838
|
-
await
|
|
1908
|
+
await fs4.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
|
|
1839
1909
|
} else {
|
|
1840
|
-
await
|
|
1910
|
+
await fs4.outputFile(staticMediaPath, `[]`);
|
|
1841
1911
|
}
|
|
1842
1912
|
const alias = {
|
|
1843
1913
|
TINA_IMPORT: configManager.prebuildFilePath,
|
|
1844
1914
|
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
|
|
1845
1915
|
STATIC_MEDIA_IMPORT: staticMediaPath,
|
|
1846
|
-
crypto:
|
|
1847
|
-
fs:
|
|
1848
|
-
os:
|
|
1849
|
-
path:
|
|
1916
|
+
crypto: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1917
|
+
fs: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1918
|
+
os: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1919
|
+
path: path5.join(configManager.spaRootPath, "src", "dummy-client.ts")
|
|
1850
1920
|
};
|
|
1851
1921
|
if (configManager.shouldSkipSDK()) {
|
|
1852
|
-
alias["CLIENT_IMPORT"] =
|
|
1922
|
+
alias["CLIENT_IMPORT"] = path5.join(
|
|
1853
1923
|
configManager.spaRootPath,
|
|
1854
1924
|
"src",
|
|
1855
1925
|
"dummy-client.ts"
|
|
@@ -1865,7 +1935,7 @@ var createConfig = async ({
|
|
|
1865
1935
|
const version2 = `${fullVersion.major}.${fullVersion.minor}`;
|
|
1866
1936
|
const config2 = {
|
|
1867
1937
|
root: configManager.spaRootPath,
|
|
1868
|
-
base: `/${basePath ? `${(
|
|
1938
|
+
base: `/${basePath ? `${normalizePath3(basePath)}/` : ""}${normalizePath3(
|
|
1869
1939
|
configManager.config.build.outputFolder
|
|
1870
1940
|
)}/`,
|
|
1871
1941
|
appType: "spa",
|
|
@@ -1892,7 +1962,7 @@ var createConfig = async ({
|
|
|
1892
1962
|
// Used by picomatch https://github.com/micromatch/picomatch/blob/master/lib/utils.js#L4
|
|
1893
1963
|
"process.platform": `"${process.platform}"`,
|
|
1894
1964
|
__API_URL__: `"${apiURL}"`,
|
|
1895
|
-
__BASE_PATH__: `"${
|
|
1965
|
+
__BASE_PATH__: `"${configManager.config?.build?.basePath || ""}"`,
|
|
1896
1966
|
__TINA_GRAPHQL_VERSION__: version2
|
|
1897
1967
|
},
|
|
1898
1968
|
logLevel: "error",
|
|
@@ -1904,7 +1974,7 @@ var createConfig = async ({
|
|
|
1904
1974
|
include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
1905
1975
|
},
|
|
1906
1976
|
server: {
|
|
1907
|
-
host:
|
|
1977
|
+
host: configManager.config?.build?.host ?? false,
|
|
1908
1978
|
watch: noWatch ? {
|
|
1909
1979
|
ignored: ["**/*"]
|
|
1910
1980
|
} : {
|
|
@@ -1928,13 +1998,14 @@ var createConfig = async ({
|
|
|
1928
1998
|
* `splitVendorChunkPlugin` is needed because `tinacms` is quite large,
|
|
1929
1999
|
* Vite's chunking strategy chokes on memory issues for smaller machines (ie. on CI).
|
|
1930
2000
|
*/
|
|
1931
|
-
(
|
|
2001
|
+
react({
|
|
1932
2002
|
babel: {
|
|
1933
2003
|
// Supresses the warning [NOTE] babel The code generator has deoptimised the styling of
|
|
1934
2004
|
compact: true
|
|
1935
|
-
}
|
|
2005
|
+
},
|
|
2006
|
+
fastRefresh: false
|
|
1936
2007
|
}),
|
|
1937
|
-
|
|
2008
|
+
splitVendorChunkPlugin(),
|
|
1938
2009
|
tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
|
|
1939
2010
|
...plugins
|
|
1940
2011
|
]
|
|
@@ -1943,21 +2014,21 @@ var createConfig = async ({
|
|
|
1943
2014
|
};
|
|
1944
2015
|
|
|
1945
2016
|
// src/next/vite/plugins.ts
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
2017
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
2018
|
+
import fs6 from "fs";
|
|
2019
|
+
import { transformWithEsbuild } from "vite";
|
|
2020
|
+
import { transform as esbuildTransform } from "esbuild";
|
|
2021
|
+
import path7 from "path";
|
|
2022
|
+
import bodyParser from "body-parser";
|
|
2023
|
+
import cors from "cors";
|
|
2024
|
+
import { resolve as gqlResolve } from "@tinacms/graphql";
|
|
1954
2025
|
|
|
1955
2026
|
// src/next/commands/dev-command/server/media.ts
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
2027
|
+
import fs5 from "fs-extra";
|
|
2028
|
+
import path6, { join } from "path";
|
|
2029
|
+
import busboy from "busboy";
|
|
1959
2030
|
var createMediaRouter = (config2) => {
|
|
1960
|
-
const mediaFolder =
|
|
2031
|
+
const mediaFolder = path6.join(
|
|
1961
2032
|
config2.rootPath,
|
|
1962
2033
|
config2.publicFolder,
|
|
1963
2034
|
config2.mediaRoot
|
|
@@ -1981,13 +2052,12 @@ var createMediaRouter = (config2) => {
|
|
|
1981
2052
|
res.end(JSON.stringify(didDelete));
|
|
1982
2053
|
};
|
|
1983
2054
|
const handlePost = async function(req, res) {
|
|
1984
|
-
const bb = (
|
|
2055
|
+
const bb = busboy({ headers: req.headers });
|
|
1985
2056
|
bb.on("file", async (_name, file, _info) => {
|
|
1986
|
-
|
|
1987
|
-
const
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
file.pipe(import_fs_extra5.default.createWriteStream(saveTo));
|
|
2057
|
+
const fullPath = decodeURI(req.url?.slice("/media/upload/".length));
|
|
2058
|
+
const saveTo = path6.join(mediaFolder, ...fullPath.split("/"));
|
|
2059
|
+
await fs5.ensureDir(path6.dirname(saveTo));
|
|
2060
|
+
file.pipe(fs5.createWriteStream(saveTo));
|
|
1991
2061
|
});
|
|
1992
2062
|
bb.on("error", (error) => {
|
|
1993
2063
|
res.statusCode = 500;
|
|
@@ -2013,6 +2083,9 @@ var parseMediaFolder = (str) => {
|
|
|
2013
2083
|
return returnString;
|
|
2014
2084
|
};
|
|
2015
2085
|
var MediaModel = class {
|
|
2086
|
+
rootPath;
|
|
2087
|
+
publicFolder;
|
|
2088
|
+
mediaRoot;
|
|
2016
2089
|
constructor({ rootPath, publicFolder, mediaRoot }) {
|
|
2017
2090
|
this.rootPath = rootPath;
|
|
2018
2091
|
this.mediaRoot = mediaRoot;
|
|
@@ -2020,23 +2093,23 @@ var MediaModel = class {
|
|
|
2020
2093
|
}
|
|
2021
2094
|
async listMedia(args) {
|
|
2022
2095
|
try {
|
|
2023
|
-
const folderPath =
|
|
2096
|
+
const folderPath = join(
|
|
2024
2097
|
this.rootPath,
|
|
2025
2098
|
this.publicFolder,
|
|
2026
2099
|
this.mediaRoot,
|
|
2027
2100
|
decodeURIComponent(args.searchPath)
|
|
2028
2101
|
);
|
|
2029
2102
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
2030
|
-
if (!await
|
|
2103
|
+
if (!await fs5.pathExists(folderPath)) {
|
|
2031
2104
|
return {
|
|
2032
2105
|
files: [],
|
|
2033
2106
|
directories: []
|
|
2034
2107
|
};
|
|
2035
2108
|
}
|
|
2036
|
-
const filesStr = await
|
|
2109
|
+
const filesStr = await fs5.readdir(folderPath);
|
|
2037
2110
|
const filesProm = filesStr.map(async (file) => {
|
|
2038
|
-
const filePath =
|
|
2039
|
-
const stat = await
|
|
2111
|
+
const filePath = join(folderPath, file);
|
|
2112
|
+
const stat = await fs5.stat(filePath);
|
|
2040
2113
|
let src = `/${file}`;
|
|
2041
2114
|
const isFile = stat.isFile();
|
|
2042
2115
|
if (!isFile) {
|
|
@@ -2086,24 +2159,24 @@ var MediaModel = class {
|
|
|
2086
2159
|
return {
|
|
2087
2160
|
files: [],
|
|
2088
2161
|
directories: [],
|
|
2089
|
-
error: error
|
|
2162
|
+
error: error?.toString()
|
|
2090
2163
|
};
|
|
2091
2164
|
}
|
|
2092
2165
|
}
|
|
2093
2166
|
async deleteMedia(args) {
|
|
2094
2167
|
try {
|
|
2095
|
-
const file =
|
|
2168
|
+
const file = join(
|
|
2096
2169
|
this.rootPath,
|
|
2097
2170
|
this.publicFolder,
|
|
2098
2171
|
this.mediaRoot,
|
|
2099
2172
|
decodeURIComponent(args.searchPath)
|
|
2100
2173
|
);
|
|
2101
|
-
await
|
|
2102
|
-
await
|
|
2174
|
+
await fs5.stat(file);
|
|
2175
|
+
await fs5.remove(file);
|
|
2103
2176
|
return { ok: true };
|
|
2104
2177
|
} catch (error) {
|
|
2105
2178
|
console.error(error);
|
|
2106
|
-
return { ok: false, message: error
|
|
2179
|
+
return { ok: false, message: error?.toString() };
|
|
2107
2180
|
}
|
|
2108
2181
|
}
|
|
2109
2182
|
};
|
|
@@ -2157,9 +2230,9 @@ var transformTsxPlugin = ({
|
|
|
2157
2230
|
const plug = {
|
|
2158
2231
|
name: "transform-tsx",
|
|
2159
2232
|
async transform(code, id) {
|
|
2160
|
-
const extName =
|
|
2233
|
+
const extName = path7.extname(id);
|
|
2161
2234
|
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
2162
|
-
const result = await (
|
|
2235
|
+
const result = await esbuildTransform(code, { loader: "tsx" });
|
|
2163
2236
|
return {
|
|
2164
2237
|
code: result.code
|
|
2165
2238
|
};
|
|
@@ -2178,16 +2251,15 @@ var devServerEndPointsPlugin = ({
|
|
|
2178
2251
|
const plug = {
|
|
2179
2252
|
name: "graphql-endpoints",
|
|
2180
2253
|
configureServer(server) {
|
|
2181
|
-
server.middlewares.use((
|
|
2182
|
-
server.middlewares.use(
|
|
2254
|
+
server.middlewares.use(cors());
|
|
2255
|
+
server.middlewares.use(bodyParser.json({ limit: "5mb" }));
|
|
2183
2256
|
server.middlewares.use(async (req, res, next) => {
|
|
2184
|
-
|
|
2185
|
-
const mediaPaths = (_a = configManager.config.media) == null ? void 0 : _a.tina;
|
|
2257
|
+
const mediaPaths = configManager.config.media?.tina;
|
|
2186
2258
|
const mediaRouter = createMediaRouter({
|
|
2187
2259
|
rootPath: configManager.rootPath,
|
|
2188
2260
|
apiURL,
|
|
2189
|
-
publicFolder: parseMediaFolder(
|
|
2190
|
-
mediaRoot: parseMediaFolder(
|
|
2261
|
+
publicFolder: parseMediaFolder(mediaPaths?.publicFolder || ""),
|
|
2262
|
+
mediaRoot: parseMediaFolder(mediaPaths?.mediaRoot || "")
|
|
2191
2263
|
});
|
|
2192
2264
|
const searchIndexRouter = createSearchIndexRouter({
|
|
2193
2265
|
config: { apiURL, searchPath: "searchIndex" },
|
|
@@ -2219,7 +2291,7 @@ var devServerEndPointsPlugin = ({
|
|
|
2219
2291
|
const { query, variables } = req.body;
|
|
2220
2292
|
let result;
|
|
2221
2293
|
await databaseLock(async () => {
|
|
2222
|
-
result = await (
|
|
2294
|
+
result = await gqlResolve({
|
|
2223
2295
|
config: {
|
|
2224
2296
|
useRelativeMedia: true
|
|
2225
2297
|
},
|
|
@@ -2255,13 +2327,13 @@ function viteTransformExtension({
|
|
|
2255
2327
|
include = "**/*.svg",
|
|
2256
2328
|
exclude
|
|
2257
2329
|
} = {}) {
|
|
2258
|
-
const filter =
|
|
2330
|
+
const filter = createFilter(include, exclude);
|
|
2259
2331
|
return {
|
|
2260
2332
|
name: "vite-plugin-svgr",
|
|
2261
2333
|
async transform(code, id) {
|
|
2262
2334
|
if (filter(id)) {
|
|
2263
|
-
const { transform: transform2 } = await
|
|
2264
|
-
const svgCode = await
|
|
2335
|
+
const { transform: transform2 } = await import("@svgr/core");
|
|
2336
|
+
const svgCode = await fs6.promises.readFile(
|
|
2265
2337
|
id.replace(/\?.*$/, ""),
|
|
2266
2338
|
"utf8"
|
|
2267
2339
|
);
|
|
@@ -2271,7 +2343,7 @@ function viteTransformExtension({
|
|
|
2271
2343
|
previousExport: exportAsDefault ? null : code
|
|
2272
2344
|
}
|
|
2273
2345
|
});
|
|
2274
|
-
const res = await
|
|
2346
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
2275
2347
|
loader: "jsx",
|
|
2276
2348
|
...esbuildOptions
|
|
2277
2349
|
});
|
|
@@ -2298,7 +2370,7 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2298
2370
|
}),
|
|
2299
2371
|
viteTransformExtension()
|
|
2300
2372
|
];
|
|
2301
|
-
return (
|
|
2373
|
+
return createViteServer(
|
|
2302
2374
|
await createConfig({
|
|
2303
2375
|
configManager,
|
|
2304
2376
|
database,
|
|
@@ -2328,23 +2400,30 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2328
2400
|
|
|
2329
2401
|
// src/next/commands/dev-command/index.ts
|
|
2330
2402
|
var DevCommand = class extends BaseCommand {
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
this
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2403
|
+
static paths = [["dev"], ["server:start"]];
|
|
2404
|
+
// NOTE: camelCase commands for string options don't work if there's an `=` used https://github.com/arcanis/clipanion/issues/141
|
|
2405
|
+
watchFolders = Option2.String("-w,--watchFolders", {
|
|
2406
|
+
description: "DEPRECATED - a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
2407
|
+
});
|
|
2408
|
+
noWatch = Option2.Boolean("--noWatch", false, {
|
|
2409
|
+
description: "Don't regenerate config on file changes"
|
|
2410
|
+
});
|
|
2411
|
+
outputSearchIndexPath = Option2.String("--outputSearchIndexPath", {
|
|
2412
|
+
description: "Path to write the search index to"
|
|
2413
|
+
});
|
|
2414
|
+
noServer = Option2.Boolean("--no-server", false, {
|
|
2415
|
+
description: "Do not start the dev server"
|
|
2416
|
+
});
|
|
2417
|
+
indexingLock = new AsyncLock();
|
|
2418
|
+
// Prevent indexes and reads occurring at once
|
|
2419
|
+
static usage = Command2.Usage({
|
|
2420
|
+
category: `Commands`,
|
|
2421
|
+
description: `Builds Tina and starts the dev server`,
|
|
2422
|
+
examples: [
|
|
2423
|
+
[`A basic example`, `$0 dev`],
|
|
2424
|
+
[`A second example`, `$0 dev --rootPath`]
|
|
2425
|
+
]
|
|
2426
|
+
});
|
|
2348
2427
|
async catch(error) {
|
|
2349
2428
|
logger.error("Error occured during tinacms dev");
|
|
2350
2429
|
console.error(error);
|
|
@@ -2359,7 +2438,6 @@ var DevCommand = class extends BaseCommand {
|
|
|
2359
2438
|
}
|
|
2360
2439
|
}
|
|
2361
2440
|
async execute() {
|
|
2362
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2363
2441
|
const configManager = new ConfigManager({
|
|
2364
2442
|
rootPath: this.rootPath,
|
|
2365
2443
|
legacyNoSDK: this.noSDK
|
|
@@ -2382,7 +2460,7 @@ var DevCommand = class extends BaseCommand {
|
|
|
2382
2460
|
} else {
|
|
2383
2461
|
database.clearCache();
|
|
2384
2462
|
}
|
|
2385
|
-
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await
|
|
2463
|
+
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await buildSchema(configManager.config);
|
|
2386
2464
|
const codegen2 = new Codegen({
|
|
2387
2465
|
isLocal: true,
|
|
2388
2466
|
configManager,
|
|
@@ -2396,29 +2474,32 @@ var DevCommand = class extends BaseCommand {
|
|
|
2396
2474
|
});
|
|
2397
2475
|
const apiURL2 = await codegen2.execute();
|
|
2398
2476
|
if (!configManager.isUsingLegacyFolder) {
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
const
|
|
2403
|
-
|
|
2404
|
-
|
|
2477
|
+
const schemaObject = await fs7.readJSON(
|
|
2478
|
+
configManager.generatedSchemaJSONPath
|
|
2479
|
+
);
|
|
2480
|
+
const lookupObject = await fs7.readJSON(
|
|
2481
|
+
configManager.generatedLookupJSONPath
|
|
2482
|
+
);
|
|
2483
|
+
const graphqlSchemaObject = await fs7.readJSON(
|
|
2484
|
+
configManager.generatedGraphQLJSONPath
|
|
2485
|
+
);
|
|
2405
2486
|
const tinaLockFilename = "tina-lock.json";
|
|
2406
2487
|
const tinaLockContent = JSON.stringify({
|
|
2407
2488
|
schema: schemaObject,
|
|
2408
2489
|
lookup: lookupObject,
|
|
2409
2490
|
graphql: graphqlSchemaObject
|
|
2410
2491
|
});
|
|
2411
|
-
|
|
2412
|
-
|
|
2492
|
+
fs7.writeFileSync(
|
|
2493
|
+
path8.join(configManager.tinaFolderPath, tinaLockFilename),
|
|
2413
2494
|
tinaLockContent
|
|
2414
2495
|
);
|
|
2415
2496
|
if (configManager.hasSeparateContentRoot()) {
|
|
2416
2497
|
const rootPath = await configManager.getTinaFolderPath(
|
|
2417
2498
|
configManager.contentRootPath
|
|
2418
2499
|
);
|
|
2419
|
-
const filePath =
|
|
2420
|
-
await
|
|
2421
|
-
await
|
|
2500
|
+
const filePath = path8.join(rootPath, tinaLockFilename);
|
|
2501
|
+
await fs7.ensureFile(filePath);
|
|
2502
|
+
await fs7.outputFile(filePath, tinaLockContent);
|
|
2422
2503
|
}
|
|
2423
2504
|
}
|
|
2424
2505
|
await this.indexContentWithSpinner({
|
|
@@ -2461,25 +2542,25 @@ ${dangerText(e.message)}
|
|
|
2461
2542
|
const { apiURL, graphQLSchema, tinaSchema } = await setup({
|
|
2462
2543
|
firstTime: true
|
|
2463
2544
|
});
|
|
2464
|
-
await
|
|
2465
|
-
await
|
|
2545
|
+
await fs7.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
2546
|
+
await fs7.outputFile(
|
|
2466
2547
|
configManager.outputGitignorePath,
|
|
2467
2548
|
"index.html\nassets/"
|
|
2468
2549
|
);
|
|
2469
|
-
const searchIndexClient = new
|
|
2470
|
-
stopwordLanguages:
|
|
2471
|
-
tokenSplitRegex:
|
|
2550
|
+
const searchIndexClient = new LocalSearchIndexClient({
|
|
2551
|
+
stopwordLanguages: configManager.config.search?.tina?.stopwordLanguages,
|
|
2552
|
+
tokenSplitRegex: configManager.config.search?.tina?.tokenSplitRegex
|
|
2472
2553
|
});
|
|
2473
2554
|
await searchIndexClient.onStartIndexing();
|
|
2474
|
-
const searchIndexer = new
|
|
2475
|
-
batchSize:
|
|
2476
|
-
bridge: new
|
|
2555
|
+
const searchIndexer = new SearchIndexer({
|
|
2556
|
+
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
2557
|
+
bridge: new FilesystemBridge2(
|
|
2477
2558
|
configManager.rootPath,
|
|
2478
2559
|
configManager.contentRootPath
|
|
2479
2560
|
),
|
|
2480
2561
|
schema: tinaSchema,
|
|
2481
2562
|
client: searchIndexClient,
|
|
2482
|
-
textIndexLength:
|
|
2563
|
+
textIndexLength: configManager.config.search?.maxSearchIndexFieldLength || 100
|
|
2483
2564
|
});
|
|
2484
2565
|
if (configManager.config.search) {
|
|
2485
2566
|
await spin({
|
|
@@ -2514,7 +2595,7 @@ ${dangerText(e.message)}
|
|
|
2514
2595
|
);
|
|
2515
2596
|
await server.listen(Number(this.port));
|
|
2516
2597
|
if (!this.noWatch) {
|
|
2517
|
-
|
|
2598
|
+
chokidar.watch(configManager.watchList).on("change", async () => {
|
|
2518
2599
|
await dbLock(async () => {
|
|
2519
2600
|
logger.info(`Tina config change detected, rebuilding`);
|
|
2520
2601
|
await setup({ firstTime: false });
|
|
@@ -2576,11 +2657,11 @@ ${dangerText(e.message)}
|
|
|
2576
2657
|
// subItems: [
|
|
2577
2658
|
// {
|
|
2578
2659
|
// key: 'Custom queries',
|
|
2579
|
-
// value: 'https://tina.io/
|
|
2660
|
+
// value: 'https://tina.io/docs/r/content-api-overview',
|
|
2580
2661
|
// },
|
|
2581
2662
|
// {
|
|
2582
2663
|
// key: 'Visual editing',
|
|
2583
|
-
// value: 'https://tina.io/visual-editing',
|
|
2664
|
+
// value: 'https://tina.io/docs/r/visual-editing-setup',
|
|
2584
2665
|
// },
|
|
2585
2666
|
// ],
|
|
2586
2667
|
// },
|
|
@@ -2591,14 +2672,14 @@ ${dangerText(e.message)}
|
|
|
2591
2672
|
watchContentFiles(configManager, database, databaseLock, searchIndexer) {
|
|
2592
2673
|
const collectionContentFiles = [];
|
|
2593
2674
|
configManager.config.schema.collections.forEach((collection) => {
|
|
2594
|
-
const collectionGlob = `${
|
|
2675
|
+
const collectionGlob = `${path8.join(
|
|
2595
2676
|
configManager.contentRootPath,
|
|
2596
2677
|
collection.path
|
|
2597
2678
|
)}/**/*.${collection.format || "md"}`;
|
|
2598
2679
|
collectionContentFiles.push(collectionGlob);
|
|
2599
2680
|
});
|
|
2600
2681
|
let ready = false;
|
|
2601
|
-
|
|
2682
|
+
chokidar.watch(collectionContentFiles).on("ready", () => {
|
|
2602
2683
|
ready = true;
|
|
2603
2684
|
}).on("add", async (addedFile) => {
|
|
2604
2685
|
if (!ready) {
|
|
@@ -2635,38 +2716,35 @@ ${dangerText(e.message)}
|
|
|
2635
2716
|
await callback();
|
|
2636
2717
|
});
|
|
2637
2718
|
};
|
|
2638
|
-
|
|
2719
|
+
chokidar.watch(configManager.userQueriesAndFragmentsGlob).on("add", executeCallback).on("change", executeCallback).on("unlink", executeCallback);
|
|
2639
2720
|
}
|
|
2640
2721
|
};
|
|
2641
|
-
DevCommand.paths = [["dev"], ["server:start"]];
|
|
2642
|
-
// Prevent indexes and reads occurring at once
|
|
2643
|
-
DevCommand.usage = import_clipanion2.Command.Usage({
|
|
2644
|
-
category: `Commands`,
|
|
2645
|
-
description: `Builds Tina and starts the dev server`,
|
|
2646
|
-
examples: [
|
|
2647
|
-
[`A basic example`, `$0 dev`],
|
|
2648
|
-
[`A second example`, `$0 dev --rootPath`]
|
|
2649
|
-
]
|
|
2650
|
-
});
|
|
2651
2722
|
|
|
2652
2723
|
// src/next/commands/build-command/index.ts
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2724
|
+
import crypto from "crypto";
|
|
2725
|
+
import path9 from "path";
|
|
2726
|
+
import { diff } from "@graphql-inspector/core";
|
|
2727
|
+
import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
|
|
2728
|
+
import { parseURL as parseURL2 } from "@tinacms/schema-tools";
|
|
2729
|
+
import {
|
|
2730
|
+
SearchIndexer as SearchIndexer2,
|
|
2731
|
+
TinaCMSSearchIndexClient
|
|
2732
|
+
} from "@tinacms/search";
|
|
2733
|
+
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
2734
|
+
import fs8 from "fs-extra";
|
|
2735
|
+
import {
|
|
2736
|
+
buildASTSchema as buildASTSchema2,
|
|
2737
|
+
buildClientSchema,
|
|
2738
|
+
getIntrospectionQuery
|
|
2739
|
+
} from "graphql";
|
|
2740
|
+
import Progress2 from "progress";
|
|
2663
2741
|
|
|
2664
2742
|
// src/utils/index.ts
|
|
2665
|
-
|
|
2743
|
+
import { ChangeType } from "@graphql-inspector/core";
|
|
2666
2744
|
var getFaqLink = (type) => {
|
|
2667
2745
|
switch (type) {
|
|
2668
|
-
case
|
|
2669
|
-
return "https://tina.io/docs/
|
|
2746
|
+
case ChangeType.FieldRemoved: {
|
|
2747
|
+
return "https://tina.io/docs/r/FAQ/#2-how-do-i-resolve-the-local-graphql-schema-doesnt-match-the-remote-graphql-schema-error";
|
|
2670
2748
|
}
|
|
2671
2749
|
default:
|
|
2672
2750
|
return null;
|
|
@@ -2687,7 +2765,7 @@ async function sleepAndCallFunc({
|
|
|
2687
2765
|
}
|
|
2688
2766
|
|
|
2689
2767
|
// src/next/commands/build-command/server.ts
|
|
2690
|
-
|
|
2768
|
+
import { build as build2 } from "vite";
|
|
2691
2769
|
var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
2692
2770
|
const publicEnv = {};
|
|
2693
2771
|
Object.keys(process.env).forEach((key) => {
|
|
@@ -2721,12 +2799,12 @@ var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
|
2721
2799
|
}
|
|
2722
2800
|
}
|
|
2723
2801
|
});
|
|
2724
|
-
return (
|
|
2802
|
+
return build2(config2);
|
|
2725
2803
|
};
|
|
2726
2804
|
|
|
2727
2805
|
// src/next/commands/build-command/waitForDB.ts
|
|
2728
|
-
|
|
2729
|
-
|
|
2806
|
+
import { parseURL } from "@tinacms/schema-tools";
|
|
2807
|
+
import Progress from "progress";
|
|
2730
2808
|
var POLLING_INTERVAL = 5e3;
|
|
2731
2809
|
var STATUS_INPROGRESS = "inprogress";
|
|
2732
2810
|
var STATUS_COMPLETE = "complete";
|
|
@@ -2739,14 +2817,14 @@ var IndexFailedError = class extends Error {
|
|
|
2739
2817
|
};
|
|
2740
2818
|
var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
2741
2819
|
const token = config2.token;
|
|
2742
|
-
const { clientId, branch, isLocalClient, host } =
|
|
2820
|
+
const { clientId, branch, isLocalClient, host } = parseURL(apiUrl);
|
|
2743
2821
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
2744
2822
|
if (verbose) {
|
|
2745
2823
|
logger.info(logText("Not using TinaCloud, skipping DB check"));
|
|
2746
2824
|
}
|
|
2747
2825
|
return;
|
|
2748
2826
|
}
|
|
2749
|
-
const bar2 = new
|
|
2827
|
+
const bar2 = new Progress(
|
|
2750
2828
|
"Checking indexing process in TinaCloud... :prog",
|
|
2751
2829
|
1
|
|
2752
2830
|
);
|
|
@@ -2809,48 +2887,49 @@ var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
|
2809
2887
|
|
|
2810
2888
|
// src/next/commands/build-command/index.ts
|
|
2811
2889
|
var BuildCommand = class extends BaseCommand {
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2890
|
+
static paths = [["build"]];
|
|
2891
|
+
localOption = Option3.Boolean("--local", {
|
|
2892
|
+
description: "Starts local Graphql server and builds the local client instead of production client"
|
|
2893
|
+
});
|
|
2894
|
+
skipIndexing = Option3.Boolean("--skip-indexing", false, {
|
|
2895
|
+
description: "Skips indexing the content. This can be used for building the site without indexing the content (defaults to false)"
|
|
2896
|
+
});
|
|
2897
|
+
partialReindex = Option3.Boolean("--partial-reindex", false, {
|
|
2898
|
+
description: "Re-indexes only the content that has changed since the last build (defaults to false). Not currently supported for separate content repos."
|
|
2899
|
+
});
|
|
2900
|
+
tinaGraphQLVersion = Option3.String("--tina-graphql-version", {
|
|
2901
|
+
description: "Specify the version of @tinacms/graphql to use (defaults to latest)"
|
|
2902
|
+
});
|
|
2903
|
+
/**
|
|
2904
|
+
* This option allows the user to skip the TinaCloud checks if they want to. This could be useful for mismatched GraphQL versions or if they want to build only using the local client and never connect to TinaCloud
|
|
2905
|
+
*/
|
|
2906
|
+
skipCloudChecks = Option3.Boolean("--skip-cloud-checks", false, {
|
|
2907
|
+
description: "Skips checking the provided cloud config."
|
|
2908
|
+
});
|
|
2909
|
+
skipSearchIndex = Option3.Boolean("--skip-search-index", false, {
|
|
2910
|
+
description: "Skip indexing the site for search"
|
|
2911
|
+
});
|
|
2912
|
+
upstreamBranch = Option3.String("--upstream-branch", {
|
|
2913
|
+
description: "Optional upstream branch with the schema. If not specified, default will be used."
|
|
2914
|
+
});
|
|
2915
|
+
previewBaseBranch = Option3.String("--preview-base-branch", {
|
|
2916
|
+
description: "The base branch for the preview"
|
|
2917
|
+
});
|
|
2918
|
+
previewName = Option3.String("--preview-name", {
|
|
2919
|
+
description: "The name of the preview branch"
|
|
2920
|
+
});
|
|
2921
|
+
noClientBuildCache = Option3.Boolean("--no-client-build-cache", false, {
|
|
2922
|
+
description: "Disables the client build cache"
|
|
2923
|
+
});
|
|
2924
|
+
static usage = Command3.Usage({
|
|
2925
|
+
category: `Commands`,
|
|
2926
|
+
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2927
|
+
});
|
|
2848
2928
|
async catch(error) {
|
|
2849
2929
|
console.error(error);
|
|
2850
2930
|
process.exit(1);
|
|
2851
2931
|
}
|
|
2852
2932
|
async execute() {
|
|
2853
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2854
2933
|
logger.info("Starting Tina build");
|
|
2855
2934
|
this.logDeprecationWarnings();
|
|
2856
2935
|
const configManager = new ConfigManager({
|
|
@@ -2890,7 +2969,7 @@ ${dangerText(e.message)}`);
|
|
|
2890
2969
|
configManager,
|
|
2891
2970
|
Number(this.datalayerPort)
|
|
2892
2971
|
);
|
|
2893
|
-
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await (
|
|
2972
|
+
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await buildSchema2(configManager.config);
|
|
2894
2973
|
const codegen2 = new Codegen({
|
|
2895
2974
|
configManager,
|
|
2896
2975
|
port: this.localOption ? Number(this.port) : void 0,
|
|
@@ -2939,56 +3018,74 @@ ${dangerText(e.message)}
|
|
|
2939
3018
|
}
|
|
2940
3019
|
const skipCloudChecks = this.skipCloudChecks || configManager.hasSelfHostedConfig();
|
|
2941
3020
|
if (!skipCloudChecks) {
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
if (!hasUpstream && this.upstreamBranch) {
|
|
2948
|
-
logger.warn(
|
|
2949
|
-
`${dangerText(
|
|
2950
|
-
`WARN: Upstream branch '${this.upstreamBranch}' specified but no upstream project was found.`
|
|
2951
|
-
)}`
|
|
3021
|
+
try {
|
|
3022
|
+
const clientInfo = await this.checkClientInfo(
|
|
3023
|
+
configManager,
|
|
3024
|
+
codegen2.productionUrl,
|
|
3025
|
+
this.previewBaseBranch
|
|
2952
3026
|
);
|
|
3027
|
+
if (clientInfo.detectedBotBranch) {
|
|
3028
|
+
logger.warn(
|
|
3029
|
+
`${warnText(
|
|
3030
|
+
`WARN: Detected bot branch. Using schema/content from default branch '${clientInfo.defaultBranch}' instead of '${configManager.config.branch}'.`
|
|
3031
|
+
)}`
|
|
3032
|
+
);
|
|
3033
|
+
}
|
|
3034
|
+
if (!clientInfo.hasUpstream && this.upstreamBranch) {
|
|
3035
|
+
logger.warn(
|
|
3036
|
+
`${dangerText(
|
|
3037
|
+
`WARN: Upstream branch '${this.upstreamBranch}' specified but no upstream project was found.`
|
|
3038
|
+
)}`
|
|
3039
|
+
);
|
|
3040
|
+
}
|
|
3041
|
+
if (clientInfo.hasUpstream || this.previewBaseBranch && this.previewName) {
|
|
3042
|
+
await this.syncProject(configManager, codegen2.productionUrl, {
|
|
3043
|
+
upstreamBranch: this.upstreamBranch,
|
|
3044
|
+
previewBaseBranch: this.previewBaseBranch,
|
|
3045
|
+
previewName: this.previewName
|
|
3046
|
+
});
|
|
3047
|
+
}
|
|
3048
|
+
await waitForDB(
|
|
3049
|
+
configManager.config,
|
|
3050
|
+
codegen2.productionUrl,
|
|
3051
|
+
this.previewName,
|
|
3052
|
+
false
|
|
3053
|
+
);
|
|
3054
|
+
await this.checkGraphqlSchema(
|
|
3055
|
+
configManager,
|
|
3056
|
+
database,
|
|
3057
|
+
codegen2.productionUrl,
|
|
3058
|
+
clientInfo.timestamp
|
|
3059
|
+
);
|
|
3060
|
+
await this.checkTinaSchema(
|
|
3061
|
+
configManager,
|
|
3062
|
+
database,
|
|
3063
|
+
codegen2.productionUrl,
|
|
3064
|
+
this.previewName,
|
|
3065
|
+
this.verbose,
|
|
3066
|
+
clientInfo.timestamp
|
|
3067
|
+
);
|
|
3068
|
+
} catch (e) {
|
|
3069
|
+
logger.error(`
|
|
3070
|
+
|
|
3071
|
+
${dangerText(e.message)}
|
|
3072
|
+
`);
|
|
3073
|
+
if (this.verbose) {
|
|
3074
|
+
console.error(e);
|
|
3075
|
+
}
|
|
3076
|
+
process.exit(1);
|
|
2953
3077
|
}
|
|
2954
|
-
if (hasUpstream || this.previewBaseBranch && this.previewName) {
|
|
2955
|
-
await this.syncProject(configManager, codegen2.productionUrl, {
|
|
2956
|
-
upstreamBranch: this.upstreamBranch,
|
|
2957
|
-
previewBaseBranch: this.previewBaseBranch,
|
|
2958
|
-
previewName: this.previewName
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
await waitForDB(
|
|
2962
|
-
configManager.config,
|
|
2963
|
-
codegen2.productionUrl,
|
|
2964
|
-
this.previewName,
|
|
2965
|
-
false
|
|
2966
|
-
);
|
|
2967
|
-
await this.checkGraphqlSchema(
|
|
2968
|
-
configManager,
|
|
2969
|
-
database,
|
|
2970
|
-
codegen2.productionUrl,
|
|
2971
|
-
timestamp
|
|
2972
|
-
);
|
|
2973
|
-
await this.checkTinaSchema(
|
|
2974
|
-
configManager,
|
|
2975
|
-
database,
|
|
2976
|
-
codegen2.productionUrl,
|
|
2977
|
-
this.previewName,
|
|
2978
|
-
this.verbose,
|
|
2979
|
-
timestamp
|
|
2980
|
-
);
|
|
2981
3078
|
}
|
|
2982
3079
|
await buildProductionSpa(configManager, database, codegen2.productionUrl);
|
|
2983
|
-
await
|
|
3080
|
+
await fs8.outputFile(
|
|
2984
3081
|
configManager.outputGitignorePath,
|
|
2985
3082
|
"index.html\nassets/"
|
|
2986
3083
|
);
|
|
2987
3084
|
if (configManager.config.search && !this.skipSearchIndex && !this.localOption) {
|
|
2988
3085
|
let client;
|
|
2989
|
-
const hasTinaSearch = Boolean(
|
|
3086
|
+
const hasTinaSearch = Boolean(configManager.config?.search?.tina);
|
|
2990
3087
|
if (hasTinaSearch) {
|
|
2991
|
-
if (!
|
|
3088
|
+
if (!configManager.config?.branch) {
|
|
2992
3089
|
logger.error(
|
|
2993
3090
|
`${dangerText(
|
|
2994
3091
|
`ERROR: Branch not configured in tina search configuration.`
|
|
@@ -2998,11 +3095,11 @@ ${dangerText(e.message)}
|
|
|
2998
3095
|
"Branch not configured in tina search configuration."
|
|
2999
3096
|
);
|
|
3000
3097
|
}
|
|
3001
|
-
if (!
|
|
3098
|
+
if (!configManager.config?.clientId) {
|
|
3002
3099
|
logger.error(`${dangerText(`ERROR: clientId not configured.`)}`);
|
|
3003
3100
|
throw new Error("clientId not configured.");
|
|
3004
3101
|
}
|
|
3005
|
-
if (!
|
|
3102
|
+
if (!configManager.config?.search?.tina?.indexerToken) {
|
|
3006
3103
|
logger.error(
|
|
3007
3104
|
`${dangerText(
|
|
3008
3105
|
`ERROR: indexerToken not configured in tina search configuration.`
|
|
@@ -3012,18 +3109,18 @@ ${dangerText(e.message)}
|
|
|
3012
3109
|
"indexerToken not configured in tina search configuration."
|
|
3013
3110
|
);
|
|
3014
3111
|
}
|
|
3015
|
-
client = new
|
|
3016
|
-
apiUrl: `${
|
|
3017
|
-
branch:
|
|
3018
|
-
indexerToken:
|
|
3019
|
-
stopwordLanguages:
|
|
3112
|
+
client = new TinaCMSSearchIndexClient({
|
|
3113
|
+
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
3114
|
+
branch: configManager.config?.branch,
|
|
3115
|
+
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
3116
|
+
stopwordLanguages: configManager.config?.search?.tina?.stopwordLanguages
|
|
3020
3117
|
});
|
|
3021
3118
|
} else {
|
|
3022
|
-
client =
|
|
3119
|
+
client = configManager.config?.search?.searchClient;
|
|
3023
3120
|
}
|
|
3024
|
-
const searchIndexer = new
|
|
3025
|
-
batchSize:
|
|
3026
|
-
bridge: new
|
|
3121
|
+
const searchIndexer = new SearchIndexer2({
|
|
3122
|
+
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
3123
|
+
bridge: new FilesystemBridge3(
|
|
3027
3124
|
configManager.rootPath,
|
|
3028
3125
|
configManager.contentRootPath
|
|
3029
3126
|
),
|
|
@@ -3090,86 +3187,88 @@ ${dangerText(e.message)}
|
|
|
3090
3187
|
}
|
|
3091
3188
|
}
|
|
3092
3189
|
async checkClientInfo(configManager, apiURL, previewBaseBranch) {
|
|
3190
|
+
const MAX_RETRIES = 5;
|
|
3093
3191
|
const { config: config2 } = configManager;
|
|
3094
3192
|
const token = config2.token;
|
|
3095
|
-
const { clientId, branch, host } = (
|
|
3096
|
-
const
|
|
3097
|
-
const
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3193
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3194
|
+
const bar2 = new Progress2("Checking clientId and token. :prog", 1);
|
|
3195
|
+
const getBranchInfo = async () => {
|
|
3196
|
+
const url = `https://${host}/db/${clientId}/status/${previewBaseBranch || branch}`;
|
|
3197
|
+
const branchInfo2 = {
|
|
3198
|
+
status: "unknown",
|
|
3199
|
+
branchKnown: false,
|
|
3200
|
+
hasUpstream: false,
|
|
3201
|
+
timestamp: 0,
|
|
3202
|
+
detectedBotBranch: false,
|
|
3203
|
+
defaultBranch: void 0
|
|
3204
|
+
};
|
|
3205
|
+
try {
|
|
3206
|
+
const res = await request({
|
|
3207
|
+
token,
|
|
3208
|
+
url
|
|
3209
|
+
});
|
|
3210
|
+
branchInfo2.status = res.status;
|
|
3211
|
+
branchInfo2.branchKnown = res.status !== "unknown";
|
|
3212
|
+
branchInfo2.timestamp = res.timestamp || 0;
|
|
3213
|
+
branchInfo2.hasUpstream = res.hasUpstream;
|
|
3214
|
+
branchInfo2.detectedBotBranch = res.json.detectedBotBranch;
|
|
3215
|
+
branchInfo2.defaultBranch = res.json.defaultBranch;
|
|
3216
|
+
} catch (e) {
|
|
3217
|
+
summary({
|
|
3218
|
+
heading: "Error when checking client information",
|
|
3219
|
+
items: [
|
|
3220
|
+
{
|
|
3221
|
+
emoji: "\u274C",
|
|
3222
|
+
heading: "You provided",
|
|
3223
|
+
subItems: [
|
|
3224
|
+
{
|
|
3225
|
+
key: "clientId",
|
|
3226
|
+
value: config2.clientId
|
|
3227
|
+
},
|
|
3228
|
+
{
|
|
3229
|
+
key: "branch",
|
|
3230
|
+
value: config2.branch
|
|
3231
|
+
},
|
|
3232
|
+
{
|
|
3233
|
+
key: "token",
|
|
3234
|
+
value: config2.token
|
|
3235
|
+
}
|
|
3236
|
+
]
|
|
3237
|
+
}
|
|
3238
|
+
]
|
|
3239
|
+
});
|
|
3240
|
+
throw e;
|
|
3115
3241
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
},
|
|
3128
|
-
{
|
|
3129
|
-
key: "branch",
|
|
3130
|
-
value: config2.branch
|
|
3131
|
-
},
|
|
3132
|
-
{
|
|
3133
|
-
key: "token",
|
|
3134
|
-
value: config2.token
|
|
3135
|
-
}
|
|
3136
|
-
]
|
|
3137
|
-
}
|
|
3138
|
-
]
|
|
3139
|
-
});
|
|
3140
|
-
throw e;
|
|
3141
|
-
}
|
|
3142
|
-
const branchBar = new import_progress2.default("Checking branch is on TinaCloud. :prog", 1);
|
|
3143
|
-
if (branchKnown) {
|
|
3242
|
+
return branchInfo2;
|
|
3243
|
+
};
|
|
3244
|
+
const branchInfo = await getBranchInfo();
|
|
3245
|
+
bar2.tick({
|
|
3246
|
+
prog: "\u2705"
|
|
3247
|
+
});
|
|
3248
|
+
const branchBar = new Progress2(
|
|
3249
|
+
`Checking branch '${config2.branch}' is on TinaCloud. :prog`,
|
|
3250
|
+
1
|
|
3251
|
+
);
|
|
3252
|
+
if (branchInfo.branchKnown) {
|
|
3144
3253
|
branchBar.tick({
|
|
3145
3254
|
prog: "\u2705"
|
|
3146
3255
|
});
|
|
3147
|
-
return
|
|
3148
|
-
hasUpstream,
|
|
3149
|
-
timestamp
|
|
3150
|
-
};
|
|
3256
|
+
return branchInfo;
|
|
3151
3257
|
}
|
|
3152
|
-
for (let i =
|
|
3153
|
-
await
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
prog: "\u2705"
|
|
3167
|
-
});
|
|
3168
|
-
return;
|
|
3169
|
-
}
|
|
3170
|
-
},
|
|
3171
|
-
ms: 5e3
|
|
3172
|
-
});
|
|
3258
|
+
for (let i = 1; i <= MAX_RETRIES; i++) {
|
|
3259
|
+
await timeout(5e3);
|
|
3260
|
+
const branchInfo2 = await getBranchInfo();
|
|
3261
|
+
if (this.verbose) {
|
|
3262
|
+
logger.info(
|
|
3263
|
+
`Branch status: ${branchInfo2.status}. Attempt: ${i}. Trying again in 5 seconds.`
|
|
3264
|
+
);
|
|
3265
|
+
}
|
|
3266
|
+
if (branchInfo2.branchKnown) {
|
|
3267
|
+
branchBar.tick({
|
|
3268
|
+
prog: "\u2705"
|
|
3269
|
+
});
|
|
3270
|
+
return branchInfo2;
|
|
3271
|
+
}
|
|
3173
3272
|
}
|
|
3174
3273
|
branchBar.tick({
|
|
3175
3274
|
prog: "\u274C"
|
|
@@ -3177,7 +3276,7 @@ ${dangerText(e.message)}
|
|
|
3177
3276
|
logger.error(
|
|
3178
3277
|
`${dangerText(
|
|
3179
3278
|
`ERROR: Branch '${branch}' is not on TinaCloud.`
|
|
3180
|
-
)} Please make sure that branch '${branch}' exists in your repository and that you have pushed your all changes to the remote. View all
|
|
3279
|
+
)} Please make sure that branch '${branch}' exists in your repository and that you have pushed your all changes to the remote. View all branches and their current status here: ${linkText(
|
|
3181
3280
|
`https://app.tina.io/projects/${clientId}/configuration`
|
|
3182
3281
|
)}`
|
|
3183
3282
|
);
|
|
@@ -3186,7 +3285,7 @@ ${dangerText(e.message)}
|
|
|
3186
3285
|
async syncProject(configManager, apiURL, options) {
|
|
3187
3286
|
const { config: config2 } = configManager;
|
|
3188
3287
|
const token = config2.token;
|
|
3189
|
-
const { clientId, branch, host } = (
|
|
3288
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3190
3289
|
const { previewName, previewBaseBranch, upstreamBranch } = options || {};
|
|
3191
3290
|
let url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true`;
|
|
3192
3291
|
if (upstreamBranch && previewBaseBranch && previewName) {
|
|
@@ -3196,7 +3295,7 @@ ${dangerText(e.message)}
|
|
|
3196
3295
|
} else if (upstreamBranch && !previewBaseBranch && !previewName) {
|
|
3197
3296
|
url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true&upstreamBranch=${upstreamBranch}`;
|
|
3198
3297
|
}
|
|
3199
|
-
const bar2 = new
|
|
3298
|
+
const bar2 = new Progress2("Syncing Project. :prog", 1);
|
|
3200
3299
|
try {
|
|
3201
3300
|
const res = await request({
|
|
3202
3301
|
token,
|
|
@@ -3237,7 +3336,7 @@ ${dangerText(e.message)}
|
|
|
3237
3336
|
}
|
|
3238
3337
|
}
|
|
3239
3338
|
async checkGraphqlSchema(configManager, database, apiURL, timestamp) {
|
|
3240
|
-
const bar2 = new
|
|
3339
|
+
const bar2 = new Progress2(
|
|
3241
3340
|
"Checking local GraphQL Schema matches server. :prog",
|
|
3242
3341
|
1
|
|
3243
3342
|
);
|
|
@@ -3252,18 +3351,18 @@ ${dangerText(e.message)}
|
|
|
3252
3351
|
prog: "\u274C"
|
|
3253
3352
|
});
|
|
3254
3353
|
let errorMessage = `The remote GraphQL schema does not exist. Check indexing for this branch.`;
|
|
3255
|
-
if (config2
|
|
3354
|
+
if (config2?.branch) {
|
|
3256
3355
|
errorMessage += `
|
|
3257
3356
|
|
|
3258
3357
|
Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
3259
3358
|
}
|
|
3260
3359
|
throw new Error(errorMessage);
|
|
3261
3360
|
}
|
|
3262
|
-
const remoteGqlSchema =
|
|
3361
|
+
const remoteGqlSchema = buildClientSchema(remoteSchema);
|
|
3263
3362
|
const localSchemaDocument = await database.getGraphQLSchemaFromBridge();
|
|
3264
|
-
const localGraphqlSchema = (
|
|
3363
|
+
const localGraphqlSchema = buildASTSchema2(localSchemaDocument);
|
|
3265
3364
|
try {
|
|
3266
|
-
const diffResult = await
|
|
3365
|
+
const diffResult = await diff(remoteGqlSchema, localGraphqlSchema);
|
|
3267
3366
|
if (diffResult.length === 0) {
|
|
3268
3367
|
bar2.tick({
|
|
3269
3368
|
prog: "\u2705"
|
|
@@ -3284,7 +3383,7 @@ Check out '${faqLink}' for possible solutions.`}`;
|
|
|
3284
3383
|
Additional info:
|
|
3285
3384
|
|
|
3286
3385
|
`;
|
|
3287
|
-
if (config2
|
|
3386
|
+
if (config2?.branch) {
|
|
3288
3387
|
errorMessage += ` Branch: ${config2.branch}, Client ID: ${config2.clientId}
|
|
3289
3388
|
`;
|
|
3290
3389
|
}
|
|
@@ -3311,13 +3410,13 @@ Additional info:
|
|
|
3311
3410
|
}
|
|
3312
3411
|
}
|
|
3313
3412
|
async checkTinaSchema(configManager, database, apiURL, previewName, verbose, timestamp) {
|
|
3314
|
-
const bar2 = new
|
|
3413
|
+
const bar2 = new Progress2(
|
|
3315
3414
|
"Checking local Tina Schema matches server. :prog",
|
|
3316
3415
|
1
|
|
3317
3416
|
);
|
|
3318
3417
|
const { config: config2 } = configManager;
|
|
3319
3418
|
const token = config2.token;
|
|
3320
|
-
const { clientId, branch, isLocalClient, host } = (
|
|
3419
|
+
const { clientId, branch, isLocalClient, host } = parseURL2(apiURL);
|
|
3321
3420
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
3322
3421
|
if (verbose) {
|
|
3323
3422
|
logger.info(logText("Not using TinaCloud, skipping Tina Schema check"));
|
|
@@ -3333,7 +3432,7 @@ Additional info:
|
|
|
3333
3432
|
prog: "\u274C"
|
|
3334
3433
|
});
|
|
3335
3434
|
let errorMessage = `The remote Tina schema does not exist. Check indexing for this branch.`;
|
|
3336
|
-
if (config2
|
|
3435
|
+
if (config2?.branch) {
|
|
3337
3436
|
errorMessage += `
|
|
3338
3437
|
|
|
3339
3438
|
Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
@@ -3345,11 +3444,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3345
3444
|
}
|
|
3346
3445
|
const localTinaSchema = JSON.parse(
|
|
3347
3446
|
await database.bridge.get(
|
|
3348
|
-
|
|
3447
|
+
path9.join(database.tinaDirectory, "__generated__", "_schema.json")
|
|
3349
3448
|
)
|
|
3350
3449
|
);
|
|
3351
3450
|
localTinaSchema.version = void 0;
|
|
3352
|
-
const localTinaSchemaSha =
|
|
3451
|
+
const localTinaSchemaSha = crypto.createHash("sha256").update(JSON.stringify(localTinaSchema)).digest("hex");
|
|
3353
3452
|
if (localTinaSchemaSha === remoteTinaSchemaSha) {
|
|
3354
3453
|
bar2.tick({
|
|
3355
3454
|
prog: "\u2705"
|
|
@@ -3364,7 +3463,7 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3364
3463
|
Additional info:
|
|
3365
3464
|
|
|
3366
3465
|
`;
|
|
3367
|
-
if (config2
|
|
3466
|
+
if (config2?.branch) {
|
|
3368
3467
|
errorMessage += ` Branch: ${config2.branch}, Client ID: ${config2.clientId}
|
|
3369
3468
|
`;
|
|
3370
3469
|
}
|
|
@@ -3376,18 +3475,13 @@ Additional info:
|
|
|
3376
3475
|
}
|
|
3377
3476
|
}
|
|
3378
3477
|
};
|
|
3379
|
-
BuildCommand.paths = [["build"]];
|
|
3380
|
-
BuildCommand.usage = import_clipanion3.Command.Usage({
|
|
3381
|
-
category: `Commands`,
|
|
3382
|
-
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
3383
|
-
});
|
|
3384
3478
|
async function request(args) {
|
|
3385
3479
|
const headers = new Headers();
|
|
3386
3480
|
if (args.token) {
|
|
3387
3481
|
headers.append("X-API-KEY", args.token);
|
|
3388
3482
|
}
|
|
3389
3483
|
headers.append("Content-Type", "application/json");
|
|
3390
|
-
const url = args
|
|
3484
|
+
const url = args?.url;
|
|
3391
3485
|
const res = await fetch(url, {
|
|
3392
3486
|
method: args.method || "GET",
|
|
3393
3487
|
headers,
|
|
@@ -3405,21 +3499,22 @@ async function request(args) {
|
|
|
3405
3499
|
Message from server: ${json.message}`;
|
|
3406
3500
|
}
|
|
3407
3501
|
throw new Error(
|
|
3408
|
-
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/
|
|
3502
|
+
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/r/FAQ/`
|
|
3409
3503
|
);
|
|
3410
3504
|
}
|
|
3411
3505
|
if (json.errors) {
|
|
3412
3506
|
throw new Error(
|
|
3413
|
-
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/
|
|
3507
|
+
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/r/FAQ/
|
|
3414
3508
|
|
|
3415
3509
|
Errors:
|
|
3416
3510
|
${json.errors.map((error) => error.message).join("\n")}`
|
|
3417
3511
|
);
|
|
3418
3512
|
}
|
|
3419
3513
|
return {
|
|
3420
|
-
status: json
|
|
3421
|
-
timestamp: json
|
|
3422
|
-
hasUpstream:
|
|
3514
|
+
status: json?.status,
|
|
3515
|
+
timestamp: json?.timestamp,
|
|
3516
|
+
hasUpstream: json?.hasUpstream || false,
|
|
3517
|
+
json
|
|
3423
3518
|
};
|
|
3424
3519
|
}
|
|
3425
3520
|
var fetchRemoteGraphqlSchema = async ({
|
|
@@ -3431,7 +3526,7 @@ var fetchRemoteGraphqlSchema = async ({
|
|
|
3431
3526
|
headers.append("X-API-KEY", token);
|
|
3432
3527
|
}
|
|
3433
3528
|
const body = JSON.stringify({
|
|
3434
|
-
query:
|
|
3529
|
+
query: getIntrospectionQuery(),
|
|
3435
3530
|
variables: {}
|
|
3436
3531
|
});
|
|
3437
3532
|
headers.append("Content-Type", "application/json");
|
|
@@ -3442,7 +3537,7 @@ var fetchRemoteGraphqlSchema = async ({
|
|
|
3442
3537
|
});
|
|
3443
3538
|
const data = await res.json();
|
|
3444
3539
|
return {
|
|
3445
|
-
remoteSchema: data
|
|
3540
|
+
remoteSchema: data?.data,
|
|
3446
3541
|
remoteRuntimeVersion: res.headers.get("tinacms-grapqhl-version"),
|
|
3447
3542
|
remoteProjectVersion: res.headers.get("tinacms-graphql-project-version")
|
|
3448
3543
|
};
|
|
@@ -3464,14 +3559,14 @@ var fetchSchemaSha = async ({
|
|
|
3464
3559
|
};
|
|
3465
3560
|
|
|
3466
3561
|
// src/next/commands/audit-command/index.ts
|
|
3467
|
-
|
|
3468
|
-
|
|
3562
|
+
import { Command as Command4, Option as Option4 } from "clipanion";
|
|
3563
|
+
import { buildSchema as buildSchema3 } from "@tinacms/graphql";
|
|
3469
3564
|
|
|
3470
3565
|
// src/next/commands/audit-command/audit.ts
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3566
|
+
import prompts from "prompts";
|
|
3567
|
+
import { Telemetry } from "@tinacms/metrics";
|
|
3568
|
+
import { resolve } from "@tinacms/graphql";
|
|
3569
|
+
import chalk5 from "chalk";
|
|
3475
3570
|
var audit = async ({
|
|
3476
3571
|
database,
|
|
3477
3572
|
clean,
|
|
@@ -3479,7 +3574,7 @@ var audit = async ({
|
|
|
3479
3574
|
noTelemetry,
|
|
3480
3575
|
verbose
|
|
3481
3576
|
}) => {
|
|
3482
|
-
const telemetry = new
|
|
3577
|
+
const telemetry = new Telemetry({ disabled: noTelemetry });
|
|
3483
3578
|
await telemetry.submitRecord({
|
|
3484
3579
|
event: {
|
|
3485
3580
|
name: "tinacms:cli:audit:invoke",
|
|
@@ -3489,25 +3584,25 @@ var audit = async ({
|
|
|
3489
3584
|
});
|
|
3490
3585
|
if (clean) {
|
|
3491
3586
|
logger.info(
|
|
3492
|
-
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${
|
|
3587
|
+
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${chalk5.bold(
|
|
3493
3588
|
"clean git tree"
|
|
3494
3589
|
)} so unwanted changes can be undone.
|
|
3495
3590
|
|
|
3496
3591
|
`
|
|
3497
3592
|
);
|
|
3498
|
-
const res = await (
|
|
3593
|
+
const res = await prompts({
|
|
3499
3594
|
name: "useClean",
|
|
3500
3595
|
type: "confirm",
|
|
3501
3596
|
message: `Do you want to continue?`
|
|
3502
3597
|
});
|
|
3503
3598
|
if (!res.useClean) {
|
|
3504
|
-
logger.warn(
|
|
3599
|
+
logger.warn(chalk5.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
3505
3600
|
process.exit(0);
|
|
3506
3601
|
}
|
|
3507
3602
|
}
|
|
3508
3603
|
if (useDefaultValues && !clean) {
|
|
3509
3604
|
logger.warn(
|
|
3510
|
-
|
|
3605
|
+
chalk5.yellowBright(
|
|
3511
3606
|
"WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"
|
|
3512
3607
|
)
|
|
3513
3608
|
);
|
|
@@ -3535,10 +3630,10 @@ var audit = async ({
|
|
|
3535
3630
|
}
|
|
3536
3631
|
if (error) {
|
|
3537
3632
|
logger.error(
|
|
3538
|
-
|
|
3633
|
+
chalk5.redBright(`\u203C\uFE0F Audit ${chalk5.bold("failed")} with errors`)
|
|
3539
3634
|
);
|
|
3540
3635
|
} else {
|
|
3541
|
-
logger.info(
|
|
3636
|
+
logger.info(chalk5.greenBright("\u2705 Audit passed"));
|
|
3542
3637
|
}
|
|
3543
3638
|
};
|
|
3544
3639
|
var auditDocuments = async (args) => {
|
|
@@ -3555,7 +3650,7 @@ var auditDocuments = async (args) => {
|
|
|
3555
3650
|
}
|
|
3556
3651
|
}
|
|
3557
3652
|
}`;
|
|
3558
|
-
const docResult = await
|
|
3653
|
+
const docResult = await resolve({
|
|
3559
3654
|
database,
|
|
3560
3655
|
query: documentQuery,
|
|
3561
3656
|
variables: {},
|
|
@@ -3566,11 +3661,11 @@ var auditDocuments = async (args) => {
|
|
|
3566
3661
|
if (docResult.errors) {
|
|
3567
3662
|
error = true;
|
|
3568
3663
|
docResult.errors.forEach((err) => {
|
|
3569
|
-
logger.error(
|
|
3664
|
+
logger.error(chalk5.red(err.message));
|
|
3570
3665
|
if (err.originalError.originalError) {
|
|
3571
3666
|
logger.error(
|
|
3572
3667
|
// @ts-ignore FIXME: this doesn't seem right
|
|
3573
|
-
|
|
3668
|
+
chalk5.red(` ${err.originalError.originalError.message}`)
|
|
3574
3669
|
);
|
|
3575
3670
|
}
|
|
3576
3671
|
});
|
|
@@ -3597,7 +3692,7 @@ var auditDocuments = async (args) => {
|
|
|
3597
3692
|
params: $params
|
|
3598
3693
|
){__typename}
|
|
3599
3694
|
}`;
|
|
3600
|
-
const mutationRes = await
|
|
3695
|
+
const mutationRes = await resolve({
|
|
3601
3696
|
database,
|
|
3602
3697
|
query: mutation,
|
|
3603
3698
|
variables: {
|
|
@@ -3612,7 +3707,7 @@ var auditDocuments = async (args) => {
|
|
|
3612
3707
|
if (mutationRes.errors) {
|
|
3613
3708
|
mutationRes.errors.forEach((err) => {
|
|
3614
3709
|
error = true;
|
|
3615
|
-
logger.error(
|
|
3710
|
+
logger.error(chalk5.red(err.message));
|
|
3616
3711
|
});
|
|
3617
3712
|
}
|
|
3618
3713
|
}
|
|
@@ -3629,29 +3724,31 @@ function filterObject(obj) {
|
|
|
3629
3724
|
}
|
|
3630
3725
|
|
|
3631
3726
|
// src/next/commands/audit-command/index.ts
|
|
3632
|
-
|
|
3633
|
-
var AuditCommand = class extends
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3727
|
+
import { AuditFileSystemBridge } from "@tinacms/graphql";
|
|
3728
|
+
var AuditCommand = class extends Command4 {
|
|
3729
|
+
static paths = [["audit"]];
|
|
3730
|
+
rootPath = Option4.String("--rootPath", {
|
|
3731
|
+
description: "Specify the root directory to run the CLI from"
|
|
3732
|
+
});
|
|
3733
|
+
verbose = Option4.Boolean("-v,--verbose", false, {
|
|
3734
|
+
description: "increase verbosity of logged output"
|
|
3735
|
+
});
|
|
3736
|
+
clean = Option4.Boolean("--clean", false, {
|
|
3737
|
+
description: "Clean the output"
|
|
3738
|
+
});
|
|
3739
|
+
useDefaultValues = Option4.Boolean("--useDefaultValues", false, {
|
|
3740
|
+
description: "When cleaning the output, use defaults on the config"
|
|
3741
|
+
});
|
|
3742
|
+
noTelemetry = Option4.Boolean("--noTelemetry", false, {
|
|
3743
|
+
description: "Disable anonymous telemetry that is collected"
|
|
3744
|
+
});
|
|
3745
|
+
datalayerPort = Option4.String("--datalayer-port", "9000", {
|
|
3746
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
3747
|
+
});
|
|
3748
|
+
static usage = Command4.Usage({
|
|
3749
|
+
category: `Commands`,
|
|
3750
|
+
description: `Audit config and content files`
|
|
3751
|
+
});
|
|
3655
3752
|
async catch(error) {
|
|
3656
3753
|
logger.error("Error occured during tinacms audit");
|
|
3657
3754
|
if (this.verbose) {
|
|
@@ -3672,9 +3769,9 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3672
3769
|
const database = await createAndInitializeDatabase(
|
|
3673
3770
|
configManager,
|
|
3674
3771
|
Number(this.datalayerPort),
|
|
3675
|
-
this.clean ? void 0 : new
|
|
3772
|
+
this.clean ? void 0 : new AuditFileSystemBridge(configManager.rootPath)
|
|
3676
3773
|
);
|
|
3677
|
-
const { tinaSchema, graphQLSchema, lookup } = await (
|
|
3774
|
+
const { tinaSchema, graphQLSchema, lookup } = await buildSchema3(
|
|
3678
3775
|
configManager.config
|
|
3679
3776
|
);
|
|
3680
3777
|
const warnings = [];
|
|
@@ -3705,36 +3802,31 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3705
3802
|
process.exit();
|
|
3706
3803
|
}
|
|
3707
3804
|
};
|
|
3708
|
-
AuditCommand.paths = [["audit"]];
|
|
3709
|
-
AuditCommand.usage = import_clipanion4.Command.Usage({
|
|
3710
|
-
category: `Commands`,
|
|
3711
|
-
description: `Audit config and content files`
|
|
3712
|
-
});
|
|
3713
3805
|
|
|
3714
3806
|
// src/next/commands/init-command/index.ts
|
|
3715
|
-
|
|
3807
|
+
import { Command as Command6, Option as Option6 } from "clipanion";
|
|
3716
3808
|
|
|
3717
3809
|
// src/cmds/init/detectEnvironment.ts
|
|
3718
|
-
|
|
3719
|
-
|
|
3810
|
+
import fs9 from "fs-extra";
|
|
3811
|
+
import path10 from "path";
|
|
3720
3812
|
var checkGitignoreForItem = async ({
|
|
3721
3813
|
baseDir,
|
|
3722
3814
|
line
|
|
3723
3815
|
}) => {
|
|
3724
|
-
const gitignoreContent =
|
|
3816
|
+
const gitignoreContent = fs9.readFileSync(path10.join(baseDir, ".gitignore")).toString();
|
|
3725
3817
|
return gitignoreContent.split("\n").some((item) => item === line);
|
|
3726
3818
|
};
|
|
3727
3819
|
var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
3728
3820
|
const result = {
|
|
3729
|
-
fullPathTS:
|
|
3821
|
+
fullPathTS: path10.join(
|
|
3730
3822
|
parentPath,
|
|
3731
|
-
`${name2}.${
|
|
3823
|
+
`${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
|
|
3732
3824
|
),
|
|
3733
|
-
fullPathJS:
|
|
3825
|
+
fullPathJS: path10.join(
|
|
3734
3826
|
parentPath,
|
|
3735
|
-
`${name2}.${
|
|
3827
|
+
`${name2}.${opts?.extensionOverride || "js"}`
|
|
3736
3828
|
),
|
|
3737
|
-
fullPathOverride:
|
|
3829
|
+
fullPathOverride: opts?.extensionOverride ? path10.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
|
|
3738
3830
|
generatedFileType,
|
|
3739
3831
|
name: name2,
|
|
3740
3832
|
parentPath,
|
|
@@ -3752,8 +3844,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
|
3752
3844
|
};
|
|
3753
3845
|
}
|
|
3754
3846
|
};
|
|
3755
|
-
result.typescriptExists = await
|
|
3756
|
-
result.javascriptExists = await
|
|
3847
|
+
result.typescriptExists = await fs9.pathExists(result.fullPathTS);
|
|
3848
|
+
result.javascriptExists = await fs9.pathExists(result.fullPathJS);
|
|
3757
3849
|
return result;
|
|
3758
3850
|
};
|
|
3759
3851
|
var detectEnvironment = async ({
|
|
@@ -3762,22 +3854,21 @@ var detectEnvironment = async ({
|
|
|
3762
3854
|
rootPath,
|
|
3763
3855
|
debug = false
|
|
3764
3856
|
}) => {
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
import_path7.default.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
3857
|
+
const hasForestryConfig = await fs9.pathExists(
|
|
3858
|
+
path10.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
3768
3859
|
);
|
|
3769
|
-
const sampleContentPath =
|
|
3860
|
+
const sampleContentPath = path10.join(
|
|
3770
3861
|
baseDir,
|
|
3771
3862
|
"content",
|
|
3772
3863
|
"posts",
|
|
3773
3864
|
"hello-world.md"
|
|
3774
3865
|
);
|
|
3775
|
-
const usingSrc =
|
|
3776
|
-
const tinaFolder =
|
|
3866
|
+
const usingSrc = fs9.pathExistsSync(path10.join(baseDir, "src")) && (fs9.pathExistsSync(path10.join(baseDir, "src", "app")) || fs9.pathExistsSync(path10.join(baseDir, "src", "pages")));
|
|
3867
|
+
const tinaFolder = path10.join(baseDir, "tina");
|
|
3777
3868
|
const tinaConfigExists = Boolean(
|
|
3778
3869
|
// Does the tina folder exist?
|
|
3779
|
-
await
|
|
3780
|
-
(await
|
|
3870
|
+
await fs9.pathExists(tinaFolder) && // Does the tina folder contain a config file?
|
|
3871
|
+
(await fs9.readdir(tinaFolder)).find((x) => x.includes("config"))
|
|
3781
3872
|
);
|
|
3782
3873
|
const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
|
|
3783
3874
|
Boolean
|
|
@@ -3789,12 +3880,12 @@ var detectEnvironment = async ({
|
|
|
3789
3880
|
"next-api-handler": await makeGeneratedFile(
|
|
3790
3881
|
"[...routes]",
|
|
3791
3882
|
"next-api-handler",
|
|
3792
|
-
|
|
3883
|
+
path10.join(...pagesDir, "api", "tina")
|
|
3793
3884
|
),
|
|
3794
3885
|
"reactive-example": await makeGeneratedFile(
|
|
3795
3886
|
"[filename]",
|
|
3796
3887
|
"reactive-example",
|
|
3797
|
-
|
|
3888
|
+
path10.join(...pagesDir, "demo", "blog"),
|
|
3798
3889
|
{
|
|
3799
3890
|
typescriptSuffix: "tsx"
|
|
3800
3891
|
}
|
|
@@ -3802,27 +3893,27 @@ var detectEnvironment = async ({
|
|
|
3802
3893
|
"users-json": await makeGeneratedFile(
|
|
3803
3894
|
"index",
|
|
3804
3895
|
"users-json",
|
|
3805
|
-
|
|
3896
|
+
path10.join(baseDir, "content", "users"),
|
|
3806
3897
|
{ extensionOverride: "json" }
|
|
3807
3898
|
),
|
|
3808
3899
|
"sample-content": await makeGeneratedFile(
|
|
3809
3900
|
"hello-world",
|
|
3810
3901
|
"sample-content",
|
|
3811
|
-
|
|
3902
|
+
path10.join(baseDir, "content", "posts"),
|
|
3812
3903
|
{ extensionOverride: "md" }
|
|
3813
3904
|
)
|
|
3814
3905
|
};
|
|
3815
|
-
const hasSampleContent = await
|
|
3816
|
-
const hasPackageJSON = await
|
|
3906
|
+
const hasSampleContent = await fs9.pathExists(sampleContentPath);
|
|
3907
|
+
const hasPackageJSON = await fs9.pathExists("package.json");
|
|
3817
3908
|
let hasTinaDeps = false;
|
|
3818
3909
|
if (hasPackageJSON) {
|
|
3819
3910
|
try {
|
|
3820
|
-
const packageJSON = await
|
|
3911
|
+
const packageJSON = await fs9.readJSON("package.json");
|
|
3821
3912
|
const deps = [];
|
|
3822
|
-
if (packageJSON
|
|
3913
|
+
if (packageJSON?.dependencies) {
|
|
3823
3914
|
deps.push(...Object.keys(packageJSON.dependencies));
|
|
3824
3915
|
}
|
|
3825
|
-
if (packageJSON
|
|
3916
|
+
if (packageJSON?.devDependencies) {
|
|
3826
3917
|
deps.push(...Object.keys(packageJSON.devDependencies));
|
|
3827
3918
|
}
|
|
3828
3919
|
if (deps.includes("@tinacms/cli") && deps.includes("tinacms")) {
|
|
@@ -3834,16 +3925,16 @@ var detectEnvironment = async ({
|
|
|
3834
3925
|
);
|
|
3835
3926
|
}
|
|
3836
3927
|
}
|
|
3837
|
-
const hasGitIgnore = await
|
|
3928
|
+
const hasGitIgnore = await fs9.pathExists(path10.join(".gitignore"));
|
|
3838
3929
|
const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
|
|
3839
3930
|
const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
|
|
3840
3931
|
const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
|
|
3841
3932
|
let frontMatterFormat;
|
|
3842
3933
|
if (hasForestryConfig) {
|
|
3843
|
-
const hugoConfigPath =
|
|
3844
|
-
if (await
|
|
3845
|
-
const hugoConfig = await
|
|
3846
|
-
const metaDataFormat =
|
|
3934
|
+
const hugoConfigPath = path10.join(rootPath, "config.toml");
|
|
3935
|
+
if (await fs9.pathExists(hugoConfigPath)) {
|
|
3936
|
+
const hugoConfig = await fs9.readFile(hugoConfigPath, "utf8");
|
|
3937
|
+
const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
|
|
3847
3938
|
if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
|
|
3848
3939
|
frontMatterFormat = metaDataFormat;
|
|
3849
3940
|
}
|
|
@@ -3873,10 +3964,10 @@ var detectEnvironment = async ({
|
|
|
3873
3964
|
var detectEnvironment_default = detectEnvironment;
|
|
3874
3965
|
|
|
3875
3966
|
// src/cmds/init/prompts/index.ts
|
|
3876
|
-
|
|
3967
|
+
import prompts6 from "prompts";
|
|
3877
3968
|
|
|
3878
3969
|
// src/cmds/init/prompts/askTinaCloudSetup.ts
|
|
3879
|
-
|
|
3970
|
+
import prompts2 from "prompts";
|
|
3880
3971
|
var tinaCloudSetupQuestions = [
|
|
3881
3972
|
{
|
|
3882
3973
|
name: "clientId",
|
|
@@ -3898,7 +3989,7 @@ ${logText(
|
|
|
3898
3989
|
}
|
|
3899
3990
|
];
|
|
3900
3991
|
var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
3901
|
-
const { clientId, token } = await (
|
|
3992
|
+
const { clientId, token } = await prompts2(tinaCloudSetupQuestions);
|
|
3902
3993
|
config2.envVars.push(
|
|
3903
3994
|
{
|
|
3904
3995
|
key: "NEXT_PUBLIC_TINA_CLIENT_ID",
|
|
@@ -3912,7 +4003,7 @@ var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
|
3912
4003
|
};
|
|
3913
4004
|
|
|
3914
4005
|
// src/cmds/init/prompts/gitProvider.ts
|
|
3915
|
-
|
|
4006
|
+
import prompts3 from "prompts";
|
|
3916
4007
|
var supportedGitProviders = {
|
|
3917
4008
|
github: {
|
|
3918
4009
|
imports: [
|
|
@@ -3934,7 +4025,7 @@ var supportedGitProviders = {
|
|
|
3934
4025
|
}
|
|
3935
4026
|
};
|
|
3936
4027
|
var chooseGitProvider = async ({ config: config2 }) => {
|
|
3937
|
-
const result = await (
|
|
4028
|
+
const result = await prompts3([
|
|
3938
4029
|
{
|
|
3939
4030
|
name: "githubToken",
|
|
3940
4031
|
type: "text",
|
|
@@ -3942,7 +4033,7 @@ var chooseGitProvider = async ({ config: config2 }) => {
|
|
|
3942
4033
|
${logText(
|
|
3943
4034
|
"Learn more here: "
|
|
3944
4035
|
)}${linkText(
|
|
3945
|
-
"https://tina.io/docs/self-
|
|
4036
|
+
"https://tina.io/docs/r/self-hosting-nextjs/#github-personal-access-token"
|
|
3946
4037
|
)}`,
|
|
3947
4038
|
initial: process.env.GITHUB_PERSONAL_ACCESS_TOKEN
|
|
3948
4039
|
},
|
|
@@ -3979,7 +4070,7 @@ ${logText(
|
|
|
3979
4070
|
};
|
|
3980
4071
|
|
|
3981
4072
|
// src/cmds/init/prompts/databaseAdapter.ts
|
|
3982
|
-
|
|
4073
|
+
import prompts4 from "prompts";
|
|
3983
4074
|
var supportedDatabaseAdapters = {
|
|
3984
4075
|
["upstash-redis"]: {
|
|
3985
4076
|
databaseAdapterClassText: `new RedisLevel({
|
|
@@ -4025,7 +4116,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4025
4116
|
other: async (_args) => {
|
|
4026
4117
|
},
|
|
4027
4118
|
mongodb: async ({ config: config2 }) => {
|
|
4028
|
-
const result = await (
|
|
4119
|
+
const result = await prompts4([
|
|
4029
4120
|
{
|
|
4030
4121
|
name: "mongoDBUri",
|
|
4031
4122
|
type: "text",
|
|
@@ -4040,7 +4131,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4040
4131
|
});
|
|
4041
4132
|
},
|
|
4042
4133
|
"upstash-redis": async ({ config: config2 }) => {
|
|
4043
|
-
const result = await (
|
|
4134
|
+
const result = await prompts4([
|
|
4044
4135
|
{
|
|
4045
4136
|
name: "kvRestApiUrl",
|
|
4046
4137
|
type: "text",
|
|
@@ -4071,7 +4162,7 @@ var chooseDatabaseAdapter = async ({
|
|
|
4071
4162
|
framework,
|
|
4072
4163
|
config: config2
|
|
4073
4164
|
}) => {
|
|
4074
|
-
const answers = await (
|
|
4165
|
+
const answers = await prompts4([
|
|
4075
4166
|
{
|
|
4076
4167
|
name: "dataLayerAdapter",
|
|
4077
4168
|
message: "Select a self-hosted Database Adapter",
|
|
@@ -4101,8 +4192,8 @@ var chooseDatabaseAdapter = async ({
|
|
|
4101
4192
|
};
|
|
4102
4193
|
|
|
4103
4194
|
// src/cmds/init/prompts/authProvider.ts
|
|
4104
|
-
|
|
4105
|
-
|
|
4195
|
+
import crypto2 from "crypto-js";
|
|
4196
|
+
import prompts5 from "prompts";
|
|
4106
4197
|
var supportedAuthProviders = {
|
|
4107
4198
|
other: {
|
|
4108
4199
|
name: "other"
|
|
@@ -4151,12 +4242,12 @@ var authProviderUpdateConfig = {
|
|
|
4151
4242
|
},
|
|
4152
4243
|
"tina-cloud": askTinaCloudSetup,
|
|
4153
4244
|
"next-auth": async ({ config: config2 }) => {
|
|
4154
|
-
const result = await (
|
|
4245
|
+
const result = await prompts5([
|
|
4155
4246
|
{
|
|
4156
4247
|
name: "nextAuthSecret",
|
|
4157
4248
|
type: "text",
|
|
4158
4249
|
message: `What is the NextAuth.js Secret? (Hit enter to use a randomly generated secret)`,
|
|
4159
|
-
initial: process.env.NEXTAUTH_SECRET ||
|
|
4250
|
+
initial: process.env.NEXTAUTH_SECRET || crypto2.lib.WordArray.random(16).toString()
|
|
4160
4251
|
}
|
|
4161
4252
|
]);
|
|
4162
4253
|
config2.envVars.push({
|
|
@@ -4181,7 +4272,7 @@ var forestryDisclaimer = logText(
|
|
|
4181
4272
|
`Note: This migration will update some of your content to match tina. Please save a backup of your content before doing this migration. (This can be done with git)`
|
|
4182
4273
|
);
|
|
4183
4274
|
var askCommonSetUp = async () => {
|
|
4184
|
-
const answers = await (
|
|
4275
|
+
const answers = await prompts6([
|
|
4185
4276
|
{
|
|
4186
4277
|
name: "framework",
|
|
4187
4278
|
type: "select",
|
|
@@ -4203,7 +4294,8 @@ var askCommonSetUp = async () => {
|
|
|
4203
4294
|
choices: [
|
|
4204
4295
|
{ title: "PNPM", value: "pnpm" },
|
|
4205
4296
|
{ title: "Yarn", value: "yarn" },
|
|
4206
|
-
{ title: "NPM", value: "npm" }
|
|
4297
|
+
{ title: "NPM", value: "npm" },
|
|
4298
|
+
{ title: "Bun", value: "bun" }
|
|
4207
4299
|
]
|
|
4208
4300
|
}
|
|
4209
4301
|
]);
|
|
@@ -4244,7 +4336,7 @@ ${forestryDisclaimer}`
|
|
|
4244
4336
|
message: `What format are you using in your frontmatter?`
|
|
4245
4337
|
});
|
|
4246
4338
|
}
|
|
4247
|
-
const answers = await (
|
|
4339
|
+
const answers = await prompts6(questions);
|
|
4248
4340
|
return answers;
|
|
4249
4341
|
};
|
|
4250
4342
|
var askTinaSetupPrompts = async (params) => {
|
|
@@ -4264,16 +4356,16 @@ var askTinaSetupPrompts = async (params) => {
|
|
|
4264
4356
|
message: `Where are public assets stored? (default: "public")
|
|
4265
4357
|
` + logText(
|
|
4266
4358
|
`Not sure what value to use? Refer to our "Frameworks" doc: ${linkText(
|
|
4267
|
-
"https://tina.io/docs/
|
|
4359
|
+
"https://tina.io/docs/r/framework-guides-overview"
|
|
4268
4360
|
)}`
|
|
4269
4361
|
)
|
|
4270
4362
|
});
|
|
4271
4363
|
}
|
|
4272
|
-
const answers = await (
|
|
4364
|
+
const answers = await prompts6(questions);
|
|
4273
4365
|
return answers;
|
|
4274
4366
|
};
|
|
4275
4367
|
var askIfUsingSelfHosted = async () => {
|
|
4276
|
-
const answers = await (
|
|
4368
|
+
const answers = await prompts6([
|
|
4277
4369
|
{
|
|
4278
4370
|
name: "hosting",
|
|
4279
4371
|
type: "select",
|
|
@@ -4306,20 +4398,20 @@ var makeImportString = (imports) => {
|
|
|
4306
4398
|
};
|
|
4307
4399
|
|
|
4308
4400
|
// src/cmds/init/prompts/generatedFiles.ts
|
|
4309
|
-
|
|
4401
|
+
import prompts7 from "prompts";
|
|
4310
4402
|
var askIfOverride = async ({
|
|
4311
4403
|
generatedFile,
|
|
4312
4404
|
usingTypescript
|
|
4313
4405
|
}) => {
|
|
4314
4406
|
if (usingTypescript) {
|
|
4315
|
-
const result = await (
|
|
4407
|
+
const result = await prompts7({
|
|
4316
4408
|
name: `override`,
|
|
4317
4409
|
type: "confirm",
|
|
4318
4410
|
message: `Found existing file at ${generatedFile.fullPathTS}. Would you like to overwrite?`
|
|
4319
4411
|
});
|
|
4320
4412
|
return Boolean(result.override);
|
|
4321
4413
|
} else {
|
|
4322
|
-
const result = await (
|
|
4414
|
+
const result = await prompts7({
|
|
4323
4415
|
name: `override`,
|
|
4324
4416
|
type: "confirm",
|
|
4325
4417
|
message: `Found existing file at ${generatedFile.fullPathJS}. Would you like to overwrite?`
|
|
@@ -4454,23 +4546,25 @@ var CLICommand = class {
|
|
|
4454
4546
|
};
|
|
4455
4547
|
|
|
4456
4548
|
// src/cmds/init/apply.ts
|
|
4457
|
-
|
|
4549
|
+
import path14 from "path";
|
|
4458
4550
|
|
|
4459
4551
|
// src/cmds/forestry-migrate/index.ts
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4552
|
+
import fs11 from "fs-extra";
|
|
4553
|
+
import path12 from "path";
|
|
4554
|
+
import yaml2 from "js-yaml";
|
|
4555
|
+
import pkg from "minimatch";
|
|
4556
|
+
import { parseFile, stringifyFile } from "@tinacms/graphql";
|
|
4557
|
+
import { CONTENT_FORMATS } from "@tinacms/schema-tools";
|
|
4465
4558
|
|
|
4466
4559
|
// src/cmds/forestry-migrate/util/index.ts
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4560
|
+
import fs10 from "fs-extra";
|
|
4561
|
+
import path11 from "path";
|
|
4562
|
+
import yaml from "js-yaml";
|
|
4563
|
+
import z from "zod";
|
|
4471
4564
|
|
|
4472
4565
|
// src/cmds/forestry-migrate/util/errorSingleton.ts
|
|
4473
4566
|
var ErrorSingleton = class _ErrorSingleton {
|
|
4567
|
+
static instance;
|
|
4474
4568
|
/**
|
|
4475
4569
|
* The Singleton's constructor should always be private to prevent direct
|
|
4476
4570
|
* construction calls with the `new` operator.
|
|
@@ -4490,12 +4584,12 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4490
4584
|
}
|
|
4491
4585
|
return _ErrorSingleton.instance;
|
|
4492
4586
|
}
|
|
4587
|
+
collectionNameErrors;
|
|
4493
4588
|
addErrorName(error) {
|
|
4494
4589
|
this.collectionNameErrors.push(error);
|
|
4495
4590
|
}
|
|
4496
4591
|
printCollectionNameErrors() {
|
|
4497
|
-
|
|
4498
|
-
if ((_a = this.collectionNameErrors) == null ? void 0 : _a.length) {
|
|
4592
|
+
if (this.collectionNameErrors?.length) {
|
|
4499
4593
|
logger.error(
|
|
4500
4594
|
dangerText("ERROR: TinaCMS only supports alphanumeric template names")
|
|
4501
4595
|
);
|
|
@@ -4513,8 +4607,8 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4513
4607
|
};
|
|
4514
4608
|
|
|
4515
4609
|
// src/cmds/forestry-migrate/util/codeTransformer.ts
|
|
4516
|
-
|
|
4517
|
-
|
|
4610
|
+
import { format } from "prettier";
|
|
4611
|
+
import TsParser from "prettier/parser-typescript.js";
|
|
4518
4612
|
var addVariablesToCode = (codeWithTinaPrefix) => {
|
|
4519
4613
|
const code = codeWithTinaPrefix.replace(
|
|
4520
4614
|
/"__TINA_INTERNAL__:::(.*?):::"/g,
|
|
@@ -4551,7 +4645,7 @@ var makeTemplateFile = async ({
|
|
|
4551
4645
|
`export function ${stringifyLabelWithField(
|
|
4552
4646
|
template.templateObj.label
|
|
4553
4647
|
)} (){
|
|
4554
|
-
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4648
|
+
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4555
4649
|
} `
|
|
4556
4650
|
);
|
|
4557
4651
|
}
|
|
@@ -4559,9 +4653,9 @@ var makeTemplateFile = async ({
|
|
|
4559
4653
|
${usingTypescript ? "import type { TinaField } from 'tinacms'" : ""}
|
|
4560
4654
|
${templateCodeText.join("\n")}
|
|
4561
4655
|
`;
|
|
4562
|
-
const formattedCode =
|
|
4656
|
+
const formattedCode = format(templateCode, {
|
|
4563
4657
|
parser: "typescript",
|
|
4564
|
-
plugins: [
|
|
4658
|
+
plugins: [TsParser]
|
|
4565
4659
|
});
|
|
4566
4660
|
return { importStatements, templateCodeText: formattedCode };
|
|
4567
4661
|
};
|
|
@@ -4593,82 +4687,82 @@ var stringifyTemplateName = (name2, template) => {
|
|
|
4593
4687
|
return newName;
|
|
4594
4688
|
}
|
|
4595
4689
|
};
|
|
4596
|
-
var forestryConfigSchema =
|
|
4597
|
-
sections:
|
|
4598
|
-
|
|
4599
|
-
type:
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4690
|
+
var forestryConfigSchema = z.object({
|
|
4691
|
+
sections: z.array(
|
|
4692
|
+
z.object({
|
|
4693
|
+
type: z.union([
|
|
4694
|
+
z.literal("directory"),
|
|
4695
|
+
z.literal("document"),
|
|
4696
|
+
z.literal("heading"),
|
|
4697
|
+
z.literal("jekyll-pages"),
|
|
4698
|
+
z.literal("jekyll-posts")
|
|
4605
4699
|
]),
|
|
4606
|
-
label:
|
|
4607
|
-
path:
|
|
4608
|
-
match:
|
|
4609
|
-
exclude:
|
|
4610
|
-
create:
|
|
4611
|
-
templates:
|
|
4612
|
-
new_doc_ext:
|
|
4613
|
-
read_only:
|
|
4700
|
+
label: z.string(),
|
|
4701
|
+
path: z.string().optional().nullable(),
|
|
4702
|
+
match: z.string().optional().nullable(),
|
|
4703
|
+
exclude: z.string().optional().nullable(),
|
|
4704
|
+
create: z.union([z.literal("all"), z.literal("documents"), z.literal("none")]).optional(),
|
|
4705
|
+
templates: z.array(z.string()).optional().nullable(),
|
|
4706
|
+
new_doc_ext: z.string().optional().nullable(),
|
|
4707
|
+
read_only: z.boolean().optional().nullable()
|
|
4614
4708
|
})
|
|
4615
4709
|
)
|
|
4616
4710
|
});
|
|
4617
|
-
var forestryFieldWithoutField =
|
|
4711
|
+
var forestryFieldWithoutField = z.object({
|
|
4618
4712
|
// TODO: maybe better type this?
|
|
4619
|
-
type:
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4713
|
+
type: z.union([
|
|
4714
|
+
z.literal("text"),
|
|
4715
|
+
z.literal("datetime"),
|
|
4716
|
+
z.literal("list"),
|
|
4717
|
+
z.literal("file"),
|
|
4718
|
+
z.literal("image_gallery"),
|
|
4719
|
+
z.literal("textarea"),
|
|
4720
|
+
z.literal("tag_list"),
|
|
4721
|
+
z.literal("number"),
|
|
4722
|
+
z.literal("boolean"),
|
|
4723
|
+
z.literal("field_group"),
|
|
4724
|
+
z.literal("field_group_list"),
|
|
4725
|
+
z.literal("select"),
|
|
4726
|
+
z.literal("include"),
|
|
4727
|
+
z.literal("blocks"),
|
|
4728
|
+
z.literal("color")
|
|
4635
4729
|
]),
|
|
4636
|
-
template_types:
|
|
4637
|
-
name:
|
|
4638
|
-
label:
|
|
4639
|
-
default:
|
|
4640
|
-
template:
|
|
4641
|
-
config:
|
|
4730
|
+
template_types: z.array(z.string()).optional().nullable(),
|
|
4731
|
+
name: z.string(),
|
|
4732
|
+
label: z.string(),
|
|
4733
|
+
default: z.any().optional(),
|
|
4734
|
+
template: z.string().optional(),
|
|
4735
|
+
config: z.object({
|
|
4642
4736
|
// min and max are used for lists
|
|
4643
|
-
min:
|
|
4644
|
-
max:
|
|
4645
|
-
required:
|
|
4646
|
-
use_select:
|
|
4647
|
-
date_format:
|
|
4648
|
-
time_format:
|
|
4649
|
-
options:
|
|
4650
|
-
source:
|
|
4651
|
-
type:
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4737
|
+
min: z.number().optional().nullable(),
|
|
4738
|
+
max: z.number().optional().nullable(),
|
|
4739
|
+
required: z.boolean().optional().nullable(),
|
|
4740
|
+
use_select: z.boolean().optional().nullable(),
|
|
4741
|
+
date_format: z.string().optional().nullable(),
|
|
4742
|
+
time_format: z.string().optional().nullable(),
|
|
4743
|
+
options: z.array(z.string()).optional().nullable(),
|
|
4744
|
+
source: z.object({
|
|
4745
|
+
type: z.union([
|
|
4746
|
+
z.literal("custom"),
|
|
4747
|
+
z.literal("pages"),
|
|
4748
|
+
z.literal("documents"),
|
|
4749
|
+
z.literal("simple"),
|
|
4656
4750
|
// TODO: I want to ignore this key if its invalid
|
|
4657
|
-
|
|
4751
|
+
z.string()
|
|
4658
4752
|
]).optional().nullable(),
|
|
4659
|
-
section:
|
|
4753
|
+
section: z.string().optional().nullable()
|
|
4660
4754
|
}).optional()
|
|
4661
4755
|
}).optional()
|
|
4662
4756
|
});
|
|
4663
|
-
var forestryField =
|
|
4757
|
+
var forestryField = z.lazy(
|
|
4664
4758
|
() => forestryFieldWithoutField.extend({
|
|
4665
|
-
fields:
|
|
4759
|
+
fields: z.array(forestryField).optional()
|
|
4666
4760
|
})
|
|
4667
4761
|
);
|
|
4668
|
-
var FrontmatterTemplateSchema =
|
|
4669
|
-
label:
|
|
4670
|
-
hide_body:
|
|
4671
|
-
fields:
|
|
4762
|
+
var FrontmatterTemplateSchema = z.object({
|
|
4763
|
+
label: z.string(),
|
|
4764
|
+
hide_body: z.boolean().optional(),
|
|
4765
|
+
fields: z.array(forestryField).optional()
|
|
4672
4766
|
});
|
|
4673
4767
|
var transformForestryFieldsToTinaFields = ({
|
|
4674
4768
|
fields,
|
|
@@ -4677,8 +4771,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4677
4771
|
skipBlocks = false
|
|
4678
4772
|
}) => {
|
|
4679
4773
|
const tinaFields = [];
|
|
4680
|
-
fields
|
|
4681
|
-
var _a, _b, _c, _d;
|
|
4774
|
+
fields?.forEach((forestryField2) => {
|
|
4682
4775
|
if (forestryField2.name === "menu") {
|
|
4683
4776
|
logger.info(
|
|
4684
4777
|
warnText(
|
|
@@ -4754,12 +4847,12 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4754
4847
|
};
|
|
4755
4848
|
break;
|
|
4756
4849
|
case "select":
|
|
4757
|
-
if (
|
|
4850
|
+
if (forestryField2.config?.options) {
|
|
4758
4851
|
field = {
|
|
4759
4852
|
type: "string",
|
|
4760
4853
|
...getTinaFieldsFromName(forestryField2.name),
|
|
4761
4854
|
label: forestryField2.label,
|
|
4762
|
-
options:
|
|
4855
|
+
options: forestryField2.config?.options || []
|
|
4763
4856
|
};
|
|
4764
4857
|
} else {
|
|
4765
4858
|
logger.info(
|
|
@@ -4777,7 +4870,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4777
4870
|
label: forestryField2.label,
|
|
4778
4871
|
list: true
|
|
4779
4872
|
};
|
|
4780
|
-
if (
|
|
4873
|
+
if (forestryField2.config?.options) {
|
|
4781
4874
|
field.options = forestryField2.config.options;
|
|
4782
4875
|
}
|
|
4783
4876
|
break;
|
|
@@ -4825,7 +4918,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4825
4918
|
break;
|
|
4826
4919
|
}
|
|
4827
4920
|
const templates2 = [];
|
|
4828
|
-
forestryField2
|
|
4921
|
+
forestryField2?.template_types.forEach((tem) => {
|
|
4829
4922
|
const { template: template2 } = getFieldsFromTemplates({
|
|
4830
4923
|
tem,
|
|
4831
4924
|
skipBlocks: true,
|
|
@@ -4883,7 +4976,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4883
4976
|
);
|
|
4884
4977
|
}
|
|
4885
4978
|
if (field) {
|
|
4886
|
-
if (
|
|
4979
|
+
if (forestryField2.config?.required) {
|
|
4887
4980
|
field = { ...field, required: true };
|
|
4888
4981
|
}
|
|
4889
4982
|
tinaFields.push(field);
|
|
@@ -4892,7 +4985,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4892
4985
|
return tinaFields;
|
|
4893
4986
|
};
|
|
4894
4987
|
var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
|
|
4895
|
-
const templatePath =
|
|
4988
|
+
const templatePath = path11.join(
|
|
4896
4989
|
pathToForestryConfig,
|
|
4897
4990
|
".forestry",
|
|
4898
4991
|
"front_matter",
|
|
@@ -4901,7 +4994,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4901
4994
|
);
|
|
4902
4995
|
let templateString = "";
|
|
4903
4996
|
try {
|
|
4904
|
-
templateString =
|
|
4997
|
+
templateString = fs10.readFileSync(templatePath).toString();
|
|
4905
4998
|
} catch {
|
|
4906
4999
|
throw new Error(
|
|
4907
5000
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -4909,7 +5002,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4909
5002
|
This will require manual migration.`
|
|
4910
5003
|
);
|
|
4911
5004
|
}
|
|
4912
|
-
const templateObj =
|
|
5005
|
+
const templateObj = yaml.load(templateString);
|
|
4913
5006
|
const template = parseTemplates({ val: templateObj });
|
|
4914
5007
|
const fields = transformForestryFieldsToTinaFields({
|
|
4915
5008
|
fields: template.fields,
|
|
@@ -4929,6 +5022,7 @@ var parseSections = ({ val }) => {
|
|
|
4929
5022
|
};
|
|
4930
5023
|
|
|
4931
5024
|
// src/cmds/forestry-migrate/index.ts
|
|
5025
|
+
var { minimatch } = pkg;
|
|
4932
5026
|
var BODY_FIELD = {
|
|
4933
5027
|
// This is the body field
|
|
4934
5028
|
type: "rich-text",
|
|
@@ -4945,8 +5039,7 @@ var stringifyLabelWithField = (label) => {
|
|
|
4945
5039
|
return `${labelString}Fields`;
|
|
4946
5040
|
};
|
|
4947
5041
|
var transformForestryMatchToTinaMatch = (match) => {
|
|
4948
|
-
|
|
4949
|
-
const newMatch = (_b = (_a = match.replace(" ", "").replace(/\.?(mdx|md|json|yaml|yml|toml)/g, "")) == null ? void 0 : _a.replace(/\..*$/g, "")) == null ? void 0 : _b.replace("{}", "");
|
|
5042
|
+
const newMatch = match.replace(" ", "").replace(/\.?(mdx|md|json|yaml|yml|toml)/g, "")?.replace(/\..*$/g, "")?.replace("{}", "");
|
|
4950
5043
|
if (match !== newMatch) {
|
|
4951
5044
|
logger.info(
|
|
4952
5045
|
`Info: Match ${match} was transformed to ${newMatch}. See ${linkText(
|
|
@@ -4958,7 +5051,7 @@ var transformForestryMatchToTinaMatch = (match) => {
|
|
|
4958
5051
|
};
|
|
4959
5052
|
function checkExt(ext) {
|
|
4960
5053
|
const extReal = ext.replace(".", "");
|
|
4961
|
-
if (
|
|
5054
|
+
if (CONTENT_FORMATS.includes(extReal)) {
|
|
4962
5055
|
return extReal;
|
|
4963
5056
|
} else {
|
|
4964
5057
|
return false;
|
|
@@ -4967,9 +5060,9 @@ function checkExt(ext) {
|
|
|
4967
5060
|
var generateAllTemplates = async ({
|
|
4968
5061
|
pathToForestryConfig
|
|
4969
5062
|
}) => {
|
|
4970
|
-
const allTemplates = (await
|
|
4971
|
-
|
|
4972
|
-
)).map((tem) =>
|
|
5063
|
+
const allTemplates = (await fs11.readdir(
|
|
5064
|
+
path12.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
|
|
5065
|
+
)).map((tem) => path12.basename(tem, ".yml"));
|
|
4973
5066
|
const templateMap = /* @__PURE__ */ new Map();
|
|
4974
5067
|
const proms = allTemplates.map(async (tem) => {
|
|
4975
5068
|
try {
|
|
@@ -5011,18 +5104,18 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5011
5104
|
}
|
|
5012
5105
|
if (section.match) {
|
|
5013
5106
|
baseCollection.match = {
|
|
5014
|
-
...
|
|
5107
|
+
...baseCollection?.match || {},
|
|
5015
5108
|
include: transformForestryMatchToTinaMatch(section.match)
|
|
5016
5109
|
};
|
|
5017
5110
|
}
|
|
5018
5111
|
if (section.exclude) {
|
|
5019
5112
|
baseCollection.match = {
|
|
5020
|
-
...
|
|
5113
|
+
...baseCollection?.match || {},
|
|
5021
5114
|
exclude: transformForestryMatchToTinaMatch(section.exclude)
|
|
5022
5115
|
};
|
|
5023
5116
|
}
|
|
5024
5117
|
if (section.type === "directory") {
|
|
5025
|
-
if (!
|
|
5118
|
+
if (!section?.path || section.path === "/" || section.path === "./" || section.path === ".") {
|
|
5026
5119
|
logger.log(
|
|
5027
5120
|
warnText(
|
|
5028
5121
|
`Warning: Section ${section.label} is using a Root Path. Currently, Tina Does not support Root paths see ${linkText(
|
|
@@ -5032,11 +5125,11 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5032
5125
|
);
|
|
5033
5126
|
return;
|
|
5034
5127
|
}
|
|
5035
|
-
const forestryTemplates =
|
|
5128
|
+
const forestryTemplates = section?.templates || [];
|
|
5036
5129
|
if (forestryTemplates.length === 0 && section.create === "all") {
|
|
5037
5130
|
for (const templateKey of templateMap.keys()) {
|
|
5038
5131
|
const { templateObj } = templateMap.get(templateKey);
|
|
5039
|
-
const pages = templateObj
|
|
5132
|
+
const pages = templateObj?.pages;
|
|
5040
5133
|
if (pages) {
|
|
5041
5134
|
let glob = section.match;
|
|
5042
5135
|
const skipPath = section.path === "" || section.path === "/" || !section.path;
|
|
@@ -5044,7 +5137,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5044
5137
|
glob = section.path + "/" + section.match;
|
|
5045
5138
|
}
|
|
5046
5139
|
if (pages.some((page) => {
|
|
5047
|
-
return (
|
|
5140
|
+
return minimatch(page, glob);
|
|
5048
5141
|
})) {
|
|
5049
5142
|
forestryTemplates.push(templateKey);
|
|
5050
5143
|
}
|
|
@@ -5053,7 +5146,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5053
5146
|
}
|
|
5054
5147
|
const hasBody = ["md", "mdx", "markdown"].includes(format3);
|
|
5055
5148
|
let c;
|
|
5056
|
-
if ((
|
|
5149
|
+
if ((forestryTemplates?.length || 0) > 1) {
|
|
5057
5150
|
c = {
|
|
5058
5151
|
...baseCollection,
|
|
5059
5152
|
// @ts-expect-error
|
|
@@ -5075,7 +5168,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5075
5168
|
})
|
|
5076
5169
|
};
|
|
5077
5170
|
}
|
|
5078
|
-
if (
|
|
5171
|
+
if (forestryTemplates?.length === 1) {
|
|
5079
5172
|
const tem = forestryTemplates[0];
|
|
5080
5173
|
const template = templateMap.get(tem);
|
|
5081
5174
|
const fieldsString = stringifyLabelWithField(template.templateObj.label);
|
|
@@ -5090,7 +5183,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5090
5183
|
})
|
|
5091
5184
|
};
|
|
5092
5185
|
}
|
|
5093
|
-
if (
|
|
5186
|
+
if (forestryTemplates?.length === 0) {
|
|
5094
5187
|
logger.warn(
|
|
5095
5188
|
warnText(
|
|
5096
5189
|
`No templates found for section ${section.label}. Please see ${linkText(
|
|
@@ -5103,7 +5196,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5103
5196
|
fields: [BODY_FIELD]
|
|
5104
5197
|
};
|
|
5105
5198
|
}
|
|
5106
|
-
if (
|
|
5199
|
+
if (section?.create === "none") {
|
|
5107
5200
|
c.ui = {
|
|
5108
5201
|
...c.ui,
|
|
5109
5202
|
allowedActions: {
|
|
@@ -5114,9 +5207,9 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5114
5207
|
return c;
|
|
5115
5208
|
} else if (section.type === "document") {
|
|
5116
5209
|
const filePath = section.path;
|
|
5117
|
-
const extname =
|
|
5118
|
-
const fileName =
|
|
5119
|
-
const dir =
|
|
5210
|
+
const extname = path12.extname(filePath);
|
|
5211
|
+
const fileName = path12.basename(filePath, extname);
|
|
5212
|
+
const dir = path12.dirname(filePath);
|
|
5120
5213
|
const ext = checkExt(extname);
|
|
5121
5214
|
if (ext) {
|
|
5122
5215
|
const fields = [];
|
|
@@ -5125,7 +5218,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5125
5218
|
}
|
|
5126
5219
|
for (const currentTemplateName of templateMap.keys()) {
|
|
5127
5220
|
const { templateObj, fields: additionalFields } = templateMap.get(currentTemplateName);
|
|
5128
|
-
const pages =
|
|
5221
|
+
const pages = templateObj?.pages || [];
|
|
5129
5222
|
if (pages.includes(section.path)) {
|
|
5130
5223
|
fields.push(...additionalFields);
|
|
5131
5224
|
break;
|
|
@@ -5136,7 +5229,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5136
5229
|
name: "dummy",
|
|
5137
5230
|
label: "Dummy field",
|
|
5138
5231
|
type: "string",
|
|
5139
|
-
description: "This is a dummy field, please replace it with the fields you want to edit. See https://tina.io/docs/
|
|
5232
|
+
description: "This is a dummy field, please replace it with the fields you want to edit. See https://tina.io/docs/r/content-modelling-collections/ for more info"
|
|
5140
5233
|
});
|
|
5141
5234
|
logger.warn(
|
|
5142
5235
|
warnText(
|
|
@@ -5178,8 +5271,8 @@ var generateCollections = async ({
|
|
|
5178
5271
|
templateMap,
|
|
5179
5272
|
usingTypescript
|
|
5180
5273
|
});
|
|
5181
|
-
const forestryConfig = await
|
|
5182
|
-
|
|
5274
|
+
const forestryConfig = await fs11.readFile(
|
|
5275
|
+
path12.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
5183
5276
|
);
|
|
5184
5277
|
rewriteTemplateKeysInDocs({
|
|
5185
5278
|
templateMap,
|
|
@@ -5189,7 +5282,7 @@ var generateCollections = async ({
|
|
|
5189
5282
|
}
|
|
5190
5283
|
});
|
|
5191
5284
|
const collections = parseSections({
|
|
5192
|
-
val:
|
|
5285
|
+
val: yaml2.load(forestryConfig.toString())
|
|
5193
5286
|
}).sections.map(
|
|
5194
5287
|
(section) => generateCollectionFromForestrySection({
|
|
5195
5288
|
section,
|
|
@@ -5204,19 +5297,18 @@ var generateCollections = async ({
|
|
|
5204
5297
|
};
|
|
5205
5298
|
};
|
|
5206
5299
|
var rewriteTemplateKeysInDocs = (args) => {
|
|
5207
|
-
var _a;
|
|
5208
5300
|
const { templateMap, markdownParseConfig } = args;
|
|
5209
5301
|
for (const templateKey of templateMap.keys()) {
|
|
5210
5302
|
const { templateObj } = templateMap.get(templateKey);
|
|
5211
|
-
|
|
5303
|
+
templateObj?.pages?.forEach((page) => {
|
|
5212
5304
|
try {
|
|
5213
|
-
const filePath =
|
|
5214
|
-
if (
|
|
5305
|
+
const filePath = path12.join(page);
|
|
5306
|
+
if (fs11.lstatSync(filePath).isDirectory()) {
|
|
5215
5307
|
return;
|
|
5216
5308
|
}
|
|
5217
|
-
const extname =
|
|
5218
|
-
const fileContent =
|
|
5219
|
-
const content =
|
|
5309
|
+
const extname = path12.extname(filePath);
|
|
5310
|
+
const fileContent = fs11.readFileSync(filePath).toString();
|
|
5311
|
+
const content = parseFile(
|
|
5220
5312
|
fileContent,
|
|
5221
5313
|
extname,
|
|
5222
5314
|
(yup) => yup.object({}),
|
|
@@ -5226,9 +5318,9 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5226
5318
|
_template: stringifyLabel(templateKey),
|
|
5227
5319
|
...content
|
|
5228
5320
|
};
|
|
5229
|
-
|
|
5321
|
+
fs11.writeFileSync(
|
|
5230
5322
|
filePath,
|
|
5231
|
-
|
|
5323
|
+
stringifyFile(newContent, extname, true, markdownParseConfig)
|
|
5232
5324
|
);
|
|
5233
5325
|
} catch (error) {
|
|
5234
5326
|
console.log(
|
|
@@ -5240,23 +5332,25 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5240
5332
|
};
|
|
5241
5333
|
|
|
5242
5334
|
// src/cmds/init/apply.ts
|
|
5243
|
-
|
|
5244
|
-
|
|
5335
|
+
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
5336
|
+
import fs14 from "fs-extra";
|
|
5245
5337
|
|
|
5246
5338
|
// src/next/commands/codemod-command/index.ts
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
var CodemodCommand = class extends
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5339
|
+
import { Command as Command5, Option as Option5 } from "clipanion";
|
|
5340
|
+
import fs12 from "fs-extra";
|
|
5341
|
+
import path13 from "path";
|
|
5342
|
+
var CodemodCommand = class extends Command5 {
|
|
5343
|
+
static paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5344
|
+
rootPath = Option5.String("--rootPath", {
|
|
5345
|
+
description: "Specify the root directory to run the CLI from"
|
|
5346
|
+
});
|
|
5347
|
+
verbose = Option5.Boolean("-v,--verbose", false, {
|
|
5348
|
+
description: "increase verbosity of logged output"
|
|
5349
|
+
});
|
|
5350
|
+
static usage = Command5.Usage({
|
|
5351
|
+
category: `Commands`,
|
|
5352
|
+
description: `Use codemods for various Tina tasks`
|
|
5353
|
+
});
|
|
5260
5354
|
async catch(error) {
|
|
5261
5355
|
console.log(error);
|
|
5262
5356
|
}
|
|
@@ -5277,11 +5371,6 @@ var CodemodCommand = class extends import_clipanion5.Command {
|
|
|
5277
5371
|
await command2();
|
|
5278
5372
|
}
|
|
5279
5373
|
};
|
|
5280
|
-
CodemodCommand.paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5281
|
-
CodemodCommand.usage = import_clipanion5.Command.Usage({
|
|
5282
|
-
category: `Commands`,
|
|
5283
|
-
description: `Use codemods for various Tina tasks`
|
|
5284
|
-
});
|
|
5285
5374
|
var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
5286
5375
|
const configManager = new ConfigManager({ rootPath });
|
|
5287
5376
|
try {
|
|
@@ -5290,13 +5379,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5290
5379
|
logger.error(e.message);
|
|
5291
5380
|
process.exit(1);
|
|
5292
5381
|
}
|
|
5293
|
-
const tinaDestination =
|
|
5294
|
-
if (await
|
|
5382
|
+
const tinaDestination = path13.join(configManager.rootPath, "tina");
|
|
5383
|
+
if (await fs12.existsSync(tinaDestination)) {
|
|
5295
5384
|
logger.info(
|
|
5296
5385
|
`Folder already exists at ${tinaDestination}. Either delete this folder to complete the codemod, or ensure you have properly copied your config from the ".tina" folder.`
|
|
5297
5386
|
);
|
|
5298
5387
|
} else {
|
|
5299
|
-
await
|
|
5388
|
+
await fs12.moveSync(configManager.tinaFolderPath, tinaDestination);
|
|
5300
5389
|
await writeGitignore(configManager.rootPath);
|
|
5301
5390
|
logger.info(
|
|
5302
5391
|
"Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
|
|
@@ -5304,8 +5393,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5304
5393
|
}
|
|
5305
5394
|
};
|
|
5306
5395
|
var writeGitignore = async (rootPath) => {
|
|
5307
|
-
await
|
|
5308
|
-
|
|
5396
|
+
await fs12.outputFileSync(
|
|
5397
|
+
path13.join(rootPath, "tina", ".gitignore"),
|
|
5309
5398
|
"__generated__"
|
|
5310
5399
|
);
|
|
5311
5400
|
};
|
|
@@ -5358,7 +5447,7 @@ const BlogPage = (props) => {
|
|
|
5358
5447
|
<div className='bg-green-100 text-center'>
|
|
5359
5448
|
Lost and looking for a place to start?
|
|
5360
5449
|
<a
|
|
5361
|
-
href='https://tina.io/
|
|
5450
|
+
href='https://tina.io/docs/r/beginner-series'
|
|
5362
5451
|
className='text-blue-500 underline'
|
|
5363
5452
|
>
|
|
5364
5453
|
{' '}
|
|
@@ -5561,11 +5650,10 @@ var baseFields = `[
|
|
|
5561
5650
|
},
|
|
5562
5651
|
]`;
|
|
5563
5652
|
var generateCollectionString = (args) => {
|
|
5564
|
-
var _a, _b, _c, _d;
|
|
5565
5653
|
if (args.collections) {
|
|
5566
5654
|
return args.collections;
|
|
5567
5655
|
}
|
|
5568
|
-
let extraTinaCollections =
|
|
5656
|
+
let extraTinaCollections = args.config.authProvider?.extraTinaCollections?.join(",\n");
|
|
5569
5657
|
if (extraTinaCollections) {
|
|
5570
5658
|
extraTinaCollections = extraTinaCollections + ",";
|
|
5571
5659
|
}
|
|
@@ -5591,18 +5679,17 @@ var generateCollectionString = (args) => {
|
|
|
5591
5679
|
},
|
|
5592
5680
|
},
|
|
5593
5681
|
]`;
|
|
5594
|
-
if (
|
|
5682
|
+
if (args.config?.framework?.name === "next") {
|
|
5595
5683
|
return nextExampleCollection;
|
|
5596
5684
|
}
|
|
5597
5685
|
return baseCollections;
|
|
5598
5686
|
};
|
|
5599
5687
|
var generateConfig = (args) => {
|
|
5600
|
-
|
|
5601
|
-
const isUsingTinaCloud = !args.selfHosted || ((_a = args.config.authProvider) == null ? void 0 : _a.name) === "tina-cloud";
|
|
5688
|
+
const isUsingTinaCloud = !args.selfHosted || args.config.authProvider?.name === "tina-cloud";
|
|
5602
5689
|
let extraImports = "";
|
|
5603
5690
|
if (args.selfHosted) {
|
|
5604
5691
|
if (args.config.authProvider) {
|
|
5605
|
-
extraImports = extraImports + makeImportString(
|
|
5692
|
+
extraImports = extraImports + makeImportString(args.config.authProvider?.configImports);
|
|
5606
5693
|
}
|
|
5607
5694
|
if (!isUsingTinaCloud) {
|
|
5608
5695
|
extraImports = extraImports + `
|
|
@@ -5625,7 +5712,7 @@ import { LocalAuthProvider } from "tinacms";`;
|
|
|
5625
5712
|
branch,
|
|
5626
5713
|
${args.selfHosted && !isUsingTinaCloud ? `authProvider: isLocal
|
|
5627
5714
|
? new LocalAuthProvider()
|
|
5628
|
-
:${
|
|
5715
|
+
:${args.config?.authProvider.configAuthProviderClass},` : ""}
|
|
5629
5716
|
${isUsingTinaCloud ? `// Get this from tina.io
|
|
5630
5717
|
clientId: process.env.NEXT_PUBLIC_TINA_CLIENT_ID,` : ""}
|
|
5631
5718
|
${isUsingTinaCloud ? `// Get this from tina.io
|
|
@@ -5642,7 +5729,7 @@ import { LocalAuthProvider } from "tinacms";`;
|
|
|
5642
5729
|
publicFolder: "${args.publicFolder}",
|
|
5643
5730
|
},
|
|
5644
5731
|
},
|
|
5645
|
-
// See docs on content modeling for more info on how to setup new content models: https://tina.io/docs/
|
|
5732
|
+
// See docs on content modeling for more info on how to setup new content models: https://tina.io/docs/r/content-modelling-collections/
|
|
5646
5733
|
schema: {
|
|
5647
5734
|
collections: ${generateCollectionString(args)},
|
|
5648
5735
|
},
|
|
@@ -5652,11 +5739,10 @@ import { LocalAuthProvider } from "tinacms";`;
|
|
|
5652
5739
|
|
|
5653
5740
|
// src/cmds/init/templates/database.ts
|
|
5654
5741
|
var databaseTemplate = ({ config: config2 }) => {
|
|
5655
|
-
var _a, _b, _c, _d;
|
|
5656
5742
|
return `
|
|
5657
5743
|
import { createDatabase, createLocalDatabase } from '@tinacms/datalayer'
|
|
5658
|
-
${makeImportString(
|
|
5659
|
-
${makeImportString(
|
|
5744
|
+
${makeImportString(config2.gitProvider?.imports)}
|
|
5745
|
+
${makeImportString(config2.databaseAdapter?.imports)}
|
|
5660
5746
|
|
|
5661
5747
|
const branch = (process.env.GITHUB_BRANCH ||
|
|
5662
5748
|
process.env.VERCEL_GIT_COMMIT_REF ||
|
|
@@ -5668,8 +5754,8 @@ const isLocal = process.env.${config2.isLocalEnvVarName} === 'true'
|
|
|
5668
5754
|
export default isLocal
|
|
5669
5755
|
? createLocalDatabase()
|
|
5670
5756
|
: createDatabase({
|
|
5671
|
-
gitProvider: ${
|
|
5672
|
-
databaseAdapter: ${
|
|
5757
|
+
gitProvider: ${config2.gitProvider?.gitProviderClassText},
|
|
5758
|
+
databaseAdapter: ${config2.databaseAdapter?.databaseAdapterClassText},
|
|
5673
5759
|
namespace: branch,
|
|
5674
5760
|
})
|
|
5675
5761
|
`;
|
|
@@ -5680,10 +5766,9 @@ var nextApiRouteTemplate = ({
|
|
|
5680
5766
|
config: config2,
|
|
5681
5767
|
env
|
|
5682
5768
|
}) => {
|
|
5683
|
-
var _a, _b;
|
|
5684
5769
|
const extraPath = env.usingSrc ? "../" : "";
|
|
5685
5770
|
return `import { TinaNodeBackend, LocalBackendAuthProvider } from '@tinacms/datalayer'
|
|
5686
|
-
${makeImportString(
|
|
5771
|
+
${makeImportString(config2.authProvider?.backendAuthProviderImports)}
|
|
5687
5772
|
|
|
5688
5773
|
|
|
5689
5774
|
|
|
@@ -5694,7 +5779,7 @@ var nextApiRouteTemplate = ({
|
|
|
5694
5779
|
const handler = TinaNodeBackend({
|
|
5695
5780
|
authProvider: isLocal
|
|
5696
5781
|
? LocalBackendAuthProvider()
|
|
5697
|
-
: ${
|
|
5782
|
+
: ${config2.authProvider?.backendAuthProvider || ""},
|
|
5698
5783
|
databaseClient,
|
|
5699
5784
|
})
|
|
5700
5785
|
|
|
@@ -5717,62 +5802,61 @@ Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a
|
|
|
5717
5802
|
`;
|
|
5718
5803
|
|
|
5719
5804
|
// src/cmds/init/apply.ts
|
|
5720
|
-
|
|
5805
|
+
import { format as format2 } from "prettier";
|
|
5721
5806
|
|
|
5722
5807
|
// src/utils/script-helpers.ts
|
|
5723
5808
|
function generateGqlScript(scriptValue, opts) {
|
|
5724
5809
|
const cmd = `tinacms dev -c "${scriptValue}"`;
|
|
5725
|
-
if (opts
|
|
5810
|
+
if (opts?.isLocalEnvVarName) {
|
|
5726
5811
|
return `${opts.isLocalEnvVarName}=true ${cmd}`;
|
|
5727
5812
|
}
|
|
5728
5813
|
return cmd;
|
|
5729
5814
|
}
|
|
5730
5815
|
function extendNextScripts(scripts, opts) {
|
|
5731
|
-
var _a, _b;
|
|
5732
5816
|
const result = {
|
|
5733
5817
|
...scripts,
|
|
5734
|
-
dev: !
|
|
5735
|
-
build: !
|
|
5818
|
+
dev: !scripts?.dev || scripts?.dev?.indexOf("tinacms dev -c") === -1 ? generateGqlScript(scripts?.dev || "next dev", opts) : scripts?.dev,
|
|
5819
|
+
build: !scripts?.build || !scripts?.build?.startsWith("tinacms build &&") ? `tinacms build && ${scripts?.build || "next build"}` : scripts?.build
|
|
5736
5820
|
};
|
|
5737
|
-
if (
|
|
5821
|
+
if (opts?.addSetupUsers && !scripts["setup:users"]) {
|
|
5738
5822
|
result["setup:users"] = "tinacms-next-auth setup";
|
|
5739
5823
|
}
|
|
5740
5824
|
return result;
|
|
5741
5825
|
}
|
|
5742
5826
|
|
|
5743
5827
|
// src/cmds/init/codegen/index.ts
|
|
5744
|
-
|
|
5745
|
-
|
|
5828
|
+
import ts2 from "typescript";
|
|
5829
|
+
import fs13 from "fs-extra";
|
|
5746
5830
|
|
|
5747
5831
|
// src/cmds/init/codegen/util.ts
|
|
5748
|
-
|
|
5749
|
-
var makeTransformer = (makeVisitor) => (ctx) => (node) =>
|
|
5832
|
+
import ts from "typescript";
|
|
5833
|
+
var makeTransformer = (makeVisitor) => (ctx) => (node) => ts.visitNode(node, makeVisitor(ctx));
|
|
5750
5834
|
function parseExpression(expression) {
|
|
5751
|
-
const sourceFile =
|
|
5835
|
+
const sourceFile = ts.createSourceFile(
|
|
5752
5836
|
"temp.ts",
|
|
5753
5837
|
expression,
|
|
5754
|
-
|
|
5838
|
+
ts.ScriptTarget.Latest
|
|
5755
5839
|
);
|
|
5756
5840
|
if (sourceFile.statements.length !== 1) {
|
|
5757
5841
|
throw new Error("Expected one statement");
|
|
5758
5842
|
}
|
|
5759
5843
|
const statement = sourceFile.statements[0];
|
|
5760
|
-
if (!
|
|
5844
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
5761
5845
|
throw new Error("Expected an expression statement");
|
|
5762
5846
|
}
|
|
5763
5847
|
return [sourceFile, statement.expression];
|
|
5764
5848
|
}
|
|
5765
5849
|
function parseVariableStatement(stmt) {
|
|
5766
|
-
const sourceFile =
|
|
5850
|
+
const sourceFile = ts.createSourceFile(
|
|
5767
5851
|
"temp.ts",
|
|
5768
5852
|
stmt,
|
|
5769
|
-
|
|
5853
|
+
ts.ScriptTarget.Latest
|
|
5770
5854
|
);
|
|
5771
5855
|
if (sourceFile.statements.length !== 1) {
|
|
5772
5856
|
throw new Error("Expected one statement");
|
|
5773
5857
|
}
|
|
5774
5858
|
const statement = sourceFile.statements[0];
|
|
5775
|
-
if (!
|
|
5859
|
+
if (!ts.isVariableStatement(statement)) {
|
|
5776
5860
|
throw new Error("Expected a variable statement");
|
|
5777
5861
|
}
|
|
5778
5862
|
return [sourceFile, statement];
|
|
@@ -5780,7 +5864,7 @@ function parseVariableStatement(stmt) {
|
|
|
5780
5864
|
|
|
5781
5865
|
// src/cmds/init/codegen/index.ts
|
|
5782
5866
|
var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variableStmt) => (ctx) => (node) => {
|
|
5783
|
-
if (
|
|
5867
|
+
if (ts2.isSourceFile(node)) {
|
|
5784
5868
|
const newStatements = [...node.statements];
|
|
5785
5869
|
let encounteredImports = false;
|
|
5786
5870
|
let firstNonImportStatementIdx = -1;
|
|
@@ -5788,7 +5872,7 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5788
5872
|
const [newVarDec] = variableStmt.declarationList.declarations;
|
|
5789
5873
|
const newVarDecName = newVarDec.name.getText(variableStmtSourceFile);
|
|
5790
5874
|
for (let i = 0; i < newStatements.length; i++) {
|
|
5791
|
-
const isImport =
|
|
5875
|
+
const isImport = ts2.isImportDeclaration(newStatements[i]);
|
|
5792
5876
|
if (isImport && !encounteredImports) {
|
|
5793
5877
|
encounteredImports = true;
|
|
5794
5878
|
}
|
|
@@ -5796,9 +5880,9 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5796
5880
|
firstNonImportStatementIdx = i;
|
|
5797
5881
|
}
|
|
5798
5882
|
const stmt = newStatements[i];
|
|
5799
|
-
if (
|
|
5883
|
+
if (ts2.isVariableStatement(stmt)) {
|
|
5800
5884
|
const [dec] = stmt.declarationList.declarations;
|
|
5801
|
-
if (dec.name &&
|
|
5885
|
+
if (dec.name && ts2.isIdentifier(dec.name) && dec.name.getText(sourceFile) === newVarDecName) {
|
|
5802
5886
|
existingStatementIdx = i;
|
|
5803
5887
|
}
|
|
5804
5888
|
}
|
|
@@ -5812,20 +5896,19 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5812
5896
|
if (existingStatementIdx === -1) {
|
|
5813
5897
|
newStatements.splice(firstNonImportStatementIdx, 0, variableStmt);
|
|
5814
5898
|
}
|
|
5815
|
-
return
|
|
5899
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5816
5900
|
}
|
|
5817
5901
|
};
|
|
5818
5902
|
var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
5819
|
-
|
|
5820
|
-
if (import_typescript3.default.isSourceFile(node)) {
|
|
5903
|
+
if (ts2.isSourceFile(node)) {
|
|
5821
5904
|
const newStatements = [...node.statements];
|
|
5822
5905
|
let changed = false;
|
|
5823
5906
|
for (const [moduleName, imports] of Object.entries(importMap)) {
|
|
5824
5907
|
let foundImportStatement = false;
|
|
5825
5908
|
for (const statement of newStatements) {
|
|
5826
|
-
if (
|
|
5909
|
+
if (ts2.isImportDeclaration(statement) && ts2.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === moduleName) {
|
|
5827
5910
|
foundImportStatement = true;
|
|
5828
|
-
const existingImports =
|
|
5911
|
+
const existingImports = statement.importClause?.namedBindings && ts2.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements.map(
|
|
5829
5912
|
(e) => e.name.text
|
|
5830
5913
|
) : [];
|
|
5831
5914
|
const newImports = [
|
|
@@ -5836,22 +5919,22 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5836
5919
|
])
|
|
5837
5920
|
];
|
|
5838
5921
|
const importSpecifiers = newImports.map(
|
|
5839
|
-
(i) =>
|
|
5922
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5840
5923
|
void 0,
|
|
5841
|
-
|
|
5842
|
-
|
|
5924
|
+
ts2.factory.createIdentifier(i),
|
|
5925
|
+
ts2.factory.createIdentifier(i)
|
|
5843
5926
|
)
|
|
5844
5927
|
);
|
|
5845
|
-
const namedImports =
|
|
5846
|
-
const importClause =
|
|
5928
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5929
|
+
const importClause = ts2.factory.createImportClause(
|
|
5847
5930
|
false,
|
|
5848
5931
|
void 0,
|
|
5849
5932
|
namedImports
|
|
5850
5933
|
);
|
|
5851
|
-
const importDec =
|
|
5934
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5852
5935
|
void 0,
|
|
5853
5936
|
importClause,
|
|
5854
|
-
|
|
5937
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5855
5938
|
);
|
|
5856
5939
|
newStatements[newStatements.indexOf(statement)] = importDec;
|
|
5857
5940
|
changed = true;
|
|
@@ -5859,45 +5942,45 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5859
5942
|
}
|
|
5860
5943
|
if (!foundImportStatement) {
|
|
5861
5944
|
const importSpecifiers = imports.map(
|
|
5862
|
-
(i) =>
|
|
5945
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5863
5946
|
void 0,
|
|
5864
|
-
|
|
5865
|
-
|
|
5947
|
+
ts2.factory.createIdentifier(i),
|
|
5948
|
+
ts2.factory.createIdentifier(i)
|
|
5866
5949
|
)
|
|
5867
5950
|
);
|
|
5868
|
-
const namedImports =
|
|
5869
|
-
const importClause =
|
|
5951
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5952
|
+
const importClause = ts2.factory.createImportClause(
|
|
5870
5953
|
false,
|
|
5871
5954
|
void 0,
|
|
5872
5955
|
namedImports
|
|
5873
5956
|
);
|
|
5874
|
-
const importDec =
|
|
5957
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5875
5958
|
void 0,
|
|
5876
5959
|
importClause,
|
|
5877
|
-
|
|
5960
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5878
5961
|
);
|
|
5879
5962
|
newStatements.unshift(importDec);
|
|
5880
5963
|
changed = true;
|
|
5881
5964
|
}
|
|
5882
5965
|
}
|
|
5883
5966
|
if (changed) {
|
|
5884
|
-
return
|
|
5967
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5885
5968
|
}
|
|
5886
5969
|
}
|
|
5887
5970
|
};
|
|
5888
5971
|
var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newExpressionSourceFile, newExpression) => (ctx) => {
|
|
5889
5972
|
const visit2 = (node) => {
|
|
5890
|
-
if (
|
|
5973
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5891
5974
|
const configObject = node.arguments[0];
|
|
5892
5975
|
const updateProperties = configObject.properties.map((property) => {
|
|
5893
|
-
if (
|
|
5976
|
+
if (ts2.isPropertyAssignment(property)) {
|
|
5894
5977
|
const thisPropertyName = property.name.getText(sourceFile);
|
|
5895
|
-
if (thisPropertyName === "schema" &&
|
|
5978
|
+
if (thisPropertyName === "schema" && ts2.isPropertyAssignment(property) && ts2.isObjectLiteralExpression(property.initializer)) {
|
|
5896
5979
|
const schemaObject = property.initializer;
|
|
5897
5980
|
const collectionsProperty = schemaObject.properties.find(
|
|
5898
|
-
(p) =>
|
|
5981
|
+
(p) => ts2.isPropertyAssignment(p) && p.name.getText(sourceFile) === "collections"
|
|
5899
5982
|
);
|
|
5900
|
-
if (collectionsProperty &&
|
|
5983
|
+
if (collectionsProperty && ts2.isPropertyAssignment(collectionsProperty) && ts2.isArrayLiteralExpression(collectionsProperty.initializer)) {
|
|
5901
5984
|
const collectionsArray = collectionsProperty.initializer;
|
|
5902
5985
|
const collectionItems = collectionsArray.elements.map(
|
|
5903
5986
|
(e) => e.getText(sourceFile)
|
|
@@ -5907,16 +5990,16 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5907
5990
|
)) {
|
|
5908
5991
|
return property;
|
|
5909
5992
|
}
|
|
5910
|
-
return
|
|
5993
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5911
5994
|
property,
|
|
5912
5995
|
property.name,
|
|
5913
|
-
|
|
5996
|
+
ts2.factory.createObjectLiteralExpression(
|
|
5914
5997
|
schemaObject.properties.map((subProp) => {
|
|
5915
|
-
if (
|
|
5916
|
-
return
|
|
5998
|
+
if (ts2.isPropertyAssignment(subProp) && subProp.name.getText(sourceFile) === "collections" && ts2.isArrayLiteralExpression(subProp.initializer)) {
|
|
5999
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5917
6000
|
subProp,
|
|
5918
6001
|
subProp.name,
|
|
5919
|
-
|
|
6002
|
+
ts2.factory.createArrayLiteralExpression(
|
|
5920
6003
|
[newExpression, ...subProp.initializer.elements],
|
|
5921
6004
|
true
|
|
5922
6005
|
)
|
|
@@ -5932,56 +6015,56 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5932
6015
|
}
|
|
5933
6016
|
return property;
|
|
5934
6017
|
});
|
|
5935
|
-
return
|
|
6018
|
+
return ts2.factory.createCallExpression(
|
|
5936
6019
|
node.expression,
|
|
5937
6020
|
node.typeArguments,
|
|
5938
|
-
[
|
|
6021
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
5939
6022
|
);
|
|
5940
6023
|
}
|
|
5941
|
-
return
|
|
6024
|
+
return ts2.visitEachChild(node, visit2, ctx);
|
|
5942
6025
|
};
|
|
5943
6026
|
return (sourceFile2) => {
|
|
5944
|
-
return
|
|
6027
|
+
return ts2.visitEachChild(sourceFile2, visit2, ctx);
|
|
5945
6028
|
};
|
|
5946
6029
|
};
|
|
5947
6030
|
var makeUpdateObjectLiteralPropertyVisitor = (sourceFile, functionName, propertyName, propertyValueExpressionSourceFile, propertyValue) => (ctx) => {
|
|
5948
6031
|
const visitor = (node) => {
|
|
5949
|
-
if (
|
|
6032
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5950
6033
|
let foundProperty = false;
|
|
5951
6034
|
const configObject = node.arguments[0];
|
|
5952
6035
|
const updateProperties = configObject.properties.map((property) => {
|
|
5953
|
-
if (
|
|
6036
|
+
if (ts2.isPropertyAssignment(property) || ts2.isShorthandPropertyAssignment(property)) {
|
|
5954
6037
|
const name2 = property.name.getText(sourceFile);
|
|
5955
6038
|
if (name2 === propertyName) {
|
|
5956
6039
|
foundProperty = true;
|
|
5957
|
-
return
|
|
6040
|
+
return ts2.factory.createPropertyAssignment(name2, propertyValue);
|
|
5958
6041
|
}
|
|
5959
6042
|
}
|
|
5960
6043
|
return property;
|
|
5961
6044
|
});
|
|
5962
6045
|
if (!foundProperty) {
|
|
5963
6046
|
updateProperties.unshift(
|
|
5964
|
-
|
|
6047
|
+
ts2.factory.createPropertyAssignment(propertyName, propertyValue)
|
|
5965
6048
|
);
|
|
5966
6049
|
}
|
|
5967
|
-
return
|
|
6050
|
+
return ts2.factory.createCallExpression(
|
|
5968
6051
|
node.expression,
|
|
5969
6052
|
node.typeArguments,
|
|
5970
|
-
[
|
|
6053
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
5971
6054
|
);
|
|
5972
6055
|
}
|
|
5973
|
-
return
|
|
6056
|
+
return ts2.visitEachChild(node, visitor, ctx);
|
|
5974
6057
|
};
|
|
5975
6058
|
return (sourceFile2) => {
|
|
5976
|
-
return
|
|
6059
|
+
return ts2.visitNode(sourceFile2, visitor);
|
|
5977
6060
|
};
|
|
5978
6061
|
};
|
|
5979
6062
|
var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
5980
6063
|
const pathToConfig = configFile.resolve(config2.typescript).path;
|
|
5981
|
-
const sourceFile =
|
|
6064
|
+
const sourceFile = ts2.createSourceFile(
|
|
5982
6065
|
pathToConfig,
|
|
5983
|
-
|
|
5984
|
-
config2.typescript ?
|
|
6066
|
+
fs13.readFileSync(pathToConfig, "utf8"),
|
|
6067
|
+
config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
|
|
5985
6068
|
);
|
|
5986
6069
|
const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
|
|
5987
6070
|
const importMap = {
|
|
@@ -5994,7 +6077,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
5994
6077
|
{}
|
|
5995
6078
|
)
|
|
5996
6079
|
};
|
|
5997
|
-
const transformedSourceFileResult =
|
|
6080
|
+
const transformedSourceFileResult = ts2.transform(
|
|
5998
6081
|
sourceFile,
|
|
5999
6082
|
[
|
|
6000
6083
|
makeImportsVisitor(sourceFile, {
|
|
@@ -6030,19 +6113,19 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6030
6113
|
)
|
|
6031
6114
|
].map((visitor) => makeTransformer(visitor))
|
|
6032
6115
|
);
|
|
6033
|
-
return
|
|
6116
|
+
return fs13.writeFile(
|
|
6034
6117
|
pathToConfig,
|
|
6035
|
-
|
|
6118
|
+
ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
|
|
6036
6119
|
);
|
|
6037
6120
|
};
|
|
6038
6121
|
|
|
6039
6122
|
// src/cmds/init/apply.ts
|
|
6123
|
+
import { exec } from "child_process";
|
|
6040
6124
|
async function apply({
|
|
6041
6125
|
env,
|
|
6042
6126
|
params,
|
|
6043
6127
|
config: config2
|
|
6044
6128
|
}) {
|
|
6045
|
-
var _a;
|
|
6046
6129
|
if (config2.framework.name === "other" && config2.hosting === "self-host") {
|
|
6047
6130
|
logger.error(
|
|
6048
6131
|
logText(
|
|
@@ -6148,8 +6231,8 @@ async function apply({
|
|
|
6148
6231
|
await addConfigFile({
|
|
6149
6232
|
configArgs: {
|
|
6150
6233
|
config: config2,
|
|
6151
|
-
publicFolder:
|
|
6152
|
-
|
|
6234
|
+
publicFolder: path14.join(
|
|
6235
|
+
path14.relative(process.cwd(), pathToForestryConfig),
|
|
6153
6236
|
config2.publicFolder
|
|
6154
6237
|
),
|
|
6155
6238
|
collections,
|
|
@@ -6168,7 +6251,7 @@ async function apply({
|
|
|
6168
6251
|
env.tinaConfigExists && // Are we running tinacms init backend
|
|
6169
6252
|
params.isBackendInit && // Do the user choose the 'self-host' option
|
|
6170
6253
|
config2.hosting === "self-host" && // the user did not choose the 'tina-cloud' auth provider
|
|
6171
|
-
(
|
|
6254
|
+
(config2.authProvider?.name || "") !== "tina-cloud"
|
|
6172
6255
|
) {
|
|
6173
6256
|
await addSelfHostedTinaAuthToConfig(config2, env.generatedFiles["config"]);
|
|
6174
6257
|
}
|
|
@@ -6206,7 +6289,7 @@ var reportTelemetry = async ({
|
|
|
6206
6289
|
if (noTelemetry) {
|
|
6207
6290
|
logger.info(logText("Telemetry disabled"));
|
|
6208
6291
|
}
|
|
6209
|
-
const telemetry = new
|
|
6292
|
+
const telemetry = new Telemetry2({ disabled: noTelemetry });
|
|
6210
6293
|
const schemaFileType = usingTypescript ? "ts" : "js";
|
|
6211
6294
|
await telemetry.submitRecord({
|
|
6212
6295
|
event: {
|
|
@@ -6222,21 +6305,20 @@ var createPackageJSON = async () => {
|
|
|
6222
6305
|
};
|
|
6223
6306
|
var createGitignore = async ({ baseDir }) => {
|
|
6224
6307
|
logger.info(logText("No .gitignore found, creating one"));
|
|
6225
|
-
|
|
6308
|
+
fs14.outputFileSync(path14.join(baseDir, ".gitignore"), "node_modules");
|
|
6226
6309
|
};
|
|
6227
6310
|
var updateGitIgnore = async ({
|
|
6228
6311
|
baseDir,
|
|
6229
6312
|
items
|
|
6230
6313
|
}) => {
|
|
6231
6314
|
logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
|
|
6232
|
-
const gitignoreContent =
|
|
6315
|
+
const gitignoreContent = fs14.readFileSync(path14.join(baseDir, ".gitignore")).toString();
|
|
6233
6316
|
const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
|
|
6234
6317
|
"\n"
|
|
6235
6318
|
);
|
|
6236
|
-
await
|
|
6319
|
+
await fs14.writeFile(path14.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
6237
6320
|
};
|
|
6238
6321
|
var addDependencies = async (config2, env, params) => {
|
|
6239
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
6240
6322
|
const { packageManager } = config2;
|
|
6241
6323
|
const tagVersion = params.tinaVersion ? `@${params.tinaVersion}` : "";
|
|
6242
6324
|
let deps = [];
|
|
@@ -6252,18 +6334,18 @@ var addDependencies = async (config2, env, params) => {
|
|
|
6252
6334
|
deps.push("@tinacms/datalayer");
|
|
6253
6335
|
}
|
|
6254
6336
|
deps.push(
|
|
6255
|
-
...
|
|
6337
|
+
...config2.databaseAdapter?.imports?.map((x) => x.packageName) || []
|
|
6256
6338
|
);
|
|
6257
|
-
deps.push(...
|
|
6339
|
+
deps.push(...config2.authProvider?.peerDependencies || []);
|
|
6258
6340
|
deps.push(
|
|
6259
|
-
...
|
|
6341
|
+
...config2.authProvider?.backendAuthProviderImports?.map(
|
|
6260
6342
|
(x) => x.packageName
|
|
6261
|
-
)
|
|
6343
|
+
) || []
|
|
6262
6344
|
);
|
|
6263
6345
|
deps.push(
|
|
6264
|
-
...
|
|
6346
|
+
...config2.authProvider?.configImports?.map((x) => x.packageName) || []
|
|
6265
6347
|
);
|
|
6266
|
-
deps.push(...
|
|
6348
|
+
deps.push(...config2.gitProvider?.imports?.map((x) => x.packageName) || []);
|
|
6267
6349
|
if (tagVersion) {
|
|
6268
6350
|
deps = deps.map(
|
|
6269
6351
|
(dep) => dep.indexOf("tina") >= 0 ? `${dep}${tagVersion}` : dep
|
|
@@ -6275,7 +6357,8 @@ var addDependencies = async (config2, env, params) => {
|
|
|
6275
6357
|
let packageManagers = {
|
|
6276
6358
|
pnpm: process.env.USE_WORKSPACE ? `pnpm add ${deps.join(" ")} --workspace` : `pnpm add ${deps.join(" ")}`,
|
|
6277
6359
|
npm: `npm install ${deps.join(" ")}`,
|
|
6278
|
-
yarn: `yarn add ${deps.join(" ")}
|
|
6360
|
+
yarn: `yarn add ${deps.join(" ")}`,
|
|
6361
|
+
bun: `bun add ${deps.join(" ")}`
|
|
6279
6362
|
};
|
|
6280
6363
|
if (packageManagers[packageManager] && deps.length > 0) {
|
|
6281
6364
|
logger.info(logText("Adding dependencies, this might take a moment..."));
|
|
@@ -6286,7 +6369,8 @@ var addDependencies = async (config2, env, params) => {
|
|
|
6286
6369
|
packageManagers = {
|
|
6287
6370
|
pnpm: process.env.USE_WORKSPACE ? `pnpm add -D ${devDeps.join(" ")} --workspace` : `pnpm add -D ${devDeps.join(" ")}`,
|
|
6288
6371
|
npm: `npm install -D ${devDeps.join(" ")}`,
|
|
6289
|
-
yarn: `yarn add -D ${devDeps.join(" ")}
|
|
6372
|
+
yarn: `yarn add -D ${devDeps.join(" ")}`,
|
|
6373
|
+
bun: `bun add -D ${devDeps.join(" ")}`
|
|
6290
6374
|
};
|
|
6291
6375
|
if (packageManagers[packageManager]) {
|
|
6292
6376
|
logger.info(
|
|
@@ -6303,22 +6387,22 @@ var writeGeneratedFile = async ({
|
|
|
6303
6387
|
content,
|
|
6304
6388
|
typescript
|
|
6305
6389
|
}) => {
|
|
6306
|
-
const { exists, path:
|
|
6390
|
+
const { exists, path: path15, parentPath } = generatedFile.resolve(typescript);
|
|
6307
6391
|
if (exists) {
|
|
6308
6392
|
if (overwrite) {
|
|
6309
|
-
logger.info(`Overwriting file at ${
|
|
6310
|
-
|
|
6393
|
+
logger.info(`Overwriting file at ${path15}... \u2705`);
|
|
6394
|
+
fs14.outputFileSync(path15, content);
|
|
6311
6395
|
} else {
|
|
6312
|
-
logger.info(`Not overwriting file at ${
|
|
6396
|
+
logger.info(`Not overwriting file at ${path15}.`);
|
|
6313
6397
|
logger.info(
|
|
6314
|
-
logText(`Please add the following to ${
|
|
6398
|
+
logText(`Please add the following to ${path15}:
|
|
6315
6399
|
${indentText(content)}}`)
|
|
6316
6400
|
);
|
|
6317
6401
|
}
|
|
6318
6402
|
} else {
|
|
6319
|
-
logger.info(`Adding file at ${
|
|
6320
|
-
await
|
|
6321
|
-
|
|
6403
|
+
logger.info(`Adding file at ${path15}... \u2705`);
|
|
6404
|
+
await fs14.ensureDir(parentPath);
|
|
6405
|
+
fs14.outputFileSync(path15, content);
|
|
6322
6406
|
}
|
|
6323
6407
|
};
|
|
6324
6408
|
var addConfigFile = async ({
|
|
@@ -6327,12 +6411,11 @@ var addConfigFile = async ({
|
|
|
6327
6411
|
generatedFile,
|
|
6328
6412
|
config: config2
|
|
6329
6413
|
}) => {
|
|
6330
|
-
|
|
6331
|
-
const content = (0, import_prettier2.format)(generateConfig(configArgs), {
|
|
6414
|
+
const content = format2(generateConfig(configArgs), {
|
|
6332
6415
|
parser: "babel"
|
|
6333
6416
|
});
|
|
6334
6417
|
await writeGeneratedFile({
|
|
6335
|
-
overwrite:
|
|
6418
|
+
overwrite: config2.overwriteList?.includes("config"),
|
|
6336
6419
|
generatedFile,
|
|
6337
6420
|
content,
|
|
6338
6421
|
typescript: config2.typescript
|
|
@@ -6346,10 +6429,9 @@ var addDatabaseFile = async ({
|
|
|
6346
6429
|
config: config2,
|
|
6347
6430
|
generatedFile
|
|
6348
6431
|
}) => {
|
|
6349
|
-
var _a;
|
|
6350
6432
|
await writeGeneratedFile({
|
|
6351
6433
|
generatedFile,
|
|
6352
|
-
overwrite:
|
|
6434
|
+
overwrite: config2.overwriteList?.includes("database"),
|
|
6353
6435
|
content: databaseTemplate({ config: config2 }),
|
|
6354
6436
|
typescript: config2.typescript
|
|
6355
6437
|
});
|
|
@@ -6359,13 +6441,12 @@ var addNextApiRoute = async ({
|
|
|
6359
6441
|
generatedFile,
|
|
6360
6442
|
env
|
|
6361
6443
|
}) => {
|
|
6362
|
-
|
|
6363
|
-
const content = (0, import_prettier2.format)(nextApiRouteTemplate({ config: config2, env }), {
|
|
6444
|
+
const content = format2(nextApiRouteTemplate({ config: config2, env }), {
|
|
6364
6445
|
parser: "babel"
|
|
6365
6446
|
});
|
|
6366
6447
|
await writeGeneratedFile({
|
|
6367
6448
|
generatedFile,
|
|
6368
|
-
overwrite:
|
|
6449
|
+
overwrite: config2.overwriteList?.includes("next-api-handler"),
|
|
6369
6450
|
content,
|
|
6370
6451
|
typescript: config2.typescript
|
|
6371
6452
|
});
|
|
@@ -6375,10 +6456,9 @@ var addTemplateFile = async ({
|
|
|
6375
6456
|
generatedFile,
|
|
6376
6457
|
config: config2
|
|
6377
6458
|
}) => {
|
|
6378
|
-
var _a;
|
|
6379
6459
|
await writeGeneratedFile({
|
|
6380
6460
|
generatedFile,
|
|
6381
|
-
overwrite:
|
|
6461
|
+
overwrite: config2.overwriteList?.includes(generatedFile.generatedFileType),
|
|
6382
6462
|
content,
|
|
6383
6463
|
typescript: config2.typescript
|
|
6384
6464
|
});
|
|
@@ -6387,7 +6467,6 @@ var addContentFile = async ({
|
|
|
6387
6467
|
config: config2,
|
|
6388
6468
|
env
|
|
6389
6469
|
}) => {
|
|
6390
|
-
var _a;
|
|
6391
6470
|
await writeGeneratedFile({
|
|
6392
6471
|
generatedFile: {
|
|
6393
6472
|
javascriptExists: false,
|
|
@@ -6401,11 +6480,11 @@ var addContentFile = async ({
|
|
|
6401
6480
|
return () => ({
|
|
6402
6481
|
exists: env.sampleContentExists,
|
|
6403
6482
|
path: env.sampleContentPath,
|
|
6404
|
-
parentPath:
|
|
6483
|
+
parentPath: path14.dirname(env.sampleContentPath)
|
|
6405
6484
|
});
|
|
6406
6485
|
}
|
|
6407
6486
|
},
|
|
6408
|
-
overwrite:
|
|
6487
|
+
overwrite: config2.overwriteList?.includes("sample-content"),
|
|
6409
6488
|
content: helloWorldPost,
|
|
6410
6489
|
typescript: false
|
|
6411
6490
|
});
|
|
@@ -6424,10 +6503,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
|
|
|
6424
6503
|
return `${x.key}=${x.value || "***"}`;
|
|
6425
6504
|
}).join("\n") + `
|
|
6426
6505
|
TINA_PUBLIC_IS_LOCAL=true`;
|
|
6427
|
-
const envFile =
|
|
6428
|
-
if (!
|
|
6506
|
+
const envFile = path14.join(process.cwd(), ".env");
|
|
6507
|
+
if (!fs14.existsSync(envFile)) {
|
|
6429
6508
|
logger.info(`Adding .env file to your project... \u2705`);
|
|
6430
|
-
|
|
6509
|
+
fs14.writeFileSync(envFile, envFileText);
|
|
6431
6510
|
} else {
|
|
6432
6511
|
logger.info(
|
|
6433
6512
|
"Please add the following environment variables to your .env file"
|
|
@@ -6470,7 +6549,8 @@ var other = ({ packageManager }) => {
|
|
|
6470
6549
|
pnpm: `pnpm`,
|
|
6471
6550
|
npm: `npx`,
|
|
6472
6551
|
// npx is the way to run executables that aren't in your "scripts"
|
|
6473
|
-
yarn: `yarn
|
|
6552
|
+
yarn: `yarn`,
|
|
6553
|
+
bun: `bun run`
|
|
6474
6554
|
};
|
|
6475
6555
|
return `${packageManagers[packageManager]} tinacms dev -c "<your dev command>"`;
|
|
6476
6556
|
};
|
|
@@ -6483,7 +6563,8 @@ var frameworkDevCmds = {
|
|
|
6483
6563
|
pnpm: `pnpm`,
|
|
6484
6564
|
npm: `npm run`,
|
|
6485
6565
|
// npx is the way to run executables that aren't in your "scripts"
|
|
6486
|
-
yarn: `yarn
|
|
6566
|
+
yarn: `yarn`,
|
|
6567
|
+
bun: `bun run`
|
|
6487
6568
|
};
|
|
6488
6569
|
return `${packageManagers[packageManager]} dev`;
|
|
6489
6570
|
}
|
|
@@ -6496,12 +6577,11 @@ var addReactiveFile = {
|
|
|
6496
6577
|
baseDir,
|
|
6497
6578
|
dataLayer
|
|
6498
6579
|
}) => {
|
|
6499
|
-
|
|
6500
|
-
const packageJsonPath = import_path11.default.join(baseDir, "package.json");
|
|
6580
|
+
const packageJsonPath = path14.join(baseDir, "package.json");
|
|
6501
6581
|
await writeGeneratedFile({
|
|
6502
6582
|
generatedFile,
|
|
6503
6583
|
typescript: config2.typescript,
|
|
6504
|
-
overwrite:
|
|
6584
|
+
overwrite: config2.overwriteList?.includes(
|
|
6505
6585
|
generatedFile.generatedFileType
|
|
6506
6586
|
),
|
|
6507
6587
|
content: templates["demo-post-page"]({
|
|
@@ -6510,24 +6590,23 @@ var addReactiveFile = {
|
|
|
6510
6590
|
})
|
|
6511
6591
|
});
|
|
6512
6592
|
logger.info("Adding a nextjs example... \u2705");
|
|
6513
|
-
const packageJson = JSON.parse(
|
|
6593
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath).toString());
|
|
6514
6594
|
const scripts = packageJson.scripts || {};
|
|
6515
6595
|
const updatedPackageJson = JSON.stringify(
|
|
6516
6596
|
{
|
|
6517
6597
|
...packageJson,
|
|
6518
6598
|
scripts: extendNextScripts(scripts, {
|
|
6519
6599
|
isLocalEnvVarName: config2.isLocalEnvVarName,
|
|
6520
|
-
addSetupUsers:
|
|
6600
|
+
addSetupUsers: config2.authProvider?.name === "next-auth"
|
|
6521
6601
|
})
|
|
6522
6602
|
},
|
|
6523
6603
|
null,
|
|
6524
6604
|
2
|
|
6525
6605
|
);
|
|
6526
|
-
|
|
6606
|
+
fs14.writeFileSync(packageJsonPath, updatedPackageJson);
|
|
6527
6607
|
}
|
|
6528
6608
|
};
|
|
6529
6609
|
function execShellCommand(cmd) {
|
|
6530
|
-
const exec = require("child_process").exec;
|
|
6531
6610
|
return new Promise((resolve2, reject) => {
|
|
6532
6611
|
exec(cmd, (error, stdout, stderr) => {
|
|
6533
6612
|
if (error) {
|
|
@@ -6573,25 +6652,27 @@ var command = new CLICommand({
|
|
|
6573
6652
|
});
|
|
6574
6653
|
|
|
6575
6654
|
// src/next/commands/init-command/index.ts
|
|
6576
|
-
var InitCommand = class extends
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6655
|
+
var InitCommand = class extends Command6 {
|
|
6656
|
+
static paths = [["init"], ["init", "backend"]];
|
|
6657
|
+
pathToForestryConfig = Option6.String("--forestryPath", {
|
|
6658
|
+
description: "Specify the relative path to the .forestry directory, if importing an existing forestry site."
|
|
6659
|
+
});
|
|
6660
|
+
rootPath = Option6.String("--rootPath", {
|
|
6661
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6662
|
+
});
|
|
6663
|
+
debug = Option6.Boolean("--debug", false, {
|
|
6664
|
+
description: "Enable debug logging"
|
|
6665
|
+
});
|
|
6666
|
+
noTelemetry = Option6.Boolean("--noTelemetry", false, {
|
|
6667
|
+
description: "Disable anonymous telemetry that is collected"
|
|
6668
|
+
});
|
|
6669
|
+
tinaVersion = Option6.String("--tinaVersion", {
|
|
6670
|
+
description: "Specify a version for tina dependencies"
|
|
6671
|
+
});
|
|
6672
|
+
static usage = Command6.Usage({
|
|
6673
|
+
category: `Commands`,
|
|
6674
|
+
description: `Add Tina to an existing project`
|
|
6675
|
+
});
|
|
6595
6676
|
async catch(error) {
|
|
6596
6677
|
logger.error("Error occured during tinacms init");
|
|
6597
6678
|
console.error(error);
|
|
@@ -6611,33 +6692,32 @@ var InitCommand = class extends import_clipanion6.Command {
|
|
|
6611
6692
|
process.exit();
|
|
6612
6693
|
}
|
|
6613
6694
|
};
|
|
6614
|
-
InitCommand.paths = [["init"], ["init", "backend"]];
|
|
6615
|
-
InitCommand.usage = import_clipanion6.Command.Usage({
|
|
6616
|
-
category: `Commands`,
|
|
6617
|
-
description: `Add Tina to an existing project`
|
|
6618
|
-
});
|
|
6619
6695
|
|
|
6620
6696
|
// src/next/commands/searchindex-command/index.ts
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6697
|
+
import { Command as Command7, Option as Option7 } from "clipanion";
|
|
6698
|
+
import { createSchema, FilesystemBridge as FilesystemBridge4 } from "@tinacms/graphql";
|
|
6699
|
+
import {
|
|
6700
|
+
SearchIndexer as SearchIndexer3,
|
|
6701
|
+
TinaCMSSearchIndexClient as TinaCMSSearchIndexClient2
|
|
6702
|
+
} from "@tinacms/search";
|
|
6703
|
+
var SearchIndexCommand = class extends Command7 {
|
|
6704
|
+
static paths = [["search-index"]];
|
|
6705
|
+
rootPath = Option7.String("--rootPath", {
|
|
6706
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6707
|
+
});
|
|
6708
|
+
verbose = Option7.Boolean("-v,--verbose", false, {
|
|
6709
|
+
description: "increase verbosity of logged output"
|
|
6710
|
+
});
|
|
6711
|
+
static usage = Command7.Usage({
|
|
6712
|
+
category: `Commands`,
|
|
6713
|
+
description: `Index the site for search`
|
|
6714
|
+
});
|
|
6634
6715
|
async catch(error) {
|
|
6635
6716
|
logger.error("Error occured during tinacms search-index");
|
|
6636
6717
|
console.error(error);
|
|
6637
6718
|
process.exit(1);
|
|
6638
6719
|
}
|
|
6639
6720
|
async execute() {
|
|
6640
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
6641
6721
|
const rootPath = this.rootPath || process.cwd();
|
|
6642
6722
|
const configManager = new ConfigManager({ rootPath });
|
|
6643
6723
|
try {
|
|
@@ -6648,18 +6728,18 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6648
6728
|
console.error(e);
|
|
6649
6729
|
}
|
|
6650
6730
|
}
|
|
6651
|
-
if (!
|
|
6731
|
+
if (!configManager.config?.search) {
|
|
6652
6732
|
logger.error("No search config found");
|
|
6653
6733
|
process.exit(1);
|
|
6654
6734
|
}
|
|
6655
6735
|
const { schema } = configManager.config;
|
|
6656
|
-
const tinaSchema = await
|
|
6736
|
+
const tinaSchema = await createSchema({
|
|
6657
6737
|
schema: { ...schema, config: configManager.config }
|
|
6658
6738
|
});
|
|
6659
6739
|
let client;
|
|
6660
|
-
const hasTinaSearch = Boolean(
|
|
6740
|
+
const hasTinaSearch = Boolean(configManager.config?.search?.tina);
|
|
6661
6741
|
if (hasTinaSearch) {
|
|
6662
|
-
if (!
|
|
6742
|
+
if (!configManager.config?.branch) {
|
|
6663
6743
|
logger.error(
|
|
6664
6744
|
`${dangerText(
|
|
6665
6745
|
`ERROR: Branch not configured in tina search configuration.`
|
|
@@ -6667,11 +6747,11 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6667
6747
|
);
|
|
6668
6748
|
throw new Error("Branch not configured in tina search configuration.");
|
|
6669
6749
|
}
|
|
6670
|
-
if (!
|
|
6750
|
+
if (!configManager.config?.clientId) {
|
|
6671
6751
|
logger.error(`${dangerText(`ERROR: clientId not configured.`)}`);
|
|
6672
6752
|
throw new Error("clientId not configured.");
|
|
6673
6753
|
}
|
|
6674
|
-
if (!
|
|
6754
|
+
if (!configManager.config?.search?.tina?.indexerToken) {
|
|
6675
6755
|
logger.error(
|
|
6676
6756
|
`${dangerText(
|
|
6677
6757
|
`ERROR: indexerToken not configured in tina search configuration.`
|
|
@@ -6681,23 +6761,23 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6681
6761
|
"indexerToken not configured in tina search configuration."
|
|
6682
6762
|
);
|
|
6683
6763
|
}
|
|
6684
|
-
client = new
|
|
6685
|
-
apiUrl: `${
|
|
6686
|
-
branch:
|
|
6687
|
-
indexerToken:
|
|
6688
|
-
stopwordLanguages:
|
|
6764
|
+
client = new TinaCMSSearchIndexClient2({
|
|
6765
|
+
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
6766
|
+
branch: configManager.config?.branch,
|
|
6767
|
+
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
6768
|
+
stopwordLanguages: configManager.config?.search?.tina?.stopwordLanguages
|
|
6689
6769
|
});
|
|
6690
6770
|
} else {
|
|
6691
|
-
client =
|
|
6771
|
+
client = configManager.config?.search?.searchClient;
|
|
6692
6772
|
}
|
|
6693
|
-
const searchIndexer = new
|
|
6694
|
-
batchSize:
|
|
6695
|
-
bridge: new
|
|
6773
|
+
const searchIndexer = new SearchIndexer3({
|
|
6774
|
+
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
6775
|
+
bridge: new FilesystemBridge4(
|
|
6696
6776
|
configManager.rootPath,
|
|
6697
6777
|
configManager.contentRootPath
|
|
6698
6778
|
),
|
|
6699
6779
|
schema: tinaSchema,
|
|
6700
|
-
textIndexLength:
|
|
6780
|
+
textIndexLength: configManager.config.search?.maxSearchIndexFieldLength || 100,
|
|
6701
6781
|
client
|
|
6702
6782
|
});
|
|
6703
6783
|
let err;
|
|
@@ -6718,14 +6798,9 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6718
6798
|
process.exit(0);
|
|
6719
6799
|
}
|
|
6720
6800
|
};
|
|
6721
|
-
SearchIndexCommand.paths = [["search-index"]];
|
|
6722
|
-
SearchIndexCommand.usage = import_clipanion7.Command.Usage({
|
|
6723
|
-
category: `Commands`,
|
|
6724
|
-
description: `Index the site for search`
|
|
6725
|
-
});
|
|
6726
6801
|
|
|
6727
6802
|
// src/index.ts
|
|
6728
|
-
var cli = new
|
|
6803
|
+
var cli = new Cli({
|
|
6729
6804
|
binaryName: `tinacms`,
|
|
6730
6805
|
binaryLabel: `TinaCMS`,
|
|
6731
6806
|
binaryVersion: version
|
|
@@ -6736,7 +6811,10 @@ cli.register(AuditCommand);
|
|
|
6736
6811
|
cli.register(InitCommand);
|
|
6737
6812
|
cli.register(CodemodCommand);
|
|
6738
6813
|
cli.register(SearchIndexCommand);
|
|
6739
|
-
cli.register(
|
|
6740
|
-
cli.register(
|
|
6741
|
-
cli.register(
|
|
6814
|
+
cli.register(Builtins.DefinitionsCommand);
|
|
6815
|
+
cli.register(Builtins.HelpCommand);
|
|
6816
|
+
cli.register(Builtins.VersionCommand);
|
|
6742
6817
|
var index_default = cli;
|
|
6818
|
+
export {
|
|
6819
|
+
index_default as default
|
|
6820
|
+
};
|