Home > Categories > Misc > Bulk Update Multiple Projects With Single Command

Home > Bulk Update Multiple Projects With Single Command

Bulk Update Multiple Projects With Single Command

Updated:

13 Jan 2021

Published:

13 Jan 2021

Back in the day software was distributed physically and updating software was very slow process.

But with the advent of fast internet the software and its dependencies can be updated multiple times per day.

Most developers learn a specific technology stack and use it on multiple projects.

If you have couple of projects then updating manually is actually faster and error free.

But as number of projects go up then just updating dependencies takes almost half of working day. And its not a task that anyone enjoys doing.

So we are going to update package version number from multiple projects with single command.

And another command to update dependencies from multiple projects.

You can even modify it to deploy the software after update. Basically modify to fit your specific use case.

To read rest of the article please Purchase Subscription

View bulk update source code on github

Before we get started I would recommend to develop CDK project inside development docker container.

So we no longer have the issue of "this works on my computer". And it will not mess with your existing workflow.

Pro Tip: Enable Subtitle

View bulk update source code on github

So the solution I am going to use is the following golang script.

However if you are more comfortable with nodejs then you can use replace-in-file.

So we are searching for string inside old variable and we are going to replace it with string from new variable.

The paths slice(array) holds path to all files that needs to be updated.

This list you will not have to update often so its below the old and new variables.

Then you loop through paths and read file at every path replace every occurrence of every old value with new value.

If you just want to find first and replace only once to make it run faster then you can replace -1 with 1.

With exact number of times you want to find and replace. -1 will replace every occurrence of old value.

If you want to update more than one value then you can take that output and replace another value as follows

Then you write the output in the same path that you read from.

But if there is no file at the path then it will create a new file. And for this new file you need to provide read/write permissions.

But if we are able to read from the path then definitely the file exists at this path. So the permissions will never be used.

Once the package version number is updated then we need to install all dependencies.

This can be done with help of task cli.

So add the following task in every project.

So name of task is update that will delete node_modules folder and install all dependencies.

Now we call this update task from outside folder for every project with this new task file.

Here you create a group for each project.

You need to specify path to task file and which directory this task will execute inside.

Then I am calling each group and running task named update from every group.

These are run serially i.e. one after the other.

But you can also run them in parallel. To execute them faster.

But I don't recommend you run them in parallel.

Now you can modify the update task above to run test for each project or deploy each project.

Basically modify to fit your specific use case.

View Source code on github

Conclusion

Developers spend lot of time automating workflow for their customers.

But they can also automate workflow for themselves with vanilla golang. And increase their productivity.

You no longer have to dread updating dependencies. It can run in background while you continue working on other tasks.

Free users cannot comment below so if you have questions then tweet me @apoorvmote. I would really like to hear your brutally honest feedback.

If you like this article please consider purchasing paid