@tinacms/cli 0.60.10 → 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 +33 -0
- package/README.md +1 -0
- package/dist/cmds/compile/defaultSchema.d.ts +1 -1
- package/dist/cmds/compile/index.d.ts +4 -1
- package/dist/cmds/init/setup-files/index.d.ts +0 -12
- package/dist/cmds/start-server/index.d.ts +2 -1
- package/dist/codegen/index.d.ts +1 -0
- package/dist/index.js +874 -806
- package/package.json +6 -5
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,467 +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)
|
|
468
|
-
|
|
469
|
-
// The Route Mapper
|
|
470
|
-
/**
|
|
471
|
-
* 1. Import \`tinacms\` and \`RouteMappingPlugin\`
|
|
472
|
-
**/
|
|
473
|
-
import("tinacms").then(({ RouteMappingPlugin }) => {
|
|
474
|
-
/**
|
|
475
|
-
* 2. Define the \`RouteMappingPlugin\` see https://tina.io/docs/tinacms-context/#the-routemappingplugin for more details
|
|
476
|
-
**/
|
|
477
|
-
const RouteMapping = new RouteMappingPlugin((collection, document) => {
|
|
478
|
-
return undefined;
|
|
479
|
-
});
|
|
480
|
-
/**
|
|
481
|
-
* 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
|
|
482
|
-
**/
|
|
483
|
-
cms.plugins.add(RouteMapping);
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
return cms;
|
|
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 instanceof 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 instanceof 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 {
|
|
542
|
-
logger.info(dangerText("Compilation failed with errors. Server has not been restarted.") + ` see error below
|
|
543
|
-
${e.message}`);
|
|
544
|
-
}
|
|
545
|
-
};
|
|
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}\`
|
|
546
425
|
|
|
547
|
-
|
|
548
|
-
var tinaPath = import_path3.default.join(process.cwd(), ".tina");
|
|
549
|
-
var packageJSONFilePath = import_path3.default.join(process.cwd(), "package.json");
|
|
550
|
-
var tinaGeneratedPath = import_path3.default.join(tinaPath, "__generated__");
|
|
551
|
-
var tinaTempPath = import_path3.default.join(tinaGeneratedPath, "temp");
|
|
552
|
-
var tinaConfigPath = import_path3.default.join(tinaGeneratedPath, "config");
|
|
553
|
-
var resetGeneratedFolder = async () => {
|
|
554
|
-
try {
|
|
555
|
-
await import_fs_extra3.default.rmdir(tinaGeneratedPath, {
|
|
556
|
-
recursive: true
|
|
557
|
-
});
|
|
558
|
-
} catch (e) {
|
|
559
|
-
console.log(e);
|
|
560
|
-
}
|
|
561
|
-
await import_fs_extra3.default.mkdir(tinaGeneratedPath);
|
|
562
|
-
await import_fs_extra3.default.outputFile(import_path3.default.join(tinaGeneratedPath, ".gitignore"), "db");
|
|
563
|
-
};
|
|
564
|
-
var cleanup = async ({ tinaTempPath: tinaTempPath2 }) => {
|
|
565
|
-
await import_fs_extra3.default.remove(tinaTempPath2);
|
|
566
|
-
};
|
|
567
|
-
var compile = async (_ctx, _next) => {
|
|
568
|
-
logger.info(logText("Compiling..."));
|
|
569
|
-
let schemaExists = true;
|
|
570
|
-
try {
|
|
571
|
-
getSchemaPath({ projectDir: tinaPath });
|
|
572
|
-
} catch {
|
|
573
|
-
schemaExists = false;
|
|
574
|
-
}
|
|
575
|
-
if (!schemaExists) {
|
|
576
|
-
logger.info(dangerText(`
|
|
577
|
-
.tina/schema.ts not found, Creating one for you...
|
|
578
|
-
See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
|
|
579
|
-
`));
|
|
580
|
-
const file = import_path3.default.join(tinaPath, "schema.ts");
|
|
581
|
-
await import_fs_extra3.default.ensureFile(file);
|
|
582
|
-
await import_fs_extra3.default.writeFile(file, defaultSchema);
|
|
583
|
-
}
|
|
584
|
-
try {
|
|
585
|
-
await transpile(tinaPath, tinaTempPath);
|
|
586
|
-
} catch (e) {
|
|
587
|
-
await cleanup({ tinaTempPath });
|
|
588
|
-
throw new BuildSchemaError(e);
|
|
589
|
-
}
|
|
590
|
-
Object.keys(require.cache).map((key) => {
|
|
591
|
-
if (key.startsWith(tinaTempPath)) {
|
|
592
|
-
delete require.cache[require.resolve(key)];
|
|
426
|
+
location: ${import_path2.default.join(rootPath2, node.sys.path)}`));
|
|
593
427
|
}
|
|
594
428
|
});
|
|
595
|
-
|
|
596
|
-
const schemaFunc = require(import_path3.default.join(tinaTempPath, "schema.js"));
|
|
597
|
-
const schemaObject = schemaFunc.default;
|
|
598
|
-
await import_fs_extra3.default.outputFile(import_path3.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
|
|
599
|
-
await cleanup({ tinaTempPath });
|
|
600
|
-
} catch (e) {
|
|
601
|
-
await cleanup({ tinaTempPath });
|
|
602
|
-
throw new ExecuteSchemaError(e);
|
|
603
|
-
}
|
|
429
|
+
return warning;
|
|
604
430
|
};
|
|
605
|
-
var
|
|
606
|
-
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
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: {}
|
|
623
457
|
});
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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
|
+
}
|
|
484
|
+
});
|
|
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
|
|
506
|
+
});
|
|
507
|
+
if (mutationRes.errors) {
|
|
508
|
+
mutationRes.errors.forEach((err) => {
|
|
509
|
+
error = true;
|
|
510
|
+
logger.error(import_chalk2.default.red(err.message));
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return error;
|
|
628
515
|
};
|
|
629
|
-
var
|
|
630
|
-
"
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
".gif": "file",
|
|
635
|
-
".jpeg": "file",
|
|
636
|
-
".jpg": "file",
|
|
637
|
-
".json": "json",
|
|
638
|
-
".mp3": "file",
|
|
639
|
-
".mp4": "file",
|
|
640
|
-
".ogg": "file",
|
|
641
|
-
".otf": "file",
|
|
642
|
-
".png": "file",
|
|
643
|
-
".svg": "file",
|
|
644
|
-
".ttf": "file",
|
|
645
|
-
".wav": "file",
|
|
646
|
-
".webm": "file",
|
|
647
|
-
".webp": "file",
|
|
648
|
-
".woff": "file",
|
|
649
|
-
".woff2": "file",
|
|
650
|
-
".js": "jsx",
|
|
651
|
-
".jsx": "jsx",
|
|
652
|
-
".tsx": "tsx"
|
|
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));
|
|
653
521
|
};
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
var import_metrics = __toModule(require("@tinacms/metrics"));
|
|
658
|
-
|
|
659
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/lock.ts
|
|
660
|
-
var AsyncLock = class {
|
|
661
|
-
constructor() {
|
|
662
|
-
this.disable = () => {
|
|
663
|
-
};
|
|
664
|
-
this.promise = Promise.resolve();
|
|
522
|
+
var transformParams = (data) => {
|
|
523
|
+
if (["string", "number", "boolean"].includes(typeof data)) {
|
|
524
|
+
return data;
|
|
665
525
|
}
|
|
666
|
-
|
|
667
|
-
|
|
526
|
+
if (Array.isArray(data)) {
|
|
527
|
+
return data.map((item) => transformParams(item));
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
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 };
|
|
534
|
+
} catch (e) {
|
|
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 [];
|
|
549
|
+
}
|
|
550
|
+
throw e;
|
|
551
|
+
}
|
|
668
552
|
}
|
|
669
553
|
};
|
|
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
|
+
}
|
|
670
559
|
|
|
671
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
672
|
-
var
|
|
673
|
-
var
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
noSDK,
|
|
680
|
-
noTelemetry,
|
|
681
|
-
watchFolders
|
|
682
|
-
}) {
|
|
683
|
-
lock.disable();
|
|
684
|
-
const rootPath2 = process.cwd();
|
|
685
|
-
const t = new import_metrics.Telemetry({ disabled: Boolean(noTelemetry) });
|
|
686
|
-
t.submitRecord({
|
|
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"));
|
|
563
|
+
var import_metrics = __toModule(require("@tinacms/metrics"));
|
|
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({
|
|
687
568
|
event: {
|
|
688
|
-
name: "tinacms:cli:
|
|
569
|
+
name: "tinacms:cli:audit:invoke",
|
|
570
|
+
clean: Boolean(options.clean),
|
|
571
|
+
useDefaults: Boolean(options.useDefaultValues)
|
|
689
572
|
}
|
|
690
573
|
});
|
|
691
|
-
if (
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
const bridge = new import_datalayer2.FilesystemBridge(rootPath2);
|
|
695
|
-
const store = experimentalData ? new import_datalayer2.LevelStore(rootPath2) : new import_datalayer2.FilesystemStore({ rootPath: rootPath2 });
|
|
696
|
-
const shouldBuild = bridge.supportsBuilding();
|
|
697
|
-
const database = await (0, import_graphql7.createDatabase)({ store, bridge });
|
|
698
|
-
const startSubprocess = () => {
|
|
699
|
-
if (typeof command === "string") {
|
|
700
|
-
const commands = command.split(" ");
|
|
701
|
-
const firstCommand = commands[0];
|
|
702
|
-
const args = commands.slice(1) || [];
|
|
703
|
-
const ps = import_child_process.default.spawn(firstCommand, args, {
|
|
704
|
-
stdio: "inherit",
|
|
705
|
-
shell: true
|
|
706
|
-
});
|
|
707
|
-
ps.on("error", (code) => {
|
|
708
|
-
logger.error(dangerText(`An error has occurred in the Next.js child process. Error message below`));
|
|
709
|
-
logger.error(`name: ${code.name}
|
|
710
|
-
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.
|
|
711
576
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
let ready = false;
|
|
721
|
-
const build2 = async (noSDK2) => {
|
|
722
|
-
await lock.promise;
|
|
723
|
-
lock.enable();
|
|
724
|
-
try {
|
|
725
|
-
if (!process.env.CI && !noWatch) {
|
|
726
|
-
await resetGeneratedFolder();
|
|
727
|
-
}
|
|
728
|
-
const database2 = await (0, import_graphql7.createDatabase)({ store, bridge });
|
|
729
|
-
await compile(null, null);
|
|
730
|
-
const schema = await (0, import_graphql7.buildSchema)(rootPath2, database2);
|
|
731
|
-
await genTypes({ schema }, () => {
|
|
732
|
-
}, { noSDK: noSDK2 });
|
|
733
|
-
} catch (error) {
|
|
734
|
-
throw error;
|
|
735
|
-
} finally {
|
|
736
|
-
lock.disable();
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
const foldersToWatch = (watchFolders || []).map((x) => import_path4.default.join(rootPath2, x));
|
|
740
|
-
if (!noWatch && !process.env.CI) {
|
|
741
|
-
import_chokidar.default.watch([
|
|
742
|
-
...foldersToWatch,
|
|
743
|
-
`${rootPath2}/.tina/**/*.{ts,gql,graphql,js,tsx,jsx}`
|
|
744
|
-
], {
|
|
745
|
-
ignored: [
|
|
746
|
-
"**/node_modules/**/*",
|
|
747
|
-
"**/.next/**/*",
|
|
748
|
-
`${import_path4.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
749
|
-
]
|
|
750
|
-
}).on("ready", async () => {
|
|
751
|
-
console.log("Generating Tina config");
|
|
752
|
-
try {
|
|
753
|
-
if (shouldBuild) {
|
|
754
|
-
await build2(noSDK);
|
|
755
|
-
}
|
|
756
|
-
ready = true;
|
|
757
|
-
startSubprocess();
|
|
758
|
-
} catch (e) {
|
|
759
|
-
handleServerErrors(e);
|
|
760
|
-
console.log(e);
|
|
761
|
-
process.exit(0);
|
|
762
|
-
}
|
|
763
|
-
}).on("all", async () => {
|
|
764
|
-
if (ready) {
|
|
765
|
-
logger.info("Tina change detected, regenerating config");
|
|
766
|
-
try {
|
|
767
|
-
if (shouldBuild) {
|
|
768
|
-
await build2(noSDK);
|
|
769
|
-
}
|
|
770
|
-
} catch (e) {
|
|
771
|
-
handleServerErrors(e);
|
|
772
|
-
t.submitRecord({
|
|
773
|
-
event: {
|
|
774
|
-
name: "tinacms:cli:server:error",
|
|
775
|
-
errorMessage: e.message
|
|
776
|
-
}
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
}
|
|
577
|
+
`);
|
|
578
|
+
const res = await (0, import_prompts.default)({
|
|
579
|
+
name: "useClean",
|
|
580
|
+
type: "confirm",
|
|
581
|
+
message: `Do you want to continue?`
|
|
780
582
|
});
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
583
|
+
if (!res.useClean) {
|
|
584
|
+
logger.warn(import_chalk3.default.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
585
|
+
process.exit(0);
|
|
784
586
|
}
|
|
785
587
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
throw e;
|
|
804
|
-
});
|
|
805
|
-
state.server.on("connection", (socket) => {
|
|
806
|
-
state.sockets.push(socket);
|
|
807
|
-
});
|
|
808
|
-
};
|
|
809
|
-
const restart = async () => {
|
|
810
|
-
logger.info("Detected change to gql package, restarting...");
|
|
811
|
-
delete require.cache[gqlPackageFile];
|
|
812
|
-
state.sockets.forEach((socket) => {
|
|
813
|
-
if (socket.destroyed === false) {
|
|
814
|
-
socket.destroy();
|
|
815
|
-
}
|
|
816
|
-
});
|
|
817
|
-
state.sockets = [];
|
|
818
|
-
state.server.close(() => {
|
|
819
|
-
logger.info("Server closed");
|
|
820
|
-
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
|
|
821
605
|
});
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
}).on("all", async () => {
|
|
828
|
-
if (isReady) {
|
|
829
|
-
restart();
|
|
830
|
-
}
|
|
606
|
+
const returnError = await auditDocuments({
|
|
607
|
+
collection,
|
|
608
|
+
database,
|
|
609
|
+
rootPath,
|
|
610
|
+
useDefaultValues: options.useDefaultValues
|
|
831
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"));
|
|
832
624
|
} else {
|
|
833
|
-
|
|
834
|
-
logger.info("Detected CI environment, omitting watch commands...");
|
|
835
|
-
}
|
|
836
|
-
start();
|
|
837
|
-
startSubprocess();
|
|
625
|
+
logger.info(import_chalk3.default.greenBright("\u2705 Audit passed"));
|
|
838
626
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
|
|
842
|
-
var import_fs_extra4 = __toModule(require("fs-extra"));
|
|
843
|
-
var import_path5 = __toModule(require("path"));
|
|
844
|
-
var import_progress = __toModule(require("progress"));
|
|
845
|
-
var import_prompts = __toModule(require("prompts"));
|
|
846
|
-
var import_metrics2 = __toModule(require("@tinacms/metrics"));
|
|
627
|
+
next();
|
|
628
|
+
};
|
|
847
629
|
|
|
848
630
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/index.ts
|
|
631
|
+
var import_chalk4 = __toModule(require("chalk"));
|
|
849
632
|
var adminPage = `import { TinaAdmin } from 'tinacms';
|
|
850
633
|
export default TinaAdmin;
|
|
851
634
|
`;
|
|
@@ -1157,23 +940,22 @@ var nextPostPage = () => `// THIS FILE HAS BEEN GENERATED WITH THE TINA CLI.
|
|
|
1157
940
|
};
|
|
1158
941
|
|
|
1159
942
|
`;
|
|
1160
|
-
var AppJsContent = (usingSrc, extraImports) =>
|
|
943
|
+
var AppJsContent = (usingSrc, extraImports) => {
|
|
944
|
+
const importLine = import_chalk4.default.green(`+ import Tina from '${usingSrc ? "../" : ""}../.tina/components/TinaDynamicProvider.js'`);
|
|
945
|
+
return `${importLine}
|
|
946
|
+
${extraImports || ""}
|
|
1161
947
|
|
|
1162
|
-
|
|
1163
|
-
const App = ({ Component, pageProps }) => {
|
|
948
|
+
const App = ({ Component, pageProps }) => {
|
|
1164
949
|
return (
|
|
1165
|
-
<Tina>
|
|
1166
|
-
|
|
1167
|
-
</Tina>
|
|
950
|
+
${import_chalk4.default.green("+ <Tina>")}
|
|
951
|
+
<Component {...pageProps} />
|
|
952
|
+
${import_chalk4.default.green("+ </Tina>")}
|
|
1168
953
|
)
|
|
1169
954
|
}
|
|
1170
|
-
|
|
955
|
+
|
|
1171
956
|
export default App
|
|
1172
|
-
|
|
1173
957
|
`;
|
|
1174
|
-
|
|
1175
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
|
|
1176
|
-
var import_chalk2 = __toModule(require("chalk"));
|
|
958
|
+
};
|
|
1177
959
|
|
|
1178
960
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/setup-files/tinaProvider.ts
|
|
1179
961
|
var TinaProvider = `import TinaCMS from 'tinacms'
|
|
@@ -1221,6 +1003,12 @@ function extendNextScripts(scripts) {
|
|
|
1221
1003
|
}
|
|
1222
1004
|
|
|
1223
1005
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/init/index.ts
|
|
1006
|
+
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
1007
|
+
var import_progress = __toModule(require("progress"));
|
|
1008
|
+
var import_metrics2 = __toModule(require("@tinacms/metrics"));
|
|
1009
|
+
var import_chalk5 = __toModule(require("chalk"));
|
|
1010
|
+
var import_path3 = __toModule(require("path"));
|
|
1011
|
+
var import_prompts2 = __toModule(require("prompts"));
|
|
1224
1012
|
function execShellCommand(cmd) {
|
|
1225
1013
|
const exec = require("child_process").exec;
|
|
1226
1014
|
return new Promise((resolve2, _reject) => {
|
|
@@ -1234,14 +1022,19 @@ function execShellCommand(cmd) {
|
|
|
1234
1022
|
}
|
|
1235
1023
|
async function initTina(ctx, next, options) {
|
|
1236
1024
|
const telemetry = new import_metrics2.Telemetry({ disabled: options.noTelemetry });
|
|
1237
|
-
await telemetry.submitRecord({
|
|
1025
|
+
await telemetry.submitRecord({
|
|
1026
|
+
event: {
|
|
1027
|
+
name: "tinacms:cli:init:invoke",
|
|
1028
|
+
schemaFileType: options.schemaFileType || "ts"
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1238
1031
|
logger.info(successText("Setting up Tina..."));
|
|
1239
1032
|
next();
|
|
1240
1033
|
}
|
|
1241
1034
|
var MIN_REACT_VERSION = ">=16.14.0";
|
|
1242
1035
|
async function checkDeps(ctx, next, options) {
|
|
1243
1036
|
const bar = new import_progress.default("Checking dependencies. :prog", 1);
|
|
1244
|
-
const packageJSON = JSON.parse((await
|
|
1037
|
+
const packageJSON = JSON.parse((await import_fs_extra2.default.readFileSync(packageJSONPath)).toString());
|
|
1245
1038
|
if (!checkPackage(packageJSON, "react") || !checkPackage(packageJSON, "react-dom")) {
|
|
1246
1039
|
const message = `Unable to initialize Tina due to outdated dependencies, try upgrading the following packages:
|
|
1247
1040
|
"react@${MIN_REACT_VERSION}"
|
|
@@ -1280,361 +1073,627 @@ var checkVersion = (version2) => {
|
|
|
1280
1073
|
return false;
|
|
1281
1074
|
}
|
|
1282
1075
|
}
|
|
1283
|
-
if (major > majorMin) {
|
|
1284
|
-
return true;
|
|
1285
|
-
} else if (major === majorMin) {
|
|
1286
|
-
if (minor >= minorMin) {
|
|
1287
|
-
return true;
|
|
1288
|
-
} else {
|
|
1289
|
-
return false;
|
|
1290
|
-
}
|
|
1291
|
-
} else {
|
|
1292
|
-
return false;
|
|
1076
|
+
if (major > majorMin) {
|
|
1077
|
+
return true;
|
|
1078
|
+
} else if (major === majorMin) {
|
|
1079
|
+
if (minor >= minorMin) {
|
|
1080
|
+
return true;
|
|
1081
|
+
} else {
|
|
1082
|
+
return false;
|
|
1083
|
+
}
|
|
1084
|
+
} else {
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
async function installDeps(ctx, next, options) {
|
|
1089
|
+
const bar = new import_progress.default("Installing Tina packages. This might take a moment... :prog", 2);
|
|
1090
|
+
const deps = ["tinacms", "styled-components", "@tinacms/cli"];
|
|
1091
|
+
bar.tick({
|
|
1092
|
+
prog: ""
|
|
1093
|
+
});
|
|
1094
|
+
const installCMD = `yarn add ${deps.join(" ")}`;
|
|
1095
|
+
await execShellCommand(installCMD);
|
|
1096
|
+
bar.tick({
|
|
1097
|
+
prog: "\u2705"
|
|
1098
|
+
});
|
|
1099
|
+
logger.level = "fatal";
|
|
1100
|
+
next();
|
|
1101
|
+
}
|
|
1102
|
+
var baseDir = process.cwd();
|
|
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");
|
|
1110
|
+
async function tinaSetup(_ctx, next, _options) {
|
|
1111
|
+
const usingSrc = import_fs_extra2.default.pathExistsSync(import_path3.default.join(baseDir, "src"));
|
|
1112
|
+
if (!import_fs_extra2.default.pathExistsSync(blogPostPath)) {
|
|
1113
|
+
logger.info(logText("Adding a content folder..."));
|
|
1114
|
+
import_fs_extra2.default.mkdirpSync(blogContentPath);
|
|
1115
|
+
import_fs_extra2.default.writeFileSync(blogPostPath, blogPost);
|
|
1116
|
+
}
|
|
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);
|
|
1121
|
+
}
|
|
1122
|
+
logger.level = "info";
|
|
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)) {
|
|
1128
|
+
logger.info(logText("Adding _app.js ... \u2705"));
|
|
1129
|
+
import_fs_extra2.default.writeFileSync(appPath, AppJsContent(usingSrc));
|
|
1130
|
+
} else {
|
|
1131
|
+
const override = await (0, import_prompts2.default)({
|
|
1132
|
+
name: "res",
|
|
1133
|
+
type: "confirm",
|
|
1134
|
+
message: `do you want us to ${import_chalk5.default.bold(`override`)} your _app${appExtension}?`
|
|
1135
|
+
});
|
|
1136
|
+
_ctx.overrideApp = override.res;
|
|
1137
|
+
if (override.res) {
|
|
1138
|
+
logger.info(logText(`Adding _app${appExtension} ... \u2705`));
|
|
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);
|
|
1141
|
+
const matches = [
|
|
1142
|
+
...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
|
|
1143
|
+
];
|
|
1144
|
+
const primaryMatches = matches.map((x) => x[0]);
|
|
1145
|
+
import_fs_extra2.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
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());
|
|
1153
|
+
}
|
|
1154
|
+
logger.info("Adding a content folder... \u2705");
|
|
1155
|
+
const packagePath = import_path3.default.join(baseDir, "package.json");
|
|
1156
|
+
const pack = JSON.parse((0, import_fs_extra2.readFileSync)(packagePath).toString());
|
|
1157
|
+
const oldScripts = pack.scripts || {};
|
|
1158
|
+
const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
|
|
1159
|
+
scripts: extendNextScripts(oldScripts)
|
|
1160
|
+
}), null, 2);
|
|
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"))) {
|
|
1164
|
+
logger.warn(`Unable to add /pages/admin.js, this path already exists.
|
|
1165
|
+
Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
|
|
1166
|
+
return next();
|
|
1167
|
+
}
|
|
1168
|
+
(0, import_fs_extra2.outputFileSync)(adminPath, adminPage);
|
|
1169
|
+
next();
|
|
1170
|
+
}
|
|
1171
|
+
async function successMessage(ctx, next, options) {
|
|
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
|
|
1174
|
+
`);
|
|
1175
|
+
logger.info("Next Steps: \n");
|
|
1176
|
+
if (!ctx.overrideApp) {
|
|
1177
|
+
logger.info(`${import_chalk5.default.bold("Add the Tina wrapper")}`);
|
|
1178
|
+
logger.info(`\u26A0\uFE0F Before using Tina, you will NEED to add the Tina wrapper to your _app.jsx
|
|
1179
|
+
`);
|
|
1180
|
+
logger.info(`${AppJsContent(usingSrc)}`);
|
|
1181
|
+
}
|
|
1182
|
+
logger.info(`${import_chalk5.default.bold("Run your site with Tina")}`);
|
|
1183
|
+
logger.info(` yarn dev
|
|
1184
|
+
`);
|
|
1185
|
+
logger.info(`${import_chalk5.default.bold("Start Editing")}`);
|
|
1186
|
+
logger.info(` Go to 'http://localhost:3000/admin'
|
|
1187
|
+
`);
|
|
1188
|
+
logger.info(`${import_chalk5.default.bold("Read the docs")}`);
|
|
1189
|
+
logger.info(` Check out 'https://tina.io/docs/introduction/tina-init/#adding-tina' for help getting started with Tina
|
|
1190
|
+
`);
|
|
1191
|
+
logger.info(`Enjoy Tina! \u{1F999}`);
|
|
1192
|
+
next();
|
|
1193
|
+
}
|
|
1194
|
+
|
|
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
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
|
|
1215
|
+
var import_chalk7 = __toModule(require("chalk"));
|
|
1216
|
+
|
|
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
|
+
}
|
|
1223
|
+
};
|
|
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"
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
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;
|
|
1330
|
+
});
|
|
1331
|
+
/**
|
|
1332
|
+
* 3. Add the \`RouteMappingPlugin\` to the \`cms\`.
|
|
1333
|
+
**/
|
|
1334
|
+
cms.plugins.add(RouteMapping);
|
|
1335
|
+
});
|
|
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);
|
|
1293
1366
|
}
|
|
1367
|
+
return inputFile;
|
|
1294
1368
|
};
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
var baseDir = process.cwd();
|
|
1310
|
-
var packageJSONPath = import_path5.default.join(baseDir, "package.json");
|
|
1311
|
-
var blogContentPath = import_path5.default.join(baseDir, "content", "posts");
|
|
1312
|
-
var blogPostPath = import_path5.default.join(blogContentPath, "HelloWorld.md");
|
|
1313
|
-
var TinaFolder = import_path5.default.join(baseDir, ".tina");
|
|
1314
|
-
var componentFolder = import_path5.default.join(TinaFolder, "components");
|
|
1315
|
-
var TinaProviderPath = import_path5.default.join(componentFolder, "TinaProvider.js");
|
|
1316
|
-
var TinaDynamicProvider = import_path5.default.join(componentFolder, "TinaDynamicProvider.js");
|
|
1317
|
-
async function tinaSetup(_ctx, next, _options) {
|
|
1318
|
-
const useingSrc = import_fs_extra4.default.pathExistsSync(import_path5.default.join(baseDir, "src"));
|
|
1319
|
-
if (!import_fs_extra4.default.pathExistsSync(blogPostPath)) {
|
|
1320
|
-
logger.info(logText("Adding a content folder..."));
|
|
1321
|
-
import_fs_extra4.default.mkdirpSync(blogContentPath);
|
|
1322
|
-
import_fs_extra4.default.writeFileSync(blogPostPath, blogPost);
|
|
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);
|
|
1323
1383
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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..."));
|
|
1328
1395
|
}
|
|
1329
|
-
|
|
1330
|
-
const
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
const appExtension = import_fs_extra4.default.existsSync(appPath) ? ".js" : ".tsx";
|
|
1334
|
-
if (!import_fs_extra4.default.pathExistsSync(appPath) && !import_fs_extra4.default.pathExistsSync(appPathTS)) {
|
|
1335
|
-
logger.info(logText("Adding _app.js ... \u2705"));
|
|
1336
|
-
import_fs_extra4.default.writeFileSync(appPath, AppJsContent(useingSrc));
|
|
1337
|
-
} else {
|
|
1338
|
-
const override = await (0, import_prompts.default)({
|
|
1339
|
-
name: "res",
|
|
1340
|
-
type: "confirm",
|
|
1341
|
-
message: `do you want us to ${import_chalk2.default.bold(`override`)} your _app${appExtension}?`
|
|
1342
|
-
});
|
|
1343
|
-
if (override.res) {
|
|
1344
|
-
logger.info(logText(`Adding _app${appExtension} ... \u2705`));
|
|
1345
|
-
const appPathWithExtension = import_path5.default.join(pagesPath, `_app${appExtension}`);
|
|
1346
|
-
const fileContent = import_fs_extra4.default.pathExistsSync(appPath) ? (0, import_fs_extra4.readFileSync)(appPath) : (0, import_fs_extra4.readFileSync)(appPathTS);
|
|
1347
|
-
const matches = [
|
|
1348
|
-
...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
|
|
1349
|
-
];
|
|
1350
|
-
const primaryMatches = matches.map((x) => x[0]);
|
|
1351
|
-
import_fs_extra4.default.writeFileSync(appPathWithExtension, AppJsContent(useingSrc, primaryMatches.join("\n")));
|
|
1352
|
-
} else {
|
|
1353
|
-
logger.info(dangerText(`Heads up, to enable live-editing you'll need to wrap your page or site in Tina:
|
|
1354
|
-
`, warnText(AppJsContent(useingSrc))));
|
|
1355
|
-
}
|
|
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'`);
|
|
1356
1400
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
if (!import_fs_extra4.default.pathExistsSync(tinaBlogPagePathFile)) {
|
|
1360
|
-
import_fs_extra4.default.mkdirpSync(tinaBlogPagePath);
|
|
1361
|
-
import_fs_extra4.default.writeFileSync(tinaBlogPagePathFile, nextPostPage());
|
|
1401
|
+
if (_ctx) {
|
|
1402
|
+
_ctx.schemaFileType = schemaFileType2;
|
|
1362
1403
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
scripts: extendNextScripts(oldScripts)
|
|
1369
|
-
}), null, 2);
|
|
1370
|
-
(0, import_fs_extra4.writeFileSync)(packagePath, newPack);
|
|
1371
|
-
const adminPath = import_path5.default.join(pagesPath, "admin.js");
|
|
1372
|
-
if (import_fs_extra4.default.pathExistsSync(import_path5.default.join(pagesPath, "admin"))) {
|
|
1373
|
-
logger.warn(`Unable to add /pages/admin.js, this path already exists.
|
|
1374
|
-
Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
|
|
1375
|
-
return next();
|
|
1404
|
+
let schemaExists = true;
|
|
1405
|
+
try {
|
|
1406
|
+
getSchemaPath({ projectDir: tinaPath });
|
|
1407
|
+
} catch {
|
|
1408
|
+
schemaExists = false;
|
|
1376
1409
|
}
|
|
1377
|
-
(
|
|
1378
|
-
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
var import_graphql9 = __toModule(require("@tinacms/graphql"));
|
|
1396
|
-
var import_chalk3 = __toModule(require("chalk"));
|
|
1397
|
-
var auditCollection = async (args) => {
|
|
1398
|
-
let warning = false;
|
|
1399
|
-
const { collection, database, rootPath: rootPath2 } = args;
|
|
1400
|
-
logger.info(`Checking collection ${collection.name}`);
|
|
1401
|
-
const query = `query {
|
|
1402
|
-
getCollection(collection: "${collection.name}") {
|
|
1403
|
-
format
|
|
1404
|
-
documents {
|
|
1405
|
-
edges {
|
|
1406
|
-
node {
|
|
1407
|
-
...on Document {
|
|
1408
|
-
sys {
|
|
1409
|
-
extension
|
|
1410
|
-
path
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
`;
|
|
1419
|
-
const result = await (0, import_graphql8.resolve)({
|
|
1420
|
-
database,
|
|
1421
|
-
query,
|
|
1422
|
-
variables: {}
|
|
1423
|
-
});
|
|
1424
|
-
const format = result.data.getCollection.format;
|
|
1425
|
-
const docs = result.data.getCollection.documents.edges;
|
|
1426
|
-
docs.forEach((x) => {
|
|
1427
|
-
const node = x.node;
|
|
1428
|
-
if (node.sys.extension.replace(".", "") !== format) {
|
|
1429
|
-
warning = true;
|
|
1430
|
-
logger.warn(import_chalk3.default.yellowBright(`WARNING: there is a file with extension \`${node.sys.extension}\` but in your schema it is defined to be \`.${format}\`
|
|
1431
|
-
|
|
1432
|
-
location: ${import_path6.default.join(rootPath2, node.sys.path)}`));
|
|
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)];
|
|
1433
1428
|
}
|
|
1434
1429
|
});
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
node {
|
|
1446
|
-
...on Document {
|
|
1447
|
-
sys {
|
|
1448
|
-
extension
|
|
1449
|
-
path
|
|
1450
|
-
relativePath
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
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;
|
|
1457
1440
|
}
|
|
1458
|
-
`;
|
|
1459
|
-
const result = await (0, import_graphql8.resolve)({
|
|
1460
|
-
database,
|
|
1461
|
-
query,
|
|
1462
|
-
variables: {}
|
|
1463
|
-
});
|
|
1464
|
-
let error = false;
|
|
1465
|
-
const documents = result.data.getCollection.documents.edges;
|
|
1466
|
-
for (let i = 0; i < documents.length; i++) {
|
|
1467
|
-
const node = documents[i].node;
|
|
1468
|
-
const fullPath = import_path6.default.join(rootPath2, node.sys.path);
|
|
1469
|
-
logger.info(`Checking document: ${fullPath}`);
|
|
1470
|
-
const documentQuery = `query {
|
|
1471
|
-
getDocument(collection: "${collection.name}", relativePath: "${node.sys.relativePath}") {
|
|
1472
|
-
__typename
|
|
1473
|
-
...on Document {
|
|
1474
|
-
values
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
}`;
|
|
1478
|
-
const docResult = await (0, import_graphql8.resolve)({
|
|
1479
|
-
database,
|
|
1480
|
-
query: documentQuery,
|
|
1481
|
-
variables: {}
|
|
1482
|
-
});
|
|
1483
|
-
const topLevelDefaults = {};
|
|
1484
|
-
if (useDefaultValues && typeof collection.fields !== "string") {
|
|
1485
|
-
collection.fields.filter((x) => !x.list).forEach((x) => {
|
|
1486
|
-
const value = x.ui;
|
|
1487
|
-
if (typeof value !== "undefined") {
|
|
1488
|
-
topLevelDefaults[x.name] = value.defaultValue;
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
const params = transformDocumentIntoMutationRequestPayload(docResult.data.getDocument.values, {
|
|
1493
|
-
includeCollection: true,
|
|
1494
|
-
includeTemplate: typeof collection.templates !== "undefined"
|
|
1495
|
-
}, topLevelDefaults);
|
|
1496
|
-
const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
1497
|
-
updateDocument(
|
|
1498
|
-
collection: $collection,
|
|
1499
|
-
relativePath: $relativePath,
|
|
1500
|
-
params: $params
|
|
1501
|
-
){__typename}
|
|
1502
|
-
}`;
|
|
1503
|
-
const mutationRes = await (0, import_graphql8.resolve)({
|
|
1504
|
-
database,
|
|
1505
|
-
query: mutation,
|
|
1506
|
-
variables: {
|
|
1507
|
-
params,
|
|
1508
|
-
collection: collection.name,
|
|
1509
|
-
relativePath: node.sys.relativePath
|
|
1510
|
-
},
|
|
1511
|
-
silenceErrors: true
|
|
1512
|
-
});
|
|
1513
|
-
if (mutationRes.errors) {
|
|
1514
|
-
mutationRes.errors.forEach((err) => {
|
|
1515
|
-
error = true;
|
|
1516
|
-
logger.error(import_chalk3.default.red(err.message));
|
|
1517
|
-
});
|
|
1518
1441
|
}
|
|
1442
|
+
throw new ExecuteSchemaError(e);
|
|
1519
1443
|
}
|
|
1520
|
-
return error;
|
|
1521
1444
|
};
|
|
1522
|
-
var
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
const
|
|
1526
|
-
|
|
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"
|
|
1527
1495
|
};
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
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();
|
|
1534
1507
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
const _a = data, { _template, __typename } = _a, rest = __objRest(_a, ["_template", "__typename"]);
|
|
1538
|
-
const nested = transformParams(rest);
|
|
1539
|
-
return { [_template]: nested };
|
|
1540
|
-
} catch (e) {
|
|
1541
|
-
if (e.message === "Failed to assertShape - _template is a required field") {
|
|
1542
|
-
if (!data) {
|
|
1543
|
-
return void 0;
|
|
1544
|
-
return [];
|
|
1545
|
-
}
|
|
1546
|
-
const accum = {};
|
|
1547
|
-
Object.entries(data).map(([keyName, value]) => {
|
|
1548
|
-
accum[keyName] = transformParams(value);
|
|
1549
|
-
});
|
|
1550
|
-
return accum;
|
|
1551
|
-
} else {
|
|
1552
|
-
if (!data) {
|
|
1553
|
-
return void 0;
|
|
1554
|
-
return [];
|
|
1555
|
-
}
|
|
1556
|
-
throw e;
|
|
1557
|
-
}
|
|
1508
|
+
enable() {
|
|
1509
|
+
this.promise = new Promise((resolve2) => this.disable = resolve2);
|
|
1558
1510
|
}
|
|
1559
1511
|
};
|
|
1560
|
-
function filterObject(obj) {
|
|
1561
|
-
const ret = {};
|
|
1562
|
-
Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
|
|
1563
|
-
return ret;
|
|
1564
|
-
}
|
|
1565
1512
|
|
|
1566
|
-
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/
|
|
1567
|
-
var import_chalk4 = __toModule(require("chalk"));
|
|
1568
|
-
var import_prompts2 = __toModule(require("prompts"));
|
|
1513
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/start-server/index.ts
|
|
1569
1514
|
var import_metrics3 = __toModule(require("@tinacms/metrics"));
|
|
1570
|
-
var
|
|
1571
|
-
var
|
|
1572
|
-
|
|
1573
|
-
|
|
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({
|
|
1574
1535
|
event: {
|
|
1575
|
-
name: "tinacms:cli:
|
|
1576
|
-
clean: Boolean(options.clean),
|
|
1577
|
-
useDefaults: Boolean(options.useDefaultValues)
|
|
1536
|
+
name: "tinacms:cli:server:start:invoke"
|
|
1578
1537
|
}
|
|
1579
1538
|
});
|
|
1580
|
-
if (
|
|
1581
|
-
|
|
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}
|
|
1582
1559
|
|
|
1583
|
-
`);
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
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
|
+
}
|
|
1588
1629
|
});
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1630
|
+
} else {
|
|
1631
|
+
if (shouldBuild) {
|
|
1632
|
+
await build2(noSDK);
|
|
1592
1633
|
}
|
|
1593
1634
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
const
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
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
|
+
`);
|
|
1611
1652
|
});
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
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
|
+
}
|
|
1617
1686
|
});
|
|
1618
|
-
warning = warning || returnWarning;
|
|
1619
|
-
error = error || returnError;
|
|
1620
|
-
}
|
|
1621
|
-
ctx.warning = warning;
|
|
1622
|
-
ctx.error = error;
|
|
1623
|
-
next();
|
|
1624
|
-
};
|
|
1625
|
-
var printFinalMessage = async (ctx, next, _options) => {
|
|
1626
|
-
if (ctx.error) {
|
|
1627
|
-
logger.error(import_chalk4.default.redBright(`\u203C\uFE0F Audit ${import_chalk4.default.bold("failed")} with errors`));
|
|
1628
|
-
} else if (ctx.warning) {
|
|
1629
|
-
logger.warn(import_chalk4.default.yellowBright("\u26A0\uFE0F Audit passed with warnings"));
|
|
1630
1687
|
} else {
|
|
1631
|
-
|
|
1688
|
+
if (process.env.CI) {
|
|
1689
|
+
logger.info("Detected CI environment, omitting watch commands...");
|
|
1690
|
+
}
|
|
1691
|
+
start();
|
|
1692
|
+
startSubprocess();
|
|
1632
1693
|
}
|
|
1633
|
-
|
|
1634
|
-
};
|
|
1694
|
+
}
|
|
1635
1695
|
|
|
1636
1696
|
// pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/cli/src/cmds/baseCmds.ts
|
|
1637
|
-
var import_chalk5 = __toModule(require("chalk"));
|
|
1638
1697
|
var CMD_GEN_TYPES = "schema:types";
|
|
1639
1698
|
var CMD_START_SERVER = "server:start";
|
|
1640
1699
|
var CMD_COMPILE_MODELS = "schema:compile";
|
|
@@ -1648,6 +1707,10 @@ var experimentalDatalayer = {
|
|
|
1648
1707
|
name: "--experimentalData",
|
|
1649
1708
|
description: "Build the server with additional data querying capabilities"
|
|
1650
1709
|
};
|
|
1710
|
+
var schemaFileType = {
|
|
1711
|
+
name: "--schemaFileType [fileType]",
|
|
1712
|
+
description: "The file type to use for the Tina schema"
|
|
1713
|
+
};
|
|
1651
1714
|
var subCommand = {
|
|
1652
1715
|
name: "-c, --command <command>",
|
|
1653
1716
|
description: "The sub-command to run"
|
|
@@ -1676,6 +1739,10 @@ var watchFileOption = {
|
|
|
1676
1739
|
name: "-w, --watchFolders [folders...]",
|
|
1677
1740
|
description: "a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
1678
1741
|
};
|
|
1742
|
+
var verboseOption = {
|
|
1743
|
+
name: "-v, --verbose",
|
|
1744
|
+
description: "increase verbosity of logged output"
|
|
1745
|
+
};
|
|
1679
1746
|
var baseCmds = [
|
|
1680
1747
|
{
|
|
1681
1748
|
command: CMD_START_SERVER,
|
|
@@ -1687,7 +1754,8 @@ var baseCmds = [
|
|
|
1687
1754
|
noWatchOption,
|
|
1688
1755
|
noSDKCodegenOption,
|
|
1689
1756
|
noTelemetryOption,
|
|
1690
|
-
watchFileOption
|
|
1757
|
+
watchFileOption,
|
|
1758
|
+
verboseOption
|
|
1691
1759
|
],
|
|
1692
1760
|
action: (options) => chain([startServer], options)
|
|
1693
1761
|
},
|
|
@@ -1705,14 +1773,14 @@ var baseCmds = [
|
|
|
1705
1773
|
},
|
|
1706
1774
|
{
|
|
1707
1775
|
command: INIT,
|
|
1708
|
-
options: [experimentalDatalayer, noTelemetryOption],
|
|
1776
|
+
options: [experimentalDatalayer, noTelemetryOption, schemaFileType],
|
|
1709
1777
|
description: "Add Tina Cloud to an existing project",
|
|
1710
1778
|
action: (options) => chain([
|
|
1711
1779
|
checkDeps,
|
|
1712
1780
|
initTina,
|
|
1713
1781
|
installDeps,
|
|
1714
|
-
async (_ctx, next) => {
|
|
1715
|
-
await compile(_ctx, next);
|
|
1782
|
+
async (_ctx, next, options2) => {
|
|
1783
|
+
await compile(_ctx, next, options2);
|
|
1716
1784
|
next();
|
|
1717
1785
|
},
|
|
1718
1786
|
attachSchema,
|
|
@@ -1731,14 +1799,14 @@ var baseCmds = [
|
|
|
1731
1799
|
next();
|
|
1732
1800
|
},
|
|
1733
1801
|
async (_ctx, next) => {
|
|
1734
|
-
await compile(_ctx, next);
|
|
1802
|
+
await compile(_ctx, next, options);
|
|
1735
1803
|
next();
|
|
1736
1804
|
},
|
|
1737
1805
|
attachSchema,
|
|
1738
1806
|
genTypes,
|
|
1739
1807
|
async (_ctx, next) => {
|
|
1740
1808
|
logger.level = "info";
|
|
1741
|
-
logger.info(
|
|
1809
|
+
logger.info(import_chalk7.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}"));
|
|
1742
1810
|
next();
|
|
1743
1811
|
},
|
|
1744
1812
|
audit,
|