@tinacms/cli 0.0.0-ced9076-20250922063813 → 0.0.0-cf37070-20251203063307
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/index.js +871 -827
- package/dist/next/codegen/index.d.ts +3 -9
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,53 +1,20 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name2 in all)
|
|
9
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
1
|
// src/index.ts
|
|
30
|
-
|
|
31
|
-
__export(index_exports, {
|
|
32
|
-
default: () => index_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
var import_clipanion8 = require("clipanion");
|
|
2
|
+
import { Cli, Builtins } from "clipanion";
|
|
36
3
|
|
|
37
4
|
// package.json
|
|
38
|
-
var version = "
|
|
5
|
+
var version = "2.0.0";
|
|
39
6
|
|
|
40
7
|
// src/next/commands/dev-command/index.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
8
|
+
import path8 from "path";
|
|
9
|
+
import { FilesystemBridge as FilesystemBridge2, buildSchema } from "@tinacms/graphql";
|
|
10
|
+
import { LocalSearchIndexClient, SearchIndexer } from "@tinacms/search";
|
|
11
|
+
import AsyncLock from "async-lock";
|
|
12
|
+
import chokidar from "chokidar";
|
|
13
|
+
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
14
|
+
import fs7 from "fs-extra";
|
|
48
15
|
|
|
49
16
|
// src/logger/index.ts
|
|
50
|
-
|
|
17
|
+
import chalk from "chalk";
|
|
51
18
|
|
|
52
19
|
// src/logger/is-unicode-supported.ts
|
|
53
20
|
function isUnicodeSupported() {
|
|
@@ -61,9 +28,9 @@ function isUnicodeSupported() {
|
|
|
61
28
|
}
|
|
62
29
|
|
|
63
30
|
// src/logger/index.ts
|
|
64
|
-
|
|
65
|
-
var logger =
|
|
66
|
-
|
|
31
|
+
import log4js from "log4js";
|
|
32
|
+
var logger = log4js.getLogger();
|
|
33
|
+
log4js.configure({
|
|
67
34
|
appenders: {
|
|
68
35
|
out: { type: "stdout", layout: { type: "messagePassThrough" } }
|
|
69
36
|
},
|
|
@@ -88,18 +55,18 @@ ${message}
|
|
|
88
55
|
return ln.length > sum ? ln.length : sum;
|
|
89
56
|
}, 0) + 2;
|
|
90
57
|
const msg = lines.map(
|
|
91
|
-
(ln) => `${
|
|
58
|
+
(ln) => `${chalk.gray(bar)} ${chalk.white(ln)}${" ".repeat(
|
|
92
59
|
len - strip(ln).length
|
|
93
|
-
)}${
|
|
60
|
+
)}${chalk.gray(bar)}`
|
|
94
61
|
).join("\n");
|
|
95
62
|
const underscoreLen = len - title.length - 1 > 0 ? len - title.length - 1 : 0;
|
|
96
63
|
process.stdout.write(
|
|
97
|
-
`${
|
|
98
|
-
${
|
|
64
|
+
`${chalk.gray(bar)}
|
|
65
|
+
${chalk.green("\u25CB")} ${chalk.reset(
|
|
99
66
|
title
|
|
100
|
-
)} ${
|
|
67
|
+
)} ${chalk.gray("\u2500".repeat(underscoreLen) + "\u256E")}
|
|
101
68
|
${msg}
|
|
102
|
-
${
|
|
69
|
+
${chalk.gray(
|
|
103
70
|
"\u251C" + "\u2500".repeat(len + 2) + "\u256F"
|
|
104
71
|
)}
|
|
105
72
|
`
|
|
@@ -116,11 +83,11 @@ var summary = (content) => {
|
|
|
116
83
|
});
|
|
117
84
|
});
|
|
118
85
|
content.items.forEach((item) => {
|
|
119
|
-
outString.push(`${item.emoji} ${
|
|
86
|
+
outString.push(`${item.emoji} ${chalk.cyan(item.heading)}`);
|
|
120
87
|
item.subItems.forEach((subItem) => {
|
|
121
88
|
const spaces = longestKey - subItem.key.length + 4;
|
|
122
89
|
outString.push(
|
|
123
|
-
` ${subItem.key}:${[...Array(spaces)].join(" ")}${
|
|
90
|
+
` ${subItem.key}:${[...Array(spaces)].join(" ")}${chalk.cyan(
|
|
124
91
|
subItem.value
|
|
125
92
|
)}`
|
|
126
93
|
);
|
|
@@ -158,12 +125,12 @@ var S_WARN = s("\u25B2", "!");
|
|
|
158
125
|
var S_ERROR = s("\u25A0", "x");
|
|
159
126
|
|
|
160
127
|
// src/utils/spinner.ts
|
|
161
|
-
|
|
128
|
+
import { Spinner } from "cli-spinner";
|
|
162
129
|
async function localSpin({
|
|
163
130
|
waitFor,
|
|
164
131
|
text
|
|
165
132
|
}) {
|
|
166
|
-
const spinner = new
|
|
133
|
+
const spinner = new Spinner({
|
|
167
134
|
text: `${text} %s`,
|
|
168
135
|
stream: process.stderr,
|
|
169
136
|
onTick: function(msg) {
|
|
@@ -194,32 +161,32 @@ function spin({
|
|
|
194
161
|
}
|
|
195
162
|
|
|
196
163
|
// src/utils/theme.ts
|
|
197
|
-
|
|
198
|
-
var successText =
|
|
199
|
-
var focusText =
|
|
200
|
-
var dangerText =
|
|
201
|
-
var neutralText =
|
|
202
|
-
var linkText =
|
|
203
|
-
var labelText =
|
|
204
|
-
var cmdText =
|
|
164
|
+
import chalk2 from "chalk";
|
|
165
|
+
var successText = chalk2.bold.green;
|
|
166
|
+
var focusText = chalk2.bold;
|
|
167
|
+
var dangerText = chalk2.bold.red;
|
|
168
|
+
var neutralText = chalk2.bold.cyan;
|
|
169
|
+
var linkText = chalk2.bold.cyan;
|
|
170
|
+
var labelText = chalk2.bold;
|
|
171
|
+
var cmdText = chalk2.inverse;
|
|
205
172
|
var indentedCmd = (str) => {
|
|
206
173
|
return ` \u2503 ` + str;
|
|
207
174
|
};
|
|
208
175
|
var indentText = (str) => {
|
|
209
176
|
return String(str).split("\n").map((line) => ` ${line}`).join("\n");
|
|
210
177
|
};
|
|
211
|
-
var logText =
|
|
212
|
-
var warnText =
|
|
213
|
-
var titleText =
|
|
214
|
-
var CONFIRMATION_TEXT =
|
|
178
|
+
var logText = chalk2.italic.gray;
|
|
179
|
+
var warnText = chalk2.yellowBright.bgBlack;
|
|
180
|
+
var titleText = chalk2.bgHex("d2f1f8").hex("ec4816");
|
|
181
|
+
var CONFIRMATION_TEXT = chalk2.dim("enter to confirm");
|
|
215
182
|
|
|
216
183
|
// src/next/codegen/index.ts
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
184
|
+
import fs from "fs-extra";
|
|
185
|
+
import path from "path";
|
|
186
|
+
import { buildASTSchema, printSchema as printSchema2 } from "graphql";
|
|
220
187
|
|
|
221
188
|
// src/next/codegen/codegen/index.ts
|
|
222
|
-
|
|
189
|
+
import { parse, printSchema } from "graphql";
|
|
223
190
|
|
|
224
191
|
// src/next/codegen/codegen/plugin.ts
|
|
225
192
|
var AddGeneratedClientFunc = (apiURL) => {
|
|
@@ -288,37 +255,44 @@ var AddGeneratedClient = (apiURL) => ({
|
|
|
288
255
|
});
|
|
289
256
|
|
|
290
257
|
// src/next/codegen/codegen/index.ts
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
258
|
+
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
259
|
+
import { codegen } from "@graphql-codegen/core";
|
|
260
|
+
import { loadDocuments } from "@graphql-tools/load";
|
|
261
|
+
import { plugin as typescriptOperationsPlugin } from "@graphql-codegen/typescript-operations";
|
|
262
|
+
import { plugin as typescriptPlugin } from "@graphql-codegen/typescript";
|
|
296
263
|
|
|
297
264
|
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
298
|
-
|
|
299
|
-
|
|
265
|
+
import { visit } from "graphql";
|
|
266
|
+
import {
|
|
267
|
+
concatAST,
|
|
268
|
+
Kind as Kind2
|
|
269
|
+
} from "graphql";
|
|
300
270
|
|
|
301
271
|
// src/next/codegen/codegen/sdkPlugin/visitor.ts
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
272
|
+
import {
|
|
273
|
+
ClientSideBaseVisitor,
|
|
274
|
+
DocumentMode,
|
|
275
|
+
indentMultiline
|
|
276
|
+
} from "@graphql-codegen/visitor-plugin-common";
|
|
277
|
+
import autoBind from "auto-bind";
|
|
278
|
+
import { Kind, print } from "graphql";
|
|
279
|
+
var GenericSdkVisitor = class extends ClientSideBaseVisitor {
|
|
280
|
+
_operationsToInclude = [];
|
|
306
281
|
constructor(schema, fragments, rawConfig) {
|
|
307
282
|
super(schema, fragments, rawConfig, {
|
|
308
283
|
usingObservableFrom: rawConfig.usingObservableFrom
|
|
309
284
|
});
|
|
310
|
-
this
|
|
311
|
-
(0, import_auto_bind.default)(this);
|
|
285
|
+
autoBind(this);
|
|
312
286
|
if (this.config.usingObservableFrom) {
|
|
313
287
|
this._additionalImports.push(this.config.usingObservableFrom);
|
|
314
288
|
}
|
|
315
|
-
if (this.config.documentMode !==
|
|
289
|
+
if (this.config.documentMode !== DocumentMode.string) {
|
|
316
290
|
}
|
|
317
291
|
}
|
|
318
292
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
319
293
|
if (node.name == null) {
|
|
320
294
|
throw new Error(
|
|
321
|
-
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" +
|
|
295
|
+
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + print(node)
|
|
322
296
|
);
|
|
323
297
|
} else {
|
|
324
298
|
this._operationsToInclude.push({
|
|
@@ -336,14 +310,14 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
336
310
|
const usingObservable = !!this.config.usingObservableFrom;
|
|
337
311
|
const allPossibleActions = this._operationsToInclude.map((o) => {
|
|
338
312
|
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every(
|
|
339
|
-
(v) => v.type.kind !==
|
|
313
|
+
(v) => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue
|
|
340
314
|
);
|
|
341
315
|
const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
|
|
342
316
|
return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
|
|
343
317
|
return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
|
|
344
318
|
}`;
|
|
345
|
-
}).map((s2) =>
|
|
346
|
-
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode ===
|
|
319
|
+
}).map((s2) => indentMultiline(s2, 2));
|
|
320
|
+
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode === DocumentMode.string ? "string" : "DocumentNode"}, vars?: V, options?: C) => ${usingObservable ? "Promise<R> & Observable<R>" : "Promise<R>"}
|
|
347
321
|
export function getSdk<C>(requester: Requester<C>) {
|
|
348
322
|
return {
|
|
349
323
|
${allPossibleActions.join(",\n")}
|
|
@@ -355,14 +329,14 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
355
329
|
|
|
356
330
|
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
357
331
|
var plugin = (schema, documents, config2) => {
|
|
358
|
-
const allAst =
|
|
332
|
+
const allAst = concatAST(
|
|
359
333
|
documents.reduce((prev, v) => {
|
|
360
334
|
return [...prev, v.document];
|
|
361
335
|
}, [])
|
|
362
336
|
);
|
|
363
337
|
const allFragments = [
|
|
364
338
|
...allAst.definitions.filter(
|
|
365
|
-
(d) => d.kind ===
|
|
339
|
+
(d) => d.kind === Kind2.FRAGMENT_DEFINITION
|
|
366
340
|
).map((fragmentDef) => ({
|
|
367
341
|
node: fragmentDef,
|
|
368
342
|
name: fragmentDef.name.value,
|
|
@@ -372,7 +346,7 @@ var plugin = (schema, documents, config2) => {
|
|
|
372
346
|
...config2.externalFragments || []
|
|
373
347
|
];
|
|
374
348
|
const visitor = new GenericSdkVisitor(schema, allFragments, config2);
|
|
375
|
-
const visitorResult =
|
|
349
|
+
const visitorResult = visit(allAst, { leave: visitor });
|
|
376
350
|
return {
|
|
377
351
|
// We will take care of imports
|
|
378
352
|
// prepend: visitor.getImports(),
|
|
@@ -390,10 +364,10 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
390
364
|
let fragDocs = [];
|
|
391
365
|
docs = await loadGraphQLDocuments(queryPathGlob);
|
|
392
366
|
fragDocs = await loadGraphQLDocuments(fragDocPath);
|
|
393
|
-
const res = await
|
|
367
|
+
const res = await codegen({
|
|
394
368
|
// Filename is not used. This is because the typescript plugin returns a string instead of writing to a file.
|
|
395
369
|
filename: process.cwd(),
|
|
396
|
-
schema:
|
|
370
|
+
schema: parse(printSchema(schema)),
|
|
397
371
|
documents: [...docs, ...fragDocs],
|
|
398
372
|
config: {},
|
|
399
373
|
plugins: [
|
|
@@ -406,10 +380,10 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
406
380
|
],
|
|
407
381
|
pluginMap: {
|
|
408
382
|
typescript: {
|
|
409
|
-
plugin:
|
|
383
|
+
plugin: typescriptPlugin
|
|
410
384
|
},
|
|
411
385
|
typescriptOperations: {
|
|
412
|
-
plugin:
|
|
386
|
+
plugin: typescriptOperationsPlugin
|
|
413
387
|
},
|
|
414
388
|
typescriptSdk: {
|
|
415
389
|
plugin
|
|
@@ -422,8 +396,8 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
422
396
|
var loadGraphQLDocuments = async (globPath) => {
|
|
423
397
|
let result = [];
|
|
424
398
|
try {
|
|
425
|
-
result = await
|
|
426
|
-
loaders: [new
|
|
399
|
+
result = await loadDocuments(globPath, {
|
|
400
|
+
loaders: [new GraphQLFileLoader()]
|
|
427
401
|
});
|
|
428
402
|
} catch (e) {
|
|
429
403
|
if (
|
|
@@ -440,11 +414,27 @@ var loadGraphQLDocuments = async (globPath) => {
|
|
|
440
414
|
};
|
|
441
415
|
|
|
442
416
|
// src/next/codegen/index.ts
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
417
|
+
import { transform } from "esbuild";
|
|
418
|
+
import { mapUserFields } from "@tinacms/graphql";
|
|
419
|
+
import normalizePath from "normalize-path";
|
|
446
420
|
var TINA_HOST = "content.tinajs.io";
|
|
447
421
|
var Codegen = class {
|
|
422
|
+
configManager;
|
|
423
|
+
port;
|
|
424
|
+
schema;
|
|
425
|
+
queryDoc;
|
|
426
|
+
fragDoc;
|
|
427
|
+
isLocal;
|
|
428
|
+
// The API url used in the client
|
|
429
|
+
apiURL;
|
|
430
|
+
// This is always the local URL.
|
|
431
|
+
localUrl;
|
|
432
|
+
// production url
|
|
433
|
+
productionUrl;
|
|
434
|
+
graphqlSchemaDoc;
|
|
435
|
+
tinaSchema;
|
|
436
|
+
lookup;
|
|
437
|
+
noClientBuildCache;
|
|
448
438
|
constructor({
|
|
449
439
|
configManager,
|
|
450
440
|
port,
|
|
@@ -460,7 +450,7 @@ var Codegen = class {
|
|
|
460
450
|
this.graphqlSchemaDoc = graphqlSchemaDoc;
|
|
461
451
|
this.configManager = configManager;
|
|
462
452
|
this.port = port;
|
|
463
|
-
this.schema =
|
|
453
|
+
this.schema = buildASTSchema(graphqlSchemaDoc);
|
|
464
454
|
this.tinaSchema = tinaSchema;
|
|
465
455
|
this.queryDoc = queryDoc;
|
|
466
456
|
this.fragDoc = fragDoc;
|
|
@@ -468,19 +458,19 @@ var Codegen = class {
|
|
|
468
458
|
this.noClientBuildCache = noClientBuildCache;
|
|
469
459
|
}
|
|
470
460
|
async writeConfigFile(fileName, data) {
|
|
471
|
-
const filePath =
|
|
461
|
+
const filePath = path.join(
|
|
472
462
|
this.configManager.generatedFolderPath,
|
|
473
463
|
fileName
|
|
474
464
|
);
|
|
475
|
-
await
|
|
476
|
-
await
|
|
465
|
+
await fs.ensureFile(filePath);
|
|
466
|
+
await fs.outputFile(filePath, data);
|
|
477
467
|
if (this.configManager.hasSeparateContentRoot()) {
|
|
478
|
-
const filePath2 =
|
|
468
|
+
const filePath2 = path.join(
|
|
479
469
|
this.configManager.generatedFolderPathContentRepo,
|
|
480
470
|
fileName
|
|
481
471
|
);
|
|
482
|
-
await
|
|
483
|
-
await
|
|
472
|
+
await fs.ensureFile(filePath2);
|
|
473
|
+
await fs.outputFile(filePath2, data);
|
|
484
474
|
}
|
|
485
475
|
}
|
|
486
476
|
async removeGeneratedFilesIfExists() {
|
|
@@ -512,11 +502,11 @@ var Codegen = class {
|
|
|
512
502
|
await this.removeGeneratedFilesIfExists();
|
|
513
503
|
return apiURL;
|
|
514
504
|
}
|
|
515
|
-
await
|
|
505
|
+
await fs.outputFile(
|
|
516
506
|
this.configManager.generatedQueriesFilePath,
|
|
517
507
|
this.queryDoc
|
|
518
508
|
);
|
|
519
|
-
await
|
|
509
|
+
await fs.outputFile(
|
|
520
510
|
this.configManager.generatedFragmentsFilePath,
|
|
521
511
|
this.fragDoc
|
|
522
512
|
);
|
|
@@ -524,21 +514,21 @@ var Codegen = class {
|
|
|
524
514
|
const { clientString } = await this.genClient();
|
|
525
515
|
const databaseClientString = this.configManager.hasSelfHostedConfig() ? await this.genDatabaseClient() : "";
|
|
526
516
|
const { codeString, schemaString } = await this.genTypes();
|
|
527
|
-
await
|
|
517
|
+
await fs.outputFile(
|
|
528
518
|
this.configManager.generatedGraphQLGQLPath,
|
|
529
519
|
schemaString
|
|
530
520
|
);
|
|
531
521
|
if (this.configManager.isUsingTs()) {
|
|
532
|
-
await
|
|
522
|
+
await fs.outputFile(
|
|
533
523
|
this.configManager.generatedTypesTSFilePath,
|
|
534
524
|
codeString
|
|
535
525
|
);
|
|
536
|
-
await
|
|
526
|
+
await fs.outputFile(
|
|
537
527
|
this.configManager.generatedClientTSFilePath,
|
|
538
528
|
clientString
|
|
539
529
|
);
|
|
540
530
|
if (this.configManager.hasSelfHostedConfig()) {
|
|
541
|
-
await
|
|
531
|
+
await fs.outputFile(
|
|
542
532
|
this.configManager.generatedDatabaseClientTSFilePath,
|
|
543
533
|
databaseClientString
|
|
544
534
|
);
|
|
@@ -547,35 +537,35 @@ var Codegen = class {
|
|
|
547
537
|
await unlinkIfExists(this.configManager.generatedTypesDFilePath);
|
|
548
538
|
await unlinkIfExists(this.configManager.generatedTypesJSFilePath);
|
|
549
539
|
} else {
|
|
550
|
-
await
|
|
540
|
+
await fs.outputFile(
|
|
551
541
|
this.configManager.generatedTypesDFilePath,
|
|
552
542
|
codeString
|
|
553
543
|
);
|
|
554
|
-
const jsTypes = await
|
|
555
|
-
await
|
|
544
|
+
const jsTypes = await transform(codeString, { loader: "ts" });
|
|
545
|
+
await fs.outputFile(
|
|
556
546
|
this.configManager.generatedTypesJSFilePath,
|
|
557
547
|
jsTypes.code
|
|
558
548
|
);
|
|
559
|
-
await
|
|
549
|
+
await fs.outputFile(
|
|
560
550
|
this.configManager.generatedClientDFilePath,
|
|
561
551
|
clientString
|
|
562
552
|
);
|
|
563
|
-
const jsClient = await
|
|
564
|
-
await
|
|
553
|
+
const jsClient = await transform(clientString, { loader: "ts" });
|
|
554
|
+
await fs.outputFile(
|
|
565
555
|
this.configManager.generatedClientJSFilePath,
|
|
566
556
|
jsClient.code
|
|
567
557
|
);
|
|
568
558
|
await unlinkIfExists(this.configManager.generatedTypesTSFilePath);
|
|
569
559
|
await unlinkIfExists(this.configManager.generatedClientTSFilePath);
|
|
570
560
|
if (this.configManager.hasSelfHostedConfig()) {
|
|
571
|
-
const jsDatabaseClient = await
|
|
561
|
+
const jsDatabaseClient = await transform(databaseClientString, {
|
|
572
562
|
loader: "ts"
|
|
573
563
|
});
|
|
574
|
-
await
|
|
564
|
+
await fs.outputFile(
|
|
575
565
|
this.configManager.generatedDatabaseClientJSFilePath,
|
|
576
566
|
jsDatabaseClient.code
|
|
577
567
|
);
|
|
578
|
-
await
|
|
568
|
+
await fs.outputFile(
|
|
579
569
|
this.configManager.generatedDatabaseClientDFilePath,
|
|
580
570
|
databaseClientString
|
|
581
571
|
);
|
|
@@ -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,26 +758,28 @@ 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";
|
|
784
776
|
|
|
785
777
|
// src/utils/path.ts
|
|
786
|
-
|
|
778
|
+
import path2 from "path";
|
|
787
779
|
function stripNativeTrailingSlash(p) {
|
|
788
|
-
const { root } =
|
|
780
|
+
const { root } = path2.parse(p);
|
|
789
781
|
let str = p;
|
|
790
|
-
while (str.length > root.length && str.endsWith(
|
|
782
|
+
while (str.length > root.length && str.endsWith(path2.sep)) {
|
|
791
783
|
str = str.slice(0, -1);
|
|
792
784
|
}
|
|
793
785
|
return str;
|
|
@@ -802,17 +794,57 @@ var GRAPHQL_GQL_FILE = "schema.gql";
|
|
|
802
794
|
var SCHEMA_JSON_FILE = "_schema.json";
|
|
803
795
|
var LOOKUP_JSON_FILE = "_lookup.json";
|
|
804
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;
|
|
805
837
|
constructor({
|
|
806
838
|
rootPath = process.cwd(),
|
|
807
839
|
tinaGraphQLVersion,
|
|
808
840
|
legacyNoSDK
|
|
809
841
|
}) {
|
|
810
|
-
this.rootPath = (
|
|
842
|
+
this.rootPath = normalizePath2(rootPath);
|
|
811
843
|
this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
|
|
812
844
|
this.legacyNoSDK = legacyNoSDK;
|
|
813
845
|
}
|
|
814
846
|
isUsingTs() {
|
|
815
|
-
return [".ts", ".tsx"].includes(
|
|
847
|
+
return [".ts", ".tsx"].includes(path3.extname(this.tinaConfigFilePath));
|
|
816
848
|
}
|
|
817
849
|
hasSelfHostedConfig() {
|
|
818
850
|
return !!this.selfHostedDatabaseFilePath;
|
|
@@ -827,13 +859,14 @@ var ConfigManager = class {
|
|
|
827
859
|
return this.config.client?.skip || false;
|
|
828
860
|
}
|
|
829
861
|
async processConfig() {
|
|
862
|
+
const require2 = createRequire(import.meta.url);
|
|
830
863
|
this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
|
|
831
|
-
this.envFilePath =
|
|
832
|
-
|
|
864
|
+
this.envFilePath = path3.resolve(
|
|
865
|
+
path3.join(this.tinaFolderPath, "..", ".env")
|
|
833
866
|
);
|
|
834
867
|
dotenv.config({ path: this.envFilePath });
|
|
835
868
|
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
836
|
-
|
|
869
|
+
path3.join(this.tinaFolderPath, "config")
|
|
837
870
|
);
|
|
838
871
|
if (!this.tinaConfigFilePath) {
|
|
839
872
|
throw new Error(
|
|
@@ -841,89 +874,89 @@ var ConfigManager = class {
|
|
|
841
874
|
);
|
|
842
875
|
}
|
|
843
876
|
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
844
|
-
|
|
877
|
+
path3.join(this.tinaFolderPath, "database")
|
|
845
878
|
);
|
|
846
|
-
this.generatedFolderPath =
|
|
847
|
-
this.generatedCachePath =
|
|
879
|
+
this.generatedFolderPath = path3.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
880
|
+
this.generatedCachePath = path3.join(
|
|
848
881
|
this.generatedFolderPath,
|
|
849
882
|
".cache",
|
|
850
883
|
String((/* @__PURE__ */ new Date()).getTime())
|
|
851
884
|
);
|
|
852
|
-
this.generatedGraphQLGQLPath =
|
|
885
|
+
this.generatedGraphQLGQLPath = path3.join(
|
|
853
886
|
this.generatedFolderPath,
|
|
854
887
|
GRAPHQL_GQL_FILE
|
|
855
888
|
);
|
|
856
|
-
this.generatedGraphQLJSONPath =
|
|
889
|
+
this.generatedGraphQLJSONPath = path3.join(
|
|
857
890
|
this.generatedFolderPath,
|
|
858
891
|
GRAPHQL_JSON_FILE
|
|
859
892
|
);
|
|
860
|
-
this.generatedSchemaJSONPath =
|
|
893
|
+
this.generatedSchemaJSONPath = path3.join(
|
|
861
894
|
this.generatedFolderPath,
|
|
862
895
|
SCHEMA_JSON_FILE
|
|
863
896
|
);
|
|
864
|
-
this.generatedLookupJSONPath =
|
|
897
|
+
this.generatedLookupJSONPath = path3.join(
|
|
865
898
|
this.generatedFolderPath,
|
|
866
899
|
LOOKUP_JSON_FILE
|
|
867
900
|
);
|
|
868
|
-
this.generatedQueriesFilePath =
|
|
901
|
+
this.generatedQueriesFilePath = path3.join(
|
|
869
902
|
this.generatedFolderPath,
|
|
870
903
|
"queries.gql"
|
|
871
904
|
);
|
|
872
|
-
this.generatedFragmentsFilePath =
|
|
905
|
+
this.generatedFragmentsFilePath = path3.join(
|
|
873
906
|
this.generatedFolderPath,
|
|
874
907
|
"frags.gql"
|
|
875
908
|
);
|
|
876
|
-
this.generatedTypesTSFilePath =
|
|
909
|
+
this.generatedTypesTSFilePath = path3.join(
|
|
877
910
|
this.generatedFolderPath,
|
|
878
911
|
"types.ts"
|
|
879
912
|
);
|
|
880
|
-
this.generatedTypesJSFilePath =
|
|
913
|
+
this.generatedTypesJSFilePath = path3.join(
|
|
881
914
|
this.generatedFolderPath,
|
|
882
915
|
"types.js"
|
|
883
916
|
);
|
|
884
|
-
this.generatedTypesDFilePath =
|
|
917
|
+
this.generatedTypesDFilePath = path3.join(
|
|
885
918
|
this.generatedFolderPath,
|
|
886
919
|
"types.d.ts"
|
|
887
920
|
);
|
|
888
|
-
this.userQueriesAndFragmentsGlob =
|
|
921
|
+
this.userQueriesAndFragmentsGlob = path3.join(
|
|
889
922
|
this.tinaFolderPath,
|
|
890
923
|
"queries/**/*.{graphql,gql}"
|
|
891
924
|
);
|
|
892
|
-
this.generatedQueriesAndFragmentsGlob =
|
|
925
|
+
this.generatedQueriesAndFragmentsGlob = path3.join(
|
|
893
926
|
this.generatedFolderPath,
|
|
894
927
|
"*.{graphql,gql}"
|
|
895
928
|
);
|
|
896
|
-
this.generatedClientTSFilePath =
|
|
929
|
+
this.generatedClientTSFilePath = path3.join(
|
|
897
930
|
this.generatedFolderPath,
|
|
898
931
|
"client.ts"
|
|
899
932
|
);
|
|
900
|
-
this.generatedClientJSFilePath =
|
|
933
|
+
this.generatedClientJSFilePath = path3.join(
|
|
901
934
|
this.generatedFolderPath,
|
|
902
935
|
"client.js"
|
|
903
936
|
);
|
|
904
|
-
this.generatedClientDFilePath =
|
|
937
|
+
this.generatedClientDFilePath = path3.join(
|
|
905
938
|
this.generatedFolderPath,
|
|
906
939
|
"client.d.ts"
|
|
907
940
|
);
|
|
908
|
-
this.generatedDatabaseClientDFilePath =
|
|
941
|
+
this.generatedDatabaseClientDFilePath = path3.join(
|
|
909
942
|
this.generatedFolderPath,
|
|
910
943
|
"databaseClient.d.ts"
|
|
911
944
|
);
|
|
912
|
-
this.generatedDatabaseClientTSFilePath =
|
|
945
|
+
this.generatedDatabaseClientTSFilePath = path3.join(
|
|
913
946
|
this.generatedFolderPath,
|
|
914
947
|
"databaseClient.ts"
|
|
915
948
|
);
|
|
916
|
-
this.generatedDatabaseClientJSFilePath =
|
|
949
|
+
this.generatedDatabaseClientJSFilePath = path3.join(
|
|
917
950
|
this.generatedFolderPath,
|
|
918
951
|
"databaseClient.js"
|
|
919
952
|
);
|
|
920
|
-
const clientExists = this.isUsingTs() ? await
|
|
953
|
+
const clientExists = this.isUsingTs() ? await fs2.pathExists(this.generatedClientTSFilePath) : await fs2.pathExists(this.generatedClientJSFilePath);
|
|
921
954
|
if (!clientExists) {
|
|
922
955
|
const file = "export default ()=>({})\nexport const client = ()=>({})";
|
|
923
956
|
if (this.isUsingTs()) {
|
|
924
|
-
await
|
|
957
|
+
await fs2.outputFile(this.generatedClientTSFilePath, file);
|
|
925
958
|
} else {
|
|
926
|
-
await
|
|
959
|
+
await fs2.outputFile(this.generatedClientJSFilePath, file);
|
|
927
960
|
}
|
|
928
961
|
}
|
|
929
962
|
const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
|
|
@@ -933,29 +966,29 @@ var ConfigManager = class {
|
|
|
933
966
|
this.watchList = watchList;
|
|
934
967
|
this.config = config2;
|
|
935
968
|
this.prebuildFilePath = prebuildPath;
|
|
936
|
-
this.publicFolderPath =
|
|
969
|
+
this.publicFolderPath = path3.join(
|
|
937
970
|
this.rootPath,
|
|
938
971
|
this.config.build.publicFolder
|
|
939
972
|
);
|
|
940
|
-
this.outputFolderPath =
|
|
973
|
+
this.outputFolderPath = path3.join(
|
|
941
974
|
this.publicFolderPath,
|
|
942
975
|
this.config.build.outputFolder
|
|
943
976
|
);
|
|
944
|
-
this.outputHTMLFilePath =
|
|
945
|
-
this.outputGitignorePath =
|
|
977
|
+
this.outputHTMLFilePath = path3.join(this.outputFolderPath, "index.html");
|
|
978
|
+
this.outputGitignorePath = path3.join(this.outputFolderPath, ".gitignore");
|
|
946
979
|
const fullLocalContentPath = stripNativeTrailingSlash(
|
|
947
|
-
|
|
980
|
+
path3.join(this.tinaFolderPath, this.config.localContentPath || "")
|
|
948
981
|
);
|
|
949
982
|
if (this.config.localContentPath) {
|
|
950
|
-
const localContentPathExists = await
|
|
983
|
+
const localContentPathExists = await fs2.pathExists(fullLocalContentPath);
|
|
951
984
|
if (localContentPathExists) {
|
|
952
985
|
logger.info(`Using separate content repo at ${fullLocalContentPath}`);
|
|
953
986
|
this.contentRootPath = fullLocalContentPath;
|
|
954
987
|
} else {
|
|
955
988
|
logger.warn(
|
|
956
|
-
`${
|
|
989
|
+
`${chalk3.yellow("Warning:")} The localContentPath ${chalk3.cyan(
|
|
957
990
|
fullLocalContentPath
|
|
958
|
-
)} 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(
|
|
959
992
|
this.tinaConfigFilePath
|
|
960
993
|
)}`
|
|
961
994
|
);
|
|
@@ -964,22 +997,22 @@ var ConfigManager = class {
|
|
|
964
997
|
if (!this.contentRootPath) {
|
|
965
998
|
this.contentRootPath = this.rootPath;
|
|
966
999
|
}
|
|
967
|
-
this.generatedFolderPathContentRepo =
|
|
1000
|
+
this.generatedFolderPathContentRepo = path3.join(
|
|
968
1001
|
await this.getTinaFolderPath(this.contentRootPath),
|
|
969
1002
|
GENERATED_FOLDER
|
|
970
1003
|
);
|
|
971
|
-
this.spaMainPath =
|
|
972
|
-
this.spaRootPath =
|
|
1004
|
+
this.spaMainPath = require2.resolve("@tinacms/app");
|
|
1005
|
+
this.spaRootPath = path3.join(this.spaMainPath, "..", "..");
|
|
973
1006
|
}
|
|
974
1007
|
async getTinaFolderPath(rootPath) {
|
|
975
|
-
const tinaFolderPath =
|
|
976
|
-
const tinaFolderExists = await
|
|
1008
|
+
const tinaFolderPath = path3.join(rootPath, TINA_FOLDER);
|
|
1009
|
+
const tinaFolderExists = await fs2.pathExists(tinaFolderPath);
|
|
977
1010
|
if (tinaFolderExists) {
|
|
978
1011
|
this.isUsingLegacyFolder = false;
|
|
979
1012
|
return tinaFolderPath;
|
|
980
1013
|
}
|
|
981
|
-
const legacyFolderPath =
|
|
982
|
-
const legacyFolderExists = await
|
|
1014
|
+
const legacyFolderPath = path3.join(rootPath, LEGACY_TINA_FOLDER);
|
|
1015
|
+
const legacyFolderExists = await fs2.pathExists(legacyFolderPath);
|
|
983
1016
|
if (legacyFolderExists) {
|
|
984
1017
|
this.isUsingLegacyFolder = true;
|
|
985
1018
|
return legacyFolderPath;
|
|
@@ -998,7 +1031,7 @@ var ConfigManager = class {
|
|
|
998
1031
|
patch: version2[2] || "x"
|
|
999
1032
|
};
|
|
1000
1033
|
}
|
|
1001
|
-
const generatedSchema =
|
|
1034
|
+
const generatedSchema = fs2.readJSONSync(this.generatedSchemaJSONPath);
|
|
1002
1035
|
if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
|
|
1003
1036
|
throw new Error(
|
|
1004
1037
|
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
@@ -1045,7 +1078,7 @@ var ConfigManager = class {
|
|
|
1045
1078
|
return;
|
|
1046
1079
|
}
|
|
1047
1080
|
const filepathWithExtension = `${filepath}.${ext}`;
|
|
1048
|
-
const exists =
|
|
1081
|
+
const exists = fs2.existsSync(filepathWithExtension);
|
|
1049
1082
|
if (exists) {
|
|
1050
1083
|
result = filepathWithExtension;
|
|
1051
1084
|
}
|
|
@@ -1054,33 +1087,53 @@ var ConfigManager = class {
|
|
|
1054
1087
|
return result;
|
|
1055
1088
|
}
|
|
1056
1089
|
async loadDatabaseFile() {
|
|
1057
|
-
const tmpdir =
|
|
1058
|
-
const outfile =
|
|
1090
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1091
|
+
const outfile = path3.join(tmpdir, "database.build.mjs");
|
|
1059
1092
|
await esbuild.build({
|
|
1060
1093
|
entryPoints: [this.selfHostedDatabaseFilePath],
|
|
1061
1094
|
bundle: true,
|
|
1062
1095
|
platform: "node",
|
|
1096
|
+
format: "esm",
|
|
1063
1097
|
outfile,
|
|
1064
|
-
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
|
+
}
|
|
1065
1107
|
});
|
|
1066
|
-
const result =
|
|
1067
|
-
|
|
1108
|
+
const result = await import(pathToFileURL(outfile).href);
|
|
1109
|
+
fs2.removeSync(outfile);
|
|
1068
1110
|
return result.default;
|
|
1069
1111
|
}
|
|
1070
1112
|
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
1071
|
-
const tmpdir =
|
|
1072
|
-
const preBuildConfigPath =
|
|
1113
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1114
|
+
const preBuildConfigPath = path3.join(
|
|
1073
1115
|
this.generatedFolderPath,
|
|
1074
1116
|
"config.prebuild.jsx"
|
|
1075
1117
|
);
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1118
|
+
const nativeNodeModulesPlugin = {
|
|
1119
|
+
name: "native-node-modules",
|
|
1120
|
+
setup(build3) {
|
|
1121
|
+
build3.onResolve({ filter: /^node:.*/ }, (args) => {
|
|
1122
|
+
return {
|
|
1123
|
+
path: args.path,
|
|
1124
|
+
external: true
|
|
1125
|
+
};
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
const outfile = path3.join(tmpdir, "config.build.jsx");
|
|
1130
|
+
const outfile2 = path3.join(tmpdir, "config.build.mjs");
|
|
1131
|
+
const tempTSConfigFile = path3.join(tmpdir, "tsconfig.json");
|
|
1132
|
+
fs2.outputFileSync(tempTSConfigFile, "{}");
|
|
1080
1133
|
const result2 = await esbuild.build({
|
|
1081
1134
|
entryPoints: [configFilePath],
|
|
1082
1135
|
bundle: true,
|
|
1083
|
-
target: ["
|
|
1136
|
+
target: ["esnext"],
|
|
1084
1137
|
platform: "browser",
|
|
1085
1138
|
format: "esm",
|
|
1086
1139
|
logLevel: "silent",
|
|
@@ -1100,9 +1153,10 @@ var ConfigManager = class {
|
|
|
1100
1153
|
await esbuild.build({
|
|
1101
1154
|
entryPoints: [configFilePath],
|
|
1102
1155
|
bundle: true,
|
|
1103
|
-
target: ["
|
|
1156
|
+
target: ["esnext"],
|
|
1104
1157
|
logLevel: "silent",
|
|
1105
1158
|
platform: "node",
|
|
1159
|
+
format: "esm",
|
|
1106
1160
|
outfile,
|
|
1107
1161
|
loader: loaders
|
|
1108
1162
|
});
|
|
@@ -1112,19 +1166,21 @@ var ConfigManager = class {
|
|
|
1112
1166
|
// Suppress warning about comparison with -0 from client module
|
|
1113
1167
|
logLevel: "silent",
|
|
1114
1168
|
platform: "node",
|
|
1169
|
+
target: ["esnext"],
|
|
1170
|
+
format: "esm",
|
|
1115
1171
|
outfile: outfile2,
|
|
1116
1172
|
loader: loaders
|
|
1117
1173
|
});
|
|
1118
1174
|
let result;
|
|
1119
1175
|
try {
|
|
1120
|
-
result =
|
|
1176
|
+
result = await import(pathToFileURL(outfile2).href);
|
|
1121
1177
|
} catch (e) {
|
|
1122
1178
|
console.error("Unexpected error loading config");
|
|
1123
1179
|
console.error(e);
|
|
1124
1180
|
throw e;
|
|
1125
1181
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1182
|
+
fs2.removeSync(outfile);
|
|
1183
|
+
fs2.removeSync(outfile2);
|
|
1128
1184
|
return {
|
|
1129
1185
|
config: result.default,
|
|
1130
1186
|
prebuildPath: preBuildConfigPath,
|
|
@@ -1159,20 +1215,24 @@ var loaders = {
|
|
|
1159
1215
|
};
|
|
1160
1216
|
|
|
1161
1217
|
// src/next/database.ts
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1218
|
+
import {
|
|
1219
|
+
createDatabaseInternal,
|
|
1220
|
+
FilesystemBridge,
|
|
1221
|
+
TinaLevelClient
|
|
1222
|
+
} from "@tinacms/graphql";
|
|
1223
|
+
import { pipeline } from "readable-stream";
|
|
1224
|
+
import { createServer } from "net";
|
|
1225
|
+
import { ManyLevelHost } from "many-level";
|
|
1226
|
+
import { MemoryLevel } from "memory-level";
|
|
1167
1227
|
var createDBServer = (port) => {
|
|
1168
|
-
const levelHost = new
|
|
1228
|
+
const levelHost = new ManyLevelHost(
|
|
1169
1229
|
// @ts-ignore
|
|
1170
|
-
new
|
|
1230
|
+
new MemoryLevel({
|
|
1171
1231
|
valueEncoding: "json"
|
|
1172
1232
|
})
|
|
1173
1233
|
);
|
|
1174
|
-
const dbServer =
|
|
1175
|
-
return
|
|
1234
|
+
const dbServer = createServer(function(socket) {
|
|
1235
|
+
return pipeline(socket, levelHost.createRpcStream(), socket, () => {
|
|
1176
1236
|
});
|
|
1177
1237
|
});
|
|
1178
1238
|
dbServer.once("error", (err) => {
|
|
@@ -1186,7 +1246,7 @@ var createDBServer = (port) => {
|
|
|
1186
1246
|
};
|
|
1187
1247
|
async function createAndInitializeDatabase(configManager, datalayerPort, bridgeOverride) {
|
|
1188
1248
|
let database;
|
|
1189
|
-
const bridge = bridgeOverride || new
|
|
1249
|
+
const bridge = bridgeOverride || new FilesystemBridge(configManager.rootPath, configManager.contentRootPath);
|
|
1190
1250
|
if (configManager.hasSelfHostedConfig() && configManager.config.contentApiUrlOverride) {
|
|
1191
1251
|
database = await configManager.loadDatabaseFile();
|
|
1192
1252
|
database.bridge = bridge;
|
|
@@ -1198,9 +1258,9 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1198
1258
|
)} but there was no "contentApiUrlOverride" set. Falling back to built-in datalayer`
|
|
1199
1259
|
);
|
|
1200
1260
|
}
|
|
1201
|
-
const level = new
|
|
1261
|
+
const level = new TinaLevelClient(datalayerPort);
|
|
1202
1262
|
level.openConnection();
|
|
1203
|
-
database =
|
|
1263
|
+
database = createDatabaseInternal({
|
|
1204
1264
|
bridge,
|
|
1205
1265
|
level,
|
|
1206
1266
|
tinaDirectory: configManager.isUsingLegacyFolder ? LEGACY_TINA_FOLDER : TINA_FOLDER
|
|
@@ -1210,17 +1270,17 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1210
1270
|
}
|
|
1211
1271
|
|
|
1212
1272
|
// src/next/commands/baseCommands.ts
|
|
1213
|
-
|
|
1214
|
-
|
|
1273
|
+
import { Command, Option } from "clipanion";
|
|
1274
|
+
import chalk4 from "chalk";
|
|
1215
1275
|
|
|
1216
1276
|
// src/utils/start-subprocess.ts
|
|
1217
|
-
|
|
1277
|
+
import childProcess from "child_process";
|
|
1218
1278
|
var startSubprocess2 = async ({ command: command2 }) => {
|
|
1219
1279
|
if (typeof command2 === "string") {
|
|
1220
1280
|
const commands = command2.split(" ");
|
|
1221
1281
|
const firstCommand = commands[0];
|
|
1222
1282
|
const args = commands.slice(1) || [];
|
|
1223
|
-
const ps =
|
|
1283
|
+
const ps = childProcess.spawn(firstCommand, args, {
|
|
1224
1284
|
stdio: "inherit",
|
|
1225
1285
|
shell: true
|
|
1226
1286
|
});
|
|
@@ -1244,45 +1304,42 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
1244
1304
|
};
|
|
1245
1305
|
|
|
1246
1306
|
// src/next/commands/baseCommands.ts
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
var BaseCommand = class extends
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
description: "Disable anonymous telemetry that is collected"
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1307
|
+
import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
|
|
1308
|
+
import fs3 from "fs-extra";
|
|
1309
|
+
var BaseCommand = class extends Command {
|
|
1310
|
+
experimentalDataLayer = Option.Boolean("--experimentalData", {
|
|
1311
|
+
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
1312
|
+
});
|
|
1313
|
+
isomorphicGitBridge = Option.Boolean("--isomorphicGitBridge", {
|
|
1314
|
+
description: "DEPRECATED - Enable Isomorphic Git Bridge Implementation"
|
|
1315
|
+
});
|
|
1316
|
+
port = Option.String("-p,--port", "4001", {
|
|
1317
|
+
description: "Specify a port to run the server on. (default 4001)"
|
|
1318
|
+
});
|
|
1319
|
+
datalayerPort = Option.String("--datalayer-port", "9000", {
|
|
1320
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
1321
|
+
});
|
|
1322
|
+
subCommand = Option.String("-c,--command", {
|
|
1323
|
+
description: "The sub-command to run"
|
|
1324
|
+
});
|
|
1325
|
+
rootPath = Option.String("--rootPath", {
|
|
1326
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
1327
|
+
});
|
|
1328
|
+
verbose = Option.Boolean("-v,--verbose", false, {
|
|
1329
|
+
description: "increase verbosity of logged output"
|
|
1330
|
+
});
|
|
1331
|
+
noSDK = Option.Boolean("--noSDK", false, {
|
|
1332
|
+
description: "DEPRECATED - This should now be set in the config at client.skip = true'. Don't generate the generated client SDK"
|
|
1333
|
+
});
|
|
1334
|
+
noTelemetry = Option.Boolean("--noTelemetry", false, {
|
|
1335
|
+
description: "Disable anonymous telemetry that is collected"
|
|
1336
|
+
});
|
|
1280
1337
|
async startSubCommand() {
|
|
1281
1338
|
let subProc;
|
|
1282
1339
|
if (this.subCommand) {
|
|
1283
1340
|
subProc = await startSubprocess2({ command: this.subCommand });
|
|
1284
1341
|
logger.info(
|
|
1285
|
-
`Running web application with command: ${
|
|
1342
|
+
`Running web application with command: ${chalk4.cyan(this.subCommand)}`
|
|
1286
1343
|
);
|
|
1287
1344
|
}
|
|
1288
1345
|
function exitHandler(options, exitCode) {
|
|
@@ -1330,7 +1387,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1330
1387
|
const rootPath = configManager.rootPath;
|
|
1331
1388
|
let sha;
|
|
1332
1389
|
try {
|
|
1333
|
-
sha = await
|
|
1390
|
+
sha = await getSha({ fs: fs3, dir: rootPath });
|
|
1334
1391
|
} catch (e) {
|
|
1335
1392
|
if (partialReindex) {
|
|
1336
1393
|
console.error(
|
|
@@ -1340,7 +1397,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1340
1397
|
}
|
|
1341
1398
|
}
|
|
1342
1399
|
const lastSha = await database.getMetadata("lastSha");
|
|
1343
|
-
const exists = lastSha && await
|
|
1400
|
+
const exists = lastSha && await shaExists({ fs: fs3, dir: rootPath, sha: lastSha });
|
|
1344
1401
|
let res;
|
|
1345
1402
|
if (partialReindex && lastSha && exists && sha) {
|
|
1346
1403
|
const pathFilter = {};
|
|
@@ -1354,8 +1411,8 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1354
1411
|
matches: collection.match?.exclude || collection.match?.include ? tinaSchema.getMatches({ collection }) : void 0
|
|
1355
1412
|
};
|
|
1356
1413
|
}
|
|
1357
|
-
const { added, modified, deleted } = await
|
|
1358
|
-
fs:
|
|
1414
|
+
const { added, modified, deleted } = await getChangedFiles({
|
|
1415
|
+
fs: fs3,
|
|
1359
1416
|
dir: rootPath,
|
|
1360
1417
|
from: lastSha,
|
|
1361
1418
|
to: sha,
|
|
@@ -1478,34 +1535,38 @@ var devHTML = (port) => `<!DOCTYPE html>
|
|
|
1478
1535
|
</html>`;
|
|
1479
1536
|
|
|
1480
1537
|
// src/next/commands/dev-command/server/index.ts
|
|
1481
|
-
|
|
1538
|
+
import { createServer as createViteServer } from "vite";
|
|
1482
1539
|
|
|
1483
1540
|
// src/next/vite/index.ts
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1541
|
+
import path5 from "node:path";
|
|
1542
|
+
import react from "@vitejs/plugin-react";
|
|
1543
|
+
import fs4 from "fs-extra";
|
|
1544
|
+
import normalizePath3 from "normalize-path";
|
|
1545
|
+
import {
|
|
1546
|
+
splitVendorChunkPlugin
|
|
1547
|
+
} from "vite";
|
|
1489
1548
|
|
|
1490
1549
|
// src/next/vite/tailwind.ts
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1550
|
+
import path4 from "node:path";
|
|
1551
|
+
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
1552
|
+
import containerQueries from "@tailwindcss/container-queries";
|
|
1553
|
+
import twTypography from "@tailwindcss/typography";
|
|
1554
|
+
import tailwind from "tailwindcss";
|
|
1555
|
+
import defaultTheme from "tailwindcss/defaultTheme.js";
|
|
1556
|
+
import { createRequire as createRequire2 } from "module";
|
|
1497
1557
|
var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
1498
1558
|
return {
|
|
1499
1559
|
name: "vite-plugin-tina",
|
|
1500
1560
|
// @ts-ignore
|
|
1501
1561
|
config: (viteConfig) => {
|
|
1562
|
+
const require2 = createRequire2(import.meta.url);
|
|
1502
1563
|
const plugins = [];
|
|
1503
1564
|
const content = [
|
|
1504
|
-
|
|
1565
|
+
path4.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
1505
1566
|
prebuildFilePath,
|
|
1506
|
-
|
|
1567
|
+
require2.resolve("tinacms")
|
|
1507
1568
|
];
|
|
1508
|
-
const tw = (
|
|
1569
|
+
const tw = tailwind({
|
|
1509
1570
|
theme: {
|
|
1510
1571
|
columns: {
|
|
1511
1572
|
auto: "auto",
|
|
@@ -1693,6 +1754,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1693
1754
|
500: "#EC4815",
|
|
1694
1755
|
600: "#DC4419"
|
|
1695
1756
|
},
|
|
1757
|
+
"tina-orange": "#EC4815",
|
|
1758
|
+
"tina-orange-dark": "#C2410C",
|
|
1759
|
+
"tina-orange-light": "#FFF7ED",
|
|
1696
1760
|
background: "#FFFFFF",
|
|
1697
1761
|
foreground: "#0A0A0A",
|
|
1698
1762
|
muted: "#F5F5F5",
|
|
@@ -1714,7 +1778,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1714
1778
|
ring: "#0A0A0A"
|
|
1715
1779
|
},
|
|
1716
1780
|
fontFamily: {
|
|
1717
|
-
sans: ["Inter", ...
|
|
1781
|
+
sans: ["Inter", ...defaultTheme.fontFamily.sans]
|
|
1718
1782
|
},
|
|
1719
1783
|
lineHeight: {
|
|
1720
1784
|
3: "12px",
|
|
@@ -1739,9 +1803,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1739
1803
|
},
|
|
1740
1804
|
content,
|
|
1741
1805
|
plugins: [
|
|
1742
|
-
(
|
|
1743
|
-
|
|
1744
|
-
|
|
1806
|
+
twTypography({ className: "tina-prose" }),
|
|
1807
|
+
aspectRatio,
|
|
1808
|
+
containerQueries
|
|
1745
1809
|
]
|
|
1746
1810
|
});
|
|
1747
1811
|
plugins.push(tw);
|
|
@@ -1762,35 +1826,35 @@ async function listFilesRecursively({
|
|
|
1762
1826
|
config: config2,
|
|
1763
1827
|
roothPath
|
|
1764
1828
|
}) {
|
|
1765
|
-
const fullDirectoryPath =
|
|
1829
|
+
const fullDirectoryPath = path5.join(
|
|
1766
1830
|
roothPath,
|
|
1767
1831
|
config2.publicFolder,
|
|
1768
1832
|
directoryPath
|
|
1769
1833
|
);
|
|
1770
|
-
const exists = await
|
|
1834
|
+
const exists = await fs4.pathExists(fullDirectoryPath);
|
|
1771
1835
|
if (!exists) {
|
|
1772
1836
|
return { "0": [] };
|
|
1773
1837
|
}
|
|
1774
|
-
const items = await
|
|
1838
|
+
const items = await fs4.readdir(fullDirectoryPath);
|
|
1775
1839
|
const staticMediaItems = [];
|
|
1776
1840
|
for (const item of items) {
|
|
1777
|
-
const itemPath =
|
|
1778
|
-
const stats = await
|
|
1841
|
+
const itemPath = path5.join(fullDirectoryPath, item);
|
|
1842
|
+
const stats = await fs4.promises.lstat(itemPath);
|
|
1779
1843
|
const staticMediaItem = {
|
|
1780
1844
|
id: item,
|
|
1781
1845
|
filename: item,
|
|
1782
1846
|
type: stats.isDirectory() ? "dir" : "file",
|
|
1783
1847
|
directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
|
|
1784
|
-
src: `/${
|
|
1848
|
+
src: `/${path5.join(directoryPath, item)}`,
|
|
1785
1849
|
thumbnails: {
|
|
1786
|
-
"75x75": `/${
|
|
1787
|
-
"400x400": `/${
|
|
1788
|
-
"1000x1000": `/${
|
|
1850
|
+
"75x75": `/${path5.join(directoryPath, item)}`,
|
|
1851
|
+
"400x400": `/${path5.join(directoryPath, item)}`,
|
|
1852
|
+
"1000x1000": `/${path5.join(directoryPath, item)}`
|
|
1789
1853
|
}
|
|
1790
1854
|
};
|
|
1791
1855
|
if (stats.isDirectory()) {
|
|
1792
1856
|
staticMediaItem.children = await listFilesRecursively({
|
|
1793
|
-
directoryPath:
|
|
1857
|
+
directoryPath: path5.join(directoryPath, item),
|
|
1794
1858
|
config: config2,
|
|
1795
1859
|
roothPath
|
|
1796
1860
|
});
|
|
@@ -1831,7 +1895,7 @@ var createConfig = async ({
|
|
|
1831
1895
|
}
|
|
1832
1896
|
}
|
|
1833
1897
|
});
|
|
1834
|
-
const staticMediaPath =
|
|
1898
|
+
const staticMediaPath = path5.join(
|
|
1835
1899
|
configManager.generatedFolderPath,
|
|
1836
1900
|
"static-media.json"
|
|
1837
1901
|
);
|
|
@@ -1841,21 +1905,21 @@ var createConfig = async ({
|
|
|
1841
1905
|
config: configManager.config.media.tina,
|
|
1842
1906
|
roothPath: configManager.rootPath
|
|
1843
1907
|
});
|
|
1844
|
-
await
|
|
1908
|
+
await fs4.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
|
|
1845
1909
|
} else {
|
|
1846
|
-
await
|
|
1910
|
+
await fs4.outputFile(staticMediaPath, `[]`);
|
|
1847
1911
|
}
|
|
1848
1912
|
const alias = {
|
|
1849
1913
|
TINA_IMPORT: configManager.prebuildFilePath,
|
|
1850
1914
|
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
|
|
1851
1915
|
STATIC_MEDIA_IMPORT: staticMediaPath,
|
|
1852
|
-
crypto:
|
|
1853
|
-
fs:
|
|
1854
|
-
os:
|
|
1855
|
-
path:
|
|
1916
|
+
crypto: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1917
|
+
fs: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1918
|
+
os: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1919
|
+
path: path5.join(configManager.spaRootPath, "src", "dummy-client.ts")
|
|
1856
1920
|
};
|
|
1857
1921
|
if (configManager.shouldSkipSDK()) {
|
|
1858
|
-
alias["CLIENT_IMPORT"] =
|
|
1922
|
+
alias["CLIENT_IMPORT"] = path5.join(
|
|
1859
1923
|
configManager.spaRootPath,
|
|
1860
1924
|
"src",
|
|
1861
1925
|
"dummy-client.ts"
|
|
@@ -1871,7 +1935,7 @@ var createConfig = async ({
|
|
|
1871
1935
|
const version2 = `${fullVersion.major}.${fullVersion.minor}`;
|
|
1872
1936
|
const config2 = {
|
|
1873
1937
|
root: configManager.spaRootPath,
|
|
1874
|
-
base: `/${basePath ? `${(
|
|
1938
|
+
base: `/${basePath ? `${normalizePath3(basePath)}/` : ""}${normalizePath3(
|
|
1875
1939
|
configManager.config.build.outputFolder
|
|
1876
1940
|
)}/`,
|
|
1877
1941
|
appType: "spa",
|
|
@@ -1934,14 +1998,14 @@ var createConfig = async ({
|
|
|
1934
1998
|
* `splitVendorChunkPlugin` is needed because `tinacms` is quite large,
|
|
1935
1999
|
* Vite's chunking strategy chokes on memory issues for smaller machines (ie. on CI).
|
|
1936
2000
|
*/
|
|
1937
|
-
(
|
|
2001
|
+
react({
|
|
1938
2002
|
babel: {
|
|
1939
2003
|
// Supresses the warning [NOTE] babel The code generator has deoptimised the styling of
|
|
1940
2004
|
compact: true
|
|
1941
2005
|
},
|
|
1942
2006
|
fastRefresh: false
|
|
1943
2007
|
}),
|
|
1944
|
-
|
|
2008
|
+
splitVendorChunkPlugin(),
|
|
1945
2009
|
tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
|
|
1946
2010
|
...plugins
|
|
1947
2011
|
]
|
|
@@ -1950,21 +2014,21 @@ var createConfig = async ({
|
|
|
1950
2014
|
};
|
|
1951
2015
|
|
|
1952
2016
|
// src/next/vite/plugins.ts
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2017
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
2018
|
+
import fs6 from "fs";
|
|
2019
|
+
import { transformWithEsbuild } from "vite";
|
|
2020
|
+
import { transform as esbuildTransform } from "esbuild";
|
|
2021
|
+
import path7 from "path";
|
|
2022
|
+
import bodyParser from "body-parser";
|
|
2023
|
+
import cors from "cors";
|
|
2024
|
+
import { resolve as gqlResolve } from "@tinacms/graphql";
|
|
1961
2025
|
|
|
1962
2026
|
// src/next/commands/dev-command/server/media.ts
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2027
|
+
import fs5 from "fs-extra";
|
|
2028
|
+
import path6, { join } from "path";
|
|
2029
|
+
import busboy from "busboy";
|
|
1966
2030
|
var createMediaRouter = (config2) => {
|
|
1967
|
-
const mediaFolder =
|
|
2031
|
+
const mediaFolder = path6.join(
|
|
1968
2032
|
config2.rootPath,
|
|
1969
2033
|
config2.publicFolder,
|
|
1970
2034
|
config2.mediaRoot
|
|
@@ -1988,12 +2052,12 @@ var createMediaRouter = (config2) => {
|
|
|
1988
2052
|
res.end(JSON.stringify(didDelete));
|
|
1989
2053
|
};
|
|
1990
2054
|
const handlePost = async function(req, res) {
|
|
1991
|
-
const bb = (
|
|
2055
|
+
const bb = busboy({ headers: req.headers });
|
|
1992
2056
|
bb.on("file", async (_name, file, _info) => {
|
|
1993
2057
|
const fullPath = decodeURI(req.url?.slice("/media/upload/".length));
|
|
1994
|
-
const saveTo =
|
|
1995
|
-
await
|
|
1996
|
-
file.pipe(
|
|
2058
|
+
const saveTo = path6.join(mediaFolder, ...fullPath.split("/"));
|
|
2059
|
+
await fs5.ensureDir(path6.dirname(saveTo));
|
|
2060
|
+
file.pipe(fs5.createWriteStream(saveTo));
|
|
1997
2061
|
});
|
|
1998
2062
|
bb.on("error", (error) => {
|
|
1999
2063
|
res.statusCode = 500;
|
|
@@ -2019,6 +2083,9 @@ var parseMediaFolder = (str) => {
|
|
|
2019
2083
|
return returnString;
|
|
2020
2084
|
};
|
|
2021
2085
|
var MediaModel = class {
|
|
2086
|
+
rootPath;
|
|
2087
|
+
publicFolder;
|
|
2088
|
+
mediaRoot;
|
|
2022
2089
|
constructor({ rootPath, publicFolder, mediaRoot }) {
|
|
2023
2090
|
this.rootPath = rootPath;
|
|
2024
2091
|
this.mediaRoot = mediaRoot;
|
|
@@ -2026,23 +2093,23 @@ var MediaModel = class {
|
|
|
2026
2093
|
}
|
|
2027
2094
|
async listMedia(args) {
|
|
2028
2095
|
try {
|
|
2029
|
-
const folderPath =
|
|
2096
|
+
const folderPath = join(
|
|
2030
2097
|
this.rootPath,
|
|
2031
2098
|
this.publicFolder,
|
|
2032
2099
|
this.mediaRoot,
|
|
2033
2100
|
decodeURIComponent(args.searchPath)
|
|
2034
2101
|
);
|
|
2035
2102
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
2036
|
-
if (!await
|
|
2103
|
+
if (!await fs5.pathExists(folderPath)) {
|
|
2037
2104
|
return {
|
|
2038
2105
|
files: [],
|
|
2039
2106
|
directories: []
|
|
2040
2107
|
};
|
|
2041
2108
|
}
|
|
2042
|
-
const filesStr = await
|
|
2109
|
+
const filesStr = await fs5.readdir(folderPath);
|
|
2043
2110
|
const filesProm = filesStr.map(async (file) => {
|
|
2044
|
-
const filePath =
|
|
2045
|
-
const stat = await
|
|
2111
|
+
const filePath = join(folderPath, file);
|
|
2112
|
+
const stat = await fs5.stat(filePath);
|
|
2046
2113
|
let src = `/${file}`;
|
|
2047
2114
|
const isFile = stat.isFile();
|
|
2048
2115
|
if (!isFile) {
|
|
@@ -2098,14 +2165,14 @@ var MediaModel = class {
|
|
|
2098
2165
|
}
|
|
2099
2166
|
async deleteMedia(args) {
|
|
2100
2167
|
try {
|
|
2101
|
-
const file =
|
|
2168
|
+
const file = join(
|
|
2102
2169
|
this.rootPath,
|
|
2103
2170
|
this.publicFolder,
|
|
2104
2171
|
this.mediaRoot,
|
|
2105
2172
|
decodeURIComponent(args.searchPath)
|
|
2106
2173
|
);
|
|
2107
|
-
await
|
|
2108
|
-
await
|
|
2174
|
+
await fs5.stat(file);
|
|
2175
|
+
await fs5.remove(file);
|
|
2109
2176
|
return { ok: true };
|
|
2110
2177
|
} catch (error) {
|
|
2111
2178
|
console.error(error);
|
|
@@ -2163,9 +2230,9 @@ var transformTsxPlugin = ({
|
|
|
2163
2230
|
const plug = {
|
|
2164
2231
|
name: "transform-tsx",
|
|
2165
2232
|
async transform(code, id) {
|
|
2166
|
-
const extName =
|
|
2233
|
+
const extName = path7.extname(id);
|
|
2167
2234
|
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
2168
|
-
const result = await (
|
|
2235
|
+
const result = await esbuildTransform(code, { loader: "tsx" });
|
|
2169
2236
|
return {
|
|
2170
2237
|
code: result.code
|
|
2171
2238
|
};
|
|
@@ -2184,8 +2251,8 @@ var devServerEndPointsPlugin = ({
|
|
|
2184
2251
|
const plug = {
|
|
2185
2252
|
name: "graphql-endpoints",
|
|
2186
2253
|
configureServer(server) {
|
|
2187
|
-
server.middlewares.use((
|
|
2188
|
-
server.middlewares.use(
|
|
2254
|
+
server.middlewares.use(cors());
|
|
2255
|
+
server.middlewares.use(bodyParser.json({ limit: "5mb" }));
|
|
2189
2256
|
server.middlewares.use(async (req, res, next) => {
|
|
2190
2257
|
const mediaPaths = configManager.config.media?.tina;
|
|
2191
2258
|
const mediaRouter = createMediaRouter({
|
|
@@ -2224,7 +2291,7 @@ var devServerEndPointsPlugin = ({
|
|
|
2224
2291
|
const { query, variables } = req.body;
|
|
2225
2292
|
let result;
|
|
2226
2293
|
await databaseLock(async () => {
|
|
2227
|
-
result = await (
|
|
2294
|
+
result = await gqlResolve({
|
|
2228
2295
|
config: {
|
|
2229
2296
|
useRelativeMedia: true
|
|
2230
2297
|
},
|
|
@@ -2260,13 +2327,13 @@ function viteTransformExtension({
|
|
|
2260
2327
|
include = "**/*.svg",
|
|
2261
2328
|
exclude
|
|
2262
2329
|
} = {}) {
|
|
2263
|
-
const filter =
|
|
2330
|
+
const filter = createFilter(include, exclude);
|
|
2264
2331
|
return {
|
|
2265
2332
|
name: "vite-plugin-svgr",
|
|
2266
2333
|
async transform(code, id) {
|
|
2267
2334
|
if (filter(id)) {
|
|
2268
2335
|
const { transform: transform2 } = await import("@svgr/core");
|
|
2269
|
-
const svgCode = await
|
|
2336
|
+
const svgCode = await fs6.promises.readFile(
|
|
2270
2337
|
id.replace(/\?.*$/, ""),
|
|
2271
2338
|
"utf8"
|
|
2272
2339
|
);
|
|
@@ -2276,7 +2343,7 @@ function viteTransformExtension({
|
|
|
2276
2343
|
previousExport: exportAsDefault ? null : code
|
|
2277
2344
|
}
|
|
2278
2345
|
});
|
|
2279
|
-
const res = await
|
|
2346
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
2280
2347
|
loader: "jsx",
|
|
2281
2348
|
...esbuildOptions
|
|
2282
2349
|
});
|
|
@@ -2303,7 +2370,7 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2303
2370
|
}),
|
|
2304
2371
|
viteTransformExtension()
|
|
2305
2372
|
];
|
|
2306
|
-
return (
|
|
2373
|
+
return createViteServer(
|
|
2307
2374
|
await createConfig({
|
|
2308
2375
|
configManager,
|
|
2309
2376
|
database,
|
|
@@ -2333,37 +2400,30 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2333
2400
|
|
|
2334
2401
|
// src/next/commands/dev-command/index.ts
|
|
2335
2402
|
var DevCommand = class extends BaseCommand {
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
this
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
description: `Builds Tina and starts the dev server`,
|
|
2361
|
-
examples: [
|
|
2362
|
-
[`A basic example`, `$0 dev`],
|
|
2363
|
-
[`A second example`, `$0 dev --rootPath`]
|
|
2364
|
-
]
|
|
2365
|
-
});
|
|
2366
|
-
}
|
|
2403
|
+
static paths = [["dev"], ["server:start"]];
|
|
2404
|
+
// NOTE: camelCase commands for string options don't work if there's an `=` used https://github.com/arcanis/clipanion/issues/141
|
|
2405
|
+
watchFolders = Option2.String("-w,--watchFolders", {
|
|
2406
|
+
description: "DEPRECATED - a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
2407
|
+
});
|
|
2408
|
+
noWatch = Option2.Boolean("--noWatch", false, {
|
|
2409
|
+
description: "Don't regenerate config on file changes"
|
|
2410
|
+
});
|
|
2411
|
+
outputSearchIndexPath = Option2.String("--outputSearchIndexPath", {
|
|
2412
|
+
description: "Path to write the search index to"
|
|
2413
|
+
});
|
|
2414
|
+
noServer = Option2.Boolean("--no-server", false, {
|
|
2415
|
+
description: "Do not start the dev server"
|
|
2416
|
+
});
|
|
2417
|
+
indexingLock = new AsyncLock();
|
|
2418
|
+
// Prevent indexes and reads occurring at once
|
|
2419
|
+
static usage = Command2.Usage({
|
|
2420
|
+
category: `Commands`,
|
|
2421
|
+
description: `Builds Tina and starts the dev server`,
|
|
2422
|
+
examples: [
|
|
2423
|
+
[`A basic example`, `$0 dev`],
|
|
2424
|
+
[`A second example`, `$0 dev --rootPath`]
|
|
2425
|
+
]
|
|
2426
|
+
});
|
|
2367
2427
|
async catch(error) {
|
|
2368
2428
|
logger.error("Error occured during tinacms dev");
|
|
2369
2429
|
console.error(error);
|
|
@@ -2400,7 +2460,7 @@ var DevCommand = class extends BaseCommand {
|
|
|
2400
2460
|
} else {
|
|
2401
2461
|
database.clearCache();
|
|
2402
2462
|
}
|
|
2403
|
-
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await
|
|
2463
|
+
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await buildSchema(configManager.config);
|
|
2404
2464
|
const codegen2 = new Codegen({
|
|
2405
2465
|
isLocal: true,
|
|
2406
2466
|
configManager,
|
|
@@ -2414,29 +2474,32 @@ var DevCommand = class extends BaseCommand {
|
|
|
2414
2474
|
});
|
|
2415
2475
|
const apiURL2 = await codegen2.execute();
|
|
2416
2476
|
if (!configManager.isUsingLegacyFolder) {
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
const
|
|
2421
|
-
|
|
2422
|
-
|
|
2477
|
+
const schemaObject = await fs7.readJSON(
|
|
2478
|
+
configManager.generatedSchemaJSONPath
|
|
2479
|
+
);
|
|
2480
|
+
const lookupObject = await fs7.readJSON(
|
|
2481
|
+
configManager.generatedLookupJSONPath
|
|
2482
|
+
);
|
|
2483
|
+
const graphqlSchemaObject = await fs7.readJSON(
|
|
2484
|
+
configManager.generatedGraphQLJSONPath
|
|
2485
|
+
);
|
|
2423
2486
|
const tinaLockFilename = "tina-lock.json";
|
|
2424
2487
|
const tinaLockContent = JSON.stringify({
|
|
2425
2488
|
schema: schemaObject,
|
|
2426
2489
|
lookup: lookupObject,
|
|
2427
2490
|
graphql: graphqlSchemaObject
|
|
2428
2491
|
});
|
|
2429
|
-
|
|
2430
|
-
|
|
2492
|
+
fs7.writeFileSync(
|
|
2493
|
+
path8.join(configManager.tinaFolderPath, tinaLockFilename),
|
|
2431
2494
|
tinaLockContent
|
|
2432
2495
|
);
|
|
2433
2496
|
if (configManager.hasSeparateContentRoot()) {
|
|
2434
2497
|
const rootPath = await configManager.getTinaFolderPath(
|
|
2435
2498
|
configManager.contentRootPath
|
|
2436
2499
|
);
|
|
2437
|
-
const filePath =
|
|
2438
|
-
await
|
|
2439
|
-
await
|
|
2500
|
+
const filePath = path8.join(rootPath, tinaLockFilename);
|
|
2501
|
+
await fs7.ensureFile(filePath);
|
|
2502
|
+
await fs7.outputFile(filePath, tinaLockContent);
|
|
2440
2503
|
}
|
|
2441
2504
|
}
|
|
2442
2505
|
await this.indexContentWithSpinner({
|
|
@@ -2479,19 +2542,19 @@ ${dangerText(e.message)}
|
|
|
2479
2542
|
const { apiURL, graphQLSchema, tinaSchema } = await setup({
|
|
2480
2543
|
firstTime: true
|
|
2481
2544
|
});
|
|
2482
|
-
await
|
|
2483
|
-
await
|
|
2545
|
+
await fs7.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
2546
|
+
await fs7.outputFile(
|
|
2484
2547
|
configManager.outputGitignorePath,
|
|
2485
2548
|
"index.html\nassets/"
|
|
2486
2549
|
);
|
|
2487
|
-
const searchIndexClient = new
|
|
2550
|
+
const searchIndexClient = new LocalSearchIndexClient({
|
|
2488
2551
|
stopwordLanguages: configManager.config.search?.tina?.stopwordLanguages,
|
|
2489
2552
|
tokenSplitRegex: configManager.config.search?.tina?.tokenSplitRegex
|
|
2490
2553
|
});
|
|
2491
2554
|
await searchIndexClient.onStartIndexing();
|
|
2492
|
-
const searchIndexer = new
|
|
2555
|
+
const searchIndexer = new SearchIndexer({
|
|
2493
2556
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
2494
|
-
bridge: new
|
|
2557
|
+
bridge: new FilesystemBridge2(
|
|
2495
2558
|
configManager.rootPath,
|
|
2496
2559
|
configManager.contentRootPath
|
|
2497
2560
|
),
|
|
@@ -2532,7 +2595,7 @@ ${dangerText(e.message)}
|
|
|
2532
2595
|
);
|
|
2533
2596
|
await server.listen(Number(this.port));
|
|
2534
2597
|
if (!this.noWatch) {
|
|
2535
|
-
|
|
2598
|
+
chokidar.watch(configManager.watchList).on("change", async () => {
|
|
2536
2599
|
await dbLock(async () => {
|
|
2537
2600
|
logger.info(`Tina config change detected, rebuilding`);
|
|
2538
2601
|
await setup({ firstTime: false });
|
|
@@ -2609,14 +2672,14 @@ ${dangerText(e.message)}
|
|
|
2609
2672
|
watchContentFiles(configManager, database, databaseLock, searchIndexer) {
|
|
2610
2673
|
const collectionContentFiles = [];
|
|
2611
2674
|
configManager.config.schema.collections.forEach((collection) => {
|
|
2612
|
-
const collectionGlob = `${
|
|
2675
|
+
const collectionGlob = `${path8.join(
|
|
2613
2676
|
configManager.contentRootPath,
|
|
2614
2677
|
collection.path
|
|
2615
2678
|
)}/**/*.${collection.format || "md"}`;
|
|
2616
2679
|
collectionContentFiles.push(collectionGlob);
|
|
2617
2680
|
});
|
|
2618
2681
|
let ready = false;
|
|
2619
|
-
|
|
2682
|
+
chokidar.watch(collectionContentFiles).on("ready", () => {
|
|
2620
2683
|
ready = true;
|
|
2621
2684
|
}).on("add", async (addedFile) => {
|
|
2622
2685
|
if (!ready) {
|
|
@@ -2653,27 +2716,34 @@ ${dangerText(e.message)}
|
|
|
2653
2716
|
await callback();
|
|
2654
2717
|
});
|
|
2655
2718
|
};
|
|
2656
|
-
|
|
2719
|
+
chokidar.watch(configManager.userQueriesAndFragmentsGlob).on("add", executeCallback).on("change", executeCallback).on("unlink", executeCallback);
|
|
2657
2720
|
}
|
|
2658
2721
|
};
|
|
2659
2722
|
|
|
2660
2723
|
// src/next/commands/build-command/index.ts
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2724
|
+
import crypto from "crypto";
|
|
2725
|
+
import path9 from "path";
|
|
2726
|
+
import { diff } from "@graphql-inspector/core";
|
|
2727
|
+
import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
|
|
2728
|
+
import { parseURL as parseURL2 } from "@tinacms/schema-tools";
|
|
2729
|
+
import {
|
|
2730
|
+
SearchIndexer as SearchIndexer2,
|
|
2731
|
+
TinaCMSSearchIndexClient
|
|
2732
|
+
} from "@tinacms/search";
|
|
2733
|
+
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
2734
|
+
import fs8 from "fs-extra";
|
|
2735
|
+
import {
|
|
2736
|
+
buildASTSchema as buildASTSchema2,
|
|
2737
|
+
buildClientSchema,
|
|
2738
|
+
getIntrospectionQuery
|
|
2739
|
+
} from "graphql";
|
|
2740
|
+
import Progress2 from "progress";
|
|
2671
2741
|
|
|
2672
2742
|
// src/utils/index.ts
|
|
2673
|
-
|
|
2743
|
+
import { ChangeType } from "@graphql-inspector/core";
|
|
2674
2744
|
var getFaqLink = (type) => {
|
|
2675
2745
|
switch (type) {
|
|
2676
|
-
case
|
|
2746
|
+
case ChangeType.FieldRemoved: {
|
|
2677
2747
|
return "https://tina.io/docs/r/FAQ/#2-how-do-i-resolve-the-local-graphql-schema-doesnt-match-the-remote-graphql-schema-error";
|
|
2678
2748
|
}
|
|
2679
2749
|
default:
|
|
@@ -2695,7 +2765,7 @@ async function sleepAndCallFunc({
|
|
|
2695
2765
|
}
|
|
2696
2766
|
|
|
2697
2767
|
// src/next/commands/build-command/server.ts
|
|
2698
|
-
|
|
2768
|
+
import { build as build2 } from "vite";
|
|
2699
2769
|
var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
2700
2770
|
const publicEnv = {};
|
|
2701
2771
|
Object.keys(process.env).forEach((key) => {
|
|
@@ -2729,12 +2799,12 @@ var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
|
2729
2799
|
}
|
|
2730
2800
|
}
|
|
2731
2801
|
});
|
|
2732
|
-
return (
|
|
2802
|
+
return build2(config2);
|
|
2733
2803
|
};
|
|
2734
2804
|
|
|
2735
2805
|
// src/next/commands/build-command/waitForDB.ts
|
|
2736
|
-
|
|
2737
|
-
|
|
2806
|
+
import { parseURL } from "@tinacms/schema-tools";
|
|
2807
|
+
import Progress from "progress";
|
|
2738
2808
|
var POLLING_INTERVAL = 5e3;
|
|
2739
2809
|
var STATUS_INPROGRESS = "inprogress";
|
|
2740
2810
|
var STATUS_COMPLETE = "complete";
|
|
@@ -2747,14 +2817,14 @@ var IndexFailedError = class extends Error {
|
|
|
2747
2817
|
};
|
|
2748
2818
|
var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
2749
2819
|
const token = config2.token;
|
|
2750
|
-
const { clientId, branch, isLocalClient, host } =
|
|
2820
|
+
const { clientId, branch, isLocalClient, host } = parseURL(apiUrl);
|
|
2751
2821
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
2752
2822
|
if (verbose) {
|
|
2753
2823
|
logger.info(logText("Not using TinaCloud, skipping DB check"));
|
|
2754
2824
|
}
|
|
2755
2825
|
return;
|
|
2756
2826
|
}
|
|
2757
|
-
const bar2 = new
|
|
2827
|
+
const bar2 = new Progress(
|
|
2758
2828
|
"Checking indexing process in TinaCloud... :prog",
|
|
2759
2829
|
1
|
|
2760
2830
|
);
|
|
@@ -2817,51 +2887,44 @@ var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
|
2817
2887
|
|
|
2818
2888
|
// src/next/commands/build-command/index.ts
|
|
2819
2889
|
var BuildCommand = class extends BaseCommand {
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
}
|
|
2859
|
-
static {
|
|
2860
|
-
this.usage = import_clipanion3.Command.Usage({
|
|
2861
|
-
category: `Commands`,
|
|
2862
|
-
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2863
|
-
});
|
|
2864
|
-
}
|
|
2890
|
+
static paths = [["build"]];
|
|
2891
|
+
localOption = Option3.Boolean("--local", {
|
|
2892
|
+
description: "Starts local Graphql server and builds the local client instead of production client"
|
|
2893
|
+
});
|
|
2894
|
+
skipIndexing = Option3.Boolean("--skip-indexing", false, {
|
|
2895
|
+
description: "Skips indexing the content. This can be used for building the site without indexing the content (defaults to false)"
|
|
2896
|
+
});
|
|
2897
|
+
partialReindex = Option3.Boolean("--partial-reindex", false, {
|
|
2898
|
+
description: "Re-indexes only the content that has changed since the last build (defaults to false). Not currently supported for separate content repos."
|
|
2899
|
+
});
|
|
2900
|
+
tinaGraphQLVersion = Option3.String("--tina-graphql-version", {
|
|
2901
|
+
description: "Specify the version of @tinacms/graphql to use (defaults to latest)"
|
|
2902
|
+
});
|
|
2903
|
+
/**
|
|
2904
|
+
* This option allows the user to skip the TinaCloud checks if they want to. This could be useful for mismatched GraphQL versions or if they want to build only using the local client and never connect to TinaCloud
|
|
2905
|
+
*/
|
|
2906
|
+
skipCloudChecks = Option3.Boolean("--skip-cloud-checks", false, {
|
|
2907
|
+
description: "Skips checking the provided cloud config."
|
|
2908
|
+
});
|
|
2909
|
+
skipSearchIndex = Option3.Boolean("--skip-search-index", false, {
|
|
2910
|
+
description: "Skip indexing the site for search"
|
|
2911
|
+
});
|
|
2912
|
+
upstreamBranch = Option3.String("--upstream-branch", {
|
|
2913
|
+
description: "Optional upstream branch with the schema. If not specified, default will be used."
|
|
2914
|
+
});
|
|
2915
|
+
previewBaseBranch = Option3.String("--preview-base-branch", {
|
|
2916
|
+
description: "The base branch for the preview"
|
|
2917
|
+
});
|
|
2918
|
+
previewName = Option3.String("--preview-name", {
|
|
2919
|
+
description: "The name of the preview branch"
|
|
2920
|
+
});
|
|
2921
|
+
noClientBuildCache = Option3.Boolean("--no-client-build-cache", false, {
|
|
2922
|
+
description: "Disables the client build cache"
|
|
2923
|
+
});
|
|
2924
|
+
static usage = Command3.Usage({
|
|
2925
|
+
category: `Commands`,
|
|
2926
|
+
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2927
|
+
});
|
|
2865
2928
|
async catch(error) {
|
|
2866
2929
|
console.error(error);
|
|
2867
2930
|
process.exit(1);
|
|
@@ -2906,7 +2969,7 @@ ${dangerText(e.message)}`);
|
|
|
2906
2969
|
configManager,
|
|
2907
2970
|
Number(this.datalayerPort)
|
|
2908
2971
|
);
|
|
2909
|
-
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await (
|
|
2972
|
+
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await buildSchema2(configManager.config);
|
|
2910
2973
|
const codegen2 = new Codegen({
|
|
2911
2974
|
configManager,
|
|
2912
2975
|
port: this.localOption ? Number(this.port) : void 0,
|
|
@@ -3014,7 +3077,7 @@ ${dangerText(e.message)}
|
|
|
3014
3077
|
}
|
|
3015
3078
|
}
|
|
3016
3079
|
await buildProductionSpa(configManager, database, codegen2.productionUrl);
|
|
3017
|
-
await
|
|
3080
|
+
await fs8.outputFile(
|
|
3018
3081
|
configManager.outputGitignorePath,
|
|
3019
3082
|
"index.html\nassets/"
|
|
3020
3083
|
);
|
|
@@ -3046,7 +3109,7 @@ ${dangerText(e.message)}
|
|
|
3046
3109
|
"indexerToken not configured in tina search configuration."
|
|
3047
3110
|
);
|
|
3048
3111
|
}
|
|
3049
|
-
client = new
|
|
3112
|
+
client = new TinaCMSSearchIndexClient({
|
|
3050
3113
|
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
3051
3114
|
branch: configManager.config?.branch,
|
|
3052
3115
|
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
@@ -3055,9 +3118,9 @@ ${dangerText(e.message)}
|
|
|
3055
3118
|
} else {
|
|
3056
3119
|
client = configManager.config?.search?.searchClient;
|
|
3057
3120
|
}
|
|
3058
|
-
const searchIndexer = new
|
|
3121
|
+
const searchIndexer = new SearchIndexer2({
|
|
3059
3122
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
3060
|
-
bridge: new
|
|
3123
|
+
bridge: new FilesystemBridge3(
|
|
3061
3124
|
configManager.rootPath,
|
|
3062
3125
|
configManager.contentRootPath
|
|
3063
3126
|
),
|
|
@@ -3127,8 +3190,8 @@ ${dangerText(e.message)}
|
|
|
3127
3190
|
const MAX_RETRIES = 5;
|
|
3128
3191
|
const { config: config2 } = configManager;
|
|
3129
3192
|
const token = config2.token;
|
|
3130
|
-
const { clientId, branch, host } = (
|
|
3131
|
-
const bar2 = new
|
|
3193
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3194
|
+
const bar2 = new Progress2("Checking clientId and token. :prog", 1);
|
|
3132
3195
|
const getBranchInfo = async () => {
|
|
3133
3196
|
const url = `https://${host}/db/${clientId}/status/${previewBaseBranch || branch}`;
|
|
3134
3197
|
const branchInfo2 = {
|
|
@@ -3182,7 +3245,7 @@ ${dangerText(e.message)}
|
|
|
3182
3245
|
bar2.tick({
|
|
3183
3246
|
prog: "\u2705"
|
|
3184
3247
|
});
|
|
3185
|
-
const branchBar = new
|
|
3248
|
+
const branchBar = new Progress2(
|
|
3186
3249
|
`Checking branch '${config2.branch}' is on TinaCloud. :prog`,
|
|
3187
3250
|
1
|
|
3188
3251
|
);
|
|
@@ -3222,7 +3285,7 @@ ${dangerText(e.message)}
|
|
|
3222
3285
|
async syncProject(configManager, apiURL, options) {
|
|
3223
3286
|
const { config: config2 } = configManager;
|
|
3224
3287
|
const token = config2.token;
|
|
3225
|
-
const { clientId, branch, host } = (
|
|
3288
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3226
3289
|
const { previewName, previewBaseBranch, upstreamBranch } = options || {};
|
|
3227
3290
|
let url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true`;
|
|
3228
3291
|
if (upstreamBranch && previewBaseBranch && previewName) {
|
|
@@ -3232,7 +3295,7 @@ ${dangerText(e.message)}
|
|
|
3232
3295
|
} else if (upstreamBranch && !previewBaseBranch && !previewName) {
|
|
3233
3296
|
url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true&upstreamBranch=${upstreamBranch}`;
|
|
3234
3297
|
}
|
|
3235
|
-
const bar2 = new
|
|
3298
|
+
const bar2 = new Progress2("Syncing Project. :prog", 1);
|
|
3236
3299
|
try {
|
|
3237
3300
|
const res = await request({
|
|
3238
3301
|
token,
|
|
@@ -3273,7 +3336,7 @@ ${dangerText(e.message)}
|
|
|
3273
3336
|
}
|
|
3274
3337
|
}
|
|
3275
3338
|
async checkGraphqlSchema(configManager, database, apiURL, timestamp) {
|
|
3276
|
-
const bar2 = new
|
|
3339
|
+
const bar2 = new Progress2(
|
|
3277
3340
|
"Checking local GraphQL Schema matches server. :prog",
|
|
3278
3341
|
1
|
|
3279
3342
|
);
|
|
@@ -3295,11 +3358,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3295
3358
|
}
|
|
3296
3359
|
throw new Error(errorMessage);
|
|
3297
3360
|
}
|
|
3298
|
-
const remoteGqlSchema =
|
|
3361
|
+
const remoteGqlSchema = buildClientSchema(remoteSchema);
|
|
3299
3362
|
const localSchemaDocument = await database.getGraphQLSchemaFromBridge();
|
|
3300
|
-
const localGraphqlSchema = (
|
|
3363
|
+
const localGraphqlSchema = buildASTSchema2(localSchemaDocument);
|
|
3301
3364
|
try {
|
|
3302
|
-
const diffResult = await
|
|
3365
|
+
const diffResult = await diff(remoteGqlSchema, localGraphqlSchema);
|
|
3303
3366
|
if (diffResult.length === 0) {
|
|
3304
3367
|
bar2.tick({
|
|
3305
3368
|
prog: "\u2705"
|
|
@@ -3347,13 +3410,13 @@ Additional info:
|
|
|
3347
3410
|
}
|
|
3348
3411
|
}
|
|
3349
3412
|
async checkTinaSchema(configManager, database, apiURL, previewName, verbose, timestamp) {
|
|
3350
|
-
const bar2 = new
|
|
3413
|
+
const bar2 = new Progress2(
|
|
3351
3414
|
"Checking local Tina Schema matches server. :prog",
|
|
3352
3415
|
1
|
|
3353
3416
|
);
|
|
3354
3417
|
const { config: config2 } = configManager;
|
|
3355
3418
|
const token = config2.token;
|
|
3356
|
-
const { clientId, branch, isLocalClient, host } = (
|
|
3419
|
+
const { clientId, branch, isLocalClient, host } = parseURL2(apiURL);
|
|
3357
3420
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
3358
3421
|
if (verbose) {
|
|
3359
3422
|
logger.info(logText("Not using TinaCloud, skipping Tina Schema check"));
|
|
@@ -3381,11 +3444,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3381
3444
|
}
|
|
3382
3445
|
const localTinaSchema = JSON.parse(
|
|
3383
3446
|
await database.bridge.get(
|
|
3384
|
-
|
|
3447
|
+
path9.join(database.tinaDirectory, "__generated__", "_schema.json")
|
|
3385
3448
|
)
|
|
3386
3449
|
);
|
|
3387
3450
|
localTinaSchema.version = void 0;
|
|
3388
|
-
const localTinaSchemaSha =
|
|
3451
|
+
const localTinaSchemaSha = crypto.createHash("sha256").update(JSON.stringify(localTinaSchema)).digest("hex");
|
|
3389
3452
|
if (localTinaSchemaSha === remoteTinaSchemaSha) {
|
|
3390
3453
|
bar2.tick({
|
|
3391
3454
|
prog: "\u2705"
|
|
@@ -3463,7 +3526,7 @@ var fetchRemoteGraphqlSchema = async ({
|
|
|
3463
3526
|
headers.append("X-API-KEY", token);
|
|
3464
3527
|
}
|
|
3465
3528
|
const body = JSON.stringify({
|
|
3466
|
-
query:
|
|
3529
|
+
query: getIntrospectionQuery(),
|
|
3467
3530
|
variables: {}
|
|
3468
3531
|
});
|
|
3469
3532
|
headers.append("Content-Type", "application/json");
|
|
@@ -3496,14 +3559,14 @@ var fetchSchemaSha = async ({
|
|
|
3496
3559
|
};
|
|
3497
3560
|
|
|
3498
3561
|
// src/next/commands/audit-command/index.ts
|
|
3499
|
-
|
|
3500
|
-
|
|
3562
|
+
import { Command as Command4, Option as Option4 } from "clipanion";
|
|
3563
|
+
import { buildSchema as buildSchema3 } from "@tinacms/graphql";
|
|
3501
3564
|
|
|
3502
3565
|
// src/next/commands/audit-command/audit.ts
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3566
|
+
import prompts from "prompts";
|
|
3567
|
+
import { Telemetry } from "@tinacms/metrics";
|
|
3568
|
+
import { resolve } from "@tinacms/graphql";
|
|
3569
|
+
import chalk5 from "chalk";
|
|
3507
3570
|
var audit = async ({
|
|
3508
3571
|
database,
|
|
3509
3572
|
clean,
|
|
@@ -3511,7 +3574,7 @@ var audit = async ({
|
|
|
3511
3574
|
noTelemetry,
|
|
3512
3575
|
verbose
|
|
3513
3576
|
}) => {
|
|
3514
|
-
const telemetry = new
|
|
3577
|
+
const telemetry = new Telemetry({ disabled: noTelemetry });
|
|
3515
3578
|
await telemetry.submitRecord({
|
|
3516
3579
|
event: {
|
|
3517
3580
|
name: "tinacms:cli:audit:invoke",
|
|
@@ -3521,25 +3584,25 @@ var audit = async ({
|
|
|
3521
3584
|
});
|
|
3522
3585
|
if (clean) {
|
|
3523
3586
|
logger.info(
|
|
3524
|
-
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${
|
|
3587
|
+
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${chalk5.bold(
|
|
3525
3588
|
"clean git tree"
|
|
3526
3589
|
)} so unwanted changes can be undone.
|
|
3527
3590
|
|
|
3528
3591
|
`
|
|
3529
3592
|
);
|
|
3530
|
-
const res = await (
|
|
3593
|
+
const res = await prompts({
|
|
3531
3594
|
name: "useClean",
|
|
3532
3595
|
type: "confirm",
|
|
3533
3596
|
message: `Do you want to continue?`
|
|
3534
3597
|
});
|
|
3535
3598
|
if (!res.useClean) {
|
|
3536
|
-
logger.warn(
|
|
3599
|
+
logger.warn(chalk5.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
3537
3600
|
process.exit(0);
|
|
3538
3601
|
}
|
|
3539
3602
|
}
|
|
3540
3603
|
if (useDefaultValues && !clean) {
|
|
3541
3604
|
logger.warn(
|
|
3542
|
-
|
|
3605
|
+
chalk5.yellowBright(
|
|
3543
3606
|
"WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"
|
|
3544
3607
|
)
|
|
3545
3608
|
);
|
|
@@ -3567,10 +3630,10 @@ var audit = async ({
|
|
|
3567
3630
|
}
|
|
3568
3631
|
if (error) {
|
|
3569
3632
|
logger.error(
|
|
3570
|
-
|
|
3633
|
+
chalk5.redBright(`\u203C\uFE0F Audit ${chalk5.bold("failed")} with errors`)
|
|
3571
3634
|
);
|
|
3572
3635
|
} else {
|
|
3573
|
-
logger.info(
|
|
3636
|
+
logger.info(chalk5.greenBright("\u2705 Audit passed"));
|
|
3574
3637
|
}
|
|
3575
3638
|
};
|
|
3576
3639
|
var auditDocuments = async (args) => {
|
|
@@ -3587,7 +3650,7 @@ var auditDocuments = async (args) => {
|
|
|
3587
3650
|
}
|
|
3588
3651
|
}
|
|
3589
3652
|
}`;
|
|
3590
|
-
const docResult = await
|
|
3653
|
+
const docResult = await resolve({
|
|
3591
3654
|
database,
|
|
3592
3655
|
query: documentQuery,
|
|
3593
3656
|
variables: {},
|
|
@@ -3598,11 +3661,11 @@ var auditDocuments = async (args) => {
|
|
|
3598
3661
|
if (docResult.errors) {
|
|
3599
3662
|
error = true;
|
|
3600
3663
|
docResult.errors.forEach((err) => {
|
|
3601
|
-
logger.error(
|
|
3664
|
+
logger.error(chalk5.red(err.message));
|
|
3602
3665
|
if (err.originalError.originalError) {
|
|
3603
3666
|
logger.error(
|
|
3604
3667
|
// @ts-ignore FIXME: this doesn't seem right
|
|
3605
|
-
|
|
3668
|
+
chalk5.red(` ${err.originalError.originalError.message}`)
|
|
3606
3669
|
);
|
|
3607
3670
|
}
|
|
3608
3671
|
});
|
|
@@ -3629,7 +3692,7 @@ var auditDocuments = async (args) => {
|
|
|
3629
3692
|
params: $params
|
|
3630
3693
|
){__typename}
|
|
3631
3694
|
}`;
|
|
3632
|
-
const mutationRes = await
|
|
3695
|
+
const mutationRes = await resolve({
|
|
3633
3696
|
database,
|
|
3634
3697
|
query: mutation,
|
|
3635
3698
|
variables: {
|
|
@@ -3644,7 +3707,7 @@ var auditDocuments = async (args) => {
|
|
|
3644
3707
|
if (mutationRes.errors) {
|
|
3645
3708
|
mutationRes.errors.forEach((err) => {
|
|
3646
3709
|
error = true;
|
|
3647
|
-
logger.error(
|
|
3710
|
+
logger.error(chalk5.red(err.message));
|
|
3648
3711
|
});
|
|
3649
3712
|
}
|
|
3650
3713
|
}
|
|
@@ -3661,38 +3724,31 @@ function filterObject(obj) {
|
|
|
3661
3724
|
}
|
|
3662
3725
|
|
|
3663
3726
|
// src/next/commands/audit-command/index.ts
|
|
3664
|
-
|
|
3665
|
-
var AuditCommand = class extends
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
}
|
|
3690
|
-
static {
|
|
3691
|
-
this.usage = import_clipanion4.Command.Usage({
|
|
3692
|
-
category: `Commands`,
|
|
3693
|
-
description: `Audit config and content files`
|
|
3694
|
-
});
|
|
3695
|
-
}
|
|
3727
|
+
import { AuditFileSystemBridge } from "@tinacms/graphql";
|
|
3728
|
+
var AuditCommand = class extends Command4 {
|
|
3729
|
+
static paths = [["audit"]];
|
|
3730
|
+
rootPath = Option4.String("--rootPath", {
|
|
3731
|
+
description: "Specify the root directory to run the CLI from"
|
|
3732
|
+
});
|
|
3733
|
+
verbose = Option4.Boolean("-v,--verbose", false, {
|
|
3734
|
+
description: "increase verbosity of logged output"
|
|
3735
|
+
});
|
|
3736
|
+
clean = Option4.Boolean("--clean", false, {
|
|
3737
|
+
description: "Clean the output"
|
|
3738
|
+
});
|
|
3739
|
+
useDefaultValues = Option4.Boolean("--useDefaultValues", false, {
|
|
3740
|
+
description: "When cleaning the output, use defaults on the config"
|
|
3741
|
+
});
|
|
3742
|
+
noTelemetry = Option4.Boolean("--noTelemetry", false, {
|
|
3743
|
+
description: "Disable anonymous telemetry that is collected"
|
|
3744
|
+
});
|
|
3745
|
+
datalayerPort = Option4.String("--datalayer-port", "9000", {
|
|
3746
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
3747
|
+
});
|
|
3748
|
+
static usage = Command4.Usage({
|
|
3749
|
+
category: `Commands`,
|
|
3750
|
+
description: `Audit config and content files`
|
|
3751
|
+
});
|
|
3696
3752
|
async catch(error) {
|
|
3697
3753
|
logger.error("Error occured during tinacms audit");
|
|
3698
3754
|
if (this.verbose) {
|
|
@@ -3713,9 +3769,9 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3713
3769
|
const database = await createAndInitializeDatabase(
|
|
3714
3770
|
configManager,
|
|
3715
3771
|
Number(this.datalayerPort),
|
|
3716
|
-
this.clean ? void 0 : new
|
|
3772
|
+
this.clean ? void 0 : new AuditFileSystemBridge(configManager.rootPath)
|
|
3717
3773
|
);
|
|
3718
|
-
const { tinaSchema, graphQLSchema, lookup } = await (
|
|
3774
|
+
const { tinaSchema, graphQLSchema, lookup } = await buildSchema3(
|
|
3719
3775
|
configManager.config
|
|
3720
3776
|
);
|
|
3721
3777
|
const warnings = [];
|
|
@@ -3748,29 +3804,29 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3748
3804
|
};
|
|
3749
3805
|
|
|
3750
3806
|
// src/next/commands/init-command/index.ts
|
|
3751
|
-
|
|
3807
|
+
import { Command as Command6, Option as Option6 } from "clipanion";
|
|
3752
3808
|
|
|
3753
3809
|
// src/cmds/init/detectEnvironment.ts
|
|
3754
|
-
|
|
3755
|
-
|
|
3810
|
+
import fs9 from "fs-extra";
|
|
3811
|
+
import path10 from "path";
|
|
3756
3812
|
var checkGitignoreForItem = async ({
|
|
3757
3813
|
baseDir,
|
|
3758
3814
|
line
|
|
3759
3815
|
}) => {
|
|
3760
|
-
const gitignoreContent =
|
|
3816
|
+
const gitignoreContent = fs9.readFileSync(path10.join(baseDir, ".gitignore")).toString();
|
|
3761
3817
|
return gitignoreContent.split("\n").some((item) => item === line);
|
|
3762
3818
|
};
|
|
3763
3819
|
var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
3764
3820
|
const result = {
|
|
3765
|
-
fullPathTS:
|
|
3821
|
+
fullPathTS: path10.join(
|
|
3766
3822
|
parentPath,
|
|
3767
3823
|
`${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
|
|
3768
3824
|
),
|
|
3769
|
-
fullPathJS:
|
|
3825
|
+
fullPathJS: path10.join(
|
|
3770
3826
|
parentPath,
|
|
3771
3827
|
`${name2}.${opts?.extensionOverride || "js"}`
|
|
3772
3828
|
),
|
|
3773
|
-
fullPathOverride: opts?.extensionOverride ?
|
|
3829
|
+
fullPathOverride: opts?.extensionOverride ? path10.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
|
|
3774
3830
|
generatedFileType,
|
|
3775
3831
|
name: name2,
|
|
3776
3832
|
parentPath,
|
|
@@ -3788,8 +3844,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
|
3788
3844
|
};
|
|
3789
3845
|
}
|
|
3790
3846
|
};
|
|
3791
|
-
result.typescriptExists = await
|
|
3792
|
-
result.javascriptExists = await
|
|
3847
|
+
result.typescriptExists = await fs9.pathExists(result.fullPathTS);
|
|
3848
|
+
result.javascriptExists = await fs9.pathExists(result.fullPathJS);
|
|
3793
3849
|
return result;
|
|
3794
3850
|
};
|
|
3795
3851
|
var detectEnvironment = async ({
|
|
@@ -3798,21 +3854,21 @@ var detectEnvironment = async ({
|
|
|
3798
3854
|
rootPath,
|
|
3799
3855
|
debug = false
|
|
3800
3856
|
}) => {
|
|
3801
|
-
const hasForestryConfig = await
|
|
3802
|
-
|
|
3857
|
+
const hasForestryConfig = await fs9.pathExists(
|
|
3858
|
+
path10.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
3803
3859
|
);
|
|
3804
|
-
const sampleContentPath =
|
|
3860
|
+
const sampleContentPath = path10.join(
|
|
3805
3861
|
baseDir,
|
|
3806
3862
|
"content",
|
|
3807
3863
|
"posts",
|
|
3808
3864
|
"hello-world.md"
|
|
3809
3865
|
);
|
|
3810
|
-
const usingSrc =
|
|
3811
|
-
const tinaFolder =
|
|
3866
|
+
const usingSrc = fs9.pathExistsSync(path10.join(baseDir, "src")) && (fs9.pathExistsSync(path10.join(baseDir, "src", "app")) || fs9.pathExistsSync(path10.join(baseDir, "src", "pages")));
|
|
3867
|
+
const tinaFolder = path10.join(baseDir, "tina");
|
|
3812
3868
|
const tinaConfigExists = Boolean(
|
|
3813
3869
|
// Does the tina folder exist?
|
|
3814
|
-
await
|
|
3815
|
-
(await
|
|
3870
|
+
await fs9.pathExists(tinaFolder) && // Does the tina folder contain a config file?
|
|
3871
|
+
(await fs9.readdir(tinaFolder)).find((x) => x.includes("config"))
|
|
3816
3872
|
);
|
|
3817
3873
|
const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
|
|
3818
3874
|
Boolean
|
|
@@ -3824,12 +3880,12 @@ var detectEnvironment = async ({
|
|
|
3824
3880
|
"next-api-handler": await makeGeneratedFile(
|
|
3825
3881
|
"[...routes]",
|
|
3826
3882
|
"next-api-handler",
|
|
3827
|
-
|
|
3883
|
+
path10.join(...pagesDir, "api", "tina")
|
|
3828
3884
|
),
|
|
3829
3885
|
"reactive-example": await makeGeneratedFile(
|
|
3830
3886
|
"[filename]",
|
|
3831
3887
|
"reactive-example",
|
|
3832
|
-
|
|
3888
|
+
path10.join(...pagesDir, "demo", "blog"),
|
|
3833
3889
|
{
|
|
3834
3890
|
typescriptSuffix: "tsx"
|
|
3835
3891
|
}
|
|
@@ -3837,22 +3893,22 @@ var detectEnvironment = async ({
|
|
|
3837
3893
|
"users-json": await makeGeneratedFile(
|
|
3838
3894
|
"index",
|
|
3839
3895
|
"users-json",
|
|
3840
|
-
|
|
3896
|
+
path10.join(baseDir, "content", "users"),
|
|
3841
3897
|
{ extensionOverride: "json" }
|
|
3842
3898
|
),
|
|
3843
3899
|
"sample-content": await makeGeneratedFile(
|
|
3844
3900
|
"hello-world",
|
|
3845
3901
|
"sample-content",
|
|
3846
|
-
|
|
3902
|
+
path10.join(baseDir, "content", "posts"),
|
|
3847
3903
|
{ extensionOverride: "md" }
|
|
3848
3904
|
)
|
|
3849
3905
|
};
|
|
3850
|
-
const hasSampleContent = await
|
|
3851
|
-
const hasPackageJSON = await
|
|
3906
|
+
const hasSampleContent = await fs9.pathExists(sampleContentPath);
|
|
3907
|
+
const hasPackageJSON = await fs9.pathExists("package.json");
|
|
3852
3908
|
let hasTinaDeps = false;
|
|
3853
3909
|
if (hasPackageJSON) {
|
|
3854
3910
|
try {
|
|
3855
|
-
const packageJSON = await
|
|
3911
|
+
const packageJSON = await fs9.readJSON("package.json");
|
|
3856
3912
|
const deps = [];
|
|
3857
3913
|
if (packageJSON?.dependencies) {
|
|
3858
3914
|
deps.push(...Object.keys(packageJSON.dependencies));
|
|
@@ -3869,15 +3925,15 @@ var detectEnvironment = async ({
|
|
|
3869
3925
|
);
|
|
3870
3926
|
}
|
|
3871
3927
|
}
|
|
3872
|
-
const hasGitIgnore = await
|
|
3928
|
+
const hasGitIgnore = await fs9.pathExists(path10.join(".gitignore"));
|
|
3873
3929
|
const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
|
|
3874
3930
|
const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
|
|
3875
3931
|
const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
|
|
3876
3932
|
let frontMatterFormat;
|
|
3877
3933
|
if (hasForestryConfig) {
|
|
3878
|
-
const hugoConfigPath =
|
|
3879
|
-
if (await
|
|
3880
|
-
const hugoConfig = await
|
|
3934
|
+
const hugoConfigPath = path10.join(rootPath, "config.toml");
|
|
3935
|
+
if (await fs9.pathExists(hugoConfigPath)) {
|
|
3936
|
+
const hugoConfig = await fs9.readFile(hugoConfigPath, "utf8");
|
|
3881
3937
|
const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
|
|
3882
3938
|
if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
|
|
3883
3939
|
frontMatterFormat = metaDataFormat;
|
|
@@ -3908,10 +3964,10 @@ var detectEnvironment = async ({
|
|
|
3908
3964
|
var detectEnvironment_default = detectEnvironment;
|
|
3909
3965
|
|
|
3910
3966
|
// src/cmds/init/prompts/index.ts
|
|
3911
|
-
|
|
3967
|
+
import prompts6 from "prompts";
|
|
3912
3968
|
|
|
3913
3969
|
// src/cmds/init/prompts/askTinaCloudSetup.ts
|
|
3914
|
-
|
|
3970
|
+
import prompts2 from "prompts";
|
|
3915
3971
|
var tinaCloudSetupQuestions = [
|
|
3916
3972
|
{
|
|
3917
3973
|
name: "clientId",
|
|
@@ -3933,7 +3989,7 @@ ${logText(
|
|
|
3933
3989
|
}
|
|
3934
3990
|
];
|
|
3935
3991
|
var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
3936
|
-
const { clientId, token } = await (
|
|
3992
|
+
const { clientId, token } = await prompts2(tinaCloudSetupQuestions);
|
|
3937
3993
|
config2.envVars.push(
|
|
3938
3994
|
{
|
|
3939
3995
|
key: "NEXT_PUBLIC_TINA_CLIENT_ID",
|
|
@@ -3947,7 +4003,7 @@ var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
|
3947
4003
|
};
|
|
3948
4004
|
|
|
3949
4005
|
// src/cmds/init/prompts/gitProvider.ts
|
|
3950
|
-
|
|
4006
|
+
import prompts3 from "prompts";
|
|
3951
4007
|
var supportedGitProviders = {
|
|
3952
4008
|
github: {
|
|
3953
4009
|
imports: [
|
|
@@ -3969,7 +4025,7 @@ var supportedGitProviders = {
|
|
|
3969
4025
|
}
|
|
3970
4026
|
};
|
|
3971
4027
|
var chooseGitProvider = async ({ config: config2 }) => {
|
|
3972
|
-
const result = await (
|
|
4028
|
+
const result = await prompts3([
|
|
3973
4029
|
{
|
|
3974
4030
|
name: "githubToken",
|
|
3975
4031
|
type: "text",
|
|
@@ -4014,7 +4070,7 @@ ${logText(
|
|
|
4014
4070
|
};
|
|
4015
4071
|
|
|
4016
4072
|
// src/cmds/init/prompts/databaseAdapter.ts
|
|
4017
|
-
|
|
4073
|
+
import prompts4 from "prompts";
|
|
4018
4074
|
var supportedDatabaseAdapters = {
|
|
4019
4075
|
["upstash-redis"]: {
|
|
4020
4076
|
databaseAdapterClassText: `new RedisLevel({
|
|
@@ -4060,7 +4116,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4060
4116
|
other: async (_args) => {
|
|
4061
4117
|
},
|
|
4062
4118
|
mongodb: async ({ config: config2 }) => {
|
|
4063
|
-
const result = await (
|
|
4119
|
+
const result = await prompts4([
|
|
4064
4120
|
{
|
|
4065
4121
|
name: "mongoDBUri",
|
|
4066
4122
|
type: "text",
|
|
@@ -4075,7 +4131,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4075
4131
|
});
|
|
4076
4132
|
},
|
|
4077
4133
|
"upstash-redis": async ({ config: config2 }) => {
|
|
4078
|
-
const result = await (
|
|
4134
|
+
const result = await prompts4([
|
|
4079
4135
|
{
|
|
4080
4136
|
name: "kvRestApiUrl",
|
|
4081
4137
|
type: "text",
|
|
@@ -4106,7 +4162,7 @@ var chooseDatabaseAdapter = async ({
|
|
|
4106
4162
|
framework,
|
|
4107
4163
|
config: config2
|
|
4108
4164
|
}) => {
|
|
4109
|
-
const answers = await (
|
|
4165
|
+
const answers = await prompts4([
|
|
4110
4166
|
{
|
|
4111
4167
|
name: "dataLayerAdapter",
|
|
4112
4168
|
message: "Select a self-hosted Database Adapter",
|
|
@@ -4136,8 +4192,8 @@ var chooseDatabaseAdapter = async ({
|
|
|
4136
4192
|
};
|
|
4137
4193
|
|
|
4138
4194
|
// src/cmds/init/prompts/authProvider.ts
|
|
4139
|
-
|
|
4140
|
-
|
|
4195
|
+
import crypto2 from "crypto-js";
|
|
4196
|
+
import prompts5 from "prompts";
|
|
4141
4197
|
var supportedAuthProviders = {
|
|
4142
4198
|
other: {
|
|
4143
4199
|
name: "other"
|
|
@@ -4186,12 +4242,12 @@ var authProviderUpdateConfig = {
|
|
|
4186
4242
|
},
|
|
4187
4243
|
"tina-cloud": askTinaCloudSetup,
|
|
4188
4244
|
"next-auth": async ({ config: config2 }) => {
|
|
4189
|
-
const result = await (
|
|
4245
|
+
const result = await prompts5([
|
|
4190
4246
|
{
|
|
4191
4247
|
name: "nextAuthSecret",
|
|
4192
4248
|
type: "text",
|
|
4193
4249
|
message: `What is the NextAuth.js Secret? (Hit enter to use a randomly generated secret)`,
|
|
4194
|
-
initial: process.env.NEXTAUTH_SECRET ||
|
|
4250
|
+
initial: process.env.NEXTAUTH_SECRET || crypto2.lib.WordArray.random(16).toString()
|
|
4195
4251
|
}
|
|
4196
4252
|
]);
|
|
4197
4253
|
config2.envVars.push({
|
|
@@ -4216,7 +4272,7 @@ var forestryDisclaimer = logText(
|
|
|
4216
4272
|
`Note: This migration will update some of your content to match tina. Please save a backup of your content before doing this migration. (This can be done with git)`
|
|
4217
4273
|
);
|
|
4218
4274
|
var askCommonSetUp = async () => {
|
|
4219
|
-
const answers = await (
|
|
4275
|
+
const answers = await prompts6([
|
|
4220
4276
|
{
|
|
4221
4277
|
name: "framework",
|
|
4222
4278
|
type: "select",
|
|
@@ -4280,7 +4336,7 @@ ${forestryDisclaimer}`
|
|
|
4280
4336
|
message: `What format are you using in your frontmatter?`
|
|
4281
4337
|
});
|
|
4282
4338
|
}
|
|
4283
|
-
const answers = await (
|
|
4339
|
+
const answers = await prompts6(questions);
|
|
4284
4340
|
return answers;
|
|
4285
4341
|
};
|
|
4286
4342
|
var askTinaSetupPrompts = async (params) => {
|
|
@@ -4305,11 +4361,11 @@ var askTinaSetupPrompts = async (params) => {
|
|
|
4305
4361
|
)
|
|
4306
4362
|
});
|
|
4307
4363
|
}
|
|
4308
|
-
const answers = await (
|
|
4364
|
+
const answers = await prompts6(questions);
|
|
4309
4365
|
return answers;
|
|
4310
4366
|
};
|
|
4311
4367
|
var askIfUsingSelfHosted = async () => {
|
|
4312
|
-
const answers = await (
|
|
4368
|
+
const answers = await prompts6([
|
|
4313
4369
|
{
|
|
4314
4370
|
name: "hosting",
|
|
4315
4371
|
type: "select",
|
|
@@ -4342,20 +4398,20 @@ var makeImportString = (imports) => {
|
|
|
4342
4398
|
};
|
|
4343
4399
|
|
|
4344
4400
|
// src/cmds/init/prompts/generatedFiles.ts
|
|
4345
|
-
|
|
4401
|
+
import prompts7 from "prompts";
|
|
4346
4402
|
var askIfOverride = async ({
|
|
4347
4403
|
generatedFile,
|
|
4348
4404
|
usingTypescript
|
|
4349
4405
|
}) => {
|
|
4350
4406
|
if (usingTypescript) {
|
|
4351
|
-
const result = await (
|
|
4407
|
+
const result = await prompts7({
|
|
4352
4408
|
name: `override`,
|
|
4353
4409
|
type: "confirm",
|
|
4354
4410
|
message: `Found existing file at ${generatedFile.fullPathTS}. Would you like to overwrite?`
|
|
4355
4411
|
});
|
|
4356
4412
|
return Boolean(result.override);
|
|
4357
4413
|
} else {
|
|
4358
|
-
const result = await (
|
|
4414
|
+
const result = await prompts7({
|
|
4359
4415
|
name: `override`,
|
|
4360
4416
|
type: "confirm",
|
|
4361
4417
|
message: `Found existing file at ${generatedFile.fullPathJS}. Would you like to overwrite?`
|
|
@@ -4490,24 +4546,25 @@ var CLICommand = class {
|
|
|
4490
4546
|
};
|
|
4491
4547
|
|
|
4492
4548
|
// src/cmds/init/apply.ts
|
|
4493
|
-
|
|
4549
|
+
import path14 from "path";
|
|
4494
4550
|
|
|
4495
4551
|
// src/cmds/forestry-migrate/index.ts
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4552
|
+
import fs11 from "fs-extra";
|
|
4553
|
+
import path12 from "path";
|
|
4554
|
+
import yaml2 from "js-yaml";
|
|
4555
|
+
import pkg from "minimatch";
|
|
4556
|
+
import { parseFile, stringifyFile } from "@tinacms/graphql";
|
|
4557
|
+
import { CONTENT_FORMATS } from "@tinacms/schema-tools";
|
|
4502
4558
|
|
|
4503
4559
|
// src/cmds/forestry-migrate/util/index.ts
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4560
|
+
import fs10 from "fs-extra";
|
|
4561
|
+
import path11 from "path";
|
|
4562
|
+
import yaml from "js-yaml";
|
|
4563
|
+
import z from "zod";
|
|
4508
4564
|
|
|
4509
4565
|
// src/cmds/forestry-migrate/util/errorSingleton.ts
|
|
4510
4566
|
var ErrorSingleton = class _ErrorSingleton {
|
|
4567
|
+
static instance;
|
|
4511
4568
|
/**
|
|
4512
4569
|
* The Singleton's constructor should always be private to prevent direct
|
|
4513
4570
|
* construction calls with the `new` operator.
|
|
@@ -4527,6 +4584,7 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4527
4584
|
}
|
|
4528
4585
|
return _ErrorSingleton.instance;
|
|
4529
4586
|
}
|
|
4587
|
+
collectionNameErrors;
|
|
4530
4588
|
addErrorName(error) {
|
|
4531
4589
|
this.collectionNameErrors.push(error);
|
|
4532
4590
|
}
|
|
@@ -4549,8 +4607,8 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4549
4607
|
};
|
|
4550
4608
|
|
|
4551
4609
|
// src/cmds/forestry-migrate/util/codeTransformer.ts
|
|
4552
|
-
|
|
4553
|
-
|
|
4610
|
+
import { format } from "prettier";
|
|
4611
|
+
import TsParser from "prettier/parser-typescript.js";
|
|
4554
4612
|
var addVariablesToCode = (codeWithTinaPrefix) => {
|
|
4555
4613
|
const code = codeWithTinaPrefix.replace(
|
|
4556
4614
|
/"__TINA_INTERNAL__:::(.*?):::"/g,
|
|
@@ -4587,7 +4645,7 @@ var makeTemplateFile = async ({
|
|
|
4587
4645
|
`export function ${stringifyLabelWithField(
|
|
4588
4646
|
template.templateObj.label
|
|
4589
4647
|
)} (){
|
|
4590
|
-
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4648
|
+
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4591
4649
|
} `
|
|
4592
4650
|
);
|
|
4593
4651
|
}
|
|
@@ -4595,9 +4653,9 @@ var makeTemplateFile = async ({
|
|
|
4595
4653
|
${usingTypescript ? "import type { TinaField } from 'tinacms'" : ""}
|
|
4596
4654
|
${templateCodeText.join("\n")}
|
|
4597
4655
|
`;
|
|
4598
|
-
const formattedCode =
|
|
4656
|
+
const formattedCode = format(templateCode, {
|
|
4599
4657
|
parser: "typescript",
|
|
4600
|
-
plugins: [
|
|
4658
|
+
plugins: [TsParser]
|
|
4601
4659
|
});
|
|
4602
4660
|
return { importStatements, templateCodeText: formattedCode };
|
|
4603
4661
|
};
|
|
@@ -4629,82 +4687,82 @@ var stringifyTemplateName = (name2, template) => {
|
|
|
4629
4687
|
return newName;
|
|
4630
4688
|
}
|
|
4631
4689
|
};
|
|
4632
|
-
var forestryConfigSchema =
|
|
4633
|
-
sections:
|
|
4634
|
-
|
|
4635
|
-
type:
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4690
|
+
var forestryConfigSchema = z.object({
|
|
4691
|
+
sections: z.array(
|
|
4692
|
+
z.object({
|
|
4693
|
+
type: z.union([
|
|
4694
|
+
z.literal("directory"),
|
|
4695
|
+
z.literal("document"),
|
|
4696
|
+
z.literal("heading"),
|
|
4697
|
+
z.literal("jekyll-pages"),
|
|
4698
|
+
z.literal("jekyll-posts")
|
|
4641
4699
|
]),
|
|
4642
|
-
label:
|
|
4643
|
-
path:
|
|
4644
|
-
match:
|
|
4645
|
-
exclude:
|
|
4646
|
-
create:
|
|
4647
|
-
templates:
|
|
4648
|
-
new_doc_ext:
|
|
4649
|
-
read_only:
|
|
4700
|
+
label: z.string(),
|
|
4701
|
+
path: z.string().optional().nullable(),
|
|
4702
|
+
match: z.string().optional().nullable(),
|
|
4703
|
+
exclude: z.string().optional().nullable(),
|
|
4704
|
+
create: z.union([z.literal("all"), z.literal("documents"), z.literal("none")]).optional(),
|
|
4705
|
+
templates: z.array(z.string()).optional().nullable(),
|
|
4706
|
+
new_doc_ext: z.string().optional().nullable(),
|
|
4707
|
+
read_only: z.boolean().optional().nullable()
|
|
4650
4708
|
})
|
|
4651
4709
|
)
|
|
4652
4710
|
});
|
|
4653
|
-
var forestryFieldWithoutField =
|
|
4711
|
+
var forestryFieldWithoutField = z.object({
|
|
4654
4712
|
// TODO: maybe better type this?
|
|
4655
|
-
type:
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4713
|
+
type: z.union([
|
|
4714
|
+
z.literal("text"),
|
|
4715
|
+
z.literal("datetime"),
|
|
4716
|
+
z.literal("list"),
|
|
4717
|
+
z.literal("file"),
|
|
4718
|
+
z.literal("image_gallery"),
|
|
4719
|
+
z.literal("textarea"),
|
|
4720
|
+
z.literal("tag_list"),
|
|
4721
|
+
z.literal("number"),
|
|
4722
|
+
z.literal("boolean"),
|
|
4723
|
+
z.literal("field_group"),
|
|
4724
|
+
z.literal("field_group_list"),
|
|
4725
|
+
z.literal("select"),
|
|
4726
|
+
z.literal("include"),
|
|
4727
|
+
z.literal("blocks"),
|
|
4728
|
+
z.literal("color")
|
|
4671
4729
|
]),
|
|
4672
|
-
template_types:
|
|
4673
|
-
name:
|
|
4674
|
-
label:
|
|
4675
|
-
default:
|
|
4676
|
-
template:
|
|
4677
|
-
config:
|
|
4730
|
+
template_types: z.array(z.string()).optional().nullable(),
|
|
4731
|
+
name: z.string(),
|
|
4732
|
+
label: z.string(),
|
|
4733
|
+
default: z.any().optional(),
|
|
4734
|
+
template: z.string().optional(),
|
|
4735
|
+
config: z.object({
|
|
4678
4736
|
// min and max are used for lists
|
|
4679
|
-
min:
|
|
4680
|
-
max:
|
|
4681
|
-
required:
|
|
4682
|
-
use_select:
|
|
4683
|
-
date_format:
|
|
4684
|
-
time_format:
|
|
4685
|
-
options:
|
|
4686
|
-
source:
|
|
4687
|
-
type:
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4737
|
+
min: z.number().optional().nullable(),
|
|
4738
|
+
max: z.number().optional().nullable(),
|
|
4739
|
+
required: z.boolean().optional().nullable(),
|
|
4740
|
+
use_select: z.boolean().optional().nullable(),
|
|
4741
|
+
date_format: z.string().optional().nullable(),
|
|
4742
|
+
time_format: z.string().optional().nullable(),
|
|
4743
|
+
options: z.array(z.string()).optional().nullable(),
|
|
4744
|
+
source: z.object({
|
|
4745
|
+
type: z.union([
|
|
4746
|
+
z.literal("custom"),
|
|
4747
|
+
z.literal("pages"),
|
|
4748
|
+
z.literal("documents"),
|
|
4749
|
+
z.literal("simple"),
|
|
4692
4750
|
// TODO: I want to ignore this key if its invalid
|
|
4693
|
-
|
|
4751
|
+
z.string()
|
|
4694
4752
|
]).optional().nullable(),
|
|
4695
|
-
section:
|
|
4753
|
+
section: z.string().optional().nullable()
|
|
4696
4754
|
}).optional()
|
|
4697
4755
|
}).optional()
|
|
4698
4756
|
});
|
|
4699
|
-
var forestryField =
|
|
4757
|
+
var forestryField = z.lazy(
|
|
4700
4758
|
() => forestryFieldWithoutField.extend({
|
|
4701
|
-
fields:
|
|
4759
|
+
fields: z.array(forestryField).optional()
|
|
4702
4760
|
})
|
|
4703
4761
|
);
|
|
4704
|
-
var FrontmatterTemplateSchema =
|
|
4705
|
-
label:
|
|
4706
|
-
hide_body:
|
|
4707
|
-
fields:
|
|
4762
|
+
var FrontmatterTemplateSchema = z.object({
|
|
4763
|
+
label: z.string(),
|
|
4764
|
+
hide_body: z.boolean().optional(),
|
|
4765
|
+
fields: z.array(forestryField).optional()
|
|
4708
4766
|
});
|
|
4709
4767
|
var transformForestryFieldsToTinaFields = ({
|
|
4710
4768
|
fields,
|
|
@@ -4927,7 +4985,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4927
4985
|
return tinaFields;
|
|
4928
4986
|
};
|
|
4929
4987
|
var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
|
|
4930
|
-
const templatePath =
|
|
4988
|
+
const templatePath = path11.join(
|
|
4931
4989
|
pathToForestryConfig,
|
|
4932
4990
|
".forestry",
|
|
4933
4991
|
"front_matter",
|
|
@@ -4936,7 +4994,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4936
4994
|
);
|
|
4937
4995
|
let templateString = "";
|
|
4938
4996
|
try {
|
|
4939
|
-
templateString =
|
|
4997
|
+
templateString = fs10.readFileSync(templatePath).toString();
|
|
4940
4998
|
} catch {
|
|
4941
4999
|
throw new Error(
|
|
4942
5000
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -4944,7 +5002,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4944
5002
|
This will require manual migration.`
|
|
4945
5003
|
);
|
|
4946
5004
|
}
|
|
4947
|
-
const templateObj =
|
|
5005
|
+
const templateObj = yaml.load(templateString);
|
|
4948
5006
|
const template = parseTemplates({ val: templateObj });
|
|
4949
5007
|
const fields = transformForestryFieldsToTinaFields({
|
|
4950
5008
|
fields: template.fields,
|
|
@@ -4964,6 +5022,7 @@ var parseSections = ({ val }) => {
|
|
|
4964
5022
|
};
|
|
4965
5023
|
|
|
4966
5024
|
// src/cmds/forestry-migrate/index.ts
|
|
5025
|
+
var { minimatch } = pkg;
|
|
4967
5026
|
var BODY_FIELD = {
|
|
4968
5027
|
// This is the body field
|
|
4969
5028
|
type: "rich-text",
|
|
@@ -4992,7 +5051,7 @@ var transformForestryMatchToTinaMatch = (match) => {
|
|
|
4992
5051
|
};
|
|
4993
5052
|
function checkExt(ext) {
|
|
4994
5053
|
const extReal = ext.replace(".", "");
|
|
4995
|
-
if (
|
|
5054
|
+
if (CONTENT_FORMATS.includes(extReal)) {
|
|
4996
5055
|
return extReal;
|
|
4997
5056
|
} else {
|
|
4998
5057
|
return false;
|
|
@@ -5001,9 +5060,9 @@ function checkExt(ext) {
|
|
|
5001
5060
|
var generateAllTemplates = async ({
|
|
5002
5061
|
pathToForestryConfig
|
|
5003
5062
|
}) => {
|
|
5004
|
-
const allTemplates = (await
|
|
5005
|
-
|
|
5006
|
-
)).map((tem) =>
|
|
5063
|
+
const allTemplates = (await fs11.readdir(
|
|
5064
|
+
path12.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
|
|
5065
|
+
)).map((tem) => path12.basename(tem, ".yml"));
|
|
5007
5066
|
const templateMap = /* @__PURE__ */ new Map();
|
|
5008
5067
|
const proms = allTemplates.map(async (tem) => {
|
|
5009
5068
|
try {
|
|
@@ -5078,7 +5137,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5078
5137
|
glob = section.path + "/" + section.match;
|
|
5079
5138
|
}
|
|
5080
5139
|
if (pages.some((page) => {
|
|
5081
|
-
return (
|
|
5140
|
+
return minimatch(page, glob);
|
|
5082
5141
|
})) {
|
|
5083
5142
|
forestryTemplates.push(templateKey);
|
|
5084
5143
|
}
|
|
@@ -5148,9 +5207,9 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5148
5207
|
return c;
|
|
5149
5208
|
} else if (section.type === "document") {
|
|
5150
5209
|
const filePath = section.path;
|
|
5151
|
-
const extname =
|
|
5152
|
-
const fileName =
|
|
5153
|
-
const dir =
|
|
5210
|
+
const extname = path12.extname(filePath);
|
|
5211
|
+
const fileName = path12.basename(filePath, extname);
|
|
5212
|
+
const dir = path12.dirname(filePath);
|
|
5154
5213
|
const ext = checkExt(extname);
|
|
5155
5214
|
if (ext) {
|
|
5156
5215
|
const fields = [];
|
|
@@ -5212,8 +5271,8 @@ var generateCollections = async ({
|
|
|
5212
5271
|
templateMap,
|
|
5213
5272
|
usingTypescript
|
|
5214
5273
|
});
|
|
5215
|
-
const forestryConfig = await
|
|
5216
|
-
|
|
5274
|
+
const forestryConfig = await fs11.readFile(
|
|
5275
|
+
path12.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
5217
5276
|
);
|
|
5218
5277
|
rewriteTemplateKeysInDocs({
|
|
5219
5278
|
templateMap,
|
|
@@ -5223,7 +5282,7 @@ var generateCollections = async ({
|
|
|
5223
5282
|
}
|
|
5224
5283
|
});
|
|
5225
5284
|
const collections = parseSections({
|
|
5226
|
-
val:
|
|
5285
|
+
val: yaml2.load(forestryConfig.toString())
|
|
5227
5286
|
}).sections.map(
|
|
5228
5287
|
(section) => generateCollectionFromForestrySection({
|
|
5229
5288
|
section,
|
|
@@ -5243,13 +5302,13 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5243
5302
|
const { templateObj } = templateMap.get(templateKey);
|
|
5244
5303
|
templateObj?.pages?.forEach((page) => {
|
|
5245
5304
|
try {
|
|
5246
|
-
const filePath =
|
|
5247
|
-
if (
|
|
5305
|
+
const filePath = path12.join(page);
|
|
5306
|
+
if (fs11.lstatSync(filePath).isDirectory()) {
|
|
5248
5307
|
return;
|
|
5249
5308
|
}
|
|
5250
|
-
const extname =
|
|
5251
|
-
const fileContent =
|
|
5252
|
-
const content =
|
|
5309
|
+
const extname = path12.extname(filePath);
|
|
5310
|
+
const fileContent = fs11.readFileSync(filePath).toString();
|
|
5311
|
+
const content = parseFile(
|
|
5253
5312
|
fileContent,
|
|
5254
5313
|
extname,
|
|
5255
5314
|
(yup) => yup.object({}),
|
|
@@ -5259,9 +5318,9 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5259
5318
|
_template: stringifyLabel(templateKey),
|
|
5260
5319
|
...content
|
|
5261
5320
|
};
|
|
5262
|
-
|
|
5321
|
+
fs11.writeFileSync(
|
|
5263
5322
|
filePath,
|
|
5264
|
-
|
|
5323
|
+
stringifyFile(newContent, extname, true, markdownParseConfig)
|
|
5265
5324
|
);
|
|
5266
5325
|
} catch (error) {
|
|
5267
5326
|
console.log(
|
|
@@ -5273,32 +5332,25 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5273
5332
|
};
|
|
5274
5333
|
|
|
5275
5334
|
// src/cmds/init/apply.ts
|
|
5276
|
-
|
|
5277
|
-
|
|
5335
|
+
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
5336
|
+
import fs14 from "fs-extra";
|
|
5278
5337
|
|
|
5279
5338
|
// src/next/commands/codemod-command/index.ts
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
var CodemodCommand = class extends
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
}
|
|
5296
|
-
static {
|
|
5297
|
-
this.usage = import_clipanion5.Command.Usage({
|
|
5298
|
-
category: `Commands`,
|
|
5299
|
-
description: `Use codemods for various Tina tasks`
|
|
5300
|
-
});
|
|
5301
|
-
}
|
|
5339
|
+
import { Command as Command5, Option as Option5 } from "clipanion";
|
|
5340
|
+
import fs12 from "fs-extra";
|
|
5341
|
+
import path13 from "path";
|
|
5342
|
+
var CodemodCommand = class extends Command5 {
|
|
5343
|
+
static paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5344
|
+
rootPath = Option5.String("--rootPath", {
|
|
5345
|
+
description: "Specify the root directory to run the CLI from"
|
|
5346
|
+
});
|
|
5347
|
+
verbose = Option5.Boolean("-v,--verbose", false, {
|
|
5348
|
+
description: "increase verbosity of logged output"
|
|
5349
|
+
});
|
|
5350
|
+
static usage = Command5.Usage({
|
|
5351
|
+
category: `Commands`,
|
|
5352
|
+
description: `Use codemods for various Tina tasks`
|
|
5353
|
+
});
|
|
5302
5354
|
async catch(error) {
|
|
5303
5355
|
console.log(error);
|
|
5304
5356
|
}
|
|
@@ -5327,13 +5379,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5327
5379
|
logger.error(e.message);
|
|
5328
5380
|
process.exit(1);
|
|
5329
5381
|
}
|
|
5330
|
-
const tinaDestination =
|
|
5331
|
-
if (await
|
|
5382
|
+
const tinaDestination = path13.join(configManager.rootPath, "tina");
|
|
5383
|
+
if (await fs12.existsSync(tinaDestination)) {
|
|
5332
5384
|
logger.info(
|
|
5333
5385
|
`Folder already exists at ${tinaDestination}. Either delete this folder to complete the codemod, or ensure you have properly copied your config from the ".tina" folder.`
|
|
5334
5386
|
);
|
|
5335
5387
|
} else {
|
|
5336
|
-
await
|
|
5388
|
+
await fs12.moveSync(configManager.tinaFolderPath, tinaDestination);
|
|
5337
5389
|
await writeGitignore(configManager.rootPath);
|
|
5338
5390
|
logger.info(
|
|
5339
5391
|
"Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
|
|
@@ -5341,8 +5393,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5341
5393
|
}
|
|
5342
5394
|
};
|
|
5343
5395
|
var writeGitignore = async (rootPath) => {
|
|
5344
|
-
await
|
|
5345
|
-
|
|
5396
|
+
await fs12.outputFileSync(
|
|
5397
|
+
path13.join(rootPath, "tina", ".gitignore"),
|
|
5346
5398
|
"__generated__"
|
|
5347
5399
|
);
|
|
5348
5400
|
};
|
|
@@ -5750,7 +5802,7 @@ Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a
|
|
|
5750
5802
|
`;
|
|
5751
5803
|
|
|
5752
5804
|
// src/cmds/init/apply.ts
|
|
5753
|
-
|
|
5805
|
+
import { format as format2 } from "prettier";
|
|
5754
5806
|
|
|
5755
5807
|
// src/utils/script-helpers.ts
|
|
5756
5808
|
function generateGqlScript(scriptValue, opts) {
|
|
@@ -5773,38 +5825,38 @@ function extendNextScripts(scripts, opts) {
|
|
|
5773
5825
|
}
|
|
5774
5826
|
|
|
5775
5827
|
// src/cmds/init/codegen/index.ts
|
|
5776
|
-
|
|
5777
|
-
|
|
5828
|
+
import ts2 from "typescript";
|
|
5829
|
+
import fs13 from "fs-extra";
|
|
5778
5830
|
|
|
5779
5831
|
// src/cmds/init/codegen/util.ts
|
|
5780
|
-
|
|
5781
|
-
var makeTransformer = (makeVisitor) => (ctx) => (node) =>
|
|
5832
|
+
import ts from "typescript";
|
|
5833
|
+
var makeTransformer = (makeVisitor) => (ctx) => (node) => ts.visitNode(node, makeVisitor(ctx));
|
|
5782
5834
|
function parseExpression(expression) {
|
|
5783
|
-
const sourceFile =
|
|
5835
|
+
const sourceFile = ts.createSourceFile(
|
|
5784
5836
|
"temp.ts",
|
|
5785
5837
|
expression,
|
|
5786
|
-
|
|
5838
|
+
ts.ScriptTarget.Latest
|
|
5787
5839
|
);
|
|
5788
5840
|
if (sourceFile.statements.length !== 1) {
|
|
5789
5841
|
throw new Error("Expected one statement");
|
|
5790
5842
|
}
|
|
5791
5843
|
const statement = sourceFile.statements[0];
|
|
5792
|
-
if (!
|
|
5844
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
5793
5845
|
throw new Error("Expected an expression statement");
|
|
5794
5846
|
}
|
|
5795
5847
|
return [sourceFile, statement.expression];
|
|
5796
5848
|
}
|
|
5797
5849
|
function parseVariableStatement(stmt) {
|
|
5798
|
-
const sourceFile =
|
|
5850
|
+
const sourceFile = ts.createSourceFile(
|
|
5799
5851
|
"temp.ts",
|
|
5800
5852
|
stmt,
|
|
5801
|
-
|
|
5853
|
+
ts.ScriptTarget.Latest
|
|
5802
5854
|
);
|
|
5803
5855
|
if (sourceFile.statements.length !== 1) {
|
|
5804
5856
|
throw new Error("Expected one statement");
|
|
5805
5857
|
}
|
|
5806
5858
|
const statement = sourceFile.statements[0];
|
|
5807
|
-
if (!
|
|
5859
|
+
if (!ts.isVariableStatement(statement)) {
|
|
5808
5860
|
throw new Error("Expected a variable statement");
|
|
5809
5861
|
}
|
|
5810
5862
|
return [sourceFile, statement];
|
|
@@ -5812,7 +5864,7 @@ function parseVariableStatement(stmt) {
|
|
|
5812
5864
|
|
|
5813
5865
|
// src/cmds/init/codegen/index.ts
|
|
5814
5866
|
var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variableStmt) => (ctx) => (node) => {
|
|
5815
|
-
if (
|
|
5867
|
+
if (ts2.isSourceFile(node)) {
|
|
5816
5868
|
const newStatements = [...node.statements];
|
|
5817
5869
|
let encounteredImports = false;
|
|
5818
5870
|
let firstNonImportStatementIdx = -1;
|
|
@@ -5820,7 +5872,7 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5820
5872
|
const [newVarDec] = variableStmt.declarationList.declarations;
|
|
5821
5873
|
const newVarDecName = newVarDec.name.getText(variableStmtSourceFile);
|
|
5822
5874
|
for (let i = 0; i < newStatements.length; i++) {
|
|
5823
|
-
const isImport =
|
|
5875
|
+
const isImport = ts2.isImportDeclaration(newStatements[i]);
|
|
5824
5876
|
if (isImport && !encounteredImports) {
|
|
5825
5877
|
encounteredImports = true;
|
|
5826
5878
|
}
|
|
@@ -5828,9 +5880,9 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5828
5880
|
firstNonImportStatementIdx = i;
|
|
5829
5881
|
}
|
|
5830
5882
|
const stmt = newStatements[i];
|
|
5831
|
-
if (
|
|
5883
|
+
if (ts2.isVariableStatement(stmt)) {
|
|
5832
5884
|
const [dec] = stmt.declarationList.declarations;
|
|
5833
|
-
if (dec.name &&
|
|
5885
|
+
if (dec.name && ts2.isIdentifier(dec.name) && dec.name.getText(sourceFile) === newVarDecName) {
|
|
5834
5886
|
existingStatementIdx = i;
|
|
5835
5887
|
}
|
|
5836
5888
|
}
|
|
@@ -5844,19 +5896,19 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5844
5896
|
if (existingStatementIdx === -1) {
|
|
5845
5897
|
newStatements.splice(firstNonImportStatementIdx, 0, variableStmt);
|
|
5846
5898
|
}
|
|
5847
|
-
return
|
|
5899
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5848
5900
|
}
|
|
5849
5901
|
};
|
|
5850
5902
|
var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
5851
|
-
if (
|
|
5903
|
+
if (ts2.isSourceFile(node)) {
|
|
5852
5904
|
const newStatements = [...node.statements];
|
|
5853
5905
|
let changed = false;
|
|
5854
5906
|
for (const [moduleName, imports] of Object.entries(importMap)) {
|
|
5855
5907
|
let foundImportStatement = false;
|
|
5856
5908
|
for (const statement of newStatements) {
|
|
5857
|
-
if (
|
|
5909
|
+
if (ts2.isImportDeclaration(statement) && ts2.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === moduleName) {
|
|
5858
5910
|
foundImportStatement = true;
|
|
5859
|
-
const existingImports = statement.importClause?.namedBindings &&
|
|
5911
|
+
const existingImports = statement.importClause?.namedBindings && ts2.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements.map(
|
|
5860
5912
|
(e) => e.name.text
|
|
5861
5913
|
) : [];
|
|
5862
5914
|
const newImports = [
|
|
@@ -5867,22 +5919,22 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5867
5919
|
])
|
|
5868
5920
|
];
|
|
5869
5921
|
const importSpecifiers = newImports.map(
|
|
5870
|
-
(i) =>
|
|
5922
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5871
5923
|
void 0,
|
|
5872
|
-
|
|
5873
|
-
|
|
5924
|
+
ts2.factory.createIdentifier(i),
|
|
5925
|
+
ts2.factory.createIdentifier(i)
|
|
5874
5926
|
)
|
|
5875
5927
|
);
|
|
5876
|
-
const namedImports =
|
|
5877
|
-
const importClause =
|
|
5928
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5929
|
+
const importClause = ts2.factory.createImportClause(
|
|
5878
5930
|
false,
|
|
5879
5931
|
void 0,
|
|
5880
5932
|
namedImports
|
|
5881
5933
|
);
|
|
5882
|
-
const importDec =
|
|
5934
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5883
5935
|
void 0,
|
|
5884
5936
|
importClause,
|
|
5885
|
-
|
|
5937
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5886
5938
|
);
|
|
5887
5939
|
newStatements[newStatements.indexOf(statement)] = importDec;
|
|
5888
5940
|
changed = true;
|
|
@@ -5890,45 +5942,45 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5890
5942
|
}
|
|
5891
5943
|
if (!foundImportStatement) {
|
|
5892
5944
|
const importSpecifiers = imports.map(
|
|
5893
|
-
(i) =>
|
|
5945
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5894
5946
|
void 0,
|
|
5895
|
-
|
|
5896
|
-
|
|
5947
|
+
ts2.factory.createIdentifier(i),
|
|
5948
|
+
ts2.factory.createIdentifier(i)
|
|
5897
5949
|
)
|
|
5898
5950
|
);
|
|
5899
|
-
const namedImports =
|
|
5900
|
-
const importClause =
|
|
5951
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5952
|
+
const importClause = ts2.factory.createImportClause(
|
|
5901
5953
|
false,
|
|
5902
5954
|
void 0,
|
|
5903
5955
|
namedImports
|
|
5904
5956
|
);
|
|
5905
|
-
const importDec =
|
|
5957
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5906
5958
|
void 0,
|
|
5907
5959
|
importClause,
|
|
5908
|
-
|
|
5960
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5909
5961
|
);
|
|
5910
5962
|
newStatements.unshift(importDec);
|
|
5911
5963
|
changed = true;
|
|
5912
5964
|
}
|
|
5913
5965
|
}
|
|
5914
5966
|
if (changed) {
|
|
5915
|
-
return
|
|
5967
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5916
5968
|
}
|
|
5917
5969
|
}
|
|
5918
5970
|
};
|
|
5919
5971
|
var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newExpressionSourceFile, newExpression) => (ctx) => {
|
|
5920
5972
|
const visit2 = (node) => {
|
|
5921
|
-
if (
|
|
5973
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5922
5974
|
const configObject = node.arguments[0];
|
|
5923
5975
|
const updateProperties = configObject.properties.map((property) => {
|
|
5924
|
-
if (
|
|
5976
|
+
if (ts2.isPropertyAssignment(property)) {
|
|
5925
5977
|
const thisPropertyName = property.name.getText(sourceFile);
|
|
5926
|
-
if (thisPropertyName === "schema" &&
|
|
5978
|
+
if (thisPropertyName === "schema" && ts2.isPropertyAssignment(property) && ts2.isObjectLiteralExpression(property.initializer)) {
|
|
5927
5979
|
const schemaObject = property.initializer;
|
|
5928
5980
|
const collectionsProperty = schemaObject.properties.find(
|
|
5929
|
-
(p) =>
|
|
5981
|
+
(p) => ts2.isPropertyAssignment(p) && p.name.getText(sourceFile) === "collections"
|
|
5930
5982
|
);
|
|
5931
|
-
if (collectionsProperty &&
|
|
5983
|
+
if (collectionsProperty && ts2.isPropertyAssignment(collectionsProperty) && ts2.isArrayLiteralExpression(collectionsProperty.initializer)) {
|
|
5932
5984
|
const collectionsArray = collectionsProperty.initializer;
|
|
5933
5985
|
const collectionItems = collectionsArray.elements.map(
|
|
5934
5986
|
(e) => e.getText(sourceFile)
|
|
@@ -5938,16 +5990,16 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5938
5990
|
)) {
|
|
5939
5991
|
return property;
|
|
5940
5992
|
}
|
|
5941
|
-
return
|
|
5993
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5942
5994
|
property,
|
|
5943
5995
|
property.name,
|
|
5944
|
-
|
|
5996
|
+
ts2.factory.createObjectLiteralExpression(
|
|
5945
5997
|
schemaObject.properties.map((subProp) => {
|
|
5946
|
-
if (
|
|
5947
|
-
return
|
|
5998
|
+
if (ts2.isPropertyAssignment(subProp) && subProp.name.getText(sourceFile) === "collections" && ts2.isArrayLiteralExpression(subProp.initializer)) {
|
|
5999
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5948
6000
|
subProp,
|
|
5949
6001
|
subProp.name,
|
|
5950
|
-
|
|
6002
|
+
ts2.factory.createArrayLiteralExpression(
|
|
5951
6003
|
[newExpression, ...subProp.initializer.elements],
|
|
5952
6004
|
true
|
|
5953
6005
|
)
|
|
@@ -5963,56 +6015,56 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5963
6015
|
}
|
|
5964
6016
|
return property;
|
|
5965
6017
|
});
|
|
5966
|
-
return
|
|
6018
|
+
return ts2.factory.createCallExpression(
|
|
5967
6019
|
node.expression,
|
|
5968
6020
|
node.typeArguments,
|
|
5969
|
-
[
|
|
6021
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
5970
6022
|
);
|
|
5971
6023
|
}
|
|
5972
|
-
return
|
|
6024
|
+
return ts2.visitEachChild(node, visit2, ctx);
|
|
5973
6025
|
};
|
|
5974
6026
|
return (sourceFile2) => {
|
|
5975
|
-
return
|
|
6027
|
+
return ts2.visitEachChild(sourceFile2, visit2, ctx);
|
|
5976
6028
|
};
|
|
5977
6029
|
};
|
|
5978
6030
|
var makeUpdateObjectLiteralPropertyVisitor = (sourceFile, functionName, propertyName, propertyValueExpressionSourceFile, propertyValue) => (ctx) => {
|
|
5979
6031
|
const visitor = (node) => {
|
|
5980
|
-
if (
|
|
6032
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5981
6033
|
let foundProperty = false;
|
|
5982
6034
|
const configObject = node.arguments[0];
|
|
5983
6035
|
const updateProperties = configObject.properties.map((property) => {
|
|
5984
|
-
if (
|
|
6036
|
+
if (ts2.isPropertyAssignment(property) || ts2.isShorthandPropertyAssignment(property)) {
|
|
5985
6037
|
const name2 = property.name.getText(sourceFile);
|
|
5986
6038
|
if (name2 === propertyName) {
|
|
5987
6039
|
foundProperty = true;
|
|
5988
|
-
return
|
|
6040
|
+
return ts2.factory.createPropertyAssignment(name2, propertyValue);
|
|
5989
6041
|
}
|
|
5990
6042
|
}
|
|
5991
6043
|
return property;
|
|
5992
6044
|
});
|
|
5993
6045
|
if (!foundProperty) {
|
|
5994
6046
|
updateProperties.unshift(
|
|
5995
|
-
|
|
6047
|
+
ts2.factory.createPropertyAssignment(propertyName, propertyValue)
|
|
5996
6048
|
);
|
|
5997
6049
|
}
|
|
5998
|
-
return
|
|
6050
|
+
return ts2.factory.createCallExpression(
|
|
5999
6051
|
node.expression,
|
|
6000
6052
|
node.typeArguments,
|
|
6001
|
-
[
|
|
6053
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
6002
6054
|
);
|
|
6003
6055
|
}
|
|
6004
|
-
return
|
|
6056
|
+
return ts2.visitEachChild(node, visitor, ctx);
|
|
6005
6057
|
};
|
|
6006
6058
|
return (sourceFile2) => {
|
|
6007
|
-
return
|
|
6059
|
+
return ts2.visitNode(sourceFile2, visitor);
|
|
6008
6060
|
};
|
|
6009
6061
|
};
|
|
6010
6062
|
var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
6011
6063
|
const pathToConfig = configFile.resolve(config2.typescript).path;
|
|
6012
|
-
const sourceFile =
|
|
6064
|
+
const sourceFile = ts2.createSourceFile(
|
|
6013
6065
|
pathToConfig,
|
|
6014
|
-
|
|
6015
|
-
config2.typescript ?
|
|
6066
|
+
fs13.readFileSync(pathToConfig, "utf8"),
|
|
6067
|
+
config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
|
|
6016
6068
|
);
|
|
6017
6069
|
const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
|
|
6018
6070
|
const importMap = {
|
|
@@ -6025,7 +6077,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6025
6077
|
{}
|
|
6026
6078
|
)
|
|
6027
6079
|
};
|
|
6028
|
-
const transformedSourceFileResult =
|
|
6080
|
+
const transformedSourceFileResult = ts2.transform(
|
|
6029
6081
|
sourceFile,
|
|
6030
6082
|
[
|
|
6031
6083
|
makeImportsVisitor(sourceFile, {
|
|
@@ -6061,13 +6113,14 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6061
6113
|
)
|
|
6062
6114
|
].map((visitor) => makeTransformer(visitor))
|
|
6063
6115
|
);
|
|
6064
|
-
return
|
|
6116
|
+
return fs13.writeFile(
|
|
6065
6117
|
pathToConfig,
|
|
6066
|
-
|
|
6118
|
+
ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
|
|
6067
6119
|
);
|
|
6068
6120
|
};
|
|
6069
6121
|
|
|
6070
6122
|
// src/cmds/init/apply.ts
|
|
6123
|
+
import { exec } from "child_process";
|
|
6071
6124
|
async function apply({
|
|
6072
6125
|
env,
|
|
6073
6126
|
params,
|
|
@@ -6178,8 +6231,8 @@ async function apply({
|
|
|
6178
6231
|
await addConfigFile({
|
|
6179
6232
|
configArgs: {
|
|
6180
6233
|
config: config2,
|
|
6181
|
-
publicFolder:
|
|
6182
|
-
|
|
6234
|
+
publicFolder: path14.join(
|
|
6235
|
+
path14.relative(process.cwd(), pathToForestryConfig),
|
|
6183
6236
|
config2.publicFolder
|
|
6184
6237
|
),
|
|
6185
6238
|
collections,
|
|
@@ -6236,7 +6289,7 @@ var reportTelemetry = async ({
|
|
|
6236
6289
|
if (noTelemetry) {
|
|
6237
6290
|
logger.info(logText("Telemetry disabled"));
|
|
6238
6291
|
}
|
|
6239
|
-
const telemetry = new
|
|
6292
|
+
const telemetry = new Telemetry2({ disabled: noTelemetry });
|
|
6240
6293
|
const schemaFileType = usingTypescript ? "ts" : "js";
|
|
6241
6294
|
await telemetry.submitRecord({
|
|
6242
6295
|
event: {
|
|
@@ -6252,18 +6305,18 @@ var createPackageJSON = async () => {
|
|
|
6252
6305
|
};
|
|
6253
6306
|
var createGitignore = async ({ baseDir }) => {
|
|
6254
6307
|
logger.info(logText("No .gitignore found, creating one"));
|
|
6255
|
-
|
|
6308
|
+
fs14.outputFileSync(path14.join(baseDir, ".gitignore"), "node_modules");
|
|
6256
6309
|
};
|
|
6257
6310
|
var updateGitIgnore = async ({
|
|
6258
6311
|
baseDir,
|
|
6259
6312
|
items
|
|
6260
6313
|
}) => {
|
|
6261
6314
|
logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
|
|
6262
|
-
const gitignoreContent =
|
|
6315
|
+
const gitignoreContent = fs14.readFileSync(path14.join(baseDir, ".gitignore")).toString();
|
|
6263
6316
|
const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
|
|
6264
6317
|
"\n"
|
|
6265
6318
|
);
|
|
6266
|
-
await
|
|
6319
|
+
await fs14.writeFile(path14.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
6267
6320
|
};
|
|
6268
6321
|
var addDependencies = async (config2, env, params) => {
|
|
6269
6322
|
const { packageManager } = config2;
|
|
@@ -6338,7 +6391,7 @@ var writeGeneratedFile = async ({
|
|
|
6338
6391
|
if (exists) {
|
|
6339
6392
|
if (overwrite) {
|
|
6340
6393
|
logger.info(`Overwriting file at ${path15}... \u2705`);
|
|
6341
|
-
|
|
6394
|
+
fs14.outputFileSync(path15, content);
|
|
6342
6395
|
} else {
|
|
6343
6396
|
logger.info(`Not overwriting file at ${path15}.`);
|
|
6344
6397
|
logger.info(
|
|
@@ -6348,8 +6401,8 @@ ${indentText(content)}}`)
|
|
|
6348
6401
|
}
|
|
6349
6402
|
} else {
|
|
6350
6403
|
logger.info(`Adding file at ${path15}... \u2705`);
|
|
6351
|
-
await
|
|
6352
|
-
|
|
6404
|
+
await fs14.ensureDir(parentPath);
|
|
6405
|
+
fs14.outputFileSync(path15, content);
|
|
6353
6406
|
}
|
|
6354
6407
|
};
|
|
6355
6408
|
var addConfigFile = async ({
|
|
@@ -6358,7 +6411,7 @@ var addConfigFile = async ({
|
|
|
6358
6411
|
generatedFile,
|
|
6359
6412
|
config: config2
|
|
6360
6413
|
}) => {
|
|
6361
|
-
const content = (
|
|
6414
|
+
const content = format2(generateConfig(configArgs), {
|
|
6362
6415
|
parser: "babel"
|
|
6363
6416
|
});
|
|
6364
6417
|
await writeGeneratedFile({
|
|
@@ -6388,7 +6441,7 @@ var addNextApiRoute = async ({
|
|
|
6388
6441
|
generatedFile,
|
|
6389
6442
|
env
|
|
6390
6443
|
}) => {
|
|
6391
|
-
const content = (
|
|
6444
|
+
const content = format2(nextApiRouteTemplate({ config: config2, env }), {
|
|
6392
6445
|
parser: "babel"
|
|
6393
6446
|
});
|
|
6394
6447
|
await writeGeneratedFile({
|
|
@@ -6427,7 +6480,7 @@ var addContentFile = async ({
|
|
|
6427
6480
|
return () => ({
|
|
6428
6481
|
exists: env.sampleContentExists,
|
|
6429
6482
|
path: env.sampleContentPath,
|
|
6430
|
-
parentPath:
|
|
6483
|
+
parentPath: path14.dirname(env.sampleContentPath)
|
|
6431
6484
|
});
|
|
6432
6485
|
}
|
|
6433
6486
|
},
|
|
@@ -6450,10 +6503,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
|
|
|
6450
6503
|
return `${x.key}=${x.value || "***"}`;
|
|
6451
6504
|
}).join("\n") + `
|
|
6452
6505
|
TINA_PUBLIC_IS_LOCAL=true`;
|
|
6453
|
-
const envFile =
|
|
6454
|
-
if (!
|
|
6506
|
+
const envFile = path14.join(process.cwd(), ".env");
|
|
6507
|
+
if (!fs14.existsSync(envFile)) {
|
|
6455
6508
|
logger.info(`Adding .env file to your project... \u2705`);
|
|
6456
|
-
|
|
6509
|
+
fs14.writeFileSync(envFile, envFileText);
|
|
6457
6510
|
} else {
|
|
6458
6511
|
logger.info(
|
|
6459
6512
|
"Please add the following environment variables to your .env file"
|
|
@@ -6524,7 +6577,7 @@ var addReactiveFile = {
|
|
|
6524
6577
|
baseDir,
|
|
6525
6578
|
dataLayer
|
|
6526
6579
|
}) => {
|
|
6527
|
-
const packageJsonPath =
|
|
6580
|
+
const packageJsonPath = path14.join(baseDir, "package.json");
|
|
6528
6581
|
await writeGeneratedFile({
|
|
6529
6582
|
generatedFile,
|
|
6530
6583
|
typescript: config2.typescript,
|
|
@@ -6537,7 +6590,7 @@ var addReactiveFile = {
|
|
|
6537
6590
|
})
|
|
6538
6591
|
});
|
|
6539
6592
|
logger.info("Adding a nextjs example... \u2705");
|
|
6540
|
-
const packageJson = JSON.parse(
|
|
6593
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath).toString());
|
|
6541
6594
|
const scripts = packageJson.scripts || {};
|
|
6542
6595
|
const updatedPackageJson = JSON.stringify(
|
|
6543
6596
|
{
|
|
@@ -6550,11 +6603,10 @@ var addReactiveFile = {
|
|
|
6550
6603
|
null,
|
|
6551
6604
|
2
|
|
6552
6605
|
);
|
|
6553
|
-
|
|
6606
|
+
fs14.writeFileSync(packageJsonPath, updatedPackageJson);
|
|
6554
6607
|
}
|
|
6555
6608
|
};
|
|
6556
6609
|
function execShellCommand(cmd) {
|
|
6557
|
-
const exec = require("child_process").exec;
|
|
6558
6610
|
return new Promise((resolve2, reject) => {
|
|
6559
6611
|
exec(cmd, (error, stdout, stderr) => {
|
|
6560
6612
|
if (error) {
|
|
@@ -6600,34 +6652,27 @@ var command = new CLICommand({
|
|
|
6600
6652
|
});
|
|
6601
6653
|
|
|
6602
6654
|
// src/next/commands/init-command/index.ts
|
|
6603
|
-
var InitCommand = class extends
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
}
|
|
6625
|
-
static {
|
|
6626
|
-
this.usage = import_clipanion6.Command.Usage({
|
|
6627
|
-
category: `Commands`,
|
|
6628
|
-
description: `Add Tina to an existing project`
|
|
6629
|
-
});
|
|
6630
|
-
}
|
|
6655
|
+
var InitCommand = class extends Command6 {
|
|
6656
|
+
static paths = [["init"], ["init", "backend"]];
|
|
6657
|
+
pathToForestryConfig = Option6.String("--forestryPath", {
|
|
6658
|
+
description: "Specify the relative path to the .forestry directory, if importing an existing forestry site."
|
|
6659
|
+
});
|
|
6660
|
+
rootPath = Option6.String("--rootPath", {
|
|
6661
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6662
|
+
});
|
|
6663
|
+
debug = Option6.Boolean("--debug", false, {
|
|
6664
|
+
description: "Enable debug logging"
|
|
6665
|
+
});
|
|
6666
|
+
noTelemetry = Option6.Boolean("--noTelemetry", false, {
|
|
6667
|
+
description: "Disable anonymous telemetry that is collected"
|
|
6668
|
+
});
|
|
6669
|
+
tinaVersion = Option6.String("--tinaVersion", {
|
|
6670
|
+
description: "Specify a version for tina dependencies"
|
|
6671
|
+
});
|
|
6672
|
+
static usage = Command6.Usage({
|
|
6673
|
+
category: `Commands`,
|
|
6674
|
+
description: `Add Tina to an existing project`
|
|
6675
|
+
});
|
|
6631
6676
|
async catch(error) {
|
|
6632
6677
|
logger.error("Error occured during tinacms init");
|
|
6633
6678
|
console.error(error);
|
|
@@ -6649,28 +6694,24 @@ var InitCommand = class extends import_clipanion6.Command {
|
|
|
6649
6694
|
};
|
|
6650
6695
|
|
|
6651
6696
|
// src/next/commands/searchindex-command/index.ts
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
category: `Commands`,
|
|
6671
|
-
description: `Index the site for search`
|
|
6672
|
-
});
|
|
6673
|
-
}
|
|
6697
|
+
import { Command as Command7, Option as Option7 } from "clipanion";
|
|
6698
|
+
import { createSchema, FilesystemBridge as FilesystemBridge4 } from "@tinacms/graphql";
|
|
6699
|
+
import {
|
|
6700
|
+
SearchIndexer as SearchIndexer3,
|
|
6701
|
+
TinaCMSSearchIndexClient as TinaCMSSearchIndexClient2
|
|
6702
|
+
} from "@tinacms/search";
|
|
6703
|
+
var SearchIndexCommand = class extends Command7 {
|
|
6704
|
+
static paths = [["search-index"]];
|
|
6705
|
+
rootPath = Option7.String("--rootPath", {
|
|
6706
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6707
|
+
});
|
|
6708
|
+
verbose = Option7.Boolean("-v,--verbose", false, {
|
|
6709
|
+
description: "increase verbosity of logged output"
|
|
6710
|
+
});
|
|
6711
|
+
static usage = Command7.Usage({
|
|
6712
|
+
category: `Commands`,
|
|
6713
|
+
description: `Index the site for search`
|
|
6714
|
+
});
|
|
6674
6715
|
async catch(error) {
|
|
6675
6716
|
logger.error("Error occured during tinacms search-index");
|
|
6676
6717
|
console.error(error);
|
|
@@ -6692,7 +6733,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6692
6733
|
process.exit(1);
|
|
6693
6734
|
}
|
|
6694
6735
|
const { schema } = configManager.config;
|
|
6695
|
-
const tinaSchema = await
|
|
6736
|
+
const tinaSchema = await createSchema({
|
|
6696
6737
|
schema: { ...schema, config: configManager.config }
|
|
6697
6738
|
});
|
|
6698
6739
|
let client;
|
|
@@ -6720,7 +6761,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6720
6761
|
"indexerToken not configured in tina search configuration."
|
|
6721
6762
|
);
|
|
6722
6763
|
}
|
|
6723
|
-
client = new
|
|
6764
|
+
client = new TinaCMSSearchIndexClient2({
|
|
6724
6765
|
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
6725
6766
|
branch: configManager.config?.branch,
|
|
6726
6767
|
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
@@ -6729,9 +6770,9 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6729
6770
|
} else {
|
|
6730
6771
|
client = configManager.config?.search?.searchClient;
|
|
6731
6772
|
}
|
|
6732
|
-
const searchIndexer = new
|
|
6773
|
+
const searchIndexer = new SearchIndexer3({
|
|
6733
6774
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
6734
|
-
bridge: new
|
|
6775
|
+
bridge: new FilesystemBridge4(
|
|
6735
6776
|
configManager.rootPath,
|
|
6736
6777
|
configManager.contentRootPath
|
|
6737
6778
|
),
|
|
@@ -6759,7 +6800,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6759
6800
|
};
|
|
6760
6801
|
|
|
6761
6802
|
// src/index.ts
|
|
6762
|
-
var cli = new
|
|
6803
|
+
var cli = new Cli({
|
|
6763
6804
|
binaryName: `tinacms`,
|
|
6764
6805
|
binaryLabel: `TinaCMS`,
|
|
6765
6806
|
binaryVersion: version
|
|
@@ -6770,7 +6811,10 @@ cli.register(AuditCommand);
|
|
|
6770
6811
|
cli.register(InitCommand);
|
|
6771
6812
|
cli.register(CodemodCommand);
|
|
6772
6813
|
cli.register(SearchIndexCommand);
|
|
6773
|
-
cli.register(
|
|
6774
|
-
cli.register(
|
|
6775
|
-
cli.register(
|
|
6814
|
+
cli.register(Builtins.DefinitionsCommand);
|
|
6815
|
+
cli.register(Builtins.HelpCommand);
|
|
6816
|
+
cli.register(Builtins.VersionCommand);
|
|
6776
6817
|
var index_default = cli;
|
|
6818
|
+
export {
|
|
6819
|
+
index_default as default
|
|
6820
|
+
};
|