Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template for tsconfig.json + getMetadata.ts + manifest.json #145

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

portdeveloper
Copy link
Collaborator

@portdeveloper portdeveloper commented Oct 26, 2024

Description

Added a template for tsconfig.json file to the project templates.

Changes

  • Added tsconfig.json template file, removed tsconfig.json

Testing

  • Tested template generation with new project creation

Here is a repo with all the changed file args
https://github.com/portdeveloper/test-everything

To-Do

  • Update nextjs config template to work with pwa

@technophile-04
Copy link
Collaborator

Hey port can you share the repo(extension) where you have the .args.mjs?

@rin-st
Copy link
Member

rin-st commented Oct 27, 2024

Could you please take a look at this table? We added it recently. Looks like you can use a raw object instead of a stringified and maybe simplify some logic

@portdeveloper
Copy link
Collaborator Author

portdeveloper commented Oct 27, 2024

Hey thanks for the comments, and I somehow did not receive a notif about Shiv's comment.

So here is the repo:
https://github.com/portdeveloper/test-tsconfig-ext

Maybe we should remove include, exclude and paths and keep the other two?
I tried using stringify but that made the process so complicated :/

lol this was difficult, lmk if i did anything wrong here

@rin-st
Copy link
Member

rin-st commented Oct 28, 2024

So here is the repo:
https://github.com/portdeveloper/test-tsconfig-ext

Update it please, params of extension are different from this pr

I tried using stringify but that made the process so complicated

Thinking without checking, but I think this should work

`${stringify({
  "compilerOptions": {
    ...
    "plugins": [
      {
        name: "next"
      },
      ...extraPlugins[0]
    ],
    ...extraCompilerOptions[0]
  },
  ...
  })}`

where extraPlugins is array of plugins and extraCompilerOptions is an object with extra options. Default values is empty array and empty object respectively

@portdeveloper
Copy link
Collaborator Author

Thanks! Could you please check again to see if i got it right? @rin-st

I have also updated the example args file

@rin-st
Copy link
Member

rin-st commented Oct 28, 2024

Thanks @portdeveloper ! Added some comments.

Also, you can test resulting template for example with this defaults

export default withDefaults(contents, {
  extraPlugins: [{name: "next-abcd"}],
  extraCompilerOptions: {abc: "def"}
})

Copy link
Member

@rin-st rin-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! But don't merge it for now, let's wait also Shiv or Carlos

my-tsconfig-test Outdated Show resolved Hide resolved
pwa Outdated Show resolved Hide resolved
Copy link
Collaborator

@technophile-04 technophile-04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm @portdeveloper I think you forgot to update https://github.com/portdeveloper/test-tsconfig-ext/blob/main/extension/packages/nextjs/tsconfig.json.args.mjs ?

I am just trying to understand what extra tsConfig things we need and maybe we can set them as default in main SE-2 (for eg last time we switched "moduleResolution": "Bundler" by default in SE-2 for better working with all extensions)

Also I think you are working on pwa extension right, so maybe can you add all the required .template.mjs in this PR itself?

@portdeveloper
Copy link
Collaborator Author

@technophile-04
We need this for serwist to work!
image

And there doesn't seem to be anything an extension-builder can add besides more plugins and more compiler options?

I have updated https://github.com/portdeveloper/test-tsconfig-ext/blob/main/extension/packages/nextjs/tsconfig.json.args.mjs too

@technophile-04
Copy link
Collaborator

And there doesn't seem to be anything an extension-builder can add besides more plugins and more compiler options?

yeah true lol there not other options to add, also for pwa do you need any other more template file like manfiest.json or it was just this file?

@portdeveloper
Copy link
Collaborator Author

portdeveloper commented Oct 31, 2024

@technophile-04

We also need these:

Should I get the manifest.json and getMetadata in this PR as well?

@technophile-04
Copy link
Collaborator

technophile-04 commented Nov 1, 2024

Should I get the manifest.json and getMetadata in this PR as well?

Yes could you do that please?

Regarding this :

Change the nextjs template so that we can put things outside of the nextConfig object as in the code below:
https://github.com/portdeveloper/scaffold-pwa/blob/main/packages/nextjs/next.config.mjs

I think we need to update main SE-2 repo with next.config.js => next.config.mjs then we make the PR here to add templatise that file

Thanks @portdeveloper!!

@portdeveloper
Copy link
Collaborator Author

portdeveloper commented Nov 1, 2024

I think we need to update main SE-2 repo with next.config.js => next.config.mjs then we make the PR here to add templatise that file

Sorry for the continued confusion on this.

I think that won't be necessary! Because I am using the next.config.js version in this template!

Let me quickly update that as well.

https://serwist.pages.dev/docs/next/getting-started
image

@technophile-04
Copy link
Collaborator

technophile-04 commented Nov 1, 2024

Oh I got it wrong then sorry : P

image
The latest nextjs uses a next.config.ts.

I wonder if that's also an option for us as well?

@technophile-04
Copy link
Collaborator

The latest nextjs uses a next.config.ts.

I wonder if that's also an option for us as well?

Ohh I see! I think last time I tried using .ts in SE-2 and it gave me weird error but might be fixed and we should use .ts if it works now 🙌 Lets tinker on SE-2 main repo

PS: I am replying to my own comment because Port replied to og comment by editing it 🤣

@portdeveloper
Copy link
Collaborator Author

The latest nextjs uses a next.config.ts.

I wonder if that's also an option for us as well?

Ohh I see! I think last time I tried using .ts in SE-2 and it gave me weird error but might be fixed and we should use .ts if it works now 🙌 Lets tinker on SE-2 main repo

PS: I am replying to my own comment because Port replied to og comment by editing it 🤣

I am never gonna work under the sun again :(((((( i was like why does it say technophile there this should be a bug lmaooo

@portdeveloper
Copy link
Collaborator Author

Hey just added a commit for the manifest.json file, and hopefully I am not editing anyone's message hehe.

args.mjs i used to test things:
https://github.com/portdeveloper/manifest-test/blob/master/extension/packages/nextjs/public/manifest.json.args.mjs

Had to make iconPath optional as that is not needed in the pwa template.

@portdeveloper
Copy link
Collaborator Author

portdeveloper commented Nov 1, 2024

Honestly, I don't understand how to templatize getMetadata.ts and how to use stringify. I am so confused lol
I did it in a way but most probably not in a good way:
please correct me if it's wrong

const contents = ({ name, description, iconPath, extraContent }) => stringify({
name: name[0],
description: description[0],
...(iconPath[0] && { iconPath: iconPath[0] }), // Only include iconPath if it's provided
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If extension developer doesn't pass the iconPath it will default to "logo.svg" right? So we don't need this check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of icon, we are gonna have icons, like the example below:
https://github.com/serwist/serwist/blob/main/examples/next-web-push/public/manifest.json
So, we don't need the icon if the dev does not provide it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh yeah makes sense! So people need to pas export const iconPath = '' to omit that field.

What if people forgot to add export const iconPath = '' but also have icons in their template, will it still work as expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/portdeveloper/test-everything

yes i tested it with this extension which has all the args mjs files for the changed files in this PR

@@ -14,7 +17,7 @@ export const getMetadata = ({
description: string;
imageRelativePath?: string;
}): Metadata => {
const imageUrl = `${baseUrl}${imageRelativePath}`;
const imageUrl = \`\${baseUrl}\${imageRelativePath}\`;

return {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't understand how to templatize getMetadata.ts

I think we can wrap this whole object inside the${stringify({...})} then inside you can extraMetadata ?

Screenshot 2024-11-04 at 9 14 08 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me if i get this wrong but then it cannot read baseUrl (If we stringify the return)
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh yeah makes sense, my bad. Can we have an corresponding args.mjs file for this file?

I don't see it in https://github.com/portdeveloper/manifest-test

Copy link
Collaborator Author

@portdeveloper portdeveloper Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const titleTemplate = "%s | My PWA App"

export const extraIcons = {
  shortcut: "/favicon.ico",
  apple: [{ url: "/icons/apple-touch-icon.png", sizes: "180x180" }]
}

export const extraMetadata = {
  applicationName: 'title',
  manifest: "/manifest.json",
  appleWebApp: {
    capable: true,
    statusBarStyle: "default",
    title: 'title'
  },
  formatDetection: {
    telephone: false
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/portdeveloper/test-everything Here is a repo with all the changed files.

Copy link
Member

@rin-st rin-st Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me if i get this wrong but then it cannot read baseUrl (If we stringify the return)

If I understand it right you can theoretically do (writing it without trying)

return {
  metadataBase: new Url(baseUrl),
  ...${stringify({title: ..., description: ... , openGraph: .., twitter: ..})},
  etc

but since that part is always the same I think it's ok that it already stringifyed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only partially stringify something, the passed args does not work
e.g.
image

@@ -45,6 +48,15 @@ export const getMetadata = ({
},
icons: {
icon: [{ url: "/favicon.png", sizes: "32x32", type: "image/png" }],
${extraIcons[0] ? Object.entries(extraIcons[0]).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(',\n ') : ''}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tried ...${stringify(extraIcons[0]} here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work since there is no object there, the "..." just gets transferred to the created file

},
${extraMetadata[0] ? Object.entries(extraMetadata[0]).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(',\n ') : ''}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here but with extraMetadata[0]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gives me weird formatting errors
image

@portdeveloper portdeveloper changed the title Add template for tsconfig.json Add template for tsconfig.json + getMetadata.ts + manifest.json Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants