@tinacms/cli 0.60.28 → 0.61.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buildTina/attachPath.d.ts +13 -0
- package/dist/buildTina/git.d.ts +22 -0
- package/dist/buildTina/index.d.ts +42 -0
- package/dist/cmds/baseCmds.d.ts +2 -3
- package/dist/cmds/compile/defaultSchema.d.ts +1 -1
- package/dist/cmds/compile/index.d.ts +10 -2
- package/dist/cmds/init/setup-files/index.d.ts +3 -1
- package/dist/cmds/query-gen/genTypes.d.ts +8 -1
- package/dist/cmds/start-server/index.d.ts +2 -1
- package/dist/index.js +1017 -722
- package/dist/lib/getPath.d.ts +8 -0
- package/dist/utils/spinner.d.ts +16 -0
- package/package.json +9 -5
package/dist/index.js
CHANGED
|
@@ -70,11 +70,11 @@ var init_utils = __esm({
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
// src/server/models/media.ts
|
|
73
|
-
var
|
|
73
|
+
var import_fs_extra7, import_path9, MediaModel;
|
|
74
74
|
var init_media = __esm({
|
|
75
75
|
"src/server/models/media.ts"() {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
import_fs_extra7 = __toModule(require("fs-extra"));
|
|
77
|
+
import_path9 = __toModule(require("path"));
|
|
78
78
|
init_utils();
|
|
79
79
|
MediaModel = class {
|
|
80
80
|
constructor({ publicFolder, mediaRoot }) {
|
|
@@ -83,12 +83,12 @@ var init_media = __esm({
|
|
|
83
83
|
}
|
|
84
84
|
async listMedia(args) {
|
|
85
85
|
try {
|
|
86
|
-
const folderPath = (0,
|
|
86
|
+
const folderPath = (0, import_path9.join)(this.publicFolder, this.mediaRoot, args.searchPath);
|
|
87
87
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
88
|
-
const filesStr = await
|
|
88
|
+
const filesStr = await import_fs_extra7.default.readdir(folderPath);
|
|
89
89
|
const filesProm = filesStr.map(async (file) => {
|
|
90
|
-
const filePath = (0,
|
|
91
|
-
const stat = await
|
|
90
|
+
const filePath = (0, import_path9.join)(folderPath, file);
|
|
91
|
+
const stat = await import_fs_extra7.default.stat(filePath);
|
|
92
92
|
let src = `/${file}`;
|
|
93
93
|
const isFile = stat.isFile();
|
|
94
94
|
if (!isFile) {
|
|
@@ -144,9 +144,9 @@ var init_media = __esm({
|
|
|
144
144
|
}
|
|
145
145
|
async deleteMedia(args) {
|
|
146
146
|
try {
|
|
147
|
-
const file = (0,
|
|
148
|
-
await
|
|
149
|
-
await
|
|
147
|
+
const file = (0, import_path9.join)(this.publicFolder, this.mediaRoot, args.searchPath);
|
|
148
|
+
await import_fs_extra7.default.stat(file);
|
|
149
|
+
await import_fs_extra7.default.remove(file);
|
|
150
150
|
return { ok: true };
|
|
151
151
|
} catch (error) {
|
|
152
152
|
console.error(error);
|
|
@@ -158,15 +158,15 @@ var init_media = __esm({
|
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
// src/server/routes/index.ts
|
|
161
|
-
var import_express,
|
|
161
|
+
var import_express, import_path10, import_multer, createMediaRouter;
|
|
162
162
|
var init_routes = __esm({
|
|
163
163
|
"src/server/routes/index.ts"() {
|
|
164
164
|
import_express = __toModule(require("express"));
|
|
165
|
-
|
|
165
|
+
import_path10 = __toModule(require("path"));
|
|
166
166
|
import_multer = __toModule(require("multer"));
|
|
167
167
|
init_media();
|
|
168
168
|
createMediaRouter = (config) => {
|
|
169
|
-
const mediaFolder = (0,
|
|
169
|
+
const mediaFolder = (0, import_path10.join)(process.cwd(), config.publicFolder, config.mediaRoot);
|
|
170
170
|
const storage = import_multer.default.diskStorage({
|
|
171
171
|
destination: function(req, file, cb) {
|
|
172
172
|
cb(null, mediaFolder);
|
|
@@ -293,22 +293,11 @@ var commander = __toModule(require("commander"));
|
|
|
293
293
|
|
|
294
294
|
// package.json
|
|
295
295
|
var name = "@tinacms/cli";
|
|
296
|
-
var version = "0.
|
|
296
|
+
var version = "0.61.2";
|
|
297
297
|
|
|
298
|
-
// src/cmds/
|
|
298
|
+
// src/cmds/audit/audit.ts
|
|
299
299
|
var import_graphql = __toModule(require("@tinacms/graphql"));
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
// src/utils/theme.ts
|
|
303
|
-
var import_chalk = __toModule(require("chalk"));
|
|
304
|
-
var successText = import_chalk.default.bold.green;
|
|
305
|
-
var dangerText = import_chalk.default.bold.red;
|
|
306
|
-
var neutralText = import_chalk.default.bold.cyan;
|
|
307
|
-
var labelText = import_chalk.default.bold;
|
|
308
|
-
var cmdText = import_chalk.default.inverse;
|
|
309
|
-
var logText = import_chalk.default.italic.gray;
|
|
310
|
-
var warnText = import_chalk.default.yellowBright.bgBlack;
|
|
311
|
-
var CONFIRMATION_TEXT = import_chalk.default.dim("enter to confirm");
|
|
300
|
+
var import_path = __toModule(require("path"));
|
|
312
301
|
|
|
313
302
|
// src/logger/index.ts
|
|
314
303
|
var import_log4js = __toModule(require("log4js"));
|
|
@@ -321,269 +310,9 @@ import_log4js.default.configure({
|
|
|
321
310
|
});
|
|
322
311
|
logger.level = "info";
|
|
323
312
|
|
|
324
|
-
// src/cmds/query-gen/attachSchema.ts
|
|
325
|
-
async function attachSchema(ctx, next, options) {
|
|
326
|
-
logger.info(logText("Building schema..."));
|
|
327
|
-
const rootPath2 = process.cwd();
|
|
328
|
-
const bridge = new import_datalayer.FilesystemBridge(rootPath2);
|
|
329
|
-
const store = new import_datalayer.FilesystemStore({ rootPath: rootPath2 });
|
|
330
|
-
const database = await (0, import_graphql.createDatabase)({ store, bridge });
|
|
331
|
-
const schema = await (0, import_graphql.buildSchema)(rootPath2, database);
|
|
332
|
-
ctx.schema = schema;
|
|
333
|
-
next();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// src/cmds/query-gen/genTypes.ts
|
|
337
|
-
var import_graphql6 = __toModule(require("graphql"));
|
|
338
|
-
var import_fs_extra = __toModule(require("fs-extra"));
|
|
339
|
-
|
|
340
|
-
// src/codegen/index.ts
|
|
341
|
-
var import_graphql5 = __toModule(require("graphql"));
|
|
342
|
-
|
|
343
|
-
// src/codegen/plugin.ts
|
|
344
|
-
var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
|
|
345
|
-
return `
|
|
346
|
-
// TinaSDK generated code
|
|
347
|
-
import { createClient, TinaClient } from "tinacms/dist/client";
|
|
348
|
-
|
|
349
|
-
const generateRequester = (client: TinaClient) => {
|
|
350
|
-
const requester: (
|
|
351
|
-
doc: any,
|
|
352
|
-
vars?: any,
|
|
353
|
-
options?: any,
|
|
354
|
-
client
|
|
355
|
-
) => Promise<any> = async (doc, vars, _options) => {
|
|
356
|
-
let data = {};
|
|
357
|
-
try {
|
|
358
|
-
data = await client.request({
|
|
359
|
-
query: doc,
|
|
360
|
-
variables: vars,
|
|
361
|
-
});
|
|
362
|
-
} catch (e) {
|
|
363
|
-
// swallow errors related to document creation
|
|
364
|
-
console.warn("Warning: There was an error when fetching data");
|
|
365
|
-
console.warn(e);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return { data: data?.data, query: doc, variables: vars || {} };
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
return requester;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* @experimental this class can be used but may change in the future
|
|
376
|
-
**/
|
|
377
|
-
export const ExperimentalGetTinaClient = () =>
|
|
378
|
-
getSdk(
|
|
379
|
-
generateRequester(createClient({ url: "http://localhost:4001/graphql" }))
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
export const queries = (client: TinaClient) => {
|
|
383
|
-
const requester = generateRequester(client);
|
|
384
|
-
return getSdk(requester);
|
|
385
|
-
};
|
|
386
|
-
`;
|
|
387
|
-
};
|
|
388
|
-
var AddGeneratedClient = {
|
|
389
|
-
plugin: AddGeneratedClientFunc
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
// src/codegen/index.ts
|
|
393
|
-
var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
|
|
394
|
-
var import_core = __toModule(require("@graphql-codegen/core"));
|
|
395
|
-
var import_load = __toModule(require("@graphql-tools/load"));
|
|
396
|
-
var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
|
|
397
|
-
var import_typescript = __toModule(require("@graphql-codegen/typescript"));
|
|
398
|
-
|
|
399
|
-
// src/codegen/sdkPlugin/index.ts
|
|
400
|
-
var import_graphql3 = __toModule(require("graphql"));
|
|
401
|
-
var import_graphql4 = __toModule(require("graphql"));
|
|
402
|
-
var import_path = __toModule(require("path"));
|
|
403
|
-
|
|
404
|
-
// src/codegen/sdkPlugin/visitor.ts
|
|
405
|
-
var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
|
|
406
|
-
var import_auto_bind = __toModule(require("auto-bind"));
|
|
407
|
-
var import_graphql2 = __toModule(require("graphql"));
|
|
408
|
-
var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBaseVisitor {
|
|
409
|
-
constructor(schema, fragments, rawConfig) {
|
|
410
|
-
super(schema, fragments, rawConfig, {
|
|
411
|
-
usingObservableFrom: rawConfig.usingObservableFrom
|
|
412
|
-
});
|
|
413
|
-
this._operationsToInclude = [];
|
|
414
|
-
(0, import_auto_bind.default)(this);
|
|
415
|
-
if (this.config.usingObservableFrom) {
|
|
416
|
-
this._additionalImports.push(this.config.usingObservableFrom);
|
|
417
|
-
}
|
|
418
|
-
if (this.config.documentMode !== import_visitor_plugin_common.DocumentMode.string) {
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
422
|
-
if (node.name == null) {
|
|
423
|
-
throw new Error("Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + (0, import_graphql2.print)(node));
|
|
424
|
-
} else {
|
|
425
|
-
this._operationsToInclude.push({
|
|
426
|
-
node,
|
|
427
|
-
documentVariableName,
|
|
428
|
-
operationType,
|
|
429
|
-
operationResultType: `{data: ${operationResultType}, variables: ${operationVariablesTypes}, query: string}`,
|
|
430
|
-
operationVariablesTypes
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
get sdkContent() {
|
|
436
|
-
const usingObservable = !!this.config.usingObservableFrom;
|
|
437
|
-
const allPossibleActions = this._operationsToInclude.map((o) => {
|
|
438
|
-
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every((v) => v.type.kind !== import_graphql2.Kind.NON_NULL_TYPE || v.defaultValue);
|
|
439
|
-
const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
|
|
440
|
-
return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
|
|
441
|
-
return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
|
|
442
|
-
}`;
|
|
443
|
-
}).map((s) => (0, import_visitor_plugin_common.indentMultiline)(s, 2));
|
|
444
|
-
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode === import_visitor_plugin_common.DocumentMode.string ? "string" : "DocumentNode"}, vars?: V, options?: C) => ${usingObservable ? "Promise<R> & Observable<R>" : "Promise<R>"}
|
|
445
|
-
export function getSdk<C>(requester: Requester<C>) {
|
|
446
|
-
return {
|
|
447
|
-
${allPossibleActions.join(",\n")}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
export type Sdk = ReturnType<typeof getSdk>;`;
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
// src/codegen/sdkPlugin/index.ts
|
|
455
|
-
var plugin = (schema, documents, config) => {
|
|
456
|
-
const allAst = (0, import_graphql4.concatAST)(documents.reduce((prev, v) => {
|
|
457
|
-
return [...prev, v.document];
|
|
458
|
-
}, []));
|
|
459
|
-
const allFragments = [
|
|
460
|
-
...allAst.definitions.filter((d) => d.kind === import_graphql4.Kind.FRAGMENT_DEFINITION).map((fragmentDef) => ({
|
|
461
|
-
node: fragmentDef,
|
|
462
|
-
name: fragmentDef.name.value,
|
|
463
|
-
onType: fragmentDef.typeCondition.name.value,
|
|
464
|
-
isExternal: false
|
|
465
|
-
})),
|
|
466
|
-
...config.externalFragments || []
|
|
467
|
-
];
|
|
468
|
-
const visitor = new GenericSdkVisitor(schema, allFragments, config);
|
|
469
|
-
const visitorResult = (0, import_graphql3.visit)(allAst, { leave: visitor });
|
|
470
|
-
return {
|
|
471
|
-
content: [
|
|
472
|
-
visitor.fragments,
|
|
473
|
-
...visitorResult.definitions.filter((t) => typeof t === "string"),
|
|
474
|
-
visitor.sdkContent
|
|
475
|
-
].join("\n")
|
|
476
|
-
};
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
// src/codegen/index.ts
|
|
480
|
-
var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = {
|
|
481
|
-
noSDK: false,
|
|
482
|
-
verbose: false
|
|
483
|
-
}) => {
|
|
484
|
-
if (options.verbose)
|
|
485
|
-
logger.info("Generating types...");
|
|
486
|
-
try {
|
|
487
|
-
let docs = [];
|
|
488
|
-
let fragDocs = [];
|
|
489
|
-
try {
|
|
490
|
-
if (!options.noSDK) {
|
|
491
|
-
docs = await (0, import_load.loadDocuments)(queryPathGlob, {
|
|
492
|
-
loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
} catch (e) {
|
|
496
|
-
let showErrorMessage = true;
|
|
497
|
-
const message = e.message || "";
|
|
498
|
-
if (message.includes("Unable to find any GraphQL type definitions for the following pointers:")) {
|
|
499
|
-
showErrorMessage = false;
|
|
500
|
-
}
|
|
501
|
-
if (showErrorMessage) {
|
|
502
|
-
console.error(e);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
try {
|
|
506
|
-
if (!options.noSDK) {
|
|
507
|
-
fragDocs = await (0, import_load.loadDocuments)(fragDocPath, {
|
|
508
|
-
loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
} catch (error) {
|
|
512
|
-
console.error(error);
|
|
513
|
-
}
|
|
514
|
-
const res = await (0, import_core.codegen)({
|
|
515
|
-
filename: process.cwd(),
|
|
516
|
-
schema: (0, import_graphql5.parse)((0, import_graphql5.printSchema)(schema)),
|
|
517
|
-
documents: [...docs, ...fragDocs],
|
|
518
|
-
config: {},
|
|
519
|
-
plugins: [
|
|
520
|
-
{ typescript: {} },
|
|
521
|
-
{ typescriptOperations: {} },
|
|
522
|
-
{
|
|
523
|
-
typescriptSdk: {}
|
|
524
|
-
},
|
|
525
|
-
{ AddGeneratedClient: {} }
|
|
526
|
-
],
|
|
527
|
-
pluginMap: {
|
|
528
|
-
typescript: {
|
|
529
|
-
plugin: import_typescript.plugin
|
|
530
|
-
},
|
|
531
|
-
typescriptOperations: {
|
|
532
|
-
plugin: import_typescript_operations.plugin
|
|
533
|
-
},
|
|
534
|
-
typescriptSdk: {
|
|
535
|
-
plugin
|
|
536
|
-
},
|
|
537
|
-
AddGeneratedClient
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
return res;
|
|
541
|
-
} catch (e) {
|
|
542
|
-
console.error(e);
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
// src/cmds/query-gen/genTypes.ts
|
|
547
|
-
async function genTypes({ schema }, next, options) {
|
|
548
|
-
const typesPath = process.cwd() + "/.tina/__generated__/types.ts";
|
|
549
|
-
const fragPath = process.cwd() + "/.tina/__generated__/*.{graphql,gql}";
|
|
550
|
-
const queryPathGlob = process.cwd() + "/.tina/queries/**/*.{graphql,gql}";
|
|
551
|
-
const typescriptTypes = await generateTypes(schema, queryPathGlob, fragPath, options);
|
|
552
|
-
await import_fs_extra.default.outputFile(typesPath, `//@ts-nocheck
|
|
553
|
-
// DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
554
|
-
export function gql(strings: TemplateStringsArray, ...args: string[]): string {
|
|
555
|
-
let str = ''
|
|
556
|
-
strings.forEach((string, i) => {
|
|
557
|
-
str += string + (args[i] || '')
|
|
558
|
-
})
|
|
559
|
-
return str
|
|
560
|
-
}
|
|
561
|
-
${typescriptTypes}
|
|
562
|
-
`);
|
|
563
|
-
logger.info(` Typescript types => ${logText(typesPath)}`);
|
|
564
|
-
const schemaString = await (0, import_graphql6.printSchema)(schema);
|
|
565
|
-
const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
|
|
566
|
-
await import_fs_extra.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
567
|
-
${schemaString}
|
|
568
|
-
schema {
|
|
569
|
-
query: Query
|
|
570
|
-
mutation: Mutation
|
|
571
|
-
}
|
|
572
|
-
`);
|
|
573
|
-
logger.info(` GraphQL types ====> ${logText(schemaPath)}
|
|
574
|
-
`);
|
|
575
|
-
next();
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// src/cmds/audit/index.ts
|
|
579
|
-
var import_graphql9 = __toModule(require("@tinacms/graphql"));
|
|
580
|
-
var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
|
|
581
|
-
|
|
582
313
|
// src/cmds/audit/audit.ts
|
|
583
|
-
var
|
|
584
|
-
var
|
|
585
|
-
var import_graphql8 = __toModule(require("@tinacms/graphql"));
|
|
586
|
-
var import_chalk2 = __toModule(require("chalk"));
|
|
314
|
+
var import_graphql2 = __toModule(require("@tinacms/graphql"));
|
|
315
|
+
var import_chalk = __toModule(require("chalk"));
|
|
587
316
|
var auditCollection = async (args) => {
|
|
588
317
|
let warning = false;
|
|
589
318
|
const { collection, database, rootPath: rootPath2 } = args;
|
|
@@ -606,7 +335,7 @@ var auditCollection = async (args) => {
|
|
|
606
335
|
}
|
|
607
336
|
}
|
|
608
337
|
`;
|
|
609
|
-
const result = await (0,
|
|
338
|
+
const result = await (0, import_graphql.resolve)({
|
|
610
339
|
database,
|
|
611
340
|
query,
|
|
612
341
|
variables: {}
|
|
@@ -617,9 +346,9 @@ var auditCollection = async (args) => {
|
|
|
617
346
|
const node = x.node;
|
|
618
347
|
if (node._sys.extension.replace(".", "") !== format) {
|
|
619
348
|
warning = true;
|
|
620
|
-
logger.warn(
|
|
349
|
+
logger.warn(import_chalk.default.yellowBright(`WARNING: there is a file with extension \`${node._sys.extension}\` but in your schema it is defined to be \`.${format}\`
|
|
621
350
|
|
|
622
|
-
location: ${
|
|
351
|
+
location: ${import_path.default.join(rootPath2, node._sys.path)}`));
|
|
623
352
|
}
|
|
624
353
|
});
|
|
625
354
|
return warning;
|
|
@@ -646,7 +375,7 @@ var auditDocuments = async (args) => {
|
|
|
646
375
|
}
|
|
647
376
|
}
|
|
648
377
|
`;
|
|
649
|
-
const result = await (0,
|
|
378
|
+
const result = await (0, import_graphql.resolve)({
|
|
650
379
|
database,
|
|
651
380
|
query,
|
|
652
381
|
variables: {}
|
|
@@ -655,7 +384,7 @@ var auditDocuments = async (args) => {
|
|
|
655
384
|
const documents = result.data.collection.documents.edges;
|
|
656
385
|
for (let i = 0; i < documents.length; i++) {
|
|
657
386
|
const node = documents[i].node;
|
|
658
|
-
const fullPath =
|
|
387
|
+
const fullPath = import_path.default.join(rootPath2, node._sys.path);
|
|
659
388
|
logger.info(`Checking document: ${fullPath}`);
|
|
660
389
|
const documentQuery = `query {
|
|
661
390
|
document(collection: "${collection.name}", relativePath: "${node._sys.relativePath}") {
|
|
@@ -665,7 +394,7 @@ var auditDocuments = async (args) => {
|
|
|
665
394
|
}
|
|
666
395
|
}
|
|
667
396
|
}`;
|
|
668
|
-
const docResult = await (0,
|
|
397
|
+
const docResult = await (0, import_graphql.resolve)({
|
|
669
398
|
database,
|
|
670
399
|
query: documentQuery,
|
|
671
400
|
variables: {}
|
|
@@ -690,7 +419,7 @@ var auditDocuments = async (args) => {
|
|
|
690
419
|
params: $params
|
|
691
420
|
){__typename}
|
|
692
421
|
}`;
|
|
693
|
-
const mutationRes = await (0,
|
|
422
|
+
const mutationRes = await (0, import_graphql.resolve)({
|
|
694
423
|
database,
|
|
695
424
|
query: mutation,
|
|
696
425
|
variables: {
|
|
@@ -704,7 +433,7 @@ var auditDocuments = async (args) => {
|
|
|
704
433
|
if (mutationRes.errors) {
|
|
705
434
|
mutationRes.errors.forEach((err) => {
|
|
706
435
|
error = true;
|
|
707
|
-
logger.error(
|
|
436
|
+
logger.error(import_chalk.default.red(err.message));
|
|
708
437
|
});
|
|
709
438
|
}
|
|
710
439
|
}
|
|
@@ -724,7 +453,7 @@ var transformParams = (data) => {
|
|
|
724
453
|
return data.map((item) => transformParams(item));
|
|
725
454
|
}
|
|
726
455
|
try {
|
|
727
|
-
(0,
|
|
456
|
+
(0, import_graphql2.assertShape)(data, (yup) => yup.object({ _template: yup.string().required() }));
|
|
728
457
|
const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
|
|
729
458
|
const nested = transformParams(rest);
|
|
730
459
|
return { [_template]: nested };
|
|
@@ -755,7 +484,7 @@ function filterObject(obj) {
|
|
|
755
484
|
}
|
|
756
485
|
|
|
757
486
|
// src/cmds/audit/index.ts
|
|
758
|
-
var
|
|
487
|
+
var import_chalk2 = __toModule(require("chalk"));
|
|
759
488
|
var import_prompts = __toModule(require("prompts"));
|
|
760
489
|
var import_metrics = __toModule(require("@tinacms/metrics"));
|
|
761
490
|
var rootPath = process.cwd();
|
|
@@ -769,7 +498,7 @@ var audit = async (ctx, next, options) => {
|
|
|
769
498
|
}
|
|
770
499
|
});
|
|
771
500
|
if (options.clean) {
|
|
772
|
-
logger.info(`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 ${
|
|
501
|
+
logger.info(`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 ${import_chalk2.default.bold("clean git tree")} so unwanted changes can be undone.
|
|
773
502
|
|
|
774
503
|
`);
|
|
775
504
|
const res = await (0, import_prompts.default)({
|
|
@@ -778,16 +507,14 @@ var audit = async (ctx, next, options) => {
|
|
|
778
507
|
message: `Do you want to continue?`
|
|
779
508
|
});
|
|
780
509
|
if (!res.useClean) {
|
|
781
|
-
logger.warn(
|
|
510
|
+
logger.warn(import_chalk2.default.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
782
511
|
process.exit(0);
|
|
783
512
|
}
|
|
784
513
|
}
|
|
785
514
|
if (options.useDefaultValues && !options.clean) {
|
|
786
|
-
logger.warn(
|
|
515
|
+
logger.warn(import_chalk2.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
|
|
787
516
|
}
|
|
788
|
-
const
|
|
789
|
-
const store = options.clean ? new import_datalayer2.FilesystemStore({ rootPath }) : new import_datalayer2.AuditFilesystemStore({ rootPath });
|
|
790
|
-
const database = await (0, import_graphql9.createDatabase)({ store, bridge });
|
|
517
|
+
const database = ctx.database;
|
|
791
518
|
const schema = await database.getSchema();
|
|
792
519
|
const collections = schema.getCollections();
|
|
793
520
|
let warning = false;
|
|
@@ -815,17 +542,17 @@ var audit = async (ctx, next, options) => {
|
|
|
815
542
|
};
|
|
816
543
|
var printFinalMessage = async (ctx, next, _options) => {
|
|
817
544
|
if (ctx.error) {
|
|
818
|
-
logger.error(
|
|
545
|
+
logger.error(import_chalk2.default.redBright(`\u203C\uFE0F Audit ${import_chalk2.default.bold("failed")} with errors`));
|
|
819
546
|
} else if (ctx.warning) {
|
|
820
|
-
logger.warn(
|
|
547
|
+
logger.warn(import_chalk2.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
|
|
821
548
|
} else {
|
|
822
|
-
logger.info(
|
|
549
|
+
logger.info(import_chalk2.default.greenBright("\u2705 Audit passed"));
|
|
823
550
|
}
|
|
824
551
|
next();
|
|
825
552
|
};
|
|
826
553
|
|
|
827
554
|
// src/cmds/init/setup-files/index.ts
|
|
828
|
-
var
|
|
555
|
+
var import_chalk3 = __toModule(require("chalk"));
|
|
829
556
|
var adminPage = `import { TinaAdmin } from 'tinacms';
|
|
830
557
|
export default TinaAdmin;
|
|
831
558
|
`;
|
|
@@ -857,65 +584,58 @@ mille rigidi sub taurum.
|
|
|
857
584
|
|
|
858
585
|
|
|
859
586
|
`;
|
|
860
|
-
var nextPostPage = (
|
|
587
|
+
var nextPostPage = ({
|
|
588
|
+
usingSrc
|
|
589
|
+
}) => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
|
|
861
590
|
// This is a demo file once you have tina setup feel free to delete this file
|
|
862
|
-
|
|
863
|
-
import
|
|
864
|
-
import
|
|
865
|
-
import {
|
|
866
|
-
import { useTina } from "tinacms/dist/edit-state";
|
|
591
|
+
|
|
592
|
+
import Head from 'next/head'
|
|
593
|
+
import { createGlobalStyle } from 'styled-components'
|
|
594
|
+
import { useTina } from 'tinacms/dist/edit-state'
|
|
867
595
|
import { TinaMarkdown } from 'tinacms/dist/rich-text'
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
query BlogPostQuery($relativePath: String!) {
|
|
871
|
-
posts(relativePath: $relativePath) {
|
|
872
|
-
title
|
|
873
|
-
body
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
\`
|
|
877
|
-
|
|
596
|
+
import client from '${usingSrc ? "../" : ""}../../../.tina/__generated__/client'
|
|
597
|
+
|
|
878
598
|
// Styles for markdown
|
|
879
599
|
const GlobalStyle = createGlobalStyle\`
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
600
|
+
h1,h2,h3,h4,h5 {
|
|
601
|
+
margin-bottom: 1.5rem;
|
|
602
|
+
margin-top: 1.5rem;
|
|
603
|
+
}
|
|
604
|
+
blockquote {
|
|
605
|
+
background-color: rgb(209,250,229);
|
|
606
|
+
}
|
|
607
|
+
h1 {
|
|
608
|
+
font-size: 45px;
|
|
609
|
+
}
|
|
610
|
+
h2 {
|
|
611
|
+
font-size: 35px;
|
|
612
|
+
}
|
|
613
|
+
h3 {
|
|
614
|
+
font-size: 25px;
|
|
615
|
+
}
|
|
616
|
+
h4 {
|
|
617
|
+
font-size: 22px;
|
|
618
|
+
}
|
|
619
|
+
ul {
|
|
620
|
+
padding-left: 0;
|
|
621
|
+
}
|
|
622
|
+
li {
|
|
623
|
+
list-style-type: none;
|
|
624
|
+
}
|
|
625
|
+
a {
|
|
626
|
+
font-weight: bold;
|
|
627
|
+
color: rgb(59,130,246);
|
|
628
|
+
text-decoration: underline;
|
|
629
|
+
}
|
|
630
|
+
\`
|
|
631
|
+
|
|
912
632
|
const BlogPage = (props) => {
|
|
913
633
|
const { data } = useTina({
|
|
914
|
-
query,
|
|
634
|
+
query: props.query,
|
|
915
635
|
variables: props.variables,
|
|
916
636
|
data: props.data,
|
|
917
|
-
})
|
|
918
|
-
|
|
637
|
+
})
|
|
638
|
+
|
|
919
639
|
return (
|
|
920
640
|
<>
|
|
921
641
|
<Head>
|
|
@@ -931,15 +651,13 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
|
|
|
931
651
|
<div>
|
|
932
652
|
<div
|
|
933
653
|
style={{
|
|
934
|
-
textAlign:
|
|
654
|
+
textAlign: 'center',
|
|
935
655
|
}}
|
|
936
656
|
>
|
|
937
657
|
<h1 className="text-3xl m-8 text-center leading-8 font-extrabold tracking-tight text-gray-900 sm:text-4xl">
|
|
938
|
-
{data.
|
|
658
|
+
{data.post.title}
|
|
939
659
|
</h1>
|
|
940
|
-
<ContentSection
|
|
941
|
-
content={data.posts.body}
|
|
942
|
-
></ContentSection>
|
|
660
|
+
<ContentSection content={data.post.body}></ContentSection>
|
|
943
661
|
</div>
|
|
944
662
|
<div className="bg-green-100 text-center">
|
|
945
663
|
Lost and looking for a place to start?
|
|
@@ -947,79 +665,65 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
|
|
|
947
665
|
href="https://tina.io/guides/tina-cloud/getting-started/overview/"
|
|
948
666
|
className="text-blue-500 underline"
|
|
949
667
|
>
|
|
950
|
-
{
|
|
668
|
+
{' '}
|
|
951
669
|
Check out this guide
|
|
952
|
-
</a>{
|
|
670
|
+
</a>{' '}
|
|
953
671
|
to see how add TinaCMS to an existing Next.js site.
|
|
954
672
|
</div>
|
|
955
673
|
</div>
|
|
956
674
|
</>
|
|
957
|
-
)
|
|
958
|
-
}
|
|
959
|
-
|
|
675
|
+
)
|
|
676
|
+
}
|
|
677
|
+
|
|
960
678
|
export const getStaticProps = async ({ params }) => {
|
|
961
|
-
const variables = { relativePath: \`\${params.filename}.md\` }
|
|
962
679
|
let data = {}
|
|
680
|
+
let query = {}
|
|
681
|
+
let variables = { relativePath: \`\${params.filename}.mdx\` }
|
|
963
682
|
try {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
683
|
+
const res = await client.queries.post(variables)
|
|
684
|
+
query = res.query
|
|
685
|
+
data = res.data
|
|
686
|
+
variables = res.variables
|
|
968
687
|
} catch {
|
|
969
688
|
// swallow errors related to document creation
|
|
970
689
|
}
|
|
971
|
-
|
|
690
|
+
|
|
972
691
|
return {
|
|
973
692
|
props: {
|
|
974
|
-
variables,
|
|
975
|
-
data,
|
|
693
|
+
variables: variables,
|
|
694
|
+
data: data,
|
|
695
|
+
query: query,
|
|
976
696
|
//myOtherProp: 'some-other-data',
|
|
977
697
|
},
|
|
978
698
|
}
|
|
979
|
-
}
|
|
980
|
-
|
|
699
|
+
}
|
|
700
|
+
|
|
981
701
|
export const getStaticPaths = async () => {
|
|
982
|
-
const postsListData =
|
|
983
|
-
|
|
984
|
-
query GetPostsList {
|
|
985
|
-
postsConnection {
|
|
986
|
-
edges {
|
|
987
|
-
node {
|
|
988
|
-
...on Document {
|
|
989
|
-
_sys {
|
|
990
|
-
filename
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
\`,
|
|
998
|
-
}));
|
|
999
|
-
|
|
702
|
+
const postsListData = await client.queries.postConnection()
|
|
703
|
+
|
|
1000
704
|
return {
|
|
1001
|
-
paths: postsListData.
|
|
705
|
+
paths: postsListData.data.postConnection.edges.map((post) => ({
|
|
1002
706
|
params: { filename: post.node._sys.filename },
|
|
1003
707
|
})),
|
|
1004
708
|
fallback: false,
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
export default BlogPage
|
|
1009
|
-
|
|
1010
|
-
const PageSection = props => {
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
export default BlogPage
|
|
713
|
+
|
|
714
|
+
const PageSection = (props) => {
|
|
1011
715
|
return (
|
|
1012
716
|
<>
|
|
1013
|
-
<h2>{
|
|
1014
|
-
<p>{
|
|
717
|
+
<h2>{props.heading}</h2>
|
|
718
|
+
<p>{props.content}</p>
|
|
1015
719
|
</>
|
|
1016
720
|
)
|
|
1017
721
|
}
|
|
1018
|
-
|
|
722
|
+
|
|
1019
723
|
const components = {
|
|
1020
724
|
PageSection: PageSection,
|
|
1021
725
|
}
|
|
1022
|
-
|
|
726
|
+
|
|
1023
727
|
const ContentSection = ({ content }) => {
|
|
1024
728
|
return (
|
|
1025
729
|
<div className="relative py-16 bg-white overflow-hidden">
|
|
@@ -1128,15 +832,13 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
|
|
|
1128
832
|
</div>
|
|
1129
833
|
<div className="relative px-4 sm:px-6 lg:px-8">
|
|
1130
834
|
<div className="text-lg max-w-prose mx-auto">
|
|
1131
|
-
<TinaMarkdown components={components} content={content}/>
|
|
835
|
+
<TinaMarkdown components={components} content={content} />
|
|
1132
836
|
<GlobalStyle />
|
|
1133
837
|
</div>
|
|
1134
838
|
</div>
|
|
1135
839
|
</div>
|
|
1136
|
-
)
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
`;
|
|
840
|
+
)
|
|
841
|
+
}`;
|
|
1140
842
|
var AppJsContent = (usingSrc, extraImports) => {
|
|
1141
843
|
const importLine = `import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`;
|
|
1142
844
|
return `${importLine}
|
|
@@ -1154,15 +856,15 @@ export default App
|
|
|
1154
856
|
`;
|
|
1155
857
|
};
|
|
1156
858
|
var AppJsContentPrintout = (usingSrc, extraImports) => {
|
|
1157
|
-
const importLine =
|
|
859
|
+
const importLine = import_chalk3.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
|
|
1158
860
|
return `${importLine}
|
|
1159
861
|
${extraImports || ""}
|
|
1160
862
|
|
|
1161
863
|
const App = ({ Component, pageProps }) => {
|
|
1162
864
|
return (
|
|
1163
|
-
${
|
|
865
|
+
${import_chalk3.default.green("+ <Tina>")}
|
|
1164
866
|
<Component {...pageProps} />
|
|
1165
|
-
${
|
|
867
|
+
${import_chalk3.default.green("+ </Tina>")}
|
|
1166
868
|
)
|
|
1167
869
|
}
|
|
1168
870
|
|
|
@@ -1203,24 +905,35 @@ const DynamicTina = ({ children }) => {
|
|
|
1203
905
|
export default DynamicTina
|
|
1204
906
|
`;
|
|
1205
907
|
|
|
908
|
+
// src/utils/theme.ts
|
|
909
|
+
var import_chalk4 = __toModule(require("chalk"));
|
|
910
|
+
var successText = import_chalk4.default.bold.green;
|
|
911
|
+
var dangerText = import_chalk4.default.bold.red;
|
|
912
|
+
var neutralText = import_chalk4.default.bold.cyan;
|
|
913
|
+
var labelText = import_chalk4.default.bold;
|
|
914
|
+
var cmdText = import_chalk4.default.inverse;
|
|
915
|
+
var logText = import_chalk4.default.italic.gray;
|
|
916
|
+
var warnText = import_chalk4.default.yellowBright.bgBlack;
|
|
917
|
+
var CONFIRMATION_TEXT = import_chalk4.default.dim("enter to confirm");
|
|
918
|
+
|
|
1206
919
|
// src/utils/script-helpers.ts
|
|
1207
920
|
function generateGqlScript(scriptValue) {
|
|
1208
|
-
return `tinacms
|
|
921
|
+
return `tinacms dev -c "${scriptValue}"`;
|
|
1209
922
|
}
|
|
1210
923
|
function extendNextScripts(scripts) {
|
|
1211
924
|
return __spreadProps(__spreadValues({}, scripts), {
|
|
1212
|
-
dev: generateGqlScript(scripts.dev || "next dev"),
|
|
1213
|
-
build:
|
|
1214
|
-
start:
|
|
925
|
+
dev: generateGqlScript((scripts == null ? void 0 : scripts.dev) || "next dev"),
|
|
926
|
+
build: `tinacms build && ${(scripts == null ? void 0 : scripts.build) || "next build"}`,
|
|
927
|
+
start: `tinacms build && ${(scripts == null ? void 0 : scripts.start) || "next start"}`
|
|
1215
928
|
});
|
|
1216
929
|
}
|
|
1217
930
|
|
|
1218
931
|
// src/cmds/init/index.ts
|
|
1219
|
-
var
|
|
932
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
1220
933
|
var import_progress = __toModule(require("progress"));
|
|
1221
934
|
var import_metrics2 = __toModule(require("@tinacms/metrics"));
|
|
1222
935
|
var import_chalk5 = __toModule(require("chalk"));
|
|
1223
|
-
var
|
|
936
|
+
var import_path2 = __toModule(require("path"));
|
|
1224
937
|
var import_prompts2 = __toModule(require("prompts"));
|
|
1225
938
|
function execShellCommand(cmd) {
|
|
1226
939
|
const exec = require("child_process").exec;
|
|
@@ -1247,7 +960,10 @@ async function initTina(ctx, next, options) {
|
|
|
1247
960
|
var MIN_REACT_VERSION = ">=16.14.0";
|
|
1248
961
|
async function checkDeps(ctx, next, options) {
|
|
1249
962
|
const bar = new import_progress.default("Checking dependencies. :prog", 1);
|
|
1250
|
-
|
|
963
|
+
if (!import_fs_extra.default.existsSync(packageJSONPath)) {
|
|
964
|
+
throw new Error("No package.json Found. Please run tinacms init at the root of your app");
|
|
965
|
+
}
|
|
966
|
+
const packageJSON = JSON.parse((await import_fs_extra.default.readFileSync(packageJSONPath)).toString());
|
|
1251
967
|
if (!checkPackage(packageJSON, "react") || !checkPackage(packageJSON, "react-dom")) {
|
|
1252
968
|
const message = `Unable to initialize Tina due to outdated dependencies, try upgrading the following packages:
|
|
1253
969
|
"react@${MIN_REACT_VERSION}"
|
|
@@ -1269,6 +985,9 @@ var checkPackage = (packageJSON, packageName) => {
|
|
|
1269
985
|
strippedVersion = version2.replace(/^[^a-zA-Z0-9]*|[^a-zA-Z0-9]*$/g, "");
|
|
1270
986
|
}
|
|
1271
987
|
});
|
|
988
|
+
if (!strippedVersion) {
|
|
989
|
+
throw new Error(`Please add ${packageName} to your project`);
|
|
990
|
+
}
|
|
1272
991
|
return checkVersion(strippedVersion);
|
|
1273
992
|
};
|
|
1274
993
|
var checkVersion = (version2) => {
|
|
@@ -1313,33 +1032,33 @@ async function installDeps(ctx, next, options) {
|
|
|
1313
1032
|
next();
|
|
1314
1033
|
}
|
|
1315
1034
|
var baseDir = process.cwd();
|
|
1316
|
-
var packageJSONPath =
|
|
1317
|
-
var blogContentPath =
|
|
1318
|
-
var blogPostPath =
|
|
1319
|
-
var TinaFolder =
|
|
1320
|
-
var componentFolder =
|
|
1321
|
-
var TinaProviderPath =
|
|
1322
|
-
var TinaDynamicProvider =
|
|
1035
|
+
var packageJSONPath = import_path2.default.join(baseDir, "package.json");
|
|
1036
|
+
var blogContentPath = import_path2.default.join(baseDir, "content", "posts");
|
|
1037
|
+
var blogPostPath = import_path2.default.join(blogContentPath, "HelloWorld.mdx");
|
|
1038
|
+
var TinaFolder = import_path2.default.join(baseDir, ".tina");
|
|
1039
|
+
var componentFolder = import_path2.default.join(TinaFolder, "components");
|
|
1040
|
+
var TinaProviderPath = import_path2.default.join(componentFolder, "TinaProvider.js");
|
|
1041
|
+
var TinaDynamicProvider = import_path2.default.join(componentFolder, "TinaDynamicProvider.js");
|
|
1323
1042
|
async function tinaSetup(_ctx, next, _options) {
|
|
1324
|
-
const usingSrc = !
|
|
1325
|
-
if (!
|
|
1043
|
+
const usingSrc = !import_fs_extra.default.pathExistsSync(import_path2.default.join(baseDir, "pages"));
|
|
1044
|
+
if (!import_fs_extra.default.pathExistsSync(blogPostPath)) {
|
|
1326
1045
|
logger.info(logText("Adding a content folder..."));
|
|
1327
|
-
|
|
1328
|
-
|
|
1046
|
+
import_fs_extra.default.mkdirpSync(blogContentPath);
|
|
1047
|
+
import_fs_extra.default.writeFileSync(blogPostPath, blogPost);
|
|
1329
1048
|
}
|
|
1330
|
-
if (!
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1049
|
+
if (!import_fs_extra.default.existsSync(TinaProviderPath) && !import_fs_extra.default.existsSync(TinaDynamicProvider)) {
|
|
1050
|
+
import_fs_extra.default.mkdirpSync(componentFolder);
|
|
1051
|
+
import_fs_extra.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.schemaFileType || "ts"}'`));
|
|
1052
|
+
import_fs_extra.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
|
|
1334
1053
|
}
|
|
1335
1054
|
logger.level = "info";
|
|
1336
|
-
const pagesPath =
|
|
1337
|
-
const appPath =
|
|
1338
|
-
const appPathTS =
|
|
1339
|
-
const appExtension =
|
|
1340
|
-
if (!
|
|
1055
|
+
const pagesPath = import_path2.default.join(baseDir, usingSrc ? "src" : "", "pages");
|
|
1056
|
+
const appPath = import_path2.default.join(pagesPath, "_app.js");
|
|
1057
|
+
const appPathTS = import_path2.default.join(pagesPath, "_app.tsx");
|
|
1058
|
+
const appExtension = import_fs_extra.default.existsSync(appPath) ? ".js" : ".tsx";
|
|
1059
|
+
if (!import_fs_extra.default.pathExistsSync(appPath) && !import_fs_extra.default.pathExistsSync(appPathTS)) {
|
|
1341
1060
|
logger.info(logText("Adding _app.js ... \u2705"));
|
|
1342
|
-
|
|
1061
|
+
import_fs_extra.default.writeFileSync(appPath, AppJsContent(usingSrc));
|
|
1343
1062
|
} else {
|
|
1344
1063
|
const override = await (0, import_prompts2.default)({
|
|
1345
1064
|
name: "res",
|
|
@@ -1349,40 +1068,43 @@ async function tinaSetup(_ctx, next, _options) {
|
|
|
1349
1068
|
_ctx.overrideApp = override.res;
|
|
1350
1069
|
if (override.res) {
|
|
1351
1070
|
logger.info(logText(`Adding _app${appExtension} ... \u2705`));
|
|
1352
|
-
const appPathWithExtension =
|
|
1353
|
-
const fileContent =
|
|
1071
|
+
const appPathWithExtension = import_path2.default.join(pagesPath, `_app${appExtension}`);
|
|
1072
|
+
const fileContent = import_fs_extra.default.pathExistsSync(appPath) ? (0, import_fs_extra.readFileSync)(appPath) : (0, import_fs_extra.readFileSync)(appPathTS);
|
|
1354
1073
|
const matches = [
|
|
1355
1074
|
...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
|
|
1356
1075
|
];
|
|
1357
1076
|
const primaryMatches = matches.map((x) => x[0]);
|
|
1358
|
-
|
|
1077
|
+
import_fs_extra.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
|
|
1359
1078
|
}
|
|
1360
1079
|
}
|
|
1361
|
-
const tinaBlogPagePath =
|
|
1362
|
-
const tinaBlogPagePathFile =
|
|
1363
|
-
if (!
|
|
1364
|
-
|
|
1365
|
-
|
|
1080
|
+
const tinaBlogPagePath = import_path2.default.join(pagesPath, "demo", "blog");
|
|
1081
|
+
const tinaBlogPagePathFile = import_path2.default.join(tinaBlogPagePath, "[filename].js");
|
|
1082
|
+
if (!import_fs_extra.default.pathExistsSync(tinaBlogPagePathFile)) {
|
|
1083
|
+
import_fs_extra.default.mkdirpSync(tinaBlogPagePath);
|
|
1084
|
+
import_fs_extra.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
|
|
1366
1085
|
}
|
|
1367
1086
|
logger.info("Adding a content folder... \u2705");
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
scripts
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1087
|
+
if (!import_fs_extra.default.existsSync(packageJSONPath)) {
|
|
1088
|
+
throw new Error("No package.json Found. Please run tinacms init at the root of your app");
|
|
1089
|
+
} else {
|
|
1090
|
+
const pack = JSON.parse((0, import_fs_extra.readFileSync)(packageJSONPath).toString());
|
|
1091
|
+
const oldScripts = pack.scripts || {};
|
|
1092
|
+
const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
|
|
1093
|
+
scripts: extendNextScripts(oldScripts)
|
|
1094
|
+
}), null, 2);
|
|
1095
|
+
(0, import_fs_extra.writeFileSync)(packageJSONPath, newPack);
|
|
1096
|
+
}
|
|
1097
|
+
const adminPath = import_path2.default.join(pagesPath, "admin.js");
|
|
1098
|
+
if (import_fs_extra.default.pathExistsSync(import_path2.default.join(pagesPath, "admin"))) {
|
|
1377
1099
|
logger.warn(`Unable to add /pages/admin.js, this path already exists.
|
|
1378
1100
|
Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
|
|
1379
1101
|
return next();
|
|
1380
1102
|
}
|
|
1381
|
-
(0,
|
|
1103
|
+
(0, import_fs_extra.outputFileSync)(adminPath, adminPage);
|
|
1382
1104
|
next();
|
|
1383
1105
|
}
|
|
1384
1106
|
async function successMessage(ctx, next, options) {
|
|
1385
|
-
const usingSrc =
|
|
1107
|
+
const usingSrc = import_fs_extra.default.pathExistsSync(import_path2.default.join(baseDir, "src"));
|
|
1386
1108
|
logger.info(`Tina setup ${import_chalk5.default.underline.green("done")} \u2705
|
|
1387
1109
|
`);
|
|
1388
1110
|
logger.info("Next Steps: \n");
|
|
@@ -1430,8 +1152,11 @@ var chain = async (cmds, options) => {
|
|
|
1430
1152
|
// src/cmds/baseCmds.ts
|
|
1431
1153
|
var import_chalk7 = __toModule(require("chalk"));
|
|
1432
1154
|
|
|
1155
|
+
// src/cmds/compile/index.ts
|
|
1156
|
+
var _ = __toModule(require("lodash"));
|
|
1157
|
+
|
|
1433
1158
|
// src/cmds/start-server/errors/index.ts
|
|
1434
|
-
var
|
|
1159
|
+
var import_graphql3 = __toModule(require("@tinacms/graphql"));
|
|
1435
1160
|
var BuildSchemaError = class extends Error {
|
|
1436
1161
|
constructor(message) {
|
|
1437
1162
|
super(message);
|
|
@@ -1457,8 +1182,8 @@ var handleServerErrors = (e) => {
|
|
|
1457
1182
|
logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
|
|
1458
1183
|
Error Message Below
|
|
1459
1184
|
${e}`);
|
|
1460
|
-
} else if (e instanceof
|
|
1461
|
-
(0,
|
|
1185
|
+
} else if (e instanceof import_graphql3.TinaFetchError) {
|
|
1186
|
+
(0, import_graphql3.handleFetchErrorError)(e, true);
|
|
1462
1187
|
} else {
|
|
1463
1188
|
logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
|
|
1464
1189
|
${e.message}`);
|
|
@@ -1466,72 +1191,78 @@ var handleServerErrors = (e) => {
|
|
|
1466
1191
|
};
|
|
1467
1192
|
|
|
1468
1193
|
// src/cmds/compile/index.ts
|
|
1469
|
-
var
|
|
1470
|
-
var
|
|
1194
|
+
var import_fs_extra3 = __toModule(require("fs-extra"));
|
|
1195
|
+
var import_path4 = __toModule(require("path"));
|
|
1471
1196
|
var import_esbuild = __toModule(require("esbuild"));
|
|
1472
1197
|
|
|
1473
1198
|
// src/cmds/compile/defaultSchema.ts
|
|
1474
1199
|
var defaultSchema = `
|
|
1475
|
-
import { defineSchema, defineConfig } from
|
|
1200
|
+
import { defineSchema, defineConfig } from 'tinacms'
|
|
1201
|
+
import { client } from './__generated__/client'
|
|
1202
|
+
|
|
1476
1203
|
|
|
1204
|
+
const branch =
|
|
1205
|
+
process.env.NEXT_PUBLIC_TINA_BRANCH ||
|
|
1206
|
+
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||
|
|
1207
|
+
process.env.HEAD ||
|
|
1208
|
+
'main'
|
|
1477
1209
|
const schema = defineSchema({
|
|
1210
|
+
// See https://tina.io/docs/tina-cloud/connecting-site/ for more information about this config
|
|
1211
|
+
config: {
|
|
1212
|
+
token: '<Your Read Only Token>', // generated on app.tina.io,
|
|
1213
|
+
clientId: '<Your Client ID>', // generated on app.tina.io
|
|
1214
|
+
branch,
|
|
1215
|
+
},
|
|
1478
1216
|
collections: [
|
|
1479
1217
|
{
|
|
1480
|
-
label:
|
|
1481
|
-
name:
|
|
1482
|
-
path:
|
|
1218
|
+
label: 'Blog Posts',
|
|
1219
|
+
name: 'post',
|
|
1220
|
+
path: 'content/posts',
|
|
1221
|
+
format: 'mdx',
|
|
1483
1222
|
fields: [
|
|
1484
1223
|
{
|
|
1485
|
-
type:
|
|
1486
|
-
label:
|
|
1487
|
-
name:
|
|
1224
|
+
type: 'string',
|
|
1225
|
+
label: 'Title',
|
|
1226
|
+
name: 'title',
|
|
1488
1227
|
},
|
|
1489
1228
|
{
|
|
1490
|
-
type:
|
|
1491
|
-
label:
|
|
1492
|
-
name:
|
|
1229
|
+
type: 'rich-text',
|
|
1230
|
+
label: 'Blog Post Body',
|
|
1231
|
+
name: 'body',
|
|
1493
1232
|
isBody: true,
|
|
1494
1233
|
templates: [
|
|
1495
1234
|
{
|
|
1496
|
-
name:
|
|
1497
|
-
label:
|
|
1235
|
+
name: 'PageSection',
|
|
1236
|
+
label: 'Page Section',
|
|
1498
1237
|
fields: [
|
|
1499
1238
|
{
|
|
1500
|
-
type:
|
|
1501
|
-
name:
|
|
1502
|
-
label:
|
|
1239
|
+
type: 'string',
|
|
1240
|
+
name: 'heading',
|
|
1241
|
+
label: 'Heading',
|
|
1503
1242
|
},
|
|
1504
1243
|
{
|
|
1505
|
-
type:
|
|
1506
|
-
name:
|
|
1507
|
-
label:
|
|
1244
|
+
type: 'string',
|
|
1245
|
+
name: 'content',
|
|
1246
|
+
label: 'Content',
|
|
1508
1247
|
ui: {
|
|
1509
|
-
component:
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1248
|
+
component: 'textarea',
|
|
1249
|
+
},
|
|
1250
|
+
},
|
|
1512
1251
|
],
|
|
1513
1252
|
},
|
|
1514
|
-
]
|
|
1253
|
+
],
|
|
1515
1254
|
},
|
|
1516
1255
|
],
|
|
1517
1256
|
},
|
|
1518
1257
|
],
|
|
1519
|
-
})
|
|
1258
|
+
})
|
|
1520
1259
|
|
|
1521
1260
|
export default schema
|
|
1522
1261
|
|
|
1523
1262
|
// Your tina config
|
|
1524
|
-
// ==============
|
|
1525
|
-
const branch = 'main'
|
|
1526
|
-
// When working locally, hit our local filesystem.
|
|
1527
|
-
// On a Vercel deployment, hit the Tina Cloud API
|
|
1528
|
-
const apiURL =
|
|
1529
|
-
process.env.NODE_ENV == 'development'
|
|
1530
|
-
? 'http://localhost:4001/graphql'
|
|
1531
|
-
: \`https://content.tinajs.io/content/\${process.env.NEXT_PUBLIC_TINA_CLIENT_ID}/github/\${branch}\`
|
|
1532
1263
|
|
|
1533
1264
|
export const tinaConfig = defineConfig({
|
|
1534
|
-
|
|
1265
|
+
client,
|
|
1535
1266
|
schema,
|
|
1536
1267
|
cmsCallback: (cms) => {
|
|
1537
1268
|
// add your CMS callback code here (if you want)
|
|
@@ -1540,41 +1271,42 @@ export const tinaConfig = defineConfig({
|
|
|
1540
1271
|
/**
|
|
1541
1272
|
* 1. Import \`tinacms\` and \`RouteMappingPlugin\`
|
|
1542
1273
|
**/
|
|
1543
|
-
import(
|
|
1274
|
+
import('tinacms').then(({ RouteMappingPlugin }) => {
|
|
1544
1275
|
/**
|
|
1545
1276
|
* 2. Define the \`RouteMappingPlugin\` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details
|
|
1546
1277
|
**/
|
|
1547
1278
|
const RouteMapping = new RouteMappingPlugin((collection, document) => {
|
|
1548
|
-
return undefined
|
|
1549
|
-
})
|
|
1279
|
+
return undefined
|
|
1280
|
+
})
|
|
1550
1281
|
/**
|
|
1551
1282
|
* 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
|
|
1552
1283
|
**/
|
|
1553
|
-
cms.plugins.add(RouteMapping)
|
|
1554
|
-
})
|
|
1284
|
+
cms.plugins.add(RouteMapping)
|
|
1285
|
+
})
|
|
1555
1286
|
|
|
1556
|
-
return cms
|
|
1287
|
+
return cms
|
|
1557
1288
|
},
|
|
1558
|
-
})
|
|
1289
|
+
})
|
|
1290
|
+
|
|
1559
1291
|
`;
|
|
1560
1292
|
|
|
1561
1293
|
// src/lib/getPath.ts
|
|
1562
|
-
var
|
|
1563
|
-
var
|
|
1294
|
+
var import_path3 = __toModule(require("path"));
|
|
1295
|
+
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
1564
1296
|
var getPath = ({
|
|
1565
1297
|
projectDir,
|
|
1566
1298
|
filename,
|
|
1567
1299
|
allowedTypes,
|
|
1568
1300
|
errorMessage
|
|
1569
1301
|
}) => {
|
|
1570
|
-
if (!
|
|
1302
|
+
if (!import_fs_extra2.default.existsSync(projectDir)) {
|
|
1571
1303
|
throw new Error(errorMessage);
|
|
1572
1304
|
}
|
|
1573
|
-
const filePaths = allowedTypes.map((ext) =>
|
|
1305
|
+
const filePaths = allowedTypes.map((ext) => import_path3.default.join(projectDir, `${filename}.${ext}`));
|
|
1574
1306
|
let inputFile = void 0;
|
|
1575
|
-
filePaths.every((
|
|
1576
|
-
if (
|
|
1577
|
-
inputFile =
|
|
1307
|
+
filePaths.every((path7) => {
|
|
1308
|
+
if (import_fs_extra2.default.existsSync(path7)) {
|
|
1309
|
+
inputFile = path7;
|
|
1578
1310
|
return false;
|
|
1579
1311
|
}
|
|
1580
1312
|
return true;
|
|
@@ -1584,12 +1316,6 @@ var getPath = ({
|
|
|
1584
1316
|
}
|
|
1585
1317
|
return inputFile;
|
|
1586
1318
|
};
|
|
1587
|
-
var getSchemaPath = ({ projectDir }) => {
|
|
1588
|
-
const filename = "schema";
|
|
1589
|
-
const allowedTypes = ["js", "jsx", "ts", "tsx"];
|
|
1590
|
-
const errorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
|
|
1591
|
-
return getPath({ projectDir, filename, allowedTypes, errorMessage });
|
|
1592
|
-
};
|
|
1593
1319
|
var getClientPath = ({ projectDir }) => {
|
|
1594
1320
|
const filename = "client";
|
|
1595
1321
|
const allowedTypes = ["js", "ts"];
|
|
@@ -1598,29 +1324,47 @@ var getClientPath = ({ projectDir }) => {
|
|
|
1598
1324
|
};
|
|
1599
1325
|
|
|
1600
1326
|
// src/cmds/compile/index.ts
|
|
1601
|
-
var
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
var resetGeneratedFolder = async () => {
|
|
1327
|
+
var resetGeneratedFolder = async ({
|
|
1328
|
+
tinaGeneratedPath,
|
|
1329
|
+
usingTs
|
|
1330
|
+
}) => {
|
|
1606
1331
|
try {
|
|
1607
|
-
await
|
|
1608
|
-
recursive: true
|
|
1609
|
-
});
|
|
1332
|
+
await import_fs_extra3.default.emptyDir(tinaGeneratedPath);
|
|
1610
1333
|
} catch (e) {
|
|
1611
1334
|
console.log(e);
|
|
1612
1335
|
}
|
|
1613
|
-
await
|
|
1614
|
-
|
|
1336
|
+
await import_fs_extra3.default.mkdirp(tinaGeneratedPath);
|
|
1337
|
+
const ext = usingTs ? "ts" : "js";
|
|
1338
|
+
await import_fs_extra3.default.writeFile(import_path4.default.join(tinaGeneratedPath, `types.${ext}`), `
|
|
1615
1339
|
export const queries = (client)=>({})
|
|
1616
1340
|
`);
|
|
1617
|
-
await
|
|
1341
|
+
await import_fs_extra3.default.writeFile(import_path4.default.join(tinaGeneratedPath, `client.${ext}`), `
|
|
1342
|
+
export const client = ()=>{}
|
|
1343
|
+
export default client
|
|
1344
|
+
`);
|
|
1345
|
+
await import_fs_extra3.default.outputFile(import_path4.default.join(tinaGeneratedPath, ".gitignore"), `db
|
|
1346
|
+
client.ts
|
|
1347
|
+
client.js
|
|
1348
|
+
types.ts
|
|
1349
|
+
types.js
|
|
1350
|
+
types.d.ts
|
|
1351
|
+
frags.gql
|
|
1352
|
+
queries.gql
|
|
1353
|
+
schema.gql
|
|
1354
|
+
`);
|
|
1618
1355
|
};
|
|
1619
1356
|
var cleanup = async ({ tinaTempPath }) => {
|
|
1620
|
-
await
|
|
1357
|
+
await import_fs_extra3.default.remove(tinaTempPath);
|
|
1621
1358
|
};
|
|
1622
1359
|
var compileClient = async (ctx, next, options) => {
|
|
1623
|
-
const
|
|
1360
|
+
const root2 = ctx.rootPath;
|
|
1361
|
+
if (!root2) {
|
|
1362
|
+
throw new Error("ctx.rootPath has not been attached");
|
|
1363
|
+
}
|
|
1364
|
+
const tinaPath = import_path4.default.join(root2, ".tina");
|
|
1365
|
+
const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
|
|
1366
|
+
const packageJSONFilePath = import_path4.default.join(root2, "package.json");
|
|
1367
|
+
const tinaTempPath = import_path4.default.join(tinaGeneratedPath, "temp_client");
|
|
1624
1368
|
if (!options.clientFileType)
|
|
1625
1369
|
options = __spreadProps(__spreadValues({}, options), { clientFileType: "ts" });
|
|
1626
1370
|
if (options.verbose) {
|
|
@@ -1635,8 +1379,9 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1635
1379
|
ctx.clientFileType = requestedClientFileType;
|
|
1636
1380
|
}
|
|
1637
1381
|
let clientExists = true;
|
|
1382
|
+
const projectDir = import_path4.default.join(tinaPath, "__generated__");
|
|
1638
1383
|
try {
|
|
1639
|
-
getClientPath({ projectDir
|
|
1384
|
+
getClientPath({ projectDir });
|
|
1640
1385
|
} catch {
|
|
1641
1386
|
clientExists = false;
|
|
1642
1387
|
}
|
|
@@ -1651,8 +1396,10 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1651
1396
|
if (!process.env.NODE_ENV) {
|
|
1652
1397
|
define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
|
|
1653
1398
|
}
|
|
1654
|
-
const inputFile = getClientPath({
|
|
1655
|
-
|
|
1399
|
+
const inputFile = getClientPath({
|
|
1400
|
+
projectDir
|
|
1401
|
+
});
|
|
1402
|
+
await transpile(inputFile, "client.js", tinaTempPath, options.verbose, define, packageJSONFilePath);
|
|
1656
1403
|
} catch (e) {
|
|
1657
1404
|
await cleanup({ tinaTempPath });
|
|
1658
1405
|
throw new BuildSchemaError(e);
|
|
@@ -1663,7 +1410,7 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1663
1410
|
}
|
|
1664
1411
|
});
|
|
1665
1412
|
try {
|
|
1666
|
-
const clientFunc = require(
|
|
1413
|
+
const clientFunc = require(import_path4.default.join(tinaTempPath, "client.js"));
|
|
1667
1414
|
const client = clientFunc.default;
|
|
1668
1415
|
ctx.client = client;
|
|
1669
1416
|
await cleanup({ tinaTempPath });
|
|
@@ -1678,43 +1425,63 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1678
1425
|
}
|
|
1679
1426
|
return next();
|
|
1680
1427
|
};
|
|
1681
|
-
var
|
|
1682
|
-
const
|
|
1683
|
-
if (!
|
|
1684
|
-
|
|
1428
|
+
var compileFile = async (ctx, _next, options, fileName) => {
|
|
1429
|
+
const root2 = ctx.rootPath;
|
|
1430
|
+
if (!root2) {
|
|
1431
|
+
throw new Error("ctx.rootPath has not been attached");
|
|
1432
|
+
}
|
|
1433
|
+
const tinaPath = import_path4.default.join(root2, ".tina");
|
|
1434
|
+
const tsConfigPath = import_path4.default.join(root2, "tsconfig.json");
|
|
1435
|
+
const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
|
|
1436
|
+
const tinaTempPath = import_path4.default.join(tinaGeneratedPath, `temp_${fileName}`);
|
|
1437
|
+
const packageJSONFilePath = import_path4.default.join(root2, "package.json");
|
|
1438
|
+
if (!options.schemaFileType) {
|
|
1439
|
+
const usingTs = await import_fs_extra3.default.pathExists(tsConfigPath);
|
|
1440
|
+
options = __spreadProps(__spreadValues({}, options), { schemaFileType: usingTs ? "ts" : "js" });
|
|
1441
|
+
}
|
|
1685
1442
|
if (options.verbose) {
|
|
1686
|
-
logger.info(logText(
|
|
1443
|
+
logger.info(logText(`Compiling ${fileName}...`));
|
|
1687
1444
|
}
|
|
1688
1445
|
const { schemaFileType: requestedSchemaFileType = "ts" } = options;
|
|
1689
1446
|
const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
|
|
1690
1447
|
if (!schemaFileType2) {
|
|
1691
1448
|
throw new Error(`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`);
|
|
1692
1449
|
}
|
|
1693
|
-
if (
|
|
1694
|
-
|
|
1450
|
+
if (ctx) {
|
|
1451
|
+
ctx.schemaFileType = schemaFileType2;
|
|
1695
1452
|
}
|
|
1696
1453
|
let schemaExists = true;
|
|
1697
1454
|
try {
|
|
1698
|
-
|
|
1455
|
+
getPath({
|
|
1456
|
+
projectDir: tinaPath,
|
|
1457
|
+
filename: fileName,
|
|
1458
|
+
allowedTypes: ["js", "jsx", "tsx", "ts"],
|
|
1459
|
+
errorMessage: `Must provide a ${fileName}.{js,jsx,tsx,ts}`
|
|
1460
|
+
});
|
|
1699
1461
|
} catch {
|
|
1700
1462
|
schemaExists = false;
|
|
1701
1463
|
}
|
|
1702
|
-
if (!schemaExists) {
|
|
1464
|
+
if (!schemaExists && fileName === "schema") {
|
|
1703
1465
|
logger.info(dangerText(`
|
|
1704
1466
|
.tina/schema.${schemaFileType2} not found, Creating one for you...
|
|
1705
1467
|
See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
|
|
1706
1468
|
`));
|
|
1707
|
-
const file =
|
|
1708
|
-
await
|
|
1709
|
-
await
|
|
1469
|
+
const file = import_path4.default.join(tinaPath, `schema.${schemaFileType2}`);
|
|
1470
|
+
await import_fs_extra3.default.ensureFile(file);
|
|
1471
|
+
await import_fs_extra3.default.writeFile(file, defaultSchema);
|
|
1710
1472
|
}
|
|
1711
1473
|
try {
|
|
1712
1474
|
const define = {};
|
|
1713
1475
|
if (!process.env.NODE_ENV) {
|
|
1714
1476
|
define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
|
|
1715
1477
|
}
|
|
1716
|
-
const inputFile =
|
|
1717
|
-
|
|
1478
|
+
const inputFile = getPath({
|
|
1479
|
+
projectDir: tinaPath,
|
|
1480
|
+
filename: fileName,
|
|
1481
|
+
allowedTypes: ["js", "jsx", "tsx", "ts"],
|
|
1482
|
+
errorMessage: `Must provide a ${fileName}.{js,jsx,tsx,ts}`
|
|
1483
|
+
});
|
|
1484
|
+
await transpile(inputFile, `${fileName}.js`, tinaTempPath, options.verbose, define, packageJSONFilePath);
|
|
1718
1485
|
} catch (e) {
|
|
1719
1486
|
await cleanup({ tinaTempPath });
|
|
1720
1487
|
throw new BuildSchemaError(e);
|
|
@@ -1723,106 +1490,396 @@ var compileSchema = async (_ctx, _next, options) => {
|
|
|
1723
1490
|
if (key.startsWith(tinaTempPath)) {
|
|
1724
1491
|
delete require.cache[require.resolve(key)];
|
|
1725
1492
|
}
|
|
1726
|
-
});
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
const
|
|
1730
|
-
|
|
1731
|
-
await cleanup({ tinaTempPath });
|
|
1732
|
-
} catch (e) {
|
|
1733
|
-
await cleanup({ tinaTempPath });
|
|
1734
|
-
if (e instanceof Error) {
|
|
1735
|
-
if (e.name === "TinaSchemaValidationError") {
|
|
1736
|
-
throw e;
|
|
1493
|
+
});
|
|
1494
|
+
let returnObject = {};
|
|
1495
|
+
try {
|
|
1496
|
+
const schemaFunc = require(import_path4.default.join(tinaTempPath, `${fileName}.js`));
|
|
1497
|
+
returnObject = schemaFunc.default;
|
|
1498
|
+
await cleanup({ tinaTempPath });
|
|
1499
|
+
} catch (e) {
|
|
1500
|
+
await cleanup({ tinaTempPath });
|
|
1501
|
+
if (e instanceof Error) {
|
|
1502
|
+
if (e.name === "TinaSchemaValidationError") {
|
|
1503
|
+
throw e;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
throw new ExecuteSchemaError(e);
|
|
1507
|
+
}
|
|
1508
|
+
return returnObject;
|
|
1509
|
+
};
|
|
1510
|
+
var compileSchema = async (ctx, _next, options) => {
|
|
1511
|
+
const root2 = ctx.rootPath;
|
|
1512
|
+
const tinaPath = import_path4.default.join(root2, ".tina");
|
|
1513
|
+
const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
|
|
1514
|
+
const tinaConfigPath = import_path4.default.join(tinaGeneratedPath, "config");
|
|
1515
|
+
let schema = await compileFile(ctx, _next, options, "schema");
|
|
1516
|
+
try {
|
|
1517
|
+
const config = await compileFile(ctx, _next, options, "config");
|
|
1518
|
+
const configCopy = _.cloneDeep(config);
|
|
1519
|
+
delete configCopy.schema;
|
|
1520
|
+
if (config == null ? void 0 : config.schema) {
|
|
1521
|
+
schema = __spreadProps(__spreadValues({}, config.schema), { config: configCopy });
|
|
1522
|
+
}
|
|
1523
|
+
} catch (e) {
|
|
1524
|
+
}
|
|
1525
|
+
ctx.schema = schema;
|
|
1526
|
+
await import_fs_extra3.default.outputFile(import_path4.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
|
|
1527
|
+
};
|
|
1528
|
+
var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
|
|
1529
|
+
if (verbose)
|
|
1530
|
+
logger.info(logText("Building javascript..."));
|
|
1531
|
+
const packageJSON = JSON.parse(import_fs_extra3.default.readFileSync(packageJSONFilePath).toString() || "{}");
|
|
1532
|
+
const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
|
|
1533
|
+
const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
|
|
1534
|
+
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
1535
|
+
const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
|
|
1536
|
+
const outputPath = import_path4.default.join(tempDir, outputFile);
|
|
1537
|
+
await (0, import_esbuild.build)({
|
|
1538
|
+
bundle: true,
|
|
1539
|
+
platform: "neutral",
|
|
1540
|
+
target: ["node10.4"],
|
|
1541
|
+
entryPoints: [inputFile],
|
|
1542
|
+
treeShaking: true,
|
|
1543
|
+
external: [...external, "./node_modules/*"],
|
|
1544
|
+
loader: loaders,
|
|
1545
|
+
outfile: outputPath,
|
|
1546
|
+
define
|
|
1547
|
+
});
|
|
1548
|
+
if (verbose)
|
|
1549
|
+
logger.info(logText(`Javascript built`));
|
|
1550
|
+
};
|
|
1551
|
+
var defineSchema = (config) => {
|
|
1552
|
+
return config;
|
|
1553
|
+
};
|
|
1554
|
+
var loaders = {
|
|
1555
|
+
".aac": "file",
|
|
1556
|
+
".css": "file",
|
|
1557
|
+
".eot": "file",
|
|
1558
|
+
".flac": "file",
|
|
1559
|
+
".gif": "file",
|
|
1560
|
+
".jpeg": "file",
|
|
1561
|
+
".jpg": "file",
|
|
1562
|
+
".json": "json",
|
|
1563
|
+
".mp3": "file",
|
|
1564
|
+
".mp4": "file",
|
|
1565
|
+
".ogg": "file",
|
|
1566
|
+
".otf": "file",
|
|
1567
|
+
".png": "file",
|
|
1568
|
+
".svg": "file",
|
|
1569
|
+
".ttf": "file",
|
|
1570
|
+
".wav": "file",
|
|
1571
|
+
".webm": "file",
|
|
1572
|
+
".webp": "file",
|
|
1573
|
+
".woff": "file",
|
|
1574
|
+
".woff2": "file",
|
|
1575
|
+
".js": "jsx",
|
|
1576
|
+
".jsx": "jsx",
|
|
1577
|
+
".tsx": "tsx"
|
|
1578
|
+
};
|
|
1579
|
+
|
|
1580
|
+
// src/cmds/start-server/index.ts
|
|
1581
|
+
var import_path11 = __toModule(require("path"));
|
|
1582
|
+
var import_chalk6 = __toModule(require("chalk"));
|
|
1583
|
+
var import_chokidar = __toModule(require("chokidar"));
|
|
1584
|
+
var import_metrics3 = __toModule(require("@tinacms/metrics"));
|
|
1585
|
+
|
|
1586
|
+
// src/buildTina/index.ts
|
|
1587
|
+
var import_async_retry = __toModule(require("async-retry"));
|
|
1588
|
+
var import_fs_extra6 = __toModule(require("fs-extra"));
|
|
1589
|
+
var import_graphql10 = __toModule(require("@tinacms/graphql"));
|
|
1590
|
+
var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
|
|
1591
|
+
var import_path8 = __toModule(require("path"));
|
|
1592
|
+
|
|
1593
|
+
// src/cmds/query-gen/attachSchema.ts
|
|
1594
|
+
var import_graphql4 = __toModule(require("@tinacms/graphql"));
|
|
1595
|
+
var import_datalayer = __toModule(require("@tinacms/datalayer"));
|
|
1596
|
+
|
|
1597
|
+
// src/cmds/query-gen/genTypes.ts
|
|
1598
|
+
var import_graphql9 = __toModule(require("graphql"));
|
|
1599
|
+
var import_fs_extra4 = __toModule(require("fs-extra"));
|
|
1600
|
+
var import_path6 = __toModule(require("path"));
|
|
1601
|
+
|
|
1602
|
+
// src/codegen/index.ts
|
|
1603
|
+
var import_graphql8 = __toModule(require("graphql"));
|
|
1604
|
+
|
|
1605
|
+
// src/codegen/plugin.ts
|
|
1606
|
+
var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
|
|
1607
|
+
return `
|
|
1608
|
+
// TinaSDK generated code
|
|
1609
|
+
import { createClient, TinaClient } from "tinacms/dist/client";
|
|
1610
|
+
|
|
1611
|
+
const generateRequester = (client: TinaClient) => {
|
|
1612
|
+
const requester: (
|
|
1613
|
+
doc: any,
|
|
1614
|
+
vars?: any,
|
|
1615
|
+
options?: any,
|
|
1616
|
+
client
|
|
1617
|
+
) => Promise<any> = async (doc, vars, _options) => {
|
|
1618
|
+
const data = await client.request({
|
|
1619
|
+
query: doc,
|
|
1620
|
+
variables: vars,
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
return { data: data?.data, query: doc, variables: vars || {} };
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
return requester;
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
/**
|
|
1630
|
+
* @experimental this class can be used but may change in the future
|
|
1631
|
+
**/
|
|
1632
|
+
export const ExperimentalGetTinaClient = () =>
|
|
1633
|
+
getSdk(
|
|
1634
|
+
generateRequester(createClient({ url: "http://localhost:4001/graphql", queries }))
|
|
1635
|
+
);
|
|
1636
|
+
|
|
1637
|
+
export const queries = (client: TinaClient) => {
|
|
1638
|
+
const requester = generateRequester(client);
|
|
1639
|
+
return getSdk(requester);
|
|
1640
|
+
};
|
|
1641
|
+
`;
|
|
1642
|
+
};
|
|
1643
|
+
var AddGeneratedClient = {
|
|
1644
|
+
plugin: AddGeneratedClientFunc
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
// src/codegen/index.ts
|
|
1648
|
+
var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
|
|
1649
|
+
var import_core = __toModule(require("@graphql-codegen/core"));
|
|
1650
|
+
var import_load = __toModule(require("@graphql-tools/load"));
|
|
1651
|
+
var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
|
|
1652
|
+
var import_typescript = __toModule(require("@graphql-codegen/typescript"));
|
|
1653
|
+
|
|
1654
|
+
// src/codegen/sdkPlugin/index.ts
|
|
1655
|
+
var import_graphql6 = __toModule(require("graphql"));
|
|
1656
|
+
var import_graphql7 = __toModule(require("graphql"));
|
|
1657
|
+
var import_path5 = __toModule(require("path"));
|
|
1658
|
+
|
|
1659
|
+
// src/codegen/sdkPlugin/visitor.ts
|
|
1660
|
+
var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
|
|
1661
|
+
var import_auto_bind = __toModule(require("auto-bind"));
|
|
1662
|
+
var import_graphql5 = __toModule(require("graphql"));
|
|
1663
|
+
var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBaseVisitor {
|
|
1664
|
+
constructor(schema, fragments, rawConfig) {
|
|
1665
|
+
super(schema, fragments, rawConfig, {
|
|
1666
|
+
usingObservableFrom: rawConfig.usingObservableFrom
|
|
1667
|
+
});
|
|
1668
|
+
this._operationsToInclude = [];
|
|
1669
|
+
(0, import_auto_bind.default)(this);
|
|
1670
|
+
if (this.config.usingObservableFrom) {
|
|
1671
|
+
this._additionalImports.push(this.config.usingObservableFrom);
|
|
1672
|
+
}
|
|
1673
|
+
if (this.config.documentMode !== import_visitor_plugin_common.DocumentMode.string) {
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
1677
|
+
if (node.name == null) {
|
|
1678
|
+
throw new Error("Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + (0, import_graphql5.print)(node));
|
|
1679
|
+
} else {
|
|
1680
|
+
this._operationsToInclude.push({
|
|
1681
|
+
node,
|
|
1682
|
+
documentVariableName,
|
|
1683
|
+
operationType,
|
|
1684
|
+
operationResultType: `{data: ${operationResultType}, variables: ${operationVariablesTypes}, query: string}`,
|
|
1685
|
+
operationVariablesTypes
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
return null;
|
|
1689
|
+
}
|
|
1690
|
+
get sdkContent() {
|
|
1691
|
+
const usingObservable = !!this.config.usingObservableFrom;
|
|
1692
|
+
const allPossibleActions = this._operationsToInclude.map((o) => {
|
|
1693
|
+
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every((v) => v.type.kind !== import_graphql5.Kind.NON_NULL_TYPE || v.defaultValue);
|
|
1694
|
+
const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
|
|
1695
|
+
return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
|
|
1696
|
+
return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
|
|
1697
|
+
}`;
|
|
1698
|
+
}).map((s) => (0, import_visitor_plugin_common.indentMultiline)(s, 2));
|
|
1699
|
+
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode === import_visitor_plugin_common.DocumentMode.string ? "string" : "DocumentNode"}, vars?: V, options?: C) => ${usingObservable ? "Promise<R> & Observable<R>" : "Promise<R>"}
|
|
1700
|
+
export function getSdk<C>(requester: Requester<C>) {
|
|
1701
|
+
return {
|
|
1702
|
+
${allPossibleActions.join(",\n")}
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
export type Sdk = ReturnType<typeof getSdk>;`;
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
// src/codegen/sdkPlugin/index.ts
|
|
1710
|
+
var plugin = (schema, documents, config) => {
|
|
1711
|
+
const allAst = (0, import_graphql7.concatAST)(documents.reduce((prev, v) => {
|
|
1712
|
+
return [...prev, v.document];
|
|
1713
|
+
}, []));
|
|
1714
|
+
const allFragments = [
|
|
1715
|
+
...allAst.definitions.filter((d) => d.kind === import_graphql7.Kind.FRAGMENT_DEFINITION).map((fragmentDef) => ({
|
|
1716
|
+
node: fragmentDef,
|
|
1717
|
+
name: fragmentDef.name.value,
|
|
1718
|
+
onType: fragmentDef.typeCondition.name.value,
|
|
1719
|
+
isExternal: false
|
|
1720
|
+
})),
|
|
1721
|
+
...config.externalFragments || []
|
|
1722
|
+
];
|
|
1723
|
+
const visitor = new GenericSdkVisitor(schema, allFragments, config);
|
|
1724
|
+
const visitorResult = (0, import_graphql6.visit)(allAst, { leave: visitor });
|
|
1725
|
+
return {
|
|
1726
|
+
content: [
|
|
1727
|
+
visitor.fragments,
|
|
1728
|
+
...visitorResult.definitions.filter((t) => typeof t === "string"),
|
|
1729
|
+
visitor.sdkContent
|
|
1730
|
+
].join("\n")
|
|
1731
|
+
};
|
|
1732
|
+
};
|
|
1733
|
+
|
|
1734
|
+
// src/codegen/index.ts
|
|
1735
|
+
var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = {
|
|
1736
|
+
noSDK: false,
|
|
1737
|
+
verbose: false
|
|
1738
|
+
}) => {
|
|
1739
|
+
if (options.verbose)
|
|
1740
|
+
logger.info("Generating types...");
|
|
1741
|
+
try {
|
|
1742
|
+
let docs = [];
|
|
1743
|
+
let fragDocs = [];
|
|
1744
|
+
try {
|
|
1745
|
+
if (!options.noSDK) {
|
|
1746
|
+
docs = await (0, import_load.loadDocuments)(queryPathGlob, {
|
|
1747
|
+
loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
} catch (e) {
|
|
1751
|
+
let showErrorMessage = true;
|
|
1752
|
+
const message = e.message || "";
|
|
1753
|
+
if (message.includes("Unable to find any GraphQL type definitions for the following pointers:")) {
|
|
1754
|
+
showErrorMessage = false;
|
|
1755
|
+
}
|
|
1756
|
+
if (showErrorMessage) {
|
|
1757
|
+
console.error(e);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
if (!options.noSDK) {
|
|
1762
|
+
fragDocs = await (0, import_load.loadDocuments)(fragDocPath, {
|
|
1763
|
+
loaders: [new import_graphql_file_loader.GraphQLFileLoader()]
|
|
1764
|
+
});
|
|
1737
1765
|
}
|
|
1766
|
+
} catch (error) {
|
|
1767
|
+
console.error(error);
|
|
1738
1768
|
}
|
|
1739
|
-
|
|
1769
|
+
const res = await (0, import_core.codegen)({
|
|
1770
|
+
filename: process.cwd(),
|
|
1771
|
+
schema: (0, import_graphql8.parse)((0, import_graphql8.printSchema)(schema)),
|
|
1772
|
+
documents: [...docs, ...fragDocs],
|
|
1773
|
+
config: {},
|
|
1774
|
+
plugins: [
|
|
1775
|
+
{ typescript: {} },
|
|
1776
|
+
{ typescriptOperations: {} },
|
|
1777
|
+
{
|
|
1778
|
+
typescriptSdk: {}
|
|
1779
|
+
},
|
|
1780
|
+
{ AddGeneratedClient: {} }
|
|
1781
|
+
],
|
|
1782
|
+
pluginMap: {
|
|
1783
|
+
typescript: {
|
|
1784
|
+
plugin: import_typescript.plugin
|
|
1785
|
+
},
|
|
1786
|
+
typescriptOperations: {
|
|
1787
|
+
plugin: import_typescript_operations.plugin
|
|
1788
|
+
},
|
|
1789
|
+
typescriptSdk: {
|
|
1790
|
+
plugin
|
|
1791
|
+
},
|
|
1792
|
+
AddGeneratedClient
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
return res;
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
console.error(e);
|
|
1740
1798
|
}
|
|
1741
1799
|
};
|
|
1742
|
-
var transpile = async (inputFile, outputFile, tempDir, verbose, define) => {
|
|
1743
|
-
if (verbose)
|
|
1744
|
-
logger.info(logText("Building javascript..."));
|
|
1745
|
-
const packageJSON = JSON.parse(import_fs_extra4.default.readFileSync(packageJSONFilePath).toString() || "{}");
|
|
1746
|
-
const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
|
|
1747
|
-
const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
|
|
1748
|
-
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
1749
|
-
const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
|
|
1750
|
-
const outputPath = import_path5.default.join(tempDir, outputFile);
|
|
1751
|
-
await (0, import_esbuild.build)({
|
|
1752
|
-
bundle: true,
|
|
1753
|
-
platform: "neutral",
|
|
1754
|
-
target: ["node10.4"],
|
|
1755
|
-
entryPoints: [inputFile],
|
|
1756
|
-
treeShaking: true,
|
|
1757
|
-
external: [...external, "./node_modules/*"],
|
|
1758
|
-
loader: loaders,
|
|
1759
|
-
outfile: outputPath,
|
|
1760
|
-
define
|
|
1761
|
-
});
|
|
1762
|
-
if (verbose)
|
|
1763
|
-
logger.info(logText(`Javascript built`));
|
|
1764
|
-
};
|
|
1765
|
-
var defineSchema = (config) => {
|
|
1766
|
-
return config;
|
|
1767
|
-
};
|
|
1768
|
-
var loaders = {
|
|
1769
|
-
".aac": "file",
|
|
1770
|
-
".css": "file",
|
|
1771
|
-
".eot": "file",
|
|
1772
|
-
".flac": "file",
|
|
1773
|
-
".gif": "file",
|
|
1774
|
-
".jpeg": "file",
|
|
1775
|
-
".jpg": "file",
|
|
1776
|
-
".json": "json",
|
|
1777
|
-
".mp3": "file",
|
|
1778
|
-
".mp4": "file",
|
|
1779
|
-
".ogg": "file",
|
|
1780
|
-
".otf": "file",
|
|
1781
|
-
".png": "file",
|
|
1782
|
-
".svg": "file",
|
|
1783
|
-
".ttf": "file",
|
|
1784
|
-
".wav": "file",
|
|
1785
|
-
".webm": "file",
|
|
1786
|
-
".webp": "file",
|
|
1787
|
-
".woff": "file",
|
|
1788
|
-
".woff2": "file",
|
|
1789
|
-
".js": "jsx",
|
|
1790
|
-
".jsx": "jsx",
|
|
1791
|
-
".tsx": "tsx"
|
|
1792
|
-
};
|
|
1793
1800
|
|
|
1794
|
-
// src/cmds/
|
|
1795
|
-
var
|
|
1796
|
-
var
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1801
|
+
// src/cmds/query-gen/genTypes.ts
|
|
1802
|
+
var import_esbuild2 = __toModule(require("esbuild"));
|
|
1803
|
+
var TINA_HOST = "content.tinajs.io";
|
|
1804
|
+
var root = process.cwd();
|
|
1805
|
+
var generatedPath = import_path6.default.join(root, ".tina", "__generated__");
|
|
1806
|
+
async function genClient({
|
|
1807
|
+
tinaSchema,
|
|
1808
|
+
usingTs
|
|
1809
|
+
}, next, options) {
|
|
1810
|
+
var _a, _b, _c;
|
|
1811
|
+
const branch = (_a = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _a.branch;
|
|
1812
|
+
const clientId = (_b = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _b.clientId;
|
|
1813
|
+
const token = (_c = tinaSchema.config) == null ? void 0 : _c.token;
|
|
1814
|
+
if ((!branch || !clientId || !token) && !(options == null ? void 0 : options.local)) {
|
|
1815
|
+
const missing = [];
|
|
1816
|
+
if (!branch)
|
|
1817
|
+
missing.push("branch");
|
|
1818
|
+
if (!clientId)
|
|
1819
|
+
missing.push("clientId");
|
|
1820
|
+
if (!token)
|
|
1821
|
+
missing.push("token");
|
|
1822
|
+
throw new Error(`Client not configured properly. Missing ${missing.join(", ")}. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information`);
|
|
1823
|
+
}
|
|
1824
|
+
const apiURL = options.local ? "http://localhost:4001/graphql" : `https://${TINA_HOST}/content/${clientId}/github/${branch}`;
|
|
1825
|
+
const clientPath = import_path6.default.join(generatedPath, `client.${usingTs ? "ts" : "js"}`);
|
|
1826
|
+
import_fs_extra4.default.writeFileSync(clientPath, `import { createClient } from "tinacms/dist/client";
|
|
1827
|
+
import { queries } from "./types";
|
|
1828
|
+
export const client = createClient({ url: '${apiURL}', token: '${token}', queries });
|
|
1829
|
+
export default client;
|
|
1830
|
+
`);
|
|
1831
|
+
return next();
|
|
1832
|
+
}
|
|
1833
|
+
async function genTypes({ schema, usingTs }, next, options) {
|
|
1834
|
+
const typesPath = process.cwd() + "/.tina/__generated__/types.ts";
|
|
1835
|
+
const typesJSPath = process.cwd() + "/.tina/__generated__/types.js";
|
|
1836
|
+
const typesDPath = process.cwd() + "/.tina/__generated__/types.d.ts";
|
|
1837
|
+
const fragPath = process.cwd() + "/.tina/__generated__/*.{graphql,gql}";
|
|
1838
|
+
const queryPathGlob = process.cwd() + "/.tina/queries/**/*.{graphql,gql}";
|
|
1839
|
+
const typescriptTypes = await generateTypes(schema, queryPathGlob, fragPath, options);
|
|
1840
|
+
const code = `//@ts-nocheck
|
|
1841
|
+
// DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
1842
|
+
export function gql(strings: TemplateStringsArray, ...args: string[]): string {
|
|
1843
|
+
let str = ''
|
|
1844
|
+
strings.forEach((string, i) => {
|
|
1845
|
+
str += string + (args[i] || '')
|
|
1846
|
+
})
|
|
1847
|
+
return str
|
|
1848
|
+
}
|
|
1849
|
+
${typescriptTypes}
|
|
1850
|
+
`;
|
|
1851
|
+
if (usingTs) {
|
|
1852
|
+
await import_fs_extra4.default.outputFile(typesPath, code);
|
|
1853
|
+
logger.info(` Typescript types => ${logText(typesPath)}`);
|
|
1854
|
+
} else {
|
|
1855
|
+
await import_fs_extra4.default.outputFile(typesDPath, code);
|
|
1856
|
+
const jsCode = await (0, import_esbuild2.transform)(code, { loader: "ts" });
|
|
1857
|
+
await import_fs_extra4.default.outputFile(typesJSPath, jsCode.code);
|
|
1807
1858
|
}
|
|
1808
|
-
|
|
1859
|
+
const schemaString = await (0, import_graphql9.printSchema)(schema);
|
|
1860
|
+
const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
|
|
1861
|
+
await import_fs_extra4.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
1862
|
+
${schemaString}
|
|
1863
|
+
schema {
|
|
1864
|
+
query: Query
|
|
1865
|
+
mutation: Mutation
|
|
1866
|
+
}
|
|
1867
|
+
`);
|
|
1868
|
+
logger.info(` GraphQL types ====> ${logText(schemaPath)}
|
|
1869
|
+
`);
|
|
1870
|
+
next();
|
|
1871
|
+
}
|
|
1809
1872
|
|
|
1810
|
-
// src/
|
|
1811
|
-
var
|
|
1812
|
-
var import_chalk6 = __toModule(require("chalk"));
|
|
1813
|
-
var import_chokidar = __toModule(require("chokidar"));
|
|
1814
|
-
var import_fs_extra6 = __toModule(require("fs-extra"));
|
|
1873
|
+
// src/buildTina/git.ts
|
|
1874
|
+
var import_fs_extra5 = __toModule(require("fs-extra"));
|
|
1815
1875
|
var import_ini = __toModule(require("ini"));
|
|
1816
1876
|
var import_os = __toModule(require("os"));
|
|
1817
|
-
var
|
|
1818
|
-
var buildLock = new AsyncLock();
|
|
1819
|
-
var reBuildLock = new AsyncLock();
|
|
1820
|
-
var gqlPackageFile = require.resolve("@tinacms/graphql");
|
|
1877
|
+
var import_path7 = __toModule(require("path"));
|
|
1821
1878
|
var resolveGitRoot = async () => {
|
|
1822
|
-
const pathParts = process.cwd().split(
|
|
1879
|
+
const pathParts = process.cwd().split(import_path7.default.sep);
|
|
1823
1880
|
while (true) {
|
|
1824
|
-
const pathToGit = pathParts.join(
|
|
1825
|
-
if (await
|
|
1881
|
+
const pathToGit = pathParts.join(import_path7.default.sep);
|
|
1882
|
+
if (await import_fs_extra5.default.pathExists(import_path7.default.join(pathToGit, ".git"))) {
|
|
1826
1883
|
return pathToGit;
|
|
1827
1884
|
}
|
|
1828
1885
|
if (!pathParts.length) {
|
|
@@ -1847,9 +1904,9 @@ async function makeIsomorphicOptions(fsBridge) {
|
|
|
1847
1904
|
await fsBridge.delete(filepath);
|
|
1848
1905
|
}
|
|
1849
1906
|
};
|
|
1850
|
-
const userGitConfig = `${import_os.default.homedir()}${
|
|
1851
|
-
if (await
|
|
1852
|
-
const config = import_ini.default.parse(await
|
|
1907
|
+
const userGitConfig = `${import_os.default.homedir()}${import_path7.default.sep}.gitconfig`;
|
|
1908
|
+
if (await import_fs_extra5.default.pathExists(userGitConfig)) {
|
|
1909
|
+
const config = import_ini.default.parse(await import_fs_extra5.default.readFile(userGitConfig, "utf-8"));
|
|
1853
1910
|
if ((_a = config["user"]) == null ? void 0 : _a["name"]) {
|
|
1854
1911
|
options.author.name = config["user"]["name"];
|
|
1855
1912
|
}
|
|
@@ -1859,7 +1916,7 @@ async function makeIsomorphicOptions(fsBridge) {
|
|
|
1859
1916
|
}
|
|
1860
1917
|
let repoGitConfig = void 0;
|
|
1861
1918
|
if (!options.author.name) {
|
|
1862
|
-
repoGitConfig = import_ini.default.parse(await
|
|
1919
|
+
repoGitConfig = import_ini.default.parse(await import_fs_extra5.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
|
|
1863
1920
|
if ((_c = repoGitConfig["user"]) == null ? void 0 : _c["name"]) {
|
|
1864
1921
|
options.author.name = repoGitConfig["user"]["name"];
|
|
1865
1922
|
}
|
|
@@ -1868,7 +1925,7 @@ async function makeIsomorphicOptions(fsBridge) {
|
|
|
1868
1925
|
}
|
|
1869
1926
|
}
|
|
1870
1927
|
if (!options.author.email) {
|
|
1871
|
-
repoGitConfig = repoGitConfig || import_ini.default.parse(await
|
|
1928
|
+
repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra5.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
|
|
1872
1929
|
if ((_d = repoGitConfig["user"]) == null ? void 0 : _d["email"]) {
|
|
1873
1930
|
options.author.email = repoGitConfig["user"]["email"];
|
|
1874
1931
|
}
|
|
@@ -1878,63 +1935,228 @@ async function makeIsomorphicOptions(fsBridge) {
|
|
|
1878
1935
|
}
|
|
1879
1936
|
return options;
|
|
1880
1937
|
}
|
|
1881
|
-
|
|
1938
|
+
|
|
1939
|
+
// src/buildTina/index.ts
|
|
1940
|
+
var import_app = __toModule(require("@tinacms/app"));
|
|
1941
|
+
|
|
1942
|
+
// src/utils/spinner.ts
|
|
1943
|
+
var import_cli_spinner = __toModule(require("cli-spinner"));
|
|
1944
|
+
async function spin({
|
|
1945
|
+
waitFor,
|
|
1946
|
+
text
|
|
1947
|
+
}) {
|
|
1948
|
+
const spinner = new import_cli_spinner.Spinner({
|
|
1949
|
+
text: `${text} %s`,
|
|
1950
|
+
stream: process.stderr,
|
|
1951
|
+
onTick: function(msg) {
|
|
1952
|
+
this.clearLine(this.stream);
|
|
1953
|
+
this.stream.write(msg);
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
spinner.setSpinnerString("\u280B\u2819\u2839\u2838\u283C\u2834\u2826\u2827\u2807\u280F");
|
|
1957
|
+
spinner.start();
|
|
1958
|
+
const res = await waitFor();
|
|
1959
|
+
spinner.stop();
|
|
1960
|
+
return res;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
// src/buildTina/index.ts
|
|
1964
|
+
var buildSetupCmdBuild = async (ctx, next, opts) => {
|
|
1965
|
+
const rootPath2 = ctx.rootPath;
|
|
1966
|
+
const { bridge, database, store } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
|
|
1967
|
+
rootPath: rootPath2,
|
|
1968
|
+
useMemoryStore: true
|
|
1969
|
+
}));
|
|
1970
|
+
ctx.bridge = bridge;
|
|
1971
|
+
ctx.database = database;
|
|
1972
|
+
ctx.store = store;
|
|
1973
|
+
next();
|
|
1974
|
+
};
|
|
1975
|
+
var buildSetupCmdServerStart = async (ctx, next, opts) => {
|
|
1976
|
+
const rootPath2 = ctx.rootPath;
|
|
1977
|
+
const { bridge, database, store } = await buildSetup(__spreadProps(__spreadValues({}, opts), {
|
|
1978
|
+
rootPath: rootPath2,
|
|
1979
|
+
useMemoryStore: false
|
|
1980
|
+
}));
|
|
1981
|
+
ctx.bridge = bridge;
|
|
1982
|
+
ctx.database = database;
|
|
1983
|
+
ctx.store = store;
|
|
1984
|
+
next();
|
|
1985
|
+
};
|
|
1986
|
+
var buildSetupCmdAudit = async (ctx, next, options) => {
|
|
1987
|
+
const rootPath2 = ctx.rootPath;
|
|
1988
|
+
const bridge = options.clean ? new import_datalayer2.FilesystemBridge(rootPath2) : new import_datalayer2.AuditFileSystemBridge(rootPath2);
|
|
1989
|
+
const store = new import_datalayer2.LevelStore(rootPath2, false);
|
|
1990
|
+
const database = await (0, import_graphql10.createDatabase)({ store, bridge });
|
|
1991
|
+
ctx.bridge = bridge;
|
|
1992
|
+
ctx.database = database;
|
|
1993
|
+
ctx.store = store;
|
|
1994
|
+
next();
|
|
1995
|
+
};
|
|
1996
|
+
var buildSetup = async ({
|
|
1997
|
+
isomorphicGitBridge: isomorphicGitBridge2,
|
|
1998
|
+
experimentalData,
|
|
1999
|
+
rootPath: rootPath2,
|
|
2000
|
+
useMemoryStore
|
|
2001
|
+
}) => {
|
|
2002
|
+
const fsBridge = new import_datalayer2.FilesystemBridge(rootPath2);
|
|
2003
|
+
const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
|
|
2004
|
+
const bridge = isomorphicGitBridge2 ? new import_datalayer2.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
|
|
2005
|
+
const store = new import_datalayer2.LevelStore(rootPath2, useMemoryStore);
|
|
2006
|
+
const database = await (0, import_graphql10.createDatabase)({ store, bridge });
|
|
2007
|
+
return { database, bridge, store };
|
|
2008
|
+
};
|
|
2009
|
+
var buildCmdBuild = async (ctx, next, options) => {
|
|
2010
|
+
const bridge = ctx.bridge;
|
|
2011
|
+
const database = ctx.database;
|
|
2012
|
+
const store = ctx.store;
|
|
2013
|
+
await build2(__spreadProps(__spreadValues({}, options), {
|
|
2014
|
+
bridge,
|
|
2015
|
+
database,
|
|
2016
|
+
store,
|
|
2017
|
+
ctx,
|
|
2018
|
+
skipIndex: true
|
|
2019
|
+
}));
|
|
2020
|
+
next();
|
|
2021
|
+
};
|
|
2022
|
+
var auditCmdBuild = async (ctx, next, options) => {
|
|
2023
|
+
const bridge = ctx.bridge;
|
|
2024
|
+
const database = ctx.database;
|
|
2025
|
+
const store = ctx.store;
|
|
2026
|
+
await build2(__spreadProps(__spreadValues({}, options), {
|
|
2027
|
+
local: true,
|
|
2028
|
+
verbose: true,
|
|
2029
|
+
bridge,
|
|
2030
|
+
database,
|
|
2031
|
+
store,
|
|
2032
|
+
ctx
|
|
2033
|
+
}));
|
|
2034
|
+
next();
|
|
2035
|
+
};
|
|
2036
|
+
var build2 = async ({
|
|
2037
|
+
noWatch,
|
|
2038
|
+
ctx,
|
|
2039
|
+
bridge,
|
|
2040
|
+
database,
|
|
2041
|
+
store,
|
|
2042
|
+
beforeBuild,
|
|
2043
|
+
afterBuild,
|
|
2044
|
+
dev,
|
|
2045
|
+
local,
|
|
2046
|
+
verbose,
|
|
2047
|
+
noSDK,
|
|
2048
|
+
skipIndex
|
|
2049
|
+
}) => {
|
|
2050
|
+
var _a, _b;
|
|
2051
|
+
const rootPath2 = ctx.rootPath;
|
|
2052
|
+
if (!rootPath2) {
|
|
2053
|
+
throw new Error("Root path has not been attached");
|
|
2054
|
+
}
|
|
2055
|
+
const tinaGeneratedPath = import_path8.default.join(rootPath2, ".tina", "__generated__");
|
|
2056
|
+
database.clearCache();
|
|
2057
|
+
if (beforeBuild) {
|
|
2058
|
+
await beforeBuild();
|
|
2059
|
+
}
|
|
2060
|
+
try {
|
|
2061
|
+
await import_fs_extra6.default.mkdirp(tinaGeneratedPath);
|
|
2062
|
+
await store.close();
|
|
2063
|
+
await resetGeneratedFolder({
|
|
2064
|
+
tinaGeneratedPath,
|
|
2065
|
+
usingTs: ctx.usingTs
|
|
2066
|
+
});
|
|
2067
|
+
await store.open();
|
|
2068
|
+
const cliFlags = [];
|
|
2069
|
+
cliFlags.push("experimentalData");
|
|
2070
|
+
cliFlags.push("isomorphicGitBridge");
|
|
2071
|
+
const database2 = await (0, import_graphql10.createDatabase)({ store, bridge });
|
|
2072
|
+
await compileSchema(ctx, null, { verbose, dev });
|
|
2073
|
+
const schema = await (0, import_async_retry.default)(async () => await (0, import_graphql10.buildSchema)(rootPath2, database2, cliFlags, skipIndex));
|
|
2074
|
+
await genTypes({ schema, usingTs: ctx.usingTs }, () => {
|
|
2075
|
+
}, {
|
|
2076
|
+
noSDK,
|
|
2077
|
+
verbose
|
|
2078
|
+
});
|
|
2079
|
+
await genClient({ tinaSchema: ctx.schema, usingTs: ctx.usingTs }, () => {
|
|
2080
|
+
}, {
|
|
2081
|
+
local
|
|
2082
|
+
});
|
|
2083
|
+
if ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build) {
|
|
2084
|
+
await spin({
|
|
2085
|
+
text: "Building static site",
|
|
2086
|
+
waitFor: async () => {
|
|
2087
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
2088
|
+
await (0, import_app.viteBuild)({
|
|
2089
|
+
local,
|
|
2090
|
+
rootPath: rootPath2,
|
|
2091
|
+
outputFolder: (_c = (_b2 = (_a2 = ctx.schema) == null ? void 0 : _a2.config) == null ? void 0 : _b2.build) == null ? void 0 : _c.outputFolder,
|
|
2092
|
+
publicFolder: (_f = (_e = (_d = ctx.schema) == null ? void 0 : _d.config) == null ? void 0 : _e.build) == null ? void 0 : _f.publicFolder
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
2096
|
+
console.log("\nDone building static site");
|
|
2097
|
+
}
|
|
2098
|
+
} catch (error) {
|
|
2099
|
+
throw error;
|
|
2100
|
+
} finally {
|
|
2101
|
+
if (afterBuild) {
|
|
2102
|
+
await afterBuild();
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
|
|
2107
|
+
// src/cmds/start-server/lock.ts
|
|
2108
|
+
var AsyncLock = class {
|
|
2109
|
+
constructor() {
|
|
2110
|
+
this.disable = () => {
|
|
2111
|
+
};
|
|
2112
|
+
this.promise = Promise.resolve();
|
|
2113
|
+
}
|
|
2114
|
+
enable() {
|
|
2115
|
+
this.promise = new Promise((resolve2) => this.disable = resolve2);
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
// src/cmds/start-server/index.ts
|
|
2120
|
+
var buildLock = new AsyncLock();
|
|
2121
|
+
var reBuildLock = new AsyncLock();
|
|
2122
|
+
var gqlPackageFile = require.resolve("@tinacms/graphql");
|
|
2123
|
+
async function startServer(ctx, next, {
|
|
1882
2124
|
port = 4001,
|
|
1883
2125
|
noWatch,
|
|
1884
|
-
experimentalData,
|
|
1885
2126
|
isomorphicGitBridge: isomorphicGitBridge2,
|
|
1886
2127
|
noSDK,
|
|
1887
2128
|
noTelemetry,
|
|
1888
2129
|
watchFolders,
|
|
1889
2130
|
verbose,
|
|
1890
|
-
dev
|
|
2131
|
+
dev,
|
|
2132
|
+
local
|
|
1891
2133
|
}) {
|
|
1892
2134
|
buildLock.disable();
|
|
1893
2135
|
reBuildLock.disable();
|
|
1894
|
-
const rootPath2 =
|
|
2136
|
+
const rootPath2 = ctx.rootPath;
|
|
1895
2137
|
const t = new import_metrics3.Telemetry({ disabled: Boolean(noTelemetry) });
|
|
1896
2138
|
t.submitRecord({
|
|
1897
2139
|
event: {
|
|
1898
2140
|
name: "tinacms:cli:server:start:invoke"
|
|
1899
2141
|
}
|
|
1900
2142
|
});
|
|
1901
|
-
const
|
|
1902
|
-
const
|
|
1903
|
-
const
|
|
1904
|
-
const store = experimentalData ? new import_datalayer3.LevelStore(rootPath2) : new import_datalayer3.FilesystemStore({ rootPath: rootPath2 });
|
|
2143
|
+
const bridge = ctx.bridge;
|
|
2144
|
+
const database = ctx.database;
|
|
2145
|
+
const store = ctx.store;
|
|
1905
2146
|
const shouldBuild = bridge.supportsBuilding();
|
|
1906
|
-
const database = await (0, import_graphql11.createDatabase)({ store, bridge });
|
|
1907
2147
|
let ready = false;
|
|
1908
|
-
const build2 = async (noSDK2) => {
|
|
1909
|
-
database.clearCache();
|
|
1910
|
-
await buildLock.promise;
|
|
1911
|
-
buildLock.enable();
|
|
1912
|
-
try {
|
|
1913
|
-
if (!process.env.CI && !noWatch) {
|
|
1914
|
-
await store.close();
|
|
1915
|
-
await resetGeneratedFolder();
|
|
1916
|
-
await store.open();
|
|
1917
|
-
}
|
|
1918
|
-
const cliFlags = [];
|
|
1919
|
-
if (isomorphicGitBridge2) {
|
|
1920
|
-
cliFlags.push("isomorphicGitBridge");
|
|
1921
|
-
}
|
|
1922
|
-
const database2 = await (0, import_graphql11.createDatabase)({ store, bridge });
|
|
1923
|
-
await compileSchema(null, null, { verbose, dev });
|
|
1924
|
-
const schema = await (0, import_graphql11.buildSchema)(rootPath2, database2, cliFlags);
|
|
1925
|
-
await genTypes({ schema }, () => {
|
|
1926
|
-
}, { noSDK: noSDK2, verbose });
|
|
1927
|
-
} catch (error) {
|
|
1928
|
-
throw error;
|
|
1929
|
-
} finally {
|
|
1930
|
-
buildLock.disable();
|
|
1931
|
-
}
|
|
1932
|
-
};
|
|
1933
2148
|
const state = {
|
|
1934
2149
|
server: null,
|
|
1935
2150
|
sockets: []
|
|
1936
2151
|
};
|
|
1937
2152
|
let isReady = false;
|
|
2153
|
+
const beforeBuild = async () => {
|
|
2154
|
+
await buildLock.promise;
|
|
2155
|
+
buildLock.enable();
|
|
2156
|
+
};
|
|
2157
|
+
const afterBuild = async () => {
|
|
2158
|
+
buildLock.disable();
|
|
2159
|
+
};
|
|
1938
2160
|
const start = async () => {
|
|
1939
2161
|
await buildLock.promise;
|
|
1940
2162
|
buildLock.enable();
|
|
@@ -1983,7 +2205,7 @@ or`);
|
|
|
1983
2205
|
});
|
|
1984
2206
|
});
|
|
1985
2207
|
};
|
|
1986
|
-
const foldersToWatch = (watchFolders || []).map((x) =>
|
|
2208
|
+
const foldersToWatch = (watchFolders || []).map((x) => import_path11.default.join(rootPath2, x));
|
|
1987
2209
|
if (!noWatch && !process.env.CI) {
|
|
1988
2210
|
import_chokidar.default.watch([
|
|
1989
2211
|
...foldersToWatch,
|
|
@@ -1993,14 +2215,27 @@ or`);
|
|
|
1993
2215
|
ignored: [
|
|
1994
2216
|
"**/node_modules/**/*",
|
|
1995
2217
|
"**/.next/**/*",
|
|
1996
|
-
`${
|
|
2218
|
+
`${import_path11.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
1997
2219
|
]
|
|
1998
2220
|
}).on("ready", async () => {
|
|
1999
2221
|
if (verbose)
|
|
2000
2222
|
console.log("Generating Tina config");
|
|
2001
2223
|
try {
|
|
2002
2224
|
if (shouldBuild) {
|
|
2003
|
-
await build2(
|
|
2225
|
+
await build2({
|
|
2226
|
+
bridge,
|
|
2227
|
+
ctx,
|
|
2228
|
+
database,
|
|
2229
|
+
store,
|
|
2230
|
+
dev,
|
|
2231
|
+
isomorphicGitBridge: isomorphicGitBridge2,
|
|
2232
|
+
local: true,
|
|
2233
|
+
noSDK,
|
|
2234
|
+
noWatch,
|
|
2235
|
+
verbose,
|
|
2236
|
+
beforeBuild,
|
|
2237
|
+
afterBuild
|
|
2238
|
+
});
|
|
2004
2239
|
}
|
|
2005
2240
|
ready = true;
|
|
2006
2241
|
isReady = true;
|
|
@@ -2018,7 +2253,20 @@ or`);
|
|
|
2018
2253
|
logger.info("Tina change detected, regenerating config");
|
|
2019
2254
|
try {
|
|
2020
2255
|
if (shouldBuild) {
|
|
2021
|
-
await build2(
|
|
2256
|
+
await build2({
|
|
2257
|
+
bridge,
|
|
2258
|
+
ctx,
|
|
2259
|
+
database,
|
|
2260
|
+
store,
|
|
2261
|
+
dev,
|
|
2262
|
+
isomorphicGitBridge: isomorphicGitBridge2,
|
|
2263
|
+
local: true,
|
|
2264
|
+
noSDK,
|
|
2265
|
+
noWatch,
|
|
2266
|
+
verbose,
|
|
2267
|
+
beforeBuild,
|
|
2268
|
+
afterBuild
|
|
2269
|
+
});
|
|
2022
2270
|
}
|
|
2023
2271
|
if (isReady) {
|
|
2024
2272
|
await restart();
|
|
@@ -2041,7 +2289,20 @@ or`);
|
|
|
2041
2289
|
logger.info("Detected CI environment, omitting watch commands...");
|
|
2042
2290
|
}
|
|
2043
2291
|
if (shouldBuild) {
|
|
2044
|
-
await build2(
|
|
2292
|
+
await build2({
|
|
2293
|
+
bridge,
|
|
2294
|
+
ctx,
|
|
2295
|
+
database,
|
|
2296
|
+
store,
|
|
2297
|
+
dev,
|
|
2298
|
+
isomorphicGitBridge: isomorphicGitBridge2,
|
|
2299
|
+
local: true,
|
|
2300
|
+
noSDK,
|
|
2301
|
+
noWatch,
|
|
2302
|
+
verbose,
|
|
2303
|
+
beforeBuild,
|
|
2304
|
+
afterBuild
|
|
2305
|
+
});
|
|
2045
2306
|
}
|
|
2046
2307
|
await start();
|
|
2047
2308
|
next();
|
|
@@ -2147,13 +2408,22 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
2147
2408
|
}
|
|
2148
2409
|
};
|
|
2149
2410
|
|
|
2411
|
+
// src/buildTina/attachPath.ts
|
|
2412
|
+
var import_fs_extra8 = __toModule(require("fs-extra"));
|
|
2413
|
+
var import_path12 = __toModule(require("path"));
|
|
2414
|
+
var attachPath = async (ctx, next, _options) => {
|
|
2415
|
+
ctx.rootPath = process.cwd();
|
|
2416
|
+
const tinaPath = import_path12.default.join(ctx.rootPath, ".tina");
|
|
2417
|
+
ctx.usingTs = await (0, import_fs_extra8.pathExists)(import_path12.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra8.pathExists)(import_path12.default.join(tinaPath, "schema.tsx"));
|
|
2418
|
+
next();
|
|
2419
|
+
};
|
|
2420
|
+
|
|
2150
2421
|
// src/cmds/baseCmds.ts
|
|
2151
|
-
var CMD_GEN_TYPES = "schema:types";
|
|
2152
2422
|
var CMD_START_SERVER = "server:start";
|
|
2153
|
-
var
|
|
2154
|
-
var CMD_WAIT_FOR_DB = "server:waitForDB";
|
|
2423
|
+
var CMD_DEV = "dev";
|
|
2155
2424
|
var INIT = "init";
|
|
2156
2425
|
var AUDIT = "audit";
|
|
2426
|
+
var CMD_BUILD = "build";
|
|
2157
2427
|
var startServerPortOption = {
|
|
2158
2428
|
name: "--port <port>",
|
|
2159
2429
|
description: "Specify a port to run the server on. (default 4001)"
|
|
@@ -2207,6 +2477,17 @@ var developmentOption = {
|
|
|
2207
2477
|
name: "--dev",
|
|
2208
2478
|
description: "Uses NODE_ENV=development when compiling client and schema"
|
|
2209
2479
|
};
|
|
2480
|
+
var localOption = {
|
|
2481
|
+
name: "--local",
|
|
2482
|
+
description: "Uses the local file system graphql server",
|
|
2483
|
+
defaultValue: false
|
|
2484
|
+
};
|
|
2485
|
+
var checkOptions = async (_ctx, next, options) => {
|
|
2486
|
+
if (options == null ? void 0 : options.experimentalData) {
|
|
2487
|
+
logger.warn(warnText("Warning: you are using the `--experimentalData`flag. This flag is not needed and can safely be removed. It will be deprecated in a future version"));
|
|
2488
|
+
}
|
|
2489
|
+
next();
|
|
2490
|
+
};
|
|
2210
2491
|
var baseCmds = [
|
|
2211
2492
|
{
|
|
2212
2493
|
command: CMD_START_SERVER,
|
|
@@ -2221,39 +2502,62 @@ var baseCmds = [
|
|
|
2221
2502
|
noTelemetryOption,
|
|
2222
2503
|
watchFileOption,
|
|
2223
2504
|
verboseOption,
|
|
2224
|
-
developmentOption
|
|
2505
|
+
developmentOption,
|
|
2506
|
+
localOption
|
|
2225
2507
|
],
|
|
2226
|
-
action: (options) => chain([
|
|
2508
|
+
action: (options) => chain([
|
|
2509
|
+
attachPath,
|
|
2510
|
+
async (ctx, next, _2) => {
|
|
2511
|
+
logger.warn(warnText("server:start will be deprecated in the future, please use `tinacms dev` instead"));
|
|
2512
|
+
next();
|
|
2513
|
+
},
|
|
2514
|
+
checkOptions,
|
|
2515
|
+
buildSetupCmdServerStart,
|
|
2516
|
+
startServer,
|
|
2517
|
+
startSubprocess
|
|
2518
|
+
], options)
|
|
2227
2519
|
},
|
|
2228
2520
|
{
|
|
2229
|
-
command:
|
|
2230
|
-
description: "
|
|
2521
|
+
command: CMD_DEV,
|
|
2522
|
+
description: "Builds tina and starts the dev server.",
|
|
2231
2523
|
options: [
|
|
2524
|
+
startServerPortOption,
|
|
2232
2525
|
subCommand,
|
|
2233
|
-
experimentalDatalayer,
|
|
2234
2526
|
isomorphicGitBridge,
|
|
2527
|
+
noWatchOption,
|
|
2528
|
+
noSDKCodegenOption,
|
|
2235
2529
|
noTelemetryOption,
|
|
2236
|
-
|
|
2237
|
-
|
|
2530
|
+
watchFileOption,
|
|
2531
|
+
verboseOption
|
|
2238
2532
|
],
|
|
2239
|
-
action: (options) => chain([
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2533
|
+
action: (options) => chain([
|
|
2534
|
+
attachPath,
|
|
2535
|
+
checkOptions,
|
|
2536
|
+
buildSetupCmdServerStart,
|
|
2537
|
+
startServer,
|
|
2538
|
+
startSubprocess
|
|
2539
|
+
], options)
|
|
2246
2540
|
},
|
|
2247
2541
|
{
|
|
2248
|
-
command:
|
|
2249
|
-
description: "
|
|
2542
|
+
command: CMD_BUILD,
|
|
2543
|
+
description: "Build Tina",
|
|
2250
2544
|
options: [
|
|
2251
2545
|
experimentalDatalayer,
|
|
2252
2546
|
isomorphicGitBridge,
|
|
2253
2547
|
noSDKCodegenOption,
|
|
2254
|
-
noTelemetryOption
|
|
2548
|
+
noTelemetryOption,
|
|
2549
|
+
verboseOption,
|
|
2550
|
+
developmentOption,
|
|
2551
|
+
localOption
|
|
2255
2552
|
],
|
|
2256
|
-
action: (options) => chain([
|
|
2553
|
+
action: (options) => chain([
|
|
2554
|
+
attachPath,
|
|
2555
|
+
checkOptions,
|
|
2556
|
+
buildSetupCmdBuild,
|
|
2557
|
+
buildCmdBuild,
|
|
2558
|
+
compileClient,
|
|
2559
|
+
waitForDB
|
|
2560
|
+
], options)
|
|
2257
2561
|
},
|
|
2258
2562
|
{
|
|
2259
2563
|
command: INIT,
|
|
@@ -2265,15 +2569,13 @@ var baseCmds = [
|
|
|
2265
2569
|
],
|
|
2266
2570
|
description: "Add Tina Cloud to an existing project",
|
|
2267
2571
|
action: (options) => chain([
|
|
2572
|
+
attachPath,
|
|
2573
|
+
checkOptions,
|
|
2268
2574
|
checkDeps,
|
|
2269
2575
|
initTina,
|
|
2270
2576
|
installDeps,
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
next();
|
|
2274
|
-
},
|
|
2275
|
-
attachSchema,
|
|
2276
|
-
genTypes,
|
|
2577
|
+
buildSetupCmdBuild,
|
|
2578
|
+
buildCmdBuild,
|
|
2277
2579
|
tinaSetup,
|
|
2278
2580
|
successMessage
|
|
2279
2581
|
], options)
|
|
@@ -2283,16 +2585,9 @@ var baseCmds = [
|
|
|
2283
2585
|
command: AUDIT,
|
|
2284
2586
|
description: "Audit your schema and the files to check for errors",
|
|
2285
2587
|
action: (options) => chain([
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
},
|
|
2290
|
-
async (_ctx, next) => {
|
|
2291
|
-
await compileSchema(_ctx, next, options);
|
|
2292
|
-
next();
|
|
2293
|
-
},
|
|
2294
|
-
attachSchema,
|
|
2295
|
-
genTypes,
|
|
2588
|
+
attachPath,
|
|
2589
|
+
buildSetupCmdAudit,
|
|
2590
|
+
auditCmdBuild,
|
|
2296
2591
|
async (_ctx, next) => {
|
|
2297
2592
|
logger.level = "info";
|
|
2298
2593
|
logger.info(import_chalk7.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
|