@tinacms/cli 0.60.12 → 0.60.13
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/CHANGELOG.md +6 -0
- package/README.md +1 -0
- package/dist/cmds/compile/index.d.ts +3 -2
- package/dist/cmds/start-server/index.d.ts +2 -1
- package/dist/codegen/index.d.ts +1 -0
- package/dist/index.js +774 -745
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -114,7 +114,11 @@ var commander = __toModule(require("commander"));
|
|
|
114
114
|
|
|
115
115
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/package.json
|
|
116
116
|
var name = "@tinacms/cli";
|
|
117
|
-
var version = "0.60.
|
|
117
|
+
var version = "0.60.13";
|
|
118
|
+
|
|
119
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
|
|
120
|
+
var import_graphql = __toModule(require("@tinacms/graphql"));
|
|
121
|
+
var import_datalayer = __toModule(require("@tinacms/datalayer"));
|
|
118
122
|
|
|
119
123
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/utils/theme.ts
|
|
120
124
|
var import_chalk = __toModule(require("chalk"));
|
|
@@ -127,29 +131,6 @@ var logText = import_chalk.default.italic.gray;
|
|
|
127
131
|
var warnText = import_chalk.default.yellowBright.bgBlack;
|
|
128
132
|
var CONFIRMATION_TEXT = import_chalk.default.dim("enter to confirm");
|
|
129
133
|
|
|
130
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
|
|
131
|
-
var chain = async (cmds, options) => {
|
|
132
|
-
const ctx = {};
|
|
133
|
-
const next = async (middlewareIndex) => {
|
|
134
|
-
if (middlewareIndex >= cmds.length) {
|
|
135
|
-
process.exit(0);
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
|
|
139
|
-
} catch (err) {
|
|
140
|
-
console.error(` ${dangerText(err)}`);
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
if (cmds.length > 0) {
|
|
145
|
-
await next(0);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/attachSchema.ts
|
|
150
|
-
var import_graphql = __toModule(require("@tinacms/graphql"));
|
|
151
|
-
var import_datalayer = __toModule(require("@tinacms/datalayer"));
|
|
152
|
-
|
|
153
134
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/logger/index.ts
|
|
154
135
|
var import_log4js = __toModule(require("log4js"));
|
|
155
136
|
var logger = import_log4js.default.getLogger();
|
|
@@ -173,11 +154,12 @@ async function attachSchema(ctx, next, options) {
|
|
|
173
154
|
next();
|
|
174
155
|
}
|
|
175
156
|
|
|
157
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
|
|
158
|
+
var import_graphql6 = __toModule(require("graphql"));
|
|
159
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
160
|
+
|
|
176
161
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
|
|
177
162
|
var import_graphql5 = __toModule(require("graphql"));
|
|
178
|
-
var import_core = __toModule(require("@graphql-codegen/core"));
|
|
179
|
-
var import_typescript = __toModule(require("@graphql-codegen/typescript"));
|
|
180
|
-
var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
|
|
181
163
|
|
|
182
164
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/plugin.ts
|
|
183
165
|
var AddGeneratedClientFunc = (_schema, _documents, _config, _info) => {
|
|
@@ -214,6 +196,13 @@ var AddGeneratedClient = {
|
|
|
214
196
|
plugin: AddGeneratedClientFunc
|
|
215
197
|
};
|
|
216
198
|
|
|
199
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
|
|
200
|
+
var import_graphql_file_loader = __toModule(require("@graphql-tools/graphql-file-loader"));
|
|
201
|
+
var import_core = __toModule(require("@graphql-codegen/core"));
|
|
202
|
+
var import_load = __toModule(require("@graphql-tools/load"));
|
|
203
|
+
var import_typescript_operations = __toModule(require("@graphql-codegen/typescript-operations"));
|
|
204
|
+
var import_typescript = __toModule(require("@graphql-codegen/typescript"));
|
|
205
|
+
|
|
217
206
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/sdkPlugin/index.ts
|
|
218
207
|
var import_graphql3 = __toModule(require("graphql"));
|
|
219
208
|
var import_graphql4 = __toModule(require("graphql"));
|
|
@@ -296,10 +285,12 @@ var plugin = (schema, documents, config) => {
|
|
|
296
285
|
};
|
|
297
286
|
|
|
298
287
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/codegen/index.ts
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
288
|
+
var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), options = {
|
|
289
|
+
noSDK: false,
|
|
290
|
+
verbose: false
|
|
291
|
+
}) => {
|
|
292
|
+
if (options.verbose)
|
|
293
|
+
logger.info("Generating types...");
|
|
303
294
|
try {
|
|
304
295
|
let docs = [];
|
|
305
296
|
let fragDocs = [];
|
|
@@ -364,8 +355,6 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
364
355
|
};
|
|
365
356
|
|
|
366
357
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/query-gen/genTypes.ts
|
|
367
|
-
var import_graphql6 = __toModule(require("graphql"));
|
|
368
|
-
var import_fs_extra = __toModule(require("fs-extra"));
|
|
369
358
|
async function genTypes({ schema }, next, options) {
|
|
370
359
|
const typesPath = process.cwd() + "/.tina/__generated__/types.ts";
|
|
371
360
|
const fragPath = process.cwd() + "/.tina/__generated__/*.{graphql,gql}";
|
|
@@ -375,7 +364,7 @@ async function genTypes({ schema }, next, options) {
|
|
|
375
364
|
// DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
376
365
|
${typescriptTypes}
|
|
377
366
|
`);
|
|
378
|
-
logger.info(`Typescript types => ${logText(typesPath)}`);
|
|
367
|
+
logger.info(` Typescript types => ${logText(typesPath)}`);
|
|
379
368
|
const schemaString = await (0, import_graphql6.printSchema)(schema);
|
|
380
369
|
const schemaPath = process.cwd() + "/.tina/__generated__/schema.gql";
|
|
381
370
|
await import_fs_extra.default.outputFile(schemaPath, `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
@@ -385,478 +374,261 @@ schema {
|
|
|
385
374
|
mutation: Mutation
|
|
386
375
|
}
|
|
387
376
|
`);
|
|
388
|
-
logger.info(`GraphQL types ====> ${logText(schemaPath)}
|
|
377
|
+
logger.info(` GraphQL types ====> ${logText(schemaPath)}
|
|
378
|
+
`);
|
|
389
379
|
next();
|
|
390
380
|
}
|
|
391
381
|
|
|
392
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
393
|
-
var
|
|
394
|
-
var import_path4 = __toModule(require("path"));
|
|
395
|
-
var import_graphql7 = __toModule(require("@tinacms/graphql"));
|
|
382
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
|
|
383
|
+
var import_graphql9 = __toModule(require("@tinacms/graphql"));
|
|
396
384
|
var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
|
|
397
385
|
|
|
398
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
399
|
-
var
|
|
400
|
-
var
|
|
401
|
-
var
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
name: "title",
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
type: "rich-text",
|
|
421
|
-
label: "Blog Post Body",
|
|
422
|
-
name: "body",
|
|
423
|
-
isBody: true,
|
|
424
|
-
templates: [
|
|
425
|
-
{
|
|
426
|
-
name: "PageSection",
|
|
427
|
-
label: "Page Section",
|
|
428
|
-
fields: [
|
|
429
|
-
{
|
|
430
|
-
type: "string",
|
|
431
|
-
name: "heading",
|
|
432
|
-
label: "Heading",
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
type: "string",
|
|
436
|
-
name: "content",
|
|
437
|
-
label: "Content",
|
|
438
|
-
ui: {
|
|
439
|
-
component: "textarea"
|
|
386
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/audit.ts
|
|
387
|
+
var import_graphql7 = __toModule(require("@tinacms/graphql"));
|
|
388
|
+
var import_path2 = __toModule(require("path"));
|
|
389
|
+
var import_graphql8 = __toModule(require("@tinacms/graphql"));
|
|
390
|
+
var import_chalk2 = __toModule(require("chalk"));
|
|
391
|
+
var auditCollection = async (args) => {
|
|
392
|
+
let warning = false;
|
|
393
|
+
const { collection, database, rootPath: rootPath2 } = args;
|
|
394
|
+
logger.info(`Checking collection ${collection.name}`);
|
|
395
|
+
const query = `query {
|
|
396
|
+
getCollection(collection: "${collection.name}") {
|
|
397
|
+
format
|
|
398
|
+
documents {
|
|
399
|
+
edges {
|
|
400
|
+
node {
|
|
401
|
+
...on Document {
|
|
402
|
+
sys {
|
|
403
|
+
extension
|
|
404
|
+
path
|
|
440
405
|
}
|
|
441
406
|
}
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
process.env.NODE_ENV == 'development'
|
|
461
|
-
? 'http://localhost:4001/graphql'
|
|
462
|
-
: \`https://content.tinajs.io/content/\${process.env.NEXT_PUBLIC_TINA_CLIENT_ID}/github/\${branch}\`
|
|
463
|
-
|
|
464
|
-
export const tinaConfig = defineConfig({
|
|
465
|
-
apiURL,
|
|
466
|
-
cmsCallback: (cms) => {
|
|
467
|
-
// add your CMS callback code here (if you want)
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
`;
|
|
413
|
+
const result = await (0, import_graphql7.resolve)({
|
|
414
|
+
database,
|
|
415
|
+
query,
|
|
416
|
+
variables: {}
|
|
417
|
+
});
|
|
418
|
+
const format = result.data.getCollection.format;
|
|
419
|
+
const docs = result.data.getCollection.documents.edges;
|
|
420
|
+
docs.forEach((x) => {
|
|
421
|
+
const node = x.node;
|
|
422
|
+
if (node.sys.extension.replace(".", "") !== format) {
|
|
423
|
+
warning = true;
|
|
424
|
+
logger.warn(import_chalk2.default.yellowBright(`WARNING: there is a file with extension \`${node.sys.extension}\` but in your schema it is defined to be \`.${format}\`
|
|
468
425
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
426
|
+
location: ${import_path2.default.join(rootPath2, node.sys.path)}`));
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
return warning;
|
|
430
|
+
};
|
|
431
|
+
var auditDocuments = async (args) => {
|
|
432
|
+
const { collection, database, rootPath: rootPath2, useDefaultValues } = args;
|
|
433
|
+
const query = `query {
|
|
434
|
+
getCollection(collection: "${collection.name}") {
|
|
435
|
+
format
|
|
436
|
+
slug
|
|
437
|
+
documents {
|
|
438
|
+
edges {
|
|
439
|
+
node {
|
|
440
|
+
...on Document {
|
|
441
|
+
sys {
|
|
442
|
+
extension
|
|
443
|
+
path
|
|
444
|
+
relativePath
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
`;
|
|
453
|
+
const result = await (0, import_graphql7.resolve)({
|
|
454
|
+
database,
|
|
455
|
+
query,
|
|
456
|
+
variables: {}
|
|
457
|
+
});
|
|
458
|
+
let error = false;
|
|
459
|
+
const documents = result.data.getCollection.documents.edges;
|
|
460
|
+
for (let i = 0; i < documents.length; i++) {
|
|
461
|
+
const node = documents[i].node;
|
|
462
|
+
const fullPath = import_path2.default.join(rootPath2, node.sys.path);
|
|
463
|
+
logger.info(`Checking document: ${fullPath}`);
|
|
464
|
+
const documentQuery = `query {
|
|
465
|
+
getDocument(collection: "${collection.name}", relativePath: "${node.sys.relativePath}") {
|
|
466
|
+
__typename
|
|
467
|
+
...on Document {
|
|
468
|
+
values
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}`;
|
|
472
|
+
const docResult = await (0, import_graphql7.resolve)({
|
|
473
|
+
database,
|
|
474
|
+
query: documentQuery,
|
|
475
|
+
variables: {}
|
|
476
|
+
});
|
|
477
|
+
const topLevelDefaults = {};
|
|
478
|
+
if (useDefaultValues && typeof collection.fields !== "string") {
|
|
479
|
+
collection.fields.filter((x) => !x.list).forEach((x) => {
|
|
480
|
+
const value = x.ui;
|
|
481
|
+
if (typeof value !== "undefined") {
|
|
482
|
+
topLevelDefaults[x.name] = value.defaultValue;
|
|
483
|
+
}
|
|
479
484
|
});
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
485
|
+
}
|
|
486
|
+
const params = transformDocumentIntoMutationRequestPayload(docResult.data.getDocument.values, {
|
|
487
|
+
includeCollection: true,
|
|
488
|
+
includeTemplate: typeof collection.templates !== "undefined"
|
|
489
|
+
}, topLevelDefaults);
|
|
490
|
+
const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
491
|
+
updateDocument(
|
|
492
|
+
collection: $collection,
|
|
493
|
+
relativePath: $relativePath,
|
|
494
|
+
params: $params
|
|
495
|
+
){__typename}
|
|
496
|
+
}`;
|
|
497
|
+
const mutationRes = await (0, import_graphql7.resolve)({
|
|
498
|
+
database,
|
|
499
|
+
query: mutation,
|
|
500
|
+
variables: {
|
|
501
|
+
params,
|
|
502
|
+
collection: collection.name,
|
|
503
|
+
relativePath: node.sys.relativePath
|
|
504
|
+
},
|
|
505
|
+
silenceErrors: true
|
|
484
506
|
});
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getSchemaPath.ts
|
|
492
|
-
var import_path2 = __toModule(require("path"));
|
|
493
|
-
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
494
|
-
var ErrorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
|
|
495
|
-
var getSchemaPath = ({ projectDir }) => {
|
|
496
|
-
if (!import_fs_extra2.default.existsSync(projectDir)) {
|
|
497
|
-
throw new Error(ErrorMessage);
|
|
498
|
-
}
|
|
499
|
-
const inputPathTS = import_path2.default.join(projectDir, "schema.ts");
|
|
500
|
-
const inputPathJS = import_path2.default.join(projectDir, "schema.js");
|
|
501
|
-
const inputPathTSX = import_path2.default.join(projectDir, "schema.tsx");
|
|
502
|
-
const inputPathJSX = import_path2.default.join(projectDir, "schema.jsx");
|
|
503
|
-
let inputFile;
|
|
504
|
-
if (import_fs_extra2.default.existsSync(inputPathTS)) {
|
|
505
|
-
inputFile = inputPathTS;
|
|
506
|
-
} else if (import_fs_extra2.default.existsSync(inputPathJS)) {
|
|
507
|
-
inputFile = inputPathJS;
|
|
508
|
-
} else if (import_fs_extra2.default.existsSync(inputPathTSX)) {
|
|
509
|
-
inputFile = inputPathTSX;
|
|
510
|
-
} else if (import_fs_extra2.default.existsSync(inputPathJSX)) {
|
|
511
|
-
inputFile = inputPathJSX;
|
|
512
|
-
}
|
|
513
|
-
if (!inputFile) {
|
|
514
|
-
throw new Error(ErrorMessage);
|
|
515
|
-
}
|
|
516
|
-
return inputFile;
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/errors/index.ts
|
|
520
|
-
var BuildSchemaError = class extends Error {
|
|
521
|
-
constructor(message) {
|
|
522
|
-
super(message);
|
|
523
|
-
this.name = "BuildSchemaError";
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
var ExecuteSchemaError = class extends Error {
|
|
527
|
-
constructor(message) {
|
|
528
|
-
super(message);
|
|
529
|
-
this.name = "ExecuteSchemaError";
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
var handleServerErrors = (e) => {
|
|
533
|
-
if (e.name === "BuildSchemaError") {
|
|
534
|
-
logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
|
|
535
|
-
Error Message Below
|
|
536
|
-
${e}`);
|
|
537
|
-
} else if (e.name === "ExecuteSchemaError") {
|
|
538
|
-
logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
|
|
539
|
-
Error Message Below
|
|
540
|
-
${e}`);
|
|
541
|
-
} else if (e.name === "TinaSchemaValidationError") {
|
|
542
|
-
logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
|
|
543
|
-
Error Message Below
|
|
544
|
-
${e}`);
|
|
545
|
-
} else {
|
|
546
|
-
logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
|
|
547
|
-
${e.message}`);
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
|
|
552
|
-
var tinaPath = import_path3.default.join(process.cwd(), ".tina");
|
|
553
|
-
var packageJSONFilePath = import_path3.default.join(process.cwd(), "package.json");
|
|
554
|
-
var tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
|
|
555
|
-
var tinaTempPath = import_path3.default.join(tinaGeneratedPath, "temp");
|
|
556
|
-
var tinaConfigPath = import_path3.default.join(tinaGeneratedPath, "config");
|
|
557
|
-
var resetGeneratedFolder = async () => {
|
|
558
|
-
try {
|
|
559
|
-
await import_fs_extra3.default.rmdir(tinaGeneratedPath, {
|
|
560
|
-
recursive: true
|
|
561
|
-
});
|
|
562
|
-
} catch (e) {
|
|
563
|
-
console.log(e);
|
|
507
|
+
if (mutationRes.errors) {
|
|
508
|
+
mutationRes.errors.forEach((err) => {
|
|
509
|
+
error = true;
|
|
510
|
+
logger.error(import_chalk2.default.red(err.message));
|
|
511
|
+
});
|
|
512
|
+
}
|
|
564
513
|
}
|
|
565
|
-
|
|
566
|
-
await import_fs_extra3.default.outputFile(import_path3.default.join(tinaGeneratedPath, ".gitignore"), "db");
|
|
514
|
+
return error;
|
|
567
515
|
};
|
|
568
|
-
var
|
|
569
|
-
|
|
516
|
+
var transformDocumentIntoMutationRequestPayload = (document, instructions, defaults) => {
|
|
517
|
+
const _a = document, { _collection, __typename, _template } = _a, rest = __objRest(_a, ["_collection", "__typename", "_template"]);
|
|
518
|
+
const params = transformParams(rest);
|
|
519
|
+
const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
|
|
520
|
+
return instructions.includeCollection ? { [_collection]: __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate)) } : __spreadValues(__spreadValues({}, defaults), filterObject(paramsWithTemplate));
|
|
570
521
|
};
|
|
571
|
-
var
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
|
|
575
|
-
if (!schemaFileType2) {
|
|
576
|
-
throw new Error(`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`);
|
|
577
|
-
}
|
|
578
|
-
if (_ctx) {
|
|
579
|
-
_ctx.schemaFileType = schemaFileType2;
|
|
580
|
-
}
|
|
581
|
-
let schemaExists = true;
|
|
582
|
-
try {
|
|
583
|
-
getSchemaPath({ projectDir: tinaPath });
|
|
584
|
-
} catch {
|
|
585
|
-
schemaExists = false;
|
|
586
|
-
}
|
|
587
|
-
if (!schemaExists) {
|
|
588
|
-
logger.info(dangerText(`
|
|
589
|
-
.tina/schema.${schemaFileType2} not found, Creating one for you...
|
|
590
|
-
See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
|
|
591
|
-
`));
|
|
592
|
-
const file = import_path3.default.join(tinaPath, `schema.${schemaFileType2}`);
|
|
593
|
-
await import_fs_extra3.default.ensureFile(file);
|
|
594
|
-
await import_fs_extra3.default.writeFile(file, defaultSchema(import_path3.default.sep));
|
|
522
|
+
var transformParams = (data) => {
|
|
523
|
+
if (["string", "number", "boolean"].includes(typeof data)) {
|
|
524
|
+
return data;
|
|
595
525
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
} catch (e) {
|
|
599
|
-
await cleanup({ tinaTempPath });
|
|
600
|
-
throw new BuildSchemaError(e);
|
|
526
|
+
if (Array.isArray(data)) {
|
|
527
|
+
return data.map((item) => transformParams(item));
|
|
601
528
|
}
|
|
602
|
-
Object.keys(require.cache).map((key) => {
|
|
603
|
-
if (key.startsWith(tinaTempPath)) {
|
|
604
|
-
delete require.cache[require.resolve(key)];
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
529
|
try {
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
530
|
+
(0, import_graphql8.assertShape)(data, (yup) => yup.object({ _template: yup.string().required() }));
|
|
531
|
+
const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
|
|
532
|
+
const nested = transformParams(rest);
|
|
533
|
+
return { [_template]: nested };
|
|
612
534
|
} catch (e) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
535
|
+
if (e.message === "Failed to assertShape - _template is a required field") {
|
|
536
|
+
if (!data) {
|
|
537
|
+
return void 0;
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
const accum = {};
|
|
541
|
+
Object.entries(data).map(([keyName, value]) => {
|
|
542
|
+
accum[keyName] = transformParams(value);
|
|
543
|
+
});
|
|
544
|
+
return accum;
|
|
545
|
+
} else {
|
|
546
|
+
if (!data) {
|
|
547
|
+
return void 0;
|
|
548
|
+
return [];
|
|
617
549
|
}
|
|
550
|
+
throw e;
|
|
618
551
|
}
|
|
619
|
-
throw new ExecuteSchemaError(e);
|
|
620
552
|
}
|
|
621
553
|
};
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
628
|
-
const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
|
|
629
|
-
const inputFile = getSchemaPath({ projectDir });
|
|
630
|
-
const outputPath = import_path3.default.join(tempDir, "schema.js");
|
|
631
|
-
await (0, import_esbuild.build)({
|
|
632
|
-
bundle: true,
|
|
633
|
-
platform: "neutral",
|
|
634
|
-
target: ["node10.4"],
|
|
635
|
-
entryPoints: [inputFile],
|
|
636
|
-
treeShaking: true,
|
|
637
|
-
external: [...external, "./node_modules/*"],
|
|
638
|
-
loader: loaders,
|
|
639
|
-
outfile: outputPath
|
|
640
|
-
});
|
|
641
|
-
logger.info(logText(`Javascript built`));
|
|
642
|
-
};
|
|
643
|
-
var defineSchema = (config) => {
|
|
644
|
-
return config;
|
|
645
|
-
};
|
|
646
|
-
var loaders = {
|
|
647
|
-
".aac": "file",
|
|
648
|
-
".css": "file",
|
|
649
|
-
".eot": "file",
|
|
650
|
-
".flac": "file",
|
|
651
|
-
".gif": "file",
|
|
652
|
-
".jpeg": "file",
|
|
653
|
-
".jpg": "file",
|
|
654
|
-
".json": "json",
|
|
655
|
-
".mp3": "file",
|
|
656
|
-
".mp4": "file",
|
|
657
|
-
".ogg": "file",
|
|
658
|
-
".otf": "file",
|
|
659
|
-
".png": "file",
|
|
660
|
-
".svg": "file",
|
|
661
|
-
".ttf": "file",
|
|
662
|
-
".wav": "file",
|
|
663
|
-
".webm": "file",
|
|
664
|
-
".webp": "file",
|
|
665
|
-
".woff": "file",
|
|
666
|
-
".woff2": "file",
|
|
667
|
-
".js": "jsx",
|
|
668
|
-
".jsx": "jsx",
|
|
669
|
-
".tsx": "tsx"
|
|
670
|
-
};
|
|
554
|
+
function filterObject(obj) {
|
|
555
|
+
const ret = {};
|
|
556
|
+
Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
|
|
557
|
+
return ret;
|
|
558
|
+
}
|
|
671
559
|
|
|
672
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
673
|
-
var
|
|
560
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/audit/index.ts
|
|
561
|
+
var import_chalk3 = __toModule(require("chalk"));
|
|
562
|
+
var import_prompts = __toModule(require("prompts"));
|
|
674
563
|
var import_metrics = __toModule(require("@tinacms/metrics"));
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
this.disable = () => {
|
|
680
|
-
};
|
|
681
|
-
this.promise = Promise.resolve();
|
|
682
|
-
}
|
|
683
|
-
enable() {
|
|
684
|
-
this.promise = new Promise((resolve2) => this.disable = resolve2);
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
|
|
689
|
-
var lock = new AsyncLock();
|
|
690
|
-
var gqlPackageFile = require.resolve("@tinacms/graphql");
|
|
691
|
-
async function startServer(_ctx, _next, {
|
|
692
|
-
port = 4001,
|
|
693
|
-
command,
|
|
694
|
-
noWatch,
|
|
695
|
-
experimentalData,
|
|
696
|
-
noSDK,
|
|
697
|
-
noTelemetry,
|
|
698
|
-
watchFolders
|
|
699
|
-
}) {
|
|
700
|
-
lock.disable();
|
|
701
|
-
const rootPath2 = process.cwd();
|
|
702
|
-
const t = new import_metrics.Telemetry({ disabled: Boolean(noTelemetry) });
|
|
703
|
-
t.submitRecord({
|
|
564
|
+
var rootPath = process.cwd();
|
|
565
|
+
var audit = async (ctx, next, options) => {
|
|
566
|
+
const telemetry = new import_metrics.Telemetry({ disabled: options.noTelemetry });
|
|
567
|
+
await telemetry.submitRecord({
|
|
704
568
|
event: {
|
|
705
|
-
name: "tinacms:cli:
|
|
569
|
+
name: "tinacms:cli:audit:invoke",
|
|
570
|
+
clean: Boolean(options.clean),
|
|
571
|
+
useDefaults: Boolean(options.useDefaultValues)
|
|
706
572
|
}
|
|
707
573
|
});
|
|
708
|
-
if (
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
const bridge = new import_datalayer2.FilesystemBridge(rootPath2);
|
|
712
|
-
const store = experimentalData ? new import_datalayer2.LevelStore(rootPath2) : new import_datalayer2.FilesystemStore({ rootPath: rootPath2 });
|
|
713
|
-
const shouldBuild = bridge.supportsBuilding();
|
|
714
|
-
const database = await (0, import_graphql7.createDatabase)({ store, bridge });
|
|
715
|
-
const startSubprocess = () => {
|
|
716
|
-
if (typeof command === "string") {
|
|
717
|
-
const commands = command.split(" ");
|
|
718
|
-
const firstCommand = commands[0];
|
|
719
|
-
const args = commands.slice(1) || [];
|
|
720
|
-
const ps = import_child_process.default.spawn(firstCommand, args, {
|
|
721
|
-
stdio: "inherit",
|
|
722
|
-
shell: true
|
|
723
|
-
});
|
|
724
|
-
ps.on("error", (code) => {
|
|
725
|
-
logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
|
|
726
|
-
logger.error(`name: ${code.name}
|
|
727
|
-
message: ${code.message}
|
|
574
|
+
if (options.clean) {
|
|
575
|
+
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_chalk3.default.bold("clean git tree")} so unwanted changes can be undone.
|
|
728
576
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
const build2 = async (noSDK2) => {
|
|
739
|
-
await lock.promise;
|
|
740
|
-
lock.enable();
|
|
741
|
-
try {
|
|
742
|
-
if (!process.env.CI && !noWatch) {
|
|
743
|
-
await resetGeneratedFolder();
|
|
744
|
-
}
|
|
745
|
-
const database2 = await (0, import_graphql7.createDatabase)({ store, bridge });
|
|
746
|
-
await compile(null, null);
|
|
747
|
-
const schema = await (0, import_graphql7.buildSchema)(rootPath2, database2);
|
|
748
|
-
await genTypes({ schema }, () => {
|
|
749
|
-
}, { noSDK: noSDK2 });
|
|
750
|
-
} catch (error) {
|
|
751
|
-
throw error;
|
|
752
|
-
} finally {
|
|
753
|
-
lock.disable();
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
const foldersToWatch = (watchFolders || []).map((x) => import_path4.default.join(rootPath2, x));
|
|
757
|
-
if (!noWatch && !process.env.CI) {
|
|
758
|
-
import_chokidar.default.watch([
|
|
759
|
-
...foldersToWatch,
|
|
760
|
-
`${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
|
|
761
|
-
], {
|
|
762
|
-
ignored: [
|
|
763
|
-
"**/node_modules/**/*",
|
|
764
|
-
"**/.next/**/*",
|
|
765
|
-
`${import_path4.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
766
|
-
]
|
|
767
|
-
}).on("ready", async () => {
|
|
768
|
-
console.log("Generating Tina config");
|
|
769
|
-
try {
|
|
770
|
-
if (shouldBuild) {
|
|
771
|
-
await build2(noSDK);
|
|
772
|
-
}
|
|
773
|
-
ready = true;
|
|
774
|
-
startSubprocess();
|
|
775
|
-
} catch (e) {
|
|
776
|
-
handleServerErrors(e);
|
|
777
|
-
console.log(e);
|
|
778
|
-
process.exit(0);
|
|
779
|
-
}
|
|
780
|
-
}).on("all", async () => {
|
|
781
|
-
if (ready) {
|
|
782
|
-
logger.info("Tina change detected, regenerating config");
|
|
783
|
-
try {
|
|
784
|
-
if (shouldBuild) {
|
|
785
|
-
await build2(noSDK);
|
|
786
|
-
}
|
|
787
|
-
} catch (e) {
|
|
788
|
-
handleServerErrors(e);
|
|
789
|
-
t.submitRecord({
|
|
790
|
-
event: {
|
|
791
|
-
name: "tinacms:cli:server:error",
|
|
792
|
-
errorMessage: e.message
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
} else {
|
|
799
|
-
if (shouldBuild) {
|
|
800
|
-
await build2(noSDK);
|
|
577
|
+
`);
|
|
578
|
+
const res = await (0, import_prompts.default)({
|
|
579
|
+
name: "useClean",
|
|
580
|
+
type: "confirm",
|
|
581
|
+
message: `Do you want to continue?`
|
|
582
|
+
});
|
|
583
|
+
if (!res.useClean) {
|
|
584
|
+
logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
585
|
+
process.exit(0);
|
|
801
586
|
}
|
|
802
587
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
throw e;
|
|
821
|
-
});
|
|
822
|
-
state.server.on("connection", (socket) => {
|
|
823
|
-
state.sockets.push(socket);
|
|
824
|
-
});
|
|
825
|
-
};
|
|
826
|
-
const restart = async () => {
|
|
827
|
-
logger.info("Detected change to gql package, restarting...");
|
|
828
|
-
delete require.cache[gqlPackageFile];
|
|
829
|
-
state.sockets.forEach((socket) => {
|
|
830
|
-
if (socket.destroyed === false) {
|
|
831
|
-
socket.destroy();
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
state.sockets = [];
|
|
835
|
-
state.server.close(() => {
|
|
836
|
-
logger.info("Server closed");
|
|
837
|
-
start();
|
|
588
|
+
if (options.useDefaultValues && !options.clean) {
|
|
589
|
+
logger.warn(import_chalk3.default.yellowBright("WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"));
|
|
590
|
+
}
|
|
591
|
+
const bridge = options.clean ? new import_datalayer2.FilesystemBridge(rootPath) : new import_datalayer2.AuditFileSystemBridge(rootPath);
|
|
592
|
+
const store = options.clean ? new import_datalayer2.FilesystemStore({ rootPath }) : new import_datalayer2.AuditFilesystemStore({ rootPath });
|
|
593
|
+
const database = await (0, import_graphql9.createDatabase)({ store, bridge });
|
|
594
|
+
const schema = await database.getSchema();
|
|
595
|
+
const collections = schema.getCollections();
|
|
596
|
+
let warning = false;
|
|
597
|
+
let error = false;
|
|
598
|
+
for (let i = 0; i < collections.length; i++) {
|
|
599
|
+
const collection = collections[i];
|
|
600
|
+
const returnWarning = await auditCollection({
|
|
601
|
+
collection,
|
|
602
|
+
database,
|
|
603
|
+
rootPath,
|
|
604
|
+
useDefaultValues: options.useDefaultValues
|
|
838
605
|
});
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
}).on("all", async () => {
|
|
845
|
-
if (isReady) {
|
|
846
|
-
restart();
|
|
847
|
-
}
|
|
606
|
+
const returnError = await auditDocuments({
|
|
607
|
+
collection,
|
|
608
|
+
database,
|
|
609
|
+
rootPath,
|
|
610
|
+
useDefaultValues: options.useDefaultValues
|
|
848
611
|
});
|
|
612
|
+
warning = warning || returnWarning;
|
|
613
|
+
error = error || returnError;
|
|
614
|
+
}
|
|
615
|
+
ctx.warning = warning;
|
|
616
|
+
ctx.error = error;
|
|
617
|
+
next();
|
|
618
|
+
};
|
|
619
|
+
var printFinalMessage = async (ctx, next, _options) => {
|
|
620
|
+
if (ctx.error) {
|
|
621
|
+
logger.error(import_chalk3.default.redBright(`\u203C\uFE0F Audit ${import_chalk3.default.bold("failed")} with errors`));
|
|
622
|
+
} else if (ctx.warning) {
|
|
623
|
+
logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
|
|
849
624
|
} else {
|
|
850
|
-
|
|
851
|
-
logger.info("Detected CI environment, omitting watch commands...");
|
|
852
|
-
}
|
|
853
|
-
start();
|
|
854
|
-
startSubprocess();
|
|
625
|
+
logger.info(import_chalk3.default.greenBright("\u2705 Audit passed"));
|
|
855
626
|
}
|
|
856
|
-
|
|
627
|
+
next();
|
|
628
|
+
};
|
|
857
629
|
|
|
858
630
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
|
|
859
|
-
var
|
|
631
|
+
var import_chalk4 = __toModule(require("chalk"));
|
|
860
632
|
var adminPage = `import { TinaAdmin } from 'tinacms';
|
|
861
633
|
export default TinaAdmin;
|
|
862
634
|
`;
|
|
@@ -1169,15 +941,15 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
|
|
|
1169
941
|
|
|
1170
942
|
`;
|
|
1171
943
|
var AppJsContent = (usingSrc, extraImports) => {
|
|
1172
|
-
const importLine =
|
|
944
|
+
const importLine = import_chalk4.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
|
|
1173
945
|
return `${importLine}
|
|
1174
946
|
${extraImports || ""}
|
|
1175
947
|
|
|
1176
948
|
const App = ({ Component, pageProps }) => {
|
|
1177
949
|
return (
|
|
1178
|
-
${
|
|
950
|
+
${import_chalk4.default.green("+ <Tina>")}
|
|
1179
951
|
<Component {...pageProps} />
|
|
1180
|
-
${
|
|
952
|
+
${import_chalk4.default.green("+ </Tina>")}
|
|
1181
953
|
)
|
|
1182
954
|
}
|
|
1183
955
|
|
|
@@ -1231,12 +1003,12 @@ function extendNextScripts(scripts) {
|
|
|
1231
1003
|
}
|
|
1232
1004
|
|
|
1233
1005
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
|
|
1234
|
-
var
|
|
1006
|
+
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
1235
1007
|
var import_progress = __toModule(require("progress"));
|
|
1236
1008
|
var import_metrics2 = __toModule(require("@tinacms/metrics"));
|
|
1237
|
-
var
|
|
1238
|
-
var
|
|
1239
|
-
var
|
|
1009
|
+
var import_chalk5 = __toModule(require("chalk"));
|
|
1010
|
+
var import_path3 = __toModule(require("path"));
|
|
1011
|
+
var import_prompts2 = __toModule(require("prompts"));
|
|
1240
1012
|
function execShellCommand(cmd) {
|
|
1241
1013
|
const exec = require("child_process").exec;
|
|
1242
1014
|
return new Promise((resolve2, _reject) => {
|
|
@@ -1262,7 +1034,7 @@ async function initTina(ctx, next, options) {
|
|
|
1262
1034
|
var MIN_REACT_VERSION = ">=16.14.0";
|
|
1263
1035
|
async function checkDeps(ctx, next, options) {
|
|
1264
1036
|
const bar = new import_progress.default("Checking dependencies. :prog", 1);
|
|
1265
|
-
const packageJSON = JSON.parse((await
|
|
1037
|
+
const packageJSON = JSON.parse((await import_fs_extra2.default.readFileSync(packageJSONPath)).toString());
|
|
1266
1038
|
if (!checkPackage(packageJSON, "react") || !checkPackage(packageJSON, "react-dom")) {
|
|
1267
1039
|
const message = `Unable to initialize Tina due to outdated dependencies, try upgrading the following packages:
|
|
1268
1040
|
"react@${MIN_REACT_VERSION}"
|
|
@@ -1328,348 +1100,600 @@ async function installDeps(ctx, next, options) {
|
|
|
1328
1100
|
next();
|
|
1329
1101
|
}
|
|
1330
1102
|
var baseDir = process.cwd();
|
|
1331
|
-
var packageJSONPath =
|
|
1332
|
-
var blogContentPath =
|
|
1333
|
-
var blogPostPath =
|
|
1334
|
-
var TinaFolder =
|
|
1335
|
-
var componentFolder =
|
|
1336
|
-
var TinaProviderPath =
|
|
1337
|
-
var TinaDynamicProvider =
|
|
1103
|
+
var packageJSONPath = import_path3.default.join(baseDir, "package.json");
|
|
1104
|
+
var blogContentPath = import_path3.default.join(baseDir, "content", "posts");
|
|
1105
|
+
var blogPostPath = import_path3.default.join(blogContentPath, "HelloWorld.md");
|
|
1106
|
+
var TinaFolder = import_path3.default.join(baseDir, ".tina");
|
|
1107
|
+
var componentFolder = import_path3.default.join(TinaFolder, "components");
|
|
1108
|
+
var TinaProviderPath = import_path3.default.join(componentFolder, "TinaProvider.js");
|
|
1109
|
+
var TinaDynamicProvider = import_path3.default.join(componentFolder, "TinaDynamicProvider.js");
|
|
1338
1110
|
async function tinaSetup(_ctx, next, _options) {
|
|
1339
|
-
const usingSrc =
|
|
1340
|
-
if (!
|
|
1111
|
+
const usingSrc = import_fs_extra2.default.pathExistsSync(import_path3.default.join(baseDir, "src"));
|
|
1112
|
+
if (!import_fs_extra2.default.pathExistsSync(blogPostPath)) {
|
|
1341
1113
|
logger.info(logText("Adding a content folder..."));
|
|
1342
|
-
|
|
1343
|
-
|
|
1114
|
+
import_fs_extra2.default.mkdirpSync(blogContentPath);
|
|
1115
|
+
import_fs_extra2.default.writeFileSync(blogPostPath, blogPost);
|
|
1344
1116
|
}
|
|
1345
|
-
if (!
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1117
|
+
if (!import_fs_extra2.default.existsSync(TinaProviderPath) && !import_fs_extra2.default.existsSync(TinaDynamicProvider)) {
|
|
1118
|
+
import_fs_extra2.default.mkdirpSync(componentFolder);
|
|
1119
|
+
import_fs_extra2.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.schemaFileType || "ts"}'`));
|
|
1120
|
+
import_fs_extra2.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
|
|
1349
1121
|
}
|
|
1350
1122
|
logger.level = "info";
|
|
1351
|
-
const pagesPath =
|
|
1352
|
-
const appPath =
|
|
1353
|
-
const appPathTS =
|
|
1354
|
-
const appExtension =
|
|
1355
|
-
if (!
|
|
1123
|
+
const pagesPath = import_path3.default.join(baseDir, usingSrc ? "src" : "", "pages");
|
|
1124
|
+
const appPath = import_path3.default.join(pagesPath, "_app.js");
|
|
1125
|
+
const appPathTS = import_path3.default.join(pagesPath, "_app.tsx");
|
|
1126
|
+
const appExtension = import_fs_extra2.default.existsSync(appPath) ? ".js" : ".tsx";
|
|
1127
|
+
if (!import_fs_extra2.default.pathExistsSync(appPath) && !import_fs_extra2.default.pathExistsSync(appPathTS)) {
|
|
1356
1128
|
logger.info(logText("Adding _app.js ... \u2705"));
|
|
1357
|
-
|
|
1129
|
+
import_fs_extra2.default.writeFileSync(appPath, AppJsContent(usingSrc));
|
|
1358
1130
|
} else {
|
|
1359
|
-
const override = await (0,
|
|
1131
|
+
const override = await (0, import_prompts2.default)({
|
|
1360
1132
|
name: "res",
|
|
1361
1133
|
type: "confirm",
|
|
1362
|
-
message: `do you want us to ${
|
|
1134
|
+
message: `do you want us to ${import_chalk5.default.bold(`override`)} your _app${appExtension}?`
|
|
1363
1135
|
});
|
|
1364
1136
|
_ctx.overrideApp = override.res;
|
|
1365
1137
|
if (override.res) {
|
|
1366
1138
|
logger.info(logText(`Adding _app${appExtension} ... \u2705`));
|
|
1367
|
-
const appPathWithExtension =
|
|
1368
|
-
const fileContent =
|
|
1139
|
+
const appPathWithExtension = import_path3.default.join(pagesPath, `_app${appExtension}`);
|
|
1140
|
+
const fileContent = import_fs_extra2.default.pathExistsSync(appPath) ? (0, import_fs_extra2.readFileSync)(appPath) : (0, import_fs_extra2.readFileSync)(appPathTS);
|
|
1369
1141
|
const matches = [
|
|
1370
1142
|
...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
|
|
1371
1143
|
];
|
|
1372
1144
|
const primaryMatches = matches.map((x) => x[0]);
|
|
1373
|
-
|
|
1145
|
+
import_fs_extra2.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
|
|
1374
1146
|
}
|
|
1375
1147
|
}
|
|
1376
|
-
const tinaBlogPagePath =
|
|
1377
|
-
const tinaBlogPagePathFile =
|
|
1378
|
-
if (!
|
|
1379
|
-
|
|
1380
|
-
|
|
1148
|
+
const tinaBlogPagePath = import_path3.default.join(pagesPath, "demo", "blog");
|
|
1149
|
+
const tinaBlogPagePathFile = import_path3.default.join(tinaBlogPagePath, "[filename].js");
|
|
1150
|
+
if (!import_fs_extra2.default.pathExistsSync(tinaBlogPagePathFile)) {
|
|
1151
|
+
import_fs_extra2.default.mkdirpSync(tinaBlogPagePath);
|
|
1152
|
+
import_fs_extra2.default.writeFileSync(tinaBlogPagePathFile, nextPostPage());
|
|
1381
1153
|
}
|
|
1382
1154
|
logger.info("Adding a content folder... \u2705");
|
|
1383
|
-
const packagePath =
|
|
1384
|
-
const pack = JSON.parse((0,
|
|
1155
|
+
const packagePath = import_path3.default.join(baseDir, "package.json");
|
|
1156
|
+
const pack = JSON.parse((0, import_fs_extra2.readFileSync)(packagePath).toString());
|
|
1385
1157
|
const oldScripts = pack.scripts || {};
|
|
1386
1158
|
const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
|
|
1387
1159
|
scripts: extendNextScripts(oldScripts)
|
|
1388
1160
|
}), null, 2);
|
|
1389
|
-
(0,
|
|
1390
|
-
const adminPath =
|
|
1391
|
-
if (
|
|
1161
|
+
(0, import_fs_extra2.writeFileSync)(packagePath, newPack);
|
|
1162
|
+
const adminPath = import_path3.default.join(pagesPath, "admin.js");
|
|
1163
|
+
if (import_fs_extra2.default.pathExistsSync(import_path3.default.join(pagesPath, "admin"))) {
|
|
1392
1164
|
logger.warn(`Unable to add /pages/admin.js, this path already exists.
|
|
1393
1165
|
Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
|
|
1394
1166
|
return next();
|
|
1395
1167
|
}
|
|
1396
|
-
(0,
|
|
1168
|
+
(0, import_fs_extra2.outputFileSync)(adminPath, adminPage);
|
|
1397
1169
|
next();
|
|
1398
1170
|
}
|
|
1399
1171
|
async function successMessage(ctx, next, options) {
|
|
1400
|
-
const usingSrc =
|
|
1401
|
-
logger.info(`Tina setup ${
|
|
1172
|
+
const usingSrc = import_fs_extra2.default.pathExistsSync(import_path3.default.join(baseDir, "src"));
|
|
1173
|
+
logger.info(`Tina setup ${import_chalk5.default.underline.green("done")} \u2705
|
|
1402
1174
|
`);
|
|
1403
1175
|
logger.info("Next Steps: \n");
|
|
1404
1176
|
if (!ctx.overrideApp) {
|
|
1405
|
-
logger.info(`${
|
|
1177
|
+
logger.info(`${import_chalk5.default.bold("Add the Tina wrapper")}`);
|
|
1406
1178
|
logger.info(`\u26A0\uFE0F Before using Tina, you will NEED to add the Tina wrapper to your _app.jsx
|
|
1407
1179
|
`);
|
|
1408
1180
|
logger.info(`${AppJsContent(usingSrc)}`);
|
|
1409
1181
|
}
|
|
1410
|
-
logger.info(`${
|
|
1182
|
+
logger.info(`${import_chalk5.default.bold("Run your site with Tina")}`);
|
|
1411
1183
|
logger.info(` yarn dev
|
|
1412
1184
|
`);
|
|
1413
|
-
logger.info(`${
|
|
1185
|
+
logger.info(`${import_chalk5.default.bold("Start Editing")}`);
|
|
1414
1186
|
logger.info(` Go to 'http://localhost:3000/admin'
|
|
1415
1187
|
`);
|
|
1416
|
-
logger.info(`${
|
|
1188
|
+
logger.info(`${import_chalk5.default.bold("Read the docs")}`);
|
|
1417
1189
|
logger.info(` Check out 'https://tina.io/docs/introduction/tina-init/#adding-tina' for help getting started with Tina
|
|
1418
1190
|
`);
|
|
1419
1191
|
logger.info(`Enjoy Tina! \u{1F999}`);
|
|
1420
1192
|
next();
|
|
1421
1193
|
}
|
|
1422
1194
|
|
|
1423
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/
|
|
1424
|
-
var
|
|
1425
|
-
|
|
1195
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/middleware.ts
|
|
1196
|
+
var chain = async (cmds, options) => {
|
|
1197
|
+
const ctx = {};
|
|
1198
|
+
const next = async (middlewareIndex) => {
|
|
1199
|
+
if (middlewareIndex >= cmds.length) {
|
|
1200
|
+
process.exit(0);
|
|
1201
|
+
}
|
|
1202
|
+
try {
|
|
1203
|
+
await cmds[middlewareIndex](ctx, () => next(middlewareIndex + 1), options || {});
|
|
1204
|
+
} catch (err) {
|
|
1205
|
+
console.error(` ${dangerText(err)}`);
|
|
1206
|
+
process.exit(1);
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
if (cmds.length > 0) {
|
|
1210
|
+
await next(0);
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1426
1213
|
|
|
1427
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
1428
|
-
var
|
|
1429
|
-
var import_path6 = __toModule(require("path"));
|
|
1430
|
-
var import_graphql9 = __toModule(require("@tinacms/graphql"));
|
|
1431
|
-
var import_chalk4 = __toModule(require("chalk"));
|
|
1432
|
-
var auditCollection = async (args) => {
|
|
1433
|
-
let warning = false;
|
|
1434
|
-
const { collection, database, rootPath: rootPath2 } = args;
|
|
1435
|
-
logger.info(`Checking collection ${collection.name}`);
|
|
1436
|
-
const query = `query {
|
|
1437
|
-
getCollection(collection: "${collection.name}") {
|
|
1438
|
-
format
|
|
1439
|
-
documents {
|
|
1440
|
-
edges {
|
|
1441
|
-
node {
|
|
1442
|
-
...on Document {
|
|
1443
|
-
sys {
|
|
1444
|
-
extension
|
|
1445
|
-
path
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
`;
|
|
1454
|
-
const result = await (0, import_graphql8.resolve)({
|
|
1455
|
-
database,
|
|
1456
|
-
query,
|
|
1457
|
-
variables: {}
|
|
1458
|
-
});
|
|
1459
|
-
const format = result.data.getCollection.format;
|
|
1460
|
-
const docs = result.data.getCollection.documents.edges;
|
|
1461
|
-
docs.forEach((x) => {
|
|
1462
|
-
const node = x.node;
|
|
1463
|
-
if (node.sys.extension.replace(".", "") !== format) {
|
|
1464
|
-
warning = true;
|
|
1465
|
-
logger.warn(import_chalk4.default.yellowBright(`WARNING: there is a file with extension \`${node.sys.extension}\` but in your schema it is defined to be \`.${format}\`
|
|
1214
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
|
|
1215
|
+
var import_chalk7 = __toModule(require("chalk"));
|
|
1466
1216
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1217
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/errors/index.ts
|
|
1218
|
+
var BuildSchemaError = class extends Error {
|
|
1219
|
+
constructor(message) {
|
|
1220
|
+
super(message);
|
|
1221
|
+
this.name = "BuildSchemaError";
|
|
1222
|
+
}
|
|
1471
1223
|
};
|
|
1472
|
-
var
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1224
|
+
var ExecuteSchemaError = class extends Error {
|
|
1225
|
+
constructor(message) {
|
|
1226
|
+
super(message);
|
|
1227
|
+
this.name = "ExecuteSchemaError";
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
var handleServerErrors = (e) => {
|
|
1231
|
+
if (e.name === "BuildSchemaError") {
|
|
1232
|
+
logger.error(`${dangerText("ERROR: your schema was not successfully built: see https://tina.io/docs/errors/esbuild-error/ for more details")}
|
|
1233
|
+
Error Message Below
|
|
1234
|
+
${e}`);
|
|
1235
|
+
} else if (e.name === "ExecuteSchemaError") {
|
|
1236
|
+
logger.error(`${dangerText("ERROR: your schema was not successfully executed: see https://tina.io/docs/errors/esbuild-error/ for more details")}
|
|
1237
|
+
Error Message Below
|
|
1238
|
+
${e}`);
|
|
1239
|
+
} else if (e.name === "TinaSchemaValidationError") {
|
|
1240
|
+
logger.error(`${dangerText("ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema")}
|
|
1241
|
+
Error Message Below
|
|
1242
|
+
${e}`);
|
|
1243
|
+
} else {
|
|
1244
|
+
logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
|
|
1245
|
+
${e.message}`);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
|
|
1250
|
+
var import_fs_extra4 = __toModule(require("fs-extra"));
|
|
1251
|
+
var import_path5 = __toModule(require("path"));
|
|
1252
|
+
var import_esbuild = __toModule(require("esbuild"));
|
|
1253
|
+
|
|
1254
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/defaultSchema.ts
|
|
1255
|
+
var defaultSchema = (sep) => `
|
|
1256
|
+
import { defineSchema, defineConfig } from "tinacms";
|
|
1257
|
+
|
|
1258
|
+
export default defineSchema({
|
|
1259
|
+
collections: [
|
|
1260
|
+
{
|
|
1261
|
+
label: "Blog Posts",
|
|
1262
|
+
name: "posts",
|
|
1263
|
+
path: "content${sep}posts",
|
|
1264
|
+
fields: [
|
|
1265
|
+
{
|
|
1266
|
+
type: "string",
|
|
1267
|
+
label: "Title",
|
|
1268
|
+
name: "title",
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
type: "rich-text",
|
|
1272
|
+
label: "Blog Post Body",
|
|
1273
|
+
name: "body",
|
|
1274
|
+
isBody: true,
|
|
1275
|
+
templates: [
|
|
1276
|
+
{
|
|
1277
|
+
name: "PageSection",
|
|
1278
|
+
label: "Page Section",
|
|
1279
|
+
fields: [
|
|
1280
|
+
{
|
|
1281
|
+
type: "string",
|
|
1282
|
+
name: "heading",
|
|
1283
|
+
label: "Heading",
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
type: "string",
|
|
1287
|
+
name: "content",
|
|
1288
|
+
label: "Content",
|
|
1289
|
+
ui: {
|
|
1290
|
+
component: "textarea"
|
|
1486
1291
|
}
|
|
1487
1292
|
}
|
|
1488
|
-
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1293
|
+
],
|
|
1294
|
+
},
|
|
1295
|
+
]
|
|
1296
|
+
},
|
|
1297
|
+
],
|
|
1298
|
+
},
|
|
1299
|
+
],
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
// Your tina config
|
|
1306
|
+
// ==============
|
|
1307
|
+
const branch = 'main'
|
|
1308
|
+
// When working locally, hit our local filesystem.
|
|
1309
|
+
// On a Vercel deployment, hit the Tina Cloud API
|
|
1310
|
+
const apiURL =
|
|
1311
|
+
process.env.NODE_ENV == 'development'
|
|
1312
|
+
? 'http://localhost:4001/graphql'
|
|
1313
|
+
: \`https://content.tinajs.io/content/\${process.env.NEXT_PUBLIC_TINA_CLIENT_ID}/github/\${branch}\`
|
|
1314
|
+
|
|
1315
|
+
export const tinaConfig = defineConfig({
|
|
1316
|
+
apiURL,
|
|
1317
|
+
cmsCallback: (cms) => {
|
|
1318
|
+
// add your CMS callback code here (if you want)
|
|
1319
|
+
|
|
1320
|
+
// The Route Mapper
|
|
1321
|
+
/**
|
|
1322
|
+
* 1. Import \`tinacms\` and \`RouteMappingPlugin\`
|
|
1323
|
+
**/
|
|
1324
|
+
import("tinacms").then(({ RouteMappingPlugin }) => {
|
|
1325
|
+
/**
|
|
1326
|
+
* 2. Define the \`RouteMappingPlugin\` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details
|
|
1327
|
+
**/
|
|
1328
|
+
const RouteMapping = new RouteMappingPlugin((collection, document) => {
|
|
1329
|
+
return undefined;
|
|
1525
1330
|
});
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
}, topLevelDefaults);
|
|
1531
|
-
const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
1532
|
-
updateDocument(
|
|
1533
|
-
collection: $collection,
|
|
1534
|
-
relativePath: $relativePath,
|
|
1535
|
-
params: $params
|
|
1536
|
-
){__typename}
|
|
1537
|
-
}`;
|
|
1538
|
-
const mutationRes = await (0, import_graphql8.resolve)({
|
|
1539
|
-
database,
|
|
1540
|
-
query: mutation,
|
|
1541
|
-
variables: {
|
|
1542
|
-
params,
|
|
1543
|
-
collection: collection.name,
|
|
1544
|
-
relativePath: node.sys.relativePath
|
|
1545
|
-
},
|
|
1546
|
-
silenceErrors: true
|
|
1331
|
+
/**
|
|
1332
|
+
* 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
|
|
1333
|
+
**/
|
|
1334
|
+
cms.plugins.add(RouteMapping);
|
|
1547
1335
|
});
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1336
|
+
|
|
1337
|
+
return cms;
|
|
1338
|
+
},
|
|
1339
|
+
});
|
|
1340
|
+
`;
|
|
1341
|
+
|
|
1342
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/lib/getSchemaPath.ts
|
|
1343
|
+
var import_path4 = __toModule(require("path"));
|
|
1344
|
+
var import_fs_extra3 = __toModule(require("fs-extra"));
|
|
1345
|
+
var ErrorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
|
|
1346
|
+
var getSchemaPath = ({ projectDir }) => {
|
|
1347
|
+
if (!import_fs_extra3.default.existsSync(projectDir)) {
|
|
1348
|
+
throw new Error(ErrorMessage);
|
|
1349
|
+
}
|
|
1350
|
+
const inputPathTS = import_path4.default.join(projectDir, "schema.ts");
|
|
1351
|
+
const inputPathJS = import_path4.default.join(projectDir, "schema.js");
|
|
1352
|
+
const inputPathTSX = import_path4.default.join(projectDir, "schema.tsx");
|
|
1353
|
+
const inputPathJSX = import_path4.default.join(projectDir, "schema.jsx");
|
|
1354
|
+
let inputFile;
|
|
1355
|
+
if (import_fs_extra3.default.existsSync(inputPathTS)) {
|
|
1356
|
+
inputFile = inputPathTS;
|
|
1357
|
+
} else if (import_fs_extra3.default.existsSync(inputPathJS)) {
|
|
1358
|
+
inputFile = inputPathJS;
|
|
1359
|
+
} else if (import_fs_extra3.default.existsSync(inputPathTSX)) {
|
|
1360
|
+
inputFile = inputPathTSX;
|
|
1361
|
+
} else if (import_fs_extra3.default.existsSync(inputPathJSX)) {
|
|
1362
|
+
inputFile = inputPathJSX;
|
|
1363
|
+
}
|
|
1364
|
+
if (!inputFile) {
|
|
1365
|
+
throw new Error(ErrorMessage);
|
|
1366
|
+
}
|
|
1367
|
+
return inputFile;
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/compile/index.ts
|
|
1371
|
+
var tinaPath = import_path5.default.join(process.cwd(), ".tina");
|
|
1372
|
+
var packageJSONFilePath = import_path5.default.join(process.cwd(), "package.json");
|
|
1373
|
+
var tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
|
|
1374
|
+
var tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp");
|
|
1375
|
+
var tinaConfigPath = import_path5.default.join(tinaGeneratedPath, "config");
|
|
1376
|
+
var resetGeneratedFolder = async () => {
|
|
1377
|
+
try {
|
|
1378
|
+
await import_fs_extra4.default.rmdir(tinaGeneratedPath, {
|
|
1379
|
+
recursive: true
|
|
1380
|
+
});
|
|
1381
|
+
} catch (e) {
|
|
1382
|
+
console.log(e);
|
|
1383
|
+
}
|
|
1384
|
+
await import_fs_extra4.default.mkdir(tinaGeneratedPath);
|
|
1385
|
+
await import_fs_extra4.default.outputFile(import_path5.default.join(tinaGeneratedPath, ".gitignore"), "db");
|
|
1386
|
+
};
|
|
1387
|
+
var cleanup = async ({ tinaTempPath: tinaTempPath2 }) => {
|
|
1388
|
+
await import_fs_extra4.default.remove(tinaTempPath2);
|
|
1389
|
+
};
|
|
1390
|
+
var compile = async (_ctx, _next, options) => {
|
|
1391
|
+
if (!options.schemaFileType)
|
|
1392
|
+
options = __spreadProps(__spreadValues({}, options), { schemaFileType: "ts" });
|
|
1393
|
+
if (options.verbose) {
|
|
1394
|
+
logger.info(logText("Compiling..."));
|
|
1395
|
+
}
|
|
1396
|
+
const { schemaFileType: requestedSchemaFileType = "ts" } = options;
|
|
1397
|
+
const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
|
|
1398
|
+
if (!schemaFileType2) {
|
|
1399
|
+
throw new Error(`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`);
|
|
1400
|
+
}
|
|
1401
|
+
if (_ctx) {
|
|
1402
|
+
_ctx.schemaFileType = schemaFileType2;
|
|
1403
|
+
}
|
|
1404
|
+
let schemaExists = true;
|
|
1405
|
+
try {
|
|
1406
|
+
getSchemaPath({ projectDir: tinaPath });
|
|
1407
|
+
} catch {
|
|
1408
|
+
schemaExists = false;
|
|
1409
|
+
}
|
|
1410
|
+
if (!schemaExists) {
|
|
1411
|
+
logger.info(dangerText(`
|
|
1412
|
+
.tina/schema.${schemaFileType2} not found, Creating one for you...
|
|
1413
|
+
See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
|
|
1414
|
+
`));
|
|
1415
|
+
const file = import_path5.default.join(tinaPath, `schema.${schemaFileType2}`);
|
|
1416
|
+
await import_fs_extra4.default.ensureFile(file);
|
|
1417
|
+
await import_fs_extra4.default.writeFile(file, defaultSchema(import_path5.default.sep));
|
|
1418
|
+
}
|
|
1419
|
+
try {
|
|
1420
|
+
await transpile(tinaPath, tinaTempPath, options.verbose);
|
|
1421
|
+
} catch (e) {
|
|
1422
|
+
await cleanup({ tinaTempPath });
|
|
1423
|
+
throw new BuildSchemaError(e);
|
|
1424
|
+
}
|
|
1425
|
+
Object.keys(require.cache).map((key) => {
|
|
1426
|
+
if (key.startsWith(tinaTempPath)) {
|
|
1427
|
+
delete require.cache[require.resolve(key)];
|
|
1553
1428
|
}
|
|
1429
|
+
});
|
|
1430
|
+
try {
|
|
1431
|
+
const schemaFunc = require(import_path5.default.join(tinaTempPath, "schema.js"));
|
|
1432
|
+
const schemaObject = schemaFunc.default;
|
|
1433
|
+
await import_fs_extra4.default.outputFile(import_path5.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
|
|
1434
|
+
await cleanup({ tinaTempPath });
|
|
1435
|
+
} catch (e) {
|
|
1436
|
+
await cleanup({ tinaTempPath });
|
|
1437
|
+
if (e instanceof Error) {
|
|
1438
|
+
if (e.name === "TinaSchemaValidationError") {
|
|
1439
|
+
throw e;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
throw new ExecuteSchemaError(e);
|
|
1554
1443
|
}
|
|
1555
|
-
return error;
|
|
1556
1444
|
};
|
|
1557
|
-
var
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1445
|
+
var transpile = async (projectDir, tempDir, verbose) => {
|
|
1446
|
+
if (verbose)
|
|
1447
|
+
logger.info(logText("Building javascript..."));
|
|
1448
|
+
const packageJSON = JSON.parse(import_fs_extra4.default.readFileSync(packageJSONFilePath).toString() || "{}");
|
|
1449
|
+
const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
|
|
1450
|
+
const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
|
|
1451
|
+
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
1452
|
+
const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
|
|
1453
|
+
const inputFile = getSchemaPath({ projectDir });
|
|
1454
|
+
const outputPath = import_path5.default.join(tempDir, "schema.js");
|
|
1455
|
+
await (0, import_esbuild.build)({
|
|
1456
|
+
bundle: true,
|
|
1457
|
+
platform: "neutral",
|
|
1458
|
+
target: ["node10.4"],
|
|
1459
|
+
entryPoints: [inputFile],
|
|
1460
|
+
treeShaking: true,
|
|
1461
|
+
external: [...external, "./node_modules/*"],
|
|
1462
|
+
loader: loaders,
|
|
1463
|
+
outfile: outputPath
|
|
1464
|
+
});
|
|
1465
|
+
if (verbose)
|
|
1466
|
+
logger.info(logText(`Javascript built`));
|
|
1467
|
+
};
|
|
1468
|
+
var defineSchema = (config) => {
|
|
1469
|
+
return config;
|
|
1470
|
+
};
|
|
1471
|
+
var loaders = {
|
|
1472
|
+
".aac": "file",
|
|
1473
|
+
".css": "file",
|
|
1474
|
+
".eot": "file",
|
|
1475
|
+
".flac": "file",
|
|
1476
|
+
".gif": "file",
|
|
1477
|
+
".jpeg": "file",
|
|
1478
|
+
".jpg": "file",
|
|
1479
|
+
".json": "json",
|
|
1480
|
+
".mp3": "file",
|
|
1481
|
+
".mp4": "file",
|
|
1482
|
+
".ogg": "file",
|
|
1483
|
+
".otf": "file",
|
|
1484
|
+
".png": "file",
|
|
1485
|
+
".svg": "file",
|
|
1486
|
+
".ttf": "file",
|
|
1487
|
+
".wav": "file",
|
|
1488
|
+
".webm": "file",
|
|
1489
|
+
".webp": "file",
|
|
1490
|
+
".woff": "file",
|
|
1491
|
+
".woff2": "file",
|
|
1492
|
+
".js": "jsx",
|
|
1493
|
+
".jsx": "jsx",
|
|
1494
|
+
".tsx": "tsx"
|
|
1562
1495
|
};
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1496
|
+
|
|
1497
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
|
|
1498
|
+
var import_datalayer3 = __toModule(require("@tinacms/datalayer"));
|
|
1499
|
+
var import_graphql10 = __toModule(require("@tinacms/graphql"));
|
|
1500
|
+
|
|
1501
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/lock.ts
|
|
1502
|
+
var AsyncLock = class {
|
|
1503
|
+
constructor() {
|
|
1504
|
+
this.disable = () => {
|
|
1505
|
+
};
|
|
1506
|
+
this.promise = Promise.resolve();
|
|
1569
1507
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
|
|
1573
|
-
const nested = transformParams(rest);
|
|
1574
|
-
return { [_template]: nested };
|
|
1575
|
-
} catch (e) {
|
|
1576
|
-
if (e.message === "Failed to assertShape - _template is a required field") {
|
|
1577
|
-
if (!data) {
|
|
1578
|
-
return void 0;
|
|
1579
|
-
return [];
|
|
1580
|
-
}
|
|
1581
|
-
const accum = {};
|
|
1582
|
-
Object.entries(data).map(([keyName, value]) => {
|
|
1583
|
-
accum[keyName] = transformParams(value);
|
|
1584
|
-
});
|
|
1585
|
-
return accum;
|
|
1586
|
-
} else {
|
|
1587
|
-
if (!data) {
|
|
1588
|
-
return void 0;
|
|
1589
|
-
return [];
|
|
1590
|
-
}
|
|
1591
|
-
throw e;
|
|
1592
|
-
}
|
|
1508
|
+
enable() {
|
|
1509
|
+
this.promise = new Promise((resolve2) => this.disable = resolve2);
|
|
1593
1510
|
}
|
|
1594
1511
|
};
|
|
1595
|
-
function filterObject(obj) {
|
|
1596
|
-
const ret = {};
|
|
1597
|
-
Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
|
|
1598
|
-
return ret;
|
|
1599
|
-
}
|
|
1600
1512
|
|
|
1601
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
1602
|
-
var import_chalk5 = __toModule(require("chalk"));
|
|
1603
|
-
var import_prompts2 = __toModule(require("prompts"));
|
|
1513
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
|
|
1604
1514
|
var import_metrics3 = __toModule(require("@tinacms/metrics"));
|
|
1605
|
-
var
|
|
1606
|
-
var
|
|
1607
|
-
|
|
1608
|
-
|
|
1515
|
+
var import_chalk6 = __toModule(require("chalk"));
|
|
1516
|
+
var import_child_process = __toModule(require("child_process"));
|
|
1517
|
+
var import_chokidar = __toModule(require("chokidar"));
|
|
1518
|
+
var import_path6 = __toModule(require("path"));
|
|
1519
|
+
var lock = new AsyncLock();
|
|
1520
|
+
var gqlPackageFile = require.resolve("@tinacms/graphql");
|
|
1521
|
+
async function startServer(_ctx, _next, {
|
|
1522
|
+
port = 4001,
|
|
1523
|
+
command,
|
|
1524
|
+
noWatch,
|
|
1525
|
+
experimentalData,
|
|
1526
|
+
noSDK,
|
|
1527
|
+
noTelemetry,
|
|
1528
|
+
watchFolders,
|
|
1529
|
+
verbose
|
|
1530
|
+
}) {
|
|
1531
|
+
lock.disable();
|
|
1532
|
+
const rootPath2 = process.cwd();
|
|
1533
|
+
const t = new import_metrics3.Telemetry({ disabled: Boolean(noTelemetry) });
|
|
1534
|
+
t.submitRecord({
|
|
1609
1535
|
event: {
|
|
1610
|
-
name: "tinacms:cli:
|
|
1611
|
-
clean: Boolean(options.clean),
|
|
1612
|
-
useDefaults: Boolean(options.useDefaultValues)
|
|
1536
|
+
name: "tinacms:cli:server:start:invoke"
|
|
1613
1537
|
}
|
|
1614
1538
|
});
|
|
1615
|
-
if (
|
|
1616
|
-
|
|
1539
|
+
if (!process.env.CI && !noWatch) {
|
|
1540
|
+
await resetGeneratedFolder();
|
|
1541
|
+
}
|
|
1542
|
+
const bridge = new import_datalayer3.FilesystemBridge(rootPath2);
|
|
1543
|
+
const store = experimentalData ? new import_datalayer3.LevelStore(rootPath2) : new import_datalayer3.FilesystemStore({ rootPath: rootPath2 });
|
|
1544
|
+
const shouldBuild = bridge.supportsBuilding();
|
|
1545
|
+
const database = await (0, import_graphql10.createDatabase)({ store, bridge });
|
|
1546
|
+
const startSubprocess = () => {
|
|
1547
|
+
if (typeof command === "string") {
|
|
1548
|
+
const commands = command.split(" ");
|
|
1549
|
+
const firstCommand = commands[0];
|
|
1550
|
+
const args = commands.slice(1) || [];
|
|
1551
|
+
const ps = import_child_process.default.spawn(firstCommand, args, {
|
|
1552
|
+
stdio: "inherit",
|
|
1553
|
+
shell: true
|
|
1554
|
+
});
|
|
1555
|
+
ps.on("error", (code) => {
|
|
1556
|
+
logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
|
|
1557
|
+
logger.error(`name: ${code.name}
|
|
1558
|
+
message: ${code.message}
|
|
1617
1559
|
|
|
1618
|
-
`);
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1560
|
+
stack: ${code.stack || "No stack was provided"}`);
|
|
1561
|
+
});
|
|
1562
|
+
ps.on("close", (code) => {
|
|
1563
|
+
logger.info(`child process exited with code ${code}`);
|
|
1564
|
+
process.exit(code);
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
let ready = false;
|
|
1569
|
+
const build2 = async (noSDK2) => {
|
|
1570
|
+
await lock.promise;
|
|
1571
|
+
lock.enable();
|
|
1572
|
+
try {
|
|
1573
|
+
if (!process.env.CI && !noWatch) {
|
|
1574
|
+
await resetGeneratedFolder();
|
|
1575
|
+
}
|
|
1576
|
+
const database2 = await (0, import_graphql10.createDatabase)({ store, bridge });
|
|
1577
|
+
await compile(null, null, { verbose });
|
|
1578
|
+
const schema = await (0, import_graphql10.buildSchema)(rootPath2, database2);
|
|
1579
|
+
await genTypes({ schema }, () => {
|
|
1580
|
+
}, { noSDK: noSDK2, verbose });
|
|
1581
|
+
} catch (error) {
|
|
1582
|
+
throw error;
|
|
1583
|
+
} finally {
|
|
1584
|
+
lock.disable();
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
const foldersToWatch = (watchFolders || []).map((x) => import_path6.default.join(rootPath2, x));
|
|
1588
|
+
if (!noWatch && !process.env.CI) {
|
|
1589
|
+
import_chokidar.default.watch([
|
|
1590
|
+
...foldersToWatch,
|
|
1591
|
+
`${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
|
|
1592
|
+
], {
|
|
1593
|
+
ignored: [
|
|
1594
|
+
"**/node_modules/**/*",
|
|
1595
|
+
"**/.next/**/*",
|
|
1596
|
+
`${import_path6.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
1597
|
+
]
|
|
1598
|
+
}).on("ready", async () => {
|
|
1599
|
+
if (verbose)
|
|
1600
|
+
console.log("Generating Tina config");
|
|
1601
|
+
try {
|
|
1602
|
+
if (shouldBuild) {
|
|
1603
|
+
await build2(noSDK);
|
|
1604
|
+
}
|
|
1605
|
+
ready = true;
|
|
1606
|
+
startSubprocess();
|
|
1607
|
+
} catch (e) {
|
|
1608
|
+
handleServerErrors(e);
|
|
1609
|
+
console.log(e);
|
|
1610
|
+
process.exit(0);
|
|
1611
|
+
}
|
|
1612
|
+
}).on("all", async () => {
|
|
1613
|
+
if (ready) {
|
|
1614
|
+
logger.info("Tina change detected, regenerating config");
|
|
1615
|
+
try {
|
|
1616
|
+
if (shouldBuild) {
|
|
1617
|
+
await build2(noSDK);
|
|
1618
|
+
}
|
|
1619
|
+
} catch (e) {
|
|
1620
|
+
handleServerErrors(e);
|
|
1621
|
+
t.submitRecord({
|
|
1622
|
+
event: {
|
|
1623
|
+
name: "tinacms:cli:server:error",
|
|
1624
|
+
errorMessage: e.message
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1623
1629
|
});
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1630
|
+
} else {
|
|
1631
|
+
if (shouldBuild) {
|
|
1632
|
+
await build2(noSDK);
|
|
1627
1633
|
}
|
|
1628
1634
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
const
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1635
|
+
const state = {
|
|
1636
|
+
server: null,
|
|
1637
|
+
sockets: []
|
|
1638
|
+
};
|
|
1639
|
+
let isReady = false;
|
|
1640
|
+
const start = async () => {
|
|
1641
|
+
const s = (init_server(), server_exports);
|
|
1642
|
+
state.server = await s.default(database);
|
|
1643
|
+
state.server.listen(port, () => {
|
|
1644
|
+
const altairUrl = `http://localhost:${port}/altair/`;
|
|
1645
|
+
const cmsUrl = `[your-development-url]/admin`;
|
|
1646
|
+
if (verbose)
|
|
1647
|
+
logger.info(`Started Filesystem GraphQL server on port: ${port}`);
|
|
1648
|
+
logger.info(`Visit the GraphQL playground at ${import_chalk6.default.underline.blueBright(altairUrl)}
|
|
1649
|
+
or`);
|
|
1650
|
+
logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
|
|
1651
|
+
`);
|
|
1646
1652
|
});
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1653
|
+
state.server.on("error", function(e) {
|
|
1654
|
+
if (e.code === "EADDRINUSE") {
|
|
1655
|
+
logger.error(dangerText(`Port 4001 already in use`));
|
|
1656
|
+
process.exit();
|
|
1657
|
+
}
|
|
1658
|
+
throw e;
|
|
1659
|
+
});
|
|
1660
|
+
state.server.on("connection", (socket) => {
|
|
1661
|
+
state.sockets.push(socket);
|
|
1662
|
+
});
|
|
1663
|
+
};
|
|
1664
|
+
const restart = async () => {
|
|
1665
|
+
logger.info("Detected change to gql package, restarting...");
|
|
1666
|
+
delete require.cache[gqlPackageFile];
|
|
1667
|
+
state.sockets.forEach((socket) => {
|
|
1668
|
+
if (socket.destroyed === false) {
|
|
1669
|
+
socket.destroy();
|
|
1670
|
+
}
|
|
1671
|
+
});
|
|
1672
|
+
state.sockets = [];
|
|
1673
|
+
state.server.close(() => {
|
|
1674
|
+
logger.info("Server closed");
|
|
1675
|
+
start();
|
|
1676
|
+
});
|
|
1677
|
+
};
|
|
1678
|
+
if (!noWatch && !process.env.CI) {
|
|
1679
|
+
import_chokidar.default.watch([gqlPackageFile]).on("ready", async () => {
|
|
1680
|
+
isReady = true;
|
|
1681
|
+
start();
|
|
1682
|
+
}).on("all", async () => {
|
|
1683
|
+
if (isReady) {
|
|
1684
|
+
restart();
|
|
1685
|
+
}
|
|
1652
1686
|
});
|
|
1653
|
-
warning = warning || returnWarning;
|
|
1654
|
-
error = error || returnError;
|
|
1655
|
-
}
|
|
1656
|
-
ctx.warning = warning;
|
|
1657
|
-
ctx.error = error;
|
|
1658
|
-
next();
|
|
1659
|
-
};
|
|
1660
|
-
var printFinalMessage = async (ctx, next, _options) => {
|
|
1661
|
-
if (ctx.error) {
|
|
1662
|
-
logger.error(import_chalk5.default.redBright(`\u203C\uFE0F Audit ${import_chalk5.default.bold("failed")} with errors`));
|
|
1663
|
-
} else if (ctx.warning) {
|
|
1664
|
-
logger.warn(import_chalk5.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
|
|
1665
1687
|
} else {
|
|
1666
|
-
|
|
1688
|
+
if (process.env.CI) {
|
|
1689
|
+
logger.info("Detected CI environment, omitting watch commands...");
|
|
1690
|
+
}
|
|
1691
|
+
start();
|
|
1692
|
+
startSubprocess();
|
|
1667
1693
|
}
|
|
1668
|
-
|
|
1669
|
-
};
|
|
1694
|
+
}
|
|
1670
1695
|
|
|
1671
1696
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
|
|
1672
|
-
var import_chalk6 = __toModule(require("chalk"));
|
|
1673
1697
|
var CMD_GEN_TYPES = "schema:types";
|
|
1674
1698
|
var CMD_START_SERVER = "server:start";
|
|
1675
1699
|
var CMD_COMPILE_MODELS = "schema:compile";
|
|
@@ -1715,6 +1739,10 @@ var watchFileOption = {
|
|
|
1715
1739
|
name: "-w, --watchFolders [folders...]",
|
|
1716
1740
|
description: "a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
1717
1741
|
};
|
|
1742
|
+
var verboseOption = {
|
|
1743
|
+
name: "-v, --verbose",
|
|
1744
|
+
description: "increase verbosity of logged output"
|
|
1745
|
+
};
|
|
1718
1746
|
var baseCmds = [
|
|
1719
1747
|
{
|
|
1720
1748
|
command: CMD_START_SERVER,
|
|
@@ -1726,7 +1754,8 @@ var baseCmds = [
|
|
|
1726
1754
|
noWatchOption,
|
|
1727
1755
|
noSDKCodegenOption,
|
|
1728
1756
|
noTelemetryOption,
|
|
1729
|
-
watchFileOption
|
|
1757
|
+
watchFileOption,
|
|
1758
|
+
verboseOption
|
|
1730
1759
|
],
|
|
1731
1760
|
action: (options) => chain([startServer], options)
|
|
1732
1761
|
},
|
|
@@ -1777,7 +1806,7 @@ var baseCmds = [
|
|
|
1777
1806
|
genTypes,
|
|
1778
1807
|
async (_ctx, next) => {
|
|
1779
1808
|
logger.level = "info";
|
|
1780
|
-
logger.info(
|
|
1809
|
+
logger.info(import_chalk7.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
|
|
1781
1810
|
next();
|
|
1782
1811
|
},
|
|
1783
1812
|
audit,
|