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

Migrate Netlify CMS to Decap CMS #79

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

Conversation

biru-codeastromer
Copy link
Contributor

@biru-codeastromer biru-codeastromer commented Dec 16, 2024

Fixes #1, fixes #78

Description

This pull request refactors the current project setup by migrating from Netlify CMS to Decap CMS. The migration enhances CMS functionality and aligns with Decap CMS's rebranding and new features. Additionally, this PR modernizes the code by updating dependencies, addressing issue #78, and improving the overall project setup.

Changes made:

1.Replaced the netlify-cms-app dependency with decap-cms in the package.json.
2.Switched from gatsby-plugin-netlify-cms to gatsby-plugin-decap-cms in gatsby-config.js.
3.Updated config.yml to ensure compatibility with Decap CMS's backend and media folder settings.
4.Modernized the project by updating outdated dependencies to improve compatibility and security.

@krisstern
Copy link
Member

Hi @biru-codeastromer please refer to this doc https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue on how to use keywords to properly link an issue. I have fixed it up for you previously. But you may want to do so properly moving forwards.

@krisstern
Copy link
Member

Also you may want to run the build locally to make sure there are no issues before pushing code to the repo. I am current seeing the following in the logs at https://github.com/jenkins-infra/stories/pull/79/checks?check_run_id=34477938558:

[2024-12-16T14:49:32.936Z] + npm run lint
[2024-12-16T14:49:33.238Z] 
[2024-12-16T14:49:33.238Z] > [email protected] lint
[2024-12-16T14:49:33.238Z] > eslint .
[2024-12-16T14:49:33.238Z] 
[2024-12-16T14:49:34.942Z] Browserslist: caniuse-lite is outdated. Please run:
[2024-12-16T14:49:34.942Z]   npx browserslist@latest --update-db
[2024-12-16T14:49:34.943Z]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2024-12-16T14:49:35.444Z] 
[2024-12-16T14:49:35.445Z] /home/jenkins/agent/workspace/Websites_stories_PR-79/gatsby-config.js
[2024-12-16T14:49:35.445Z]   25:11  error  Trailing spaces not allowed  no-trailing-spaces
[2024-12-16T14:49:35.445Z] 
[2024-12-16T14:49:35.445Z] /home/jenkins/agent/workspace/Websites_stories_PR-79/src/cms/cms.js
[2024-12-16T14:49:35.445Z]    1:17  error  Unable to resolve path to module 'decap-cms-app'  import/no-unresolved
[2024-12-16T14:49:35.445Z]    3:20  error  Missing file extension for "../layout"            import/extensions
[2024-12-16T14:49:35.445Z]    3:20  error  Unable to resolve path to module '../layout'      import/no-unresolved
[2024-12-16T14:49:35.445Z]   13:28  error  There should be no space after '{'                object-curly-spacing
[2024-12-16T14:49:35.445Z]   13:56  error  There should be no space before '}'               object-curly-spacing
[2024-12-16T14:49:35.445Z]   23:35  error  Unexpected function expression                    prefer-arrow-callback
[2024-12-16T14:49:35.446Z]   28:10  error  Missing semicolon                                 semi
[2024-12-16T14:49:35.446Z]   35:5   error  Unexpected console statement                      no-console
[2024-12-16T14:49:35.446Z] 
[2024-12-16T14:49:35.446Z] ✖ 9 problems (9 errors, 0 warnings)
[2024-12-16T14:49:35.446Z]   5 errors and 0 warnings potentially fixable with the `--fix` option.
[2024-12-16T14:49:35.446Z] 

Copy link
Member

@krisstern krisstern left a comment

Choose a reason for hiding this comment

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

Please update the file name src/cms/cms.js to src/cms/index.js, and update all references to this path accordingly.

@biru-codeastromer
Copy link
Contributor Author

Hi @biru-codeastromer please refer to this doc https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue on how to use keywords to properly link an issue. I have fixed it up for you previously. But you may want to do so properly moving forwards.

Hi @krisstern Sir,

Thank you for pointing that out! I appreciate you fixing the issue previously. I’ll make sure to follow the guidelines provided in the doc moving forward and use the appropriate keywords to link issues and pull requests properly. I’ll refer to the resource to ensure I’m following the best practices.

Thanks for your help!

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 16, 2024

Please update the file name src/cms/cms.js to src/cms/index.js, and update all references to this path accordingly.

Done Sir

@biru-codeastromer
Copy link
Contributor Author

Also you may want to run the build locally to make sure there are no issues before pushing code to the repo. I am current seeing the following in the logs at https://github.com/jenkins-infra/stories/pull/79/checks?check_run_id=34477938558:

Hi @krisstern,

I’ve completed fixing the previous errors, but I am still encountering issues with the layout and Decap CMS integration. It seems like the layout module is not being found in the src folder, which is causing problems with the build. Additionally, the decap-cms-app module also isn’t resolving properly.

Interestingly, the same issue I saw in the template provided by the zbynek Sir comment on #1 , where the problem also occurred in the build of that repo.
The issue arises because [email protected] has a peer dependency requirement for react@^18.2.0, while our repo is using [email protected]. This results in a conflict that prevents the installation from proceeding.

To resolve the npm install decap-cms-app issue, I used the yarn method as an alternative to npm. While this did successfully solve the dependency conflict, I’ve encountered a new issue after deploying the changes. Specifically, the images are no longer showing up on the deployed site.

It seems like the change may have affected how the assets are being referenced or loaded. I’m currently looking into this issue.

After resolving all the other errors, these 3 remaining issues persist in the logs:
/Users/birajitsaikia/Documents/decapcms/stories/src/cms/index.js
birajitsaikia@Birajits-MacBook-Pro stories % npm run lint
1:17 error Unable to resolve path to module 'decap-cms-app' import/no-unresolved
3:20 error Missing file extension for "../layout" import/extensions
3:20 error Unable to resolve path to module '../layout' import/no-unresolved

@krisstern
Copy link
Member

krisstern commented Dec 16, 2024

Please note we also have this issue #78 for modernizing dependecies, maybe you can use the same PR to resolve both issues.

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 16, 2024

Please note we also have this issue #78 for modernizing dependecies, maybe you can use the same PR to resolve both issues.

Okay Sir ,I will take a look at the details there and work on resolving both issues in a single PR.

@biru-codeastromer
Copy link
Contributor Author

Screenshot 2024-12-17 at 4 34 20 AM

I corrected the required errors and did it successfully the building .Still some ci checks failed and will now look onto it.

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 16, 2024

Hi Sir @krisstern ,I have encountered an issue while trying to resolve the CI checks for the project. The problem seems to occur depending on the file name and the configuration of the gatsby-config file. Here's a breakdown of the situation:

  1. When I keep the file name as gatsby-config.js:

    • After making the necessary changes, I encounter the following error during the build process:
      [2024-12-16T23:40:18.122Z] + npm run build
      [2024-12-16T23:40:18.323Z]
      > [email protected] build
      > gatsby build
      [2024-12-16T23:40:21.430Z] error We encountered an error while trying to load your site's gatsby-config. Please fix the error and try again.
      ReferenceError: module is not defined in ES module scope
      This file is being treated as an ES module because it has a '.js' file extension and '/home/jenkins/agent/workspace/Websites_stories_PR-79/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
      
    • This error occurs because the gatsby-config.js file is being treated as an ES module due to the package.json "type": "module" setting. The error message suggests renaming the file to .cjs to treat it as a CommonJS script.
  2. When I rename the file to gatsby-config.cjs:

    • After renaming it and making the other required changes, I receive the following error:
      [2024-12-16T23:30:23.459Z] + npm run build
      [2024-12-16T23:30:23.761Z] 
      > [email protected] build
      > gatsby build
      [2024-12-16T23:30:26.968Z] error It looks like you were trying to add the config file? Please rename "gatsby-config.cjs" to "gatsby-config.js"
      
    • This error seems to indicate that Gatsby expects the configuration file to be named gatsby-config.js and doesn't recognize the .cjs extension, even though it should be treated as CommonJS.

It appears that whichever suggestion I follow leads to one of these errors, and I am unable to find a solution that resolves both issues at the same time.So deep driving and checking possible ways to tackle this error.

@krisstern
Copy link
Member

For upgrading from React 17 to 18 there are additional steps like they outline here https://react.dev/blog/2022/03/08/react-18-upgrade-guide. So @biru-codeastromer you may want to do some more background research instead of going by trial-and-error.

@krisstern
Copy link
Member

@biru-codeastromer Could you please remove the .DS_Store you have added and add an entry for .DS_Store in the .gitignore file?

@krisstern
Copy link
Member

Also, could you please try running npm audit fix as well for this PR?

@krisstern
Copy link
Member

I also see the following in the stack trace currently:

Error: Cannot create as TypeComposer the following value: 
    GraphQLScalarType({ name: "Date", description: "A date string, such as 2007-12-03, compliant with the ISO 8601
   standard for representation of dates and times using the Gregorian calendar.", specifiedByURL: undefined, seria
  lize: [function String], parseValue: [function String], parseLiteral: [function parseLiteral], extensions: {  },
   astNode: undefined, extensionASTNodes: [] }).

@krisstern
Copy link
Member

Could you also check if we will need to upgrade from gatsby-plugin-netlify to gatsby-plugin-decap-cms in the dependencies? Otherwise it may not work.

@krisstern
Copy link
Member

Is there a reason why I am seeing

"react": "^18.0.0",
    "react-dom": "^18.0.0",

in the package.json instead of the latest v18 version? Could you please update this as well?

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 18, 2024

Could you also check if we will need to upgrade from gatsby-plugin-netlify to gatsby-plugin-decap-cms in the dependencies? Otherwise it may not work.

Thank you for the suggestion Sir! I have attempted upgrading to the latest version of React. However, I encountered compatibility issues with some other dependencies in the project, which forced me to downgrade React back to version 18.0.0.

@biru-codeastromer
Copy link
Contributor Author

Also, could you please try running npm audit fix as well for this PR?

I’ve run npm audit fix multiple times during this process, but it hasn’t resolved all vulnerabilities. I will review the remaining audit issues manually and see if further updates or alternate solutions are required.

@biru-codeastromer
Copy link
Contributor Author

I also see the following in the stack trace currently:

Error: Cannot create as TypeComposer the following value: 
    GraphQLScalarType({ name: "Date", description: "A date string, such as 2007-12-03, compliant with the ISO 8601
   standard for representation of dates and times using the Gregorian calendar.", specifiedByURL: undefined, seria
  lize: [function String], parseValue: [function String], parseLiteral: [function parseLiteral], extensions: {  },
   astNode: undefined, extensionASTNodes: [] }).

Hi Sir @krisstern ,regarding the GraphQL error, I have made several attempts to resolve the issue, but the same error persists. I am currently investigating the root cause more deeply, including examining plugin compatibility and schema handling.

Additionally, I’ll check the feasibility of replacing gatsby-plugin-netlify with gatsby-plugin-decap-cms to improve compatibility and align with updated project requirements.

Thank you for your guidance!

@biru-codeastromer
Copy link
Contributor Author

Screenshot 2024-12-18 at 7 30 50 PM

I found this on documentation of gatsby. The error i am facing is mentioned ,It is said to be cause to multiple.I tried using resolutions tactics but same issue came up again .Should I use this " delete node_modules and re-install with npm install --legacy-peer-deps/yarn install" to tackle this Sir.

@krisstern
Copy link
Member

I found this on documentation of gatsby. The error i am facing is mentioned ,It is said to be cause to multiple.I tried using resolutions tactics but same issue came up again .Should I use this " delete node_modules and re-install with npm install --legacy-peer-deps/yarn install" to tackle this Sir.

Yes, do try to delete the packge.json lock file as well as the node_modules directory with all its contents and then reinstall the dependencies using the following:

npm install --legacy-peer-deps

Keep us posted how it goes.

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 18, 2024

Yes, do try to delete the packge.json lock file as well as the node_modules directory with all its contents and then reinstall the dependencies using the following:

npm install --legacy-peer-deps

Keep us posted how it goes.

Screenshot 2024-12-18 at 9 12 31 PM Screenshot 2024-12-18 at 9 12 18 PM Screenshot 2024-12-18 at 9 29 51 PM

Hi Sir , I solved the issue without legacy peer deps.

Changes Made

1.Renamed Scalar Type:

a.Changed the custom scalar type from Date to CustomDate in gatsby-node.js.
b.Updated schema customization to define CustomDate directly.

2.Removed Redundant Resolvers:

a.Removed the createResolvers function for the CustomDate scalar type as it's not required for scalar types.

3.Ensured Single Version of graphql:

a.Added resolutions and overrides in package.json to enforce the use of a single version of graphql (16.10.0).

@krisstern
Copy link
Member

Remember to push your code changes here

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 18, 2024

Remember to push your code changes here

I encountered a permission issue during the build process in our CI pipeline. The error message indicated that there was a permission denied error when trying to create a directory in the /opt/build path. Here are the details of the error:

[2024-12-18T16:36:44.466Z] error Cannot copy from `.cache/.eslintrc.json` to `/opt/build/cache/cwd/.cache/.eslintrc.json`: Cannot create directory `/opt/build/cache/cwd/.cache`: EACCES: permission denied, mkdir '/opt/build'
[2024-12-18T16:36:44.466Z] 
[2024-12-18T16:36:44.466Z] 
[2024-12-18T16:36:44.466Z]   NestedError: Cannot copy from `.cache/.eslintrc.json` to `/opt/build/cache/cwd  /.cache/.eslintrc.json`: Cannot create directory `/opt/build/cache/cwd/.cache`  : EACCES: permission denied, mkdir '/opt/build'
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - index.js:274 pMap.concurrency.concurrency
[2024-12-18T16:36:44.467Z]     [adapters]/[cpy]/index.js:274:12
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - index.js:141 
[2024-12-18T16:36:44.467Z]     [adapters]/[p-map]/index.js:141:20
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - Caused By: NestedError: Cannot create directory `/opt/build/cache/cwd/.cache    `: EACCES: permission denied, mkdir '/opt/build'
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - fs.js:61 
[2024-12-18T16:36:44.467Z]     [adapters]/[cp-file]/fs.js:61:8
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - index.js:15 async cpFileAsync
[2024-12-18T16:36:44.467Z]     [adapters]/[cp-file]/index.js:15:2
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - index.js:269 async pMap.concurrency.concurrency
[2024-12-18T16:36:44.467Z]     [adapters]/[cpy]/index.js:269:6
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - index.js:141 
[2024-12-18T16:36:44.467Z]     [adapters]/[p-map]/index.js:141:20
[2024-12-18T16:36:44.467Z]   
[2024-12-18T16:36:44.467Z]   - Caused By: Error: EACCES: permission denied, mkdir '/opt/build'

@krisstern
Copy link
Member

It looks like the build step (which is the only one you have control of) has been successful, and the problem looks like a deployment issue as discussed for example in https://community.cloudflare.com/t/gatsby-pages-deployment-error/558278/5. Let me follow this up with the Jenkins Infra team shortly.

@krisstern
Copy link
Member

I have opened an issue with the Infra team helpdesk at jenkins-infra/helpdesk#4461. But please do not comment on that issue. In case of anything you would like to voice out let me know and I will liaise with the Infra team via that ticket.

@biru-codeastromer
Copy link
Contributor Author

It looks like the build step (which is the only one you have control of) has been successful, and the problem looks like a deployment issue as discussed for example in https://community.cloudflare.com/t/gatsby-pages-deployment-error/558278/5. Let me follow this up with the Jenkins Infra team shortly.

Thank you Sir for clarifying that the build step completed successfully and for identifying the deployment issue. I appreciate the reference to the related Cloudflare community discussion and your initiative to follow up with the Jenkins Infra team.

@biru-codeastromer
Copy link
Contributor Author

I have opened an issue with the Infra team helpdesk at jenkins-infra/helpdesk#4461. But please do not comment on that issue. In case of anything you would like to voice out let me know and I will liaise with the Infra team via that ticket.

Also thank you Sir for opening the issue with the Infra team and for sharing the helpdesk ticket reference. I understand your request not to comment directly on the issue, and I will ensure to communicate any additional input or concerns through you. Let me know if there’s anything further I can provide to assist with the resolution.

@biru-codeastromer
Copy link
Contributor Author

Hi Sir,

To resolve the permission issue during the build process, I propose using a custom cache directory. This involves setting environment variables and updating the build command to specify a directory with appropriate permissions:

1.Set Environment Variables
2.Update Build Command

Please let me know if you agree with this approach/thought or if there are any additional considerations.

@krisstern
Copy link
Member

krisstern commented Dec 19, 2024

Hi @biru-codeastromer The Infra team will come up with a solution shortly. Unless they ask for our opinion, we do not need to provide any feedback at this stage.

@biru-codeastromer
Copy link
Contributor Author

Hi @biru-codeastromer The Infra team will come up with a solution shortly. Unless they ask for our opinion, we do not need to provide any feedback at this stage.

Thank You Sir for the clarification .

@krisstern
Copy link
Member

Also, this is not a trivial change. Once we update the configuration it will affect the entire repo moving forwards, so it is better to let the Infra team step in and do some magic for us. However, since we are officially in the winter break, so the change may not come as soon as it normally does.

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Dec 19, 2024

Also, this is not a trivial change. Once we update the configuration it will affect the entire repo moving forwards, so it is better to let the Infra team step in and do some magic for us. However, since we are officially in the winter break, so the change may not come as soon as it normally does.

Okay Sir, thank you for the details. Okay Sir I will wait since this PR is also has a connection with PR #77 and both these PR's solves three issues at together,so looking forward for the changes by the infra team whenever possible

Sure, till then I will continue solving other issues and make other contributions.

@krisstern
Copy link
Member

Hi @biru-codeastromer could you please take some time to resolve the conclicts in this PR?

@biru-codeastromer
Copy link
Contributor Author

Hi @biru-codeastromer could you please take some time to resolve the conclicts in this PR?

Sure Sir @krisstern will be doing It !

@biru-codeastromer
Copy link
Contributor Author

Hi Sir @krisstern I have resolved the merge conflicts in the PR.
Thanks!

@biru-codeastromer
Copy link
Contributor Author

biru-codeastromer commented Jan 20, 2025

Hi @biru-codeastromer could you please take some time to resolve the conclicts in this PR?

I solved it , but due to regular changes in main it keeps getting conflicts ,
do you think Sir , I should wait for the PR's #80 and #84 to get merged then finally solved the conflicts at once . Or should I resolved it regularly . Please let me know !

@biru-codeastromer
Copy link
Contributor Author

I solved it , but due to regular changes in main it keeps getting conflicts , do you think Sir , I should wait for the PR's #80 and #84 to get merged then finally solved the conflicts at once . Or should I resolved it regularly . Please let me know !

Also I will follow your method what you told me in an issue regarding merging main

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.

Modernize code by updating dependencies Add Decap CMS
2 participants