Giter Club home page Giter Club logo

netlify-ts's People

Contributors

gewfy avatar jsaari97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

netlify-ts's Issues

CLI Output Path Not Working

Hi having problems with the file output location of the types file
When I'm running on the CLI, the output argument will always use the default value of netlify-types.ts

Expected Behavior

netlify-ts public/admin/config.yml src/my-types.ts outputs a file to src/my-types.ts

Current Behavior

netlify-ts public/admin/config.yml src/my-types.ts outputs a file to netlify-types.ts

Context (Environment)

WSL2 Ubuntu on windows 11
npm 6.13.15
node 14.17.6

Feature request: allow usage of "label_singular" as interface name

Hi, first of all - nice project!

If I have a collection like this:

name: "cars"
label: "Cars"
label_singular: "Car"

the generated interface is called cars. That is a good default because it is the unique identifier. It would, however, be more idiomatic to name the interface Car.

What do you think about adding an opt-in configuration for using the label_singular as interface name? Or maybe a way to define a custom mapping for interface names?

Best regards

Number widget is typed as string

Hey, first of all, this is a very nice library!

If I define a field with widget: "number", the generated type for this field is a string. Is there a reasoning behind this or could this be changed to number?

Widget type number defaults to type string

Hi ๐Ÿ‘‹
Merry Christmas and Happy New Year!

Minor tweak here. The default value_type for widget type number seems to be int. So if you don't specify it, it will type fields as strings

case "number":
return field.value_type === "int" || field.value_type === "float" ? "number" : "string";

Makes sense since the docs describe value_type as it defaults to string:

value_type: accepts int or float; any other value results in saving as a string

But that is simply not true :P
https://github.com/netlify/netlify-cms/blob/88a5a8098e16f36254d96ec0b814d27e4415f100/packages/netlify-cms-widget-number/src/NumberControl.js#L71-L81

Support multiple uploads

If an image or file widget has property media_library.config.multiple set to true, and is using an external filesystem (eg. Cloudinary or Uploadcare) โ€“ then the widget type should resolve to string[], as the widget data type is saved as an array of strings.

In other cases the data type should be string.

Transform breaks if field name isn't Capitalized

also it fails if field name is something like 'large_video'

in transform.js

const pattern = new RegExp(`(${typeNames.map((w) => `${name}_${w}`).join("|")}) {`);

here's my regexp
/(Post_Slice_Hero|Post_Slice_editor|Post_Slice_large_video) {/

and here's what pattern.test runs against (for example)

'interface Page_Slice_LargeVideo { title: string; description?: string; media: any; poster?: string; }',

so 'rest' and 'interfaces' arrays get messed up and types eventually are broken

UPD: some more info

I believe it happens only to "typed lists" when label is used to set widgetName here

I'll have to disable labels anyways as they are less permanent and robust.

Thanks for a great module BTW. I wonder why it's not more popular. It would be great to have a way to parse a js object instead of config.yml to use with manual init .

Body field is missing

Hello! It seems the body field is missing from my types. I haven't managed to track down the cause (don't have time now), but definitely happening in the transformType() function.

This console.log() could help in tracking down the cause.

if (widget.name === "body") {
    console.log('body types', types);
    // outputs: body types [ [ 'title: string;', 'date: string;' ], [] ]
    return types;
}

My config and generated type:

Config.yml

...
collections:
    - label: "Blog"
      name: "blog"
      folder: "content/post"
      create: true
      slug: "{{slug}}"
      fields:
          - { label: "Title", name: "title", widget: "string", required: true }
          - {
                label: "Publish date",
                name: "publishDate",
                widget: "datetime",
                required: true,
            }
          - {
                label: "Featured Image",
                name: "thumbnail",
                widget: "image",
                required: false,
            }
          - { label: "Body", name: "body", widget: "markdown", required: true }
          - {
                label: "Created date",
                name: "createdDate",
                widget: "datetime",
                required: true,
            }
...

Generated type:

export interface Blog {
  title: string;
  publishDate: string;
  thumbnail?: string;
  createdDate: string;
}

Use name instead of label

If you translate anything to accomodate the end user, it's the label. The names, however, are more of "code" than anything else, so the types should be named from the names of the fields and collections rather than the labels.

feature request: possibility for datetime widgets to be typed as Date

When generating fields with the widget datetime I'd like them to be typed as Date because gray-matter automatically parses these fields to Date.

Example Netlify config.yml:

collections:
    - label: "Blog"
      name: "blog"
      fields:
          - {
                label: "Published date",
                name: "publishedDate",
                widget: "datetime",
                required: true,
            }

Generated types:

export interface Blog {
  publishedDate: string;
}

Desired generated type:

export interface Blog {
  publishedDate: Date;
}

My setup:

    "gray-matter": "^4.0.3",
    "netlify-ts": "^2.0.0",

Sync version?

For situations when promises aren't supported (for example, inside an eslint rule), would you be open to a netlifyTs.sync(...) function? It seems like it's only the filesystem-reading that relies on promises, and those APIs have sync equivalents too. I'd be happy to put up a PR if so.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.