0

I want to create multiple Gatsby site which will use same theme. But maintaining them is hard because if I update a npm package in one repository then it won't update in other repositories. So, I have to update all of them separately. Is there any way to update packages in all repositories at once?

  1. /src/pages/posts
  2. /gatsby-config.js

Only these two files need to be unchanged in all the repositories.

underscore_d
  • 6,309
  • 3
  • 38
  • 64

2 Answers2

0

Welcome to StackOverflow!

Maybe Git is not the best solution for this, I will advise you use a bash/Powershell script to trigger npm update across all the sites. But if you really want to do it with Git, below you will get an option.

Step 0: Clone the site you want to take as a base for all the others in your local computer

Step 1: Create Git remotes required on your local computer. This are the urls/pointers to the different sites you need to push and pull**

# Syntax - git remote add <remote_name> <remote_url>
> git remote add site1 https://github.com/user/repo1.git
> git remote add site2 https://github.com/user/repo2.git

Step 2: Add to .gitignore file the files/folders that you don't want to change across sites

> cat .gitignore

/src/pages/posts
/gatsby-config.js

**Step 3: Now every time you make changes to these packages you can, push to all the remotes master branch with the following command

git remote | xargs -L1 -I R git push R master

Note: With this solution when you pull an update to your other sites, you need to modify the .gitignore file deleting the entries you made. Otherwise you sites will start ignoring those folders too. Reference of this third step: https://stackoverflow.com/a/18674313/10783334

Erick Guillen
  • 547
  • 4
  • 11
0

Assuming you have all the sites inside a folder, you can copy the following code to a Powershell script like "ScriptUpdateNpm.ps1" and run it in your root folder

Folder structure

 - GatbsySites
  - Site1
  - Site2
  - Site3
  - ScriptUpdateNpm.ps1
$Script:Modules = @(
    'Package1',
    'Package2'
)

$folders = Get-ChildItem -Attributes Directory
$rootFolder = Get-Location

foreach ($folder in $folders) {
    Set-Location $folder 
    npm update $Script:Modules
    Set-Location $rootFolder
}
Erick Guillen
  • 547
  • 4
  • 11