@tinacms/cli 1.5.3 → 1.5.5

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.
@@ -1,10 +1,17 @@
1
1
  import type { Collection, TinaField } from '@tinacms/schema-tools';
2
+ export declare const stringifyLabel: (label: string) => string;
3
+ export declare const stringifyLabelWithField: (label: string) => string;
2
4
  export declare const generateAllTemplates: ({ pathToForestryConfig, }: {
3
5
  pathToForestryConfig: string;
4
6
  }) => Promise<Map<string, {
5
7
  fields: TinaField[];
6
8
  templateObj: any;
7
9
  }>>;
8
- export declare const generateCollections: ({ pathToForestryConfig, }: {
10
+ export declare const generateCollections: ({ pathToForestryConfig, usingTypescript, }: {
9
11
  pathToForestryConfig: string;
10
- }) => Promise<Collection<false>[]>;
12
+ usingTypescript: boolean;
13
+ }) => Promise<{
14
+ collections: Collection<false>[];
15
+ importStatements: string;
16
+ templateCode: string;
17
+ }>;
@@ -0,0 +1,38 @@
1
+ import { TinaField } from '@tinacms/schema-tools';
2
+ /**
3
+ * This function is used to replace the internal code with the actual code
4
+ *
5
+ * EX:
6
+ * __TINA_INTERNAL__:::...fields::: => ...fields
7
+ *
8
+ * or __TINA_INTERNAL__:::fields::: => fields
9
+ */
10
+ export declare const addVariablesToCode: (codeWithTinaPrefix: string) => {
11
+ code: string;
12
+ };
13
+ export declare const makeFieldsWithInternalCode: ({ hasBody, field, bodyField, spread, }: {
14
+ hasBody: true;
15
+ field: string;
16
+ spread?: never;
17
+ bodyField: unknown;
18
+ } | {
19
+ hasBody: false;
20
+ field: string;
21
+ spread?: boolean;
22
+ bodyField?: never;
23
+ } | {
24
+ hasBody: boolean;
25
+ field: string;
26
+ spread?: boolean;
27
+ bodyField: unknown;
28
+ }) => string | unknown[];
29
+ export declare const makeTemplateFile: ({ templateMap, usingTypescript, }: {
30
+ templateMap: Map<string, {
31
+ fields: TinaField[];
32
+ templateObj: any;
33
+ }>;
34
+ usingTypescript: boolean;
35
+ }) => Promise<{
36
+ importStatements: string[];
37
+ templateCodeText: string;
38
+ }>;
@@ -17,6 +17,7 @@ declare const forestryFieldWithoutField: z.ZodObject<{
17
17
  name: z.ZodString;
18
18
  label: z.ZodString;
19
19
  default: z.ZodOptional<z.ZodAny>;
20
+ template: z.ZodOptional<z.ZodString>;
20
21
  config: z.ZodOptional<z.ZodObject<{
21
22
  min: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
22
23
  max: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
@@ -79,6 +80,7 @@ declare const forestryFieldWithoutField: z.ZodObject<{
79
80
  type?: "number" | "boolean" | "file" | "text" | "include" | "list" | "select" | "datetime" | "image_gallery" | "textarea" | "tag_list" | "field_group" | "field_group_list" | "blocks" | "color";
80
81
  label?: string;
81
82
  template_types?: string[];
83
+ template?: string;
82
84
  }, {
83
85
  default?: any;
84
86
  config?: {
@@ -98,6 +100,7 @@ declare const forestryFieldWithoutField: z.ZodObject<{
98
100
  type?: "number" | "boolean" | "file" | "text" | "include" | "list" | "select" | "datetime" | "image_gallery" | "textarea" | "tag_list" | "field_group" | "field_group_list" | "blocks" | "color";
99
101
  label?: string;
100
102
  template_types?: string[];
103
+ template?: string;
101
104
  }>;
102
105
  declare type ForestryFieldWithoutFieldType = z.infer<typeof forestryFieldWithoutField>;
103
106
  interface ForestryFieldType extends ForestryFieldWithoutFieldType {
@@ -8,6 +8,7 @@ export declare function initStaticTina({ rootPath, pathToForestryConfig, noTelem
8
8
  noTelemetry: boolean;
9
9
  }): Promise<void>;
10
10
  export interface AddConfigArgs {
11
+ extraText?: string;
11
12
  publicFolder: string;
12
13
  baseDir: string;
13
14
  usingTypescript: boolean;
@@ -17,6 +18,11 @@ export interface AddConfigArgs {
17
18
  clientId?: string;
18
19
  isForestryMigration?: boolean;
19
20
  }
21
+ export declare const addTemplateFile: (args: {
22
+ templateCode: string;
23
+ baseDir: string;
24
+ usingTypescript: boolean;
25
+ }) => Promise<void>;
20
26
  /**
21
27
  * Executes a shell command and return it as a Promise.
22
28
  * @param cmd {string}
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(src_exports);
31
31
  var import_clipanion6 = require("clipanion");
32
32
 
33
33
  // package.json
34
- var version = "1.5.3";
34
+ var version = "1.5.5";
35
35
 
36
36
  // src/next/commands/dev-command/index.ts
37
37
  var import_clipanion = require("clipanion");
@@ -2583,7 +2583,7 @@ var import_clipanion5 = require("clipanion");
2583
2583
 
2584
2584
  // src/cmds/init/index.ts
2585
2585
  var import_path10 = __toESM(require("path"));
2586
- var import_prettier = require("prettier");
2586
+ var import_prettier2 = require("prettier");
2587
2587
  var import_fs_extra9 = __toESM(require("fs-extra"));
2588
2588
  var import_prompts2 = __toESM(require("prompts"));
2589
2589
  var import_metrics2 = require("@tinacms/metrics");
@@ -2832,6 +2832,7 @@ var clientConfig = (isForestryMigration) => {
2832
2832
  var other = (args) => {
2833
2833
  return `
2834
2834
  import { defineConfig } from "tinacms";
2835
+ ${args.extraText || ""}
2835
2836
 
2836
2837
  // Your hosting provider likely exposes this as an environment variable
2837
2838
  const branch = process.env.HEAD || process.env.VERCEL_GIT_COMMIT_REF || "main";
@@ -2980,6 +2981,61 @@ var ErrorSingleton = class {
2980
2981
  }
2981
2982
  };
2982
2983
 
2984
+ // src/cmds/forestry-migrate/util/codeTransformer.ts
2985
+ var import_prettier = require("prettier");
2986
+ var import_parser_typescript = __toESM(require("prettier/parser-typescript"));
2987
+ var addVariablesToCode = (codeWithTinaPrefix) => {
2988
+ const code = codeWithTinaPrefix.replace(
2989
+ /"__TINA_INTERNAL__:::(.*?):::"/g,
2990
+ "$1"
2991
+ );
2992
+ return { code };
2993
+ };
2994
+ var makeFieldsWithInternalCode = ({
2995
+ hasBody,
2996
+ field,
2997
+ bodyField,
2998
+ spread
2999
+ }) => {
3000
+ if (hasBody) {
3001
+ return [bodyField, `__TINA_INTERNAL__:::...${field}():::`];
3002
+ } else {
3003
+ if (spread)
3004
+ return `__TINA_INTERNAL__:::...${field}():::`;
3005
+ return `__TINA_INTERNAL__:::${field}():::`;
3006
+ }
3007
+ };
3008
+ var makeTemplateFile = async ({
3009
+ templateMap,
3010
+ usingTypescript
3011
+ }) => {
3012
+ const importStatements = [];
3013
+ const templateCodeText = [];
3014
+ for (const template of templateMap.values()) {
3015
+ importStatements.push(
3016
+ `import { ${stringifyLabelWithField(
3017
+ template.templateObj.label
3018
+ )} } from './templates'`
3019
+ );
3020
+ templateCodeText.push(
3021
+ `export function ${stringifyLabelWithField(
3022
+ template.templateObj.label
3023
+ )} (){
3024
+ return ${addVariablesToCode(JSON.stringify(template.fields, null, 2)).code} ${usingTypescript ? "as TinaField[]" : ""}
3025
+ } `
3026
+ );
3027
+ }
3028
+ const templateCode = `
3029
+ ${usingTypescript ? "import type { TinaField } from 'tinacms'" : ""}
3030
+ ${templateCodeText.join("\n")}
3031
+ `;
3032
+ const formattedCode = (0, import_prettier.format)(templateCode, {
3033
+ parser: "typescript",
3034
+ plugins: [import_parser_typescript.default]
3035
+ });
3036
+ return { importStatements, templateCodeText: formattedCode };
3037
+ };
3038
+
2983
3039
  // src/cmds/forestry-migrate/util/index.ts
2984
3040
  var errorSingletonInstance = ErrorSingleton.getInstance();
2985
3041
  var NAME_TEST_REGEX = /^[a-zA-Z0-9_]*$/;
@@ -3050,6 +3106,7 @@ var forestryFieldWithoutField = import_zod.default.object({
3050
3106
  name: import_zod.default.string(),
3051
3107
  label: import_zod.default.string(),
3052
3108
  default: import_zod.default.any().optional(),
3109
+ template: import_zod.default.string().optional(),
3053
3110
  config: import_zod.default.object({
3054
3111
  min: import_zod.default.number().optional().nullable(),
3055
3112
  max: import_zod.default.number().optional().nullable(),
@@ -3227,19 +3284,23 @@ var transformForestryFieldsToTinaFields = ({
3227
3284
  })
3228
3285
  };
3229
3286
  break;
3230
- case "blocks":
3287
+ case "blocks": {
3231
3288
  if (skipBlocks) {
3232
3289
  break;
3233
3290
  }
3234
3291
  const templates = [];
3235
3292
  forestryField2 == null ? void 0 : forestryField2.template_types.forEach((tem) => {
3236
- const { fields: fields2, template: template2 } = getFieldsFromTemplates({
3293
+ const { template: template2 } = getFieldsFromTemplates({
3237
3294
  tem,
3238
3295
  skipBlocks: true,
3239
3296
  pathToForestryConfig
3240
3297
  });
3298
+ const fieldsString = stringifyLabelWithField(template2.label);
3241
3299
  const t = {
3242
- fields: fields2,
3300
+ fields: makeFieldsWithInternalCode({
3301
+ hasBody: false,
3302
+ field: fieldsString
3303
+ }),
3243
3304
  label: template2.label,
3244
3305
  name: stringifyTemplateName(tem, tem)
3245
3306
  };
@@ -3258,13 +3319,25 @@ var transformForestryFieldsToTinaFields = ({
3258
3319
  templates
3259
3320
  };
3260
3321
  break;
3261
- case "include":
3262
- logger.info(
3263
- warnText(
3264
- `Unsupported field type: ${forestryField2.type}, in forestry ${template}. This will not be added to the schema.`
3265
- )
3322
+ }
3323
+ case "include": {
3324
+ const tem = forestryField2.template;
3325
+ const { template: template2 } = getFieldsFromTemplates({
3326
+ tem,
3327
+ skipBlocks: true,
3328
+ pathToForestryConfig
3329
+ });
3330
+ const fieldsString = stringifyLabelWithField(template2.label);
3331
+ const field2 = makeFieldsWithInternalCode({
3332
+ field: fieldsString,
3333
+ hasBody: false,
3334
+ spread: true
3335
+ });
3336
+ tinaFields.push(
3337
+ field2
3266
3338
  );
3267
3339
  break;
3340
+ }
3268
3341
  default:
3269
3342
  logger.info(
3270
3343
  warnText(
@@ -3329,6 +3402,10 @@ var BODY_FIELD = {
3329
3402
  var stringifyLabel = (label) => {
3330
3403
  return label.replace(/[^a-zA-Z0-9]/g, "_").toLowerCase();
3331
3404
  };
3405
+ var stringifyLabelWithField = (label) => {
3406
+ const labelString = stringifyLabel(label);
3407
+ return `${labelString}Fields`;
3408
+ };
3332
3409
  var transformForestryMatchToTinaMatch = (match) => {
3333
3410
  var _a, _b;
3334
3411
  const newMatch = (_b = (_a = match.replace(" ", "").replace(/\.?(mdx|md|json|yaml|yml|toml)/g, "")) == null ? void 0 : _a.replace(/\..*$/g, "")) == null ? void 0 : _b.replace("{}", "");
@@ -3375,143 +3452,197 @@ var generateAllTemplates = async ({
3375
3452
  var generateCollectionFromForestrySection = (section, templateMap) => {
3376
3453
  if (section.read_only)
3377
3454
  return;
3378
- {
3379
- if (section.read_only)
3380
- return;
3381
- const baseCollection = {
3382
- label: section.label,
3383
- name: stringifyLabel(section.label),
3384
- path: section.path
3385
- };
3386
- if (section.match) {
3387
- baseCollection.match = {
3388
- ...(baseCollection == null ? void 0 : baseCollection.match) || {},
3389
- include: transformForestryMatchToTinaMatch(section.match)
3390
- };
3455
+ let format3 = "md";
3456
+ if (section.new_doc_ext) {
3457
+ const ext = checkExt(section.new_doc_ext);
3458
+ if (ext) {
3459
+ format3 = ext;
3391
3460
  }
3392
- if (section.exclude) {
3393
- baseCollection.match = {
3394
- ...(baseCollection == null ? void 0 : baseCollection.match) || {},
3395
- exclude: transformForestryMatchToTinaMatch(section.exclude)
3396
- };
3461
+ }
3462
+ const baseCollection = {
3463
+ format: format3,
3464
+ label: section.label,
3465
+ name: stringifyLabel(section.label),
3466
+ path: section.path || "/"
3467
+ };
3468
+ if (section.match) {
3469
+ baseCollection.match = {
3470
+ ...(baseCollection == null ? void 0 : baseCollection.match) || {},
3471
+ include: transformForestryMatchToTinaMatch(section.match)
3472
+ };
3473
+ }
3474
+ if (section.exclude) {
3475
+ baseCollection.match = {
3476
+ ...(baseCollection == null ? void 0 : baseCollection.match) || {},
3477
+ exclude: transformForestryMatchToTinaMatch(section.exclude)
3478
+ };
3479
+ }
3480
+ if (section.type === "directory") {
3481
+ if (!(section == null ? void 0 : section.path) || section.path === "/" || section.path === "./" || section.path === ".") {
3482
+ logger.log(
3483
+ warnText(
3484
+ `Warning: Section ${section.label} is using a Root Path. Currently, Tina Does not support Root paths see ${linkText(
3485
+ "https://github.com/tinacms/tinacms/issues/3768"
3486
+ )} for more updates on this issue.`
3487
+ )
3488
+ );
3489
+ return;
3397
3490
  }
3398
- if (section.type === "directory") {
3399
- const forestryTemplates = (section == null ? void 0 : section.templates) || [];
3400
- if (forestryTemplates.length === 0 && section.create === "all") {
3401
- for (let templateKey of templateMap.keys()) {
3402
- const { templateObj } = templateMap.get(templateKey);
3403
- const pages = templateObj == null ? void 0 : templateObj.pages;
3404
- if (pages) {
3405
- if (pages.some(
3406
- (page) => (0, import_minimatch.default)(page, section.path + "/" + section.match)
3407
- )) {
3408
- forestryTemplates.push(templateKey);
3409
- }
3491
+ const forestryTemplates = (section == null ? void 0 : section.templates) || [];
3492
+ if (forestryTemplates.length === 0 && section.create === "all") {
3493
+ for (let templateKey of templateMap.keys()) {
3494
+ const { templateObj } = templateMap.get(templateKey);
3495
+ const pages = templateObj == null ? void 0 : templateObj.pages;
3496
+ if (pages) {
3497
+ let glob = section.match;
3498
+ const skipPath = section.path === "" || section.path === "/" || !section.path;
3499
+ if (!skipPath) {
3500
+ glob = section.path + "/" + section.match;
3501
+ }
3502
+ if (pages.some((page) => {
3503
+ return (0, import_minimatch.default)(page, glob);
3504
+ })) {
3505
+ forestryTemplates.push(templateKey);
3410
3506
  }
3411
3507
  }
3412
3508
  }
3413
- const c = ((forestryTemplates == null ? void 0 : forestryTemplates.length) || 0) > 1 ? {
3509
+ }
3510
+ const hasBody = ["md", "mdx", "markdown"].includes(format3);
3511
+ let c;
3512
+ if (((forestryTemplates == null ? void 0 : forestryTemplates.length) || 0) > 1) {
3513
+ c = {
3414
3514
  ...baseCollection,
3415
3515
  templates: forestryTemplates.map((tem) => {
3416
- const { fields } = templateMap.get(tem);
3516
+ const currentTemplate = templateMap.get(tem);
3517
+ const fieldsString = stringifyLabelWithField(
3518
+ currentTemplate.templateObj.label
3519
+ );
3417
3520
  return {
3418
- fields: [BODY_FIELD, ...fields],
3521
+ fields: makeFieldsWithInternalCode({
3522
+ hasBody,
3523
+ field: fieldsString,
3524
+ bodyField: BODY_FIELD
3525
+ }),
3419
3526
  label: tem,
3420
3527
  name: stringifyLabel(tem)
3421
3528
  };
3422
3529
  })
3423
- } : {
3530
+ };
3531
+ }
3532
+ if ((forestryTemplates == null ? void 0 : forestryTemplates.length) === 1) {
3533
+ const tem = forestryTemplates[0];
3534
+ const template = templateMap.get(tem);
3535
+ const fieldsString = stringifyLabelWithField(template.templateObj.label);
3536
+ c = {
3424
3537
  ...baseCollection,
3425
- fields: [
3426
- BODY_FIELD,
3427
- ...(forestryTemplates || []).flatMap((tem) => {
3428
- try {
3429
- const { fields: additionalFields } = templateMap.get(tem);
3430
- return additionalFields;
3431
- } catch (e) {
3432
- logger.log("Error parsing template ", tem);
3433
- return [];
3434
- }
3435
- })
3436
- ]
3538
+ fields: makeFieldsWithInternalCode({
3539
+ field: fieldsString,
3540
+ hasBody,
3541
+ bodyField: BODY_FIELD
3542
+ })
3437
3543
  };
3438
- if ((section == null ? void 0 : section.create) === "none") {
3439
- c.ui = {
3440
- ...c.ui,
3441
- allowedActions: {
3442
- create: false
3443
- }
3444
- };
3445
- }
3446
- return c;
3447
- } else if (section.type === "document") {
3448
- const filePath = section.path;
3449
- const extname = import_path8.default.extname(filePath);
3450
- const fileName = import_path8.default.basename(filePath, extname);
3451
- const dir = import_path8.default.dirname(filePath);
3452
- const ext = checkExt(extname);
3453
- if (ext) {
3454
- const fields = [];
3455
- if (ext === "md" || ext === "mdx") {
3456
- fields.push(BODY_FIELD);
3457
- }
3458
- for (let currentTemplateName of templateMap.keys()) {
3459
- const { templateObj, fields: additionalFields } = templateMap.get(currentTemplateName);
3460
- const pages = (templateObj == null ? void 0 : templateObj.pages) || [];
3461
- if (pages.includes(section.path)) {
3462
- fields.push(...additionalFields);
3463
- break;
3464
- }
3544
+ }
3545
+ if ((forestryTemplates == null ? void 0 : forestryTemplates.length) === 0) {
3546
+ logger.warn(
3547
+ warnText(
3548
+ `No templates found for section ${section.label}. Please see ${linkText(
3549
+ "https://tina.io/docs/forestry/content-modelling/"
3550
+ )} for more information`
3551
+ )
3552
+ );
3553
+ c = {
3554
+ ...baseCollection,
3555
+ fields: [BODY_FIELD]
3556
+ };
3557
+ }
3558
+ if ((section == null ? void 0 : section.create) === "none") {
3559
+ c.ui = {
3560
+ ...c.ui,
3561
+ allowedActions: {
3562
+ create: false
3465
3563
  }
3466
- if (fields.length === 0) {
3467
- fields.push({
3468
- name: "dummy",
3469
- label: "Dummy field",
3470
- type: "string",
3471
- description: "This is a dummy field, please replace it with the fields you want to edit. See https://tina.io/docs/schema/ for more info"
3472
- });
3473
- logger.warn(
3474
- warnText(
3475
- `No fields found for ${section.path}. Please add the fields you want to edit to the ${section.label} collection in the config file.`
3476
- )
3477
- );
3564
+ };
3565
+ }
3566
+ return c;
3567
+ } else if (section.type === "document") {
3568
+ const filePath = section.path;
3569
+ const extname = import_path8.default.extname(filePath);
3570
+ const fileName = import_path8.default.basename(filePath, extname);
3571
+ const dir = import_path8.default.dirname(filePath);
3572
+ const ext = checkExt(extname);
3573
+ if (ext) {
3574
+ const fields = [];
3575
+ if (ext === "md" || ext === "mdx") {
3576
+ fields.push(BODY_FIELD);
3577
+ }
3578
+ for (let currentTemplateName of templateMap.keys()) {
3579
+ const { templateObj, fields: additionalFields } = templateMap.get(currentTemplateName);
3580
+ const pages = (templateObj == null ? void 0 : templateObj.pages) || [];
3581
+ if (pages.includes(section.path)) {
3582
+ fields.push(...additionalFields);
3583
+ break;
3478
3584
  }
3479
- return {
3480
- ...baseCollection,
3481
- path: dir,
3482
- format: ext,
3483
- ui: {
3484
- allowedActions: {
3485
- create: false,
3486
- delete: false
3487
- }
3488
- },
3489
- match: {
3490
- include: fileName
3491
- },
3492
- fields
3493
- };
3494
- } else {
3495
- logger.log(
3585
+ }
3586
+ if (fields.length === 0) {
3587
+ fields.push({
3588
+ name: "dummy",
3589
+ label: "Dummy field",
3590
+ type: "string",
3591
+ description: "This is a dummy field, please replace it with the fields you want to edit. See https://tina.io/docs/schema/ for more info"
3592
+ });
3593
+ logger.warn(
3496
3594
  warnText(
3497
- `Error: document section has an unsupported file extension: ${extname} in ${section.path}`
3595
+ `No fields found for ${section.path}. Please add the fields you want to edit to the ${section.label} collection in the config file.`
3498
3596
  )
3499
3597
  );
3500
3598
  }
3599
+ return {
3600
+ ...baseCollection,
3601
+ path: dir,
3602
+ format: ext,
3603
+ ui: {
3604
+ allowedActions: {
3605
+ create: false,
3606
+ delete: false
3607
+ }
3608
+ },
3609
+ match: {
3610
+ include: fileName
3611
+ },
3612
+ fields
3613
+ };
3614
+ } else {
3615
+ logger.log(
3616
+ warnText(
3617
+ `Error: document section has an unsupported file extension: ${extname} in ${section.path}`
3618
+ )
3619
+ );
3501
3620
  }
3502
3621
  }
3503
3622
  };
3504
3623
  var generateCollections = async ({
3505
- pathToForestryConfig
3624
+ pathToForestryConfig,
3625
+ usingTypescript
3506
3626
  }) => {
3507
3627
  const templateMap = await generateAllTemplates({ pathToForestryConfig });
3628
+ const { importStatements, templateCodeText } = await makeTemplateFile({
3629
+ templateMap,
3630
+ usingTypescript
3631
+ });
3508
3632
  const forestryConfig = await import_fs_extra7.default.readFile(
3509
3633
  import_path8.default.join(pathToForestryConfig, ".forestry", "settings.yml")
3510
3634
  );
3511
3635
  rewriteTemplateKeysInDocs(templateMap, pathToForestryConfig);
3512
- return parseSections({ val: import_js_yaml2.default.load(forestryConfig.toString()) }).sections.map(
3636
+ const collections = parseSections({
3637
+ val: import_js_yaml2.default.load(forestryConfig.toString())
3638
+ }).sections.map(
3513
3639
  (section) => generateCollectionFromForestrySection(section, templateMap)
3514
3640
  ).filter((c) => c !== void 0);
3641
+ return {
3642
+ collections,
3643
+ importStatements: importStatements.join("\n"),
3644
+ templateCode: templateCodeText
3645
+ };
3515
3646
  };
3516
3647
  var rewriteTemplateKeysInDocs = (templateMap, rootPath) => {
3517
3648
  var _a;
@@ -3625,15 +3756,21 @@ async function initStaticTina({
3625
3756
  const usingTypescript = await chooseTypescript();
3626
3757
  const publicFolder = await choosePublicFolder({ framework });
3627
3758
  let collections;
3759
+ let templateCode;
3760
+ let extraText;
3628
3761
  const hasForestryConfig = await import_fs_extra9.default.pathExists(
3629
3762
  import_path10.default.join(pathToForestryConfig, ".forestry", "settings.yml")
3630
3763
  );
3631
3764
  let isForestryMigration = false;
3632
3765
  if (hasForestryConfig) {
3633
- collections = await forestryMigrate({
3766
+ const { collectionString, importStatements, templateCodeString } = await forestryMigrate({
3767
+ usingTypescript,
3634
3768
  pathToForestryConfig
3635
3769
  });
3636
- if (collections) {
3770
+ if (collectionString) {
3771
+ templateCode = templateCodeString;
3772
+ collections = collectionString;
3773
+ extraText = importStatements;
3637
3774
  isForestryMigration = true;
3638
3775
  }
3639
3776
  }
@@ -3658,6 +3795,9 @@ async function initStaticTina({
3658
3795
  }
3659
3796
  }
3660
3797
  await addDependencies(packageManager);
3798
+ if (hasForestryConfig) {
3799
+ await addTemplateFile({ baseDir: "", usingTypescript, templateCode });
3800
+ }
3661
3801
  await addConfigFile({
3662
3802
  publicFolder: import_path10.default.join(
3663
3803
  import_path10.default.relative(process.cwd(), pathToForestryConfig),
@@ -3669,7 +3809,8 @@ async function initStaticTina({
3669
3809
  collections,
3670
3810
  token,
3671
3811
  clientId,
3672
- isForestryMigration
3812
+ isForestryMigration,
3813
+ extraText
3673
3814
  });
3674
3815
  if (!hasForestryConfig) {
3675
3816
  await addContentFile({ baseDir: "" });
@@ -3723,7 +3864,7 @@ var chooseTypescript = async () => {
3723
3864
  name: "selection",
3724
3865
  type: "confirm",
3725
3866
  initial: true,
3726
- message: "Would you like to use Typescript?"
3867
+ message: "Would you like to use Typescript for your Tina Configuration (Recommended)?"
3727
3868
  });
3728
3869
  return option["selection"];
3729
3870
  };
@@ -3768,7 +3909,8 @@ var chooseFramework = async () => {
3768
3909
  return option["selection"];
3769
3910
  };
3770
3911
  var forestryMigrate = async ({
3771
- pathToForestryConfig
3912
+ pathToForestryConfig,
3913
+ usingTypescript
3772
3914
  }) => {
3773
3915
  logger.info(`Forestry.io configuration found.`);
3774
3916
  const disclaimer = logText(
@@ -3784,11 +3926,18 @@ ${disclaimer}`
3784
3926
  if (!option["selection"]) {
3785
3927
  return null;
3786
3928
  }
3787
- const collections = await generateCollections({
3788
- pathToForestryConfig
3929
+ const { collections, importStatements, templateCode } = await generateCollections({
3930
+ pathToForestryConfig,
3931
+ usingTypescript
3789
3932
  });
3790
3933
  ErrorSingleton.getInstance().printCollectionNameErrors();
3791
- return JSON.stringify(collections, null, 2);
3934
+ const JSONString = JSON.stringify(collections, null, 2);
3935
+ const { code } = addVariablesToCode(JSONString);
3936
+ return {
3937
+ collectionString: code,
3938
+ importStatements,
3939
+ templateCodeString: templateCode
3940
+ };
3792
3941
  };
3793
3942
  var reportTelemetry = async ({
3794
3943
  hasForestryConfig,
@@ -3871,6 +4020,30 @@ var addConfigFile = async (args) => {
3871
4020
  await writeGitignore(baseDir);
3872
4021
  }
3873
4022
  };
4023
+ var addTemplateFile = async (args) => {
4024
+ const { baseDir, usingTypescript, templateCode } = args;
4025
+ const templatesPath = import_path10.default.join(
4026
+ "tina",
4027
+ `templates.${usingTypescript ? "ts" : "js"}`
4028
+ );
4029
+ const fullTemplatesPath = import_path10.default.join(baseDir, templatesPath);
4030
+ if (import_fs_extra9.default.pathExistsSync(fullTemplatesPath)) {
4031
+ const override = await (0, import_prompts2.default)({
4032
+ name: "selection",
4033
+ type: "confirm",
4034
+ message: `Found existing file at ${templatesPath}. Would you like to override?`
4035
+ });
4036
+ if (override["selection"]) {
4037
+ logger.info(logText(`Overriding file at ${templatesPath}.`));
4038
+ await import_fs_extra9.default.outputFileSync(fullTemplatesPath, templateCode);
4039
+ } else {
4040
+ logger.info(logText(`Not overriding file at ${templatesPath}.`));
4041
+ }
4042
+ } else {
4043
+ logger.info(logText(`Adding template file at ${templatesPath}`));
4044
+ await import_fs_extra9.default.outputFileSync(fullTemplatesPath, templateCode);
4045
+ }
4046
+ };
3874
4047
  var addContentFile = async ({ baseDir }) => {
3875
4048
  const contentPath = import_path10.default.join("content", "posts", "hello-world.md");
3876
4049
  const fullContentPath = import_path10.default.join(baseDir, contentPath);
@@ -3931,7 +4104,7 @@ var frameworkDevCmds = {
3931
4104
  }
3932
4105
  };
3933
4106
  var config2 = (args) => {
3934
- return (0, import_prettier.format)(configExamples[args.framework.name](args), { parser: "babel" });
4107
+ return (0, import_prettier2.format)(configExamples[args.framework.name](args), { parser: "babel" });
3935
4108
  };
3936
4109
  var content = `---
3937
4110
  title: Hello, World!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -58,9 +58,9 @@
58
58
  "@tailwindcss/aspect-ratio": "^0.4.0",
59
59
  "@tailwindcss/line-clamp": "^0.3.1",
60
60
  "@tailwindcss/typography": "^0.5.9",
61
- "@tinacms/app": "1.2.3",
62
- "@tinacms/datalayer": "1.2.4",
63
- "@tinacms/graphql": "1.4.4",
61
+ "@tinacms/app": "1.2.5",
62
+ "@tinacms/datalayer": "1.2.6",
63
+ "@tinacms/graphql": "1.4.6",
64
64
  "@tinacms/metrics": "1.0.2",
65
65
  "@tinacms/schema-tools": "1.4.2",
66
66
  "@vitejs/plugin-react": "3.1.0",