calling gulp

Melody Scott
Melody Scott used Ask the Experts™
on
Hi, I hope I can explain this well enough.

My folder structure looks like the attached. In each folder, I have src/pages, results, dev/gulp.

pages contains the nunjucks files, results are the resulting html files from running gulp nunjucks, and dev/gulp is where the gulpfile.js is.

When I want to make a change across the board, say to the navigation, I have to use the command line to go into each folder, gulp nunjucks, upload, then back out by changing directories, navigate to the next one, gulp nunjucks, and on through all 13. So my command line looks like the attached.

Can you help me find a way to speed that up?
Capture.JPG
cmd.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Are you using a BAT script to perform all that, or are you actually manually doing it at the command line?  Wasn't sure if just a BAT script that intelligently processed all the needed directories would be helpful or not.  Or if you were looking for a different process etc to avoid the actual multiple executions of "gulp".


»bp

Author

Commented:
I'm a newbie at this, so just doing command line. I hadn't thought of a BAT script, I can look into that, good idea.
IT / Software Engineering Consultant
Top Expert 2016
Commented:
Here's a couple of approaches on a BAT script.  There are two approaches in this example, one if you want to process all subfolders of that base folder, or another approach where you just process each one that you need by name.  Hope this makes sense and gives you some ideas...  (Didn't test it here, so check syntax and test there, questions welcome)

@echo off
setlocal

rem Define base folder
set "BaseDir=C:\Users\Mel\Desktop\_magic-kitchen 2"

rem Process the base folder
call :DoGulp "%BaseDir%"

rem Process each subfolder of base folder
for /d %%D in ("%BaseDir%\*.") do call :DoGulp "%%~D"

rem ALTERNATIVE IF NOT ALL SUBFOLDERS SHOULD BE PROCESSED
call :DoGulp "%BaseDir%\affiliates"
call :DoGulp "%BaseDir%\diet"
call :DoGulp "%BaseDir%\discounts"
call :DoGulp "%BaseDir%\ebooks"
call :DoGulp "%BaseDir%\exercises"
call :DoGulp "%BaseDir%\gift"
call :DoGulp "%BaseDir%\info"
call :DoGulp "%BaseDir%\landing"
call :DoGulp "%BaseDir%\master-gift"
call :DoGulp "%BaseDir%\news"
call :DoGulp "%BaseDir%\partners"
call :DoGulp "%BaseDir%\products"
call :DoGulp "%BaseDir%\thanks"

rem Exit script (needed before subroutines)
exit /b

rem Try to change to a folder and then execute gulp
:DoGulp [folder-path]
  pushd "%~1\dev\gulp"
  if /i "%CD%" EQU "%~1\dev\gulp" (
    echo Processing folder "%~1\dev\gulp"
    gulp nunjucks
    popd
  ) else (
    echo Unable to access "%~1\dev\gulp"
  )
  exit /b

Open in new window


»bp
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Thanks!

Author

Commented:
Works amazingly well, I did see one error slip by, I assume if I remove the last   exit /b, the screen will remain open and I can track it down? This is so cool. :)
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
If you want the screen to stay open then add a PAUSE, like below.  But easier might be to just open a command window first, and then run the BAT there.  That way you will see all output in that window.

@echo off
setlocal

rem Define base folder
set "BaseDir=C:\Users\Mel\Desktop\_magic-kitchen 2"

rem Process the base folder
call :DoGulp "%BaseDir%"

rem Process each subfolder of base folder
for /d %%D in ("%BaseDir%\*.") do call :DoGulp "%%~D"

rem ALTERNATIVE IF NOT ALL SUBFOLDERS SHOULD BE PROCESSED
call :DoGulp "%BaseDir%\affiliates"
call :DoGulp "%BaseDir%\diet"
call :DoGulp "%BaseDir%\discounts"
call :DoGulp "%BaseDir%\ebooks"
call :DoGulp "%BaseDir%\exercises"
call :DoGulp "%BaseDir%\gift"
call :DoGulp "%BaseDir%\info"
call :DoGulp "%BaseDir%\landing"
call :DoGulp "%BaseDir%\master-gift"
call :DoGulp "%BaseDir%\news"
call :DoGulp "%BaseDir%\partners"
call :DoGulp "%BaseDir%\products"
call :DoGulp "%BaseDir%\thanks"

rem Exit script (needed before subroutines)
pause
exit /b

rem Try to change to a folder and then execute gulp
:DoGulp [folder-path]
  pushd "%~1\dev\gulp"
  if /i "%CD%" EQU "%~1\dev\gulp" (
    echo Processing folder "%~1\dev\gulp"
    gulp nunjucks
    popd
  ) else (
    echo Unable to access "%~1\dev\gulp"
  )
  exit /b

Open in new window


»bp

Author

Commented:
Excellent solution to this question, exactly what I needed, thanks!

Author

Commented:
Bill, I have another gulp related question I'll put up shortly, can I send you a message about it once it's up?
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Sure, happy to take a look and try to help if I can.


»bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial