@tinacms/cli 1.12.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tinacms +12 -6
- package/dist/index.js +874 -826
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,53 +1,27 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
28
7
|
|
|
29
8
|
// 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");
|
|
9
|
+
import { Cli, Builtins } from "clipanion";
|
|
36
10
|
|
|
37
11
|
// package.json
|
|
38
|
-
var version = "
|
|
12
|
+
var version = "2.0.0";
|
|
39
13
|
|
|
40
14
|
// src/next/commands/dev-command/index.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
15
|
+
import path8 from "path";
|
|
16
|
+
import { FilesystemBridge as FilesystemBridge2, buildSchema } from "@tinacms/graphql";
|
|
17
|
+
import { LocalSearchIndexClient, SearchIndexer } from "@tinacms/search";
|
|
18
|
+
import AsyncLock from "async-lock";
|
|
19
|
+
import chokidar from "chokidar";
|
|
20
|
+
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
21
|
+
import fs7 from "fs-extra";
|
|
48
22
|
|
|
49
23
|
// src/logger/index.ts
|
|
50
|
-
|
|
24
|
+
import chalk from "chalk";
|
|
51
25
|
|
|
52
26
|
// src/logger/is-unicode-supported.ts
|
|
53
27
|
function isUnicodeSupported() {
|
|
@@ -61,9 +35,9 @@ function isUnicodeSupported() {
|
|
|
61
35
|
}
|
|
62
36
|
|
|
63
37
|
// src/logger/index.ts
|
|
64
|
-
|
|
65
|
-
var logger =
|
|
66
|
-
|
|
38
|
+
import log4js from "log4js";
|
|
39
|
+
var logger = log4js.getLogger();
|
|
40
|
+
log4js.configure({
|
|
67
41
|
appenders: {
|
|
68
42
|
out: { type: "stdout", layout: { type: "messagePassThrough" } }
|
|
69
43
|
},
|
|
@@ -88,18 +62,18 @@ ${message}
|
|
|
88
62
|
return ln.length > sum ? ln.length : sum;
|
|
89
63
|
}, 0) + 2;
|
|
90
64
|
const msg = lines.map(
|
|
91
|
-
(ln) => `${
|
|
65
|
+
(ln) => `${chalk.gray(bar)} ${chalk.white(ln)}${" ".repeat(
|
|
92
66
|
len - strip(ln).length
|
|
93
|
-
)}${
|
|
67
|
+
)}${chalk.gray(bar)}`
|
|
94
68
|
).join("\n");
|
|
95
69
|
const underscoreLen = len - title.length - 1 > 0 ? len - title.length - 1 : 0;
|
|
96
70
|
process.stdout.write(
|
|
97
|
-
`${
|
|
98
|
-
${
|
|
71
|
+
`${chalk.gray(bar)}
|
|
72
|
+
${chalk.green("\u25CB")} ${chalk.reset(
|
|
99
73
|
title
|
|
100
|
-
)} ${
|
|
74
|
+
)} ${chalk.gray("\u2500".repeat(underscoreLen) + "\u256E")}
|
|
101
75
|
${msg}
|
|
102
|
-
${
|
|
76
|
+
${chalk.gray(
|
|
103
77
|
"\u251C" + "\u2500".repeat(len + 2) + "\u256F"
|
|
104
78
|
)}
|
|
105
79
|
`
|
|
@@ -116,11 +90,11 @@ var summary = (content) => {
|
|
|
116
90
|
});
|
|
117
91
|
});
|
|
118
92
|
content.items.forEach((item) => {
|
|
119
|
-
outString.push(`${item.emoji} ${
|
|
93
|
+
outString.push(`${item.emoji} ${chalk.cyan(item.heading)}`);
|
|
120
94
|
item.subItems.forEach((subItem) => {
|
|
121
95
|
const spaces = longestKey - subItem.key.length + 4;
|
|
122
96
|
outString.push(
|
|
123
|
-
` ${subItem.key}:${[...Array(spaces)].join(" ")}${
|
|
97
|
+
` ${subItem.key}:${[...Array(spaces)].join(" ")}${chalk.cyan(
|
|
124
98
|
subItem.value
|
|
125
99
|
)}`
|
|
126
100
|
);
|
|
@@ -158,12 +132,12 @@ var S_WARN = s("\u25B2", "!");
|
|
|
158
132
|
var S_ERROR = s("\u25A0", "x");
|
|
159
133
|
|
|
160
134
|
// src/utils/spinner.ts
|
|
161
|
-
|
|
135
|
+
import { Spinner } from "cli-spinner";
|
|
162
136
|
async function localSpin({
|
|
163
137
|
waitFor,
|
|
164
138
|
text
|
|
165
139
|
}) {
|
|
166
|
-
const spinner = new
|
|
140
|
+
const spinner = new Spinner({
|
|
167
141
|
text: `${text} %s`,
|
|
168
142
|
stream: process.stderr,
|
|
169
143
|
onTick: function(msg) {
|
|
@@ -194,32 +168,32 @@ function spin({
|
|
|
194
168
|
}
|
|
195
169
|
|
|
196
170
|
// 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 =
|
|
171
|
+
import chalk2 from "chalk";
|
|
172
|
+
var successText = chalk2.bold.green;
|
|
173
|
+
var focusText = chalk2.bold;
|
|
174
|
+
var dangerText = chalk2.bold.red;
|
|
175
|
+
var neutralText = chalk2.bold.cyan;
|
|
176
|
+
var linkText = chalk2.bold.cyan;
|
|
177
|
+
var labelText = chalk2.bold;
|
|
178
|
+
var cmdText = chalk2.inverse;
|
|
205
179
|
var indentedCmd = (str) => {
|
|
206
180
|
return ` \u2503 ` + str;
|
|
207
181
|
};
|
|
208
182
|
var indentText = (str) => {
|
|
209
183
|
return String(str).split("\n").map((line) => ` ${line}`).join("\n");
|
|
210
184
|
};
|
|
211
|
-
var logText =
|
|
212
|
-
var warnText =
|
|
213
|
-
var titleText =
|
|
214
|
-
var CONFIRMATION_TEXT =
|
|
185
|
+
var logText = chalk2.italic.gray;
|
|
186
|
+
var warnText = chalk2.yellowBright.bgBlack;
|
|
187
|
+
var titleText = chalk2.bgHex("d2f1f8").hex("ec4816");
|
|
188
|
+
var CONFIRMATION_TEXT = chalk2.dim("enter to confirm");
|
|
215
189
|
|
|
216
190
|
// src/next/codegen/index.ts
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
191
|
+
import fs from "fs-extra";
|
|
192
|
+
import path from "path";
|
|
193
|
+
import { buildASTSchema, printSchema as printSchema2 } from "graphql";
|
|
220
194
|
|
|
221
195
|
// src/next/codegen/codegen/index.ts
|
|
222
|
-
|
|
196
|
+
import { parse, printSchema } from "graphql";
|
|
223
197
|
|
|
224
198
|
// src/next/codegen/codegen/plugin.ts
|
|
225
199
|
var AddGeneratedClientFunc = (apiURL) => {
|
|
@@ -288,37 +262,44 @@ var AddGeneratedClient = (apiURL) => ({
|
|
|
288
262
|
});
|
|
289
263
|
|
|
290
264
|
// src/next/codegen/codegen/index.ts
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
265
|
+
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
266
|
+
import { codegen } from "@graphql-codegen/core";
|
|
267
|
+
import { loadDocuments } from "@graphql-tools/load";
|
|
268
|
+
import { plugin as typescriptOperationsPlugin } from "@graphql-codegen/typescript-operations";
|
|
269
|
+
import { plugin as typescriptPlugin } from "@graphql-codegen/typescript";
|
|
296
270
|
|
|
297
271
|
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
298
|
-
|
|
299
|
-
|
|
272
|
+
import { visit } from "graphql";
|
|
273
|
+
import {
|
|
274
|
+
concatAST,
|
|
275
|
+
Kind as Kind2
|
|
276
|
+
} from "graphql";
|
|
300
277
|
|
|
301
278
|
// src/next/codegen/codegen/sdkPlugin/visitor.ts
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
279
|
+
import {
|
|
280
|
+
ClientSideBaseVisitor,
|
|
281
|
+
DocumentMode,
|
|
282
|
+
indentMultiline
|
|
283
|
+
} from "@graphql-codegen/visitor-plugin-common";
|
|
284
|
+
import autoBind from "auto-bind";
|
|
285
|
+
import { Kind, print } from "graphql";
|
|
286
|
+
var GenericSdkVisitor = class extends ClientSideBaseVisitor {
|
|
287
|
+
_operationsToInclude = [];
|
|
306
288
|
constructor(schema, fragments, rawConfig) {
|
|
307
289
|
super(schema, fragments, rawConfig, {
|
|
308
290
|
usingObservableFrom: rawConfig.usingObservableFrom
|
|
309
291
|
});
|
|
310
|
-
this
|
|
311
|
-
(0, import_auto_bind.default)(this);
|
|
292
|
+
autoBind(this);
|
|
312
293
|
if (this.config.usingObservableFrom) {
|
|
313
294
|
this._additionalImports.push(this.config.usingObservableFrom);
|
|
314
295
|
}
|
|
315
|
-
if (this.config.documentMode !==
|
|
296
|
+
if (this.config.documentMode !== DocumentMode.string) {
|
|
316
297
|
}
|
|
317
298
|
}
|
|
318
299
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
319
300
|
if (node.name == null) {
|
|
320
301
|
throw new Error(
|
|
321
|
-
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" +
|
|
302
|
+
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + print(node)
|
|
322
303
|
);
|
|
323
304
|
} else {
|
|
324
305
|
this._operationsToInclude.push({
|
|
@@ -336,14 +317,14 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
336
317
|
const usingObservable = !!this.config.usingObservableFrom;
|
|
337
318
|
const allPossibleActions = this._operationsToInclude.map((o) => {
|
|
338
319
|
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every(
|
|
339
|
-
(v) => v.type.kind !==
|
|
320
|
+
(v) => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue
|
|
340
321
|
);
|
|
341
322
|
const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
|
|
342
323
|
return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
|
|
343
324
|
return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
|
|
344
325
|
}`;
|
|
345
|
-
}).map((s2) =>
|
|
346
|
-
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode ===
|
|
326
|
+
}).map((s2) => indentMultiline(s2, 2));
|
|
327
|
+
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
328
|
export function getSdk<C>(requester: Requester<C>) {
|
|
348
329
|
return {
|
|
349
330
|
${allPossibleActions.join(",\n")}
|
|
@@ -355,14 +336,14 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
355
336
|
|
|
356
337
|
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
357
338
|
var plugin = (schema, documents, config2) => {
|
|
358
|
-
const allAst =
|
|
339
|
+
const allAst = concatAST(
|
|
359
340
|
documents.reduce((prev, v) => {
|
|
360
341
|
return [...prev, v.document];
|
|
361
342
|
}, [])
|
|
362
343
|
);
|
|
363
344
|
const allFragments = [
|
|
364
345
|
...allAst.definitions.filter(
|
|
365
|
-
(d) => d.kind ===
|
|
346
|
+
(d) => d.kind === Kind2.FRAGMENT_DEFINITION
|
|
366
347
|
).map((fragmentDef) => ({
|
|
367
348
|
node: fragmentDef,
|
|
368
349
|
name: fragmentDef.name.value,
|
|
@@ -372,7 +353,7 @@ var plugin = (schema, documents, config2) => {
|
|
|
372
353
|
...config2.externalFragments || []
|
|
373
354
|
];
|
|
374
355
|
const visitor = new GenericSdkVisitor(schema, allFragments, config2);
|
|
375
|
-
const visitorResult =
|
|
356
|
+
const visitorResult = visit(allAst, { leave: visitor });
|
|
376
357
|
return {
|
|
377
358
|
// We will take care of imports
|
|
378
359
|
// prepend: visitor.getImports(),
|
|
@@ -390,10 +371,10 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
390
371
|
let fragDocs = [];
|
|
391
372
|
docs = await loadGraphQLDocuments(queryPathGlob);
|
|
392
373
|
fragDocs = await loadGraphQLDocuments(fragDocPath);
|
|
393
|
-
const res = await
|
|
374
|
+
const res = await codegen({
|
|
394
375
|
// Filename is not used. This is because the typescript plugin returns a string instead of writing to a file.
|
|
395
376
|
filename: process.cwd(),
|
|
396
|
-
schema:
|
|
377
|
+
schema: parse(printSchema(schema)),
|
|
397
378
|
documents: [...docs, ...fragDocs],
|
|
398
379
|
config: {},
|
|
399
380
|
plugins: [
|
|
@@ -406,10 +387,10 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
406
387
|
],
|
|
407
388
|
pluginMap: {
|
|
408
389
|
typescript: {
|
|
409
|
-
plugin:
|
|
390
|
+
plugin: typescriptPlugin
|
|
410
391
|
},
|
|
411
392
|
typescriptOperations: {
|
|
412
|
-
plugin:
|
|
393
|
+
plugin: typescriptOperationsPlugin
|
|
413
394
|
},
|
|
414
395
|
typescriptSdk: {
|
|
415
396
|
plugin
|
|
@@ -422,8 +403,8 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
422
403
|
var loadGraphQLDocuments = async (globPath) => {
|
|
423
404
|
let result = [];
|
|
424
405
|
try {
|
|
425
|
-
result = await
|
|
426
|
-
loaders: [new
|
|
406
|
+
result = await loadDocuments(globPath, {
|
|
407
|
+
loaders: [new GraphQLFileLoader()]
|
|
427
408
|
});
|
|
428
409
|
} catch (e) {
|
|
429
410
|
if (
|
|
@@ -440,11 +421,27 @@ var loadGraphQLDocuments = async (globPath) => {
|
|
|
440
421
|
};
|
|
441
422
|
|
|
442
423
|
// src/next/codegen/index.ts
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
424
|
+
import { transform } from "esbuild";
|
|
425
|
+
import { mapUserFields } from "@tinacms/graphql";
|
|
426
|
+
import normalizePath from "normalize-path";
|
|
446
427
|
var TINA_HOST = "content.tinajs.io";
|
|
447
428
|
var Codegen = class {
|
|
429
|
+
configManager;
|
|
430
|
+
port;
|
|
431
|
+
schema;
|
|
432
|
+
queryDoc;
|
|
433
|
+
fragDoc;
|
|
434
|
+
isLocal;
|
|
435
|
+
// The API url used in the client
|
|
436
|
+
apiURL;
|
|
437
|
+
// This is always the local URL.
|
|
438
|
+
localUrl;
|
|
439
|
+
// production url
|
|
440
|
+
productionUrl;
|
|
441
|
+
graphqlSchemaDoc;
|
|
442
|
+
tinaSchema;
|
|
443
|
+
lookup;
|
|
444
|
+
noClientBuildCache;
|
|
448
445
|
constructor({
|
|
449
446
|
configManager,
|
|
450
447
|
port,
|
|
@@ -460,7 +457,7 @@ var Codegen = class {
|
|
|
460
457
|
this.graphqlSchemaDoc = graphqlSchemaDoc;
|
|
461
458
|
this.configManager = configManager;
|
|
462
459
|
this.port = port;
|
|
463
|
-
this.schema =
|
|
460
|
+
this.schema = buildASTSchema(graphqlSchemaDoc);
|
|
464
461
|
this.tinaSchema = tinaSchema;
|
|
465
462
|
this.queryDoc = queryDoc;
|
|
466
463
|
this.fragDoc = fragDoc;
|
|
@@ -468,19 +465,19 @@ var Codegen = class {
|
|
|
468
465
|
this.noClientBuildCache = noClientBuildCache;
|
|
469
466
|
}
|
|
470
467
|
async writeConfigFile(fileName, data) {
|
|
471
|
-
const filePath =
|
|
468
|
+
const filePath = path.join(
|
|
472
469
|
this.configManager.generatedFolderPath,
|
|
473
470
|
fileName
|
|
474
471
|
);
|
|
475
|
-
await
|
|
476
|
-
await
|
|
472
|
+
await fs.ensureFile(filePath);
|
|
473
|
+
await fs.outputFile(filePath, data);
|
|
477
474
|
if (this.configManager.hasSeparateContentRoot()) {
|
|
478
|
-
const filePath2 =
|
|
475
|
+
const filePath2 = path.join(
|
|
479
476
|
this.configManager.generatedFolderPathContentRepo,
|
|
480
477
|
fileName
|
|
481
478
|
);
|
|
482
|
-
await
|
|
483
|
-
await
|
|
479
|
+
await fs.ensureFile(filePath2);
|
|
480
|
+
await fs.outputFile(filePath2, data);
|
|
484
481
|
}
|
|
485
482
|
}
|
|
486
483
|
async removeGeneratedFilesIfExists() {
|
|
@@ -512,11 +509,11 @@ var Codegen = class {
|
|
|
512
509
|
await this.removeGeneratedFilesIfExists();
|
|
513
510
|
return apiURL;
|
|
514
511
|
}
|
|
515
|
-
await
|
|
512
|
+
await fs.outputFile(
|
|
516
513
|
this.configManager.generatedQueriesFilePath,
|
|
517
514
|
this.queryDoc
|
|
518
515
|
);
|
|
519
|
-
await
|
|
516
|
+
await fs.outputFile(
|
|
520
517
|
this.configManager.generatedFragmentsFilePath,
|
|
521
518
|
this.fragDoc
|
|
522
519
|
);
|
|
@@ -524,21 +521,21 @@ var Codegen = class {
|
|
|
524
521
|
const { clientString } = await this.genClient();
|
|
525
522
|
const databaseClientString = this.configManager.hasSelfHostedConfig() ? await this.genDatabaseClient() : "";
|
|
526
523
|
const { codeString, schemaString } = await this.genTypes();
|
|
527
|
-
await
|
|
524
|
+
await fs.outputFile(
|
|
528
525
|
this.configManager.generatedGraphQLGQLPath,
|
|
529
526
|
schemaString
|
|
530
527
|
);
|
|
531
528
|
if (this.configManager.isUsingTs()) {
|
|
532
|
-
await
|
|
529
|
+
await fs.outputFile(
|
|
533
530
|
this.configManager.generatedTypesTSFilePath,
|
|
534
531
|
codeString
|
|
535
532
|
);
|
|
536
|
-
await
|
|
533
|
+
await fs.outputFile(
|
|
537
534
|
this.configManager.generatedClientTSFilePath,
|
|
538
535
|
clientString
|
|
539
536
|
);
|
|
540
537
|
if (this.configManager.hasSelfHostedConfig()) {
|
|
541
|
-
await
|
|
538
|
+
await fs.outputFile(
|
|
542
539
|
this.configManager.generatedDatabaseClientTSFilePath,
|
|
543
540
|
databaseClientString
|
|
544
541
|
);
|
|
@@ -547,35 +544,35 @@ var Codegen = class {
|
|
|
547
544
|
await unlinkIfExists(this.configManager.generatedTypesDFilePath);
|
|
548
545
|
await unlinkIfExists(this.configManager.generatedTypesJSFilePath);
|
|
549
546
|
} else {
|
|
550
|
-
await
|
|
547
|
+
await fs.outputFile(
|
|
551
548
|
this.configManager.generatedTypesDFilePath,
|
|
552
549
|
codeString
|
|
553
550
|
);
|
|
554
|
-
const jsTypes = await
|
|
555
|
-
await
|
|
551
|
+
const jsTypes = await transform(codeString, { loader: "ts" });
|
|
552
|
+
await fs.outputFile(
|
|
556
553
|
this.configManager.generatedTypesJSFilePath,
|
|
557
554
|
jsTypes.code
|
|
558
555
|
);
|
|
559
|
-
await
|
|
556
|
+
await fs.outputFile(
|
|
560
557
|
this.configManager.generatedClientDFilePath,
|
|
561
558
|
clientString
|
|
562
559
|
);
|
|
563
|
-
const jsClient = await
|
|
564
|
-
await
|
|
560
|
+
const jsClient = await transform(clientString, { loader: "ts" });
|
|
561
|
+
await fs.outputFile(
|
|
565
562
|
this.configManager.generatedClientJSFilePath,
|
|
566
563
|
jsClient.code
|
|
567
564
|
);
|
|
568
565
|
await unlinkIfExists(this.configManager.generatedTypesTSFilePath);
|
|
569
566
|
await unlinkIfExists(this.configManager.generatedClientTSFilePath);
|
|
570
567
|
if (this.configManager.hasSelfHostedConfig()) {
|
|
571
|
-
const jsDatabaseClient = await
|
|
568
|
+
const jsDatabaseClient = await transform(databaseClientString, {
|
|
572
569
|
loader: "ts"
|
|
573
570
|
});
|
|
574
|
-
await
|
|
571
|
+
await fs.outputFile(
|
|
575
572
|
this.configManager.generatedDatabaseClientJSFilePath,
|
|
576
573
|
jsDatabaseClient.code
|
|
577
574
|
);
|
|
578
|
-
await
|
|
575
|
+
await fs.outputFile(
|
|
579
576
|
this.configManager.generatedDatabaseClientDFilePath,
|
|
580
577
|
databaseClientString
|
|
581
578
|
);
|
|
@@ -623,7 +620,7 @@ var Codegen = class {
|
|
|
623
620
|
const authCollection = this.tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
624
621
|
let authFields = [];
|
|
625
622
|
if (authCollection) {
|
|
626
|
-
const usersFields =
|
|
623
|
+
const usersFields = mapUserFields(authCollection, []);
|
|
627
624
|
if (usersFields.length === 0) {
|
|
628
625
|
throw new Error("No user field found");
|
|
629
626
|
}
|
|
@@ -713,7 +710,7 @@ export default databaseClient;
|
|
|
713
710
|
const apiURL = this.getApiURL();
|
|
714
711
|
const clientString = `import { createClient } from "tinacms/dist/client";
|
|
715
712
|
import { queries } from "./types";
|
|
716
|
-
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${(
|
|
713
|
+
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${normalizePath(
|
|
717
714
|
this.configManager.generatedCachePath
|
|
718
715
|
)}', ` : ""}url: '${apiURL}', token: '${token}', queries, ${errorPolicy ? `errorPolicy: '${errorPolicy}'` : ""} });
|
|
719
716
|
export default client;
|
|
@@ -739,7 +736,7 @@ export default client;
|
|
|
739
736
|
${typescriptTypes}
|
|
740
737
|
`;
|
|
741
738
|
const schemaString = `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
742
|
-
${(
|
|
739
|
+
${printSchema2(this.schema)}
|
|
743
740
|
schema {
|
|
744
741
|
query: Query
|
|
745
742
|
mutation: Mutation
|
|
@@ -751,7 +748,7 @@ schema {
|
|
|
751
748
|
var maybeWarnFragmentSize = async (filepath) => {
|
|
752
749
|
if (
|
|
753
750
|
// is the file bigger than 100kb?
|
|
754
|
-
(await
|
|
751
|
+
(await fs.stat(filepath)).size > // convert to 100 kb to bytes
|
|
755
752
|
100 * 1024
|
|
756
753
|
) {
|
|
757
754
|
console.warn(
|
|
@@ -768,26 +765,28 @@ var maybeWarnFragmentSize = async (filepath) => {
|
|
|
768
765
|
}
|
|
769
766
|
};
|
|
770
767
|
var unlinkIfExists = async (filepath) => {
|
|
771
|
-
if (
|
|
772
|
-
|
|
768
|
+
if (fs.existsSync(filepath)) {
|
|
769
|
+
fs.unlinkSync(filepath);
|
|
773
770
|
}
|
|
774
771
|
};
|
|
775
772
|
|
|
776
773
|
// src/next/config-manager.ts
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
774
|
+
import fs2 from "fs-extra";
|
|
775
|
+
import path3 from "path";
|
|
776
|
+
import os from "os";
|
|
777
|
+
import { pathToFileURL } from "url";
|
|
778
|
+
import * as esbuild from "esbuild";
|
|
779
|
+
import * as dotenv from "dotenv";
|
|
780
|
+
import normalizePath2 from "normalize-path";
|
|
781
|
+
import chalk3 from "chalk";
|
|
782
|
+
import { createRequire } from "module";
|
|
784
783
|
|
|
785
784
|
// src/utils/path.ts
|
|
786
|
-
|
|
785
|
+
import path2 from "path";
|
|
787
786
|
function stripNativeTrailingSlash(p) {
|
|
788
|
-
const { root } =
|
|
787
|
+
const { root } = path2.parse(p);
|
|
789
788
|
let str = p;
|
|
790
|
-
while (str.length > root.length && str.endsWith(
|
|
789
|
+
while (str.length > root.length && str.endsWith(path2.sep)) {
|
|
791
790
|
str = str.slice(0, -1);
|
|
792
791
|
}
|
|
793
792
|
return str;
|
|
@@ -802,17 +801,57 @@ var GRAPHQL_GQL_FILE = "schema.gql";
|
|
|
802
801
|
var SCHEMA_JSON_FILE = "_schema.json";
|
|
803
802
|
var LOOKUP_JSON_FILE = "_lookup.json";
|
|
804
803
|
var ConfigManager = class {
|
|
804
|
+
config;
|
|
805
|
+
rootPath;
|
|
806
|
+
tinaFolderPath;
|
|
807
|
+
isUsingLegacyFolder;
|
|
808
|
+
tinaConfigFilePath;
|
|
809
|
+
tinaSpaPackagePath;
|
|
810
|
+
contentRootPath;
|
|
811
|
+
envFilePath;
|
|
812
|
+
generatedCachePath;
|
|
813
|
+
generatedFolderPath;
|
|
814
|
+
generatedFolderPathContentRepo;
|
|
815
|
+
generatedGraphQLGQLPath;
|
|
816
|
+
generatedGraphQLJSONPath;
|
|
817
|
+
generatedSchemaJSONPath;
|
|
818
|
+
generatedLookupJSONPath;
|
|
819
|
+
generatedTypesTSFilePath;
|
|
820
|
+
generatedTypesJSFilePath;
|
|
821
|
+
generatedTypesDFilePath;
|
|
822
|
+
generatedClientTSFilePath;
|
|
823
|
+
generatedClientJSFilePath;
|
|
824
|
+
generatedClientDFilePath;
|
|
825
|
+
generatedDatabaseClientJSFilePath;
|
|
826
|
+
generatedDatabaseClientTSFilePath;
|
|
827
|
+
generatedDatabaseClientDFilePath;
|
|
828
|
+
generatedQueriesFilePath;
|
|
829
|
+
generatedFragmentsFilePath;
|
|
830
|
+
generatedQueriesAndFragmentsGlob;
|
|
831
|
+
userQueriesAndFragmentsGlob;
|
|
832
|
+
publicFolderPath;
|
|
833
|
+
outputFolderPath;
|
|
834
|
+
outputHTMLFilePath;
|
|
835
|
+
outputGitignorePath;
|
|
836
|
+
selfHostedDatabaseFilePath;
|
|
837
|
+
prebuildFilePath;
|
|
838
|
+
spaRootPath;
|
|
839
|
+
spaMainPath;
|
|
840
|
+
spaHTMLPath;
|
|
841
|
+
tinaGraphQLVersionFromCLI;
|
|
842
|
+
legacyNoSDK;
|
|
843
|
+
watchList;
|
|
805
844
|
constructor({
|
|
806
845
|
rootPath = process.cwd(),
|
|
807
846
|
tinaGraphQLVersion,
|
|
808
847
|
legacyNoSDK
|
|
809
848
|
}) {
|
|
810
|
-
this.rootPath = (
|
|
849
|
+
this.rootPath = normalizePath2(rootPath);
|
|
811
850
|
this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
|
|
812
851
|
this.legacyNoSDK = legacyNoSDK;
|
|
813
852
|
}
|
|
814
853
|
isUsingTs() {
|
|
815
|
-
return [".ts", ".tsx"].includes(
|
|
854
|
+
return [".ts", ".tsx"].includes(path3.extname(this.tinaConfigFilePath));
|
|
816
855
|
}
|
|
817
856
|
hasSelfHostedConfig() {
|
|
818
857
|
return !!this.selfHostedDatabaseFilePath;
|
|
@@ -827,13 +866,14 @@ var ConfigManager = class {
|
|
|
827
866
|
return this.config.client?.skip || false;
|
|
828
867
|
}
|
|
829
868
|
async processConfig() {
|
|
869
|
+
const require2 = createRequire(import.meta.url);
|
|
830
870
|
this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
|
|
831
|
-
this.envFilePath =
|
|
832
|
-
|
|
871
|
+
this.envFilePath = path3.resolve(
|
|
872
|
+
path3.join(this.tinaFolderPath, "..", ".env")
|
|
833
873
|
);
|
|
834
874
|
dotenv.config({ path: this.envFilePath });
|
|
835
875
|
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
836
|
-
|
|
876
|
+
path3.join(this.tinaFolderPath, "config")
|
|
837
877
|
);
|
|
838
878
|
if (!this.tinaConfigFilePath) {
|
|
839
879
|
throw new Error(
|
|
@@ -841,89 +881,89 @@ var ConfigManager = class {
|
|
|
841
881
|
);
|
|
842
882
|
}
|
|
843
883
|
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
844
|
-
|
|
884
|
+
path3.join(this.tinaFolderPath, "database")
|
|
845
885
|
);
|
|
846
|
-
this.generatedFolderPath =
|
|
847
|
-
this.generatedCachePath =
|
|
886
|
+
this.generatedFolderPath = path3.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
887
|
+
this.generatedCachePath = path3.join(
|
|
848
888
|
this.generatedFolderPath,
|
|
849
889
|
".cache",
|
|
850
890
|
String((/* @__PURE__ */ new Date()).getTime())
|
|
851
891
|
);
|
|
852
|
-
this.generatedGraphQLGQLPath =
|
|
892
|
+
this.generatedGraphQLGQLPath = path3.join(
|
|
853
893
|
this.generatedFolderPath,
|
|
854
894
|
GRAPHQL_GQL_FILE
|
|
855
895
|
);
|
|
856
|
-
this.generatedGraphQLJSONPath =
|
|
896
|
+
this.generatedGraphQLJSONPath = path3.join(
|
|
857
897
|
this.generatedFolderPath,
|
|
858
898
|
GRAPHQL_JSON_FILE
|
|
859
899
|
);
|
|
860
|
-
this.generatedSchemaJSONPath =
|
|
900
|
+
this.generatedSchemaJSONPath = path3.join(
|
|
861
901
|
this.generatedFolderPath,
|
|
862
902
|
SCHEMA_JSON_FILE
|
|
863
903
|
);
|
|
864
|
-
this.generatedLookupJSONPath =
|
|
904
|
+
this.generatedLookupJSONPath = path3.join(
|
|
865
905
|
this.generatedFolderPath,
|
|
866
906
|
LOOKUP_JSON_FILE
|
|
867
907
|
);
|
|
868
|
-
this.generatedQueriesFilePath =
|
|
908
|
+
this.generatedQueriesFilePath = path3.join(
|
|
869
909
|
this.generatedFolderPath,
|
|
870
910
|
"queries.gql"
|
|
871
911
|
);
|
|
872
|
-
this.generatedFragmentsFilePath =
|
|
912
|
+
this.generatedFragmentsFilePath = path3.join(
|
|
873
913
|
this.generatedFolderPath,
|
|
874
914
|
"frags.gql"
|
|
875
915
|
);
|
|
876
|
-
this.generatedTypesTSFilePath =
|
|
916
|
+
this.generatedTypesTSFilePath = path3.join(
|
|
877
917
|
this.generatedFolderPath,
|
|
878
918
|
"types.ts"
|
|
879
919
|
);
|
|
880
|
-
this.generatedTypesJSFilePath =
|
|
920
|
+
this.generatedTypesJSFilePath = path3.join(
|
|
881
921
|
this.generatedFolderPath,
|
|
882
922
|
"types.js"
|
|
883
923
|
);
|
|
884
|
-
this.generatedTypesDFilePath =
|
|
924
|
+
this.generatedTypesDFilePath = path3.join(
|
|
885
925
|
this.generatedFolderPath,
|
|
886
926
|
"types.d.ts"
|
|
887
927
|
);
|
|
888
|
-
this.userQueriesAndFragmentsGlob =
|
|
928
|
+
this.userQueriesAndFragmentsGlob = path3.join(
|
|
889
929
|
this.tinaFolderPath,
|
|
890
930
|
"queries/**/*.{graphql,gql}"
|
|
891
931
|
);
|
|
892
|
-
this.generatedQueriesAndFragmentsGlob =
|
|
932
|
+
this.generatedQueriesAndFragmentsGlob = path3.join(
|
|
893
933
|
this.generatedFolderPath,
|
|
894
934
|
"*.{graphql,gql}"
|
|
895
935
|
);
|
|
896
|
-
this.generatedClientTSFilePath =
|
|
936
|
+
this.generatedClientTSFilePath = path3.join(
|
|
897
937
|
this.generatedFolderPath,
|
|
898
938
|
"client.ts"
|
|
899
939
|
);
|
|
900
|
-
this.generatedClientJSFilePath =
|
|
940
|
+
this.generatedClientJSFilePath = path3.join(
|
|
901
941
|
this.generatedFolderPath,
|
|
902
942
|
"client.js"
|
|
903
943
|
);
|
|
904
|
-
this.generatedClientDFilePath =
|
|
944
|
+
this.generatedClientDFilePath = path3.join(
|
|
905
945
|
this.generatedFolderPath,
|
|
906
946
|
"client.d.ts"
|
|
907
947
|
);
|
|
908
|
-
this.generatedDatabaseClientDFilePath =
|
|
948
|
+
this.generatedDatabaseClientDFilePath = path3.join(
|
|
909
949
|
this.generatedFolderPath,
|
|
910
950
|
"databaseClient.d.ts"
|
|
911
951
|
);
|
|
912
|
-
this.generatedDatabaseClientTSFilePath =
|
|
952
|
+
this.generatedDatabaseClientTSFilePath = path3.join(
|
|
913
953
|
this.generatedFolderPath,
|
|
914
954
|
"databaseClient.ts"
|
|
915
955
|
);
|
|
916
|
-
this.generatedDatabaseClientJSFilePath =
|
|
956
|
+
this.generatedDatabaseClientJSFilePath = path3.join(
|
|
917
957
|
this.generatedFolderPath,
|
|
918
958
|
"databaseClient.js"
|
|
919
959
|
);
|
|
920
|
-
const clientExists = this.isUsingTs() ? await
|
|
960
|
+
const clientExists = this.isUsingTs() ? await fs2.pathExists(this.generatedClientTSFilePath) : await fs2.pathExists(this.generatedClientJSFilePath);
|
|
921
961
|
if (!clientExists) {
|
|
922
962
|
const file = "export default ()=>({})\nexport const client = ()=>({})";
|
|
923
963
|
if (this.isUsingTs()) {
|
|
924
|
-
await
|
|
964
|
+
await fs2.outputFile(this.generatedClientTSFilePath, file);
|
|
925
965
|
} else {
|
|
926
|
-
await
|
|
966
|
+
await fs2.outputFile(this.generatedClientJSFilePath, file);
|
|
927
967
|
}
|
|
928
968
|
}
|
|
929
969
|
const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
|
|
@@ -933,29 +973,29 @@ var ConfigManager = class {
|
|
|
933
973
|
this.watchList = watchList;
|
|
934
974
|
this.config = config2;
|
|
935
975
|
this.prebuildFilePath = prebuildPath;
|
|
936
|
-
this.publicFolderPath =
|
|
976
|
+
this.publicFolderPath = path3.join(
|
|
937
977
|
this.rootPath,
|
|
938
978
|
this.config.build.publicFolder
|
|
939
979
|
);
|
|
940
|
-
this.outputFolderPath =
|
|
980
|
+
this.outputFolderPath = path3.join(
|
|
941
981
|
this.publicFolderPath,
|
|
942
982
|
this.config.build.outputFolder
|
|
943
983
|
);
|
|
944
|
-
this.outputHTMLFilePath =
|
|
945
|
-
this.outputGitignorePath =
|
|
984
|
+
this.outputHTMLFilePath = path3.join(this.outputFolderPath, "index.html");
|
|
985
|
+
this.outputGitignorePath = path3.join(this.outputFolderPath, ".gitignore");
|
|
946
986
|
const fullLocalContentPath = stripNativeTrailingSlash(
|
|
947
|
-
|
|
987
|
+
path3.join(this.tinaFolderPath, this.config.localContentPath || "")
|
|
948
988
|
);
|
|
949
989
|
if (this.config.localContentPath) {
|
|
950
|
-
const localContentPathExists = await
|
|
990
|
+
const localContentPathExists = await fs2.pathExists(fullLocalContentPath);
|
|
951
991
|
if (localContentPathExists) {
|
|
952
992
|
logger.info(`Using separate content repo at ${fullLocalContentPath}`);
|
|
953
993
|
this.contentRootPath = fullLocalContentPath;
|
|
954
994
|
} else {
|
|
955
995
|
logger.warn(
|
|
956
|
-
`${
|
|
996
|
+
`${chalk3.yellow("Warning:")} The localContentPath ${chalk3.cyan(
|
|
957
997
|
fullLocalContentPath
|
|
958
|
-
)} does not exist. Please create it or remove the localContentPath from your config file at ${
|
|
998
|
+
)} does not exist. Please create it or remove the localContentPath from your config file at ${chalk3.cyan(
|
|
959
999
|
this.tinaConfigFilePath
|
|
960
1000
|
)}`
|
|
961
1001
|
);
|
|
@@ -964,22 +1004,22 @@ var ConfigManager = class {
|
|
|
964
1004
|
if (!this.contentRootPath) {
|
|
965
1005
|
this.contentRootPath = this.rootPath;
|
|
966
1006
|
}
|
|
967
|
-
this.generatedFolderPathContentRepo =
|
|
1007
|
+
this.generatedFolderPathContentRepo = path3.join(
|
|
968
1008
|
await this.getTinaFolderPath(this.contentRootPath),
|
|
969
1009
|
GENERATED_FOLDER
|
|
970
1010
|
);
|
|
971
|
-
this.spaMainPath =
|
|
972
|
-
this.spaRootPath =
|
|
1011
|
+
this.spaMainPath = require2.resolve("@tinacms/app");
|
|
1012
|
+
this.spaRootPath = path3.join(this.spaMainPath, "..", "..");
|
|
973
1013
|
}
|
|
974
1014
|
async getTinaFolderPath(rootPath) {
|
|
975
|
-
const tinaFolderPath =
|
|
976
|
-
const tinaFolderExists = await
|
|
1015
|
+
const tinaFolderPath = path3.join(rootPath, TINA_FOLDER);
|
|
1016
|
+
const tinaFolderExists = await fs2.pathExists(tinaFolderPath);
|
|
977
1017
|
if (tinaFolderExists) {
|
|
978
1018
|
this.isUsingLegacyFolder = false;
|
|
979
1019
|
return tinaFolderPath;
|
|
980
1020
|
}
|
|
981
|
-
const legacyFolderPath =
|
|
982
|
-
const legacyFolderExists = await
|
|
1021
|
+
const legacyFolderPath = path3.join(rootPath, LEGACY_TINA_FOLDER);
|
|
1022
|
+
const legacyFolderExists = await fs2.pathExists(legacyFolderPath);
|
|
983
1023
|
if (legacyFolderExists) {
|
|
984
1024
|
this.isUsingLegacyFolder = true;
|
|
985
1025
|
return legacyFolderPath;
|
|
@@ -998,7 +1038,7 @@ var ConfigManager = class {
|
|
|
998
1038
|
patch: version2[2] || "x"
|
|
999
1039
|
};
|
|
1000
1040
|
}
|
|
1001
|
-
const generatedSchema =
|
|
1041
|
+
const generatedSchema = fs2.readJSONSync(this.generatedSchemaJSONPath);
|
|
1002
1042
|
if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
|
|
1003
1043
|
throw new Error(
|
|
1004
1044
|
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
@@ -1045,7 +1085,7 @@ var ConfigManager = class {
|
|
|
1045
1085
|
return;
|
|
1046
1086
|
}
|
|
1047
1087
|
const filepathWithExtension = `${filepath}.${ext}`;
|
|
1048
|
-
const exists =
|
|
1088
|
+
const exists = fs2.existsSync(filepathWithExtension);
|
|
1049
1089
|
if (exists) {
|
|
1050
1090
|
result = filepathWithExtension;
|
|
1051
1091
|
}
|
|
@@ -1054,33 +1094,53 @@ var ConfigManager = class {
|
|
|
1054
1094
|
return result;
|
|
1055
1095
|
}
|
|
1056
1096
|
async loadDatabaseFile() {
|
|
1057
|
-
const tmpdir =
|
|
1058
|
-
const outfile =
|
|
1097
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1098
|
+
const outfile = path3.join(tmpdir, "database.build.mjs");
|
|
1059
1099
|
await esbuild.build({
|
|
1060
1100
|
entryPoints: [this.selfHostedDatabaseFilePath],
|
|
1061
1101
|
bundle: true,
|
|
1062
1102
|
platform: "node",
|
|
1103
|
+
format: "esm",
|
|
1063
1104
|
outfile,
|
|
1064
|
-
loader: loaders
|
|
1105
|
+
loader: loaders,
|
|
1106
|
+
// Provide a require() polyfill for ESM bundles containing CommonJS packages.
|
|
1107
|
+
// Some bundled packages (e.g., 'scmp' used by 'mongodb-level') use require('crypto').
|
|
1108
|
+
// When esbuild inlines these CommonJS packages, it keeps the require() calls,
|
|
1109
|
+
// but ESM doesn't have a global require. This banner creates one using Node.js's
|
|
1110
|
+
// official createRequire API, allowing the bundled CommonJS code to work in ESM.
|
|
1111
|
+
banner: {
|
|
1112
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
1113
|
+
}
|
|
1065
1114
|
});
|
|
1066
|
-
const result =
|
|
1067
|
-
|
|
1115
|
+
const result = await import(pathToFileURL(outfile).href);
|
|
1116
|
+
fs2.removeSync(outfile);
|
|
1068
1117
|
return result.default;
|
|
1069
1118
|
}
|
|
1070
1119
|
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
1071
|
-
const tmpdir =
|
|
1072
|
-
const preBuildConfigPath =
|
|
1120
|
+
const tmpdir = path3.join(os.tmpdir(), Date.now().toString());
|
|
1121
|
+
const preBuildConfigPath = path3.join(
|
|
1073
1122
|
this.generatedFolderPath,
|
|
1074
1123
|
"config.prebuild.jsx"
|
|
1075
1124
|
);
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1125
|
+
const nativeNodeModulesPlugin = {
|
|
1126
|
+
name: "native-node-modules",
|
|
1127
|
+
setup(build3) {
|
|
1128
|
+
build3.onResolve({ filter: /^node:.*/ }, (args) => {
|
|
1129
|
+
return {
|
|
1130
|
+
path: args.path,
|
|
1131
|
+
external: true
|
|
1132
|
+
};
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
const outfile = path3.join(tmpdir, "config.build.jsx");
|
|
1137
|
+
const outfile2 = path3.join(tmpdir, "config.build.mjs");
|
|
1138
|
+
const tempTSConfigFile = path3.join(tmpdir, "tsconfig.json");
|
|
1139
|
+
fs2.outputFileSync(tempTSConfigFile, "{}");
|
|
1080
1140
|
const result2 = await esbuild.build({
|
|
1081
1141
|
entryPoints: [configFilePath],
|
|
1082
1142
|
bundle: true,
|
|
1083
|
-
target: ["
|
|
1143
|
+
target: ["esnext"],
|
|
1084
1144
|
platform: "browser",
|
|
1085
1145
|
format: "esm",
|
|
1086
1146
|
logLevel: "silent",
|
|
@@ -1100,9 +1160,10 @@ var ConfigManager = class {
|
|
|
1100
1160
|
await esbuild.build({
|
|
1101
1161
|
entryPoints: [configFilePath],
|
|
1102
1162
|
bundle: true,
|
|
1103
|
-
target: ["
|
|
1163
|
+
target: ["esnext"],
|
|
1104
1164
|
logLevel: "silent",
|
|
1105
1165
|
platform: "node",
|
|
1166
|
+
format: "esm",
|
|
1106
1167
|
outfile,
|
|
1107
1168
|
loader: loaders
|
|
1108
1169
|
});
|
|
@@ -1112,19 +1173,21 @@ var ConfigManager = class {
|
|
|
1112
1173
|
// Suppress warning about comparison with -0 from client module
|
|
1113
1174
|
logLevel: "silent",
|
|
1114
1175
|
platform: "node",
|
|
1176
|
+
target: ["esnext"],
|
|
1177
|
+
format: "esm",
|
|
1115
1178
|
outfile: outfile2,
|
|
1116
1179
|
loader: loaders
|
|
1117
1180
|
});
|
|
1118
1181
|
let result;
|
|
1119
1182
|
try {
|
|
1120
|
-
result =
|
|
1183
|
+
result = await import(pathToFileURL(outfile2).href);
|
|
1121
1184
|
} catch (e) {
|
|
1122
1185
|
console.error("Unexpected error loading config");
|
|
1123
1186
|
console.error(e);
|
|
1124
1187
|
throw e;
|
|
1125
1188
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1189
|
+
fs2.removeSync(outfile);
|
|
1190
|
+
fs2.removeSync(outfile2);
|
|
1128
1191
|
return {
|
|
1129
1192
|
config: result.default,
|
|
1130
1193
|
prebuildPath: preBuildConfigPath,
|
|
@@ -1159,20 +1222,24 @@ var loaders = {
|
|
|
1159
1222
|
};
|
|
1160
1223
|
|
|
1161
1224
|
// src/next/database.ts
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1225
|
+
import {
|
|
1226
|
+
createDatabaseInternal,
|
|
1227
|
+
FilesystemBridge,
|
|
1228
|
+
TinaLevelClient
|
|
1229
|
+
} from "@tinacms/graphql";
|
|
1230
|
+
import { pipeline } from "readable-stream";
|
|
1231
|
+
import { createServer } from "net";
|
|
1232
|
+
import { ManyLevelHost } from "many-level";
|
|
1233
|
+
import { MemoryLevel } from "memory-level";
|
|
1167
1234
|
var createDBServer = (port) => {
|
|
1168
|
-
const levelHost = new
|
|
1235
|
+
const levelHost = new ManyLevelHost(
|
|
1169
1236
|
// @ts-ignore
|
|
1170
|
-
new
|
|
1237
|
+
new MemoryLevel({
|
|
1171
1238
|
valueEncoding: "json"
|
|
1172
1239
|
})
|
|
1173
1240
|
);
|
|
1174
|
-
const dbServer =
|
|
1175
|
-
return
|
|
1241
|
+
const dbServer = createServer(function(socket) {
|
|
1242
|
+
return pipeline(socket, levelHost.createRpcStream(), socket, () => {
|
|
1176
1243
|
});
|
|
1177
1244
|
});
|
|
1178
1245
|
dbServer.once("error", (err) => {
|
|
@@ -1186,7 +1253,7 @@ var createDBServer = (port) => {
|
|
|
1186
1253
|
};
|
|
1187
1254
|
async function createAndInitializeDatabase(configManager, datalayerPort, bridgeOverride) {
|
|
1188
1255
|
let database;
|
|
1189
|
-
const bridge = bridgeOverride || new
|
|
1256
|
+
const bridge = bridgeOverride || new FilesystemBridge(configManager.rootPath, configManager.contentRootPath);
|
|
1190
1257
|
if (configManager.hasSelfHostedConfig() && configManager.config.contentApiUrlOverride) {
|
|
1191
1258
|
database = await configManager.loadDatabaseFile();
|
|
1192
1259
|
database.bridge = bridge;
|
|
@@ -1198,9 +1265,9 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1198
1265
|
)} but there was no "contentApiUrlOverride" set. Falling back to built-in datalayer`
|
|
1199
1266
|
);
|
|
1200
1267
|
}
|
|
1201
|
-
const level = new
|
|
1268
|
+
const level = new TinaLevelClient(datalayerPort);
|
|
1202
1269
|
level.openConnection();
|
|
1203
|
-
database =
|
|
1270
|
+
database = createDatabaseInternal({
|
|
1204
1271
|
bridge,
|
|
1205
1272
|
level,
|
|
1206
1273
|
tinaDirectory: configManager.isUsingLegacyFolder ? LEGACY_TINA_FOLDER : TINA_FOLDER
|
|
@@ -1210,17 +1277,17 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1210
1277
|
}
|
|
1211
1278
|
|
|
1212
1279
|
// src/next/commands/baseCommands.ts
|
|
1213
|
-
|
|
1214
|
-
|
|
1280
|
+
import { Command, Option } from "clipanion";
|
|
1281
|
+
import chalk4 from "chalk";
|
|
1215
1282
|
|
|
1216
1283
|
// src/utils/start-subprocess.ts
|
|
1217
|
-
|
|
1284
|
+
import childProcess from "child_process";
|
|
1218
1285
|
var startSubprocess2 = async ({ command: command2 }) => {
|
|
1219
1286
|
if (typeof command2 === "string") {
|
|
1220
1287
|
const commands = command2.split(" ");
|
|
1221
1288
|
const firstCommand = commands[0];
|
|
1222
1289
|
const args = commands.slice(1) || [];
|
|
1223
|
-
const ps =
|
|
1290
|
+
const ps = childProcess.spawn(firstCommand, args, {
|
|
1224
1291
|
stdio: "inherit",
|
|
1225
1292
|
shell: true
|
|
1226
1293
|
});
|
|
@@ -1244,45 +1311,42 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
1244
1311
|
};
|
|
1245
1312
|
|
|
1246
1313
|
// 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
|
-
}
|
|
1314
|
+
import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
|
|
1315
|
+
import fs3 from "fs-extra";
|
|
1316
|
+
var BaseCommand = class extends Command {
|
|
1317
|
+
experimentalDataLayer = Option.Boolean("--experimentalData", {
|
|
1318
|
+
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
1319
|
+
});
|
|
1320
|
+
isomorphicGitBridge = Option.Boolean("--isomorphicGitBridge", {
|
|
1321
|
+
description: "DEPRECATED - Enable Isomorphic Git Bridge Implementation"
|
|
1322
|
+
});
|
|
1323
|
+
port = Option.String("-p,--port", "4001", {
|
|
1324
|
+
description: "Specify a port to run the server on. (default 4001)"
|
|
1325
|
+
});
|
|
1326
|
+
datalayerPort = Option.String("--datalayer-port", "9000", {
|
|
1327
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
1328
|
+
});
|
|
1329
|
+
subCommand = Option.String("-c,--command", {
|
|
1330
|
+
description: "The sub-command to run"
|
|
1331
|
+
});
|
|
1332
|
+
rootPath = Option.String("--rootPath", {
|
|
1333
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
1334
|
+
});
|
|
1335
|
+
verbose = Option.Boolean("-v,--verbose", false, {
|
|
1336
|
+
description: "increase verbosity of logged output"
|
|
1337
|
+
});
|
|
1338
|
+
noSDK = Option.Boolean("--noSDK", false, {
|
|
1339
|
+
description: "DEPRECATED - This should now be set in the config at client.skip = true'. Don't generate the generated client SDK"
|
|
1340
|
+
});
|
|
1341
|
+
noTelemetry = Option.Boolean("--noTelemetry", false, {
|
|
1342
|
+
description: "Disable anonymous telemetry that is collected"
|
|
1343
|
+
});
|
|
1280
1344
|
async startSubCommand() {
|
|
1281
1345
|
let subProc;
|
|
1282
1346
|
if (this.subCommand) {
|
|
1283
1347
|
subProc = await startSubprocess2({ command: this.subCommand });
|
|
1284
1348
|
logger.info(
|
|
1285
|
-
`Running web application with command: ${
|
|
1349
|
+
`Running web application with command: ${chalk4.cyan(this.subCommand)}`
|
|
1286
1350
|
);
|
|
1287
1351
|
}
|
|
1288
1352
|
function exitHandler(options, exitCode) {
|
|
@@ -1330,7 +1394,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1330
1394
|
const rootPath = configManager.rootPath;
|
|
1331
1395
|
let sha;
|
|
1332
1396
|
try {
|
|
1333
|
-
sha = await
|
|
1397
|
+
sha = await getSha({ fs: fs3, dir: rootPath });
|
|
1334
1398
|
} catch (e) {
|
|
1335
1399
|
if (partialReindex) {
|
|
1336
1400
|
console.error(
|
|
@@ -1340,7 +1404,7 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1340
1404
|
}
|
|
1341
1405
|
}
|
|
1342
1406
|
const lastSha = await database.getMetadata("lastSha");
|
|
1343
|
-
const exists = lastSha && await
|
|
1407
|
+
const exists = lastSha && await shaExists({ fs: fs3, dir: rootPath, sha: lastSha });
|
|
1344
1408
|
let res;
|
|
1345
1409
|
if (partialReindex && lastSha && exists && sha) {
|
|
1346
1410
|
const pathFilter = {};
|
|
@@ -1354,8 +1418,8 @@ var BaseCommand = class extends import_clipanion.Command {
|
|
|
1354
1418
|
matches: collection.match?.exclude || collection.match?.include ? tinaSchema.getMatches({ collection }) : void 0
|
|
1355
1419
|
};
|
|
1356
1420
|
}
|
|
1357
|
-
const { added, modified, deleted } = await
|
|
1358
|
-
fs:
|
|
1421
|
+
const { added, modified, deleted } = await getChangedFiles({
|
|
1422
|
+
fs: fs3,
|
|
1359
1423
|
dir: rootPath,
|
|
1360
1424
|
from: lastSha,
|
|
1361
1425
|
to: sha,
|
|
@@ -1478,34 +1542,38 @@ var devHTML = (port) => `<!DOCTYPE html>
|
|
|
1478
1542
|
</html>`;
|
|
1479
1543
|
|
|
1480
1544
|
// src/next/commands/dev-command/server/index.ts
|
|
1481
|
-
|
|
1545
|
+
import { createServer as createViteServer } from "vite";
|
|
1482
1546
|
|
|
1483
1547
|
// src/next/vite/index.ts
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1548
|
+
import path5 from "node:path";
|
|
1549
|
+
import react from "@vitejs/plugin-react";
|
|
1550
|
+
import fs4 from "fs-extra";
|
|
1551
|
+
import normalizePath3 from "normalize-path";
|
|
1552
|
+
import {
|
|
1553
|
+
splitVendorChunkPlugin
|
|
1554
|
+
} from "vite";
|
|
1489
1555
|
|
|
1490
1556
|
// src/next/vite/tailwind.ts
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1557
|
+
import path4 from "node:path";
|
|
1558
|
+
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
1559
|
+
import containerQueries from "@tailwindcss/container-queries";
|
|
1560
|
+
import twTypography from "@tailwindcss/typography";
|
|
1561
|
+
import tailwind from "tailwindcss";
|
|
1562
|
+
import defaultTheme from "tailwindcss/defaultTheme.js";
|
|
1563
|
+
import { createRequire as createRequire2 } from "module";
|
|
1497
1564
|
var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
1498
1565
|
return {
|
|
1499
1566
|
name: "vite-plugin-tina",
|
|
1500
1567
|
// @ts-ignore
|
|
1501
1568
|
config: (viteConfig) => {
|
|
1569
|
+
const require2 = createRequire2(import.meta.url);
|
|
1502
1570
|
const plugins = [];
|
|
1503
1571
|
const content = [
|
|
1504
|
-
|
|
1572
|
+
path4.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
1505
1573
|
prebuildFilePath,
|
|
1506
|
-
|
|
1574
|
+
require2.resolve("tinacms")
|
|
1507
1575
|
];
|
|
1508
|
-
const tw = (
|
|
1576
|
+
const tw = tailwind({
|
|
1509
1577
|
theme: {
|
|
1510
1578
|
columns: {
|
|
1511
1579
|
auto: "auto",
|
|
@@ -1717,7 +1785,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1717
1785
|
ring: "#0A0A0A"
|
|
1718
1786
|
},
|
|
1719
1787
|
fontFamily: {
|
|
1720
|
-
sans: ["Inter", ...
|
|
1788
|
+
sans: ["Inter", ...defaultTheme.fontFamily.sans]
|
|
1721
1789
|
},
|
|
1722
1790
|
lineHeight: {
|
|
1723
1791
|
3: "12px",
|
|
@@ -1742,9 +1810,9 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1742
1810
|
},
|
|
1743
1811
|
content,
|
|
1744
1812
|
plugins: [
|
|
1745
|
-
(
|
|
1746
|
-
|
|
1747
|
-
|
|
1813
|
+
twTypography({ className: "tina-prose" }),
|
|
1814
|
+
aspectRatio,
|
|
1815
|
+
containerQueries
|
|
1748
1816
|
]
|
|
1749
1817
|
});
|
|
1750
1818
|
plugins.push(tw);
|
|
@@ -1765,35 +1833,35 @@ async function listFilesRecursively({
|
|
|
1765
1833
|
config: config2,
|
|
1766
1834
|
roothPath
|
|
1767
1835
|
}) {
|
|
1768
|
-
const fullDirectoryPath =
|
|
1836
|
+
const fullDirectoryPath = path5.join(
|
|
1769
1837
|
roothPath,
|
|
1770
1838
|
config2.publicFolder,
|
|
1771
1839
|
directoryPath
|
|
1772
1840
|
);
|
|
1773
|
-
const exists = await
|
|
1841
|
+
const exists = await fs4.pathExists(fullDirectoryPath);
|
|
1774
1842
|
if (!exists) {
|
|
1775
1843
|
return { "0": [] };
|
|
1776
1844
|
}
|
|
1777
|
-
const items = await
|
|
1845
|
+
const items = await fs4.readdir(fullDirectoryPath);
|
|
1778
1846
|
const staticMediaItems = [];
|
|
1779
1847
|
for (const item of items) {
|
|
1780
|
-
const itemPath =
|
|
1781
|
-
const stats = await
|
|
1848
|
+
const itemPath = path5.join(fullDirectoryPath, item);
|
|
1849
|
+
const stats = await fs4.promises.lstat(itemPath);
|
|
1782
1850
|
const staticMediaItem = {
|
|
1783
1851
|
id: item,
|
|
1784
1852
|
filename: item,
|
|
1785
1853
|
type: stats.isDirectory() ? "dir" : "file",
|
|
1786
1854
|
directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
|
|
1787
|
-
src: `/${
|
|
1855
|
+
src: `/${path5.join(directoryPath, item)}`,
|
|
1788
1856
|
thumbnails: {
|
|
1789
|
-
"75x75": `/${
|
|
1790
|
-
"400x400": `/${
|
|
1791
|
-
"1000x1000": `/${
|
|
1857
|
+
"75x75": `/${path5.join(directoryPath, item)}`,
|
|
1858
|
+
"400x400": `/${path5.join(directoryPath, item)}`,
|
|
1859
|
+
"1000x1000": `/${path5.join(directoryPath, item)}`
|
|
1792
1860
|
}
|
|
1793
1861
|
};
|
|
1794
1862
|
if (stats.isDirectory()) {
|
|
1795
1863
|
staticMediaItem.children = await listFilesRecursively({
|
|
1796
|
-
directoryPath:
|
|
1864
|
+
directoryPath: path5.join(directoryPath, item),
|
|
1797
1865
|
config: config2,
|
|
1798
1866
|
roothPath
|
|
1799
1867
|
});
|
|
@@ -1834,7 +1902,7 @@ var createConfig = async ({
|
|
|
1834
1902
|
}
|
|
1835
1903
|
}
|
|
1836
1904
|
});
|
|
1837
|
-
const staticMediaPath =
|
|
1905
|
+
const staticMediaPath = path5.join(
|
|
1838
1906
|
configManager.generatedFolderPath,
|
|
1839
1907
|
"static-media.json"
|
|
1840
1908
|
);
|
|
@@ -1844,21 +1912,21 @@ var createConfig = async ({
|
|
|
1844
1912
|
config: configManager.config.media.tina,
|
|
1845
1913
|
roothPath: configManager.rootPath
|
|
1846
1914
|
});
|
|
1847
|
-
await
|
|
1915
|
+
await fs4.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
|
|
1848
1916
|
} else {
|
|
1849
|
-
await
|
|
1917
|
+
await fs4.outputFile(staticMediaPath, `[]`);
|
|
1850
1918
|
}
|
|
1851
1919
|
const alias = {
|
|
1852
1920
|
TINA_IMPORT: configManager.prebuildFilePath,
|
|
1853
1921
|
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
|
|
1854
1922
|
STATIC_MEDIA_IMPORT: staticMediaPath,
|
|
1855
|
-
crypto:
|
|
1856
|
-
fs:
|
|
1857
|
-
os:
|
|
1858
|
-
path:
|
|
1923
|
+
crypto: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1924
|
+
fs: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1925
|
+
os: path5.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
1926
|
+
path: path5.join(configManager.spaRootPath, "src", "dummy-client.ts")
|
|
1859
1927
|
};
|
|
1860
1928
|
if (configManager.shouldSkipSDK()) {
|
|
1861
|
-
alias["CLIENT_IMPORT"] =
|
|
1929
|
+
alias["CLIENT_IMPORT"] = path5.join(
|
|
1862
1930
|
configManager.spaRootPath,
|
|
1863
1931
|
"src",
|
|
1864
1932
|
"dummy-client.ts"
|
|
@@ -1874,7 +1942,7 @@ var createConfig = async ({
|
|
|
1874
1942
|
const version2 = `${fullVersion.major}.${fullVersion.minor}`;
|
|
1875
1943
|
const config2 = {
|
|
1876
1944
|
root: configManager.spaRootPath,
|
|
1877
|
-
base: `/${basePath ? `${(
|
|
1945
|
+
base: `/${basePath ? `${normalizePath3(basePath)}/` : ""}${normalizePath3(
|
|
1878
1946
|
configManager.config.build.outputFolder
|
|
1879
1947
|
)}/`,
|
|
1880
1948
|
appType: "spa",
|
|
@@ -1937,14 +2005,14 @@ var createConfig = async ({
|
|
|
1937
2005
|
* `splitVendorChunkPlugin` is needed because `tinacms` is quite large,
|
|
1938
2006
|
* Vite's chunking strategy chokes on memory issues for smaller machines (ie. on CI).
|
|
1939
2007
|
*/
|
|
1940
|
-
(
|
|
2008
|
+
react({
|
|
1941
2009
|
babel: {
|
|
1942
2010
|
// Supresses the warning [NOTE] babel The code generator has deoptimised the styling of
|
|
1943
2011
|
compact: true
|
|
1944
2012
|
},
|
|
1945
2013
|
fastRefresh: false
|
|
1946
2014
|
}),
|
|
1947
|
-
|
|
2015
|
+
splitVendorChunkPlugin(),
|
|
1948
2016
|
tinaTailwind(configManager.spaRootPath, configManager.prebuildFilePath),
|
|
1949
2017
|
...plugins
|
|
1950
2018
|
]
|
|
@@ -1953,21 +2021,21 @@ var createConfig = async ({
|
|
|
1953
2021
|
};
|
|
1954
2022
|
|
|
1955
2023
|
// src/next/vite/plugins.ts
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
2024
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
2025
|
+
import fs6 from "fs";
|
|
2026
|
+
import { transformWithEsbuild } from "vite";
|
|
2027
|
+
import { transform as esbuildTransform } from "esbuild";
|
|
2028
|
+
import path7 from "path";
|
|
2029
|
+
import bodyParser from "body-parser";
|
|
2030
|
+
import cors from "cors";
|
|
2031
|
+
import { resolve as gqlResolve } from "@tinacms/graphql";
|
|
1964
2032
|
|
|
1965
2033
|
// src/next/commands/dev-command/server/media.ts
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2034
|
+
import fs5 from "fs-extra";
|
|
2035
|
+
import path6, { join } from "path";
|
|
2036
|
+
import busboy from "busboy";
|
|
1969
2037
|
var createMediaRouter = (config2) => {
|
|
1970
|
-
const mediaFolder =
|
|
2038
|
+
const mediaFolder = path6.join(
|
|
1971
2039
|
config2.rootPath,
|
|
1972
2040
|
config2.publicFolder,
|
|
1973
2041
|
config2.mediaRoot
|
|
@@ -1991,12 +2059,12 @@ var createMediaRouter = (config2) => {
|
|
|
1991
2059
|
res.end(JSON.stringify(didDelete));
|
|
1992
2060
|
};
|
|
1993
2061
|
const handlePost = async function(req, res) {
|
|
1994
|
-
const bb = (
|
|
2062
|
+
const bb = busboy({ headers: req.headers });
|
|
1995
2063
|
bb.on("file", async (_name, file, _info) => {
|
|
1996
2064
|
const fullPath = decodeURI(req.url?.slice("/media/upload/".length));
|
|
1997
|
-
const saveTo =
|
|
1998
|
-
await
|
|
1999
|
-
file.pipe(
|
|
2065
|
+
const saveTo = path6.join(mediaFolder, ...fullPath.split("/"));
|
|
2066
|
+
await fs5.ensureDir(path6.dirname(saveTo));
|
|
2067
|
+
file.pipe(fs5.createWriteStream(saveTo));
|
|
2000
2068
|
});
|
|
2001
2069
|
bb.on("error", (error) => {
|
|
2002
2070
|
res.statusCode = 500;
|
|
@@ -2022,6 +2090,9 @@ var parseMediaFolder = (str) => {
|
|
|
2022
2090
|
return returnString;
|
|
2023
2091
|
};
|
|
2024
2092
|
var MediaModel = class {
|
|
2093
|
+
rootPath;
|
|
2094
|
+
publicFolder;
|
|
2095
|
+
mediaRoot;
|
|
2025
2096
|
constructor({ rootPath, publicFolder, mediaRoot }) {
|
|
2026
2097
|
this.rootPath = rootPath;
|
|
2027
2098
|
this.mediaRoot = mediaRoot;
|
|
@@ -2029,23 +2100,23 @@ var MediaModel = class {
|
|
|
2029
2100
|
}
|
|
2030
2101
|
async listMedia(args) {
|
|
2031
2102
|
try {
|
|
2032
|
-
const folderPath =
|
|
2103
|
+
const folderPath = join(
|
|
2033
2104
|
this.rootPath,
|
|
2034
2105
|
this.publicFolder,
|
|
2035
2106
|
this.mediaRoot,
|
|
2036
2107
|
decodeURIComponent(args.searchPath)
|
|
2037
2108
|
);
|
|
2038
2109
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
2039
|
-
if (!await
|
|
2110
|
+
if (!await fs5.pathExists(folderPath)) {
|
|
2040
2111
|
return {
|
|
2041
2112
|
files: [],
|
|
2042
2113
|
directories: []
|
|
2043
2114
|
};
|
|
2044
2115
|
}
|
|
2045
|
-
const filesStr = await
|
|
2116
|
+
const filesStr = await fs5.readdir(folderPath);
|
|
2046
2117
|
const filesProm = filesStr.map(async (file) => {
|
|
2047
|
-
const filePath =
|
|
2048
|
-
const stat = await
|
|
2118
|
+
const filePath = join(folderPath, file);
|
|
2119
|
+
const stat = await fs5.stat(filePath);
|
|
2049
2120
|
let src = `/${file}`;
|
|
2050
2121
|
const isFile = stat.isFile();
|
|
2051
2122
|
if (!isFile) {
|
|
@@ -2101,14 +2172,14 @@ var MediaModel = class {
|
|
|
2101
2172
|
}
|
|
2102
2173
|
async deleteMedia(args) {
|
|
2103
2174
|
try {
|
|
2104
|
-
const file =
|
|
2175
|
+
const file = join(
|
|
2105
2176
|
this.rootPath,
|
|
2106
2177
|
this.publicFolder,
|
|
2107
2178
|
this.mediaRoot,
|
|
2108
2179
|
decodeURIComponent(args.searchPath)
|
|
2109
2180
|
);
|
|
2110
|
-
await
|
|
2111
|
-
await
|
|
2181
|
+
await fs5.stat(file);
|
|
2182
|
+
await fs5.remove(file);
|
|
2112
2183
|
return { ok: true };
|
|
2113
2184
|
} catch (error) {
|
|
2114
2185
|
console.error(error);
|
|
@@ -2166,9 +2237,9 @@ var transformTsxPlugin = ({
|
|
|
2166
2237
|
const plug = {
|
|
2167
2238
|
name: "transform-tsx",
|
|
2168
2239
|
async transform(code, id) {
|
|
2169
|
-
const extName =
|
|
2240
|
+
const extName = path7.extname(id);
|
|
2170
2241
|
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
2171
|
-
const result = await (
|
|
2242
|
+
const result = await esbuildTransform(code, { loader: "tsx" });
|
|
2172
2243
|
return {
|
|
2173
2244
|
code: result.code
|
|
2174
2245
|
};
|
|
@@ -2187,8 +2258,8 @@ var devServerEndPointsPlugin = ({
|
|
|
2187
2258
|
const plug = {
|
|
2188
2259
|
name: "graphql-endpoints",
|
|
2189
2260
|
configureServer(server) {
|
|
2190
|
-
server.middlewares.use((
|
|
2191
|
-
server.middlewares.use(
|
|
2261
|
+
server.middlewares.use(cors());
|
|
2262
|
+
server.middlewares.use(bodyParser.json({ limit: "5mb" }));
|
|
2192
2263
|
server.middlewares.use(async (req, res, next) => {
|
|
2193
2264
|
const mediaPaths = configManager.config.media?.tina;
|
|
2194
2265
|
const mediaRouter = createMediaRouter({
|
|
@@ -2227,7 +2298,7 @@ var devServerEndPointsPlugin = ({
|
|
|
2227
2298
|
const { query, variables } = req.body;
|
|
2228
2299
|
let result;
|
|
2229
2300
|
await databaseLock(async () => {
|
|
2230
|
-
result = await (
|
|
2301
|
+
result = await gqlResolve({
|
|
2231
2302
|
config: {
|
|
2232
2303
|
useRelativeMedia: true
|
|
2233
2304
|
},
|
|
@@ -2263,13 +2334,13 @@ function viteTransformExtension({
|
|
|
2263
2334
|
include = "**/*.svg",
|
|
2264
2335
|
exclude
|
|
2265
2336
|
} = {}) {
|
|
2266
|
-
const filter =
|
|
2337
|
+
const filter = createFilter(include, exclude);
|
|
2267
2338
|
return {
|
|
2268
2339
|
name: "vite-plugin-svgr",
|
|
2269
2340
|
async transform(code, id) {
|
|
2270
2341
|
if (filter(id)) {
|
|
2271
2342
|
const { transform: transform2 } = await import("@svgr/core");
|
|
2272
|
-
const svgCode = await
|
|
2343
|
+
const svgCode = await fs6.promises.readFile(
|
|
2273
2344
|
id.replace(/\?.*$/, ""),
|
|
2274
2345
|
"utf8"
|
|
2275
2346
|
);
|
|
@@ -2279,7 +2350,7 @@ function viteTransformExtension({
|
|
|
2279
2350
|
previousExport: exportAsDefault ? null : code
|
|
2280
2351
|
}
|
|
2281
2352
|
});
|
|
2282
|
-
const res = await
|
|
2353
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
2283
2354
|
loader: "jsx",
|
|
2284
2355
|
...esbuildOptions
|
|
2285
2356
|
});
|
|
@@ -2306,7 +2377,7 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2306
2377
|
}),
|
|
2307
2378
|
viteTransformExtension()
|
|
2308
2379
|
];
|
|
2309
|
-
return (
|
|
2380
|
+
return createViteServer(
|
|
2310
2381
|
await createConfig({
|
|
2311
2382
|
configManager,
|
|
2312
2383
|
database,
|
|
@@ -2336,37 +2407,30 @@ var createDevServer = async (configManager, database, searchIndex, apiURL, noWat
|
|
|
2336
2407
|
|
|
2337
2408
|
// src/next/commands/dev-command/index.ts
|
|
2338
2409
|
var DevCommand = class extends BaseCommand {
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
this
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
description: `Builds Tina and starts the dev server`,
|
|
2364
|
-
examples: [
|
|
2365
|
-
[`A basic example`, `$0 dev`],
|
|
2366
|
-
[`A second example`, `$0 dev --rootPath`]
|
|
2367
|
-
]
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2410
|
+
static paths = [["dev"], ["server:start"]];
|
|
2411
|
+
// NOTE: camelCase commands for string options don't work if there's an `=` used https://github.com/arcanis/clipanion/issues/141
|
|
2412
|
+
watchFolders = Option2.String("-w,--watchFolders", {
|
|
2413
|
+
description: "DEPRECATED - a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
2414
|
+
});
|
|
2415
|
+
noWatch = Option2.Boolean("--noWatch", false, {
|
|
2416
|
+
description: "Don't regenerate config on file changes"
|
|
2417
|
+
});
|
|
2418
|
+
outputSearchIndexPath = Option2.String("--outputSearchIndexPath", {
|
|
2419
|
+
description: "Path to write the search index to"
|
|
2420
|
+
});
|
|
2421
|
+
noServer = Option2.Boolean("--no-server", false, {
|
|
2422
|
+
description: "Do not start the dev server"
|
|
2423
|
+
});
|
|
2424
|
+
indexingLock = new AsyncLock();
|
|
2425
|
+
// Prevent indexes and reads occurring at once
|
|
2426
|
+
static usage = Command2.Usage({
|
|
2427
|
+
category: `Commands`,
|
|
2428
|
+
description: `Builds Tina and starts the dev server`,
|
|
2429
|
+
examples: [
|
|
2430
|
+
[`A basic example`, `$0 dev`],
|
|
2431
|
+
[`A second example`, `$0 dev --rootPath`]
|
|
2432
|
+
]
|
|
2433
|
+
});
|
|
2370
2434
|
async catch(error) {
|
|
2371
2435
|
logger.error("Error occured during tinacms dev");
|
|
2372
2436
|
console.error(error);
|
|
@@ -2403,7 +2467,7 @@ var DevCommand = class extends BaseCommand {
|
|
|
2403
2467
|
} else {
|
|
2404
2468
|
database.clearCache();
|
|
2405
2469
|
}
|
|
2406
|
-
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await
|
|
2470
|
+
const { tinaSchema: tinaSchema2, graphQLSchema: graphQLSchema2, lookup, queryDoc, fragDoc } = await buildSchema(configManager.config);
|
|
2407
2471
|
const codegen2 = new Codegen({
|
|
2408
2472
|
isLocal: true,
|
|
2409
2473
|
configManager,
|
|
@@ -2417,29 +2481,32 @@ var DevCommand = class extends BaseCommand {
|
|
|
2417
2481
|
});
|
|
2418
2482
|
const apiURL2 = await codegen2.execute();
|
|
2419
2483
|
if (!configManager.isUsingLegacyFolder) {
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
const
|
|
2424
|
-
|
|
2425
|
-
|
|
2484
|
+
const schemaObject = await fs7.readJSON(
|
|
2485
|
+
configManager.generatedSchemaJSONPath
|
|
2486
|
+
);
|
|
2487
|
+
const lookupObject = await fs7.readJSON(
|
|
2488
|
+
configManager.generatedLookupJSONPath
|
|
2489
|
+
);
|
|
2490
|
+
const graphqlSchemaObject = await fs7.readJSON(
|
|
2491
|
+
configManager.generatedGraphQLJSONPath
|
|
2492
|
+
);
|
|
2426
2493
|
const tinaLockFilename = "tina-lock.json";
|
|
2427
2494
|
const tinaLockContent = JSON.stringify({
|
|
2428
2495
|
schema: schemaObject,
|
|
2429
2496
|
lookup: lookupObject,
|
|
2430
2497
|
graphql: graphqlSchemaObject
|
|
2431
2498
|
});
|
|
2432
|
-
|
|
2433
|
-
|
|
2499
|
+
fs7.writeFileSync(
|
|
2500
|
+
path8.join(configManager.tinaFolderPath, tinaLockFilename),
|
|
2434
2501
|
tinaLockContent
|
|
2435
2502
|
);
|
|
2436
2503
|
if (configManager.hasSeparateContentRoot()) {
|
|
2437
2504
|
const rootPath = await configManager.getTinaFolderPath(
|
|
2438
2505
|
configManager.contentRootPath
|
|
2439
2506
|
);
|
|
2440
|
-
const filePath =
|
|
2441
|
-
await
|
|
2442
|
-
await
|
|
2507
|
+
const filePath = path8.join(rootPath, tinaLockFilename);
|
|
2508
|
+
await fs7.ensureFile(filePath);
|
|
2509
|
+
await fs7.outputFile(filePath, tinaLockContent);
|
|
2443
2510
|
}
|
|
2444
2511
|
}
|
|
2445
2512
|
await this.indexContentWithSpinner({
|
|
@@ -2482,19 +2549,19 @@ ${dangerText(e.message)}
|
|
|
2482
2549
|
const { apiURL, graphQLSchema, tinaSchema } = await setup({
|
|
2483
2550
|
firstTime: true
|
|
2484
2551
|
});
|
|
2485
|
-
await
|
|
2486
|
-
await
|
|
2552
|
+
await fs7.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
2553
|
+
await fs7.outputFile(
|
|
2487
2554
|
configManager.outputGitignorePath,
|
|
2488
2555
|
"index.html\nassets/"
|
|
2489
2556
|
);
|
|
2490
|
-
const searchIndexClient = new
|
|
2557
|
+
const searchIndexClient = new LocalSearchIndexClient({
|
|
2491
2558
|
stopwordLanguages: configManager.config.search?.tina?.stopwordLanguages,
|
|
2492
2559
|
tokenSplitRegex: configManager.config.search?.tina?.tokenSplitRegex
|
|
2493
2560
|
});
|
|
2494
2561
|
await searchIndexClient.onStartIndexing();
|
|
2495
|
-
const searchIndexer = new
|
|
2562
|
+
const searchIndexer = new SearchIndexer({
|
|
2496
2563
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
2497
|
-
bridge: new
|
|
2564
|
+
bridge: new FilesystemBridge2(
|
|
2498
2565
|
configManager.rootPath,
|
|
2499
2566
|
configManager.contentRootPath
|
|
2500
2567
|
),
|
|
@@ -2535,7 +2602,7 @@ ${dangerText(e.message)}
|
|
|
2535
2602
|
);
|
|
2536
2603
|
await server.listen(Number(this.port));
|
|
2537
2604
|
if (!this.noWatch) {
|
|
2538
|
-
|
|
2605
|
+
chokidar.watch(configManager.watchList).on("change", async () => {
|
|
2539
2606
|
await dbLock(async () => {
|
|
2540
2607
|
logger.info(`Tina config change detected, rebuilding`);
|
|
2541
2608
|
await setup({ firstTime: false });
|
|
@@ -2612,14 +2679,14 @@ ${dangerText(e.message)}
|
|
|
2612
2679
|
watchContentFiles(configManager, database, databaseLock, searchIndexer) {
|
|
2613
2680
|
const collectionContentFiles = [];
|
|
2614
2681
|
configManager.config.schema.collections.forEach((collection) => {
|
|
2615
|
-
const collectionGlob = `${
|
|
2682
|
+
const collectionGlob = `${path8.join(
|
|
2616
2683
|
configManager.contentRootPath,
|
|
2617
2684
|
collection.path
|
|
2618
2685
|
)}/**/*.${collection.format || "md"}`;
|
|
2619
2686
|
collectionContentFiles.push(collectionGlob);
|
|
2620
2687
|
});
|
|
2621
2688
|
let ready = false;
|
|
2622
|
-
|
|
2689
|
+
chokidar.watch(collectionContentFiles).on("ready", () => {
|
|
2623
2690
|
ready = true;
|
|
2624
2691
|
}).on("add", async (addedFile) => {
|
|
2625
2692
|
if (!ready) {
|
|
@@ -2656,27 +2723,34 @@ ${dangerText(e.message)}
|
|
|
2656
2723
|
await callback();
|
|
2657
2724
|
});
|
|
2658
2725
|
};
|
|
2659
|
-
|
|
2726
|
+
chokidar.watch(configManager.userQueriesAndFragmentsGlob).on("add", executeCallback).on("change", executeCallback).on("unlink", executeCallback);
|
|
2660
2727
|
}
|
|
2661
2728
|
};
|
|
2662
2729
|
|
|
2663
2730
|
// src/next/commands/build-command/index.ts
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2731
|
+
import crypto from "crypto";
|
|
2732
|
+
import path9 from "path";
|
|
2733
|
+
import { diff } from "@graphql-inspector/core";
|
|
2734
|
+
import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
|
|
2735
|
+
import { parseURL as parseURL2 } from "@tinacms/schema-tools";
|
|
2736
|
+
import {
|
|
2737
|
+
SearchIndexer as SearchIndexer2,
|
|
2738
|
+
TinaCMSSearchIndexClient
|
|
2739
|
+
} from "@tinacms/search";
|
|
2740
|
+
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
2741
|
+
import fs8 from "fs-extra";
|
|
2742
|
+
import {
|
|
2743
|
+
buildASTSchema as buildASTSchema2,
|
|
2744
|
+
buildClientSchema,
|
|
2745
|
+
getIntrospectionQuery
|
|
2746
|
+
} from "graphql";
|
|
2747
|
+
import Progress2 from "progress";
|
|
2674
2748
|
|
|
2675
2749
|
// src/utils/index.ts
|
|
2676
|
-
|
|
2750
|
+
import { ChangeType } from "@graphql-inspector/core";
|
|
2677
2751
|
var getFaqLink = (type) => {
|
|
2678
2752
|
switch (type) {
|
|
2679
|
-
case
|
|
2753
|
+
case ChangeType.FieldRemoved: {
|
|
2680
2754
|
return "https://tina.io/docs/r/FAQ/#2-how-do-i-resolve-the-local-graphql-schema-doesnt-match-the-remote-graphql-schema-error";
|
|
2681
2755
|
}
|
|
2682
2756
|
default:
|
|
@@ -2698,7 +2772,7 @@ async function sleepAndCallFunc({
|
|
|
2698
2772
|
}
|
|
2699
2773
|
|
|
2700
2774
|
// src/next/commands/build-command/server.ts
|
|
2701
|
-
|
|
2775
|
+
import { build as build2 } from "vite";
|
|
2702
2776
|
var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
2703
2777
|
const publicEnv = {};
|
|
2704
2778
|
Object.keys(process.env).forEach((key) => {
|
|
@@ -2732,12 +2806,12 @@ var buildProductionSpa = async (configManager, database, apiURL) => {
|
|
|
2732
2806
|
}
|
|
2733
2807
|
}
|
|
2734
2808
|
});
|
|
2735
|
-
return (
|
|
2809
|
+
return build2(config2);
|
|
2736
2810
|
};
|
|
2737
2811
|
|
|
2738
2812
|
// src/next/commands/build-command/waitForDB.ts
|
|
2739
|
-
|
|
2740
|
-
|
|
2813
|
+
import { parseURL } from "@tinacms/schema-tools";
|
|
2814
|
+
import Progress from "progress";
|
|
2741
2815
|
var POLLING_INTERVAL = 5e3;
|
|
2742
2816
|
var STATUS_INPROGRESS = "inprogress";
|
|
2743
2817
|
var STATUS_COMPLETE = "complete";
|
|
@@ -2750,14 +2824,14 @@ var IndexFailedError = class extends Error {
|
|
|
2750
2824
|
};
|
|
2751
2825
|
var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
2752
2826
|
const token = config2.token;
|
|
2753
|
-
const { clientId, branch, isLocalClient, host } =
|
|
2827
|
+
const { clientId, branch, isLocalClient, host } = parseURL(apiUrl);
|
|
2754
2828
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
2755
2829
|
if (verbose) {
|
|
2756
2830
|
logger.info(logText("Not using TinaCloud, skipping DB check"));
|
|
2757
2831
|
}
|
|
2758
2832
|
return;
|
|
2759
2833
|
}
|
|
2760
|
-
const bar2 = new
|
|
2834
|
+
const bar2 = new Progress(
|
|
2761
2835
|
"Checking indexing process in TinaCloud... :prog",
|
|
2762
2836
|
1
|
|
2763
2837
|
);
|
|
@@ -2820,51 +2894,44 @@ var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
|
2820
2894
|
|
|
2821
2895
|
// src/next/commands/build-command/index.ts
|
|
2822
2896
|
var BuildCommand = class extends BaseCommand {
|
|
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
|
-
|
|
2860
|
-
|
|
2861
|
-
}
|
|
2862
|
-
static {
|
|
2863
|
-
this.usage = import_clipanion3.Command.Usage({
|
|
2864
|
-
category: `Commands`,
|
|
2865
|
-
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2866
|
-
});
|
|
2867
|
-
}
|
|
2897
|
+
static paths = [["build"]];
|
|
2898
|
+
localOption = Option3.Boolean("--local", {
|
|
2899
|
+
description: "Starts local Graphql server and builds the local client instead of production client"
|
|
2900
|
+
});
|
|
2901
|
+
skipIndexing = Option3.Boolean("--skip-indexing", false, {
|
|
2902
|
+
description: "Skips indexing the content. This can be used for building the site without indexing the content (defaults to false)"
|
|
2903
|
+
});
|
|
2904
|
+
partialReindex = Option3.Boolean("--partial-reindex", false, {
|
|
2905
|
+
description: "Re-indexes only the content that has changed since the last build (defaults to false). Not currently supported for separate content repos."
|
|
2906
|
+
});
|
|
2907
|
+
tinaGraphQLVersion = Option3.String("--tina-graphql-version", {
|
|
2908
|
+
description: "Specify the version of @tinacms/graphql to use (defaults to latest)"
|
|
2909
|
+
});
|
|
2910
|
+
/**
|
|
2911
|
+
* 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
|
|
2912
|
+
*/
|
|
2913
|
+
skipCloudChecks = Option3.Boolean("--skip-cloud-checks", false, {
|
|
2914
|
+
description: "Skips checking the provided cloud config."
|
|
2915
|
+
});
|
|
2916
|
+
skipSearchIndex = Option3.Boolean("--skip-search-index", false, {
|
|
2917
|
+
description: "Skip indexing the site for search"
|
|
2918
|
+
});
|
|
2919
|
+
upstreamBranch = Option3.String("--upstream-branch", {
|
|
2920
|
+
description: "Optional upstream branch with the schema. If not specified, default will be used."
|
|
2921
|
+
});
|
|
2922
|
+
previewBaseBranch = Option3.String("--preview-base-branch", {
|
|
2923
|
+
description: "The base branch for the preview"
|
|
2924
|
+
});
|
|
2925
|
+
previewName = Option3.String("--preview-name", {
|
|
2926
|
+
description: "The name of the preview branch"
|
|
2927
|
+
});
|
|
2928
|
+
noClientBuildCache = Option3.Boolean("--no-client-build-cache", false, {
|
|
2929
|
+
description: "Disables the client build cache"
|
|
2930
|
+
});
|
|
2931
|
+
static usage = Command3.Usage({
|
|
2932
|
+
category: `Commands`,
|
|
2933
|
+
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
2934
|
+
});
|
|
2868
2935
|
async catch(error) {
|
|
2869
2936
|
console.error(error);
|
|
2870
2937
|
process.exit(1);
|
|
@@ -2909,7 +2976,7 @@ ${dangerText(e.message)}`);
|
|
|
2909
2976
|
configManager,
|
|
2910
2977
|
Number(this.datalayerPort)
|
|
2911
2978
|
);
|
|
2912
|
-
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await (
|
|
2979
|
+
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await buildSchema2(configManager.config);
|
|
2913
2980
|
const codegen2 = new Codegen({
|
|
2914
2981
|
configManager,
|
|
2915
2982
|
port: this.localOption ? Number(this.port) : void 0,
|
|
@@ -3017,7 +3084,7 @@ ${dangerText(e.message)}
|
|
|
3017
3084
|
}
|
|
3018
3085
|
}
|
|
3019
3086
|
await buildProductionSpa(configManager, database, codegen2.productionUrl);
|
|
3020
|
-
await
|
|
3087
|
+
await fs8.outputFile(
|
|
3021
3088
|
configManager.outputGitignorePath,
|
|
3022
3089
|
"index.html\nassets/"
|
|
3023
3090
|
);
|
|
@@ -3049,7 +3116,7 @@ ${dangerText(e.message)}
|
|
|
3049
3116
|
"indexerToken not configured in tina search configuration."
|
|
3050
3117
|
);
|
|
3051
3118
|
}
|
|
3052
|
-
client = new
|
|
3119
|
+
client = new TinaCMSSearchIndexClient({
|
|
3053
3120
|
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
3054
3121
|
branch: configManager.config?.branch,
|
|
3055
3122
|
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
@@ -3058,9 +3125,9 @@ ${dangerText(e.message)}
|
|
|
3058
3125
|
} else {
|
|
3059
3126
|
client = configManager.config?.search?.searchClient;
|
|
3060
3127
|
}
|
|
3061
|
-
const searchIndexer = new
|
|
3128
|
+
const searchIndexer = new SearchIndexer2({
|
|
3062
3129
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
3063
|
-
bridge: new
|
|
3130
|
+
bridge: new FilesystemBridge3(
|
|
3064
3131
|
configManager.rootPath,
|
|
3065
3132
|
configManager.contentRootPath
|
|
3066
3133
|
),
|
|
@@ -3130,8 +3197,8 @@ ${dangerText(e.message)}
|
|
|
3130
3197
|
const MAX_RETRIES = 5;
|
|
3131
3198
|
const { config: config2 } = configManager;
|
|
3132
3199
|
const token = config2.token;
|
|
3133
|
-
const { clientId, branch, host } = (
|
|
3134
|
-
const bar2 = new
|
|
3200
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3201
|
+
const bar2 = new Progress2("Checking clientId and token. :prog", 1);
|
|
3135
3202
|
const getBranchInfo = async () => {
|
|
3136
3203
|
const url = `https://${host}/db/${clientId}/status/${previewBaseBranch || branch}`;
|
|
3137
3204
|
const branchInfo2 = {
|
|
@@ -3185,7 +3252,7 @@ ${dangerText(e.message)}
|
|
|
3185
3252
|
bar2.tick({
|
|
3186
3253
|
prog: "\u2705"
|
|
3187
3254
|
});
|
|
3188
|
-
const branchBar = new
|
|
3255
|
+
const branchBar = new Progress2(
|
|
3189
3256
|
`Checking branch '${config2.branch}' is on TinaCloud. :prog`,
|
|
3190
3257
|
1
|
|
3191
3258
|
);
|
|
@@ -3225,7 +3292,7 @@ ${dangerText(e.message)}
|
|
|
3225
3292
|
async syncProject(configManager, apiURL, options) {
|
|
3226
3293
|
const { config: config2 } = configManager;
|
|
3227
3294
|
const token = config2.token;
|
|
3228
|
-
const { clientId, branch, host } = (
|
|
3295
|
+
const { clientId, branch, host } = parseURL2(apiURL);
|
|
3229
3296
|
const { previewName, previewBaseBranch, upstreamBranch } = options || {};
|
|
3230
3297
|
let url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true`;
|
|
3231
3298
|
if (upstreamBranch && previewBaseBranch && previewName) {
|
|
@@ -3235,7 +3302,7 @@ ${dangerText(e.message)}
|
|
|
3235
3302
|
} else if (upstreamBranch && !previewBaseBranch && !previewName) {
|
|
3236
3303
|
url = `https://${host}/db/${clientId}/reset/${branch}?refreshSchema=true&skipIfSchemaCurrent=true&upstreamBranch=${upstreamBranch}`;
|
|
3237
3304
|
}
|
|
3238
|
-
const bar2 = new
|
|
3305
|
+
const bar2 = new Progress2("Syncing Project. :prog", 1);
|
|
3239
3306
|
try {
|
|
3240
3307
|
const res = await request({
|
|
3241
3308
|
token,
|
|
@@ -3276,7 +3343,7 @@ ${dangerText(e.message)}
|
|
|
3276
3343
|
}
|
|
3277
3344
|
}
|
|
3278
3345
|
async checkGraphqlSchema(configManager, database, apiURL, timestamp) {
|
|
3279
|
-
const bar2 = new
|
|
3346
|
+
const bar2 = new Progress2(
|
|
3280
3347
|
"Checking local GraphQL Schema matches server. :prog",
|
|
3281
3348
|
1
|
|
3282
3349
|
);
|
|
@@ -3298,11 +3365,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3298
3365
|
}
|
|
3299
3366
|
throw new Error(errorMessage);
|
|
3300
3367
|
}
|
|
3301
|
-
const remoteGqlSchema =
|
|
3368
|
+
const remoteGqlSchema = buildClientSchema(remoteSchema);
|
|
3302
3369
|
const localSchemaDocument = await database.getGraphQLSchemaFromBridge();
|
|
3303
|
-
const localGraphqlSchema = (
|
|
3370
|
+
const localGraphqlSchema = buildASTSchema2(localSchemaDocument);
|
|
3304
3371
|
try {
|
|
3305
|
-
const diffResult = await
|
|
3372
|
+
const diffResult = await diff(remoteGqlSchema, localGraphqlSchema);
|
|
3306
3373
|
if (diffResult.length === 0) {
|
|
3307
3374
|
bar2.tick({
|
|
3308
3375
|
prog: "\u2705"
|
|
@@ -3350,13 +3417,13 @@ Additional info:
|
|
|
3350
3417
|
}
|
|
3351
3418
|
}
|
|
3352
3419
|
async checkTinaSchema(configManager, database, apiURL, previewName, verbose, timestamp) {
|
|
3353
|
-
const bar2 = new
|
|
3420
|
+
const bar2 = new Progress2(
|
|
3354
3421
|
"Checking local Tina Schema matches server. :prog",
|
|
3355
3422
|
1
|
|
3356
3423
|
);
|
|
3357
3424
|
const { config: config2 } = configManager;
|
|
3358
3425
|
const token = config2.token;
|
|
3359
|
-
const { clientId, branch, isLocalClient, host } = (
|
|
3426
|
+
const { clientId, branch, isLocalClient, host } = parseURL2(apiURL);
|
|
3360
3427
|
if (isLocalClient || !host || !clientId || !branch) {
|
|
3361
3428
|
if (verbose) {
|
|
3362
3429
|
logger.info(logText("Not using TinaCloud, skipping Tina Schema check"));
|
|
@@ -3384,11 +3451,11 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3384
3451
|
}
|
|
3385
3452
|
const localTinaSchema = JSON.parse(
|
|
3386
3453
|
await database.bridge.get(
|
|
3387
|
-
|
|
3454
|
+
path9.join(database.tinaDirectory, "__generated__", "_schema.json")
|
|
3388
3455
|
)
|
|
3389
3456
|
);
|
|
3390
3457
|
localTinaSchema.version = void 0;
|
|
3391
|
-
const localTinaSchemaSha =
|
|
3458
|
+
const localTinaSchemaSha = crypto.createHash("sha256").update(JSON.stringify(localTinaSchema)).digest("hex");
|
|
3392
3459
|
if (localTinaSchemaSha === remoteTinaSchemaSha) {
|
|
3393
3460
|
bar2.tick({
|
|
3394
3461
|
prog: "\u2705"
|
|
@@ -3466,7 +3533,7 @@ var fetchRemoteGraphqlSchema = async ({
|
|
|
3466
3533
|
headers.append("X-API-KEY", token);
|
|
3467
3534
|
}
|
|
3468
3535
|
const body = JSON.stringify({
|
|
3469
|
-
query:
|
|
3536
|
+
query: getIntrospectionQuery(),
|
|
3470
3537
|
variables: {}
|
|
3471
3538
|
});
|
|
3472
3539
|
headers.append("Content-Type", "application/json");
|
|
@@ -3499,14 +3566,14 @@ var fetchSchemaSha = async ({
|
|
|
3499
3566
|
};
|
|
3500
3567
|
|
|
3501
3568
|
// src/next/commands/audit-command/index.ts
|
|
3502
|
-
|
|
3503
|
-
|
|
3569
|
+
import { Command as Command4, Option as Option4 } from "clipanion";
|
|
3570
|
+
import { buildSchema as buildSchema3 } from "@tinacms/graphql";
|
|
3504
3571
|
|
|
3505
3572
|
// src/next/commands/audit-command/audit.ts
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3573
|
+
import prompts from "prompts";
|
|
3574
|
+
import { Telemetry } from "@tinacms/metrics";
|
|
3575
|
+
import { resolve } from "@tinacms/graphql";
|
|
3576
|
+
import chalk5 from "chalk";
|
|
3510
3577
|
var audit = async ({
|
|
3511
3578
|
database,
|
|
3512
3579
|
clean,
|
|
@@ -3514,7 +3581,7 @@ var audit = async ({
|
|
|
3514
3581
|
noTelemetry,
|
|
3515
3582
|
verbose
|
|
3516
3583
|
}) => {
|
|
3517
|
-
const telemetry = new
|
|
3584
|
+
const telemetry = new Telemetry({ disabled: noTelemetry });
|
|
3518
3585
|
await telemetry.submitRecord({
|
|
3519
3586
|
event: {
|
|
3520
3587
|
name: "tinacms:cli:audit:invoke",
|
|
@@ -3524,25 +3591,25 @@ var audit = async ({
|
|
|
3524
3591
|
});
|
|
3525
3592
|
if (clean) {
|
|
3526
3593
|
logger.info(
|
|
3527
|
-
`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 ${
|
|
3594
|
+
`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(
|
|
3528
3595
|
"clean git tree"
|
|
3529
3596
|
)} so unwanted changes can be undone.
|
|
3530
3597
|
|
|
3531
3598
|
`
|
|
3532
3599
|
);
|
|
3533
|
-
const res = await (
|
|
3600
|
+
const res = await prompts({
|
|
3534
3601
|
name: "useClean",
|
|
3535
3602
|
type: "confirm",
|
|
3536
3603
|
message: `Do you want to continue?`
|
|
3537
3604
|
});
|
|
3538
3605
|
if (!res.useClean) {
|
|
3539
|
-
logger.warn(
|
|
3606
|
+
logger.warn(chalk5.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
3540
3607
|
process.exit(0);
|
|
3541
3608
|
}
|
|
3542
3609
|
}
|
|
3543
3610
|
if (useDefaultValues && !clean) {
|
|
3544
3611
|
logger.warn(
|
|
3545
|
-
|
|
3612
|
+
chalk5.yellowBright(
|
|
3546
3613
|
"WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"
|
|
3547
3614
|
)
|
|
3548
3615
|
);
|
|
@@ -3570,10 +3637,10 @@ var audit = async ({
|
|
|
3570
3637
|
}
|
|
3571
3638
|
if (error) {
|
|
3572
3639
|
logger.error(
|
|
3573
|
-
|
|
3640
|
+
chalk5.redBright(`\u203C\uFE0F Audit ${chalk5.bold("failed")} with errors`)
|
|
3574
3641
|
);
|
|
3575
3642
|
} else {
|
|
3576
|
-
logger.info(
|
|
3643
|
+
logger.info(chalk5.greenBright("\u2705 Audit passed"));
|
|
3577
3644
|
}
|
|
3578
3645
|
};
|
|
3579
3646
|
var auditDocuments = async (args) => {
|
|
@@ -3590,7 +3657,7 @@ var auditDocuments = async (args) => {
|
|
|
3590
3657
|
}
|
|
3591
3658
|
}
|
|
3592
3659
|
}`;
|
|
3593
|
-
const docResult = await
|
|
3660
|
+
const docResult = await resolve({
|
|
3594
3661
|
database,
|
|
3595
3662
|
query: documentQuery,
|
|
3596
3663
|
variables: {},
|
|
@@ -3601,11 +3668,11 @@ var auditDocuments = async (args) => {
|
|
|
3601
3668
|
if (docResult.errors) {
|
|
3602
3669
|
error = true;
|
|
3603
3670
|
docResult.errors.forEach((err) => {
|
|
3604
|
-
logger.error(
|
|
3671
|
+
logger.error(chalk5.red(err.message));
|
|
3605
3672
|
if (err.originalError.originalError) {
|
|
3606
3673
|
logger.error(
|
|
3607
3674
|
// @ts-ignore FIXME: this doesn't seem right
|
|
3608
|
-
|
|
3675
|
+
chalk5.red(` ${err.originalError.originalError.message}`)
|
|
3609
3676
|
);
|
|
3610
3677
|
}
|
|
3611
3678
|
});
|
|
@@ -3632,7 +3699,7 @@ var auditDocuments = async (args) => {
|
|
|
3632
3699
|
params: $params
|
|
3633
3700
|
){__typename}
|
|
3634
3701
|
}`;
|
|
3635
|
-
const mutationRes = await
|
|
3702
|
+
const mutationRes = await resolve({
|
|
3636
3703
|
database,
|
|
3637
3704
|
query: mutation,
|
|
3638
3705
|
variables: {
|
|
@@ -3647,7 +3714,7 @@ var auditDocuments = async (args) => {
|
|
|
3647
3714
|
if (mutationRes.errors) {
|
|
3648
3715
|
mutationRes.errors.forEach((err) => {
|
|
3649
3716
|
error = true;
|
|
3650
|
-
logger.error(
|
|
3717
|
+
logger.error(chalk5.red(err.message));
|
|
3651
3718
|
});
|
|
3652
3719
|
}
|
|
3653
3720
|
}
|
|
@@ -3664,38 +3731,31 @@ function filterObject(obj) {
|
|
|
3664
3731
|
}
|
|
3665
3732
|
|
|
3666
3733
|
// src/next/commands/audit-command/index.ts
|
|
3667
|
-
|
|
3668
|
-
var AuditCommand = class extends
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
}
|
|
3693
|
-
static {
|
|
3694
|
-
this.usage = import_clipanion4.Command.Usage({
|
|
3695
|
-
category: `Commands`,
|
|
3696
|
-
description: `Audit config and content files`
|
|
3697
|
-
});
|
|
3698
|
-
}
|
|
3734
|
+
import { AuditFileSystemBridge } from "@tinacms/graphql";
|
|
3735
|
+
var AuditCommand = class extends Command4 {
|
|
3736
|
+
static paths = [["audit"]];
|
|
3737
|
+
rootPath = Option4.String("--rootPath", {
|
|
3738
|
+
description: "Specify the root directory to run the CLI from"
|
|
3739
|
+
});
|
|
3740
|
+
verbose = Option4.Boolean("-v,--verbose", false, {
|
|
3741
|
+
description: "increase verbosity of logged output"
|
|
3742
|
+
});
|
|
3743
|
+
clean = Option4.Boolean("--clean", false, {
|
|
3744
|
+
description: "Clean the output"
|
|
3745
|
+
});
|
|
3746
|
+
useDefaultValues = Option4.Boolean("--useDefaultValues", false, {
|
|
3747
|
+
description: "When cleaning the output, use defaults on the config"
|
|
3748
|
+
});
|
|
3749
|
+
noTelemetry = Option4.Boolean("--noTelemetry", false, {
|
|
3750
|
+
description: "Disable anonymous telemetry that is collected"
|
|
3751
|
+
});
|
|
3752
|
+
datalayerPort = Option4.String("--datalayer-port", "9000", {
|
|
3753
|
+
description: "Specify a port to run the datalayer server on. (default 9000)"
|
|
3754
|
+
});
|
|
3755
|
+
static usage = Command4.Usage({
|
|
3756
|
+
category: `Commands`,
|
|
3757
|
+
description: `Audit config and content files`
|
|
3758
|
+
});
|
|
3699
3759
|
async catch(error) {
|
|
3700
3760
|
logger.error("Error occured during tinacms audit");
|
|
3701
3761
|
if (this.verbose) {
|
|
@@ -3716,9 +3776,9 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3716
3776
|
const database = await createAndInitializeDatabase(
|
|
3717
3777
|
configManager,
|
|
3718
3778
|
Number(this.datalayerPort),
|
|
3719
|
-
this.clean ? void 0 : new
|
|
3779
|
+
this.clean ? void 0 : new AuditFileSystemBridge(configManager.rootPath)
|
|
3720
3780
|
);
|
|
3721
|
-
const { tinaSchema, graphQLSchema, lookup } = await (
|
|
3781
|
+
const { tinaSchema, graphQLSchema, lookup } = await buildSchema3(
|
|
3722
3782
|
configManager.config
|
|
3723
3783
|
);
|
|
3724
3784
|
const warnings = [];
|
|
@@ -3751,29 +3811,29 @@ var AuditCommand = class extends import_clipanion4.Command {
|
|
|
3751
3811
|
};
|
|
3752
3812
|
|
|
3753
3813
|
// src/next/commands/init-command/index.ts
|
|
3754
|
-
|
|
3814
|
+
import { Command as Command6, Option as Option6 } from "clipanion";
|
|
3755
3815
|
|
|
3756
3816
|
// src/cmds/init/detectEnvironment.ts
|
|
3757
|
-
|
|
3758
|
-
|
|
3817
|
+
import fs9 from "fs-extra";
|
|
3818
|
+
import path10 from "path";
|
|
3759
3819
|
var checkGitignoreForItem = async ({
|
|
3760
3820
|
baseDir,
|
|
3761
3821
|
line
|
|
3762
3822
|
}) => {
|
|
3763
|
-
const gitignoreContent =
|
|
3823
|
+
const gitignoreContent = fs9.readFileSync(path10.join(baseDir, ".gitignore")).toString();
|
|
3764
3824
|
return gitignoreContent.split("\n").some((item) => item === line);
|
|
3765
3825
|
};
|
|
3766
3826
|
var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
3767
3827
|
const result = {
|
|
3768
|
-
fullPathTS:
|
|
3828
|
+
fullPathTS: path10.join(
|
|
3769
3829
|
parentPath,
|
|
3770
3830
|
`${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
|
|
3771
3831
|
),
|
|
3772
|
-
fullPathJS:
|
|
3832
|
+
fullPathJS: path10.join(
|
|
3773
3833
|
parentPath,
|
|
3774
3834
|
`${name2}.${opts?.extensionOverride || "js"}`
|
|
3775
3835
|
),
|
|
3776
|
-
fullPathOverride: opts?.extensionOverride ?
|
|
3836
|
+
fullPathOverride: opts?.extensionOverride ? path10.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
|
|
3777
3837
|
generatedFileType,
|
|
3778
3838
|
name: name2,
|
|
3779
3839
|
parentPath,
|
|
@@ -3791,8 +3851,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
|
3791
3851
|
};
|
|
3792
3852
|
}
|
|
3793
3853
|
};
|
|
3794
|
-
result.typescriptExists = await
|
|
3795
|
-
result.javascriptExists = await
|
|
3854
|
+
result.typescriptExists = await fs9.pathExists(result.fullPathTS);
|
|
3855
|
+
result.javascriptExists = await fs9.pathExists(result.fullPathJS);
|
|
3796
3856
|
return result;
|
|
3797
3857
|
};
|
|
3798
3858
|
var detectEnvironment = async ({
|
|
@@ -3801,21 +3861,21 @@ var detectEnvironment = async ({
|
|
|
3801
3861
|
rootPath,
|
|
3802
3862
|
debug = false
|
|
3803
3863
|
}) => {
|
|
3804
|
-
const hasForestryConfig = await
|
|
3805
|
-
|
|
3864
|
+
const hasForestryConfig = await fs9.pathExists(
|
|
3865
|
+
path10.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
3806
3866
|
);
|
|
3807
|
-
const sampleContentPath =
|
|
3867
|
+
const sampleContentPath = path10.join(
|
|
3808
3868
|
baseDir,
|
|
3809
3869
|
"content",
|
|
3810
3870
|
"posts",
|
|
3811
3871
|
"hello-world.md"
|
|
3812
3872
|
);
|
|
3813
|
-
const usingSrc =
|
|
3814
|
-
const tinaFolder =
|
|
3873
|
+
const usingSrc = fs9.pathExistsSync(path10.join(baseDir, "src")) && (fs9.pathExistsSync(path10.join(baseDir, "src", "app")) || fs9.pathExistsSync(path10.join(baseDir, "src", "pages")));
|
|
3874
|
+
const tinaFolder = path10.join(baseDir, "tina");
|
|
3815
3875
|
const tinaConfigExists = Boolean(
|
|
3816
3876
|
// Does the tina folder exist?
|
|
3817
|
-
await
|
|
3818
|
-
(await
|
|
3877
|
+
await fs9.pathExists(tinaFolder) && // Does the tina folder contain a config file?
|
|
3878
|
+
(await fs9.readdir(tinaFolder)).find((x) => x.includes("config"))
|
|
3819
3879
|
);
|
|
3820
3880
|
const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
|
|
3821
3881
|
Boolean
|
|
@@ -3827,12 +3887,12 @@ var detectEnvironment = async ({
|
|
|
3827
3887
|
"next-api-handler": await makeGeneratedFile(
|
|
3828
3888
|
"[...routes]",
|
|
3829
3889
|
"next-api-handler",
|
|
3830
|
-
|
|
3890
|
+
path10.join(...pagesDir, "api", "tina")
|
|
3831
3891
|
),
|
|
3832
3892
|
"reactive-example": await makeGeneratedFile(
|
|
3833
3893
|
"[filename]",
|
|
3834
3894
|
"reactive-example",
|
|
3835
|
-
|
|
3895
|
+
path10.join(...pagesDir, "demo", "blog"),
|
|
3836
3896
|
{
|
|
3837
3897
|
typescriptSuffix: "tsx"
|
|
3838
3898
|
}
|
|
@@ -3840,22 +3900,22 @@ var detectEnvironment = async ({
|
|
|
3840
3900
|
"users-json": await makeGeneratedFile(
|
|
3841
3901
|
"index",
|
|
3842
3902
|
"users-json",
|
|
3843
|
-
|
|
3903
|
+
path10.join(baseDir, "content", "users"),
|
|
3844
3904
|
{ extensionOverride: "json" }
|
|
3845
3905
|
),
|
|
3846
3906
|
"sample-content": await makeGeneratedFile(
|
|
3847
3907
|
"hello-world",
|
|
3848
3908
|
"sample-content",
|
|
3849
|
-
|
|
3909
|
+
path10.join(baseDir, "content", "posts"),
|
|
3850
3910
|
{ extensionOverride: "md" }
|
|
3851
3911
|
)
|
|
3852
3912
|
};
|
|
3853
|
-
const hasSampleContent = await
|
|
3854
|
-
const hasPackageJSON = await
|
|
3913
|
+
const hasSampleContent = await fs9.pathExists(sampleContentPath);
|
|
3914
|
+
const hasPackageJSON = await fs9.pathExists("package.json");
|
|
3855
3915
|
let hasTinaDeps = false;
|
|
3856
3916
|
if (hasPackageJSON) {
|
|
3857
3917
|
try {
|
|
3858
|
-
const packageJSON = await
|
|
3918
|
+
const packageJSON = await fs9.readJSON("package.json");
|
|
3859
3919
|
const deps = [];
|
|
3860
3920
|
if (packageJSON?.dependencies) {
|
|
3861
3921
|
deps.push(...Object.keys(packageJSON.dependencies));
|
|
@@ -3872,15 +3932,15 @@ var detectEnvironment = async ({
|
|
|
3872
3932
|
);
|
|
3873
3933
|
}
|
|
3874
3934
|
}
|
|
3875
|
-
const hasGitIgnore = await
|
|
3935
|
+
const hasGitIgnore = await fs9.pathExists(path10.join(".gitignore"));
|
|
3876
3936
|
const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
|
|
3877
3937
|
const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
|
|
3878
3938
|
const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
|
|
3879
3939
|
let frontMatterFormat;
|
|
3880
3940
|
if (hasForestryConfig) {
|
|
3881
|
-
const hugoConfigPath =
|
|
3882
|
-
if (await
|
|
3883
|
-
const hugoConfig = await
|
|
3941
|
+
const hugoConfigPath = path10.join(rootPath, "config.toml");
|
|
3942
|
+
if (await fs9.pathExists(hugoConfigPath)) {
|
|
3943
|
+
const hugoConfig = await fs9.readFile(hugoConfigPath, "utf8");
|
|
3884
3944
|
const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
|
|
3885
3945
|
if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
|
|
3886
3946
|
frontMatterFormat = metaDataFormat;
|
|
@@ -3911,10 +3971,10 @@ var detectEnvironment = async ({
|
|
|
3911
3971
|
var detectEnvironment_default = detectEnvironment;
|
|
3912
3972
|
|
|
3913
3973
|
// src/cmds/init/prompts/index.ts
|
|
3914
|
-
|
|
3974
|
+
import prompts6 from "prompts";
|
|
3915
3975
|
|
|
3916
3976
|
// src/cmds/init/prompts/askTinaCloudSetup.ts
|
|
3917
|
-
|
|
3977
|
+
import prompts2 from "prompts";
|
|
3918
3978
|
var tinaCloudSetupQuestions = [
|
|
3919
3979
|
{
|
|
3920
3980
|
name: "clientId",
|
|
@@ -3936,7 +3996,7 @@ ${logText(
|
|
|
3936
3996
|
}
|
|
3937
3997
|
];
|
|
3938
3998
|
var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
3939
|
-
const { clientId, token } = await (
|
|
3999
|
+
const { clientId, token } = await prompts2(tinaCloudSetupQuestions);
|
|
3940
4000
|
config2.envVars.push(
|
|
3941
4001
|
{
|
|
3942
4002
|
key: "NEXT_PUBLIC_TINA_CLIENT_ID",
|
|
@@ -3950,7 +4010,7 @@ var askTinaCloudSetup = async ({ config: config2 }) => {
|
|
|
3950
4010
|
};
|
|
3951
4011
|
|
|
3952
4012
|
// src/cmds/init/prompts/gitProvider.ts
|
|
3953
|
-
|
|
4013
|
+
import prompts3 from "prompts";
|
|
3954
4014
|
var supportedGitProviders = {
|
|
3955
4015
|
github: {
|
|
3956
4016
|
imports: [
|
|
@@ -3972,7 +4032,7 @@ var supportedGitProviders = {
|
|
|
3972
4032
|
}
|
|
3973
4033
|
};
|
|
3974
4034
|
var chooseGitProvider = async ({ config: config2 }) => {
|
|
3975
|
-
const result = await (
|
|
4035
|
+
const result = await prompts3([
|
|
3976
4036
|
{
|
|
3977
4037
|
name: "githubToken",
|
|
3978
4038
|
type: "text",
|
|
@@ -4017,7 +4077,7 @@ ${logText(
|
|
|
4017
4077
|
};
|
|
4018
4078
|
|
|
4019
4079
|
// src/cmds/init/prompts/databaseAdapter.ts
|
|
4020
|
-
|
|
4080
|
+
import prompts4 from "prompts";
|
|
4021
4081
|
var supportedDatabaseAdapters = {
|
|
4022
4082
|
["upstash-redis"]: {
|
|
4023
4083
|
databaseAdapterClassText: `new RedisLevel({
|
|
@@ -4063,7 +4123,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4063
4123
|
other: async (_args) => {
|
|
4064
4124
|
},
|
|
4065
4125
|
mongodb: async ({ config: config2 }) => {
|
|
4066
|
-
const result = await (
|
|
4126
|
+
const result = await prompts4([
|
|
4067
4127
|
{
|
|
4068
4128
|
name: "mongoDBUri",
|
|
4069
4129
|
type: "text",
|
|
@@ -4078,7 +4138,7 @@ var databaseAdapterUpdateConfig = {
|
|
|
4078
4138
|
});
|
|
4079
4139
|
},
|
|
4080
4140
|
"upstash-redis": async ({ config: config2 }) => {
|
|
4081
|
-
const result = await (
|
|
4141
|
+
const result = await prompts4([
|
|
4082
4142
|
{
|
|
4083
4143
|
name: "kvRestApiUrl",
|
|
4084
4144
|
type: "text",
|
|
@@ -4109,7 +4169,7 @@ var chooseDatabaseAdapter = async ({
|
|
|
4109
4169
|
framework,
|
|
4110
4170
|
config: config2
|
|
4111
4171
|
}) => {
|
|
4112
|
-
const answers = await (
|
|
4172
|
+
const answers = await prompts4([
|
|
4113
4173
|
{
|
|
4114
4174
|
name: "dataLayerAdapter",
|
|
4115
4175
|
message: "Select a self-hosted Database Adapter",
|
|
@@ -4139,8 +4199,8 @@ var chooseDatabaseAdapter = async ({
|
|
|
4139
4199
|
};
|
|
4140
4200
|
|
|
4141
4201
|
// src/cmds/init/prompts/authProvider.ts
|
|
4142
|
-
|
|
4143
|
-
|
|
4202
|
+
import crypto2 from "crypto-js";
|
|
4203
|
+
import prompts5 from "prompts";
|
|
4144
4204
|
var supportedAuthProviders = {
|
|
4145
4205
|
other: {
|
|
4146
4206
|
name: "other"
|
|
@@ -4189,12 +4249,12 @@ var authProviderUpdateConfig = {
|
|
|
4189
4249
|
},
|
|
4190
4250
|
"tina-cloud": askTinaCloudSetup,
|
|
4191
4251
|
"next-auth": async ({ config: config2 }) => {
|
|
4192
|
-
const result = await (
|
|
4252
|
+
const result = await prompts5([
|
|
4193
4253
|
{
|
|
4194
4254
|
name: "nextAuthSecret",
|
|
4195
4255
|
type: "text",
|
|
4196
4256
|
message: `What is the NextAuth.js Secret? (Hit enter to use a randomly generated secret)`,
|
|
4197
|
-
initial: process.env.NEXTAUTH_SECRET ||
|
|
4257
|
+
initial: process.env.NEXTAUTH_SECRET || crypto2.lib.WordArray.random(16).toString()
|
|
4198
4258
|
}
|
|
4199
4259
|
]);
|
|
4200
4260
|
config2.envVars.push({
|
|
@@ -4219,7 +4279,7 @@ var forestryDisclaimer = logText(
|
|
|
4219
4279
|
`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)`
|
|
4220
4280
|
);
|
|
4221
4281
|
var askCommonSetUp = async () => {
|
|
4222
|
-
const answers = await (
|
|
4282
|
+
const answers = await prompts6([
|
|
4223
4283
|
{
|
|
4224
4284
|
name: "framework",
|
|
4225
4285
|
type: "select",
|
|
@@ -4283,7 +4343,7 @@ ${forestryDisclaimer}`
|
|
|
4283
4343
|
message: `What format are you using in your frontmatter?`
|
|
4284
4344
|
});
|
|
4285
4345
|
}
|
|
4286
|
-
const answers = await (
|
|
4346
|
+
const answers = await prompts6(questions);
|
|
4287
4347
|
return answers;
|
|
4288
4348
|
};
|
|
4289
4349
|
var askTinaSetupPrompts = async (params) => {
|
|
@@ -4308,11 +4368,11 @@ var askTinaSetupPrompts = async (params) => {
|
|
|
4308
4368
|
)
|
|
4309
4369
|
});
|
|
4310
4370
|
}
|
|
4311
|
-
const answers = await (
|
|
4371
|
+
const answers = await prompts6(questions);
|
|
4312
4372
|
return answers;
|
|
4313
4373
|
};
|
|
4314
4374
|
var askIfUsingSelfHosted = async () => {
|
|
4315
|
-
const answers = await (
|
|
4375
|
+
const answers = await prompts6([
|
|
4316
4376
|
{
|
|
4317
4377
|
name: "hosting",
|
|
4318
4378
|
type: "select",
|
|
@@ -4345,20 +4405,20 @@ var makeImportString = (imports) => {
|
|
|
4345
4405
|
};
|
|
4346
4406
|
|
|
4347
4407
|
// src/cmds/init/prompts/generatedFiles.ts
|
|
4348
|
-
|
|
4408
|
+
import prompts7 from "prompts";
|
|
4349
4409
|
var askIfOverride = async ({
|
|
4350
4410
|
generatedFile,
|
|
4351
4411
|
usingTypescript
|
|
4352
4412
|
}) => {
|
|
4353
4413
|
if (usingTypescript) {
|
|
4354
|
-
const result = await (
|
|
4414
|
+
const result = await prompts7({
|
|
4355
4415
|
name: `override`,
|
|
4356
4416
|
type: "confirm",
|
|
4357
4417
|
message: `Found existing file at ${generatedFile.fullPathTS}. Would you like to overwrite?`
|
|
4358
4418
|
});
|
|
4359
4419
|
return Boolean(result.override);
|
|
4360
4420
|
} else {
|
|
4361
|
-
const result = await (
|
|
4421
|
+
const result = await prompts7({
|
|
4362
4422
|
name: `override`,
|
|
4363
4423
|
type: "confirm",
|
|
4364
4424
|
message: `Found existing file at ${generatedFile.fullPathJS}. Would you like to overwrite?`
|
|
@@ -4493,24 +4553,25 @@ var CLICommand = class {
|
|
|
4493
4553
|
};
|
|
4494
4554
|
|
|
4495
4555
|
// src/cmds/init/apply.ts
|
|
4496
|
-
|
|
4556
|
+
import path14 from "path";
|
|
4497
4557
|
|
|
4498
4558
|
// src/cmds/forestry-migrate/index.ts
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4559
|
+
import fs11 from "fs-extra";
|
|
4560
|
+
import path12 from "path";
|
|
4561
|
+
import yaml2 from "js-yaml";
|
|
4562
|
+
import pkg from "minimatch";
|
|
4563
|
+
import { parseFile, stringifyFile } from "@tinacms/graphql";
|
|
4564
|
+
import { CONTENT_FORMATS } from "@tinacms/schema-tools";
|
|
4505
4565
|
|
|
4506
4566
|
// src/cmds/forestry-migrate/util/index.ts
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4567
|
+
import fs10 from "fs-extra";
|
|
4568
|
+
import path11 from "path";
|
|
4569
|
+
import yaml from "js-yaml";
|
|
4570
|
+
import z from "zod";
|
|
4511
4571
|
|
|
4512
4572
|
// src/cmds/forestry-migrate/util/errorSingleton.ts
|
|
4513
4573
|
var ErrorSingleton = class _ErrorSingleton {
|
|
4574
|
+
static instance;
|
|
4514
4575
|
/**
|
|
4515
4576
|
* The Singleton's constructor should always be private to prevent direct
|
|
4516
4577
|
* construction calls with the `new` operator.
|
|
@@ -4530,6 +4591,7 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4530
4591
|
}
|
|
4531
4592
|
return _ErrorSingleton.instance;
|
|
4532
4593
|
}
|
|
4594
|
+
collectionNameErrors;
|
|
4533
4595
|
addErrorName(error) {
|
|
4534
4596
|
this.collectionNameErrors.push(error);
|
|
4535
4597
|
}
|
|
@@ -4552,8 +4614,8 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4552
4614
|
};
|
|
4553
4615
|
|
|
4554
4616
|
// src/cmds/forestry-migrate/util/codeTransformer.ts
|
|
4555
|
-
|
|
4556
|
-
|
|
4617
|
+
import { format } from "prettier";
|
|
4618
|
+
import TsParser from "prettier/parser-typescript.js";
|
|
4557
4619
|
var addVariablesToCode = (codeWithTinaPrefix) => {
|
|
4558
4620
|
const code = codeWithTinaPrefix.replace(
|
|
4559
4621
|
/"__TINA_INTERNAL__:::(.*?):::"/g,
|
|
@@ -4590,7 +4652,7 @@ var makeTemplateFile = async ({
|
|
|
4590
4652
|
`export function ${stringifyLabelWithField(
|
|
4591
4653
|
template.templateObj.label
|
|
4592
4654
|
)} (){
|
|
4593
|
-
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4655
|
+
return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
|
|
4594
4656
|
} `
|
|
4595
4657
|
);
|
|
4596
4658
|
}
|
|
@@ -4598,9 +4660,9 @@ var makeTemplateFile = async ({
|
|
|
4598
4660
|
${usingTypescript ? "import type { TinaField } from 'tinacms'" : ""}
|
|
4599
4661
|
${templateCodeText.join("\n")}
|
|
4600
4662
|
`;
|
|
4601
|
-
const formattedCode =
|
|
4663
|
+
const formattedCode = format(templateCode, {
|
|
4602
4664
|
parser: "typescript",
|
|
4603
|
-
plugins: [
|
|
4665
|
+
plugins: [TsParser]
|
|
4604
4666
|
});
|
|
4605
4667
|
return { importStatements, templateCodeText: formattedCode };
|
|
4606
4668
|
};
|
|
@@ -4632,82 +4694,82 @@ var stringifyTemplateName = (name2, template) => {
|
|
|
4632
4694
|
return newName;
|
|
4633
4695
|
}
|
|
4634
4696
|
};
|
|
4635
|
-
var forestryConfigSchema =
|
|
4636
|
-
sections:
|
|
4637
|
-
|
|
4638
|
-
type:
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4697
|
+
var forestryConfigSchema = z.object({
|
|
4698
|
+
sections: z.array(
|
|
4699
|
+
z.object({
|
|
4700
|
+
type: z.union([
|
|
4701
|
+
z.literal("directory"),
|
|
4702
|
+
z.literal("document"),
|
|
4703
|
+
z.literal("heading"),
|
|
4704
|
+
z.literal("jekyll-pages"),
|
|
4705
|
+
z.literal("jekyll-posts")
|
|
4644
4706
|
]),
|
|
4645
|
-
label:
|
|
4646
|
-
path:
|
|
4647
|
-
match:
|
|
4648
|
-
exclude:
|
|
4649
|
-
create:
|
|
4650
|
-
templates:
|
|
4651
|
-
new_doc_ext:
|
|
4652
|
-
read_only:
|
|
4707
|
+
label: z.string(),
|
|
4708
|
+
path: z.string().optional().nullable(),
|
|
4709
|
+
match: z.string().optional().nullable(),
|
|
4710
|
+
exclude: z.string().optional().nullable(),
|
|
4711
|
+
create: z.union([z.literal("all"), z.literal("documents"), z.literal("none")]).optional(),
|
|
4712
|
+
templates: z.array(z.string()).optional().nullable(),
|
|
4713
|
+
new_doc_ext: z.string().optional().nullable(),
|
|
4714
|
+
read_only: z.boolean().optional().nullable()
|
|
4653
4715
|
})
|
|
4654
4716
|
)
|
|
4655
4717
|
});
|
|
4656
|
-
var forestryFieldWithoutField =
|
|
4718
|
+
var forestryFieldWithoutField = z.object({
|
|
4657
4719
|
// TODO: maybe better type this?
|
|
4658
|
-
type:
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4720
|
+
type: z.union([
|
|
4721
|
+
z.literal("text"),
|
|
4722
|
+
z.literal("datetime"),
|
|
4723
|
+
z.literal("list"),
|
|
4724
|
+
z.literal("file"),
|
|
4725
|
+
z.literal("image_gallery"),
|
|
4726
|
+
z.literal("textarea"),
|
|
4727
|
+
z.literal("tag_list"),
|
|
4728
|
+
z.literal("number"),
|
|
4729
|
+
z.literal("boolean"),
|
|
4730
|
+
z.literal("field_group"),
|
|
4731
|
+
z.literal("field_group_list"),
|
|
4732
|
+
z.literal("select"),
|
|
4733
|
+
z.literal("include"),
|
|
4734
|
+
z.literal("blocks"),
|
|
4735
|
+
z.literal("color")
|
|
4674
4736
|
]),
|
|
4675
|
-
template_types:
|
|
4676
|
-
name:
|
|
4677
|
-
label:
|
|
4678
|
-
default:
|
|
4679
|
-
template:
|
|
4680
|
-
config:
|
|
4737
|
+
template_types: z.array(z.string()).optional().nullable(),
|
|
4738
|
+
name: z.string(),
|
|
4739
|
+
label: z.string(),
|
|
4740
|
+
default: z.any().optional(),
|
|
4741
|
+
template: z.string().optional(),
|
|
4742
|
+
config: z.object({
|
|
4681
4743
|
// min and max are used for lists
|
|
4682
|
-
min:
|
|
4683
|
-
max:
|
|
4684
|
-
required:
|
|
4685
|
-
use_select:
|
|
4686
|
-
date_format:
|
|
4687
|
-
time_format:
|
|
4688
|
-
options:
|
|
4689
|
-
source:
|
|
4690
|
-
type:
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4744
|
+
min: z.number().optional().nullable(),
|
|
4745
|
+
max: z.number().optional().nullable(),
|
|
4746
|
+
required: z.boolean().optional().nullable(),
|
|
4747
|
+
use_select: z.boolean().optional().nullable(),
|
|
4748
|
+
date_format: z.string().optional().nullable(),
|
|
4749
|
+
time_format: z.string().optional().nullable(),
|
|
4750
|
+
options: z.array(z.string()).optional().nullable(),
|
|
4751
|
+
source: z.object({
|
|
4752
|
+
type: z.union([
|
|
4753
|
+
z.literal("custom"),
|
|
4754
|
+
z.literal("pages"),
|
|
4755
|
+
z.literal("documents"),
|
|
4756
|
+
z.literal("simple"),
|
|
4695
4757
|
// TODO: I want to ignore this key if its invalid
|
|
4696
|
-
|
|
4758
|
+
z.string()
|
|
4697
4759
|
]).optional().nullable(),
|
|
4698
|
-
section:
|
|
4760
|
+
section: z.string().optional().nullable()
|
|
4699
4761
|
}).optional()
|
|
4700
4762
|
}).optional()
|
|
4701
4763
|
});
|
|
4702
|
-
var forestryField =
|
|
4764
|
+
var forestryField = z.lazy(
|
|
4703
4765
|
() => forestryFieldWithoutField.extend({
|
|
4704
|
-
fields:
|
|
4766
|
+
fields: z.array(forestryField).optional()
|
|
4705
4767
|
})
|
|
4706
4768
|
);
|
|
4707
|
-
var FrontmatterTemplateSchema =
|
|
4708
|
-
label:
|
|
4709
|
-
hide_body:
|
|
4710
|
-
fields:
|
|
4769
|
+
var FrontmatterTemplateSchema = z.object({
|
|
4770
|
+
label: z.string(),
|
|
4771
|
+
hide_body: z.boolean().optional(),
|
|
4772
|
+
fields: z.array(forestryField).optional()
|
|
4711
4773
|
});
|
|
4712
4774
|
var transformForestryFieldsToTinaFields = ({
|
|
4713
4775
|
fields,
|
|
@@ -4930,7 +4992,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
4930
4992
|
return tinaFields;
|
|
4931
4993
|
};
|
|
4932
4994
|
var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
|
|
4933
|
-
const templatePath =
|
|
4995
|
+
const templatePath = path11.join(
|
|
4934
4996
|
pathToForestryConfig,
|
|
4935
4997
|
".forestry",
|
|
4936
4998
|
"front_matter",
|
|
@@ -4939,7 +5001,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4939
5001
|
);
|
|
4940
5002
|
let templateString = "";
|
|
4941
5003
|
try {
|
|
4942
|
-
templateString =
|
|
5004
|
+
templateString = fs10.readFileSync(templatePath).toString();
|
|
4943
5005
|
} catch {
|
|
4944
5006
|
throw new Error(
|
|
4945
5007
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -4947,7 +5009,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
4947
5009
|
This will require manual migration.`
|
|
4948
5010
|
);
|
|
4949
5011
|
}
|
|
4950
|
-
const templateObj =
|
|
5012
|
+
const templateObj = yaml.load(templateString);
|
|
4951
5013
|
const template = parseTemplates({ val: templateObj });
|
|
4952
5014
|
const fields = transformForestryFieldsToTinaFields({
|
|
4953
5015
|
fields: template.fields,
|
|
@@ -4967,6 +5029,7 @@ var parseSections = ({ val }) => {
|
|
|
4967
5029
|
};
|
|
4968
5030
|
|
|
4969
5031
|
// src/cmds/forestry-migrate/index.ts
|
|
5032
|
+
var { minimatch } = pkg;
|
|
4970
5033
|
var BODY_FIELD = {
|
|
4971
5034
|
// This is the body field
|
|
4972
5035
|
type: "rich-text",
|
|
@@ -4995,7 +5058,7 @@ var transformForestryMatchToTinaMatch = (match) => {
|
|
|
4995
5058
|
};
|
|
4996
5059
|
function checkExt(ext) {
|
|
4997
5060
|
const extReal = ext.replace(".", "");
|
|
4998
|
-
if (
|
|
5061
|
+
if (CONTENT_FORMATS.includes(extReal)) {
|
|
4999
5062
|
return extReal;
|
|
5000
5063
|
} else {
|
|
5001
5064
|
return false;
|
|
@@ -5004,9 +5067,9 @@ function checkExt(ext) {
|
|
|
5004
5067
|
var generateAllTemplates = async ({
|
|
5005
5068
|
pathToForestryConfig
|
|
5006
5069
|
}) => {
|
|
5007
|
-
const allTemplates = (await
|
|
5008
|
-
|
|
5009
|
-
)).map((tem) =>
|
|
5070
|
+
const allTemplates = (await fs11.readdir(
|
|
5071
|
+
path12.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
|
|
5072
|
+
)).map((tem) => path12.basename(tem, ".yml"));
|
|
5010
5073
|
const templateMap = /* @__PURE__ */ new Map();
|
|
5011
5074
|
const proms = allTemplates.map(async (tem) => {
|
|
5012
5075
|
try {
|
|
@@ -5081,7 +5144,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5081
5144
|
glob = section.path + "/" + section.match;
|
|
5082
5145
|
}
|
|
5083
5146
|
if (pages.some((page) => {
|
|
5084
|
-
return
|
|
5147
|
+
return minimatch(page, glob);
|
|
5085
5148
|
})) {
|
|
5086
5149
|
forestryTemplates.push(templateKey);
|
|
5087
5150
|
}
|
|
@@ -5151,9 +5214,9 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5151
5214
|
return c;
|
|
5152
5215
|
} else if (section.type === "document") {
|
|
5153
5216
|
const filePath = section.path;
|
|
5154
|
-
const extname =
|
|
5155
|
-
const fileName =
|
|
5156
|
-
const dir =
|
|
5217
|
+
const extname = path12.extname(filePath);
|
|
5218
|
+
const fileName = path12.basename(filePath, extname);
|
|
5219
|
+
const dir = path12.dirname(filePath);
|
|
5157
5220
|
const ext = checkExt(extname);
|
|
5158
5221
|
if (ext) {
|
|
5159
5222
|
const fields = [];
|
|
@@ -5215,8 +5278,8 @@ var generateCollections = async ({
|
|
|
5215
5278
|
templateMap,
|
|
5216
5279
|
usingTypescript
|
|
5217
5280
|
});
|
|
5218
|
-
const forestryConfig = await
|
|
5219
|
-
|
|
5281
|
+
const forestryConfig = await fs11.readFile(
|
|
5282
|
+
path12.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
5220
5283
|
);
|
|
5221
5284
|
rewriteTemplateKeysInDocs({
|
|
5222
5285
|
templateMap,
|
|
@@ -5226,7 +5289,7 @@ var generateCollections = async ({
|
|
|
5226
5289
|
}
|
|
5227
5290
|
});
|
|
5228
5291
|
const collections = parseSections({
|
|
5229
|
-
val:
|
|
5292
|
+
val: yaml2.load(forestryConfig.toString())
|
|
5230
5293
|
}).sections.map(
|
|
5231
5294
|
(section) => generateCollectionFromForestrySection({
|
|
5232
5295
|
section,
|
|
@@ -5246,13 +5309,13 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5246
5309
|
const { templateObj } = templateMap.get(templateKey);
|
|
5247
5310
|
templateObj?.pages?.forEach((page) => {
|
|
5248
5311
|
try {
|
|
5249
|
-
const filePath =
|
|
5250
|
-
if (
|
|
5312
|
+
const filePath = path12.join(page);
|
|
5313
|
+
if (fs11.lstatSync(filePath).isDirectory()) {
|
|
5251
5314
|
return;
|
|
5252
5315
|
}
|
|
5253
|
-
const extname =
|
|
5254
|
-
const fileContent =
|
|
5255
|
-
const content =
|
|
5316
|
+
const extname = path12.extname(filePath);
|
|
5317
|
+
const fileContent = fs11.readFileSync(filePath).toString();
|
|
5318
|
+
const content = parseFile(
|
|
5256
5319
|
fileContent,
|
|
5257
5320
|
extname,
|
|
5258
5321
|
(yup) => yup.object({}),
|
|
@@ -5262,9 +5325,9 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5262
5325
|
_template: stringifyLabel(templateKey),
|
|
5263
5326
|
...content
|
|
5264
5327
|
};
|
|
5265
|
-
|
|
5328
|
+
fs11.writeFileSync(
|
|
5266
5329
|
filePath,
|
|
5267
|
-
|
|
5330
|
+
stringifyFile(newContent, extname, true, markdownParseConfig)
|
|
5268
5331
|
);
|
|
5269
5332
|
} catch (error) {
|
|
5270
5333
|
console.log(
|
|
@@ -5276,32 +5339,25 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5276
5339
|
};
|
|
5277
5340
|
|
|
5278
5341
|
// src/cmds/init/apply.ts
|
|
5279
|
-
|
|
5280
|
-
|
|
5342
|
+
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
5343
|
+
import fs14 from "fs-extra";
|
|
5281
5344
|
|
|
5282
5345
|
// src/next/commands/codemod-command/index.ts
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
var CodemodCommand = class extends
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
}
|
|
5299
|
-
static {
|
|
5300
|
-
this.usage = import_clipanion5.Command.Usage({
|
|
5301
|
-
category: `Commands`,
|
|
5302
|
-
description: `Use codemods for various Tina tasks`
|
|
5303
|
-
});
|
|
5304
|
-
}
|
|
5346
|
+
import { Command as Command5, Option as Option5 } from "clipanion";
|
|
5347
|
+
import fs12 from "fs-extra";
|
|
5348
|
+
import path13 from "path";
|
|
5349
|
+
var CodemodCommand = class extends Command5 {
|
|
5350
|
+
static paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5351
|
+
rootPath = Option5.String("--rootPath", {
|
|
5352
|
+
description: "Specify the root directory to run the CLI from"
|
|
5353
|
+
});
|
|
5354
|
+
verbose = Option5.Boolean("-v,--verbose", false, {
|
|
5355
|
+
description: "increase verbosity of logged output"
|
|
5356
|
+
});
|
|
5357
|
+
static usage = Command5.Usage({
|
|
5358
|
+
category: `Commands`,
|
|
5359
|
+
description: `Use codemods for various Tina tasks`
|
|
5360
|
+
});
|
|
5305
5361
|
async catch(error) {
|
|
5306
5362
|
console.log(error);
|
|
5307
5363
|
}
|
|
@@ -5330,13 +5386,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5330
5386
|
logger.error(e.message);
|
|
5331
5387
|
process.exit(1);
|
|
5332
5388
|
}
|
|
5333
|
-
const tinaDestination =
|
|
5334
|
-
if (await
|
|
5389
|
+
const tinaDestination = path13.join(configManager.rootPath, "tina");
|
|
5390
|
+
if (await fs12.existsSync(tinaDestination)) {
|
|
5335
5391
|
logger.info(
|
|
5336
5392
|
`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.`
|
|
5337
5393
|
);
|
|
5338
5394
|
} else {
|
|
5339
|
-
await
|
|
5395
|
+
await fs12.moveSync(configManager.tinaFolderPath, tinaDestination);
|
|
5340
5396
|
await writeGitignore(configManager.rootPath);
|
|
5341
5397
|
logger.info(
|
|
5342
5398
|
"Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
|
|
@@ -5344,8 +5400,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5344
5400
|
}
|
|
5345
5401
|
};
|
|
5346
5402
|
var writeGitignore = async (rootPath) => {
|
|
5347
|
-
await
|
|
5348
|
-
|
|
5403
|
+
await fs12.outputFileSync(
|
|
5404
|
+
path13.join(rootPath, "tina", ".gitignore"),
|
|
5349
5405
|
"__generated__"
|
|
5350
5406
|
);
|
|
5351
5407
|
};
|
|
@@ -5753,7 +5809,7 @@ Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a
|
|
|
5753
5809
|
`;
|
|
5754
5810
|
|
|
5755
5811
|
// src/cmds/init/apply.ts
|
|
5756
|
-
|
|
5812
|
+
import { format as format2 } from "prettier";
|
|
5757
5813
|
|
|
5758
5814
|
// src/utils/script-helpers.ts
|
|
5759
5815
|
function generateGqlScript(scriptValue, opts) {
|
|
@@ -5776,38 +5832,38 @@ function extendNextScripts(scripts, opts) {
|
|
|
5776
5832
|
}
|
|
5777
5833
|
|
|
5778
5834
|
// src/cmds/init/codegen/index.ts
|
|
5779
|
-
|
|
5780
|
-
|
|
5835
|
+
import ts2 from "typescript";
|
|
5836
|
+
import fs13 from "fs-extra";
|
|
5781
5837
|
|
|
5782
5838
|
// src/cmds/init/codegen/util.ts
|
|
5783
|
-
|
|
5784
|
-
var makeTransformer = (makeVisitor) => (ctx) => (node) =>
|
|
5839
|
+
import ts from "typescript";
|
|
5840
|
+
var makeTransformer = (makeVisitor) => (ctx) => (node) => ts.visitNode(node, makeVisitor(ctx));
|
|
5785
5841
|
function parseExpression(expression) {
|
|
5786
|
-
const sourceFile =
|
|
5842
|
+
const sourceFile = ts.createSourceFile(
|
|
5787
5843
|
"temp.ts",
|
|
5788
5844
|
expression,
|
|
5789
|
-
|
|
5845
|
+
ts.ScriptTarget.Latest
|
|
5790
5846
|
);
|
|
5791
5847
|
if (sourceFile.statements.length !== 1) {
|
|
5792
5848
|
throw new Error("Expected one statement");
|
|
5793
5849
|
}
|
|
5794
5850
|
const statement = sourceFile.statements[0];
|
|
5795
|
-
if (!
|
|
5851
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
5796
5852
|
throw new Error("Expected an expression statement");
|
|
5797
5853
|
}
|
|
5798
5854
|
return [sourceFile, statement.expression];
|
|
5799
5855
|
}
|
|
5800
5856
|
function parseVariableStatement(stmt) {
|
|
5801
|
-
const sourceFile =
|
|
5857
|
+
const sourceFile = ts.createSourceFile(
|
|
5802
5858
|
"temp.ts",
|
|
5803
5859
|
stmt,
|
|
5804
|
-
|
|
5860
|
+
ts.ScriptTarget.Latest
|
|
5805
5861
|
);
|
|
5806
5862
|
if (sourceFile.statements.length !== 1) {
|
|
5807
5863
|
throw new Error("Expected one statement");
|
|
5808
5864
|
}
|
|
5809
5865
|
const statement = sourceFile.statements[0];
|
|
5810
|
-
if (!
|
|
5866
|
+
if (!ts.isVariableStatement(statement)) {
|
|
5811
5867
|
throw new Error("Expected a variable statement");
|
|
5812
5868
|
}
|
|
5813
5869
|
return [sourceFile, statement];
|
|
@@ -5815,7 +5871,7 @@ function parseVariableStatement(stmt) {
|
|
|
5815
5871
|
|
|
5816
5872
|
// src/cmds/init/codegen/index.ts
|
|
5817
5873
|
var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variableStmt) => (ctx) => (node) => {
|
|
5818
|
-
if (
|
|
5874
|
+
if (ts2.isSourceFile(node)) {
|
|
5819
5875
|
const newStatements = [...node.statements];
|
|
5820
5876
|
let encounteredImports = false;
|
|
5821
5877
|
let firstNonImportStatementIdx = -1;
|
|
@@ -5823,7 +5879,7 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5823
5879
|
const [newVarDec] = variableStmt.declarationList.declarations;
|
|
5824
5880
|
const newVarDecName = newVarDec.name.getText(variableStmtSourceFile);
|
|
5825
5881
|
for (let i = 0; i < newStatements.length; i++) {
|
|
5826
|
-
const isImport =
|
|
5882
|
+
const isImport = ts2.isImportDeclaration(newStatements[i]);
|
|
5827
5883
|
if (isImport && !encounteredImports) {
|
|
5828
5884
|
encounteredImports = true;
|
|
5829
5885
|
}
|
|
@@ -5831,9 +5887,9 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5831
5887
|
firstNonImportStatementIdx = i;
|
|
5832
5888
|
}
|
|
5833
5889
|
const stmt = newStatements[i];
|
|
5834
|
-
if (
|
|
5890
|
+
if (ts2.isVariableStatement(stmt)) {
|
|
5835
5891
|
const [dec] = stmt.declarationList.declarations;
|
|
5836
|
-
if (dec.name &&
|
|
5892
|
+
if (dec.name && ts2.isIdentifier(dec.name) && dec.name.getText(sourceFile) === newVarDecName) {
|
|
5837
5893
|
existingStatementIdx = i;
|
|
5838
5894
|
}
|
|
5839
5895
|
}
|
|
@@ -5847,19 +5903,19 @@ var makeVariableStatementVisitor = (sourceFile, variableStmtSourceFile, variable
|
|
|
5847
5903
|
if (existingStatementIdx === -1) {
|
|
5848
5904
|
newStatements.splice(firstNonImportStatementIdx, 0, variableStmt);
|
|
5849
5905
|
}
|
|
5850
|
-
return
|
|
5906
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5851
5907
|
}
|
|
5852
5908
|
};
|
|
5853
5909
|
var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
5854
|
-
if (
|
|
5910
|
+
if (ts2.isSourceFile(node)) {
|
|
5855
5911
|
const newStatements = [...node.statements];
|
|
5856
5912
|
let changed = false;
|
|
5857
5913
|
for (const [moduleName, imports] of Object.entries(importMap)) {
|
|
5858
5914
|
let foundImportStatement = false;
|
|
5859
5915
|
for (const statement of newStatements) {
|
|
5860
|
-
if (
|
|
5916
|
+
if (ts2.isImportDeclaration(statement) && ts2.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === moduleName) {
|
|
5861
5917
|
foundImportStatement = true;
|
|
5862
|
-
const existingImports = statement.importClause?.namedBindings &&
|
|
5918
|
+
const existingImports = statement.importClause?.namedBindings && ts2.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements.map(
|
|
5863
5919
|
(e) => e.name.text
|
|
5864
5920
|
) : [];
|
|
5865
5921
|
const newImports = [
|
|
@@ -5870,22 +5926,22 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5870
5926
|
])
|
|
5871
5927
|
];
|
|
5872
5928
|
const importSpecifiers = newImports.map(
|
|
5873
|
-
(i) =>
|
|
5929
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5874
5930
|
void 0,
|
|
5875
|
-
|
|
5876
|
-
|
|
5931
|
+
ts2.factory.createIdentifier(i),
|
|
5932
|
+
ts2.factory.createIdentifier(i)
|
|
5877
5933
|
)
|
|
5878
5934
|
);
|
|
5879
|
-
const namedImports =
|
|
5880
|
-
const importClause =
|
|
5935
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5936
|
+
const importClause = ts2.factory.createImportClause(
|
|
5881
5937
|
false,
|
|
5882
5938
|
void 0,
|
|
5883
5939
|
namedImports
|
|
5884
5940
|
);
|
|
5885
|
-
const importDec =
|
|
5941
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5886
5942
|
void 0,
|
|
5887
5943
|
importClause,
|
|
5888
|
-
|
|
5944
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5889
5945
|
);
|
|
5890
5946
|
newStatements[newStatements.indexOf(statement)] = importDec;
|
|
5891
5947
|
changed = true;
|
|
@@ -5893,45 +5949,45 @@ var makeImportsVisitor = (sourceFile, importMap) => (ctx) => (node) => {
|
|
|
5893
5949
|
}
|
|
5894
5950
|
if (!foundImportStatement) {
|
|
5895
5951
|
const importSpecifiers = imports.map(
|
|
5896
|
-
(i) =>
|
|
5952
|
+
(i) => ts2.factory.createImportSpecifier(
|
|
5897
5953
|
void 0,
|
|
5898
|
-
|
|
5899
|
-
|
|
5954
|
+
ts2.factory.createIdentifier(i),
|
|
5955
|
+
ts2.factory.createIdentifier(i)
|
|
5900
5956
|
)
|
|
5901
5957
|
);
|
|
5902
|
-
const namedImports =
|
|
5903
|
-
const importClause =
|
|
5958
|
+
const namedImports = ts2.factory.createNamedImports(importSpecifiers);
|
|
5959
|
+
const importClause = ts2.factory.createImportClause(
|
|
5904
5960
|
false,
|
|
5905
5961
|
void 0,
|
|
5906
5962
|
namedImports
|
|
5907
5963
|
);
|
|
5908
|
-
const importDec =
|
|
5964
|
+
const importDec = ts2.factory.createImportDeclaration(
|
|
5909
5965
|
void 0,
|
|
5910
5966
|
importClause,
|
|
5911
|
-
|
|
5967
|
+
ts2.factory.createStringLiteral(moduleName)
|
|
5912
5968
|
);
|
|
5913
5969
|
newStatements.unshift(importDec);
|
|
5914
5970
|
changed = true;
|
|
5915
5971
|
}
|
|
5916
5972
|
}
|
|
5917
5973
|
if (changed) {
|
|
5918
|
-
return
|
|
5974
|
+
return ts2.factory.updateSourceFile(node, newStatements);
|
|
5919
5975
|
}
|
|
5920
5976
|
}
|
|
5921
5977
|
};
|
|
5922
5978
|
var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newExpressionSourceFile, newExpression) => (ctx) => {
|
|
5923
5979
|
const visit2 = (node) => {
|
|
5924
|
-
if (
|
|
5980
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5925
5981
|
const configObject = node.arguments[0];
|
|
5926
5982
|
const updateProperties = configObject.properties.map((property) => {
|
|
5927
|
-
if (
|
|
5983
|
+
if (ts2.isPropertyAssignment(property)) {
|
|
5928
5984
|
const thisPropertyName = property.name.getText(sourceFile);
|
|
5929
|
-
if (thisPropertyName === "schema" &&
|
|
5985
|
+
if (thisPropertyName === "schema" && ts2.isPropertyAssignment(property) && ts2.isObjectLiteralExpression(property.initializer)) {
|
|
5930
5986
|
const schemaObject = property.initializer;
|
|
5931
5987
|
const collectionsProperty = schemaObject.properties.find(
|
|
5932
|
-
(p) =>
|
|
5988
|
+
(p) => ts2.isPropertyAssignment(p) && p.name.getText(sourceFile) === "collections"
|
|
5933
5989
|
);
|
|
5934
|
-
if (collectionsProperty &&
|
|
5990
|
+
if (collectionsProperty && ts2.isPropertyAssignment(collectionsProperty) && ts2.isArrayLiteralExpression(collectionsProperty.initializer)) {
|
|
5935
5991
|
const collectionsArray = collectionsProperty.initializer;
|
|
5936
5992
|
const collectionItems = collectionsArray.elements.map(
|
|
5937
5993
|
(e) => e.getText(sourceFile)
|
|
@@ -5941,16 +5997,16 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5941
5997
|
)) {
|
|
5942
5998
|
return property;
|
|
5943
5999
|
}
|
|
5944
|
-
return
|
|
6000
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5945
6001
|
property,
|
|
5946
6002
|
property.name,
|
|
5947
|
-
|
|
6003
|
+
ts2.factory.createObjectLiteralExpression(
|
|
5948
6004
|
schemaObject.properties.map((subProp) => {
|
|
5949
|
-
if (
|
|
5950
|
-
return
|
|
6005
|
+
if (ts2.isPropertyAssignment(subProp) && subProp.name.getText(sourceFile) === "collections" && ts2.isArrayLiteralExpression(subProp.initializer)) {
|
|
6006
|
+
return ts2.factory.updatePropertyAssignment(
|
|
5951
6007
|
subProp,
|
|
5952
6008
|
subProp.name,
|
|
5953
|
-
|
|
6009
|
+
ts2.factory.createArrayLiteralExpression(
|
|
5954
6010
|
[newExpression, ...subProp.initializer.elements],
|
|
5955
6011
|
true
|
|
5956
6012
|
)
|
|
@@ -5966,56 +6022,56 @@ var makeAddExpressionToSchemaCollectionVisitor = (sourceFile, functionName, newE
|
|
|
5966
6022
|
}
|
|
5967
6023
|
return property;
|
|
5968
6024
|
});
|
|
5969
|
-
return
|
|
6025
|
+
return ts2.factory.createCallExpression(
|
|
5970
6026
|
node.expression,
|
|
5971
6027
|
node.typeArguments,
|
|
5972
|
-
[
|
|
6028
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
5973
6029
|
);
|
|
5974
6030
|
}
|
|
5975
|
-
return
|
|
6031
|
+
return ts2.visitEachChild(node, visit2, ctx);
|
|
5976
6032
|
};
|
|
5977
6033
|
return (sourceFile2) => {
|
|
5978
|
-
return
|
|
6034
|
+
return ts2.visitEachChild(sourceFile2, visit2, ctx);
|
|
5979
6035
|
};
|
|
5980
6036
|
};
|
|
5981
6037
|
var makeUpdateObjectLiteralPropertyVisitor = (sourceFile, functionName, propertyName, propertyValueExpressionSourceFile, propertyValue) => (ctx) => {
|
|
5982
6038
|
const visitor = (node) => {
|
|
5983
|
-
if (
|
|
6039
|
+
if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === functionName && node.arguments.length > 0 && ts2.isObjectLiteralExpression(node.arguments[0])) {
|
|
5984
6040
|
let foundProperty = false;
|
|
5985
6041
|
const configObject = node.arguments[0];
|
|
5986
6042
|
const updateProperties = configObject.properties.map((property) => {
|
|
5987
|
-
if (
|
|
6043
|
+
if (ts2.isPropertyAssignment(property) || ts2.isShorthandPropertyAssignment(property)) {
|
|
5988
6044
|
const name2 = property.name.getText(sourceFile);
|
|
5989
6045
|
if (name2 === propertyName) {
|
|
5990
6046
|
foundProperty = true;
|
|
5991
|
-
return
|
|
6047
|
+
return ts2.factory.createPropertyAssignment(name2, propertyValue);
|
|
5992
6048
|
}
|
|
5993
6049
|
}
|
|
5994
6050
|
return property;
|
|
5995
6051
|
});
|
|
5996
6052
|
if (!foundProperty) {
|
|
5997
6053
|
updateProperties.unshift(
|
|
5998
|
-
|
|
6054
|
+
ts2.factory.createPropertyAssignment(propertyName, propertyValue)
|
|
5999
6055
|
);
|
|
6000
6056
|
}
|
|
6001
|
-
return
|
|
6057
|
+
return ts2.factory.createCallExpression(
|
|
6002
6058
|
node.expression,
|
|
6003
6059
|
node.typeArguments,
|
|
6004
|
-
[
|
|
6060
|
+
[ts2.factory.createObjectLiteralExpression(updateProperties, true)]
|
|
6005
6061
|
);
|
|
6006
6062
|
}
|
|
6007
|
-
return
|
|
6063
|
+
return ts2.visitEachChild(node, visitor, ctx);
|
|
6008
6064
|
};
|
|
6009
6065
|
return (sourceFile2) => {
|
|
6010
|
-
return
|
|
6066
|
+
return ts2.visitNode(sourceFile2, visitor);
|
|
6011
6067
|
};
|
|
6012
6068
|
};
|
|
6013
6069
|
var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
6014
6070
|
const pathToConfig = configFile.resolve(config2.typescript).path;
|
|
6015
|
-
const sourceFile =
|
|
6071
|
+
const sourceFile = ts2.createSourceFile(
|
|
6016
6072
|
pathToConfig,
|
|
6017
|
-
|
|
6018
|
-
config2.typescript ?
|
|
6073
|
+
fs13.readFileSync(pathToConfig, "utf8"),
|
|
6074
|
+
config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
|
|
6019
6075
|
);
|
|
6020
6076
|
const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
|
|
6021
6077
|
const importMap = {
|
|
@@ -6028,7 +6084,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6028
6084
|
{}
|
|
6029
6085
|
)
|
|
6030
6086
|
};
|
|
6031
|
-
const transformedSourceFileResult =
|
|
6087
|
+
const transformedSourceFileResult = ts2.transform(
|
|
6032
6088
|
sourceFile,
|
|
6033
6089
|
[
|
|
6034
6090
|
makeImportsVisitor(sourceFile, {
|
|
@@ -6064,9 +6120,9 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6064
6120
|
)
|
|
6065
6121
|
].map((visitor) => makeTransformer(visitor))
|
|
6066
6122
|
);
|
|
6067
|
-
return
|
|
6123
|
+
return fs13.writeFile(
|
|
6068
6124
|
pathToConfig,
|
|
6069
|
-
|
|
6125
|
+
ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
|
|
6070
6126
|
);
|
|
6071
6127
|
};
|
|
6072
6128
|
|
|
@@ -6181,8 +6237,8 @@ async function apply({
|
|
|
6181
6237
|
await addConfigFile({
|
|
6182
6238
|
configArgs: {
|
|
6183
6239
|
config: config2,
|
|
6184
|
-
publicFolder:
|
|
6185
|
-
|
|
6240
|
+
publicFolder: path14.join(
|
|
6241
|
+
path14.relative(process.cwd(), pathToForestryConfig),
|
|
6186
6242
|
config2.publicFolder
|
|
6187
6243
|
),
|
|
6188
6244
|
collections,
|
|
@@ -6239,7 +6295,7 @@ var reportTelemetry = async ({
|
|
|
6239
6295
|
if (noTelemetry) {
|
|
6240
6296
|
logger.info(logText("Telemetry disabled"));
|
|
6241
6297
|
}
|
|
6242
|
-
const telemetry = new
|
|
6298
|
+
const telemetry = new Telemetry2({ disabled: noTelemetry });
|
|
6243
6299
|
const schemaFileType = usingTypescript ? "ts" : "js";
|
|
6244
6300
|
await telemetry.submitRecord({
|
|
6245
6301
|
event: {
|
|
@@ -6255,18 +6311,18 @@ var createPackageJSON = async () => {
|
|
|
6255
6311
|
};
|
|
6256
6312
|
var createGitignore = async ({ baseDir }) => {
|
|
6257
6313
|
logger.info(logText("No .gitignore found, creating one"));
|
|
6258
|
-
|
|
6314
|
+
fs14.outputFileSync(path14.join(baseDir, ".gitignore"), "node_modules");
|
|
6259
6315
|
};
|
|
6260
6316
|
var updateGitIgnore = async ({
|
|
6261
6317
|
baseDir,
|
|
6262
6318
|
items
|
|
6263
6319
|
}) => {
|
|
6264
6320
|
logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
|
|
6265
|
-
const gitignoreContent =
|
|
6321
|
+
const gitignoreContent = fs14.readFileSync(path14.join(baseDir, ".gitignore")).toString();
|
|
6266
6322
|
const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
|
|
6267
6323
|
"\n"
|
|
6268
6324
|
);
|
|
6269
|
-
await
|
|
6325
|
+
await fs14.writeFile(path14.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
6270
6326
|
};
|
|
6271
6327
|
var addDependencies = async (config2, env, params) => {
|
|
6272
6328
|
const { packageManager } = config2;
|
|
@@ -6341,7 +6397,7 @@ var writeGeneratedFile = async ({
|
|
|
6341
6397
|
if (exists) {
|
|
6342
6398
|
if (overwrite) {
|
|
6343
6399
|
logger.info(`Overwriting file at ${path15}... \u2705`);
|
|
6344
|
-
|
|
6400
|
+
fs14.outputFileSync(path15, content);
|
|
6345
6401
|
} else {
|
|
6346
6402
|
logger.info(`Not overwriting file at ${path15}.`);
|
|
6347
6403
|
logger.info(
|
|
@@ -6351,8 +6407,8 @@ ${indentText(content)}}`)
|
|
|
6351
6407
|
}
|
|
6352
6408
|
} else {
|
|
6353
6409
|
logger.info(`Adding file at ${path15}... \u2705`);
|
|
6354
|
-
await
|
|
6355
|
-
|
|
6410
|
+
await fs14.ensureDir(parentPath);
|
|
6411
|
+
fs14.outputFileSync(path15, content);
|
|
6356
6412
|
}
|
|
6357
6413
|
};
|
|
6358
6414
|
var addConfigFile = async ({
|
|
@@ -6361,7 +6417,7 @@ var addConfigFile = async ({
|
|
|
6361
6417
|
generatedFile,
|
|
6362
6418
|
config: config2
|
|
6363
6419
|
}) => {
|
|
6364
|
-
const content = (
|
|
6420
|
+
const content = format2(generateConfig(configArgs), {
|
|
6365
6421
|
parser: "babel"
|
|
6366
6422
|
});
|
|
6367
6423
|
await writeGeneratedFile({
|
|
@@ -6391,7 +6447,7 @@ var addNextApiRoute = async ({
|
|
|
6391
6447
|
generatedFile,
|
|
6392
6448
|
env
|
|
6393
6449
|
}) => {
|
|
6394
|
-
const content = (
|
|
6450
|
+
const content = format2(nextApiRouteTemplate({ config: config2, env }), {
|
|
6395
6451
|
parser: "babel"
|
|
6396
6452
|
});
|
|
6397
6453
|
await writeGeneratedFile({
|
|
@@ -6430,7 +6486,7 @@ var addContentFile = async ({
|
|
|
6430
6486
|
return () => ({
|
|
6431
6487
|
exists: env.sampleContentExists,
|
|
6432
6488
|
path: env.sampleContentPath,
|
|
6433
|
-
parentPath:
|
|
6489
|
+
parentPath: path14.dirname(env.sampleContentPath)
|
|
6434
6490
|
});
|
|
6435
6491
|
}
|
|
6436
6492
|
},
|
|
@@ -6453,10 +6509,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
|
|
|
6453
6509
|
return `${x.key}=${x.value || "***"}`;
|
|
6454
6510
|
}).join("\n") + `
|
|
6455
6511
|
TINA_PUBLIC_IS_LOCAL=true`;
|
|
6456
|
-
const envFile =
|
|
6457
|
-
if (!
|
|
6512
|
+
const envFile = path14.join(process.cwd(), ".env");
|
|
6513
|
+
if (!fs14.existsSync(envFile)) {
|
|
6458
6514
|
logger.info(`Adding .env file to your project... \u2705`);
|
|
6459
|
-
|
|
6515
|
+
fs14.writeFileSync(envFile, envFileText);
|
|
6460
6516
|
} else {
|
|
6461
6517
|
logger.info(
|
|
6462
6518
|
"Please add the following environment variables to your .env file"
|
|
@@ -6527,7 +6583,7 @@ var addReactiveFile = {
|
|
|
6527
6583
|
baseDir,
|
|
6528
6584
|
dataLayer
|
|
6529
6585
|
}) => {
|
|
6530
|
-
const packageJsonPath =
|
|
6586
|
+
const packageJsonPath = path14.join(baseDir, "package.json");
|
|
6531
6587
|
await writeGeneratedFile({
|
|
6532
6588
|
generatedFile,
|
|
6533
6589
|
typescript: config2.typescript,
|
|
@@ -6540,7 +6596,7 @@ var addReactiveFile = {
|
|
|
6540
6596
|
})
|
|
6541
6597
|
});
|
|
6542
6598
|
logger.info("Adding a nextjs example... \u2705");
|
|
6543
|
-
const packageJson = JSON.parse(
|
|
6599
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath).toString());
|
|
6544
6600
|
const scripts = packageJson.scripts || {};
|
|
6545
6601
|
const updatedPackageJson = JSON.stringify(
|
|
6546
6602
|
{
|
|
@@ -6553,11 +6609,11 @@ var addReactiveFile = {
|
|
|
6553
6609
|
null,
|
|
6554
6610
|
2
|
|
6555
6611
|
);
|
|
6556
|
-
|
|
6612
|
+
fs14.writeFileSync(packageJsonPath, updatedPackageJson);
|
|
6557
6613
|
}
|
|
6558
6614
|
};
|
|
6559
6615
|
function execShellCommand(cmd) {
|
|
6560
|
-
const exec =
|
|
6616
|
+
const exec = __require("child_process").exec;
|
|
6561
6617
|
return new Promise((resolve2, reject) => {
|
|
6562
6618
|
exec(cmd, (error, stdout, stderr) => {
|
|
6563
6619
|
if (error) {
|
|
@@ -6603,34 +6659,27 @@ var command = new CLICommand({
|
|
|
6603
6659
|
});
|
|
6604
6660
|
|
|
6605
6661
|
// src/next/commands/init-command/index.ts
|
|
6606
|
-
var InitCommand = class extends
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
}
|
|
6628
|
-
static {
|
|
6629
|
-
this.usage = import_clipanion6.Command.Usage({
|
|
6630
|
-
category: `Commands`,
|
|
6631
|
-
description: `Add Tina to an existing project`
|
|
6632
|
-
});
|
|
6633
|
-
}
|
|
6662
|
+
var InitCommand = class extends Command6 {
|
|
6663
|
+
static paths = [["init"], ["init", "backend"]];
|
|
6664
|
+
pathToForestryConfig = Option6.String("--forestryPath", {
|
|
6665
|
+
description: "Specify the relative path to the .forestry directory, if importing an existing forestry site."
|
|
6666
|
+
});
|
|
6667
|
+
rootPath = Option6.String("--rootPath", {
|
|
6668
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6669
|
+
});
|
|
6670
|
+
debug = Option6.Boolean("--debug", false, {
|
|
6671
|
+
description: "Enable debug logging"
|
|
6672
|
+
});
|
|
6673
|
+
noTelemetry = Option6.Boolean("--noTelemetry", false, {
|
|
6674
|
+
description: "Disable anonymous telemetry that is collected"
|
|
6675
|
+
});
|
|
6676
|
+
tinaVersion = Option6.String("--tinaVersion", {
|
|
6677
|
+
description: "Specify a version for tina dependencies"
|
|
6678
|
+
});
|
|
6679
|
+
static usage = Command6.Usage({
|
|
6680
|
+
category: `Commands`,
|
|
6681
|
+
description: `Add Tina to an existing project`
|
|
6682
|
+
});
|
|
6634
6683
|
async catch(error) {
|
|
6635
6684
|
logger.error("Error occured during tinacms init");
|
|
6636
6685
|
console.error(error);
|
|
@@ -6652,28 +6701,24 @@ var InitCommand = class extends import_clipanion6.Command {
|
|
|
6652
6701
|
};
|
|
6653
6702
|
|
|
6654
6703
|
// src/next/commands/searchindex-command/index.ts
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
category: `Commands`,
|
|
6674
|
-
description: `Index the site for search`
|
|
6675
|
-
});
|
|
6676
|
-
}
|
|
6704
|
+
import { Command as Command7, Option as Option7 } from "clipanion";
|
|
6705
|
+
import { createSchema, FilesystemBridge as FilesystemBridge4 } from "@tinacms/graphql";
|
|
6706
|
+
import {
|
|
6707
|
+
SearchIndexer as SearchIndexer3,
|
|
6708
|
+
TinaCMSSearchIndexClient as TinaCMSSearchIndexClient2
|
|
6709
|
+
} from "@tinacms/search";
|
|
6710
|
+
var SearchIndexCommand = class extends Command7 {
|
|
6711
|
+
static paths = [["search-index"]];
|
|
6712
|
+
rootPath = Option7.String("--rootPath", {
|
|
6713
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
6714
|
+
});
|
|
6715
|
+
verbose = Option7.Boolean("-v,--verbose", false, {
|
|
6716
|
+
description: "increase verbosity of logged output"
|
|
6717
|
+
});
|
|
6718
|
+
static usage = Command7.Usage({
|
|
6719
|
+
category: `Commands`,
|
|
6720
|
+
description: `Index the site for search`
|
|
6721
|
+
});
|
|
6677
6722
|
async catch(error) {
|
|
6678
6723
|
logger.error("Error occured during tinacms search-index");
|
|
6679
6724
|
console.error(error);
|
|
@@ -6695,7 +6740,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6695
6740
|
process.exit(1);
|
|
6696
6741
|
}
|
|
6697
6742
|
const { schema } = configManager.config;
|
|
6698
|
-
const tinaSchema = await
|
|
6743
|
+
const tinaSchema = await createSchema({
|
|
6699
6744
|
schema: { ...schema, config: configManager.config }
|
|
6700
6745
|
});
|
|
6701
6746
|
let client;
|
|
@@ -6723,7 +6768,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6723
6768
|
"indexerToken not configured in tina search configuration."
|
|
6724
6769
|
);
|
|
6725
6770
|
}
|
|
6726
|
-
client = new
|
|
6771
|
+
client = new TinaCMSSearchIndexClient2({
|
|
6727
6772
|
apiUrl: `${configManager.config.tinaioConfig?.contentApiUrlOverride || "https://content.tinajs.io"}/searchIndex/${configManager.config?.clientId}`,
|
|
6728
6773
|
branch: configManager.config?.branch,
|
|
6729
6774
|
indexerToken: configManager.config?.search?.tina?.indexerToken,
|
|
@@ -6732,9 +6777,9 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6732
6777
|
} else {
|
|
6733
6778
|
client = configManager.config?.search?.searchClient;
|
|
6734
6779
|
}
|
|
6735
|
-
const searchIndexer = new
|
|
6780
|
+
const searchIndexer = new SearchIndexer3({
|
|
6736
6781
|
batchSize: configManager.config.search?.indexBatchSize || 100,
|
|
6737
|
-
bridge: new
|
|
6782
|
+
bridge: new FilesystemBridge4(
|
|
6738
6783
|
configManager.rootPath,
|
|
6739
6784
|
configManager.contentRootPath
|
|
6740
6785
|
),
|
|
@@ -6762,7 +6807,7 @@ var SearchIndexCommand = class extends import_clipanion7.Command {
|
|
|
6762
6807
|
};
|
|
6763
6808
|
|
|
6764
6809
|
// src/index.ts
|
|
6765
|
-
var cli = new
|
|
6810
|
+
var cli = new Cli({
|
|
6766
6811
|
binaryName: `tinacms`,
|
|
6767
6812
|
binaryLabel: `TinaCMS`,
|
|
6768
6813
|
binaryVersion: version
|
|
@@ -6773,7 +6818,10 @@ cli.register(AuditCommand);
|
|
|
6773
6818
|
cli.register(InitCommand);
|
|
6774
6819
|
cli.register(CodemodCommand);
|
|
6775
6820
|
cli.register(SearchIndexCommand);
|
|
6776
|
-
cli.register(
|
|
6777
|
-
cli.register(
|
|
6778
|
-
cli.register(
|
|
6821
|
+
cli.register(Builtins.DefinitionsCommand);
|
|
6822
|
+
cli.register(Builtins.HelpCommand);
|
|
6823
|
+
cli.register(Builtins.VersionCommand);
|
|
6779
6824
|
var index_default = cli;
|
|
6825
|
+
export {
|
|
6826
|
+
index_default as default
|
|
6827
|
+
};
|