Full TypeScript support in `frontity create`

Description

It looks like when users do frontity create --typescript it doesn’t quite work yet. @orballo opened a topic with the current problems: Creating a new package and a custom theme with TypeScript

User Stories

As a Frontity project developer
I want to be able to start a project in TypeScript
so that I can type all my local packages.

Current Problems

These are copied and refactored from the ones @orballo exposed in his post: Creating a new package and a custom theme with TypeScript

  • The project needs these dependencies:

    • typescript
    • @types/react
    • @types/node-fetch
    • Maybe other @types packages used by frontity.
  • The above dependencies could be (not sure which one is better yet):

    • dependencies declared in the root’s package.json.
    • devDependencies declared in the root’s package.json.
    • dependencies declared in the package’s package.json, like @frontity/core.
  • The project needs a tsconfig.json file. Similar to the one we have in our repo.

  • When users add a new field to the default package export, like
    { state: { theme: { some: "field" } } }
    TypeScript won’t complain unless there is at least one defined field at the same level. This is probably due to the default definition of state:
    { state: [key: string]: object }
    We need to improve that.

Questions

  • If users opt-in to use TypeScript (with --typescript or by answering Yes to a Do you want to use TypeScript prompt): should frontity create let them choose only a TypeScript theme? or also a JavaScript theme?
  • I think this one is already solved. @orballo could you please confirm it?
    When you run frontity create-package -t , it is not yet implemented the support for this option (and is not explained in the help command, which leads the developer to believe that there is a bug).

I ran this command in frontity 1.4.2 and it doesn’t seem fixed. The command runs without minding my -t, --typescript option. And when running npx frontity create-package --help the -t option is still present.

Oh I thought you were talking about frontity create, not frontity create-package. My bad.

It looks like @david added the option but didn’t implement the feature and I didn’t noticed it in the code review. I’ve done a PR to remove the option until it is implemented.

1 Like

I was creating a new project, and I think that while there isn’t an available typescript theme (or even if there is one, when I know what I’m doing, I might want to start from zero) there should be an option in frontity create to create a project without any theme installed.

I’ll be working on this from today. One question, are there e2e tests for the CLI? If not, are they needed?

Also, if there is something else that needs to be discussed regarding the implementation, let me know :slight_smile:

For the moment I’ll focus on generating a tsconfig.json file and adding dependencies as devDependencies to the root foolder.

Nope and nope :slightly_smiling_face:

Opened a draft here: Fixes behaviour for the `--typescript` flag when using `frontity create` by orballo · Pull Request #786 · frontity/frontity · GitHub

2 Likes

PR reviewed and approved :slightly_smiling_face::clap:

2 Likes

This PR has been merged :slight_smile:

3 Likes

Awesome. Thanks a lot for your contribution Eduardo!! :grinning_face_with_smiling_eyes::clap:

@david and I have just finished a mars-theme-typescript theme which is used automatically when you do npx frontity create with the --typescript option.

This is the PR, which is right now awaiting a review:

1 Like