Multiple Node.js builds in different subfolders with different node versions with one command possible?

I’m working on a project, a WordPress plugin for the Divi theme, with the following file structure:

  • root
    • gulpfile.js
    • package.json
    • /src/divi4
      • gulpfile.js
      • package.json
    • /src/divi5
      • gulpfile.js
      • package.json
    • /src/utils
    • /src/some_other_stuff
    • /target/my-plugin

I use the gulpfile in the root directory to copy various php files from /src/utils and other subfolders to /target/my-plugin. I also minify some JS and CSS files and use the root scripts to zip the finished build.

Additionally, I have a gulpfile in /src/divi4 to build some legacy code for the Divi 4 theme. This also includes copying files to /target and minify JS and CSS. Besides that, I also run a Webpack build, based on some legacy scripts. The package.json containing the build scripts looks like this:

"build": "npm-run-all --parallel build:*",
"build:webpack": "node my-build-scripts/build.js",
"build:gulp": "gulp build"

The build scripts came from a Elegant Themes, the creator of the Divi theme and they require node 14 in order to work.

Elegant Themes now is working on Divi 5, where they completely redesigned their APIs and they want us to build Divi 5 modules using node 18. Therefore I use nvm to switch to node 18, cd into /src/divi5 and run the node build there, which does more or less the same as the other parts of the build: copy php files, minify JS and CSS and run a webpack build.

Instead of having to run multiple commands in 3 separate folders for the finished zip file of my plugin to contain all required files like:

# build legacy Divi 4 modules:
cd src/divi4 
nvm use 14
yarn install
yarn build

# build new Divi 5 modules
cd ../divi5 
nvm use 18
yarn install 
yarn build

# build the rest of the plugin and create the zip file
cd ../.. 
yarn install
yarn build

I would like to only have to run 1 single yarn install && yarn build command in the root directory of my git repository. The Divi 4 and Divi 5 builds are independent from each other so they could theoretically run in parallel whereas the build in the root directory has to wait in order to get all files when creating the zip file.

Question: Do you know a way to trigger the Divi 4 and 5 builds from the root directory of my git plugin?

I’ve tried the following code in my root/gulpfile.js and wrapped the command [ -5 "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && cd src/divi4 && nvm use 14 && yarn install && yarn build inside the function but some of our devs use Windows and though the command seemed to work on macOS, it didn’t work on Windows and I’m not sure if this would be the way to go. I hope you can give me a hint to a solution which works on every OS.

const { exec } = require('child_process');

function runCommand(command, callback) {
    exec(command, (err, stdout, stderr) => {
        if (err) {
            console.log(stdout);
            console.error(`Error: ${stderr}`);
            callback(err);
        } else {
            console.log(stdout);
            callback();
        }
    });
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật