@tinacms/cli 0.0.0-f0adfbf-20250521015212 → 0.0.0-f1cec43-20251216232909
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/forestry-migrate/util/index.d.ts +4 -4
- 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.js +1107 -980
- package/dist/logger/index.d.ts +7 -2
- package/dist/next/codegen/index.d.ts +3 -9
- package/dist/next/commands/build-command/index.d.ts +3 -0
- package/dist/next/commands/dev-command/server/searchIndex.d.ts +40 -4
- package/dist/server/server.d.ts +1 -1
- package/dist/utils/path.d.ts +3 -0
- package/dist/utils/sleep.d.ts +1 -0
- package/dist/utils/theme.d.ts +10 -30
- package/package.json +11 -12
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.3";
|
|
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,15 +28,15 @@ function isUnicodeSupported() {
|
|
|
61
28
|
}
|
|
62
29
|
|
|
63
30
|
// src/logger/index.ts
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
31
|
+
var logger = {
|
|
32
|
+
level: "info",
|
|
33
|
+
info: (msg) => process.stdout.write(msg + "\n"),
|
|
34
|
+
warn: (msg) => process.stdout.write(msg + "\n"),
|
|
35
|
+
error: (msg) => process.stderr.write(msg + "\n"),
|
|
36
|
+
debug: (msg) => {
|
|
37
|
+
if (logger.level === "debug") process.stdout.write(msg + "\n");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
73
40
|
function ansiRegex() {
|
|
74
41
|
const pattern = [
|
|
75
42
|
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
@@ -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
|
);
|
|
@@ -601,7 +591,7 @@ var Codegen = class {
|
|
|
601
591
|
throw new Error(
|
|
602
592
|
`Client not configured properly. Missing ${missing.join(
|
|
603
593
|
", "
|
|
604
|
-
)}. Please visit https://tina.io/docs/
|
|
594
|
+
)}. Please visit https://tina.io/docs/r/what-is-tinacloud for more information`
|
|
605
595
|
);
|
|
606
596
|
}
|
|
607
597
|
let localUrl = `http://localhost:${this.port}/graphql`;
|
|
@@ -623,7 +613,7 @@ var Codegen = class {
|
|
|
623
613
|
const authCollection = this.tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
624
614
|
let authFields = [];
|
|
625
615
|
if (authCollection) {
|
|
626
|
-
const usersFields =
|
|
616
|
+
const usersFields = mapUserFields(authCollection, []);
|
|
627
617
|
if (usersFields.length === 0) {
|
|
628
618
|
throw new Error("No user field found");
|
|
629
619
|
}
|
|
@@ -713,7 +703,7 @@ export default databaseClient;
|
|
|
713
703
|
const apiURL = this.getApiURL();
|
|
714
704
|
const clientString = `import { createClient } from "tinacms/dist/client";
|
|
715
705
|
import { queries } from "./types";
|
|
716
|
-
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${(
|
|
706
|
+
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${normalizePath(
|
|
717
707
|
this.configManager.generatedCachePath
|
|
718
708
|
)}', ` : ""}url: '${apiURL}', token: '${token}', queries, ${errorPolicy ? `errorPolicy: '${errorPolicy}'` : ""} });
|
|
719
709
|
export default client;
|
|
@@ -739,7 +729,7 @@ export default client;
|
|
|
739
729
|
${typescriptTypes}
|
|
740
730
|
`;
|
|
741
731
|
const schemaString = `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
742
|
-
${(
|
|
732
|
+
${printSchema2(this.schema)}
|
|
743
733
|
schema {
|
|
744
734
|
query: Query
|
|
745
735
|
mutation: Mutation
|
|
@@ -751,7 +741,7 @@ schema {
|
|
|
751
741
|
var maybeWarnFragmentSize = async (filepath) => {
|
|
752
742
|
if (
|
|
753
743
|
// is the file bigger than 100kb?
|
|
754
|
-
(await
|
|
744
|
+
(await fs.stat(filepath)).size > // convert to 100 kb to bytes
|
|
755
745
|
100 * 1024
|
|
756
746
|
) {
|
|
757
747
|
console.warn(
|
|
@@ -768,19 +758,34 @@ var maybeWarnFragmentSize = async (filepath) => {
|
|
|
768
758
|
}
|
|
769
759
|
};
|
|
770
760
|
var unlinkIfExists = async (filepath) => {
|
|
771
|
-
if (
|
|
772
|
-
|
|
761
|
+
if (fs.existsSync(filepath)) {
|
|
762
|
+
fs.unlinkSync(filepath);
|
|
773
763
|
}
|
|
774
764
|
};
|
|
775
765
|
|
|
776
766
|
// src/next/config-manager.ts
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
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
|
|
784
789
|
var TINA_FOLDER = "tina";
|
|
785
790
|
var LEGACY_TINA_FOLDER = ".tina";
|
|
786
791
|
var GENERATED_FOLDER = "__generated__";
|
|
@@ -789,17 +794,57 @@ var GRAPHQL_GQL_FILE = "schema.gql";
|
|
|
789
794
|
var SCHEMA_JSON_FILE = "_schema.json";
|
|
790
795
|
var LOOKUP_JSON_FILE = "_lookup.json";
|
|
791
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;
|
|
792
837
|
constructor({
|
|
793
838
|
rootPath = process.cwd(),
|
|
794
839
|
tinaGraphQLVersion,
|
|
795
840
|
legacyNoSDK
|
|
796
841
|
}) {
|
|
797
|
-
this.rootPath = (
|
|
842
|
+
this.rootPath = normalizePath2(rootPath);
|
|
798
843
|
this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
|
|
799
844
|
this.legacyNoSDK = legacyNoSDK;
|
|
800
845
|
}
|
|
801
846
|
isUsingTs() {
|
|
802
|
-
return [".ts", ".tsx"].includes(
|
|
847
|
+
return [".ts", ".tsx"].includes(path3.extname(this.tinaConfigFilePath));
|
|
803
848
|
}
|
|
804
849
|
hasSelfHostedConfig() {
|
|
805
850
|
return !!this.selfHostedDatabaseFilePath;
|
|
@@ -814,13 +859,14 @@ var ConfigManager = class {
|
|
|
814
859
|
return this.config.client?.skip || false;
|
|
815
860
|
}
|
|
816
861
|
async processConfig() {
|
|
862
|
+
const require2 = createRequire(import.meta.url);
|
|
817
863
|
this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
|
|
818
|
-
this.envFilePath =
|
|
819
|
-
|
|
864
|
+
this.envFilePath = path3.resolve(
|
|
865
|
+
path3.join(this.tinaFolderPath, "..", ".env")
|
|
820
866
|
);
|
|
821
867
|
dotenv.config({ path: this.envFilePath });
|
|
822
868
|
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
823
|
-
|
|
869
|
+
path3.join(this.tinaFolderPath, "config")
|
|
824
870
|
);
|
|
825
871
|
if (!this.tinaConfigFilePath) {
|
|
826
872
|
throw new Error(
|
|
@@ -828,89 +874,89 @@ var ConfigManager = class {
|
|
|
828
874
|
);
|
|
829
875
|
}
|
|
830
876
|
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
831
|
-
|
|
877
|
+
path3.join(this.tinaFolderPath, "database")
|
|
832
878
|
);
|
|
833
|
-
this.generatedFolderPath =
|
|
834
|
-
this.generatedCachePath =
|
|
879
|
+
this.generatedFolderPath = path3.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
880
|
+
this.generatedCachePath = path3.join(
|
|
835
881
|
this.generatedFolderPath,
|
|
836
882
|
".cache",
|
|
837
883
|
String((/* @__PURE__ */ new Date()).getTime())
|
|
838
884
|
);
|
|
839
|
-
this.generatedGraphQLGQLPath =
|
|
885
|
+
this.generatedGraphQLGQLPath = path3.join(
|
|
840
886
|
this.generatedFolderPath,
|
|
841
887
|
GRAPHQL_GQL_FILE
|
|
842
888
|
);
|
|
843
|
-
this.generatedGraphQLJSONPath =
|
|
889
|
+
this.generatedGraphQLJSONPath = path3.join(
|
|
844
890
|
this.generatedFolderPath,
|
|
845
891
|
GRAPHQL_JSON_FILE
|
|
846
892
|
);
|
|
847
|
-
this.generatedSchemaJSONPath =
|
|
893
|
+
this.generatedSchemaJSONPath = path3.join(
|
|
848
894
|
this.generatedFolderPath,
|
|
849
895
|
SCHEMA_JSON_FILE
|
|
850
896
|
);
|
|
851
|
-
this.generatedLookupJSONPath =
|
|
897
|
+
this.generatedLookupJSONPath = path3.join(
|
|
852
898
|
this.generatedFolderPath,
|
|
853
899
|
LOOKUP_JSON_FILE
|
|
854
900
|
);
|
|
855
|
-
this.generatedQueriesFilePath =
|
|
901
|
+
this.generatedQueriesFilePath = path3.join(
|
|
856
902
|
this.generatedFolderPath,
|
|
857
903
|
"queries.gql"
|
|
858
904
|
);
|
|
859
|
-
this.generatedFragmentsFilePath =
|
|
905
|
+
this.generatedFragmentsFilePath = path3.join(
|
|
860
906
|
this.generatedFolderPath,
|
|
861
907
|
"frags.gql"
|
|
862
908
|
);
|
|
863
|
-
this.generatedTypesTSFilePath =
|
|
909
|
+
this.generatedTypesTSFilePath = path3.join(
|
|
864
910
|
this.generatedFolderPath,
|
|
865
911
|
"types.ts"
|
|
866
912
|
);
|
|
867
|
-
this.generatedTypesJSFilePath =
|
|
913
|
+
this.generatedTypesJSFilePath = path3.join(
|
|
868
914
|
this.generatedFolderPath,
|
|
869
915
|
"types.js"
|
|
870
916
|
);
|
|
871
|
-
this.generatedTypesDFilePath =
|
|
917
|
+
this.generatedTypesDFilePath = path3.join(
|
|
872
918
|
this.generatedFolderPath,
|
|
873
919
|
"types.d.ts"
|
|
874
920
|
);
|
|
875
|
-
this.userQueriesAndFragmentsGlob =
|
|
921
|
+
this.userQueriesAndFragmentsGlob = path3.join(
|
|
876
922
|
this.tinaFolderPath,
|
|
877
923
|
"queries/**/*.{graphql,gql}"
|
|
878
924
|
);
|
|
879
|
-
this.generatedQueriesAndFragmentsGlob =
|
|
925
|
+
this.generatedQueriesAndFragmentsGlob = path3.join(
|
|
880
926
|
this.generatedFolderPath,
|
|
881
927
|
"*.{graphql,gql}"
|
|
882
928
|
);
|
|
883
|
-
this.generatedClientTSFilePath =
|
|
929
|
+
this.generatedClientTSFilePath = path3.join(
|
|
884
930
|
this.generatedFolderPath,
|
|
885
931
|
"client.ts"
|
|
886
932
|
);
|
|
887
|
-
this.generatedClientJSFilePath =
|
|
933
|
+
this.generatedClientJSFilePath = path3.join(
|
|
888
934
|
this.generatedFolderPath,
|
|
889
935
|
"client.js"
|
|
890
936
|
);
|
|
891
|
-
this.generatedClientDFilePath =
|
|
937
|
+
this.generatedClientDFilePath = path3.join(
|
|
892
938
|
this.generatedFolderPath,
|
|
893
939
|
"client.d.ts"
|
|
894
940
|
);
|
|
895
|
-
this.generatedDatabaseClientDFilePath =
|
|
941
|
+
this.generatedDatabaseClientDFilePath = path3.join(
|
|
896
942
|
this.generatedFolderPath,
|
|
897
943
|
"databaseClient.d.ts"
|
|
898
944
|
);
|
|
899
|
-
this.generatedDatabaseClientTSFilePath =
|
|
945
|
+
this.generatedDatabaseClientTSFilePath = path3.join(
|
|
900
946
|
this.generatedFolderPath,
|
|
901
947
|
"databaseClient.ts"
|
|
902
948
|
);
|
|
903
|
-
this.generatedDatabaseClientJSFilePath =
|
|
949
|
+
this.generatedDatabaseClientJSFilePath = path3.join(
|
|
904
950
|
this.generatedFolderPath,
|
|
905
951
|
"databaseClient.js"
|
|
906
952
|
);
|
|
907
|
-
const clientExists = this.isUsingTs() ? await
|
|
953
|
+
const clientExists = this.isUsingTs() ? await fs2.pathExists(this.generatedClientTSFilePath) : await fs2.pathExists(this.generatedClientJSFilePath);
|
|
908
954
|
if (!clientExists) {
|
|
909
955
|
const file = "export default ()=>({})\nexport const client = ()=>({})";
|
|
910
956
|
if (this.isUsingTs()) {
|
|
911
|
-
await
|
|
957
|
+
await fs2.outputFile(this.generatedClientTSFilePath, file);
|
|
912
958
|
} else {
|
|
913
|
-
await
|
|
959
|
+
await fs2.outputFile(this.generatedClientJSFilePath, file);
|
|
914
960
|
}
|
|
915
961
|
}
|
|
916
962
|
const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
|
|
@@ -920,30 +966,29 @@ var ConfigManager = class {
|
|
|
920
966
|
this.watchList = watchList;
|
|
921
967
|
this.config = config2;
|
|
922
968
|
this.prebuildFilePath = prebuildPath;
|
|
923
|
-
this.publicFolderPath =
|
|
969
|
+
this.publicFolderPath = path3.join(
|
|
924
970
|
this.rootPath,
|
|
925
971
|
this.config.build.publicFolder
|
|
926
972
|
);
|
|
927
|
-
this.outputFolderPath =
|
|
973
|
+
this.outputFolderPath = path3.join(
|
|
928
974
|
this.publicFolderPath,
|
|
929
975
|
this.config.build.outputFolder
|
|
930
976
|
);
|
|
931
|
-
this.outputHTMLFilePath =
|
|
932
|
-
this.outputGitignorePath =
|
|
933
|
-
const fullLocalContentPath =
|
|
934
|
-
this.tinaFolderPath,
|
|
935
|
-
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 || "")
|
|
936
981
|
);
|
|
937
982
|
if (this.config.localContentPath) {
|
|
938
|
-
const localContentPathExists = await
|
|
983
|
+
const localContentPathExists = await fs2.pathExists(fullLocalContentPath);
|
|
939
984
|
if (localContentPathExists) {
|
|
940
985
|
logger.info(`Using separate content repo at ${fullLocalContentPath}`);
|
|
941
986
|
this.contentRootPath = fullLocalContentPath;
|
|
942
987
|
} else {
|
|
943
988
|
logger.warn(
|
|
944
|
-
`${
|
|
989
|
+
`${chalk3.yellow("Warning:")} The localContentPath ${chalk3.cyan(
|
|
945
990
|
fullLocalContentPath
|
|
946
|
-
)} 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(
|
|
947
992
|
this.tinaConfigFilePath
|
|
948
993
|
)}`
|
|
949
994
|
);
|
|
@@ -952,22 +997,22 @@ var ConfigManager = class {
|
|
|
952
997
|
if (!this.contentRootPath) {
|
|
953
998
|
this.contentRootPath = this.rootPath;
|
|
954
999
|
}
|
|
955
|
-
this.generatedFolderPathContentRepo =
|
|
1000
|
+
this.generatedFolderPathContentRepo = path3.join(
|
|
956
1001
|
await this.getTinaFolderPath(this.contentRootPath),
|
|
957
1002
|
GENERATED_FOLDER
|
|
958
1003
|
);
|
|
959
|
-
this.spaMainPath =
|
|
960
|
-
this.spaRootPath =
|
|
1004
|
+
this.spaMainPath = require2.resolve("@tinacms/app");
|
|
1005
|
+
this.spaRootPath = path3.join(this.spaMainPath, "..", "..");
|
|
961
1006
|
}
|
|
962
1007
|
async getTinaFolderPath(rootPath) {
|
|
963
|
-
const tinaFolderPath =
|
|
964
|
-
const tinaFolderExists = await
|
|
1008
|
+
const tinaFolderPath = path3.join(rootPath, TINA_FOLDER);
|
|
1009
|
+
const tinaFolderExists = await fs2.pathExists(tinaFolderPath);
|
|
965
1010
|
if (tinaFolderExists) {
|
|
966
1011
|
this.isUsingLegacyFolder = false;
|
|
967
1012
|
return tinaFolderPath;
|
|
968
1013
|
}
|
|
969
|
-
const legacyFolderPath =
|
|
970
|
-
const legacyFolderExists = await
|
|
1014
|
+
const legacyFolderPath = path3.join(rootPath, LEGACY_TINA_FOLDER);
|
|
1015
|
+
const legacyFolderExists = await fs2.pathExists(legacyFolderPath);
|
|
971
1016
|
if (legacyFolderExists) {
|
|
972
1017
|
this.isUsingLegacyFolder = true;
|
|
973
1018
|
return legacyFolderPath;
|
|
@@ -986,7 +1031,7 @@ var ConfigManager = class {
|
|
|
986
1031
|
patch: version2[2] || "x"
|
|
987
1032
|
};
|
|
988
1033
|
}
|
|
989
|
-
const generatedSchema =
|
|
1034
|
+
const generatedSchema = fs2.readJSONSync(this.generatedSchemaJSONPath);
|
|
990
1035
|
if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
|
|
991
1036
|
throw new Error(
|
|
992
1037
|
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
@@ -1033,7 +1078,7 @@ var ConfigManager = class {
|
|
|
1033
1078
|
return;
|
|
1034
1079
|
}
|
|
1035
1080
|
const filepathWithExtension = `${filepath}.${ext}`;
|
|
1036
|
-
const exists =
|
|
1081
|
+
const exists = fs2.existsSync(filepathWithExtension);
|
|
1037
1082
|
if (exists) {
|
|
1038
1083
|
result = filepathWithExtension;
|
|
1039
1084
|
}
|
|
@@ -1042,33 +1087,45 @@ var ConfigManager = class {
|
|
|
1042
1087
|
return result;
|
|
1043
1088
|
}
|
|
1044
1089
|
async loadDatabaseFile() {
|
|
1045
|
-
const tmpdir =
|
|
1046
|
-
const outfile =
|
|
1090
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1091
|
+
const outfile = path3.join(tmpdir, "database.build.mjs");
|
|
1047
1092
|
await esbuild.build({
|
|
1048
1093
|
entryPoints: [this.selfHostedDatabaseFilePath],
|
|
1049
1094
|
bundle: true,
|
|
1050
1095
|
platform: "node",
|
|
1096
|
+
format: "esm",
|
|
1051
1097
|
outfile,
|
|
1052
|
-
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
|
+
}
|
|
1053
1107
|
});
|
|
1054
|
-
const result =
|
|
1055
|
-
|
|
1108
|
+
const result = await import(pathToFileURL(outfile).href);
|
|
1109
|
+
fs2.removeSync(outfile);
|
|
1056
1110
|
return result.default;
|
|
1057
1111
|
}
|
|
1058
1112
|
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
1059
|
-
const tmpdir =
|
|
1060
|
-
const preBuildConfigPath =
|
|
1113
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1114
|
+
const preBuildConfigPath = path3.join(
|
|
1061
1115
|
this.generatedFolderPath,
|
|
1062
1116
|
"config.prebuild.jsx"
|
|
1063
1117
|
);
|
|
1064
|
-
const outfile =
|
|
1065
|
-
const outfile2 =
|
|
1066
|
-
const tempTSConfigFile =
|
|
1067
|
-
|
|
1118
|
+
const outfile = path3.join(tmpdir, "config.build.jsx");
|
|
1119
|
+
const outfile2 = path3.join(tmpdir, "config.build.mjs");
|
|
1120
|
+
const tempTSConfigFile = path3.join(tmpdir, "tsconfig.json");
|
|
1121
|
+
const esmRequireBanner = {
|
|
1122
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
1123
|
+
};
|
|
1124
|
+
fs2.outputFileSync(tempTSConfigFile, "{}");
|
|
1068
1125
|
const result2 = await esbuild.build({
|
|
1069
1126
|
entryPoints: [configFilePath],
|
|
1070
1127
|
bundle: true,
|
|
1071
|
-
target: ["
|
|
1128
|
+
target: ["esnext"],
|
|
1072
1129
|
platform: "browser",
|
|
1073
1130
|
format: "esm",
|
|
1074
1131
|
logLevel: "silent",
|
|
@@ -1088,31 +1145,34 @@ var ConfigManager = class {
|
|
|
1088
1145
|
await esbuild.build({
|
|
1089
1146
|
entryPoints: [configFilePath],
|
|
1090
1147
|
bundle: true,
|
|
1091
|
-
target: ["
|
|
1148
|
+
target: ["esnext"],
|
|
1092
1149
|
logLevel: "silent",
|
|
1093
1150
|
platform: "node",
|
|
1151
|
+
format: "esm",
|
|
1094
1152
|
outfile,
|
|
1095
|
-
loader: loaders
|
|
1153
|
+
loader: loaders,
|
|
1154
|
+
banner: esmRequireBanner
|
|
1096
1155
|
});
|
|
1097
1156
|
await esbuild.build({
|
|
1098
1157
|
entryPoints: [outfile],
|
|
1099
1158
|
bundle: true,
|
|
1100
|
-
// Suppress warning about comparison with -0 from client module
|
|
1101
1159
|
logLevel: "silent",
|
|
1102
1160
|
platform: "node",
|
|
1161
|
+
target: ["esnext"],
|
|
1162
|
+
format: "esm",
|
|
1103
1163
|
outfile: outfile2,
|
|
1104
1164
|
loader: loaders
|
|
1105
1165
|
});
|
|
1106
1166
|
let result;
|
|
1107
1167
|
try {
|
|
1108
|
-
result =
|
|
1168
|
+
result = await import(pathToFileURL(outfile2).href);
|
|
1109
1169
|
} catch (e) {
|
|
1110
1170
|
console.error("Unexpected error loading config");
|
|
1111
1171
|
console.error(e);
|
|
1112
1172
|
throw e;
|
|
1113
1173
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1174
|
+
fs2.removeSync(outfile);
|
|
1175
|
+
fs2.removeSync(outfile2);
|
|
1116
1176
|
return {
|
|
1117
1177
|
config: result.default,
|
|
1118
1178
|
prebuildPath: preBuildConfigPath,
|
|
@@ -1147,20 +1207,24 @@ var loaders = {
|
|
|
1147
1207
|
};
|
|
1148
1208
|
|
|
1149
1209
|
// src/next/database.ts
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1210
|
+
import {
|
|
1211
|
+
createDatabaseInternal,
|
|
1212
|
+
FilesystemBridge,
|
|
1213
|
+
TinaLevelClient
|
|
1214
|
+
} from "@tinacms/graphql";
|
|
1215
|
+
import { pipeline } from "readable-stream";
|
|
1216
|
+
import { createServer } from "net";
|
|
1217
|
+
import { ManyLevelHost } from "many-level";
|
|
1218
|
+
import { MemoryLevel } from "memory-level";
|
|
1155
1219
|
var createDBServer = (port) => {
|
|
1156
|
-
const levelHost = new
|
|
1220
|
+
const levelHost = new ManyLevelHost(
|
|
1157
1221
|
// @ts-ignore
|
|
1158
|
-
new
|
|
1222
|
+
new MemoryLevel({
|
|
1159
1223
|
valueEncoding: "json"
|
|
1160
1224
|
})
|
|
1161
1225
|
);
|
|
1162
|
-
const dbServer =
|
|
1163
|
-
return
|
|
1226
|
+
const dbServer = createServer(function(socket) {
|
|
1227
|
+
return pipeline(socket, levelHost.createRpcStream(), socket, () => {
|
|
1164
1228
|
});
|
|
1165
1229
|
});
|
|
1166
1230
|
dbServer.once("error", (err) => {
|
|
@@ -1174,7 +1238,7 @@ var createDBServer = (port) => {
|
|
|
1174
1238
|
};
|
|
1175
1239
|
async function createAndInitializeDatabase(configManager, datalayerPort, bridgeOverride) {
|
|
1176
1240
|
let database;
|
|
1177
|
-
const bridge = bridgeOverride || new
|
|
1241
|
+
const bridge = bridgeOverride || new FilesystemBridge(configManager.rootPath, configManager.contentRootPath);
|
|
1178
1242
|
if (configManager.hasSelfHostedConfig() && configManager.config.contentApiUrlOverride) {
|
|
1179
1243
|
database = await configManager.loadDatabaseFile();
|
|
1180
1244
|
database.bridge = bridge;
|
|
@@ -1186,9 +1250,9 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1186
1250
|
)} but there was no "contentApiUrlOverride" set. Falling back to built-in datalayer`
|
|
1187
1251
|
);
|
|
1188
1252
|
}
|
|
1189
|
-
const level = new
|
|
1253
|
+
const level = new TinaLevelClient(datalayerPort);
|
|
1190
1254
|
level.openConnection();
|
|
1191
|
-
database =
|
|
1255
|
+
database = createDatabaseInternal({
|
|
1192
1256
|
bridge,
|
|
1193
1257
|
level,
|
|
1194
1258
|
tinaDirectory: configManager.isUsingLegacyFolder ? LEGACY_TINA_FOLDER : TINA_FOLDER
|
|
@@ -1198,17 +1262,17 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1198
1262
|
}
|
|
1199
1263
|
|
|
1200
1264
|
// src/next/commands/baseCommands.ts
|
|
1201
|
-
|
|
1202
|
-
|
|
1265
|
+
import { Command, Option } from "clipanion";
|
|
1266
|
+
import chalk4 from "chalk";
|
|
1203
1267
|
|
|
1204
1268
|
// src/utils/start-subprocess.ts
|
|
1205
|
-
|
|
1269
|
+
import childProcess from "child_process";
|
|
1206
1270
|
var startSubprocess2 = async ({ command: command2 }) => {
|
|
1207
1271
|
if (typeof command2 === "string") {
|
|
1208
1272
|
const commands = command2.split(" ");
|
|
1209
1273
|
const firstCommand = commands[0];
|
|
1210
1274
|
const args = commands.slice(1) || [];
|
|
1211
|
-
const ps =
|
|
1275
|
+
const ps = childProcess.spawn(firstCommand, args, {
|
|
1212
1276
|
stdio: "inherit",
|
|
1213
1277
|
shell: true
|
|
1214
1278
|
});
|
|
@@ -1232,45 +1296,42 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
1232
1296
|
};
|
|
1233
1297
|
|
|
1234
1298
|
// src/next/commands/baseCommands.ts
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
var BaseCommand = class extends
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
description: "Disable anonymous telemetry that is collected"
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1299
|
+
import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
|
|
1300
|
+
import fs3 from "fs-extra";
|
|
1301
|
+
var BaseCommand = class extends Command {
|
|
1302
|
+
experimentalDataLayer = Option.Boolean("--experimentalData", {
|
|
1303
|
+
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
1304
|
+
});
|
|
1305
|
+
isomorphicGitBridge = Option.Boolean("--isomorphicGitBridge", {
|
|
1306
|
+
description: "DEPRECATED - Enable Isomorphic Git Bridge Implementation"
|
|
1307
|
+
});
|
|
1308
|
+
port = Option.String("-p,--port", "4001", {
|
|
1309
|
+
description: "Specify a port to run the server on. (default 4001)"
|
|
1310
|
+
});
|
|
1311
|
+
datalayerPort = Option.String("--datalayer-port", "9000", {
|
|
1312
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
1313
|
+
});
|
|
1314
|
+
subCommand = Option.String("-c,--command", {
|
|
1315
|
+
description: "The sub-command to run"
|
|
1316
|
+
});
|
|
1317
|
+
rootPath = Option.String("--rootPath", {
|
|
1318
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
1319
|
+
});
|
|
1320
|
+
verbose = Option.Boolean("-v,--verbose", false, {
|
|
1321
|
+
description: "increase verbosity of logged output"
|
|
1322
|
+
});
|
|
1323
|
+
noSDK = Option.Boolean("--noSDK", false, {
|
|
1324
|
+
description: "DEPRECATED - This should now be set in the config at client.skip = true'. Don't generate the generated client SDK"
|
|
1325
|
+
});
|
|
1326
|
+
noTelemetry = Option.Boolean("--noTelemetry", false, {
|
|
1327
|
+
description: "Disable anonymous telemetry that is collected"
|
|
1328
|
+
});
|
|
1268
1329
|
async startSubCommand() {
|
|
1269
1330
|
let subProc;
|
|
1270
1331
|
if (this.subCommand) {
|
|
1271
1332
|
subProc = await startSubprocess2({ command: this.subCommand });
|
|
1272
1333
|
logger.info(
|
|
1273
|
-
`Running web application with command: ${
|
|
1334
|
+
`Running web application with command: ${chalk4.cyan(this.subCommand)}`
|
|
1274
1335
|
);
|
|
1275
1336
|
}
|
|
1276
1337
|
function exitHandler(options, exitCode) {
|
|
@@ -1318,7 +1379,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1318
1379
|
const rootPath = configManager.rootPath;
|
|
1319
1380
|
let sha;
|
|
1320
1381
|
try {
|
|
1321
|
-
sha = await
|
|
1382
|
+
sha = await getSha({ fs: fs3, dir: rootPath });
|
|
1322
1383
|
} catch (e) {
|
|
1323
1384
|
if (partialReindex) {
|
|
1324
1385
|
console.error(
|
|
@@ -1328,7 +1389,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1328
1389
|
}
|
|
1329
1390
|
}
|
|
1330
1391
|
const lastSha = await database.getMetadata("lastSha");
|
|
1331
|
-
const exists = lastSha && await
|
|
1392
|
+
const exists = lastSha && await shaExists({ fs: fs3, dir: rootPath, sha: lastSha });
|
|
1332
1393
|
let res;
|
|
1333
1394
|
if (partialReindex && lastSha && exists && sha) {
|
|
1334
1395
|
const pathFilter = {};
|
|
@@ -1342,15 +1403,15 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1342
1403
|
matches: collection.match?.exclude || collection.match?.include ? tinaSchema.getMatches({ collection }) : void 0
|
|
1343
1404
|
};
|
|
1344
1405
|
}
|
|
1345
|
-
const { added, modified, deleted } = await
|
|
1346
|
-
fs:
|
|
1406
|
+
const { added, modified, deleted } = await getChangedFiles({
|
|
1407
|
+
fs: fs3,
|
|
1347
1408
|
dir: rootPath,
|
|
1348
1409
|
from: lastSha,
|
|
1349
1410
|
to: sha,
|
|
1350
1411
|
pathFilter
|
|
1351
1412
|
});
|
|
1352
1413
|
const tinaPathUpdates = modified.filter(
|
|
1353
|
-
(
|
|
1414
|
+
(path15) => path15.startsWith(".tina/__generated__/_schema.json") || path15.startsWith("tina/tina-lock.json")
|
|
1354
1415
|
);
|
|
1355
1416
|
if (tinaPathUpdates.length > 0) {
|
|
1356
1417
|
res = await database.indexContent({
|
|
@@ -1428,7 +1489,7 @@ var errorHTML = `<style type="text/css">
|
|
|
1428
1489
|
the assets for this page.
|
|
1429
1490
|
</p>
|
|
1430
1491
|
<p>
|
|
1431
|
-
Please visit <a href="https://tina.io/docs/
|
|
1492
|
+
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.
|
|
1432
1493
|
</p>
|
|
1433
1494
|
</div>
|
|
1434
1495
|
</div>`.trim().replace(/[\r\n\s]+/g, " ");
|
|
@@ -1466,34 +1527,38 @@ var devHTML = (port) => `<!DOCTYPE html>
|
|
|
1466
1527
|
</html>`;
|
|
1467
1528
|
|
|
1468
1529
|
// src/next/commands/dev-command/server/index.ts
|
|
1469
|
-
|
|
1530
|
+
import { createServer as createViteServer } from "vite";
|
|
1470
1531
|
|
|
1471
1532
|
// src/next/vite/index.ts
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1533
|
+
import path5 from "node:path";
|
|
1534
|
+
import react from "@vitejs/plugin-react";
|
|
1535
|
+
import fs4 from "fs-extra";
|
|
1536
|
+
import normalizePath3 from "normalize-path";
|
|
1537
|
+
import {
|
|
1538
|
+
splitVendorChunkPlugin
|
|
1539
|
+
} from "vite";
|
|
1477
1540
|
|
|
1478
1541
|
// src/next/vite/tailwind.ts
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1542
|
+
import path4 from "node:path";
|
|
1543
|
+
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
1544
|
+
import containerQueries from "@tailwindcss/container-queries";
|
|
1545
|
+
import twTypography from "@tailwindcss/typography";
|
|
1546
|
+
import tailwind from "tailwindcss";
|
|
1547
|
+
import defaultTheme from "tailwindcss/defaultTheme.js";
|
|
1548
|
+
import { createRequire as createRequire2 } from "module";
|
|
1485
1549
|
var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
1486
1550
|
return {
|
|
1487
1551
|
name: "vite-plugin-tina",
|
|
1488
1552
|
// @ts-ignore
|
|
1489
1553
|
config: (viteConfig) => {
|
|
1554
|
+
const require2 = createRequire2(import.meta.url);
|
|
1490
1555
|
const plugins = [];
|
|
1491
1556
|
const content = [
|
|
1492
|
-
|
|
1557
|
+
path4.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
1493
1558
|
prebuildFilePath,
|
|
1494
|
-
|
|
1559
|
+
require2.resolve("tinacms")
|
|
1495
1560
|
];
|
|
1496
|
-
const tw = (
|
|
1561
|
+
const tw = tailwind({
|
|
1497
1562
|
theme: {
|
|
1498
1563
|
columns: {
|
|
1499
1564
|
auto: "auto",
|
|
@@ -1681,6 +1746,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1681
1746
|
500: "#EC4815",
|
|
1682
1747
|
600: "#DC4419"
|
|
1683
1748
|
},
|
|
1749
|
+
"tina-orange": "#EC4815",
|
|
1750
|
+
"tina-orange-dark": "#C2410C",
|
|
1751
|
+
"tina-orange-light": "#FFF7ED",
|
|
1684
1752
|
background: "#FFFFFF",
|
|
1685
1753
|
foreground: "#0A0A0A",
|
|
1686
1754
|
muted: "#F5F5F5",
|
|
@@ -1702,7 +1770,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1702
1770
|
ring: "#0A0A0A"
|
|
1703
1771
|
},
|
|
1704
1772
|
fontFamily: {
|
|
1705
|
-
sans: ["Inter", ...
|
|
1773
|
+
sans: ["Inter", ...defaultTheme.fontFamily.sans]
|
|
1706
1774
|
},
|
|
1707
1775
|
lineHeight: {
|
|
1708
1776
|
3: "12px",
|
|
@@ -1727,9 +1795,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1727
1795
|
},
|
|
1728
1796
|
content,
|
|
1729
1797
|
plugins: [
|
|
1730
|
-
(
|
|
1731
|
-
|
|
1732
|
-
|
|
1798
|
+
twTypography({ className: "tina-prose" }),
|
|
1799
|
+
aspectRatio,
|
|
1800
|
+
containerQueries
|
|
1733
1801
|
]
|
|
1734
1802
|
});
|
|
1735
1803
|
plugins.push(tw);
|
|
@@ -1750,35 +1818,35 @@ async function listFilesRecursively({
|
|
|
1750
1818
|
config: config2,
|
|
1751
1819
|
roothPath
|
|
1752
1820
|
}) {
|
|
1753
|
-
const fullDirectoryPath =
|
|
1821
|
+
const fullDirectoryPath = path5.join(
|
|
1754
1822
|
roothPath,
|
|
1755
1823
|
config2.publicFolder,
|
|
1756
1824
|
directoryPath
|
|
1757
1825
|
);
|
|
1758
|
-
const exists = await
|
|
1826
|
+
const exists = await fs4.pathExists(fullDirectoryPath);
|
|
1759
1827
|
if (!exists) {
|
|
1760
1828
|
return { "0": [] };
|
|
1761
1829
|
}
|
|
1762
|
-
const items = await
|
|
1830
|
+
const items = await fs4.readdir(fullDirectoryPath);
|
|
1763
1831
|
const staticMediaItems = [];
|
|
1764
1832
|
for (const item of items) {
|
|
1765
|
-
const itemPath =
|
|
1766
|
-
const stats = await
|
|
1833
|
+
const itemPath = path5.join(fullDirectoryPath, item);
|
|
1834
|
+
const stats = await fs4.promises.lstat(itemPath);
|
|
1767
1835
|
const staticMediaItem = {
|
|
1768
1836
|
id: item,
|
|
1769
1837
|
filename: item,
|
|
1770
1838
|
type: stats.isDirectory() ? "dir" : "file",
|
|
1771
1839
|
directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
|
|
1772
|
-
src: `/${
|
|
1840
|
+
src: `/${path5.join(directoryPath, item)}`,
|
|
1773
1841
|
thumbnails: {
|
|
1774
|
-
"75x75": `/${
|
|
1775
|
-
"400x400": `/${
|
|
1776
|
-
"1000x1000": `/${
|
|
1842
|
+
"75x75": `/${path5.join(directoryPath, item)}`,
|
|
1843
|
+
"400x400": `/${path5.join(directoryPath, item)}`,
|
|
1844
|
+
"1000x1000": `/${path5.join(directoryPath, item)}`
|
|
1777
1845
|
}
|
|
1778
1846
|
};
|
|
1779
1847
|
if (stats.isDirectory()) {
|
|
1780
1848
|
staticMediaItem.children = await listFilesRecursively({
|
|
1781
|
-
directoryPath:
|
|
1849
|
+
directoryPath: path5.join(directoryPath, item),
|
|
1782
1850
|
config: config2,
|
|
1783
1851
|
roothPath
|
|
1784
1852
|
});
|
|
@@ -1819,7 +1887,7 @@ var createConfig = async ({
|
|
|
1819
1887
|
}
|
|
1820
1888
|
}
|
|
1821
1889
|
});
|
|
1822
|
-
const staticMediaPath =
|
|
1890
|
+
const staticMediaPath = path5.join(
|
|
1823
1891
|
configManager.generatedFolderPath,
|
|
1824
1892
|
"static-media.json"
|
|
1825
1893
|
);
|
|
@@ -1829,21 +1897,21 @@ var createConfig = async ({
|
|
|
1829
1897
|
config: configManager.config.media.tina,
|
|
1830
1898
|
roothPath: configManager.rootPath
|
|
1831
1899
|
});
|
|
1832
|
-
await
|
|
1900
|
+
await fs4.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
|
|
1833
1901
|
} else {
|
|
1834
|
-
await
|
|
1902
|
+
await fs4.outputFile(staticMediaPath, `[]`);
|
|
1835
1903
|
}
|
|
1836
1904
|
const alias = {
|
|
1837
1905
|
TINA_IMPORT: configManager.prebuildFilePath,
|
|
1838
1906
|
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
|
|
1839
1907
|
STATIC_MEDIA_IMPORT: staticMediaPath,
|
|
1840
|
-
crypto:
|
|
1841
|
-
fs:
|
|
1842
|
-
os:
|
|
1843
|
-
path:
|
|
1908
|
+
crypto: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1909
|
+
fs: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1910
|
+
os: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1911
|
+
path: path5.join(configManager.spaRootPath, "src", "dummy-client.ts")
|
|
1844
1912
|
};
|
|
1845
1913
|
if (configManager.shouldSkipSDK()) {
|
|
1846
|
-
alias["CLIENT_IMPORT"] =
|
|
1914
|
+
alias["CLIENT_IMPORT"] = path5.join(
|
|
1847
1915
|
configManager.spaRootPath,
|
|
1848
1916
|
"src",
|
|
1849
1917
|
"dummy-client.ts"
|
|
@@ -1859,7 +1927,7 @@ var createConfig = async ({
|
|
|
1859
1927
|
const version2 = `${fullVersion.major}.${fullVersion.minor}`;
|
|
1860
1928
|
const config2 = {
|
|
1861
1929
|
root: configManager.spaRootPath,
|
|
1862
|
-
base: `/${basePath ? `${(
|
|
1930
|
+
base: `/${basePath ? `${normalizePath3(basePath)}/` : ""}${normalizePath3(
|
|
1863
1931
|
configManager.config.build.outputFolder
|
|
1864
1932
|
)}/`,
|
|
1865
1933
|
appType: "spa",
|
|
@@ -1922,13 +1990,14 @@ var createConfig = async ({
|
|
|
1922
1990
|
* `splitVendorChunkPlugin` is needed because `tinacms` is quite large,
|
|
1923
1991
|
* Vite's chunking strategy chokes on memory issues for smaller machines (ie. on CI).
|
|
1924
1992
|
*/
|
|
1925
|
-
(
|
|
1993
|
+
react({
|
|
1926
1994
|
babel: {
|
|
1927
1995
|
// Supresses the warning [NOTE] babel The code generator has deoptimised the styling of
|
|
1928
1996
|
compact: true
|
|
1929
|
-
}
|
|
1997
|
+
},
|
|
1998
|
+
fastRefresh: false
|
|
1930
1999
|
}),
|
|
1931
|
-
|
|
2000
|
+
splitVendorChunkPlugin(),
|
|
1932
2001
|
tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
|
|
1933
2002
|
...plugins
|
|
1934
2003
|
]
|
|
@@ -1937,21 +2006,21 @@ var createConfig = async ({
|
|
|
1937
2006
|
};
|
|
1938
2007
|
|
|
1939
2008
|
// src/next/vite/plugins.ts
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2009
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
2010
|
+
import fs6 from "fs";
|
|
2011
|
+
import { transformWithEsbuild } from "vite";
|
|
2012
|
+
import { transform as esbuildTransform } from "esbuild";
|
|
2013
|
+
import path7 from "path";
|
|
2014
|
+
import bodyParser from "body-parser";
|
|
2015
|
+
import cors from "cors";
|
|
2016
|
+
import { resolve as gqlResolve } from "@tinacms/graphql";
|
|
1948
2017
|
|
|
1949
2018
|
// src/next/commands/dev-command/server/media.ts
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
2019
|
+
import fs5 from "fs-extra";
|
|
2020
|
+
import path6, { join } from "path";
|
|
2021
|
+
import busboy from "busboy";
|
|
1953
2022
|
var createMediaRouter = (config2) => {
|
|
1954
|
-
const mediaFolder =
|
|
2023
|
+
const mediaFolder = path6.join(
|
|
1955
2024
|
config2.rootPath,
|
|
1956
2025
|
config2.publicFolder,
|
|
1957
2026
|
config2.mediaRoot
|
|
@@ -1975,12 +2044,12 @@ var createMediaRouter = (config2) => {
|
|
|
1975
2044
|
res.end(JSON.stringify(didDelete));
|
|
1976
2045
|
};
|
|
1977
2046
|
const handlePost = async function(req, res) {
|
|
1978
|
-
const bb = (
|
|
2047
|
+
const bb = busboy({ headers: req.headers });
|
|
1979
2048
|
bb.on("file", async (_name, file, _info) => {
|
|
1980
2049
|
const fullPath = decodeURI(req.url?.slice("/media/upload/".length));
|
|
1981
|
-
const saveTo =
|
|
1982
|
-
await
|
|
1983
|
-
file.pipe(
|
|
2050
|
+
const saveTo = path6.join(mediaFolder, ...fullPath.split("/"));
|
|
2051
|
+
await fs5.ensureDir(path6.dirname(saveTo));
|
|
2052
|
+
file.pipe(fs5.createWriteStream(saveTo));
|
|
1984
2053
|
});
|
|
1985
2054
|
bb.on("error", (error) => {
|
|
1986
2055
|
res.statusCode = 500;
|
|
@@ -2006,6 +2075,9 @@ var parseMediaFolder = (str) => {
|
|
|
2006
2075
|
return returnString;
|
|
2007
2076
|
};
|
|
2008
2077
|
var MediaModel = class {
|
|
2078
|
+
rootPath;
|
|
2079
|
+
publicFolder;
|
|
2080
|
+
mediaRoot;
|
|
2009
2081
|
constructor({ rootPath, publicFolder, mediaRoot }) {
|
|
2010
2082
|
this.rootPath = rootPath;
|
|
2011
2083
|
this.mediaRoot = mediaRoot;
|
|
@@ -2013,23 +2085,23 @@ var MediaModel = class {
|
|
|
2013
2085
|
}
|
|
2014
2086
|
async listMedia(args) {
|
|
2015
2087
|
try {
|
|
2016
|
-
const folderPath =
|
|
2088
|
+
const folderPath = join(
|
|
2017
2089
|
this.rootPath,
|
|
2018
2090
|
this.publicFolder,
|
|
2019
2091
|
this.mediaRoot,
|
|
2020
2092
|
decodeURIComponent(args.searchPath)
|
|
2021
2093
|
);
|
|
2022
2094
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
2023
|
-
if (!await
|
|
2095
|
+
if (!await fs5.pathExists(folderPath)) {
|
|
2024
2096
|
return {
|
|
2025
2097
|
files: [],
|
|
2026
2098
|
directories: []
|
|
2027
2099
|
};
|
|
2028
2100
|
}
|
|
2029
|
-
const filesStr = await
|
|
2101
|
+
const filesStr = await fs5.readdir(folderPath);
|
|
2030
2102
|
const filesProm = filesStr.map(async (file) => {
|
|
2031
|
-
const filePath =
|
|
2032
|
-
const stat = await
|
|
2103
|
+
const filePath = join(folderPath, file);
|
|
2104
|
+
const stat = await fs5.stat(filePath);
|
|
2033
2105
|
let src = `/${file}`;
|
|
2034
2106
|
const isFile = stat.isFile();
|
|
2035
2107
|
if (!isFile) {
|
|
@@ -2085,14 +2157,14 @@ var MediaModel = class {
|
|
|
2085
2157
|
}
|
|
2086
2158
|
async deleteMedia(args) {
|
|
2087
2159
|
try {
|
|
2088
|
-
const file =
|
|
2160
|
+
const file = join(
|
|
2089
2161
|
this.rootPath,
|
|
2090
2162
|
this.publicFolder,
|
|
2091
2163
|
this.mediaRoot,
|
|
2092
2164
|
decodeURIComponent(args.searchPath)
|
|
2093
2165
|
);
|
|
2094
|
-
await
|
|
2095
|
-
await
|
|
2166
|
+
await fs5.stat(file);
|
|
2167
|
+
await fs5.remove(file);
|
|
2096
2168
|
return { ok: true };
|
|
2097
2169
|
} catch (error) {
|
|
2098
2170
|
console.error(error);
|
|
@@ -2107,34 +2179,83 @@ var createSearchIndexRouter = ({
|
|
|
2107
2179
|
searchIndex
|
|
2108
2180
|
}) => {
|
|
2109
2181
|
const put = async (req, res) => {
|
|
2110
|
-
const
|
|
2182
|
+
const docs = req.body?.docs ?? [];
|
|
2111
2183
|
const result = await searchIndex.PUT(docs);
|
|
2112
2184
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
2113
2185
|
res.end(JSON.stringify({ result }));
|
|
2114
2186
|
};
|
|
2115
2187
|
const get = async (req, res) => {
|
|
2116
|
-
const requestURL = new URL(req.url, config2.apiURL);
|
|
2188
|
+
const requestURL = new URL(req.url ?? "", config2.apiURL);
|
|
2117
2189
|
const query = requestURL.searchParams.get("q");
|
|
2118
2190
|
const optionsParam = requestURL.searchParams.get("options");
|
|
2119
|
-
|
|
2191
|
+
const fuzzyParam = requestURL.searchParams.get("fuzzy");
|
|
2192
|
+
const fuzzyOptionsParam = requestURL.searchParams.get("fuzzyOptions");
|
|
2193
|
+
let searchIndexOptions = {
|
|
2120
2194
|
DOCUMENTS: false
|
|
2121
2195
|
};
|
|
2122
2196
|
if (optionsParam) {
|
|
2123
|
-
|
|
2124
|
-
...
|
|
2197
|
+
searchIndexOptions = {
|
|
2198
|
+
...searchIndexOptions,
|
|
2125
2199
|
...JSON.parse(optionsParam)
|
|
2126
2200
|
};
|
|
2127
2201
|
}
|
|
2128
2202
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
2129
2203
|
if (query) {
|
|
2130
|
-
const
|
|
2204
|
+
const queryObj = JSON.parse(query);
|
|
2205
|
+
if (fuzzyParam === "true" && searchIndex.fuzzySearchWrapper) {
|
|
2206
|
+
try {
|
|
2207
|
+
const fuzzyOptions = fuzzyOptionsParam ? JSON.parse(fuzzyOptionsParam) : {};
|
|
2208
|
+
const searchTerms = queryObj.AND ? queryObj.AND.filter(
|
|
2209
|
+
(term) => !term.includes("_collection:")
|
|
2210
|
+
) : [];
|
|
2211
|
+
const collectionFilter = queryObj.AND?.find(
|
|
2212
|
+
(term) => term.includes("_collection:")
|
|
2213
|
+
);
|
|
2214
|
+
const paginationOptions = {};
|
|
2215
|
+
if (searchIndexOptions.PAGE) {
|
|
2216
|
+
paginationOptions.limit = searchIndexOptions.PAGE.SIZE;
|
|
2217
|
+
paginationOptions.cursor = searchIndexOptions.PAGE.NUMBER.toString();
|
|
2218
|
+
}
|
|
2219
|
+
const searchQuery = collectionFilter ? `${searchTerms.join(" ")} ${collectionFilter}` : searchTerms.join(" ");
|
|
2220
|
+
const result2 = await searchIndex.fuzzySearchWrapper.query(
|
|
2221
|
+
searchQuery,
|
|
2222
|
+
{
|
|
2223
|
+
...paginationOptions,
|
|
2224
|
+
fuzzy: true,
|
|
2225
|
+
fuzzyOptions
|
|
2226
|
+
}
|
|
2227
|
+
);
|
|
2228
|
+
if (collectionFilter) {
|
|
2229
|
+
const collection = collectionFilter.split(":")[1];
|
|
2230
|
+
result2.results = result2.results.filter(
|
|
2231
|
+
(r) => r._id && r._id.startsWith(`${collection}:`)
|
|
2232
|
+
);
|
|
2233
|
+
}
|
|
2234
|
+
res.end(
|
|
2235
|
+
JSON.stringify({
|
|
2236
|
+
RESULT: result2.results,
|
|
2237
|
+
RESULT_LENGTH: result2.total,
|
|
2238
|
+
NEXT_CURSOR: result2.nextCursor,
|
|
2239
|
+
PREV_CURSOR: result2.prevCursor,
|
|
2240
|
+
FUZZY_MATCHES: result2.fuzzyMatches || {}
|
|
2241
|
+
})
|
|
2242
|
+
);
|
|
2243
|
+
return;
|
|
2244
|
+
} catch (error) {
|
|
2245
|
+
console.warn(
|
|
2246
|
+
"[search] Fuzzy search failed, falling back to standard search:",
|
|
2247
|
+
error instanceof Error ? error.message : error
|
|
2248
|
+
);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
const result = await searchIndex.QUERY(queryObj, searchIndexOptions);
|
|
2131
2252
|
res.end(JSON.stringify(result));
|
|
2132
2253
|
} else {
|
|
2133
2254
|
res.end(JSON.stringify({ RESULT: [] }));
|
|
2134
2255
|
}
|
|
2135
2256
|
};
|
|
2136
2257
|
const del = async (req, res) => {
|
|
2137
|
-
const requestURL = new URL(req.url, config2.apiURL);
|
|
2258
|
+
const requestURL = new URL(req.url ?? "", config2.apiURL);
|
|
2138
2259
|
const docId = requestURL.pathname.split("/").filter(Boolean).slice(1).join("/");
|
|
2139
2260
|
const result = await searchIndex.DELETE(docId);
|
|
2140
2261
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -2150,9 +2271,9 @@ var transformTsxPlugin = ({
|
|
|
2150
2271
|
const plug = {
|
|
2151
2272
|
name: "transform-tsx",
|
|
2152
2273
|
async transform(code, id) {
|
|
2153
|
-
const extName =
|
|
2274
|
+
const extName = path7.extname(id);
|
|
2154
2275
|
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
2155
|
-
const result = await (
|
|
2276
|
+
const result = await esbuildTransform(code, { loader: "tsx" });
|
|
2156
2277
|
return {
|
|
2157
2278
|
code: result.code
|
|
2158
2279
|
};
|
|
@@ -2171,8 +2292,8 @@ var devServerEndPointsPlugin = ({
|
|
|
2171
2292
|
const plug = {
|
|
2172
2293
|
name: "graphql-endpoints",
|
|
2173
2294
|
configureServer(server) {
|
|
2174
|
-
server.middlewares.use((
|
|
2175
|
-
server.middlewares.use(
|
|
2295
|
+
server.middlewares.use(cors());
|
|
2296
|
+
server.middlewares.use(bodyParser.json({ limit: "5mb" }));
|
|
2176
2297
|
server.middlewares.use(async (req, res, next) => {
|
|
2177
2298
|
const mediaPaths = configManager.config.media?.tina;
|
|
2178
2299
|
const mediaRouter = createMediaRouter({
|
|
@@ -2211,7 +2332,7 @@ var devServerEndPointsPlugin = ({
|
|
|
2211
2332
|
const { query, variables } = req.body;
|
|
2212
2333
|
let result;
|
|
2213
2334
|
await databaseLock(async () => {
|
|
2214
|
-
result = await (
|
|
2335
|
+
result = await gqlResolve({
|
|
2215
2336
|
config: {
|
|
2216
2337
|
useRelativeMedia: true
|
|
2217
2338
|
},
|
|
@@ -2247,13 +2368,13 @@ function viteTransformExtension({
|
|
|
2247
2368
|
include = "**/*.svg",
|
|
2248
2369
|
exclude
|
|
2249
2370
|
} = {}) {
|
|
2250
|
-
const filter =
|
|
2371
|
+
const filter = createFilter(include, exclude);
|
|
2251
2372
|
return {
|
|
2252
2373
|
name: "vite-plugin-svgr",
|
|
2253
2374
|
async transform(code, id) {
|
|
2254
2375
|
if (filter(id)) {
|
|
2255
2376
|
const { transform: transform2 } = await import("@svgr/core");
|
|
2256
|
-
const svgCode = await
|
|
2377
|
+
const svgCode = await fs6.promises.readFile(
|
|
2257
2378
|
id.replace(/\?.*$/, ""),
|
|
2258
2379
|
"utf8"
|
|
2259
2380
|
);
|
|
@@ -2263,7 +2384,7 @@ function viteTransformExtension({
|
|
|
2263
2384
|
previousExport: exportAsDefault ? null : code
|
|
2264
2385
|
}
|
|
2265
2386
|
});
|
|
2266
|
-
const res = await
|
|
2387
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
2267
2388
|
loader: "jsx",
|
|
2268
2389
|
...esbuildOptions
|
|
2269
2390
|
});
|
|
@@ -2290,7 +2411,7 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2290
2411
|
}),
|
|
2291
2412
|
viteTransformExtension()
|
|
2292
2413
|
];
|
|
2293
|
-
return (
|
|
2414
|
+
return createViteServer(
|
|
2294
2415
|
await createConfig({
|
|
2295
2416
|
configManager,
|
|
2296
2417
|
database,
|
|
@@ -2320,37 +2441,30 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2320
2441
|
|
|
2321
2442
|
// src/next/commands/dev-command/index.ts
|
|
2322
2443
|
var DevCommand = class extends BaseCommand {
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
this
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
description: `Builds Tina and starts the dev server`,
|
|
2348
|
-
examples: [
|
|
2349
|
-
[`A basic example`, `$0 dev`],
|
|
2350
|
-
[`A second example`, `$0 dev --rootPath`]
|
|
2351
|
-
]
|
|
2352
|
-
});
|
|
2353
|
-
}
|
|
2444
|
+
static paths = [["dev"], ["server:start"]];
|
|
2445
|
+
// NOTE: camelCase commands for string options don't work if there's an `=` used https://github.com/arcanis/clipanion/issues/141
|
|
2446
|
+
watchFolders = Option2.String("-w,--watchFolders", {
|
|
2447
|
+
description: "DEPRECATED - a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
2448
|
+
});
|
|
2449
|
+
noWatch = Option2.Boolean("--noWatch", false, {
|
|
2450
|
+
description: "Don't regenerate config on file changes"
|
|
2451
|
+
});
|
|
2452
|
+
outputSearchIndexPath = Option2.String("--outputSearchIndexPath", {
|
|
2453
|
+
description: "Path to write the search index to"
|
|
2454
|
+
});
|
|
2455
|
+
noServer = Option2.Boolean("--no-server", false, {
|
|
2456
|
+
description: "Do not start the dev server"
|
|
2457
|
+
});
|
|
2458
|
+
indexingLock = new AsyncLock();
|
|
2459
|
+
// Prevent indexes and reads occurring at once
|
|
2460
|
+
static usage = Command2.Usage({
|
|
2461
|
+
category: `Commands`,
|
|
2462
|
+
description: `Builds Tina and starts the dev server`,
|
|
2463
|
+
examples: [
|
|
2464
|
+
[`A basic example`, `$0 dev`],
|
|
2465
|
+
[`A second example`, `$0 dev --rootPath`]
|
|
2466
|
+
]
|
|
2467
|
+
});
|
|
2354
2468
|
async catch(error) {
|
|
2355
2469
|
logger.error("Error occured during tinacms dev");
|
|
2356
2470
|
console.error(error);
|
|
@@ -2387,7 +2501,7 @@ var DevCommand = class extends BaseCommand {
|
|
|
2387
2501
|
} else {
|
|
2388
2502
|
database.clearCache();
|
|
2389
2503
|
}
|
|
2390
|
-
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await
|
|
2504
|
+
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await buildSchema(configManager.config);
|
|
2391
2505
|
const codegen2 = new Codegen({
|
|
2392
2506
|
isLocal: true,
|
|
2393
2507
|
configManager,
|
|
@@ -2401,29 +2515,32 @@ var DevCommand = class extends BaseCommand {
|
|
|
2401
2515
|
});
|
|
2402
2516
|
const apiURL2 = await codegen2.execute();
|
|
2403
2517
|
if (!configManager.isUsingLegacyFolder) {
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
const
|
|
2408
|
-
|
|
2409
|
-
|
|
2518
|
+
const schemaObject = await fs7.readJSON(
|
|
2519
|
+
configManager.generatedSchemaJSONPath
|
|
2520
|
+
);
|
|
2521
|
+
const lookupObject = await fs7.readJSON(
|
|
2522
|
+
configManager.generatedLookupJSONPath
|
|
2523
|
+
);
|
|
2524
|
+
const graphqlSchemaObject = await fs7.readJSON(
|
|
2525
|
+
configManager.generatedGraphQLJSONPath
|
|
2526
|
+
);
|
|
2410
2527
|
const tinaLockFilename = "tina-lock.json";
|
|
2411
2528
|
const tinaLockContent = JSON.stringify({
|
|
2412
2529
|
schema: schemaObject,
|
|
2413
2530
|
lookup: lookupObject,
|
|
2414
2531
|
graphql: graphqlSchemaObject
|
|
2415
2532
|
});
|
|
2416
|
-
|
|
2417
|
-
|
|
2533
|
+
fs7.writeFileSync(
|
|
2534
|
+
path8.join(configManager.tinaFolderPath, tinaLockFilename),
|
|
2418
2535
|
tinaLockContent
|
|
2419
2536
|
);
|
|
2420
2537
|
if (configManager.hasSeparateContentRoot()) {
|
|
2421
2538
|
const rootPath = await configManager.getTinaFolderPath(
|
|
2422
2539
|
configManager.contentRootPath
|
|
2423
2540
|
);
|
|
2424
|
-
const filePath =
|
|
2425
|
-
await
|
|
2426
|
-
await
|
|
2541
|
+
const filePath = path8.join(rootPath, tinaLockFilename);
|
|
2542
|
+
await fs7.ensureFile(filePath);
|
|
2543
|
+
await fs7.outputFile(filePath, tinaLockContent);
|
|
2427
2544
|
}
|
|
2428
2545
|
}
|
|
2429
2546
|
await this.indexContentWithSpinner({
|
|
@@ -2466,19 +2583,19 @@ ${dangerText(e.message)}
|
|
|
2466
2583
|
const { apiURL, graphQLSchema, tinaSchema } = await setup({
|
|
2467
2584
|
firstTime: true
|
|
2468
2585
|
});
|
|
2469
|
-
await
|
|
2470
|
-
await
|
|
2586
|
+
await fs7.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
2587
|
+
await fs7.outputFile(
|
|
2471
2588
|
configManager.outputGitignorePath,
|
|
2472
2589
|
"index.html\nassets/"
|
|
2473
2590
|
);
|
|
2474
|
-
const searchIndexClient = new
|
|
2591
|
+
const searchIndexClient = new LocalSearchIndexClient({
|
|
2475
2592
|
stopwordLanguages: configManager.config.search?.tina?.stopwordLanguages,
|
|
2476
2593
|
tokenSplitRegex: configManager.config.search?.tina?.tokenSplitRegex
|
|
2477
2594
|
});
|
|
2478
2595
|
await searchIndexClient.onStartIndexing();
|
|
2479
|
-
const searchIndexer = new
|
|
2596
|
+
const searchIndexer = new SearchIndexer({
|
|
2480
2597
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
2481
|
-
bridge: new
|
|
2598
|
+
bridge: new FilesystemBridge2(
|
|
2482
2599
|
configManager.rootPath,
|
|
2483
2600
|
configManager.contentRootPath
|
|
2484
2601
|
),
|
|
@@ -2509,17 +2626,21 @@ ${dangerText(e.message)}
|
|
|
2509
2626
|
configManager.config.search && searchIndexer
|
|
2510
2627
|
);
|
|
2511
2628
|
}
|
|
2629
|
+
const searchIndexWithFuzzy = searchIndexClient.searchIndex;
|
|
2630
|
+
if (searchIndexClient.fuzzySearchWrapper) {
|
|
2631
|
+
searchIndexWithFuzzy.fuzzySearchWrapper = searchIndexClient.fuzzySearchWrapper;
|
|
2632
|
+
}
|
|
2512
2633
|
const server = await createDevServer(
|
|
2513
2634
|
configManager,
|
|
2514
2635
|
database,
|
|
2515
|
-
|
|
2636
|
+
searchIndexWithFuzzy,
|
|
2516
2637
|
apiURL,
|
|
2517
2638
|
this.noWatch,
|
|
2518
2639
|
dbLock
|
|
2519
2640
|
);
|
|
2520
2641
|
await server.listen(Number(this.port));
|
|
2521
2642
|
if (!this.noWatch) {
|
|
2522
|
-
|
|
2643
|
+
chokidar.watch(configManager.watchList).on("change", async () => {
|
|
2523
2644
|
await dbLock(async () => {
|
|
2524
2645
|
logger.info(`Tina config change detected, rebuilding`);
|
|
2525
2646
|
await setup({ firstTime: false });
|
|
@@ -2581,11 +2702,11 @@ ${dangerText(e.message)}
|
|
|
2581
2702
|
// subItems: [
|
|
2582
2703
|
// {
|
|
2583
2704
|
// key: 'Custom queries',
|
|
2584
|
-
// value: 'https://tina.io/
|
|
2705
|
+
// value: 'https://tina.io/docs/r/content-api-overview',
|
|
2585
2706
|
// },
|
|
2586
2707
|
// {
|
|
2587
2708
|
// key: 'Visual editing',
|
|
2588
|
-
// value: 'https://tina.io/visual-editing',
|
|
2709
|
+
// value: 'https://tina.io/docs/r/visual-editing-setup',
|
|
2589
2710
|
// },
|
|
2590
2711
|
// ],
|
|
2591
2712
|
// },
|
|
@@ -2596,14 +2717,14 @@ ${dangerText(e.message)}
|
|
|
2596
2717
|
watchContentFiles(configManager, database, databaseLock, searchIndexer) {
|
|
2597
2718
|
const collectionContentFiles = [];
|
|
2598
2719
|
configManager.config.schema.collections.forEach((collection) => {
|
|
2599
|
-
const collectionGlob = `${
|
|
2720
|
+
const collectionGlob = `${path8.join(
|
|
2600
2721
|
configManager.contentRootPath,
|
|
2601
2722
|
collection.path
|
|
2602
2723
|
)}/**/*.${collection.format || "md"}`;
|
|
2603
2724
|
collectionContentFiles.push(collectionGlob);
|
|
2604
2725
|
});
|
|
2605
2726
|
let ready = false;
|
|
2606
|
-
|
|
2727
|
+
chokidar.watch(collectionContentFiles).on("ready", () => {
|
|
2607
2728
|
ready = true;
|
|
2608
2729
|
}).on("add", async (addedFile) => {
|
|
2609
2730
|
if (!ready) {
|
|
@@ -2640,28 +2761,35 @@ ${dangerText(e.message)}
|
|
|
2640
2761
|
await callback();
|
|
2641
2762
|
});
|
|
2642
2763
|
};
|
|
2643
|
-
|
|
2764
|
+
chokidar.watch(configManager.userQueriesAndFragmentsGlob).on("add", executeCallback).on("change", executeCallback).on("unlink", executeCallback);
|
|
2644
2765
|
}
|
|
2645
2766
|
};
|
|
2646
2767
|
|
|
2647
2768
|
// src/next/commands/build-command/index.ts
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2769
|
+
import crypto from "crypto";
|
|
2770
|
+
import path9 from "path";
|
|
2771
|
+
import { diff } from "@graphql-inspector/core";
|
|
2772
|
+
import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
|
|
2773
|
+
import { parseURL as parseURL2 } from "@tinacms/schema-tools";
|
|
2774
|
+
import {
|
|
2775
|
+
SearchIndexer as SearchIndexer2,
|
|
2776
|
+
TinaCMSSearchIndexClient
|
|
2777
|
+
} from "@tinacms/search";
|
|
2778
|
+
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
2779
|
+
import fs8 from "fs-extra";
|
|
2780
|
+
import {
|
|
2781
|
+
buildASTSchema as buildASTSchema2,
|
|
2782
|
+
buildClientSchema,
|
|
2783
|
+
getIntrospectionQuery
|
|
2784
|
+
} from "graphql";
|
|
2785
|
+
import Progress2 from "progress";
|
|
2658
2786
|
|
|
2659
2787
|
// src/utils/index.ts
|
|
2660
|
-
|
|
2788
|
+
import { ChangeType } from "@graphql-inspector/core";
|
|
2661
2789
|
var getFaqLink = (type) => {
|
|
2662
2790
|
switch (type) {
|
|
2663
|
-
case
|
|
2664
|
-
return "https://tina.io/docs/
|
|
2791
|
+
case ChangeType.FieldRemoved: {
|
|
2792
|
+
return "https://tina.io/docs/r/FAQ/#2-how-do-i-resolve-the-local-graphql-schema-doesnt-match-the-remote-graphql-schema-error";
|
|
2665
2793
|
}
|
|
2666
2794
|
default:
|
|
2667
2795
|
return null;
|
|
@@ -2682,7 +2810,7 @@ async function sleepAndCallFunc({
|
|
|
2682
2810
|
}
|
|
2683
2811
|
|
|
2684
2812
|
// src/next/commands/build-command/server.ts
|
|
2685
|
-
|
|
2813
|
+
import { build as build2 } from "vite";
|
|
2686
2814
|
var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
2687
2815
|
const publicEnv = {};
|
|
2688
2816
|
Object.keys(process.env).forEach((key) => {
|
|
@@ -2716,12 +2844,12 @@ var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
|
2716
2844
|
}
|
|
2717
2845
|
}
|
|
2718
2846
|
});
|
|
2719
|
-
return (
|
|
2847
|
+
return build2(config2);
|
|
2720
2848
|
};
|
|
2721
2849
|
|
|
2722
2850
|
// src/next/commands/build-command/waitForDB.ts
|
|
2723
|
-
|
|
2724
|
-
|
|
2851
|
+
import { parseURL } from "@tinacms/schema-tools";
|
|
2852
|
+
import Progress from "progress";
|
|
2725
2853
|
var POLLING_INTERVAL = 5e3;
|
|
2726
2854
|
var STATUS_INPROGRESS = "inprogress";
|
|
2727
2855
|
var STATUS_COMPLETE = "complete";
|
|
@@ -2734,14 +2862,14 @@ var IndexFailedError = class extends Error {
|
|
|
2734
2862
|
};
|
|
2735
2863
|
var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
2736
2864
|
const token = config2.token;
|
|
2737
|
-
const { clientId, branch, isLocalClient, host } =
|
|
2865
|
+
const { clientId, branch, isLocalClient, host } = parseURL(apiUrl);
|
|
2738
2866
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
2739
2867
|
if (verbose) {
|
|
2740
2868
|
logger.info(logText("Not using TinaCloud, skipping DB check"));
|
|
2741
2869
|
}
|
|
2742
2870
|
return;
|
|
2743
2871
|
}
|
|
2744
|
-
const bar2 = new
|
|
2872
|
+
const bar2 = new Progress(
|
|
2745
2873
|
"Checking indexing process in TinaCloud... :prog",
|
|
2746
2874
|
1
|
|
2747
2875
|
);
|
|
@@ -2804,51 +2932,44 @@ var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
|
2804
2932
|
|
|
2805
2933
|
// src/next/commands/build-command/index.ts
|
|
2806
2934
|
var BuildCommand = class extends BaseCommand {
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
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
|
-
static {
|
|
2847
|
-
this.usage = import_clipanion3.Command.Usage({
|
|
2848
|
-
category: `Commands`,
|
|
2849
|
-
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2850
|
-
});
|
|
2851
|
-
}
|
|
2935
|
+
static paths = [["build"]];
|
|
2936
|
+
localOption = Option3.Boolean("--local", {
|
|
2937
|
+
description: "Starts local Graphql server and builds the local client instead of production client"
|
|
2938
|
+
});
|
|
2939
|
+
skipIndexing = Option3.Boolean("--skip-indexing", false, {
|
|
2940
|
+
description: "Skips indexing the content. This can be used for building the site without indexing the content (defaults to false)"
|
|
2941
|
+
});
|
|
2942
|
+
partialReindex = Option3.Boolean("--partial-reindex", false, {
|
|
2943
|
+
description: "Re-indexes only the content that has changed since the last build (defaults to false). Not currently supported for separate content repos."
|
|
2944
|
+
});
|
|
2945
|
+
tinaGraphQLVersion = Option3.String("--tina-graphql-version", {
|
|
2946
|
+
description: "Specify the version of @tinacms/graphql to use (defaults to latest)"
|
|
2947
|
+
});
|
|
2948
|
+
/**
|
|
2949
|
+
* 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
|
|
2950
|
+
*/
|
|
2951
|
+
skipCloudChecks = Option3.Boolean("--skip-cloud-checks", false, {
|
|
2952
|
+
description: "Skips checking the provided cloud config."
|
|
2953
|
+
});
|
|
2954
|
+
skipSearchIndex = Option3.Boolean("--skip-search-index", false, {
|
|
2955
|
+
description: "Skip indexing the site for search"
|
|
2956
|
+
});
|
|
2957
|
+
upstreamBranch = Option3.String("--upstream-branch", {
|
|
2958
|
+
description: "Optional upstream branch with the schema. If not specified, default will be used."
|
|
2959
|
+
});
|
|
2960
|
+
previewBaseBranch = Option3.String("--preview-base-branch", {
|
|
2961
|
+
description: "The base branch for the preview"
|
|
2962
|
+
});
|
|
2963
|
+
previewName = Option3.String("--preview-name", {
|
|
2964
|
+
description: "The name of the preview branch"
|
|
2965
|
+
});
|
|
2966
|
+
noClientBuildCache = Option3.Boolean("--no-client-build-cache", false, {
|
|
2967
|
+
description: "Disables the client build cache"
|
|
2968
|
+
});
|
|
2969
|
+
static usage = Command3.Usage({
|
|
2970
|
+
category: `Commands`,
|
|
2971
|
+
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2972
|
+
});
|
|
2852
2973
|
async catch(error) {
|
|
2853
2974
|
console.error(error);
|
|
2854
2975
|
process.exit(1);
|
|
@@ -2893,7 +3014,7 @@ ${dangerText(e.message)}`);
|
|
|
2893
3014
|
configManager,
|
|
2894
3015
|
Number(this.datalayerPort)
|
|
2895
3016
|
);
|
|
2896
|
-
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await (
|
|
3017
|
+
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await buildSchema2(configManager.config);
|
|
2897
3018
|
const codegen2 = new Codegen({
|
|
2898
3019
|
configManager,
|
|
2899
3020
|
port: this.localOption ? Number(this.port) : void 0,
|
|
@@ -2942,48 +3063,66 @@ ${dangerText(e.message)}
|
|
|
2942
3063
|
}
|
|
2943
3064
|
const skipCloudChecks = this.skipCloudChecks || configManager.hasSelfHostedConfig();
|
|
2944
3065
|
if (!skipCloudChecks) {
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
if (!hasUpstream && this.upstreamBranch) {
|
|
2951
|
-
logger.warn(
|
|
2952
|
-
`${dangerText(
|
|
2953
|
-
`WARN: Upstream branch '${this.upstreamBranch}' specified but no upstream project was found.`
|
|
2954
|
-
)}`
|
|
3066
|
+
try {
|
|
3067
|
+
const clientInfo = await this.checkClientInfo(
|
|
3068
|
+
configManager,
|
|
3069
|
+
codegen2.productionUrl,
|
|
3070
|
+
this.previewBaseBranch
|
|
2955
3071
|
);
|
|
3072
|
+
if (clientInfo.detectedBotBranch) {
|
|
3073
|
+
logger.warn(
|
|
3074
|
+
`${warnText(
|
|
3075
|
+
`WARN: Detected bot branch. Using schema/content from default branch '${clientInfo.defaultBranch}' instead of '${configManager.config.branch}'.`
|
|
3076
|
+
)}`
|
|
3077
|
+
);
|
|
3078
|
+
}
|
|
3079
|
+
if (!clientInfo.hasUpstream && this.upstreamBranch) {
|
|
3080
|
+
logger.warn(
|
|
3081
|
+
`${dangerText(
|
|
3082
|
+
`WARN: Upstream branch '${this.upstreamBranch}' specified but no upstream project was found.`
|
|
3083
|
+
)}`
|
|
3084
|
+
);
|
|
3085
|
+
}
|
|
3086
|
+
if (clientInfo.hasUpstream || this.previewBaseBranch && this.previewName) {
|
|
3087
|
+
await this.syncProject(configManager, codegen2.productionUrl, {
|
|
3088
|
+
upstreamBranch: this.upstreamBranch,
|
|
3089
|
+
previewBaseBranch: this.previewBaseBranch,
|
|
3090
|
+
previewName: this.previewName
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
await waitForDB(
|
|
3094
|
+
configManager.config,
|
|
3095
|
+
codegen2.productionUrl,
|
|
3096
|
+
this.previewName,
|
|
3097
|
+
false
|
|
3098
|
+
);
|
|
3099
|
+
await this.checkGraphqlSchema(
|
|
3100
|
+
configManager,
|
|
3101
|
+
database,
|
|
3102
|
+
codegen2.productionUrl,
|
|
3103
|
+
clientInfo.timestamp
|
|
3104
|
+
);
|
|
3105
|
+
await this.checkTinaSchema(
|
|
3106
|
+
configManager,
|
|
3107
|
+
database,
|
|
3108
|
+
codegen2.productionUrl,
|
|
3109
|
+
this.previewName,
|
|
3110
|
+
this.verbose,
|
|
3111
|
+
clientInfo.timestamp
|
|
3112
|
+
);
|
|
3113
|
+
} catch (e) {
|
|
3114
|
+
logger.error(`
|
|
3115
|
+
|
|
3116
|
+
${dangerText(e.message)}
|
|
3117
|
+
`);
|
|
3118
|
+
if (this.verbose) {
|
|
3119
|
+
console.error(e);
|
|
3120
|
+
}
|
|
3121
|
+
process.exit(1);
|
|
2956
3122
|
}
|
|
2957
|
-
if (hasUpstream || this.previewBaseBranch && this.previewName) {
|
|
2958
|
-
await this.syncProject(configManager, codegen2.productionUrl, {
|
|
2959
|
-
upstreamBranch: this.upstreamBranch,
|
|
2960
|
-
previewBaseBranch: this.previewBaseBranch,
|
|
2961
|
-
previewName: this.previewName
|
|
2962
|
-
});
|
|
2963
|
-
}
|
|
2964
|
-
await waitForDB(
|
|
2965
|
-
configManager.config,
|
|
2966
|
-
codegen2.productionUrl,
|
|
2967
|
-
this.previewName,
|
|
2968
|
-
false
|
|
2969
|
-
);
|
|
2970
|
-
await this.checkGraphqlSchema(
|
|
2971
|
-
configManager,
|
|
2972
|
-
database,
|
|
2973
|
-
codegen2.productionUrl,
|
|
2974
|
-
timestamp
|
|
2975
|
-
);
|
|
2976
|
-
await this.checkTinaSchema(
|
|
2977
|
-
configManager,
|
|
2978
|
-
database,
|
|
2979
|
-
codegen2.productionUrl,
|
|
2980
|
-
this.previewName,
|
|
2981
|
-
this.verbose,
|
|
2982
|
-
timestamp
|
|
2983
|
-
);
|
|
2984
3123
|
}
|
|
2985
3124
|
await buildProductionSpa(configManager, database, codegen2.productionUrl);
|
|
2986
|
-
await
|
|
3125
|
+
await fs8.outputFile(
|
|
2987
3126
|
configManager.outputGitignorePath,
|
|
2988
3127
|
"index.html\nassets/"
|
|
2989
3128
|
);
|
|
@@ -3015,7 +3154,7 @@ ${dangerText(e.message)}
|
|
|
3015
3154
|
"indexerToken not configured in tina search configuration."
|
|
3016
3155
|
);
|
|
3017
3156
|
}
|
|
3018
|
-
client = new
|
|
3157
|
+
client = new TinaCMSSearchIndexClient({
|
|
3019
3158
|
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
3020
3159
|
branch: configManager.config?.branch,
|
|
3021
3160
|
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
@@ -3024,9 +3163,9 @@ ${dangerText(e.message)}
|
|
|
3024
3163
|
} else {
|
|
3025
3164
|
client = configManager.config?.search?.searchClient;
|
|
3026
3165
|
}
|
|
3027
|
-
const searchIndexer = new
|
|
3166
|
+
const searchIndexer = new SearchIndexer2({
|
|
3028
3167
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
3029
|
-
bridge: new
|
|
3168
|
+
bridge: new FilesystemBridge3(
|
|
3030
3169
|
configManager.rootPath,
|
|
3031
3170
|
configManager.contentRootPath
|
|
3032
3171
|
),
|
|
@@ -3093,86 +3232,88 @@ ${dangerText(e.message)}
|
|
|
3093
3232
|
}
|
|
3094
3233
|
}
|
|
3095
3234
|
async checkClientInfo(configManager, apiURL, previewBaseBranch) {
|
|
3235
|
+
const MAX_RETRIES = 5;
|
|
3096
3236
|
const { config: config2 } = configManager;
|
|
3097
3237
|
const token = config2.token;
|
|
3098
|
-
const { clientId, branch, host } = (
|
|
3099
|
-
const
|
|
3100
|
-
const
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3238
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3239
|
+
const bar2 = new Progress2("Checking clientId and token. :prog", 1);
|
|
3240
|
+
const getBranchInfo = async () => {
|
|
3241
|
+
const url = `https://${host}/db/${clientId}/status/${previewBaseBranch || branch}`;
|
|
3242
|
+
const branchInfo2 = {
|
|
3243
|
+
status: "unknown",
|
|
3244
|
+
branchKnown: false,
|
|
3245
|
+
hasUpstream: false,
|
|
3246
|
+
timestamp: 0,
|
|
3247
|
+
detectedBotBranch: false,
|
|
3248
|
+
defaultBranch: void 0
|
|
3249
|
+
};
|
|
3250
|
+
try {
|
|
3251
|
+
const res = await request({
|
|
3252
|
+
token,
|
|
3253
|
+
url
|
|
3254
|
+
});
|
|
3255
|
+
branchInfo2.status = res.status;
|
|
3256
|
+
branchInfo2.branchKnown = res.status !== "unknown";
|
|
3257
|
+
branchInfo2.timestamp = res.timestamp || 0;
|
|
3258
|
+
branchInfo2.hasUpstream = res.hasUpstream;
|
|
3259
|
+
branchInfo2.detectedBotBranch = res.json.detectedBotBranch;
|
|
3260
|
+
branchInfo2.defaultBranch = res.json.defaultBranch;
|
|
3261
|
+
} catch (e) {
|
|
3262
|
+
summary({
|
|
3263
|
+
heading: "Error when checking client information",
|
|
3264
|
+
items: [
|
|
3265
|
+
{
|
|
3266
|
+
emoji: "\u274C",
|
|
3267
|
+
heading: "You provided",
|
|
3268
|
+
subItems: [
|
|
3269
|
+
{
|
|
3270
|
+
key: "clientId",
|
|
3271
|
+
value: config2.clientId
|
|
3272
|
+
},
|
|
3273
|
+
{
|
|
3274
|
+
key: "branch",
|
|
3275
|
+
value: config2.branch
|
|
3276
|
+
},
|
|
3277
|
+
{
|
|
3278
|
+
key: "token",
|
|
3279
|
+
value: config2.token
|
|
3280
|
+
}
|
|
3281
|
+
]
|
|
3282
|
+
}
|
|
3283
|
+
]
|
|
3284
|
+
});
|
|
3285
|
+
throw e;
|
|
3118
3286
|
}
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
},
|
|
3131
|
-
{
|
|
3132
|
-
key: "branch",
|
|
3133
|
-
value: config2.branch
|
|
3134
|
-
},
|
|
3135
|
-
{
|
|
3136
|
-
key: "token",
|
|
3137
|
-
value: config2.token
|
|
3138
|
-
}
|
|
3139
|
-
]
|
|
3140
|
-
}
|
|
3141
|
-
]
|
|
3142
|
-
});
|
|
3143
|
-
throw e;
|
|
3144
|
-
}
|
|
3145
|
-
const branchBar = new import_progress2.default("Checking branch is on TinaCloud. :prog", 1);
|
|
3146
|
-
if (branchKnown) {
|
|
3287
|
+
return branchInfo2;
|
|
3288
|
+
};
|
|
3289
|
+
const branchInfo = await getBranchInfo();
|
|
3290
|
+
bar2.tick({
|
|
3291
|
+
prog: "\u2705"
|
|
3292
|
+
});
|
|
3293
|
+
const branchBar = new Progress2(
|
|
3294
|
+
`Checking branch '${config2.branch}' is on TinaCloud. :prog`,
|
|
3295
|
+
1
|
|
3296
|
+
);
|
|
3297
|
+
if (branchInfo.branchKnown) {
|
|
3147
3298
|
branchBar.tick({
|
|
3148
3299
|
prog: "\u2705"
|
|
3149
3300
|
});
|
|
3150
|
-
return
|
|
3151
|
-
hasUpstream,
|
|
3152
|
-
timestamp
|
|
3153
|
-
};
|
|
3301
|
+
return branchInfo;
|
|
3154
3302
|
}
|
|
3155
|
-
for (let i =
|
|
3156
|
-
await
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
prog: "\u2705"
|
|
3170
|
-
});
|
|
3171
|
-
return;
|
|
3172
|
-
}
|
|
3173
|
-
},
|
|
3174
|
-
ms: 5e3
|
|
3175
|
-
});
|
|
3303
|
+
for (let i = 1; i <= MAX_RETRIES; i++) {
|
|
3304
|
+
await timeout(5e3);
|
|
3305
|
+
const branchInfo2 = await getBranchInfo();
|
|
3306
|
+
if (this.verbose) {
|
|
3307
|
+
logger.info(
|
|
3308
|
+
`Branch status: ${branchInfo2.status}. Attempt: ${i}. Trying again in 5 seconds.`
|
|
3309
|
+
);
|
|
3310
|
+
}
|
|
3311
|
+
if (branchInfo2.branchKnown) {
|
|
3312
|
+
branchBar.tick({
|
|
3313
|
+
prog: "\u2705"
|
|
3314
|
+
});
|
|
3315
|
+
return branchInfo2;
|
|
3316
|
+
}
|
|
3176
3317
|
}
|
|
3177
3318
|
branchBar.tick({
|
|
3178
3319
|
prog: "\u274C"
|
|
@@ -3180,7 +3321,7 @@ ${dangerText(e.message)}
|
|
|
3180
3321
|
logger.error(
|
|
3181
3322
|
`${dangerText(
|
|
3182
3323
|
`ERROR: Branch '${branch}' is not on TinaCloud.`
|
|
3183
|
-
)} Please make sure that branch '${branch}' exists in your repository and that you have pushed your all changes to the remote. View all
|
|
3324
|
+
)} 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(
|
|
3184
3325
|
`https://app.tina.io/projects/${clientId}/configuration`
|
|
3185
3326
|
)}`
|
|
3186
3327
|
);
|
|
@@ -3189,7 +3330,7 @@ ${dangerText(e.message)}
|
|
|
3189
3330
|
async syncProject(configManager, apiURL, options) {
|
|
3190
3331
|
const { config: config2 } = configManager;
|
|
3191
3332
|
const token = config2.token;
|
|
3192
|
-
const { clientId, branch, host } = (
|
|
3333
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3193
3334
|
const { previewName, previewBaseBranch, upstreamBranch } = options || {};
|
|
3194
3335
|
let url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true`;
|
|
3195
3336
|
if (upstreamBranch && previewBaseBranch && previewName) {
|
|
@@ -3199,7 +3340,7 @@ ${dangerText(e.message)}
|
|
|
3199
3340
|
} else if (upstreamBranch && !previewBaseBranch && !previewName) {
|
|
3200
3341
|
url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true&upstreamBranch=${upstreamBranch}`;
|
|
3201
3342
|
}
|
|
3202
|
-
const bar2 = new
|
|
3343
|
+
const bar2 = new Progress2("Syncing Project. :prog", 1);
|
|
3203
3344
|
try {
|
|
3204
3345
|
const res = await request({
|
|
3205
3346
|
token,
|
|
@@ -3240,7 +3381,7 @@ ${dangerText(e.message)}
|
|
|
3240
3381
|
}
|
|
3241
3382
|
}
|
|
3242
3383
|
async checkGraphqlSchema(configManager, database, apiURL, timestamp) {
|
|
3243
|
-
const bar2 = new
|
|
3384
|
+
const bar2 = new Progress2(
|
|
3244
3385
|
"Checking local GraphQL Schema matches server. :prog",
|
|
3245
3386
|
1
|
|
3246
3387
|
);
|
|
@@ -3262,11 +3403,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3262
3403
|
}
|
|
3263
3404
|
throw new Error(errorMessage);
|
|
3264
3405
|
}
|
|
3265
|
-
const remoteGqlSchema =
|
|
3406
|
+
const remoteGqlSchema = buildClientSchema(remoteSchema);
|
|
3266
3407
|
const localSchemaDocument = await database.getGraphQLSchemaFromBridge();
|
|
3267
|
-
const localGraphqlSchema = (
|
|
3408
|
+
const localGraphqlSchema = buildASTSchema2(localSchemaDocument);
|
|
3268
3409
|
try {
|
|
3269
|
-
const diffResult = await
|
|
3410
|
+
const diffResult = await diff(remoteGqlSchema, localGraphqlSchema);
|
|
3270
3411
|
if (diffResult.length === 0) {
|
|
3271
3412
|
bar2.tick({
|
|
3272
3413
|
prog: "\u2705"
|
|
@@ -3314,13 +3455,13 @@ Additional info:
|
|
|
3314
3455
|
}
|
|
3315
3456
|
}
|
|
3316
3457
|
async checkTinaSchema(configManager, database, apiURL, previewName, verbose, timestamp) {
|
|
3317
|
-
const bar2 = new
|
|
3458
|
+
const bar2 = new Progress2(
|
|
3318
3459
|
"Checking local Tina Schema matches server. :prog",
|
|
3319
3460
|
1
|
|
3320
3461
|
);
|
|
3321
3462
|
const { config: config2 } = configManager;
|
|
3322
3463
|
const token = config2.token;
|
|
3323
|
-
const { clientId, branch, isLocalClient, host } = (
|
|
3464
|
+
const { clientId, branch, isLocalClient, host } = parseURL2(apiURL);
|
|
3324
3465
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
3325
3466
|
if (verbose) {
|
|
3326
3467
|
logger.info(logText("Not using TinaCloud, skipping Tina Schema check"));
|
|
@@ -3348,11 +3489,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3348
3489
|
}
|
|
3349
3490
|
const localTinaSchema = JSON.parse(
|
|
3350
3491
|
await database.bridge.get(
|
|
3351
|
-
|
|
3492
|
+
path9.join(database.tinaDirectory, "__generated__", "_schema.json")
|
|
3352
3493
|
)
|
|
3353
3494
|
);
|
|
3354
3495
|
localTinaSchema.version = void 0;
|
|
3355
|
-
const localTinaSchemaSha =
|
|
3496
|
+
const localTinaSchemaSha = crypto.createHash("sha256").update(JSON.stringify(localTinaSchema)).digest("hex");
|
|
3356
3497
|
if (localTinaSchemaSha === remoteTinaSchemaSha) {
|
|
3357
3498
|
bar2.tick({
|
|
3358
3499
|
prog: "\u2705"
|
|
@@ -3403,12 +3544,12 @@ async function request(args) {
|
|
|
3403
3544
|
Message from server: ${json.message}`;
|
|
3404
3545
|
}
|
|
3405
3546
|
throw new Error(
|
|
3406
|
-
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/
|
|
3547
|
+
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/r/FAQ/`
|
|
3407
3548
|
);
|
|
3408
3549
|
}
|
|
3409
3550
|
if (json.errors) {
|
|
3410
3551
|
throw new Error(
|
|
3411
|
-
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/
|
|
3552
|
+
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/r/FAQ/
|
|
3412
3553
|
|
|
3413
3554
|
Errors:
|
|
3414
3555
|
${json.errors.map((error) => error.message).join("\n")}`
|
|
@@ -3417,7 +3558,8 @@ Message from server: ${json.message}`;
|
|
|
3417
3558
|
return {
|
|
3418
3559
|
status: json?.status,
|
|
3419
3560
|
timestamp: json?.timestamp,
|
|
3420
|
-
hasUpstream: json?.hasUpstream || false
|
|
3561
|
+
hasUpstream: json?.hasUpstream || false,
|
|
3562
|
+
json
|
|
3421
3563
|
};
|
|
3422
3564
|
}
|
|
3423
3565
|
var fetchRemoteGraphqlSchema = async ({
|
|
@@ -3429,7 +3571,7 @@ var fetchRemoteGraphqlSchema = async ({
|
|
|
3429
3571
|
headers.append("X-API-KEY", token);
|
|
3430
3572
|
}
|
|
3431
3573
|
const body = JSON.stringify({
|
|
3432
|
-
query:
|
|
3574
|
+
query: getIntrospectionQuery(),
|
|
3433
3575
|
variables: {}
|
|
3434
3576
|
});
|
|
3435
3577
|
headers.append("Content-Type", "application/json");
|
|
@@ -3462,14 +3604,14 @@ var fetchSchemaSha = async ({
|
|
|
3462
3604
|
};
|
|
3463
3605
|
|
|
3464
3606
|
// src/next/commands/audit-command/index.ts
|
|
3465
|
-
|
|
3466
|
-
|
|
3607
|
+
import { Command as Command4, Option as Option4 } from "clipanion";
|
|
3608
|
+
import { buildSchema as buildSchema3 } from "@tinacms/graphql";
|
|
3467
3609
|
|
|
3468
3610
|
// src/next/commands/audit-command/audit.ts
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3611
|
+
import prompts from "prompts";
|
|
3612
|
+
import { Telemetry } from "@tinacms/metrics";
|
|
3613
|
+
import { resolve } from "@tinacms/graphql";
|
|
3614
|
+
import chalk5 from "chalk";
|
|
3473
3615
|
var audit = async ({
|
|
3474
3616
|
database,
|
|
3475
3617
|
clean,
|
|
@@ -3477,7 +3619,7 @@ var audit = async ({
|
|
|
3477
3619
|
noTelemetry,
|
|
3478
3620
|
verbose
|
|
3479
3621
|
}) => {
|
|
3480
|
-
const telemetry = new
|
|
3622
|
+
const telemetry = new Telemetry({ disabled: noTelemetry });
|
|
3481
3623
|
await telemetry.submitRecord({
|
|
3482
3624
|
event: {
|
|
3483
3625
|
name: "tinacms:cli:audit:invoke",
|
|
@@ -3487,25 +3629,25 @@ var audit = async ({
|
|
|
3487
3629
|
});
|
|
3488
3630
|
if (clean) {
|
|
3489
3631
|
logger.info(
|
|
3490
|
-
`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 ${
|
|
3632
|
+
`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(
|
|
3491
3633
|
"clean git tree"
|
|
3492
3634
|
)} so unwanted changes can be undone.
|
|
3493
3635
|
|
|
3494
3636
|
`
|
|
3495
3637
|
);
|
|
3496
|
-
const res = await (
|
|
3638
|
+
const res = await prompts({
|
|
3497
3639
|
name: "useClean",
|
|
3498
3640
|
type: "confirm",
|
|
3499
3641
|
message: `Do you want to continue?`
|
|
3500
3642
|
});
|
|
3501
3643
|
if (!res.useClean) {
|
|
3502
|
-
logger.warn(
|
|
3644
|
+
logger.warn(chalk5.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
3503
3645
|
process.exit(0);
|
|
3504
3646
|
}
|
|
3505
3647
|
}
|
|
3506
3648
|
if (useDefaultValues && !clean) {
|
|
3507
3649
|
logger.warn(
|
|
3508
|
-
|
|
3650
|
+
chalk5.yellowBright(
|
|
3509
3651
|
"WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"
|
|
3510
3652
|
)
|
|
3511
3653
|
);
|
|
@@ -3533,10 +3675,10 @@ var audit = async ({
|
|
|
3533
3675
|
}
|
|
3534
3676
|
if (error) {
|
|
3535
3677
|
logger.error(
|
|
3536
|
-
|
|
3678
|
+
chalk5.redBright(`\u203C\uFE0F Audit ${chalk5.bold("failed")} with errors`)
|
|
3537
3679
|
);
|
|
3538
3680
|
} else {
|
|
3539
|
-
logger.info(
|
|
3681
|
+
logger.info(chalk5.greenBright("\u2705 Audit passed"));
|
|
3540
3682
|
}
|
|
3541
3683
|
};
|
|
3542
3684
|
var auditDocuments = async (args) => {
|
|
@@ -3553,7 +3695,7 @@ var auditDocuments = async (args) => {
|
|
|
3553
3695
|
}
|
|
3554
3696
|
}
|
|
3555
3697
|
}`;
|
|
3556
|
-
const docResult = await
|
|
3698
|
+
const docResult = await resolve({
|
|
3557
3699
|
database,
|
|
3558
3700
|
query: documentQuery,
|
|
3559
3701
|
variables: {},
|
|
@@ -3564,11 +3706,11 @@ var auditDocuments = async (args) => {
|
|
|
3564
3706
|
if (docResult.errors) {
|
|
3565
3707
|
error = true;
|
|
3566
3708
|
docResult.errors.forEach((err) => {
|
|
3567
|
-
logger.error(
|
|
3709
|
+
logger.error(chalk5.red(err.message));
|
|
3568
3710
|
if (err.originalError.originalError) {
|
|
3569
3711
|
logger.error(
|
|
3570
3712
|
// @ts-ignore FIXME: this doesn't seem right
|
|
3571
|
-
|
|
3713
|
+
chalk5.red(` ${err.originalError.originalError.message}`)
|
|
3572
3714
|
);
|
|
3573
3715
|
}
|
|
3574
3716
|
});
|
|
@@ -3595,7 +3737,7 @@ var auditDocuments = async (args) => {
|
|
|
3595
3737
|
params: $params
|
|
3596
3738
|
){__typename}
|
|
3597
3739
|
}`;
|
|
3598
|
-
const mutationRes = await
|
|
3740
|
+
const mutationRes = await resolve({
|
|
3599
3741
|
database,
|
|
3600
3742
|
query: mutation,
|
|
3601
3743
|
variables: {
|
|
@@ -3610,7 +3752,7 @@ var auditDocuments = async (args) => {
|
|
|
3610
3752
|
if (mutationRes.errors) {
|
|
3611
3753
|
mutationRes.errors.forEach((err) => {
|
|
3612
3754
|
error = true;
|
|
3613
|
-
logger.error(
|
|
3755
|
+
logger.error(chalk5.red(err.message));
|
|
3614
3756
|
});
|
|
3615
3757
|
}
|
|
3616
3758
|
}
|
|
@@ -3627,38 +3769,31 @@ function filterObject(obj) {
|
|
|
3627
3769
|
}
|
|
3628
3770
|
|
|
3629
3771
|
// src/next/commands/audit-command/index.ts
|
|
3630
|
-
|
|
3631
|
-
var AuditCommand = class extends
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
}
|
|
3656
|
-
static {
|
|
3657
|
-
this.usage = import_clipanion4.Command.Usage({
|
|
3658
|
-
category: `Commands`,
|
|
3659
|
-
description: `Audit config and content files`
|
|
3660
|
-
});
|
|
3661
|
-
}
|
|
3772
|
+
import { AuditFileSystemBridge } from "@tinacms/graphql";
|
|
3773
|
+
var AuditCommand = class extends Command4 {
|
|
3774
|
+
static paths = [["audit"]];
|
|
3775
|
+
rootPath = Option4.String("--rootPath", {
|
|
3776
|
+
description: "Specify the root directory to run the CLI from"
|
|
3777
|
+
});
|
|
3778
|
+
verbose = Option4.Boolean("-v,--verbose", false, {
|
|
3779
|
+
description: "increase verbosity of logged output"
|
|
3780
|
+
});
|
|
3781
|
+
clean = Option4.Boolean("--clean", false, {
|
|
3782
|
+
description: "Clean the output"
|
|
3783
|
+
});
|
|
3784
|
+
useDefaultValues = Option4.Boolean("--useDefaultValues", false, {
|
|
3785
|
+
description: "When cleaning the output, use defaults on the config"
|
|
3786
|
+
});
|
|
3787
|
+
noTelemetry = Option4.Boolean("--noTelemetry", false, {
|
|
3788
|
+
description: "Disable anonymous telemetry that is collected"
|
|
3789
|
+
});
|
|
3790
|
+
datalayerPort = Option4.String("--datalayer-port", "9000", {
|
|
3791
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
3792
|
+
});
|
|
3793
|
+
static usage = Command4.Usage({
|
|
3794
|
+
category: `Commands`,
|
|
3795
|
+
description: `Audit config and content files`
|
|
3796
|
+
});
|
|
3662
3797
|
async catch(error) {
|
|
3663
3798
|
logger.error("Error occured during tinacms audit");
|
|
3664
3799
|
if (this.verbose) {
|
|
@@ -3679,9 +3814,9 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3679
3814
|
const database = await createAndInitializeDatabase(
|
|
3680
3815
|
configManager,
|
|
3681
3816
|
Number(this.datalayerPort),
|
|
3682
|
-
this.clean ? void 0 : new
|
|
3817
|
+
this.clean ? void 0 : new AuditFileSystemBridge(configManager.rootPath)
|
|
3683
3818
|
);
|
|
3684
|
-
const { tinaSchema, graphQLSchema, lookup } = await (
|
|
3819
|
+
const { tinaSchema, graphQLSchema, lookup } = await buildSchema3(
|
|
3685
3820
|
configManager.config
|
|
3686
3821
|
);
|
|
3687
3822
|
const warnings = [];
|
|
@@ -3714,29 +3849,29 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3714
3849
|
};
|
|
3715
3850
|
|
|
3716
3851
|
// src/next/commands/init-command/index.ts
|
|
3717
|
-
|
|
3852
|
+
import { Command as Command6, Option as Option6 } from "clipanion";
|
|
3718
3853
|
|
|
3719
3854
|
// src/cmds/init/detectEnvironment.ts
|
|
3720
|
-
|
|
3721
|
-
|
|
3855
|
+
import fs9 from "fs-extra";
|
|
3856
|
+
import path10 from "path";
|
|
3722
3857
|
var checkGitignoreForItem = async ({
|
|
3723
3858
|
baseDir,
|
|
3724
3859
|
line
|
|
3725
3860
|
}) => {
|
|
3726
|
-
const gitignoreContent =
|
|
3861
|
+
const gitignoreContent = fs9.readFileSync(path10.join(baseDir, ".gitignore")).toString();
|
|
3727
3862
|
return gitignoreContent.split("\n").some((item) => item === line);
|
|
3728
3863
|
};
|
|
3729
3864
|
var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
3730
3865
|
const result = {
|
|
3731
|
-
fullPathTS:
|
|
3866
|
+
fullPathTS: path10.join(
|
|
3732
3867
|
parentPath,
|
|
3733
3868
|
`${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
|
|
3734
3869
|
),
|
|
3735
|
-
fullPathJS:
|
|
3870
|
+
fullPathJS: path10.join(
|
|
3736
3871
|
parentPath,
|
|
3737
3872
|
`${name2}.${opts?.extensionOverride || "js"}`
|
|
3738
3873
|
),
|
|
3739
|
-
fullPathOverride: opts?.extensionOverride ?
|
|
3874
|
+
fullPathOverride: opts?.extensionOverride ? path10.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
|
|
3740
3875
|
generatedFileType,
|
|
3741
3876
|
name: name2,
|
|
3742
3877
|
parentPath,
|
|
@@ -3754,8 +3889,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
|
3754
3889
|
};
|
|
3755
3890
|
}
|
|
3756
3891
|
};
|
|
3757
|
-
result.typescriptExists = await
|
|
3758
|
-
result.javascriptExists = await
|
|
3892
|
+
result.typescriptExists = await fs9.pathExists(result.fullPathTS);
|
|
3893
|
+
result.javascriptExists = await fs9.pathExists(result.fullPathJS);
|
|
3759
3894
|
return result;
|
|
3760
3895
|
};
|
|
3761
3896
|
var detectEnvironment = async ({
|
|
@@ -3764,21 +3899,21 @@ var detectEnvironment = async ({
|
|
|
3764
3899
|
rootPath,
|
|
3765
3900
|
debug = false
|
|
3766
3901
|
}) => {
|
|
3767
|
-
const hasForestryConfig = await
|
|
3768
|
-
|
|
3902
|
+
const hasForestryConfig = await fs9.pathExists(
|
|
3903
|
+
path10.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
3769
3904
|
);
|
|
3770
|
-
const sampleContentPath =
|
|
3905
|
+
const sampleContentPath = path10.join(
|
|
3771
3906
|
baseDir,
|
|
3772
3907
|
"content",
|
|
3773
3908
|
"posts",
|
|
3774
3909
|
"hello-world.md"
|
|
3775
3910
|
);
|
|
3776
|
-
const usingSrc =
|
|
3777
|
-
const tinaFolder =
|
|
3911
|
+
const usingSrc = fs9.pathExistsSync(path10.join(baseDir, "src")) && (fs9.pathExistsSync(path10.join(baseDir, "src", "app")) || fs9.pathExistsSync(path10.join(baseDir, "src", "pages")));
|
|
3912
|
+
const tinaFolder = path10.join(baseDir, "tina");
|
|
3778
3913
|
const tinaConfigExists = Boolean(
|
|
3779
3914
|
// Does the tina folder exist?
|
|
3780
|
-
await
|
|
3781
|
-
(await
|
|
3915
|
+
await fs9.pathExists(tinaFolder) && // Does the tina folder contain a config file?
|
|
3916
|
+
(await fs9.readdir(tinaFolder)).find((x) => x.includes("config"))
|
|
3782
3917
|
);
|
|
3783
3918
|
const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
|
|
3784
3919
|
Boolean
|
|
@@ -3790,12 +3925,12 @@ var detectEnvironment = async ({
|
|
|
3790
3925
|
"next-api-handler": await makeGeneratedFile(
|
|
3791
3926
|
"[...routes]",
|
|
3792
3927
|
"next-api-handler",
|
|
3793
|
-
|
|
3928
|
+
path10.join(...pagesDir, "api", "tina")
|
|
3794
3929
|
),
|
|
3795
3930
|
"reactive-example": await makeGeneratedFile(
|
|
3796
3931
|
"[filename]",
|
|
3797
3932
|
"reactive-example",
|
|
3798
|
-
|
|
3933
|
+
path10.join(...pagesDir, "demo", "blog"),
|
|
3799
3934
|
{
|
|
3800
3935
|
typescriptSuffix: "tsx"
|
|
3801
3936
|
}
|
|
@@ -3803,22 +3938,22 @@ var detectEnvironment = async ({
|
|
|
3803
3938
|
"users-json": await makeGeneratedFile(
|
|
3804
3939
|
"index",
|
|
3805
3940
|
"users-json",
|
|
3806
|
-
|
|
3941
|
+
path10.join(baseDir, "content", "users"),
|
|
3807
3942
|
{ extensionOverride: "json" }
|
|
3808
3943
|
),
|
|
3809
3944
|
"sample-content": await makeGeneratedFile(
|
|
3810
3945
|
"hello-world",
|
|
3811
3946
|
"sample-content",
|
|
3812
|
-
|
|
3947
|
+
path10.join(baseDir, "content", "posts"),
|
|
3813
3948
|
{ extensionOverride: "md" }
|
|
3814
3949
|
)
|
|
3815
3950
|
};
|
|
3816
|
-
const hasSampleContent = await
|
|
3817
|
-
const hasPackageJSON = await
|
|
3951
|
+
const hasSampleContent = await fs9.pathExists(sampleContentPath);
|
|
3952
|
+
const hasPackageJSON = await fs9.pathExists("package.json");
|
|
3818
3953
|
let hasTinaDeps = false;
|
|
3819
3954
|
if (hasPackageJSON) {
|
|
3820
3955
|
try {
|
|
3821
|
-
const packageJSON = await
|
|
3956
|
+
const packageJSON = await fs9.readJSON("package.json");
|
|
3822
3957
|
const deps = [];
|
|
3823
3958
|
if (packageJSON?.dependencies) {
|
|
3824
3959
|
deps.push(...Object.keys(packageJSON.dependencies));
|
|
@@ -3835,15 +3970,15 @@ var detectEnvironment = async ({
|
|
|
3835
3970
|
);
|
|
3836
3971
|
}
|
|
3837
3972
|
}
|
|
3838
|
-
const hasGitIgnore = await
|
|
3973
|
+
const hasGitIgnore = await fs9.pathExists(path10.join(".gitignore"));
|
|
3839
3974
|
const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
|
|
3840
3975
|
const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
|
|
3841
3976
|
const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
|
|
3842
3977
|
let frontMatterFormat;
|
|
3843
3978
|
if (hasForestryConfig) {
|
|
3844
|
-
const hugoConfigPath =
|
|
3845
|
-
if (await
|
|
3846
|
-
const hugoConfig = await
|
|
3979
|
+
const hugoConfigPath = path10.join(rootPath, "config.toml");
|
|
3980
|
+
if (await fs9.pathExists(hugoConfigPath)) {
|
|
3981
|
+
const hugoConfig = await fs9.readFile(hugoConfigPath, "utf8");
|
|
3847
3982
|
const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
|
|
3848
3983
|
if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
|
|
3849
3984
|
frontMatterFormat = metaDataFormat;
|
|
@@ -3874,10 +4009,10 @@ var detectEnvironment = async ({
|
|
|
3874
4009
|
var detectEnvironment_default = detectEnvironment;
|
|
3875
4010
|
|
|
3876
4011
|
// src/cmds/init/prompts/index.ts
|
|
3877
|
-
|
|
4012
|
+
import prompts6 from "prompts";
|
|
3878
4013
|
|
|
3879
4014
|
// src/cmds/init/prompts/askTinaCloudSetup.ts
|
|
3880
|
-
|
|
4015
|
+
import prompts2 from "prompts";
|
|
3881
4016
|
var tinaCloudSetupQuestions = [
|
|
3882
4017
|
{
|
|
3883
4018
|
name: "clientId",
|
|
@@ -3899,7 +4034,7 @@ ${logText(
|
|
|
3899
4034
|
}
|
|
3900
4035
|
];
|
|
3901
4036
|
var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
3902
|
-
const { clientId, token } = await (
|
|
4037
|
+
const { clientId, token } = await prompts2(tinaCloudSetupQuestions);
|
|
3903
4038
|
config2.envVars.push(
|
|
3904
4039
|
{
|
|
3905
4040
|
key: "NEXT_PUBLIC_TINA_CLIENT_ID",
|
|
@@ -3913,7 +4048,7 @@ var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
|
3913
4048
|
};
|
|
3914
4049
|
|
|
3915
4050
|
// src/cmds/init/prompts/gitProvider.ts
|
|
3916
|
-
|
|
4051
|
+
import prompts3 from "prompts";
|
|
3917
4052
|
var supportedGitProviders = {
|
|
3918
4053
|
github: {
|
|
3919
4054
|
imports: [
|
|
@@ -3935,7 +4070,7 @@ var supportedGitProviders = {
|
|
|
3935
4070
|
}
|
|
3936
4071
|
};
|
|
3937
4072
|
var chooseGitProvider = async ({ config: config2 }) => {
|
|
3938
|
-
const result = await (
|
|
4073
|
+
const result = await prompts3([
|
|
3939
4074
|
{
|
|
3940
4075
|
name: "githubToken",
|
|
3941
4076
|
type: "text",
|
|
@@ -3943,7 +4078,7 @@ var chooseGitProvider = async ({ config: config2 }) => {
|
|
|
3943
4078
|
${logText(
|
|
3944
4079
|
"Learn more here: "
|
|
3945
4080
|
)}${linkText(
|
|
3946
|
-
"https://tina.io/docs/self-
|
|
4081
|
+
"https://tina.io/docs/r/self-hosting-nextjs/#github-personal-access-token"
|
|
3947
4082
|
)}`,
|
|
3948
4083
|
initial: process.env.GITHUB_PERSONAL_ACCESS_TOKEN
|
|
3949
4084
|
},
|
|
@@ -3980,7 +4115,7 @@ ${logText(
|
|
|
3980
4115
|
};
|
|
3981
4116
|
|
|
3982
4117
|
// src/cmds/init/prompts/databaseAdapter.ts
|
|
3983
|
-
|
|
4118
|
+
import prompts4 from "prompts";
|
|
3984
4119
|
var supportedDatabaseAdapters = {
|
|
3985
4120
|
["upstash-redis"]: {
|
|
3986
4121
|
databaseAdapterClassText: `new RedisLevel({
|
|
@@ -4026,7 +4161,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4026
4161
|
other: async (_args) => {
|
|
4027
4162
|
},
|
|
4028
4163
|
mongodb: async ({ config: config2 }) => {
|
|
4029
|
-
const result = await (
|
|
4164
|
+
const result = await prompts4([
|
|
4030
4165
|
{
|
|
4031
4166
|
name: "mongoDBUri",
|
|
4032
4167
|
type: "text",
|
|
@@ -4041,7 +4176,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4041
4176
|
});
|
|
4042
4177
|
},
|
|
4043
4178
|
"upstash-redis": async ({ config: config2 }) => {
|
|
4044
|
-
const result = await (
|
|
4179
|
+
const result = await prompts4([
|
|
4045
4180
|
{
|
|
4046
4181
|
name: "kvRestApiUrl",
|
|
4047
4182
|
type: "text",
|
|
@@ -4072,7 +4207,7 @@ var chooseDatabaseAdapter = async ({
|
|
|
4072
4207
|
framework,
|
|
4073
4208
|
config: config2
|
|
4074
4209
|
}) => {
|
|
4075
|
-
const answers = await (
|
|
4210
|
+
const answers = await prompts4([
|
|
4076
4211
|
{
|
|
4077
4212
|
name: "dataLayerAdapter",
|
|
4078
4213
|
message: "Select a self-hosted Database Adapter",
|
|
@@ -4102,8 +4237,8 @@ var chooseDatabaseAdapter = async ({
|
|
|
4102
4237
|
};
|
|
4103
4238
|
|
|
4104
4239
|
// src/cmds/init/prompts/authProvider.ts
|
|
4105
|
-
|
|
4106
|
-
|
|
4240
|
+
import crypto2 from "crypto-js";
|
|
4241
|
+
import prompts5 from "prompts";
|
|
4107
4242
|
var supportedAuthProviders = {
|
|
4108
4243
|
other: {
|
|
4109
4244
|
name: "other"
|
|
@@ -4152,12 +4287,12 @@ var authProviderUpdateConfig = {
|
|
|
4152
4287
|
},
|
|
4153
4288
|
"tina-cloud": askTinaCloudSetup,
|
|
4154
4289
|
"next-auth": async ({ config: config2 }) => {
|
|
4155
|
-
const result = await (
|
|
4290
|
+
const result = await prompts5([
|
|
4156
4291
|
{
|
|
4157
4292
|
name: "nextAuthSecret",
|
|
4158
4293
|
type: "text",
|
|
4159
4294
|
message: `What is the NextAuth.js Secret? (Hit enter to use a randomly generated secret)`,
|
|
4160
|
-
initial: process.env.NEXTAUTH_SECRET ||
|
|
4295
|
+
initial: process.env.NEXTAUTH_SECRET || crypto2.lib.WordArray.random(16).toString()
|
|
4161
4296
|
}
|
|
4162
4297
|
]);
|
|
4163
4298
|
config2.envVars.push({
|
|
@@ -4182,7 +4317,7 @@ var forestryDisclaimer = logText(
|
|
|
4182
4317
|
`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)`
|
|
4183
4318
|
);
|
|
4184
4319
|
var askCommonSetUp = async () => {
|
|
4185
|
-
const answers = await (
|
|
4320
|
+
const answers = await prompts6([
|
|
4186
4321
|
{
|
|
4187
4322
|
name: "framework",
|
|
4188
4323
|
type: "select",
|
|
@@ -4204,7 +4339,8 @@ var askCommonSetUp = async () => {
|
|
|
4204
4339
|
choices: [
|
|
4205
4340
|
{ title: "PNPM", value: "pnpm" },
|
|
4206
4341
|
{ title: "Yarn", value: "yarn" },
|
|
4207
|
-
{ title: "NPM", value: "npm" }
|
|
4342
|
+
{ title: "NPM", value: "npm" },
|
|
4343
|
+
{ title: "Bun", value: "bun" }
|
|
4208
4344
|
]
|
|
4209
4345
|
}
|
|
4210
4346
|
]);
|
|
@@ -4245,7 +4381,7 @@ ${forestryDisclaimer}`
|
|
|
4245
4381
|
message: `What format are you using in your frontmatter?`
|
|
4246
4382
|
});
|
|
4247
4383
|
}
|
|
4248
|
-
const answers = await (
|
|
4384
|
+
const answers = await prompts6(questions);
|
|
4249
4385
|
return answers;
|
|
4250
4386
|
};
|
|
4251
4387
|
var askTinaSetupPrompts = async (params) => {
|
|
@@ -4265,16 +4401,16 @@ var askTinaSetupPrompts = async (params) => {
|
|
|
4265
4401
|
message: `Where are public assets stored? (default: "public")
|
|
4266
4402
|
` + logText(
|
|
4267
4403
|
`Not sure what value to use? Refer to our "Frameworks" doc: ${linkText(
|
|
4268
|
-
"https://tina.io/docs/
|
|
4404
|
+
"https://tina.io/docs/r/framework-guides-overview"
|
|
4269
4405
|
)}`
|
|
4270
4406
|
)
|
|
4271
4407
|
});
|
|
4272
4408
|
}
|
|
4273
|
-
const answers = await (
|
|
4409
|
+
const answers = await prompts6(questions);
|
|
4274
4410
|
return answers;
|
|
4275
4411
|
};
|
|
4276
4412
|
var askIfUsingSelfHosted = async () => {
|
|
4277
|
-
const answers = await (
|
|
4413
|
+
const answers = await prompts6([
|
|
4278
4414
|
{
|
|
4279
4415
|
name: "hosting",
|
|
4280
4416
|
type: "select",
|
|
@@ -4307,20 +4443,20 @@ var makeImportString = (imports) => {
|
|
|
4307
4443
|
};
|
|
4308
4444
|
|
|
4309
4445
|
// src/cmds/init/prompts/generatedFiles.ts
|
|
4310
|
-
|
|
4446
|
+
import prompts7 from "prompts";
|
|
4311
4447
|
var askIfOverride = async ({
|
|
4312
4448
|
generatedFile,
|
|
4313
4449
|
usingTypescript
|
|
4314
4450
|
}) => {
|
|
4315
4451
|
if (usingTypescript) {
|
|
4316
|
-
const result = await (
|
|
4452
|
+
const result = await prompts7({
|
|
4317
4453
|
name: `override`,
|
|
4318
4454
|
type: "confirm",
|
|
4319
4455
|
message: `Found existing file at ${generatedFile.fullPathTS}. Would you like to overwrite?`
|
|
4320
4456
|
});
|
|
4321
4457
|
return Boolean(result.override);
|
|
4322
4458
|
} else {
|
|
4323
|
-
const result = await (
|
|
4459
|
+
const result = await prompts7({
|
|
4324
4460
|
name: `override`,
|
|
4325
4461
|
type: "confirm",
|
|
4326
4462
|
message: `Found existing file at ${generatedFile.fullPathJS}. Would you like to overwrite?`
|
|
@@ -4455,23 +4591,25 @@ var CLICommand = class {
|
|
|
4455
4591
|
};
|
|
4456
4592
|
|
|
4457
4593
|
// src/cmds/init/apply.ts
|
|
4458
|
-
|
|
4594
|
+
import path14 from "path";
|
|
4459
4595
|
|
|
4460
4596
|
// src/cmds/forestry-migrate/index.ts
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4597
|
+
import fs11 from "fs-extra";
|
|
4598
|
+
import path12 from "path";
|
|
4599
|
+
import yaml2 from "js-yaml";
|
|
4600
|
+
import pkg from "minimatch";
|
|
4601
|
+
import { parseFile, stringifyFile } from "@tinacms/graphql";
|
|
4602
|
+
import { CONTENT_FORMATS } from "@tinacms/schema-tools";
|
|
4466
4603
|
|
|
4467
4604
|
// src/cmds/forestry-migrate/util/index.ts
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4605
|
+
import fs10 from "fs-extra";
|
|
4606
|
+
import path11 from "path";
|
|
4607
|
+
import yaml from "js-yaml";
|
|
4608
|
+
import z from "zod";
|
|
4472
4609
|
|
|
4473
4610
|
// src/cmds/forestry-migrate/util/errorSingleton.ts
|
|
4474
4611
|
var ErrorSingleton = class _ErrorSingleton {
|
|
4612
|
+
static instance;
|
|
4475
4613
|
/**
|
|
4476
4614
|
* The Singleton's constructor should always be private to prevent direct
|
|
4477
4615
|
* construction calls with the `new` operator.
|
|
@@ -4491,6 +4629,7 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4491
4629
|
}
|
|
4492
4630
|
return _ErrorSingleton.instance;
|
|
4493
4631
|
}
|
|
4632
|
+
collectionNameErrors;
|
|
4494
4633
|
addErrorName(error) {
|
|
4495
4634
|
this.collectionNameErrors.push(error);
|
|
4496
4635
|
}
|
|
@@ -4513,8 +4652,8 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4513
4652
|
};
|
|
4514
4653
|
|
|
4515
4654
|
// src/cmds/forestry-migrate/util/codeTransformer.ts
|
|
4516
|
-
|
|
4517
|
-
|
|
4655
|
+
import { format } from "prettier";
|
|
4656
|
+
import TsParser from "prettier/parser-typescript.js";
|
|
4518
4657
|
var addVariablesToCode = (codeWithTinaPrefix) => {
|
|
4519
4658
|
const code = codeWithTinaPrefix.replace(
|
|
4520
4659
|
/"__TINA_INTERNAL__:::(.*?):::"/g,
|
|
@@ -4551,7 +4690,7 @@ var makeTemplateFile = async ({
|
|
|
4551
4690
|
`export function ${stringifyLabelWithField(
|
|
4552
4691
|
template.templateObj.label
|
|
4553
4692
|
)} (){
|
|
4554
|
-
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4693
|
+
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4555
4694
|
} `
|
|
4556
4695
|
);
|
|
4557
4696
|
}
|
|
@@ -4559,9 +4698,9 @@ var makeTemplateFile = async ({
|
|
|
4559
4698
|
${usingTypescript ? "import type { TinaField } from 'tinacms'" : ""}
|
|
4560
4699
|
${templateCodeText.join("\n")}
|
|
4561
4700
|
`;
|
|
4562
|
-
const formattedCode =
|
|
4701
|
+
const formattedCode = format(templateCode, {
|
|
4563
4702
|
parser: "typescript",
|
|
4564
|
-
plugins: [
|
|
4703
|
+
plugins: [TsParser]
|
|
4565
4704
|
});
|
|
4566
4705
|
return { importStatements, templateCodeText: formattedCode };
|
|
4567
4706
|
};
|
|
@@ -4593,82 +4732,82 @@ var stringifyTemplateName = (name2, template) => {
|
|
|
4593
4732
|
return newName;
|
|
4594
4733
|
}
|
|
4595
4734
|
};
|
|
4596
|
-
var forestryConfigSchema =
|
|
4597
|
-
sections:
|
|
4598
|
-
|
|
4599
|
-
type:
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4735
|
+
var forestryConfigSchema = z.object({
|
|
4736
|
+
sections: z.array(
|
|
4737
|
+
z.object({
|
|
4738
|
+
type: z.union([
|
|
4739
|
+
z.literal("directory"),
|
|
4740
|
+
z.literal("document"),
|
|
4741
|
+
z.literal("heading"),
|
|
4742
|
+
z.literal("jekyll-pages"),
|
|
4743
|
+
z.literal("jekyll-posts")
|
|
4605
4744
|
]),
|
|
4606
|
-
label:
|
|
4607
|
-
path:
|
|
4608
|
-
match:
|
|
4609
|
-
exclude:
|
|
4610
|
-
create:
|
|
4611
|
-
templates:
|
|
4612
|
-
new_doc_ext:
|
|
4613
|
-
read_only:
|
|
4745
|
+
label: z.string(),
|
|
4746
|
+
path: z.string().optional().nullable(),
|
|
4747
|
+
match: z.string().optional().nullable(),
|
|
4748
|
+
exclude: z.string().optional().nullable(),
|
|
4749
|
+
create: z.union([z.literal("all"), z.literal("documents"), z.literal("none")]).optional(),
|
|
4750
|
+
templates: z.array(z.string()).optional().nullable(),
|
|
4751
|
+
new_doc_ext: z.string().optional().nullable(),
|
|
4752
|
+
read_only: z.boolean().optional().nullable()
|
|
4614
4753
|
})
|
|
4615
4754
|
)
|
|
4616
4755
|
});
|
|
4617
|
-
var forestryFieldWithoutField =
|
|
4756
|
+
var forestryFieldWithoutField = z.object({
|
|
4618
4757
|
// TODO: maybe better type this?
|
|
4619
|
-
type:
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4758
|
+
type: z.union([
|
|
4759
|
+
z.literal("text"),
|
|
4760
|
+
z.literal("datetime"),
|
|
4761
|
+
z.literal("list"),
|
|
4762
|
+
z.literal("file"),
|
|
4763
|
+
z.literal("image_gallery"),
|
|
4764
|
+
z.literal("textarea"),
|
|
4765
|
+
z.literal("tag_list"),
|
|
4766
|
+
z.literal("number"),
|
|
4767
|
+
z.literal("boolean"),
|
|
4768
|
+
z.literal("field_group"),
|
|
4769
|
+
z.literal("field_group_list"),
|
|
4770
|
+
z.literal("select"),
|
|
4771
|
+
z.literal("include"),
|
|
4772
|
+
z.literal("blocks"),
|
|
4773
|
+
z.literal("color")
|
|
4635
4774
|
]),
|
|
4636
|
-
template_types:
|
|
4637
|
-
name:
|
|
4638
|
-
label:
|
|
4639
|
-
default:
|
|
4640
|
-
template:
|
|
4641
|
-
config:
|
|
4775
|
+
template_types: z.array(z.string()).optional().nullable(),
|
|
4776
|
+
name: z.string(),
|
|
4777
|
+
label: z.string(),
|
|
4778
|
+
default: z.any().optional(),
|
|
4779
|
+
template: z.string().optional(),
|
|
4780
|
+
config: z.object({
|
|
4642
4781
|
// 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
|
-
|
|
4782
|
+
min: z.number().optional().nullable(),
|
|
4783
|
+
max: z.number().optional().nullable(),
|
|
4784
|
+
required: z.boolean().optional().nullable(),
|
|
4785
|
+
use_select: z.boolean().optional().nullable(),
|
|
4786
|
+
date_format: z.string().optional().nullable(),
|
|
4787
|
+
time_format: z.string().optional().nullable(),
|
|
4788
|
+
options: z.array(z.string()).optional().nullable(),
|
|
4789
|
+
source: z.object({
|
|
4790
|
+
type: z.union([
|
|
4791
|
+
z.literal("custom"),
|
|
4792
|
+
z.literal("pages"),
|
|
4793
|
+
z.literal("documents"),
|
|
4794
|
+
z.literal("simple"),
|
|
4656
4795
|
// TODO: I want to ignore this key if its invalid
|
|
4657
|
-
|
|
4796
|
+
z.string()
|
|
4658
4797
|
]).optional().nullable(),
|
|
4659
|
-
section:
|
|
4798
|
+
section: z.string().optional().nullable()
|
|
4660
4799
|
}).optional()
|
|
4661
4800
|
}).optional()
|
|
4662
4801
|
});
|
|
4663
|
-
var forestryField =
|
|
4802
|
+
var forestryField = z.lazy(
|
|
4664
4803
|
() => forestryFieldWithoutField.extend({
|
|
4665
|
-
fields:
|
|
4804
|
+
fields: z.array(forestryField).optional()
|
|
4666
4805
|
})
|
|
4667
4806
|
);
|
|
4668
|
-
var FrontmatterTemplateSchema =
|
|
4669
|
-
label:
|
|
4670
|
-
hide_body:
|
|
4671
|
-
fields:
|
|
4807
|
+
var FrontmatterTemplateSchema = z.object({
|
|
4808
|
+
label: z.string(),
|
|
4809
|
+
hide_body: z.boolean().optional(),
|
|
4810
|
+
fields: z.array(forestryField).optional()
|
|
4672
4811
|
});
|
|
4673
4812
|
var transformForestryFieldsToTinaFields = ({
|
|
4674
4813
|
fields,
|
|
@@ -4891,7 +5030,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4891
5030
|
return tinaFields;
|
|
4892
5031
|
};
|
|
4893
5032
|
var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
|
|
4894
|
-
const templatePath =
|
|
5033
|
+
const templatePath = path11.join(
|
|
4895
5034
|
pathToForestryConfig,
|
|
4896
5035
|
".forestry",
|
|
4897
5036
|
"front_matter",
|
|
@@ -4900,7 +5039,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4900
5039
|
);
|
|
4901
5040
|
let templateString = "";
|
|
4902
5041
|
try {
|
|
4903
|
-
templateString =
|
|
5042
|
+
templateString = fs10.readFileSync(templatePath).toString();
|
|
4904
5043
|
} catch {
|
|
4905
5044
|
throw new Error(
|
|
4906
5045
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -4908,7 +5047,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4908
5047
|
This will require manual migration.`
|
|
4909
5048
|
);
|
|
4910
5049
|
}
|
|
4911
|
-
const templateObj =
|
|
5050
|
+
const templateObj = yaml.load(templateString);
|
|
4912
5051
|
const template = parseTemplates({ val: templateObj });
|
|
4913
5052
|
const fields = transformForestryFieldsToTinaFields({
|
|
4914
5053
|
fields: template.fields,
|
|
@@ -4928,6 +5067,7 @@ var parseSections = ({ val }) => {
|
|
|
4928
5067
|
};
|
|
4929
5068
|
|
|
4930
5069
|
// src/cmds/forestry-migrate/index.ts
|
|
5070
|
+
var { minimatch } = pkg;
|
|
4931
5071
|
var BODY_FIELD = {
|
|
4932
5072
|
// This is the body field
|
|
4933
5073
|
type: "rich-text",
|
|
@@ -4956,7 +5096,7 @@ var transformForestryMatchToTinaMatch = (match) => {
|
|
|
4956
5096
|
};
|
|
4957
5097
|
function checkExt(ext) {
|
|
4958
5098
|
const extReal = ext.replace(".", "");
|
|
4959
|
-
if (
|
|
5099
|
+
if (CONTENT_FORMATS.includes(extReal)) {
|
|
4960
5100
|
return extReal;
|
|
4961
5101
|
} else {
|
|
4962
5102
|
return false;
|
|
@@ -4965,9 +5105,9 @@ function checkExt(ext) {
|
|
|
4965
5105
|
var generateAllTemplates = async ({
|
|
4966
5106
|
pathToForestryConfig
|
|
4967
5107
|
}) => {
|
|
4968
|
-
const allTemplates = (await
|
|
4969
|
-
|
|
4970
|
-
)).map((tem) =>
|
|
5108
|
+
const allTemplates = (await fs11.readdir(
|
|
5109
|
+
path12.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
|
|
5110
|
+
)).map((tem) => path12.basename(tem, ".yml"));
|
|
4971
5111
|
const templateMap = /* @__PURE__ */ new Map();
|
|
4972
5112
|
const proms = allTemplates.map(async (tem) => {
|
|
4973
5113
|
try {
|
|
@@ -4977,7 +5117,7 @@ var generateAllTemplates = async ({
|
|
|
4977
5117
|
});
|
|
4978
5118
|
templateMap.set(tem, { fields, templateObj });
|
|
4979
5119
|
} catch (e) {
|
|
4980
|
-
logger.
|
|
5120
|
+
logger.warn(`Error parsing template frontmatter template, ${tem}.yml`);
|
|
4981
5121
|
console.error(e);
|
|
4982
5122
|
templateMap.set(tem, { fields: [], templateObj: {} });
|
|
4983
5123
|
}
|
|
@@ -5021,7 +5161,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5021
5161
|
}
|
|
5022
5162
|
if (section.type === "directory") {
|
|
5023
5163
|
if (!section?.path || section.path === "/" || section.path === "./" || section.path === ".") {
|
|
5024
|
-
logger.
|
|
5164
|
+
logger.warn(
|
|
5025
5165
|
warnText(
|
|
5026
5166
|
`Warning: Section ${section.label} is using a Root Path. Currently, Tina Does not support Root paths see ${linkText(
|
|
5027
5167
|
"https://github.com/tinacms/tinacms/issues/3768"
|
|
@@ -5042,7 +5182,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5042
5182
|
glob = section.path + "/" + section.match;
|
|
5043
5183
|
}
|
|
5044
5184
|
if (pages.some((page) => {
|
|
5045
|
-
return (
|
|
5185
|
+
return minimatch(page, glob);
|
|
5046
5186
|
})) {
|
|
5047
5187
|
forestryTemplates.push(templateKey);
|
|
5048
5188
|
}
|
|
@@ -5112,9 +5252,9 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5112
5252
|
return c;
|
|
5113
5253
|
} else if (section.type === "document") {
|
|
5114
5254
|
const filePath = section.path;
|
|
5115
|
-
const extname =
|
|
5116
|
-
const fileName =
|
|
5117
|
-
const dir =
|
|
5255
|
+
const extname = path12.extname(filePath);
|
|
5256
|
+
const fileName = path12.basename(filePath, extname);
|
|
5257
|
+
const dir = path12.dirname(filePath);
|
|
5118
5258
|
const ext = checkExt(extname);
|
|
5119
5259
|
if (ext) {
|
|
5120
5260
|
const fields = [];
|
|
@@ -5134,7 +5274,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5134
5274
|
name: "dummy",
|
|
5135
5275
|
label: "Dummy field",
|
|
5136
5276
|
type: "string",
|
|
5137
|
-
description: "This is a dummy field, please replace it with the fields you want to edit. See https://tina.io/docs/
|
|
5277
|
+
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"
|
|
5138
5278
|
});
|
|
5139
5279
|
logger.warn(
|
|
5140
5280
|
warnText(
|
|
@@ -5158,7 +5298,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5158
5298
|
fields
|
|
5159
5299
|
};
|
|
5160
5300
|
} else {
|
|
5161
|
-
logger.
|
|
5301
|
+
logger.warn(
|
|
5162
5302
|
warnText(
|
|
5163
5303
|
`Error: document section has an unsupported file extension: ${extname} in ${section.path}`
|
|
5164
5304
|
)
|
|
@@ -5176,8 +5316,8 @@ var generateCollections = async ({
|
|
|
5176
5316
|
templateMap,
|
|
5177
5317
|
usingTypescript
|
|
5178
5318
|
});
|
|
5179
|
-
const forestryConfig = await
|
|
5180
|
-
|
|
5319
|
+
const forestryConfig = await fs11.readFile(
|
|
5320
|
+
path12.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
5181
5321
|
);
|
|
5182
5322
|
rewriteTemplateKeysInDocs({
|
|
5183
5323
|
templateMap,
|
|
@@ -5187,7 +5327,7 @@ var generateCollections = async ({
|
|
|
5187
5327
|
}
|
|
5188
5328
|
});
|
|
5189
5329
|
const collections = parseSections({
|
|
5190
|
-
val:
|
|
5330
|
+
val: yaml2.load(forestryConfig.toString())
|
|
5191
5331
|
}).sections.map(
|
|
5192
5332
|
(section) => generateCollectionFromForestrySection({
|
|
5193
5333
|
section,
|
|
@@ -5207,13 +5347,13 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5207
5347
|
const { templateObj } = templateMap.get(templateKey);
|
|
5208
5348
|
templateObj?.pages?.forEach((page) => {
|
|
5209
5349
|
try {
|
|
5210
|
-
const filePath =
|
|
5211
|
-
if (
|
|
5350
|
+
const filePath = path12.join(page);
|
|
5351
|
+
if (fs11.lstatSync(filePath).isDirectory()) {
|
|
5212
5352
|
return;
|
|
5213
5353
|
}
|
|
5214
|
-
const extname =
|
|
5215
|
-
const fileContent =
|
|
5216
|
-
const content =
|
|
5354
|
+
const extname = path12.extname(filePath);
|
|
5355
|
+
const fileContent = fs11.readFileSync(filePath).toString();
|
|
5356
|
+
const content = parseFile(
|
|
5217
5357
|
fileContent,
|
|
5218
5358
|
extname,
|
|
5219
5359
|
(yup) => yup.object({}),
|
|
@@ -5223,9 +5363,9 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5223
5363
|
_template: stringifyLabel(templateKey),
|
|
5224
5364
|
...content
|
|
5225
5365
|
};
|
|
5226
|
-
|
|
5366
|
+
fs11.writeFileSync(
|
|
5227
5367
|
filePath,
|
|
5228
|
-
|
|
5368
|
+
stringifyFile(newContent, extname, true, markdownParseConfig)
|
|
5229
5369
|
);
|
|
5230
5370
|
} catch (error) {
|
|
5231
5371
|
console.log(
|
|
@@ -5237,32 +5377,25 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5237
5377
|
};
|
|
5238
5378
|
|
|
5239
5379
|
// src/cmds/init/apply.ts
|
|
5240
|
-
|
|
5241
|
-
|
|
5380
|
+
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
5381
|
+
import fs14 from "fs-extra";
|
|
5242
5382
|
|
|
5243
5383
|
// src/next/commands/codemod-command/index.ts
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
var CodemodCommand = class extends
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
}
|
|
5260
|
-
static {
|
|
5261
|
-
this.usage = import_clipanion5.Command.Usage({
|
|
5262
|
-
category: `Commands`,
|
|
5263
|
-
description: `Use codemods for various Tina tasks`
|
|
5264
|
-
});
|
|
5265
|
-
}
|
|
5384
|
+
import { Command as Command5, Option as Option5 } from "clipanion";
|
|
5385
|
+
import fs12 from "fs-extra";
|
|
5386
|
+
import path13 from "path";
|
|
5387
|
+
var CodemodCommand = class extends Command5 {
|
|
5388
|
+
static paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5389
|
+
rootPath = Option5.String("--rootPath", {
|
|
5390
|
+
description: "Specify the root directory to run the CLI from"
|
|
5391
|
+
});
|
|
5392
|
+
verbose = Option5.Boolean("-v,--verbose", false, {
|
|
5393
|
+
description: "increase verbosity of logged output"
|
|
5394
|
+
});
|
|
5395
|
+
static usage = Command5.Usage({
|
|
5396
|
+
category: `Commands`,
|
|
5397
|
+
description: `Use codemods for various Tina tasks`
|
|
5398
|
+
});
|
|
5266
5399
|
async catch(error) {
|
|
5267
5400
|
console.log(error);
|
|
5268
5401
|
}
|
|
@@ -5291,13 +5424,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5291
5424
|
logger.error(e.message);
|
|
5292
5425
|
process.exit(1);
|
|
5293
5426
|
}
|
|
5294
|
-
const tinaDestination =
|
|
5295
|
-
if (await
|
|
5427
|
+
const tinaDestination = path13.join(configManager.rootPath, "tina");
|
|
5428
|
+
if (await fs12.existsSync(tinaDestination)) {
|
|
5296
5429
|
logger.info(
|
|
5297
5430
|
`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.`
|
|
5298
5431
|
);
|
|
5299
5432
|
} else {
|
|
5300
|
-
await
|
|
5433
|
+
await fs12.moveSync(configManager.tinaFolderPath, tinaDestination);
|
|
5301
5434
|
await writeGitignore(configManager.rootPath);
|
|
5302
5435
|
logger.info(
|
|
5303
5436
|
"Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
|
|
@@ -5305,8 +5438,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5305
5438
|
}
|
|
5306
5439
|
};
|
|
5307
5440
|
var writeGitignore = async (rootPath) => {
|
|
5308
|
-
await
|
|
5309
|
-
|
|
5441
|
+
await fs12.outputFileSync(
|
|
5442
|
+
path13.join(rootPath, "tina", ".gitignore"),
|
|
5310
5443
|
"__generated__"
|
|
5311
5444
|
);
|
|
5312
5445
|
};
|
|
@@ -5359,7 +5492,7 @@ const BlogPage = (props) => {
|
|
|
5359
5492
|
<div className='bg-green-100 text-center'>
|
|
5360
5493
|
Lost and looking for a place to start?
|
|
5361
5494
|
<a
|
|
5362
|
-
href='https://tina.io/
|
|
5495
|
+
href='https://tina.io/docs/r/beginner-series'
|
|
5363
5496
|
className='text-blue-500 underline'
|
|
5364
5497
|
>
|
|
5365
5498
|
{' '}
|
|
@@ -5641,7 +5774,7 @@ import { LocalAuthProvider } from "tinacms";`;
|
|
|
5641
5774
|
publicFolder: "${args.publicFolder}",
|
|
5642
5775
|
},
|
|
5643
5776
|
},
|
|
5644
|
-
// See docs on content modeling for more info on how to setup new content models: https://tina.io/docs/
|
|
5777
|
+
// See docs on content modeling for more info on how to setup new content models: https://tina.io/docs/r/content-modelling-collections/
|
|
5645
5778
|
schema: {
|
|
5646
5779
|
collections: ${generateCollectionString(args)},
|
|
5647
5780
|
},
|
|
@@ -5714,7 +5847,7 @@ Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a
|
|
|
5714
5847
|
`;
|
|
5715
5848
|
|
|
5716
5849
|
// src/cmds/init/apply.ts
|
|
5717
|
-
|
|
5850
|
+
import { format as format2 } from "prettier";
|
|
5718
5851
|
|
|
5719
5852
|
// src/utils/script-helpers.ts
|
|
5720
5853
|
function generateGqlScript(scriptValue, opts) {
|
|
@@ -5737,38 +5870,38 @@ function extendNextScripts(scripts, opts) {
|
|
|
5737
5870
|
}
|
|
5738
5871
|
|
|
5739
5872
|
// src/cmds/init/codegen/index.ts
|
|
5740
|
-
|
|
5741
|
-
|
|
5873
|
+
import ts2 from "typescript";
|
|
5874
|
+
import fs13 from "fs-extra";
|
|
5742
5875
|
|
|
5743
5876
|
// src/cmds/init/codegen/util.ts
|
|
5744
|
-
|
|
5745
|
-
var makeTransformer = (makeVisitor) => (ctx) => (node) =>
|
|
5877
|
+
import ts from "typescript";
|
|
5878
|
+
var makeTransformer = (makeVisitor) => (ctx) => (node) => ts.visitNode(node, makeVisitor(ctx));
|
|
5746
5879
|
function parseExpression(expression) {
|
|
5747
|
-
const sourceFile =
|
|
5880
|
+
const sourceFile = ts.createSourceFile(
|
|
5748
5881
|
"temp.ts",
|
|
5749
5882
|
expression,
|
|
5750
|
-
|
|
5883
|
+
ts.ScriptTarget.Latest
|
|
5751
5884
|
);
|
|
5752
5885
|
if (sourceFile.statements.length !== 1) {
|
|
5753
5886
|
throw new Error("Expected one statement");
|
|
5754
5887
|
}
|
|
5755
5888
|
const statement = sourceFile.statements[0];
|
|
5756
|
-
if (!
|
|
5889
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
5757
5890
|
throw new Error("Expected an expression statement");
|
|
5758
5891
|
}
|
|
5759
5892
|
return [sourceFile, statement.expression];
|
|
5760
5893
|
}
|
|
5761
5894
|
function parseVariableStatement(stmt) {
|
|
5762
|
-
const sourceFile =
|
|
5895
|
+
const sourceFile = ts.createSourceFile(
|
|
5763
5896
|
"temp.ts",
|
|
5764
5897
|
stmt,
|
|
5765
|
-
|
|
5898
|
+
ts.ScriptTarget.Latest
|
|
5766
5899
|
);
|
|
5767
5900
|
if (sourceFile.statements.length !== 1) {
|
|
5768
5901
|
throw new Error("Expected one statement");
|
|
5769
5902
|
}
|
|
5770
5903
|
const statement = sourceFile.statements[0];
|
|
5771
|
-
if (!
|
|
5904
|
+
if (!ts.isVariableStatement(statement)) {
|
|
5772
5905
|
throw new Error("Expected a variable statement");
|
|
5773
5906
|
}
|
|
5774
5907
|
return [sourceFile, statement];
|
|
@@ -5776,7 +5909,7 @@ function parseVariableStatement(stmt) {
|
|
|
5776
5909
|
|
|
5777
5910
|
// src/cmds/init/codegen/index.ts
|
|
5778
5911
|
var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variableStmt) => (ctx) => (node) => {
|
|
5779
|
-
if (
|
|
5912
|
+
if (ts2.isSourceFile(node)) {
|
|
5780
5913
|
const newStatements = [...node.statements];
|
|
5781
5914
|
let encounteredImports = false;
|
|
5782
5915
|
let firstNonImportStatementIdx = -1;
|
|
@@ -5784,7 +5917,7 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5784
5917
|
const [newVarDec] = variableStmt.declarationList.declarations;
|
|
5785
5918
|
const newVarDecName = newVarDec.name.getText(variableStmtSourceFile);
|
|
5786
5919
|
for (let i = 0; i < newStatements.length; i++) {
|
|
5787
|
-
const isImport =
|
|
5920
|
+
const isImport = ts2.isImportDeclaration(newStatements[i]);
|
|
5788
5921
|
if (isImport && !encounteredImports) {
|
|
5789
5922
|
encounteredImports = true;
|
|
5790
5923
|
}
|
|
@@ -5792,9 +5925,9 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5792
5925
|
firstNonImportStatementIdx = i;
|
|
5793
5926
|
}
|
|
5794
5927
|
const stmt = newStatements[i];
|
|
5795
|
-
if (
|
|
5928
|
+
if (ts2.isVariableStatement(stmt)) {
|
|
5796
5929
|
const [dec] = stmt.declarationList.declarations;
|
|
5797
|
-
if (dec.name &&
|
|
5930
|
+
if (dec.name && ts2.isIdentifier(dec.name) && dec.name.getText(sourceFile) === newVarDecName) {
|
|
5798
5931
|
existingStatementIdx = i;
|
|
5799
5932
|
}
|
|
5800
5933
|
}
|
|
@@ -5808,19 +5941,19 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5808
5941
|
if (existingStatementIdx === -1) {
|
|
5809
5942
|
newStatements.splice(firstNonImportStatementIdx, 0, variableStmt);
|
|
5810
5943
|
}
|
|
5811
|
-
return
|
|
5944
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5812
5945
|
}
|
|
5813
5946
|
};
|
|
5814
5947
|
var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
5815
|
-
if (
|
|
5948
|
+
if (ts2.isSourceFile(node)) {
|
|
5816
5949
|
const newStatements = [...node.statements];
|
|
5817
5950
|
let changed = false;
|
|
5818
5951
|
for (const [moduleName, imports] of Object.entries(importMap)) {
|
|
5819
5952
|
let foundImportStatement = false;
|
|
5820
5953
|
for (const statement of newStatements) {
|
|
5821
|
-
if (
|
|
5954
|
+
if (ts2.isImportDeclaration(statement) && ts2.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === moduleName) {
|
|
5822
5955
|
foundImportStatement = true;
|
|
5823
|
-
const existingImports = statement.importClause?.namedBindings &&
|
|
5956
|
+
const existingImports = statement.importClause?.namedBindings && ts2.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements.map(
|
|
5824
5957
|
(e) => e.name.text
|
|
5825
5958
|
) : [];
|
|
5826
5959
|
const newImports = [
|
|
@@ -5831,22 +5964,22 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5831
5964
|
])
|
|
5832
5965
|
];
|
|
5833
5966
|
const importSpecifiers = newImports.map(
|
|
5834
|
-
(i) =>
|
|
5967
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5835
5968
|
void 0,
|
|
5836
|
-
|
|
5837
|
-
|
|
5969
|
+
ts2.factory.createIdentifier(i),
|
|
5970
|
+
ts2.factory.createIdentifier(i)
|
|
5838
5971
|
)
|
|
5839
5972
|
);
|
|
5840
|
-
const namedImports =
|
|
5841
|
-
const importClause =
|
|
5973
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5974
|
+
const importClause = ts2.factory.createImportClause(
|
|
5842
5975
|
false,
|
|
5843
5976
|
void 0,
|
|
5844
5977
|
namedImports
|
|
5845
5978
|
);
|
|
5846
|
-
const importDec =
|
|
5979
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5847
5980
|
void 0,
|
|
5848
5981
|
importClause,
|
|
5849
|
-
|
|
5982
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5850
5983
|
);
|
|
5851
5984
|
newStatements[newStatements.indexOf(statement)] = importDec;
|
|
5852
5985
|
changed = true;
|
|
@@ -5854,45 +5987,45 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5854
5987
|
}
|
|
5855
5988
|
if (!foundImportStatement) {
|
|
5856
5989
|
const importSpecifiers = imports.map(
|
|
5857
|
-
(i) =>
|
|
5990
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5858
5991
|
void 0,
|
|
5859
|
-
|
|
5860
|
-
|
|
5992
|
+
ts2.factory.createIdentifier(i),
|
|
5993
|
+
ts2.factory.createIdentifier(i)
|
|
5861
5994
|
)
|
|
5862
5995
|
);
|
|
5863
|
-
const namedImports =
|
|
5864
|
-
const importClause =
|
|
5996
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5997
|
+
const importClause = ts2.factory.createImportClause(
|
|
5865
5998
|
false,
|
|
5866
5999
|
void 0,
|
|
5867
6000
|
namedImports
|
|
5868
6001
|
);
|
|
5869
|
-
const importDec =
|
|
6002
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5870
6003
|
void 0,
|
|
5871
6004
|
importClause,
|
|
5872
|
-
|
|
6005
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5873
6006
|
);
|
|
5874
6007
|
newStatements.unshift(importDec);
|
|
5875
6008
|
changed = true;
|
|
5876
6009
|
}
|
|
5877
6010
|
}
|
|
5878
6011
|
if (changed) {
|
|
5879
|
-
return
|
|
6012
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5880
6013
|
}
|
|
5881
6014
|
}
|
|
5882
6015
|
};
|
|
5883
6016
|
var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newExpressionSourceFile, newExpression) => (ctx) => {
|
|
5884
6017
|
const visit2 = (node) => {
|
|
5885
|
-
if (
|
|
6018
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5886
6019
|
const configObject = node.arguments[0];
|
|
5887
6020
|
const updateProperties = configObject.properties.map((property) => {
|
|
5888
|
-
if (
|
|
6021
|
+
if (ts2.isPropertyAssignment(property)) {
|
|
5889
6022
|
const thisPropertyName = property.name.getText(sourceFile);
|
|
5890
|
-
if (thisPropertyName === "schema" &&
|
|
6023
|
+
if (thisPropertyName === "schema" && ts2.isPropertyAssignment(property) && ts2.isObjectLiteralExpression(property.initializer)) {
|
|
5891
6024
|
const schemaObject = property.initializer;
|
|
5892
6025
|
const collectionsProperty = schemaObject.properties.find(
|
|
5893
|
-
(p) =>
|
|
6026
|
+
(p) => ts2.isPropertyAssignment(p) && p.name.getText(sourceFile) === "collections"
|
|
5894
6027
|
);
|
|
5895
|
-
if (collectionsProperty &&
|
|
6028
|
+
if (collectionsProperty && ts2.isPropertyAssignment(collectionsProperty) && ts2.isArrayLiteralExpression(collectionsProperty.initializer)) {
|
|
5896
6029
|
const collectionsArray = collectionsProperty.initializer;
|
|
5897
6030
|
const collectionItems = collectionsArray.elements.map(
|
|
5898
6031
|
(e) => e.getText(sourceFile)
|
|
@@ -5902,16 +6035,16 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5902
6035
|
)) {
|
|
5903
6036
|
return property;
|
|
5904
6037
|
}
|
|
5905
|
-
return
|
|
6038
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5906
6039
|
property,
|
|
5907
6040
|
property.name,
|
|
5908
|
-
|
|
6041
|
+
ts2.factory.createObjectLiteralExpression(
|
|
5909
6042
|
schemaObject.properties.map((subProp) => {
|
|
5910
|
-
if (
|
|
5911
|
-
return
|
|
6043
|
+
if (ts2.isPropertyAssignment(subProp) && subProp.name.getText(sourceFile) === "collections" && ts2.isArrayLiteralExpression(subProp.initializer)) {
|
|
6044
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5912
6045
|
subProp,
|
|
5913
6046
|
subProp.name,
|
|
5914
|
-
|
|
6047
|
+
ts2.factory.createArrayLiteralExpression(
|
|
5915
6048
|
[newExpression, ...subProp.initializer.elements],
|
|
5916
6049
|
true
|
|
5917
6050
|
)
|
|
@@ -5927,56 +6060,56 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5927
6060
|
}
|
|
5928
6061
|
return property;
|
|
5929
6062
|
});
|
|
5930
|
-
return
|
|
6063
|
+
return ts2.factory.createCallExpression(
|
|
5931
6064
|
node.expression,
|
|
5932
6065
|
node.typeArguments,
|
|
5933
|
-
[
|
|
6066
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
5934
6067
|
);
|
|
5935
6068
|
}
|
|
5936
|
-
return
|
|
6069
|
+
return ts2.visitEachChild(node, visit2, ctx);
|
|
5937
6070
|
};
|
|
5938
6071
|
return (sourceFile2) => {
|
|
5939
|
-
return
|
|
6072
|
+
return ts2.visitEachChild(sourceFile2, visit2, ctx);
|
|
5940
6073
|
};
|
|
5941
6074
|
};
|
|
5942
6075
|
var makeUpdateObjectLiteralPropertyVisitor = (sourceFile, functionName, propertyName, propertyValueExpressionSourceFile, propertyValue) => (ctx) => {
|
|
5943
6076
|
const visitor = (node) => {
|
|
5944
|
-
if (
|
|
6077
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5945
6078
|
let foundProperty = false;
|
|
5946
6079
|
const configObject = node.arguments[0];
|
|
5947
6080
|
const updateProperties = configObject.properties.map((property) => {
|
|
5948
|
-
if (
|
|
6081
|
+
if (ts2.isPropertyAssignment(property) || ts2.isShorthandPropertyAssignment(property)) {
|
|
5949
6082
|
const name2 = property.name.getText(sourceFile);
|
|
5950
6083
|
if (name2 === propertyName) {
|
|
5951
6084
|
foundProperty = true;
|
|
5952
|
-
return
|
|
6085
|
+
return ts2.factory.createPropertyAssignment(name2, propertyValue);
|
|
5953
6086
|
}
|
|
5954
6087
|
}
|
|
5955
6088
|
return property;
|
|
5956
6089
|
});
|
|
5957
6090
|
if (!foundProperty) {
|
|
5958
6091
|
updateProperties.unshift(
|
|
5959
|
-
|
|
6092
|
+
ts2.factory.createPropertyAssignment(propertyName, propertyValue)
|
|
5960
6093
|
);
|
|
5961
6094
|
}
|
|
5962
|
-
return
|
|
6095
|
+
return ts2.factory.createCallExpression(
|
|
5963
6096
|
node.expression,
|
|
5964
6097
|
node.typeArguments,
|
|
5965
|
-
[
|
|
6098
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
5966
6099
|
);
|
|
5967
6100
|
}
|
|
5968
|
-
return
|
|
6101
|
+
return ts2.visitEachChild(node, visitor, ctx);
|
|
5969
6102
|
};
|
|
5970
6103
|
return (sourceFile2) => {
|
|
5971
|
-
return
|
|
6104
|
+
return ts2.visitNode(sourceFile2, visitor);
|
|
5972
6105
|
};
|
|
5973
6106
|
};
|
|
5974
6107
|
var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
5975
6108
|
const pathToConfig = configFile.resolve(config2.typescript).path;
|
|
5976
|
-
const sourceFile =
|
|
6109
|
+
const sourceFile = ts2.createSourceFile(
|
|
5977
6110
|
pathToConfig,
|
|
5978
|
-
|
|
5979
|
-
config2.typescript ?
|
|
6111
|
+
fs13.readFileSync(pathToConfig, "utf8"),
|
|
6112
|
+
config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
|
|
5980
6113
|
);
|
|
5981
6114
|
const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
|
|
5982
6115
|
const importMap = {
|
|
@@ -5989,7 +6122,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
5989
6122
|
{}
|
|
5990
6123
|
)
|
|
5991
6124
|
};
|
|
5992
|
-
const transformedSourceFileResult =
|
|
6125
|
+
const transformedSourceFileResult = ts2.transform(
|
|
5993
6126
|
sourceFile,
|
|
5994
6127
|
[
|
|
5995
6128
|
makeImportsVisitor(sourceFile, {
|
|
@@ -6025,13 +6158,14 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6025
6158
|
)
|
|
6026
6159
|
].map((visitor) => makeTransformer(visitor))
|
|
6027
6160
|
);
|
|
6028
|
-
return
|
|
6161
|
+
return fs13.writeFile(
|
|
6029
6162
|
pathToConfig,
|
|
6030
|
-
|
|
6163
|
+
ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
|
|
6031
6164
|
);
|
|
6032
6165
|
};
|
|
6033
6166
|
|
|
6034
6167
|
// src/cmds/init/apply.ts
|
|
6168
|
+
import { exec } from "child_process";
|
|
6035
6169
|
async function apply({
|
|
6036
6170
|
env,
|
|
6037
6171
|
params,
|
|
@@ -6142,8 +6276,8 @@ async function apply({
|
|
|
6142
6276
|
await addConfigFile({
|
|
6143
6277
|
configArgs: {
|
|
6144
6278
|
config: config2,
|
|
6145
|
-
publicFolder:
|
|
6146
|
-
|
|
6279
|
+
publicFolder: path14.join(
|
|
6280
|
+
path14.relative(process.cwd(), pathToForestryConfig),
|
|
6147
6281
|
config2.publicFolder
|
|
6148
6282
|
),
|
|
6149
6283
|
collections,
|
|
@@ -6200,7 +6334,7 @@ var reportTelemetry = async ({
|
|
|
6200
6334
|
if (noTelemetry) {
|
|
6201
6335
|
logger.info(logText("Telemetry disabled"));
|
|
6202
6336
|
}
|
|
6203
|
-
const telemetry = new
|
|
6337
|
+
const telemetry = new Telemetry2({ disabled: noTelemetry });
|
|
6204
6338
|
const schemaFileType = usingTypescript ? "ts" : "js";
|
|
6205
6339
|
await telemetry.submitRecord({
|
|
6206
6340
|
event: {
|
|
@@ -6216,18 +6350,18 @@ var createPackageJSON = async () => {
|
|
|
6216
6350
|
};
|
|
6217
6351
|
var createGitignore = async ({ baseDir }) => {
|
|
6218
6352
|
logger.info(logText("No .gitignore found, creating one"));
|
|
6219
|
-
|
|
6353
|
+
fs14.outputFileSync(path14.join(baseDir, ".gitignore"), "node_modules");
|
|
6220
6354
|
};
|
|
6221
6355
|
var updateGitIgnore = async ({
|
|
6222
6356
|
baseDir,
|
|
6223
6357
|
items
|
|
6224
6358
|
}) => {
|
|
6225
6359
|
logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
|
|
6226
|
-
const gitignoreContent =
|
|
6360
|
+
const gitignoreContent = fs14.readFileSync(path14.join(baseDir, ".gitignore")).toString();
|
|
6227
6361
|
const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
|
|
6228
6362
|
"\n"
|
|
6229
6363
|
);
|
|
6230
|
-
await
|
|
6364
|
+
await fs14.writeFile(path14.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
6231
6365
|
};
|
|
6232
6366
|
var addDependencies = async (config2, env, params) => {
|
|
6233
6367
|
const { packageManager } = config2;
|
|
@@ -6268,7 +6402,8 @@ var addDependencies = async (config2, env, params) => {
|
|
|
6268
6402
|
let packageManagers = {
|
|
6269
6403
|
pnpm: process.env.USE_WORKSPACE ? `pnpm add ${deps.join(" ")} --workspace` : `pnpm add ${deps.join(" ")}`,
|
|
6270
6404
|
npm: `npm install ${deps.join(" ")}`,
|
|
6271
|
-
yarn: `yarn add ${deps.join(" ")}
|
|
6405
|
+
yarn: `yarn add ${deps.join(" ")}`,
|
|
6406
|
+
bun: `bun add ${deps.join(" ")}`
|
|
6272
6407
|
};
|
|
6273
6408
|
if (packageManagers[packageManager] && deps.length > 0) {
|
|
6274
6409
|
logger.info(logText("Adding dependencies, this might take a moment..."));
|
|
@@ -6279,7 +6414,8 @@ var addDependencies = async (config2, env, params) => {
|
|
|
6279
6414
|
packageManagers = {
|
|
6280
6415
|
pnpm: process.env.USE_WORKSPACE ? `pnpm add -D ${devDeps.join(" ")} --workspace` : `pnpm add -D ${devDeps.join(" ")}`,
|
|
6281
6416
|
npm: `npm install -D ${devDeps.join(" ")}`,
|
|
6282
|
-
yarn: `yarn add -D ${devDeps.join(" ")}
|
|
6417
|
+
yarn: `yarn add -D ${devDeps.join(" ")}`,
|
|
6418
|
+
bun: `bun add -D ${devDeps.join(" ")}`
|
|
6283
6419
|
};
|
|
6284
6420
|
if (packageManagers[packageManager]) {
|
|
6285
6421
|
logger.info(
|
|
@@ -6296,22 +6432,22 @@ var writeGeneratedFile = async ({
|
|
|
6296
6432
|
content,
|
|
6297
6433
|
typescript
|
|
6298
6434
|
}) => {
|
|
6299
|
-
const { exists, path:
|
|
6435
|
+
const { exists, path: path15, parentPath } = generatedFile.resolve(typescript);
|
|
6300
6436
|
if (exists) {
|
|
6301
6437
|
if (overwrite) {
|
|
6302
|
-
logger.info(`Overwriting file at ${
|
|
6303
|
-
|
|
6438
|
+
logger.info(`Overwriting file at ${path15}... \u2705`);
|
|
6439
|
+
fs14.outputFileSync(path15, content);
|
|
6304
6440
|
} else {
|
|
6305
|
-
logger.info(`Not overwriting file at ${
|
|
6441
|
+
logger.info(`Not overwriting file at ${path15}.`);
|
|
6306
6442
|
logger.info(
|
|
6307
|
-
logText(`Please add the following to ${
|
|
6443
|
+
logText(`Please add the following to ${path15}:
|
|
6308
6444
|
${indentText(content)}}`)
|
|
6309
6445
|
);
|
|
6310
6446
|
}
|
|
6311
6447
|
} else {
|
|
6312
|
-
logger.info(`Adding file at ${
|
|
6313
|
-
await
|
|
6314
|
-
|
|
6448
|
+
logger.info(`Adding file at ${path15}... \u2705`);
|
|
6449
|
+
await fs14.ensureDir(parentPath);
|
|
6450
|
+
fs14.outputFileSync(path15, content);
|
|
6315
6451
|
}
|
|
6316
6452
|
};
|
|
6317
6453
|
var addConfigFile = async ({
|
|
@@ -6320,7 +6456,7 @@ var addConfigFile = async ({
|
|
|
6320
6456
|
generatedFile,
|
|
6321
6457
|
config: config2
|
|
6322
6458
|
}) => {
|
|
6323
|
-
const content = (
|
|
6459
|
+
const content = format2(generateConfig(configArgs), {
|
|
6324
6460
|
parser: "babel"
|
|
6325
6461
|
});
|
|
6326
6462
|
await writeGeneratedFile({
|
|
@@ -6350,7 +6486,7 @@ var addNextApiRoute = async ({
|
|
|
6350
6486
|
generatedFile,
|
|
6351
6487
|
env
|
|
6352
6488
|
}) => {
|
|
6353
|
-
const content = (
|
|
6489
|
+
const content = format2(nextApiRouteTemplate({ config: config2, env }), {
|
|
6354
6490
|
parser: "babel"
|
|
6355
6491
|
});
|
|
6356
6492
|
await writeGeneratedFile({
|
|
@@ -6389,7 +6525,7 @@ var addContentFile = async ({
|
|
|
6389
6525
|
return () => ({
|
|
6390
6526
|
exists: env.sampleContentExists,
|
|
6391
6527
|
path: env.sampleContentPath,
|
|
6392
|
-
parentPath:
|
|
6528
|
+
parentPath: path14.dirname(env.sampleContentPath)
|
|
6393
6529
|
});
|
|
6394
6530
|
}
|
|
6395
6531
|
},
|
|
@@ -6412,10 +6548,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
|
|
|
6412
6548
|
return `${x.key}=${x.value || "***"}`;
|
|
6413
6549
|
}).join("\n") + `
|
|
6414
6550
|
TINA_PUBLIC_IS_LOCAL=true`;
|
|
6415
|
-
const envFile =
|
|
6416
|
-
if (!
|
|
6551
|
+
const envFile = path14.join(process.cwd(), ".env");
|
|
6552
|
+
if (!fs14.existsSync(envFile)) {
|
|
6417
6553
|
logger.info(`Adding .env file to your project... \u2705`);
|
|
6418
|
-
|
|
6554
|
+
fs14.writeFileSync(envFile, envFileText);
|
|
6419
6555
|
} else {
|
|
6420
6556
|
logger.info(
|
|
6421
6557
|
"Please add the following environment variables to your .env file"
|
|
@@ -6437,9 +6573,7 @@ ${titleText(" TinaCMS ")} has been initialized!`));
|
|
|
6437
6573
|
);
|
|
6438
6574
|
if (framework.name === "hugo") {
|
|
6439
6575
|
logger.info(
|
|
6440
|
-
focusText("Hugo is required. ")
|
|
6441
|
-
"Don't have Hugo installed? Follow this guide to set it up: ",
|
|
6442
|
-
linkText("https://gohugo.io/installation/")
|
|
6576
|
+
focusText("Hugo is required. ") + "Don't have Hugo installed? Follow this guide to set it up: " + linkText("https://gohugo.io/installation/")
|
|
6443
6577
|
);
|
|
6444
6578
|
}
|
|
6445
6579
|
logger.info(
|
|
@@ -6458,7 +6592,8 @@ var other = ({ packageManager }) => {
|
|
|
6458
6592
|
pnpm: `pnpm`,
|
|
6459
6593
|
npm: `npx`,
|
|
6460
6594
|
// npx is the way to run executables that aren't in your "scripts"
|
|
6461
|
-
yarn: `yarn
|
|
6595
|
+
yarn: `yarn`,
|
|
6596
|
+
bun: `bun run`
|
|
6462
6597
|
};
|
|
6463
6598
|
return `${packageManagers[packageManager]} tinacms dev -c "<your dev command>"`;
|
|
6464
6599
|
};
|
|
@@ -6471,7 +6606,8 @@ var frameworkDevCmds = {
|
|
|
6471
6606
|
pnpm: `pnpm`,
|
|
6472
6607
|
npm: `npm run`,
|
|
6473
6608
|
// npx is the way to run executables that aren't in your "scripts"
|
|
6474
|
-
yarn: `yarn
|
|
6609
|
+
yarn: `yarn`,
|
|
6610
|
+
bun: `bun run`
|
|
6475
6611
|
};
|
|
6476
6612
|
return `${packageManagers[packageManager]} dev`;
|
|
6477
6613
|
}
|
|
@@ -6484,7 +6620,7 @@ var addReactiveFile = {
|
|
|
6484
6620
|
baseDir,
|
|
6485
6621
|
dataLayer
|
|
6486
6622
|
}) => {
|
|
6487
|
-
const packageJsonPath =
|
|
6623
|
+
const packageJsonPath = path14.join(baseDir, "package.json");
|
|
6488
6624
|
await writeGeneratedFile({
|
|
6489
6625
|
generatedFile,
|
|
6490
6626
|
typescript: config2.typescript,
|
|
@@ -6497,7 +6633,7 @@ var addReactiveFile = {
|
|
|
6497
6633
|
})
|
|
6498
6634
|
});
|
|
6499
6635
|
logger.info("Adding a nextjs example... \u2705");
|
|
6500
|
-
const packageJson = JSON.parse(
|
|
6636
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath).toString());
|
|
6501
6637
|
const scripts = packageJson.scripts || {};
|
|
6502
6638
|
const updatedPackageJson = JSON.stringify(
|
|
6503
6639
|
{
|
|
@@ -6510,11 +6646,10 @@ var addReactiveFile = {
|
|
|
6510
6646
|
null,
|
|
6511
6647
|
2
|
|
6512
6648
|
);
|
|
6513
|
-
|
|
6649
|
+
fs14.writeFileSync(packageJsonPath, updatedPackageJson);
|
|
6514
6650
|
}
|
|
6515
6651
|
};
|
|
6516
6652
|
function execShellCommand(cmd) {
|
|
6517
|
-
const exec = require("child_process").exec;
|
|
6518
6653
|
return new Promise((resolve2, reject) => {
|
|
6519
6654
|
exec(cmd, (error, stdout, stderr) => {
|
|
6520
6655
|
if (error) {
|
|
@@ -6560,34 +6695,27 @@ var command = new CLICommand({
|
|
|
6560
6695
|
});
|
|
6561
6696
|
|
|
6562
6697
|
// src/next/commands/init-command/index.ts
|
|
6563
|
-
var InitCommand = class extends
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
}
|
|
6585
|
-
static {
|
|
6586
|
-
this.usage = import_clipanion6.Command.Usage({
|
|
6587
|
-
category: `Commands`,
|
|
6588
|
-
description: `Add Tina to an existing project`
|
|
6589
|
-
});
|
|
6590
|
-
}
|
|
6698
|
+
var InitCommand = class extends Command6 {
|
|
6699
|
+
static paths = [["init"], ["init", "backend"]];
|
|
6700
|
+
pathToForestryConfig = Option6.String("--forestryPath", {
|
|
6701
|
+
description: "Specify the relative path to the .forestry directory, if importing an existing forestry site."
|
|
6702
|
+
});
|
|
6703
|
+
rootPath = Option6.String("--rootPath", {
|
|
6704
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6705
|
+
});
|
|
6706
|
+
debug = Option6.Boolean("--debug", false, {
|
|
6707
|
+
description: "Enable debug logging"
|
|
6708
|
+
});
|
|
6709
|
+
noTelemetry = Option6.Boolean("--noTelemetry", false, {
|
|
6710
|
+
description: "Disable anonymous telemetry that is collected"
|
|
6711
|
+
});
|
|
6712
|
+
tinaVersion = Option6.String("--tinaVersion", {
|
|
6713
|
+
description: "Specify a version for tina dependencies"
|
|
6714
|
+
});
|
|
6715
|
+
static usage = Command6.Usage({
|
|
6716
|
+
category: `Commands`,
|
|
6717
|
+
description: `Add Tina to an existing project`
|
|
6718
|
+
});
|
|
6591
6719
|
async catch(error) {
|
|
6592
6720
|
logger.error("Error occured during tinacms init");
|
|
6593
6721
|
console.error(error);
|
|
@@ -6609,28 +6737,24 @@ var InitCommand = class extends import_clipanion6.Command {
|
|
|
6609
6737
|
};
|
|
6610
6738
|
|
|
6611
6739
|
// src/next/commands/searchindex-command/index.ts
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
category: `Commands`,
|
|
6631
|
-
description: `Index the site for search`
|
|
6632
|
-
});
|
|
6633
|
-
}
|
|
6740
|
+
import { Command as Command7, Option as Option7 } from "clipanion";
|
|
6741
|
+
import { createSchema, FilesystemBridge as FilesystemBridge4 } from "@tinacms/graphql";
|
|
6742
|
+
import {
|
|
6743
|
+
SearchIndexer as SearchIndexer3,
|
|
6744
|
+
TinaCMSSearchIndexClient as TinaCMSSearchIndexClient2
|
|
6745
|
+
} from "@tinacms/search";
|
|
6746
|
+
var SearchIndexCommand = class extends Command7 {
|
|
6747
|
+
static paths = [["search-index"]];
|
|
6748
|
+
rootPath = Option7.String("--rootPath", {
|
|
6749
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6750
|
+
});
|
|
6751
|
+
verbose = Option7.Boolean("-v,--verbose", false, {
|
|
6752
|
+
description: "increase verbosity of logged output"
|
|
6753
|
+
});
|
|
6754
|
+
static usage = Command7.Usage({
|
|
6755
|
+
category: `Commands`,
|
|
6756
|
+
description: `Index the site for search`
|
|
6757
|
+
});
|
|
6634
6758
|
async catch(error) {
|
|
6635
6759
|
logger.error("Error occured during tinacms search-index");
|
|
6636
6760
|
console.error(error);
|
|
@@ -6652,7 +6776,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6652
6776
|
process.exit(1);
|
|
6653
6777
|
}
|
|
6654
6778
|
const { schema } = configManager.config;
|
|
6655
|
-
const tinaSchema = await
|
|
6779
|
+
const tinaSchema = await createSchema({
|
|
6656
6780
|
schema: { ...schema, config: configManager.config }
|
|
6657
6781
|
});
|
|
6658
6782
|
let client;
|
|
@@ -6680,7 +6804,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6680
6804
|
"indexerToken not configured in tina search configuration."
|
|
6681
6805
|
);
|
|
6682
6806
|
}
|
|
6683
|
-
client = new
|
|
6807
|
+
client = new TinaCMSSearchIndexClient2({
|
|
6684
6808
|
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
6685
6809
|
branch: configManager.config?.branch,
|
|
6686
6810
|
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
@@ -6689,9 +6813,9 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6689
6813
|
} else {
|
|
6690
6814
|
client = configManager.config?.search?.searchClient;
|
|
6691
6815
|
}
|
|
6692
|
-
const searchIndexer = new
|
|
6816
|
+
const searchIndexer = new SearchIndexer3({
|
|
6693
6817
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
6694
|
-
bridge: new
|
|
6818
|
+
bridge: new FilesystemBridge4(
|
|
6695
6819
|
configManager.rootPath,
|
|
6696
6820
|
configManager.contentRootPath
|
|
6697
6821
|
),
|
|
@@ -6719,7 +6843,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6719
6843
|
};
|
|
6720
6844
|
|
|
6721
6845
|
// src/index.ts
|
|
6722
|
-
var cli = new
|
|
6846
|
+
var cli = new Cli({
|
|
6723
6847
|
binaryName: `tinacms`,
|
|
6724
6848
|
binaryLabel: `TinaCMS`,
|
|
6725
6849
|
binaryVersion: version
|
|
@@ -6730,7 +6854,10 @@ cli.register(AuditCommand);
|
|
|
6730
6854
|
cli.register(InitCommand);
|
|
6731
6855
|
cli.register(CodemodCommand);
|
|
6732
6856
|
cli.register(SearchIndexCommand);
|
|
6733
|
-
cli.register(
|
|
6734
|
-
cli.register(
|
|
6735
|
-
cli.register(
|
|
6857
|
+
cli.register(Builtins.DefinitionsCommand);
|
|
6858
|
+
cli.register(Builtins.HelpCommand);
|
|
6859
|
+
cli.register(Builtins.VersionCommand);
|
|
6736
6860
|
var index_default = cli;
|
|
6861
|
+
export {
|
|
6862
|
+
index_default as default
|
|
6863
|
+
};
|