@tinacms/cli 1.5.4 → 1.5.6

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.
@@ -7,7 +7,8 @@ export declare const generateAllTemplates: ({ pathToForestryConfig, }: {
7
7
  fields: TinaField[];
8
8
  templateObj: any;
9
9
  }>>;
10
- export declare const generateCollections: ({ pathToForestryConfig, usingTypescript, }: {
10
+ export declare const generateCollections: ({ pathToForestryConfig, usingTypescript, frontMatterFormat, }: {
11
+ frontMatterFormat?: 'toml' | 'yaml' | 'json';
11
12
  pathToForestryConfig: string;
12
13
  usingTypescript: boolean;
13
14
  }) => Promise<{
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.4";
34
+ var version = "1.5.6";
35
35
 
36
36
  // src/next/commands/dev-command/index.ts
37
37
  var import_clipanion = require("clipanion");
@@ -200,7 +200,7 @@ var ConfigManager = class {
200
200
  );
201
201
  if (!this.tinaConfigFilePath) {
202
202
  throw new Error(
203
- `Unable to find confg file in ${this.tinaFolderPath}. Looking for a file named "config.{ts,tsx,js,jsx}"`
203
+ `Unable to find config file in ${this.tinaFolderPath}. Looking for a file named "config.{ts,tsx,js,jsx}"`
204
204
  );
205
205
  }
206
206
  this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
@@ -339,13 +339,13 @@ var ConfigManager = class {
339
339
  }
340
340
  printRelativePath(filename) {
341
341
  if (filename) {
342
- return filename.replace(`${this.rootPath}/`, "");
342
+ return filename.replace(/\\/g, "/").replace(`${this.rootPath}/`, "");
343
343
  }
344
344
  throw `No path provided to print`;
345
345
  }
346
346
  printContentRelativePath(filename) {
347
347
  if (filename) {
348
- return filename.replace(`${this.contentRootPath}/`, "");
348
+ return filename.replace(/\\/g, "/").replace(`${this.contentRootPath}/`, "");
349
349
  }
350
350
  throw `No path provided to print`;
351
351
  }
@@ -3449,7 +3449,8 @@ var generateAllTemplates = async ({
3449
3449
  await Promise.all(proms);
3450
3450
  return templateMap;
3451
3451
  };
3452
- var generateCollectionFromForestrySection = (section, templateMap) => {
3452
+ var generateCollectionFromForestrySection = (args) => {
3453
+ const { section, templateMap } = args;
3453
3454
  if (section.read_only)
3454
3455
  return;
3455
3456
  let format3 = "md";
@@ -3465,6 +3466,12 @@ var generateCollectionFromForestrySection = (section, templateMap) => {
3465
3466
  name: stringifyLabel(section.label),
3466
3467
  path: section.path || "/"
3467
3468
  };
3469
+ if (args.frontMatterFormat) {
3470
+ baseCollection.frontmatterFormat = args.frontMatterFormat;
3471
+ if (args.frontMatterFormat === "toml") {
3472
+ baseCollection.frontmatterDelimiters = "+++";
3473
+ }
3474
+ }
3468
3475
  if (section.match) {
3469
3476
  baseCollection.match = {
3470
3477
  ...(baseCollection == null ? void 0 : baseCollection.match) || {},
@@ -3622,7 +3629,8 @@ var generateCollectionFromForestrySection = (section, templateMap) => {
3622
3629
  };
3623
3630
  var generateCollections = async ({
3624
3631
  pathToForestryConfig,
3625
- usingTypescript
3632
+ usingTypescript,
3633
+ frontMatterFormat
3626
3634
  }) => {
3627
3635
  const templateMap = await generateAllTemplates({ pathToForestryConfig });
3628
3636
  const { importStatements, templateCodeText } = await makeTemplateFile({
@@ -3632,11 +3640,21 @@ var generateCollections = async ({
3632
3640
  const forestryConfig = await import_fs_extra7.default.readFile(
3633
3641
  import_path8.default.join(pathToForestryConfig, ".forestry", "settings.yml")
3634
3642
  );
3635
- rewriteTemplateKeysInDocs(templateMap, pathToForestryConfig);
3643
+ rewriteTemplateKeysInDocs({
3644
+ templateMap,
3645
+ markdownParseConfig: {
3646
+ frontmatterFormat: frontMatterFormat,
3647
+ frontmatterDelimiters: frontMatterFormat === "toml" ? "+++" : void 0
3648
+ }
3649
+ });
3636
3650
  const collections = parseSections({
3637
3651
  val: import_js_yaml2.default.load(forestryConfig.toString())
3638
3652
  }).sections.map(
3639
- (section) => generateCollectionFromForestrySection(section, templateMap)
3653
+ (section) => generateCollectionFromForestrySection({
3654
+ section,
3655
+ templateMap,
3656
+ frontMatterFormat
3657
+ })
3640
3658
  ).filter((c) => c !== void 0);
3641
3659
  return {
3642
3660
  collections,
@@ -3644,8 +3662,9 @@ var generateCollections = async ({
3644
3662
  templateCode: templateCodeText
3645
3663
  };
3646
3664
  };
3647
- var rewriteTemplateKeysInDocs = (templateMap, rootPath) => {
3665
+ var rewriteTemplateKeysInDocs = (args) => {
3648
3666
  var _a;
3667
+ const { templateMap, markdownParseConfig } = args;
3649
3668
  for (const templateKey of templateMap.keys()) {
3650
3669
  const { templateObj } = templateMap.get(templateKey);
3651
3670
  (_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
@@ -3656,12 +3675,20 @@ var rewriteTemplateKeysInDocs = (templateMap, rootPath) => {
3656
3675
  }
3657
3676
  const extname = import_path8.default.extname(filePath);
3658
3677
  const fileContent = import_fs_extra7.default.readFileSync(filePath).toString();
3659
- const content2 = (0, import_graphql14.parseFile)(fileContent, extname, (yup) => yup.object({}));
3678
+ const content2 = (0, import_graphql14.parseFile)(
3679
+ fileContent,
3680
+ extname,
3681
+ (yup) => yup.object({}),
3682
+ markdownParseConfig
3683
+ );
3660
3684
  const newContent = {
3661
3685
  _template: stringifyLabel(templateKey),
3662
3686
  ...content2
3663
3687
  };
3664
- import_fs_extra7.default.writeFileSync(filePath, (0, import_graphql14.stringifyFile)(newContent, extname, true));
3688
+ import_fs_extra7.default.writeFileSync(
3689
+ filePath,
3690
+ (0, import_graphql14.stringifyFile)(newContent, extname, true, markdownParseConfig)
3691
+ );
3665
3692
  } catch (error) {
3666
3693
  console.log(
3667
3694
  dangerText("Error updating template -> _template in ", page)
@@ -3765,7 +3792,9 @@ async function initStaticTina({
3765
3792
  if (hasForestryConfig) {
3766
3793
  const { collectionString, importStatements, templateCodeString } = await forestryMigrate({
3767
3794
  usingTypescript,
3768
- pathToForestryConfig
3795
+ pathToForestryConfig,
3796
+ rootPath,
3797
+ framework
3769
3798
  });
3770
3799
  if (collectionString) {
3771
3800
  templateCode = templateCodeString;
@@ -3910,7 +3939,9 @@ var chooseFramework = async () => {
3910
3939
  };
3911
3940
  var forestryMigrate = async ({
3912
3941
  pathToForestryConfig,
3913
- usingTypescript
3942
+ usingTypescript,
3943
+ rootPath,
3944
+ framework
3914
3945
  }) => {
3915
3946
  logger.info(`Forestry.io configuration found.`);
3916
3947
  const disclaimer = logText(
@@ -3926,11 +3957,15 @@ ${disclaimer}`
3926
3957
  if (!option["selection"]) {
3927
3958
  return null;
3928
3959
  }
3960
+ let frontMatterFormat = null;
3961
+ if (framework.name === "hugo") {
3962
+ frontMatterFormat = await getFrontmatterFormat(rootPath);
3963
+ }
3929
3964
  const { collections, importStatements, templateCode } = await generateCollections({
3930
3965
  pathToForestryConfig,
3931
- usingTypescript
3966
+ usingTypescript,
3967
+ frontMatterFormat
3932
3968
  });
3933
- ErrorSingleton.getInstance().printCollectionNameErrors();
3934
3969
  const JSONString = JSON.stringify(collections, null, 2);
3935
3970
  const { code } = addVariablesToCode(JSONString);
3936
3971
  return {
@@ -3939,6 +3974,32 @@ ${disclaimer}`
3939
3974
  templateCodeString: templateCode
3940
3975
  };
3941
3976
  };
3977
+ var getFrontmatterFormat = async (rootPath) => {
3978
+ try {
3979
+ const hugoConfigPath = import_path10.default.join(rootPath, "config.toml");
3980
+ const hugoConfig = await import_fs_extra9.default.readFile(hugoConfigPath, "utf8");
3981
+ const frontMatterFormat = hugoConfig.match(/metaDataFormat = "(.*)"/);
3982
+ console.log({ frontMatterFormat });
3983
+ if (frontMatterFormat && frontMatterFormat[1]) {
3984
+ return frontMatterFormat[1];
3985
+ }
3986
+ } catch (e) {
3987
+ }
3988
+ const option = await (0, import_prompts2.default)({
3989
+ name: "selection",
3990
+ type: "select",
3991
+ choices: [
3992
+ { title: "yaml", value: "yaml" },
3993
+ { title: "toml", value: "toml" },
3994
+ { title: "json", value: "json" }
3995
+ ],
3996
+ message: `What format are you using in your frontmatter?`
3997
+ });
3998
+ if (!option["selection"]) {
3999
+ return null;
4000
+ }
4001
+ return option["selection"];
4002
+ };
3942
4003
  var reportTelemetry = async ({
3943
4004
  hasForestryConfig,
3944
4005
  noTelemetry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
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.4",
62
- "@tinacms/datalayer": "1.2.5",
63
- "@tinacms/graphql": "1.4.5",
61
+ "@tinacms/app": "1.2.6",
62
+ "@tinacms/datalayer": "1.2.7",
63
+ "@tinacms/graphql": "1.4.7",
64
64
  "@tinacms/metrics": "1.0.2",
65
65
  "@tinacms/schema-tools": "1.4.2",
66
66
  "@vitejs/plugin-react": "3.1.0",